; 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 }
%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
define dso_local i32 @blake2b_init_param(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %9, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp eq ptr null, %10
  br i1 %11, label %15, label %12

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp eq ptr null, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %12, %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %45

16:                                               ; preds = %12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  call void @blake2b_init0(ptr noundef %17)
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %35, %16
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = icmp ult i32 %19, 8
  br i1 %20, label %21, label %38

21:                                               ; preds = %18
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = mul i64 %24, 8
  %26 = getelementptr inbounds i8, ptr %22, i64 %25
  %27 = call i64 @load64(ptr noundef %26)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.__blake2b_state, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds [8 x i64], ptr %29, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !11
  %34 = xor i64 %33, %27
  store i64 %34, ptr %32, align 8, !tbaa !11
  br label %35

35:                                               ; preds = %21
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = add i32 %36, 1
  store i32 %37, ptr %7, align 4, !tbaa !9
  br label %18, !llvm.loop !13

38:                                               ; preds = %18
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.__blake2b_param, ptr %39, i32 0, i32 0
  %41 = load i8, ptr %40, align 1, !tbaa !15
  %42 = zext i8 %41 to i32
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.__blake2b_state, ptr %43, i32 0, i32 5
  store i32 %42, ptr %44, align 4, !tbaa !17
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %45

45:                                               ; preds = %38, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %46 = load i32, ptr %3, align 4
  ret i32 %46
}

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

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

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

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

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 = { 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}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !7, i64 0}
!16 = !{!"__blake2b_param", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !10, i64 4, !12, i64 8, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 32, !7, i64 48}
!17 = !{!18, !10, i64 228}
!18 = !{!"__blake2b_state", !7, i64 0, !7, i64 64, !7, i64 80, !7, i64 96, !10, i64 224, !10, i64 228, !7, i64 232}


; 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: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @blake2b_init_param(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %1, null
  %4 = icmp eq ptr %0, null
  %or.cond = or i1 %4, %3
  br i1 %or.cond, label %47, label %5

5:                                                ; preds = %2
  tail call void @blake2b_init0(ptr noundef nonnull %0)
  %6 = tail call i64 @load64(ptr noundef nonnull %1)
  %7 = load i64, ptr %0, align 8, !tbaa !5
  %8 = xor i64 %7, %6
  store i64 %8, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = tail call i64 @load64(ptr noundef nonnull %9)
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = xor i64 %12, %10
  store i64 %13, ptr %11, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %1, i64 16
  %15 = tail call i64 @load64(ptr noundef nonnull %14)
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = xor i64 %17, %15
  store i64 %18, ptr %16, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %1, i64 24
  %20 = tail call i64 @load64(ptr noundef nonnull %19)
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = xor i64 %22, %20
  store i64 %23, ptr %21, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %1, i64 32
  %25 = tail call i64 @load64(ptr noundef nonnull %24)
  %26 = getelementptr inbounds i8, ptr %0, i64 32
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = xor i64 %27, %25
  store i64 %28, ptr %26, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %1, i64 40
  %30 = tail call i64 @load64(ptr noundef nonnull %29)
  %31 = getelementptr inbounds i8, ptr %0, i64 40
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = xor i64 %32, %30
  store i64 %33, ptr %31, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %1, i64 48
  %35 = tail call i64 @load64(ptr noundef nonnull %34)
  %36 = getelementptr inbounds i8, ptr %0, i64 48
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = xor i64 %37, %35
  store i64 %38, ptr %36, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %1, i64 56
  %40 = tail call i64 @load64(ptr noundef nonnull %39)
  %41 = getelementptr inbounds i8, ptr %0, i64 56
  %42 = load i64, ptr %41, align 8, !tbaa !5
  %43 = xor i64 %42, %40
  store i64 %43, ptr %41, align 8, !tbaa !5
  %44 = load i8, ptr %1, align 1, !tbaa !9
  %45 = zext i8 %44 to i32
  %46 = getelementptr inbounds i8, ptr %0, i64 228
  store i32 %45, ptr %46, align 4, !tbaa !12
  br label %47

47:                                               ; preds = %2, %5
  %.013 = phi i32 [ 0, %5 ], [ -1, %2 ]
  ret i32 %.013
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @load64(ptr noundef) local_unnamed_addr #1

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 = { 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, !7, i64 0}
!10 = !{!"__blake2b_param", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !11, i64 4, !6, i64 8, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 32, !7, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 228}
!13 = !{!"__blake2b_state", !7, i64 0, !7, i64 64, !7, i64 80, !7, i64 96, !11, i64 224, !11, i64 228, !7, i64 232}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass