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

; 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] }
%struct.curve448_point_s = type { [1 x %struct.gf_s], [1 x %struct.gf_s], [1 x %struct.gf_s], [1 x %struct.gf_s] }
%struct.gf_s = type { [8 x i64] }

@ossl_curve448_precomputed_base = external global ptr, align 8

; Function Attrs: nounwind uwtable
declare hidden i32 @oneshot_hash(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_c448_ed448_derive_public_key(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca [57 x i8], align 16
  %11 = alloca [1 x %struct.curve448_scalar_s], align 16
  %12 = alloca i32, align 4
  %13 = alloca [1 x %struct.curve448_point_s], align 16
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 57, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 56, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 256, ptr %13) #3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds [57 x i8], ptr %10, i64 0, i64 0
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = call i32 @oneshot_hash(ptr noundef %15, ptr noundef %16, i64 noundef 57, ptr noundef %17, i64 noundef 57, ptr noundef %18)
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %22, label %21

21:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %44

22:                                               ; preds = %4
  %23 = getelementptr inbounds [57 x i8], ptr %10, i64 0, i64 0
  call void @clamp(ptr noundef %23)
  %24 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %11, i64 0, i64 0
  %25 = getelementptr inbounds [57 x i8], ptr %10, i64 0, i64 0
  call void @ossl_curve448_scalar_decode_long(ptr noundef %24, ptr noundef %25, i64 noundef 57)
  store i32 1, ptr %12, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %32, %22
  %27 = load i32, ptr %12, align 4, !tbaa !9
  %28 = icmp ult i32 %27, 4
  br i1 %28, label %29, label %35

29:                                               ; preds = %26
  %30 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %11, i64 0, i64 0
  %31 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %11, i64 0, i64 0
  call void @ossl_curve448_scalar_halve(ptr noundef %30, ptr noundef %31)
  br label %32

32:                                               ; preds = %29
  %33 = load i32, ptr %12, align 4, !tbaa !9
  %34 = shl i32 %33, 1
  store i32 %34, ptr %12, align 4, !tbaa !9
  br label %26, !llvm.loop !11

35:                                               ; preds = %26
  %36 = getelementptr inbounds [1 x %struct.curve448_point_s], ptr %13, i64 0, i64 0
  %37 = load ptr, ptr @ossl_curve448_precomputed_base, align 8, !tbaa !5
  %38 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %11, i64 0, i64 0
  call void @ossl_curve448_precomputed_scalarmul(ptr noundef %36, ptr noundef %37, ptr noundef %38)
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds [1 x %struct.curve448_point_s], ptr %13, i64 0, i64 0
  call void @ossl_curve448_point_mul_by_ratio_and_encode_like_eddsa(ptr noundef %39, ptr noundef %40)
  %41 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %11, i64 0, i64 0
  call void @ossl_curve448_scalar_destroy(ptr noundef %41)
  %42 = getelementptr inbounds [1 x %struct.curve448_point_s], ptr %13, i64 0, i64 0
  call void @ossl_curve448_point_destroy(ptr noundef %42)
  %43 = getelementptr inbounds [57 x i8], ptr %10, i64 0, i64 0
  call void @OPENSSL_cleanse(ptr noundef %43, i64 noundef 57)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %44

44:                                               ; preds = %35, %21
  call void @llvm.lifetime.end.p0(i64 256, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 56, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 57, ptr %10) #3
  %45 = load i32, ptr %5, align 4
  ret i32 %45
}

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

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

declare void @ossl_curve448_scalar_decode_long(ptr noundef, ptr noundef, i64 noundef) #2

declare void @ossl_curve448_scalar_halve(ptr noundef, ptr noundef) #2

declare void @ossl_curve448_precomputed_scalarmul(ptr noundef, ptr noundef, ptr noundef) #2

declare void @ossl_curve448_point_mul_by_ratio_and_encode_like_eddsa(ptr noundef, ptr noundef) #2

declare void @ossl_curve448_scalar_destroy(ptr noundef) #2

declare void @ossl_curve448_point_destroy(ptr noundef) #2

declare void @OPENSSL_cleanse(ptr noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"int", !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] }
%struct.curve448_point_s = type { [1 x %struct.gf_s], [1 x %struct.gf_s], [1 x %struct.gf_s], [1 x %struct.gf_s] }
%struct.gf_s = type { [8 x i64] }

@ossl_curve448_precomputed_base = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare hidden i32 @oneshot_hash(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @ossl_c448_ed448_derive_public_key(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca [57 x i8], align 16
  %6 = alloca [1 x %struct.curve448_scalar_s], align 16
  %7 = alloca [1 x %struct.curve448_point_s], align 16
  call void @llvm.lifetime.start.p0(i64 57, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %7) #3
  %8 = call i32 @oneshot_hash(ptr noundef %0, ptr noundef nonnull %5, i64 noundef 57, ptr noundef %2, i64 noundef 57, ptr noundef %3)
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %11, label %9

9:                                                ; preds = %4
  call void @clamp(ptr noundef nonnull %5)
  call void @ossl_curve448_scalar_decode_long(ptr noundef nonnull %6, ptr noundef nonnull %5, i64 noundef 57) #3
  call void @ossl_curve448_scalar_halve(ptr noundef nonnull %6, ptr noundef nonnull %6) #3
  call void @ossl_curve448_scalar_halve(ptr noundef nonnull %6, ptr noundef nonnull %6) #3
  %10 = load ptr, ptr @ossl_curve448_precomputed_base, align 8, !tbaa !5
  call void @ossl_curve448_precomputed_scalarmul(ptr noundef nonnull %7, ptr noundef %10, ptr noundef nonnull %6) #3
  call void @ossl_curve448_point_mul_by_ratio_and_encode_like_eddsa(ptr noundef %1, ptr noundef nonnull %7) #3
  call void @ossl_curve448_scalar_destroy(ptr noundef nonnull %6) #3
  call void @ossl_curve448_point_destroy(ptr noundef nonnull %7) #3
  call void @OPENSSL_cleanse(ptr noundef nonnull %5, i64 noundef 57) #3
  br label %11

11:                                               ; preds = %4, %9
  %.06 = phi i32 [ -1, %9 ], [ 0, %4 ]
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 57, ptr nonnull %5) #3
  ret i32 %.06
}

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

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

declare void @ossl_curve448_scalar_decode_long(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @ossl_curve448_scalar_halve(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @ossl_curve448_precomputed_scalarmul(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @ossl_curve448_point_mul_by_ratio_and_encode_like_eddsa(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @ossl_curve448_scalar_destroy(ptr noundef) local_unnamed_addr #2

declare void @ossl_curve448_point_destroy(ptr noundef) local_unnamed_addr #2

declare void @OPENSSL_cleanse(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass