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

; 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.__blake2b_state = type { [8 x i64], [2 x i64], [2 x i64], [128 x i8], i64, i64, i8 }
%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 @expand256_modm(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @ed25519_hram(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef) #3

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ed25519_sign_ext_blake2b(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #3 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca %struct.__blake2b_state, align 8
  %12 = alloca [9 x i32], align 16
  %13 = alloca [9 x i32], align 16
  %14 = alloca [9 x i32], align 16
  %15 = alloca %struct.ge25519_t, align 16
  %16 = alloca %struct.ge25519_t, align 16
  %17 = alloca [32 x i8], align 16
  %18 = alloca [64 x i8], align 16
  %19 = alloca [64 x i8], align 16
  %20 = alloca [64 x i8], align 16
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 248, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 36, ptr %12) #5
  call void @llvm.memset.p0.i64(ptr align 16 %12, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr %13) #5
  call void @llvm.memset.p0.i64(ptr align 16 %13, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr %14) #5
  call void @llvm.memset.p0.i64(ptr align 16 %14, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 160, ptr %15) #5
  call void @llvm.memset.p0.i64(ptr align 16 %15, i8 0, i64 160, i1 false)
  call void @llvm.lifetime.start.p0(i64 160, ptr %16) #5
  call void @llvm.memset.p0.i64(ptr align 16 %16, i8 0, i64 160, i1 false)
  call void @llvm.lifetime.start.p0(i64 32, ptr %17) #5
  call void @llvm.memset.p0.i64(ptr align 16 %17, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 64, ptr %18) #5
  call void @llvm.memset.p0.i64(ptr align 16 %18, i8 0, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 64, ptr %19) #5
  call void @llvm.memset.p0.i64(ptr align 16 %19, i8 0, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 64, ptr %20) #5
  call void @llvm.memset.p0.i64(ptr align 16 %20, i8 0, i64 64, i1 false)
  %21 = getelementptr inbounds [64 x i8], ptr %18, i64 0, i64 0
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %21, ptr align 1 %22, i64 32, i1 false)
  %23 = getelementptr inbounds [64 x i8], ptr %18, i64 0, i64 0
  %24 = getelementptr inbounds i8, ptr %23, i64 32
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %24, ptr align 1 %25, i64 32, i1 false)
  %26 = call i32 @tc_blake2b_Init(ptr noundef %11, i64 noundef 64)
  %27 = getelementptr inbounds [64 x i8], ptr %18, i64 0, i64 0
  %28 = getelementptr inbounds i8, ptr %27, i64 32
  %29 = call i32 @tc_blake2b_Update(ptr noundef %11, ptr noundef %28, i64 noundef 32)
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = call i32 @tc_blake2b_Update(ptr noundef %11, ptr noundef %30, i64 noundef %31)
  %33 = getelementptr inbounds [64 x i8], ptr %19, i64 0, i64 0
  %34 = call i32 @tc_blake2b_Final(ptr noundef %11, ptr noundef %33, i64 noundef 64)
  %35 = getelementptr inbounds [9 x i32], ptr %12, i64 0, i64 0
  %36 = getelementptr inbounds [64 x i8], ptr %19, i64 0, i64 0
  call void @expand256_modm(ptr noundef %35, ptr noundef %36, i64 noundef 64)
  call void @memzero(ptr noundef %19, i64 noundef 64)
  %37 = getelementptr inbounds [9 x i32], ptr %12, i64 0, i64 0
  call void @ge25519_scalarmult_base_niels(ptr noundef %15, ptr noundef @ge25519_niels_base_multiples, ptr noundef %37)
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  call void @ge25519_pack(ptr noundef %38, ptr noundef %15)
  %39 = getelementptr inbounds [9 x i32], ptr %14, i64 0, i64 0
  %40 = getelementptr inbounds [64 x i8], ptr %18, i64 0, i64 0
  call void @expand256_modm(ptr noundef %39, ptr noundef %40, i64 noundef 32)
  call void @memzero(ptr noundef %18, i64 noundef 64)
  %41 = getelementptr inbounds [9 x i32], ptr %14, i64 0, i64 0
  call void @ge25519_scalarmult_base_niels(ptr noundef %16, ptr noundef @ge25519_niels_base_multiples, ptr noundef %41)
  %42 = getelementptr inbounds [32 x i8], ptr %17, i64 0, i64 0
  call void @ge25519_pack(ptr noundef %42, ptr noundef %16)
  %43 = getelementptr inbounds [64 x i8], ptr %20, i64 0, i64 0
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds [32 x i8], ptr %17, i64 0, i64 0
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load i64, ptr %7, align 8, !tbaa !9
  call void @ed25519_hram(ptr noundef %43, ptr noundef %44, ptr noundef %45, ptr noundef %46, i64 noundef %47)
  %48 = getelementptr inbounds [9 x i32], ptr %13, i64 0, i64 0
  %49 = getelementptr inbounds [64 x i8], ptr %20, i64 0, i64 0
  call void @expand256_modm(ptr noundef %48, ptr noundef %49, i64 noundef 64)
  %50 = getelementptr inbounds [9 x i32], ptr %13, i64 0, i64 0
  %51 = getelementptr inbounds [9 x i32], ptr %13, i64 0, i64 0
  %52 = getelementptr inbounds [9 x i32], ptr %14, i64 0, i64 0
  call void @mul256_modm(ptr noundef %50, ptr noundef %51, ptr noundef %52)
  call void @memzero(ptr noundef %14, i64 noundef 36)
  %53 = getelementptr inbounds [9 x i32], ptr %13, i64 0, i64 0
  %54 = getelementptr inbounds [9 x i32], ptr %13, i64 0, i64 0
  %55 = getelementptr inbounds [9 x i32], ptr %12, i64 0, i64 0
  call void @add256_modm(ptr noundef %53, ptr noundef %54, ptr noundef %55)
  call void @memzero(ptr noundef %12, i64 noundef 36)
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i64 32
  %58 = getelementptr inbounds [9 x i32], ptr %13, i64 0, i64 0
  call void @contract256_modm(ptr noundef %57, ptr noundef %58)
  call void @llvm.lifetime.end.p0(i64 64, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 160, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 160, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 248, ptr %11) #5
  ret void
}

; 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

declare i32 @tc_blake2b_Init(ptr noundef, i64 noundef) #2

declare i32 @tc_blake2b_Update(ptr noundef, ptr noundef, i64 noundef) #2

declare i32 @tc_blake2b_Final(ptr noundef, ptr noundef, i64 noundef) #2

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

declare void @ge25519_pack(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 = { 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 = !{!"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}


; 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.__blake2b_state = type { [8 x i64], [2 x i64], [2 x i64], [128 x i8], i64, i64, i8 }
%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 @expand256_modm(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @ed25519_hram(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ed25519_sign_ext_blake2b(ptr noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr noundef %4) local_unnamed_addr #3 {
  %6 = alloca %struct.__blake2b_state, align 8
  %7 = alloca [9 x i32], align 16
  %8 = alloca [9 x i32], align 16
  %9 = alloca [9 x i32], align 16
  %10 = alloca %struct.ge25519_t, align 16
  %11 = alloca %struct.ge25519_t, align 16
  %12 = alloca [32 x i8], align 16
  %13 = alloca [64 x i8], align 16
  %14 = alloca [64 x i8], align 16
  %15 = alloca [64 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 248, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %7) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(36) %7, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %8) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(36) %8, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %9) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(36) %9, i8 0, i64 36, i1 false)
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %10) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(160) %10, i8 0, i64 160, i1 false)
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %11) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(160) %11, i8 0, i64 160, i1 false)
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %12) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %12, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %13) #5
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %14) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %14, i8 0, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %15) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %15, i8 0, i64 64, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %13, ptr noundef nonnull align 1 dereferenceable(32) %2, i64 32, i1 false)
  %16 = getelementptr inbounds i8, ptr %13, i64 32
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %16, ptr noundef nonnull align 1 dereferenceable(32) %3, i64 32, i1 false)
  %17 = call i32 @tc_blake2b_Init(ptr noundef nonnull %6, i64 noundef 64) #5
  %18 = call i32 @tc_blake2b_Update(ptr noundef nonnull %6, ptr noundef nonnull %16, i64 noundef 32) #5
  %19 = call i32 @tc_blake2b_Update(ptr noundef nonnull %6, ptr noundef %0, i64 noundef %1) #5
  %20 = call i32 @tc_blake2b_Final(ptr noundef nonnull %6, ptr noundef nonnull %14, i64 noundef 64) #5
  call void @expand256_modm(ptr noundef nonnull %7, ptr noundef nonnull %14, i64 noundef 64) #5
  call void @memzero(ptr noundef nonnull %14, i64 noundef 64) #5
  call void @ge25519_scalarmult_base_niels(ptr noundef nonnull %10, ptr noundef nonnull @ge25519_niels_base_multiples, ptr noundef nonnull %7) #5
  call void @ge25519_pack(ptr noundef %4, ptr noundef nonnull %10) #5
  call void @expand256_modm(ptr noundef nonnull %9, ptr noundef nonnull %13, i64 noundef 32) #5
  call void @memzero(ptr noundef nonnull %13, i64 noundef 64) #5
  call void @ge25519_scalarmult_base_niels(ptr noundef nonnull %11, ptr noundef nonnull @ge25519_niels_base_multiples, ptr noundef nonnull %9) #5
  call void @ge25519_pack(ptr noundef nonnull %12, ptr noundef nonnull %11) #5
  call void @ed25519_hram(ptr noundef nonnull %15, ptr noundef %4, ptr noundef nonnull %12, ptr noundef %0, i64 noundef %1)
  call void @expand256_modm(ptr noundef nonnull %8, ptr noundef nonnull %15, i64 noundef 64) #5
  call void @mul256_modm(ptr noundef nonnull %8, ptr noundef nonnull %8, ptr noundef nonnull %9) #5
  call void @memzero(ptr noundef nonnull %9, i64 noundef 36) #5
  call void @add256_modm(ptr noundef nonnull %8, ptr noundef nonnull %8, ptr noundef nonnull %7) #5
  call void @memzero(ptr noundef nonnull %7, i64 noundef 36) #5
  %21 = getelementptr inbounds i8, ptr %4, i64 32
  call void @contract256_modm(ptr noundef nonnull %21, ptr noundef nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %15) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %14) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %13) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %12) #5
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %11) #5
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %10) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %9) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 248, ptr nonnull %6) #5
  ret void
}

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

declare i32 @tc_blake2b_Init(ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @tc_blake2b_Update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @tc_blake2b_Final(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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

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

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 = { mustprogress 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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass