; 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_ge = type { %struct.secp256k1_fe, %struct.secp256k1_fe, i32 }
%struct.secp256k1_fe = type { [5 x i64] }
%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_callback = type { ptr, ptr }

@.str.7 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [60 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: 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_ecmult_gen_context_is_built(ptr noundef) #4

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

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

12:                                               ; preds = %3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  %15 = zext i1 %14 to i32
  br label %16

16:                                               ; preds = %12
  br label %17

17:                                               ; preds = %16
  br label %18

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

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

29:                                               ; preds = %18
  br label %30

30:                                               ; preds = %29
  br label %31

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

33:                                               ; preds = %31
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %34, i32 0, i32 0
  %36 = call i32 @secp256k1_ecmult_gen_context_is_built(ptr noundef %35)
  %37 = icmp ne i32 %36, 0
  %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 = %33
  %44 = load ptr, ptr %5, 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.18)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %74

46:                                               ; preds = %33
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %7, 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 %5, 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.20)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %74

60:                                               ; preds = %49
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = call i32 @secp256k1_ec_pubkey_create_helper(ptr noundef %64, ptr noundef %9, ptr noundef %8, ptr noundef %65)
  store i32 %66, ptr %10, align 4, !tbaa !9
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  call void @secp256k1_pubkey_save(ptr noundef %67, ptr noundef %8)
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load i32, ptr %10, align 4, !tbaa !9
  %70 = icmp ne i32 %69, 0
  %71 = xor i1 %70, true
  %72 = zext i1 %71 to i32
  call void @secp256k1_memczero(ptr noundef %68, i64 noundef 64, i32 noundef %72)
  call void @secp256k1_scalar_clear(ptr noundef %9)
  %73 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %73, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %74

74:                                               ; preds = %62, %57, %43, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 88, ptr %8) #5
  %75 = load i32, ptr %4, align 4
  ret i32 %75
}

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

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

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 = !{!"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_ge = type { %struct.secp256k1_fe, %struct.secp256k1_fe, i32 }
%struct.secp256k1_fe = type { [5 x i64] }
%struct.secp256k1_scalar = type { [4 x i64] }

@.str.7 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [60 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: 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_ecmult_gen_context_is_built(ptr noundef) local_unnamed_addr #3

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

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

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 168
  tail call void @secp256k1_callback_call(ptr noundef nonnull %7, ptr noundef nonnull @.str.7)
  br label %18

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

10:                                               ; preds = %8
  %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 %18

12:                                               ; preds = %8
  %.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.20)
  br label %18

15:                                               ; preds = %12
  %16 = call i32 @secp256k1_ec_pubkey_create_helper(ptr noundef %0, ptr noundef nonnull %5, ptr noundef nonnull %4, ptr noundef nonnull %2)
  call void @secp256k1_pubkey_save(ptr noundef nonnull %1, ptr noundef nonnull %4)
  %.not16 = icmp eq i32 %16, 0
  %17 = zext i1 %.not16 to i32
  call void @secp256k1_memczero(ptr noundef nonnull %1, i64 noundef 64, i32 noundef %17)
  call void @secp256k1_scalar_clear(ptr noundef nonnull %5)
  br label %18

18:                                               ; preds = %15, %13, %10, %6
  %.0 = phi i32 [ 0, %6 ], [ 0, %10 ], [ 0, %13 ], [ %16, %15 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 88, ptr nonnull %4) #4
  ret i32 %.0
}

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

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

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}


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