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

@peacemakr_global_malloc = external global ptr, align 8
@__FUNCTION__.peacemakr_key_new_bytes = external hidden unnamed_addr constant [24 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [16 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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @parse_cipher(i32 noundef) #2

declare i32 @EVP_CIPHER_get_key_length(ptr noundef) #0

declare ptr @buffer_new(i64 noundef) #0

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

14:                                               ; preds = %3
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_key_new_bytes, i32 noundef 264, ptr noundef @.str.6)
  store ptr null, ptr %4, align 8
  br label %67

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = call ptr @parse_cipher(i32 noundef %16)
  store ptr %17, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %18 = load ptr, ptr %8, align 8, !tbaa !9
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %29

20:                                               ; preds = %15
  %21 = load ptr, ptr %8, align 8, !tbaa !9
  %22 = call i32 @EVP_CIPHER_get_key_length(ptr noundef %21)
  %23 = sext i32 %22 to i64
  store i64 %23, ptr %9, align 8, !tbaa !11
  %24 = load i64, ptr %7, align 8, !tbaa !11
  %25 = load i64, ptr %9, align 8, !tbaa !11
  %26 = icmp uge i64 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %20
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_key_new_bytes, i32 noundef 271, ptr noundef @.str.7)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %66

28:                                               ; preds = %20
  br label %31

29:                                               ; preds = %15
  %30 = load i64, ptr %7, align 8, !tbaa !11
  store i64 %30, ptr %9, align 8, !tbaa !11
  br label %31

31:                                               ; preds = %29, %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %32 = load ptr, ptr @peacemakr_global_malloc, align 8, !tbaa !9
  %33 = call ptr %32(i64 noundef 32)
  store ptr %33, ptr %11, align 8, !tbaa !9
  %34 = load ptr, ptr %11, align 8, !tbaa !9
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %37

36:                                               ; preds = %31
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_key_new_bytes, i32 noundef 277, ptr noundef @.str.8)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %65

37:                                               ; preds = %31
  %38 = load ptr, ptr %11, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.PeacemakrKey, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds %struct.crypto_config_t, ptr %39, i32 0, i32 0
  store i32 0, ptr %40, align 8, !tbaa !13
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = load ptr, ptr %11, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.PeacemakrKey, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds %struct.crypto_config_t, ptr %43, i32 0, i32 1
  store i32 %41, ptr %44, align 4, !tbaa !16
  %45 = load ptr, ptr %11, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.PeacemakrKey, ptr %45, i32 0, i32 0
  %47 = getelementptr inbounds %struct.crypto_config_t, ptr %46, i32 0, i32 2
  store i32 0, ptr %47, align 8, !tbaa !17
  %48 = load ptr, ptr %11, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.PeacemakrKey, ptr %48, i32 0, i32 0
  %50 = getelementptr inbounds %struct.crypto_config_t, ptr %49, i32 0, i32 3
  store i32 0, ptr %50, align 4, !tbaa !18
  %51 = load ptr, ptr %11, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.PeacemakrKey, ptr %51, i32 0, i32 1
  store ptr null, ptr %52, align 8, !tbaa !19
  %53 = load ptr, ptr %11, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.PeacemakrKey, ptr %53, i32 0, i32 2
  store ptr null, ptr %54, align 8, !tbaa !20
  %55 = load i64, ptr %9, align 8, !tbaa !11
  %56 = call ptr @buffer_new(i64 noundef %55)
  %57 = load ptr, ptr %11, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.PeacemakrKey, ptr %57, i32 0, i32 1
  store ptr %56, ptr %58, align 8, !tbaa !19
  %59 = load ptr, ptr %11, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.PeacemakrKey, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !19
  %62 = load ptr, ptr %6, align 8, !tbaa !9
  %63 = load i64, ptr %9, align 8, !tbaa !11
  call void @buffer_set_bytes(ptr noundef %61, ptr noundef %62, i64 noundef %63)
  %64 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %64, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %65

65:                                               ; preds = %37, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %66

66:                                               ; preds = %65, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %67

67:                                               ; preds = %66, %14
  %68 = load ptr, ptr %4, align 8
  ret ptr %68
}

declare void @buffer_set_bytes(ptr noundef, ptr noundef, i64 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 = { inlinehint 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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"PeacemakrKey", !15, i64 0, !7, i64 16, !10, i64 24}
!15 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!16 = !{!14, !6, i64 4}
!17 = !{!14, !6, i64 8}
!18 = !{!14, !6, i64 12}
!19 = !{!7, !7, i64 0}
!20 = !{!14, !10, i64 24}


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

@peacemakr_global_malloc = external local_unnamed_addr global ptr, align 8
@__FUNCTION__.peacemakr_key_new_bytes = external hidden unnamed_addr constant [24 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [16 x i8], align 1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @parse_cipher(i32 noundef) local_unnamed_addr #1

declare i32 @EVP_CIPHER_get_key_length(ptr noundef) local_unnamed_addr #0

declare ptr @buffer_new(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @peacemakr_key_new_bytes(i32 noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #2 {
  %4 = icmp eq ptr %1, 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_new_bytes, i32 noundef 264, ptr noundef nonnull @.str.6) #4
  br label %22

6:                                                ; preds = %3
  %7 = tail call ptr @parse_cipher(i32 noundef %0)
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %12, label %8

8:                                                ; preds = %6
  %9 = tail call i32 @EVP_CIPHER_get_key_length(ptr noundef nonnull %7) #4
  %10 = sext i32 %9 to i64
  %.not26 = icmp ugt i64 %10, %2
  br i1 %.not26, label %11, label %12

11:                                               ; preds = %8
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_new_bytes, i32 noundef 271, ptr noundef nonnull @.str.7) #4
  br label %22

12:                                               ; preds = %6, %8
  %.021 = phi i64 [ %10, %8 ], [ %2, %6 ]
  %13 = load ptr, ptr @peacemakr_global_malloc, align 8, !tbaa !5
  %14 = tail call ptr %13(i64 noundef 32) #4
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %12
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_new_bytes, i32 noundef 277, ptr noundef nonnull @.str.8) #4
  br label %22

17:                                               ; preds = %12
  store i32 0, ptr %14, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %14, i64 4
  store i32 %0, ptr %18, align 4, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %14, i64 8
  %20 = getelementptr inbounds i8, ptr %14, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %19, i8 0, i64 24, i1 false)
  %21 = tail call ptr @buffer_new(i64 noundef %.021) #4
  store ptr %21, ptr %20, align 8, !tbaa !14
  tail call void @buffer_set_bytes(ptr noundef %21, ptr noundef nonnull %1, i64 noundef %.021) #4
  br label %22

22:                                               ; preds = %11, %17, %16, %5
  %.2 = phi ptr [ null, %5 ], [ null, %11 ], [ null, %16 ], [ %14, %17 ]
  ret ptr %.2
}

declare void @buffer_set_bytes(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { inlinehint 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 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !12, i64 4}
!14 = !{!7, !7, i64 0}


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