; LLVM IR from UBIC-repo/core :: Tools/MetricTool.ll (ZN10MetricTool22getPassportBlockSupplyEh)

; 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.UAmount = type { %"class.std::map.8" }
%"class.std::map.8" = type { %"class.std::_Rb_tree.9" }
%"class.std::_Rb_tree.9" = type { %"struct.std::_Rb_tree<unsigned char, std::pair<const unsigned char, unsigned long>, std::_Select1st<std::pair<const unsigned char, unsigned long>>, std::less<unsigned char>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<unsigned char, std::pair<const unsigned char, unsigned long>, std::_Select1st<std::pair<const unsigned char, unsigned long>>, std::less<unsigned char>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"struct.std::_Rb_tree_iterator.18" = type { ptr }
%"struct.std::pair.19" = type { i8, i64 }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZN5Chain8InstanceEv() #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN10MetricTool22getPassportBlockSupplyEh(i8 noundef zeroext %0) #2 align 2 {
  %2 = alloca i64, align 8
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.UAmount, align 8
  %7 = alloca %"struct.std::_Rb_tree_iterator.18", align 8
  %8 = alloca %"struct.std::_Rb_tree_iterator.18", align 8
  %9 = alloca i32, align 4
  %10 = alloca %"struct.std::_Rb_tree_iterator.18", align 8
  store i8 %0, ptr %3, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %11 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZN5Chain8InstanceEv()
  store ptr %11, ptr %4, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !8
  %13 = call noundef ptr @_ZN5Chain18getBestBlockHeaderEv(ptr noundef nonnull align 8 dereferenceable(32) %12)
  store ptr %13, ptr %5, align 8, !tbaa !8
  %14 = load ptr, ptr %5, align 8, !tbaa !8
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %49

16:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 48, ptr %6) #4
  %17 = load ptr, ptr %5, align 8, !tbaa !8
  call void @_ZN11BlockHeader9getPayoutEv(ptr dead_on_unwind writable sret(%struct.UAmount) align 8 %6, ptr noundef nonnull align 8 dereferenceable(400) %17)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %18 = getelementptr inbounds %struct.UAmount, ptr %6, i32 0, i32 0
  %19 = call ptr @_ZNSt3mapIhmSt4lessIhESaISt4pairIKhmEEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48) %18) #4
  %20 = getelementptr inbounds %"struct.std::_Rb_tree_iterator.18", ptr %7, i32 0, i32 0
  store ptr %19, ptr %20, align 8
  br label %21

21:                                               ; preds = %40, %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %22 = getelementptr inbounds %struct.UAmount, ptr %6, i32 0, i32 0
  %23 = call ptr @_ZNSt3mapIhmSt4lessIhESaISt4pairIKhmEEE3endEv(ptr noundef nonnull align 8 dereferenceable(48) %22) #4
  %24 = getelementptr inbounds %"struct.std::_Rb_tree_iterator.18", ptr %8, i32 0, i32 0
  store ptr %23, ptr %24, align 8
  %25 = call noundef zeroext i1 @_ZStneRKSt17_Rb_tree_iteratorISt4pairIKhmEES5_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  store i32 2, ptr %9, align 4
  br label %43

27:                                               ; preds = %21
  %28 = call noundef ptr @_ZNKSt17_Rb_tree_iteratorISt4pairIKhmEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %7) #4
  %29 = getelementptr inbounds %"struct.std::pair.19", ptr %28, i32 0, i32 0
  %30 = load i8, ptr %29, align 8, !tbaa !10
  %31 = zext i8 %30 to i32
  %32 = load i8, ptr %3, align 1, !tbaa !5
  %33 = zext i8 %32 to i32
  %34 = icmp eq i32 %31, %33
  br i1 %34, label %35, label %39

35:                                               ; preds = %27
  %36 = call noundef ptr @_ZNKSt17_Rb_tree_iteratorISt4pairIKhmEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %7) #4
  %37 = getelementptr inbounds %"struct.std::pair.19", ptr %36, i32 0, i32 1
  %38 = load i64, ptr %37, align 8, !tbaa !13
  store i64 %38, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %43

39:                                               ; preds = %27
  br label %40

40:                                               ; preds = %39
  %41 = call ptr @_ZNSt17_Rb_tree_iteratorISt4pairIKhmEEppEi(ptr noundef nonnull align 8 dereferenceable(8) %7, i32 noundef 0) #4
  %42 = getelementptr inbounds %"struct.std::_Rb_tree_iterator.18", ptr %10, i32 0, i32 0
  store ptr %41, ptr %42, align 8
  br label %21, !llvm.loop !14

43:                                               ; preds = %35, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %44 = load i32, ptr %9, align 4
  switch i32 %44, label %46 [
    i32 2, label %45
  ]

45:                                               ; preds = %43
  store i32 0, ptr %9, align 4
  br label %46

46:                                               ; preds = %45, %43
  call void @_ZN7UAmountD2Ev(ptr noundef nonnull align 8 dereferenceable(48) %6) #4
  call void @llvm.lifetime.end.p0(i64 48, ptr %6) #4
  %47 = load i32, ptr %9, align 4
  switch i32 %47, label %50 [
    i32 0, label %48
  ]

48:                                               ; preds = %46
  br label %49

49:                                               ; preds = %48, %1
  store i64 0, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %50

50:                                               ; preds = %49, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %51 = load i64, ptr %2, align 8
  ret i64 %51
}

declare noundef ptr @_ZN5Chain18getBestBlockHeaderEv(ptr noundef nonnull align 8 dereferenceable(32)) #3

declare void @_ZN11BlockHeader9getPayoutEv(ptr dead_on_unwind writable sret(%struct.UAmount) align 8, ptr noundef nonnull align 8 dereferenceable(400)) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt3mapIhmSt4lessIhESaISt4pairIKhmEEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZStneRKSt17_Rb_tree_iteratorISt4pairIKhmEES5_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt3mapIhmSt4lessIhESaISt4pairIKhmEEE3endEv(ptr noundef nonnull align 8 dereferenceable(48)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt17_Rb_tree_iteratorISt4pairIKhmEEptEv(ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt17_Rb_tree_iteratorISt4pairIKhmEEppEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7UAmountD2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"_ZTSSt4pairIKhmE", !6, i64 0, !12, i64 8}
!12 = !{!"long", !6, i64 0}
!13 = !{!11, !12, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"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.UAmount = type { %"class.std::map.8" }
%"class.std::map.8" = type { %"class.std::_Rb_tree.9" }
%"class.std::_Rb_tree.9" = type { %"struct.std::_Rb_tree<unsigned char, std::pair<const unsigned char, unsigned long>, std::_Select1st<std::pair<const unsigned char, unsigned long>>, std::less<unsigned char>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<unsigned char, std::pair<const unsigned char, unsigned long>, std::_Select1st<std::pair<const unsigned char, unsigned long>>, std::less<unsigned char>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"struct.std::_Rb_tree_iterator.18" = type { ptr }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZN5Chain8InstanceEv() local_unnamed_addr #1 align 2

; 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 uwtable
define dso_local noundef i64 @_ZN10MetricTool22getPassportBlockSupplyEh(i8 noundef zeroext %0) local_unnamed_addr #2 align 2 {
  %2 = alloca %struct.UAmount, align 8
  %3 = alloca %"struct.std::_Rb_tree_iterator.18", align 8
  %4 = alloca %"struct.std::_Rb_tree_iterator.18", align 8
  %5 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZN5Chain8InstanceEv()
  %6 = tail call noundef ptr @_ZN5Chain18getBestBlockHeaderEv(ptr noundef nonnull align 8 dereferenceable(32) %5)
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %21, label %7

7:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %2) #4
  call void @_ZN11BlockHeader9getPayoutEv(ptr dead_on_unwind nonnull writable sret(%struct.UAmount) align 8 %2, ptr noundef nonnull align 8 dereferenceable(400) %6)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %8 = call ptr @_ZNSt3mapIhmSt4lessIhESaISt4pairIKhmEEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48) %2) #4
  store ptr %8, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %9 = call ptr @_ZNSt3mapIhmSt4lessIhESaISt4pairIKhmEEE3endEv(ptr noundef nonnull align 8 dereferenceable(48) %2) #4
  store ptr %9, ptr %4, align 8
  %10 = call noundef zeroext i1 @_ZStneRKSt17_Rb_tree_iteratorISt4pairIKhmEES5_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %7, %17
  %11 = call noundef ptr @_ZNKSt17_Rb_tree_iteratorISt4pairIKhmEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %3) #4
  %12 = load i8, ptr %11, align 8, !tbaa !5
  %13 = icmp eq i8 %12, %0
  br i1 %13, label %.thread, label %17

.thread:                                          ; preds = %.lr.ph
  %14 = call noundef ptr @_ZNKSt17_Rb_tree_iteratorISt4pairIKhmEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %3) #4
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @_ZN7UAmountD2Ev(ptr noundef nonnull align 8 dereferenceable(48) %2) #4
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %2) #4
  br label %21

17:                                               ; preds = %.lr.ph
  %18 = call ptr @_ZNSt17_Rb_tree_iteratorISt4pairIKhmEEppEi(ptr noundef nonnull align 8 dereferenceable(8) %3, i32 noundef 0) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %19 = call ptr @_ZNSt3mapIhmSt4lessIhESaISt4pairIKhmEEE3endEv(ptr noundef nonnull align 8 dereferenceable(48) %2) #4
  store ptr %19, ptr %4, align 8
  %20 = call noundef zeroext i1 @_ZStneRKSt17_Rb_tree_iteratorISt4pairIKhmEES5_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %17, %7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @_ZN7UAmountD2Ev(ptr noundef nonnull align 8 dereferenceable(48) %2) #4
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %2) #4
  br label %21

21:                                               ; preds = %1, %._crit_edge, %.thread
  %.1 = phi i64 [ %16, %.thread ], [ 0, %._crit_edge ], [ 0, %1 ]
  ret i64 %.1
}

declare noundef ptr @_ZN5Chain18getBestBlockHeaderEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #3

declare void @_ZN11BlockHeader9getPayoutEv(ptr dead_on_unwind writable sret(%struct.UAmount) align 8, ptr noundef nonnull align 8 dereferenceable(400)) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt3mapIhmSt4lessIhESaISt4pairIKhmEEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt3mapIhmSt4lessIhESaISt4pairIKhmEEE3endEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #1 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7UAmountD2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #1 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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, !7, i64 0}
!6 = !{!"_ZTSSt4pairIKhmE", !7, i64 0, !9, i64 8}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!6, !9, i64 8}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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