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

%struct.ceiling_t = type { %struct.thinker_s, i32, ptr, i32, i32, i32, i32, i32, i32, i32 }
%struct.thinker_s = type { ptr, ptr, %union.actionf_t }
%union.actionf_t = type { ptr }
%struct.sector_t = type { i32, i32, i16, i16, i16, i16, i16, i32, ptr, [4 x i32], %struct.degenmobj_t, i32, ptr, ptr, i32, ptr }
%struct.degenmobj_t = type { %struct.thinker_s, i32, i32, i32 }

@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: nounwind uwtable
define dso_local void @P_RemoveActiveCeiling(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 = %31, %1
  %5 = load i32, ptr %3, align 4, !tbaa !9
  %6 = icmp slt i32 %5, 30
  br i1 %6, label %7, label %34

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 @activeceilings, i64 0, i64 %9
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = icmp eq ptr %11, %12
  br i1 %13, label %14, label %30

14:                                               ; preds = %7
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [30 x ptr], ptr @activeceilings, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ceiling_t, ptr %18, i32 0, i32 2
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.sector_t, ptr %20, i32 0, i32 13
  store ptr null, ptr %21, align 8, !tbaa !14
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [30 x ptr], ptr @activeceilings, i64 0, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ceiling_t, ptr %25, i32 0, i32 0
  call void @P_RemoveThinker(ptr noundef %26)
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [30 x ptr], ptr @activeceilings, i64 0, i64 %28
  store ptr null, ptr %29, align 8, !tbaa !5
  br label %34

30:                                               ; preds = %7
  br label %31

31:                                               ; preds = %30
  %32 = load i32, ptr %3, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %3, align 4, !tbaa !9
  br label %4, !llvm.loop !18

34:                                               ; preds = %14, %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

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

declare void @P_RemoveThinker(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 = { "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 }

!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 = !{!12, !6, i64 32}
!12 = !{!"", !13, i64 0, !10, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64}
!13 = !{!"thinker_s", !6, i64 0, !6, i64 8, !7, i64 16}
!14 = !{!15, !6, i64 104}
!15 = !{!"", !10, i64 0, !10, i64 4, !16, i64 8, !16, i64 10, !16, i64 12, !16, i64 14, !16, i64 16, !10, i64 20, !6, i64 24, !7, i64 32, !17, i64 48, !10, i64 88, !6, i64 96, !6, i64 104, !10, i64 112, !6, i64 120}
!16 = !{!"short", !7, i64 0}
!17 = !{!"", !13, i64 0, !10, i64 24, !10, i64 28, !10, i64 32}
!18 = distinct !{!18, !19}
!19 = !{!"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: nounwind uwtable
define dso_local void @P_RemoveActiveCeiling(ptr noundef readnone %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @activeceilings, align 16, !tbaa !5
  %3 = icmp eq ptr %2, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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, %0
  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
  %.lcssa11 = 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 ]
  %.lcssa = phi ptr [ %2, %1 ], [ %5, %4 ], [ %8, %7 ], [ %11, %10 ], [ %14, %13 ], [ %17, %16 ], [ %20, %19 ], [ %23, %22 ], [ %26, %25 ], [ %29, %28 ], [ %32, %31 ], [ %35, %34 ], [ %38, %37 ], [ %41, %40 ], [ %44, %43 ], [ %47, %46 ], [ %50, %49 ], [ %53, %52 ], [ %56, %55 ], [ %59, %58 ], [ %62, %61 ], [ %65, %64 ], [ %68, %67 ], [ %71, %70 ], [ %74, %73 ], [ %77, %76 ], [ %80, %79 ], [ %83, %82 ], [ %86, %85 ], [ %89, %88 ]
  %92 = getelementptr inbounds [30 x ptr], ptr @activeceilings, i64 0, i64 %.lcssa11
  %93 = getelementptr inbounds i8, ptr %.lcssa, i64 32
  %94 = load ptr, ptr %93, align 8, !tbaa !9
  %95 = getelementptr inbounds i8, ptr %94, i64 104
  store ptr null, ptr %95, align 8, !tbaa !13
  %96 = load ptr, ptr %92, align 8, !tbaa !5
  tail call void @P_RemoveThinker(ptr noundef %96) #2
  store ptr null, ptr %92, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %88, %91
  ret void
}

declare void @P_RemoveThinker(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 = { "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, !6, i64 32}
!10 = !{!"", !11, i64 0, !12, i64 24, !6, i64 32, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64}
!11 = !{!"thinker_s", !6, i64 0, !6, i64 8, !7, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 104}
!14 = !{!"", !12, i64 0, !12, i64 4, !15, i64 8, !15, i64 10, !15, i64 12, !15, i64 14, !15, i64 16, !12, i64 20, !6, i64 24, !7, i64 32, !16, i64 48, !12, i64 88, !6, i64 96, !6, i64 104, !12, i64 112, !6, i64 120}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !11, i64 0, !12, i64 24, !12, i64 28, !12, i64 32}


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