; LLVM IR from trustwallet/wallet-core :: trezor-crypto/crypto/sodium/private (ed25519_ref10)

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

@__const.ge25519_mul_l.aslide = external hidden unnamed_addr constant [253 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @ge25519_p3_0(ptr noundef) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ge25519_mul_l(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [253 x i8], align 16
  %6 = alloca [8 x %struct.ge25519_cached], align 16
  %7 = alloca %struct.ge25519_p1p1_1, align 4
  %8 = alloca %struct.ge25519_p3, align 4
  %9 = alloca %struct.ge25519_p3, align 4
  %10 = 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 253, ptr %5) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %5, ptr align 16 @__const.ge25519_mul_l.aslide, i64 253, i1 false)
  call void @llvm.lifetime.start.p0(i64 1280, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 160, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 160, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 160, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %11 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 0
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_p3_to_cached(ptr noundef %11, ptr noundef %12)
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_p3_dbl(ptr noundef %7, ptr noundef %13)
  call void @ge25519_p1p1_to_p3(ptr noundef %9, ptr noundef %7)
  %14 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 0
  call void @ge25519_add2(ptr noundef %7, ptr noundef %9, ptr noundef %14)
  call void @ge25519_p1p1_to_p3(ptr noundef %8, ptr noundef %7)
  %15 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 1
  call void @ge25519_p3_to_cached(ptr noundef %15, ptr noundef %8)
  %16 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 1
  call void @ge25519_add2(ptr noundef %7, ptr noundef %9, ptr noundef %16)
  call void @ge25519_p1p1_to_p3(ptr noundef %8, ptr noundef %7)
  %17 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 2
  call void @ge25519_p3_to_cached(ptr noundef %17, ptr noundef %8)
  %18 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 2
  call void @ge25519_add2(ptr noundef %7, ptr noundef %9, ptr noundef %18)
  call void @ge25519_p1p1_to_p3(ptr noundef %8, ptr noundef %7)
  %19 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 3
  call void @ge25519_p3_to_cached(ptr noundef %19, ptr noundef %8)
  %20 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 3
  call void @ge25519_add2(ptr noundef %7, ptr noundef %9, ptr noundef %20)
  call void @ge25519_p1p1_to_p3(ptr noundef %8, ptr noundef %7)
  %21 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 4
  call void @ge25519_p3_to_cached(ptr noundef %21, ptr noundef %8)
  %22 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 4
  call void @ge25519_add2(ptr noundef %7, ptr noundef %9, ptr noundef %22)
  call void @ge25519_p1p1_to_p3(ptr noundef %8, ptr noundef %7)
  %23 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 5
  call void @ge25519_p3_to_cached(ptr noundef %23, ptr noundef %8)
  %24 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 5
  call void @ge25519_add2(ptr noundef %7, ptr noundef %9, ptr noundef %24)
  call void @ge25519_p1p1_to_p3(ptr noundef %8, ptr noundef %7)
  %25 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 6
  call void @ge25519_p3_to_cached(ptr noundef %25, ptr noundef %8)
  %26 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 6
  call void @ge25519_add2(ptr noundef %7, ptr noundef %9, ptr noundef %26)
  call void @ge25519_p1p1_to_p3(ptr noundef %8, ptr noundef %7)
  %27 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 7
  call void @ge25519_p3_to_cached(ptr noundef %27, ptr noundef %8)
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  call void @ge25519_p3_0(ptr noundef %28)
  store i32 252, ptr %10, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %69, %2
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = icmp sge i32 %30, 0
  br i1 %31, label %32, label %72

32:                                               ; preds = %29
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  call void @ge25519_p3_dbl(ptr noundef %7, ptr noundef %33)
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [253 x i8], ptr %5, i64 0, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = sext i8 %37 to i32
  %39 = icmp sgt i32 %38, 0
  br i1 %39, label %40, label %49

40:                                               ; preds = %32
  call void @ge25519_p1p1_to_p3(ptr noundef %8, ptr noundef %7)
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [253 x i8], ptr %5, i64 0, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = sext i8 %44 to i32
  %46 = sdiv i32 %45, 2
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 %47
  call void @ge25519_add2(ptr noundef %7, ptr noundef %8, ptr noundef %48)
  br label %67

49:                                               ; preds = %32
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [253 x i8], ptr %5, i64 0, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !11
  %54 = sext i8 %53 to i32
  %55 = icmp slt i32 %54, 0
  br i1 %55, label %56, label %66

56:                                               ; preds = %49
  call void @ge25519_p1p1_to_p3(ptr noundef %8, ptr noundef %7)
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [253 x i8], ptr %5, i64 0, i64 %58
  %60 = load i8, ptr %59, align 1, !tbaa !11
  %61 = sext i8 %60 to i32
  %62 = sub nsw i32 0, %61
  %63 = sdiv i32 %62, 2
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %6, i64 0, i64 %64
  call void @ge25519_sub(ptr noundef %7, ptr noundef %8, ptr noundef %65)
  br label %66

66:                                               ; preds = %56, %49
  br label %67

67:                                               ; preds = %66, %40
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  call void @ge25519_p1p1_to_p3(ptr noundef %68, ptr noundef %7)
  br label %69

69:                                               ; preds = %67
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = add nsw i32 %70, -1
  store i32 %71, ptr %10, align 4, !tbaa !9
  br label %29, !llvm.loop !12

72:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 160, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 160, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 160, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 1280, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 253, ptr %5) #3
  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) #2

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


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

@__const.ge25519_mul_l.aslide = external hidden unnamed_addr constant [253 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ge25519_mul_l(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca [8 x %struct.ge25519_cached], align 16
  %4 = alloca %struct.ge25519_p1p1_1, align 4
  %5 = alloca %struct.ge25519_p3, align 4
  %6 = alloca %struct.ge25519_p3, align 4
  call void @llvm.lifetime.start.p0(i64 1280, ptr nonnull %3) #2
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %4) #2
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %5) #2
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %6) #2
  call void @ge25519_p3_to_cached(ptr noundef nonnull %3, ptr noundef %1)
  call void @ge25519_p3_dbl(ptr noundef nonnull %4, ptr noundef %1)
  call void @ge25519_p1p1_to_p3(ptr noundef nonnull %6, ptr noundef nonnull %4)
  call void @ge25519_add2(ptr noundef nonnull %4, ptr noundef nonnull %6, ptr noundef nonnull %3)
  call void @ge25519_p1p1_to_p3(ptr noundef nonnull %5, ptr noundef nonnull %4)
  %7 = getelementptr inbounds i8, ptr %3, i64 160
  call void @ge25519_p3_to_cached(ptr noundef nonnull %7, ptr noundef nonnull %5)
  call void @ge25519_add2(ptr noundef nonnull %4, ptr noundef nonnull %6, ptr noundef nonnull %7)
  call void @ge25519_p1p1_to_p3(ptr noundef nonnull %5, ptr noundef nonnull %4)
  %8 = getelementptr inbounds i8, ptr %3, i64 320
  call void @ge25519_p3_to_cached(ptr noundef nonnull %8, ptr noundef nonnull %5)
  call void @ge25519_add2(ptr noundef nonnull %4, ptr noundef nonnull %6, ptr noundef nonnull %8)
  call void @ge25519_p1p1_to_p3(ptr noundef nonnull %5, ptr noundef nonnull %4)
  %9 = getelementptr inbounds i8, ptr %3, i64 480
  call void @ge25519_p3_to_cached(ptr noundef nonnull %9, ptr noundef nonnull %5)
  call void @ge25519_add2(ptr noundef nonnull %4, ptr noundef nonnull %6, ptr noundef nonnull %9)
  call void @ge25519_p1p1_to_p3(ptr noundef nonnull %5, ptr noundef nonnull %4)
  %10 = getelementptr inbounds i8, ptr %3, i64 640
  call void @ge25519_p3_to_cached(ptr noundef nonnull %10, ptr noundef nonnull %5)
  call void @ge25519_add2(ptr noundef nonnull %4, ptr noundef nonnull %6, ptr noundef nonnull %10)
  call void @ge25519_p1p1_to_p3(ptr noundef nonnull %5, ptr noundef nonnull %4)
  %11 = getelementptr inbounds i8, ptr %3, i64 800
  call void @ge25519_p3_to_cached(ptr noundef nonnull %11, ptr noundef nonnull %5)
  call void @ge25519_add2(ptr noundef nonnull %4, ptr noundef nonnull %6, ptr noundef nonnull %11)
  call void @ge25519_p1p1_to_p3(ptr noundef nonnull %5, ptr noundef nonnull %4)
  %12 = getelementptr inbounds i8, ptr %3, i64 960
  call void @ge25519_p3_to_cached(ptr noundef nonnull %12, ptr noundef nonnull %5)
  call void @ge25519_add2(ptr noundef nonnull %4, ptr noundef nonnull %6, ptr noundef nonnull %12)
  call void @ge25519_p1p1_to_p3(ptr noundef nonnull %5, ptr noundef nonnull %4)
  %13 = getelementptr inbounds i8, ptr %3, i64 1120
  call void @ge25519_p3_to_cached(ptr noundef nonnull %13, ptr noundef nonnull %5)
  call void @ge25519_p3_0(ptr noundef %0)
  br label %14

14:                                               ; preds = %2, %28
  %indvars.iv = phi i64 [ 252, %2 ], [ %indvars.iv.next, %28 ]
  call void @ge25519_p3_dbl(ptr noundef nonnull %4, ptr noundef %0)
  %15 = getelementptr inbounds [253 x i8], ptr @__const.ge25519_mul_l.aslide, i64 0, i64 %indvars.iv
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = icmp sgt i8 %16, 0
  br i1 %17, label %18, label %22

18:                                               ; preds = %14
  call void @ge25519_p1p1_to_p3(ptr noundef nonnull %5, ptr noundef nonnull %4)
  %19 = lshr i8 %16, 1
  %20 = zext nneg i8 %19 to i64
  %21 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %3, i64 0, i64 %20
  call void @ge25519_add2(ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %21)
  br label %28

22:                                               ; preds = %14
  %23 = icmp slt i8 %16, 0
  br i1 %23, label %24, label %28

24:                                               ; preds = %22
  call void @ge25519_p1p1_to_p3(ptr noundef nonnull %5, ptr noundef nonnull %4)
  %.nonneg = sub i8 0, %16
  %25 = lshr i8 %.nonneg, 1
  %26 = zext nneg i8 %25 to i64
  %27 = getelementptr inbounds [8 x %struct.ge25519_cached], ptr %3, i64 0, i64 %26
  call void @ge25519_sub(ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %27)
  br label %28

28:                                               ; preds = %22, %24, %18
  call void @ge25519_p1p1_to_p3(ptr noundef %0, ptr noundef nonnull %4)
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %.not = icmp eq i64 %indvars.iv, 0
  br i1 %.not, label %29, label %14, !llvm.loop !8

29:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %4) #2
  call void @llvm.lifetime.end.p0(i64 1280, ptr nonnull %3) #2
  ret void
}

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


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