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

; 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.Argon2_instance_t = type { ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr }
%struct.block_ = type { [128 x i64] }

; 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 void @clear_internal_memory(ptr noundef, i64 noundef) #1

declare i32 @blake2b_long(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @fill_first_blocks(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [1024 x i8], align 16
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 1024, ptr %6) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %52, %2
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.Argon2_instance_t, ptr %9, i32 0, i32 6
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %12 = icmp ult i32 %8, %11
  br i1 %12, label %13, label %55

13:                                               ; preds = %7
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 64
  call void @store32(ptr noundef %15, i32 noundef 0)
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 64
  %18 = getelementptr inbounds i8, ptr %17, i64 4
  %19 = load i32, ptr %5, align 4, !tbaa !9
  call void @store32(ptr noundef %18, i32 noundef %19)
  %20 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = call i32 @blake2b_long(ptr noundef %20, i64 noundef 1024, ptr noundef %21, i64 noundef 72)
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Argon2_instance_t, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Argon2_instance_t, ptr %27, i32 0, i32 5
  %29 = load i32, ptr %28, align 8, !tbaa !14
  %30 = mul i32 %26, %29
  %31 = add i32 %30, 0
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds %struct.block_, ptr %25, i64 %32
  %34 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  call void @load_block(ptr noundef %33, ptr noundef %34)
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 64
  call void @store32(ptr noundef %36, i32 noundef 1)
  %37 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = call i32 @blake2b_long(ptr noundef %37, i64 noundef 1024, ptr noundef %38, i64 noundef 72)
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.Argon2_instance_t, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Argon2_instance_t, ptr %44, i32 0, i32 5
  %46 = load i32, ptr %45, align 8, !tbaa !14
  %47 = mul i32 %43, %46
  %48 = add i32 %47, 1
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds %struct.block_, ptr %42, i64 %49
  %51 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  call void @load_block(ptr noundef %50, ptr noundef %51)
  br label %52

52:                                               ; preds = %13
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = add i32 %53, 1
  store i32 %54, ptr %5, align 4, !tbaa !9
  br label %7, !llvm.loop !15

55:                                               ; preds = %7
  %56 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  call void @clear_internal_memory(ptr noundef %56, i64 noundef 1024)
  call void @llvm.lifetime.end.p0(i64 1024, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

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

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

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 = { 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, !10, i64 28}
!12 = !{!"Argon2_instance_t", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !6, i64 48}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !10, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"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"

%struct.block_ = type { [128 x i64] }

; 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 void @clear_internal_memory(ptr noundef, i64 noundef) local_unnamed_addr #1

declare i32 @blake2b_long(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @fill_first_blocks(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = alloca [1024 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %3) #4
  %4 = getelementptr inbounds i8, ptr %1, i64 28
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  %7 = getelementptr inbounds i8, ptr %0, i64 68
  %8 = getelementptr inbounds i8, ptr %1, i64 24
  br label %9

9:                                                ; preds = %.lr.ph, %9
  %.014 = phi i32 [ 0, %.lr.ph ], [ %23, %9 ]
  call void @store32(ptr noundef nonnull %6, i32 noundef 0)
  call void @store32(ptr noundef nonnull %7, i32 noundef %.014)
  %10 = call i32 @blake2b_long(ptr noundef nonnull %3, i64 noundef 1024, ptr noundef %0, i64 noundef 72) #4
  %11 = load ptr, ptr %1, align 8, !tbaa !11
  %12 = load i32, ptr %8, align 8, !tbaa !12
  %13 = mul i32 %12, %.014
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds %struct.block_, ptr %11, i64 %14
  call void @load_block(ptr noundef %15, ptr noundef nonnull %3)
  call void @store32(ptr noundef nonnull %6, i32 noundef 1)
  %16 = call i32 @blake2b_long(ptr noundef nonnull %3, i64 noundef 1024, ptr noundef %0, i64 noundef 72) #4
  %17 = load ptr, ptr %1, align 8, !tbaa !11
  %18 = load i32, ptr %8, align 8, !tbaa !12
  %19 = mul i32 %18, %.014
  %20 = add i32 %19, 1
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds %struct.block_, ptr %17, i64 %21
  call void @load_block(ptr noundef %22, ptr noundef nonnull %3)
  %23 = add nuw i32 %.014, 1
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = icmp ult i32 %23, %24
  br i1 %25, label %9, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %9, %2
  call void @clear_internal_memory(ptr noundef nonnull %3, i64 noundef 1024)
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %3) #4
  ret void
}

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

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

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 = { 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, !10, i64 28}
!6 = !{!"Argon2_instance_t", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !7, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 24}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass