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

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

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

12:                                               ; preds = %2
  store i32 1, ptr %8, align 4
  br label %73

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.curve_point, ptr %14, i32 0, i32 1
  %16 = call i32 @bn_is_zero(ptr noundef %15)
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %20

18:                                               ; preds = %13
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  call void @point_set_infinity(ptr noundef %19)
  store i32 1, ptr %8, align 4
  br label %73

20:                                               ; preds = %13
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.curve_point, ptr %21, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 4 %22, i64 36, i1 false), !tbaa.struct !9
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ecdsa_curve, ptr %23, i32 0, i32 0
  call void @bn_mult_k(ptr noundef %5, i8 noundef zeroext 2, ptr noundef %24)
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ecdsa_curve, ptr %25, i32 0, i32 0
  call void @bn_fast_mod(ptr noundef %5, ptr noundef %26)
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ecdsa_curve, ptr %27, i32 0, i32 0
  call void @bn_mod(ptr noundef %5, ptr noundef %28)
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ecdsa_curve, ptr %29, i32 0, i32 0
  call void @bn_inverse(ptr noundef %5, ptr noundef %30)
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.curve_point, ptr %31, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %32, i64 36, i1 false), !tbaa.struct !9
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ecdsa_curve, ptr %33, i32 0, i32 0
  call void @bn_multiply(ptr noundef %6, ptr noundef %6, ptr noundef %34)
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ecdsa_curve, ptr %35, i32 0, i32 0
  call void @bn_mult_k(ptr noundef %6, i8 noundef zeroext 3, ptr noundef %36)
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ecdsa_curve, ptr %37, i32 0, i32 4
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = sub nsw i32 0, %39
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ecdsa_curve, ptr %41, i32 0, i32 0
  call void @bn_subi(ptr noundef %6, i32 noundef %40, ptr noundef %42)
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ecdsa_curve, ptr %43, i32 0, i32 0
  call void @bn_multiply(ptr noundef %6, ptr noundef %5, ptr noundef %44)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %5, i64 36, i1 false), !tbaa.struct !9
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ecdsa_curve, ptr %45, i32 0, i32 0
  call void @bn_multiply(ptr noundef %6, ptr noundef %6, ptr noundef %46)
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.curve_point, ptr %47, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %48, i64 36, i1 false), !tbaa.struct !9
  call void @bn_lshift(ptr noundef %7)
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ecdsa_curve, ptr %49, i32 0, i32 0
  call void @bn_subtractmod(ptr noundef %6, ptr noundef %7, ptr noundef %6, ptr noundef %50)
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ecdsa_curve, ptr %51, i32 0, i32 0
  call void @bn_fast_mod(ptr noundef %6, ptr noundef %52)
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ecdsa_curve, ptr %53, i32 0, i32 0
  call void @bn_mod(ptr noundef %6, ptr noundef %54)
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.curve_point, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ecdsa_curve, ptr %57, i32 0, i32 0
  call void @bn_subtractmod(ptr noundef %56, ptr noundef %6, ptr noundef %7, ptr noundef %58)
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.ecdsa_curve, ptr %59, i32 0, i32 0
  call void @bn_multiply(ptr noundef %5, ptr noundef %7, ptr noundef %60)
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.curve_point, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ecdsa_curve, ptr %63, i32 0, i32 0
  call void @bn_subtractmod(ptr noundef %7, ptr noundef %62, ptr noundef %7, ptr noundef %64)
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ecdsa_curve, ptr %65, i32 0, i32 0
  call void @bn_fast_mod(ptr noundef %7, ptr noundef %66)
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.ecdsa_curve, ptr %67, i32 0, i32 0
  call void @bn_mod(ptr noundef %7, ptr noundef %68)
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.curve_point, ptr %69, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %70, ptr align 4 %6, i64 36, i1 false), !tbaa.struct !9
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.curve_point, ptr %71, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %72, ptr align 4 %7, i64 36, i1 false), !tbaa.struct !9
  store i32 0, ptr %8, align 4
  br label %73

73:                                               ; preds = %20, %18, %12
  call void @llvm.lifetime.end.p0(i64 36, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr %5) #5
  %74 = load i32, ptr %8, align 4
  switch i32 %74, label %76 [
    i32 0, label %75
    i32 1, label %75
  ]

75:                                               ; preds = %73, %73
  ret void

76:                                               ; preds = %73
  unreachable
}

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

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

declare i32 @bn_is_zero(ptr noundef) #4

declare void @bn_mult_k(ptr noundef, i8 noundef zeroext, ptr noundef) #4

declare void @bn_subi(ptr noundef, i32 noundef, ptr noundef) #4

declare void @bn_lshift(ptr noundef) #4

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { "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}
!11 = !{!12, !15, i64 180}
!12 = !{!"", !13, i64 0, !14, i64 36, !13, i64 108, !13, i64 144, !15, i64 180, !13, i64 184, !7, i64 220}
!13 = !{!"", !7, i64 0}
!14 = !{!"", !13, i64 0, !13, i64 36}
!15 = !{!"int", !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: 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) #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: nounwind uwtable
declare dso_local i32 @point_is_infinity(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @point_double(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca %struct.bignum256, align 4
  %4 = alloca %struct.bignum256, align 4
  %5 = alloca %struct.bignum256, align 4
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %5) #4
  %6 = tail call i32 @point_is_infinity(ptr noundef %1)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %15

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %1, i64 36
  %9 = tail call i32 @bn_is_zero(ptr noundef nonnull %8) #4
  %.not28 = icmp eq i32 %9, 0
  br i1 %.not28, label %11, label %10

10:                                               ; preds = %7
  tail call void @point_set_infinity(ptr noundef %1)
  br label %15

11:                                               ; preds = %7
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %3, ptr noundef nonnull align 4 dereferenceable(36) %8, i64 36, i1 false), !tbaa.struct !5
  call void @bn_mult_k(ptr noundef nonnull %3, i8 noundef zeroext 2, ptr noundef %0) #4
  call void @bn_fast_mod(ptr noundef nonnull %3, ptr noundef %0) #4
  call void @bn_mod(ptr noundef nonnull %3, ptr noundef %0) #4
  call void @bn_inverse(ptr noundef nonnull %3, ptr noundef %0) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %4, ptr noundef nonnull align 4 dereferenceable(36) %1, i64 36, i1 false), !tbaa.struct !5
  call void @bn_multiply(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %0) #4
  call void @bn_mult_k(ptr noundef nonnull %4, i8 noundef zeroext 3, ptr noundef %0) #4
  %12 = getelementptr inbounds i8, ptr %0, i64 180
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = sub nsw i32 0, %13
  call void @bn_subi(ptr noundef nonnull %4, i32 noundef %14, ptr noundef %0) #4
  call void @bn_multiply(ptr noundef nonnull %4, ptr noundef nonnull %3, ptr noundef %0) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %4, ptr noundef nonnull align 4 dereferenceable(36) %3, i64 36, i1 false), !tbaa.struct !5
  call void @bn_multiply(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %0) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %5, ptr noundef nonnull align 4 dereferenceable(36) %1, i64 36, i1 false), !tbaa.struct !5
  call void @bn_lshift(ptr noundef nonnull %5) #4
  call void @bn_subtractmod(ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %4, ptr noundef %0) #4
  call void @bn_fast_mod(ptr noundef nonnull %4, ptr noundef %0) #4
  call void @bn_mod(ptr noundef nonnull %4, ptr noundef %0) #4
  call void @bn_subtractmod(ptr noundef %1, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef %0) #4
  call void @bn_multiply(ptr noundef nonnull %3, ptr noundef nonnull %5, ptr noundef %0) #4
  call void @bn_subtractmod(ptr noundef nonnull %5, ptr noundef nonnull %8, ptr noundef nonnull %5, ptr noundef %0) #4
  call void @bn_fast_mod(ptr noundef nonnull %5, ptr noundef %0) #4
  call void @bn_mod(ptr noundef nonnull %5, ptr noundef %0) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %1, ptr noundef nonnull align 4 dereferenceable(36) %4, i64 36, i1 false), !tbaa.struct !5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %8, ptr noundef nonnull align 4 dereferenceable(36) %5, i64 36, i1 false), !tbaa.struct !5
  br label %15

15:                                               ; preds = %2, %11, %10
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %3) #4
  ret void
}

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

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

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

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

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

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

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

declare i32 @bn_is_zero(ptr noundef) local_unnamed_addr #3

declare void @bn_mult_k(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #3

declare void @bn_subi(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

declare void @bn_lshift(ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 = !{i64 0, i64 36, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !13, i64 180}
!10 = !{!"", !11, i64 0, !12, i64 36, !11, i64 108, !11, i64 144, !13, i64 180, !11, i64 184, !7, i64 220}
!11 = !{!"", !7, i64 0}
!12 = !{!"", !11, i64 0, !11, i64 36}
!13 = !{!"int", !7, i64 0}


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