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

@_ZN2rw3d3d18nativeRasterOffsetE = external global i32, align 4
@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@_ZN2rw3d3d13isP8supportedE = 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 @_ZN2rw9findChunkEPNS_6StreamEjPjS2_(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

declare noundef ptr @_ZN2rw9dbgsprintEjz(i32 noundef, ...) #1

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) #1

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

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

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

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 noundef ptr @_ZN2rw6Raster6createEiiiii(i32 noundef, i32 noundef, i32 noundef, 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 noundef ptr @_ZN2rw4d3d817readNativeTextureEPNS_6StreamE(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca %"struct.rw::Error", align 4
  %6 = alloca i32, align 4
  %7 = alloca %"struct.rw::Error", align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = alloca ptr, align 8
  %22 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = call noundef zeroext i1 @_ZN2rw9findChunkEPNS_6StreamEjPjS2_(ptr noundef %23, i32 noundef 1, ptr noundef null, ptr noundef null)
  br i1 %24, label %36, label %25

25:                                               ; preds = %1
  br label %26

26:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %27 = getelementptr inbounds %"struct.rw::Error", ptr %5, i32 0, i32 0
  store i32 2, ptr %27, align 4, !tbaa !9
  %28 = getelementptr inbounds %"struct.rw::Error", ptr %5, i32 0, i32 1
  store i32 -2147483644, ptr %28, align 4, !tbaa !12
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 535) #4
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  %32 = call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483644, ptr noundef @.str.3)
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef @.str.2, ptr noundef %32) #4
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef %5)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %34

34:                                               ; preds = %26
  br label %35

35:                                               ; preds = %34
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %221

36:                                               ; preds = %1
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = call noundef i32 @_ZN2rw6Stream7readU32Ev(ptr noundef nonnull align 8 dereferenceable(8) %37)
  store i32 %38, ptr %4, align 4, !tbaa !13
  %39 = load i32, ptr %4, align 4, !tbaa !13
  %40 = icmp ne i32 %39, 8
  br i1 %40, label %41, label %53

41:                                               ; preds = %36
  br label %42

42:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %43 = getelementptr inbounds %"struct.rw::Error", ptr %7, i32 0, i32 0
  store i32 2, ptr %43, align 4, !tbaa !9
  %44 = getelementptr inbounds %"struct.rw::Error", ptr %7, i32 0, i32 1
  store i32 -2147483642, ptr %44, align 4, !tbaa !12
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 540) #4
  %47 = load ptr, ptr @stderr, align 8, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !13
  %49 = call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483642, i32 noundef %48)
  %50 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef @.str.2, ptr noundef %49) #4
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef %7)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %51

51:                                               ; preds = %42
  br label %52

52:                                               ; preds = %51
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %221

53:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %54 = call noundef ptr @_ZN2rw7Texture6createEPNS_6RasterE(ptr noundef null)
  store ptr %54, ptr %8, align 8, !tbaa !5
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = icmp eq ptr %55, null
  br i1 %56, label %57, label %58

57:                                               ; preds = %53
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %220

58:                                               ; preds = %53
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = call noundef i32 @_ZN2rw6Stream7readU32Ev(ptr noundef nonnull align 8 dereferenceable(8) %59)
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %"struct.rw::Texture", ptr %61, i32 0, i32 5
  store i32 %60, ptr %62, align 8, !tbaa !14
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds %"struct.rw::Texture", ptr %64, i32 0, i32 3
  %66 = getelementptr inbounds [32 x i8], ptr %65, i64 0, i64 0
  %67 = load ptr, ptr %63, align 8, !tbaa !17
  %68 = getelementptr inbounds ptr, ptr %67, i64 4
  %69 = load ptr, ptr %68, align 8
  %70 = call noundef i32 %69(ptr noundef nonnull align 8 dereferenceable(8) %63, ptr noundef %66, i32 noundef 32)
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds %"struct.rw::Texture", ptr %72, i32 0, i32 4
  %74 = getelementptr inbounds [32 x i8], ptr %73, i64 0, i64 0
  %75 = load ptr, ptr %71, align 8, !tbaa !17
  %76 = getelementptr inbounds ptr, ptr %75, i64 4
  %77 = load ptr, ptr %76, align 8
  %78 = call noundef i32 %77(ptr noundef nonnull align 8 dereferenceable(8) %71, ptr noundef %74, i32 noundef 32)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = call noundef i32 @_ZN2rw6Stream7readU32Ev(ptr noundef nonnull align 8 dereferenceable(8) %79)
  store i32 %80, ptr %9, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %81)
  store i32 %82, ptr %10, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = call noundef zeroext i16 @_ZN2rw6Stream7readU16Ev(ptr noundef nonnull align 8 dereferenceable(8) %83)
  %85 = zext i16 %84 to i32
  store i32 %85, ptr %11, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = call noundef zeroext i16 @_ZN2rw6Stream7readU16Ev(ptr noundef nonnull align 8 dereferenceable(8) %86)
  %88 = zext i16 %87 to i32
  store i32 %88, ptr %12, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = call noundef zeroext i8 @_ZN2rw6Stream6readU8Ev(ptr noundef nonnull align 8 dereferenceable(8) %89)
  %91 = zext i8 %90 to i32
  store i32 %91, ptr %13, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %92 = load ptr, ptr %3, align 8, !tbaa !5
  %93 = call noundef zeroext i8 @_ZN2rw6Stream6readU8Ev(ptr noundef nonnull align 8 dereferenceable(8) %92)
  %94 = zext i8 %93 to i32
  store i32 %94, ptr %14, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  %96 = call noundef zeroext i8 @_ZN2rw6Stream6readU8Ev(ptr noundef nonnull align 8 dereferenceable(8) %95)
  %97 = zext i8 %96 to i32
  store i32 %97, ptr %15, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = call noundef zeroext i8 @_ZN2rw6Stream6readU8Ev(ptr noundef nonnull align 8 dereferenceable(8) %98)
  %100 = zext i8 %99 to i32
  store i32 %100, ptr %16, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  store i32 0, ptr %17, align 4, !tbaa !13
  %101 = load i32, ptr %9, align 4, !tbaa !13
  %102 = and i32 %101, 16384
  %103 = icmp ne i32 %102, 0
  br i1 %103, label %108, label %104

104:                                              ; preds = %58
  %105 = load i32, ptr %9, align 4, !tbaa !13
  %106 = and i32 %105, 8192
  %107 = icmp ne i32 %106, 0
  br i1 %107, label %108, label %130

108:                                              ; preds = %104, %58
  %109 = load i32, ptr %9, align 4, !tbaa !13
  %110 = and i32 %109, 16384
  %111 = icmp ne i32 %110, 0
  %112 = zext i1 %111 to i64
  %113 = select i1 %111, i32 32, i32 256
  store i32 %113, ptr %17, align 4, !tbaa !13
  %114 = load i32, ptr @_ZN2rw3d3d13isP8supportedE, align 4, !tbaa !13
  %115 = icmp ne i32 %114, 0
  br i1 %115, label %129, label %116

116:                                              ; preds = %108
  %117 = load ptr, ptr %3, align 8, !tbaa !5
  %118 = load i32, ptr %11, align 4, !tbaa !13
  %119 = load i32, ptr %12, align 4, !tbaa !13
  %120 = load i32, ptr %13, align 4, !tbaa !13
  %121 = load i32, ptr %9, align 4, !tbaa !13
  %122 = load i32, ptr %15, align 4, !tbaa !13
  %123 = or i32 %121, %122
  %124 = load i32, ptr %14, align 4, !tbaa !13
  %125 = call noundef ptr @_ZN2rw4d3d811readAsImageEPNS_6StreamEiiiii(ptr noundef %117, i32 noundef %118, i32 noundef %119, i32 noundef %120, i32 noundef %123, i32 noundef %124)
  %126 = load ptr, ptr %8, align 8, !tbaa !5
  %127 = getelementptr inbounds %"struct.rw::Texture", ptr %126, i32 0, i32 0
  store ptr %125, ptr %127, align 8, !tbaa !19
  %128 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %128, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %219

129:                                              ; preds = %108
  br label %130

130:                                              ; preds = %129, %104
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %131 = load i32, ptr %16, align 4, !tbaa !13
  %132 = icmp ne i32 %131, 0
  br i1 %132, label %133, label %152

133:                                              ; preds = %130
  %134 = load i32, ptr %11, align 4, !tbaa !13
  %135 = load i32, ptr %12, align 4, !tbaa !13
  %136 = load i32, ptr %13, align 4, !tbaa !13
  %137 = load i32, ptr %9, align 4, !tbaa !13
  %138 = load i32, ptr %15, align 4, !tbaa !13
  %139 = or i32 %137, %138
  %140 = or i32 %139, 128
  %141 = call noundef ptr @_ZN2rw6Raster6createEiiiii(i32 noundef %134, i32 noundef %135, i32 noundef %136, i32 noundef %140, i32 noundef 8)
  store ptr %141, ptr %18, align 8, !tbaa !5
  %142 = load ptr, ptr %18, align 8, !tbaa !5
  %143 = load i32, ptr @_ZN2rw3d3d18nativeRasterOffsetE, align 4, !tbaa !13
  %144 = sext i32 %143 to i64
  %145 = getelementptr inbounds i8, ptr %142, i64 %144
  store ptr %145, ptr %19, align 8, !tbaa !5
  %146 = load ptr, ptr %18, align 8, !tbaa !5
  %147 = load i32, ptr %16, align 4, !tbaa !13
  %148 = load i32, ptr %14, align 4, !tbaa !13
  %149 = load i32, ptr %10, align 4, !tbaa !13
  call void @_ZN2rw3d3d11allocateDXTEPNS_6RasterEiii(ptr noundef %146, i32 noundef %147, i32 noundef %148, i32 noundef %149)
  %150 = load ptr, ptr %19, align 8, !tbaa !5
  %151 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %150, i32 0, i32 6
  store i8 1, ptr %151, align 1, !tbaa !20
  br label %164

152:                                              ; preds = %130
  %153 = load i32, ptr %11, align 4, !tbaa !13
  %154 = load i32, ptr %12, align 4, !tbaa !13
  %155 = load i32, ptr %13, align 4, !tbaa !13
  %156 = load i32, ptr %9, align 4, !tbaa !13
  %157 = load i32, ptr %15, align 4, !tbaa !13
  %158 = or i32 %156, %157
  %159 = call noundef ptr @_ZN2rw6Raster6createEiiiii(i32 noundef %153, i32 noundef %154, i32 noundef %155, i32 noundef %158, i32 noundef 8)
  store ptr %159, ptr %18, align 8, !tbaa !5
  %160 = load ptr, ptr %18, align 8, !tbaa !5
  %161 = load i32, ptr @_ZN2rw3d3d18nativeRasterOffsetE, align 4, !tbaa !13
  %162 = sext i32 %161 to i64
  %163 = getelementptr inbounds i8, ptr %160, i64 %162
  store ptr %163, ptr %19, align 8, !tbaa !5
  br label %164

164:                                              ; preds = %152, %133
  %165 = load ptr, ptr %18, align 8, !tbaa !5
  %166 = load ptr, ptr %8, align 8, !tbaa !5
  %167 = getelementptr inbounds %"struct.rw::Texture", ptr %166, i32 0, i32 0
  store ptr %165, ptr %167, align 8, !tbaa !19
  %168 = load i32, ptr %17, align 4, !tbaa !13
  %169 = icmp ne i32 %168, 0
  br i1 %169, label %170, label %181

170:                                              ; preds = %164
  %171 = load ptr, ptr %3, align 8, !tbaa !5
  %172 = load ptr, ptr %19, align 8, !tbaa !5
  %173 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %172, i32 0, i32 1
  %174 = load ptr, ptr %173, align 8, !tbaa !23
  %175 = load i32, ptr %17, align 4, !tbaa !13
  %176 = mul nsw i32 4, %175
  %177 = load ptr, ptr %171, align 8, !tbaa !17
  %178 = getelementptr inbounds ptr, ptr %177, i64 4
  %179 = load ptr, ptr %178, align 8
  %180 = call noundef i32 %179(ptr noundef nonnull align 8 dereferenceable(8) %171, ptr noundef %174, i32 noundef %176)
  br label %181

181:                                              ; preds = %170, %164
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #4
  store i32 0, ptr %22, align 4, !tbaa !13
  br label %182

182:                                              ; preds = %214, %181
  %183 = load i32, ptr %22, align 4, !tbaa !13
  %184 = load i32, ptr %14, align 4, !tbaa !13
  %185 = icmp slt i32 %183, %184
  br i1 %185, label %187, label %186

186:                                              ; preds = %182
  store i32 6, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #4
  br label %217

187:                                              ; preds = %182
  %188 = load ptr, ptr %3, align 8, !tbaa !5
  %189 = call noundef i32 @_ZN2rw6Stream7readU32Ev(ptr noundef nonnull align 8 dereferenceable(8) %188)
  store i32 %189, ptr %20, align 4, !tbaa !13
  %190 = load i32, ptr %22, align 4, !tbaa !13
  %191 = load ptr, ptr %18, align 8, !tbaa !5
  %192 = call noundef i32 @_ZN2rw6Raster12getNumLevelsEv(ptr noundef nonnull align 8 dereferenceable(96) %191)
  %193 = icmp slt i32 %190, %192
  br i1 %193, label %194, label %207

194:                                              ; preds = %187
  %195 = load ptr, ptr %18, align 8, !tbaa !5
  %196 = load i32, ptr %22, align 4, !tbaa !13
  %197 = call noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96) %195, i32 noundef %196, i32 noundef 5)
  store ptr %197, ptr %21, align 8, !tbaa !5
  %198 = load ptr, ptr %3, align 8, !tbaa !5
  %199 = load ptr, ptr %21, align 8, !tbaa !5
  %200 = load i32, ptr %20, align 4, !tbaa !13
  %201 = load ptr, ptr %198, align 8, !tbaa !17
  %202 = getelementptr inbounds ptr, ptr %201, i64 4
  %203 = load ptr, ptr %202, align 8
  %204 = call noundef i32 %203(ptr noundef nonnull align 8 dereferenceable(8) %198, ptr noundef %199, i32 noundef %200)
  %205 = load ptr, ptr %18, align 8, !tbaa !5
  %206 = load i32, ptr %22, align 4, !tbaa !13
  call void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96) %205, i32 noundef %206)
  br label %213

207:                                              ; preds = %187
  %208 = load ptr, ptr %3, align 8, !tbaa !5
  %209 = load i32, ptr %20, align 4, !tbaa !13
  %210 = load ptr, ptr %208, align 8, !tbaa !17
  %211 = getelementptr inbounds ptr, ptr %210, i64 5
  %212 = load ptr, ptr %211, align 8
  call void %212(ptr noundef nonnull align 8 dereferenceable(8) %208, i32 noundef %209, i32 noundef 1)
  br label %213

213:                                              ; preds = %207, %194
  br label %214

214:                                              ; preds = %213
  %215 = load i32, ptr %22, align 4, !tbaa !13
  %216 = add nsw i32 %215, 1
  store i32 %216, ptr %22, align 4, !tbaa !13
  br label %182, !llvm.loop !24

217:                                              ; preds = %186
  %218 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %218, ptr %2, align 8
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  br label %219

219:                                              ; preds = %217, %116
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %220

220:                                              ; preds = %219, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %221

221:                                              ; preds = %220, %52, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %222 = load ptr, ptr %2, align 8
  ret ptr %222
}

declare noundef ptr @_ZN2rw7Texture6createEPNS_6RasterE(ptr noundef) #1

declare noundef zeroext i16 @_ZN2rw6Stream7readU16Ev(ptr noundef nonnull align 8 dereferenceable(8)) #1

declare noundef zeroext i8 @_ZN2rw6Stream6readU8Ev(ptr noundef nonnull align 8 dereferenceable(8)) #1

declare void @_ZN2rw3d3d11allocateDXTEPNS_6RasterEiii(ptr noundef, i32 noundef, i32 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 = { nounwind "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, !11, i64 0}
!10 = !{!"_ZTSN2rw5ErrorE", !11, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !11, i64 96}
!15 = !{!"_ZTSN2rw7TextureE", !6, i64 0, !6, i64 8, !16, i64 16, !7, i64 32, !7, i64 64, !11, i64 96, !11, i64 100, !16, i64 104}
!16 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!17 = !{!18, !18, i64 0}
!18 = !{!"vtable pointer", !8, i64 0}
!19 = !{!15, !6, i64 0}
!20 = !{!21, !22, i64 33}
!21 = !{!"_ZTSN2rw3d3d9D3dRasterE", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 28, !22, i64 32, !22, i64 33, !22, i64 34}
!22 = !{!"bool", !7, i64 0}
!23 = !{!21, !6, i64 8}
!24 = distinct !{!24, !25}
!25 = !{!"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"

%"struct.rw::Error" = type { i32, i32 }

@_ZN2rw3d3d18nativeRasterOffsetE = external local_unnamed_addr global i32, align 4
@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@_ZN2rw3d3d13isP8supportedE = external local_unnamed_addr global i32, align 4

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare noundef ptr @_ZN2rw9dbgsprintEjz(i32 noundef, ...) local_unnamed_addr #1

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) local_unnamed_addr #1

declare noundef i32 @_ZN2rw6Stream7readU32Ev(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

declare noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

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

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

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

declare noundef ptr @_ZN2rw6Raster6createEiiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw4d3d817readNativeTextureEPNS_6StreamE(ptr noundef %0) local_unnamed_addr #3 {
  %2 = alloca %"struct.rw::Error", align 4
  %3 = alloca %"struct.rw::Error", align 4
  %4 = tail call noundef zeroext i1 @_ZN2rw9findChunkEPNS_6StreamEjPjS2_(ptr noundef %0, i32 noundef 1, ptr noundef null, ptr noundef null)
  br i1 %4, label %12, label %5

5:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  store i32 2, ptr %2, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 -2147483644, ptr %6, align 4, !tbaa !10
  %7 = load ptr, ptr @stderr, align 8, !tbaa !11
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 535) #5
  %9 = load ptr, ptr @stderr, align 8, !tbaa !11
  %10 = tail call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483644, ptr noundef nonnull @.str.3)
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str.2, ptr noundef %10) #5
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  br label %.loopexit

12:                                               ; preds = %1
  %13 = tail call noundef i32 @_ZN2rw6Stream7readU32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %.not = icmp eq i32 %13, 8
  br i1 %.not, label %21, label %14

14:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  store i32 2, ptr %3, align 4, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 -2147483642, ptr %15, align 4, !tbaa !10
  %16 = load ptr, ptr @stderr, align 8, !tbaa !11
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 540) #5
  %18 = load ptr, ptr @stderr, align 8, !tbaa !11
  %19 = tail call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483642, i32 noundef %13)
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str.2, ptr noundef %19) #5
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  br label %.loopexit

21:                                               ; preds = %12
  %22 = tail call noundef ptr @_ZN2rw7Texture6createEPNS_6RasterE(ptr noundef null)
  %23 = icmp eq ptr %22, null
  br i1 %23, label %.loopexit, label %24

24:                                               ; preds = %21
  %25 = tail call noundef i32 @_ZN2rw6Stream7readU32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %26 = getelementptr inbounds i8, ptr %22, i64 96
  store i32 %25, ptr %26, align 8, !tbaa !13
  %27 = getelementptr inbounds i8, ptr %22, i64 32
  %28 = load ptr, ptr %0, align 8, !tbaa !16
  %29 = getelementptr inbounds i8, ptr %28, i64 32
  %30 = load ptr, ptr %29, align 8
  %31 = tail call noundef i32 %30(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %27, i32 noundef 32)
  %32 = getelementptr inbounds i8, ptr %22, i64 64
  %33 = load ptr, ptr %0, align 8, !tbaa !16
  %34 = getelementptr inbounds i8, ptr %33, i64 32
  %35 = load ptr, ptr %34, align 8
  %36 = tail call noundef i32 %35(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %32, i32 noundef 32)
  %37 = tail call noundef i32 @_ZN2rw6Stream7readU32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %38 = tail call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %39 = tail call noundef zeroext i16 @_ZN2rw6Stream7readU16Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %40 = zext i16 %39 to i32
  %41 = tail call noundef zeroext i16 @_ZN2rw6Stream7readU16Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %42 = zext i16 %41 to i32
  %43 = tail call noundef zeroext i8 @_ZN2rw6Stream6readU8Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %44 = zext i8 %43 to i32
  %45 = tail call noundef zeroext i8 @_ZN2rw6Stream6readU8Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %46 = zext i8 %45 to i32
  %47 = tail call noundef zeroext i8 @_ZN2rw6Stream6readU8Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %48 = zext i8 %47 to i32
  %49 = tail call noundef zeroext i8 @_ZN2rw6Stream6readU8Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %50 = zext i8 %49 to i32
  %51 = and i32 %37, 16384
  %.not78 = icmp eq i32 %51, 0
  br i1 %.not78, label %52, label %54

52:                                               ; preds = %24
  %53 = and i32 %37, 8192
  %.not79 = icmp eq i32 %53, 0
  br i1 %.not79, label %60, label %54

54:                                               ; preds = %52, %24
  %55 = phi i32 [ 256, %52 ], [ 32, %24 ]
  %56 = load i32, ptr @_ZN2rw3d3d13isP8supportedE, align 4, !tbaa !18
  %.not80 = icmp eq i32 %56, 0
  br i1 %.not80, label %57, label %60

57:                                               ; preds = %54
  %58 = or i32 %37, %48
  %59 = tail call noundef ptr @_ZN2rw4d3d811readAsImageEPNS_6StreamEiiiii(ptr noundef nonnull %0, i32 noundef %40, i32 noundef %42, i32 noundef %44, i32 noundef %58, i32 noundef %46)
  store ptr %59, ptr %22, align 8, !tbaa !19
  br label %.loopexit

60:                                               ; preds = %54, %52
  %.074 = phi i32 [ %55, %54 ], [ 0, %52 ]
  %.not81 = icmp eq i8 %49, 0
  %61 = or i32 %37, %48
  br i1 %.not81, label %69, label %62

62:                                               ; preds = %60
  %63 = or i32 %61, 128
  %64 = tail call noundef ptr @_ZN2rw6Raster6createEiiiii(i32 noundef %40, i32 noundef %42, i32 noundef %44, i32 noundef %63, i32 noundef 8)
  %65 = load i32, ptr @_ZN2rw3d3d18nativeRasterOffsetE, align 4, !tbaa !18
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i8, ptr %64, i64 %66
  tail call void @_ZN2rw3d3d11allocateDXTEPNS_6RasterEiii(ptr noundef %64, i32 noundef %50, i32 noundef %46, i32 noundef %38)
  %68 = getelementptr inbounds i8, ptr %67, i64 33
  store i8 1, ptr %68, align 1, !tbaa !20
  br label %74

69:                                               ; preds = %60
  %70 = tail call noundef ptr @_ZN2rw6Raster6createEiiiii(i32 noundef %40, i32 noundef %42, i32 noundef %44, i32 noundef %61, i32 noundef 8)
  %71 = load i32, ptr @_ZN2rw3d3d18nativeRasterOffsetE, align 4, !tbaa !18
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i8, ptr %70, i64 %72
  br label %74

74:                                               ; preds = %69, %62
  %.073 = phi ptr [ %64, %62 ], [ %70, %69 ]
  %.072 = phi ptr [ %67, %62 ], [ %73, %69 ]
  store ptr %.073, ptr %22, align 8, !tbaa !19
  %.not82 = icmp eq i32 %.074, 0
  br i1 %.not82, label %83, label %75

75:                                               ; preds = %74
  %76 = getelementptr inbounds i8, ptr %.072, i64 8
  %77 = load ptr, ptr %76, align 8, !tbaa !23
  %78 = shl nuw nsw i32 %.074, 2
  %79 = load ptr, ptr %0, align 8, !tbaa !16
  %80 = getelementptr inbounds i8, ptr %79, i64 32
  %81 = load ptr, ptr %80, align 8
  %82 = tail call noundef i32 %81(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %77, i32 noundef %78)
  br label %83

83:                                               ; preds = %75, %74
  %.not84 = icmp eq i8 %45, 0
  br i1 %.not84, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %83, %97
  %.083 = phi i32 [ %98, %97 ], [ 0, %83 ]
  %84 = tail call noundef i32 @_ZN2rw6Stream7readU32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %85 = tail call noundef i32 @_ZN2rw6Raster12getNumLevelsEv(ptr noundef nonnull align 8 dereferenceable(96) %.073)
  %86 = icmp slt i32 %.083, %85
  br i1 %86, label %87, label %93

87:                                               ; preds = %.lr.ph
  %88 = tail call noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96) %.073, i32 noundef %.083, i32 noundef 5)
  %89 = load ptr, ptr %0, align 8, !tbaa !16
  %90 = getelementptr inbounds i8, ptr %89, i64 32
  %91 = load ptr, ptr %90, align 8
  %92 = tail call noundef i32 %91(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %88, i32 noundef %84)
  tail call void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96) %.073, i32 noundef %.083)
  br label %97

93:                                               ; preds = %.lr.ph
  %94 = load ptr, ptr %0, align 8, !tbaa !16
  %95 = getelementptr inbounds i8, ptr %94, i64 40
  %96 = load ptr, ptr %95, align 8
  tail call void %96(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %84, i32 noundef 1)
  br label %97

97:                                               ; preds = %87, %93
  %98 = add nuw nsw i32 %.083, 1
  %exitcond.not = icmp eq i32 %98, %46
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !24

.loopexit:                                        ; preds = %97, %83, %21, %57, %14, %5
  %.2 = phi ptr [ null, %14 ], [ null, %5 ], [ null, %21 ], [ %22, %57 ], [ %22, %83 ], [ %22, %97 ]
  ret ptr %.2
}

declare noundef ptr @_ZN2rw7Texture6createEPNS_6RasterE(ptr noundef) local_unnamed_addr #1

declare noundef zeroext i16 @_ZN2rw6Stream7readU16Ev(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

declare noundef zeroext i8 @_ZN2rw6Stream6readU8Ev(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

declare void @_ZN2rw3d3d11allocateDXTEPNS_6RasterEiii(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { nofree nounwind "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 }
attributes #5 = { cold 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, !7, i64 0}
!6 = !{!"_ZTSN2rw5ErrorE", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!14, !7, i64 96}
!14 = !{!"_ZTSN2rw7TextureE", !12, i64 0, !12, i64 8, !15, i64 16, !8, i64 32, !8, i64 64, !7, i64 96, !7, i64 100, !15, i64 104}
!15 = !{!"_ZTSN2rw6LLLinkE", !12, i64 0, !12, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !9, i64 0}
!18 = !{!7, !7, i64 0}
!19 = !{!14, !12, i64 0}
!20 = !{!21, !22, i64 33}
!21 = !{!"_ZTSN2rw3d3d9D3dRasterE", !12, i64 0, !12, i64 8, !12, i64 16, !7, i64 24, !7, i64 28, !22, i64 32, !22, i64 33, !22, i64 34}
!22 = !{!"bool", !8, i64 0}
!23 = !{!21, !12, i64 8}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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