; LLVM IR from aap/librw :: src/d3d/d3d8.ll (ZN2rw4d3d818writeNativeTextureEPNS_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 @_ZN2rw4d3d818writeNativeTextureEPNS_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 i32, align 4
  %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 @_ZN2rw4d3d820getSizeNativeTextureEPNS_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 8)
  %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 5
  %59 = load i8, ptr %58, align 8, !tbaa !19, !range !22, !noundef !23
  %60 = trunc i8 %59 to i1
  %61 = zext i1 %60 to i32
  %62 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %56, i32 noundef %61)
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %"struct.rw::Raster", ptr %64, i32 0, i32 5
  %66 = load i32, ptr %65, align 4, !tbaa !24
  %67 = trunc i32 %66 to i16
  %68 = call noundef i32 @_ZN2rw6Stream8writeU16Et(ptr noundef nonnull align 8 dereferenceable(8) %63, i16 noundef zeroext %67)
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %"struct.rw::Raster", ptr %70, i32 0, i32 6
  %72 = load i32, ptr %71, align 8, !tbaa !25
  %73 = trunc i32 %72 to i16
  %74 = call noundef i32 @_ZN2rw6Stream8writeU16Et(ptr noundef nonnull align 8 dereferenceable(8) %69, i16 noundef zeroext %73)
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %"struct.rw::Raster", ptr %76, i32 0, i32 7
  %78 = load i32, ptr %77, align 4, !tbaa !26
  %79 = trunc i32 %78 to i8
  %80 = call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %75, i8 noundef zeroext %79)
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = load i32, ptr %8, align 4, !tbaa !9
  %83 = trunc i32 %82 to i8
  %84 = call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %81, i8 noundef zeroext %83)
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %"struct.rw::Raster", ptr %86, i32 0, i32 1
  %88 = load i32, ptr %87, align 4, !tbaa !27
  %89 = trunc i32 %88 to i8
  %90 = call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %85, i8 noundef zeroext %89)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %91, i32 0, i32 3
  %93 = load i32, ptr %92, align 8, !tbaa !28
  %94 = icmp ne i32 %93, 0
  br i1 %94, label %95, label %105

95:                                               ; preds = %2
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %96, i32 0, i32 3
  %98 = load i32, ptr %97, align 8, !tbaa !28
  switch i32 %98, label %104 [
    i32 827611204, label %99
    i32 844388420, label %100
    i32 861165636, label %101
    i32 877942852, label %102
    i32 894720068, label %103
  ]

99:                                               ; preds = %95
  store i32 1, ptr %9, align 4, !tbaa !9
  br label %104

100:                                              ; preds = %95
  store i32 2, ptr %9, align 4, !tbaa !9
  br label %104

101:                                              ; preds = %95
  store i32 3, ptr %9, align 4, !tbaa !9
  br label %104

102:                                              ; preds = %95
  store i32 4, ptr %9, align 4, !tbaa !9
  br label %104

103:                                              ; preds = %95
  store i32 5, ptr %9, align 4, !tbaa !9
  br label %104

104:                                              ; preds = %103, %102, %101, %100, %99, %95
  br label %105

105:                                              ; preds = %104, %2
  %106 = load ptr, ptr %4, align 8, !tbaa !5
  %107 = load i32, ptr %9, align 4, !tbaa !9
  %108 = trunc i32 %107 to i8
  %109 = call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %106, i8 noundef zeroext %108)
  %110 = load ptr, ptr %6, align 8, !tbaa !5
  %111 = getelementptr inbounds %"struct.rw::Raster", ptr %110, i32 0, i32 4
  %112 = load i32, ptr %111, align 8, !tbaa !17
  %113 = and i32 %112, 16384
  %114 = icmp ne i32 %113, 0
  br i1 %114, label %115, label %124

115:                                              ; preds = %105
  %116 = load ptr, ptr %4, align 8, !tbaa !5
  %117 = load ptr, ptr %7, align 8, !tbaa !5
  %118 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %117, i32 0, i32 1
  %119 = load ptr, ptr %118, align 8, !tbaa !29
  %120 = load ptr, ptr %116, align 8, !tbaa !14
  %121 = getelementptr inbounds ptr, ptr %120, i64 3
  %122 = load ptr, ptr %121, align 8
  %123 = call noundef i32 %122(ptr noundef nonnull align 8 dereferenceable(8) %116, ptr noundef %119, i32 noundef 128)
  br label %140

124:                                              ; preds = %105
  %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, 8192
  %129 = icmp ne i32 %128, 0
  br i1 %129, label %130, label %139

130:                                              ; preds = %124
  %131 = load ptr, ptr %4, align 8, !tbaa !5
  %132 = load ptr, ptr %7, align 8, !tbaa !5
  %133 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %132, i32 0, i32 1
  %134 = load ptr, ptr %133, align 8, !tbaa !29
  %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 1024)
  br label %139

139:                                              ; preds = %130, %124
  br label %140

140:                                              ; preds = %139, %115
  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 %141

141:                                              ; preds = %165, %140
  %142 = load i32, ptr %12, align 4, !tbaa !9
  %143 = load i32, ptr %8, align 4, !tbaa !9
  %144 = icmp slt i32 %142, %143
  br i1 %144, label %146, label %145

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

146:                                              ; preds = %141
  %147 = load ptr, ptr %6, align 8, !tbaa !5
  %148 = load i32, ptr %12, align 4, !tbaa !9
  %149 = call noundef i32 @_ZN2rw3d3d12getLevelSizeEPNS_6RasterEi(ptr noundef %147, i32 noundef %148)
  store i32 %149, ptr %10, align 4, !tbaa !9
  %150 = load ptr, ptr %4, align 8, !tbaa !5
  %151 = load i32, ptr %10, align 4, !tbaa !9
  %152 = call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %150, i32 noundef %151)
  %153 = load ptr, ptr %6, align 8, !tbaa !5
  %154 = load i32, ptr %12, align 4, !tbaa !9
  %155 = call noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96) %153, i32 noundef %154, i32 noundef 2)
  store ptr %155, ptr %11, align 8, !tbaa !5
  %156 = load ptr, ptr %4, align 8, !tbaa !5
  %157 = load ptr, ptr %11, align 8, !tbaa !5
  %158 = load i32, ptr %10, align 4, !tbaa !9
  %159 = load ptr, ptr %156, align 8, !tbaa !14
  %160 = getelementptr inbounds ptr, ptr %159, i64 3
  %161 = load ptr, ptr %160, align 8
  %162 = call noundef i32 %161(ptr noundef nonnull align 8 dereferenceable(8) %156, ptr noundef %157, i32 noundef %158)
  %163 = load ptr, ptr %6, align 8, !tbaa !5
  %164 = load i32, ptr %12, align 4, !tbaa !9
  call void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96) %163, i32 noundef %164)
  br label %165

165:                                              ; preds = %146
  %166 = load i32, ptr %12, align 4, !tbaa !9
  %167 = add nsw i32 %166, 1
  store i32 %167, ptr %12, align 4, !tbaa !9
  br label %141, !llvm.loop !30

168:                                              ; preds = %145
  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 4, 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 @_ZN2rw4d3d820getSizeNativeTextureEPNS_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, !21, i64 32}
!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 = !{i8 0, i8 2}
!23 = !{}
!24 = !{!18, !10, i64 20}
!25 = !{!18, !10, i64 24}
!26 = !{!18, !10, i64 28}
!27 = !{!18, !10, i64 4}
!28 = !{!20, !10, i64 24}
!29 = !{!20, !6, i64 8}
!30 = distinct !{!30, !31}
!31 = !{!"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 @_ZN2rw4d3d818writeNativeTextureEPNS_7TextureEPNS_6StreamE(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call noundef i32 @_ZN2rw4d3d820getSizeNativeTextureEPNS_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 8)
  %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 32
  %29 = load i8, ptr %28, align 8, !tbaa !18, !range !21, !noundef !22
  %30 = zext nneg i8 %29 to i32
  %31 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %30)
  %32 = getelementptr inbounds i8, ptr %20, i64 20
  %33 = load i32, ptr %32, align 4, !tbaa !23
  %34 = trunc i32 %33 to i16
  %35 = tail call noundef i32 @_ZN2rw6Stream8writeU16Et(ptr noundef nonnull align 8 dereferenceable(8) %1, i16 noundef zeroext %34)
  %36 = getelementptr inbounds i8, ptr %20, i64 24
  %37 = load i32, ptr %36, align 8, !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 28
  %41 = load i32, ptr %40, align 4, !tbaa !25
  %42 = trunc i32 %41 to i8
  %43 = tail call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %1, i8 noundef zeroext %42)
  %44 = trunc i32 %24 to i8
  %45 = tail call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %1, i8 noundef zeroext %44)
  %46 = getelementptr inbounds i8, ptr %20, i64 4
  %47 = load i32, ptr %46, align 4, !tbaa !26
  %48 = trunc i32 %47 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 %23, i64 24
  %51 = load i32, ptr %50, align 8, !tbaa !27
  %.not = icmp eq i32 %51, 0
  br i1 %.not, label %56, label %52

52:                                               ; preds = %2
  %53 = add i32 %51, -827611204
  %54 = tail call i32 @llvm.fshl.i32(i32 %53, i32 %53, i32 8)
  %55 = icmp ult i32 %54, 5
  br i1 %55, label %switch.lookup, label %56

switch.lookup:                                    ; preds = %52
  %switch.idx.cast = trunc nuw i32 %54 to i8
  %switch.offset = add nuw nsw i8 %switch.idx.cast, 1
  br label %56

56:                                               ; preds = %switch.lookup, %52, %2
  %.050 = phi i8 [ 0, %52 ], [ 0, %2 ], [ %switch.offset, %switch.lookup ]
  %57 = tail call noundef i32 @_ZN2rw6Stream7writeU8Eh(ptr noundef nonnull align 8 dereferenceable(8) %1, i8 noundef zeroext %.050)
  %58 = load i32, ptr %25, align 8, !tbaa !16
  %59 = and i32 %58, 16384
  %.not52 = icmp eq i32 %59, 0
  br i1 %.not52, label %60, label %.sink.split

60:                                               ; preds = %56
  %61 = and i32 %58, 8192
  %.not53 = icmp eq i32 %61, 0
  br i1 %.not53, label %68, label %.sink.split

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

68:                                               ; preds = %.sink.split, %60
  %69 = icmp sgt i32 %24, 0
  br i1 %69, label %.lr.ph, label %._crit_edge

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2rw4d3d820getSizeNativeTextureEPNS_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

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

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" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 32}
!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 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!17, !11, i64 20}
!24 = !{!17, !11, i64 24}
!25 = !{!17, !11, i64 28}
!26 = !{!17, !11, i64 4}
!27 = !{!19, !11, i64 24}
!28 = !{!19, !7, i64 8}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}


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