; 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_param = type { i8, i8, i8, i8, i32, i64, i8, i8, [14 x i8], [16 x i8], [16 x i8] }

; Function Attrs: nounwind uwtable
declare dso_local i32 @blake2b_init_param(ptr 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 void @blake2b_invalidate_state(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @blake2b_init_key(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #0 {
  %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 %struct.__blake2b_param, align 1
  %11 = alloca i32, align 4
  %12 = alloca [128 x i8], align 16
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 64, ptr %10) #6
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %4
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %68

16:                                               ; preds = %4
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %22, label %19

19:                                               ; preds = %16
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = icmp ugt i64 %20, 64
  br i1 %21, label %22, label %24

22:                                               ; preds = %19, %16
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  call void @blake2b_invalidate_state(ptr noundef %23)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %68

24:                                               ; preds = %19
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %33, label %27

27:                                               ; preds = %24
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = icmp eq i64 %28, 0
  br i1 %29, label %33, label %30

30:                                               ; preds = %27
  %31 = load i64, ptr %9, align 8, !tbaa !9
  %32 = icmp ugt i64 %31, 64
  br i1 %32, label %33, label %35

33:                                               ; preds = %30, %27, %24
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  call void @blake2b_invalidate_state(ptr noundef %34)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %68

35:                                               ; preds = %30
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = trunc i64 %36 to i8
  %38 = getelementptr inbounds %struct.__blake2b_param, ptr %10, i32 0, i32 0
  store i8 %37, ptr %38, align 1, !tbaa !11
  %39 = load i64, ptr %9, align 8, !tbaa !9
  %40 = trunc i64 %39 to i8
  %41 = getelementptr inbounds %struct.__blake2b_param, ptr %10, i32 0, i32 1
  store i8 %40, ptr %41, align 1, !tbaa !14
  %42 = getelementptr inbounds %struct.__blake2b_param, ptr %10, i32 0, i32 2
  store i8 1, ptr %42, align 1, !tbaa !15
  %43 = getelementptr inbounds %struct.__blake2b_param, ptr %10, i32 0, i32 3
  store i8 1, ptr %43, align 1, !tbaa !16
  %44 = getelementptr inbounds %struct.__blake2b_param, ptr %10, i32 0, i32 4
  store i32 0, ptr %44, align 1, !tbaa !17
  %45 = getelementptr inbounds %struct.__blake2b_param, ptr %10, i32 0, i32 5
  store i64 0, ptr %45, align 1, !tbaa !18
  %46 = getelementptr inbounds %struct.__blake2b_param, ptr %10, i32 0, i32 6
  store i8 0, ptr %46, align 1, !tbaa !19
  %47 = getelementptr inbounds %struct.__blake2b_param, ptr %10, i32 0, i32 7
  store i8 0, ptr %47, align 1, !tbaa !20
  %48 = getelementptr inbounds %struct.__blake2b_param, ptr %10, i32 0, i32 8
  %49 = getelementptr inbounds [14 x i8], ptr %48, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 1 %49, i8 0, i64 14, i1 false)
  %50 = getelementptr inbounds %struct.__blake2b_param, ptr %10, i32 0, i32 9
  %51 = getelementptr inbounds [16 x i8], ptr %50, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 1 %51, i8 0, i64 16, i1 false)
  %52 = getelementptr inbounds %struct.__blake2b_param, ptr %10, i32 0, i32 10
  %53 = getelementptr inbounds [16 x i8], ptr %52, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 1 %53, i8 0, i64 16, i1 false)
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = call i32 @blake2b_init_param(ptr noundef %54, ptr noundef %10)
  %56 = icmp slt i32 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %35
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  call void @blake2b_invalidate_state(ptr noundef %58)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %68

59:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 128, ptr %12) #6
  %60 = getelementptr inbounds [128 x i8], ptr %12, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %60, i8 0, i64 128, i1 false)
  %61 = getelementptr inbounds [128 x i8], ptr %12, i64 0, i64 0
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %61, ptr align 1 %62, i64 %63, i1 false)
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds [128 x i8], ptr %12, i64 0, i64 0
  %66 = call i32 @blake2b_update(ptr noundef %64, ptr noundef %65, i64 noundef 128)
  %67 = getelementptr inbounds [128 x i8], ptr %12, i64 0, i64 0
  call void @clear_internal_memory(ptr noundef %67, i64 noundef 128)
  call void @llvm.lifetime.end.p0(i64 128, ptr %12) #6
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %68

68:                                               ; preds = %59, %57, %33, %22, %15
  call void @llvm.lifetime.end.p0(i64 64, ptr %10) #6
  %69 = load i32, ptr %5, align 4
  ret i32 %69
}

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

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

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

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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { "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 #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 = !{!"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, !7, i64 0}
!12 = !{!"__blake2b_param", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !13, i64 4, !10, i64 8, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 32, !7, i64 48}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !7, i64 1}
!15 = !{!12, !7, i64 2}
!16 = !{!12, !7, i64 3}
!17 = !{!12, !13, i64 4}
!18 = !{!12, !10, i64 8}
!19 = !{!12, !7, i64 16}
!20 = !{!12, !7, i64 17}


; 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_param = type { i8, i8, i8, i8, i32, i64, i8, i8, [14 x i8], [16 x i8], [16 x i8] }

; Function Attrs: nounwind uwtable
declare dso_local i32 @blake2b_init_param(ptr 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 void @blake2b_invalidate_state(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @blake2b_init_key(ptr noundef %0, i64 noundef %1, ptr noundef readonly %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.__blake2b_param, align 1
  %6 = alloca [128 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %5) #6
  %7 = icmp eq ptr %0, null
  br i1 %7, label %28, label %8

8:                                                ; preds = %4
  %9 = add i64 %1, -65
  %or.cond = icmp ult i64 %9, -64
  br i1 %or.cond, label %10, label %11

10:                                               ; preds = %8
  tail call void @blake2b_invalidate_state(ptr noundef nonnull %0)
  br label %28

11:                                               ; preds = %8
  %12 = icmp eq ptr %2, null
  %13 = add i64 %3, -65
  %14 = icmp ult i64 %13, -64
  %or.cond5 = or i1 %12, %14
  br i1 %or.cond5, label %15, label %16

15:                                               ; preds = %11
  tail call void @blake2b_invalidate_state(ptr noundef nonnull %0)
  br label %28

16:                                               ; preds = %11
  %17 = trunc nuw nsw i64 %1 to i8
  store i8 %17, ptr %5, align 1, !tbaa !5
  %18 = trunc nuw nsw i64 %3 to i8
  %19 = getelementptr inbounds i8, ptr %5, i64 1
  store i8 %18, ptr %19, align 1, !tbaa !11
  %20 = getelementptr inbounds i8, ptr %5, i64 2
  store i8 1, ptr %20, align 1, !tbaa !12
  %21 = getelementptr inbounds i8, ptr %5, i64 3
  store i8 1, ptr %21, align 1, !tbaa !13
  %22 = getelementptr inbounds i8, ptr %5, i64 4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(60) %22, i8 0, i64 60, i1 false)
  %23 = call i32 @blake2b_init_param(ptr noundef nonnull %0, ptr noundef nonnull %5)
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %16
  call void @blake2b_invalidate_state(ptr noundef nonnull %0)
  br label %28

26:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %6) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(128) %6, i8 0, i64 128, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %6, ptr nonnull align 1 %2, i64 %3, i1 false)
  %27 = call i32 @blake2b_update(ptr noundef nonnull %0, ptr noundef nonnull %6, i64 noundef 128)
  call void @clear_internal_memory(ptr noundef nonnull %6, i64 noundef 128) #6
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %6) #6
  br label %28

28:                                               ; preds = %4, %26, %25, %15, %10
  %.0 = phi i32 [ -1, %10 ], [ -1, %15 ], [ -1, %25 ], [ 0, %26 ], [ -1, %4 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %5) #6
  ret i32 %.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) #4

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

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

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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { "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 #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, !7, i64 0}
!6 = !{!"__blake2b_param", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !9, i64 4, !10, i64 8, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 32, !7, i64 48}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!6, !7, i64 1}
!12 = !{!6, !7, i64 2}
!13 = !{!6, !7, i64 3}


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