#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 */
double INT_MAX;
__attribute__((unused)) int ls_tmo_to_ms(double tmo) {
  if (tmo != tmo)
    return 0;
  if (tmo < 0.0)
    return -1;
  double ms = tmo * 1000;
  return ms > INT_MAX ? INT_MAX : ms;
}


x86 assembly (clang, -O0):
<ls_tmo_to_ms>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    1124 <ls_tmo_to_ms+0x24>
jp     1124 <ls_tmo_to_ms+0x24>
jmp    1130 <ls_tmo_to_ms+0x30>
movl   $0x0,-0x4(%rbp)
jmp    119d <ls_tmo_to_ms+0x9d>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    114a <ls_tmo_to_ms+0x4a>
movl   $0xffffffff,-0x4(%rbp)
jmp    119d <ls_tmo_to_ms+0x9d>
movsd  0xeae(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    0x2e80(%rip),%rax
ucomisd (%rax),%xmm0
jbe    1187 <ls_tmo_to_ms+0x87>
mov    0x2e6f(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1191 <ls_tmo_to_ms+0x91>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ls_tmo_to_ms>:
ucomisd %xmm0,%xmm0
jp     1131 <ls_tmo_to_ms+0x31>
mov    $0xffffffff,%eax
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1130 <ls_tmo_to_ms+0x30>
mulsd  0xee3(%rip),%xmm0
mov    0x2ec4(%rip),%rax
movsd  (%rax),%xmm1
minsd  %xmm0,%xmm1
cvttsd2si %xmm1,%eax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@INT_MAX = global double 0.000000e+00
define i32 @ls_tmo_to_ms(double %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
store double %0, double* %3
%5 = load double, double* %3
%6 = load double, double* %3
%7 = fcmp une double %5, %6
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %2
br label %26
9: ; preds = %1
%10 = load double, double* %3
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 -1, i32* %2
br label %26
13: ; preds = %9
%14 = load double, double* %3
%15 = fmul double %14, 1.000000e+03
store double %15, double* %4
%16 = load double, double* %4
%17 = load double, double* @INT_MAX
%18 = fcmp ogt double %16, %17
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = load double, double* @INT_MAX
br label %23
21: ; preds = %13
%22 = load double, double* %4
br label %23
23: ; preds = %21, %19
%24 = phi double [ %20, %19 ], [ %22, %21 ]
%25 = fptosi double %24 to i32
store i32 %25, i32* %2
br label %26
26: ; preds = %23, %12, %8
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@INT_MAX = global double 0.000000e+00
define i32 @ls_tmo_to_ms(double %0) {
%2 = fcmp uno double %0, 0.000000e+00
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = fcmp olt double %0, 0.000000e+00
br i1 %4, label %11, label %5
5: ; preds = %3
%6 = fmul double %0, 1.000000e+03
%7 = load double, double* @INT_MAX
%8 = fcmp ogt double %6, %7
%9 = select i1 %8, double %7, double %6
%10 = fptosi double %9 to i32
br label %11
11: ; preds = %3, %1, %5
%12 = phi i32 [ %10, %5 ], [ 0, %1 ], [ -1, %3 ]
ret i32 %12
}