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

@.str.7 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [72 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
define dso_local i32 @secp256k1_ec_pubkey_serialize(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) #4 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca %struct.secp256k1_ge, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 88, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %16

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

24:                                               ; preds = %16
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %25, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %26, ptr noundef @.str.9)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %120

27:                                               ; preds = %16
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = load i64, ptr %31, align 8, !tbaa !11
  %33 = load i32, ptr %11, align 4, !tbaa !9
  %34 = and i32 %33, 256
  %35 = icmp ne i32 %34, 0
  %36 = zext i1 %35 to i64
  %37 = select i1 %35, i32 33, i32 65
  %38 = zext i32 %37 to i64
  %39 = icmp uge i64 %32, %38
  %40 = xor i1 %39, true
  %41 = zext i1 %40 to i32
  %42 = sext i32 %41 to i64
  %43 = call i64 @llvm.expect.i64(i64 %42, i64 0)
  %44 = icmp ne i64 %43, 0
  br i1 %44, label %45, label %48

45:                                               ; preds = %30
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %46, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %47, ptr noundef @.str.10)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %120

48:                                               ; preds = %30
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load i64, ptr %51, align 8, !tbaa !11
  store i64 %52, ptr %13, align 8, !tbaa !11
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %53, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %50
  %55 = load ptr, ptr %8, 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 %7, 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.11)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %120

65:                                               ; preds = %54
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = load i64, ptr %13, align 8, !tbaa !11
  call void @llvm.memset.p0.i64(ptr align 1 %68, i8 0, i64 %69, i1 false)
  br label %70

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

78:                                               ; preds = %70
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %79, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %80, ptr noundef @.str.7)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %120

81:                                               ; preds = %70
  br label %82

82:                                               ; preds = %81
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83
  %85 = load i32, ptr %11, align 4, !tbaa !9
  %86 = and i32 %85, 255
  %87 = icmp eq i32 %86, 2
  %88 = xor i1 %87, true
  %89 = zext i1 %88 to i32
  %90 = sext i32 %89 to i64
  %91 = call i64 @llvm.expect.i64(i64 %90, i64 0)
  %92 = icmp ne i64 %91, 0
  br i1 %92, label %93, label %96

93:                                               ; preds = %84
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %94, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %95, ptr noundef @.str.12)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %120

96:                                               ; preds = %84
  br label %97

97:                                               ; preds = %96
  br label %98

98:                                               ; preds = %97
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  %100 = load ptr, ptr %10, align 8, !tbaa !5
  %101 = call i32 @secp256k1_pubkey_load(ptr noundef %99, ptr noundef %12, ptr noundef %100)
  %102 = icmp ne i32 %101, 0
  br i1 %102, label %103, label %118

103:                                              ; preds = %98
  %104 = load ptr, ptr %8, align 8, !tbaa !5
  %105 = load i32, ptr %11, align 4, !tbaa !9
  %106 = and i32 %105, 256
  %107 = icmp ne i32 %106, 0
  %108 = xor i1 %107, true
  %109 = xor i1 %108, true
  %110 = zext i1 %109 to i32
  %111 = call i32 @secp256k1_eckey_pubkey_serialize(ptr noundef %12, ptr noundef %104, ptr noundef %13, i32 noundef %110)
  store i32 %111, ptr %14, align 4, !tbaa !9
  %112 = load i32, ptr %14, align 4, !tbaa !9
  %113 = icmp ne i32 %112, 0
  br i1 %113, label %114, label %117

114:                                              ; preds = %103
  %115 = load i64, ptr %13, align 8, !tbaa !11
  %116 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %115, ptr %116, align 8, !tbaa !11
  br label %117

117:                                              ; preds = %114, %103
  br label %118

118:                                              ; preds = %117, %98
  %119 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %119, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %120

120:                                              ; preds = %118, %93, %78, %62, %45, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 88, ptr %12) #5
  %121 = load i32, ptr %6, align 4
  ret i32 %121
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @secp256k1_eckey_pubkey_serialize(ptr noundef, ptr noundef, ptr noundef, i32 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !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] }

@.str.7 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [72 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
define dso_local i32 @secp256k1_ec_pubkey_serialize(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #3 {
  %6 = alloca %struct.secp256k1_ge, align 8
  %7 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 88, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %8, label %10, !prof !5

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

10:                                               ; preds = %5
  %11 = load i64, ptr %2, align 8, !tbaa !6
  %12 = and i32 %4, 256
  %.not28 = icmp eq i32 %12, 0
  %13 = select i1 %.not28, i64 65, i64 33
  %.not23 = icmp ult i64 %11, %13
  br i1 %.not23, label %14, label %16, !prof !5

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %0, i64 168
  tail call void @secp256k1_callback_call(ptr noundef nonnull %15, ptr noundef nonnull @.str.10)
  br label %32

16:                                               ; preds = %10
  store i64 %11, ptr %7, align 8, !tbaa !6
  store i64 0, ptr %2, align 8, !tbaa !6
  %.not24 = icmp eq ptr %1, null
  br i1 %.not24, label %17, label %19, !prof !5

17:                                               ; preds = %16
  %18 = getelementptr inbounds i8, ptr %0, i64 168
  tail call void @secp256k1_callback_call(ptr noundef nonnull %18, ptr noundef nonnull @.str.11)
  br label %32

19:                                               ; preds = %16
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %1, i8 0, i64 %11, i1 false)
  %.not25 = icmp eq ptr %3, null
  br i1 %.not25, label %20, label %22, !prof !5

20:                                               ; preds = %19
  %21 = getelementptr inbounds i8, ptr %0, i64 168
  tail call void @secp256k1_callback_call(ptr noundef nonnull %21, ptr noundef nonnull @.str.7)
  br label %32

22:                                               ; preds = %19
  %23 = and i32 %4, 255
  %.not26 = icmp eq i32 %23, 2
  br i1 %.not26, label %26, label %24, !prof !10

24:                                               ; preds = %22
  %25 = getelementptr inbounds i8, ptr %0, i64 168
  tail call void @secp256k1_callback_call(ptr noundef nonnull %25, ptr noundef nonnull @.str.12)
  br label %32

26:                                               ; preds = %22
  %27 = call i32 @secp256k1_pubkey_load(ptr noundef %0, ptr noundef nonnull %6, ptr noundef nonnull %3)
  %.not27 = icmp eq i32 %27, 0
  br i1 %.not27, label %32, label %28

28:                                               ; preds = %26
  %.lobit = lshr exact i32 %12, 8
  %29 = call i32 @secp256k1_eckey_pubkey_serialize(ptr noundef nonnull %6, ptr noundef nonnull %1, ptr noundef nonnull %7, i32 noundef %.lobit)
  %.not29 = icmp eq i32 %29, 0
  br i1 %.not29, label %32, label %30

30:                                               ; preds = %28
  %31 = load i64, ptr %7, align 8, !tbaa !6
  store i64 %31, ptr %2, align 8, !tbaa !6
  br label %32

32:                                               ; preds = %26, %30, %28, %24, %20, %17, %14, %8
  %.021 = phi i32 [ 0, %8 ], [ 0, %14 ], [ 0, %17 ], [ 0, %20 ], [ 0, %24 ], [ %29, %30 ], [ 0, %28 ], [ 0, %26 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 88, ptr nonnull %6) #4
  ret i32 %.021
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @secp256k1_eckey_pubkey_serialize(ptr noundef, ptr noundef, ptr noundef, i32 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 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"branch_weights", !"expected", i32 2000, i32 1}


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