; LLVM IR from BrunoLevy/learn-fpga :: LiteX/software/Doom/mc1-doom/src (wi_stuff)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@state = external hidden global i32, align 4
@acceleratestage = external hidden global i32, align 4
@playeringame = external global [4 x i32], align 16
@dm_state = external hidden global i32, align 4
@cnt_pause = external hidden global i32, align 4
@dm_frags = external hidden global [4 x [4 x i32]], align 16
@dm_totals = external hidden global [4 x i32], align 16

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @WI_initAnimatedBack() #1

; Function Attrs: nounwind uwtable
define dso_local void @WI_initDeathmatchStats() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr @state, align 4, !tbaa !5
  store i32 0, ptr @acceleratestage, align 4, !tbaa !5
  store i32 1, ptr @dm_state, align 4, !tbaa !5
  store i32 35, ptr @cnt_pause, align 4, !tbaa !5
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %38, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = icmp slt i32 %4, 4
  br i1 %5, label %6, label %41

6:                                                ; preds = %3
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [4 x i32], ptr @playeringame, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %37

12:                                               ; preds = %6
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %30, %12
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = icmp slt i32 %14, 4
  br i1 %15, label %16, label %33

16:                                               ; preds = %13
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [4 x i32], ptr @playeringame, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %29

22:                                               ; preds = %16
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [4 x [4 x i32]], ptr @dm_frags, i64 0, i64 %24
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [4 x i32], ptr %25, i64 0, i64 %27
  store i32 0, ptr %28, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %22, %16
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !9

33:                                               ; preds = %13
  %34 = load i32, ptr %1, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [4 x i32], ptr @dm_totals, i64 0, i64 %35
  store i32 0, ptr %36, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %33, %6
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %1, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %1, align 4, !tbaa !5
  br label %3, !llvm.loop !11

41:                                               ; preds = %3
  call void @WI_initAnimatedBack()
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@state = external hidden local_unnamed_addr global i32, align 4
@acceleratestage = external hidden local_unnamed_addr global i32, align 4
@playeringame = external local_unnamed_addr global [4 x i32], align 16
@dm_state = external hidden local_unnamed_addr global i32, align 4
@cnt_pause = external hidden local_unnamed_addr global i32, align 4
@dm_frags = external hidden local_unnamed_addr global [4 x [4 x i32]], align 16
@dm_totals = external hidden local_unnamed_addr global [4 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @WI_initAnimatedBack() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @WI_initDeathmatchStats() local_unnamed_addr #0 {
  store i32 0, ptr @state, align 4, !tbaa !5
  store i32 0, ptr @acceleratestage, align 4, !tbaa !5
  store i32 1, ptr @dm_state, align 4, !tbaa !5
  store i32 35, ptr @cnt_pause, align 4, !tbaa !5
  %1 = load i32, ptr @playeringame, align 16, !tbaa !5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %8, label %.preheader.1

.preheader.1:                                     ; preds = %0
  store i32 0, ptr @dm_frags, align 16, !tbaa !5
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @playeringame, i64 4), align 4, !tbaa !5
  %.not10.1 = icmp eq i32 %2, 0
  br i1 %.not10.1, label %.preheader.2, label %3

3:                                                ; preds = %.preheader.1
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_frags, i64 4), align 4, !tbaa !5
  br label %.preheader.2

.preheader.2:                                     ; preds = %3, %.preheader.1
  %4 = load i32, ptr getelementptr inbounds (i8, ptr @playeringame, i64 8), align 8, !tbaa !5
  %.not10.2 = icmp eq i32 %4, 0
  br i1 %.not10.2, label %.preheader.3, label %5

5:                                                ; preds = %.preheader.2
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_frags, i64 8), align 8, !tbaa !5
  br label %.preheader.3

.preheader.3:                                     ; preds = %5, %.preheader.2
  %6 = load i32, ptr getelementptr inbounds (i8, ptr @playeringame, i64 12), align 4, !tbaa !5
  %.not10.3 = icmp eq i32 %6, 0
  br i1 %.not10.3, label %.thread, label %7

7:                                                ; preds = %.preheader.3
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_frags, i64 12), align 4, !tbaa !5
  br label %.thread

8:                                                ; preds = %0
  %.pre = load i32, ptr getelementptr inbounds (i8, ptr @playeringame, i64 4), align 4, !tbaa !5
  %.not.1 = icmp eq i32 %.pre, 0
  br i1 %.not.1, label %._crit_edge21, label %.preheader.2.1

.thread:                                          ; preds = %.preheader.3, %7
  store i32 0, ptr @dm_totals, align 16, !tbaa !5
  %.not.125 = icmp eq i32 %2, 0
  br i1 %.not.125, label %._crit_edge21, label %.preheader.preheader.1.thread

._crit_edge21:                                    ; preds = %.thread, %8
  %.pre22 = load i32, ptr getelementptr inbounds (i8, ptr @playeringame, i64 8), align 8, !tbaa !5
  br label %14

.preheader.preheader.1.thread:                    ; preds = %.thread
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_frags, i64 16), align 16, !tbaa !5
  br label %.preheader.2.1

.preheader.2.1:                                   ; preds = %8, %.preheader.preheader.1.thread
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_frags, i64 20), align 4, !tbaa !5
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @playeringame, i64 8), align 8, !tbaa !5
  %.not10.2.1 = icmp eq i32 %9, 0
  br i1 %.not10.2.1, label %.preheader.3.1, label %10

10:                                               ; preds = %.preheader.2.1
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_frags, i64 24), align 8, !tbaa !5
  br label %.preheader.3.1

.preheader.3.1:                                   ; preds = %10, %.preheader.2.1
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @playeringame, i64 12), align 4, !tbaa !5
  %.not10.3.1 = icmp eq i32 %11, 0
  br i1 %.not10.3.1, label %13, label %12

12:                                               ; preds = %.preheader.3.1
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_frags, i64 28), align 4, !tbaa !5
  br label %13

13:                                               ; preds = %12, %.preheader.3.1
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_totals, i64 4), align 4, !tbaa !5
  br label %14

14:                                               ; preds = %._crit_edge21, %13
  %.not.126 = phi i1 [ true, %._crit_edge21 ], [ false, %13 ]
  %15 = phi i32 [ %.pre22, %._crit_edge21 ], [ %9, %13 ]
  %.not.2 = icmp eq i32 %15, 0
  br i1 %.not.2, label %._crit_edge23, label %.preheader.preheader.2

._crit_edge23:                                    ; preds = %14
  %.pre24 = load i32, ptr getelementptr inbounds (i8, ptr @playeringame, i64 12), align 4, !tbaa !5
  br label %21

.preheader.preheader.2:                           ; preds = %14
  br i1 %.not, label %.preheader.1.2, label %16

16:                                               ; preds = %.preheader.preheader.2
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_frags, i64 32), align 16, !tbaa !5
  br label %.preheader.1.2

.preheader.1.2:                                   ; preds = %16, %.preheader.preheader.2
  br i1 %.not.126, label %.preheader.3.2, label %17

17:                                               ; preds = %.preheader.1.2
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_frags, i64 36), align 4, !tbaa !5
  br label %.preheader.3.2

.preheader.3.2:                                   ; preds = %17, %.preheader.1.2
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_frags, i64 40), align 8, !tbaa !5
  %18 = load i32, ptr getelementptr inbounds (i8, ptr @playeringame, i64 12), align 4, !tbaa !5
  %.not10.3.2 = icmp eq i32 %18, 0
  br i1 %.not10.3.2, label %20, label %19

19:                                               ; preds = %.preheader.3.2
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_frags, i64 44), align 4, !tbaa !5
  br label %20

20:                                               ; preds = %19, %.preheader.3.2
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_totals, i64 8), align 8, !tbaa !5
  br label %21

21:                                               ; preds = %._crit_edge23, %20
  %22 = phi i32 [ %.pre24, %._crit_edge23 ], [ %18, %20 ]
  %.not.3 = icmp eq i32 %22, 0
  br i1 %.not.3, label %27, label %.preheader.preheader.3

.preheader.preheader.3:                           ; preds = %21
  br i1 %.not, label %.preheader.1.3, label %23

23:                                               ; preds = %.preheader.preheader.3
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_frags, i64 48), align 16, !tbaa !5
  br label %.preheader.1.3

.preheader.1.3:                                   ; preds = %23, %.preheader.preheader.3
  br i1 %.not.126, label %.preheader.2.3, label %24

24:                                               ; preds = %.preheader.1.3
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_frags, i64 52), align 4, !tbaa !5
  br label %.preheader.2.3

.preheader.2.3:                                   ; preds = %24, %.preheader.1.3
  br i1 %.not.2, label %26, label %25

25:                                               ; preds = %.preheader.2.3
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_frags, i64 56), align 8, !tbaa !5
  br label %26

26:                                               ; preds = %25, %.preheader.2.3
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_frags, i64 60), align 4, !tbaa !5
  store i32 0, ptr getelementptr inbounds (i8, ptr @dm_totals, i64 12), align 4, !tbaa !5
  br label %27

27:                                               ; preds = %26, %21
  tail call void @WI_initAnimatedBack()
  ret void
}

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass