; LLVM IR from aap/librw :: src/geometry.ll (ZN2rw12MaterialList10streamReadEPNS_6StreamEPS0_)

; 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::MemoryFunctions" = type { ptr, ptr, ptr, ptr, ptr }
%"struct.rw::Error" = type { i32, i32 }
%"struct.rw::MaterialList" = type { ptr, i32, i32 }

@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@_ZN2rw6Engine8memfuncsE = external global %"struct.rw::MemoryFunctions", align 8
@.str.6 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [9 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: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw10malloc_LOCEmjPKc(i64 noundef, i32 noundef, ptr noundef) #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) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw12MaterialList4initEv(ptr noundef nonnull align 8 dereferenceable(16)) #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2rw12MaterialList6deinitEv(ptr noundef nonnull align 8 dereferenceable(16)) #5 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw12MaterialList10streamReadEPNS_6StreamEPS0_(ptr noundef %0, ptr noundef %1) #5 align 2 {
  %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 %"struct.rw::Error", align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca %"struct.rw::Error", align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call noundef zeroext i1 @_ZN2rw9findChunkEPNS_6StreamEjPjS2_(ptr noundef %13, i32 noundef 1, ptr noundef null, ptr noundef null)
  br i1 %14, label %26, label %15

15:                                               ; preds = %2
  br label %16

16:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %17 = getelementptr inbounds %"struct.rw::Error", ptr %8, i32 0, i32 0
  store i32 7, ptr %17, align 4, !tbaa !9
  %18 = getelementptr inbounds %"struct.rw::Error", ptr %8, i32 0, i32 1
  store i32 -2147483644, ptr %18, align 4, !tbaa !12
  %19 = load ptr, ptr @stderr, align 8, !tbaa !5
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef @.str.2, ptr noundef @.str.3, i32 noundef 771) #6
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483644, ptr noundef @.str.6)
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef @.str.4, ptr noundef %22) #6
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef %8)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %24

24:                                               ; preds = %16
  br label %25

25:                                               ; preds = %24
  br label %119

26:                                               ; preds = %2
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN2rw12MaterialList4initEv(ptr noundef nonnull align 8 dereferenceable(16) %27)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %28)
  store i32 %29, ptr %7, align 4, !tbaa !13
  %30 = load i32, ptr %7, align 4, !tbaa !13
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %26
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %33, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %123

34:                                               ; preds = %26
  %35 = load i32, ptr %7, align 4, !tbaa !13
  %36 = sext i32 %35 to i64
  %37 = mul i64 %36, 8
  %38 = call noundef ptr @_ZN2rw10malloc_LOCEmjPKc(i64 noundef %37, i32 noundef 196615, ptr noundef @.str.21)
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.rw::MaterialList", ptr %39, i32 0, i32 0
  store ptr %38, ptr %40, align 8, !tbaa !14
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.rw::MaterialList", ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %46

45:                                               ; preds = %34
  br label %119

46:                                               ; preds = %34
  %47 = load i32, ptr %7, align 4, !tbaa !13
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.rw::MaterialList", ptr %48, i32 0, i32 2
  store i32 %47, ptr %49, align 4, !tbaa !16
  %50 = load i32, ptr %7, align 4, !tbaa !13
  %51 = mul nsw i32 %50, 4
  %52 = sext i32 %51 to i64
  %53 = call noundef ptr @_ZN2rw10malloc_LOCEmjPKc(i64 noundef %52, i32 noundef 65543, ptr noundef @.str.22)
  store ptr %53, ptr %6, align 8, !tbaa !5
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !13
  %57 = mul nsw i32 %56, 4
  %58 = call noundef i32 @_ZN2rw6Stream6read32EPvj(ptr noundef nonnull align 8 dereferenceable(8) %54, ptr noundef %55, i32 noundef %57)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 0, ptr %11, align 4, !tbaa !13
  br label %59

59:                                               ; preds = %110, %46
  %60 = load i32, ptr %11, align 4, !tbaa !13
  %61 = load i32, ptr %7, align 4, !tbaa !13
  %62 = icmp slt i32 %60, %61
  br i1 %62, label %64, label %63

63:                                               ; preds = %59
  store i32 5, ptr %9, align 4
  br label %113

64:                                               ; preds = %59
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load i32, ptr %11, align 4, !tbaa !13
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i32, ptr %65, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !13
  %70 = icmp sge i32 %69, 0
  br i1 %70, label %71, label %84

71:                                               ; preds = %64
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %"struct.rw::MaterialList", ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !14
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = load i32, ptr %11, align 4, !tbaa !13
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i32, ptr %75, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !13
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds ptr, ptr %74, i64 %80
  %82 = load ptr, ptr %81, align 8, !tbaa !5
  store ptr %82, ptr %10, align 8, !tbaa !5
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZN2rw8Material6addRefEv(ptr noundef nonnull align 8 dereferenceable(40) %83)
  br label %105

84:                                               ; preds = %64
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = call noundef zeroext i1 @_ZN2rw9findChunkEPNS_6StreamEjPjS2_(ptr noundef %85, i32 noundef 7, ptr noundef null, ptr noundef null)
  br i1 %86, label %98, label %87

87:                                               ; preds = %84
  br label %88

88:                                               ; preds = %87
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %89 = getelementptr inbounds %"struct.rw::Error", ptr %12, i32 0, i32 0
  store i32 7, ptr %89, align 4, !tbaa !9
  %90 = getelementptr inbounds %"struct.rw::Error", ptr %12, i32 0, i32 1
  store i32 -2147483644, ptr %90, align 4, !tbaa !12
  %91 = load ptr, ptr @stderr, align 8, !tbaa !5
  %92 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %91, ptr noundef @.str.2, ptr noundef @.str.3, i32 noundef 793) #6
  %93 = load ptr, ptr @stderr, align 8, !tbaa !5
  %94 = call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483644, ptr noundef @.str.23)
  %95 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %93, ptr noundef @.str.4, ptr noundef %94) #6
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef %12)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %96

96:                                               ; preds = %88
  br label %97

97:                                               ; preds = %96
  store i32 4, ptr %9, align 4
  br label %113

98:                                               ; preds = %84
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = call noundef ptr @_ZN2rw8Material10streamReadEPNS_6StreamE(ptr noundef %99)
  store ptr %100, ptr %10, align 8, !tbaa !5
  %101 = load ptr, ptr %10, align 8, !tbaa !5
  %102 = icmp eq ptr %101, null
  br i1 %102, label %103, label %104

103:                                              ; preds = %98
  store i32 4, ptr %9, align 4
  br label %113

104:                                              ; preds = %98
  br label %105

105:                                              ; preds = %104, %71
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = load ptr, ptr %10, align 8, !tbaa !5
  %108 = call noundef i32 @_ZN2rw12MaterialList14appendMaterialEPNS_8MaterialE(ptr noundef nonnull align 8 dereferenceable(16) %106, ptr noundef %107)
  %109 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZN2rw8Material7destroyEv(ptr noundef nonnull align 8 dereferenceable(40) %109)
  br label %110

110:                                              ; preds = %105
  %111 = load i32, ptr %11, align 4, !tbaa !13
  %112 = add nsw i32 %111, 1
  store i32 %112, ptr %11, align 4, !tbaa !13
  br label %59, !llvm.loop !17

113:                                              ; preds = %103, %97, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  %114 = load i32, ptr %9, align 4
  switch i32 %114, label %123 [
    i32 5, label %115
    i32 4, label %119
  ]

115:                                              ; preds = %113
  %116 = load ptr, ptr getelementptr inbounds (%"struct.rw::MemoryFunctions", ptr @_ZN2rw6Engine8memfuncsE, i32 0, i32 2), align 8, !tbaa !19
  %117 = load ptr, ptr %6, align 8, !tbaa !5
  call void %116(ptr noundef %117)
  %118 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %118, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %123

119:                                              ; preds = %113, %45, %25
  %120 = load ptr, ptr getelementptr inbounds (%"struct.rw::MemoryFunctions", ptr @_ZN2rw6Engine8memfuncsE, i32 0, i32 2), align 8, !tbaa !19
  %121 = load ptr, ptr %6, align 8, !tbaa !5
  call void %120(ptr noundef %121)
  %122 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN2rw12MaterialList6deinitEv(ptr noundef nonnull align 8 dereferenceable(16) %122)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %123

123:                                              ; preds = %119, %115, %113, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %124 = load ptr, ptr %3, align 8
  ret ptr %124
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw8Material6addRefEv(ptr noundef nonnull align 8 dereferenceable(40)) #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2rw8Material7destroyEv(ptr noundef nonnull align 8 dereferenceable(40)) #5 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2rw12MaterialList14appendMaterialEPNS_8MaterialE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) #5 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw8Material10streamReadEPNS_6StreamE(ptr noundef) #5 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { 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 = { 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 = { 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 }

!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, !6, i64 0}
!15 = !{!"_ZTSN2rw12MaterialListE", !6, i64 0, !11, i64 8, !11, i64 12}
!16 = !{!15, !11, i64 12}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !6, i64 16}
!20 = !{!"_ZTSN2rw15MemoryFunctionsE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}


; 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::MemoryFunctions" = type { ptr, ptr, ptr, ptr, ptr }
%"struct.rw::Error" = type { i32, i32 }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@_ZN2rw6Engine8memfuncsE = external local_unnamed_addr global %"struct.rw::MemoryFunctions", align 8
@.str.6 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [9 x i8], align 1

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw10malloc_LOCEmjPKc(i64 noundef, i32 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 #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) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw12MaterialList4initEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2rw12MaterialList6deinitEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #5 align 2

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

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

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

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

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

13:                                               ; preds = %2
  tail call void @_ZN2rw12MaterialList4initEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %14 = tail call noundef i32 @_ZN2rw6Stream7readI32Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %52, label %16

16:                                               ; preds = %13
  %17 = sext i32 %14 to i64
  %18 = shl nsw i64 %17, 3
  %19 = tail call noundef ptr @_ZN2rw10malloc_LOCEmjPKc(i64 noundef %18, i32 noundef 196615, ptr noundef nonnull @.str.21)
  store ptr %19, ptr %1, align 8, !tbaa !13
  %20 = icmp eq ptr %19, null
  br i1 %20, label %.thread, label %21

21:                                               ; preds = %16
  %22 = getelementptr inbounds i8, ptr %1, i64 12
  store i32 %14, ptr %22, align 4, !tbaa !15
  %23 = shl nsw i32 %14, 2
  %24 = sext i32 %23 to i64
  %25 = tail call noundef ptr @_ZN2rw10malloc_LOCEmjPKc(i64 noundef %24, i32 noundef 65543, ptr noundef nonnull @.str.22)
  %26 = tail call noundef i32 @_ZN2rw6Stream6read32EPvj(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %25, i32 noundef %23)
  %27 = icmp sgt i32 %14, 0
  br i1 %27, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %21
  %wide.trip.count = zext nneg i32 %14 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %48
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %48 ]
  %28 = getelementptr inbounds i32, ptr %25, i64 %indvars.iv
  %29 = load i32, ptr %28, align 4, !tbaa !16
  %30 = icmp sgt i32 %29, -1
  br i1 %30, label %31, label %36

31:                                               ; preds = %.lr.ph
  %32 = load ptr, ptr %1, align 8, !tbaa !13
  %33 = zext nneg i32 %29 to i64
  %34 = getelementptr inbounds ptr, ptr %32, i64 %33
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  tail call void @_ZN2rw8Material6addRefEv(ptr noundef nonnull align 8 dereferenceable(40) %35)
  br label %48

36:                                               ; preds = %.lr.ph
  %37 = tail call noundef zeroext i1 @_ZN2rw9findChunkEPNS_6StreamEjPjS2_(ptr noundef nonnull %0, i32 noundef 7, ptr noundef null, ptr noundef null)
  br i1 %37, label %45, label %38

38:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  store i32 7, ptr %4, align 4, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 -2147483644, ptr %39, align 4, !tbaa !10
  %40 = load ptr, ptr @stderr, align 8, !tbaa !11
  %41 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, i32 noundef 793) #7
  %42 = load ptr, ptr @stderr, align 8, !tbaa !11
  %43 = tail call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483644, ptr noundef nonnull @.str.23)
  %44 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef nonnull @.str.4, ptr noundef %43) #7
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  br label %.thread

45:                                               ; preds = %36
  %46 = tail call noundef ptr @_ZN2rw8Material10streamReadEPNS_6StreamE(ptr noundef nonnull %0)
  %47 = icmp eq ptr %46, null
  br i1 %47, label %.thread, label %48

48:                                               ; preds = %45, %31
  %.034 = phi ptr [ %35, %31 ], [ %46, %45 ]
  %49 = tail call noundef i32 @_ZN2rw12MaterialList14appendMaterialEPNS_8MaterialE(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull %.034)
  tail call void @_ZN2rw8Material7destroyEv(ptr noundef nonnull align 8 dereferenceable(40) %.034)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %48, %21
  %50 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2rw6Engine8memfuncsE, i64 16), align 8, !tbaa !19
  tail call void %50(ptr noundef %25)
  br label %52

.thread:                                          ; preds = %45, %38, %16, %6
  %.037 = phi ptr [ null, %16 ], [ null, %6 ], [ %25, %38 ], [ %25, %45 ]
  %51 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2rw6Engine8memfuncsE, i64 16), align 8, !tbaa !19
  call void %51(ptr noundef %.037)
  call void @_ZN2rw12MaterialList6deinitEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  br label %52

52:                                               ; preds = %13, %.thread, %._crit_edge
  %.036 = phi ptr [ null, %.thread ], [ %1, %._crit_edge ], [ %1, %13 ]
  ret ptr %.036
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2rw8Material6addRefEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2rw8Material7destroyEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #5 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2rw12MaterialList14appendMaterialEPNS_8MaterialE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) local_unnamed_addr #5 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw8Material10streamReadEPNS_6StreamE(ptr noundef) local_unnamed_addr #5 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { 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 = { 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 = { 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 }

!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, !12, i64 0}
!14 = !{!"_ZTSN2rw12MaterialListE", !12, i64 0, !7, i64 8, !7, i64 12}
!15 = !{!14, !7, i64 12}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !12, i64 16}
!20 = !{!"_ZTSN2rw15MemoryFunctionsE", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}


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