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

; Function Attrs: nounwind uwtable
declare dso_local void @copy_block(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @xor_block(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: nounwind uwtable
declare dso_local void @free_memory(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @finalize(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.block_, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca [1024 x i8], align 16
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %72

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %72

14:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 1024, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Argon2_instance_t, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.Argon2_instance_t, ptr %18, i32 0, i32 5
  %20 = load i32, ptr %19, align 8, !tbaa !12
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds %struct.block_, ptr %17, i64 %21
  %23 = getelementptr inbounds %struct.block_, ptr %22, i64 -1
  call void @copy_block(ptr noundef %5, ptr noundef %23)
  store i32 1, ptr %6, align 4, !tbaa !13
  br label %24

24:                                               ; preds = %47, %14
  %25 = load i32, ptr %6, align 4, !tbaa !13
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Argon2_instance_t, ptr %26, i32 0, i32 6
  %28 = load i32, ptr %27, align 4, !tbaa !14
  %29 = icmp ult i32 %25, %28
  br i1 %29, label %30, label %50

30:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %31 = load i32, ptr %6, align 4, !tbaa !13
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Argon2_instance_t, ptr %32, i32 0, i32 5
  %34 = load i32, ptr %33, align 8, !tbaa !12
  %35 = mul i32 %31, %34
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Argon2_instance_t, ptr %36, i32 0, i32 5
  %38 = load i32, ptr %37, align 8, !tbaa !12
  %39 = sub i32 %38, 1
  %40 = add i32 %35, %39
  store i32 %40, ptr %7, align 4, !tbaa !13
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Argon2_instance_t, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = load i32, ptr %7, align 4, !tbaa !13
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds %struct.block_, ptr %43, i64 %45
  call void @xor_block(ptr noundef %5, ptr noundef %46)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %47

47:                                               ; preds = %30
  %48 = load i32, ptr %6, align 4, !tbaa !13
  %49 = add i32 %48, 1
  store i32 %49, ptr %6, align 4, !tbaa !13
  br label %24, !llvm.loop !15

50:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 1024, ptr %8) #3
  %51 = getelementptr inbounds [1024 x i8], ptr %8, i64 0, i64 0
  call void @store_block(ptr noundef %51, ptr noundef %5)
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Argon2_Context, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !17
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.Argon2_Context, ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 8, !tbaa !19
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds [1024 x i8], ptr %8, i64 0, i64 0
  %60 = call i32 @blake2b_long(ptr noundef %54, i64 noundef %58, ptr noundef %59, i64 noundef 1024)
  %61 = getelementptr inbounds %struct.block_, ptr %5, i32 0, i32 0
  %62 = getelementptr inbounds [128 x i64], ptr %61, i64 0, i64 0
  call void @clear_internal_memory(ptr noundef %62, i64 noundef 1024)
  %63 = getelementptr inbounds [1024 x i8], ptr %8, i64 0, i64 0
  call void @clear_internal_memory(ptr noundef %63, i64 noundef 1024)
  call void @llvm.lifetime.end.p0(i64 1024, ptr %8) #3
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.Argon2_instance_t, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !9
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.Argon2_instance_t, ptr %68, i32 0, i32 3
  %70 = load i32, ptr %69, align 8, !tbaa !20
  %71 = zext i32 %70 to i64
  call void @free_memory(ptr noundef %64, ptr noundef %67, i64 noundef %71, i64 noundef 1024)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1024, ptr %5) #3
  br label %72

72:                                               ; preds = %50, %11, %2
  ret void
}

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

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

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 = { "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, !6, i64 0}
!10 = !{!"Argon2_instance_t", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !6, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 24}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 28}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !6, i64 0}
!18 = !{!"Argon2_Context", !6, i64 0, !11, i64 8, !6, i64 16, !11, i64 24, !6, i64 32, !11, i64 40, !6, i64 48, !11, i64 56, !6, i64 64, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !6, i64 96, !6, i64 104, !11, i64 112}
!19 = !{!18, !11, i64 8}
!20 = !{!10, !11, i64 16}


; 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: nounwind uwtable
declare dso_local void @copy_block(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @xor_block(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: nounwind uwtable
declare dso_local void @free_memory(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @finalize(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca %struct.block_, align 8
  %4 = alloca [1024 x i8], align 16
  %5 = icmp ne ptr %0, null
  %6 = icmp ne ptr %1, null
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %7, label %36

7:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %3) #3
  %8 = load ptr, ptr %1, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %1, i64 24
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = zext i32 %10 to i64
  %12 = getelementptr inbounds %struct.block_, ptr %8, i64 %11
  %13 = getelementptr inbounds i8, ptr %12, i64 -1024
  call void @copy_block(ptr noundef nonnull %3, ptr noundef nonnull %13)
  %14 = getelementptr inbounds i8, ptr %1, i64 28
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = icmp ugt i32 %15, 1
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %7, %.lr.ph
  %.019 = phi i32 [ %24, %.lr.ph ], [ 1, %7 ]
  %17 = load i32, ptr %9, align 8, !tbaa !11
  %18 = mul i32 %17, %.019
  %19 = add i32 %17, -1
  %20 = add i32 %19, %18
  %21 = load ptr, ptr %1, align 8, !tbaa !5
  %22 = zext i32 %20 to i64
  %23 = getelementptr inbounds %struct.block_, ptr %21, i64 %22
  call void @xor_block(ptr noundef nonnull %3, ptr noundef %23)
  %24 = add nuw i32 %.019, 1
  %25 = load i32, ptr %14, align 4, !tbaa !12
  %26 = icmp ult i32 %24, %25
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %7
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %4) #3
  call void @store_block(ptr noundef nonnull %4, ptr noundef nonnull %3)
  %27 = load ptr, ptr %0, align 8, !tbaa !15
  %28 = getelementptr inbounds i8, ptr %0, i64 8
  %29 = load i32, ptr %28, align 8, !tbaa !17
  %30 = zext i32 %29 to i64
  %31 = call i32 @blake2b_long(ptr noundef %27, i64 noundef %30, ptr noundef nonnull %4, i64 noundef 1024) #3
  call void @clear_internal_memory(ptr noundef nonnull %3, i64 noundef 1024)
  call void @clear_internal_memory(ptr noundef nonnull %4, i64 noundef 1024)
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %4) #3
  %32 = load ptr, ptr %1, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %1, i64 16
  %34 = load i32, ptr %33, align 8, !tbaa !18
  %35 = zext i32 %34 to i64
  call void @free_memory(ptr noundef nonnull %0, ptr noundef %32, i64 noundef %35, i64 noundef 1024)
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %3) #3
  br label %36

36:                                               ; preds = %._crit_edge, %2
  ret void
}

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

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

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 = { "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, !7, i64 0}
!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, !10, i64 24}
!12 = !{!6, !10, i64 28}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !7, i64 0}
!16 = !{!"Argon2_Context", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !10, i64 40, !7, i64 48, !10, i64 56, !7, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !7, i64 96, !7, i64 104, !10, i64 112}
!17 = !{!16, !10, i64 8}
!18 = !{!6, !10, i64 16}


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