#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 /*<<< orphan*/ v;
typedef int uint64_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ f;
typedef int /*<<< orphan*/ d;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int *, double *, int);
uint64_t repr_double(double v) {
  if (sizeof(v) == sizeof(uint64_t)) {
    uint64_t d;
    memcpy(&d, &v, sizeof(d));
    return d;
  }
  uint32_t f;
  memcpy(&f, &v, sizeof(f));
  if (!(f & 0x7fffffff))
    return (uint64_t)f << 32;
  uint32_t s = f >> 31;
  uint32_t e = ((f & 0x7f800000) >> 23) - 128;
  uint32_t m = f & 0x007fffff;
  if (e == -128) {
    while (!(m & 0x00800000)) {
      m <<= 1;
      e--;
    }
    m &= 0x007fffff;
    e++;
  } else if (e == 127) {
    e = 1023;
  }
  uint64_t d = s;
  d <<= 11;
  d |= e + 1024;
  d <<= 23;
  d |= m;
  d <<= 52 - 23;
  return d;
}


x86 assembly (clang, -O0):
<repr_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    -0x14(%rbp),%eax
and    $0x7fffffff,%eax
cmp    $0x0,%eax
jne    1152 <repr_double+0x42>
mov    -0x14(%rbp),%eax
mov    $0x20,%ecx
shl    %cl,%eax
mov    %eax,-0x4(%rbp)
jmp    1229 <repr_double+0x119>
mov    -0x14(%rbp),%eax
sar    $0x1f,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
and    $0x7f800000,%eax
sar    $0x17,%eax
sub    $0x80,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
and    $0x7fffff,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0xffffff80,-0x1c(%rbp)
jne    11d5 <repr_double+0xc5>
jmp    1188 <repr_double+0x78>
mov    -0x20(%rbp),%eax
and    $0x800000,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a5 <repr_double+0x95>
jmp    11bc <repr_double+0xac>
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1188 <repr_double+0x78>
mov    -0x20(%rbp),%eax
and    $0x7fffff,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11eb <repr_double+0xdb>
cmpl   $0x7f,-0x1c(%rbp)
jne    11e6 <repr_double+0xd6>
movl   $0x3ff,-0x1c(%rbp)
jmp    11eb <repr_double+0xdb>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
shl    $0xb,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x400,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
shl    $0x17,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
shl    $0x1d,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<repr_double>:
sub    $0x18,%rsp
movsd  %xmm0,0x10(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    0xc(%rsp),%ecx
test   $0x7fffffff,%ecx
je     116d <repr_double+0x5d>
mov    %ecx,%eax
and    $0x7fffff,%eax
test   $0x7f800000,%ecx
jne    1165 <repr_double+0x55>
nopl   0x0(%rax)
mov    %eax,%ecx
lea    (%rcx,%rcx,1),%eax
test   $0x800000,%ecx
je     1150 <repr_double+0x40>
and    $0x7fffff,%ecx
mov    %ecx,%eax
shl    $0x1d,%eax
add    $0x18,%rsp
ret
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @repr_double(double %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store double %0, double* %3
%9 = call i32 @memcpy(i32* %4, double* %3, i32 4)
%10 = load i32, i32* %4
%11 = and i32 %10, 2147483647
%12 = icmp ne i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = load i32, i32* %4
%15 = shl i32 %14, 32
store i32 %15, i32* %2
br label %64
16: ; preds = %1
%17 = load i32, i32* %4
%18 = ashr i32 %17, 31
store i32 %18, i32* %5
%19 = load i32, i32* %4
%20 = and i32 %19, 2139095040
%21 = ashr i32 %20, 23
%22 = sub nsw i32 %21, 128
store i32 %22, i32* %6
%23 = load i32, i32* %4
%24 = and i32 %23, 8388607
store i32 %24, i32* %7
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -128
br i1 %26, label %27, label %43
27: ; preds = %16
br label %28
28: ; preds = %33, %27
%29 = load i32, i32* %7
%30 = and i32 %29, 8388608
%31 = icmp ne i32 %30, 0
%32 = xor i1 %31, true
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = load i32, i32* %7
%35 = shl i32 %34, 1
store i32 %35, i32* %7
%36 = load i32, i32* %6
%37 = add nsw i32 %36, -1
store i32 %37, i32* %6
br label %28
38: ; preds = %28
%39 = load i32, i32* %7
%40 = and i32 %39, 8388607
store i32 %40, i32* %7
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %48
43: ; preds = %16
%44 = load i32, i32* %6
%45 = icmp eq i32 %44, 127
br i1 %45, label %46, label %47
46: ; preds = %43
store i32 1023, i32* %6
br label %47
47: ; preds = %46, %43
br label %48
48: ; preds = %47, %38
%49 = load i32, i32* %5
store i32 %49, i32* %8
%50 = load i32, i32* %8
%51 = shl i32 %50, 11
store i32 %51, i32* %8
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1024
%54 = load i32, i32* %8
%55 = or i32 %54, %53
store i32 %55, i32* %8
%56 = load i32, i32* %8
%57 = shl i32 %56, 23
store i32 %57, i32* %8
%58 = load i32, i32* %7
%59 = load i32, i32* %8
%60 = or i32 %59, %58
store i32 %60, i32* %8
%61 = load i32, i32* %8
%62 = shl i32 %61, 29
store i32 %62, i32* %8
%63 = load i32, i32* %8
store i32 %63, i32* %2
br label %64
64: ; preds = %48, %13
%65 = load i32, i32* %2
ret i32 %65
}

LLVM IR (-O2):
define i32 @repr_double(double %0) {
%2 = alloca double
%3 = alloca i32
store double %0, double* %2
%4 = bitcast i32* %3 to i8*
%5 = call i32 @memcpy(i32* %3, double* %2, i32 4)
%6 = load i32, i32* %3
%7 = and i32 %6, 2147483647
%8 = icmp eq i32 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %1
%10 = and i32 %6, 8388607
%11 = and i32 %6, 2139095040
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %9, %13
%14 = phi i32 [ %17, %13 ], [ %10, %9 ]
%15 = and i32 %14, 8388608
%16 = icmp eq i32 %15, 0
%17 = shl i32 %14, 1
br i1 %16, label %13, label %18
18: ; preds = %13
%19 = and i32 %14, 8388607
br label %20
20: ; preds = %9, %18
%21 = phi i32 [ %19, %18 ], [ %10, %9 ]
%22 = shl i32 %21, 29
br label %23
23: ; preds = %1, %20
%24 = phi i32 [ %22, %20 ], [ poison, %1 ]
ret i32 %24
}