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

; 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_hmac = external hidden unnamed_addr constant [15 x i8], align 1
@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 x i8], align 1
@peacemakr_global_calloc = external global ptr, align 8

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

20:                                               ; preds = %5
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_hmac, i32 noundef 22, ptr noundef @.str)
  store ptr null, ptr %6, align 8
  br label %62

21:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %22 = load ptr, ptr %8, align 8, !tbaa !9
  %23 = call ptr @peacemakr_key_symmetric(ptr noundef %22)
  store ptr %23, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %24 = load ptr, ptr %12, align 8, !tbaa !9
  %25 = call i64 @buffer_get_size(ptr noundef %24)
  store i64 %25, ptr %13, align 8, !tbaa !11
  %26 = load i64, ptr %13, align 8, !tbaa !11
  %27 = icmp ule i64 %26, 2147483647
  br i1 %27, label %29, label %28

28:                                               ; preds = %21
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_hmac, i32 noundef 26, ptr noundef @.str.1)
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %61

29:                                               ; preds = %21
  %30 = load ptr, ptr %9, align 8, !tbaa !9
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = load i64, ptr %10, align 8, !tbaa !11
  %34 = icmp ugt i64 %33, 0
  br i1 %34, label %36, label %35

35:                                               ; preds = %32, %29
  call void (ptr, i32, ptr, ...) @log_printf(ptr noundef @__FUNCTION__.peacemakr_hmac, i32 noundef 28, ptr noundef @.str.2)
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %61

36:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %37 = load ptr, ptr @peacemakr_global_calloc, align 8, !tbaa !9
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = call i64 @get_digest_len(i32 noundef %38)
  %40 = udiv i64 %39, 1
  %41 = call ptr %37(i64 noundef %40, i64 noundef 1)
  store ptr %41, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  store i32 0, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %42 = load ptr, ptr %12, align 8, !tbaa !9
  %43 = call ptr @buffer_get_bytes(ptr noundef %42, ptr noundef null)
  store ptr %43, ptr %17, align 8, !tbaa !9
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = call ptr @parse_digest(i32 noundef %44)
  %46 = load ptr, ptr %17, align 8, !tbaa !9
  %47 = load i64, ptr %13, align 8, !tbaa !11
  %48 = trunc i64 %47 to i32
  %49 = load ptr, ptr %9, align 8, !tbaa !9
  %50 = load i64, ptr %10, align 8, !tbaa !11
  %51 = load ptr, ptr %15, align 8, !tbaa !9
  %52 = call ptr @HMAC(ptr noundef %45, ptr noundef %46, i32 noundef %48, ptr noundef %49, i64 noundef %50, ptr noundef %51, ptr noundef %16)
  %53 = load ptr, ptr %11, align 8, !tbaa !9
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %59

55:                                               ; preds = %36
  %56 = load i32, ptr %16, align 4, !tbaa !5
  %57 = zext i32 %56 to i64
  %58 = load ptr, ptr %11, align 8, !tbaa !9
  store i64 %57, ptr %58, align 8, !tbaa !11
  br label %59

59:                                               ; preds = %55, %36
  %60 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %60, ptr %6, align 8
  store i32 1, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  br label %61

61:                                               ; preds = %59, %35, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %62

62:                                               ; preds = %61, %20
  %63 = load ptr, ptr %6, align 8
  ret ptr %63
}

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

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

declare ptr @peacemakr_key_symmetric(ptr noundef) #1

declare i64 @buffer_get_size(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @get_digest_len(i32 noundef) #3

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

declare ptr @HMAC(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #1

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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}


; 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_hmac = external hidden unnamed_addr constant [15 x i8], align 1
@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 x i8], align 1
@peacemakr_global_calloc = external local_unnamed_addr global ptr, align 8

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

8:                                                ; preds = %5
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_hmac, i32 noundef 22, ptr noundef nonnull @.str) #4
  br label %30

9:                                                ; preds = %5
  %10 = tail call ptr @peacemakr_key_symmetric(ptr noundef nonnull %1) #4
  %11 = tail call i64 @buffer_get_size(ptr noundef %10) #4
  %12 = icmp ult i64 %11, 2147483648
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_hmac, i32 noundef 26, ptr noundef nonnull @.str.1) #4
  br label %30

14:                                               ; preds = %9
  %15 = icmp ne ptr %2, null
  %16 = icmp ne i64 %3, 0
  %or.cond = and i1 %15, %16
  br i1 %or.cond, label %18, label %17

17:                                               ; preds = %14
  tail call void (ptr, i32, ptr, ...) @log_printf(ptr noundef nonnull @__FUNCTION__.peacemakr_hmac, i32 noundef 28, ptr noundef nonnull @.str.2) #4
  br label %30

18:                                               ; preds = %14
  %19 = load ptr, ptr @peacemakr_global_calloc, align 8, !tbaa !5
  %20 = tail call i64 @get_digest_len(i32 noundef %0)
  %21 = tail call ptr %19(i64 noundef %20, i64 noundef 1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  %22 = tail call ptr @buffer_get_bytes(ptr noundef %10, ptr noundef null) #4
  %23 = tail call ptr @parse_digest(i32 noundef %0)
  %24 = trunc nuw nsw i64 %11 to i32
  %25 = call ptr @HMAC(ptr noundef %23, ptr noundef %22, i32 noundef %24, ptr noundef nonnull %2, i64 noundef %3, ptr noundef %21, ptr noundef nonnull %6) #4
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %29, label %26

26:                                               ; preds = %18
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = zext i32 %27 to i64
  store i64 %28, ptr %4, align 8, !tbaa !11
  br label %29

29:                                               ; preds = %26, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #4
  br label %30

30:                                               ; preds = %13, %17, %29, %8
  %.1 = phi ptr [ null, %8 ], [ %21, %29 ], [ null, %17 ], [ null, %13 ]
  ret ptr %.1
}

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

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

declare ptr @peacemakr_key_symmetric(ptr noundef) local_unnamed_addr #1

declare i64 @buffer_get_size(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @get_digest_len(i32 noundef) local_unnamed_addr #3

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

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

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

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}


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