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

; 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: 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 @ossl_curve448_precomputed_scalarmul(ptr noundef, ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @ossl_curve448_point_destroy(ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

; Function Attrs: nounwind uwtable
define dso_local void @ossl_x448_derive_public_key(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [56 x i8], align 16
  %6 = alloca [1 x %struct.curve448_scalar_s], align 16
  %7 = alloca [1 x %struct.curve448_point_s], align 16
  %8 = alloca i32, align 4
  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 56, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 56, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 256, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %9 = getelementptr inbounds [56 x i8], ptr %5, i64 0, i64 0
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %9, ptr align 1 %10, i64 56, i1 false)
  %11 = getelementptr inbounds [56 x i8], ptr %5, i64 0, i64 0
  %12 = load i8, ptr %11, align 16, !tbaa !9
  %13 = zext i8 %12 to i32
  %14 = and i32 %13, -4
  %15 = trunc i32 %14 to i8
  store i8 %15, ptr %11, align 16, !tbaa !9
  %16 = getelementptr inbounds [56 x i8], ptr %5, i64 0, i64 55
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = zext i8 %17 to i32
  %19 = and i32 %18, 127
  %20 = trunc i32 %19 to i8
  store i8 %20, ptr %16, align 1, !tbaa !9
  %21 = getelementptr inbounds [56 x i8], ptr %5, i64 0, i64 55
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = zext i8 %22 to i32
  %24 = or i32 %23, 128
  %25 = trunc i32 %24 to i8
  store i8 %25, ptr %21, align 1, !tbaa !9
  %26 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %6, i64 0, i64 0
  %27 = getelementptr inbounds [56 x i8], ptr %5, i64 0, i64 0
  call void @ossl_curve448_scalar_decode_long(ptr noundef %26, ptr noundef %27, i64 noundef 56)
  store i32 1, ptr %8, align 4, !tbaa !10
  br label %28

28:                                               ; preds = %34, %2
  %29 = load i32, ptr %8, align 4, !tbaa !10
  %30 = icmp ult i32 %29, 2
  br i1 %30, label %31, label %37

31:                                               ; preds = %28
  %32 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %6, i64 0, i64 0
  %33 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %6, i64 0, i64 0
  call void @ossl_curve448_scalar_halve(ptr noundef %32, ptr noundef %33)
  br label %34

34:                                               ; preds = %31
  %35 = load i32, ptr %8, align 4, !tbaa !10
  %36 = shl i32 %35, 1
  store i32 %36, ptr %8, align 4, !tbaa !10
  br label %28, !llvm.loop !12

37:                                               ; preds = %28
  %38 = getelementptr inbounds [1 x %struct.curve448_point_s], ptr %7, i64 0, i64 0
  %39 = load ptr, ptr @ossl_curve448_precomputed_base, align 8, !tbaa !5
  %40 = getelementptr inbounds [1 x %struct.curve448_scalar_s], ptr %6, i64 0, i64 0
  call void @ossl_curve448_precomputed_scalarmul(ptr noundef %38, ptr noundef %39, ptr noundef %40)
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds [1 x %struct.curve448_point_s], ptr %7, i64 0, i64 0
  call void @ossl_curve448_point_mul_by_ratio_and_encode_like_x448(ptr noundef %41, ptr noundef %42)
  %43 = getelementptr inbounds [1 x %struct.curve448_point_s], ptr %7, i64 0, i64 0
  call void @ossl_curve448_point_destroy(ptr noundef %43)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 256, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 56, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 56, ptr %5) #4
  ret void
}

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

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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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: 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

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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

; Function Attrs: nounwind uwtable
define dso_local void @ossl_x448_derive_public_key(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
.critedge:
  %2 = alloca [56 x i8], align 16
  %3 = alloca [1 x %struct.curve448_scalar_s], align 16
  %4 = alloca [1 x %struct.curve448_point_s], align 16
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(56) %2, ptr noundef nonnull align 1 dereferenceable(56) %1, i64 56, i1 false)
  %5 = load i8, ptr %2, align 16, !tbaa !5
  %6 = and i8 %5, -4
  store i8 %6, ptr %2, align 16, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %2, i64 55
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = or i8 %8, -128
  store i8 %9, ptr %7, align 1, !tbaa !5
  call void @ossl_curve448_scalar_decode_long(ptr noundef nonnull %3, ptr noundef nonnull %2, i64 noundef 56) #4
  call void @ossl_curve448_scalar_halve(ptr noundef nonnull %3, ptr noundef nonnull %3) #4
  %10 = load ptr, ptr @ossl_curve448_precomputed_base, align 8, !tbaa !8
  call void @ossl_curve448_precomputed_scalarmul(ptr noundef nonnull %4, ptr noundef %10, ptr noundef nonnull %3)
  call void @ossl_curve448_point_mul_by_ratio_and_encode_like_x448(ptr noundef %0, ptr noundef nonnull %4)
  call void @ossl_curve448_point_destroy(ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %2) #4
  ret void
}

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

attributes #0 = { mustprogress 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 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}


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