; 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.20 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [32 x i8], align 1
@peacemakr_global_calloc = external global ptr, align 8
@.str.45 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.47 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [41 x i8], align 1
@__FUNCTION__.peacemakr_key_pub_to_pem = external hidden unnamed_addr constant [25 x i8], align 1
@.str.50 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.51 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.52 = external hidden unnamed_addr constant [31 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

; 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) #2

declare ptr @BIO_new(ptr noundef) #0

declare i32 @BIO_free(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @peacemakr_key_pub_to_pem(ptr noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, 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 ptr %2, ptr %7, align 8, !tbaa !5
  %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_pub_to_pem, i32 noundef 900, ptr noundef @.str.45)
  store i1 false, ptr %4, align 1
  br label %84

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_pub_to_pem, i32 noundef 901, ptr noundef @.str.46)
  store i1 false, ptr %4, align 1
  br label %84

18:                                               ; preds = %14
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 903, ptr noundef @.str.47)
  store i1 false, ptr %4, align 1
  br label %84

22:                                               ; preds = %18
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.PeacemakrKey, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.crypto_config_t, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !9
  %27 = icmp ne i32 %26, 1
  br i1 %27, label %28, label %29

28:                                               ; preds = %22
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 906, ptr noundef @.str.48)
  store i1 false, ptr %4, align 1
  br label %84

29:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %30 = call ptr @BIO_s_mem()
  %31 = call ptr @BIO_new(ptr noundef %30)
  store ptr %31, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.PeacemakrKey, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %45

36:                                               ; preds = %29
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.PeacemakrKey, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = call i32 @PEM_write_bio_X509(ptr noundef %37, ptr noundef %40)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %44, label %43

43:                                               ; preds = %36
  call void @openssl_log(ptr noundef @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 915)
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 916, ptr noundef @.str.50)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %83

44:                                               ; preds = %36
  br label %54

45:                                               ; preds = %29
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 920, ptr noundef @.str.51)
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.PeacemakrKey, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !14
  %50 = call i32 @PEM_write_bio_PUBKEY(ptr noundef %46, ptr noundef %49)
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %53, label %52

52:                                               ; preds = %45
  call void @openssl_log(ptr noundef @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 922)
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 923, ptr noundef @.str.52)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %83

53:                                               ; preds = %45
  br label %54

54:                                               ; preds = %53, %44
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = call i64 @BIO_ctrl(ptr noundef %55, i32 noundef 2, i64 noundef 0, ptr noundef null)
  %57 = trunc i64 %56 to i32
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %54
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 929, ptr noundef @.str.20)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %83

60:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store ptr null, ptr %10, align 8, !tbaa !5
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = call i64 @BIO_ctrl(ptr noundef %61, i32 noundef 3, i64 noundef 0, ptr noundef %10)
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %62, ptr %63, align 8, !tbaa !15
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = icmp eq ptr %64, null
  br i1 %65, label %66, label %69

66:                                               ; preds = %60
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = call i32 @BIO_free(ptr noundef %67)
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 936, ptr noundef @.str.21)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %82

69:                                               ; preds = %60
  %70 = load ptr, ptr @peacemakr_global_calloc, align 8, !tbaa !5
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = load i64, ptr %71, align 8, !tbaa !15
  %73 = call ptr %70(i64 noundef %72, i64 noundef 1)
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %73, ptr %74, align 8, !tbaa !5
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = load ptr, ptr %75, align 8, !tbaa !5
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = load i64, ptr %78, align 8, !tbaa !15
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %76, ptr align 1 %77, i64 %79, i1 false)
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = call i32 @BIO_free(ptr noundef %80)
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %82

82:                                               ; preds = %69, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %83

83:                                               ; preds = %82, %59, %52, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %84

84:                                               ; preds = %83, %28, %21, %17, %13
  %85 = load i1, ptr %4, align 1
  ret i1 %85
}

declare ptr @BIO_s_mem() #0

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

declare i32 @PEM_write_bio_PUBKEY(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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !12, i64 0}
!10 = !{!"PeacemakrKey", !11, i64 0, !7, i64 16, !6, i64 24}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 24}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !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.20 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [32 x i8], align 1
@peacemakr_global_calloc = external local_unnamed_addr global ptr, align 8
@.str.45 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.47 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [41 x i8], align 1
@__FUNCTION__.peacemakr_key_pub_to_pem = external hidden unnamed_addr constant [25 x i8], align 1
@.str.50 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.51 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.52 = external hidden unnamed_addr constant [31 x i8], align 1

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

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

; Function Attrs: mustprogress 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) local_unnamed_addr #0

; 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) #2

declare ptr @BIO_new(ptr noundef) local_unnamed_addr #0

declare i32 @BIO_free(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @peacemakr_key_pub_to_pem(ptr noundef readonly %0, ptr noundef writeonly %1, ptr noundef %2) local_unnamed_addr #3 {
  %4 = alloca ptr, align 8
  %5 = icmp eq ptr %0, null
  br i1 %5, label %6, label %7

6:                                                ; preds = %3
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 900, ptr noundef nonnull @.str.45) #4
  br label %46

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

9:                                                ; preds = %7
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 901, ptr noundef nonnull @.str.46) #4
  br label %46

10:                                               ; preds = %7
  %11 = icmp eq ptr %2, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %10
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 903, ptr noundef nonnull @.str.47) #4
  br label %46

13:                                               ; preds = %10
  %14 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %14, 1
  br i1 %.not, label %16, label %15

15:                                               ; preds = %13
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 906, ptr noundef nonnull @.str.48) #4
  br label %46

16:                                               ; preds = %13
  %17 = tail call ptr @BIO_s_mem() #4
  %18 = tail call ptr @BIO_new(ptr noundef %17) #4
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %.not23 = icmp eq ptr %20, null
  br i1 %.not23, label %24, label %21

21:                                               ; preds = %16
  %22 = tail call i32 @PEM_write_bio_X509(ptr noundef %18, ptr noundef nonnull %20) #4
  %.not25 = icmp eq i32 %22, 0
  br i1 %.not25, label %23, label %29

23:                                               ; preds = %21
  tail call void @openssl_log(ptr noundef nonnull @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 915) #4
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 916, ptr noundef nonnull @.str.50) #4
  br label %46

24:                                               ; preds = %16
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 920, ptr noundef nonnull @.str.51) #4
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = tail call i32 @PEM_write_bio_PUBKEY(ptr noundef %18, ptr noundef %26) #4
  %.not24 = icmp eq i32 %27, 0
  br i1 %.not24, label %28, label %29

28:                                               ; preds = %24
  tail call void @openssl_log(ptr noundef nonnull @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 922) #4
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 923, ptr noundef nonnull @.str.52) #4
  br label %46

29:                                               ; preds = %24, %21
  %30 = tail call i64 @BIO_ctrl(ptr noundef %18, i32 noundef 2, i64 noundef 0, ptr noundef null) #4
  %31 = and i64 %30, 4294967295
  %.not26 = icmp eq i64 %31, 0
  br i1 %.not26, label %33, label %32

32:                                               ; preds = %29
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 929, ptr noundef nonnull @.str.20) #4
  br label %46

33:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  store ptr null, ptr %4, align 8, !tbaa !14
  %34 = call i64 @BIO_ctrl(ptr noundef %18, i32 noundef 3, i64 noundef 0, ptr noundef nonnull %4) #4
  store i64 %34, ptr %2, align 8, !tbaa !15
  %35 = load ptr, ptr %4, align 8, !tbaa !14
  %36 = icmp ne ptr %35, null
  br i1 %36, label %39, label %37

37:                                               ; preds = %33
  %38 = call i32 @BIO_free(ptr noundef %18) #4
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_pub_to_pem, i32 noundef 936, ptr noundef nonnull @.str.21) #4
  br label %45

39:                                               ; preds = %33
  %40 = load ptr, ptr @peacemakr_global_calloc, align 8, !tbaa !14
  %41 = call ptr %40(i64 noundef %34, i64 noundef 1) #4
  store ptr %41, ptr %1, align 8, !tbaa !14
  %42 = load ptr, ptr %4, align 8, !tbaa !14
  %43 = load i64, ptr %2, align 8, !tbaa !15
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %41, ptr align 1 %42, i64 %43, i1 false)
  %44 = call i32 @BIO_free(ptr noundef %18) #4
  br label %45

45:                                               ; preds = %39, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  br label %46

46:                                               ; preds = %23, %28, %32, %45, %15, %12, %9, %6
  %.2 = phi i1 [ false, %6 ], [ false, %9 ], [ false, %12 ], [ false, %15 ], [ false, %32 ], [ %36, %45 ], [ false, %23 ], [ false, %28 ]
  ret i1 %.2
}

declare ptr @BIO_s_mem() local_unnamed_addr #0

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

declare i32 @PEM_write_bio_PUBKEY(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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !8, i64 0}
!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}
!12 = !{!6, !11, i64 24}
!13 = !{!9, !9, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !9, i64 0}


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