; LLVM IR from aap/librw :: src/gl/gl3raster.ll (ZN2rw3gl317readNativeTextureEPNS_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::gl3::Gl3Caps" = type { i32, i32, i8, i8, float }
%"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 }

@_ZN2rw3gl318nativeRasterOffsetE = external dso_local 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 [64 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@_ZN2rw3gl37gl3CapsE = external global %"struct.rw::gl3::Gl3Caps", align 4
@.str.8 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [7 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw3gl317readNativeTextureEPNS_6StreamE = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw3gl311allocateDXTEPNS_6RasterEiii(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #0

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

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

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

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) #3

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw3gl317readNativeTextureEPNS_6StreamE(ptr noundef %0) #5 {
  %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 %"struct.rw::Error", align 4
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca %"struct.rw::Error", align 4
  %21 = alloca i32, align 4
  %22 = alloca ptr, align 8
  %23 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = call noundef zeroext i1 @_ZN2rw9findChunkEPNS_6StreamEjPjS2_(ptr noundef %24, i32 noundef 1, ptr noundef null, ptr noundef null)
  br i1 %25, label %37, label %26

26:                                               ; preds = %1
  br label %27

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

35:                                               ; preds = %27
  br label %36

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

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

42:                                               ; preds = %37
  br label %43

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

52:                                               ; preds = %43
  br label %53

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

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

58:                                               ; preds = %54
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %192

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

99:                                               ; preds = %59
  %100 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN2rw7Texture7destroyEv(ptr noundef nonnull align 8 dereferenceable(120) %100)
  br label %101

101:                                              ; preds = %99
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #6
  %102 = getelementptr inbounds %"struct.rw::Error", ptr %17, i32 0, i32 0
  store i32 2816, ptr %102, align 4, !tbaa !9
  %103 = getelementptr inbounds %"struct.rw::Error", ptr %17, i32 0, i32 1
  store i32 -2147483642, ptr %103, align 4, !tbaa !12
  %104 = load ptr, ptr @stderr, align 8, !tbaa !5
  %105 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %104, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 928) #6
  %106 = load ptr, ptr @stderr, align 8, !tbaa !5
  %107 = load i32, ptr %4, align 4, !tbaa !13
  %108 = call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483642, i32 noundef %107)
  %109 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %106, ptr noundef @.str.2, ptr noundef %108) #6
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef %17)
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #6
  br label %110

110:                                              ; preds = %101
  br label %111

111:                                              ; preds = %110
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %191

112:                                              ; preds = %59
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #6
  %113 = load i32, ptr %15, align 4, !tbaa !13
  %114 = and i32 %113, 2
  %115 = icmp ne i32 %114, 0
  br i1 %115, label %116, label %144

116:                                              ; preds = %112
  %117 = load i8, ptr getelementptr inbounds (%"struct.rw::gl3::Gl3Caps", ptr @_ZN2rw3gl37gl3CapsE, i32 0, i32 2), align 4, !tbaa !23, !range !24, !noundef !25
  %118 = trunc i8 %117 to i1
  br i1 %118, label %131, label %119

119:                                              ; preds = %116
  %120 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN2rw7Texture7destroyEv(ptr noundef nonnull align 8 dereferenceable(120) %120)
  br label %121

121:                                              ; preds = %119
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #6
  %122 = getelementptr inbounds %"struct.rw::Error", ptr %20, i32 0, i32 0
  store i32 2816, ptr %122, align 4, !tbaa !9
  %123 = getelementptr inbounds %"struct.rw::Error", ptr %20, i32 0, i32 1
  store i32 -2147483636, ptr %123, align 4, !tbaa !12
  %124 = load ptr, ptr @stderr, align 8, !tbaa !5
  %125 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %124, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 937) #6
  %126 = load ptr, ptr @stderr, align 8, !tbaa !5
  %127 = call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483636)
  %128 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %126, ptr noundef @.str.2, ptr noundef %127) #6
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef %20)
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #6
  br label %129

129:                                              ; preds = %121
  br label %130

130:                                              ; preds = %129
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %190

131:                                              ; preds = %116
  %132 = load i32, ptr %10, align 4, !tbaa !13
  %133 = load i32, ptr %11, align 4, !tbaa !13
  %134 = load i32, ptr %12, align 4, !tbaa !13
  %135 = load i32, ptr %9, align 4, !tbaa !13
  %136 = or i32 %135, 4
  %137 = or i32 %136, 128
  %138 = call noundef ptr @_ZN2rw6Raster6createEiiiii(i32 noundef %132, i32 noundef %133, i32 noundef %134, i32 noundef %137, i32 noundef 12)
  store ptr %138, ptr %18, align 8, !tbaa !5
  %139 = load ptr, ptr %18, align 8, !tbaa !5
  %140 = load i32, ptr %16, align 4, !tbaa !13
  %141 = load i32, ptr %13, align 4, !tbaa !13
  %142 = load i32, ptr %15, align 4, !tbaa !13
  %143 = and i32 %142, 1
  call void @_ZN2rw3gl311allocateDXTEPNS_6RasterEiii(ptr noundef %139, i32 noundef %140, i32 noundef %141, i32 noundef %143)
  br label %151

144:                                              ; preds = %112
  %145 = load i32, ptr %10, align 4, !tbaa !13
  %146 = load i32, ptr %11, align 4, !tbaa !13
  %147 = load i32, ptr %12, align 4, !tbaa !13
  %148 = load i32, ptr %9, align 4, !tbaa !13
  %149 = or i32 %148, 4
  %150 = call noundef ptr @_ZN2rw6Raster6createEiiiii(i32 noundef %145, i32 noundef %146, i32 noundef %147, i32 noundef %149, i32 noundef 12)
  store ptr %150, ptr %18, align 8, !tbaa !5
  br label %151

151:                                              ; preds = %144, %131
  %152 = load ptr, ptr %18, align 8, !tbaa !5
  %153 = icmp ne ptr %152, null
  br i1 %153, label %154, label %155

154:                                              ; preds = %151
  br label %157

155:                                              ; preds = %151
  call void @__assert_fail(ptr noundef @.str.9, ptr noundef @.str.1, i32 noundef 945, ptr noundef @__PRETTY_FUNCTION__._ZN2rw3gl317readNativeTextureEPNS_6StreamE) #7
  unreachable

156:                                              ; No predecessors!
  br label %157

157:                                              ; preds = %156, %154
  %158 = load ptr, ptr %18, align 8, !tbaa !5
  %159 = load i32, ptr @_ZN2rw3gl318nativeRasterOffsetE, align 4, !tbaa !13
  %160 = sext i32 %159 to i64
  %161 = getelementptr inbounds i8, ptr %158, i64 %160
  store ptr %161, ptr %19, align 8, !tbaa !5
  %162 = load ptr, ptr %18, align 8, !tbaa !5
  %163 = load ptr, ptr %8, align 8, !tbaa !5
  %164 = getelementptr inbounds %"struct.rw::Texture", ptr %163, i32 0, i32 0
  store ptr %162, ptr %164, align 8, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #6
  store i32 0, ptr %23, align 4, !tbaa !13
  br label %165

165:                                              ; preds = %185, %157
  %166 = load i32, ptr %23, align 4, !tbaa !13
  %167 = load i32, ptr %13, align 4, !tbaa !13
  %168 = icmp slt i32 %166, %167
  br i1 %168, label %170, label %169

169:                                              ; preds = %165
  store i32 10, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #6
  br label %188

170:                                              ; preds = %165
  %171 = load ptr, ptr %3, align 8, !tbaa !5
  %172 = call noundef i32 @_ZN2rw6Stream7readU32Ev(ptr noundef nonnull align 8 dereferenceable(8) %171)
  store i32 %172, ptr %21, align 4, !tbaa !13
  %173 = load ptr, ptr %18, align 8, !tbaa !5
  %174 = load i32, ptr %23, align 4, !tbaa !13
  %175 = call noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96) %173, i32 noundef %174, i32 noundef 5)
  store ptr %175, ptr %22, align 8, !tbaa !5
  %176 = load ptr, ptr %3, align 8, !tbaa !5
  %177 = load ptr, ptr %22, align 8, !tbaa !5
  %178 = load i32, ptr %21, align 4, !tbaa !13
  %179 = load ptr, ptr %176, align 8, !tbaa !17
  %180 = getelementptr inbounds ptr, ptr %179, i64 4
  %181 = load ptr, ptr %180, align 8
  %182 = call noundef i32 %181(ptr noundef nonnull align 8 dereferenceable(8) %176, ptr noundef %177, i32 noundef %178)
  %183 = load ptr, ptr %18, align 8, !tbaa !5
  %184 = load i32, ptr %23, align 4, !tbaa !13
  call void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96) %183, i32 noundef %184)
  br label %185

185:                                              ; preds = %170
  %186 = load i32, ptr %23, align 4, !tbaa !13
  %187 = add nsw i32 %186, 1
  store i32 %187, ptr %23, align 4, !tbaa !13
  br label %165, !llvm.loop !27

188:                                              ; preds = %169
  %189 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %189, ptr %2, align 8
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #6
  br label %190

190:                                              ; preds = %188, %130
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  br label %191

191:                                              ; preds = %190, %111
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %192

192:                                              ; preds = %191, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %193

193:                                              ; preds = %192, %53, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  %194 = load ptr, ptr %2, align 8
  ret ptr %194
}

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

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

declare noundef ptr @_ZN2rw7Texture6createEPNS_6RasterE(ptr noundef) #3

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

declare void @_ZN2rw7Texture7destroyEv(ptr noundef nonnull align 8 dereferenceable(120)) #3

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { noreturn 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { noreturn 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 = !{!20, !11, i64 0}
!20 = !{!"_ZTSN2rw3gl37Gl3CapsE", !11, i64 0, !11, i64 4, !21, i64 8, !21, i64 9, !22, i64 12}
!21 = !{!"bool", !7, i64 0}
!22 = !{!"float", !7, i64 0}
!23 = !{!20, !21, i64 8}
!24 = !{i8 0, i8 2}
!25 = !{}
!26 = !{!15, !6, i64 0}
!27 = distinct !{!27, !28}
!28 = !{!"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::gl3::Gl3Caps" = type { i32, i32, i8, i8, float }
%"struct.rw::Error" = type { i32, i32 }

@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 [64 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@_ZN2rw3gl37gl3CapsE = external local_unnamed_addr global %"struct.rw::gl3::Gl3Caps", align 4
@.str.8 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [7 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw3gl317readNativeTextureEPNS_6StreamE = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw3gl311allocateDXTEPNS_6RasterEiii(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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 #3

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) local_unnamed_addr #3

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #4

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

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

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

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

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

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

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

26:                                               ; preds = %23
  %27 = tail call noundef i32 @_ZN2rw6Stream7readU32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %28 = getelementptr inbounds i8, ptr %24, i64 96
  store i32 %27, ptr %28, align 8, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %24, i64 32
  %30 = load ptr, ptr %0, align 8, !tbaa !16
  %31 = getelementptr inbounds i8, ptr %30, i64 32
  %32 = load ptr, ptr %31, align 8
  %33 = tail call noundef i32 %32(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %29, i32 noundef 32)
  %34 = getelementptr inbounds i8, ptr %24, i64 64
  %35 = load ptr, ptr %0, align 8, !tbaa !16
  %36 = getelementptr inbounds i8, ptr %35, i64 32
  %37 = load ptr, ptr %36, align 8
  %38 = tail call noundef i32 %37(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %34, i32 noundef 32)
  %39 = tail call noundef i32 @_ZN2rw6Stream7readU32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %40 = tail call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %41 = tail call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %42 = tail call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %43 = tail call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %44 = tail call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %45 = tail call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %46 = tail call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %47 = load i32, ptr @_ZN2rw3gl37gl3CapsE, align 4, !tbaa !18
  %.not57 = icmp eq i32 %44, %47
  br i1 %.not57, label %55, label %48

48:                                               ; preds = %26
  tail call void @_ZN2rw7Texture7destroyEv(ptr noundef nonnull align 8 dereferenceable(120) %24)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  store i32 2816, ptr %4, align 4, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 -2147483642, ptr %49, align 4, !tbaa !10
  %50 = load ptr, ptr @stderr, align 8, !tbaa !11
  %51 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %50, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 928) #7
  %52 = load ptr, ptr @stderr, align 8, !tbaa !11
  %53 = tail call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483642, i32 noundef 12)
  %54 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef nonnull @.str.2, ptr noundef %53) #7
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  br label %.loopexit

55:                                               ; preds = %26
  %56 = and i32 %45, 2
  %.not58 = icmp eq i32 %56, 0
  br i1 %.not58, label %71, label %57

57:                                               ; preds = %55
  %58 = load i8, ptr getelementptr inbounds (i8, ptr @_ZN2rw3gl37gl3CapsE, i64 8), align 4, !tbaa !22, !range !23, !noundef !24
  %59 = trunc nuw i8 %58 to i1
  br i1 %59, label %67, label %60

60:                                               ; preds = %57
  tail call void @_ZN2rw7Texture7destroyEv(ptr noundef nonnull align 8 dereferenceable(120) %24)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #6
  store i32 2816, ptr %5, align 4, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %5, i64 4
  store i32 -2147483636, ptr %61, align 4, !tbaa !10
  %62 = load ptr, ptr @stderr, align 8, !tbaa !11
  %63 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %62, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 937) #7
  %64 = load ptr, ptr @stderr, align 8, !tbaa !11
  %65 = tail call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483636)
  %66 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %64, ptr noundef nonnull @.str.2, ptr noundef %65) #7
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %5)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #6
  br label %.loopexit

67:                                               ; preds = %57
  %68 = or i32 %39, 132
  %69 = tail call noundef ptr @_ZN2rw6Raster6createEiiiii(i32 noundef %40, i32 noundef %41, i32 noundef %42, i32 noundef %68, i32 noundef 12)
  %70 = and i32 %45, 1
  tail call void @_ZN2rw3gl311allocateDXTEPNS_6RasterEiii(ptr noundef %69, i32 noundef %46, i32 noundef %43, i32 noundef %70)
  br label %74

71:                                               ; preds = %55
  %72 = or i32 %39, 4
  %73 = tail call noundef ptr @_ZN2rw6Raster6createEiiiii(i32 noundef %40, i32 noundef %41, i32 noundef %42, i32 noundef %72, i32 noundef 12)
  br label %74

74:                                               ; preds = %71, %67
  %.053 = phi ptr [ %69, %67 ], [ %73, %71 ]
  %.not59 = icmp eq ptr %.053, null
  br i1 %.not59, label %75, label %76

75:                                               ; preds = %74
  tail call void @__assert_fail(ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.1, i32 noundef 945, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN2rw3gl317readNativeTextureEPNS_6StreamE) #8
  unreachable

76:                                               ; preds = %74
  store ptr %.053, ptr %24, align 8, !tbaa !25
  %77 = icmp sgt i32 %43, 0
  br i1 %77, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %76, %.lr.ph
  %.060 = phi i32 [ %84, %.lr.ph ], [ 0, %76 ]
  %78 = tail call noundef i32 @_ZN2rw6Stream7readU32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %79 = tail call noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96) %.053, i32 noundef %.060, i32 noundef 5)
  %80 = load ptr, ptr %0, align 8, !tbaa !16
  %81 = getelementptr inbounds i8, ptr %80, i64 32
  %82 = load ptr, ptr %81, align 8
  %83 = tail call noundef i32 %82(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %79, i32 noundef %78)
  tail call void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96) %.053, i32 noundef %.060)
  %84 = add nuw nsw i32 %.060, 1
  %exitcond.not = icmp eq i32 %84, %43
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !26

.loopexit:                                        ; preds = %.lr.ph, %76, %23, %60, %48, %16, %7
  %.3 = phi ptr [ null, %16 ], [ null, %7 ], [ null, %23 ], [ null, %48 ], [ null, %60 ], [ %24, %76 ], [ %24, %.lr.ph ]
  ret ptr %.3
}

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

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

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

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

declare void @_ZN2rw7Texture7destroyEv(ptr noundef nonnull align 8 dereferenceable(120)) local_unnamed_addr #3

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { noreturn 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { cold nounwind }
attributes #8 = { noreturn 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 = !{!19, !7, i64 0}
!19 = !{!"_ZTSN2rw3gl37Gl3CapsE", !7, i64 0, !7, i64 4, !20, i64 8, !20, i64 9, !21, i64 12}
!20 = !{!"bool", !8, i64 0}
!21 = !{!"float", !8, i64 0}
!22 = !{!19, !20, i64 8}
!23 = !{i8 0, i8 2}
!24 = !{}
!25 = !{!14, !12, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}


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