; LLVM IR from LoupVaillant/Monocypher-Utils :: src (monocypher)

; 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.crypto_blake2b_ctx = type { [8 x i64], [2 x i64], [16 x i64], i64, i64 }

@iv = external hidden constant [8 x i64], align 16
@zero = external hidden constant [128 x i8], align 16

; 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
define dso_local void @crypto_blake2b_general_init(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %22, %4
  %11 = load i64, ptr %9, align 8, !tbaa !9
  %12 = icmp ult i64 %11, 8
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %25

14:                                               ; preds = %10
  %15 = load i64, ptr %9, align 8, !tbaa !9
  %16 = getelementptr inbounds [8 x i64], ptr @iv, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %18, i32 0, i32 0
  %20 = load i64, ptr %9, align 8, !tbaa !9
  %21 = getelementptr inbounds [8 x i64], ptr %19, i64 0, i64 %20
  store i64 %17, ptr %21, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %14
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = add i64 %23, 1
  store i64 %24, ptr %9, align 8, !tbaa !9
  br label %10, !llvm.loop !11

25:                                               ; preds = %13
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = shl i64 %26, 8
  %28 = xor i64 16842752, %27
  %29 = load i64, ptr %6, align 8, !tbaa !9
  %30 = xor i64 %28, %29
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds [8 x i64], ptr %32, i64 0, i64 0
  %34 = load i64, ptr %33, align 8, !tbaa !9
  %35 = xor i64 %34, %30
  store i64 %35, ptr %33, align 8, !tbaa !9
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %36, i32 0, i32 1
  %38 = getelementptr inbounds [2 x i64], ptr %37, i64 0, i64 0
  store i64 0, ptr %38, align 8, !tbaa !9
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %39, i32 0, i32 1
  %41 = getelementptr inbounds [2 x i64], ptr %40, i64 0, i64 1
  store i64 0, ptr %41, align 8, !tbaa !9
  %42 = load i64, ptr %6, align 8, !tbaa !9
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %43, i32 0, i32 4
  store i64 %42, ptr %44, align 8, !tbaa !13
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %45, i32 0, i32 3
  store i64 0, ptr %46, align 8, !tbaa !15
  %47 = load i64, ptr %8, align 8, !tbaa !9
  %48 = icmp ugt i64 %47, 0
  br i1 %48, label %49, label %56

49:                                               ; preds = %25
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load i64, ptr %8, align 8, !tbaa !9
  call void @crypto_blake2b_update(ptr noundef %50, ptr noundef %51, i64 noundef %52)
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load i64, ptr %8, align 8, !tbaa !9
  %55 = sub i64 128, %54
  call void @crypto_blake2b_update(ptr noundef %53, ptr noundef @zero, i64 noundef %55)
  br label %56

56:                                               ; preds = %49, %25
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @crypto_blake2b_update(ptr noundef, ptr noundef, i64 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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 216}
!14 = !{!"", !7, i64 0, !7, i64 64, !7, i64 80, !10, i64 208, !10, i64 216}
!15 = !{!14, !10, i64 208}


; 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"

@iv = external hidden local_unnamed_addr constant [8 x i64], align 16
@zero = external hidden constant [128 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local void @crypto_blake2b_general_init(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = load i64, ptr @iv, align 16, !tbaa !5
  store i64 %5, ptr %0, align 8, !tbaa !5
  %6 = load i64, ptr getelementptr inbounds (i8, ptr @iv, i64 8), align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %6, ptr %7, align 8, !tbaa !5
  %8 = load i64, ptr getelementptr inbounds (i8, ptr @iv, i64 16), align 16, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %8, ptr %9, align 8, !tbaa !5
  %10 = load i64, ptr getelementptr inbounds (i8, ptr @iv, i64 24), align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %10, ptr %11, align 8, !tbaa !5
  %12 = load i64, ptr getelementptr inbounds (i8, ptr @iv, i64 32), align 16, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %12, ptr %13, align 8, !tbaa !5
  %14 = load i64, ptr getelementptr inbounds (i8, ptr @iv, i64 40), align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 %14, ptr %15, align 8, !tbaa !5
  %16 = load i64, ptr getelementptr inbounds (i8, ptr @iv, i64 48), align 16, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 %16, ptr %17, align 8, !tbaa !5
  %18 = load i64, ptr getelementptr inbounds (i8, ptr @iv, i64 56), align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %0, i64 56
  store i64 %18, ptr %19, align 8, !tbaa !5
  %20 = shl i64 %3, 8
  %21 = xor i64 %20, %5
  %22 = xor i64 %21, %1
  %23 = xor i64 %22, 16842752
  store i64 %23, ptr %0, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %0, i64 64
  %25 = getelementptr inbounds i8, ptr %0, i64 216
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %24, i8 0, i64 16, i1 false)
  store i64 %1, ptr %25, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %0, i64 208
  store i64 0, ptr %26, align 8, !tbaa !11
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %29, label %27

27:                                               ; preds = %4
  tail call void @crypto_blake2b_update(ptr noundef nonnull %0, ptr noundef %2, i64 noundef %3)
  %28 = sub i64 128, %3
  tail call void @crypto_blake2b_update(ptr noundef nonnull %0, ptr noundef nonnull @zero, i64 noundef %28)
  br label %29

29:                                               ; preds = %27, %4
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

!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, !6, i64 216}
!10 = !{!"", !7, i64 0, !7, i64 64, !7, i64 80, !6, i64 208, !6, i64 216}
!11 = !{!10, !6, i64 208}


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