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

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

@activeplats = external dso_local global [30 x ptr], align 16
@.str = external hidden unnamed_addr constant [32 x i8], align 1

; 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 @P_AddActivePlat(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %4

4:                                                ; preds = %19, %1
  %5 = load i32, ptr %3, align 4, !tbaa !9
  %6 = icmp slt i32 %5, 30
  br i1 %6, label %7, label %22

7:                                                ; preds = %4
  %8 = load i32, ptr %3, align 4, !tbaa !9
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [30 x ptr], ptr @activeplats, i64 0, i64 %9
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %18

13:                                               ; preds = %7
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [30 x ptr], ptr @activeplats, i64 0, i64 %16
  store ptr %14, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void

18:                                               ; preds = %7
  br label %19

19:                                               ; preds = %18
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %3, align 4, !tbaa !9
  br label %4, !llvm.loop !11

22:                                               ; preds = %4
  call void (ptr, ...) @I_Error(ptr noundef @.str) #4
  unreachable
}

; Function Attrs: noreturn
declare void @I_Error(ptr noundef, ...) #2

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 = { noreturn "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 #3 = { nounwind }
attributes #4 = { noreturn }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@activeplats = external dso_local local_unnamed_addr global [30 x ptr], align 16
@.str = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @P_AddActivePlat(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @activeplats, align 16, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %92, label %4

4:                                                ; preds = %1
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 8), align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %92, label %7

7:                                                ; preds = %4
  %8 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 16), align 16, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %92, label %10

10:                                               ; preds = %7
  %11 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 24), align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %92, label %13

13:                                               ; preds = %10
  %14 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 32), align 16, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %92, label %16

16:                                               ; preds = %13
  %17 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 40), align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %92, label %19

19:                                               ; preds = %16
  %20 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 48), align 16, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %92, label %22

22:                                               ; preds = %19
  %23 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 56), align 8, !tbaa !5
  %24 = icmp eq ptr %23, null
  br i1 %24, label %92, label %25

25:                                               ; preds = %22
  %26 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 64), align 16, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %92, label %28

28:                                               ; preds = %25
  %29 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 72), align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %92, label %31

31:                                               ; preds = %28
  %32 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 80), align 16, !tbaa !5
  %33 = icmp eq ptr %32, null
  br i1 %33, label %92, label %34

34:                                               ; preds = %31
  %35 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 88), align 8, !tbaa !5
  %36 = icmp eq ptr %35, null
  br i1 %36, label %92, label %37

37:                                               ; preds = %34
  %38 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 96), align 16, !tbaa !5
  %39 = icmp eq ptr %38, null
  br i1 %39, label %92, label %40

40:                                               ; preds = %37
  %41 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 104), align 8, !tbaa !5
  %42 = icmp eq ptr %41, null
  br i1 %42, label %92, label %43

43:                                               ; preds = %40
  %44 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 112), align 16, !tbaa !5
  %45 = icmp eq ptr %44, null
  br i1 %45, label %92, label %46

46:                                               ; preds = %43
  %47 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 120), align 8, !tbaa !5
  %48 = icmp eq ptr %47, null
  br i1 %48, label %92, label %49

49:                                               ; preds = %46
  %50 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 128), align 16, !tbaa !5
  %51 = icmp eq ptr %50, null
  br i1 %51, label %92, label %52

52:                                               ; preds = %49
  %53 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 136), align 8, !tbaa !5
  %54 = icmp eq ptr %53, null
  br i1 %54, label %92, label %55

55:                                               ; preds = %52
  %56 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 144), align 16, !tbaa !5
  %57 = icmp eq ptr %56, null
  br i1 %57, label %92, label %58

58:                                               ; preds = %55
  %59 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 152), align 8, !tbaa !5
  %60 = icmp eq ptr %59, null
  br i1 %60, label %92, label %61

61:                                               ; preds = %58
  %62 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 160), align 16, !tbaa !5
  %63 = icmp eq ptr %62, null
  br i1 %63, label %92, label %64

64:                                               ; preds = %61
  %65 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 168), align 8, !tbaa !5
  %66 = icmp eq ptr %65, null
  br i1 %66, label %92, label %67

67:                                               ; preds = %64
  %68 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 176), align 16, !tbaa !5
  %69 = icmp eq ptr %68, null
  br i1 %69, label %92, label %70

70:                                               ; preds = %67
  %71 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 184), align 8, !tbaa !5
  %72 = icmp eq ptr %71, null
  br i1 %72, label %92, label %73

73:                                               ; preds = %70
  %74 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 192), align 16, !tbaa !5
  %75 = icmp eq ptr %74, null
  br i1 %75, label %92, label %76

76:                                               ; preds = %73
  %77 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 200), align 8, !tbaa !5
  %78 = icmp eq ptr %77, null
  br i1 %78, label %92, label %79

79:                                               ; preds = %76
  %80 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 208), align 16, !tbaa !5
  %81 = icmp eq ptr %80, null
  br i1 %81, label %92, label %82

82:                                               ; preds = %79
  %83 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 216), align 8, !tbaa !5
  %84 = icmp eq ptr %83, null
  br i1 %84, label %92, label %85

85:                                               ; preds = %82
  %86 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 224), align 16, !tbaa !5
  %87 = icmp eq ptr %86, null
  br i1 %87, label %92, label %88

88:                                               ; preds = %85
  %89 = load ptr, ptr getelementptr inbounds (i8, ptr @activeplats, i64 232), align 8, !tbaa !5
  %90 = icmp eq ptr %89, null
  br i1 %90, label %92, label %91

91:                                               ; preds = %88
  tail call void (ptr, ...) @I_Error(ptr noundef nonnull @.str) #2
  unreachable

92:                                               ; preds = %88, %85, %82, %79, %76, %73, %70, %67, %64, %61, %58, %55, %52, %49, %46, %43, %40, %37, %34, %31, %28, %25, %22, %19, %16, %13, %10, %7, %4, %1
  %.lcssa = phi i64 [ 0, %1 ], [ 1, %4 ], [ 2, %7 ], [ 3, %10 ], [ 4, %13 ], [ 5, %16 ], [ 6, %19 ], [ 7, %22 ], [ 8, %25 ], [ 9, %28 ], [ 10, %31 ], [ 11, %34 ], [ 12, %37 ], [ 13, %40 ], [ 14, %43 ], [ 15, %46 ], [ 16, %49 ], [ 17, %52 ], [ 18, %55 ], [ 19, %58 ], [ 20, %61 ], [ 21, %64 ], [ 22, %67 ], [ 23, %70 ], [ 24, %73 ], [ 25, %76 ], [ 26, %79 ], [ 27, %82 ], [ 28, %85 ], [ 29, %88 ]
  %93 = getelementptr inbounds [30 x ptr], ptr @activeplats, i64 0, i64 %.lcssa
  store ptr %0, ptr %93, align 8, !tbaa !5
  ret void
}

; Function Attrs: noreturn
declare void @I_Error(ptr noundef, ...) local_unnamed_addr #1

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" }
attributes #1 = { noreturn "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 = { noreturn 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass