; 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: 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_update(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %11, i32 0, i32 3
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = xor i64 %13, -1
  %15 = add i64 %14, 1
  %16 = and i64 %15, 127
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = icmp ule i64 %16, %17
  br i1 %18, label %19, label %26

19:                                               ; preds = %3
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %20, i32 0, i32 3
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = xor i64 %22, -1
  %24 = add i64 %23, 1
  %25 = and i64 %24, 127
  br label %28

26:                                               ; preds = %3
  %27 = load i64, ptr %6, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %26, %19
  %29 = phi i64 [ %25, %19 ], [ %27, %26 ]
  store i64 %29, ptr %7, align 8, !tbaa !9
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %7, align 8, !tbaa !9
  call void @blake2b_update(ptr noundef %30, ptr noundef %31, i64 noundef %32)
  %33 = load i64, ptr %7, align 8, !tbaa !9
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 %33
  store ptr %35, ptr %5, align 8, !tbaa !5
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = load i64, ptr %6, align 8, !tbaa !9
  %38 = sub i64 %37, %36
  store i64 %38, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %69, %28
  %40 = load i64, ptr %8, align 8, !tbaa !9
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = lshr i64 %41, 7
  %43 = icmp ult i64 %40, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %39
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %72

45:                                               ; preds = %39
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  call void @blake2b_end_block(ptr noundef %46)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %61, %45
  %48 = load i64, ptr %10, align 8, !tbaa !9
  %49 = icmp ult i64 %48, 16
  br i1 %49, label %51, label %50

50:                                               ; preds = %47
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %64

51:                                               ; preds = %47
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load i64, ptr %10, align 8, !tbaa !9
  %54 = mul i64 %53, 8
  %55 = getelementptr inbounds i8, ptr %52, i64 %54
  %56 = call i64 @load64_le(ptr noundef %55)
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %57, i32 0, i32 2
  %59 = load i64, ptr %10, align 8, !tbaa !9
  %60 = getelementptr inbounds [16 x i64], ptr %58, i64 0, i64 %59
  store i64 %56, ptr %60, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %51
  %62 = load i64, ptr %10, align 8, !tbaa !9
  %63 = add i64 %62, 1
  store i64 %63, ptr %10, align 8, !tbaa !9
  br label %47, !llvm.loop !13

64:                                               ; preds = %50
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds i8, ptr %65, i64 128
  store ptr %66, ptr %5, align 8, !tbaa !5
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.crypto_blake2b_ctx, ptr %67, i32 0, i32 3
  store i64 128, ptr %68, align 8, !tbaa !11
  br label %69

69:                                               ; preds = %64
  %70 = load i64, ptr %8, align 8, !tbaa !9
  %71 = add i64 %70, 1
  store i64 %71, ptr %8, align 8, !tbaa !9
  br label %39, !llvm.loop !15

72:                                               ; preds = %44
  %73 = load i64, ptr %6, align 8, !tbaa !9
  %74 = and i64 %73, 127
  store i64 %74, ptr %6, align 8, !tbaa !9
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = load i64, ptr %6, align 8, !tbaa !9
  call void @blake2b_update(ptr noundef %75, ptr noundef %76, i64 noundef %77)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden void @blake2b_end_block(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i64 @load64_le(ptr 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 = !{!12, !10, i64 208}
!12 = !{!"", !7, i64 0, !7, i64 64, !7, i64 80, !10, i64 208, !10, i64 216}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !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
define dso_local void @crypto_blake2b_update(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 208
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = sub i64 0, %5
  %7 = and i64 %6, 127
  %. = tail call i64 @llvm.umin.i64(i64 %7, i64 %2)
  tail call void @blake2b_update(ptr noundef %0, ptr noundef %1, i64 noundef %.)
  %8 = getelementptr inbounds i8, ptr %1, i64 %.
  %9 = sub i64 %2, %.
  %.not = icmp ult i64 %9, 128
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %10 = lshr i64 %9, 7
  %11 = getelementptr inbounds i8, ptr %0, i64 80
  %12 = getelementptr inbounds i8, ptr %0, i64 88
  %13 = getelementptr inbounds i8, ptr %0, i64 96
  %14 = getelementptr inbounds i8, ptr %0, i64 104
  %15 = getelementptr inbounds i8, ptr %0, i64 112
  %16 = getelementptr inbounds i8, ptr %0, i64 120
  %17 = getelementptr inbounds i8, ptr %0, i64 128
  %18 = getelementptr inbounds i8, ptr %0, i64 136
  %19 = getelementptr inbounds i8, ptr %0, i64 144
  %20 = getelementptr inbounds i8, ptr %0, i64 152
  %21 = getelementptr inbounds i8, ptr %0, i64 160
  %22 = getelementptr inbounds i8, ptr %0, i64 168
  %23 = getelementptr inbounds i8, ptr %0, i64 176
  %24 = getelementptr inbounds i8, ptr %0, i64 184
  %25 = getelementptr inbounds i8, ptr %0, i64 192
  %26 = getelementptr inbounds i8, ptr %0, i64 200
  br label %28

._crit_edge:                                      ; preds = %28, %3
  %.027.lcssa = phi ptr [ %8, %3 ], [ %60, %28 ]
  %27 = and i64 %9, 127
  tail call void @blake2b_update(ptr noundef nonnull %0, ptr noundef %.027.lcssa, i64 noundef %27)
  ret void

28:                                               ; preds = %.lr.ph, %28
  %.02632 = phi i64 [ 0, %.lr.ph ], [ %61, %28 ]
  %.02731 = phi ptr [ %8, %.lr.ph ], [ %60, %28 ]
  tail call void @blake2b_end_block(ptr noundef nonnull %0)
  %29 = tail call i64 @load64_le(ptr noundef %.02731)
  store i64 %29, ptr %11, align 8, !tbaa !10
  %30 = getelementptr inbounds i8, ptr %.02731, i64 8
  %31 = tail call i64 @load64_le(ptr noundef nonnull %30)
  store i64 %31, ptr %12, align 8, !tbaa !10
  %32 = getelementptr inbounds i8, ptr %.02731, i64 16
  %33 = tail call i64 @load64_le(ptr noundef nonnull %32)
  store i64 %33, ptr %13, align 8, !tbaa !10
  %34 = getelementptr inbounds i8, ptr %.02731, i64 24
  %35 = tail call i64 @load64_le(ptr noundef nonnull %34)
  store i64 %35, ptr %14, align 8, !tbaa !10
  %36 = getelementptr inbounds i8, ptr %.02731, i64 32
  %37 = tail call i64 @load64_le(ptr noundef nonnull %36)
  store i64 %37, ptr %15, align 8, !tbaa !10
  %38 = getelementptr inbounds i8, ptr %.02731, i64 40
  %39 = tail call i64 @load64_le(ptr noundef nonnull %38)
  store i64 %39, ptr %16, align 8, !tbaa !10
  %40 = getelementptr inbounds i8, ptr %.02731, i64 48
  %41 = tail call i64 @load64_le(ptr noundef nonnull %40)
  store i64 %41, ptr %17, align 8, !tbaa !10
  %42 = getelementptr inbounds i8, ptr %.02731, i64 56
  %43 = tail call i64 @load64_le(ptr noundef nonnull %42)
  store i64 %43, ptr %18, align 8, !tbaa !10
  %44 = getelementptr inbounds i8, ptr %.02731, i64 64
  %45 = tail call i64 @load64_le(ptr noundef nonnull %44)
  store i64 %45, ptr %19, align 8, !tbaa !10
  %46 = getelementptr inbounds i8, ptr %.02731, i64 72
  %47 = tail call i64 @load64_le(ptr noundef nonnull %46)
  store i64 %47, ptr %20, align 8, !tbaa !10
  %48 = getelementptr inbounds i8, ptr %.02731, i64 80
  %49 = tail call i64 @load64_le(ptr noundef nonnull %48)
  store i64 %49, ptr %21, align 8, !tbaa !10
  %50 = getelementptr inbounds i8, ptr %.02731, i64 88
  %51 = tail call i64 @load64_le(ptr noundef nonnull %50)
  store i64 %51, ptr %22, align 8, !tbaa !10
  %52 = getelementptr inbounds i8, ptr %.02731, i64 96
  %53 = tail call i64 @load64_le(ptr noundef nonnull %52)
  store i64 %53, ptr %23, align 8, !tbaa !10
  %54 = getelementptr inbounds i8, ptr %.02731, i64 104
  %55 = tail call i64 @load64_le(ptr noundef nonnull %54)
  store i64 %55, ptr %24, align 8, !tbaa !10
  %56 = getelementptr inbounds i8, ptr %.02731, i64 112
  %57 = tail call i64 @load64_le(ptr noundef nonnull %56)
  store i64 %57, ptr %25, align 8, !tbaa !10
  %58 = getelementptr inbounds i8, ptr %.02731, i64 120
  %59 = tail call i64 @load64_le(ptr noundef nonnull %58)
  store i64 %59, ptr %26, align 8, !tbaa !10
  %60 = getelementptr inbounds i8, ptr %.02731, i64 128
  store i64 128, ptr %4, align 8, !tbaa !5
  %61 = add nuw nsw i64 %.02632, 1
  %exitcond.not = icmp eq i64 %61, %10
  br i1 %exitcond.not, label %._crit_edge, label %28, !llvm.loop !11
}

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #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 nosync nounwind speculatable willreturn memory(none) }

!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 = !{!9, !9, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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