; LLVM IR from aap/librw :: src/d3d/xbox.ll (ZN2rw4xbox18writeNativeTextureEPNS_7TextureEPNS_6StreamE)

; 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.rw::Texture" = type { ptr, ptr, %"struct.rw::LLLink", [32 x i8], [32 x i8], i32, i32, %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }
%"struct.rw::Raster" = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, i32, i32, i32, ptr, i32, i32 }
%"struct.rw::xbox::XboxRaster" = type { ptr, ptr, i32, i32, i8, i8, i32 }

@_ZN2rw4xbox18nativeRasterOffsetE = 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef, i32 noundef, i32 noundef) #1

declare noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #1

declare noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96), i32 noundef, i32 noundef) #1

declare void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96), i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN2rw4xbox12getLevelSizeEPNS_6RasterEi(ptr noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw4xbox18writeNativeTextureEPNS_7TextureEPNS_6StreamE(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = call noundef i32 @_ZN2rw4xbox20getSizeNativeTextureEPNS_7TextureE(ptr noundef %12)
  store i32 %13, ptr %5, align 4, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = sub nsw i32 %15, 12
  %17 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %14, i32 noundef 1, i32 noundef %16)
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %18, i32 noundef 5)
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.rw::Texture", ptr %21, i32 0, i32 5
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %20, i32 noundef %23)
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.rw::Texture", ptr %26, i32 0, i32 3
  %28 = getelementptr inbounds [32 x i8], ptr %27, i64 0, i64 0
  %29 = load ptr, ptr %25, align 8, !tbaa !14
  %30 = getelementptr inbounds ptr, ptr %29, i64 3
  %31 = load ptr, ptr %30, align 8
  %32 = call noundef i32 %31(ptr noundef nonnull align 8 dereferenceable(8) %25, ptr noundef %28, i32 noundef 32)
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.rw::Texture", ptr %34, i32 0, i32 4
  %36 = getelementptr inbounds [32 x i8], ptr %35, i64 0, i64 0
  %37 = load ptr, ptr %33, align 8, !tbaa !14
  %38 = getelementptr inbounds ptr, ptr %37, i64 3
  %39 = load ptr, ptr %38, align 8
  %40 = call noundef i32 %39(ptr noundef nonnull align 8 dereferenceable(8) %33, ptr noundef %36, i32 noundef 32)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.rw::Texture", ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !16
  store ptr %43, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load i32, ptr @_ZN2rw4xbox18nativeRasterOffsetE, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %44, i64 %46
  store ptr %47, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = call noundef i32 @_ZN2rw6Raster12getNumLevelsEv(ptr noundef nonnull align 8 dereferenceable(96) %48)
  store i32 %49, ptr %8, align 4, !tbaa !9
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %"struct.rw::Raster", ptr %51, i32 0, i32 4
  %53 = load i32, ptr %52, align 8, !tbaa !17
  %54 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %50, i32 noundef %53)
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %"struct.rw::xbox::XboxRaster", ptr %56, i32 0, i32 4
  %58 = load i8, ptr %57, align 8, !tbaa !19, !range !22, !noundef !23
  %59 = trunc i8 %58 to i1
  %60 = zext i1 %59 to i16
  %61 = call noundef i32 @_ZN2rw6Stream8writeI16Es(ptr noundef nonnull align 8 dereferenceable(8) %55, i16 noundef signext %60)
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %"struct.rw::xbox::XboxRaster", ptr %63, i32 0, i32 6
  %65 = load i32, ptr %64, align 4, !tbaa !24
  %66 = trunc i32 %65 to i16
  %67 = call noundef i32 @_ZN2rw6Stream8writeI16Es(ptr noundef nonnull align 8 dereferenceable(8) %62, i16 noundef signext %66)
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %"struct.rw::Raster", ptr %69, i32 0, i32 5
  %71 = load i32, ptr %70, align 4, !tbaa !25
  %72 = trunc i32 %71 to i16
  %73 = call noundef i32 @_ZN2rw6Stream8writeU16Et(ptr noundef nonnull align 8 dereferenceable(8) %68, i16 noundef zeroext %72)
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %"struct.rw::Raster", ptr %75, i32 0, i32 6
  %77 = load i32, ptr %76, align 8, !tbaa !26
  %78 = trunc i32 %77 to i16
  %79 = call noundef i32 @_ZN2rw6Stream8writeU16Et(ptr noundef nonnull align 8 dereferenceable(8) %74, i16 noundef zeroext %78)
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %"struct.rw::Raster", ptr %81, i32 0, i32 7
  %83 = load i32, ptr %82, align 4, !tbaa !27
  %84 = trunc i32 %83 to i8
  %85 = call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %80, i8 noundef zeroext %84)
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = load i32, ptr %8, align 4, !tbaa !9
  %88 = trunc i32 %87 to i8
  %89 = call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %86, i8 noundef zeroext %88)
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = load ptr, ptr %6, align 8, !tbaa !5
  %92 = getelementptr inbounds %"struct.rw::Raster", ptr %91, i32 0, i32 1
  %93 = load i32, ptr %92, align 4, !tbaa !28
  %94 = trunc i32 %93 to i8
  %95 = call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %90, i8 noundef zeroext %94)
  %96 = load ptr, ptr %4, align 8, !tbaa !5
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = getelementptr inbounds %"struct.rw::xbox::XboxRaster", ptr %97, i32 0, i32 2
  %99 = load i32, ptr %98, align 8, !tbaa !29
  %100 = trunc i32 %99 to i8
  %101 = call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %96, i8 noundef zeroext %100)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %102

102:                                              ; preds = %115, %2
  %103 = load i32, ptr %10, align 4, !tbaa !9
  %104 = load i32, ptr %8, align 4, !tbaa !9
  %105 = icmp slt i32 %103, %104
  br i1 %105, label %107, label %106

106:                                              ; preds = %102
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %118

107:                                              ; preds = %102
  %108 = load ptr, ptr %3, align 8, !tbaa !5
  %109 = getelementptr inbounds %"struct.rw::Texture", ptr %108, i32 0, i32 0
  %110 = load ptr, ptr %109, align 8, !tbaa !16
  %111 = load i32, ptr %10, align 4, !tbaa !9
  %112 = call noundef i32 @_ZN2rw4xbox12getLevelSizeEPNS_6RasterEi(ptr noundef %110, i32 noundef %111)
  %113 = load i32, ptr %9, align 4, !tbaa !9
  %114 = add nsw i32 %113, %112
  store i32 %114, ptr %9, align 4, !tbaa !9
  br label %115

115:                                              ; preds = %107
  %116 = load i32, ptr %10, align 4, !tbaa !9
  %117 = add nsw i32 %116, 1
  store i32 %117, ptr %10, align 4, !tbaa !9
  br label %102, !llvm.loop !30

118:                                              ; preds = %106
  %119 = load i32, ptr %9, align 4, !tbaa !9
  %120 = add nsw i32 %119, 3
  %121 = and i32 %120, -4
  store i32 %121, ptr %9, align 4, !tbaa !9
  %122 = load ptr, ptr %4, align 8, !tbaa !5
  %123 = load i32, ptr %9, align 4, !tbaa !9
  %124 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %122, i32 noundef %123)
  %125 = load ptr, ptr %6, align 8, !tbaa !5
  %126 = getelementptr inbounds %"struct.rw::Raster", ptr %125, i32 0, i32 4
  %127 = load i32, ptr %126, align 8, !tbaa !17
  %128 = and i32 %127, 16384
  %129 = icmp ne i32 %128, 0
  br i1 %129, label %130, label %139

130:                                              ; preds = %118
  %131 = load ptr, ptr %4, align 8, !tbaa !5
  %132 = load ptr, ptr %7, align 8, !tbaa !5
  %133 = getelementptr inbounds %"struct.rw::xbox::XboxRaster", ptr %132, i32 0, i32 1
  %134 = load ptr, ptr %133, align 8, !tbaa !32
  %135 = load ptr, ptr %131, align 8, !tbaa !14
  %136 = getelementptr inbounds ptr, ptr %135, i64 3
  %137 = load ptr, ptr %136, align 8
  %138 = call noundef i32 %137(ptr noundef nonnull align 8 dereferenceable(8) %131, ptr noundef %134, i32 noundef 128)
  br label %155

139:                                              ; preds = %118
  %140 = load ptr, ptr %6, align 8, !tbaa !5
  %141 = getelementptr inbounds %"struct.rw::Raster", ptr %140, i32 0, i32 4
  %142 = load i32, ptr %141, align 8, !tbaa !17
  %143 = and i32 %142, 8192
  %144 = icmp ne i32 %143, 0
  br i1 %144, label %145, label %154

145:                                              ; preds = %139
  %146 = load ptr, ptr %4, align 8, !tbaa !5
  %147 = load ptr, ptr %7, align 8, !tbaa !5
  %148 = getelementptr inbounds %"struct.rw::xbox::XboxRaster", ptr %147, i32 0, i32 1
  %149 = load ptr, ptr %148, align 8, !tbaa !32
  %150 = load ptr, ptr %146, align 8, !tbaa !14
  %151 = getelementptr inbounds ptr, ptr %150, i64 3
  %152 = load ptr, ptr %151, align 8
  %153 = call noundef i32 %152(ptr noundef nonnull align 8 dereferenceable(8) %146, ptr noundef %149, i32 noundef 1024)
  br label %154

154:                                              ; preds = %145, %139
  br label %155

155:                                              ; preds = %154, %130
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %156 = load ptr, ptr %6, align 8, !tbaa !5
  %157 = call noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96) %156, i32 noundef 0, i32 noundef 2)
  store ptr %157, ptr %11, align 8, !tbaa !5
  %158 = load ptr, ptr %4, align 8, !tbaa !5
  %159 = load ptr, ptr %11, align 8, !tbaa !5
  %160 = load i32, ptr %9, align 4, !tbaa !9
  %161 = load ptr, ptr %158, align 8, !tbaa !14
  %162 = getelementptr inbounds ptr, ptr %161, i64 3
  %163 = load ptr, ptr %162, align 8
  %164 = call noundef i32 %163(ptr noundef nonnull align 8 dereferenceable(8) %158, ptr noundef %159, i32 noundef %160)
  %165 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96) %165, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2rw4xbox20getSizeNativeTextureEPNS_7TextureE(ptr noundef) #3

declare noundef i32 @_ZN2rw6Raster12getNumLevelsEv(ptr noundef nonnull align 8 dereferenceable(96)) #1

declare noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #1

declare noundef i32 @_ZN2rw6Stream8writeI16Es(ptr noundef nonnull align 8 dereferenceable(8), i16 noundef signext) #1

declare noundef i32 @_ZN2rw6Stream8writeU16Et(ptr noundef nonnull align 8 dereferenceable(8), i16 noundef zeroext) #1

declare noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef zeroext) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress 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 = { mustprogress 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 #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 96}
!12 = !{!"_ZTSN2rw7TextureE", !6, i64 0, !6, i64 8, !13, i64 16, !7, i64 32, !7, i64 64, !10, i64 96, !10, i64 100, !13, i64 104}
!13 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"vtable pointer", !8, i64 0}
!16 = !{!12, !6, i64 0}
!17 = !{!18, !10, i64 16}
!18 = !{!"_ZTSN2rw6RasterE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !6, i64 80, !10, i64 88, !10, i64 92}
!19 = !{!20, !21, i64 24}
!20 = !{!"_ZTSN2rw4xbox10XboxRasterE", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !21, i64 24, !21, i64 25, !10, i64 28}
!21 = !{!"bool", !7, i64 0}
!22 = !{i8 0, i8 2}
!23 = !{}
!24 = !{!20, !10, i64 28}
!25 = !{!18, !10, i64 20}
!26 = !{!18, !10, i64 24}
!27 = !{!18, !10, i64 28}
!28 = !{!18, !10, i64 4}
!29 = !{!20, !10, i64 16}
!30 = distinct !{!30, !31}
!31 = !{!"llvm.loop.mustprogress"}
!32 = !{!20, !6, i64 8}


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

@_ZN2rw4xbox18nativeRasterOffsetE = external dso_local local_unnamed_addr global i32, align 4

declare noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #0

declare noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96), i32 noundef, i32 noundef) local_unnamed_addr #0

declare void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96), i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN2rw4xbox12getLevelSizeEPNS_6RasterEi(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw4xbox18writeNativeTextureEPNS_7TextureEPNS_6StreamE(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = tail call noundef i32 @_ZN2rw4xbox20getSizeNativeTextureEPNS_7TextureE(ptr noundef %0)
  %4 = add nsw i32 %3, -12
  %5 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %1, i32 noundef 1, i32 noundef %4)
  %6 = tail call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef 5)
  %7 = getelementptr inbounds i8, ptr %0, i64 96
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = tail call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %8)
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load ptr, ptr %1, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %11, i64 24
  %13 = load ptr, ptr %12, align 8
  %14 = tail call noundef i32 %13(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull %10, i32 noundef 32)
  %15 = getelementptr inbounds i8, ptr %0, i64 64
  %16 = load ptr, ptr %1, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %16, i64 24
  %18 = load ptr, ptr %17, align 8
  %19 = tail call noundef i32 %18(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull %15, i32 noundef 32)
  %20 = load ptr, ptr %0, align 8, !tbaa !14
  %21 = load i32, ptr @_ZN2rw4xbox18nativeRasterOffsetE, align 4, !tbaa !15
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %20, i64 %22
  %24 = tail call noundef i32 @_ZN2rw6Raster12getNumLevelsEv(ptr noundef nonnull align 8 dereferenceable(96) %20)
  %25 = getelementptr inbounds i8, ptr %20, i64 16
  %26 = load i32, ptr %25, align 8, !tbaa !16
  %27 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %26)
  %28 = getelementptr inbounds i8, ptr %23, i64 24
  %29 = load i8, ptr %28, align 8, !tbaa !18, !range !21, !noundef !22
  %30 = zext nneg i8 %29 to i16
  %31 = tail call noundef i32 @_ZN2rw6Stream8writeI16Es(ptr noundef nonnull align 8 dereferenceable(8) %1, i16 noundef signext %30)
  %32 = getelementptr inbounds i8, ptr %23, i64 28
  %33 = load i32, ptr %32, align 4, !tbaa !23
  %34 = trunc i32 %33 to i16
  %35 = tail call noundef i32 @_ZN2rw6Stream8writeI16Es(ptr noundef nonnull align 8 dereferenceable(8) %1, i16 noundef signext %34)
  %36 = getelementptr inbounds i8, ptr %20, i64 20
  %37 = load i32, ptr %36, align 4, !tbaa !24
  %38 = trunc i32 %37 to i16
  %39 = tail call noundef i32 @_ZN2rw6Stream8writeU16Et(ptr noundef nonnull align 8 dereferenceable(8) %1, i16 noundef zeroext %38)
  %40 = getelementptr inbounds i8, ptr %20, i64 24
  %41 = load i32, ptr %40, align 8, !tbaa !25
  %42 = trunc i32 %41 to i16
  %43 = tail call noundef i32 @_ZN2rw6Stream8writeU16Et(ptr noundef nonnull align 8 dereferenceable(8) %1, i16 noundef zeroext %42)
  %44 = getelementptr inbounds i8, ptr %20, i64 28
  %45 = load i32, ptr %44, align 4, !tbaa !26
  %46 = trunc i32 %45 to i8
  %47 = tail call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %1, i8 noundef zeroext %46)
  %48 = trunc i32 %24 to i8
  %49 = tail call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %1, i8 noundef zeroext %48)
  %50 = getelementptr inbounds i8, ptr %20, i64 4
  %51 = load i32, ptr %50, align 4, !tbaa !27
  %52 = trunc i32 %51 to i8
  %53 = tail call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %1, i8 noundef zeroext %52)
  %54 = getelementptr inbounds i8, ptr %23, i64 16
  %55 = load i32, ptr %54, align 8, !tbaa !28
  %56 = trunc i32 %55 to i8
  %57 = tail call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %1, i8 noundef zeroext %56)
  %58 = icmp sgt i32 %24, 0
  br i1 %58, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %59 = add nsw i32 %66, 3
  %60 = and i32 %59, -4
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %.0.lcssa = phi i32 [ 0, %2 ], [ %60, %._crit_edge.loopexit ]
  %61 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %.0.lcssa)
  %62 = load i32, ptr %25, align 8, !tbaa !16
  %63 = and i32 %62, 16384
  %.not = icmp eq i32 %63, 0
  br i1 %.not, label %68, label %.sink.split

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.053 = phi i32 [ %66, %.lr.ph ], [ 0, %2 ]
  %.05052 = phi i32 [ %67, %.lr.ph ], [ 0, %2 ]
  %64 = load ptr, ptr %0, align 8, !tbaa !14
  %65 = tail call noundef i32 @_ZN2rw4xbox12getLevelSizeEPNS_6RasterEi(ptr noundef %64, i32 noundef %.05052)
  %66 = add nsw i32 %65, %.053
  %67 = add nuw nsw i32 %.05052, 1
  %exitcond.not = icmp eq i32 %67, %24
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !29

68:                                               ; preds = %._crit_edge
  %69 = and i32 %62, 8192
  %.not51 = icmp eq i32 %69, 0
  br i1 %.not51, label %76, label %.sink.split

.sink.split:                                      ; preds = %68, %._crit_edge
  %.sink54 = phi i32 [ 128, %._crit_edge ], [ 1024, %68 ]
  %70 = getelementptr inbounds i8, ptr %23, i64 8
  %71 = load ptr, ptr %70, align 8, !tbaa !31
  %72 = load ptr, ptr %1, align 8, !tbaa !12
  %73 = getelementptr inbounds i8, ptr %72, i64 24
  %74 = load ptr, ptr %73, align 8
  %75 = tail call noundef i32 %74(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %71, i32 noundef %.sink54)
  br label %76

76:                                               ; preds = %.sink.split, %68
  %77 = tail call noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96) %20, i32 noundef 0, i32 noundef 2)
  %78 = load ptr, ptr %1, align 8, !tbaa !12
  %79 = getelementptr inbounds i8, ptr %78, i64 24
  %80 = load ptr, ptr %79, align 8
  %81 = tail call noundef i32 %80(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %77, i32 noundef %.0.lcssa)
  tail call void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96) %20, i32 noundef 0)
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2rw4xbox20getSizeNativeTextureEPNS_7TextureE(ptr noundef) local_unnamed_addr #2

declare noundef i32 @_ZN2rw6Raster12getNumLevelsEv(ptr noundef nonnull align 8 dereferenceable(96)) local_unnamed_addr #0

declare noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #0

declare noundef i32 @_ZN2rw6Stream8writeI16Es(ptr noundef nonnull align 8 dereferenceable(8), i16 noundef signext) local_unnamed_addr #0

declare noundef i32 @_ZN2rw6Stream8writeU16Et(ptr noundef nonnull align 8 dereferenceable(8), i16 noundef zeroext) local_unnamed_addr #0

declare noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef zeroext) local_unnamed_addr #0

attributes #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 = { mustprogress 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 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !11, i64 96}
!6 = !{!"_ZTSN2rw7TextureE", !7, i64 0, !7, i64 8, !10, i64 16, !8, i64 32, !8, i64 64, !11, i64 96, !11, i64 100, !10, i64 104}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN2rw6LLLinkE", !7, i64 0, !7, i64 8}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"vtable pointer", !9, i64 0}
!14 = !{!6, !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !11, i64 16}
!17 = !{!"_ZTSN2rw6RasterE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !11, i64 64, !11, i64 68, !11, i64 72, !7, i64 80, !11, i64 88, !11, i64 92}
!18 = !{!19, !20, i64 24}
!19 = !{!"_ZTSN2rw4xbox10XboxRasterE", !7, i64 0, !7, i64 8, !11, i64 16, !11, i64 20, !20, i64 24, !20, i64 25, !11, i64 28}
!20 = !{!"bool", !8, i64 0}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!19, !11, i64 28}
!24 = !{!17, !11, i64 20}
!25 = !{!17, !11, i64 24}
!26 = !{!17, !11, i64 28}
!27 = !{!17, !11, i64 4}
!28 = !{!19, !11, i64 16}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}
!31 = !{!19, !7, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass