; 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: 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) #1

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

15:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %92

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %22, label %19

19:                                               ; preds = %16
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %19, %16
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %92

23:                                               ; preds = %19
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.__blake2b_state, ptr %24, i32 0, i32 2
  %26 = getelementptr inbounds [2 x i64], ptr %25, i64 0, i64 0
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %23
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %92

30:                                               ; preds = %23
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.__blake2b_state, ptr %31, i32 0, i32 4
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = zext i32 %33 to i64
  %35 = load i64, ptr %7, align 8, !tbaa !9
  %36 = add i64 %34, %35
  %37 = icmp ugt i64 %36, 128
  br i1 %37, label %38, label %76

38:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.__blake2b_state, ptr %39, i32 0, i32 4
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = zext i32 %41 to i64
  store i64 %42, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %43 = load i64, ptr %10, align 8, !tbaa !9
  %44 = sub i64 128, %43
  store i64 %44, ptr %11, align 8, !tbaa !9
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.__blake2b_state, ptr %45, i32 0, i32 3
  %47 = load i64, ptr %10, align 8, !tbaa !9
  %48 = getelementptr inbounds [128 x i8], ptr %46, i64 0, i64 %47
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i64, ptr %11, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %48, ptr align 1 %49, i64 %50, i1 false)
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  call void @blake2b_increment_counter(ptr noundef %51, i64 noundef 128)
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.__blake2b_state, ptr %53, i32 0, i32 3
  %55 = getelementptr inbounds [128 x i8], ptr %54, i64 0, i64 0
  call void @blake2b_compress(ptr noundef %52, ptr noundef %55)
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.__blake2b_state, ptr %56, i32 0, i32 4
  store i32 0, ptr %57, align 8, !tbaa !11
  %58 = load i64, ptr %11, align 8, !tbaa !9
  %59 = load i64, ptr %7, align 8, !tbaa !9
  %60 = sub i64 %59, %58
  store i64 %60, ptr %7, align 8, !tbaa !9
  %61 = load i64, ptr %11, align 8, !tbaa !9
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %62, i64 %61
  store ptr %63, ptr %8, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %67, %38
  %65 = load i64, ptr %7, align 8, !tbaa !9
  %66 = icmp ugt i64 %65, 128
  br i1 %66, label %67, label %75

67:                                               ; preds = %64
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  call void @blake2b_increment_counter(ptr noundef %68, i64 noundef 128)
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  call void @blake2b_compress(ptr noundef %69, ptr noundef %70)
  %71 = load i64, ptr %7, align 8, !tbaa !9
  %72 = sub i64 %71, 128
  store i64 %72, ptr %7, align 8, !tbaa !9
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i64 128
  store ptr %74, ptr %8, align 8, !tbaa !5
  br label %64, !llvm.loop !14

75:                                               ; preds = %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %76

76:                                               ; preds = %75, %30
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.__blake2b_state, ptr %77, i32 0, i32 3
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.__blake2b_state, ptr %79, i32 0, i32 4
  %81 = load i32, ptr %80, align 8, !tbaa !11
  %82 = zext i32 %81 to i64
  %83 = getelementptr inbounds [128 x i8], ptr %78, i64 0, i64 %82
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %83, ptr align 1 %84, i64 %85, i1 false)
  %86 = load i64, ptr %7, align 8, !tbaa !9
  %87 = trunc i64 %86 to i32
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.__blake2b_state, ptr %88, i32 0, i32 4
  %90 = load i32, ptr %89, align 8, !tbaa !11
  %91 = add i32 %90, %87
  store i32 %91, ptr %89, align 8, !tbaa !11
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %92

92:                                               ; preds = %76, %29, %22, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %93 = load i32, ptr %4, align 4
  ret i32 %93
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @blake2b_increment_counter(ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
declare hidden void @blake2b_compress(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 224}
!12 = !{!"__blake2b_state", !7, i64 0, !7, i64 64, !7, i64 80, !7, i64 96, !13, i64 224, !13, i64 228, !7, i64 232}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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 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) #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @blake2b_update(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq i64 %2, 0
  br i1 %4, label %34, label %5

5:                                                ; preds = %3
  %6 = icmp eq ptr %0, null
  %7 = icmp eq ptr %1, null
  %or.cond = or i1 %6, %7
  br i1 %or.cond, label %34, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 80
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %11, label %34

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 224
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = zext i32 %13 to i64
  %15 = add i64 %14, %2
  %16 = icmp ugt i64 %15, 128
  br i1 %16, label %17, label %.loopexit

17:                                               ; preds = %11
  %18 = sub nsw i64 128, %14
  %19 = getelementptr inbounds i8, ptr %0, i64 96
  %20 = getelementptr inbounds [128 x i8], ptr %19, i64 0, i64 %14
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %20, ptr nonnull align 1 %1, i64 %18, i1 false)
  tail call void @blake2b_increment_counter(ptr noundef nonnull %0, i64 noundef 128)
  tail call void @blake2b_compress(ptr noundef nonnull %0, ptr noundef nonnull %19)
  store i32 0, ptr %12, align 8, !tbaa !9
  %21 = sub i64 %2, %18
  %22 = getelementptr inbounds i8, ptr %1, i64 %18
  %23 = icmp ugt i64 %21, 128
  br i1 %23, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %17, %.lr.ph
  %.03441 = phi i64 [ %24, %.lr.ph ], [ %21, %17 ]
  %.03540 = phi ptr [ %25, %.lr.ph ], [ %22, %17 ]
  tail call void @blake2b_increment_counter(ptr noundef %0, i64 noundef 128)
  tail call void @blake2b_compress(ptr noundef %0, ptr noundef %.03540)
  %24 = add i64 %.03441, -128
  %25 = getelementptr inbounds i8, ptr %.03540, i64 128
  %26 = icmp ugt i64 %24, 128
  br i1 %26, label %.lr.ph, label %.loopexit.loopexit, !llvm.loop !12

.loopexit.loopexit:                               ; preds = %.lr.ph
  %.pre = load i32, ptr %12, align 8, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %17, %11
  %27 = phi i32 [ %13, %11 ], [ 0, %17 ], [ %.pre, %.loopexit.loopexit ]
  %.136 = phi ptr [ %1, %11 ], [ %22, %17 ], [ %25, %.loopexit.loopexit ]
  %.1 = phi i64 [ %2, %11 ], [ %21, %17 ], [ %24, %.loopexit.loopexit ]
  %28 = getelementptr inbounds i8, ptr %0, i64 96
  %29 = zext i32 %27 to i64
  %30 = getelementptr inbounds [128 x i8], ptr %28, i64 0, i64 %29
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %30, ptr align 1 %.136, i64 %.1, i1 false)
  %31 = trunc i64 %.1 to i32
  %32 = load i32, ptr %12, align 8, !tbaa !9
  %33 = add i32 %32, %31
  store i32 %33, ptr %12, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %8, %5, %3, %.loopexit
  %.0 = phi i32 [ 0, %.loopexit ], [ 0, %3 ], [ -1, %5 ], [ -1, %8 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @blake2b_increment_counter(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @blake2b_compress(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree 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 = { 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" }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 224}
!10 = !{!"__blake2b_state", !7, i64 0, !7, i64 64, !7, i64 80, !7, i64 96, !11, i64 224, !11, i64 228, !7, i64 232}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass