; LLVM IR from openssl/openssl :: crypto/dh (dh_kdf)

; 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.ossl_param_st = type { ptr, i32, ptr, i64, i64 }

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

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_dh_kdf_X9_42_asn1(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, ptr noundef %8, ptr noundef %9) #0 {
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i64, align 8
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  %21 = alloca ptr, align 8
  %22 = alloca i32, align 4
  %23 = alloca ptr, align 8
  %24 = alloca ptr, align 8
  %25 = alloca [5 x %struct.ossl_param_st], align 16
  %26 = alloca ptr, align 8
  %27 = alloca ptr, align 8
  %28 = alloca i32, align 4
  %29 = alloca %struct.ossl_param_st, align 8
  %30 = alloca %struct.ossl_param_st, align 8
  %31 = alloca %struct.ossl_param_st, align 8
  %32 = alloca %struct.ossl_param_st, align 8
  %33 = alloca %struct.ossl_param_st, align 8
  store ptr %0, ptr %12, align 8, !tbaa !5
  store i64 %1, ptr %13, align 8, !tbaa !9
  store ptr %2, ptr %14, align 8, !tbaa !5
  store i64 %3, ptr %15, align 8, !tbaa !9
  store ptr %4, ptr %16, align 8, !tbaa !5
  store ptr %5, ptr %17, align 8, !tbaa !5
  store i64 %6, ptr %18, align 8, !tbaa !9
  store ptr %7, ptr %19, align 8, !tbaa !5
  store ptr %8, ptr %20, align 8, !tbaa !5
  store ptr %9, ptr %21, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #4
  store i32 0, ptr %22, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #4
  store ptr null, ptr %23, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #4
  store ptr null, ptr %24, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 200, ptr %25) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %26) #4
  %34 = getelementptr inbounds [5 x %struct.ossl_param_st], ptr %25, i64 0, i64 0
  store ptr %34, ptr %26, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %27) #4
  %35 = load ptr, ptr %19, align 8, !tbaa !5
  %36 = call ptr @EVP_MD_get0_name(ptr noundef %35)
  store ptr %36, ptr %27, align 8, !tbaa !5
  %37 = load ptr, ptr %20, align 8, !tbaa !5
  %38 = load ptr, ptr %21, align 8, !tbaa !5
  %39 = call ptr @EVP_KDF_fetch(ptr noundef %37, ptr noundef @.str, ptr noundef %38)
  store ptr %39, ptr %24, align 8, !tbaa !5
  %40 = load ptr, ptr %24, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %43

42:                                               ; preds = %10
  store i32 0, ptr %11, align 4
  store i32 1, ptr %28, align 4
  br label %80

43:                                               ; preds = %10
  %44 = load ptr, ptr %24, align 8, !tbaa !5
  %45 = call ptr @EVP_KDF_CTX_new(ptr noundef %44)
  store ptr %45, ptr %23, align 8, !tbaa !5
  %46 = load ptr, ptr %23, align 8, !tbaa !5
  %47 = icmp eq ptr %46, null
  br i1 %47, label %48, label %49

48:                                               ; preds = %43
  br label %76

49:                                               ; preds = %43
  %50 = load ptr, ptr %26, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ossl_param_st, ptr %50, i32 1
  store ptr %51, ptr %26, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %29) #4
  %52 = load ptr, ptr %27, align 8, !tbaa !5
  call void @OSSL_PARAM_construct_utf8_string(ptr dead_on_unwind writable sret(%struct.ossl_param_st) align 8 %29, ptr noundef @.str.1, ptr noundef %52, i64 noundef 0)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %50, ptr align 8 %29, i64 40, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 40, ptr %29) #4
  %53 = load ptr, ptr %26, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ossl_param_st, ptr %53, i32 1
  store ptr %54, ptr %26, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %30) #4
  %55 = load ptr, ptr %14, align 8, !tbaa !5
  %56 = load i64, ptr %15, align 8, !tbaa !9
  call void @OSSL_PARAM_construct_octet_string(ptr dead_on_unwind writable sret(%struct.ossl_param_st) align 8 %30, ptr noundef @.str.2, ptr noundef %55, i64 noundef %56)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %53, ptr align 8 %30, i64 40, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 40, ptr %30) #4
  %57 = load ptr, ptr %17, align 8, !tbaa !5
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %64

59:                                               ; preds = %49
  %60 = load ptr, ptr %26, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ossl_param_st, ptr %60, i32 1
  store ptr %61, ptr %26, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %31) #4
  %62 = load ptr, ptr %17, align 8, !tbaa !5
  %63 = load i64, ptr %18, align 8, !tbaa !9
  call void @OSSL_PARAM_construct_octet_string(ptr dead_on_unwind writable sret(%struct.ossl_param_st) align 8 %31, ptr noundef @.str.3, ptr noundef %62, i64 noundef %63)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %60, ptr align 8 %31, i64 40, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 40, ptr %31) #4
  br label %64

64:                                               ; preds = %59, %49
  %65 = load ptr, ptr %26, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ossl_param_st, ptr %65, i32 1
  store ptr %66, ptr %26, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %32) #4
  %67 = load ptr, ptr %16, align 8, !tbaa !5
  call void @OSSL_PARAM_construct_utf8_string(ptr dead_on_unwind writable sret(%struct.ossl_param_st) align 8 %32, ptr noundef @.str.4, ptr noundef %67, i64 noundef 0)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %65, ptr align 8 %32, i64 40, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 40, ptr %32) #4
  %68 = load ptr, ptr %26, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %33) #4
  call void @OSSL_PARAM_construct_end(ptr dead_on_unwind writable sret(%struct.ossl_param_st) align 8 %33)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %68, ptr align 8 %33, i64 40, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 40, ptr %33) #4
  %69 = load ptr, ptr %23, align 8, !tbaa !5
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = load i64, ptr %13, align 8, !tbaa !9
  %72 = getelementptr inbounds [5 x %struct.ossl_param_st], ptr %25, i64 0, i64 0
  %73 = call i32 @EVP_KDF_derive(ptr noundef %69, ptr noundef %70, i64 noundef %71, ptr noundef %72)
  %74 = icmp sgt i32 %73, 0
  %75 = zext i1 %74 to i32
  store i32 %75, ptr %22, align 4, !tbaa !11
  br label %76

76:                                               ; preds = %64, %48
  %77 = load ptr, ptr %23, align 8, !tbaa !5
  call void @EVP_KDF_CTX_free(ptr noundef %77)
  %78 = load ptr, ptr %24, align 8, !tbaa !5
  call void @EVP_KDF_free(ptr noundef %78)
  %79 = load i32, ptr %22, align 4, !tbaa !11
  store i32 %79, ptr %11, align 4
  store i32 1, ptr %28, align 4
  br label %80

80:                                               ; preds = %76, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %26) #4
  call void @llvm.lifetime.end.p0(i64 200, ptr %25) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #4
  %81 = load i32, ptr %11, align 4
  ret i32 %81
}

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

declare ptr @EVP_MD_get0_name(ptr noundef) #2

declare ptr @EVP_KDF_fetch(ptr noundef, ptr noundef, ptr noundef) #2

declare ptr @EVP_KDF_CTX_new(ptr noundef) #2

declare void @OSSL_PARAM_construct_utf8_string(ptr dead_on_unwind writable sret(%struct.ossl_param_st) align 8, ptr noundef, ptr noundef, i64 noundef) #2

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare void @OSSL_PARAM_construct_octet_string(ptr dead_on_unwind writable sret(%struct.ossl_param_st) align 8, ptr noundef, ptr noundef, i64 noundef) #2

declare void @OSSL_PARAM_construct_end(ptr dead_on_unwind writable sret(%struct.ossl_param_st) align 8) #2

declare i32 @EVP_KDF_derive(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #2

declare void @EVP_KDF_CTX_free(ptr noundef) #2

declare void @EVP_KDF_free(ptr 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 = { "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 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{i64 0, i64 8, !5, i64 8, i64 4, !11, i64 16, i64 8, !5, i64 24, i64 8, !9, i64 32, i64 8, !9}


; 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.ossl_param_st = type { ptr, i32, ptr, i64, i64 }

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ossl_dh_kdf_X9_42_asn1(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, ptr noundef %8, ptr noundef %9) local_unnamed_addr #0 {
  %11 = alloca [5 x %struct.ossl_param_st], align 16
  %12 = alloca %struct.ossl_param_st, align 8
  %13 = alloca %struct.ossl_param_st, align 8
  %14 = alloca %struct.ossl_param_st, align 8
  %15 = alloca %struct.ossl_param_st, align 8
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %11) #4
  %16 = tail call ptr @EVP_MD_get0_name(ptr noundef %7) #4
  %17 = tail call ptr @EVP_KDF_fetch(ptr noundef %8, ptr noundef nonnull @.str, ptr noundef %9) #4
  %18 = icmp eq ptr %17, null
  br i1 %18, label %33, label %19

19:                                               ; preds = %10
  %20 = tail call ptr @EVP_KDF_CTX_new(ptr noundef nonnull %17) #4
  %21 = icmp eq ptr %20, null
  br i1 %21, label %32, label %22

22:                                               ; preds = %19
  %23 = getelementptr inbounds i8, ptr %11, i64 40
  call void @OSSL_PARAM_construct_utf8_string(ptr dead_on_unwind nonnull writable sret(%struct.ossl_param_st) align 8 %11, ptr noundef nonnull @.str.1, ptr noundef %16, i64 noundef 0) #4
  %24 = getelementptr inbounds i8, ptr %11, i64 80
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %12) #4
  call void @OSSL_PARAM_construct_octet_string(ptr dead_on_unwind nonnull writable sret(%struct.ossl_param_st) align 8 %12, ptr noundef nonnull @.str.2, ptr noundef %2, i64 noundef %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %23, ptr noundef nonnull align 8 dereferenceable(40) %12, i64 40, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %12) #4
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %27, label %25

25:                                               ; preds = %22
  %26 = getelementptr inbounds i8, ptr %11, i64 120
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %13) #4
  call void @OSSL_PARAM_construct_octet_string(ptr dead_on_unwind nonnull writable sret(%struct.ossl_param_st) align 8 %13, ptr noundef nonnull @.str.3, ptr noundef nonnull %5, i64 noundef %6) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %24, ptr noundef nonnull align 8 dereferenceable(40) %13, i64 40, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %13) #4
  br label %27

27:                                               ; preds = %25, %22
  %.024 = phi ptr [ %26, %25 ], [ %24, %22 ]
  %28 = getelementptr inbounds i8, ptr %.024, i64 40
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %14) #4
  call void @OSSL_PARAM_construct_utf8_string(ptr dead_on_unwind nonnull writable sret(%struct.ossl_param_st) align 8 %14, ptr noundef nonnull @.str.4, ptr noundef %4, i64 noundef 0) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %.024, ptr noundef nonnull align 8 dereferenceable(40) %14, i64 40, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %14) #4
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %15) #4
  call void @OSSL_PARAM_construct_end(ptr dead_on_unwind nonnull writable sret(%struct.ossl_param_st) align 8 %15) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %28, ptr noundef nonnull align 8 dereferenceable(40) %15, i64 40, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %15) #4
  %29 = call i32 @EVP_KDF_derive(ptr noundef nonnull %20, ptr noundef %0, i64 noundef %1, ptr noundef nonnull %11) #4
  %30 = icmp sgt i32 %29, 0
  %31 = zext i1 %30 to i32
  br label %32

32:                                               ; preds = %19, %27
  %.025 = phi i32 [ 0, %19 ], [ %31, %27 ]
  call void @EVP_KDF_CTX_free(ptr noundef %20) #4
  call void @EVP_KDF_free(ptr noundef nonnull %17) #4
  br label %33

33:                                               ; preds = %10, %32
  %.0 = phi i32 [ %.025, %32 ], [ 0, %10 ]
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %11) #4
  ret i32 %.0
}

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

declare ptr @EVP_MD_get0_name(ptr noundef) local_unnamed_addr #2

declare ptr @EVP_KDF_fetch(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @EVP_KDF_CTX_new(ptr noundef) local_unnamed_addr #2

declare void @OSSL_PARAM_construct_utf8_string(ptr dead_on_unwind writable sret(%struct.ossl_param_st) align 8, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare void @OSSL_PARAM_construct_octet_string(ptr dead_on_unwind writable sret(%struct.ossl_param_st) align 8, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @OSSL_PARAM_construct_end(ptr dead_on_unwind writable sret(%struct.ossl_param_st) align 8) local_unnamed_addr #2

declare i32 @EVP_KDF_derive(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

declare void @EVP_KDF_CTX_free(ptr noundef) local_unnamed_addr #2

declare void @EVP_KDF_free(ptr noundef) local_unnamed_addr #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 = { 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 = { 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 = !{i64 0, i64 8, !6, i64 8, i64 4, !10, i64 16, i64 8, !6, i64 24, i64 8, !12, i64 32, i64 8, !12}
!6 = !{!7, !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !8, i64 0}


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