; LLVM IR from DanEngelbrecht/longtail :: lib/blake2/ext (blake2s)

; 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.blake2s_state__ = type { [8 x i32], [2 x i32], [2 x i32], [64 x i8], i64, i64, i8 }

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @store32(ptr noundef, i32 noundef) #2

; 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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @secure_zero_memory(ptr noundef, i64 noundef) #2

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

; Function Attrs: nounwind uwtable
declare hidden void @blake2s_compress(ptr noundef, ptr noundef) #5

; Function Attrs: nounwind uwtable
define dso_local i32 @blake2s_final(ptr noundef %0, ptr noundef %1, i64 noundef %2) #4 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca [32 x i8], align 16
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #6
  call void @llvm.memset.p0.i64(ptr align 16 %8, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %19, label %13

13:                                               ; preds = %3
  %14 = load i64, ptr %7, align 8, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.blake2s_state__, ptr %15, i32 0, i32 5
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = icmp ult i64 %14, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %13, %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %70

20:                                               ; preds = %13
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call i32 @blake2s_is_lastblock(ptr noundef %21)
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %20
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %70

25:                                               ; preds = %20
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.blake2s_state__, ptr %27, i32 0, i32 4
  %29 = load i64, ptr %28, align 8, !tbaa !13
  %30 = trunc i64 %29 to i32
  call void @blake2s_increment_counter(ptr noundef %26, i32 noundef %30)
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  call void @blake2s_set_lastblock(ptr noundef %31)
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.blake2s_state__, ptr %32, i32 0, i32 3
  %34 = getelementptr inbounds [64 x i8], ptr %33, i64 0, i64 0
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.blake2s_state__, ptr %35, i32 0, i32 4
  %37 = load i64, ptr %36, align 8, !tbaa !13
  %38 = getelementptr inbounds i8, ptr %34, i64 %37
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.blake2s_state__, ptr %39, i32 0, i32 4
  %41 = load i64, ptr %40, align 8, !tbaa !13
  %42 = sub i64 64, %41
  call void @llvm.memset.p0.i64(ptr align 1 %38, i8 0, i64 %42, i1 false)
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.blake2s_state__, ptr %44, i32 0, i32 3
  %46 = getelementptr inbounds [64 x i8], ptr %45, i64 0, i64 0
  call void @blake2s_compress(ptr noundef %43, ptr noundef %46)
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %60, %25
  %48 = load i64, ptr %9, align 8, !tbaa !9
  %49 = icmp ult i64 %48, 8
  br i1 %49, label %50, label %63

50:                                               ; preds = %47
  %51 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  %52 = load i64, ptr %9, align 8, !tbaa !9
  %53 = mul i64 4, %52
  %54 = getelementptr inbounds i8, ptr %51, i64 %53
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.blake2s_state__, ptr %55, i32 0, i32 0
  %57 = load i64, ptr %9, align 8, !tbaa !9
  %58 = getelementptr inbounds [8 x i32], ptr %56, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !14
  call void @store32(ptr noundef %54, i32 noundef %59)
  br label %60

60:                                               ; preds = %50
  %61 = load i64, ptr %9, align 8, !tbaa !9
  %62 = add i64 %61, 1
  store i64 %62, ptr %9, align 8, !tbaa !9
  br label %47, !llvm.loop !16

63:                                               ; preds = %47
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.blake2s_state__, ptr %66, i32 0, i32 5
  %68 = load i64, ptr %67, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %64, ptr align 16 %65, i64 %68, i1 false)
  %69 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  call void @secure_zero_memory(ptr noundef %69, i64 noundef 32)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %70

70:                                               ; preds = %63, %24, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #6
  %71 = load i32, ptr %4, align 4
  ret i32 %71
}

; Function Attrs: nounwind uwtable
declare hidden i32 @blake2s_is_lastblock(ptr noundef) #4

; Function Attrs: nounwind uwtable
declare hidden void @blake2s_set_lastblock(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { inlinehint 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nounwind uwtable "min-legal-vector-width"="128" "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 #6 = { 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 120}
!12 = !{!"blake2s_state__", !7, i64 0, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 112, !10, i64 120, !7, i64 128}
!13 = !{!12, !10, i64 112}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @store32(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @secure_zero_memory(ptr noundef, i64 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare hidden void @blake2s_compress(ptr noundef, ptr noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @blake2s_final(ptr noundef %0, ptr noundef writeonly %1, i64 noundef %2) local_unnamed_addr #4 {
  %4 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %4, i8 0, i64 32, i1 false)
  %5 = icmp eq ptr %1, null
  br i1 %5, label %43, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 120
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = icmp ugt i64 %8, %2
  br i1 %9, label %43, label %10

10:                                               ; preds = %6
  %11 = tail call i32 @blake2s_is_lastblock(ptr noundef nonnull %0)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %43

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %0, i64 112
  %14 = load i64, ptr %13, align 8, !tbaa !10
  %15 = trunc i64 %14 to i32
  tail call void @blake2s_increment_counter(ptr noundef nonnull %0, i32 noundef %15)
  tail call void @blake2s_set_lastblock(ptr noundef nonnull %0)
  %16 = getelementptr inbounds i8, ptr %0, i64 48
  %17 = load i64, ptr %13, align 8, !tbaa !10
  %18 = getelementptr inbounds i8, ptr %16, i64 %17
  %19 = sub i64 64, %17
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %18, i8 0, i64 %19, i1 false)
  tail call void @blake2s_compress(ptr noundef nonnull %0, ptr noundef nonnull %16)
  %20 = load i32, ptr %0, align 4, !tbaa !11
  call void @store32(ptr noundef nonnull %4, i32 noundef %20)
  %21 = getelementptr inbounds i8, ptr %4, i64 4
  %22 = getelementptr inbounds i8, ptr %0, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !11
  call void @store32(ptr noundef nonnull %21, i32 noundef %23)
  %24 = getelementptr inbounds i8, ptr %4, i64 8
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  %26 = load i32, ptr %25, align 4, !tbaa !11
  call void @store32(ptr noundef nonnull %24, i32 noundef %26)
  %27 = getelementptr inbounds i8, ptr %4, i64 12
  %28 = getelementptr inbounds i8, ptr %0, i64 12
  %29 = load i32, ptr %28, align 4, !tbaa !11
  call void @store32(ptr noundef nonnull %27, i32 noundef %29)
  %30 = getelementptr inbounds i8, ptr %4, i64 16
  %31 = getelementptr inbounds i8, ptr %0, i64 16
  %32 = load i32, ptr %31, align 4, !tbaa !11
  call void @store32(ptr noundef nonnull %30, i32 noundef %32)
  %33 = getelementptr inbounds i8, ptr %4, i64 20
  %34 = getelementptr inbounds i8, ptr %0, i64 20
  %35 = load i32, ptr %34, align 4, !tbaa !11
  call void @store32(ptr noundef nonnull %33, i32 noundef %35)
  %36 = getelementptr inbounds i8, ptr %4, i64 24
  %37 = getelementptr inbounds i8, ptr %0, i64 24
  %38 = load i32, ptr %37, align 4, !tbaa !11
  call void @store32(ptr noundef nonnull %36, i32 noundef %38)
  %39 = getelementptr inbounds i8, ptr %4, i64 28
  %40 = getelementptr inbounds i8, ptr %0, i64 28
  %41 = load i32, ptr %40, align 4, !tbaa !11
  call void @store32(ptr noundef nonnull %39, i32 noundef %41)
  %42 = load i64, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %1, ptr nonnull align 16 %4, i64 %42, i1 false)
  call void @secure_zero_memory(ptr noundef nonnull %4, i64 noundef 32)
  br label %43

43:                                               ; preds = %10, %3, %6, %12
  %.019 = phi i32 [ 0, %12 ], [ -1, %6 ], [ -1, %3 ], [ -1, %10 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #6
  ret i32 %.019
}

; Function Attrs: nounwind uwtable
declare hidden i32 @blake2s_is_lastblock(ptr noundef) local_unnamed_addr #4

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { inlinehint 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nounwind uwtable "min-legal-vector-width"="128" "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 #6 = { 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, !9, i64 120}
!6 = !{!"blake2s_state__", !7, i64 0, !7, i64 32, !7, i64 40, !7, i64 48, !9, i64 112, !9, i64 120, !7, i64 128}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!6, !9, i64 112}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


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