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

; 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.UAmount32 = type { %"class.std::map" }
%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<unsigned char, std::pair<const unsigned char, unsigned int>, std::_Select1st<std::pair<const unsigned char, unsigned int>>, std::less<unsigned char>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<unsigned char, std::pair<const unsigned char, unsigned int>, std::_Select1st<std::pair<const unsigned char, unsigned int>>, 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" = type { ptr }
%"struct.std::pair" = type { i8, i32 }

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN10MetricTool28findFirstPassportBlockHeightEh(i8 noundef zeroext %0) #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.UAmount32, align 8
  %9 = alloca %"struct.std::_Rb_tree_iterator", align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca %"struct.std::_Rb_tree_iterator", align 8
  store i8 %0, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %13 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZN5Chain8InstanceEv()
  store ptr %13, ptr %3, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 1, ptr %4, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %14 = load ptr, ptr %3, align 8, !tbaa !8
  %15 = call noundef i32 @_ZN5Chain26getCurrentBlockchainHeightEv(ptr noundef nonnull align 8 dereferenceable(32) %14)
  %16 = zext i32 %15 to i64
  store i64 %16, ptr %5, align 8, !tbaa !10
  br label %17

17:                                               ; preds = %57, %1
  %18 = load i64, ptr %4, align 8, !tbaa !10
  %19 = add i64 %18, 1
  %20 = load i64, ptr %5, align 8, !tbaa !10
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %22, label %58

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %23 = load i64, ptr %4, align 8, !tbaa !10
  %24 = load i64, ptr %5, align 8, !tbaa !10
  %25 = load i64, ptr %4, align 8, !tbaa !10
  %26 = sub i64 %24, %25
  %27 = udiv i64 %26, 2
  %28 = add i64 %23, %27
  store i64 %28, ptr %6, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %29 = load ptr, ptr %3, align 8, !tbaa !8
  %30 = load i64, ptr %6, align 8, !tbaa !10
  %31 = call noundef ptr @_ZN5Chain14getBlockHeaderEm(ptr noundef nonnull align 8 dereferenceable(32) %29, i64 noundef %30)
  store ptr %31, ptr %7, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 48, ptr %8) #4
  %32 = load ptr, ptr %7, align 8, !tbaa !8
  call void @_ZN11BlockHeader19getUbiReceiverCountEv(ptr dead_on_unwind writable sret(%struct.UAmount32) align 8 %8, ptr noundef nonnull align 8 dereferenceable(400) %32)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %33 = getelementptr inbounds %struct.UAmount32, ptr %8, i32 0, i32 0
  %34 = invoke ptr @_ZNSt3mapIhjSt4lessIhESaISt4pairIKhjEEE4findERS3_(ptr noundef nonnull align 8 dereferenceable(48) %33, ptr noundef nonnull align 1 dereferenceable(1) %2)
          to label %35 unwind label %43

35:                                               ; preds = %22
  %36 = getelementptr inbounds %"struct.std::_Rb_tree_iterator", ptr %9, i32 0, i32 0
  store ptr %34, ptr %36, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %37 = getelementptr inbounds %struct.UAmount32, ptr %8, i32 0, i32 0
  %38 = call ptr @_ZNSt3mapIhjSt4lessIhESaISt4pairIKhjEEE3endEv(ptr noundef nonnull align 8 dereferenceable(48) %37) #4
  %39 = getelementptr inbounds %"struct.std::_Rb_tree_iterator", ptr %12, i32 0, i32 0
  store ptr %38, ptr %39, align 8
  %40 = call noundef zeroext i1 @_ZSteqRKSt17_Rb_tree_iteratorISt4pairIKhjEES5_(ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef nonnull align 8 dereferenceable(8) %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br i1 %40, label %41, label %47

41:                                               ; preds = %35
  %42 = load i64, ptr %6, align 8, !tbaa !10
  store i64 %42, ptr %4, align 8, !tbaa !10
  br label %57

43:                                               ; preds = %22
  %44 = landingpad { ptr, i32 }
          cleanup
  %45 = extractvalue { ptr, i32 } %44, 0
  store ptr %45, ptr %10, align 8
  %46 = extractvalue { ptr, i32 } %44, 1
  store i32 %46, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @_ZN9UAmount32D2Ev(ptr noundef nonnull align 8 dereferenceable(48) %8) #4
  call void @llvm.lifetime.end.p0(i64 48, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %60

47:                                               ; preds = %35
  %48 = call noundef ptr @_ZNKSt17_Rb_tree_iteratorISt4pairIKhjEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %9) #4
  %49 = getelementptr inbounds %"struct.std::pair", ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !12
  %51 = icmp ugt i32 %50, 0
  br i1 %51, label %52, label %54

52:                                               ; preds = %47
  %53 = load i64, ptr %6, align 8, !tbaa !10
  store i64 %53, ptr %5, align 8, !tbaa !10
  br label %56

54:                                               ; preds = %47
  %55 = load i64, ptr %6, align 8, !tbaa !10
  store i64 %55, ptr %4, align 8, !tbaa !10
  br label %56

56:                                               ; preds = %54, %52
  br label %57

57:                                               ; preds = %56, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @_ZN9UAmount32D2Ev(ptr noundef nonnull align 8 dereferenceable(48) %8) #4
  call void @llvm.lifetime.end.p0(i64 48, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %17, !llvm.loop !15

58:                                               ; preds = %17
  %59 = load i64, ptr %5, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret i64 %59

60:                                               ; preds = %43
  %61 = load ptr, ptr %10, align 8
  %62 = load i32, ptr %11, align 4
  %63 = insertvalue { ptr, i32 } poison, ptr %61, 0
  %64 = insertvalue { ptr, i32 } %63, i32 %62, 1
  resume { ptr, i32 } %64
}

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

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

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

declare noundef ptr @_ZN5Chain14getBlockHeaderEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #3

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

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

declare i32 @__gxx_personality_v0(...)

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

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

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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !11, i64 0}
!11 = !{!"long", !6, i64 0}
!12 = !{!13, !14, i64 4}
!13 = !{!"_ZTSSt4pairIKhjE", !6, i64 0, !14, i64 4}
!14 = !{!"int", !6, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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.UAmount32 = type { %"class.std::map" }
%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<unsigned char, std::pair<const unsigned char, unsigned int>, std::_Select1st<std::pair<const unsigned char, unsigned int>>, std::less<unsigned char>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<unsigned char, std::pair<const unsigned char, unsigned int>, std::_Select1st<std::pair<const unsigned char, unsigned int>>, 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" = type { ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN10MetricTool28findFirstPassportBlockHeightEh(i8 noundef zeroext %0) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i8, align 1
  %3 = alloca %struct.UAmount32, align 8
  %4 = alloca %"struct.std::_Rb_tree_iterator", align 8
  %5 = alloca %"struct.std::_Rb_tree_iterator", align 8
  store i8 %0, ptr %2, align 1, !tbaa !5
  %6 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZN5Chain8InstanceEv()
  %7 = tail call noundef i32 @_ZN5Chain26getCurrentBlockchainHeightEv(ptr noundef nonnull align 8 dereferenceable(32) %6)
  %8 = zext i32 %7 to i64
  %9 = icmp ugt i32 %7, 2
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1, %24
  %.018 = phi i64 [ %.1, %24 ], [ 1, %1 ]
  %.01417 = phi i64 [ %.115, %24 ], [ %8, %1 ]
  %10 = sub i64 %.01417, %.018
  %11 = lshr i64 %10, 1
  %12 = add i64 %11, %.018
  %13 = call noundef ptr @_ZN5Chain14getBlockHeaderEm(ptr noundef nonnull align 8 dereferenceable(32) %6, i64 noundef %12)
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %3) #4
  call void @_ZN11BlockHeader19getUbiReceiverCountEv(ptr dead_on_unwind nonnull writable sret(%struct.UAmount32) align 8 %3, ptr noundef nonnull align 8 dereferenceable(400) %13)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %14 = invoke ptr @_ZNSt3mapIhjSt4lessIhESaISt4pairIKhjEEE4findERS3_(ptr noundef nonnull align 8 dereferenceable(48) %3, ptr noundef nonnull align 1 dereferenceable(1) %2)
          to label %15 unwind label %18

15:                                               ; preds = %.lr.ph
  store ptr %14, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %16 = call ptr @_ZNSt3mapIhjSt4lessIhESaISt4pairIKhjEEE3endEv(ptr noundef nonnull align 8 dereferenceable(48) %3) #4
  store ptr %16, ptr %5, align 8
  %17 = call noundef zeroext i1 @_ZSteqRKSt17_Rb_tree_iteratorISt4pairIKhjEES5_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  br i1 %17, label %24, label %20

18:                                               ; preds = %.lr.ph
  %19 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @_ZN9UAmount32D2Ev(ptr noundef nonnull align 8 dereferenceable(48) %3) #4
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %3) #4
  resume { ptr, i32 } %19

20:                                               ; preds = %15
  %21 = call noundef ptr @_ZNKSt17_Rb_tree_iteratorISt4pairIKhjEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %4) #4
  %22 = getelementptr inbounds i8, ptr %21, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !8
  %.not = icmp eq i32 %23, 0
  %.014. = select i1 %.not, i64 %.01417, i64 %12
  %..0 = select i1 %.not, i64 %12, i64 %.018
  br label %24

24:                                               ; preds = %20, %15
  %.115 = phi i64 [ %.01417, %15 ], [ %.014., %20 ]
  %.1 = phi i64 [ %12, %15 ], [ %..0, %20 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @_ZN9UAmount32D2Ev(ptr noundef nonnull align 8 dereferenceable(48) %3) #4
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %3) #4
  %25 = add i64 %.1, 1
  %26 = icmp ult i64 %25, %.115
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %24, %1
  %.014.lcssa = phi i64 [ %8, %1 ], [ %.115, %24 ]
  ret i64 %.014.lcssa
}

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

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

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

declare noundef ptr @_ZN5Chain14getBlockHeaderEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #3

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

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

declare i32 @__gxx_personality_v0(...)

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

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

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

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

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !10, i64 4}
!9 = !{!"_ZTSSt4pairIKhjE", !6, i64 0, !10, i64 4}
!10 = !{!"int", !6, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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