; LLVM IR from jgaeddert/liquid-dsp :: src/utility/bench (byte_utilities_benchmark)

; 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 @benchmark_count_ones(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 1024, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %12 = load i32, ptr %9, align 4, !tbaa !9
  %13 = zext i32 %12 to i64
  %14 = mul i64 %13, 4
  %15 = call noalias ptr @malloc(i64 noundef %14) #6
  store ptr %15, ptr %10, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %27, %3
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = icmp ult i32 %17, %18
  br i1 %19, label %20, label %30

20:                                               ; preds = %16
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = and i32 %21, 255
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr %23, i64 %25
  store i32 %22, ptr %26, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %20
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = add i32 %28, 1
  store i32 %29, ptr %7, align 4, !tbaa !9
  br label %16, !llvm.loop !11

30:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = call i32 @getrusage(i32 noundef 0, ptr noundef %31) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %59, %30
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load i64, ptr %36, align 8, !tbaa !13
  %38 = icmp ult i64 %35, %37
  br i1 %38, label %39, label %62

39:                                               ; preds = %33
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = and i32 %40, 65535
  store i32 %41, ptr %11, align 4, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %55, %39
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = icmp ult i32 %43, %44
  br i1 %45, label %46, label %58

46:                                               ; preds = %42
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr %47, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = call i32 @liquid_count_ones(i32 noundef %51)
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = add i32 %53, %52
  store i32 %54, ptr %11, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %46
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = add i32 %56, 1
  store i32 %57, ptr %8, align 4, !tbaa !9
  br label %42, !llvm.loop !15

58:                                               ; preds = %42
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = add i32 %60, 1
  store i32 %61, ptr %7, align 4, !tbaa !9
  br label %33, !llvm.loop !16

62:                                               ; preds = %33
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = call i32 @getrusage(i32 noundef 0, ptr noundef %63) #5
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = mul i32 4, %65
  %67 = zext i32 %66 to i64
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load i64, ptr %68, align 8, !tbaa !13
  %70 = mul i64 %69, %67
  store i64 %70, ptr %68, align 8, !tbaa !13
  %71 = load i32, ptr %11, align 4, !tbaa !9
  %72 = and i32 %71, 1
  %73 = zext i32 %72 to i64
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = load i64, ptr %74, align 8, !tbaa !13
  %76 = add i64 %75, %73
  store i64 %76, ptr %74, align 8, !tbaa !13
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %77) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret void
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind
declare i32 @getrusage(i32 noundef, ptr noundef) #3

declare i32 @liquid_count_ones(i32 noundef) #4

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(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 = { nounwind "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 #4 = { "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 }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


; 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 @benchmark_count_ones(ptr noundef %0, ptr noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
vector.ph:
  %3 = tail call noalias dereferenceable_or_null(4096) ptr @malloc(i64 noundef 4096) #5
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next.1, %vector.body ]
  %vec.ind = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %vector.ph ], [ %vec.ind.next.1, %vector.body ]
  %step.add = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %4 = and <4 x i32> %vec.ind, <i32 255, i32 255, i32 255, i32 255>
  %5 = and <4 x i32> %step.add, <i32 255, i32 255, i32 255, i32 255>
  %6 = getelementptr inbounds i32, ptr %3, i64 %index
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  store <4 x i32> %4, ptr %6, align 4, !tbaa !5
  store <4 x i32> %5, ptr %7, align 4, !tbaa !5
  %index.next = or disjoint i64 %index, 8
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %step.add.1 = add <4 x i32> %vec.ind, <i32 12, i32 12, i32 12, i32 12>
  %8 = and <4 x i32> %vec.ind.next, <i32 255, i32 255, i32 255, i32 255>
  %9 = and <4 x i32> %step.add.1, <i32 255, i32 255, i32 255, i32 255>
  %10 = getelementptr inbounds i32, ptr %3, i64 %index.next
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  store <4 x i32> %8, ptr %10, align 4, !tbaa !5
  store <4 x i32> %9, ptr %11, align 4, !tbaa !5
  %index.next.1 = add nuw nsw i64 %index, 16
  %vec.ind.next.1 = add <4 x i32> %vec.ind, <i32 16, i32 16, i32 16, i32 16>
  %12 = icmp eq i64 %index.next.1, 1024
  br i1 %12, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %13 = tail call i32 @getrusage(i32 noundef 0, ptr noundef %0) #6
  %14 = load i64, ptr %2, align 8, !tbaa !13
  %.not = icmp eq i64 %14, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %middle.block, %20
  %.030 = phi i32 [ %19, %20 ], [ 0, %middle.block ]
  %.12429 = phi i32 [ %21, %20 ], [ 0, %middle.block ]
  br label %15

15:                                               ; preds = %.lr.ph, %15
  %indvars.iv32 = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next33, %15 ]
  %.128 = phi i32 [ %.030, %.lr.ph ], [ %19, %15 ]
  %16 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv32
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = tail call i32 @liquid_count_ones(i32 noundef %17) #6
  %19 = add i32 %18, %.128
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %exitcond35.not = icmp eq i64 %indvars.iv.next33, 1024
  br i1 %exitcond35.not, label %20, label %15, !llvm.loop !15

20:                                               ; preds = %15
  %21 = add i32 %.12429, 1
  %22 = zext i32 %21 to i64
  %23 = load i64, ptr %2, align 8, !tbaa !13
  %24 = icmp ugt i64 %23, %22
  br i1 %24, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !16

._crit_edge.loopexit:                             ; preds = %20
  %25 = and i32 %19, 1
  %26 = zext nneg i32 %25 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %middle.block
  %.0.lcssa = phi i64 [ 0, %middle.block ], [ %26, %._crit_edge.loopexit ]
  %27 = tail call i32 @getrusage(i32 noundef 0, ptr noundef %1) #6
  %28 = load i64, ptr %2, align 8, !tbaa !13
  %29 = shl i64 %28, 12
  %30 = or disjoint i64 %29, %.0.lcssa
  store i64 %30, ptr %2, align 8, !tbaa !13
  tail call void @free(ptr noundef nonnull %3) #6
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @getrusage(i32 noundef, ptr noundef) local_unnamed_addr #2

declare i32 @liquid_count_ones(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 "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 = { "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 #4 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}


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