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

; Function Attrs: nounwind uwtable
declare dso_local void @crypto_wipe(ptr noundef, i64 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 hidden void @blake2b_set_input(ptr noundef, i8 noundef zeroext, i64 noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @crypto_blake2b_final(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  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 8, ptr %5) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %8, i32 0, i32 3
  %10 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %10, ptr %5, align 8, !tbaa !12
  br label %11

11:                                               ; preds = %18, %2
  %12 = load i64, ptr %5, align 8, !tbaa !12
  %13 = icmp ult i64 %12, 128
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %21

15:                                               ; preds = %11
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load i64, ptr %5, align 8, !tbaa !12
  call void @blake2b_set_input(ptr noundef %16, i8 noundef zeroext 0, i64 noundef %17)
  br label %18

18:                                               ; preds = %15
  %19 = load i64, ptr %5, align 8, !tbaa !12
  %20 = add i64 %19, 1
  store i64 %20, ptr %5, align 8, !tbaa !12
  br label %11, !llvm.loop !13

21:                                               ; preds = %14
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  call void @blake2b_compress(ptr noundef %22, i32 noundef 1)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %23, i32 0, i32 4
  %25 = load i64, ptr %24, align 8, !tbaa !15
  %26 = lshr i64 %25, 3
  store i64 %26, ptr %6, align 8, !tbaa !12
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds [8 x i64], ptr %29, i64 0, i64 0
  %31 = load i64, ptr %6, align 8, !tbaa !12
  call void @store64_le_buf(ptr noundef %27, ptr noundef %30, i64 noundef %31)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %32 = load i64, ptr %6, align 8, !tbaa !12
  %33 = shl i64 %32, 3
  store i64 %33, ptr %7, align 8, !tbaa !12
  br label %34

34:                                               ; preds = %57, %21
  %35 = load i64, ptr %7, align 8, !tbaa !12
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %36, i32 0, i32 4
  %38 = load i64, ptr %37, align 8, !tbaa !15
  %39 = icmp ult i64 %35, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %60

41:                                               ; preds = %34
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %42, i32 0, i32 0
  %44 = load i64, ptr %7, align 8, !tbaa !12
  %45 = lshr i64 %44, 3
  %46 = getelementptr inbounds [8 x i64], ptr %43, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !12
  %48 = load i64, ptr %7, align 8, !tbaa !12
  %49 = and i64 %48, 7
  %50 = mul i64 8, %49
  %51 = lshr i64 %47, %50
  %52 = and i64 %51, 255
  %53 = trunc i64 %52 to i8
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load i64, ptr %7, align 8, !tbaa !12
  %56 = getelementptr inbounds i8, ptr %54, i64 %55
  store i8 %53, ptr %56, align 1, !tbaa !16
  br label %57

57:                                               ; preds = %41
  %58 = load i64, ptr %7, align 8, !tbaa !12
  %59 = add i64 %58, 1
  store i64 %59, ptr %7, align 8, !tbaa !12
  br label %34, !llvm.loop !17

60:                                               ; preds = %40
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  call void @crypto_wipe(ptr noundef %61, i64 noundef 224)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  ret void
}

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

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 = { 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, !11, i64 208}
!10 = !{!"", !7, i64 0, !7, i64 64, !7, i64 80, !11, i64 208, !11, i64 216}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !11, i64 216}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !14}


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

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

; Function Attrs: nounwind uwtable
declare hidden void @blake2b_set_input(ptr noundef, i8 noundef zeroext, i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @crypto_blake2b_final(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 208
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = icmp ult i64 %4, 128
  br i1 %5, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %2
  tail call void @blake2b_compress(ptr noundef %0, i32 noundef 1)
  %6 = getelementptr inbounds i8, ptr %0, i64 216
  %7 = load i64, ptr %6, align 8, !tbaa !10
  %8 = lshr i64 %7, 3
  tail call void @store64_le_buf(ptr noundef %1, ptr noundef %0, i64 noundef %8)
  %9 = and i64 %7, -8
  %10 = load i64, ptr %6, align 8, !tbaa !10
  %11 = icmp ult i64 %9, %10
  br i1 %11, label %.lr.ph23, label %._crit_edge24

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.01920 = phi i64 [ %12, %.lr.ph ], [ %4, %2 ]
  tail call void @blake2b_set_input(ptr noundef %0, i8 noundef zeroext 0, i64 noundef %.01920)
  %12 = add i64 %.01920, 1
  %exitcond.not = icmp eq i64 %12, 128
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge24:                                    ; preds = %.lr.ph23, %._crit_edge
  tail call void @crypto_wipe(ptr noundef nonnull %0, i64 noundef 224)
  ret void

.lr.ph23:                                         ; preds = %._crit_edge, %.lr.ph23
  %.021 = phi i64 [ %21, %.lr.ph23 ], [ %9, %._crit_edge ]
  %13 = lshr i64 %.021, 3
  %14 = getelementptr inbounds [8 x i64], ptr %0, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !13
  %16 = shl i64 %.021, 3
  %17 = and i64 %16, 56
  %18 = lshr i64 %15, %17
  %19 = trunc i64 %18 to i8
  %20 = getelementptr inbounds i8, ptr %1, i64 %.021
  store i8 %19, ptr %20, align 1, !tbaa !14
  %21 = add nuw i64 %.021, 1
  %22 = load i64, ptr %6, align 8, !tbaa !10
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %.lr.ph23, label %._crit_edge24, !llvm.loop !15
}

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

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

!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, !9, i64 208}
!6 = !{!"", !7, i64 0, !7, i64 64, !7, i64 80, !9, i64 208, !9, i64 216}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!6, !9, i64 216}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!9, !9, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !12}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass