#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
float fabs(float);
int /*<<< orphan*/ isinff(float);
int /*<<< orphan*/ isnanf(float);
void arr_float_average_stages(float *pDest, float *pSrc,
                              unsigned long int uStates,
                              unsigned long int uStages) {
  float fTol = 1E-3;
  unsigned long int i, j, k;
  for (i = 0; i < uStates; i++) {
    k = 0;
    pDest[i] = 0;
    for (j = 0; j < uStages; j++) {
      float v = pSrc[j * uStates + i];
      if (!isnanf(v) && !isinff(v) && (fabs(v) > fTol)) {
        pDest[i] += v;
        k++;
      }
    }
    if (k > 0) {
      pDest[i] /= k;
    }
  }
}


x86 assembly (clang, -O0):
<arr_float_average_stages>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movss  0xeb0(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    12a0 <arr_float_average_stages+0x170>
movq   $0x0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1227 <arr_float_average_stages+0xf7>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
imul   -0x18(%rbp),%rcx
add    -0x30(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x44(%rbp),%xmm0
call   1030 <isnanf@plt>
cmp    $0x0,%eax
jne    1211 <arr_float_average_stages+0xe1>
movss  -0x44(%rbp),%xmm0
call   1050 <isinff@plt>
cmp    $0x0,%eax
jne    1211 <arr_float_average_stages+0xe1>
movss  -0x44(%rbp),%xmm0
call   1040 <fabs@plt>
ucomiss -0x24(%rbp),%xmm0
jbe    1211 <arr_float_average_stages+0xe1>
movss  -0x44(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
addss  (%rax,%rcx,4),%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1216 <arr_float_average_stages+0xe6>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    118b <arr_float_average_stages+0x5b>
cmpq   $0x0,-0x40(%rbp)
jbe    128a <arr_float_average_stages+0x15a>
mov    -0x40(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x4c(%rbp)
test   %rax,%rax
movss  %xmm0,-0x48(%rbp)
js     126f <arr_float_average_stages+0x13f>
movss  -0x4c(%rbp),%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x48(%rbp),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,(%rax,%rcx,4)
jmp    128f <arr_float_average_stages+0x15f>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    115d <arr_float_average_stages+0x2d>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arr_float_average_stages>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%rax
mov    %rdx,0x8(%rsp)
test   %rdx,%rdx
je     1247 <arr_float_average_stages+0x127>
mov    %rcx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
mov    0x8(%rsp),%rax
lea    0x0(,%rax,4),%rbx
xor    %ebp,%ebp
mov    %rcx,0x28(%rsp)
jmp    118b <arr_float_average_stages+0x6b>
xorps  %xmm0,%xmm0
cvtsi2ss %r14,%xmm0
movss  0x0(%r13,%rbp,4),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x0(%r13,%rbp,4)
add    $0x1,%rbp
add    $0x4,%r12
cmp    0x8(%rsp),%rbp
je     1247 <arr_float_average_stages+0x127>
movl   $0x0,0x0(%r13,%rbp,4)
test   %r15,%r15
je     1178 <arr_float_average_stages+0x58>
mov    %r12,0x30(%rsp)
xor    %r14d,%r14d
jmp    11b9 <arr_float_average_stages+0x99>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %rbx,%r12
add    $0xffffffffffffffff,%r15
je     1210 <arr_float_average_stages+0xf0>
movss  (%r12),%xmm0
movaps %xmm0,0x10(%rsp)
call   1030 <isnanf@plt>
test   %eax,%eax
jne    11b0 <arr_float_average_stages+0x90>
movaps 0x10(%rsp),%xmm0
call   1040 <isinff@plt>
test   %eax,%eax
jne    11b0 <arr_float_average_stages+0x90>
movaps 0x10(%rsp),%xmm0
andps  0xe19(%rip),%xmm0
ucomiss 0xe22(%rip),%xmm0
jbe    11b0 <arr_float_average_stages+0x90>
movaps 0x10(%rsp),%xmm0
addss  0x0(%r13,%rbp,4),%xmm0
movss  %xmm0,0x0(%r13,%rbp,4)
add    $0x1,%r14
jmp    11b0 <arr_float_average_stages+0x90>
nopl   0x0(%rax)
test   %r14,%r14
mov    0x28(%rsp),%r15
mov    0x30(%rsp),%r12
je     1178 <arr_float_average_stages+0x58>
jns    115e <arr_float_average_stages+0x3e>
mov    %r14,%rax
shr    %rax
and    $0x1,%r14d
or     %rax,%r14
xorps  %xmm0,%xmm0
cvtsi2ss %r14,%xmm0
addss  %xmm0,%xmm0
jmp    1166 <arr_float_average_stages+0x46>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @arr_float_average_stages(float* %0, float* %1, i64 %2, i64 %3) {
%5 = alloca float*
%6 = alloca float*
%7 = alloca i64
%8 = alloca i64
%9 = alloca float
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca float
store float* %0, float** %5
store float* %1, float** %6
store i64 %2, i64* %7
store i64 %3, i64* %8
store float 0x3F50624DE0000000, float* %9
store i64 0, i64* %10
br label %14
14: ; preds = %72, %4
%15 = load i64, i64* %10
%16 = load i64, i64* %7
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %75
18: ; preds = %14
store i64 0, i64* %12
%19 = load float*, float** %5
%20 = load i64, i64* %10
%21 = getelementptr inbounds float, float* %19, i64 %20
store float 0.000000e+00, float* %21
store i64 0, i64* %11
br label %22
22: ; preds = %57, %18
%23 = load i64, i64* %11
%24 = load i64, i64* %8
%25 = icmp ult i64 %23, %24
br i1 %25, label %26, label %60
26: ; preds = %22
%27 = load float*, float** %6
%28 = load i64, i64* %11
%29 = load i64, i64* %7
%30 = mul i64 %28, %29
%31 = load i64, i64* %10
%32 = add i64 %30, %31
%33 = getelementptr inbounds float, float* %27, i64 %32
%34 = load float, float* %33
store float %34, float* %13
%35 = load float, float* %13
%36 = call i32 @isnanf(float %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %56, label %38
38: ; preds = %26
%39 = load float, float* %13
%40 = call i32 @isinff(float %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %56, label %42
42: ; preds = %38
%43 = load float, float* %13
%44 = call float @fabs(float %43)
%45 = load float, float* %9
%46 = fcmp ogt float %44, %45
br i1 %46, label %47, label %56
47: ; preds = %42
%48 = load float, float* %13
%49 = load float*, float** %5
%50 = load i64, i64* %10
%51 = getelementptr inbounds float, float* %49, i64 %50
%52 = load float, float* %51
%53 = fadd float %52, %48
store float %53, float* %51
%54 = load i64, i64* %12
%55 = add i64 %54, 1
store i64 %55, i64* %12
br label %56
56: ; preds = %47, %42, %38, %26
br label %57
57: ; preds = %56
%58 = load i64, i64* %11
%59 = add i64 %58, 1
store i64 %59, i64* %11
br label %22
60: ; preds = %22
%61 = load i64, i64* %12
%62 = icmp ugt i64 %61, 0
br i1 %62, label %63, label %71
63: ; preds = %60
%64 = load i64, i64* %12
%65 = uitofp i64 %64 to float
%66 = load float*, float** %5
%67 = load i64, i64* %10
%68 = getelementptr inbounds float, float* %66, i64 %67
%69 = load float, float* %68
%70 = fdiv float %69, %65
store float %70, float* %68
br label %71
71: ; preds = %63, %60
br label %72
72: ; preds = %71
%73 = load i64, i64* %10
%74 = add i64 %73, 1
store i64 %74, i64* %10
br label %14
75: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @arr_float_average_stages(float* nocapture %0, float* nocapture %1, i64 %2, i64 %3) {
%5 = icmp eq i64 %2, 0
br i1 %5, label %43, label %6
6: ; preds = %4
%7 = icmp eq i64 %3, 0
br label %8
8: ; preds = %6, %40
%9 = phi i64 [ 0, %6 ], [ %41, %40 ]
%10 = getelementptr inbounds float, float* %0, i64 %9
store float 0.000000e+00, float* %10
br i1 %7, label %40, label %11
11: ; preds = %8, %30
%12 = phi i64 [ %31, %30 ], [ 0, %8 ]
%13 = phi i64 [ %32, %30 ], [ 0, %8 ]
%14 = mul i64 %13, %2
%15 = add i64 %14, %9
%16 = getelementptr inbounds float, float* %1, i64 %15
%17 = load float, float* %16
%18 = tail call i32 @isnanf(float %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %11
%21 = tail call i32 @isinff(float %17)
%22 = icmp eq i32 %21, 0
%23 = tail call float @llvm.fabs.f32(float %17)
%24 = fcmp ogt float %23, 0x3F50624DE0000000
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = load float, float* %10
%28 = fadd float %17, %27
store float %28, float* %10
%29 = add i64 %12, 1
br label %30
30: ; preds = %26, %20, %11
%31 = phi i64 [ %12, %11 ], [ %12, %20 ], [ %29, %26 ]
%32 = add nuw i64 %13, 1
%33 = icmp eq i64 %32, %3
br i1 %33, label %34, label %11
34: ; preds = %30
%35 = icmp eq i64 %31, 0
br i1 %35, label %40, label %36
36: ; preds = %34
%37 = uitofp i64 %31 to float
%38 = load float, float* %10
%39 = fdiv float %38, %37
store float %39, float* %10
br label %40
40: ; preds = %8, %34, %36
%41 = add nuw i64 %9, 1
%42 = icmp eq i64 %41, %2
br i1 %42, label %43, label %8
43: ; preds = %40, %4
ret void
}