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

@__FUNCTION__.peacemakr_key_new_from_master = external hidden unnamed_addr constant [30 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [26 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

; Function Attrs: nounwind uwtable
declare dso_local ptr @peacemakr_key_new_bytes(i32 noundef, ptr noundef, i64 noundef) #3

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #4

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #4

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

32:                                               ; preds = %5
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_key_new_from_master, i32 noundef 330, ptr noundef @.str.13)
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %107

33:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %34 = load i64, ptr %12, align 8, !tbaa !11
  %35 = mul i64 %34, 8
  store i64 %35, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = call ptr @parse_cipher(i32 noundef %36)
  %38 = call i32 @EVP_CIPHER_get_key_length(ptr noundef %37)
  store i32 %38, ptr %15, align 4, !tbaa !5
  %39 = load i32, ptr %15, align 4, !tbaa !5
  %40 = icmp sle i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %33
  call void @openssl_log(ptr noundef @__FUNCTION__.peacemakr_key_new_from_master, i32 noundef 339)
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_key_new_from_master, i32 noundef 340, ptr noundef @.str.14)
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %106

42:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  %43 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %43, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #6
  %44 = load i32, ptr %16, align 4, !tbaa !5
  %45 = mul i32 %44, 8
  store i32 %45, ptr %17, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #6
  %46 = load i32, ptr %17, align 4, !tbaa !5
  %47 = zext i32 %46 to i64
  %48 = load i64, ptr %14, align 8, !tbaa !11
  %49 = udiv i64 %47, %48
  %50 = load i32, ptr %17, align 4, !tbaa !5
  %51 = zext i32 %50 to i64
  %52 = load i64, ptr %14, align 8, !tbaa !11
  %53 = urem i64 %51, %52
  %54 = icmp ne i64 %53, 0
  %55 = zext i1 %54 to i32
  %56 = sext i32 %55 to i64
  %57 = add i64 %49, %56
  store i64 %57, ptr %18, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #6
  %58 = load i64, ptr %11, align 8, !tbaa !11
  %59 = add i64 4, %58
  %60 = add i64 %59, 4
  store i64 %60, ptr %19, align 8, !tbaa !11
  %61 = load i64, ptr %19, align 8, !tbaa !11
  %62 = call ptr @llvm.stacksave.p0()
  store ptr %62, ptr %20, align 8
  %63 = alloca i8, i64 %61, align 16
  store i64 %61, ptr %21, align 8
  %64 = getelementptr inbounds i8, ptr %63, i64 4
  %65 = load ptr, ptr %10, align 8, !tbaa !9
  %66 = load i64, ptr %11, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %64, ptr align 1 %65, i64 %66, i1 false)
  %67 = getelementptr inbounds i8, ptr %63, i64 4
  %68 = load i64, ptr %11, align 8, !tbaa !11
  %69 = getelementptr inbounds i8, ptr %67, i64 %68
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %69, ptr align 4 %17, i64 4, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #6
  %70 = load ptr, ptr %9, align 8, !tbaa !9
  %71 = call ptr @peacemakr_key_symmetric(ptr noundef %70)
  store ptr %71, ptr %22, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #6
  %72 = load ptr, ptr %22, align 8, !tbaa !9
  %73 = call i64 @buffer_get_size(ptr noundef %72)
  store i64 %73, ptr %23, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #6
  %74 = load ptr, ptr %22, align 8, !tbaa !9
  %75 = call ptr @buffer_get_bytes(ptr noundef %74, ptr noundef null)
  store ptr %75, ptr %24, align 8, !tbaa !9
  %76 = load i64, ptr %18, align 8, !tbaa !11
  %77 = load i64, ptr %12, align 8, !tbaa !11
  %78 = mul i64 %76, %77
  %79 = alloca i8, i64 %78, align 16
  store i64 %78, ptr %25, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #6
  store i32 0, ptr %26, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %27) #6
  store i64 0, ptr %27, align 8, !tbaa !11
  br label %80

80:                                               ; preds = %97, %42
  %81 = load i64, ptr %27, align 8, !tbaa !11
  %82 = load i64, ptr %18, align 8, !tbaa !11
  %83 = icmp ult i64 %81, %82
  br i1 %83, label %85, label %84

84:                                               ; preds = %80
  store i32 2, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #6
  br label %100

85:                                               ; preds = %80
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %63, ptr align 8 %27, i64 4, i1 false)
  %86 = load i32, ptr %8, align 4, !tbaa !5
  %87 = call ptr @parse_digest(i32 noundef %86)
  %88 = load ptr, ptr %24, align 8, !tbaa !9
  %89 = load i64, ptr %23, align 8, !tbaa !11
  %90 = trunc i64 %89 to i32
  %91 = load i64, ptr %19, align 8, !tbaa !11
  %92 = load i64, ptr %27, align 8, !tbaa !11
  %93 = load i64, ptr %12, align 8, !tbaa !11
  %94 = mul i64 %92, %93
  %95 = getelementptr inbounds i8, ptr %79, i64 %94
  %96 = call ptr @HMAC(ptr noundef %87, ptr noundef %88, i32 noundef %90, ptr noundef %63, i64 noundef %91, ptr noundef %95, ptr noundef %26)
  br label %97

97:                                               ; preds = %85
  %98 = load i64, ptr %27, align 8, !tbaa !11
  %99 = add i64 %98, 1
  store i64 %99, ptr %27, align 8, !tbaa !11
  br label %80, !llvm.loop !13

100:                                              ; preds = %84
  %101 = load i32, ptr %7, align 4, !tbaa !5
  %102 = load i32, ptr %16, align 4, !tbaa !5
  %103 = zext i32 %102 to i64
  %104 = call ptr @peacemakr_key_new_bytes(i32 noundef %101, ptr noundef %79, i64 noundef %103)
  store ptr %104, ptr %6, align 8
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #6
  %105 = load ptr, ptr %20, align 8
  call void @llvm.stackrestore.p0(ptr %105)
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  br label %106

106:                                              ; preds = %100, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  br label %107

107:                                              ; preds = %106, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  %108 = load ptr, ptr %6, align 8
  ret ptr %108
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @get_digest_len(i32 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) #5

; Function Attrs: nounwind uwtable
declare dso_local ptr @peacemakr_key_symmetric(ptr noundef) #3

declare i64 @buffer_get_size(ptr noundef) #0

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

declare ptr @HMAC(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 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 = { 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 = { nocallback nofree nosync nounwind willreturn }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

@__FUNCTION__.peacemakr_key_new_from_master = external hidden unnamed_addr constant [30 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [26 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

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

declare i32 @EVP_CIPHER_get_key_length(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @peacemakr_key_new_bytes(i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #4

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @peacemakr_key_new_from_master(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr nocapture noundef readonly %3, i64 noundef %4) local_unnamed_addr #3 {
  %6 = alloca i32, align 4
  %7 = tail call i64 @get_digest_len(i32 noundef %1)
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %5
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_new_from_master, i32 noundef 330, ptr noundef nonnull @.str.13) #6
  br label %44

10:                                               ; preds = %5
  %11 = tail call ptr @parse_cipher(i32 noundef %0)
  %12 = tail call i32 @EVP_CIPHER_get_key_length(ptr noundef %11) #6
  %13 = icmp slt i32 %12, 1
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  tail call void @openssl_log(ptr noundef nonnull @__FUNCTION__.peacemakr_key_new_from_master, i32 noundef 339) #6
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_key_new_from_master, i32 noundef 340, ptr noundef nonnull @.str.14) #6
  br label %44

15:                                               ; preds = %10
  %16 = shl i64 %7, 3
  %17 = shl i32 %12, 3
  %18 = zext i32 %17 to i64
  %19 = udiv i64 %18, %16
  %20 = urem i64 %18, %16
  %21 = icmp ne i64 %20, 0
  %22 = zext i1 %21 to i64
  %23 = add nuw nsw i64 %19, %22
  %24 = add i64 %4, 8
  %25 = tail call ptr @llvm.stacksave.p0()
  %26 = alloca i8, i64 %24, align 16
  %27 = getelementptr inbounds i8, ptr %26, i64 4
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %27, ptr align 1 %3, i64 %4, i1 false)
  %28 = getelementptr inbounds i8, ptr %27, i64 %4
  store i32 %17, ptr %28, align 1
  %29 = tail call ptr @peacemakr_key_symmetric(ptr noundef %2)
  %30 = tail call i64 @buffer_get_size(ptr noundef %29) #6
  %31 = tail call ptr @buffer_get_bytes(ptr noundef %29, ptr noundef null) #6
  %32 = mul i64 %23, %7
  %33 = alloca i8, i64 %32, align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #6
  store i32 0, ptr %6, align 4, !tbaa !5
  %.not = icmp eq i64 %23, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15
  %34 = trunc i64 %30 to i32
  br label %37

._crit_edge:                                      ; preds = %37, %15
  %35 = zext nneg i32 %12 to i64
  %36 = call ptr @peacemakr_key_new_bytes(i32 noundef %0, ptr noundef nonnull %33, i64 noundef %35)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #6
  call void @llvm.stackrestore.p0(ptr %25)
  br label %44

37:                                               ; preds = %.lr.ph, %37
  %.037 = phi i64 [ 0, %.lr.ph ], [ %42, %37 ]
  %.0.extract.trunc = trunc nuw i64 %.037 to i32
  store i32 %.0.extract.trunc, ptr %26, align 16
  %38 = call ptr @parse_digest(i32 noundef %1)
  %39 = mul i64 %.037, %7
  %40 = getelementptr inbounds i8, ptr %33, i64 %39
  %41 = call ptr @HMAC(ptr noundef %38, ptr noundef %31, i32 noundef %34, ptr noundef nonnull %26, i64 noundef %24, ptr noundef nonnull %40, ptr noundef nonnull %6) #6
  %42 = add nuw nsw i64 %.037, 1
  %43 = icmp ult i64 %42, %23
  br i1 %43, label %37, label %._crit_edge, !llvm.loop !9

44:                                               ; preds = %14, %._crit_edge, %9
  %.1 = phi ptr [ null, %9 ], [ null, %14 ], [ %36, %._crit_edge ]
  ret ptr %.1
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @get_digest_len(i32 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) #5

; Function Attrs: nounwind uwtable
declare dso_local ptr @peacemakr_key_symmetric(ptr noundef) local_unnamed_addr #3

declare i64 @buffer_get_size(ptr noundef) local_unnamed_addr #0

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

declare ptr @HMAC(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 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 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass