#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 */
scalar_t__ isnan(float);
int fvec_purge_nans(float *v, long n, float replace_value) {
  long i, count = 0;
  for (i = 0; i < n; i++)
    if (isnan(v[i])) {
      count++;
      v[i] = replace_value;
    }
  return count;
}


x86 assembly (clang, -O0):
<fvec_purge_nans>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movss  %xmm0,-0x14(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1193 <fvec_purge_nans+0x83>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     117d <fvec_purge_nans+0x6d>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
movss  -0x14(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
jmp    1182 <fvec_purge_nans+0x72>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1135 <fvec_purge_nans+0x25>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fvec_purge_nans>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movss  %xmm0,0x4(%rsp)
test   %rsi,%rsi
jle    115b <fvec_purge_nans+0x4b>
mov    %rsi,%r14
mov    %rdi,%r12
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    1139 <fvec_purge_nans+0x29>
add    $0x1,%rbx
cmp    %rbx,%r14
je     115e <fvec_purge_nans+0x4e>
movss  (%r12,%rbx,4),%xmm0
call   1030 <isnan@plt>
test   %rax,%rax
je     1130 <fvec_purge_nans+0x20>
add    $0x1,%r15
movss  0x4(%rsp),%xmm0
movss  %xmm0,(%r12,%rbx,4)
jmp    1130 <fvec_purge_nans+0x20>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @fvec_purge_nans(float* %0, i64 %1, float %2) {
%4 = alloca float*
%5 = alloca i64
%6 = alloca float
%7 = alloca i64
%8 = alloca i64
store float* %0, float** %4
store i64 %1, i64* %5
store float %2, float* %6
store i64 0, i64* %8
store i64 0, i64* %7
br label %9
9: ; preds = %28, %3
%10 = load i64, i64* %7
%11 = load i64, i64* %5
%12 = icmp slt i64 %10, %11
br i1 %12, label %13, label %31
13: ; preds = %9
%14 = load float*, float** %4
%15 = load i64, i64* %7
%16 = getelementptr inbounds float, float* %14, i64 %15
%17 = load float, float* %16
%18 = call i64 @isnan(float %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %13
%21 = load i64, i64* %8
%22 = add nsw i64 %21, 1
store i64 %22, i64* %8
%23 = load float, float* %6
%24 = load float*, float** %4
%25 = load i64, i64* %7
%26 = getelementptr inbounds float, float* %24, i64 %25
store float %23, float* %26
br label %27
27: ; preds = %20, %13
br label %28
28: ; preds = %27
%29 = load i64, i64* %7
%30 = add nsw i64 %29, 1
store i64 %30, i64* %7
br label %9
31: ; preds = %9
%32 = load i64, i64* %8
%33 = trunc i64 %32 to i32
ret i32 %33
}

LLVM IR (-O2):
define i32 @fvec_purge_nans(float* nocapture %0, i64 %1, float %2) {
%4 = icmp sgt i64 %1, 0
br i1 %4, label %5, label %18
5: ; preds = %3, %14
%6 = phi i64 [ %15, %14 ], [ 0, %3 ]
%7 = phi i64 [ %16, %14 ], [ 0, %3 ]
%8 = getelementptr inbounds float, float* %0, i64 %7
%9 = load float, float* %8
%10 = tail call i64 @isnan(float %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %5
%13 = add nsw i64 %6, 1
store float %2, float* %8
br label %14
14: ; preds = %5, %12
%15 = phi i64 [ %13, %12 ], [ %6, %5 ]
%16 = add nuw nsw i64 %7, 1
%17 = icmp eq i64 %16, %1
br i1 %17, label %18, label %5
18: ; preds = %14, %3
%19 = phi i64 [ 0, %3 ], [ %15, %14 ]
%20 = trunc i64 %19 to i32
ret i32 %20
}