; 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"

%struct.player_s = type { ptr, i32, %struct.ticcmd_t, i32, i32, i32, i32, i32, i32, i32, [6 x i32], [6 x i32], i32, [4 x i32], i32, i32, [9 x i32], [4 x i32], [4 x i32], i32, i32, i32, i32, i32, i32, i32, ptr, i32, i32, ptr, i32, i32, i32, [2 x %struct.pspdef_t], i32 }
%struct.ticcmd_t = type { i8, i8, i16, i16, i8, i8 }
%struct.pspdef_t = type { ptr, i32, i32, i32 }

@acceleratestage = external hidden global i32, align 4
@playeringame = external global [4 x i32], align 16
@players = external global [4 x %struct.player_s], 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
define dso_local void @WI_checkForAccelerate() #1 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  store ptr @players, ptr %2, align 8, !tbaa !9
  br label %3

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

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 %53

12:                                               ; preds = %6
  %13 = load ptr, ptr %2, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.player_s, ptr %13, i32 0, i32 2
  %15 = getelementptr inbounds %struct.ticcmd_t, ptr %14, i32 0, i32 5
  %16 = load i8, ptr %15, align 1, !tbaa !11
  %17 = zext i8 %16 to i32
  %18 = and i32 %17, 1
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %29

20:                                               ; preds = %12
  %21 = load ptr, ptr %2, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.player_s, ptr %21, i32 0, i32 19
  %23 = load i32, ptr %22, align 8, !tbaa !15
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %26, label %25

25:                                               ; preds = %20
  store i32 1, ptr @acceleratestage, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %25, %20
  %27 = load ptr, ptr %2, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.player_s, ptr %27, i32 0, i32 19
  store i32 1, ptr %28, align 8, !tbaa !15
  br label %32

29:                                               ; preds = %12
  %30 = load ptr, ptr %2, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.player_s, ptr %30, i32 0, i32 19
  store i32 0, ptr %31, align 8, !tbaa !15
  br label %32

32:                                               ; preds = %29, %26
  %33 = load ptr, ptr %2, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.player_s, ptr %33, i32 0, i32 2
  %35 = getelementptr inbounds %struct.ticcmd_t, ptr %34, i32 0, i32 5
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = zext i8 %36 to i32
  %38 = and i32 %37, 2
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %49

40:                                               ; preds = %32
  %41 = load ptr, ptr %2, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.player_s, ptr %41, i32 0, i32 20
  %43 = load i32, ptr %42, align 4, !tbaa !16
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %46, label %45

45:                                               ; preds = %40
  store i32 1, ptr @acceleratestage, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %45, %40
  %47 = load ptr, ptr %2, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.player_s, ptr %47, i32 0, i32 20
  store i32 1, ptr %48, align 4, !tbaa !16
  br label %52

49:                                               ; preds = %32
  %50 = load ptr, ptr %2, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.player_s, ptr %50, i32 0, i32 20
  store i32 0, ptr %51, align 4, !tbaa !16
  br label %52

52:                                               ; preds = %49, %46
  br label %53

53:                                               ; preds = %52, %6
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %1, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %1, align 4, !tbaa !5
  %57 = load ptr, ptr %2, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.player_s, ptr %57, i32 1
  store ptr %58, ptr %2, align 8, !tbaa !9
  br label %3, !llvm.loop !17

59:                                               ; preds = %3
  call void @llvm.lifetime.end.p0(i64 8, 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !7, i64 19}
!12 = !{!"player_s", !10, i64 0, !6, i64 8, !13, i64 12, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !7, i64 48, !7, i64 72, !6, i64 96, !7, i64 100, !6, i64 116, !6, i64 120, !7, i64 124, !7, i64 160, !7, i64 176, !6, i64 192, !6, i64 196, !6, i64 200, !6, i64 204, !6, i64 208, !6, i64 212, !6, i64 216, !10, i64 224, !6, i64 232, !6, i64 236, !10, i64 240, !6, i64 248, !6, i64 252, !6, i64 256, !7, i64 264, !6, i64 312}
!13 = !{!"", !7, i64 0, !7, i64 1, !14, i64 2, !14, i64 4, !7, i64 6, !7, i64 7}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !6, i64 192}
!16 = !{!12, !6, i64 196}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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"

%struct.player_s = type { ptr, i32, %struct.ticcmd_t, i32, i32, i32, i32, i32, i32, i32, [6 x i32], [6 x i32], i32, [4 x i32], i32, i32, [9 x i32], [4 x i32], [4 x i32], i32, i32, i32, i32, i32, i32, i32, ptr, i32, i32, ptr, i32, i32, i32, [2 x %struct.pspdef_t], i32 }
%struct.ticcmd_t = type { i8, i8, i16, i16, i8, i8 }
%struct.pspdef_t = type { ptr, i32, i32, i32 }

@acceleratestage = external hidden local_unnamed_addr global i32, align 4
@playeringame = external local_unnamed_addr global [4 x i32], align 16
@players = external local_unnamed_addr global [4 x %struct.player_s], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @WI_checkForAccelerate() local_unnamed_addr #0 {
  %1 = load i32, ptr @playeringame, align 16, !tbaa !5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %13, label %2

2:                                                ; preds = %0
  %3 = load i8, ptr getelementptr inbounds (i8, ptr @players, i64 19), align 1, !tbaa !9
  %4 = and i8 %3, 1
  %.not12 = icmp eq i8 %4, 0
  br i1 %.not12, label %8, label %5

5:                                                ; preds = %2
  %6 = load i32, ptr getelementptr inbounds (i8, ptr @players, i64 192), align 16, !tbaa !14
  %.not13 = icmp eq i32 %6, 0
  br i1 %.not13, label %7, label %8

7:                                                ; preds = %5
  store i32 1, ptr @acceleratestage, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %2, %5, %7
  %storemerge = phi i32 [ 1, %7 ], [ 1, %5 ], [ 0, %2 ]
  store i32 %storemerge, ptr getelementptr inbounds (i8, ptr @players, i64 192), align 16, !tbaa !14
  %9 = and i8 %3, 2
  %.not14 = icmp eq i8 %9, 0
  br i1 %.not14, label %.sink.split, label %10

10:                                               ; preds = %8
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @players, i64 196), align 4, !tbaa !15
  %.not15 = icmp eq i32 %11, 0
  br i1 %.not15, label %12, label %.sink.split

12:                                               ; preds = %10
  store i32 1, ptr @acceleratestage, align 4, !tbaa !5
  br label %.sink.split

.sink.split:                                      ; preds = %8, %10, %12
  %.sink = phi i32 [ 1, %12 ], [ 1, %10 ], [ 0, %8 ]
  store i32 %.sink, ptr getelementptr inbounds (i8, ptr @players, i64 196), align 4, !tbaa !15
  br label %13

13:                                               ; preds = %.sink.split, %0
  %14 = load i32, ptr getelementptr inbounds (i8, ptr @playeringame, i64 4), align 4, !tbaa !5
  %.not.1 = icmp eq i32 %14, 0
  br i1 %.not.1, label %26, label %15

15:                                               ; preds = %13
  %16 = load i8, ptr getelementptr inbounds (i8, ptr @players, i64 339), align 1, !tbaa !9
  %17 = and i8 %16, 1
  %.not12.1 = icmp eq i8 %17, 0
  br i1 %.not12.1, label %21, label %18

18:                                               ; preds = %15
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @players, i64 512), align 16, !tbaa !14
  %.not13.1 = icmp eq i32 %19, 0
  br i1 %.not13.1, label %20, label %21

20:                                               ; preds = %18
  store i32 1, ptr @acceleratestage, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %15, %18, %20
  %storemerge19 = phi i32 [ 1, %20 ], [ 1, %18 ], [ 0, %15 ]
  store i32 %storemerge19, ptr getelementptr inbounds (i8, ptr @players, i64 512), align 16, !tbaa !14
  %22 = and i8 %16, 2
  %.not14.1 = icmp eq i8 %22, 0
  br i1 %.not14.1, label %.sink.split22, label %23

23:                                               ; preds = %21
  %24 = load i32, ptr getelementptr inbounds (i8, ptr @players, i64 516), align 4, !tbaa !15
  %.not15.1 = icmp eq i32 %24, 0
  br i1 %.not15.1, label %25, label %.sink.split22

25:                                               ; preds = %23
  store i32 1, ptr @acceleratestage, align 4, !tbaa !5
  br label %.sink.split22

.sink.split22:                                    ; preds = %21, %23, %25
  %.sink23 = phi i32 [ 1, %25 ], [ 1, %23 ], [ 0, %21 ]
  store i32 %.sink23, ptr getelementptr inbounds (i8, ptr @players, i64 516), align 4, !tbaa !15
  br label %26

26:                                               ; preds = %.sink.split22, %13
  %27 = load i32, ptr getelementptr inbounds (i8, ptr @playeringame, i64 8), align 8, !tbaa !5
  %.not.2 = icmp eq i32 %27, 0
  br i1 %.not.2, label %39, label %28

28:                                               ; preds = %26
  %29 = load i8, ptr getelementptr inbounds (i8, ptr @players, i64 659), align 1, !tbaa !9
  %30 = and i8 %29, 1
  %.not12.2 = icmp eq i8 %30, 0
  br i1 %.not12.2, label %34, label %31

31:                                               ; preds = %28
  %32 = load i32, ptr getelementptr inbounds (i8, ptr @players, i64 832), align 16, !tbaa !14
  %.not13.2 = icmp eq i32 %32, 0
  br i1 %.not13.2, label %33, label %34

33:                                               ; preds = %31
  store i32 1, ptr @acceleratestage, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %28, %31, %33
  %storemerge20 = phi i32 [ 1, %33 ], [ 1, %31 ], [ 0, %28 ]
  store i32 %storemerge20, ptr getelementptr inbounds (i8, ptr @players, i64 832), align 16, !tbaa !14
  %35 = and i8 %29, 2
  %.not14.2 = icmp eq i8 %35, 0
  br i1 %.not14.2, label %.sink.split24, label %36

36:                                               ; preds = %34
  %37 = load i32, ptr getelementptr inbounds (i8, ptr @players, i64 836), align 4, !tbaa !15
  %.not15.2 = icmp eq i32 %37, 0
  br i1 %.not15.2, label %38, label %.sink.split24

38:                                               ; preds = %36
  store i32 1, ptr @acceleratestage, align 4, !tbaa !5
  br label %.sink.split24

.sink.split24:                                    ; preds = %34, %36, %38
  %.sink25 = phi i32 [ 1, %38 ], [ 1, %36 ], [ 0, %34 ]
  store i32 %.sink25, ptr getelementptr inbounds (i8, ptr @players, i64 836), align 4, !tbaa !15
  br label %39

39:                                               ; preds = %.sink.split24, %26
  %40 = load i32, ptr getelementptr inbounds (i8, ptr @playeringame, i64 12), align 4, !tbaa !5
  %.not.3 = icmp eq i32 %40, 0
  br i1 %.not.3, label %52, label %41

41:                                               ; preds = %39
  %42 = load i8, ptr getelementptr inbounds (i8, ptr @players, i64 979), align 1, !tbaa !9
  %43 = and i8 %42, 1
  %.not12.3 = icmp eq i8 %43, 0
  br i1 %.not12.3, label %47, label %44

44:                                               ; preds = %41
  %45 = load i32, ptr getelementptr inbounds (i8, ptr @players, i64 1152), align 16, !tbaa !14
  %.not13.3 = icmp eq i32 %45, 0
  br i1 %.not13.3, label %46, label %47

46:                                               ; preds = %44
  store i32 1, ptr @acceleratestage, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %41, %44, %46
  %storemerge21 = phi i32 [ 1, %46 ], [ 1, %44 ], [ 0, %41 ]
  store i32 %storemerge21, ptr getelementptr inbounds (i8, ptr @players, i64 1152), align 16, !tbaa !14
  %48 = and i8 %42, 2
  %.not14.3 = icmp eq i8 %48, 0
  br i1 %.not14.3, label %.sink.split26, label %49

49:                                               ; preds = %47
  %50 = load i32, ptr getelementptr inbounds (i8, ptr @players, i64 1156), align 4, !tbaa !15
  %.not15.3 = icmp eq i32 %50, 0
  br i1 %.not15.3, label %51, label %.sink.split26

51:                                               ; preds = %49
  store i32 1, ptr @acceleratestage, align 4, !tbaa !5
  br label %.sink.split26

.sink.split26:                                    ; preds = %47, %49, %51
  %.sink27 = phi i32 [ 1, %51 ], [ 1, %49 ], [ 0, %47 ]
  store i32 %.sink27, ptr getelementptr inbounds (i8, ptr @players, i64 1156), align 4, !tbaa !15
  br label %52

52:                                               ; preds = %.sink.split26, %39
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) 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"}
!9 = !{!10, !7, i64 19}
!10 = !{!"player_s", !11, i64 0, !6, i64 8, !12, i64 12, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !7, i64 48, !7, i64 72, !6, i64 96, !7, i64 100, !6, i64 116, !6, i64 120, !7, i64 124, !7, i64 160, !7, i64 176, !6, i64 192, !6, i64 196, !6, i64 200, !6, i64 204, !6, i64 208, !6, i64 212, !6, i64 216, !11, i64 224, !6, i64 232, !6, i64 236, !11, i64 240, !6, i64 248, !6, i64 252, !6, i64 256, !7, i64 264, !6, i64 312}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"", !7, i64 0, !7, i64 1, !13, i64 2, !13, i64 4, !7, i64 6, !7, i64 7}
!13 = !{!"short", !7, i64 0}
!14 = !{!10, !6, i64 192}
!15 = !{!10, !6, i64 196}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass