; LLVM IR from peacemakr-io/peacemakr-core-crypto :: src/core/src (Key)

; 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.PeacemakrKey = type { %struct.crypto_config_t, %union.anon, ptr }
%struct.crypto_config_t = type { i32, i32, i32, i32 }
%union.anon = type { ptr }

@.str.15 = external hidden unnamed_addr constant [22 x i8], align 1
@__FUNCTION__.peacemakr_key_add_certificate = external hidden unnamed_addr constant [30 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [43 x i8], align 1

declare void @log_printf(ptr noundef, i32 noundef, ptr noundef, ...) #0

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

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

declare void @openssl_log(ptr noundef, i32 noundef) #0

declare i32 @BIO_free(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @peacemakr_key_add_certificate(ptr noundef %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_key_add_certificate, i32 noundef 490, ptr noundef @.str.15)
  store i1 false, ptr %4, align 1
  br label %44

14:                                               ; preds = %3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_key_add_certificate, i32 noundef 491, ptr noundef @.str.23)
  store i1 false, ptr %4, align 1
  br label %44

18:                                               ; preds = %14
  %19 = load i64, ptr %7, align 8, !tbaa !9
  %20 = icmp ugt i64 %19, 2147483647
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_key_add_certificate, i32 noundef 493, ptr noundef @.str.24)
  store i1 false, ptr %4, align 1
  br label %44

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = trunc i64 %24 to i32
  %26 = call ptr @BIO_new_mem_buf(ptr noundef %23, i32 noundef %25)
  store ptr %26, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %30

29:                                               ; preds = %22
  call void @openssl_log(ptr noundef @__FUNCTION__.peacemakr_key_add_certificate, i32 noundef 499)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %43

30:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = call ptr @PEM_read_bio_X509(ptr noundef %31, ptr noundef null, ptr noundef null, ptr noundef null)
  store ptr %32, ptr %10, align 8, !tbaa !5
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %38

35:                                               ; preds = %30
  call void @openssl_log(ptr noundef @__FUNCTION__.peacemakr_key_add_certificate, i32 noundef 505)
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = call i32 @BIO_free(ptr noundef %36)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %42

38:                                               ; preds = %30
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.PeacemakrKey, ptr %40, i32 0, i32 2
  store ptr %39, ptr %41, align 8, !tbaa !11
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %42

42:                                               ; preds = %38, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %43

43:                                               ; preds = %42, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %44

44:                                               ; preds = %43, %21, %17, %13
  %45 = load i1, ptr %4, align 1
  ret i1 %45
}

declare ptr @BIO_new_mem_buf(ptr noundef, i32 noundef) #0

declare ptr @PEM_read_bio_X509(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

attributes #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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"PeacemakrKey", !13, i64 0, !7, i64 16, !6, i64 24}
!13 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12}
!14 = !{!"int", !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"

@.str.15 = external hidden unnamed_addr constant [22 x i8], align 1
@__FUNCTION__.peacemakr_key_add_certificate = external hidden unnamed_addr constant [30 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [43 x i8], align 1

declare void @log_printf(ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

declare void @openssl_log(ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @BIO_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @peacemakr_key_add_certificate(ptr noundef writeonly %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %5, label %6

5:                                                ; preds = %3
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_add_certificate, i32 noundef 490, ptr noundef nonnull @.str.15) #2
  br label %23

6:                                                ; preds = %3
  %7 = icmp eq ptr %1, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %6
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_add_certificate, i32 noundef 491, ptr noundef nonnull @.str.23) #2
  br label %23

9:                                                ; preds = %6
  %10 = icmp ugt i64 %2, 2147483647
  br i1 %10, label %11, label %12

11:                                               ; preds = %9
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_add_certificate, i32 noundef 493, ptr noundef nonnull @.str.24) #2
  br label %23

12:                                               ; preds = %9
  %13 = trunc nuw nsw i64 %2 to i32
  %14 = tail call ptr @BIO_new_mem_buf(ptr noundef nonnull %1, i32 noundef %13) #2
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %12
  tail call void @openssl_log(ptr noundef nonnull @__FUNCTION__.peacemakr_key_add_certificate, i32 noundef 499) #2
  br label %23

17:                                               ; preds = %12
  %18 = tail call ptr @PEM_read_bio_X509(ptr noundef nonnull %14, ptr noundef null, ptr noundef null, ptr noundef null) #2
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %19, label %21

19:                                               ; preds = %17
  tail call void @openssl_log(ptr noundef nonnull @__FUNCTION__.peacemakr_key_add_certificate, i32 noundef 505) #2
  %20 = tail call i32 @BIO_free(ptr noundef nonnull %14) #2
  br label %23

21:                                               ; preds = %17
  %22 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %18, ptr %22, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %16, %21, %19, %11, %8, %5
  %.2 = phi i1 [ false, %5 ], [ false, %8 ], [ false, %11 ], [ false, %16 ], [ true, %21 ], [ false, %19 ]
  ret i1 %.2
}

declare ptr @BIO_new_mem_buf(ptr noundef, i32 noundef) local_unnamed_addr #0

declare ptr @PEM_read_bio_X509(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 = { 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, !11, i64 24}
!6 = !{!"PeacemakrKey", !7, i64 0, !9, i64 16, !11, i64 24}
!7 = !{!"", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}


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