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

@.str.23 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [21 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @secp256k1_ec_pubkey_combine(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #4 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca %struct.secp256k1_gej, align 8
  %12 = alloca %struct.secp256k1_ge, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 128, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 88, ptr %12) #5
  br label %14

14:                                               ; preds = %4
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  %17 = xor i1 %16, true
  %18 = zext i1 %17 to i32
  %19 = sext i32 %18 to i64
  %20 = call i64 @llvm.expect.i64(i64 %19, i64 0)
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %22, label %25

22:                                               ; preds = %14
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %23, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %24, ptr noundef @.str.23)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %94

25:                                               ; preds = %14
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 1 %28, i8 0, i64 64, i1 false)
  br label %29

29:                                               ; preds = %27
  %30 = load i64, ptr %9, align 8, !tbaa !9
  %31 = icmp uge i64 %30, 1
  %32 = xor i1 %31, true
  %33 = zext i1 %32 to i32
  %34 = sext i32 %33 to i64
  %35 = call i64 @llvm.expect.i64(i64 %34, i64 0)
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %37, label %40

37:                                               ; preds = %29
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %38, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %39, ptr noundef @.str.24)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %94

40:                                               ; preds = %29
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41
  br label %43

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

51:                                               ; preds = %43
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %52, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %53, ptr noundef @.str.25)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %94

54:                                               ; preds = %43
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  call void @secp256k1_gej_set_infinity(ptr noundef %11)
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %85, %56
  %58 = load i64, ptr %10, align 8, !tbaa !9
  %59 = load i64, ptr %9, align 8, !tbaa !9
  %60 = icmp ult i64 %58, %59
  br i1 %60, label %61, label %88

61:                                               ; preds = %57
  br label %62

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

73:                                               ; preds = %62
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %74, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %75, ptr noundef @.str.26)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %94

76:                                               ; preds = %62
  br label %77

77:                                               ; preds = %76
  br label %78

78:                                               ; preds = %77
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = load i64, ptr %10, align 8, !tbaa !9
  %82 = getelementptr inbounds ptr, ptr %80, i64 %81
  %83 = load ptr, ptr %82, align 8, !tbaa !5
  %84 = call i32 @secp256k1_pubkey_load(ptr noundef %79, ptr noundef %12, ptr noundef %83)
  call void @secp256k1_gej_add_ge(ptr noundef %11, ptr noundef %11, ptr noundef %12)
  br label %85

85:                                               ; preds = %78
  %86 = load i64, ptr %10, align 8, !tbaa !9
  %87 = add i64 %86, 1
  store i64 %87, ptr %10, align 8, !tbaa !9
  br label %57, !llvm.loop !11

88:                                               ; preds = %57
  %89 = call i32 @secp256k1_gej_is_infinity(ptr noundef %11)
  %90 = icmp ne i32 %89, 0
  br i1 %90, label %91, label %92

91:                                               ; preds = %88
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %94

92:                                               ; preds = %88
  call void @secp256k1_ge_set_gej(ptr noundef %12, ptr noundef %11)
  %93 = load ptr, ptr %7, align 8, !tbaa !5
  call void @secp256k1_pubkey_save(ptr noundef %93, ptr noundef %12)
  store i32 1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %94

94:                                               ; preds = %92, %91, %73, %51, %37, %22
  call void @llvm.lifetime.end.p0(i64 88, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %95 = load i32, ptr %5, align 4
  ret i32 %95
}

; Function Attrs: nounwind uwtable
declare hidden void @secp256k1_gej_set_infinity(ptr noundef) #4

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

; Function Attrs: nounwind uwtable
declare hidden i32 @secp256k1_gej_is_infinity(ptr noundef) #4

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { 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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

%struct.secp256k1_gej = type { %struct.secp256k1_fe, %struct.secp256k1_fe, %struct.secp256k1_fe, i32 }
%struct.secp256k1_fe = type { [5 x i64] }
%struct.secp256k1_ge = type { %struct.secp256k1_fe, %struct.secp256k1_fe, i32 }

@.str.23 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [21 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @secp256k1_ec_pubkey_combine(ptr noundef %0, ptr noundef %1, ptr noundef readonly %2, i64 noundef %3) local_unnamed_addr #3 {
  %5 = alloca %struct.secp256k1_gej, align 8
  %6 = alloca %struct.secp256k1_ge, align 8
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 88, ptr nonnull %6) #4
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %7, label %9, !prof !5

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 168
  tail call void @secp256k1_callback_call(ptr noundef nonnull %8, ptr noundef nonnull @.str.23)
  br label %27

9:                                                ; preds = %4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(64) %1, i8 0, i64 64, i1 false)
  %.not18 = icmp eq i64 %3, 0
  br i1 %.not18, label %10, label %12, !prof !5

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

12:                                               ; preds = %9
  %.not19 = icmp eq ptr %2, null
  br i1 %.not19, 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.25)
  br label %27

15:                                               ; preds = %12
  call void @secp256k1_gej_set_infinity(ptr noundef nonnull %5)
  br label %16

16:                                               ; preds = %15, %21
  %.022 = phi i64 [ 0, %15 ], [ %23, %21 ]
  %17 = getelementptr inbounds ptr, ptr %2, i64 %.022
  %18 = load ptr, ptr %17, align 8, !tbaa !6
  %.not21 = icmp eq ptr %18, null
  br i1 %.not21, label %19, label %21, !prof !5

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %0, i64 168
  call void @secp256k1_callback_call(ptr noundef nonnull %20, ptr noundef nonnull @.str.26)
  br label %27

21:                                               ; preds = %16
  %22 = call i32 @secp256k1_pubkey_load(ptr noundef %0, ptr noundef nonnull %6, ptr noundef nonnull %18)
  call void @secp256k1_gej_add_ge(ptr noundef nonnull %5, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %23 = add nuw i64 %.022, 1
  %exitcond.not = icmp eq i64 %23, %3
  br i1 %exitcond.not, label %24, label %16, !llvm.loop !10

24:                                               ; preds = %21
  %25 = call i32 @secp256k1_gej_is_infinity(ptr noundef nonnull %5)
  %.not20 = icmp eq i32 %25, 0
  br i1 %.not20, label %26, label %27

26:                                               ; preds = %24
  call void @secp256k1_ge_set_gej(ptr noundef nonnull %6, ptr noundef nonnull %5)
  call void @secp256k1_pubkey_save(ptr noundef nonnull %1, ptr noundef nonnull %6)
  br label %27

27:                                               ; preds = %24, %26, %19, %13, %10, %7
  %.017 = phi i32 [ 0, %7 ], [ 0, %10 ], [ 0, %13 ], [ 0, %19 ], [ 1, %26 ], [ 0, %24 ]
  call void @llvm.lifetime.end.p0(i64 88, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %5) #4
  ret i32 %.017
}

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @secp256k1_ge_set_gej(ptr noundef, ptr noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!6 = !{!7, !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LowerExpectIntrinsicPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass