; LLVM IR from catid/Zpng :: zstd (fse_compress)

; 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: 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 i64 @FSE_count_simple(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %16, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %17 = load ptr, ptr %10, align 8, !tbaa !5
  %18 = load i64, ptr %9, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %17, i64 %18
  store ptr %19, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load i32, ptr %20, align 4, !tbaa !11
  store i32 %21, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !11
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i32, ptr %12, align 4, !tbaa !11
  %24 = add i32 %23, 1
  %25 = zext i32 %24 to i64
  %26 = mul i64 %25, 4
  call void @llvm.memset.p0.i64(ptr align 4 %22, i8 0, i64 %26, i1 false)
  %27 = load i64, ptr %9, align 8, !tbaa !9
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %4
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %30, align 4, !tbaa !11
  store i64 0, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %85

31:                                               ; preds = %4
  br label %32

32:                                               ; preds = %36, %31
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = icmp ult ptr %33, %34
  br i1 %35, label %36, label %45

36:                                               ; preds = %32
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i32 1
  store ptr %39, ptr %10, align 8, !tbaa !5
  %40 = load i8, ptr %38, align 1, !tbaa !13
  %41 = zext i8 %40 to i64
  %42 = getelementptr inbounds i32, ptr %37, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = add i32 %43, 1
  store i32 %44, ptr %42, align 4, !tbaa !11
  br label %32, !llvm.loop !14

45:                                               ; preds = %32
  br label %46

46:                                               ; preds = %54, %45
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load i32, ptr %12, align 4, !tbaa !11
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr %47, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !11
  %52 = icmp ne i32 %51, 0
  %53 = xor i1 %52, true
  br i1 %53, label %54, label %57

54:                                               ; preds = %46
  %55 = load i32, ptr %12, align 4, !tbaa !11
  %56 = add i32 %55, -1
  store i32 %56, ptr %12, align 4, !tbaa !11
  br label %46, !llvm.loop !16

57:                                               ; preds = %46
  %58 = load i32, ptr %12, align 4, !tbaa !11
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %58, ptr %59, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 0, ptr %15, align 4, !tbaa !11
  br label %60

60:                                               ; preds = %79, %57
  %61 = load i32, ptr %15, align 4, !tbaa !11
  %62 = load i32, ptr %12, align 4, !tbaa !11
  %63 = icmp ule i32 %61, %62
  br i1 %63, label %64, label %82

64:                                               ; preds = %60
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load i32, ptr %15, align 4, !tbaa !11
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds i32, ptr %65, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !11
  %70 = load i32, ptr %13, align 4, !tbaa !11
  %71 = icmp ugt i32 %69, %70
  br i1 %71, label %72, label %78

72:                                               ; preds = %64
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = load i32, ptr %15, align 4, !tbaa !11
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds i32, ptr %73, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !11
  store i32 %77, ptr %13, align 4, !tbaa !11
  br label %78

78:                                               ; preds = %72, %64
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %15, align 4, !tbaa !11
  %81 = add i32 %80, 1
  store i32 %81, ptr %15, align 4, !tbaa !11
  br label %60, !llvm.loop !17

82:                                               ; preds = %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  %83 = load i32, ptr %13, align 4, !tbaa !11
  %84 = zext i32 %83 to i64
  store i64 %84, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %85

85:                                               ; preds = %82, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %86 = load i64, ptr %5, align 8
  ret i64 %86
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


; 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: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local range(i64 0, 4294967296) i64 @FSE_count_simple(ptr nocapture noundef %0, ptr nocapture noundef %1, ptr noundef readonly %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %2, i64 %3
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = add i32 %6, 1
  %8 = zext i32 %7 to i64
  %9 = shl nuw nsw i64 %8, 2
  tail call void @llvm.memset.p0.i64(ptr align 4 %0, i8 0, i64 %9, i1 false)
  %10 = icmp eq i64 %3, 0
  br i1 %10, label %12, label %.preheader32

.preheader32:                                     ; preds = %4
  %11 = icmp sgt i64 %3, 0
  br i1 %11, label %.lr.ph, label %.preheader.preheader

12:                                               ; preds = %4
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %35

.lr.ph:                                           ; preds = %.preheader32, %.lr.ph
  %.02933 = phi ptr [ %13, %.lr.ph ], [ %2, %.preheader32 ]
  %13 = getelementptr inbounds i8, ptr %.02933, i64 1
  %14 = load i8, ptr %.02933, align 1, !tbaa !9
  %15 = zext i8 %14 to i64
  %16 = getelementptr inbounds i32, ptr %0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = add i32 %17, 1
  store i32 %18, ptr %16, align 4, !tbaa !5
  %19 = icmp ult ptr %13, %5
  br i1 %19, label %.lr.ph, label %.preheader.preheader, !llvm.loop !10

.preheader.preheader:                             ; preds = %.lr.ph, %.preheader32
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %.027 = phi i32 [ %23, %.preheader ], [ %6, %.preheader.preheader ]
  %20 = zext i32 %.027 to i64
  %21 = getelementptr inbounds i32, ptr %0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %.not = icmp eq i32 %22, 0
  %23 = add i32 %.027, -1
  br i1 %.not, label %.preheader, label %24, !llvm.loop !12

24:                                               ; preds = %.preheader
  store i32 %.027, ptr %1, align 4, !tbaa !5
  %25 = add nuw nsw i64 %20, 1
  %min.iters.check = icmp ult i32 %.027, 7
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %24
  %n.vec = and i64 %25, 8589934584
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %28, %vector.body ]
  %vec.phi37 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %29, %vector.body ]
  %26 = getelementptr inbounds i32, ptr %0, i64 %index
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %wide.load = load <4 x i32>, ptr %26, align 4, !tbaa !5
  %wide.load38 = load <4 x i32>, ptr %27, align 4, !tbaa !5
  %28 = tail call <4 x i32> @llvm.umax.v4i32(<4 x i32> %wide.load, <4 x i32> %vec.phi)
  %29 = tail call <4 x i32> @llvm.umax.v4i32(<4 x i32> %wide.load38, <4 x i32> %vec.phi37)
  %index.next = add nuw i64 %index, 8
  %30 = icmp eq i64 %index.next, %n.vec
  br i1 %30, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %rdx.minmax = tail call <4 x i32> @llvm.umax.v4i32(<4 x i32> %28, <4 x i32> %29)
  %31 = tail call i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %rdx.minmax)
  %cmp.n = icmp eq i64 %25, %n.vec
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %24
  %indvars.iv.ph = phi i64 [ 0, %24 ], [ %n.vec, %middle.block ]
  %.02634.ph = phi i32 [ 0, %24 ], [ %31, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %.02634 = phi i32 [ %spec.select, %scalar.ph ], [ %.02634.ph, %scalar.ph.preheader ]
  %32 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %spec.select = tail call i32 @llvm.umax.i32(i32 %33, i32 %.02634)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.not31.not = icmp ult i64 %indvars.iv, %20
  br i1 %.not31.not, label %scalar.ph, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %scalar.ph, %middle.block
  %spec.select.lcssa = phi i32 [ %31, %middle.block ], [ %spec.select, %scalar.ph ]
  %34 = zext i32 %spec.select.lcssa to i64
  br label %35

35:                                               ; preds = %.loopexit, %12
  %.028 = phi i64 [ 0, %12 ], [ %34, %.loopexit ]
  ret i64 %.028
}

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.umax.v4i32(<4 x i32>, <4 x i32>) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.umax.v4i32(<4 x i32>) #2

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11, !14, !15}
!14 = !{!"llvm.loop.isvectorized", i32 1}
!15 = !{!"llvm.loop.unroll.runtime.disable"}
!16 = distinct !{!16, !11, !15, !14}


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