; 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_fast(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 ptr, align 8
  %11 = alloca i16, align 2
  %12 = alloca double, align 8
  %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) #4
  store i64 0, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = mul i64 %16, 2
  %18 = call noalias ptr @malloc(i64 noundef %17) #5
  store ptr %18, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  store double 0.000000e+00, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %19

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

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %48

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

45:                                               ; preds = %24
  %46 = load i64, ptr %13, align 8, !tbaa !9
  %47 = add i64 %46, 1
  store i64 %47, ptr %13, align 8, !tbaa !9
  br label %19, !llvm.loop !16

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

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

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 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 #4 = { nounwind }
attributes #5 = { 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 = !{!"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_fast(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