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


x86 assembly (clang, -O0):
<FDLIBM_ldexp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <FDLIBM_finite@plt>
cmp    $0x0,%eax
je     115b <FDLIBM_ldexp+0x3b>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    116a <FDLIBM_ldexp+0x4a>
jp     116a <FDLIBM_ldexp+0x4a>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c3 <FDLIBM_ldexp+0xa3>
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%edi
call   1040 <FDLIBM_scalbn@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <FDLIBM_finite@plt>
cmp    $0x0,%eax
je     11a7 <FDLIBM_ldexp+0x87>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b9 <FDLIBM_ldexp+0x99>
jp     11b9 <FDLIBM_ldexp+0x99>
mov    0x2e3a(%rip),%rax
mov    (%rax),%ecx
mov    0x2e21(%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):
<FDLIBM_ldexp>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movsd  %xmm0,0x8(%rsp)
call   1030 <FDLIBM_finite@plt>
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
movapd %xmm1,%xmm0
jne    1148 <FDLIBM_ldexp+0x28>
jnp    118a <FDLIBM_ldexp+0x6a>
test   %eax,%eax
je     118a <FDLIBM_ldexp+0x6a>
mov    %ebx,%edi
call   1040 <FDLIBM_scalbn@plt>
movsd  %xmm0,0x8(%rsp)
call   1030 <FDLIBM_finite@plt>
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
movapd %xmm1,%xmm0
jne    1174 <FDLIBM_ldexp+0x54>
jnp    1178 <FDLIBM_ldexp+0x58>
test   %eax,%eax
jne    118a <FDLIBM_ldexp+0x6a>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    0x2e50(%rip),%rcx
mov    %eax,(%rcx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@ERANGE = global i32 0
@errno = global i32 0
define double @FDLIBM_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 i32 @FDLIBM_finite(double %6)
%8 = icmp ne i32 %7, 0
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 @FDLIBM_scalbn(double %15, i32 %16)
store double %17, double* %4
%18 = load double, double* %4
%19 = call i32 @FDLIBM_finite(double %18)
%20 = icmp ne i32 %19, 0
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 @FDLIBM_ldexp(double %0, i32 %1) {
%3 = tail call i32 @FDLIBM_finite(double %0)
%4 = icmp eq i32 %3, 0
%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 @FDLIBM_scalbn(double %0, i32 %1)
%9 = tail call i32 @FDLIBM_finite(double %8)
%10 = icmp eq i32 %9, 0
%11 = fcmp oeq double %8, 0.000000e+00
%12 = or i1 %11, %10
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
}