; LLVM IR from bitcoin-core/secp256k1 :: src (bench_ecmult)

; 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.secp256k1_scalar = type { [4 x i64] }
%struct.secp256k1_context_struct = type { %struct.secp256k1_ecmult_gen_context, %struct.secp256k1_callback, %struct.secp256k1_callback, i32 }
%struct.secp256k1_ecmult_gen_context = type { i32, %struct.secp256k1_scalar, %struct.secp256k1_ge, %struct.secp256k1_fe }
%struct.secp256k1_ge = type { %struct.secp256k1_fe, %struct.secp256k1_fe, i32 }
%struct.secp256k1_fe = type { [5 x i64] }
%struct.secp256k1_callback = type { ptr, ptr }

@.str.18 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @secp256k1_callback_call(ptr noundef, ptr noundef) #0

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @secp256k1_ecdsa_sign(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #3 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca %struct.secp256k1_scalar, align 8
  %15 = alloca %struct.secp256k1_scalar, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  br label %18

18:                                               ; preds = %6
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %19, i32 0, i32 0
  %21 = call i32 @secp256k1_ecmult_gen_context_is_built(ptr noundef %20)
  %22 = icmp ne i32 %21, 0
  %23 = xor i1 %22, true
  %24 = zext i1 %23 to i32
  %25 = sext i32 %24 to i64
  %26 = call i64 @llvm.expect.i64(i64 %25, i64 0)
  %27 = icmp ne i64 %26, 0
  br i1 %27, label %28, label %31

28:                                               ; preds = %18
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %29, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %30, ptr noundef @.str.19)
  store i32 0, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %84

31:                                               ; preds = %18
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  %37 = xor i1 %36, true
  %38 = zext i1 %37 to i32
  %39 = sext i32 %38 to i64
  %40 = call i64 @llvm.expect.i64(i64 %39, i64 0)
  %41 = icmp ne i64 %40, 0
  br i1 %41, label %42, label %45

42:                                               ; preds = %34
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %43, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %44, ptr noundef @.str.18)
  store i32 0, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %84

45:                                               ; preds = %34
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  %51 = xor i1 %50, true
  %52 = zext i1 %51 to i32
  %53 = sext i32 %52 to i64
  %54 = call i64 @llvm.expect.i64(i64 %53, i64 0)
  %55 = icmp ne i64 %54, 0
  br i1 %55, label %56, label %59

56:                                               ; preds = %48
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %57, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %58, ptr noundef @.str.20)
  store i32 0, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %84

59:                                               ; preds = %48
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = icmp ne ptr %63, null
  %65 = xor i1 %64, true
  %66 = zext i1 %65 to i32
  %67 = sext i32 %66 to i64
  %68 = call i64 @llvm.expect.i64(i64 %67, i64 0)
  %69 = icmp ne i64 %68, 0
  br i1 %69, label %70, label %73

70:                                               ; preds = %62
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %71, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %72, ptr noundef @.str.21)
  store i32 0, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %84

73:                                               ; preds = %62
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = load ptr, ptr %11, align 8, !tbaa !5
  %79 = load ptr, ptr %12, align 8, !tbaa !5
  %80 = load ptr, ptr %13, align 8, !tbaa !5
  %81 = call i32 @secp256k1_ecdsa_sign_inner(ptr noundef %76, ptr noundef %14, ptr noundef %15, ptr noundef null, ptr noundef %77, ptr noundef %78, ptr noundef %79, ptr noundef %80)
  store i32 %81, ptr %16, align 4, !tbaa !9
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  call void @secp256k1_ecdsa_signature_save(ptr noundef %82, ptr noundef %14, ptr noundef %15)
  %83 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %83, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %84

84:                                               ; preds = %75, %70, %56, %42, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %14) #4
  %85 = load i32, ptr %7, align 4
  ret i32 %85
}

; Function Attrs: nounwind uwtable
declare hidden i32 @secp256k1_ecmult_gen_context_is_built(ptr noundef) #3

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #3 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


; 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.secp256k1_scalar = type { [4 x i64] }

@.str.18 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @secp256k1_callback_call(ptr noundef, ptr noundef) local_unnamed_addr #0

; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @secp256k1_ecdsa_sign(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #2 {
  %7 = alloca %struct.secp256k1_scalar, align 8
  %8 = alloca %struct.secp256k1_scalar, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %8) #3
  %9 = tail call i32 @secp256k1_ecmult_gen_context_is_built(ptr noundef %0)
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %12, !prof !5

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 168
  tail call void @secp256k1_callback_call(ptr noundef nonnull %11, ptr noundef nonnull @.str.19)
  br label %23

12:                                               ; preds = %6
  %.not15 = icmp eq ptr %2, null
  br i1 %.not15, label %13, label %15, !prof !5

13:                                               ; preds = %12
  %14 = getelementptr inbounds i8, ptr %0, i64 168
  tail call void @secp256k1_callback_call(ptr noundef nonnull %14, ptr noundef nonnull @.str.18)
  br label %23

15:                                               ; preds = %12
  %.not16 = icmp eq ptr %1, null
  br i1 %.not16, label %16, label %18, !prof !5

16:                                               ; preds = %15
  %17 = getelementptr inbounds i8, ptr %0, i64 168
  tail call void @secp256k1_callback_call(ptr noundef nonnull %17, ptr noundef nonnull @.str.20)
  br label %23

18:                                               ; preds = %15
  %.not17 = icmp eq ptr %3, null
  br i1 %.not17, label %19, label %21, !prof !5

19:                                               ; preds = %18
  %20 = getelementptr inbounds i8, ptr %0, i64 168
  tail call void @secp256k1_callback_call(ptr noundef nonnull %20, ptr noundef nonnull @.str.21)
  br label %23

21:                                               ; preds = %18
  %22 = call i32 @secp256k1_ecdsa_sign_inner(ptr noundef %0, ptr noundef nonnull %7, ptr noundef nonnull %8, ptr noundef null, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef %4, ptr noundef %5)
  call void @secp256k1_ecdsa_signature_save(ptr noundef nonnull %1, ptr noundef nonnull %7, ptr noundef nonnull %8)
  br label %23

23:                                               ; preds = %21, %19, %16, %13, %10
  %.0 = phi i32 [ 0, %10 ], [ 0, %13 ], [ 0, %16 ], [ 0, %19 ], [ %22, %21 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #3
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @secp256k1_ecmult_gen_context_is_built(ptr noundef) local_unnamed_addr #2

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 = !{!"branch_weights", !"expected", i32 1, i32 2000}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass