; LLVM IR from zchrissirhcz/pixel :: legacy/matcalc (mean_stddev)

; 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
declare double @sqrt(double noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @mean_stddev_u8_asimd2(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca double, align 8
  %12 = alloca i16, align 2
  %13 = alloca i64, align 8
  %14 = alloca float, align 4
  %15 = alloca double, 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 ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store double 0.000000e+00, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %16 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %16, ptr %13, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %43, %4
  %18 = load i64, ptr %13, align 8, !tbaa !9
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = icmp ult i64 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %46

22:                                               ; preds = %17
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i64, ptr %13, align 8, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %23, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !13
  %27 = zext i8 %26 to i64
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = add i64 %28, %27
  store i64 %29, ptr %9, align 8, !tbaa !9
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i64, ptr %13, align 8, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %30, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !13
  %34 = zext i8 %33 to i16
  store i16 %34, ptr %12, align 2, !tbaa !14
  %35 = load i16, ptr %12, align 2, !tbaa !14
  %36 = zext i16 %35 to i32
  %37 = load i16, ptr %12, align 2, !tbaa !14
  %38 = zext i16 %37 to i32
  %39 = mul nsw i32 %36, %38
  %40 = sitofp i32 %39 to double
  %41 = load double, ptr %11, align 8, !tbaa !11
  %42 = fadd double %41, %40
  store double %42, ptr %11, align 8, !tbaa !11
  br label %43

43:                                               ; preds = %22
  %44 = load i64, ptr %13, align 8, !tbaa !9
  %45 = add i64 %44, 1
  store i64 %45, ptr %13, align 8, !tbaa !9
  br label %17, !llvm.loop !16

46:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %47 = load i64, ptr %9, align 8, !tbaa !9
  %48 = uitofp i64 %47 to double
  %49 = fmul double %48, 1.000000e+00
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = uitofp i64 %50 to double
  %52 = fdiv double %49, %51
  %53 = fptrunc double %52 to float
  store float %53, ptr %14, align 4, !tbaa !18
  %54 = load double, ptr %11, align 8, !tbaa !11
  %55 = load i64, ptr %6, align 8, !tbaa !9
  %56 = uitofp i64 %55 to double
  %57 = fdiv double %54, %56
  %58 = load float, ptr %14, align 4, !tbaa !18
  %59 = load float, ptr %14, align 4, !tbaa !18
  %60 = fmul float %58, %59
  %61 = fpext float %60 to double
  %62 = fsub double %57, %61
  store double %62, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %63 = load double, ptr %11, align 8, !tbaa !11
  %64 = call double @sqrt(double noundef %63) #3
  store double %64, ptr %15, align 8, !tbaa !11
  %65 = load float, ptr %14, align 4, !tbaa !18
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  store float %65, ptr %66, align 4, !tbaa !18
  %67 = load double, ptr %15, align 8, !tbaa !11
  %68 = fptrunc double %67 to float
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  store float %68, ptr %69, align 4, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 2, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = !{!"double", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !19, i64 0}
!19 = !{!"float", !7, i64 0}


; 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 nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind memory(write, argmem: readwrite) uwtable
define dso_local void @mean_stddev_u8_asimd2(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #1 {
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %xtraiter = and i64 %1, 3
  %5 = icmp ult i64 %1, 4
  br i1 %5, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %1, -4
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa32.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %55, %.lr.ph ]
  %.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %59, %.lr.ph ]
  %.027.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %55, %.lr.ph ]
  %.02226.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %59, %.lr.ph ]
  %.02325.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %60, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.027.epil = phi i64 [ %9, %.lr.ph.epil ], [ %.027.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.02226.epil = phi double [ %13, %.lr.ph.epil ], [ %.02226.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.02325.epil = phi i64 [ %14, %.lr.ph.epil ], [ %.02325.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %6 = getelementptr inbounds i8, ptr %0, i64 %.02325.epil
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = zext i8 %7 to i64
  %9 = add i64 %.027.epil, %8
  %10 = zext i8 %7 to i32
  %11 = mul nuw nsw i32 %10, %10
  %12 = uitofp nneg i32 %11 to double
  %13 = fadd double %.02226.epil, %12
  %14 = add nuw i64 %.02325.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.loopexit, label %.lr.ph.epil, !llvm.loop !8

._crit_edge.loopexit:                             ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa
  %.lcssa32 = phi i64 [ %.lcssa32.ph, %._crit_edge.loopexit.unr-lcssa ], [ %9, %.lr.ph.epil ]
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %13, %.lr.ph.epil ]
  %15 = uitofp i64 %.lcssa32 to double
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %4
  %.022.lcssa = phi double [ 0.000000e+00, %4 ], [ %.lcssa, %._crit_edge.loopexit ]
  %.0.lcssa = phi double [ 0.000000e+00, %4 ], [ %15, %._crit_edge.loopexit ]
  %16 = uitofp i64 %1 to double
  %17 = fdiv double %.0.lcssa, %16
  %18 = fptrunc double %17 to float
  %19 = fdiv double %.022.lcssa, %16
  %20 = fmul float %18, %18
  %21 = fpext float %20 to double
  %22 = fsub double %19, %21
  %23 = tail call double @sqrt(double noundef %22) #2
  store float %18, ptr %2, align 4, !tbaa !10
  %24 = fptrunc double %23 to float
  store float %24, ptr %3, align 4, !tbaa !10
  ret void

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.027 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %55, %.lr.ph ]
  %.02226 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %59, %.lr.ph ]
  %.02325 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %60, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %25 = getelementptr inbounds i8, ptr %0, i64 %.02325
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = zext i8 %26 to i64
  %28 = add i64 %.027, %27
  %29 = zext i8 %26 to i32
  %30 = mul nuw nsw i32 %29, %29
  %31 = uitofp nneg i32 %30 to double
  %32 = fadd double %.02226, %31
  %33 = or disjoint i64 %.02325, 1
  %34 = getelementptr inbounds i8, ptr %0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !5
  %36 = zext i8 %35 to i64
  %37 = add i64 %28, %36
  %38 = zext i8 %35 to i32
  %39 = mul nuw nsw i32 %38, %38
  %40 = uitofp nneg i32 %39 to double
  %41 = fadd double %32, %40
  %42 = or disjoint i64 %.02325, 2
  %43 = getelementptr inbounds i8, ptr %0, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !5
  %45 = zext i8 %44 to i64
  %46 = add i64 %37, %45
  %47 = zext i8 %44 to i32
  %48 = mul nuw nsw i32 %47, %47
  %49 = uitofp nneg i32 %48 to double
  %50 = fadd double %41, %49
  %51 = or disjoint i64 %.02325, 3
  %52 = getelementptr inbounds i8, ptr %0, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !5
  %54 = zext i8 %53 to i64
  %55 = add i64 %46, %54
  %56 = zext i8 %53 to i32
  %57 = mul nuw nsw i32 %56, %56
  %58 = uitofp nneg i32 %57 to double
  %59 = fadd double %50, %58
  %60 = add nuw i64 %.02325, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !12
}

attributes #0 = { mustprogress nofree nounwind willreturn memory(write) "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 = { nofree nounwind memory(write, argmem: readwrite) 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 }

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


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