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

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

@activeceilings = external dso_local global [30 x ptr], 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 @P_AddActiveCeiling(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %5

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

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

14:                                               ; preds = %8
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [30 x ptr], ptr @activeceilings, i64 0, i64 %17
  store ptr %15, ptr %18, align 8, !tbaa !5
  store i32 1, ptr %4, align 4
  br label %24

19:                                               ; preds = %8
  br label %20

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

23:                                               ; preds = %5
  store i32 0, ptr %4, align 4
  br label %24

24:                                               ; preds = %23, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  %25 = load i32, ptr %4, align 4
  switch i32 %25, label %27 [
    i32 0, label %26
    i32 1, label %26
  ]

26:                                               ; preds = %24, %24
  ret void

27:                                               ; preds = %24
  unreachable
}

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 = !{!"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"

@activeceilings = external dso_local local_unnamed_addr global [30 x ptr], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @P_AddActiveCeiling(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @activeceilings, align 16, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %91, label %4

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

91:                                               ; 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 ]
  %92 = getelementptr inbounds [30 x ptr], ptr @activeceilings, i64 0, i64 %.lcssa
  store ptr %0, ptr %92, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %88, %91
  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 = !{!"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,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass