#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
unsigned long myDoubleToUlong(double val) {
  unsigned long ul;
  if (val < 0) {
    fprintf(stderr, "IEEE80:DoubleToUlong: val < 0\n");
  }
  if (val < ((double)2147483648.0))
    ul = (unsigned long)val;
  else
    ul = ((unsigned long)0x80000000L) |
         (unsigned long)(val - ((double)2147483648.0));
  return ul;
}


x86 assembly (clang, -O0):
<myDoubleToUlong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1140 <myDoubleToUlong+0x30>
mov    0x2eae(%rip),%rax
mov    (%rax),%edi
lea    0xedd(%rip),%rsi
call   1030 <fprintf@plt>
movsd  0xeb8(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1187 <myDoubleToUlong+0x77>
movsd  -0x8(%rbp),%xmm0
movsd  0xeb0(%rip),%xmm2
movaps %xmm0,%xmm1
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rcx
cvttsd2si %xmm0,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    11cf <myDoubleToUlong+0xbf>
movsd  -0x8(%rbp),%xmm0
movsd  0xe74(%rip),%xmm1
addsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xe61(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
movabs $0x80000000,%rcx
or     %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myDoubleToUlong>:
sub    $0x18,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    113d <myDoubleToUlong+0x2d>
mov    0x2ebb(%rip),%rax
mov    (%rax),%edi
lea    0xeea(%rip),%rsi
movapd %xmm0,(%rsp)
call   1030 <fprintf@plt>
movapd (%rsp),%xmm0
movsd  0xebb(%rip),%xmm2
movapd %xmm0,%xmm1
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rax
cvttsd2si %xmm0,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
and    %rax,%rdx
movsd  0xe9f(%rip),%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rsi
or     %rcx,%rdx
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rcx
mov    $0x80000000,%eax
or     %rsi,%rax
sar    $0x3f,%rsi
and    %rcx,%rsi
or     %rsi,%rax
movsd  0xe78(%rip),%xmm1
ucomisd %xmm0,%xmm1
cmova  %rdx,%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"IEEE80:DoubleToUlong: val < 0\0A\00"
define i64 @myDoubleToUlong(double %0) {
%2 = alloca double
%3 = alloca i64
store double %0, double* %2
%4 = load double, double* %2
%5 = fcmp olt double %4, 0.000000e+00
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %6, %1
%10 = load double, double* %2
%11 = fcmp olt double %10, 0x41E0000000000000
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load double, double* %2
%14 = fptoui double %13 to i64
store i64 %14, i64* %3
br label %20
15: ; preds = %9
%16 = load double, double* %2
%17 = fsub double %16, 0x41E0000000000000
%18 = fptoui double %17 to i64
%19 = or i64 2147483648, %18
store i64 %19, i64* %3
br label %20
20: ; preds = %15, %12
%21 = load i64, i64* %3
ret i64 %21
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"IEEE80:DoubleToUlong: val < 0\0A\00"
define i64 @myDoubleToUlong(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %3, %1
%7 = fcmp olt double %0, 0x41E0000000000000
%8 = fptoui double %0 to i64
%9 = fadd double %0, 0xC1E0000000000000
%10 = fptoui double %9 to i64
%11 = or i64 %10, 2147483648
%12 = select i1 %7, i64 %8, i64 %11
ret i64 %12
}