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

; 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.castinfo_t = type { ptr, i32 }
%struct.state_t = type { i32, i64, i64, %union.actionf_t, i32, i64, i64 }
%union.actionf_t = type { ptr }
%struct.mobjinfo_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

@castorder = external dso_local global [18 x %struct.castinfo_t], align 16
@castnum = external dso_local global i32, align 4
@states = external global [967 x %struct.state_t], align 16
@mobjinfo = external global [137 x %struct.mobjinfo_t], align 16
@caststate = external dso_local global ptr, align 8
@casttics = external dso_local global i32, align 4
@castdeath = external dso_local global i32, align 4
@castframes = external dso_local global i32, align 4
@castonmelee = external dso_local global i32, align 4
@castattacking = external dso_local global i32, align 4

; 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 @F_CastTicker() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %4 = load i32, ptr @casttics, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @casttics, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %0
  store i32 1, ptr %3, align 4
  br label %206

8:                                                ; preds = %0
  %9 = load ptr, ptr @caststate, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.state_t, ptr %9, i32 0, i32 2
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = icmp eq i64 %11, -1
  br i1 %12, label %18, label %13

13:                                               ; preds = %8
  %14 = load ptr, ptr @caststate, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.state_t, ptr %14, i32 0, i32 4
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %61

18:                                               ; preds = %13, %8
  %19 = load i32, ptr @castnum, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @castnum, align 4, !tbaa !5
  store i32 0, ptr @castdeath, align 4, !tbaa !5
  %21 = load i32, ptr @castnum, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.castinfo_t, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 16, !tbaa !15
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %18
  store i32 0, ptr @castnum, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %27, %18
  %29 = load i32, ptr @castnum, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.castinfo_t, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !17
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.mobjinfo_t, ptr %35, i32 0, i32 4
  %37 = load i32, ptr %36, align 4, !tbaa !18
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %49

39:                                               ; preds = %28
  %40 = load i32, ptr @castnum, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.castinfo_t, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 8, !tbaa !17
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %45
  %47 = getelementptr inbounds %struct.mobjinfo_t, ptr %46, i32 0, i32 4
  %48 = load i32, ptr %47, align 4, !tbaa !18
  call void @S_StartSound(ptr noundef null, i32 noundef %48)
  br label %49

49:                                               ; preds = %39, %28
  %50 = load i32, ptr @castnum, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.castinfo_t, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 8, !tbaa !17
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %55
  %57 = getelementptr inbounds %struct.mobjinfo_t, ptr %56, i32 0, i32 3
  %58 = load i32, ptr %57, align 4, !tbaa !20
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [967 x %struct.state_t], ptr @states, i64 0, i64 %59
  store ptr %60, ptr @caststate, align 8, !tbaa !9
  store i32 0, ptr @castframes, align 4, !tbaa !5
  br label %99

61:                                               ; preds = %13
  %62 = load ptr, ptr @caststate, align 8, !tbaa !9
  %63 = icmp eq ptr %62, getelementptr inbounds ([967 x %struct.state_t], ptr @states, i64 0, i64 154)
  br i1 %63, label %64, label %65

64:                                               ; preds = %61
  br label %184

65:                                               ; preds = %61
  %66 = load ptr, ptr @caststate, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.state_t, ptr %66, i32 0, i32 4
  %68 = load i32, ptr %67, align 8, !tbaa !14
  store i32 %68, ptr %1, align 4, !tbaa !5
  %69 = load i32, ptr %1, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [967 x %struct.state_t], ptr @states, i64 0, i64 %70
  store ptr %71, ptr @caststate, align 8, !tbaa !9
  %72 = load i32, ptr @castframes, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr @castframes, align 4, !tbaa !5
  %74 = load i32, ptr %1, align 4, !tbaa !5
  switch i32 %74, label %92 [
    i32 154, label %75
    i32 185, label %76
    i32 218, label %77
    i32 256, label %78
    i32 336, label %79
    i32 338, label %80
    i32 340, label %81
    i32 383, label %82
    i32 380, label %82
    i32 377, label %82
    i32 417, label %83
    i32 418, label %83
    i32 419, label %83
    i32 454, label %84
    i32 486, label %85
    i32 538, label %86
    i32 567, label %86
    i32 505, label %86
    i32 590, label %87
    i32 616, label %88
    i32 617, label %88
    i32 648, label %89
    i32 685, label %90
    i32 687, label %90
    i32 689, label %90
    i32 710, label %91
  ]

75:                                               ; preds = %65
  store i32 4, ptr %2, align 4, !tbaa !5
  br label %93

76:                                               ; preds = %65
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %93

77:                                               ; preds = %65
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %93

78:                                               ; preds = %65
  store i32 54, ptr %2, align 4, !tbaa !5
  br label %93

79:                                               ; preds = %65
  store i32 56, ptr %2, align 4, !tbaa !5
  br label %93

80:                                               ; preds = %65
  store i32 53, ptr %2, align 4, !tbaa !5
  br label %93

81:                                               ; preds = %65
  store i32 107, ptr %2, align 4, !tbaa !5
  br label %93

82:                                               ; preds = %65, %65, %65
  store i32 16, ptr %2, align 4, !tbaa !5
  br label %93

83:                                               ; preds = %65, %65, %65
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %93

84:                                               ; preds = %65
  store i32 55, ptr %2, align 4, !tbaa !5
  br label %93

85:                                               ; preds = %65
  store i32 52, ptr %2, align 4, !tbaa !5
  br label %93

86:                                               ; preds = %65, %65, %65
  store i32 16, ptr %2, align 4, !tbaa !5
  br label %93

87:                                               ; preds = %65
  store i32 51, ptr %2, align 4, !tbaa !5
  br label %93

88:                                               ; preds = %65, %65
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %93

89:                                               ; preds = %65
  store i32 8, ptr %2, align 4, !tbaa !5
  br label %93

90:                                               ; preds = %65, %65, %65
  store i32 14, ptr %2, align 4, !tbaa !5
  br label %93

91:                                               ; preds = %65
  store i32 51, ptr %2, align 4, !tbaa !5
  br label %93

92:                                               ; preds = %65
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %93

93:                                               ; preds = %92, %91, %90, %89, %88, %87, %86, %85, %84, %83, %82, %81, %80, %79, %78, %77, %76, %75
  %94 = load i32, ptr %2, align 4, !tbaa !5
  %95 = icmp ne i32 %94, 0
  br i1 %95, label %96, label %98

96:                                               ; preds = %93
  %97 = load i32, ptr %2, align 4, !tbaa !5
  call void @S_StartSound(ptr noundef null, i32 noundef %97)
  br label %98

98:                                               ; preds = %96, %93
  br label %99

99:                                               ; preds = %98, %49
  %100 = load i32, ptr @castframes, align 4, !tbaa !5
  %101 = icmp eq i32 %100, 12
  br i1 %101, label %102, label %163

102:                                              ; preds = %99
  store i32 1, ptr @castattacking, align 4, !tbaa !5
  %103 = load i32, ptr @castonmelee, align 4, !tbaa !5
  %104 = icmp ne i32 %103, 0
  br i1 %104, label %105, label %117

105:                                              ; preds = %102
  %106 = load i32, ptr @castnum, align 4, !tbaa !5
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %107
  %109 = getelementptr inbounds %struct.castinfo_t, ptr %108, i32 0, i32 1
  %110 = load i32, ptr %109, align 8, !tbaa !17
  %111 = zext i32 %110 to i64
  %112 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %111
  %113 = getelementptr inbounds %struct.mobjinfo_t, ptr %112, i32 0, i32 10
  %114 = load i32, ptr %113, align 4, !tbaa !21
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds [967 x %struct.state_t], ptr @states, i64 0, i64 %115
  store ptr %116, ptr @caststate, align 8, !tbaa !9
  br label %129

117:                                              ; preds = %102
  %118 = load i32, ptr @castnum, align 4, !tbaa !5
  %119 = sext i32 %118 to i64
  %120 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %119
  %121 = getelementptr inbounds %struct.castinfo_t, ptr %120, i32 0, i32 1
  %122 = load i32, ptr %121, align 8, !tbaa !17
  %123 = zext i32 %122 to i64
  %124 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %123
  %125 = getelementptr inbounds %struct.mobjinfo_t, ptr %124, i32 0, i32 11
  %126 = load i32, ptr %125, align 4, !tbaa !22
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds [967 x %struct.state_t], ptr @states, i64 0, i64 %127
  store ptr %128, ptr @caststate, align 8, !tbaa !9
  br label %129

129:                                              ; preds = %117, %105
  %130 = load i32, ptr @castonmelee, align 4, !tbaa !5
  %131 = xor i32 %130, 1
  store i32 %131, ptr @castonmelee, align 4, !tbaa !5
  %132 = load ptr, ptr @caststate, align 8, !tbaa !9
  %133 = icmp eq ptr %132, @states
  br i1 %133, label %134, label %162

134:                                              ; preds = %129
  %135 = load i32, ptr @castonmelee, align 4, !tbaa !5
  %136 = icmp ne i32 %135, 0
  br i1 %136, label %137, label %149

137:                                              ; preds = %134
  %138 = load i32, ptr @castnum, align 4, !tbaa !5
  %139 = sext i32 %138 to i64
  %140 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %139
  %141 = getelementptr inbounds %struct.castinfo_t, ptr %140, i32 0, i32 1
  %142 = load i32, ptr %141, align 8, !tbaa !17
  %143 = zext i32 %142 to i64
  %144 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %143
  %145 = getelementptr inbounds %struct.mobjinfo_t, ptr %144, i32 0, i32 10
  %146 = load i32, ptr %145, align 4, !tbaa !21
  %147 = sext i32 %146 to i64
  %148 = getelementptr inbounds [967 x %struct.state_t], ptr @states, i64 0, i64 %147
  store ptr %148, ptr @caststate, align 8, !tbaa !9
  br label %161

149:                                              ; preds = %134
  %150 = load i32, ptr @castnum, align 4, !tbaa !5
  %151 = sext i32 %150 to i64
  %152 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %151
  %153 = getelementptr inbounds %struct.castinfo_t, ptr %152, i32 0, i32 1
  %154 = load i32, ptr %153, align 8, !tbaa !17
  %155 = zext i32 %154 to i64
  %156 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %155
  %157 = getelementptr inbounds %struct.mobjinfo_t, ptr %156, i32 0, i32 11
  %158 = load i32, ptr %157, align 4, !tbaa !22
  %159 = sext i32 %158 to i64
  %160 = getelementptr inbounds [967 x %struct.state_t], ptr @states, i64 0, i64 %159
  store ptr %160, ptr @caststate, align 8, !tbaa !9
  br label %161

161:                                              ; preds = %149, %137
  br label %162

162:                                              ; preds = %161, %129
  br label %163

163:                                              ; preds = %162, %99
  %164 = load i32, ptr @castattacking, align 4, !tbaa !5
  %165 = icmp ne i32 %164, 0
  br i1 %165, label %166, label %197

166:                                              ; preds = %163
  %167 = load i32, ptr @castframes, align 4, !tbaa !5
  %168 = icmp eq i32 %167, 24
  br i1 %168, label %183, label %169

169:                                              ; preds = %166
  %170 = load ptr, ptr @caststate, align 8, !tbaa !9
  %171 = load i32, ptr @castnum, align 4, !tbaa !5
  %172 = sext i32 %171 to i64
  %173 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %172
  %174 = getelementptr inbounds %struct.castinfo_t, ptr %173, i32 0, i32 1
  %175 = load i32, ptr %174, align 8, !tbaa !17
  %176 = zext i32 %175 to i64
  %177 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %176
  %178 = getelementptr inbounds %struct.mobjinfo_t, ptr %177, i32 0, i32 3
  %179 = load i32, ptr %178, align 4, !tbaa !20
  %180 = sext i32 %179 to i64
  %181 = getelementptr inbounds [967 x %struct.state_t], ptr @states, i64 0, i64 %180
  %182 = icmp eq ptr %170, %181
  br i1 %182, label %183, label %196

183:                                              ; preds = %169, %166
  br label %184

184:                                              ; preds = %183, %64
  store i32 0, ptr @castattacking, align 4, !tbaa !5
  store i32 0, ptr @castframes, align 4, !tbaa !5
  %185 = load i32, ptr @castnum, align 4, !tbaa !5
  %186 = sext i32 %185 to i64
  %187 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %186
  %188 = getelementptr inbounds %struct.castinfo_t, ptr %187, i32 0, i32 1
  %189 = load i32, ptr %188, align 8, !tbaa !17
  %190 = zext i32 %189 to i64
  %191 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %190
  %192 = getelementptr inbounds %struct.mobjinfo_t, ptr %191, i32 0, i32 3
  %193 = load i32, ptr %192, align 4, !tbaa !20
  %194 = sext i32 %193 to i64
  %195 = getelementptr inbounds [967 x %struct.state_t], ptr @states, i64 0, i64 %194
  store ptr %195, ptr @caststate, align 8, !tbaa !9
  br label %196

196:                                              ; preds = %184, %169
  br label %197

197:                                              ; preds = %196, %163
  %198 = load ptr, ptr @caststate, align 8, !tbaa !9
  %199 = getelementptr inbounds %struct.state_t, ptr %198, i32 0, i32 2
  %200 = load i64, ptr %199, align 8, !tbaa !11
  %201 = trunc i64 %200 to i32
  store i32 %201, ptr @casttics, align 4, !tbaa !5
  %202 = load i32, ptr @casttics, align 4, !tbaa !5
  %203 = icmp eq i32 %202, -1
  br i1 %203, label %204, label %205

204:                                              ; preds = %197
  store i32 15, ptr @casttics, align 4, !tbaa !5
  br label %205

205:                                              ; preds = %204, %197
  store i32 0, ptr %3, align 4
  br label %206

206:                                              ; preds = %205, %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  %207 = load i32, ptr %3, align 4
  switch i32 %207, label %209 [
    i32 0, label %208
    i32 1, label %208
  ]

208:                                              ; preds = %206, %206
  ret void

209:                                              ; preds = %206
  unreachable
}

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

declare void @S_StartSound(ptr noundef, i32 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 = !{!"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, !13, i64 16}
!12 = !{!"", !6, i64 0, !13, i64 8, !13, i64 16, !7, i64 24, !6, i64 32, !13, i64 40, !13, i64 48}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 32}
!15 = !{!16, !10, i64 0}
!16 = !{!"", !10, i64 0, !6, i64 8}
!17 = !{!16, !6, i64 8}
!18 = !{!19, !6, i64 16}
!19 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !6, i64 48, !6, i64 52, !6, i64 56, !6, i64 60, !6, i64 64, !6, i64 68, !6, i64 72, !6, i64 76, !6, i64 80, !6, i64 84, !6, i64 88}
!20 = !{!19, !6, i64 12}
!21 = !{!19, !6, i64 40}
!22 = !{!19, !6, i64 44}


; 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.castinfo_t = type { ptr, i32 }
%struct.state_t = type { i32, i64, i64, %union.actionf_t, i32, i64, i64 }
%union.actionf_t = type { ptr }
%struct.mobjinfo_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

@castorder = external dso_local local_unnamed_addr global [18 x %struct.castinfo_t], align 16
@castnum = external dso_local local_unnamed_addr global i32, align 4
@states = external global [967 x %struct.state_t], align 16
@mobjinfo = external local_unnamed_addr global [137 x %struct.mobjinfo_t], align 16
@caststate = external dso_local local_unnamed_addr global ptr, align 8
@casttics = external dso_local local_unnamed_addr global i32, align 4
@castdeath = external dso_local local_unnamed_addr global i32, align 4
@castframes = external dso_local local_unnamed_addr global i32, align 4
@castonmelee = external dso_local local_unnamed_addr global i32, align 4
@castattacking = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @F_CastTicker() local_unnamed_addr #0 {
  %1 = load i32, ptr @casttics, align 4, !tbaa !5
  %2 = add nsw i32 %1, -1
  store i32 %2, ptr @casttics, align 4, !tbaa !5
  %3 = icmp sgt i32 %1, 1
  br i1 %3, label %104, label %4

4:                                                ; preds = %0
  %5 = load ptr, ptr @caststate, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  %7 = load i64, ptr %6, align 8, !tbaa !11
  %8 = icmp eq i64 %7, -1
  br i1 %8, label %13, label %9

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %5, i64 32
  %11 = load i32, ptr %10, align 8, !tbaa !14
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %30

13:                                               ; preds = %9, %4
  %14 = load i32, ptr @castnum, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr @castnum, align 4, !tbaa !5
  store i32 0, ptr @castdeath, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 16, !tbaa !15
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %13
  store i32 0, ptr @castnum, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %20, %13
  %22 = phi i32 [ 0, %20 ], [ %15, %13 ]
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %23, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !17
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %26, i32 4
  %28 = load i32, ptr %27, align 4, !tbaa !18
  %.not6 = icmp eq i32 %28, 0
  br i1 %.not6, label %.thread14, label %29

29:                                               ; preds = %21
  tail call void @S_StartSound(ptr noundef null, i32 noundef %28) #2
  %.pre17 = load i32, ptr @castnum, align 4, !tbaa !5
  %.phi.trans.insert = sext i32 %.pre17 to i64
  %.phi.trans.insert18 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %.phi.trans.insert, i32 1
  %.pre19 = load i32, ptr %.phi.trans.insert18, align 8, !tbaa !17
  %.pre33 = zext i32 %.pre19 to i64
  br label %.thread14

30:                                               ; preds = %9
  %31 = icmp eq ptr %5, getelementptr inbounds (i8, ptr @states, i64 8624)
  br i1 %31, label %._crit_edge28, label %32

._crit_edge28:                                    ; preds = %30
  %.pre29 = load i32, ptr @castnum, align 4, !tbaa !5
  br label %88

32:                                               ; preds = %30
  %33 = sext i32 %11 to i64
  %34 = getelementptr inbounds [967 x %struct.state_t], ptr @states, i64 0, i64 %33
  store ptr %34, ptr @caststate, align 8, !tbaa !9
  %35 = load i32, ptr @castframes, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr @castframes, align 4, !tbaa !5
  switch i32 %11, label %54 [
    i32 154, label %53
    i32 185, label %37
    i32 218, label %38
    i32 256, label %39
    i32 336, label %40
    i32 338, label %41
    i32 340, label %42
    i32 383, label %43
    i32 380, label %43
    i32 377, label %43
    i32 417, label %44
    i32 418, label %44
    i32 419, label %44
    i32 454, label %45
    i32 486, label %46
    i32 538, label %47
    i32 567, label %47
    i32 505, label %47
    i32 590, label %48
    i32 616, label %49
    i32 617, label %49
    i32 648, label %50
    i32 685, label %51
    i32 687, label %51
    i32 689, label %51
    i32 710, label %52
  ]

37:                                               ; preds = %32
  br label %53

38:                                               ; preds = %32
  br label %53

39:                                               ; preds = %32
  br label %53

40:                                               ; preds = %32
  br label %53

41:                                               ; preds = %32
  br label %53

42:                                               ; preds = %32
  br label %53

43:                                               ; preds = %32, %32, %32
  br label %53

44:                                               ; preds = %32, %32, %32
  br label %53

45:                                               ; preds = %32
  br label %53

46:                                               ; preds = %32
  br label %53

47:                                               ; preds = %32, %32, %32
  br label %53

48:                                               ; preds = %32
  br label %53

49:                                               ; preds = %32, %32
  br label %53

50:                                               ; preds = %32
  br label %53

51:                                               ; preds = %32, %32, %32
  br label %53

52:                                               ; preds = %32
  br label %53

53:                                               ; preds = %52, %51, %50, %49, %48, %47, %46, %45, %44, %43, %42, %41, %40, %39, %38, %37, %32
  %.0.ph = phi i32 [ 4, %32 ], [ 1, %37 ], [ 2, %38 ], [ 54, %39 ], [ 56, %40 ], [ 53, %41 ], [ 107, %42 ], [ 16, %43 ], [ 2, %44 ], [ 55, %45 ], [ 52, %46 ], [ 16, %47 ], [ 51, %48 ], [ 2, %49 ], [ 8, %50 ], [ 14, %51 ], [ 51, %52 ]
  tail call void @S_StartSound(ptr noundef null, i32 noundef %.0.ph) #2
  %.pr = load i32, ptr @castframes, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %32, %53
  %55 = phi i32 [ %36, %32 ], [ %.pr, %53 ]
  %56 = icmp eq i32 %55, 12
  br i1 %56, label %57, label %74

57:                                               ; preds = %54
  store i32 1, ptr @castattacking, align 4, !tbaa !5
  %58 = load i32, ptr @castonmelee, align 4, !tbaa !5
  %.not7 = icmp eq i32 %58, 0
  %59 = load i32, ptr @castnum, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %60, i32 1
  %62 = load i32, ptr %61, align 8, !tbaa !17
  %63 = zext i32 %62 to i64
  %64 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %63, i32 11
  %65 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %63, i32 10
  %.pn.in.in = select i1 %.not7, ptr %64, ptr %65
  %.pn.in = load i32, ptr %.pn.in.in, align 4, !tbaa !5
  %.pn = sext i32 %.pn.in to i64
  %storemerge = getelementptr inbounds [967 x %struct.state_t], ptr @states, i64 0, i64 %.pn
  store ptr %storemerge, ptr @caststate, align 8, !tbaa !9
  %66 = xor i32 %58, 1
  store i32 %66, ptr @castonmelee, align 4, !tbaa !5
  %67 = icmp eq i32 %.pn.in, 0
  br i1 %67, label %.thread41.sink.split, label %.thread41

.thread41.sink.split:                             ; preds = %57
  %.not8 = icmp eq i32 %58, 1
  %68 = zext i32 %62 to i64
  %69 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %68, i32 10
  %70 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %68, i32 11
  %.sink45 = select i1 %.not8, ptr %70, ptr %69
  %71 = load i32, ptr %.sink45, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [967 x %struct.state_t], ptr @states, i64 0, i64 %72
  store ptr %73, ptr @caststate, align 8, !tbaa !9
  br label %.thread41

.thread41:                                        ; preds = %.thread41.sink.split, %57
  %.pre3042 = load i32, ptr @castnum, align 4, !tbaa !5
  br label %..thread16_crit_edge

74:                                               ; preds = %54
  %.pre = load i32, ptr @castattacking, align 4, !tbaa !5
  %75 = icmp eq i32 %.pre, 0
  br i1 %75, label %._crit_edge31, label %82

._crit_edge31:                                    ; preds = %74
  %.pre32 = load ptr, ptr @caststate, align 8, !tbaa !9
  br label %98

.thread14:                                        ; preds = %29, %21
  %.pre-phi = phi i64 [ %.pre33, %29 ], [ %26, %21 ]
  %76 = phi i32 [ %.pre17, %29 ], [ %22, %21 ]
  %77 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %.pre-phi, i32 3
  %78 = load i32, ptr %77, align 4, !tbaa !20
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [967 x %struct.state_t], ptr @states, i64 0, i64 %79
  store ptr %80, ptr @caststate, align 8, !tbaa !9
  store i32 0, ptr @castframes, align 4, !tbaa !5
  %81 = load i32, ptr @castattacking, align 4, !tbaa !5
  %.not915 = icmp eq i32 %81, 0
  br i1 %.not915, label %98, label %.thread16

82:                                               ; preds = %74
  %83 = icmp eq i32 %55, 24
  %.pre30 = load i32, ptr @castnum, align 4, !tbaa !5
  br i1 %83, label %88, label %..thread16_crit_edge

..thread16_crit_edge:                             ; preds = %.thread41, %82
  %.pre3043 = phi i32 [ %.pre3042, %.thread41 ], [ %.pre30, %82 ]
  %.pre20 = load ptr, ptr @caststate, align 8, !tbaa !9
  %.phi.trans.insert22 = sext i32 %.pre3043 to i64
  %.phi.trans.insert23 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %.phi.trans.insert22, i32 1
  %.pre24 = load i32, ptr %.phi.trans.insert23, align 8, !tbaa !17
  %.phi.trans.insert25 = zext i32 %.pre24 to i64
  %.phi.trans.insert26 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %.phi.trans.insert25, i32 3
  %.pre27 = load i32, ptr %.phi.trans.insert26, align 4, !tbaa !20
  %.pre36 = sext i32 %.pre27 to i64
  br label %.thread16

.thread16:                                        ; preds = %.thread14, %..thread16_crit_edge
  %.pre-phi37 = phi i64 [ %.pre36, %..thread16_crit_edge ], [ %79, %.thread14 ]
  %84 = phi i32 [ %.pre3043, %..thread16_crit_edge ], [ %76, %.thread14 ]
  %85 = phi ptr [ %.pre20, %..thread16_crit_edge ], [ %80, %.thread14 ]
  %86 = getelementptr inbounds [967 x %struct.state_t], ptr @states, i64 0, i64 %.pre-phi37
  %87 = icmp eq ptr %85, %86
  br i1 %87, label %88, label %98

88:                                               ; preds = %._crit_edge28, %82, %.thread16
  %89 = phi i32 [ %.pre29, %._crit_edge28 ], [ %.pre30, %82 ], [ %84, %.thread16 ]
  store i32 0, ptr @castattacking, align 4, !tbaa !5
  store i32 0, ptr @castframes, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [18 x %struct.castinfo_t], ptr @castorder, i64 0, i64 %90, i32 1
  %92 = load i32, ptr %91, align 8, !tbaa !17
  %93 = zext i32 %92 to i64
  %94 = getelementptr inbounds [137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 %93, i32 3
  %95 = load i32, ptr %94, align 4, !tbaa !20
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [967 x %struct.state_t], ptr @states, i64 0, i64 %96
  store ptr %97, ptr @caststate, align 8, !tbaa !9
  br label %98

98:                                               ; preds = %._crit_edge31, %.thread14, %.thread16, %88
  %99 = phi ptr [ %.pre32, %._crit_edge31 ], [ %80, %.thread14 ], [ %85, %.thread16 ], [ %97, %88 ]
  %100 = getelementptr inbounds i8, ptr %99, i64 16
  %101 = load i64, ptr %100, align 8, !tbaa !11
  %102 = trunc i64 %101 to i32
  %103 = icmp eq i32 %102, -1
  %spec.store.select = select i1 %103, i32 15, i32 %102
  store i32 %spec.store.select, ptr @casttics, align 4
  br label %104

104:                                              ; preds = %0, %98
  ret void
}

declare void @S_StartSound(ptr noundef, i32 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 = !{!"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, !13, i64 16}
!12 = !{!"", !6, i64 0, !13, i64 8, !13, i64 16, !7, i64 24, !6, i64 32, !13, i64 40, !13, i64 48}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 32}
!15 = !{!16, !10, i64 0}
!16 = !{!"", !10, i64 0, !6, i64 8}
!17 = !{!16, !6, i64 8}
!18 = !{!19, !6, i64 16}
!19 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !6, i64 48, !6, i64 52, !6, i64 56, !6, i64 60, !6, i64 64, !6, i64 68, !6, i64 72, !6, i64 76, !6, i64 80, !6, i64 84, !6, i64 88}
!20 = !{!19, !6, i64 12}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass