; LLVM IR from trustwallet/wallet-core :: trezor-crypto/crypto (ecdsa)

; 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.bignum256 = type { [9 x i32] }
%struct.curve_point = type { %struct.bignum256, %struct.bignum256 }
%struct.ecdsa_curve = type { %struct.bignum256, %struct.curve_point, %struct.bignum256, %struct.bignum256, i32, %struct.bignum256, [64 x [8 x %struct.curve_point]] }

; Function Attrs: nounwind uwtable
declare dso_local void @point_copy(ptr noundef, ptr noundef) #0

; 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) #1

; Function Attrs: nounwind uwtable
define dso_local void @point_add(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.bignum256, align 4
  %8 = alloca %struct.bignum256, align 4
  %9 = alloca %struct.bignum256, align 4
  %10 = alloca %struct.bignum256, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 36, ptr %7) #5
  call void @llvm.memset.p0.i64(ptr align 4 %7, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr %8) #5
  call void @llvm.memset.p0.i64(ptr align 4 %8, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr %9) #5
  call void @llvm.memset.p0.i64(ptr align 4 %9, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr %10) #5
  call void @llvm.memset.p0.i64(ptr align 4 %10, i8 0, i64 36, i1 false)
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call i32 @point_is_infinity(ptr noundef %12)
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store i32 1, ptr %11, align 4
  br label %87

16:                                               ; preds = %3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = call i32 @point_is_infinity(ptr noundef %17)
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %16
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  call void @point_copy(ptr noundef %21, ptr noundef %22)
  store i32 1, ptr %11, align 4
  br label %87

23:                                               ; preds = %16
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = call i32 @point_is_equal(ptr noundef %24, ptr noundef %25)
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %31

28:                                               ; preds = %23
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  call void @point_double(ptr noundef %29, ptr noundef %30)
  store i32 1, ptr %11, align 4
  br label %87

31:                                               ; preds = %23
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = call i32 @point_is_negative_of(ptr noundef %32, ptr noundef %33)
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %38

36:                                               ; preds = %31
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  call void @point_set_infinity(ptr noundef %37)
  store i32 1, ptr %11, align 4
  br label %87

38:                                               ; preds = %31
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.curve_point, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.curve_point, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ecdsa_curve, ptr %43, i32 0, i32 0
  call void @bn_subtractmod(ptr noundef %40, ptr noundef %42, ptr noundef %8, ptr noundef %44)
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ecdsa_curve, ptr %45, i32 0, i32 0
  call void @bn_inverse(ptr noundef %8, ptr noundef %46)
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.curve_point, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.curve_point, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ecdsa_curve, ptr %51, i32 0, i32 0
  call void @bn_subtractmod(ptr noundef %48, ptr noundef %50, ptr noundef %7, ptr noundef %52)
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ecdsa_curve, ptr %53, i32 0, i32 0
  call void @bn_multiply(ptr noundef %8, ptr noundef %7, ptr noundef %54)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %7, i64 36, i1 false), !tbaa.struct !9
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ecdsa_curve, ptr %55, i32 0, i32 0
  call void @bn_multiply(ptr noundef %9, ptr noundef %9, ptr noundef %56)
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.curve_point, ptr %57, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %58, i64 36, i1 false), !tbaa.struct !9
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.curve_point, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.ecdsa_curve, ptr %61, i32 0, i32 0
  call void @bn_addmod(ptr noundef %10, ptr noundef %60, ptr noundef %62)
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ecdsa_curve, ptr %63, i32 0, i32 0
  call void @bn_subtractmod(ptr noundef %9, ptr noundef %10, ptr noundef %9, ptr noundef %64)
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ecdsa_curve, ptr %65, i32 0, i32 0
  call void @bn_fast_mod(ptr noundef %9, ptr noundef %66)
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.ecdsa_curve, ptr %67, i32 0, i32 0
  call void @bn_mod(ptr noundef %9, ptr noundef %68)
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.curve_point, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.ecdsa_curve, ptr %71, i32 0, i32 0
  call void @bn_subtractmod(ptr noundef %70, ptr noundef %9, ptr noundef %10, ptr noundef %72)
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.ecdsa_curve, ptr %73, i32 0, i32 0
  call void @bn_multiply(ptr noundef %7, ptr noundef %10, ptr noundef %74)
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.curve_point, ptr %75, i32 0, i32 1
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.ecdsa_curve, ptr %77, i32 0, i32 0
  call void @bn_subtractmod(ptr noundef %10, ptr noundef %76, ptr noundef %10, ptr noundef %78)
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.ecdsa_curve, ptr %79, i32 0, i32 0
  call void @bn_fast_mod(ptr noundef %10, ptr noundef %80)
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.ecdsa_curve, ptr %81, i32 0, i32 0
  call void @bn_mod(ptr noundef %10, ptr noundef %82)
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.curve_point, ptr %83, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %84, ptr align 4 %9, i64 36, i1 false), !tbaa.struct !9
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.curve_point, ptr %85, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %86, ptr align 4 %10, i64 36, i1 false), !tbaa.struct !9
  store i32 0, ptr %11, align 4
  br label %87

87:                                               ; preds = %38, %36, %28, %20, %15
  call void @llvm.lifetime.end.p0(i64 36, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr %7) #5
  %88 = load i32, ptr %11, align 4
  switch i32 %88, label %90 [
    i32 0, label %89
    i32 1, label %89
  ]

89:                                               ; preds = %87, %87
  ret void

90:                                               ; preds = %87
  unreachable
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @point_is_infinity(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @point_is_equal(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @point_double(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @point_is_negative_of(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @point_set_infinity(ptr noundef) #0

declare void @bn_subtractmod(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #4

declare void @bn_inverse(ptr noundef, ptr noundef) #4

declare void @bn_multiply(ptr noundef, ptr noundef, ptr noundef) #4

declare void @bn_addmod(ptr noundef, ptr noundef, ptr noundef) #4

declare void @bn_fast_mod(ptr noundef, ptr noundef) #4

declare void @bn_mod(ptr noundef, ptr noundef) #4

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

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 nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { "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 = !{i64 0, i64 36, !10}
!10 = !{!7, !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.bignum256 = type { [9 x i32] }

; Function Attrs: nounwind uwtable
declare dso_local void @point_copy(ptr noundef, ptr noundef) local_unnamed_addr #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
define dso_local void @point_add(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.bignum256, align 4
  %5 = alloca %struct.bignum256, align 4
  %6 = alloca %struct.bignum256, align 4
  %7 = alloca %struct.bignum256, align 4
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %4) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %4, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %5) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %5, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %7) #5
  %8 = tail call i32 @point_is_infinity(ptr noundef %1)
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %9, label %21

9:                                                ; preds = %3
  %10 = tail call i32 @point_is_infinity(ptr noundef %2)
  %.not35 = icmp eq i32 %10, 0
  br i1 %.not35, label %12, label %11

11:                                               ; preds = %9
  tail call void @point_copy(ptr noundef %1, ptr noundef %2)
  br label %21

12:                                               ; preds = %9
  %13 = tail call i32 @point_is_equal(ptr noundef %1, ptr noundef %2)
  %.not36 = icmp eq i32 %13, 0
  br i1 %.not36, label %15, label %14

14:                                               ; preds = %12
  tail call void @point_double(ptr noundef %0, ptr noundef %2)
  br label %21

15:                                               ; preds = %12
  %16 = tail call i32 @point_is_negative_of(ptr noundef %1, ptr noundef %2)
  %.not37 = icmp eq i32 %16, 0
  br i1 %.not37, label %18, label %17

17:                                               ; preds = %15
  tail call void @point_set_infinity(ptr noundef %2)
  br label %21

18:                                               ; preds = %15
  call void @bn_subtractmod(ptr noundef %2, ptr noundef %1, ptr noundef nonnull %5, ptr noundef %0) #5
  call void @bn_inverse(ptr noundef nonnull %5, ptr noundef %0) #5
  %19 = getelementptr inbounds i8, ptr %2, i64 36
  %20 = getelementptr inbounds i8, ptr %1, i64 36
  call void @bn_subtractmod(ptr noundef nonnull %19, ptr noundef nonnull %20, ptr noundef nonnull %4, ptr noundef %0) #5
  call void @bn_multiply(ptr noundef nonnull %5, ptr noundef nonnull %4, ptr noundef %0) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %6, ptr noundef nonnull align 4 dereferenceable(36) %4, i64 36, i1 false), !tbaa.struct !5
  call void @bn_multiply(ptr noundef nonnull %6, ptr noundef nonnull %6, ptr noundef %0) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %7, ptr noundef nonnull align 4 dereferenceable(36) %1, i64 36, i1 false), !tbaa.struct !5
  call void @bn_addmod(ptr noundef nonnull %7, ptr noundef %2, ptr noundef %0) #5
  call void @bn_subtractmod(ptr noundef nonnull %6, ptr noundef nonnull %7, ptr noundef nonnull %6, ptr noundef %0) #5
  call void @bn_fast_mod(ptr noundef nonnull %6, ptr noundef %0) #5
  call void @bn_mod(ptr noundef nonnull %6, ptr noundef %0) #5
  call void @bn_subtractmod(ptr noundef %1, ptr noundef nonnull %6, ptr noundef nonnull %7, ptr noundef %0) #5
  call void @bn_multiply(ptr noundef nonnull %4, ptr noundef nonnull %7, ptr noundef %0) #5
  call void @bn_subtractmod(ptr noundef nonnull %7, ptr noundef nonnull %20, ptr noundef nonnull %7, ptr noundef %0) #5
  call void @bn_fast_mod(ptr noundef nonnull %7, ptr noundef %0) #5
  call void @bn_mod(ptr noundef nonnull %7, ptr noundef %0) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %2, ptr noundef nonnull align 4 dereferenceable(36) %6, i64 36, i1 false), !tbaa.struct !5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %19, ptr noundef nonnull align 4 dereferenceable(36) %7, i64 36, i1 false), !tbaa.struct !5
  br label %21

21:                                               ; preds = %3, %18, %17, %14, %11
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %4) #5
  ret void
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @point_is_equal(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @point_double(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @point_is_negative_of(ptr noundef, ptr noundef) local_unnamed_addr #0

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

declare void @bn_subtractmod(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

declare void @bn_inverse(ptr noundef, ptr noundef) local_unnamed_addr #4

declare void @bn_multiply(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

declare void @bn_addmod(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

declare void @bn_fast_mod(ptr noundef, ptr noundef) local_unnamed_addr #4

declare void @bn_mod(ptr noundef, ptr noundef) local_unnamed_addr #4

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

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) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { "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 = !{i64 0, i64 36, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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