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

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

%"class.std::vector.3" = type { %"struct.std::_Vector_base.4" }
%"struct.std::_Vector_base.4" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; 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

declare i32 @__gxx_personality_v0(...)

; 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
declare dso_local noundef i64 @_ZN10MetricTool22getPassportBlockSupplyEh(i8 noundef zeroext) #2 align 2

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

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

17:                                               ; preds = %1
  store i64 0, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %51

18:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %19 = load ptr, ptr %5, align 8, !tbaa !8
  %20 = call noundef i32 @_ZN11BlockHeader12getTimestampEv(ptr noundef nonnull align 8 dereferenceable(400) %19)
  %21 = zext i32 %20 to i64
  store i64 %21, ptr %7, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 1, ptr %8, align 4, !tbaa !12
  br label %22

22:                                               ; preds = %37, %18
  %23 = load ptr, ptr %4, align 8, !tbaa !8
  %24 = load ptr, ptr %5, align 8, !tbaa !8
  call void @_ZN11BlockHeader21getPreviousHeaderHashEv(ptr dead_on_unwind writable sret(%"class.std::vector.3") align 8 %9, ptr noundef nonnull align 8 dereferenceable(400) %24)
  %25 = invoke noundef ptr @_ZN5Chain14getBlockHeaderESt6vectorIhSaIhEE(ptr noundef nonnull align 8 dereferenceable(32) %23, ptr noundef %9)
          to label %26 unwind label %30

26:                                               ; preds = %22
  store ptr %25, ptr %5, align 8, !tbaa !8
  call void @_ZNSt6vectorIhSaIhEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %9) #4
  %27 = load ptr, ptr %5, align 8, !tbaa !8
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %34

29:                                               ; preds = %26
  store i64 0, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %50

30:                                               ; preds = %22
  %31 = landingpad { ptr, i32 }
          cleanup
  %32 = extractvalue { ptr, i32 } %31, 0
  store ptr %32, ptr %10, align 8
  %33 = extractvalue { ptr, i32 } %31, 1
  store i32 %33, ptr %11, align 4
  call void @_ZNSt6vectorIhSaIhEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %53

34:                                               ; preds = %26
  %35 = load i32, ptr %8, align 4, !tbaa !12
  %36 = add i32 %35, 1
  store i32 %36, ptr %8, align 4, !tbaa !12
  br label %37

37:                                               ; preds = %34
  %38 = load ptr, ptr %5, align 8, !tbaa !8
  %39 = call noundef i32 @_ZN11BlockHeader12getTimestampEv(ptr noundef nonnull align 8 dereferenceable(400) %38)
  %40 = zext i32 %39 to i64
  %41 = load i64, ptr %7, align 8, !tbaa !10
  %42 = sub i64 %41, 86400
  %43 = icmp ugt i64 %40, %42
  br i1 %43, label %22, label %44, !llvm.loop !14

44:                                               ; preds = %37
  %45 = load i8, ptr %3, align 1, !tbaa !5
  %46 = call noundef i64 @_ZN10MetricTool22getPassportBlockSupplyEh(i8 noundef zeroext %45)
  %47 = load i32, ptr %8, align 4, !tbaa !12
  %48 = zext i32 %47 to i64
  %49 = mul i64 %46, %48
  store i64 %49, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %50

50:                                               ; preds = %44, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %51

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

53:                                               ; preds = %30
  %54 = load ptr, ptr %10, align 8
  %55 = load i32, ptr %11, align 4
  %56 = insertvalue { ptr, i32 } poison, ptr %54, 0
  %57 = insertvalue { ptr, i32 } %56, i32 %55, 1
  resume { ptr, i32 } %57
}

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

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

declare void @_ZN11BlockHeader21getPreviousHeaderHashEv(ptr dead_on_unwind writable sret(%"class.std::vector.3") align 8, ptr noundef nonnull align 8 dereferenceable(400)) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIhSaIhEED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) 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, !11, i64 0}
!11 = !{!"long", !6, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !6, i64 0}
!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"

%"class.std::vector.3" = type { %"struct.std::_Vector_base.4" }
%"struct.std::_Vector_base.4" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" = type { ptr, ptr, ptr }

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN10MetricTool22getPassportBlockSupplyEh(i8 noundef zeroext) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN10MetricTool21getPassportSupply1DayEh(i8 noundef zeroext %0) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %"class.std::vector.3", align 8
  %3 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZN5Chain8InstanceEv()
  %4 = tail call noundef ptr @_ZN5Chain18getBestBlockHeaderEv(ptr noundef nonnull align 8 dereferenceable(32) %3)
  %5 = icmp eq ptr %4, null
  br i1 %5, label %.loopexit, label %6

6:                                                ; preds = %1
  %7 = tail call noundef i32 @_ZN11BlockHeader12getTimestampEv(ptr noundef nonnull align 8 dereferenceable(400) %4)
  %8 = zext i32 %7 to i64
  %9 = add nsw i64 %8, -86400
  br label %10

10:                                               ; preds = %16, %6
  %.014 = phi i32 [ 1, %6 ], [ %17, %16 ]
  %.013 = phi ptr [ %4, %6 ], [ %11, %16 ]
  call void @_ZN11BlockHeader21getPreviousHeaderHashEv(ptr dead_on_unwind nonnull writable sret(%"class.std::vector.3") align 8 %2, ptr noundef nonnull align 8 dereferenceable(400) %.013)
  %11 = invoke noundef ptr @_ZN5Chain14getBlockHeaderESt6vectorIhSaIhEE(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull %2)
          to label %12 unwind label %14

12:                                               ; preds = %10
  call void @_ZNSt6vectorIhSaIhEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %2) #3
  %13 = icmp eq ptr %11, null
  br i1 %13, label %.loopexit, label %16

14:                                               ; preds = %10
  %15 = landingpad { ptr, i32 }
          cleanup
  call void @_ZNSt6vectorIhSaIhEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %2) #3
  resume { ptr, i32 } %15

16:                                               ; preds = %12
  %17 = add i32 %.014, 1
  %18 = call noundef i32 @_ZN11BlockHeader12getTimestampEv(ptr noundef nonnull align 8 dereferenceable(400) %11)
  %19 = zext i32 %18 to i64
  %20 = icmp ult i64 %9, %19
  br i1 %20, label %10, label %21, !llvm.loop !5

21:                                               ; preds = %16
  %22 = call noundef i64 @_ZN10MetricTool22getPassportBlockSupplyEh(i8 noundef zeroext %0)
  %23 = zext i32 %17 to i64
  %24 = mul i64 %22, %23
  br label %.loopexit

.loopexit:                                        ; preds = %12, %21, %1
  %.1 = phi i64 [ 0, %1 ], [ %24, %21 ], [ 0, %12 ]
  ret i64 %.1
}

declare noundef i32 @_ZN11BlockHeader12getTimestampEv(ptr noundef nonnull align 8 dereferenceable(400)) local_unnamed_addr #2

declare noundef ptr @_ZN5Chain14getBlockHeaderESt6vectorIhSaIhEE(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef) local_unnamed_addr #2

declare void @_ZN11BlockHeader21getPreviousHeaderHashEv(ptr dead_on_unwind writable sret(%"class.std::vector.3") align 8, ptr noundef nonnull align 8 dereferenceable(400)) local_unnamed_addr #2

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

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 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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