; LLVM IR from lelegard/cryptobench :: issues (montmult)

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

@bin_mod = external hidden constant [257 x i8], align 16
@bin_1 = external hidden constant [256 x i8], align 16
@bin_2 = external hidden constant [256 x i8], align 16
@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [51 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %19 = call ptr @BN_bin2bn(ptr noundef @bin_mod, i32 noundef 257, ptr noundef null)
  store ptr %19, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %20 = call ptr @BN_bin2bn(ptr noundef @bin_1, i32 noundef 256, ptr noundef null)
  store ptr %20, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %21 = call ptr @BN_bin2bn(ptr noundef @bin_2, i32 noundef 256, ptr noundef null)
  store ptr %21, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %22 = call ptr @BN_new()
  store ptr %22, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %23 = call ptr @BN_CTX_new()
  store ptr %23, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %24 = call ptr @BN_MONT_CTX_new()
  store ptr %24, ptr %11, align 8, !tbaa !9
  %25 = load ptr, ptr %11, align 8, !tbaa !9
  %26 = load ptr, ptr %6, align 8, !tbaa !9
  %27 = load ptr, ptr %10, align 8, !tbaa !9
  %28 = call i32 @BN_MONT_CTX_set(ptr noundef %25, ptr noundef %26, ptr noundef %27)
  call void @check(i32 noundef %28, ptr noundef @.str)
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %29 = call i64 @cpu_time()
  store i64 %29, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 1000000, ptr %13, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %41, %2
  %31 = load i32, ptr %13, align 4, !tbaa !5
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %44

34:                                               ; preds = %30
  %35 = load ptr, ptr %9, align 8, !tbaa !9
  %36 = load ptr, ptr %7, align 8, !tbaa !9
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = load ptr, ptr %6, align 8, !tbaa !9
  %39 = load ptr, ptr %10, align 8, !tbaa !9
  %40 = call i32 @BN_mod_add(ptr noundef %35, ptr noundef %36, ptr noundef %37, ptr noundef %38, ptr noundef %39)
  call void @check(i32 noundef %40, ptr noundef @.str.1)
  br label %41

41:                                               ; preds = %34
  %42 = load i32, ptr %13, align 4, !tbaa !5
  %43 = add nsw i32 %42, -1
  store i32 %43, ptr %13, align 4, !tbaa !5
  br label %30, !llvm.loop !13

44:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %45 = call i64 @cpu_time()
  store i64 %45, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 500000, ptr %15, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %57, %44
  %47 = load i32, ptr %15, align 4, !tbaa !5
  %48 = icmp sgt i32 %47, 0
  br i1 %48, label %50, label %49

49:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %60

50:                                               ; preds = %46
  %51 = load ptr, ptr %9, align 8, !tbaa !9
  %52 = load ptr, ptr %7, align 8, !tbaa !9
  %53 = load ptr, ptr %8, align 8, !tbaa !9
  %54 = load ptr, ptr %6, align 8, !tbaa !9
  %55 = load ptr, ptr %10, align 8, !tbaa !9
  %56 = call i32 @BN_mod_mul(ptr noundef %51, ptr noundef %52, ptr noundef %53, ptr noundef %54, ptr noundef %55)
  call void @check(i32 noundef %56, ptr noundef @.str.2)
  br label %57

57:                                               ; preds = %50
  %58 = load i32, ptr %15, align 4, !tbaa !5
  %59 = add nsw i32 %58, -1
  store i32 %59, ptr %15, align 4, !tbaa !5
  br label %46, !llvm.loop !15

60:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %61 = call i64 @cpu_time()
  store i64 %61, ptr %16, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  store i32 1000000, ptr %17, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %73, %60
  %63 = load i32, ptr %17, align 4, !tbaa !5
  %64 = icmp sgt i32 %63, 0
  br i1 %64, label %66, label %65

65:                                               ; preds = %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %76

66:                                               ; preds = %62
  %67 = load ptr, ptr %9, align 8, !tbaa !9
  %68 = load ptr, ptr %7, align 8, !tbaa !9
  %69 = load ptr, ptr %8, align 8, !tbaa !9
  %70 = load ptr, ptr %11, align 8, !tbaa !9
  %71 = load ptr, ptr %10, align 8, !tbaa !9
  %72 = call i32 @BN_mod_mul_montgomery(ptr noundef %67, ptr noundef %68, ptr noundef %69, ptr noundef %70, ptr noundef %71)
  call void @check(i32 noundef %72, ptr noundef @.str.3)
  br label %73

73:                                               ; preds = %66
  %74 = load i32, ptr %17, align 4, !tbaa !5
  %75 = add nsw i32 %74, -1
  store i32 %75, ptr %17, align 4, !tbaa !5
  br label %62, !llvm.loop !16

76:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %77 = call i64 @cpu_time()
  store i64 %77, ptr %18, align 8, !tbaa !11
  %78 = load i64, ptr %14, align 8, !tbaa !11
  %79 = load i64, ptr %12, align 8, !tbaa !11
  %80 = sub i64 %78, %79
  %81 = uitofp i64 %80 to double
  %82 = fdiv double %81, 1.000000e+06
  %83 = load i64, ptr %16, align 8, !tbaa !11
  %84 = load i64, ptr %14, align 8, !tbaa !11
  %85 = sub i64 %83, %84
  %86 = uitofp i64 %85 to double
  %87 = fdiv double %86, 5.000000e+05
  %88 = load i64, ptr %18, align 8, !tbaa !11
  %89 = load i64, ptr %16, align 8, !tbaa !11
  %90 = sub i64 %88, %89
  %91 = uitofp i64 %90 to double
  %92 = fdiv double %91, 1.000000e+06
  %93 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, double noundef %82, double noundef %87, double noundef %92)
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, 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
  ret i32 0
}

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

declare ptr @BN_bin2bn(ptr noundef, i32 noundef, ptr noundef) #2

declare ptr @BN_new() #2

declare ptr @BN_CTX_new() #2

declare ptr @BN_MONT_CTX_new() #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @check(i32 noundef, ptr noundef) #3

declare i32 @BN_MONT_CTX_set(ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @BN_mod_add(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

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

declare i32 @BN_mod_mul(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @BN_mod_mul_montgomery(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare hidden i64 @cpu_time() #0

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@bin_mod = external hidden constant [257 x i8], align 16
@bin_1 = external hidden constant [256 x i8], align 16
@bin_2 = external hidden constant [256 x i8], align 16
@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [51 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = tail call ptr @BN_bin2bn(ptr noundef nonnull @bin_mod, i32 noundef 257, ptr noundef null) #4
  %4 = tail call ptr @BN_bin2bn(ptr noundef nonnull @bin_1, i32 noundef 256, ptr noundef null) #4
  %5 = tail call ptr @BN_bin2bn(ptr noundef nonnull @bin_2, i32 noundef 256, ptr noundef null) #4
  %6 = tail call ptr @BN_new() #4
  %7 = tail call ptr @BN_CTX_new() #4
  %8 = tail call ptr @BN_MONT_CTX_new() #4
  %9 = tail call i32 @BN_MONT_CTX_set(ptr noundef %8, ptr noundef %3, ptr noundef %7) #4
  tail call void @check(i32 noundef %9, ptr noundef nonnull @.str)
  %10 = tail call i64 @cpu_time()
  br label %13

11:                                               ; preds = %13
  %12 = tail call i64 @cpu_time()
  br label %19

13:                                               ; preds = %2, %13
  %.031 = phi i32 [ 1000000, %2 ], [ %15, %13 ]
  %14 = tail call i32 @BN_mod_add(ptr noundef %6, ptr noundef %4, ptr noundef %5, ptr noundef %3, ptr noundef %7) #4
  tail call void @check(i32 noundef %14, ptr noundef nonnull @.str.1)
  %15 = add nsw i32 %.031, -1
  %16 = icmp ugt i32 %.031, 1
  br i1 %16, label %13, label %11, !llvm.loop !5

17:                                               ; preds = %19
  %18 = tail call i64 @cpu_time()
  br label %35

19:                                               ; preds = %11, %19
  %.03032 = phi i32 [ 500000, %11 ], [ %21, %19 ]
  %20 = tail call i32 @BN_mod_mul(ptr noundef %6, ptr noundef %4, ptr noundef %5, ptr noundef %3, ptr noundef %7) #4
  tail call void @check(i32 noundef %20, ptr noundef nonnull @.str.2)
  %21 = add nsw i32 %.03032, -1
  %22 = icmp ugt i32 %.03032, 1
  br i1 %22, label %19, label %17, !llvm.loop !7

23:                                               ; preds = %35
  %24 = tail call i64 @cpu_time()
  %25 = sub i64 %12, %10
  %26 = uitofp i64 %25 to double
  %27 = fdiv double %26, 1.000000e+06
  %28 = sub i64 %18, %12
  %29 = uitofp i64 %28 to double
  %30 = fdiv double %29, 5.000000e+05
  %31 = sub i64 %24, %18
  %32 = uitofp i64 %31 to double
  %33 = fdiv double %32, 1.000000e+06
  %34 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, double noundef %27, double noundef %30, double noundef %33)
  ret i32 0

35:                                               ; preds = %17, %35
  %.02933 = phi i32 [ 1000000, %17 ], [ %37, %35 ]
  %36 = tail call i32 @BN_mod_mul_montgomery(ptr noundef %6, ptr noundef %4, ptr noundef %5, ptr noundef %8, ptr noundef %7) #4
  tail call void @check(i32 noundef %36, ptr noundef nonnull @.str.3)
  %37 = add nsw i32 %.02933, -1
  %38 = icmp ugt i32 %.02933, 1
  br i1 %38, label %35, label %23, !llvm.loop !8
}

declare ptr @BN_bin2bn(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare ptr @BN_new() local_unnamed_addr #1

declare ptr @BN_CTX_new() local_unnamed_addr #1

declare ptr @BN_MONT_CTX_new() local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @check(i32 noundef, ptr noundef) local_unnamed_addr #2

declare i32 @BN_MONT_CTX_set(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @BN_mod_add(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @BN_mod_mul(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @BN_mod_mul_montgomery(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i64 @cpu_time() local_unnamed_addr #0

attributes #0 = { 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 = { "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 = { inlinehint 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 = { 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 = { 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"}
!7 = distinct !{!7, !6}
!8 = distinct !{!8, !6}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass