; LLVM IR from VivyTeam/krypt-ios :: Krypt/Source (x509)

; 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"

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

; Function Attrs: nounwind uwtable
define dso_local ptr @x509_wrap_pubkey(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store ptr null, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store ptr null, ptr %12, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call ptr @BIO_from_str(ptr noundef %15)
  store ptr %16, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = call ptr @PEM_read_bio_PrivateKey(ptr noundef %17, ptr noundef null, ptr noundef null, ptr noundef null)
  store ptr %18, ptr %9, align 8, !tbaa !5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call ptr @BIO_from_str(ptr noundef %19)
  store ptr %20, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = call ptr @PEM_read_bio_PUBKEY(ptr noundef %21, ptr noundef null, ptr noundef null, ptr noundef null)
  store ptr %22, ptr %10, align 8, !tbaa !5
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = icmp eq ptr %23, null
  br i1 %24, label %28, label %25

25:                                               ; preds = %2
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %35

28:                                               ; preds = %25, %2
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  call void @x509_wrap_pubkey_free_all(ptr noundef %29, ptr noundef %30, ptr noundef %31, ptr noundef %32, ptr noundef %33, ptr noundef %34)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %90

35:                                               ; preds = %25
  %36 = call ptr @X509_new()
  store ptr %36, ptr %11, align 8, !tbaa !5
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = call ptr @X509_get_serialNumber(ptr noundef %37)
  %39 = call i32 @ASN1_INTEGER_set(ptr noundef %38, i64 noundef 1)
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = call ptr @X509_getm_notBefore(ptr noundef %40)
  %42 = call ptr @X509_gmtime_adj(ptr noundef %41, i64 noundef 0)
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = call ptr @X509_getm_notAfter(ptr noundef %43)
  %45 = call ptr @X509_gmtime_adj(ptr noundef %44, i64 noundef 31536000)
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = call i32 @X509_set_pubkey(ptr noundef %46, ptr noundef %47)
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = call ptr @X509_get_subject_name(ptr noundef %49)
  store ptr %50, ptr %12, align 8, !tbaa !5
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  %52 = call i32 @X509_NAME_add_entry_by_txt(ptr noundef %51, ptr noundef @.str, i32 noundef 4097, ptr noundef @.str.1, i32 noundef -1, i32 noundef -1, i32 noundef 0)
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = call i32 @X509_NAME_add_entry_by_txt(ptr noundef %53, ptr noundef @.str.2, i32 noundef 4097, ptr noundef @.str.1, i32 noundef -1, i32 noundef -1, i32 noundef 0)
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = call i32 @X509_NAME_add_entry_by_txt(ptr noundef %55, ptr noundef @.str.3, i32 noundef 4097, ptr noundef @.str.1, i32 noundef -1, i32 noundef -1, i32 noundef 0)
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = call i32 @X509_set_issuer_name(ptr noundef %57, ptr noundef %58)
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = call ptr @EVP_sha1()
  %63 = call i32 @X509_sign(ptr noundef %60, ptr noundef %61, ptr noundef %62)
  %64 = call ptr @BIO_s_mem()
  %65 = call ptr @BIO_new(ptr noundef %64)
  store ptr %65, ptr %8, align 8, !tbaa !5
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = call i64 @BIO_ctrl(ptr noundef %66, i32 noundef 130, i64 noundef 0, ptr noundef null)
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = call i32 @PEM_write_bio_X509(ptr noundef %68, ptr noundef %69)
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = icmp eq ptr %71, null
  br i1 %72, label %73, label %80

73:                                               ; preds = %35
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  call void @x509_wrap_pubkey_free_all(ptr noundef %74, ptr noundef %75, ptr noundef %76, ptr noundef %77, ptr noundef %78, ptr noundef %79)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %90

80:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  %82 = call ptr @str_from_BIO(ptr noundef %81)
  store ptr %82, ptr %14, align 8, !tbaa !5
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  %86 = load ptr, ptr %9, align 8, !tbaa !5
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  %88 = load ptr, ptr %11, align 8, !tbaa !5
  call void @x509_wrap_pubkey_free_all(ptr noundef %83, ptr noundef %84, ptr noundef %85, ptr noundef %86, ptr noundef %87, ptr noundef %88)
  %89 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %89, ptr %3, align 8
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %90

90:                                               ; preds = %80, %73, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %91 = load ptr, ptr %3, align 8
  ret ptr %91
}

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

declare ptr @BIO_from_str(ptr noundef) #2

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

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

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

declare ptr @X509_new() #2

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

declare ptr @X509_get_serialNumber(ptr noundef) #2

declare ptr @X509_gmtime_adj(ptr noundef, i64 noundef) #2

declare ptr @X509_getm_notBefore(ptr noundef) #2

declare ptr @X509_getm_notAfter(ptr noundef) #2

declare i32 @X509_set_pubkey(ptr noundef, ptr noundef) #2

declare ptr @X509_get_subject_name(ptr noundef) #2

declare i32 @X509_NAME_add_entry_by_txt(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) #2

declare i32 @X509_set_issuer_name(ptr noundef, ptr noundef) #2

declare i32 @X509_sign(ptr noundef, ptr noundef, ptr noundef) #2

declare ptr @EVP_sha1() #2

declare ptr @BIO_new(ptr noundef) #2

declare ptr @BIO_s_mem() #2

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

declare i32 @PEM_write_bio_X509(ptr noundef, ptr noundef) #2

declare ptr @str_from_BIO(ptr 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"}


; 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"

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

; Function Attrs: nounwind uwtable
define dso_local ptr @x509_wrap_pubkey(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @BIO_from_str(ptr noundef %0) #2
  %4 = tail call ptr @PEM_read_bio_PrivateKey(ptr noundef %3, ptr noundef null, ptr noundef null, ptr noundef null) #2
  %5 = tail call ptr @BIO_from_str(ptr noundef %1) #2
  %6 = tail call ptr @PEM_read_bio_PUBKEY(ptr noundef %5, ptr noundef null, ptr noundef null, ptr noundef null) #2
  %7 = icmp eq ptr %4, null
  %8 = icmp eq ptr %6, null
  %or.cond = select i1 %7, i1 true, i1 %8
  br i1 %or.cond, label %9, label %10

9:                                                ; preds = %2
  tail call void @x509_wrap_pubkey_free_all(ptr noundef %3, ptr noundef %5, ptr noundef null, ptr noundef %4, ptr noundef %6, ptr noundef null)
  br label %34

10:                                               ; preds = %2
  %11 = tail call ptr @X509_new() #2
  %12 = tail call ptr @X509_get_serialNumber(ptr noundef %11) #2
  %13 = tail call i32 @ASN1_INTEGER_set(ptr noundef %12, i64 noundef 1) #2
  %14 = tail call ptr @X509_getm_notBefore(ptr noundef %11) #2
  %15 = tail call ptr @X509_gmtime_adj(ptr noundef %14, i64 noundef 0) #2
  %16 = tail call ptr @X509_getm_notAfter(ptr noundef %11) #2
  %17 = tail call ptr @X509_gmtime_adj(ptr noundef %16, i64 noundef 31536000) #2
  %18 = tail call i32 @X509_set_pubkey(ptr noundef %11, ptr noundef nonnull %6) #2
  %19 = tail call ptr @X509_get_subject_name(ptr noundef %11) #2
  %20 = tail call i32 @X509_NAME_add_entry_by_txt(ptr noundef %19, ptr noundef nonnull @.str, i32 noundef 4097, ptr noundef nonnull @.str.1, i32 noundef -1, i32 noundef -1, i32 noundef 0) #2
  %21 = tail call i32 @X509_NAME_add_entry_by_txt(ptr noundef %19, ptr noundef nonnull @.str.2, i32 noundef 4097, ptr noundef nonnull @.str.1, i32 noundef -1, i32 noundef -1, i32 noundef 0) #2
  %22 = tail call i32 @X509_NAME_add_entry_by_txt(ptr noundef %19, ptr noundef nonnull @.str.3, i32 noundef 4097, ptr noundef nonnull @.str.1, i32 noundef -1, i32 noundef -1, i32 noundef 0) #2
  %23 = tail call i32 @X509_set_issuer_name(ptr noundef %11, ptr noundef %19) #2
  %24 = tail call ptr @EVP_sha1() #2
  %25 = tail call i32 @X509_sign(ptr noundef %11, ptr noundef nonnull %4, ptr noundef %24) #2
  %26 = tail call ptr @BIO_s_mem() #2
  %27 = tail call ptr @BIO_new(ptr noundef %26) #2
  %28 = tail call i64 @BIO_ctrl(ptr noundef %27, i32 noundef 130, i64 noundef 0, ptr noundef null) #2
  %29 = tail call i32 @PEM_write_bio_X509(ptr noundef %27, ptr noundef %11) #2
  %30 = icmp eq ptr %27, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %10
  tail call void @x509_wrap_pubkey_free_all(ptr noundef %3, ptr noundef %5, ptr noundef null, ptr noundef nonnull %4, ptr noundef nonnull %6, ptr noundef %11)
  br label %34

32:                                               ; preds = %10
  %33 = tail call ptr @str_from_BIO(ptr noundef nonnull %27) #2
  tail call void @x509_wrap_pubkey_free_all(ptr noundef %3, ptr noundef %5, ptr noundef nonnull %27, ptr noundef nonnull %4, ptr noundef nonnull %6, ptr noundef %11)
  br label %34

34:                                               ; preds = %32, %31, %9
  %.0 = phi ptr [ null, %9 ], [ null, %31 ], [ %33, %32 ]
  ret ptr %.0
}

declare ptr @BIO_from_str(ptr noundef) local_unnamed_addr #1

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

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

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

declare ptr @X509_new() local_unnamed_addr #1

declare i32 @ASN1_INTEGER_set(ptr noundef, i64 noundef) local_unnamed_addr #1

declare ptr @X509_get_serialNumber(ptr noundef) local_unnamed_addr #1

declare ptr @X509_gmtime_adj(ptr noundef, i64 noundef) local_unnamed_addr #1

declare ptr @X509_getm_notBefore(ptr noundef) local_unnamed_addr #1

declare ptr @X509_getm_notAfter(ptr noundef) local_unnamed_addr #1

declare i32 @X509_set_pubkey(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @X509_get_subject_name(ptr noundef) local_unnamed_addr #1

declare i32 @X509_NAME_add_entry_by_txt(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @X509_set_issuer_name(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @X509_sign(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @EVP_sha1() local_unnamed_addr #1

declare ptr @BIO_new(ptr noundef) local_unnamed_addr #1

declare ptr @BIO_s_mem() local_unnamed_addr #1

declare i64 @BIO_ctrl(ptr noundef, i32 noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @PEM_write_bio_X509(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @str_from_BIO(ptr 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 = { "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 }

!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)"}


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