#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*/ ERANGE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ finite(double);
double scalbn(double, int);
double ldexp(double value, int exp) {
  if (!finite(value) || value == 0.0)
    return value;
  value = scalbn(value, exp);
  if (!finite(value) || value == 0.0)
    errno = ERANGE;
  return value;
}


x86 assembly (clang, -O0):
<ldexp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xee4(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xec8(%rip),%xmm1
ucomisd %xmm1,%xmm0
je     115a <ldexp+0x4a>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1169 <ldexp+0x59>
jp     1169 <ldexp+0x59>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d1 <ldexp+0xc1>
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%edi
call   1030 <scalbn@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xe89(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe6d(%rip),%xmm1
ucomisd %xmm1,%xmm0
je     11b5 <ldexp+0xa5>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11c7 <ldexp+0xb7>
jp     11c7 <ldexp+0xb7>
mov    0x2e2c(%rip),%rax
mov    (%rax),%ecx
mov    0x2e13(%rip),%rax
mov    %ecx,(%rax)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ldexp>:
push   %rax
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    111d <ldexp+0xd>
jnp    115a <ldexp+0x4a>
movapd 0xedb(%rip),%xmm1
andpd  %xmm0,%xmm1
ucomisd 0xedf(%rip),%xmm1
je     115a <ldexp+0x4a>
call   1030 <scalbn@plt>
movapd 0xec0(%rip),%xmm1
andpd  %xmm0,%xmm1
ucomisd 0xec4(%rip),%xmm1
je     115c <ldexp+0x4c>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    115a <ldexp+0x4a>
jnp    115c <ldexp+0x4c>
pop    %rax
ret
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
mov    0x2e6c(%rip),%rcx
mov    %eax,(%rcx)
pop    %rax
ret

LLVM IR (-O0):
@ERANGE = global i32 0
@errno = global i32 0
define double @ldexp(double %0, i32 %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store double %0, double* %4
store i32 %1, i32* %5
%6 = load double, double* %4
%7 = call double @llvm.fabs.f64(double %6)
%8 = fcmp one double %7, 0x7FF0000000000000
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load double, double* %4
%11 = fcmp oeq double %10, 0.000000e+00
br i1 %11, label %12, label %14
12: ; preds = %9, %2
%13 = load double, double* %4
store double %13, double* %3
br label %28
14: ; preds = %9
%15 = load double, double* %4
%16 = load i32, i32* %5
%17 = call double @scalbn(double %15, i32 %16)
store double %17, double* %4
%18 = load double, double* %4
%19 = call double @llvm.fabs.f64(double %18)
%20 = fcmp one double %19, 0x7FF0000000000000
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load double, double* %4
%23 = fcmp oeq double %22, 0.000000e+00
br i1 %23, label %24, label %26
24: ; preds = %21, %14
%25 = load i32, i32* @ERANGE
store i32 %25, i32* @errno
br label %26
26: ; preds = %24, %21
%27 = load double, double* %4
store double %27, double* %3
br label %28
28: ; preds = %26, %12
%29 = load double, double* %3
ret double %29
}

LLVM IR (-O2):
@ERANGE = global i32 0
@errno = global i32 0
define double @ldexp(double %0, i32 %1) {
%3 = tail call double @llvm.fabs.f64(double %0)
%4 = fcmp ueq double %3, 0x7FF0000000000000
%5 = fcmp oeq double %0, 0.000000e+00
%6 = or i1 %5, %4
br i1 %6, label %15, label %7
7: ; preds = %2
%8 = tail call double @scalbn(double %0, i32 %1)
%9 = tail call double @llvm.fabs.f64(double %8)
%10 = fcmp ueq double %9, 0x7FF0000000000000
%11 = fcmp oeq double %8, 0.000000e+00
%12 = select i1 %10, i1 true, i1 %11
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = load i32, i32* @ERANGE
store i32 %14, i32* @errno
br label %15
15: ; preds = %13, %7, %2
%16 = phi double [ %0, %2 ], [ %8, %7 ], [ %8, %13 ]
ret double %16
}