#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 */
typedef int int64_t;

/* Variables and functions */
double fabs(double);
double frexp(double, int *);
int64_t av_dbl2int(double d) {
  int e;
  if (!d)
    return 0;
  else if (d - d)
    return 0x7FF0000000000000LL + ((int64_t)(d < 0) << 63) + (d != d);
  d = frexp(d, &e);
  return (int64_t)(d < 0) << 63 | (e + 1022LL) << 52 |
         (int64_t)((fabs(d) - 0.5) * (1LL << 53));
}


x86 assembly (clang, -O0):
<av_dbl2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1141 <av_dbl2int+0x31>
jp     1141 <av_dbl2int+0x31>
movl   $0x0,-0x4(%rbp)
jmp    1227 <av_dbl2int+0x117>
movsd  -0x10(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1163 <av_dbl2int+0x53>
jp     1163 <av_dbl2int+0x53>
jmp    11af <av_dbl2int+0x9f>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    $0x3f,%ecx
shl    %cl,%eax
cltq
movabs $0x7ff0000000000000,%rcx
add    %rcx,%rax
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
setne  %cl
setp   %dl
or     %dl,%cl
and    $0x1,%cl
movzbl %cl,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
jmp    1227 <av_dbl2int+0x117>
jmp    11b4 <av_dbl2int+0xa4>
movsd  -0x10(%rbp),%xmm0
lea    -0x14(%rbp),%rdi
call   1030 <frexp@plt>
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    $0x3f,%ecx
shl    %cl,%eax
cltq
movslq -0x14(%rbp),%rcx
add    $0x3fe,%rcx
shl    $0x34,%rcx
or     %rcx,%rax
movsd  -0x10(%rbp),%xmm0
movaps 0xe12(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xdfe(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xdea(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
movslq %ecx,%rcx
or     %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<av_dbl2int>:
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    111c <av_dbl2int+0xc>
jnp    113b <av_dbl2int+0x2b>
movapd %xmm0,%xmm2
subsd  %xmm0,%xmm2
ucomisd %xmm1,%xmm2
jne    113b <av_dbl2int+0x2b>
jp     113b <av_dbl2int+0x2b>
push   %rax
lea    0x4(%rsp),%rdi
call   1030 <frexp@plt>
add    $0x8,%rsp
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @av_dbl2int(double %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
store double %0, double* %3
%5 = load double, double* %3
%6 = fcmp une double %5, 0.000000e+00
br i1 %6, label %8, label %7
7: ; preds = %1
store i32 0, i32* %2
br label %49
8: ; preds = %1
%9 = load double, double* %3
%10 = load double, double* %3
%11 = fsub double %9, %10
%12 = fcmp une double %11, 0.000000e+00
br i1 %12, label %13, label %27
13: ; preds = %8
%14 = load double, double* %3
%15 = fcmp olt double %14, 0.000000e+00
%16 = zext i1 %15 to i32
%17 = shl i32 %16, 63
%18 = sext i32 %17 to i64
%19 = add nsw i64 9218868437227405312, %18
%20 = load double, double* %3
%21 = load double, double* %3
%22 = fcmp une double %20, %21
%23 = zext i1 %22 to i32
%24 = sext i32 %23 to i64
%25 = add nsw i64 %19, %24
%26 = trunc i64 %25 to i32
store i32 %26, i32* %2
br label %49
27: ; preds = %8
br label %28
28: ; preds = %27
%29 = load double, double* %3
%30 = call double @frexp(double %29, i32* %4)
store double %30, double* %3
%31 = load double, double* %3
%32 = fcmp olt double %31, 0.000000e+00
%33 = zext i1 %32 to i32
%34 = shl i32 %33, 63
%35 = sext i32 %34 to i64
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = add nsw i64 %37, 1022
%39 = shl i64 %38, 52
%40 = or i64 %35, %39
%41 = load double, double* %3
%42 = call double @llvm.fabs.f64(double %41)
%43 = fsub double %42, 5.000000e-01
%44 = fmul double %43, 0x4340000000000000
%45 = fptosi double %44 to i32
%46 = sext i32 %45 to i64
%47 = or i64 %40, %46
%48 = trunc i64 %47 to i32
store i32 %48, i32* %2
br label %49
49: ; preds = %28, %13, %7
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
define i32 @av_dbl2int(double %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = fcmp oeq double %0, 0.000000e+00
%5 = fsub double %0, %0
%6 = fcmp une double %5, 0.000000e+00
%7 = or i1 %4, %6
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call double @frexp(double %0, i32* %2)
br label %10
10: ; preds = %1, %8
ret i32 0
}