; 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_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_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.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 %7, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  %19 = zext i1 %18 to i32
  br label %20

20:                                               ; preds = %16
  br label %21

21:                                               ; preds = %20
  br label %22

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

30:                                               ; preds = %22
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %31, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %32, ptr noundef @.str.9)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %122

33:                                               ; preds = %22
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = load i64, ptr %37, align 8, !tbaa !11
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = and i32 %39, 256
  %41 = icmp ne i32 %40, 0
  %42 = zext i1 %41 to i64
  %43 = select i1 %41, i32 33, i32 65
  %44 = zext i32 %43 to i64
  %45 = icmp uge i64 %38, %44
  %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 = %36
  %52 = load ptr, ptr %7, 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.10)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %122

54:                                               ; preds = %36
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = load i64, ptr %57, align 8, !tbaa !11
  store i64 %58, ptr %13, align 8, !tbaa !11
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %59, align 8, !tbaa !11
  br label %60

60:                                               ; preds = %56
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  %63 = xor i1 %62, true
  %64 = zext i1 %63 to i32
  %65 = sext i32 %64 to i64
  %66 = call i64 @llvm.expect.i64(i64 %65, i64 0)
  %67 = icmp ne i64 %66, 0
  br i1 %67, label %68, label %71

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

71:                                               ; preds = %60
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = load i64, ptr %13, align 8, !tbaa !11
  call void @llvm.memset.p0.i64(ptr align 1 %74, i8 0, i64 %75, i1 false)
  br label %76

76:                                               ; preds = %73
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = icmp ne ptr %77, null
  %79 = xor i1 %78, true
  %80 = zext i1 %79 to i32
  %81 = sext i32 %80 to i64
  %82 = call i64 @llvm.expect.i64(i64 %81, i64 0)
  %83 = icmp ne i64 %82, 0
  br i1 %83, label %84, label %87

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

87:                                               ; preds = %76
  br label %88

88:                                               ; preds = %87
  br label %89

89:                                               ; preds = %88
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %11, align 4, !tbaa !9
  %92 = and i32 %91, 255
  %93 = icmp eq i32 %92, 2
  %94 = xor i1 %93, true
  %95 = zext i1 %94 to i32
  %96 = sext i32 %95 to i64
  %97 = call i64 @llvm.expect.i64(i64 %96, i64 0)
  %98 = icmp ne i64 %97, 0
  br i1 %98, label %99, label %102

99:                                               ; preds = %90
  %100 = load ptr, ptr %7, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %100, i32 0, i32 1
  call void @secp256k1_callback_call(ptr noundef %101, ptr noundef @.str.12)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %122

102:                                              ; preds = %90
  br label %103

103:                                              ; preds = %102
  br label %104

104:                                              ; preds = %103
  %105 = load ptr, ptr %7, align 8, !tbaa !5
  %106 = load ptr, ptr %10, align 8, !tbaa !5
  %107 = call i32 @secp256k1_pubkey_load(ptr noundef %105, ptr noundef %12, ptr noundef %106)
  %108 = icmp ne i32 %107, 0
  br i1 %108, label %109, label %120

109:                                              ; preds = %104
  %110 = load ptr, ptr %8, align 8, !tbaa !5
  %111 = load i32, ptr %11, align 4, !tbaa !9
  %112 = and i32 %111, 256
  %113 = call i32 @secp256k1_eckey_pubkey_serialize(ptr noundef %12, ptr noundef %110, ptr noundef %13, i32 noundef %112)
  store i32 %113, ptr %14, align 4, !tbaa !9
  %114 = load i32, ptr %14, align 4, !tbaa !9
  %115 = icmp ne i32 %114, 0
  br i1 %115, label %116, label %119

116:                                              ; preds = %109
  %117 = load i64, ptr %13, align 8, !tbaa !11
  %118 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %117, ptr %118, align 8, !tbaa !11
  br label %119

119:                                              ; preds = %116, %109
  br label %120

120:                                              ; preds = %119, %104
  %121 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %121, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %122

122:                                              ; preds = %120, %99, %84, %68, %51, %30
  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
  %123 = load i32, ptr %6, align 4
  ret i32 %123
}

; 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
  %.not24 = icmp eq i32 %12, 0
  %13 = select i1 %.not24, i64 65, i64 33
  %.not25 = icmp ult i64 %11, %13
  br i1 %.not25, 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
  %.not26 = icmp eq ptr %1, null
  br i1 %.not26, 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)
  %.not27 = icmp eq ptr %3, null
  br i1 %.not27, 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
  %.not28 = icmp eq i32 %23, 2
  br i1 %.not28, 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)
  %.not29 = icmp eq i32 %27, 0
  br i1 %.not29, label %32, label %28

28:                                               ; preds = %26
  %29 = call i32 @secp256k1_eckey_pubkey_serialize(ptr noundef nonnull %6, ptr noundef nonnull %1, ptr noundef nonnull %7, i32 noundef %12)
  %.not30 = icmp eq i32 %29, 0
  br i1 %.not30, 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
  %.022 = 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 %.022
}

; 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