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

; 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.visplane_t = type { i32, i32, i32, i32, i32, i16, [320 x i16], i16, i16, [320 x i16], i16 }
%struct.drawseg_s = type { ptr, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr }
%struct.memblock_s = type { i32, i32, ptr, i32, i32, ptr, ptr, i32 }

@planeheight = external dso_local global i32, align 4
@viewangle = external global i32, align 4
@xtoviewangle = external global [321 x i32], align 16
@planezlight = external dso_local global ptr, align 8
@visplanes = external dso_local global [128 x %struct.visplane_t], align 16
@lastvisplane = external dso_local global ptr, align 8
@openings = external dso_local global [20480 x i16], align 16
@lastopening = external dso_local global ptr, align 8
@skyflatnum = external global i32, align 4
@ds_p = external global ptr, align 8
@drawsegs = external global [256 x %struct.drawseg_s], align 16
@.str.2 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [36 x i8], align 1
@pspriteiscale = external global i32, align 4
@dc_iscale = external global i32, align 4
@colormaps = external global ptr, align 8
@dc_colormap = external global ptr, align 8
@skytexturemid = external global i32, align 4
@dc_texturemid = external global i32, align 4
@dc_yl = external global i32, align 4
@dc_yh = external global i32, align 4
@dc_x = external global i32, align 4
@skytexture = external global i32, align 4
@dc_source = external global ptr, align 8
@colfunc = external global ptr, align 8
@firstflat = external global i32, align 4
@flattranslation = external global ptr, align 8
@ds_source = external global ptr, align 8
@viewz = external global i32, align 4
@extralight = external global i32, align 4
@zlight = external global [16 x [128 x ptr]], align 16
@.str.5 = external hidden unnamed_addr constant [108 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: noreturn
declare void @I_Error(ptr noundef, ...) #1

; 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
declare dso_local void @R_MakeSpans(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @R_DrawPlanes() #2 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %6 = load ptr, ptr @ds_p, align 8, !tbaa !5
  %7 = ptrtoint ptr %6 to i64
  %8 = sub i64 %7, ptrtoint (ptr @drawsegs to i64)
  %9 = sdiv exact i64 %8, 64
  %10 = icmp sgt i64 %9, 256
  br i1 %10, label %11, label %16

11:                                               ; preds = %0
  %12 = load ptr, ptr @ds_p, align 8, !tbaa !5
  %13 = ptrtoint ptr %12 to i64
  %14 = sub i64 %13, ptrtoint (ptr @drawsegs to i64)
  %15 = sdiv exact i64 %14, 64
  call void (ptr, ...) @I_Error(ptr noundef @.str.2, i64 noundef %15) #6
  unreachable

16:                                               ; preds = %0
  %17 = load ptr, ptr @lastvisplane, align 8, !tbaa !5
  %18 = ptrtoint ptr %17 to i64
  %19 = sub i64 %18, ptrtoint (ptr @visplanes to i64)
  %20 = sdiv exact i64 %19, 1308
  %21 = icmp sgt i64 %20, 128
  br i1 %21, label %22, label %27

22:                                               ; preds = %16
  %23 = load ptr, ptr @lastvisplane, align 8, !tbaa !5
  %24 = ptrtoint ptr %23 to i64
  %25 = sub i64 %24, ptrtoint (ptr @visplanes to i64)
  %26 = sdiv exact i64 %25, 1308
  call void (ptr, ...) @I_Error(ptr noundef @.str.3, i64 noundef %26) #6
  unreachable

27:                                               ; preds = %16
  %28 = load ptr, ptr @lastopening, align 8, !tbaa !5
  %29 = ptrtoint ptr %28 to i64
  %30 = sub i64 %29, ptrtoint (ptr @openings to i64)
  %31 = sdiv exact i64 %30, 2
  %32 = icmp sgt i64 %31, 20480
  br i1 %32, label %33, label %38

33:                                               ; preds = %27
  %34 = load ptr, ptr @lastopening, align 8, !tbaa !5
  %35 = ptrtoint ptr %34 to i64
  %36 = sub i64 %35, ptrtoint (ptr @openings to i64)
  %37 = sdiv exact i64 %36, 2
  call void (ptr, ...) @I_Error(ptr noundef @.str.4, i64 noundef %37) #6
  unreachable

38:                                               ; preds = %27
  store ptr @visplanes, ptr %1, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %213, %38
  %40 = load ptr, ptr %1, align 8, !tbaa !5
  %41 = load ptr, ptr @lastvisplane, align 8, !tbaa !5
  %42 = icmp ult ptr %40, %41
  br i1 %42, label %43, label %216

43:                                               ; preds = %39
  %44 = load ptr, ptr %1, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.visplane_t, ptr %44, i32 0, i32 3
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = load ptr, ptr %1, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.visplane_t, ptr %47, i32 0, i32 4
  %49 = load i32, ptr %48, align 4, !tbaa !13
  %50 = icmp sgt i32 %46, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %43
  br label %213

52:                                               ; preds = %43
  %53 = load ptr, ptr %1, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.visplane_t, ptr %53, i32 0, i32 1
  %55 = load i32, ptr %54, align 4, !tbaa !14
  %56 = load i32, ptr @skyflatnum, align 4, !tbaa !15
  %57 = icmp eq i32 %55, %56
  br i1 %57, label %58, label %107

58:                                               ; preds = %52
  %59 = load i32, ptr @pspriteiscale, align 4, !tbaa !15
  store i32 %59, ptr @dc_iscale, align 4, !tbaa !15
  %60 = load ptr, ptr @colormaps, align 8, !tbaa !5
  store ptr %60, ptr @dc_colormap, align 8, !tbaa !5
  %61 = load i32, ptr @skytexturemid, align 4, !tbaa !15
  store i32 %61, ptr @dc_texturemid, align 4, !tbaa !15
  %62 = load ptr, ptr %1, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.visplane_t, ptr %62, i32 0, i32 3
  %64 = load i32, ptr %63, align 4, !tbaa !9
  store i32 %64, ptr %3, align 4, !tbaa !15
  br label %65

65:                                               ; preds = %103, %58
  %66 = load i32, ptr %3, align 4, !tbaa !15
  %67 = load ptr, ptr %1, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.visplane_t, ptr %67, i32 0, i32 4
  %69 = load i32, ptr %68, align 4, !tbaa !13
  %70 = icmp sle i32 %66, %69
  br i1 %70, label %71, label %106

71:                                               ; preds = %65
  %72 = load ptr, ptr %1, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.visplane_t, ptr %72, i32 0, i32 6
  %74 = load i32, ptr %3, align 4, !tbaa !15
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [320 x i16], ptr %73, i64 0, i64 %75
  %77 = load i16, ptr %76, align 2, !tbaa !16
  %78 = zext i16 %77 to i32
  store i32 %78, ptr @dc_yl, align 4, !tbaa !15
  %79 = load ptr, ptr %1, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.visplane_t, ptr %79, i32 0, i32 9
  %81 = load i32, ptr %3, align 4, !tbaa !15
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [320 x i16], ptr %80, i64 0, i64 %82
  %84 = load i16, ptr %83, align 2, !tbaa !16
  %85 = zext i16 %84 to i32
  store i32 %85, ptr @dc_yh, align 4, !tbaa !15
  %86 = load i32, ptr @dc_yl, align 4, !tbaa !15
  %87 = load i32, ptr @dc_yh, align 4, !tbaa !15
  %88 = icmp sle i32 %86, %87
  br i1 %88, label %89, label %102

89:                                               ; preds = %71
  %90 = load i32, ptr @viewangle, align 4, !tbaa !15
  %91 = load i32, ptr %3, align 4, !tbaa !15
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [321 x i32], ptr @xtoviewangle, i64 0, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !15
  %95 = add i32 %90, %94
  %96 = lshr i32 %95, 22
  store i32 %96, ptr %5, align 4, !tbaa !15
  %97 = load i32, ptr %3, align 4, !tbaa !15
  store i32 %97, ptr @dc_x, align 4, !tbaa !15
  %98 = load i32, ptr @skytexture, align 4, !tbaa !15
  %99 = load i32, ptr %5, align 4, !tbaa !15
  %100 = call ptr @R_GetColumn(i32 noundef %98, i32 noundef %99)
  store ptr %100, ptr @dc_source, align 8, !tbaa !5
  %101 = load ptr, ptr @colfunc, align 8, !tbaa !5
  call void %101()
  br label %102

102:                                              ; preds = %89, %71
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr %3, align 4, !tbaa !15
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %3, align 4, !tbaa !15
  br label %65, !llvm.loop !17

106:                                              ; preds = %65
  br label %213

107:                                              ; preds = %52
  %108 = load i32, ptr @firstflat, align 4, !tbaa !15
  %109 = load ptr, ptr @flattranslation, align 8, !tbaa !5
  %110 = load ptr, ptr %1, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.visplane_t, ptr %110, i32 0, i32 1
  %112 = load i32, ptr %111, align 4, !tbaa !14
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds i32, ptr %109, i64 %113
  %115 = load i32, ptr %114, align 4, !tbaa !15
  %116 = add nsw i32 %108, %115
  %117 = call ptr @W_CacheLumpNum(i32 noundef %116, i32 noundef 1)
  store ptr %117, ptr @ds_source, align 8, !tbaa !5
  %118 = load ptr, ptr %1, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.visplane_t, ptr %118, i32 0, i32 0
  %120 = load i32, ptr %119, align 4, !tbaa !19
  %121 = load i32, ptr @viewz, align 4, !tbaa !15
  %122 = sub nsw i32 %120, %121
  %123 = call i32 @llvm.abs.i32(i32 %122, i1 true)
  store i32 %123, ptr @planeheight, align 4, !tbaa !15
  %124 = load ptr, ptr %1, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.visplane_t, ptr %124, i32 0, i32 2
  %126 = load i32, ptr %125, align 4, !tbaa !20
  %127 = ashr i32 %126, 4
  %128 = load i32, ptr @extralight, align 4, !tbaa !15
  %129 = add nsw i32 %127, %128
  store i32 %129, ptr %2, align 4, !tbaa !15
  %130 = load i32, ptr %2, align 4, !tbaa !15
  %131 = icmp sge i32 %130, 16
  br i1 %131, label %132, label %133

132:                                              ; preds = %107
  store i32 15, ptr %2, align 4, !tbaa !15
  br label %133

133:                                              ; preds = %132, %107
  %134 = load i32, ptr %2, align 4, !tbaa !15
  %135 = icmp slt i32 %134, 0
  br i1 %135, label %136, label %137

136:                                              ; preds = %133
  store i32 0, ptr %2, align 4, !tbaa !15
  br label %137

137:                                              ; preds = %136, %133
  %138 = load i32, ptr %2, align 4, !tbaa !15
  %139 = sext i32 %138 to i64
  %140 = getelementptr inbounds [16 x [128 x ptr]], ptr @zlight, i64 0, i64 %139
  %141 = getelementptr inbounds [128 x ptr], ptr %140, i64 0, i64 0
  store ptr %141, ptr @planezlight, align 8, !tbaa !5
  %142 = load ptr, ptr %1, align 8, !tbaa !5
  %143 = getelementptr inbounds %struct.visplane_t, ptr %142, i32 0, i32 6
  %144 = load ptr, ptr %1, align 8, !tbaa !5
  %145 = getelementptr inbounds %struct.visplane_t, ptr %144, i32 0, i32 4
  %146 = load i32, ptr %145, align 4, !tbaa !13
  %147 = add nsw i32 %146, 1
  %148 = sext i32 %147 to i64
  %149 = getelementptr inbounds [320 x i16], ptr %143, i64 0, i64 %148
  store i16 -1, ptr %149, align 2, !tbaa !16
  %150 = load ptr, ptr %1, align 8, !tbaa !5
  %151 = getelementptr inbounds %struct.visplane_t, ptr %150, i32 0, i32 6
  %152 = load ptr, ptr %1, align 8, !tbaa !5
  %153 = getelementptr inbounds %struct.visplane_t, ptr %152, i32 0, i32 3
  %154 = load i32, ptr %153, align 4, !tbaa !9
  %155 = sub nsw i32 %154, 1
  %156 = sext i32 %155 to i64
  %157 = getelementptr inbounds [320 x i16], ptr %151, i64 0, i64 %156
  store i16 -1, ptr %157, align 2, !tbaa !16
  %158 = load ptr, ptr %1, align 8, !tbaa !5
  %159 = getelementptr inbounds %struct.visplane_t, ptr %158, i32 0, i32 4
  %160 = load i32, ptr %159, align 4, !tbaa !13
  %161 = add nsw i32 %160, 1
  store i32 %161, ptr %4, align 4, !tbaa !15
  %162 = load ptr, ptr %1, align 8, !tbaa !5
  %163 = getelementptr inbounds %struct.visplane_t, ptr %162, i32 0, i32 3
  %164 = load i32, ptr %163, align 4, !tbaa !9
  store i32 %164, ptr %3, align 4, !tbaa !15
  br label %165

165:                                              ; preds = %201, %137
  %166 = load i32, ptr %3, align 4, !tbaa !15
  %167 = load i32, ptr %4, align 4, !tbaa !15
  %168 = icmp sle i32 %166, %167
  br i1 %168, label %169, label %204

169:                                              ; preds = %165
  %170 = load i32, ptr %3, align 4, !tbaa !15
  %171 = load ptr, ptr %1, align 8, !tbaa !5
  %172 = getelementptr inbounds %struct.visplane_t, ptr %171, i32 0, i32 6
  %173 = load i32, ptr %3, align 4, !tbaa !15
  %174 = sub nsw i32 %173, 1
  %175 = sext i32 %174 to i64
  %176 = getelementptr inbounds [320 x i16], ptr %172, i64 0, i64 %175
  %177 = load i16, ptr %176, align 2, !tbaa !16
  %178 = zext i16 %177 to i32
  %179 = load ptr, ptr %1, align 8, !tbaa !5
  %180 = getelementptr inbounds %struct.visplane_t, ptr %179, i32 0, i32 9
  %181 = load i32, ptr %3, align 4, !tbaa !15
  %182 = sub nsw i32 %181, 1
  %183 = sext i32 %182 to i64
  %184 = getelementptr inbounds [320 x i16], ptr %180, i64 0, i64 %183
  %185 = load i16, ptr %184, align 2, !tbaa !16
  %186 = zext i16 %185 to i32
  %187 = load ptr, ptr %1, align 8, !tbaa !5
  %188 = getelementptr inbounds %struct.visplane_t, ptr %187, i32 0, i32 6
  %189 = load i32, ptr %3, align 4, !tbaa !15
  %190 = sext i32 %189 to i64
  %191 = getelementptr inbounds [320 x i16], ptr %188, i64 0, i64 %190
  %192 = load i16, ptr %191, align 2, !tbaa !16
  %193 = zext i16 %192 to i32
  %194 = load ptr, ptr %1, align 8, !tbaa !5
  %195 = getelementptr inbounds %struct.visplane_t, ptr %194, i32 0, i32 9
  %196 = load i32, ptr %3, align 4, !tbaa !15
  %197 = sext i32 %196 to i64
  %198 = getelementptr inbounds [320 x i16], ptr %195, i64 0, i64 %197
  %199 = load i16, ptr %198, align 2, !tbaa !16
  %200 = zext i16 %199 to i32
  call void @R_MakeSpans(i32 noundef %170, i32 noundef %178, i32 noundef %186, i32 noundef %193, i32 noundef %200)
  br label %201

201:                                              ; preds = %169
  %202 = load i32, ptr %3, align 4, !tbaa !15
  %203 = add nsw i32 %202, 1
  store i32 %203, ptr %3, align 4, !tbaa !15
  br label %165, !llvm.loop !21

204:                                              ; preds = %165
  %205 = load ptr, ptr @ds_source, align 8, !tbaa !5
  %206 = getelementptr inbounds i8, ptr %205, i64 -48
  %207 = getelementptr inbounds %struct.memblock_s, ptr %206, i32 0, i32 4
  %208 = load i32, ptr %207, align 4, !tbaa !22
  %209 = icmp ne i32 %208, 1919505
  br i1 %209, label %210, label %211

210:                                              ; preds = %204
  call void (ptr, ...) @I_Error(ptr noundef @.str.5, i32 noundef 430) #6
  unreachable

211:                                              ; preds = %204
  %212 = load ptr, ptr @ds_source, align 8, !tbaa !5
  call void @Z_ChangeTag2(ptr noundef %212, i32 noundef 101)
  br label %213

213:                                              ; preds = %211, %106, %51
  %214 = load ptr, ptr %1, align 8, !tbaa !5
  %215 = getelementptr inbounds %struct.visplane_t, ptr %214, i32 1
  store ptr %215, ptr %1, align 8, !tbaa !5
  br label %39, !llvm.loop !24

216:                                              ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  ret void
}

declare ptr @R_GetColumn(i32 noundef, i32 noundef) #3

declare ptr @W_CacheLumpNum(i32 noundef, i32 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #4

declare void @Z_ChangeTag2(ptr noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { "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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { 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, !11, i64 12}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !12, i64 20, !7, i64 22, !12, i64 662, !12, i64 664, !7, i64 666, !12, i64 1306}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!10, !11, i64 16}
!14 = !{!10, !11, i64 4}
!15 = !{!11, !11, i64 0}
!16 = !{!12, !12, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!10, !11, i64 0}
!20 = !{!10, !11, i64 8}
!21 = distinct !{!21, !18}
!22 = !{!23, !11, i64 20}
!23 = !{!"memblock_s", !11, i64 0, !11, i64 4, !6, i64 8, !11, i64 16, !11, i64 20, !6, i64 24, !6, i64 32, !11, i64 40}
!24 = distinct !{!24, !18}


; 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.visplane_t = type { i32, i32, i32, i32, i32, i16, [320 x i16], i16, i16, [320 x i16], i16 }
%struct.drawseg_s = type { ptr, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr }

@planeheight = external dso_local local_unnamed_addr global i32, align 4
@viewangle = external local_unnamed_addr global i32, align 4
@xtoviewangle = external local_unnamed_addr global [321 x i32], align 16
@planezlight = external dso_local local_unnamed_addr global ptr, align 8
@visplanes = external dso_local global [128 x %struct.visplane_t], align 16
@lastvisplane = external dso_local local_unnamed_addr global ptr, align 8
@openings = external dso_local global [20480 x i16], align 16
@lastopening = external dso_local local_unnamed_addr global ptr, align 8
@skyflatnum = external local_unnamed_addr global i32, align 4
@ds_p = external local_unnamed_addr global ptr, align 8
@drawsegs = external global [256 x %struct.drawseg_s], align 16
@.str.2 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [36 x i8], align 1
@pspriteiscale = external local_unnamed_addr global i32, align 4
@dc_iscale = external local_unnamed_addr global i32, align 4
@colormaps = external local_unnamed_addr global ptr, align 8
@dc_colormap = external local_unnamed_addr global ptr, align 8
@skytexturemid = external local_unnamed_addr global i32, align 4
@dc_texturemid = external local_unnamed_addr global i32, align 4
@dc_yl = external local_unnamed_addr global i32, align 4
@dc_yh = external local_unnamed_addr global i32, align 4
@dc_x = external local_unnamed_addr global i32, align 4
@skytexture = external local_unnamed_addr global i32, align 4
@dc_source = external local_unnamed_addr global ptr, align 8
@colfunc = external local_unnamed_addr global ptr, align 8
@firstflat = external local_unnamed_addr global i32, align 4
@flattranslation = external local_unnamed_addr global ptr, align 8
@ds_source = external local_unnamed_addr global ptr, align 8
@viewz = external local_unnamed_addr global i32, align 4
@extralight = external local_unnamed_addr global i32, align 4
@zlight = external global [16 x [128 x ptr]], align 16
@.str.5 = external hidden unnamed_addr constant [108 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local void @R_MakeSpans(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @R_DrawPlanes() local_unnamed_addr #1 {
  %1 = load ptr, ptr @ds_p, align 8, !tbaa !5
  %2 = ptrtoint ptr %1 to i64
  %3 = sub i64 %2, ptrtoint (ptr @drawsegs to i64)
  %4 = ashr exact i64 %3, 6
  %5 = icmp sgt i64 %4, 256
  br i1 %5, label %6, label %7

6:                                                ; preds = %0
  tail call void (ptr, ...) @I_Error(ptr noundef nonnull @.str.2, i64 noundef %4) #5
  unreachable

7:                                                ; preds = %0
  %8 = load ptr, ptr @lastvisplane, align 8, !tbaa !5
  %9 = ptrtoint ptr %8 to i64
  %10 = sub i64 %9, ptrtoint (ptr @visplanes to i64)
  %11 = icmp sgt i64 %10, 167424
  br i1 %11, label %12, label %14

12:                                               ; preds = %7
  %13 = udiv exact i64 %10, 1308
  tail call void (ptr, ...) @I_Error(ptr noundef nonnull @.str.3, i64 noundef %13) #5
  unreachable

14:                                               ; preds = %7
  %15 = load ptr, ptr @lastopening, align 8, !tbaa !5
  %16 = ptrtoint ptr %15 to i64
  %17 = sub i64 %16, ptrtoint (ptr @openings to i64)
  %18 = ashr exact i64 %17, 1
  %19 = icmp sgt i64 %18, 20480
  br i1 %19, label %21, label %.preheader

.preheader:                                       ; preds = %14
  %20 = icmp ugt ptr %8, @visplanes
  br i1 %20, label %.lr.ph55, label %._crit_edge56

21:                                               ; preds = %14
  tail call void (ptr, ...) @I_Error(ptr noundef nonnull @.str.4, i64 noundef %18) #5
  unreachable

.lr.ph55:                                         ; preds = %.preheader, %.loopexit
  %.054 = phi ptr [ %110, %.loopexit ], [ @visplanes, %.preheader ]
  %22 = getelementptr inbounds i8, ptr %.054, i64 12
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = getelementptr inbounds i8, ptr %.054, i64 16
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = icmp sgt i32 %23, %25
  br i1 %26, label %.loopexit, label %27

27:                                               ; preds = %.lr.ph55
  %28 = getelementptr inbounds i8, ptr %.054, i64 4
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %30 = load i32, ptr @skyflatnum, align 4, !tbaa !15
  %31 = icmp eq i32 %29, %30
  br i1 %31, label %.lr.ph53, label %59

.lr.ph53:                                         ; preds = %27
  %32 = load i32, ptr @pspriteiscale, align 4, !tbaa !15
  store i32 %32, ptr @dc_iscale, align 4, !tbaa !15
  %33 = load ptr, ptr @colormaps, align 8, !tbaa !5
  store ptr %33, ptr @dc_colormap, align 8, !tbaa !5
  %34 = load i32, ptr @skytexturemid, align 4, !tbaa !15
  store i32 %34, ptr @dc_texturemid, align 4, !tbaa !15
  %35 = getelementptr inbounds i8, ptr %.054, i64 22
  %36 = getelementptr inbounds i8, ptr %.054, i64 666
  %37 = sext i32 %23 to i64
  br label %38

38:                                               ; preds = %.lr.ph53, %56
  %39 = phi i32 [ %25, %.lr.ph53 ], [ %57, %56 ]
  %indvars.iv58 = phi i64 [ %37, %.lr.ph53 ], [ %indvars.iv.next59, %56 ]
  %40 = getelementptr inbounds [320 x i16], ptr %35, i64 0, i64 %indvars.iv58
  %41 = load i16, ptr %40, align 2, !tbaa !16
  %42 = zext i16 %41 to i32
  store i32 %42, ptr @dc_yl, align 4, !tbaa !15
  %43 = getelementptr inbounds [320 x i16], ptr %36, i64 0, i64 %indvars.iv58
  %44 = load i16, ptr %43, align 2, !tbaa !16
  %45 = zext i16 %44 to i32
  store i32 %45, ptr @dc_yh, align 4, !tbaa !15
  %.not47 = icmp ugt i16 %41, %44
  br i1 %.not47, label %56, label %46

46:                                               ; preds = %38
  %47 = load i32, ptr @viewangle, align 4, !tbaa !15
  %48 = getelementptr inbounds [321 x i32], ptr @xtoviewangle, i64 0, i64 %indvars.iv58
  %49 = load i32, ptr %48, align 4, !tbaa !15
  %50 = add i32 %49, %47
  %51 = lshr i32 %50, 22
  %52 = trunc nsw i64 %indvars.iv58 to i32
  store i32 %52, ptr @dc_x, align 4, !tbaa !15
  %53 = load i32, ptr @skytexture, align 4, !tbaa !15
  %54 = tail call ptr @R_GetColumn(i32 noundef %53, i32 noundef %51) #6
  store ptr %54, ptr @dc_source, align 8, !tbaa !5
  %55 = load ptr, ptr @colfunc, align 8, !tbaa !5
  tail call void %55() #6
  %.pre61 = load i32, ptr %24, align 4, !tbaa !13
  br label %56

56:                                               ; preds = %38, %46
  %57 = phi i32 [ %39, %38 ], [ %.pre61, %46 ]
  %indvars.iv.next59 = add nsw i64 %indvars.iv58, 1
  %58 = sext i32 %57 to i64
  %.not46.not = icmp slt i64 %indvars.iv58, %58
  br i1 %.not46.not, label %38, label %.loopexit, !llvm.loop !17

59:                                               ; preds = %27
  %60 = load i32, ptr @firstflat, align 4, !tbaa !15
  %61 = load ptr, ptr @flattranslation, align 8, !tbaa !5
  %62 = sext i32 %29 to i64
  %63 = getelementptr inbounds i32, ptr %61, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !15
  %65 = add nsw i32 %64, %60
  %66 = tail call ptr @W_CacheLumpNum(i32 noundef %65, i32 noundef 1) #6
  store ptr %66, ptr @ds_source, align 8, !tbaa !5
  %67 = load i32, ptr %.054, align 4, !tbaa !19
  %68 = load i32, ptr @viewz, align 4, !tbaa !15
  %69 = sub nsw i32 %67, %68
  %70 = tail call i32 @llvm.abs.i32(i32 %69, i1 true)
  store i32 %70, ptr @planeheight, align 4, !tbaa !15
  %71 = getelementptr inbounds i8, ptr %.054, i64 8
  %72 = load i32, ptr %71, align 4, !tbaa !20
  %73 = ashr i32 %72, 4
  %74 = load i32, ptr @extralight, align 4, !tbaa !15
  %75 = add nsw i32 %73, %74
  %spec.store.select = tail call i32 @llvm.smin.i32(i32 %75, i32 15)
  %spec.store.select1 = tail call i32 @llvm.smax.i32(i32 %spec.store.select, i32 0)
  %76 = zext nneg i32 %spec.store.select1 to i64
  %77 = getelementptr inbounds [16 x [128 x ptr]], ptr @zlight, i64 0, i64 %76
  store ptr %77, ptr @planezlight, align 8, !tbaa !5
  %78 = getelementptr inbounds i8, ptr %.054, i64 22
  %79 = load i32, ptr %24, align 4, !tbaa !13
  %80 = add nsw i32 %79, 1
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [320 x i16], ptr %78, i64 0, i64 %81
  store i16 -1, ptr %82, align 2, !tbaa !16
  %83 = load i32, ptr %22, align 4, !tbaa !9
  %84 = add nsw i32 %83, -1
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [320 x i16], ptr %78, i64 0, i64 %85
  store i16 -1, ptr %86, align 2, !tbaa !16
  %.not48 = icmp sgt i32 %83, %80
  br i1 %.not48, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %59
  %87 = getelementptr inbounds i8, ptr %.054, i64 666
  %88 = sext i32 %83 to i64
  %89 = sext i32 %79 to i64
  br label %90

90:                                               ; preds = %.lr.ph, %90
  %indvars.iv = phi i64 [ %88, %.lr.ph ], [ %indvars.iv.next, %90 ]
  %91 = add nsw i64 %indvars.iv, -1
  %92 = getelementptr inbounds [320 x i16], ptr %78, i64 0, i64 %91
  %93 = load i16, ptr %92, align 2, !tbaa !16
  %94 = zext i16 %93 to i32
  %95 = getelementptr inbounds [320 x i16], ptr %87, i64 0, i64 %91
  %96 = load i16, ptr %95, align 2, !tbaa !16
  %97 = zext i16 %96 to i32
  %98 = getelementptr inbounds [320 x i16], ptr %78, i64 0, i64 %indvars.iv
  %99 = load i16, ptr %98, align 2, !tbaa !16
  %100 = zext i16 %99 to i32
  %101 = getelementptr inbounds [320 x i16], ptr %87, i64 0, i64 %indvars.iv
  %102 = load i16, ptr %101, align 2, !tbaa !16
  %103 = zext i16 %102 to i32
  %104 = trunc nsw i64 %indvars.iv to i32
  tail call void @R_MakeSpans(i32 noundef %104, i32 noundef %94, i32 noundef %97, i32 noundef %100, i32 noundef %103)
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %.not = icmp sgt i64 %indvars.iv, %89
  br i1 %.not, label %._crit_edge.loopexit, label %90, !llvm.loop !21

._crit_edge.loopexit:                             ; preds = %90
  %.pre = load ptr, ptr @ds_source, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %59
  %105 = phi ptr [ %.pre, %._crit_edge.loopexit ], [ %66, %59 ]
  %106 = getelementptr inbounds i8, ptr %105, i64 -28
  %107 = load i32, ptr %106, align 4, !tbaa !22
  %.not45 = icmp eq i32 %107, 1919505
  br i1 %.not45, label %109, label %108

108:                                              ; preds = %._crit_edge
  tail call void (ptr, ...) @I_Error(ptr noundef nonnull @.str.5, i32 noundef 430) #5
  unreachable

109:                                              ; preds = %._crit_edge
  tail call void @Z_ChangeTag2(ptr noundef nonnull %105, i32 noundef 101) #6
  br label %.loopexit

.loopexit:                                        ; preds = %56, %.lr.ph55, %109
  %110 = getelementptr inbounds i8, ptr %.054, i64 1308
  %111 = load ptr, ptr @lastvisplane, align 8, !tbaa !5
  %112 = icmp ult ptr %110, %111
  br i1 %112, label %.lr.ph55, label %._crit_edge56, !llvm.loop !24

._crit_edge56:                                    ; preds = %.loopexit, %.preheader
  ret void
}

declare ptr @R_GetColumn(i32 noundef, i32 noundef) local_unnamed_addr #2

declare ptr @W_CacheLumpNum(i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

declare void @Z_ChangeTag2(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

attributes #0 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { noreturn nounwind }
attributes #6 = { 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, !11, i64 12}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !12, i64 20, !7, i64 22, !12, i64 662, !12, i64 664, !7, i64 666, !12, i64 1306}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!10, !11, i64 16}
!14 = !{!10, !11, i64 4}
!15 = !{!11, !11, i64 0}
!16 = !{!12, !12, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!10, !11, i64 0}
!20 = !{!10, !11, i64 8}
!21 = distinct !{!21, !18}
!22 = !{!23, !11, i64 20}
!23 = !{!"memblock_s", !11, i64 0, !11, i64 4, !6, i64 8, !11, i64 16, !11, i64 20, !6, i64 24, !6, i64 32, !11, i64 40}
!24 = distinct !{!24, !18}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass