; 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
@sc_p = external hidden constant [1 x %struct.curve448_scalar_s], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @ossl_curve448_scalar_mul(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
define dso_local i32 @ossl_curve448_scalar_decode(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i128, align 16
  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) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #3
  store i128 0, ptr %6, align 16, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  call void @scalar_decode_short(ptr noundef %7, ptr noundef %8, i64 noundef 56)
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %9

9:                                                ; preds = %29, %2
  %10 = load i32, ptr %5, align 4, !tbaa !11
  %11 = icmp ult i32 %10, 7
  br i1 %11, label %12, label %32

12:                                               ; preds = %9
  %13 = load i128, ptr %6, align 16, !tbaa !9
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.curve448_scalar_s, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %5, align 4, !tbaa !11
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds [7 x i64], ptr %15, i64 0, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = zext i64 %19 to i128
  %21 = add nsw i128 %13, %20
  %22 = load i32, ptr %5, align 4, !tbaa !11
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds [7 x i64], ptr @sc_p, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !13
  %26 = zext i64 %25 to i128
  %27 = sub nsw i128 %21, %26
  %28 = ashr i128 %27, 64
  store i128 %28, ptr %6, align 16, !tbaa !9
  br label %29

29:                                               ; preds = %12
  %30 = load i32, ptr %5, align 4, !tbaa !11
  %31 = add i32 %30, 1
  store i32 %31, ptr %5, align 4, !tbaa !11
  br label %9, !llvm.loop !15

32:                                               ; preds = %9
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  call void @ossl_curve448_scalar_mul(ptr noundef %33, ptr noundef %34, ptr noundef @ossl_curve448_scalar_one)
  %35 = load i128, ptr %6, align 16, !tbaa !9
  %36 = trunc i128 %35 to i32
  %37 = zext i32 %36 to i64
  %38 = call i64 @constant_time_is_zero_64(i64 noundef %37)
  %39 = xor i64 %38, -1
  %40 = call i32 @c448_succeed_if(i64 noundef %39)
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %40
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @c448_succeed_if(i64 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @constant_time_is_zero_64(i64 noundef) #2

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 = { 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 = !{!"__int128", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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
@sc_p = external hidden local_unnamed_addr constant [1 x %struct.curve448_scalar_s], align 16

; 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
define dso_local i32 @ossl_curve448_scalar_decode(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  tail call void @scalar_decode_short(ptr noundef %0, ptr noundef %1, i64 noundef 56)
  %3 = load i64, ptr %0, align 8, !tbaa !5
  %4 = zext i64 %3 to i128
  %5 = load i64, ptr @sc_p, align 16, !tbaa !5
  %6 = zext i64 %5 to i128
  %7 = sub nsw i128 %4, %6
  %8 = ashr i128 %7, 64
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = zext i64 %10 to i128
  %12 = add nsw i128 %8, %11
  %13 = load i64, ptr getelementptr inbounds (i8, ptr @sc_p, i64 8), align 8, !tbaa !5
  %14 = zext i64 %13 to i128
  %15 = sub nsw i128 %12, %14
  %16 = ashr i128 %15, 64
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = zext i64 %18 to i128
  %20 = add nsw i128 %16, %19
  %21 = load i64, ptr getelementptr inbounds (i8, ptr @sc_p, i64 16), align 16, !tbaa !5
  %22 = zext i64 %21 to i128
  %23 = sub nsw i128 %20, %22
  %24 = ashr i128 %23, 64
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = zext i64 %26 to i128
  %28 = add nsw i128 %24, %27
  %29 = load i64, ptr getelementptr inbounds (i8, ptr @sc_p, i64 24), align 8, !tbaa !5
  %30 = zext i64 %29 to i128
  %31 = sub nsw i128 %28, %30
  %32 = ashr i128 %31, 64
  %33 = getelementptr inbounds i8, ptr %0, i64 32
  %34 = load i64, ptr %33, align 8, !tbaa !5
  %35 = zext i64 %34 to i128
  %36 = add nsw i128 %32, %35
  %37 = load i64, ptr getelementptr inbounds (i8, ptr @sc_p, i64 32), align 16, !tbaa !5
  %38 = zext i64 %37 to i128
  %39 = sub nsw i128 %36, %38
  %40 = ashr i128 %39, 64
  %41 = getelementptr inbounds i8, ptr %0, i64 40
  %42 = load i64, ptr %41, align 8, !tbaa !5
  %43 = zext i64 %42 to i128
  %44 = add nsw i128 %40, %43
  %45 = load i64, ptr getelementptr inbounds (i8, ptr @sc_p, i64 40), align 8, !tbaa !5
  %46 = zext i64 %45 to i128
  %47 = sub nsw i128 %44, %46
  %48 = ashr i128 %47, 64
  %49 = getelementptr inbounds i8, ptr %0, i64 48
  %50 = load i64, ptr %49, align 8, !tbaa !5
  %51 = zext i64 %50 to i128
  %52 = add nsw i128 %48, %51
  %53 = load i64, ptr getelementptr inbounds (i8, ptr @sc_p, i64 48), align 16, !tbaa !5
  %54 = zext i64 %53 to i128
  %55 = sub nsw i128 %52, %54
  %56 = lshr i128 %55, 64
  tail call void @ossl_curve448_scalar_mul(ptr noundef nonnull %0, ptr noundef nonnull %0, ptr noundef nonnull @ossl_curve448_scalar_one)
  %57 = trunc nuw i128 %56 to i64
  %58 = and i64 %57, 4294967295
  %59 = tail call i64 @constant_time_is_zero_64(i64 noundef %58)
  %60 = xor i64 %59, -1
  %61 = tail call i32 @c448_succeed_if(i64 noundef %60)
  ret i32 %61
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @c448_succeed_if(i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @constant_time_is_zero_64(i64 noundef) local_unnamed_addr #1

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

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass