; LLVM IR from aap/librw :: tools/dumprwtree/dumprwtree.ll (Z9readchunkPN2rw10StreamFileEPNS_15ChunkHeaderInfoEi)

; 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::ChunkHeaderInfo" = type { i32, i32, i32, i32 }

@.str.171 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.172 = external hidden unnamed_addr constant [36 x i8], align 1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9readchunkPN2rw10StreamFileEPNS_15ChunkHeaderInfoEi(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %"struct.rw::ChunkHeaderInfo", align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %19, %3
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %22

17:                                               ; preds = %12
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.171)
  br label %19

19:                                               ; preds = %17
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %7, align 4, !tbaa !9
  br label %12, !llvm.loop !11

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = call noundef ptr @_Z12getChunkNamej(i32 noundef %25)
  store ptr %26, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !15
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = getelementptr inbounds ptr, ptr %32, i64 6
  %34 = load ptr, ptr %33, align 8
  %35 = call noundef i32 %34(ptr noundef nonnull align 8 dereferenceable(16) %31)
  %36 = sub i32 %35, 12
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load ptr, ptr %37, align 8, !tbaa !16
  %39 = getelementptr inbounds ptr, ptr %38, i64 6
  %40 = load ptr, ptr %39, align 8
  %41 = call noundef i32 %40(ptr noundef nonnull align 8 dereferenceable(16) %37)
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 4, !tbaa !13
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.172, ptr noundef %27, i32 noundef %30, i32 noundef %36, i32 noundef %41, i32 noundef %44)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  %48 = getelementptr inbounds ptr, ptr %47, i64 6
  %49 = load ptr, ptr %48, align 8
  %50 = call noundef i32 %49(ptr noundef nonnull align 8 dereferenceable(16) %46)
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !15
  %54 = add i32 %50, %53
  store i32 %54, ptr %9, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %106, %22
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load ptr, ptr %56, align 8, !tbaa !16
  %58 = getelementptr inbounds ptr, ptr %57, i64 6
  %59 = load ptr, ptr %58, align 8
  %60 = call noundef i32 %59(ptr noundef nonnull align 8 dereferenceable(16) %56)
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = icmp ult i32 %60, %61
  br i1 %62, label %63, label %107

63:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #4
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = call noundef zeroext i1 @_ZN2rw19readChunkHeaderInfoEPNS_6StreamEPNS_15ChunkHeaderInfoE(ptr noundef %64, ptr noundef %10)
  %66 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %10, i32 0, i32 2
  %67 = load i32, ptr %66, align 4, !tbaa !18
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %68, i32 0, i32 2
  %70 = load i32, ptr %69, align 4, !tbaa !18
  %71 = icmp eq i32 %67, %70
  br i1 %71, label %72, label %94

72:                                               ; preds = %63
  %73 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %10, i32 0, i32 3
  %74 = load i32, ptr %73, align 4, !tbaa !19
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %75, i32 0, i32 3
  %77 = load i32, ptr %76, align 4, !tbaa !19
  %78 = icmp eq i32 %74, %77
  br i1 %78, label %79, label %94

79:                                               ; preds = %72
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = load i32, ptr %6, align 4, !tbaa !9
  %82 = add nsw i32 %81, 1
  call void @_Z9readchunkPN2rw10StreamFileEPNS_15ChunkHeaderInfoEi(ptr noundef %80, ptr noundef %10, i32 noundef %82)
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %83, i32 0, i32 0
  %85 = load i32, ptr %84, align 4, !tbaa !13
  %86 = icmp eq i32 %85, 1296
  br i1 %86, label %87, label %93

87:                                               ; preds = %79
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = load i32, ptr %9, align 4, !tbaa !9
  %90 = load ptr, ptr %88, align 8, !tbaa !16
  %91 = getelementptr inbounds ptr, ptr %90, i64 5
  %92 = load ptr, ptr %91, align 8
  call void %92(ptr noundef nonnull align 8 dereferenceable(16) %88, i32 noundef %89, i32 noundef 0)
  br label %93

93:                                               ; preds = %87, %79
  br label %103

94:                                               ; preds = %72, %63
  %95 = load ptr, ptr %4, align 8, !tbaa !5
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %96, i32 0, i32 1
  %98 = load i32, ptr %97, align 4, !tbaa !15
  %99 = sub i32 %98, 12
  %100 = load ptr, ptr %95, align 8, !tbaa !16
  %101 = getelementptr inbounds ptr, ptr %100, i64 5
  %102 = load ptr, ptr %101, align 8
  call void %102(ptr noundef nonnull align 8 dereferenceable(16) %95, i32 noundef %99, i32 noundef 1)
  store i32 6, ptr %11, align 4
  br label %104

103:                                              ; preds = %93
  store i32 0, ptr %11, align 4
  br label %104

104:                                              ; preds = %103, %94
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #4
  %105 = load i32, ptr %11, align 4
  switch i32 %105, label %108 [
    i32 0, label %106
    i32 6, label %107
  ]

106:                                              ; preds = %104
  br label %55, !llvm.loop !20

107:                                              ; preds = %104, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  ret void

108:                                              ; preds = %104
  unreachable
}

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

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

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

declare noundef zeroext i1 @_ZN2rw19readChunkHeaderInfoEPNS_6StreamEPNS_15ChunkHeaderInfoE(ptr noundef, ptr 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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTSN2rw15ChunkHeaderInfoE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!15 = !{!14, !10, i64 4}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !8, i64 0}
!18 = !{!14, !10, i64 8}
!19 = !{!14, !10, i64 12}
!20 = distinct !{!20, !12}


; 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::ChunkHeaderInfo" = type { i32, i32, i32, i32 }

@.str.171 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.172 = external hidden unnamed_addr constant [36 x i8], align 1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9readchunkPN2rw10StreamFileEPNS_15ChunkHeaderInfoEi(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca %"struct.rw::ChunkHeaderInfo", align 4
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %3
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = tail call noundef ptr @_Z12getChunkNamej(i32 noundef %6)
  %8 = getelementptr inbounds i8, ptr %1, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !10
  %10 = load ptr, ptr %0, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %10, i64 48
  %12 = load ptr, ptr %11, align 8
  %13 = tail call noundef i32 %12(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %14 = add i32 %13, -12
  %15 = load ptr, ptr %0, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %15, i64 48
  %17 = load ptr, ptr %16, align 8
  %18 = tail call noundef i32 %17(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.172, ptr noundef %7, i32 noundef %9, i32 noundef %14, i32 noundef %18, i32 noundef %19)
  %21 = load ptr, ptr %0, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %21, i64 48
  %23 = load ptr, ptr %22, align 8
  %24 = tail call noundef i32 %23(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %25 = load i32, ptr %8, align 4, !tbaa !10
  %26 = add i32 %25, %24
  %27 = load ptr, ptr %0, align 8, !tbaa !11
  %28 = getelementptr inbounds i8, ptr %27, i64 48
  %29 = load ptr, ptr %28, align 8
  %30 = tail call noundef i32 %29(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %31 = icmp ult i32 %30, %26
  br i1 %31, label %.lr.ph30, label %.loopexit

.lr.ph30:                                         ; preds = %._crit_edge
  %32 = getelementptr inbounds i8, ptr %4, i64 8
  %33 = getelementptr inbounds i8, ptr %1, i64 8
  %34 = getelementptr inbounds i8, ptr %4, i64 12
  %35 = getelementptr inbounds i8, ptr %1, i64 12
  %36 = add nsw i32 %2, 1
  br label %39

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.02328 = phi i32 [ %38, %.lr.ph ], [ 0, %3 ]
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.171)
  %38 = add nuw nsw i32 %.02328, 1
  %exitcond.not = icmp eq i32 %38, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

39:                                               ; preds = %.lr.ph30, %60
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  %40 = call noundef zeroext i1 @_ZN2rw19readChunkHeaderInfoEPNS_6StreamEPNS_15ChunkHeaderInfoE(ptr noundef nonnull %0, ptr noundef nonnull %4)
  %41 = load i32, ptr %32, align 4, !tbaa !15
  %42 = load i32, ptr %33, align 4, !tbaa !15
  %43 = icmp eq i32 %41, %42
  br i1 %43, label %44, label %.thread

44:                                               ; preds = %39
  %45 = load i32, ptr %34, align 4, !tbaa !16
  %46 = load i32, ptr %35, align 4, !tbaa !16
  %47 = icmp eq i32 %45, %46
  br i1 %47, label %48, label %.thread

48:                                               ; preds = %44
  call void @_Z9readchunkPN2rw10StreamFileEPNS_15ChunkHeaderInfoEi(ptr noundef nonnull %0, ptr noundef nonnull %4, i32 noundef %36)
  %49 = load i32, ptr %1, align 4, !tbaa !5
  %50 = icmp eq i32 %49, 1296
  br i1 %50, label %51, label %60

51:                                               ; preds = %48
  %52 = load ptr, ptr %0, align 8, !tbaa !11
  %53 = getelementptr inbounds i8, ptr %52, i64 40
  %54 = load ptr, ptr %53, align 8
  call void %54(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %26, i32 noundef 0)
  br label %60

.thread:                                          ; preds = %39, %44
  %55 = load i32, ptr %8, align 4, !tbaa !10
  %56 = add i32 %55, -12
  %57 = load ptr, ptr %0, align 8, !tbaa !11
  %58 = getelementptr inbounds i8, ptr %57, i64 40
  %59 = load ptr, ptr %58, align 8
  call void %59(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %56, i32 noundef 1)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  br label %.loopexit

60:                                               ; preds = %51, %48
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  %61 = load ptr, ptr %0, align 8, !tbaa !11
  %62 = getelementptr inbounds i8, ptr %61, i64 48
  %63 = load ptr, ptr %62, align 8
  %64 = call noundef i32 %63(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %65 = icmp ult i32 %64, %26
  br i1 %65, label %39, label %.loopexit

.loopexit:                                        ; preds = %60, %._crit_edge, %.thread
  ret void
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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) #2

declare noundef zeroext i1 @_ZN2rw19readChunkHeaderInfoEPNS_6StreamEPNS_15ChunkHeaderInfoE(ptr noundef, ptr noundef) local_unnamed_addr #4

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 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { "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 }

!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 = !{!"_ZTSN2rw15ChunkHeaderInfoE", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!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 = !{!"vtable pointer", !9, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !7, i64 8}
!16 = !{!6, !7, i64 12}


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