#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 uint_least64_t;

/* Variables and functions */
double INFINITY;
double NAN;
double ldexp(double, int);
int wire_to_double(double *pval, uint_least64_t onwire) {
  double val;
  uint_least64_t m;
  int e;
  int s = 0;
  m = onwire & (((uint_least64_t)1 << 52) - 1);
  s = (onwire >> 63) & 1;
  e = (onwire >> 52) & ((1 << 11) - 1);
  if (e == ((1 << 11) - 1)) {
    if (m)
      val = NAN;
    else
      val = INFINITY;
  } else if (!e && !m) {
    val = 0.0;
  } else {
    if (e) {
      m |= ((uint_least64_t)1 << 52);
    } else {
      e = 1;
    }
    e -= ((1 << 10) - 1 + 52);
    val = ldexp((double)m, e);
  }
  if (s)
    val = -val;
  *pval = val;
  return 0;
}


x86 assembly (clang, -O0):
<wire_to_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x24(%rbp)
and    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3f,%ecx
sar    %cl,%eax
and    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x34,%ecx
sar    %cl,%eax
and    $0x7ff,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x7ff,-0x20(%rbp)
jne    118f <wire_to_double+0x7f>
cmpl   $0x0,-0x1c(%rbp)
je     117a <wire_to_double+0x6a>
mov    0x2e8c(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    118a <wire_to_double+0x7a>
mov    0x2e5f(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11ee <wire_to_double+0xde>
cmpl   $0x0,-0x20(%rbp)
jne    11b0 <wire_to_double+0xa0>
cmpl   $0x0,-0x1c(%rbp)
jne    11b0 <wire_to_double+0xa0>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11e9 <wire_to_double+0xd9>
cmpl   $0x0,-0x20(%rbp)
je     11c5 <wire_to_double+0xb5>
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11cc <wire_to_double+0xbc>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
sub    $0x433,%eax
mov    %eax,-0x20(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
mov    -0x20(%rbp),%edi
call   1030 <ldexp@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    11ee <wire_to_double+0xde>
cmpl   $0x0,-0x24(%rbp)
je     1219 <wire_to_double+0x109>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wire_to_double>:
movq   $0x0,(%rdi)
xor    %eax,%eax
ret

LLVM IR (-O0):
@NAN = global double 0.000000e+00
@INFINITY = global double 0.000000e+00
define i32 @wire_to_double(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = and i32 %9, poison
store i32 %10, i32* %6
%11 = load i32, i32* %4
%12 = ashr i32 %11, 63
%13 = and i32 %12, 1
store i32 %13, i32* %8
%14 = load i32, i32* %4
%15 = ashr i32 %14, 52
%16 = and i32 %15, 2047
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, 2047
br i1 %18, label %19, label %27
19: ; preds = %2
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load double, double* @NAN
store double %23, double* %5
br label %26
24: ; preds = %19
%25 = load double, double* @INFINITY
store double %25, double* %5
br label %26
26: ; preds = %24, %22
br label %49
27: ; preds = %2
%28 = load i32, i32* %7
%29 = icmp ne i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = load i32, i32* %6
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %30
store double 0.000000e+00, double* %5
br label %48
34: ; preds = %30, %27
%35 = load i32, i32* %7
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* %6
%39 = or i32 %38, poison
store i32 %39, i32* %6
br label %41
40: ; preds = %34
store i32 1, i32* %7
br label %41
41: ; preds = %40, %37
%42 = load i32, i32* %7
%43 = sub nsw i32 %42, 1075
store i32 %43, i32* %7
%44 = load i32, i32* %6
%45 = sitofp i32 %44 to double
%46 = load i32, i32* %7
%47 = call double @ldexp(double %45, i32 %46)
store double %47, double* %5
br label %48
48: ; preds = %41, %33
br label %49
49: ; preds = %48, %26
%50 = load i32, i32* %8
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load double, double* %5
%54 = fneg double %53
store double %54, double* %5
br label %55
55: ; preds = %52, %49
%56 = load double, double* %5
%57 = load double*, double** %3
store double %56, double* %57
ret i32 0
}

LLVM IR (-O2):
@NAN = global double 0.000000e+00
@INFINITY = global double 0.000000e+00
define i32 @wire_to_double(double* nocapture writeonly %0, i32 %1) {
store double 0.000000e+00, double* %0
ret i32 0
}