; LLVM IR from sca-secure-library-sca25519/sca25519 :: STM32F407-ephemeral/crypto/numerics (fe25519)

; 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"

%union.UN_256bitValue_ = type { [4 x %union.UN_64bitValue_] }
%union.UN_64bitValue_ = type { [1 x i64] }

@__const.fe25519_squareroot.pminusone = external hidden unnamed_addr constant { [32 x i8] }, align 8

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @fe25519_squareroot(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %union.UN_256bitValue_, align 8
  %7 = alloca %union.UN_256bitValue_, align 8
  %8 = alloca %union.UN_256bitValue_, align 8
  %9 = alloca %union.UN_256bitValue_, align 8
  %10 = alloca i32, align 4
  %11 = alloca %union.UN_256bitValue_, 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 4, ptr %5) #4
  store i32 -1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 @__const.fe25519_squareroot.pminusone, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  call void @fe25519_cpy(ptr noundef %6, ptr noundef %12)
  call void @fe25519_setone(ptr noundef %8)
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  call void @fe25519_cpy(ptr noundef %7, ptr noundef %13)
  call void @fe25519_square_asm(ptr noundef %6, ptr noundef %6)
  call void @fe25519_mul_asm(ptr noundef %7, ptr noundef %6, ptr noundef %7)
  call void @fe25519_square_asm(ptr noundef %6, ptr noundef %6)
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %18, %2
  %15 = load i32, ptr %10, align 4, !tbaa !9
  %16 = icmp slt i32 %15, 250
  br i1 %16, label %17, label %21

17:                                               ; preds = %14
  call void @fe25519_square_asm(ptr noundef %6, ptr noundef %6)
  call void @fe25519_mul_asm(ptr noundef %7, ptr noundef %6, ptr noundef %7)
  br label %18

18:                                               ; preds = %17
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %10, align 4, !tbaa !9
  br label %14, !llvm.loop !11

21:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #4
  %22 = call i32 @fe25519_iseq_vartime(ptr noundef %7, ptr noundef %8)
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %37

24:                                               ; preds = %21
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  call void @fe25519_cpy(ptr noundef %6, ptr noundef %25)
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  call void @fe25519_setone(ptr noundef %26)
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %33, %24
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = icmp slt i32 %28, 251
  br i1 %29, label %30, label %36

30:                                               ; preds = %27
  call void @fe25519_square_asm(ptr noundef %6, ptr noundef %6)
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  call void @fe25519_mul_asm(ptr noundef %31, ptr noundef %32, ptr noundef %6)
  br label %33

33:                                               ; preds = %30
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %10, align 4, !tbaa !9
  br label %27, !llvm.loop !13

36:                                               ; preds = %27
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %58

37:                                               ; preds = %21
  %38 = call i32 @fe25519_iseq_vartime(ptr noundef %7, ptr noundef %9)
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %57

40:                                               ; preds = %37
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  call void @fe25519_add_asm(ptr noundef %11, ptr noundef %41, ptr noundef %42)
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  call void @fe25519_add_asm(ptr noundef %43, ptr noundef %11, ptr noundef %11)
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  call void @fe25519_cpy(ptr noundef %6, ptr noundef %44)
  call void @fe25519_square_asm(ptr noundef %6, ptr noundef %6)
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %51, %40
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = icmp slt i32 %46, 250
  br i1 %47, label %48, label %54

48:                                               ; preds = %45
  call void @fe25519_square_asm(ptr noundef %6, ptr noundef %6)
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  call void @fe25519_mul_asm(ptr noundef %49, ptr noundef %50, ptr noundef %6)
  br label %51

51:                                               ; preds = %48
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %10, align 4, !tbaa !9
  br label %45, !llvm.loop !14

54:                                               ; preds = %45
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  call void @fe25519_mul_asm(ptr noundef %55, ptr noundef %56, ptr noundef %11)
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %54, %37
  br label %58

58:                                               ; preds = %57, %36
  %59 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %59
}

; 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

declare void @fe25519_square_asm(ptr noundef, ptr noundef) #3

declare void @fe25519_mul_asm(ptr noundef, ptr noundef, ptr noundef) #3

declare void @fe25519_add_asm(ptr noundef, ptr noundef, ptr noundef) #3

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 = { "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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!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"

%union.UN_256bitValue_ = type { [4 x %union.UN_64bitValue_] }
%union.UN_64bitValue_ = type { [1 x i64] }

@__const.fe25519_squareroot.pminusone = external hidden unnamed_addr constant { [32 x i8] }, align 8

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @fe25519_squareroot(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca %union.UN_256bitValue_, align 8
  %4 = alloca %union.UN_256bitValue_, align 8
  %5 = alloca %union.UN_256bitValue_, align 8
  %6 = alloca %union.UN_256bitValue_, align 8
  %7 = alloca %union.UN_256bitValue_, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %6, ptr noundef nonnull align 8 dereferenceable(32) @__const.fe25519_squareroot.pminusone, i64 32, i1 false)
  call void @fe25519_cpy(ptr noundef nonnull %3, ptr noundef %1)
  call void @fe25519_setone(ptr noundef nonnull %5)
  call void @fe25519_cpy(ptr noundef nonnull %4, ptr noundef %1)
  call void @fe25519_square_asm(ptr noundef nonnull %3, ptr noundef nonnull %3) #4
  call void @fe25519_mul_asm(ptr noundef nonnull %4, ptr noundef nonnull %3, ptr noundef nonnull %4) #4
  call void @fe25519_square_asm(ptr noundef nonnull %3, ptr noundef nonnull %3) #4
  br label %8

8:                                                ; preds = %2, %8
  %.022 = phi i32 [ 0, %2 ], [ %9, %8 ]
  call void @fe25519_square_asm(ptr noundef nonnull %3, ptr noundef nonnull %3) #4
  call void @fe25519_mul_asm(ptr noundef nonnull %4, ptr noundef nonnull %3, ptr noundef nonnull %4) #4
  %9 = add nuw nsw i32 %.022, 1
  %exitcond.not = icmp eq i32 %9, 250
  br i1 %exitcond.not, label %10, label %8, !llvm.loop !5

10:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %7) #4
  %11 = call i32 @fe25519_iseq_vartime(ptr noundef nonnull %4, ptr noundef nonnull %5)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %15, label %12

12:                                               ; preds = %10
  call void @fe25519_cpy(ptr noundef nonnull %3, ptr noundef %1)
  call void @fe25519_setone(ptr noundef %0)
  br label %13

13:                                               ; preds = %12, %13
  %.123 = phi i32 [ 0, %12 ], [ %14, %13 ]
  call void @fe25519_square_asm(ptr noundef nonnull %3, ptr noundef nonnull %3) #4
  call void @fe25519_mul_asm(ptr noundef %0, ptr noundef %0, ptr noundef nonnull %3) #4
  %14 = add nuw nsw i32 %.123, 1
  %exitcond25.not = icmp eq i32 %14, 251
  br i1 %exitcond25.not, label %.loopexit, label %13, !llvm.loop !7

15:                                               ; preds = %10
  %16 = call i32 @fe25519_iseq_vartime(ptr noundef nonnull %4, ptr noundef nonnull %6)
  %.not21 = icmp eq i32 %16, 0
  br i1 %.not21, label %.loopexit, label %17

17:                                               ; preds = %15
  call void @fe25519_add_asm(ptr noundef nonnull %7, ptr noundef %1, ptr noundef %1) #4
  call void @fe25519_add_asm(ptr noundef %0, ptr noundef nonnull %7, ptr noundef nonnull %7) #4
  call void @fe25519_cpy(ptr noundef nonnull %3, ptr noundef %0)
  call void @fe25519_square_asm(ptr noundef nonnull %3, ptr noundef nonnull %3) #4
  br label %18

18:                                               ; preds = %17, %18
  %.224 = phi i32 [ 0, %17 ], [ %19, %18 ]
  call void @fe25519_square_asm(ptr noundef nonnull %3, ptr noundef nonnull %3) #4
  call void @fe25519_mul_asm(ptr noundef %0, ptr noundef %0, ptr noundef nonnull %3) #4
  %19 = add nuw nsw i32 %.224, 1
  %exitcond26.not = icmp eq i32 %19, 250
  br i1 %exitcond26.not, label %20, label %18, !llvm.loop !8

20:                                               ; preds = %18
  call void @fe25519_mul_asm(ptr noundef %0, ptr noundef %0, ptr noundef nonnull %7) #4
  br label %.loopexit

.loopexit:                                        ; preds = %13, %15, %20
  %.020 = phi i32 [ 0, %20 ], [ -1, %15 ], [ 0, %13 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  ret i32 %.020
}

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

declare void @fe25519_square_asm(ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @fe25519_mul_asm(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @fe25519_add_asm(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = distinct !{!8, !6}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass