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

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

@ge25519_niels_base_multiples = external constant [256 x [96 x i8]], 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

declare void @ge25519_scalarmult_base_niels(ptr noundef, ptr noundef, ptr noundef) #2

declare void @expand_raw256_modm(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @curve25519_scalarmult_basepoint(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [32 x i8], align 16
  %6 = alloca [9 x i32], align 16
  %7 = alloca [10 x i32], align 16
  %8 = alloca [10 x i32], align 16
  %9 = alloca %struct.ge25519_t, align 16
  %10 = alloca i64, align 8
  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 32, ptr %5) #4
  call void @llvm.memset.p0.i64(ptr align 16 %5, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr %6) #4
  call void @llvm.memset.p0.i64(ptr align 16 %6, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 40, ptr %7) #4
  call void @llvm.memset.p0.i64(ptr align 16 %7, i8 0, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 40, ptr %8) #4
  call void @llvm.memset.p0.i64(ptr align 16 %8, i8 0, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 160, ptr %9) #4
  call void @llvm.memset.p0.i64(ptr align 16 %9, i8 0, i64 160, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !9
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %21, %2
  %12 = load i64, ptr %10, align 8, !tbaa !9
  %13 = icmp ult i64 %12, 32
  br i1 %13, label %14, label %24

14:                                               ; preds = %11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i64, ptr %10, align 8, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %15, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = load i64, ptr %10, align 8, !tbaa !9
  %20 = getelementptr inbounds [32 x i8], ptr %5, i64 0, i64 %19
  store i8 %18, ptr %20, align 1, !tbaa !11
  br label %21

21:                                               ; preds = %14
  %22 = load i64, ptr %10, align 8, !tbaa !9
  %23 = add i64 %22, 1
  store i64 %23, ptr %10, align 8, !tbaa !9
  br label %11, !llvm.loop !12

24:                                               ; preds = %11
  %25 = getelementptr inbounds [32 x i8], ptr %5, i64 0, i64 0
  %26 = load i8, ptr %25, align 16, !tbaa !11
  %27 = zext i8 %26 to i32
  %28 = and i32 %27, 248
  %29 = trunc i32 %28 to i8
  store i8 %29, ptr %25, align 16, !tbaa !11
  %30 = getelementptr inbounds [32 x i8], ptr %5, i64 0, i64 31
  %31 = load i8, ptr %30, align 1, !tbaa !11
  %32 = zext i8 %31 to i32
  %33 = and i32 %32, 127
  %34 = trunc i32 %33 to i8
  store i8 %34, ptr %30, align 1, !tbaa !11
  %35 = getelementptr inbounds [32 x i8], ptr %5, i64 0, i64 31
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = zext i8 %36 to i32
  %38 = or i32 %37, 64
  %39 = trunc i32 %38 to i8
  store i8 %39, ptr %35, align 1, !tbaa !11
  %40 = getelementptr inbounds [9 x i32], ptr %6, i64 0, i64 0
  %41 = getelementptr inbounds [32 x i8], ptr %5, i64 0, i64 0
  call void @expand_raw256_modm(ptr noundef %40, ptr noundef %41)
  call void @memzero(ptr noundef %5, i64 noundef 32)
  %42 = getelementptr inbounds [9 x i32], ptr %6, i64 0, i64 0
  call void @ge25519_scalarmult_base_niels(ptr noundef %9, ptr noundef @ge25519_niels_base_multiples, ptr noundef %42)
  call void @memzero(ptr noundef %6, i64 noundef 36)
  %43 = getelementptr inbounds [10 x i32], ptr %7, i64 0, i64 0
  %44 = getelementptr inbounds %struct.ge25519_t, ptr %9, i32 0, i32 1
  %45 = getelementptr inbounds [10 x i32], ptr %44, i64 0, i64 0
  %46 = getelementptr inbounds %struct.ge25519_t, ptr %9, i32 0, i32 2
  %47 = getelementptr inbounds [10 x i32], ptr %46, i64 0, i64 0
  call void @curve25519_add(ptr noundef %43, ptr noundef %45, ptr noundef %47)
  %48 = getelementptr inbounds [10 x i32], ptr %8, i64 0, i64 0
  %49 = getelementptr inbounds %struct.ge25519_t, ptr %9, i32 0, i32 2
  %50 = getelementptr inbounds [10 x i32], ptr %49, i64 0, i64 0
  %51 = getelementptr inbounds %struct.ge25519_t, ptr %9, i32 0, i32 1
  %52 = getelementptr inbounds [10 x i32], ptr %51, i64 0, i64 0
  call void @curve25519_sub(ptr noundef %48, ptr noundef %50, ptr noundef %52)
  %53 = getelementptr inbounds [10 x i32], ptr %8, i64 0, i64 0
  %54 = getelementptr inbounds [10 x i32], ptr %8, i64 0, i64 0
  call void @curve25519_recip(ptr noundef %53, ptr noundef %54)
  %55 = getelementptr inbounds [10 x i32], ptr %7, i64 0, i64 0
  %56 = getelementptr inbounds [10 x i32], ptr %7, i64 0, i64 0
  %57 = getelementptr inbounds [10 x i32], ptr %8, i64 0, i64 0
  call void @curve25519_mul(ptr noundef %55, ptr noundef %56, ptr noundef %57)
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds [10 x i32], ptr %7, i64 0, i64 0
  call void @curve25519_contract(ptr noundef %58, ptr noundef %59)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 160, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 36, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #4
  ret void
}

declare void @curve25519_add(ptr noundef, ptr noundef, ptr noundef) #2

declare void @curve25519_sub(ptr noundef, ptr noundef, ptr noundef) #2

declare void @curve25519_recip(ptr noundef, ptr noundef) #2

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

declare void @curve25519_contract(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { "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 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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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

@ge25519_niels_base_multiples = external constant [256 x [96 x i8]], 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

declare void @ge25519_scalarmult_base_niels(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @expand_raw256_modm(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @curve25519_scalarmult_basepoint(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #3 {
  %3 = alloca [32 x i8], align 16
  %4 = alloca [9 x i32], align 16
  %5 = alloca [10 x i32], align 16
  %6 = alloca [10 x i32], align 16
  %7 = alloca %struct.ge25519_t, align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %4) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(36) %4, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %5) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %5, i8 0, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %6) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %6, i8 0, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %7) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(160) %7, i8 0, i64 160, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %3, ptr noundef nonnull align 1 dereferenceable(32) %1, i64 32, i1 false), !tbaa !5
  %8 = load i8, ptr %3, align 16, !tbaa !5
  %9 = and i8 %8, -8
  store i8 %9, ptr %3, align 16, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %3, i64 31
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = and i8 %11, 63
  %13 = or disjoint i8 %12, 64
  store i8 %13, ptr %10, align 1, !tbaa !5
  call void @expand_raw256_modm(ptr noundef nonnull %4, ptr noundef nonnull %3) #5
  call void @memzero(ptr noundef nonnull %3, i64 noundef 32) #5
  call void @ge25519_scalarmult_base_niels(ptr noundef nonnull %7, ptr noundef nonnull @ge25519_niels_base_multiples, ptr noundef nonnull %4) #5
  call void @memzero(ptr noundef nonnull %4, i64 noundef 36) #5
  %14 = getelementptr inbounds i8, ptr %7, i64 40
  %15 = getelementptr inbounds i8, ptr %7, i64 80
  call void @curve25519_add(ptr noundef nonnull %5, ptr noundef nonnull %14, ptr noundef nonnull %15) #5
  call void @curve25519_sub(ptr noundef nonnull %6, ptr noundef nonnull %15, ptr noundef nonnull %14) #5
  call void @curve25519_recip(ptr noundef nonnull %6, ptr noundef nonnull %6) #5
  call void @curve25519_mul(ptr noundef nonnull %5, ptr noundef nonnull %5, ptr noundef nonnull %6) #5
  call void @curve25519_contract(ptr noundef %0, ptr noundef nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #5
  ret void
}

declare void @curve25519_add(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @curve25519_sub(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @curve25519_recip(ptr noundef, ptr noundef) local_unnamed_addr #2

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

declare void @curve25519_contract(ptr noundef, ptr noundef) local_unnamed_addr #2

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

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass