; LLVM IR from square/subzero :: core/trezor-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_pniels_t = type { [10 x i32], [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] }
%struct.ge25519_p1p1_t = type { [10 x i32], [10 x i32], [10 x i32], [10 x i32] }

; 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_p1p1_to_partial(ptr noundef, ptr noundef) #1

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

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

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

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

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

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

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

; Function Attrs: nounwind uwtable
define dso_local void @ge25519_scalarmult(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [64 x i8], align 16
  %8 = alloca [9 x %struct.ge25519_pniels_t], align 16
  %9 = alloca %struct.ge25519_pniels_t, align 4
  %10 = alloca %struct.ge25519_t, align 4
  %11 = alloca %struct.ge25519_p1p1_t, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, 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.lifetime.start.p0(i64 1440, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 160, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 160, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 160, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %14 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  call void @contract256_window4_modm(ptr noundef %14, ptr noundef %15)
  %16 = getelementptr inbounds [9 x %struct.ge25519_pniels_t], ptr %8, i64 0, i64 0
  %17 = getelementptr inbounds %struct.ge25519_pniels_t, ptr %16, i64 1
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  call void @ge25519_full_to_pniels(ptr noundef %17, ptr noundef %18)
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  call void @ge25519_double(ptr noundef %10, ptr noundef %19)
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_set_neutral(ptr noundef %20)
  %21 = getelementptr inbounds [9 x %struct.ge25519_pniels_t], ptr %8, i64 0, i64 0
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_full_to_pniels(ptr noundef %21, ptr noundef %22)
  %23 = getelementptr inbounds [9 x %struct.ge25519_pniels_t], ptr %8, i64 0, i64 0
  %24 = getelementptr inbounds %struct.ge25519_pniels_t, ptr %23, i64 2
  call void @ge25519_full_to_pniels(ptr noundef %24, ptr noundef %10)
  store i32 1, ptr %12, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %36, %3
  %26 = load i32, ptr %12, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 7
  br i1 %27, label %28, label %39

28:                                               ; preds = %25
  %29 = load i32, ptr %12, align 4, !tbaa !9
  %30 = add nsw i32 %29, 2
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [9 x %struct.ge25519_pniels_t], ptr %8, i64 0, i64 %31
  %33 = load i32, ptr %12, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [9 x %struct.ge25519_pniels_t], ptr %8, i64 0, i64 %34
  call void @ge25519_pnielsadd(ptr noundef %32, ptr noundef %10, ptr noundef %35)
  br label %36

36:                                               ; preds = %28
  %37 = load i32, ptr %12, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %12, align 4, !tbaa !9
  br label %25, !llvm.loop !11

39:                                               ; preds = %25
  store i32 63, ptr %12, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %69, %39
  %41 = load i32, ptr %12, align 4, !tbaa !9
  %42 = icmp sge i32 %41, 0
  br i1 %42, label %43, label %72

43:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %44 = load i32, ptr %12, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !13
  %48 = sext i8 %47 to i32
  %49 = call i32 @llvm.abs.i32(i32 %48, i1 true)
  store i32 %49, ptr %13, align 4, !tbaa !9
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_double_partial(ptr noundef %50, ptr noundef %51)
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_double_partial(ptr noundef %52, ptr noundef %53)
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_double_partial(ptr noundef %54, ptr noundef %55)
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_double_p1p1(ptr noundef %11, ptr noundef %56)
  %57 = getelementptr inbounds [9 x %struct.ge25519_pniels_t], ptr %8, i64 0, i64 0
  %58 = load i32, ptr %13, align 4, !tbaa !9
  call void @ge25519_move_conditional_pniels_array(ptr noundef %9, ptr noundef %57, i32 noundef %58, i32 noundef 9)
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_p1p1_to_full(ptr noundef %59, ptr noundef %11)
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i32, ptr %12, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !13
  %65 = zext i8 %64 to i32
  %66 = ashr i32 %65, 7
  %67 = trunc i32 %66 to i8
  call void @ge25519_pnielsadd_p1p1(ptr noundef %11, ptr noundef %60, ptr noundef %9, i8 noundef zeroext %67)
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ge25519_p1p1_to_partial(ptr noundef %68, ptr noundef %11)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %69

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

72:                                               ; preds = %40
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.ge25519_t, ptr %73, i32 0, i32 3
  %75 = getelementptr inbounds [10 x i32], ptr %74, i64 0, i64 0
  %76 = getelementptr inbounds %struct.ge25519_p1p1_t, ptr %11, i32 0, i32 0
  %77 = getelementptr inbounds [10 x i32], ptr %76, i64 0, i64 0
  %78 = getelementptr inbounds %struct.ge25519_p1p1_t, ptr %11, i32 0, i32 1
  %79 = getelementptr inbounds [10 x i32], ptr %78, i64 0, i64 0
  call void @curve25519_mul(ptr noundef %75, ptr noundef %77, ptr noundef %79)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 160, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 160, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 160, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1440, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %7) #4
  ret void
}

declare void @contract256_window4_modm(ptr noundef, ptr noundef) #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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !12}


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

; 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_p1p1_to_partial(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

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

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

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ge25519_scalarmult(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
.preheader.preheader:
  %3 = alloca [64 x i8], align 16
  %4 = alloca [9 x %struct.ge25519_pniels_t], align 16
  %5 = alloca %struct.ge25519_pniels_t, align 4
  %6 = alloca %struct.ge25519_t, align 4
  %7 = alloca %struct.ge25519_p1p1_t, align 4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 1440, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %7) #4
  call void @contract256_window4_modm(ptr noundef nonnull %3, ptr noundef %2) #4
  %8 = getelementptr inbounds i8, ptr %4, i64 160
  call void @ge25519_full_to_pniels(ptr noundef nonnull %8, ptr noundef %1)
  call void @ge25519_double(ptr noundef nonnull %6, ptr noundef %1)
  call void @ge25519_set_neutral(ptr noundef %0)
  call void @ge25519_full_to_pniels(ptr noundef nonnull %4, ptr noundef %0)
  %9 = getelementptr inbounds i8, ptr %4, i64 320
  call void @ge25519_full_to_pniels(ptr noundef nonnull %9, ptr noundef nonnull %6)
  %10 = getelementptr inbounds i8, ptr %4, i64 480
  call void @ge25519_pnielsadd(ptr noundef nonnull %10, ptr noundef nonnull %6, ptr noundef nonnull %8)
  %11 = getelementptr inbounds i8, ptr %4, i64 640
  call void @ge25519_pnielsadd(ptr noundef nonnull %11, ptr noundef nonnull %6, ptr noundef nonnull %9)
  %12 = getelementptr inbounds i8, ptr %4, i64 800
  call void @ge25519_pnielsadd(ptr noundef nonnull %12, ptr noundef nonnull %6, ptr noundef nonnull %10)
  %13 = getelementptr inbounds i8, ptr %4, i64 960
  call void @ge25519_pnielsadd(ptr noundef nonnull %13, ptr noundef nonnull %6, ptr noundef nonnull %11)
  %14 = getelementptr inbounds i8, ptr %4, i64 1120
  call void @ge25519_pnielsadd(ptr noundef nonnull %14, ptr noundef nonnull %6, ptr noundef nonnull %12)
  %15 = getelementptr inbounds i8, ptr %4, i64 1280
  call void @ge25519_pnielsadd(ptr noundef nonnull %15, ptr noundef nonnull %6, ptr noundef nonnull %13)
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %indvars.iv = phi i64 [ 63, %.preheader.preheader ], [ %indvars.iv.next, %.preheader ]
  %16 = getelementptr inbounds [64 x i8], ptr %3, i64 0, i64 %indvars.iv
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %18 = call i8 @llvm.abs.i8(i8 %17, i1 false)
  %19 = zext i8 %18 to i32
  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_p1p1(ptr noundef nonnull %7, ptr noundef %0)
  call void @ge25519_move_conditional_pniels_array(ptr noundef nonnull %5, ptr noundef nonnull %4, i32 noundef %19, i32 noundef 9)
  call void @ge25519_p1p1_to_full(ptr noundef %0, ptr noundef nonnull %7)
  %20 = load i8, ptr %16, align 1, !tbaa !5
  %21 = lshr i8 %20, 7
  call void @ge25519_pnielsadd_p1p1(ptr noundef nonnull %7, ptr noundef %0, ptr noundef nonnull %5, i8 noundef zeroext %21)
  call void @ge25519_p1p1_to_partial(ptr noundef %0, ptr noundef nonnull %7)
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %.not = icmp eq i64 %indvars.iv, 0
  br i1 %.not, label %22, label %.preheader, !llvm.loop !8

22:                                               ; preds = %.preheader
  %23 = getelementptr inbounds i8, ptr %0, i64 120
  %24 = getelementptr inbounds i8, ptr %7, i64 40
  call void @curve25519_mul(ptr noundef nonnull %23, ptr noundef nonnull %7, ptr noundef nonnull %24) #4
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 1440, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #4
  ret void
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.abs.i8(i8, i1 immarg) #3

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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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