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

; 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] }

; 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

declare void @cpy_256bitvalue(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @bigint_sub(ptr noundef, ptr noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @sc25519_binary_extended_gcd(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, 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 %union.UN_256bitValue_, align 8
  %11 = alloca %union.UN_256bitValue_, align 8
  %12 = alloca %union.UN_256bitValue_, align 8
  %13 = alloca %union.UN_256bitValue_, align 8
  %14 = alloca %union.UN_256bitValue_, align 8
  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 32, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %14) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  call void @cpy_256bitvalue(ptr noundef %12, ptr noundef %15)
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  call void @cpy_256bitvalue(ptr noundef %13, ptr noundef %16)
  call void @setone_256bitvalue(ptr noundef %11)
  br label %17

17:                                               ; preds = %31, %3
  %18 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  %19 = load i8, ptr %18, align 8, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = and i32 %20, 1
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %29

23:                                               ; preds = %17
  %24 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  %25 = load i8, ptr %24, align 8, !tbaa !9
  %26 = zext i8 %25 to i32
  %27 = and i32 %26, 1
  %28 = icmp eq i32 %27, 0
  br label %29

29:                                               ; preds = %23, %17
  %30 = phi i1 [ false, %17 ], [ %28, %23 ]
  br i1 %30, label %31, label %32

31:                                               ; preds = %29
  call void @shiftRightOne(ptr noundef %12)
  call void @shiftRightOne(ptr noundef %13)
  call void @shiftLeftOne(ptr noundef %11)
  br label %17, !llvm.loop !10

32:                                               ; preds = %29
  call void @cpy_256bitvalue(ptr noundef %10, ptr noundef %12)
  call void @cpy_256bitvalue(ptr noundef %9, ptr noundef %13)
  call void @setzero_256bitvalue(ptr noundef %7)
  call void @setone_256bitvalue(ptr noundef %8)
  call void @setzero_256bitvalue(ptr noundef %14)
  br label %33

33:                                               ; preds = %94, %32
  %34 = call i32 @isEqual_256bitvalue(ptr noundef %10, ptr noundef %14)
  %35 = icmp ugt i32 %34, 0
  br i1 %35, label %36, label %95

36:                                               ; preds = %33
  br label %37

37:                                               ; preds = %54, %36
  %38 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %39 = load i8, ptr %38, align 8, !tbaa !9
  %40 = zext i8 %39 to i32
  %41 = and i32 %40, 1
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %55

43:                                               ; preds = %37
  call void @shiftRightOne(ptr noundef %10)
  %44 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 0
  %45 = load i8, ptr %44, align 8, !tbaa !9
  %46 = zext i8 %45 to i32
  %47 = and i32 %46, 1
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %43
  call void @shiftRightOne(ptr noundef %7)
  br label %54

50:                                               ; preds = %43
  %51 = getelementptr inbounds [8 x i32], ptr %7, i64 0, i64 0
  %52 = getelementptr inbounds [8 x i32], ptr %12, i64 0, i64 0
  %53 = call i32 @bigint_sub(ptr noundef %51, ptr noundef %52, i32 noundef 8)
  call void @shiftRightOne(ptr noundef %7)
  br label %54

54:                                               ; preds = %50, %49
  br label %37, !llvm.loop !12

55:                                               ; preds = %37
  br label %56

56:                                               ; preds = %73, %55
  %57 = getelementptr inbounds [32 x i8], ptr %9, i64 0, i64 0
  %58 = load i8, ptr %57, align 8, !tbaa !9
  %59 = zext i8 %58 to i32
  %60 = and i32 %59, 1
  %61 = icmp eq i32 %60, 0
  br i1 %61, label %62, label %74

62:                                               ; preds = %56
  call void @shiftRightOne(ptr noundef %9)
  %63 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  %64 = load i8, ptr %63, align 8, !tbaa !9
  %65 = zext i8 %64 to i32
  %66 = and i32 %65, 1
  %67 = icmp eq i32 %66, 0
  br i1 %67, label %68, label %69

68:                                               ; preds = %62
  call void @shiftRightOne(ptr noundef %8)
  br label %73

69:                                               ; preds = %62
  %70 = getelementptr inbounds [8 x i32], ptr %8, i64 0, i64 0
  %71 = getelementptr inbounds [8 x i32], ptr %12, i64 0, i64 0
  %72 = call i32 @bigint_sub(ptr noundef %70, ptr noundef %71, i32 noundef 8)
  call void @shiftRightOne(ptr noundef %8)
  br label %73

73:                                               ; preds = %69, %68
  br label %56, !llvm.loop !13

74:                                               ; preds = %56
  %75 = call i32 @greaterThan(ptr noundef %10, ptr noundef %9)
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %77, label %80

77:                                               ; preds = %74
  %78 = call i32 @isEqual_256bitvalue(ptr noundef %10, ptr noundef %9)
  %79 = icmp eq i32 %78, 0
  br i1 %79, label %80, label %87

80:                                               ; preds = %77, %74
  %81 = getelementptr inbounds [8 x i32], ptr %10, i64 0, i64 0
  %82 = getelementptr inbounds [8 x i32], ptr %9, i64 0, i64 0
  %83 = call i32 @bigint_sub(ptr noundef %81, ptr noundef %82, i32 noundef 8)
  %84 = getelementptr inbounds [8 x i32], ptr %7, i64 0, i64 0
  %85 = getelementptr inbounds [8 x i32], ptr %8, i64 0, i64 0
  %86 = call i32 @bigint_sub(ptr noundef %84, ptr noundef %85, i32 noundef 8)
  br label %94

87:                                               ; preds = %77
  %88 = getelementptr inbounds [8 x i32], ptr %9, i64 0, i64 0
  %89 = getelementptr inbounds [8 x i32], ptr %10, i64 0, i64 0
  %90 = call i32 @bigint_sub(ptr noundef %88, ptr noundef %89, i32 noundef 8)
  %91 = getelementptr inbounds [8 x i32], ptr %8, i64 0, i64 0
  %92 = getelementptr inbounds [8 x i32], ptr %7, i64 0, i64 0
  %93 = call i32 @bigint_sub(ptr noundef %91, ptr noundef %92, i32 noundef 8)
  br label %94

94:                                               ; preds = %87, %80
  br label %33, !llvm.loop !14

95:                                               ; preds = %33
  %96 = load ptr, ptr %4, align 8, !tbaa !5
  call void @cpy_256bitvalue(ptr noundef %96, ptr noundef %8)
  call void @llvm.lifetime.end.p0(i64 32, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #3
  ret void
}

declare void @setone_256bitvalue(ptr noundef) #1

declare void @shiftRightOne(ptr noundef) #1

declare void @shiftLeftOne(ptr noundef) #1

declare void @setzero_256bitvalue(ptr noundef) #1

declare i32 @isEqual_256bitvalue(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}


; 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] }

; 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

declare void @cpy_256bitvalue(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @bigint_sub(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local void @sc25519_binary_extended_gcd(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %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
  %8 = alloca %union.UN_256bitValue_, align 8
  %9 = alloca %union.UN_256bitValue_, align 8
  %10 = alloca %union.UN_256bitValue_, align 8
  %11 = alloca %union.UN_256bitValue_, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %8) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %9) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %10) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %11) #3
  call void @cpy_256bitvalue(ptr noundef nonnull %9, ptr noundef %1) #3
  call void @cpy_256bitvalue(ptr noundef nonnull %10, ptr noundef %2) #3
  call void @setone_256bitvalue(ptr noundef nonnull %8) #3
  %12 = load i8, ptr %9, align 8, !tbaa !5
  %13 = and i8 %12, 1
  %14 = icmp eq i8 %13, 0
  %15 = load i8, ptr %10, align 8
  %16 = and i8 %15, 1
  %17 = icmp eq i8 %16, 0
  %18 = select i1 %14, i1 %17, i1 false
  br i1 %18, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  call void @shiftRightOne(ptr noundef nonnull %9) #3
  call void @shiftRightOne(ptr noundef nonnull %10) #3
  call void @shiftLeftOne(ptr noundef nonnull %8) #3
  %19 = load i8, ptr %9, align 8, !tbaa !5
  %20 = and i8 %19, 1
  %21 = icmp eq i8 %20, 0
  %22 = load i8, ptr %10, align 8
  %23 = and i8 %22, 1
  %24 = icmp eq i8 %23, 0
  %25 = select i1 %21, i1 %24, i1 false
  br i1 %25, label %.lr.ph, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph, %3
  call void @cpy_256bitvalue(ptr noundef nonnull %7, ptr noundef nonnull %9) #3
  call void @cpy_256bitvalue(ptr noundef nonnull %6, ptr noundef nonnull %10) #3
  call void @setzero_256bitvalue(ptr noundef nonnull %4) #3
  call void @setone_256bitvalue(ptr noundef nonnull %5) #3
  call void @setzero_256bitvalue(ptr noundef nonnull %11) #3
  %26 = call i32 @isEqual_256bitvalue(ptr noundef nonnull %7, ptr noundef nonnull %11) #3
  %.not8 = icmp eq i32 %26, 0
  br i1 %.not8, label %._crit_edge9, label %.preheader4

.preheader4:                                      ; preds = %._crit_edge, %61
  %27 = load i8, ptr %7, align 8, !tbaa !5
  %28 = and i8 %27, 1
  %29 = icmp eq i8 %28, 0
  br i1 %29, label %.lr.ph5, label %.preheader

.preheader:                                       ; preds = %38, %.preheader4
  %30 = load i8, ptr %6, align 8, !tbaa !5
  %31 = and i8 %30, 1
  %32 = icmp eq i8 %31, 0
  br i1 %32, label %.lr.ph6, label %._crit_edge7

.lr.ph5:                                          ; preds = %.preheader4, %38
  call void @shiftRightOne(ptr noundef nonnull %7) #3
  %33 = load i8, ptr %4, align 8, !tbaa !5
  %34 = and i8 %33, 1
  %35 = icmp eq i8 %34, 0
  br i1 %35, label %38, label %36

36:                                               ; preds = %.lr.ph5
  %37 = call i32 @bigint_sub(ptr noundef nonnull %4, ptr noundef nonnull %9, i32 noundef 8)
  br label %38

38:                                               ; preds = %.lr.ph5, %36
  call void @shiftRightOne(ptr noundef nonnull %4) #3
  %39 = load i8, ptr %7, align 8, !tbaa !5
  %40 = and i8 %39, 1
  %41 = icmp eq i8 %40, 0
  br i1 %41, label %.lr.ph5, label %.preheader, !llvm.loop !10

.lr.ph6:                                          ; preds = %.preheader, %47
  call void @shiftRightOne(ptr noundef nonnull %6) #3
  %42 = load i8, ptr %5, align 8, !tbaa !5
  %43 = and i8 %42, 1
  %44 = icmp eq i8 %43, 0
  br i1 %44, label %47, label %45

45:                                               ; preds = %.lr.ph6
  %46 = call i32 @bigint_sub(ptr noundef nonnull %5, ptr noundef nonnull %9, i32 noundef 8)
  br label %47

47:                                               ; preds = %.lr.ph6, %45
  call void @shiftRightOne(ptr noundef nonnull %5) #3
  %48 = load i8, ptr %6, align 8, !tbaa !5
  %49 = and i8 %48, 1
  %50 = icmp eq i8 %49, 0
  br i1 %50, label %.lr.ph6, label %._crit_edge7, !llvm.loop !11

._crit_edge7:                                     ; preds = %47, %.preheader
  %51 = call i32 @greaterThan(ptr noundef nonnull %7, ptr noundef nonnull %6)
  %.not3 = icmp eq i32 %51, 0
  br i1 %.not3, label %55, label %52

52:                                               ; preds = %._crit_edge7
  %53 = call i32 @isEqual_256bitvalue(ptr noundef nonnull %7, ptr noundef nonnull %6) #3
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %58

55:                                               ; preds = %52, %._crit_edge7
  %56 = call i32 @bigint_sub(ptr noundef nonnull %7, ptr noundef nonnull %6, i32 noundef 8)
  %57 = call i32 @bigint_sub(ptr noundef nonnull %4, ptr noundef nonnull %5, i32 noundef 8)
  br label %61

58:                                               ; preds = %52
  %59 = call i32 @bigint_sub(ptr noundef nonnull %6, ptr noundef nonnull %7, i32 noundef 8)
  %60 = call i32 @bigint_sub(ptr noundef nonnull %5, ptr noundef nonnull %4, i32 noundef 8)
  br label %61

61:                                               ; preds = %58, %55
  %62 = call i32 @isEqual_256bitvalue(ptr noundef nonnull %7, ptr noundef nonnull %11) #3
  %.not = icmp eq i32 %62, 0
  br i1 %.not, label %._crit_edge9, label %.preheader4, !llvm.loop !12

._crit_edge9:                                     ; preds = %61, %._crit_edge
  call void @cpy_256bitvalue(ptr noundef %0, ptr noundef nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %11) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %10) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #3
  ret void
}

declare void @setone_256bitvalue(ptr noundef) local_unnamed_addr #1

declare void @shiftRightOne(ptr noundef) local_unnamed_addr #1

declare void @shiftLeftOne(ptr noundef) local_unnamed_addr #1

declare void @setzero_256bitvalue(ptr noundef) local_unnamed_addr #1

declare i32 @isEqual_256bitvalue(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}
!11 = distinct !{!11, !9}
!12 = distinct !{!12, !9}


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