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

; 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.output_t = type { [8 x i32], i64, [64 x i8], i8, i8 }
%struct.blake3_hasher = type { [8 x i32], %struct.blake3_chunk_state, i8, [1760 x i8] }
%struct.blake3_chunk_state = type { [8 x i32], i64, [64 x i8], i8, i8, 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i64 @chunk_state_len(ptr noundef) #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @chunk_state_output(ptr dead_on_unwind noalias writable sret(%struct.output_t) align 8, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @blake3_hasher_finalize_seek(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca %struct.output_t, align 8
  %10 = alloca %struct.output_t, align 8
  %11 = alloca i64, align 8
  %12 = alloca %struct.output_t, align 8
  %13 = alloca %struct.output_t, align 8
  %14 = alloca [64 x i8], align 16
  %15 = alloca %struct.output_t, 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
  %16 = load i64, ptr %8, align 8, !tbaa !9
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %4
  br label %88

19:                                               ; preds = %4
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.blake3_hasher, ptr %20, i32 0, i32 2
  %22 = load i8, ptr %21, align 8, !tbaa !11
  %23 = zext i8 %22 to i32
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %31

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 112, ptr %9) #4
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.blake3_hasher, ptr %26, i32 0, i32 1
  call void @chunk_state_output(ptr dead_on_unwind writable sret(%struct.output_t) align 8 %9, ptr noundef %27)
  %28 = load i64, ptr %6, align 8, !tbaa !9
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load i64, ptr %8, align 8, !tbaa !9
  call void @output_root_bytes(ptr noundef %9, i64 noundef %28, ptr noundef %29, i64 noundef %30)
  call void @llvm.lifetime.end.p0(i64 112, ptr %9) #4
  br label %88

31:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 112, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.blake3_hasher, ptr %32, i32 0, i32 1
  %34 = call i64 @chunk_state_len(ptr noundef %33)
  %35 = icmp ugt i64 %34, 0
  br i1 %35, label %36, label %43

36:                                               ; preds = %31
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.blake3_hasher, ptr %37, i32 0, i32 2
  %39 = load i8, ptr %38, align 8, !tbaa !11
  %40 = zext i8 %39 to i64
  store i64 %40, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 112, ptr %12) #4
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.blake3_hasher, ptr %41, i32 0, i32 1
  call void @chunk_state_output(ptr dead_on_unwind writable sret(%struct.output_t) align 8 %12, ptr noundef %42)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %12, i64 112, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 112, ptr %12) #4
  br label %62

43:                                               ; preds = %31
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.blake3_hasher, ptr %44, i32 0, i32 2
  %46 = load i8, ptr %45, align 8, !tbaa !11
  %47 = zext i8 %46 to i32
  %48 = sub nsw i32 %47, 2
  %49 = sext i32 %48 to i64
  store i64 %49, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 112, ptr %13) #4
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.blake3_hasher, ptr %50, i32 0, i32 3
  %52 = load i64, ptr %11, align 8, !tbaa !9
  %53 = mul i64 %52, 32
  %54 = getelementptr inbounds [1760 x i8], ptr %51, i64 0, i64 %53
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.blake3_hasher, ptr %55, i32 0, i32 0
  %57 = getelementptr inbounds [8 x i32], ptr %56, i64 0, i64 0
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.blake3_hasher, ptr %58, i32 0, i32 1
  %60 = getelementptr inbounds %struct.blake3_chunk_state, ptr %59, i32 0, i32 5
  %61 = load i8, ptr %60, align 2, !tbaa !16
  call void @parent_output(ptr dead_on_unwind writable sret(%struct.output_t) align 8 %13, ptr noundef %54, ptr noundef %57, i8 noundef zeroext %61)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %13, i64 112, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 112, ptr %13) #4
  br label %62

62:                                               ; preds = %43, %36
  br label %63

63:                                               ; preds = %66, %62
  %64 = load i64, ptr %11, align 8, !tbaa !9
  %65 = icmp ugt i64 %64, 0
  br i1 %65, label %66, label %84

66:                                               ; preds = %63
  %67 = load i64, ptr %11, align 8, !tbaa !9
  %68 = sub i64 %67, 1
  store i64 %68, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 64, ptr %14) #4
  %69 = getelementptr inbounds [64 x i8], ptr %14, i64 0, i64 0
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.blake3_hasher, ptr %70, i32 0, i32 3
  %72 = load i64, ptr %11, align 8, !tbaa !9
  %73 = mul i64 %72, 32
  %74 = getelementptr inbounds [1760 x i8], ptr %71, i64 0, i64 %73
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %69, ptr align 1 %74, i64 32, i1 false)
  %75 = getelementptr inbounds [64 x i8], ptr %14, i64 0, i64 32
  call void @output_chaining_value(ptr noundef %10, ptr noundef %75)
  call void @llvm.lifetime.start.p0(i64 112, ptr %15) #4
  %76 = getelementptr inbounds [64 x i8], ptr %14, i64 0, i64 0
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.blake3_hasher, ptr %77, i32 0, i32 0
  %79 = getelementptr inbounds [8 x i32], ptr %78, i64 0, i64 0
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.blake3_hasher, ptr %80, i32 0, i32 1
  %82 = getelementptr inbounds %struct.blake3_chunk_state, ptr %81, i32 0, i32 5
  %83 = load i8, ptr %82, align 2, !tbaa !16
  call void @parent_output(ptr dead_on_unwind writable sret(%struct.output_t) align 8 %15, ptr noundef %76, ptr noundef %79, i8 noundef zeroext %83)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %15, i64 112, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 112, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %14) #4
  br label %63, !llvm.loop !17

84:                                               ; preds = %63
  %85 = load i64, ptr %6, align 8, !tbaa !9
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = load i64, ptr %8, align 8, !tbaa !9
  call void @output_root_bytes(ptr noundef %10, i64 noundef %85, ptr noundef %86, i64 noundef %87)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 112, ptr %10) #4
  br label %88

88:                                               ; preds = %84, %25, %18
  ret void
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @output_root_bytes(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @parent_output(ptr dead_on_unwind noalias writable sret(%struct.output_t) align 8, ptr noundef, ptr noundef, i8 noundef zeroext) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 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 }

!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, !7, i64 144}
!12 = !{!"", !7, i64 0, !13, i64 32, !7, i64 144, !7, i64 145}
!13 = !{!"", !7, i64 0, !10, i64 32, !7, i64 40, !7, i64 104, !7, i64 105, !7, i64 106}
!14 = !{i64 0, i64 32, !15, i64 32, i64 8, !9, i64 40, i64 64, !15, i64 104, i64 1, !15, i64 105, i64 1, !15}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !7, i64 138}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%struct.output_t = type { [8 x i32], i64, [64 x i8], i8, i8 }

; 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: alwaysinline nounwind uwtable
declare hidden i64 @chunk_state_len(ptr noundef) local_unnamed_addr #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @chunk_state_output(ptr dead_on_unwind noalias writable sret(%struct.output_t) align 8, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @blake3_hasher_finalize_seek(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.output_t, align 8
  %6 = alloca %struct.output_t, align 8
  %7 = alloca [64 x i8], align 16
  %8 = alloca %struct.output_t, align 8
  %9 = icmp eq i64 %3, 0
  br i1 %9, label %37, label %10

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %0, i64 144
  %12 = load i8, ptr %11, align 8, !tbaa !5
  %13 = icmp eq i8 %12, 0
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  br i1 %13, label %15, label %16

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %5) #4
  call void @chunk_state_output(ptr dead_on_unwind nonnull writable sret(%struct.output_t) align 8 %5, ptr noundef nonnull %14)
  call void @output_root_bytes(ptr noundef nonnull %5, i64 noundef %1, ptr noundef %2, i64 noundef %3)
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %5) #4
  br label %37

16:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %6) #4
  %17 = tail call i64 @chunk_state_len(ptr noundef nonnull %14)
  %.not = icmp eq i64 %17, 0
  %18 = load i8, ptr %11, align 8, !tbaa !5
  %19 = zext i8 %18 to i64
  br i1 %.not, label %21, label %20

20:                                               ; preds = %16
  call void @chunk_state_output(ptr dead_on_unwind nonnull writable sret(%struct.output_t) align 8 %6, ptr noundef nonnull %14)
  br label %28

21:                                               ; preds = %16
  %22 = add nsw i64 %19, -2
  %23 = getelementptr inbounds i8, ptr %0, i64 145
  %24 = shl nsw i64 %22, 5
  %25 = getelementptr inbounds [1760 x i8], ptr %23, i64 0, i64 %24
  %26 = getelementptr inbounds i8, ptr %0, i64 138
  %27 = load i8, ptr %26, align 2, !tbaa !11
  call void @parent_output(ptr dead_on_unwind nonnull writable sret(%struct.output_t) align 8 %6, ptr noundef nonnull %25, ptr noundef nonnull %0, i8 noundef zeroext %27)
  br label %28

28:                                               ; preds = %21, %20
  %.0 = phi i64 [ %19, %20 ], [ %22, %21 ]
  %.not2324 = icmp eq i64 %.0, 0
  br i1 %.not2324, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %28
  %29 = getelementptr inbounds i8, ptr %0, i64 145
  %30 = getelementptr inbounds i8, ptr %7, i64 32
  %31 = getelementptr inbounds i8, ptr %0, i64 138
  br label %32

32:                                               ; preds = %.lr.ph, %32
  %.125 = phi i64 [ %.0, %.lr.ph ], [ %33, %32 ]
  %33 = add i64 %.125, -1
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %7) #4
  %34 = shl i64 %33, 5
  %35 = getelementptr inbounds [1760 x i8], ptr %29, i64 0, i64 %34
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %7, ptr noundef nonnull align 1 dereferenceable(32) %35, i64 32, i1 false)
  call void @output_chaining_value(ptr noundef nonnull %6, ptr noundef nonnull %30)
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %8) #4
  %36 = load i8, ptr %31, align 2, !tbaa !11
  call void @parent_output(ptr dead_on_unwind nonnull writable sret(%struct.output_t) align 8 %8, ptr noundef nonnull %7, ptr noundef nonnull %0, i8 noundef zeroext %36)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(112) %6, ptr noundef nonnull align 8 dereferenceable(112) %8, i64 112, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %7) #4
  %.not23 = icmp eq i64 %33, 0
  br i1 %.not23, label %._crit_edge, label %32, !llvm.loop !15

._crit_edge:                                      ; preds = %32, %28
  call void @output_root_bytes(ptr noundef nonnull %6, i64 noundef %1, ptr noundef %2, i64 noundef %3)
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %6) #4
  br label %37

37:                                               ; preds = %4, %._crit_edge, %15
  ret void
}

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

; 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: alwaysinline nounwind uwtable
declare hidden void @parent_output(ptr dead_on_unwind noalias writable sret(%struct.output_t) align 8, ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 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 }

!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, !7, i64 144}
!6 = !{!"", !7, i64 0, !9, i64 32, !7, i64 144, !7, i64 145}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"", !7, i64 0, !10, i64 32, !7, i64 40, !7, i64 104, !7, i64 105, !7, i64 106}
!10 = !{!"long", !7, i64 0}
!11 = !{!6, !7, i64 138}
!12 = !{i64 0, i64 32, !13, i64 32, i64 8, !14, i64 40, i64 64, !13, i64 104, i64 1, !13, i64 105, i64 1, !13}
!13 = !{!7, !7, i64 0}
!14 = !{!10, !10, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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