; 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_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_gej }
%struct.secp256k1_scalar = type { [4 x i64] }
%struct.secp256k1_callback = type { ptr, ptr }

@.str.22 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.25 = 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 %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  %17 = zext i1 %16 to i32
  br label %18

18:                                               ; preds = %14
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  %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 = %20
  %29 = load ptr, ptr %6, 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.22)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %100

31:                                               ; preds = %20
  br label %32

32:                                               ; preds = %31
  br label %33

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

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

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

46:                                               ; preds = %35
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  br label %49

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

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

60:                                               ; preds = %49
  br label %61

61:                                               ; preds = %60
  br label %62

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

63:                                               ; preds = %91, %62
  %64 = load i64, ptr %10, align 8, !tbaa !9
  %65 = load i64, ptr %9, align 8, !tbaa !9
  %66 = icmp ult i64 %64, %65
  br i1 %66, label %67, label %94

67:                                               ; preds = %63
  br label %68

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

79:                                               ; preds = %68
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %80, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %81, ptr noundef @.str.25)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %100

82:                                               ; preds = %68
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = load i64, ptr %10, align 8, !tbaa !9
  %88 = getelementptr inbounds ptr, ptr %86, i64 %87
  %89 = load ptr, ptr %88, align 8, !tbaa !5
  %90 = call i32 @secp256k1_pubkey_load(ptr noundef %85, ptr noundef %12, ptr noundef %89)
  call void @secp256k1_gej_add_ge(ptr noundef %11, ptr noundef %11, ptr noundef %12)
  br label %91

91:                                               ; preds = %84
  %92 = load i64, ptr %10, align 8, !tbaa !9
  %93 = add i64 %92, 1
  store i64 %93, ptr %10, align 8, !tbaa !9
  br label %63, !llvm.loop !11

94:                                               ; preds = %63
  %95 = call i32 @secp256k1_gej_is_infinity(ptr noundef %11)
  %96 = icmp ne i32 %95, 0
  br i1 %96, label %97, label %98

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

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

100:                                              ; preds = %98, %97, %79, %57, %43, %28
  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
  %101 = load i32, ptr %5, align 4
  ret i32 %101
}

; 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.22 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.25 = 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.22)
  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)
  %.not19 = icmp eq i64 %3, 0
  br i1 %.not19, 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.23)
  br label %27

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

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

16:                                               ; preds = %15, %21
  %.023 = phi i64 [ 0, %15 ], [ %23, %21 ]
  %17 = getelementptr inbounds ptr, ptr %2, i64 %.023
  %18 = load ptr, ptr %17, align 8, !tbaa !6
  %.not22 = icmp eq ptr %18, null
  br i1 %.not22, 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.25)
  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 %.023, 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)
  %.not21 = icmp eq i32 %25, 0
  br i1 %.not21, 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
  %.018 = 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 %.018
}

; 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