#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 */
int /*<<< orphan*/ fabs(double);
double floor(int /*<<< orphan*/);
scalar_t__ isinf(double);
scalar_t__ isnan(double);
int jsV_numbertointeger(double n) {
  double sign = n < 0 ? -1 : 1;
  if (isnan(n))
    return 0;
  if (n == 0 || isinf(n))
    return n;
  return sign * floor(fabs(n));
}


x86 assembly (clang, -O0):
<jsV_numbertointeger>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
xorps  %xmm0,%xmm0
mov    $0x1,%eax
mov    $0xffffffff,%ecx
ucomisd %xmm1,%xmm0
cmova  %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
je     118f <jsV_numbertointeger+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    11fb <jsV_numbertointeger+0xbb>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ac <jsV_numbertointeger+0x6c>
jp     11ac <jsV_numbertointeger+0x6c>
jmp    11c0 <jsV_numbertointeger+0x80>
movsd  -0x10(%rbp),%xmm0
call   1060 <isinf@plt>
cmp    $0x0,%rax
je     11cd <jsV_numbertointeger+0x8d>
cvttsd2si -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fb <jsV_numbertointeger+0xbb>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %eax,%edi
call   1050 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jsV_numbertointeger>:
sub    $0x18,%rsp
movapd %xmm0,(%rsp)
call   1040 <isnan@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     115d <jsV_numbertointeger+0x1d>
add    $0x18,%rsp
ret
xorpd  %xmm0,%xmm0
movapd (%rsp),%xmm1
ucomisd %xmm0,%xmm1
movapd %xmm1,%xmm0
jne    1172 <jsV_numbertointeger+0x32>
jnp    1185 <jsV_numbertointeger+0x45>
movaps (%rsp),%xmm0
call   1060 <isinf@plt>
movapd (%rsp),%xmm0
test   %rax,%rax
je     118e <jsV_numbertointeger+0x4e>
cvttsd2si %xmm0,%eax
add    $0x18,%rsp
ret
call   1030 <fabs@plt>
mov    %eax,%edi
call   1050 <floor@plt>
movapd 0xe5e(%rip),%xmm1
xorpd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
movapd (%rsp),%xmm3
cmpltsd %xmm2,%xmm3
movapd %xmm3,%xmm2
andnpd %xmm0,%xmm2
andpd  %xmm1,%xmm3
orpd   %xmm2,%xmm3
cvttsd2si %xmm3,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @jsV_numbertointeger(double %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
store double %0, double* %3
%5 = load double, double* %3
%6 = fcmp olt double %5, 0.000000e+00
%7 = zext i1 %6 to i64
%8 = select i1 %6, i32 -1, i32 1
%9 = sitofp i32 %8 to double
store double %9, double* %4
%10 = load double, double* %3
%11 = call i64 @isnan(double %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 0, i32* %2
br label %31
14: ; preds = %1
%15 = load double, double* %3
%16 = fcmp oeq double %15, 0.000000e+00
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = load double, double* %3
%19 = call i64 @isinf(double %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17, %14
%22 = load double, double* %3
%23 = fptosi double %22 to i32
store i32 %23, i32* %2
br label %31
24: ; preds = %17
%25 = load double, double* %4
%26 = load double, double* %3
%27 = call i32 @fabs(double %26)
%28 = call double @floor(i32 %27)
%29 = fmul double %25, %28
%30 = fptosi double %29 to i32
store i32 %30, i32* %2
br label %31
31: ; preds = %24, %21, %13
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
define i32 @jsV_numbertointeger(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
%3 = tail call i64 @isnan(double %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %1
%6 = fcmp oeq double %0, 0.000000e+00
br i1 %6, label %10, label %7
7: ; preds = %5
%8 = tail call i64 @isinf(double %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7, %5
%11 = fptosi double %0 to i32
br label %18
12: ; preds = %7
%13 = tail call i32 @fabs(double %0)
%14 = tail call double @floor(i32 %13)
%15 = fneg double %14
%16 = select i1 %2, double %15, double %14
%17 = fptosi double %16 to i32
br label %18
18: ; preds = %1, %12, %10
%19 = phi i32 [ %11, %10 ], [ %17, %12 ], [ 0, %1 ]
ret i32 %19
}