; LLVM IR from trustwallet/wallet-core :: trezor-crypto/crypto/ed25519-donna (ed25519-donna-impl-base)

; 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.ge25519_niels_t = type { [10 x i32], [10 x i32], [10 x i32] }
%struct.ge25519_t = type { [10 x i32], [10 x i32], [10 x i32], [10 x i32] }

@ge25519_ecd = external constant [10 x i32], align 16

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

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

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

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

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

declare void @memzero(ptr noundef, i64 noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @ge25519_scalarmult_base_choose_niels(ptr noundef, ptr noundef, i32 noundef, i8 noundef signext) #3

; Function Attrs: nounwind uwtable
define dso_local void @ge25519_scalarmult_base_niels(ptr noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [64 x i8], align 16
  %8 = alloca i32, align 4
  %9 = alloca %struct.ge25519_niels_t, 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 64, ptr %7) #4
  call void @llvm.memset.p0.i64(ptr align 16 %7, i8 0, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 120, ptr %9) #4
  call void @llvm.memset.p0.i64(ptr align 4 %9, i8 0, i64 120, i1 false)
  %10 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  call void @contract256_window4_modm(ptr noundef %10, ptr noundef %11)
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 1
  %14 = load i8, ptr %13, align 1, !tbaa !11
  call void @ge25519_scalarmult_base_choose_niels(ptr noundef %9, ptr noundef %12, i32 noundef 0, i8 noundef signext %14)
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ge25519_t, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds [10 x i32], ptr %16, i64 0, i64 0
  %18 = getelementptr inbounds %struct.ge25519_niels_t, ptr %9, i32 0, i32 1
  %19 = getelementptr inbounds [10 x i32], ptr %18, i64 0, i64 0
  %20 = getelementptr inbounds %struct.ge25519_niels_t, ptr %9, i32 0, i32 0
  %21 = getelementptr inbounds [10 x i32], ptr %20, i64 0, i64 0
  call void @curve25519_sub_reduce(ptr noundef %17, ptr noundef %19, ptr noundef %21)
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ge25519_t, ptr %22, i32 0, i32 1
  %24 = getelementptr inbounds [10 x i32], ptr %23, i64 0, i64 0
  %25 = getelementptr inbounds %struct.ge25519_niels_t, ptr %9, i32 0, i32 1
  %26 = getelementptr inbounds [10 x i32], ptr %25, i64 0, i64 0
  %27 = getelementptr inbounds %struct.ge25519_niels_t, ptr %9, i32 0, i32 0
  %28 = getelementptr inbounds [10 x i32], ptr %27, i64 0, i64 0
  call void @curve25519_add_reduce(ptr noundef %24, ptr noundef %26, ptr noundef %28)
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ge25519_t, ptr %29, i32 0, i32 2
  %31 = getelementptr inbounds [10 x i32], ptr %30, i64 0, i64 0
  call void @memzero(ptr noundef %31, i64 noundef 40)
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ge25519_t, ptr %32, i32 0, i32 3
  %34 = getelementptr inbounds [10 x i32], ptr %33, i64 0, i64 0
  %35 = getelementptr inbounds %struct.ge25519_niels_t, ptr %9, i32 0, i32 2
  %36 = getelementptr inbounds [10 x i32], ptr %35, i64 0, i64 0
  call void @curve25519_copy(ptr noundef %34, ptr noundef %36)
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ge25519_t, ptr %37, i32 0, i32 2
  %39 = getelementptr inbounds [10 x i32], ptr %38, i64 0, i64 0
  store i32 2, ptr %39, align 4, !tbaa !9
  store i32 3, ptr %8, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %52, %3
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = icmp ult i32 %41, 64
  br i1 %42, label %43, label %55

43:                                               ; preds = %40
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = udiv i32 %45, 2
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !11
  call void @ge25519_scalarmult_base_choose_niels(ptr noundef %9, ptr noundef %44, i32 noundef %46, i8 noundef signext %50)
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_nielsadd2(ptr noundef %51, ptr noundef %9)
  br label %52

52:                                               ; preds = %43
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = add i32 %53, 2
  store i32 %54, ptr %8, align 4, !tbaa !9
  br label %40, !llvm.loop !12

55:                                               ; preds = %40
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_double_partial(ptr noundef %56, ptr noundef %57)
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_double_partial(ptr noundef %58, ptr noundef %59)
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_double_partial(ptr noundef %60, ptr noundef %61)
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_double(ptr noundef %62, ptr noundef %63)
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  %66 = load i8, ptr %65, align 16, !tbaa !11
  call void @ge25519_scalarmult_base_choose_niels(ptr noundef %9, ptr noundef %64, i32 noundef 0, i8 noundef signext %66)
  %67 = getelementptr inbounds %struct.ge25519_niels_t, ptr %9, i32 0, i32 2
  %68 = getelementptr inbounds [10 x i32], ptr %67, i64 0, i64 0
  %69 = getelementptr inbounds %struct.ge25519_niels_t, ptr %9, i32 0, i32 2
  %70 = getelementptr inbounds [10 x i32], ptr %69, i64 0, i64 0
  call void @curve25519_mul(ptr noundef %68, ptr noundef %70, ptr noundef @ge25519_ecd)
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_nielsadd2(ptr noundef %71, ptr noundef %9)
  store i32 2, ptr %8, align 4, !tbaa !9
  br label %72

72:                                               ; preds = %84, %55
  %73 = load i32, ptr %8, align 4, !tbaa !9
  %74 = icmp ult i32 %73, 64
  br i1 %74, label %75, label %87

75:                                               ; preds = %72
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = load i32, ptr %8, align 4, !tbaa !9
  %78 = udiv i32 %77, 2
  %79 = load i32, ptr %8, align 4, !tbaa !9
  %80 = zext i32 %79 to i64
  %81 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 %80
  %82 = load i8, ptr %81, align 1, !tbaa !11
  call void @ge25519_scalarmult_base_choose_niels(ptr noundef %9, ptr noundef %76, i32 noundef %78, i8 noundef signext %82)
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_nielsadd2(ptr noundef %83, ptr noundef %9)
  br label %84

84:                                               ; preds = %75
  %85 = load i32, ptr %8, align 4, !tbaa !9
  %86 = add i32 %85, 2
  store i32 %86, ptr %8, align 4, !tbaa !9
  br label %72, !llvm.loop !14

87:                                               ; preds = %72
  call void @llvm.lifetime.end.p0(i64 120, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %7) #4
  ret void
}

attributes #0 = { nocallback nofree nosync 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 = { 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 = { 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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.ge25519_niels_t = type { [10 x i32], [10 x i32], [10 x i32] }

@ge25519_ecd = external constant [10 x i32], align 16

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

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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

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

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

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

declare void @memzero(ptr noundef, i64 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @ge25519_scalarmult_base_choose_niels(ptr noundef, ptr noundef, i32 noundef, i8 noundef signext) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @ge25519_scalarmult_base_niels(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #3 {
  %4 = alloca [64 x i8], align 16
  %5 = alloca %struct.ge25519_niels_t, align 4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %4) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %4, i8 0, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 120, ptr nonnull %5) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(120) %5, i8 0, i64 120, i1 false)
  call void @contract256_window4_modm(ptr noundef nonnull %4, ptr noundef %2) #4
  %6 = getelementptr inbounds i8, ptr %4, i64 1
  %7 = load i8, ptr %6, align 1, !tbaa !5
  call void @ge25519_scalarmult_base_choose_niels(ptr noundef nonnull %5, ptr noundef %1, i32 noundef 0, i8 noundef signext %7)
  %8 = getelementptr inbounds i8, ptr %5, i64 40
  call void @curve25519_sub_reduce(ptr noundef %0, ptr noundef nonnull %8, ptr noundef nonnull %5) #4
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  call void @curve25519_add_reduce(ptr noundef nonnull %9, ptr noundef nonnull %8, ptr noundef nonnull %5) #4
  %10 = getelementptr inbounds i8, ptr %0, i64 80
  call void @memzero(ptr noundef nonnull %10, i64 noundef 40) #4
  %11 = getelementptr inbounds i8, ptr %0, i64 120
  %12 = getelementptr inbounds i8, ptr %5, i64 80
  call void @curve25519_copy(ptr noundef nonnull %11, ptr noundef nonnull %12) #4
  store i32 2, ptr %10, align 4, !tbaa !8
  br label %13

13:                                               ; preds = %3, %13
  %indvars.iv = phi i64 [ 3, %3 ], [ %indvars.iv.next, %13 ]
  %14 = lshr i64 %indvars.iv, 1
  %15 = getelementptr inbounds [64 x i8], ptr %4, i64 0, i64 %indvars.iv
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = trunc nuw nsw i64 %14 to i32
  call void @ge25519_scalarmult_base_choose_niels(ptr noundef nonnull %5, ptr noundef %1, i32 noundef %17, i8 noundef signext %16)
  call void @ge25519_nielsadd2(ptr noundef %0, ptr noundef nonnull %5)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %18 = icmp ult i64 %indvars.iv, 62
  br i1 %18, label %13, label %19, !llvm.loop !10

19:                                               ; preds = %13
  call void @ge25519_double_partial(ptr noundef %0, ptr noundef %0)
  call void @ge25519_double_partial(ptr noundef %0, ptr noundef %0)
  call void @ge25519_double_partial(ptr noundef %0, ptr noundef %0)
  call void @ge25519_double(ptr noundef %0, ptr noundef %0)
  %20 = load i8, ptr %4, align 16, !tbaa !5
  call void @ge25519_scalarmult_base_choose_niels(ptr noundef nonnull %5, ptr noundef %1, i32 noundef 0, i8 noundef signext %20)
  call void @curve25519_mul(ptr noundef nonnull %12, ptr noundef nonnull %12, ptr noundef nonnull @ge25519_ecd) #4
  call void @ge25519_nielsadd2(ptr noundef %0, ptr noundef nonnull %5)
  br label %21

21:                                               ; preds = %19, %21
  %indvars.iv31 = phi i64 [ 2, %19 ], [ %indvars.iv.next32, %21 ]
  %22 = lshr exact i64 %indvars.iv31, 1
  %23 = getelementptr inbounds [64 x i8], ptr %4, i64 0, i64 %indvars.iv31
  %24 = load i8, ptr %23, align 2, !tbaa !5
  %25 = trunc nuw nsw i64 %22 to i32
  call void @ge25519_scalarmult_base_choose_niels(ptr noundef nonnull %5, ptr noundef %1, i32 noundef %25, i8 noundef signext %24)
  call void @ge25519_nielsadd2(ptr noundef %0, ptr noundef nonnull %5)
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 2
  %26 = icmp ult i64 %indvars.iv31, 62
  br i1 %26, label %21, label %27, !llvm.loop !12

27:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 120, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #4
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync 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 = { mustprogress 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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass