#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 longBitsToDouble(int);
double ldexpk(double x, int q) {
  double u;
  int m;
  m = q >> 31;
  m = (((m + q) >> 9) - m) << 7;
  q = q - (m << 2);
  m += 0x3ff;
  m = m < 0 ? 0 : m;
  m = m > 0x7ff ? 0x7ff : m;
  u = longBitsToDouble(((int64_t)m) << 52);
  x = x * u * u * u * u;
  u = longBitsToDouble(((int64_t)(q + 0x3ff)) << 52);
  return x * u;
}


x86 assembly (clang, -O0):
<ldexpk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x1f,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0xc(%rbp),%eax
sar    $0x9,%eax
sub    -0x1c(%rbp),%eax
shl    $0x7,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x2,%ecx
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x3ff,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1168 <ldexpk+0x58>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    116e <ldexpk+0x5e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x7ff,-0x1c(%rbp)
jle    118e <ldexpk+0x7e>
mov    $0x7ff,%eax
mov    %eax,-0x24(%rbp)
jmp    1194 <ldexpk+0x84>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x34,%ecx
shl    %cl,%edi
call   1030 <longBitsToDouble@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    -0xc(%rbp),%edi
add    $0x3ff,%edi
mov    $0x34,%ecx
shl    %cl,%edi
call   1030 <longBitsToDouble@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ldexpk>:
push   %rax
movsd  %xmm0,(%rsp)
call   1030 <longBitsToDouble@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
call   1030 <longBitsToDouble@plt>
mulsd  (%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @ldexpk(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
store double %0, double* %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = ashr i32 %7, 31
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = add nsw i32 %9, %10
%12 = ashr i32 %11, 9
%13 = load i32, i32* %6
%14 = sub nsw i32 %12, %13
%15 = shl i32 %14, 7
store i32 %15, i32* %6
%16 = load i32, i32* %4
%17 = load i32, i32* %6
%18 = shl i32 %17, 2
%19 = sub nsw i32 %16, %18
store i32 %19, i32* %4
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1023
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %2
br label %27
25: ; preds = %2
%26 = load i32, i32* %6
br label %27
27: ; preds = %25, %24
%28 = phi i32 [ 0, %24 ], [ %26, %25 ]
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp sgt i32 %29, 2047
br i1 %30, label %31, label %32
31: ; preds = %27
br label %34
32: ; preds = %27
%33 = load i32, i32* %6
br label %34
34: ; preds = %32, %31
%35 = phi i32 [ 2047, %31 ], [ %33, %32 ]
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = shl i32 %36, 52
%38 = call double @longBitsToDouble(i32 %37)
store double %38, double* %5
%39 = load double, double* %3
%40 = load double, double* %5
%41 = fmul double %39, %40
%42 = load double, double* %5
%43 = fmul double %41, %42
%44 = load double, double* %5
%45 = fmul double %43, %44
%46 = load double, double* %5
%47 = fmul double %45, %46
store double %47, double* %3
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1023
%50 = shl i32 %49, 52
%51 = call double @longBitsToDouble(i32 %50)
store double %51, double* %5
%52 = load double, double* %3
%53 = load double, double* %5
%54 = fmul double %52, %53
ret double %54
}

LLVM IR (-O2):
define double @ldexpk(double %0, i32 %1) {
%3 = tail call double @longBitsToDouble(i32 poison)
%4 = fmul double %3, %0
%5 = fmul double %3, %4
%6 = fmul double %3, %5
%7 = fmul double %3, %6
%8 = tail call double @longBitsToDouble(i32 poison)
%9 = fmul double %8, %7
ret double %9
}