; LLVM IR from aap/librw :: src/d3d/d3d9.ll (ZN2rw4d3d918writeNativeTextureEPNS_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::d3d::D3dRaster" = type { ptr, ptr, ptr, i32, i32, i8, i8, i8 }

@_ZN2rw3d3d18nativeRasterOffsetE = external 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 i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #1

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

93:                                               ; preds = %2
  %94 = load i8, ptr %9, align 1, !tbaa !26
  %95 = zext i8 %94 to i32
  %96 = or i32 %95, 1
  %97 = trunc i32 %96 to i8
  store i8 %97, ptr %9, align 1, !tbaa !26
  br label %98

98:                                               ; preds = %93, %2
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  %100 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %99, i32 0, i32 7
  %101 = load i8, ptr %100, align 2, !tbaa !30, !range !28, !noundef !29
  %102 = trunc i8 %101 to i1
  br i1 %102, label %103, label %108

103:                                              ; preds = %98
  %104 = load i8, ptr %9, align 1, !tbaa !26
  %105 = zext i8 %104 to i32
  %106 = or i32 %105, 4
  %107 = trunc i32 %106 to i8
  store i8 %107, ptr %9, align 1, !tbaa !26
  br label %108

108:                                              ; preds = %103, %98
  %109 = load ptr, ptr %7, align 8, !tbaa !5
  %110 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %109, i32 0, i32 6
  %111 = load i8, ptr %110, align 1, !tbaa !31, !range !28, !noundef !29
  %112 = trunc i8 %111 to i1
  br i1 %112, label %113, label %118

113:                                              ; preds = %108
  %114 = load i8, ptr %9, align 1, !tbaa !26
  %115 = zext i8 %114 to i32
  %116 = or i32 %115, 8
  %117 = trunc i32 %116 to i8
  store i8 %117, ptr %9, align 1, !tbaa !26
  br label %118

118:                                              ; preds = %113, %108
  %119 = load ptr, ptr %4, align 8, !tbaa !5
  %120 = load i8, ptr %9, align 1, !tbaa !26
  %121 = call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %119, i8 noundef zeroext %120)
  %122 = load ptr, ptr %6, align 8, !tbaa !5
  %123 = getelementptr inbounds %"struct.rw::Raster", ptr %122, i32 0, i32 4
  %124 = load i32, ptr %123, align 8, !tbaa !17
  %125 = and i32 %124, 16384
  %126 = icmp ne i32 %125, 0
  br i1 %126, label %127, label %136

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

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

142:                                              ; preds = %136
  %143 = load ptr, ptr %4, align 8, !tbaa !5
  %144 = load ptr, ptr %7, align 8, !tbaa !5
  %145 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %144, i32 0, i32 1
  %146 = load ptr, ptr %145, align 8, !tbaa !32
  %147 = load ptr, ptr %143, align 8, !tbaa !14
  %148 = getelementptr inbounds ptr, ptr %147, i64 3
  %149 = load ptr, ptr %148, align 8
  %150 = call noundef i32 %149(ptr noundef nonnull align 8 dereferenceable(8) %143, ptr noundef %146, i32 noundef 1024)
  br label %151

151:                                              ; preds = %142, %136
  br label %152

152:                                              ; preds = %151, %127
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %153

153:                                              ; preds = %177, %152
  %154 = load i32, ptr %12, align 4, !tbaa !9
  %155 = load i32, ptr %8, align 4, !tbaa !9
  %156 = icmp slt i32 %154, %155
  br i1 %156, label %158, label %157

157:                                              ; preds = %153
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %180

158:                                              ; preds = %153
  %159 = load ptr, ptr %6, align 8, !tbaa !5
  %160 = load i32, ptr %12, align 4, !tbaa !9
  %161 = call noundef i32 @_ZN2rw3d3d12getLevelSizeEPNS_6RasterEi(ptr noundef %159, i32 noundef %160)
  store i32 %161, ptr %10, align 4, !tbaa !9
  %162 = load ptr, ptr %4, align 8, !tbaa !5
  %163 = load i32, ptr %10, align 4, !tbaa !9
  %164 = call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %162, i32 noundef %163)
  %165 = load ptr, ptr %6, align 8, !tbaa !5
  %166 = load i32, ptr %12, align 4, !tbaa !9
  %167 = call noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96) %165, i32 noundef %166, i32 noundef 2)
  store ptr %167, ptr %11, align 8, !tbaa !5
  %168 = load ptr, ptr %4, align 8, !tbaa !5
  %169 = load ptr, ptr %11, align 8, !tbaa !5
  %170 = load i32, ptr %10, align 4, !tbaa !9
  %171 = load ptr, ptr %168, align 8, !tbaa !14
  %172 = getelementptr inbounds ptr, ptr %171, i64 3
  %173 = load ptr, ptr %172, align 8
  %174 = call noundef i32 %173(ptr noundef nonnull align 8 dereferenceable(8) %168, ptr noundef %169, i32 noundef %170)
  %175 = load ptr, ptr %6, align 8, !tbaa !5
  %176 = load i32, ptr %12, align 4, !tbaa !9
  call void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96) %175, i32 noundef %176)
  br label %177

177:                                              ; preds = %158
  %178 = load i32, ptr %12, align 4, !tbaa !9
  %179 = add nsw i32 %178, 1
  store i32 %179, ptr %12, align 4, !tbaa !9
  br label %153, !llvm.loop !33

180:                                              ; preds = %157
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

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

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

declare noundef i32 @_ZN2rw3d3d12getLevelSizeEPNS_6RasterEi(ptr noundef, i32 noundef) #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 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 = { 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, !10, i64 24}
!20 = !{!"_ZTSN2rw3d3d9D3dRasterE", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !21, i64 32, !21, i64 33, !21, i64 34}
!21 = !{!"bool", !7, i64 0}
!22 = !{!18, !10, i64 20}
!23 = !{!18, !10, i64 24}
!24 = !{!18, !10, i64 28}
!25 = !{!18, !10, i64 4}
!26 = !{!7, !7, i64 0}
!27 = !{!20, !21, i64 32}
!28 = !{i8 0, i8 2}
!29 = !{}
!30 = !{!20, !21, i64 34}
!31 = !{!20, !21, i64 33}
!32 = !{!20, !6, i64 8}
!33 = distinct !{!33, !34}
!34 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@_ZN2rw3d3d18nativeRasterOffsetE = external 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 i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #0

declare noundef i32 @_ZN2rw6Raster12getNumLevelsEv(ptr noundef nonnull align 8 dereferenceable(96)) 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 uwtable
define dso_local void @_ZN2rw4d3d918writeNativeTextureEPNS_7TextureEPNS_6StreamE(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call noundef i32 @_ZN2rw4d3d920getSizeNativeTextureEPNS_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 9)
  %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 @_ZN2rw3d3d18nativeRasterOffsetE, 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 i32, ptr %28, align 8, !tbaa !18
  %30 = tail call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %29)
  %31 = getelementptr inbounds i8, ptr %20, i64 20
  %32 = load i32, ptr %31, align 4, !tbaa !21
  %33 = trunc i32 %32 to i16
  %34 = tail call noundef i32 @_ZN2rw6Stream8writeU16Et(ptr noundef nonnull align 8 dereferenceable(8) %1, i16 noundef zeroext %33)
  %35 = getelementptr inbounds i8, ptr %20, i64 24
  %36 = load i32, ptr %35, align 8, !tbaa !22
  %37 = trunc i32 %36 to i16
  %38 = tail call noundef i32 @_ZN2rw6Stream8writeU16Et(ptr noundef nonnull align 8 dereferenceable(8) %1, i16 noundef zeroext %37)
  %39 = getelementptr inbounds i8, ptr %20, i64 28
  %40 = load i32, ptr %39, align 4, !tbaa !23
  %41 = trunc i32 %40 to i8
  %42 = tail call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %1, i8 noundef zeroext %41)
  %43 = trunc i32 %24 to i8
  %44 = tail call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %1, i8 noundef zeroext %43)
  %45 = getelementptr inbounds i8, ptr %20, i64 4
  %46 = load i32, ptr %45, align 4, !tbaa !24
  %47 = trunc i32 %46 to i8
  %48 = tail call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %1, i8 noundef zeroext %47)
  %49 = getelementptr inbounds i8, ptr %23, i64 32
  %50 = load i8, ptr %49, align 8, !tbaa !25, !range !26, !noundef !27
  %51 = getelementptr inbounds i8, ptr %23, i64 34
  %52 = load i8, ptr %51, align 2, !tbaa !28, !range !26, !noundef !27
  %53 = trunc nuw i8 %52 to i1
  %54 = or disjoint i8 %50, 4
  %.1 = select i1 %53, i8 %54, i8 %50
  %55 = getelementptr inbounds i8, ptr %23, i64 33
  %56 = load i8, ptr %55, align 1, !tbaa !29, !range !26, !noundef !27
  %57 = trunc nuw i8 %56 to i1
  %58 = or disjoint i8 %.1, 8
  %.2 = select i1 %57, i8 %58, i8 %.1
  %59 = tail call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %1, i8 noundef zeroext %.2)
  %60 = load i32, ptr %25, align 8, !tbaa !16
  %61 = and i32 %60, 16384
  %.not = icmp eq i32 %61, 0
  br i1 %.not, label %62, label %.sink.split

62:                                               ; preds = %2
  %63 = and i32 %60, 8192
  %.not55 = icmp eq i32 %63, 0
  br i1 %.not55, label %70, label %.sink.split

.sink.split:                                      ; preds = %62, %2
  %.sink57 = phi i32 [ 128, %2 ], [ 1024, %62 ]
  %64 = getelementptr inbounds i8, ptr %23, i64 8
  %65 = load ptr, ptr %64, align 8, !tbaa !30
  %66 = load ptr, ptr %1, align 8, !tbaa !12
  %67 = getelementptr inbounds i8, ptr %66, i64 24
  %68 = load ptr, ptr %67, align 8
  %69 = tail call noundef i32 %68(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %65, i32 noundef %.sink57)
  br label %70

70:                                               ; preds = %.sink.split, %62
  %71 = icmp sgt i32 %24, 0
  br i1 %71, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %70
  ret void

.lr.ph:                                           ; preds = %70, %.lr.ph
  %.056 = phi i32 [ %79, %.lr.ph ], [ 0, %70 ]
  %72 = tail call noundef i32 @_ZN2rw3d3d12getLevelSizeEPNS_6RasterEi(ptr noundef nonnull %20, i32 noundef %.056)
  %73 = tail call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %72)
  %74 = tail call noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96) %20, i32 noundef %.056, i32 noundef 2)
  %75 = load ptr, ptr %1, align 8, !tbaa !12
  %76 = getelementptr inbounds i8, ptr %75, i64 24
  %77 = load ptr, ptr %76, align 8
  %78 = tail call noundef i32 %77(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %74, i32 noundef %72)
  tail call void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96) %20, i32 noundef %.056)
  %79 = add nuw nsw i32 %.056, 1
  %exitcond.not = icmp eq i32 %79, %24
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !31
}

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

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

declare noundef i32 @_ZN2rw3d3d12getLevelSizeEPNS_6RasterEi(ptr noundef, i32 noundef) 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 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, !11, i64 24}
!19 = !{!"_ZTSN2rw3d3d9D3dRasterE", !7, i64 0, !7, i64 8, !7, i64 16, !11, i64 24, !11, i64 28, !20, i64 32, !20, i64 33, !20, i64 34}
!20 = !{!"bool", !8, i64 0}
!21 = !{!17, !11, i64 20}
!22 = !{!17, !11, i64 24}
!23 = !{!17, !11, i64 28}
!24 = !{!17, !11, i64 4}
!25 = !{!19, !20, i64 32}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = !{!19, !20, i64 34}
!29 = !{!19, !20, i64 33}
!30 = !{!19, !7, i64 8}
!31 = distinct !{!31, !32}
!32 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass