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

@leveltime = external global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @T_MoveCeiling(ptr noundef %0) #0 {
  %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
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.ceiling_t, ptr %4, i32 0, i32 7
  %6 = load i32, ptr %5, align 8, !tbaa !9
  switch i32 %6, label %120 [
    i32 0, label %120
    i32 1, label %7
    i32 -1, label %54
  ]

7:                                                ; preds = %1
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.ceiling_t, ptr %8, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ceiling_t, ptr %11, i32 0, i32 5
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ceiling_t, ptr %14, i32 0, i32 4
  %16 = load i32, ptr %15, align 4, !tbaa !15
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ceiling_t, ptr %17, i32 0, i32 7
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = call i32 @T_MovePlane(ptr noundef %10, i32 noundef %13, i32 noundef %16, i32 noundef 0, i32 noundef 1, i32 noundef %19)
  store i32 %20, ptr %3, align 4, !tbaa !16
  %21 = load i32, ptr @leveltime, align 4, !tbaa !16
  %22 = and i32 %21, 7
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %34, label %24

24:                                               ; preds = %7
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ceiling_t, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 8, !tbaa !17
  switch i32 %27, label %28 [
    i32 5, label %33
  ]

28:                                               ; preds = %24
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ceiling_t, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = getelementptr inbounds %struct.sector_t, ptr %31, i32 0, i32 10
  call void @S_StartSound(ptr noundef %32, i32 noundef 22)
  br label %33

33:                                               ; preds = %28, %24
  br label %34

34:                                               ; preds = %33, %7
  %35 = load i32, ptr %3, align 4, !tbaa !16
  %36 = icmp eq i32 %35, 2
  br i1 %36, label %37, label %53

37:                                               ; preds = %34
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ceiling_t, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 8, !tbaa !17
  switch i32 %40, label %51 [
    i32 1, label %41
    i32 5, label %43
    i32 4, label %48
    i32 3, label %48
  ]

41:                                               ; preds = %37
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  call void @P_RemoveActiveCeiling(ptr noundef %42)
  br label %52

43:                                               ; preds = %37
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ceiling_t, ptr %44, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !13
  %47 = getelementptr inbounds %struct.sector_t, ptr %46, i32 0, i32 10
  call void @S_StartSound(ptr noundef %47, i32 noundef 19)
  br label %48

48:                                               ; preds = %43, %37, %37
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ceiling_t, ptr %49, i32 0, i32 7
  store i32 -1, ptr %50, align 8, !tbaa !9
  br label %52

51:                                               ; preds = %37
  br label %52

52:                                               ; preds = %51, %48, %41
  br label %53

53:                                               ; preds = %52, %34
  br label %120

54:                                               ; preds = %1
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ceiling_t, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !13
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ceiling_t, ptr %58, i32 0, i32 5
  %60 = load i32, ptr %59, align 8, !tbaa !14
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.ceiling_t, ptr %61, i32 0, i32 3
  %63 = load i32, ptr %62, align 8, !tbaa !18
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.ceiling_t, ptr %64, i32 0, i32 6
  %66 = load i32, ptr %65, align 4, !tbaa !19
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.ceiling_t, ptr %67, i32 0, i32 7
  %69 = load i32, ptr %68, align 8, !tbaa !9
  %70 = call i32 @T_MovePlane(ptr noundef %57, i32 noundef %60, i32 noundef %63, i32 noundef %66, i32 noundef 1, i32 noundef %69)
  store i32 %70, ptr %3, align 4, !tbaa !16
  %71 = load i32, ptr @leveltime, align 4, !tbaa !16
  %72 = and i32 %71, 7
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %84, label %74

74:                                               ; preds = %54
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.ceiling_t, ptr %75, i32 0, i32 1
  %77 = load i32, ptr %76, align 8, !tbaa !17
  switch i32 %77, label %78 [
    i32 5, label %83
  ]

78:                                               ; preds = %74
  %79 = load ptr, ptr %2, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.ceiling_t, ptr %79, i32 0, i32 2
  %81 = load ptr, ptr %80, align 8, !tbaa !13
  %82 = getelementptr inbounds %struct.sector_t, ptr %81, i32 0, i32 10
  call void @S_StartSound(ptr noundef %82, i32 noundef 22)
  br label %83

83:                                               ; preds = %78, %74
  br label %84

84:                                               ; preds = %83, %54
  %85 = load i32, ptr %3, align 4, !tbaa !16
  %86 = icmp eq i32 %85, 2
  br i1 %86, label %87, label %106

87:                                               ; preds = %84
  %88 = load ptr, ptr %2, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.ceiling_t, ptr %88, i32 0, i32 1
  %90 = load i32, ptr %89, align 8, !tbaa !17
  switch i32 %90, label %104 [
    i32 5, label %91
    i32 3, label %96
    i32 4, label %99
    i32 2, label %102
    i32 0, label %102
  ]

91:                                               ; preds = %87
  %92 = load ptr, ptr %2, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.ceiling_t, ptr %92, i32 0, i32 2
  %94 = load ptr, ptr %93, align 8, !tbaa !13
  %95 = getelementptr inbounds %struct.sector_t, ptr %94, i32 0, i32 10
  call void @S_StartSound(ptr noundef %95, i32 noundef 19)
  br label %96

96:                                               ; preds = %91, %87
  %97 = load ptr, ptr %2, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.ceiling_t, ptr %97, i32 0, i32 5
  store i32 65536, ptr %98, align 8, !tbaa !14
  br label %99

99:                                               ; preds = %96, %87
  %100 = load ptr, ptr %2, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.ceiling_t, ptr %100, i32 0, i32 7
  store i32 1, ptr %101, align 8, !tbaa !9
  br label %105

102:                                              ; preds = %87, %87
  %103 = load ptr, ptr %2, align 8, !tbaa !5
  call void @P_RemoveActiveCeiling(ptr noundef %103)
  br label %105

104:                                              ; preds = %87
  br label %105

105:                                              ; preds = %104, %102, %99
  br label %119

106:                                              ; preds = %84
  %107 = load i32, ptr %3, align 4, !tbaa !16
  %108 = icmp eq i32 %107, 1
  br i1 %108, label %109, label %118

109:                                              ; preds = %106
  %110 = load ptr, ptr %2, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.ceiling_t, ptr %110, i32 0, i32 1
  %112 = load i32, ptr %111, align 8, !tbaa !17
  switch i32 %112, label %116 [
    i32 5, label %113
    i32 3, label %113
    i32 2, label %113
  ]

113:                                              ; preds = %109, %109, %109
  %114 = load ptr, ptr %2, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.ceiling_t, ptr %114, i32 0, i32 5
  store i32 8192, ptr %115, align 8, !tbaa !14
  br label %117

116:                                              ; preds = %109
  br label %117

117:                                              ; preds = %116, %113
  br label %118

118:                                              ; preds = %117, %106
  br label %119

119:                                              ; preds = %118, %105
  br label %120

120:                                              ; preds = %119, %53, %1, %1
  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.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @T_MovePlane(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

declare void @S_StartSound(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @P_RemoveActiveCeiling(ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !12, i64 56}
!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 = !{!10, !6, i64 32}
!14 = !{!10, !12, i64 48}
!15 = !{!10, !12, i64 44}
!16 = !{!12, !12, i64 0}
!17 = !{!10, !12, i64 24}
!18 = !{!10, !12, i64 40}
!19 = !{!10, !12, i64 52}


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

@leveltime = external local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @T_MoveCeiling(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 56
  %3 = load i32, ptr %2, align 8, !tbaa !5
  switch i32 %3, label %62 [
    i32 -1, label %30
    i32 1, label %4
  ]

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = load i32, ptr %7, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %0, i64 44
  %10 = load i32, ptr %9, align 4, !tbaa !14
  %11 = tail call i32 @T_MovePlane(ptr noundef %6, i32 noundef %8, i32 noundef %10, i32 noundef 0, i32 noundef 1, i32 noundef 1) #2
  %12 = load i32, ptr @leveltime, align 4, !tbaa !15
  %13 = and i32 %12, 7
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %14, label %20

14:                                               ; preds = %4
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  %16 = load i32, ptr %15, align 8, !tbaa !16
  %cond = icmp eq i32 %16, 5
  br i1 %cond, label %20, label %17

17:                                               ; preds = %14
  %18 = load ptr, ptr %5, align 8, !tbaa !12
  %19 = getelementptr inbounds i8, ptr %18, i64 48
  tail call void @S_StartSound(ptr noundef nonnull %19, i32 noundef 22) #2
  br label %20

20:                                               ; preds = %17, %14, %4
  %21 = icmp eq i32 %11, 2
  br i1 %21, label %22, label %62

22:                                               ; preds = %20
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  %24 = load i32, ptr %23, align 8, !tbaa !16
  switch i32 %24, label %62 [
    i32 1, label %25
    i32 5, label %26
    i32 4, label %29
    i32 3, label %29
  ]

25:                                               ; preds = %22
  tail call void @P_RemoveActiveCeiling(ptr noundef nonnull %0)
  br label %62

26:                                               ; preds = %22
  %27 = load ptr, ptr %5, align 8, !tbaa !12
  %28 = getelementptr inbounds i8, ptr %27, i64 48
  tail call void @S_StartSound(ptr noundef nonnull %28, i32 noundef 19) #2
  br label %29

29:                                               ; preds = %26, %22, %22
  store i32 -1, ptr %2, align 8, !tbaa !5
  br label %62

30:                                               ; preds = %1
  %31 = getelementptr inbounds i8, ptr %0, i64 32
  %32 = load ptr, ptr %31, align 8, !tbaa !12
  %33 = getelementptr inbounds i8, ptr %0, i64 48
  %34 = load i32, ptr %33, align 8, !tbaa !13
  %35 = getelementptr inbounds i8, ptr %0, i64 40
  %36 = load i32, ptr %35, align 8, !tbaa !17
  %37 = getelementptr inbounds i8, ptr %0, i64 52
  %38 = load i32, ptr %37, align 4, !tbaa !18
  %39 = tail call i32 @T_MovePlane(ptr noundef %32, i32 noundef %34, i32 noundef %36, i32 noundef %38, i32 noundef 1, i32 noundef -1) #2
  %40 = load i32, ptr @leveltime, align 4, !tbaa !15
  %41 = and i32 %40, 7
  %.not29 = icmp eq i32 %41, 0
  br i1 %.not29, label %42, label %48

42:                                               ; preds = %30
  %43 = getelementptr inbounds i8, ptr %0, i64 24
  %44 = load i32, ptr %43, align 8, !tbaa !16
  %cond1 = icmp eq i32 %44, 5
  br i1 %cond1, label %48, label %45

45:                                               ; preds = %42
  %46 = load ptr, ptr %31, align 8, !tbaa !12
  %47 = getelementptr inbounds i8, ptr %46, i64 48
  tail call void @S_StartSound(ptr noundef nonnull %47, i32 noundef 22) #2
  br label %48

48:                                               ; preds = %45, %42, %30
  switch i32 %39, label %62 [
    i32 2, label %49
    i32 1, label %58
  ]

49:                                               ; preds = %48
  %50 = getelementptr inbounds i8, ptr %0, i64 24
  %51 = load i32, ptr %50, align 8, !tbaa !16
  switch i32 %51, label %62 [
    i32 5, label %52
    i32 3, label %55
    i32 4, label %56
    i32 2, label %57
    i32 0, label %57
  ]

52:                                               ; preds = %49
  %53 = load ptr, ptr %31, align 8, !tbaa !12
  %54 = getelementptr inbounds i8, ptr %53, i64 48
  tail call void @S_StartSound(ptr noundef nonnull %54, i32 noundef 19) #2
  br label %55

55:                                               ; preds = %52, %49
  store i32 65536, ptr %33, align 8, !tbaa !13
  br label %56

56:                                               ; preds = %55, %49
  store i32 1, ptr %2, align 8, !tbaa !5
  br label %62

57:                                               ; preds = %49, %49
  tail call void @P_RemoveActiveCeiling(ptr noundef nonnull %0)
  br label %62

58:                                               ; preds = %48
  %59 = getelementptr inbounds i8, ptr %0, i64 24
  %60 = load i32, ptr %59, align 8, !tbaa !16
  switch i32 %60, label %62 [
    i32 5, label %61
    i32 3, label %61
    i32 2, label %61
  ]

61:                                               ; preds = %58, %58, %58
  store i32 8192, ptr %33, align 8, !tbaa !13
  br label %62

62:                                               ; preds = %48, %49, %57, %56, %61, %58, %20, %22, %29, %25, %1
  ret void
}

declare i32 @T_MovePlane(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @S_StartSound(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @P_RemoveActiveCeiling(ptr noundef) local_unnamed_addr #0

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, !11, i64 56}
!6 = !{!"", !7, i64 0, !11, i64 24, !8, i64 32, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64}
!7 = !{!"thinker_s", !8, i64 0, !8, i64 8, !9, i64 16}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!6, !8, i64 32}
!13 = !{!6, !11, i64 48}
!14 = !{!6, !11, i64 44}
!15 = !{!11, !11, i64 0}
!16 = !{!6, !11, i64 24}
!17 = !{!6, !11, i64 40}
!18 = !{!6, !11, i64 52}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass