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

10:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %38

11:                                               ; preds = %2
  %12 = load i64, ptr %5, align 8, !tbaa !9
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %17, label %14

14:                                               ; preds = %11
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = icmp ugt i64 %15, 64
  br i1 %16, label %17, label %19

17:                                               ; preds = %14, %11
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  call void @blake2b_invalidate_state(ptr noundef %18)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %38

19:                                               ; preds = %14
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = trunc i64 %20 to i8
  %22 = getelementptr inbounds %struct.__blake2b_param, ptr %6, i32 0, i32 0
  store i8 %21, ptr %22, align 1, !tbaa !11
  %23 = getelementptr inbounds %struct.__blake2b_param, ptr %6, i32 0, i32 1
  store i8 0, ptr %23, align 1, !tbaa !14
  %24 = getelementptr inbounds %struct.__blake2b_param, ptr %6, i32 0, i32 2
  store i8 1, ptr %24, align 1, !tbaa !15
  %25 = getelementptr inbounds %struct.__blake2b_param, ptr %6, i32 0, i32 3
  store i8 1, ptr %25, align 1, !tbaa !16
  %26 = getelementptr inbounds %struct.__blake2b_param, ptr %6, i32 0, i32 4
  store i32 0, ptr %26, align 1, !tbaa !17
  %27 = getelementptr inbounds %struct.__blake2b_param, ptr %6, i32 0, i32 5
  store i64 0, ptr %27, align 1, !tbaa !18
  %28 = getelementptr inbounds %struct.__blake2b_param, ptr %6, i32 0, i32 6
  store i8 0, ptr %28, align 1, !tbaa !19
  %29 = getelementptr inbounds %struct.__blake2b_param, ptr %6, i32 0, i32 7
  store i8 0, ptr %29, align 1, !tbaa !20
  %30 = getelementptr inbounds %struct.__blake2b_param, ptr %6, i32 0, i32 8
  %31 = getelementptr inbounds [14 x i8], ptr %30, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 1 %31, i8 0, i64 14, i1 false)
  %32 = getelementptr inbounds %struct.__blake2b_param, ptr %6, i32 0, i32 9
  %33 = getelementptr inbounds [16 x i8], ptr %32, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 1 %33, i8 0, i64 16, i1 false)
  %34 = getelementptr inbounds %struct.__blake2b_param, ptr %6, i32 0, i32 10
  %35 = getelementptr inbounds [16 x i8], ptr %34, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 1 %35, i8 0, i64 16, i1 false)
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = call i32 @blake2b_init_param(ptr noundef %36, ptr noundef %6)
  store i32 %37, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %38

38:                                               ; preds = %19, %17, %10
  call void @llvm.lifetime.end.p0(i64 64, ptr %6) #4
  %39 = load i32, ptr %3, align 4
  ret i32 %39
}

; 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

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 = { 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: nounwind uwtable
define dso_local i32 @blake2b_init(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.__blake2b_param, align 1
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #4
  %4 = icmp eq ptr %0, null
  br i1 %4, label %15, label %5

5:                                                ; preds = %2
  %6 = add i64 %1, -65
  %or.cond = icmp ult i64 %6, -64
  br i1 %or.cond, label %7, label %8

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

8:                                                ; preds = %5
  %9 = trunc nuw nsw i64 %1 to i8
  store i8 %9, ptr %3, align 1, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 0, ptr %10, align 1, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %3, i64 2
  store i8 1, ptr %11, align 1, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %3, i64 3
  store i8 1, ptr %12, align 1, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %3, i64 4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(60) %13, i8 0, i64 60, i1 false)
  %14 = call i32 @blake2b_init_param(ptr noundef nonnull %0, ptr noundef nonnull %3)
  br label %15

15:                                               ; preds = %2, %8, %7
  %.0 = phi i32 [ -1, %7 ], [ %14, %8 ], [ -1, %2 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #4
  ret i32 %.0
}

; 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

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 = { 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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass