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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN10MetricTool28findFirstPassportBlockHeightEh(i8 noundef zeroext) #0 align 2

; 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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN10MetricTool20calculateTotalSupplyEmmmjh(i64 noundef %0, i64 noundef %1, i64 noundef %2, i32 noundef %3, i8 noundef zeroext %4) #0 align 2 {
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store i64 %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i8 %4, ptr %10, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %17 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZN5Chain8InstanceEv()
  store ptr %17, ptr %11, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %18 = load ptr, ptr %11, align 8, !tbaa !12
  %19 = call noundef i32 @_ZN5Chain26getCurrentBlockchainHeightEv(ptr noundef nonnull align 8 dereferenceable(32) %18)
  store i32 %19, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store i64 0, ptr %13, align 8, !tbaa !5
  %20 = load i32, ptr %12, align 4, !tbaa !9
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = icmp ugt i32 %20, %21
  br i1 %22, label %23, label %86

23:                                               ; preds = %5
  %24 = load i64, ptr %6, align 8, !tbaa !5
  %25 = load i32, ptr %12, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = load i8, ptr %10, align 1, !tbaa !11
  %28 = call noundef i64 @_ZN10MetricTool28findFirstPassportBlockHeightEh(i8 noundef zeroext %27)
  %29 = sub i64 %26, %28
  %30 = mul i64 %24, %29
  %31 = load i64, ptr %13, align 8, !tbaa !5
  %32 = add i64 %31, %30
  store i64 %32, ptr %13, align 8, !tbaa !5
  %33 = load i64, ptr %8, align 8, !tbaa !5
  %34 = load i32, ptr %12, align 4, !tbaa !9
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = sub i32 %34, %35
  %37 = zext i32 %36 to i64
  %38 = mul i64 %33, %37
  %39 = load i64, ptr %13, align 8, !tbaa !5
  %40 = add i64 %39, %38
  store i64 %40, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 1, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %82, %23
  %42 = load i32, ptr %15, align 4, !tbaa !9
  %43 = icmp slt i32 %42, 4
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %85

45:                                               ; preds = %41
  %46 = load i32, ptr %15, align 4, !tbaa !9
  %47 = mul nsw i32 525600, %46
  %48 = load i32, ptr %12, align 4, !tbaa !9
  %49 = icmp ult i32 %47, %48
  br i1 %49, label %50, label %81

50:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %51 = load i32, ptr %15, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  %53 = mul nsw i32 525600, %52
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = icmp ugt i32 %53, %54
  br i1 %55, label %56, label %58

56:                                               ; preds = %50
  %57 = load i32, ptr %12, align 4, !tbaa !9
  br label %62

58:                                               ; preds = %50
  %59 = load i32, ptr %15, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  %61 = mul nsw i32 525600, %60
  br label %62

62:                                               ; preds = %58, %56
  %63 = phi i32 [ %57, %56 ], [ %61, %58 ]
  store i32 %63, ptr %16, align 4, !tbaa !9
  %64 = load i32, ptr %16, align 4, !tbaa !9
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = icmp ugt i32 %64, %65
  br i1 %66, label %67, label %78

67:                                               ; preds = %62
  %68 = load i64, ptr %7, align 8, !tbaa !5
  %69 = load i64, ptr %14, align 8, !tbaa !5
  %70 = udiv i64 %68, %69
  %71 = load i32, ptr %16, align 4, !tbaa !9
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = sub i32 %71, %72
  %74 = zext i32 %73 to i64
  %75 = mul i64 %70, %74
  %76 = load i64, ptr %13, align 8, !tbaa !5
  %77 = add i64 %76, %75
  store i64 %77, ptr %13, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %67, %62
  %79 = load i64, ptr %14, align 8, !tbaa !5
  %80 = mul i64 %79, 2
  store i64 %80, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %81

81:                                               ; preds = %78, %45
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %15, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %15, align 4, !tbaa !9
  br label %41, !llvm.loop !14

85:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %86

86:                                               ; preds = %85, %5
  %87 = load i64, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  ret i64 %87
}

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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !7, 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"

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN10MetricTool20calculateTotalSupplyEmmmjh(i64 noundef %0, i64 noundef %1, i64 noundef %2, i32 noundef %3, i8 noundef zeroext %4) local_unnamed_addr #0 align 2 {
  %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 = icmp ugt i32 %7, %3
  br i1 %8, label %9, label %.loopexit

9:                                                ; preds = %5
  %10 = zext i32 %7 to i64
  %11 = tail call noundef i64 @_ZN10MetricTool28findFirstPassportBlockHeightEh(i8 noundef zeroext %4)
  %12 = sub i64 %10, %11
  %13 = mul i64 %12, %0
  %14 = sub i32 %7, %3
  %15 = zext i32 %14 to i64
  %16 = mul i64 %15, %2
  %17 = add i64 %13, %16
  %18 = tail call i32 @llvm.umin.i32(i32 %7, i32 525600)
  %19 = icmp ult i32 %3, 525600
  %20 = sub nsw i32 %18, %3
  %21 = zext i32 %20 to i64
  %22 = mul i64 %21, %1
  %23 = select i1 %19, i64 %22, i64 0
  %.1 = add i64 %17, %23
  %24 = icmp ugt i32 %7, 525600
  br i1 %24, label %25, label %.loopexit

25:                                               ; preds = %9
  %26 = tail call i32 @llvm.umin.i32(i32 %7, i32 1051200)
  %27 = icmp ugt i32 %26, %3
  br i1 %27, label %28, label %34

28:                                               ; preds = %25
  %29 = lshr i64 %1, 1
  %30 = sub nsw i32 %26, %3
  %31 = zext i32 %30 to i64
  %32 = mul i64 %29, %31
  %33 = add i64 %32, %.1
  br label %34

34:                                               ; preds = %25, %28
  %.2.1 = phi i64 [ %33, %28 ], [ %.1, %25 ]
  %35 = icmp ugt i32 %7, 1051200
  br i1 %35, label %36, label %.loopexit

36:                                               ; preds = %34
  %37 = tail call i32 @llvm.umin.i32(i32 %7, i32 1576800)
  %38 = icmp ugt i32 %37, %3
  br i1 %38, label %39, label %45

39:                                               ; preds = %36
  %40 = lshr i64 %1, 2
  %41 = sub nsw i32 %37, %3
  %42 = zext i32 %41 to i64
  %43 = mul i64 %40, %42
  %44 = add i64 %43, %.2.1
  br label %45

45:                                               ; preds = %36, %39
  %.1.2 = phi i64 [ %44, %39 ], [ %.2.1, %36 ]
  %46 = icmp ugt i32 %7, 1576800
  br i1 %46, label %47, label %.loopexit

47:                                               ; preds = %45
  %48 = tail call i32 @llvm.umin.i32(i32 %7, i32 2102400)
  %49 = icmp ugt i32 %48, %3
  br i1 %49, label %50, label %.loopexit

50:                                               ; preds = %47
  %51 = lshr i64 %1, 3
  %52 = sub nsw i32 %48, %3
  %53 = zext i32 %52 to i64
  %54 = mul i64 %51, %53
  %55 = add i64 %54, %.1.2
  br label %.loopexit

.loopexit:                                        ; preds = %9, %34, %45, %50, %47, %5
  %.3 = phi i64 [ 0, %5 ], [ %.1.2, %45 ], [ %55, %50 ], [ %.1.2, %47 ], [ %.2.1, %34 ], [ %.1, %9 ]
  ret i64 %.3
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #3

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 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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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)"}


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