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

; 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
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
  %8 = 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
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %9, i32 0, i32 3
  %11 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %11, ptr %5, align 8, !tbaa !12
  br label %12

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

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

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

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

22:                                               ; preds = %15
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  call void @blake2b_incr(ptr noundef %23)
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  call void @blake2b_compress(ptr noundef %24, i32 noundef -1)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %25, i32 0, i32 4
  %27 = load i64, ptr %26, align 8, !tbaa !15
  %28 = lshr i64 %27, 3
  store i64 %28, ptr %6, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !12
  br label %29

29:                                               ; preds = %44, %22
  %30 = load i64, ptr %7, align 8, !tbaa !12
  %31 = load i64, ptr %6, align 8, !tbaa !12
  %32 = icmp ult i64 %30, %31
  br i1 %32, label %34, label %33

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

34:                                               ; preds = %29
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load i64, ptr %7, align 8, !tbaa !12
  %37 = mul i64 %36, 8
  %38 = getelementptr inbounds i8, ptr %35, i64 %37
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %39, i32 0, i32 0
  %41 = load i64, ptr %7, align 8, !tbaa !12
  %42 = getelementptr inbounds [8 x i64], ptr %40, i64 0, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !12
  call void @store64_le(ptr noundef %38, i64 noundef %43)
  br label %44

44:                                               ; preds = %34
  %45 = load i64, ptr %7, align 8, !tbaa !12
  %46 = add i64 %45, 1
  store i64 %46, ptr %7, align 8, !tbaa !12
  br label %29, !llvm.loop !16

47:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %48 = load i64, ptr %6, align 8, !tbaa !12
  %49 = mul i64 %48, 8
  store i64 %49, ptr %8, align 8, !tbaa !12
  br label %50

50:                                               ; preds = %73, %47
  %51 = load i64, ptr %8, align 8, !tbaa !12
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %52, i32 0, i32 4
  %54 = load i64, ptr %53, align 8, !tbaa !15
  %55 = icmp ult i64 %51, %54
  br i1 %55, label %57, label %56

56:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %76

57:                                               ; preds = %50
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %58, i32 0, i32 0
  %60 = load i64, ptr %8, align 8, !tbaa !12
  %61 = lshr i64 %60, 3
  %62 = getelementptr inbounds [8 x i64], ptr %59, i64 0, i64 %61
  %63 = load i64, ptr %62, align 8, !tbaa !12
  %64 = load i64, ptr %8, align 8, !tbaa !12
  %65 = and i64 %64, 7
  %66 = mul i64 8, %65
  %67 = lshr i64 %63, %66
  %68 = and i64 %67, 255
  %69 = trunc i64 %68 to i8
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = load i64, ptr %8, align 8, !tbaa !12
  %72 = getelementptr inbounds i8, ptr %70, i64 %71
  store i8 %69, ptr %72, align 1, !tbaa !17
  br label %73

73:                                               ; preds = %57
  %74 = load i64, ptr %8, align 8, !tbaa !12
  %75 = add i64 %74, 1
  store i64 %75, ptr %8, align 8, !tbaa !12
  br label %50, !llvm.loop !18

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

; 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_incr(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden void @store64_le(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 = distinct !{!16, !14}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !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
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_incr(ptr noundef %0)
  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
  %.not = icmp ult i64 %7, 8
  br i1 %.not, label %._crit_edge31, label %.lr.ph30

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

._crit_edge31.loopexit:                           ; preds = %.lr.ph30
  %.pre = load i64, ptr %6, align 8, !tbaa !10
  br label %._crit_edge31

._crit_edge31:                                    ; preds = %._crit_edge31.loopexit, %._crit_edge
  %10 = phi i64 [ %.pre, %._crit_edge31.loopexit ], [ %7, %._crit_edge ]
  %11 = and i64 %7, -8
  %12 = icmp ult i64 %11, %10
  br i1 %12, label %.lr.ph34, label %._crit_edge35

.lr.ph30:                                         ; preds = %._crit_edge, %.lr.ph30
  %.02428 = phi i64 [ %17, %.lr.ph30 ], [ 0, %._crit_edge ]
  %13 = shl nuw i64 %.02428, 3
  %14 = getelementptr inbounds i8, ptr %1, i64 %13
  %15 = getelementptr inbounds [8 x i64], ptr %0, i64 0, i64 %.02428
  %16 = load i64, ptr %15, align 8, !tbaa !13
  tail call void @store64_le(ptr noundef %14, i64 noundef %16)
  %17 = add nuw nsw i64 %.02428, 1
  %exitcond36.not = icmp eq i64 %17, %8
  br i1 %exitcond36.not, label %._crit_edge31.loopexit, label %.lr.ph30, !llvm.loop !14

._crit_edge35:                                    ; preds = %.lr.ph34, %._crit_edge31
  tail call void @crypto_wipe(ptr noundef nonnull %0, i64 noundef 224)
  ret void

.lr.ph34:                                         ; preds = %._crit_edge31, %.lr.ph34
  %.032 = phi i64 [ %26, %.lr.ph34 ], [ %11, %._crit_edge31 ]
  %18 = lshr i64 %.032, 3
  %19 = getelementptr inbounds [8 x i64], ptr %0, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !13
  %21 = shl i64 %.032, 3
  %22 = and i64 %21, 56
  %23 = lshr i64 %20, %22
  %24 = trunc i64 %23 to i8
  %25 = getelementptr inbounds i8, ptr %1, i64 %.032
  store i8 %24, ptr %25, align 1, !tbaa !15
  %26 = add nuw i64 %.032, 1
  %27 = load i64, ptr %6, align 8, !tbaa !10
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %.lr.ph34, label %._crit_edge35, !llvm.loop !16
}

; 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_incr(ptr 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
declare hidden void @store64_le(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 = distinct !{!14, !12}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !12}


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