; 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.21 = external hidden unnamed_addr constant [15 x i8], align 1
@secp256k1_scalar_zero = external hidden constant %struct.secp256k1_scalar, align 8
@.str.22 = external hidden unnamed_addr constant [16 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_scalar_get_b32(ptr noundef, ptr noundef) #3

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @secp256k1_ec_seckey_tweak_add(ptr noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.secp256k1_scalar, align 8
  %9 = alloca i32, align 4
  %10 = 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 32, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %11

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

19:                                               ; preds = %11
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %20, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %21, ptr noundef @.str.21)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %51

22:                                               ; preds = %11
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  %28 = xor i1 %27, true
  %29 = zext i1 %28 to i32
  %30 = sext i32 %29 to i64
  %31 = call i64 @llvm.expect.i64(i64 %30, i64 0)
  %32 = icmp ne i64 %31, 0
  br i1 %32, label %33, label %36

33:                                               ; preds = %25
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %34, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %35, ptr noundef @.str.22)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %51

36:                                               ; preds = %25
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = call i32 @secp256k1_scalar_set_b32_seckey(ptr noundef %8, ptr noundef %39)
  store i32 %40, ptr %9, align 4, !tbaa !9
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = call i32 @secp256k1_ec_seckey_tweak_add_helper(ptr noundef %8, ptr noundef %41)
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = and i32 %43, %42
  store i32 %44, ptr %9, align 4, !tbaa !9
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = icmp ne i32 %45, 0
  %47 = xor i1 %46, true
  %48 = zext i1 %47 to i32
  call void @secp256k1_scalar_cmov(ptr noundef %8, ptr noundef @secp256k1_scalar_zero, i32 noundef %48)
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  call void @secp256k1_scalar_get_b32(ptr noundef %49, ptr noundef %8)
  call void @secp256k1_scalar_clear(ptr noundef %8)
  %50 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %50, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %51

51:                                               ; preds = %38, %33, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #4
  %52 = load i32, ptr %4, align 4
  ret i32 %52
}

; Function Attrs: nounwind uwtable
declare hidden i32 @secp256k1_ec_seckey_tweak_add_helper(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.21 = external hidden unnamed_addr constant [15 x i8], align 1
@secp256k1_scalar_zero = external hidden constant %struct.secp256k1_scalar, align 8
@.str.22 = external hidden unnamed_addr constant [16 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_scalar_get_b32(ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

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

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

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

7:                                                ; preds = %3
  %.not10 = icmp eq ptr %2, null
  br i1 %.not10, label %8, label %10, !prof !5

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

10:                                               ; preds = %7
  %11 = call i32 @secp256k1_scalar_set_b32_seckey(ptr noundef nonnull %4, ptr noundef nonnull %1)
  %12 = call i32 @secp256k1_ec_seckey_tweak_add_helper(ptr noundef nonnull %4, ptr noundef nonnull %2)
  %13 = and i32 %12, %11
  %.not11 = icmp eq i32 %13, 0
  %14 = zext i1 %.not11 to i32
  call void @secp256k1_scalar_cmov(ptr noundef nonnull %4, ptr noundef nonnull @secp256k1_scalar_zero, i32 noundef %14)
  call void @secp256k1_scalar_get_b32(ptr noundef nonnull %1, ptr noundef nonnull %4)
  call void @secp256k1_scalar_clear(ptr noundef nonnull %4)
  br label %15

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

; Function Attrs: nounwind uwtable
declare hidden i32 @secp256k1_ec_seckey_tweak_add_helper(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,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass