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

; 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.ge_p3 = type { [10 x i32], [10 x i32], [10 x i32], [10 x i32] }

@.str = external hidden unnamed_addr constant [7 x i8], align 1

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

declare ptr @EVP_MD_fetch(ptr noundef, ptr noundef, ptr noundef) #1

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

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

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

declare void @EVP_MD_free(ptr noundef) #1

; 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
define dso_local i32 @ossl_ed25519_public_from_private(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %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 [64 x i8], align 16
  %11 = alloca %struct.ge_p3, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %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 64, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 160, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store ptr null, ptr %13, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = call ptr @EVP_MD_fetch(ptr noundef %15, ptr noundef @.str, ptr noundef %16)
  store ptr %17, ptr %13, align 8, !tbaa !5
  %18 = load ptr, ptr %13, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

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

21:                                               ; preds = %4
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  %24 = load ptr, ptr %13, align 8, !tbaa !5
  %25 = call i32 @EVP_Digest(ptr noundef %22, i64 noundef 32, ptr noundef %23, ptr noundef null, ptr noundef %24, ptr noundef null)
  store i32 %25, ptr %12, align 4, !tbaa !9
  %26 = load ptr, ptr %13, align 8, !tbaa !5
  call void @EVP_MD_free(ptr noundef %26)
  %27 = load i32, ptr %12, align 4, !tbaa !9
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %31, label %29

29:                                               ; preds = %21
  %30 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  call void @OPENSSL_cleanse(ptr noundef %30, i64 noundef 64)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %50

31:                                               ; preds = %21
  %32 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  %33 = load i8, ptr %32, align 16, !tbaa !11
  %34 = zext i8 %33 to i32
  %35 = and i32 %34, 248
  %36 = trunc i32 %35 to i8
  store i8 %36, ptr %32, align 16, !tbaa !11
  %37 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 31
  %38 = load i8, ptr %37, align 1, !tbaa !11
  %39 = zext i8 %38 to i32
  %40 = and i32 %39, 63
  %41 = trunc i32 %40 to i8
  store i8 %41, ptr %37, align 1, !tbaa !11
  %42 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 31
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = zext i8 %43 to i32
  %45 = or i32 %44, 64
  %46 = trunc i32 %45 to i8
  store i8 %46, ptr %42, align 1, !tbaa !11
  %47 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  call void @ge_scalarmult_base(ptr noundef %11, ptr noundef %47)
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ge_p3_tobytes(ptr noundef %48, ptr noundef %11)
  %49 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  call void @OPENSSL_cleanse(ptr noundef %49, i64 noundef 64)
  store i32 1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %50

50:                                               ; preds = %31, %29, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 160, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr %10) #3
  %51 = load i32, ptr %5, align 4
  ret i32 %51
}

declare i32 @EVP_Digest(ptr noundef, i64 noundef, ptr noundef, ptr noundef, 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}


; 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.ge_p3 = type { [10 x i32], [10 x i32], [10 x i32], [10 x i32] }

@.str = external hidden unnamed_addr constant [7 x i8], align 1

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

declare ptr @EVP_MD_fetch(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

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

declare void @EVP_MD_free(ptr noundef) local_unnamed_addr #1

; 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
define dso_local range(i32 0, 2) i32 @ossl_ed25519_public_from_private(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = alloca [64 x i8], align 16
  %6 = alloca %struct.ge_p3, align 4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %6) #3
  %7 = tail call ptr @EVP_MD_fetch(ptr noundef %0, ptr noundef nonnull @.str, ptr noundef %3) #3
  %8 = icmp eq ptr %7, null
  br i1 %8, label %18, label %9

9:                                                ; preds = %4
  %10 = call i32 @EVP_Digest(ptr noundef %2, i64 noundef 32, ptr noundef nonnull %5, ptr noundef null, ptr noundef nonnull %7, ptr noundef null) #3
  call void @EVP_MD_free(ptr noundef nonnull %7) #3
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %.sink.split, label %11

11:                                               ; preds = %9
  %12 = load i8, ptr %5, align 16, !tbaa !5
  %13 = and i8 %12, -8
  store i8 %13, ptr %5, align 16, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %5, i64 31
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = and i8 %15, 63
  %17 = or disjoint i8 %16, 64
  store i8 %17, ptr %14, align 1, !tbaa !5
  call void @ge_scalarmult_base(ptr noundef nonnull %6, ptr noundef nonnull %5)
  call void @ge_p3_tobytes(ptr noundef %1, ptr noundef nonnull %6)
  br label %.sink.split

.sink.split:                                      ; preds = %9, %11
  %.0.ph = phi i32 [ 1, %11 ], [ 0, %9 ]
  call void @OPENSSL_cleanse(ptr noundef nonnull %5, i64 noundef 64) #3
  br label %18

18:                                               ; preds = %.sink.split, %4
  %.0 = phi i32 [ 0, %4 ], [ %.0.ph, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %5) #3
  ret i32 %.0
}

declare i32 @EVP_Digest(ptr noundef, i64 noundef, ptr noundef, ptr noundef, 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"}


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