; 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_callback = type { ptr, ptr }
%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_fe = type { [5 x i64] }

@default_error_callback = external hidden constant %struct.secp256k1_callback, align 8
@default_illegal_callback = external hidden constant %struct.secp256k1_callback, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @secp256k1_selftest() #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @secp256k1_context_preallocated_size(i32 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(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @secp256k1_context_preallocated_create(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @secp256k1_selftest()
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = call i64 @secp256k1_context_preallocated_size(i32 noundef %9)
  store i64 %10, ptr %6, align 8, !tbaa !11
  %11 = load i64, ptr %6, align 8, !tbaa !11
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %44

14:                                               ; preds = %2
  br label %15

15:                                               ; preds = %14
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  %18 = zext i1 %17 to i32
  br label %19

19:                                               ; preds = %15
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %21, ptr %7, align 8, !tbaa !5
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %22, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %23, ptr align 8 @default_illegal_callback, i64 16, i1 false), !tbaa.struct !13
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %24, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %25, ptr align 8 @default_error_callback, i64 16, i1 false), !tbaa.struct !13
  br label %26

26:                                               ; preds = %20
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = and i32 %27, 255
  %29 = icmp eq i32 %28, 1
  %30 = zext i1 %29 to i32
  br label %31

31:                                               ; preds = %26
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %33, i32 0, i32 0
  call void @secp256k1_ecmult_gen_context_build(ptr noundef %34)
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = and i32 %35, 1024
  %37 = icmp ne i32 %36, 0
  %38 = xor i1 %37, true
  %39 = xor i1 %38, true
  %40 = zext i1 %39 to i32
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.secp256k1_context_struct, ptr %41, i32 0, i32 3
  store i32 %40, ptr %42, align 8, !tbaa !14
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %43, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %44

44:                                               ; preds = %32, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %45 = load ptr, ptr %3, align 8
  ret ptr %45
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

attributes #0 = { 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 nounwind willreturn memory(argmem: readwrite) }
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 = !{!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}
!13 = !{i64 0, i64 8, !5, i64 8, i64 8, !5}
!14 = !{!15, !10, i64 200}
!15 = !{!"secp256k1_context_struct", !16, i64 0, !19, i64 168, !19, i64 184, !10, i64 200}
!16 = !{!"", !10, i64 0, !17, i64 8, !18, i64 40}
!17 = !{!"", !7, i64 0}
!18 = !{!"", !17, i64 0, !17, i64 40, !17, i64 80, !10, i64 120}
!19 = !{!"", !6, i64 0, !6, i64 8}


; 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_callback = type { ptr, ptr }

@default_error_callback = external hidden local_unnamed_addr constant %struct.secp256k1_callback, align 8
@default_illegal_callback = external hidden local_unnamed_addr constant %struct.secp256k1_callback, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @secp256k1_selftest() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @secp256k1_context_preallocated_size(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @secp256k1_context_preallocated_create(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  tail call void @secp256k1_selftest()
  %3 = tail call i64 @secp256k1_context_preallocated_size(i32 noundef %1)
  %4 = icmp eq i64 %3, 0
  br i1 %4, label %10, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 168
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(16) @default_illegal_callback, i64 16, i1 false), !tbaa.struct !5
  %7 = getelementptr inbounds i8, ptr %0, i64 184
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %7, ptr noundef nonnull align 8 dereferenceable(16) @default_error_callback, i64 16, i1 false), !tbaa.struct !5
  tail call void @secp256k1_ecmult_gen_context_build(ptr noundef %0)
  %8 = lshr i32 %1, 10
  %.lobit = and i32 %8, 1
  %9 = getelementptr inbounds i8, ptr %0, i64 200
  store i32 %.lobit, ptr %9, align 8, !tbaa !10
  br label %10

10:                                               ; preds = %2, %5
  %.0 = phi ptr [ %0, %5 ], [ null, %2 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

attributes #0 = { 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 nounwind willreturn memory(argmem: readwrite) }

!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 = !{i64 0, i64 8, !6, i64 8, i64 8, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !13, i64 200}
!11 = !{!"secp256k1_context_struct", !12, i64 0, !16, i64 168, !16, i64 184, !13, i64 200}
!12 = !{!"", !13, i64 0, !14, i64 8, !15, i64 40}
!13 = !{!"int", !8, i64 0}
!14 = !{!"", !8, i64 0}
!15 = !{!"", !14, i64 0, !14, i64 40, !14, i64 80, !13, i64 120}
!16 = !{!"", !7, i64 0, !7, i64 8}


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