; LLVM IR from imkcat/CatCrypto :: Sources/ModuleMaps/Argon2 (blake2b)

; 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.__blake2b_state = type { [8 x i64], [2 x i64], [2 x i64], [128 x i8], i32, i32, i8 }

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

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

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

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

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

declare void @clear_internal_memory(ptr noundef, i64 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @blake2b(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5) #1 {
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca %struct.__blake2b_state, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  store i64 %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 240, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 -1, ptr %14, align 4, !tbaa !11
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = icmp eq ptr null, %15
  br i1 %16, label %17, label %21

17:                                               ; preds = %6
  %18 = load i64, ptr %10, align 8, !tbaa !9
  %19 = icmp ugt i64 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  br label %68

21:                                               ; preds = %17, %6
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = icmp eq ptr null, %22
  br i1 %23, label %30, label %24

24:                                               ; preds = %21
  %25 = load i64, ptr %8, align 8, !tbaa !9
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %30, label %27

27:                                               ; preds = %24
  %28 = load i64, ptr %8, align 8, !tbaa !9
  %29 = icmp ugt i64 %28, 64
  br i1 %29, label %30, label %31

30:                                               ; preds = %27, %24, %21
  br label %68

31:                                               ; preds = %27
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = icmp eq ptr null, %32
  br i1 %33, label %34, label %37

34:                                               ; preds = %31
  %35 = load i64, ptr %12, align 8, !tbaa !9
  %36 = icmp ugt i64 %35, 0
  br i1 %36, label %40, label %37

37:                                               ; preds = %34, %31
  %38 = load i64, ptr %12, align 8, !tbaa !9
  %39 = icmp ugt i64 %38, 64
  br i1 %39, label %40, label %41

40:                                               ; preds = %37, %34
  br label %68

41:                                               ; preds = %37
  %42 = load i64, ptr %12, align 8, !tbaa !9
  %43 = icmp ugt i64 %42, 0
  br i1 %43, label %44, label %52

44:                                               ; preds = %41
  %45 = load i64, ptr %8, align 8, !tbaa !9
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = load i64, ptr %12, align 8, !tbaa !9
  %48 = call i32 @blake2b_init_key(ptr noundef %13, i64 noundef %45, ptr noundef %46, i64 noundef %47)
  %49 = icmp slt i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %44
  br label %68

51:                                               ; preds = %44
  br label %58

52:                                               ; preds = %41
  %53 = load i64, ptr %8, align 8, !tbaa !9
  %54 = call i32 @blake2b_init(ptr noundef %13, i64 noundef %53)
  %55 = icmp slt i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %52
  br label %68

57:                                               ; preds = %52
  br label %58

58:                                               ; preds = %57, %51
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = load i64, ptr %10, align 8, !tbaa !9
  %61 = call i32 @blake2b_update(ptr noundef %13, ptr noundef %59, i64 noundef %60)
  %62 = icmp slt i32 %61, 0
  br i1 %62, label %63, label %64

63:                                               ; preds = %58
  br label %68

64:                                               ; preds = %58
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load i64, ptr %8, align 8, !tbaa !9
  %67 = call i32 @blake2b_final(ptr noundef %13, ptr noundef %65, i64 noundef %66)
  store i32 %67, ptr %14, align 4, !tbaa !11
  br label %68

68:                                               ; preds = %64, %63, %56, %50, %40, %30, %20
  call void @clear_internal_memory(ptr noundef %13, i64 noundef 240)
  %69 = load i32, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 240, ptr %13) #3
  ret i32 %69
}

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

%struct.__blake2b_state = type { [8 x i64], [2 x i64], [2 x i64], [128 x i8], i32, i32, i8 }

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

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

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

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

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

declare void @clear_internal_memory(ptr noundef, i64 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @blake2b(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5) local_unnamed_addr #1 {
  %7 = alloca %struct.__blake2b_state, align 8
  call void @llvm.lifetime.start.p0(i64 240, ptr nonnull %7) #3
  %8 = icmp eq ptr %2, null
  %9 = icmp ne i64 %3, 0
  %or.cond = and i1 %8, %9
  br i1 %or.cond, label %30, label %10

10:                                               ; preds = %6
  %11 = icmp eq ptr %0, null
  %12 = add i64 %1, -65
  %13 = icmp ult i64 %12, -64
  %or.cond5 = or i1 %11, %13
  br i1 %or.cond5, label %30, label %14

14:                                               ; preds = %10
  %15 = icmp eq ptr %4, null
  %16 = icmp ne i64 %5, 0
  %or.cond7 = and i1 %15, %16
  %17 = icmp ugt i64 %5, 64
  %or.cond9 = or i1 %17, %or.cond7
  br i1 %or.cond9, label %30, label %18

18:                                               ; preds = %14
  br i1 %16, label %19, label %22

19:                                               ; preds = %18
  %20 = call i32 @blake2b_init_key(ptr noundef nonnull %7, i64 noundef %1, ptr noundef %4, i64 noundef %5)
  %21 = icmp slt i32 %20, 0
  br i1 %21, label %30, label %25

22:                                               ; preds = %18
  %23 = call i32 @blake2b_init(ptr noundef nonnull %7, i64 noundef %1)
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %30, label %25

25:                                               ; preds = %22, %19
  %26 = call i32 @blake2b_update(ptr noundef nonnull %7, ptr noundef %2, i64 noundef %3)
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %30, label %28

28:                                               ; preds = %25
  %29 = call i32 @blake2b_final(ptr noundef nonnull %7, ptr noundef nonnull %0, i64 noundef %1)
  br label %30

30:                                               ; preds = %25, %22, %19, %14, %10, %6, %28
  %.0 = phi i32 [ -1, %6 ], [ -1, %10 ], [ -1, %14 ], [ -1, %19 ], [ -1, %25 ], [ %29, %28 ], [ -1, %22 ]
  call void @clear_internal_memory(ptr noundef nonnull %7, i64 noundef 240) #3
  call void @llvm.lifetime.end.p0(i64 240, ptr nonnull %7) #3
  ret i32 %.0
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass