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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @fe25519_iseq_vartime(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds [8 x i32], ptr %8, i64 0, i64 7
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds [8 x i32], ptr %11, i64 0, i64 7
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = icmp ne i32 %10, %13
  br i1 %14, label %15, label %27

15:                                               ; preds = %2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  call void @fe25519_reduceCompletely(ptr noundef %16)
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  call void @fe25519_reduceCompletely(ptr noundef %17)
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds [8 x i32], ptr %18, i64 0, i64 7
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds [8 x i32], ptr %21, i64 0, i64 7
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = icmp ne i32 %20, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %15
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

26:                                               ; preds = %15
  br label %27

27:                                               ; preds = %26, %2
  store i8 0, ptr %6, align 1, !tbaa !9
  br label %28

28:                                               ; preds = %46, %27
  %29 = load i8, ptr %6, align 1, !tbaa !9
  %30 = zext i8 %29 to i32
  %31 = icmp slt i32 %30, 7
  br i1 %31, label %32, label %49

32:                                               ; preds = %28
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load i8, ptr %6, align 1, !tbaa !9
  %35 = zext i8 %34 to i64
  %36 = getelementptr inbounds [8 x i32], ptr %33, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load i8, ptr %6, align 1, !tbaa !9
  %40 = zext i8 %39 to i64
  %41 = getelementptr inbounds [8 x i32], ptr %38, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = icmp ne i32 %37, %42
  br i1 %43, label %44, label %45

44:                                               ; preds = %32
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

45:                                               ; preds = %32
  br label %46

46:                                               ; preds = %45
  %47 = load i8, ptr %6, align 1, !tbaa !9
  %48 = add i8 %47, 1
  store i8 %48, ptr %6, align 1, !tbaa !9
  br label %28, !llvm.loop !10

49:                                               ; preds = %28
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

50:                                               ; preds = %49, %44, %25
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  %51 = load i32, ptr %3, align 4
  ret i32 %51
}

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 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @fe25519_iseq_vartime(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 28
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 28
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not = icmp eq i32 %4, %6
  br i1 %.not, label %10, label %7

7:                                                ; preds = %2
  tail call void @fe25519_reduceCompletely(ptr noundef nonnull %0)
  tail call void @fe25519_reduceCompletely(ptr noundef nonnull %1)
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %.not13 = icmp eq i32 %8, %9
  br i1 %.not13, label %10, label %.loopexit

10:                                               ; preds = %7, %2
  %11 = load i32, ptr %0, align 4, !tbaa !5
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %.not14 = icmp eq i32 %11, %12
  br i1 %.not14, label %13, label %.loopexit

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %0, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %1, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %.not14.1 = icmp eq i32 %15, %17
  br i1 %.not14.1, label %18, label %.loopexit

18:                                               ; preds = %13
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %1, i64 8
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %.not14.2 = icmp eq i32 %20, %22
  br i1 %.not14.2, label %23, label %.loopexit

23:                                               ; preds = %18
  %24 = getelementptr inbounds i8, ptr %0, i64 12
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %1, i64 12
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not14.3 = icmp eq i32 %25, %27
  br i1 %.not14.3, label %28, label %.loopexit

28:                                               ; preds = %23
  %29 = getelementptr inbounds i8, ptr %0, i64 16
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %1, i64 16
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %.not14.4 = icmp eq i32 %30, %32
  br i1 %.not14.4, label %33, label %.loopexit

33:                                               ; preds = %28
  %34 = getelementptr inbounds i8, ptr %0, i64 20
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %1, i64 20
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %.not14.5 = icmp eq i32 %35, %37
  br i1 %.not14.5, label %38, label %.loopexit

38:                                               ; preds = %33
  %39 = getelementptr inbounds i8, ptr %0, i64 24
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %1, i64 24
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %.not14.6 = icmp eq i32 %40, %42
  %spec.select = zext i1 %.not14.6 to i32
  br label %.loopexit

.loopexit:                                        ; preds = %38, %10, %13, %18, %23, %28, %33, %7
  %.012 = phi i32 [ 0, %7 ], [ 0, %10 ], [ 0, %13 ], [ 0, %18 ], [ 0, %23 ], [ 0, %28 ], [ 0, %33 ], [ %spec.select, %38 ]
  ret i32 %.012
}

attributes #0 = { 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" }

!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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass