; LLVM IR from vergecurrency/verge :: src/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_gej }
%struct.secp256k1_gej = type { %struct.secp256k1_fe, %struct.secp256k1_fe, %struct.secp256k1_fe, i32 }
%struct.secp256k1_fe = type { [5 x i64] }
%struct.secp256k1_callback = type { ptr, ptr }

@.str.17 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.20 = 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 = icmp ne ptr %19, null
  %21 = zext i1 %20 to i32
  br label %22

22:                                               ; preds = %18
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %25, i32 0, i32 0
  %27 = call i32 @secp256k1_ecmult_gen_context_is_built(ptr noundef %26)
  %28 = icmp ne i32 %27, 0
  %29 = xor i1 %28, true
  %30 = zext i1 %29 to i32
  %31 = sext i32 %30 to i64
  %32 = call i64 @llvm.expect.i64(i64 %31, i64 0)
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %34, label %37

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

37:                                               ; preds = %24
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  %43 = xor i1 %42, true
  %44 = zext i1 %43 to i32
  %45 = sext i32 %44 to i64
  %46 = call i64 @llvm.expect.i64(i64 %45, i64 0)
  %47 = icmp ne i64 %46, 0
  br i1 %47, label %48, label %51

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

51:                                               ; preds = %40
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  %57 = xor i1 %56, true
  %58 = zext i1 %57 to i32
  %59 = sext i32 %58 to i64
  %60 = call i64 @llvm.expect.i64(i64 %59, i64 0)
  %61 = icmp ne i64 %60, 0
  br i1 %61, label %62, label %65

62:                                               ; preds = %54
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %63, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %64, ptr noundef @.str.19)
  store i32 0, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %90

65:                                               ; preds = %54
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = icmp ne ptr %69, null
  %71 = xor i1 %70, true
  %72 = zext i1 %71 to i32
  %73 = sext i32 %72 to i64
  %74 = call i64 @llvm.expect.i64(i64 %73, i64 0)
  %75 = icmp ne i64 %74, 0
  br i1 %75, label %76, label %79

76:                                               ; preds = %68
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %77, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %78, ptr noundef @.str.20)
  store i32 0, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %90

79:                                               ; preds = %68
  br label %80

80:                                               ; preds = %79
  br label %81

81:                                               ; preds = %80
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  %85 = load ptr, ptr %12, align 8, !tbaa !5
  %86 = load ptr, ptr %13, align 8, !tbaa !5
  %87 = call i32 @secp256k1_ecdsa_sign_inner(ptr noundef %82, ptr noundef %14, ptr noundef %15, ptr noundef null, ptr noundef %83, ptr noundef %84, ptr noundef %85, ptr noundef %86)
  store i32 %87, ptr %16, align 4, !tbaa !9
  %88 = load ptr, ptr %9, align 8, !tbaa !5
  call void @secp256k1_ecdsa_signature_save(ptr noundef %88, ptr noundef %14, ptr noundef %15)
  %89 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %89, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %90

90:                                               ; preds = %81, %76, %62, %48, %34
  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
  %91 = load i32, ptr %7, align 4
  ret i32 %91
}

; 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.17 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.20 = 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.18)
  br label %23

12:                                               ; preds = %6
  %.not16 = icmp eq ptr %2, null
  br i1 %.not16, 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.17)
  br label %23

15:                                               ; preds = %12
  %.not17 = icmp eq ptr %1, null
  br i1 %.not17, 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.19)
  br label %23

18:                                               ; preds = %15
  %.not18 = icmp eq ptr %3, null
  br i1 %.not18, 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.20)
  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