#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*/ finite(double);
scalar_t__ isnan(double);
double rint(double);
double scalbn(double, int);
double __ieee754_scalb(double x, double fn) {
  if (isnan(x) || isnan(fn))
    return x * fn;
  if (!finite(fn)) {
    if (fn > 0.0)
      return x * fn;
    else
      return x / (-fn);
  }
  if (rint(fn) != fn)
    return (fn - fn) / (fn - fn);
  if (fn > 65000.0)
    return scalbn(x, 65000);
  if (-fn > 65000.0)
    return scalbn(x, -65000);
  return scalbn(x, (int)fn);
}


x86 assembly (clang, -O0):
<__ieee754_scalb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <isnan@plt>
cmp    $0x0,%rax
jne    116a <__ieee754_scalb+0x3a>
movsd  -0x18(%rbp),%xmm0
call   1050 <isnan@plt>
cmp    $0x0,%rax
je     117e <__ieee754_scalb+0x4e>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c2 <__ieee754_scalb+0x192>
movsd  -0x18(%rbp),%xmm0
movaps 0xe86(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe6a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11f5 <__ieee754_scalb+0xc5>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11c6 <__ieee754_scalb+0x96>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c2 <__ieee754_scalb+0x192>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c2 <__ieee754_scalb+0x192>
movsd  -0x18(%rbp),%xmm0
call   1030 <rint@plt>
ucomisd -0x18(%rbp),%xmm0
jne    1215 <__ieee754_scalb+0xe5>
jp     1215 <__ieee754_scalb+0xe5>
jmp    1237 <__ieee754_scalb+0x107>
movsd  -0x18(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c2 <__ieee754_scalb+0x192>
movsd  -0x18(%rbp),%xmm0
movsd  0xdc4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1267 <__ieee754_scalb+0x137>
movsd  -0x10(%rbp),%xmm0
mov    $0xfde8,%edi
call   1040 <scalbn@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    12c2 <__ieee754_scalb+0x192>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xd7d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12ae <__ieee754_scalb+0x17e>
movsd  -0x10(%rbp),%xmm0
mov    $0xffff0218,%edi
call   1040 <scalbn@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    12c2 <__ieee754_scalb+0x192>
movsd  -0x10(%rbp),%xmm0
cvttsd2si -0x18(%rbp),%edi
call   1040 <scalbn@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__ieee754_scalb>:
sub    $0x18,%rsp
movapd %xmm1,(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1050 <isnan@plt>
test   %rax,%rax
jne    1158 <__ieee754_scalb+0x28>
movapd (%rsp),%xmm0
call   1050 <isnan@plt>
test   %rax,%rax
je     1168 <__ieee754_scalb+0x38>
movsd  0x10(%rsp),%xmm0
mulsd  (%rsp),%xmm0
add    $0x18,%rsp
ret
movapd 0xe90(%rip),%xmm0
andpd  (%rsp),%xmm0
ucomisd 0xea3(%rip),%xmm0
je     11a4 <__ieee754_scalb+0x74>
movapd (%rsp),%xmm0
call   1030 <rint@plt>
ucomisd (%rsp),%xmm0
jne    1192 <__ieee754_scalb+0x62>
jnp    11cf <__ieee754_scalb+0x9f>
movapd (%rsp),%xmm0
subsd  %xmm0,%xmm0
divsd  %xmm0,%xmm0
add    $0x18,%rsp
ret
xorpd  %xmm0,%xmm0
movapd (%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     1158 <__ieee754_scalb+0x28>
movapd (%rsp),%xmm1
xorpd  0xe50(%rip),%xmm1
movsd  0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
add    $0x18,%rsp
ret
movapd (%rsp),%xmm0
ucomisd 0xe4c(%rip),%xmm0
jbe    11f2 <__ieee754_scalb+0xc2>
movsd  0x10(%rsp),%xmm0
mov    $0xfde8,%edi
add    $0x18,%rsp
jmp    1040 <scalbn@plt>
movsd  0xe36(%rip),%xmm0
ucomisd (%rsp),%xmm0
movsd  0x10(%rsp),%xmm0
jbe    1215 <__ieee754_scalb+0xe5>
mov    $0xffff0218,%edi
add    $0x18,%rsp
jmp    1040 <scalbn@plt>
cvttsd2si (%rsp),%edi
add    $0x18,%rsp
jmp    1040 <scalbn@plt>

LLVM IR (-O0):
define double @__ieee754_scalb(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %4
store double %1, double* %5
%6 = load double, double* %4
%7 = call i64 @isnan(double %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load double, double* %5
%11 = call i64 @isnan(double %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9, %2
%14 = load double, double* %4
%15 = load double, double* %5
%16 = fmul double %14, %15
store double %16, double* %3
br label %64
17: ; preds = %9
%18 = load double, double* %5
%19 = call double @llvm.fabs.f64(double %18)
%20 = fcmp one double %19, 0x7FF0000000000000
br i1 %20, label %33, label %21
21: ; preds = %17
%22 = load double, double* %5
%23 = fcmp ogt double %22, 0.000000e+00
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load double, double* %4
%26 = load double, double* %5
%27 = fmul double %25, %26
store double %27, double* %3
br label %64
28: ; preds = %21
%29 = load double, double* %4
%30 = load double, double* %5
%31 = fneg double %30
%32 = fdiv double %29, %31
store double %32, double* %3
br label %64
33: ; preds = %17
%34 = load double, double* %5
%35 = call double @llvm.rint.f64(double %34)
%36 = load double, double* %5
%37 = fcmp une double %35, %36
br i1 %37, label %38, label %46
38: ; preds = %33
%39 = load double, double* %5
%40 = load double, double* %5
%41 = fsub double %39, %40
%42 = load double, double* %5
%43 = load double, double* %5
%44 = fsub double %42, %43
%45 = fdiv double %41, %44
store double %45, double* %3
br label %64
46: ; preds = %33
%47 = load double, double* %5
%48 = fcmp ogt double %47, 6.500000e+04
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load double, double* %4
%51 = call double @scalbn(double %50, i32 65000)
store double %51, double* %3
br label %64
52: ; preds = %46
%53 = load double, double* %5
%54 = fneg double %53
%55 = fcmp ogt double %54, 6.500000e+04
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = load double, double* %4
%58 = call double @scalbn(double %57, i32 -65000)
store double %58, double* %3
br label %64
59: ; preds = %52
%60 = load double, double* %4
%61 = load double, double* %5
%62 = fptosi double %61 to i32
%63 = call double @scalbn(double %60, i32 %62)
store double %63, double* %3
br label %64
64: ; preds = %59, %56, %49, %38, %28, %24, %13
%65 = load double, double* %3
ret double %65
}

LLVM IR (-O2):
define double @__ieee754_scalb(double %0, double %1) {
%3 = tail call i64 @isnan(double %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i64 @isnan(double %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5, %2
%9 = fmul double %0, %1
br label %37
10: ; preds = %5
%11 = tail call double @llvm.fabs.f64(double %1)
%12 = fcmp ueq double %11, 0x7FF0000000000000
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = fcmp ogt double %1, 0.000000e+00
br i1 %14, label %15, label %17
15: ; preds = %13
%16 = fmul double %0, %1
br label %37
17: ; preds = %13
%18 = fneg double %1
%19 = fdiv double %0, %18
br label %37
20: ; preds = %10
%21 = tail call double @llvm.rint.f64(double %1)
%22 = fcmp une double %21, %1
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = fsub double %1, %1
%25 = fdiv double %24, %24
br label %37
26: ; preds = %20
%27 = fcmp ogt double %1, 6.500000e+04
br i1 %27, label %28, label %30
28: ; preds = %26
%29 = tail call double @scalbn(double %0, i32 65000)
br label %37
30: ; preds = %26
%31 = fcmp olt double %1, -6.500000e+04
br i1 %31, label %32, label %34
32: ; preds = %30
%33 = tail call double @scalbn(double %0, i32 -65000)
br label %37
34: ; preds = %30
%35 = fptosi double %1 to i32
%36 = tail call double @scalbn(double %0, i32 %35)
br label %37
37: ; preds = %34, %32, %28, %23, %17, %15, %8
%38 = phi double [ %9, %8 ], [ %25, %23 ], [ %29, %28 ], [ %33, %32 ], [ %36, %34 ], [ %16, %15 ], [ %19, %17 ]
ret double %38
}