; LLVM IR from philanc/luazen :: src/mono (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

; 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
  %10 = alloca [128 x i8], align 16
  %11 = 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) #3
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %24, %4
  %13 = load i64, ptr %9, align 8, !tbaa !9
  %14 = icmp ult i64 %13, 8
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %27

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

24:                                               ; preds = %16
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = add i64 %25, 1
  store i64 %26, ptr %9, align 8, !tbaa !9
  br label %12, !llvm.loop !11

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

51:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 128, ptr %10) #3
  call void @llvm.memset.p0.i64(ptr align 16 %10, i8 0, i64 128, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %52

52:                                               ; preds = %64, %51
  %53 = load i64, ptr %11, align 8, !tbaa !9
  %54 = load i64, ptr %8, align 8, !tbaa !9
  %55 = icmp ult i64 %53, %54
  br i1 %55, label %57, label %56

56:                                               ; preds = %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %67

57:                                               ; preds = %52
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load i64, ptr %11, align 8, !tbaa !9
  %60 = getelementptr inbounds i8, ptr %58, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !16
  %62 = load i64, ptr %11, align 8, !tbaa !9
  %63 = getelementptr inbounds [128 x i8], ptr %10, i64 0, i64 %62
  store i8 %61, ptr %63, align 1, !tbaa !16
  br label %64

64:                                               ; preds = %57
  %65 = load i64, ptr %11, align 8, !tbaa !9
  %66 = add i64 %65, 1
  store i64 %66, ptr %11, align 8, !tbaa !9
  br label %52, !llvm.loop !17

67:                                               ; preds = %56
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %68, i32 0, i32 2
  %70 = getelementptr inbounds [16 x i64], ptr %69, i64 0, i64 0
  %71 = getelementptr inbounds [128 x i8], ptr %10, i64 0, i64 0
  call void @load64_le_buf(ptr noundef %70, ptr noundef %71, i64 noundef 16)
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %72, i32 0, i32 3
  store i64 128, ptr %73, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 128, ptr %10) #3
  br label %74

74:                                               ; preds = %67, %27
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare hidden void @load64_le_buf(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !12}


; 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

; 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
define dso_local void @crypto_blake2b_general_init(ptr noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3) local_unnamed_addr #1 {
  %5 = alloca [128 x i8], align 16
  %6 = load i64, ptr @iv, align 16, !tbaa !5
  store i64 %6, ptr %0, align 8, !tbaa !5
  %7 = load i64, ptr getelementptr inbounds (i8, ptr @iv, i64 8), align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %7, ptr %8, align 8, !tbaa !5
  %9 = load i64, ptr getelementptr inbounds (i8, ptr @iv, i64 16), align 16, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %9, ptr %10, align 8, !tbaa !5
  %11 = load i64, ptr getelementptr inbounds (i8, ptr @iv, i64 24), align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %11, ptr %12, align 8, !tbaa !5
  %13 = load i64, ptr getelementptr inbounds (i8, ptr @iv, i64 32), align 16, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %13, ptr %14, align 8, !tbaa !5
  %15 = load i64, ptr getelementptr inbounds (i8, ptr @iv, i64 40), align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 %15, ptr %16, align 8, !tbaa !5
  %17 = load i64, ptr getelementptr inbounds (i8, ptr @iv, i64 48), align 16, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 %17, ptr %18, align 8, !tbaa !5
  %19 = load i64, ptr getelementptr inbounds (i8, ptr @iv, i64 56), align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %0, i64 56
  store i64 %19, ptr %20, align 8, !tbaa !5
  %21 = shl i64 %3, 8
  %22 = xor i64 %21, %6
  %23 = xor i64 %22, %1
  %24 = xor i64 %23, 16842752
  store i64 %24, ptr %0, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %0, i64 64
  %26 = getelementptr inbounds i8, ptr %0, i64 216
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %25, i8 0, i64 16, i1 false)
  store i64 %1, ptr %26, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %0, i64 208
  store i64 0, ptr %27, align 8, !tbaa !11
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %34, label %28

28:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %5) #4
  %29 = icmp ugt i64 %3, 127
  %30 = sub i64 128, %3
  %31 = select i1 %29, i64 0, i64 %30
  %32 = getelementptr i8, ptr %5, i64 %3
  call void @llvm.memset.p0.i64(ptr align 1 %32, i8 0, i64 %31, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %5, ptr align 1 %2, i64 %3, i1 false), !tbaa !12
  %33 = getelementptr inbounds i8, ptr %0, i64 80
  call void @load64_le_buf(ptr noundef nonnull %33, ptr noundef nonnull %5, i64 noundef 16)
  store i64 128, ptr %27, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %5) #4
  br label %34

34:                                               ; preds = %28, %4
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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}
!12 = !{!7, !7, i64 0}


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