; LLVM IR from albertobsd/keyhunt :: gmp256k1/GMP256K1.ll (ZN9Secp256K14GetYE3Intb)

; 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"

%class.Int = type { [1 x %struct.__mpz_struct] }
%struct.__mpz_struct = type { i32, i32, ptr }
%class.Secp256K1 = type { %class.Point, %class.Int, %class.Int, [8192 x %class.Point] }
%class.Point = type { %class.Int, %class.Int, %class.Int }

declare void @_ZN3IntC1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN3IntD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9Secp256K14GetYE3Intb(ptr dead_on_unwind noalias writable sret(%class.Int) align 8 %0, ptr noundef nonnull align 8 dereferenceable(393296) %1, ptr noundef %2, i1 noundef zeroext %3) #3 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i1, align 1
  %10 = alloca [1 x %struct.__mpz_struct], align 16
  %11 = alloca [1 x %struct.__mpz_struct], align 16
  %12 = alloca [1 x %struct.__mpz_struct], align 16
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %15 = zext i1 %3 to i8
  store i8 %15, ptr %8, align 1, !tbaa !9
  %16 = load ptr, ptr %6, align 8
  store i1 false, ptr %9, align 1
  call void @_ZN3IntC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0)
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #5
  %17 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %10, i64 0, i64 0
  %18 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %11, i64 0, i64 0
  %19 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %12, i64 0, i64 0
  call void (ptr, ...) @__gmpz_inits(ptr noundef %17, ptr noundef %18, ptr noundef %19, i64 noundef 0) #5
  %20 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %10, i64 0, i64 0
  %21 = getelementptr inbounds %class.Int, ptr %2, i32 0, i32 0
  %22 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %21, i64 0, i64 0
  invoke void @__gmpz_pow_ui(ptr noundef %20, ptr noundef %22, i64 noundef 3)
          to label %23 unwind label %69

23:                                               ; preds = %4
  %24 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %12, i64 0, i64 0
  %25 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %10, i64 0, i64 0
  invoke void @__gmpz_add_ui(ptr noundef %24, ptr noundef %25, i64 noundef 7)
          to label %26 unwind label %69

26:                                               ; preds = %23
  %27 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %12, i64 0, i64 0
  %28 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %12, i64 0, i64 0
  %29 = getelementptr inbounds %class.Secp256K1, ptr %16, i32 0, i32 1
  %30 = getelementptr inbounds %class.Int, ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %30, i64 0, i64 0
  invoke void @__gmpz_mod(ptr noundef %27, ptr noundef %28, ptr noundef %31)
          to label %32 unwind label %69

32:                                               ; preds = %26
  %33 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %10, i64 0, i64 0
  %34 = getelementptr inbounds %class.Secp256K1, ptr %16, i32 0, i32 1
  %35 = getelementptr inbounds %class.Int, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %35, i64 0, i64 0
  invoke void @__gmpz_add_ui(ptr noundef %33, ptr noundef %36, i64 noundef 1)
          to label %37 unwind label %69

37:                                               ; preds = %32
  %38 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %11, i64 0, i64 0
  %39 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %10, i64 0, i64 0
  %40 = invoke i64 @__gmpz_fdiv_q_ui(ptr noundef %38, ptr noundef %39, i64 noundef 4)
          to label %41 unwind label %69

41:                                               ; preds = %37
  %42 = getelementptr inbounds %class.Int, ptr %0, i32 0, i32 0
  %43 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %42, i64 0, i64 0
  %44 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %12, i64 0, i64 0
  %45 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %11, i64 0, i64 0
  %46 = getelementptr inbounds %class.Secp256K1, ptr %16, i32 0, i32 1
  %47 = getelementptr inbounds %class.Int, ptr %46, i32 0, i32 0
  %48 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %47, i64 0, i64 0
  invoke void @__gmpz_powm(ptr noundef %43, ptr noundef %44, ptr noundef %45, ptr noundef %48)
          to label %49 unwind label %69

49:                                               ; preds = %41
  %50 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %10, i64 0, i64 0
  %51 = getelementptr inbounds %class.Secp256K1, ptr %16, i32 0, i32 1
  %52 = getelementptr inbounds %class.Int, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %52, i64 0, i64 0
  %54 = getelementptr inbounds %class.Int, ptr %0, i32 0, i32 0
  %55 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %54, i64 0, i64 0
  invoke void @__gmpz_sub(ptr noundef %50, ptr noundef %53, ptr noundef %55)
          to label %56 unwind label %69

56:                                               ; preds = %49
  %57 = getelementptr inbounds %class.Int, ptr %0, i32 0, i32 0
  %58 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %57, i64 0, i64 0
  %59 = call i32 @__gmpz_tstbit(ptr noundef %58, i64 noundef 0) #6
  %60 = icmp eq i32 %59, 1
  br i1 %60, label %61, label %73

61:                                               ; preds = %56
  %62 = load i8, ptr %8, align 1, !tbaa !9, !range !11, !noundef !12
  %63 = trunc i8 %62 to i1
  br i1 %63, label %64, label %73

64:                                               ; preds = %61
  %65 = getelementptr inbounds %class.Int, ptr %0, i32 0, i32 0
  %66 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %65, i64 0, i64 0
  %67 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %10, i64 0, i64 0
  invoke void @__gmpz_set(ptr noundef %66, ptr noundef %67)
          to label %68 unwind label %69

68:                                               ; preds = %64
  br label %87

69:                                               ; preds = %87, %81, %64, %49, %41, %37, %32, %26, %23, %4
  %70 = landingpad { ptr, i32 }
          cleanup
  %71 = extractvalue { ptr, i32 } %70, 0
  store ptr %71, ptr %13, align 8
  %72 = extractvalue { ptr, i32 } %70, 1
  store i32 %72, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #5
  call void @_ZN3IntD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #5
  br label %95

73:                                               ; preds = %61, %56
  %74 = getelementptr inbounds %class.Int, ptr %0, i32 0, i32 0
  %75 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %74, i64 0, i64 0
  %76 = call i32 @__gmpz_tstbit(ptr noundef %75, i64 noundef 0) #6
  %77 = icmp eq i32 %76, 0
  br i1 %77, label %78, label %86

78:                                               ; preds = %73
  %79 = load i8, ptr %8, align 1, !tbaa !9, !range !11, !noundef !12
  %80 = trunc i8 %79 to i1
  br i1 %80, label %86, label %81

81:                                               ; preds = %78
  %82 = getelementptr inbounds %class.Int, ptr %0, i32 0, i32 0
  %83 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %82, i64 0, i64 0
  %84 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %10, i64 0, i64 0
  invoke void @__gmpz_set(ptr noundef %83, ptr noundef %84)
          to label %85 unwind label %69

85:                                               ; preds = %81
  br label %86

86:                                               ; preds = %85, %78, %73
  br label %87

87:                                               ; preds = %86, %68
  %88 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %10, i64 0, i64 0
  %89 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %11, i64 0, i64 0
  %90 = getelementptr inbounds [1 x %struct.__mpz_struct], ptr %12, i64 0, i64 0
  invoke void (ptr, ...) @__gmpz_clears(ptr noundef %88, ptr noundef %89, ptr noundef %90, i64 noundef 0)
          to label %91 unwind label %69

91:                                               ; preds = %87
  store i1 true, ptr %9, align 1
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #5
  %92 = load i1, ptr %9, align 1
  br i1 %92, label %94, label %93

93:                                               ; preds = %91
  call void @_ZN3IntD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #5
  br label %94

94:                                               ; preds = %93, %91
  ret void

95:                                               ; preds = %69
  %96 = load ptr, ptr %13, align 8
  %97 = load i32, ptr %14, align 4
  %98 = insertvalue { ptr, i32 } poison, ptr %96, 0
  %99 = insertvalue { ptr, i32 } %98, i32 %97, 1
  resume { ptr, i32 } %99
}

; Function Attrs: nounwind
declare void @__gmpz_inits(ptr noundef, ...) #1

declare void @__gmpz_pow_ui(ptr noundef, ptr noundef, i64 noundef) #0

declare void @__gmpz_add_ui(ptr noundef, ptr noundef, i64 noundef) #0

declare void @__gmpz_mod(ptr noundef, ptr noundef, ptr noundef) #0

declare i64 @__gmpz_fdiv_q_ui(ptr noundef, ptr noundef, i64 noundef) #0

declare void @__gmpz_powm(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

declare void @__gmpz_sub(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind willreturn memory(read)
declare i32 @__gmpz_tstbit(ptr noundef, i64 noundef) #4

declare void @__gmpz_set(ptr noundef, ptr noundef) #0

declare void @__gmpz_clears(ptr noundef, ...) #0

attributes #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 = { nounwind "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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress 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 willreturn memory(read) "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 }
attributes #6 = { nounwind willreturn memory(read) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}


; 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"

%class.Int = type { [1 x %struct.__mpz_struct] }
%struct.__mpz_struct = type { i32, i32, ptr }

declare void @_ZN3IntC1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN3IntD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9Secp256K14GetYE3Intb(ptr dead_on_unwind noalias nonnull writable sret(%class.Int) align 8 %0, ptr noundef nonnull align 8 dereferenceable(393296) %1, ptr noundef %2, i1 noundef zeroext %3) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca [1 x %struct.__mpz_struct], align 16
  %6 = alloca [1 x %struct.__mpz_struct], align 16
  %7 = alloca [1 x %struct.__mpz_struct], align 16
  tail call void @_ZN3IntC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #5
  call void (ptr, ...) @__gmpz_inits(ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef nonnull %7, i64 noundef 0) #5
  invoke void @__gmpz_pow_ui(ptr noundef nonnull %5, ptr noundef %2, i64 noundef 3)
          to label %8 unwind label %18

8:                                                ; preds = %4
  invoke void @__gmpz_add_ui(ptr noundef nonnull %7, ptr noundef nonnull %5, i64 noundef 7)
          to label %9 unwind label %18

9:                                                ; preds = %8
  %10 = getelementptr inbounds i8, ptr %1, i64 48
  invoke void @__gmpz_mod(ptr noundef nonnull %7, ptr noundef nonnull %7, ptr noundef nonnull %10)
          to label %11 unwind label %18

11:                                               ; preds = %9
  invoke void @__gmpz_add_ui(ptr noundef nonnull %5, ptr noundef nonnull %10, i64 noundef 1)
          to label %12 unwind label %18

12:                                               ; preds = %11
  %13 = invoke i64 @__gmpz_fdiv_q_ui(ptr noundef nonnull %6, ptr noundef nonnull %5, i64 noundef 4)
          to label %14 unwind label %18

14:                                               ; preds = %12
  invoke void @__gmpz_powm(ptr noundef nonnull %0, ptr noundef nonnull %7, ptr noundef nonnull %6, ptr noundef nonnull %10)
          to label %15 unwind label %18

15:                                               ; preds = %14
  invoke void @__gmpz_sub(ptr noundef nonnull %5, ptr noundef nonnull %10, ptr noundef nonnull %0)
          to label %16 unwind label %18

16:                                               ; preds = %15
  %17 = call i32 @__gmpz_tstbit(ptr noundef nonnull %0, i64 noundef 0) #6
  %or.cond.v = zext i1 %3 to i32
  %or.cond.not = icmp eq i32 %17, %or.cond.v
  br i1 %or.cond.not, label %.invoke, label %20

18:                                               ; preds = %.invoke, %20, %15, %14, %12, %11, %9, %8, %4
  %19 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #5
  call void @_ZN3IntD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #5
  resume { ptr, i32 } %19

.invoke:                                          ; preds = %16
  invoke void @__gmpz_set(ptr noundef nonnull %0, ptr noundef nonnull %5)
          to label %20 unwind label %18

20:                                               ; preds = %16, %.invoke
  invoke void (ptr, ...) @__gmpz_clears(ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef nonnull %7, i64 noundef 0)
          to label %21 unwind label %18

21:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #5
  ret void
}

; Function Attrs: nounwind
declare void @__gmpz_inits(ptr noundef, ...) local_unnamed_addr #1

declare void @__gmpz_pow_ui(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

declare void @__gmpz_add_ui(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

declare void @__gmpz_mod(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare i64 @__gmpz_fdiv_q_ui(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

declare void @__gmpz_powm(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @__gmpz_sub(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @__gmpz_tstbit(ptr noundef, i64 noundef) local_unnamed_addr #4

declare void @__gmpz_set(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @__gmpz_clears(ptr noundef, ...) local_unnamed_addr #0

attributes #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 = { nounwind "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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress 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 = { mustprogress nofree nounwind willreturn memory(read) "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 }
attributes #6 = { nounwind willreturn memory(read) }

!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)"}


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