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

@_ZN2rw3gl318nativeRasterOffsetE = external dso_local global i32, align 4
@.str.1 = external hidden unnamed_addr constant [64 x i8], align 1
@_ZN2rw3gl37gl3CapsE = external global %"struct.rw::gl3::Gl3Caps", align 4
@.str.10 = external hidden unnamed_addr constant [27 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw3gl318writeNativeTextureEPNS_7TextureEPNS_6StreamE = external hidden unnamed_addr constant [54 x i8], align 1

; 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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw3gl318writeNativeTextureEPNS_7TextureEPNS_6StreamE(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = 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 8, ptr %5) #5
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %"struct.rw::Texture", ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %16, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i32, ptr @_ZN2rw3gl318nativeRasterOffsetE, align 4, !tbaa !13
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %17, i64 %19
  store ptr %20, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = call noundef i32 @_ZN2rw3gl320getSizeNativeTextureEPNS_7TextureE(ptr noundef %21)
  store i32 %22, ptr %7, align 4, !tbaa !13
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !13
  %25 = sub nsw i32 %24, 12
  %26 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %23, i32 noundef 1, i32 noundef %25)
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %27, i32 noundef 12)
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.rw::Texture", ptr %30, i32 0, i32 5
  %32 = load i32, ptr %31, align 8, !tbaa !14
  %33 = call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %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 3
  %37 = getelementptr inbounds [32 x i8], ptr %36, i64 0, i64 0
  %38 = load ptr, ptr %34, align 8, !tbaa !15
  %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)
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.rw::Texture", ptr %43, i32 0, i32 4
  %45 = getelementptr inbounds [32 x i8], ptr %44, i64 0, i64 0
  %46 = load ptr, ptr %42, align 8, !tbaa !15
  %47 = getelementptr inbounds ptr, ptr %46, i64 3
  %48 = load ptr, ptr %47, align 8
  %49 = call noundef i32 %48(ptr noundef nonnull align 8 dereferenceable(8) %42, ptr noundef %45, i32 noundef 32)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.rw::gl3::Gl3Raster", ptr %50, i32 0, i32 8
  %52 = load i8, ptr %51, align 1, !tbaa !17
  %53 = sext i8 %52 to i32
  store i32 %53, ptr %8, align 4, !tbaa !13
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %"struct.rw::Raster", ptr %55, i32 0, i32 4
  %57 = load i32, ptr %56, align 8, !tbaa !20
  %58 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %54, i32 noundef %57)
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %"struct.rw::Raster", ptr %60, i32 0, i32 5
  %62 = load i32, ptr %61, align 4, !tbaa !22
  %63 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %59, i32 noundef %62)
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %"struct.rw::Raster", ptr %65, i32 0, i32 6
  %67 = load i32, ptr %66, align 8, !tbaa !23
  %68 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %64, i32 noundef %67)
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %"struct.rw::Raster", ptr %70, i32 0, i32 7
  %72 = load i32, ptr %71, align 4, !tbaa !24
  %73 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %69, i32 noundef %72)
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = load i32, ptr %8, align 4, !tbaa !13
  %76 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %74, i32 noundef %75)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !13
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %"struct.rw::gl3::Gl3Raster", ptr %77, i32 0, i32 6
  %79 = load i8, ptr %78, align 1, !tbaa !25, !range !26, !noundef !27
  %80 = trunc i8 %79 to i1
  br i1 %80, label %81, label %84

81:                                               ; preds = %2
  %82 = load i32, ptr %9, align 4, !tbaa !13
  %83 = or i32 %82, 1
  store i32 %83, ptr %9, align 4, !tbaa !13
  br label %84

84:                                               ; preds = %81, %2
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = getelementptr inbounds %"struct.rw::gl3::Gl3Raster", ptr %85, i32 0, i32 5
  %87 = load i8, ptr %86, align 4, !tbaa !28, !range !26, !noundef !27
  %88 = trunc i8 %87 to i1
  br i1 %88, label %89, label %96

89:                                               ; preds = %84
  %90 = load i32, ptr %9, align 4, !tbaa !13
  %91 = or i32 %90, 2
  store i32 %91, ptr %9, align 4, !tbaa !13
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = getelementptr inbounds %"struct.rw::gl3::Gl3Raster", ptr %92, i32 0, i32 0
  %94 = load i32, ptr %93, align 8, !tbaa !29
  switch i32 %94, label %95 [
  ]

95:                                               ; preds = %89
  call void @__assert_fail(ptr noundef @.str.10, ptr noundef @.str.1, i32 noundef 1004, ptr noundef @__PRETTY_FUNCTION__._ZN2rw3gl318writeNativeTextureEPNS_7TextureEPNS_6StreamE) #6
  unreachable

96:                                               ; preds = %84
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = load i32, ptr @_ZN2rw3gl37gl3CapsE, align 4, !tbaa !30
  %99 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %97, i32 noundef %98)
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = load i32, ptr %9, align 4, !tbaa !13
  %102 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %100, i32 noundef %101)
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = load i32, ptr %10, align 4, !tbaa !13
  %105 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %103, i32 noundef %104)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 0, ptr %13, align 4, !tbaa !13
  br label %106

106:                                              ; preds = %130, %96
  %107 = load i32, ptr %13, align 4, !tbaa !13
  %108 = load i32, ptr %8, align 4, !tbaa !13
  %109 = icmp slt i32 %107, %108
  br i1 %109, label %111, label %110

110:                                              ; preds = %106
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %133

111:                                              ; preds = %106
  %112 = load ptr, ptr %5, align 8, !tbaa !5
  %113 = load i32, ptr %13, align 4, !tbaa !13
  %114 = call noundef i32 @_ZN2rw3gl3L12getLevelSizeEPNS_6RasterEi(ptr noundef %112, i32 noundef %113)
  store i32 %114, ptr %11, align 4, !tbaa !13
  %115 = load ptr, ptr %4, align 8, !tbaa !5
  %116 = load i32, ptr %11, align 4, !tbaa !13
  %117 = call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %115, i32 noundef %116)
  %118 = load ptr, ptr %5, align 8, !tbaa !5
  %119 = load i32, ptr %13, align 4, !tbaa !13
  %120 = call noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96) %118, i32 noundef %119, i32 noundef 2)
  store ptr %120, ptr %12, align 8, !tbaa !5
  %121 = load ptr, ptr %4, align 8, !tbaa !5
  %122 = load ptr, ptr %12, align 8, !tbaa !5
  %123 = load i32, ptr %11, align 4, !tbaa !13
  %124 = load ptr, ptr %121, align 8, !tbaa !15
  %125 = getelementptr inbounds ptr, ptr %124, i64 3
  %126 = load ptr, ptr %125, align 8
  %127 = call noundef i32 %126(ptr noundef nonnull align 8 dereferenceable(8) %121, ptr noundef %122, i32 noundef %123)
  %128 = load ptr, ptr %5, align 8, !tbaa !5
  %129 = load i32, ptr %13, align 4, !tbaa !13
  call void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96) %128, i32 noundef %129)
  br label %130

130:                                              ; preds = %111
  %131 = load i32, ptr %13, align 4, !tbaa !13
  %132 = add nsw i32 %131, 1
  store i32 %132, ptr %13, align 4, !tbaa !13
  br label %106, !llvm.loop !33

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

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN2rw3gl3L12getLevelSizeEPNS_6RasterEi(ptr noundef, i32 noundef) #4

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


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

%"struct.rw::gl3::Gl3Caps" = type { i32, i32, i8, i8, float }

@_ZN2rw3gl318nativeRasterOffsetE = external dso_local local_unnamed_addr global i32, align 4
@.str.1 = external hidden unnamed_addr constant [64 x i8], align 1
@_ZN2rw3gl37gl3CapsE = external local_unnamed_addr global %"struct.rw::gl3::Gl3Caps", align 4
@.str.10 = external hidden unnamed_addr constant [27 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw3gl318writeNativeTextureEPNS_7TextureEPNS_6StreamE = external hidden unnamed_addr constant [54 x i8], align 1

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

declare noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96), 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 void @_ZN2rw3gl318writeNativeTextureEPNS_7TextureEPNS_6StreamE(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = load i32, ptr @_ZN2rw3gl318nativeRasterOffsetE, align 4, !tbaa !12
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds i8, ptr %3, i64 %5
  %7 = tail call noundef i32 @_ZN2rw3gl320getSizeNativeTextureEPNS_7TextureE(ptr noundef nonnull %0)
  %8 = add nsw i32 %7, -12
  %9 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %1, i32 noundef 1, i32 noundef %8)
  %10 = tail call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef 12)
  %11 = getelementptr inbounds i8, ptr %0, i64 96
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = tail call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %12)
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %15 = load ptr, ptr %1, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %15, i64 24
  %17 = load ptr, ptr %16, align 8
  %18 = tail call noundef i32 %17(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull %14, i32 noundef 32)
  %19 = getelementptr inbounds i8, ptr %0, i64 64
  %20 = load ptr, ptr %1, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %20, i64 24
  %22 = load ptr, ptr %21, align 8
  %23 = tail call noundef i32 %22(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull %19, i32 noundef 32)
  %24 = getelementptr inbounds i8, ptr %6, i64 23
  %25 = load i8, ptr %24, align 1, !tbaa !16
  %26 = sext i8 %25 to i32
  %27 = getelementptr inbounds i8, ptr %3, i64 16
  %28 = load i32, ptr %27, align 8, !tbaa !19
  %29 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %28)
  %30 = getelementptr inbounds i8, ptr %3, i64 20
  %31 = load i32, ptr %30, align 4, !tbaa !21
  %32 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %31)
  %33 = getelementptr inbounds i8, ptr %3, i64 24
  %34 = load i32, ptr %33, align 8, !tbaa !22
  %35 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %34)
  %36 = getelementptr inbounds i8, ptr %3, i64 28
  %37 = load i32, ptr %36, align 4, !tbaa !23
  %38 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %37)
  %39 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %26)
  %40 = getelementptr inbounds i8, ptr %6, i64 20
  %41 = load i8, ptr %40, align 4, !tbaa !24, !range !25, !noundef !26
  %42 = trunc nuw i8 %41 to i1
  br i1 %42, label %43, label %44

43:                                               ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.1, i32 noundef 1004, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN2rw3gl318writeNativeTextureEPNS_7TextureEPNS_6StreamE) #4
  unreachable

44:                                               ; preds = %2
  %45 = getelementptr inbounds i8, ptr %6, i64 21
  %46 = load i8, ptr %45, align 1, !tbaa !27, !range !25, !noundef !26
  %spec.select = zext nneg i8 %46 to i32
  %47 = load i32, ptr @_ZN2rw3gl37gl3CapsE, align 4, !tbaa !28
  %48 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %47)
  %49 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %spec.select)
  %50 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef 0)
  %51 = icmp sgt i8 %25, 0
  br i1 %51, label %.lr.ph, label %._crit_edge

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

.lr.ph:                                           ; preds = %44, %.lr.ph
  %.046 = phi i32 [ %59, %.lr.ph ], [ 0, %44 ]
  %52 = tail call noundef i32 @_ZN2rw3gl3L12getLevelSizeEPNS_6RasterEi(ptr noundef %3, i32 noundef %.046)
  %53 = tail call noundef i32 @_ZN2rw6Stream8writeU32Ej(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %52)
  %54 = tail call noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96) %3, i32 noundef %.046, i32 noundef 2)
  %55 = load ptr, ptr %1, align 8, !tbaa !14
  %56 = getelementptr inbounds i8, ptr %55, i64 24
  %57 = load ptr, ptr %56, align 8
  %58 = tail call noundef i32 %57(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %54, i32 noundef %52)
  tail call void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96) %3, i32 noundef %.046)
  %59 = add nuw nsw i32 %.046, 1
  %exitcond.not = icmp eq i32 %59, %26
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !31
}

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN2rw3gl3L12getLevelSizeEPNS_6RasterEi(ptr noundef, i32 noundef) local_unnamed_addr #3

attributes #0 = { 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 #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 = { 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 #4 = { 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 = !{!"_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 = !{!11, !11, i64 0}
!13 = !{!6, !11, i64 96}
!14 = !{!15, !15, i64 0}
!15 = !{!"vtable pointer", !9, i64 0}
!16 = !{!17, !8, i64 23}
!17 = !{!"_ZTSN2rw3gl39Gl3RasterE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !18, i64 20, !18, i64 21, !18, i64 22, !8, i64 23, !8, i64 24, !8, i64 25, !8, i64 26, !11, i64 28, !11, i64 32, !7, i64 40, !7, i64 48}
!18 = !{!"bool", !8, i64 0}
!19 = !{!20, !11, i64 16}
!20 = !{!"_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}
!21 = !{!20, !11, i64 20}
!22 = !{!20, !11, i64 24}
!23 = !{!20, !11, i64 28}
!24 = !{!17, !18, i64 20}
!25 = !{i8 0, i8 2}
!26 = !{}
!27 = !{!17, !18, i64 21}
!28 = !{!29, !11, i64 0}
!29 = !{!"_ZTSN2rw3gl37Gl3CapsE", !11, i64 0, !11, i64 4, !18, i64 8, !18, i64 9, !30, i64 12}
!30 = !{!"float", !8, i64 0}
!31 = distinct !{!31, !32}
!32 = !{!"llvm.loop.mustprogress"}


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