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

; 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

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

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

declare void @bn_add(ptr noundef, ptr noundef) #1

declare void @bn_subtract(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @uncompress_coords(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %10, i64 36, i1 false)
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = load ptr, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ecdsa_curve, ptr %13, i32 0, i32 0
  call void @bn_multiply(ptr noundef %11, ptr noundef %12, ptr noundef %14)
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ecdsa_curve, ptr %16, i32 0, i32 4
  %18 = load i32, ptr %17, align 4, !tbaa !10
  %19 = sub nsw i32 0, %18
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ecdsa_curve, ptr %20, i32 0, i32 0
  call void @bn_subi(ptr noundef %15, i32 noundef %19, ptr noundef %21)
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ecdsa_curve, ptr %24, i32 0, i32 0
  call void @bn_multiply(ptr noundef %22, ptr noundef %23, ptr noundef %25)
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ecdsa_curve, ptr %27, i32 0, i32 5
  call void @bn_add(ptr noundef %26, ptr noundef %28)
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ecdsa_curve, ptr %30, i32 0, i32 0
  call void @bn_sqrt(ptr noundef %29, ptr noundef %31)
  %32 = load i8, ptr %6, align 1, !tbaa !9
  %33 = zext i8 %32 to i32
  %34 = and i32 %33, 1
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.bignum256, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds [9 x i32], ptr %36, i64 0, i64 0
  %38 = load i32, ptr %37, align 4, !tbaa !15
  %39 = and i32 %38, 1
  %40 = icmp ne i32 %34, %39
  br i1 %40, label %41, label %46

41:                                               ; preds = %4
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ecdsa_curve, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  call void @bn_subtract(ptr noundef %43, ptr noundef %44, ptr noundef %45)
  br label %46

46:                                               ; preds = %41, %4
  ret void
}

declare void @bn_sqrt(ptr noundef, ptr noundef) #1

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

!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 = !{!7, !7, i64 0}
!10 = !{!11, !14, i64 180}
!11 = !{!"", !12, i64 0, !13, i64 36, !12, i64 108, !12, i64 144, !14, i64 180, !12, i64 184, !7, i64 220}
!12 = !{!"", !7, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 36}
!14 = !{!"int", !7, i64 0}
!15 = !{!14, !14, 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"

; 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

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

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

declare void @bn_add(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @bn_subtract(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @uncompress_coords(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %3, ptr noundef nonnull align 4 dereferenceable(36) %2, i64 36, i1 false)
  tail call void @bn_multiply(ptr noundef %2, ptr noundef %3, ptr noundef %0) #3
  %5 = getelementptr inbounds i8, ptr %0, i64 180
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = sub nsw i32 0, %6
  tail call void @bn_subi(ptr noundef %3, i32 noundef %7, ptr noundef %0) #3
  tail call void @bn_multiply(ptr noundef %2, ptr noundef %3, ptr noundef %0) #3
  %8 = getelementptr inbounds i8, ptr %0, i64 184
  tail call void @bn_add(ptr noundef %3, ptr noundef nonnull %8) #3
  tail call void @bn_sqrt(ptr noundef %3, ptr noundef %0) #3
  %9 = and i8 %1, 1
  %10 = zext nneg i8 %9 to i32
  %11 = load i32, ptr %3, align 4, !tbaa !12
  %12 = and i32 %11, 1
  %.not = icmp eq i32 %12, %10
  br i1 %.not, label %14, label %13

13:                                               ; preds = %4
  tail call void @bn_subtract(ptr noundef nonnull %0, ptr noundef nonnull %3, ptr noundef nonnull %3) #3
  br label %14

14:                                               ; preds = %13, %4
  ret void
}

declare void @bn_sqrt(ptr noundef, ptr noundef) local_unnamed_addr #1

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


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