; LLVM IR from openssl/openssl :: crypto/ec/curve448 (scalar)

; 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.curve448_scalar_s = type { [7 x i64] }

@ossl_curve448_scalar_one = external dso_local constant [1 x %struct.curve448_scalar_s], align 16
@ossl_curve448_scalar_zero = external dso_local constant [1 x %struct.curve448_scalar_s], align 16
@sc_r2 = external hidden constant [1 x %struct.curve448_scalar_s], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@__PRETTY_FUNCTION__.ossl_curve448_scalar_decode_long = external hidden unnamed_addr constant [97 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare hidden void @sc_montmul(ptr noundef, ptr noundef, ptr noundef) #0

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @scalar_decode_short(ptr noundef, ptr noundef, i64 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @ossl_curve448_scalar_decode_long(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca [1 x %struct.curve448_scalar_s], align 16
  %9 = alloca [1 x %struct.curve448_scalar_s], align 16
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 56, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 56, ptr %9) #4
  %11 = load i64, ptr %6, align 8, !tbaa !9
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  call void @curve448_scalar_copy(ptr noundef %14, ptr noundef @ossl_curve448_scalar_zero)
  store i32 1, ptr %10, align 4
  br label %67

15:                                               ; preds = %3
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = urem i64 %17, 56
  %19 = sub i64 %16, %18
  store i64 %19, ptr %7, align 8, !tbaa !9
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = icmp eq i64 %20, %21
  br i1 %22, label %23, label %26

23:                                               ; preds = %15
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = sub i64 %24, 56
  store i64 %25, ptr %7, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %23, %15
  %27 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %8, i64 0, i64 0
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %28, i64 %29
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = load i64, ptr %7, align 8, !tbaa !9
  %33 = sub i64 %31, %32
  call void @scalar_decode_short(ptr noundef %27, ptr noundef %30, i64 noundef %33)
  %34 = load i64, ptr %6, align 8, !tbaa !9
  %35 = icmp eq i64 %34, 56
  br i1 %35, label %36, label %45

36:                                               ; preds = %26
  %37 = load i64, ptr %7, align 8, !tbaa !9
  %38 = icmp eq i64 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  br label %41

40:                                               ; preds = %36
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 194, ptr noundef @__PRETTY_FUNCTION__.ossl_curve448_scalar_decode_long) #5
  unreachable

41:                                               ; preds = %39
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %8, i64 0, i64 0
  call void @ossl_curve448_scalar_mul(ptr noundef %42, ptr noundef %43, ptr noundef @ossl_curve448_scalar_one)
  %44 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %8, i64 0, i64 0
  call void @ossl_curve448_scalar_destroy(ptr noundef %44)
  store i32 1, ptr %10, align 4
  br label %67

45:                                               ; preds = %26
  br label %46

46:                                               ; preds = %49, %45
  %47 = load i64, ptr %7, align 8, !tbaa !9
  %48 = icmp ne i64 %47, 0
  br i1 %48, label %49, label %62

49:                                               ; preds = %46
  %50 = load i64, ptr %7, align 8, !tbaa !9
  %51 = sub i64 %50, 56
  store i64 %51, ptr %7, align 8, !tbaa !9
  %52 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %8, i64 0, i64 0
  %53 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %8, i64 0, i64 0
  call void @sc_montmul(ptr noundef %52, ptr noundef %53, ptr noundef @sc_r2)
  %54 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %9, i64 0, i64 0
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i64, ptr %7, align 8, !tbaa !9
  %57 = getelementptr inbounds i8, ptr %55, i64 %56
  %58 = call i32 @ossl_curve448_scalar_decode(ptr noundef %54, ptr noundef %57)
  %59 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %8, i64 0, i64 0
  %60 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %8, i64 0, i64 0
  %61 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %9, i64 0, i64 0
  call void @ossl_curve448_scalar_add(ptr noundef %59, ptr noundef %60, ptr noundef %61)
  br label %46, !llvm.loop !11

62:                                               ; preds = %46
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %8, i64 0, i64 0
  call void @curve448_scalar_copy(ptr noundef %63, ptr noundef %64)
  %65 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %8, i64 0, i64 0
  call void @ossl_curve448_scalar_destroy(ptr noundef %65)
  %66 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %9, i64 0, i64 0
  call void @ossl_curve448_scalar_destroy(ptr noundef %66)
  store i32 0, ptr %10, align 4
  br label %67

67:                                               ; preds = %62, %41, %13
  call void @llvm.lifetime.end.p0(i64 56, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 56, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %68 = load i32, ptr %10, align 4
  switch i32 %68, label %70 [
    i32 0, label %69
    i32 1, label %69
  ]

69:                                               ; preds = %67, %67
  ret void

70:                                               ; preds = %67
  unreachable
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @curve448_scalar_copy(ptr noundef, ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = { noreturn nounwind "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 }
attributes #5 = { noreturn 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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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.curve448_scalar_s = type { [7 x i64] }

@ossl_curve448_scalar_one = external dso_local constant [1 x %struct.curve448_scalar_s], align 16
@ossl_curve448_scalar_zero = external dso_local constant [1 x %struct.curve448_scalar_s], align 16
@sc_r2 = external hidden constant [1 x %struct.curve448_scalar_s], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@__PRETTY_FUNCTION__.ossl_curve448_scalar_decode_long = external hidden unnamed_addr constant [97 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare hidden void @sc_montmul(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @scalar_decode_short(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local void @ossl_curve448_scalar_decode_long(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = alloca [1 x %struct.curve448_scalar_s], align 16
  %5 = alloca [1 x %struct.curve448_scalar_s], align 16
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %5) #4
  %6 = icmp eq i64 %2, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %3
  tail call void @curve448_scalar_copy(ptr noundef %0, ptr noundef nonnull @ossl_curve448_scalar_zero)
  br label %23

8:                                                ; preds = %3
  %9 = urem i64 %2, 56
  %10 = sub nuw i64 %2, %9
  %11 = icmp eq i64 %9, 0
  %12 = add i64 %10, -56
  %spec.select = select i1 %11, i64 %12, i64 %10
  %13 = getelementptr inbounds i8, ptr %1, i64 %spec.select
  %14 = sub i64 %2, %spec.select
  call void @scalar_decode_short(ptr noundef nonnull %4, ptr noundef %13, i64 noundef %14)
  %15 = icmp eq i64 %2, 56
  br i1 %15, label %16, label %.preheader

.preheader:                                       ; preds = %8
  %.not21 = icmp eq i64 %spec.select, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph

16:                                               ; preds = %8
  %17 = icmp eq i64 %12, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %16
  call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 194, ptr noundef nonnull @__PRETTY_FUNCTION__.ossl_curve448_scalar_decode_long) #5
  unreachable

19:                                               ; preds = %16
  call void @ossl_curve448_scalar_mul(ptr noundef %0, ptr noundef nonnull %4, ptr noundef nonnull @ossl_curve448_scalar_one)
  call void @ossl_curve448_scalar_destroy(ptr noundef nonnull %4)
  br label %23

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.122 = phi i64 [ %20, %.lr.ph ], [ %spec.select, %.preheader ]
  %20 = add i64 %.122, -56
  call void @sc_montmul(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef nonnull @sc_r2)
  %21 = getelementptr inbounds i8, ptr %1, i64 %20
  %22 = call i32 @ossl_curve448_scalar_decode(ptr noundef nonnull %5, ptr noundef %21)
  call void @ossl_curve448_scalar_add(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %.not = icmp eq i64 %20, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  call void @curve448_scalar_copy(ptr noundef %0, ptr noundef nonnull %4)
  call void @ossl_curve448_scalar_destroy(ptr noundef nonnull %4)
  call void @ossl_curve448_scalar_destroy(ptr noundef nonnull %5)
  br label %23

23:                                               ; preds = %._crit_edge, %19, %7
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %4) #4
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @curve448_scalar_copy(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = { noreturn nounwind "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 }
attributes #5 = { noreturn 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"}


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