; LLVM IR from aap/librw :: src/geometry.ll (ZN2rw12MaterialList11streamWriteEPNS_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::MaterialList" = type { ptr, i32, i32 }

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2rw12MaterialList11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %13 = call noundef i32 @_ZN2rw12MaterialList13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(16) %12)
  store i32 %13, ptr %5, align 4, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %14, i32 noundef 8, i32 noundef %15)
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %"struct.rw::MaterialList", ptr %12, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = mul nsw i32 %19, 4
  %21 = add nsw i32 4, %20
  %22 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %17, i32 noundef 1, i32 noundef %21)
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.rw::MaterialList", ptr %12, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %23, i32 noundef %25)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %65, %2
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = getelementptr inbounds %"struct.rw::MaterialList", ptr %12, i32 0, i32 1
  %30 = load i32, ptr %29, align 8, !tbaa !11
  %31 = icmp slt i32 %28, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %27
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %68

33:                                               ; preds = %27
  store i32 -1, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = sub nsw i32 %34, 1
  store i32 %35, ptr %9, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %57, %33
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = icmp sge i32 %37, 0
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  store i32 5, ptr %8, align 4
  br label %60

40:                                               ; preds = %36
  %41 = getelementptr inbounds %"struct.rw::MaterialList", ptr %12, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds ptr, ptr %42, i64 %44
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.rw::MaterialList", ptr %12, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds ptr, ptr %48, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  %53 = icmp eq ptr %46, %52
  br i1 %53, label %54, label %56

54:                                               ; preds = %40
  %55 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %55, ptr %6, align 4, !tbaa !9
  store i32 5, ptr %8, align 4
  br label %60

56:                                               ; preds = %40
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = add nsw i32 %58, -1
  store i32 %59, ptr %9, align 4, !tbaa !9
  br label %36, !llvm.loop !14

60:                                               ; preds = %54, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %61

61:                                               ; preds = %60
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %62, i32 noundef %63)
  br label %65

65:                                               ; preds = %61
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %7, align 4, !tbaa !9
  br label %27, !llvm.loop !16

68:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %69

69:                                               ; preds = %113, %68
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = getelementptr inbounds %"struct.rw::MaterialList", ptr %12, i32 0, i32 1
  %72 = load i32, ptr %71, align 8, !tbaa !11
  %73 = icmp slt i32 %70, %72
  br i1 %73, label %75, label %74

74:                                               ; preds = %69
  store i32 8, ptr %8, align 4
  br label %116

75:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = sub nsw i32 %76, 1
  store i32 %77, ptr %11, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %98, %75
  %79 = load i32, ptr %11, align 4, !tbaa !9
  %80 = icmp sge i32 %79, 0
  br i1 %80, label %82, label %81

81:                                               ; preds = %78
  store i32 11, ptr %8, align 4
  br label %101

82:                                               ; preds = %78
  %83 = getelementptr inbounds %"struct.rw::MaterialList", ptr %12, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8, !tbaa !13
  %85 = load i32, ptr %10, align 4, !tbaa !9
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds ptr, ptr %84, i64 %86
  %88 = load ptr, ptr %87, align 8, !tbaa !5
  %89 = getelementptr inbounds %"struct.rw::MaterialList", ptr %12, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !13
  %91 = load i32, ptr %11, align 4, !tbaa !9
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds ptr, ptr %90, i64 %92
  %94 = load ptr, ptr %93, align 8, !tbaa !5
  %95 = icmp eq ptr %88, %94
  br i1 %95, label %96, label %97

96:                                               ; preds = %82
  store i32 14, ptr %8, align 4
  br label %101

97:                                               ; preds = %82
  br label %98

98:                                               ; preds = %97
  %99 = load i32, ptr %11, align 4, !tbaa !9
  %100 = add nsw i32 %99, -1
  store i32 %100, ptr %11, align 4, !tbaa !9
  br label %78, !llvm.loop !17

101:                                              ; preds = %96, %81
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %102 = load i32, ptr %8, align 4
  switch i32 %102, label %116 [
    i32 11, label %103
    i32 14, label %112
  ]

103:                                              ; preds = %101
  %104 = getelementptr inbounds %"struct.rw::MaterialList", ptr %12, i32 0, i32 0
  %105 = load ptr, ptr %104, align 8, !tbaa !13
  %106 = load i32, ptr %10, align 4, !tbaa !9
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds ptr, ptr %105, i64 %107
  %109 = load ptr, ptr %108, align 8, !tbaa !5
  %110 = load ptr, ptr %4, align 8, !tbaa !5
  %111 = call noundef zeroext i1 @_ZN2rw8Material11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(40) %109, ptr noundef %110)
  br label %112

112:                                              ; preds = %103, %101
  br label %113

113:                                              ; preds = %112
  %114 = load i32, ptr %10, align 4, !tbaa !9
  %115 = add nsw i32 %114, 1
  store i32 %115, ptr %10, align 4, !tbaa !9
  br label %69, !llvm.loop !18

116:                                              ; preds = %101, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %117

117:                                              ; preds = %116
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i1 true
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN2rw8Material11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef) #2 align 2

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

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTSN2rw12MaterialListE", !6, i64 0, !10, i64 8, !10, i64 12}
!13 = !{!12, !6, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}
!18 = distinct !{!18, !15}


; 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"

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2rw12MaterialList11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef i32 @_ZN2rw12MaterialList13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %4 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %1, i32 noundef 8, i32 noundef %3)
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = shl nsw i32 %6, 2
  %8 = add nsw i32 %7, 4
  %9 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %1, i32 noundef 1, i32 noundef %8)
  %10 = load i32, ptr %5, align 8, !tbaa !5
  %11 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %10)
  %12 = load i32, ptr %5, align 8, !tbaa !5
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.preheader31, label %._crit_edge

.preheader31:                                     ; preds = %2, %.split.loop.exit48
  %indvars.iv = phi i64 [ %indvars.iv.next, %.split.loop.exit48 ], [ 0, %2 ]
  %14 = load ptr, ptr %0, align 8
  %15 = getelementptr inbounds ptr, ptr %14, i64 %indvars.iv
  br label %17

.preheader30:                                     ; preds = %.split.loop.exit48
  %16 = icmp sgt i32 %26, 0
  br i1 %16, label %.preheader, label %._crit_edge

17:                                               ; preds = %.preheader31, %19
  %indvars.iv34 = phi i64 [ %indvars.iv, %.preheader31 ], [ %indvars.iv.next35, %19 ]
  %18 = icmp sgt i64 %indvars.iv34, 0
  br i1 %18, label %19, label %.split.loop.exit48

19:                                               ; preds = %17
  %indvars.iv.next35 = add nsw i64 %indvars.iv34, -1
  %20 = load ptr, ptr %15, align 8, !tbaa !11
  %21 = and i64 %indvars.iv.next35, 4294967295
  %22 = getelementptr inbounds ptr, ptr %14, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = icmp eq ptr %20, %23
  br i1 %24, label %.split.loop.exit, label %17, !llvm.loop !12

.split.loop.exit:                                 ; preds = %19
  %indvars.le = trunc i64 %indvars.iv.next35 to i32
  br label %.split.loop.exit48

.split.loop.exit48:                               ; preds = %17, %.split.loop.exit
  %.028 = phi i32 [ %indvars.le, %.split.loop.exit ], [ -1, %17 ]
  %25 = tail call noundef i32 @_ZN2rw6Stream8writeI32Ei(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %.028)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = load i32, ptr %5, align 8, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = icmp slt i64 %indvars.iv.next, %27
  br i1 %28, label %.preheader31, label %.preheader30, !llvm.loop !14

.preheader:                                       ; preds = %.preheader30, %.loopexit
  %29 = phi i32 [ %43, %.loopexit ], [ %26, %.preheader30 ]
  %indvars.iv39 = phi i64 [ %indvars.iv.next40, %.loopexit ], [ 0, %.preheader30 ]
  %30 = load ptr, ptr %0, align 8
  %31 = getelementptr inbounds ptr, ptr %30, i64 %indvars.iv39
  br label %32

32:                                               ; preds = %.preheader, %34
  %indvars.iv41 = phi i64 [ %indvars.iv39, %.preheader ], [ %35, %34 ]
  %33 = icmp sgt i64 %indvars.iv41, 0
  br i1 %33, label %34, label %40

34:                                               ; preds = %32
  %35 = add nsw i64 %indvars.iv41, -1
  %36 = load ptr, ptr %31, align 8, !tbaa !11
  %37 = getelementptr inbounds ptr, ptr %30, i64 %35
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = icmp eq ptr %36, %38
  br i1 %39, label %.loopexit, label %32, !llvm.loop !15

40:                                               ; preds = %32
  %41 = load ptr, ptr %31, align 8, !tbaa !11
  %42 = tail call noundef zeroext i1 @_ZN2rw8Material11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(40) %41, ptr noundef nonnull %1)
  %.pre = load i32, ptr %5, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %34, %40
  %43 = phi i32 [ %.pre, %40 ], [ %29, %34 ]
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %44 = sext i32 %43 to i64
  %45 = icmp slt i64 %indvars.iv.next40, %44
  br i1 %45, label %.preheader, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %.loopexit, %2, %.preheader30
  ret i1 true
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN2rw8Material11streamWriteEPNS_6StreamE(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef) local_unnamed_addr #1 align 2

attributes #0 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!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, !10, i64 8}
!6 = !{!"_ZTSN2rw12MaterialListE", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !13}


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