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

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

; Function Attrs: nounwind uwtable
define dso_local void @blake3_hash_many_sse2(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, i1 noundef zeroext %5, i8 noundef zeroext %6, i8 noundef zeroext %7, i8 noundef zeroext %8, ptr noundef %9) #0 {
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i8, align 1
  %17 = alloca i8, align 1
  %18 = alloca i8, align 1
  %19 = alloca i8, align 1
  %20 = alloca ptr, align 8
  store ptr %0, ptr %11, align 8, !tbaa !5
  store i64 %1, ptr %12, align 8, !tbaa !9
  store i64 %2, ptr %13, align 8, !tbaa !9
  store ptr %3, ptr %14, align 8, !tbaa !5
  store i64 %4, ptr %15, align 8, !tbaa !9
  %21 = zext i1 %5 to i8
  store i8 %21, ptr %16, align 1, !tbaa !11
  store i8 %6, ptr %17, align 1, !tbaa !13
  store i8 %7, ptr %18, align 1, !tbaa !13
  store i8 %8, ptr %19, align 1, !tbaa !13
  store ptr %9, ptr %20, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %41, %10
  %23 = load i64, ptr %12, align 8, !tbaa !9
  %24 = icmp uge i64 %23, 4
  br i1 %24, label %25, label %48

25:                                               ; preds = %22
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = load i64, ptr %13, align 8, !tbaa !9
  %28 = load ptr, ptr %14, align 8, !tbaa !5
  %29 = load i64, ptr %15, align 8, !tbaa !9
  %30 = load i8, ptr %16, align 1, !tbaa !11, !range !14, !noundef !15
  %31 = trunc i8 %30 to i1
  %32 = load i8, ptr %17, align 1, !tbaa !13
  %33 = load i8, ptr %18, align 1, !tbaa !13
  %34 = load i8, ptr %19, align 1, !tbaa !13
  %35 = load ptr, ptr %20, align 8, !tbaa !5
  call void @blake3_hash4_sse2(ptr noundef %26, i64 noundef %27, ptr noundef %28, i64 noundef %29, i1 noundef zeroext %31, i8 noundef zeroext %32, i8 noundef zeroext %33, i8 noundef zeroext %34, ptr noundef %35)
  %36 = load i8, ptr %16, align 1, !tbaa !11, !range !14, !noundef !15
  %37 = trunc i8 %36 to i1
  br i1 %37, label %38, label %41

38:                                               ; preds = %25
  %39 = load i64, ptr %15, align 8, !tbaa !9
  %40 = add i64 %39, 4
  store i64 %40, ptr %15, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %38, %25
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = getelementptr inbounds ptr, ptr %42, i64 4
  store ptr %43, ptr %11, align 8, !tbaa !5
  %44 = load i64, ptr %12, align 8, !tbaa !9
  %45 = sub i64 %44, 4
  store i64 %45, ptr %12, align 8, !tbaa !9
  %46 = load ptr, ptr %20, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 128
  store ptr %47, ptr %20, align 8, !tbaa !5
  br label %22, !llvm.loop !16

48:                                               ; preds = %22
  br label %49

49:                                               ; preds = %68, %48
  %50 = load i64, ptr %12, align 8, !tbaa !9
  %51 = icmp ugt i64 %50, 0
  br i1 %51, label %52, label %75

52:                                               ; preds = %49
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = getelementptr inbounds ptr, ptr %53, i64 0
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = load i64, ptr %13, align 8, !tbaa !9
  %57 = load ptr, ptr %14, align 8, !tbaa !5
  %58 = load i64, ptr %15, align 8, !tbaa !9
  %59 = load i8, ptr %17, align 1, !tbaa !13
  %60 = load i8, ptr %18, align 1, !tbaa !13
  %61 = load i8, ptr %19, align 1, !tbaa !13
  %62 = load ptr, ptr %20, align 8, !tbaa !5
  call void @hash_one_sse2(ptr noundef %55, i64 noundef %56, ptr noundef %57, i64 noundef %58, i8 noundef zeroext %59, i8 noundef zeroext %60, i8 noundef zeroext %61, ptr noundef %62)
  %63 = load i8, ptr %16, align 1, !tbaa !11, !range !14, !noundef !15
  %64 = trunc i8 %63 to i1
  br i1 %64, label %65, label %68

65:                                               ; preds = %52
  %66 = load i64, ptr %15, align 8, !tbaa !9
  %67 = add i64 %66, 1
  store i64 %67, ptr %15, align 8, !tbaa !9
  br label %68

68:                                               ; preds = %65, %52
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = getelementptr inbounds ptr, ptr %69, i64 1
  store ptr %70, ptr %11, align 8, !tbaa !5
  %71 = load i64, ptr %12, align 8, !tbaa !9
  %72 = sub i64 %71, 1
  store i64 %72, ptr %12, align 8, !tbaa !9
  %73 = load ptr, ptr %20, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i64 32
  store ptr %74, ptr %20, align 8, !tbaa !5
  br label %49, !llvm.loop !18

75:                                               ; preds = %49
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @blake3_hash4_sse2(ptr noundef, i64 noundef, ptr noundef, i64 noundef, i1 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, ptr noundef) #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @hash_one_sse2(ptr noundef, i64 noundef, ptr noundef, i64 noundef, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, ptr noundef) #2

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 = { 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 #2 = { 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" }

!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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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 @blake3_hash_many_sse2(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, i1 noundef zeroext %5, i8 noundef zeroext %6, i8 noundef zeroext %7, i8 noundef zeroext %8, ptr noundef %9) local_unnamed_addr #0 {
  %11 = icmp ugt i64 %1, 3
  br i1 %11, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %10
  br i1 %5, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %.038.us = phi ptr [ %15, %.lr.ph.split.us ], [ %9, %.lr.ph ]
  %.02837.us = phi ptr [ %13, %.lr.ph.split.us ], [ %0, %.lr.ph ]
  %.03036.us = phi i64 [ %14, %.lr.ph.split.us ], [ %1, %.lr.ph ]
  %.03235.us = phi i64 [ %12, %.lr.ph.split.us ], [ %4, %.lr.ph ]
  tail call void @blake3_hash4_sse2(ptr noundef %.02837.us, i64 noundef %2, ptr noundef %3, i64 noundef %.03235.us, i1 noundef zeroext true, i8 noundef zeroext %6, i8 noundef zeroext %7, i8 noundef zeroext %8, ptr noundef %.038.us)
  %12 = add i64 %.03235.us, 4
  %13 = getelementptr inbounds i8, ptr %.02837.us, i64 32
  %14 = add i64 %.03036.us, -4
  %15 = getelementptr inbounds i8, ptr %.038.us, i64 128
  %16 = icmp ugt i64 %14, 3
  br i1 %16, label %.lr.ph.split.us, label %.preheader, !llvm.loop !5

.preheader:                                       ; preds = %.lr.ph.split, %.lr.ph.split.us, %10
  %.032.lcssa = phi i64 [ %4, %10 ], [ %12, %.lr.ph.split.us ], [ %4, %.lr.ph.split ]
  %.030.lcssa = phi i64 [ %1, %10 ], [ %14, %.lr.ph.split.us ], [ %19, %.lr.ph.split ]
  %.028.lcssa = phi ptr [ %0, %10 ], [ %13, %.lr.ph.split.us ], [ %18, %.lr.ph.split ]
  %.0.lcssa = phi ptr [ %9, %10 ], [ %15, %.lr.ph.split.us ], [ %20, %.lr.ph.split ]
  %.not45 = icmp eq i64 %.030.lcssa, 0
  br i1 %.not45, label %._crit_edge, label %.lr.ph50

.lr.ph50:                                         ; preds = %.preheader
  %17 = zext i1 %5 to i64
  br label %22

.lr.ph.split:                                     ; preds = %.lr.ph, %.lr.ph.split
  %.038 = phi ptr [ %20, %.lr.ph.split ], [ %9, %.lr.ph ]
  %.02837 = phi ptr [ %18, %.lr.ph.split ], [ %0, %.lr.ph ]
  %.03036 = phi i64 [ %19, %.lr.ph.split ], [ %1, %.lr.ph ]
  tail call void @blake3_hash4_sse2(ptr noundef %.02837, i64 noundef %2, ptr noundef %3, i64 noundef %4, i1 noundef zeroext false, i8 noundef zeroext %6, i8 noundef zeroext %7, i8 noundef zeroext %8, ptr noundef %.038)
  %18 = getelementptr inbounds i8, ptr %.02837, i64 32
  %19 = add i64 %.03036, -4
  %20 = getelementptr inbounds i8, ptr %.038, i64 128
  %21 = icmp ugt i64 %19, 3
  br i1 %21, label %.lr.ph.split, label %.preheader, !llvm.loop !5

22:                                               ; preds = %.lr.ph50, %22
  %.149 = phi ptr [ %.0.lcssa, %.lr.ph50 ], [ %26, %22 ]
  %.12948 = phi ptr [ %.028.lcssa, %.lr.ph50 ], [ %24, %22 ]
  %.13147 = phi i64 [ %.030.lcssa, %.lr.ph50 ], [ %25, %22 ]
  %.246 = phi i64 [ %.032.lcssa, %.lr.ph50 ], [ %spec.select34, %22 ]
  %23 = load ptr, ptr %.12948, align 8, !tbaa !7
  tail call void @hash_one_sse2(ptr noundef %23, i64 noundef %2, ptr noundef %3, i64 noundef %.246, i8 noundef zeroext %6, i8 noundef zeroext %7, i8 noundef zeroext %8, ptr noundef %.149)
  %spec.select34 = add i64 %.246, %17
  %24 = getelementptr inbounds i8, ptr %.12948, i64 8
  %25 = add nsw i64 %.13147, -1
  %26 = getelementptr inbounds i8, ptr %.149, i64 32
  %.not = icmp eq i64 %25, 0
  br i1 %.not, label %._crit_edge, label %22, !llvm.loop !11

._crit_edge:                                      ; preds = %22, %.preheader
  ret void
}

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

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

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 = { 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 #2 = { 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = distinct !{!11, !6}


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