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

/* Variables and functions */
double __floatsidf(long i) {
  long msc;
  ulong v;
  long lc[2];
  if (i > 0)
    msc = 0x41e00000 - 0x100000, v = i;
  else if (i < 0)
    msc = 0xc1e00000 - 0x100000, v = -i;
  else
    return 0;
  while (v < 0x01000000)
    v <<= 8, msc -= 0x00800000;
  if (v < 0x10000000)
    v <<= 4, msc -= 0x00400000;
  while (v < 0x80000000)
    v <<= 1, msc -= 0x00100000;
  lc[1] = msc + (v >> 11);
  lc[0] = v << 21;
  return (*(const double *)lc);
}


x86 assembly (clang, -O0):
<__floatsidf>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    1127 <__floatsidf+0x27>
movq   $0x41d00000,-0x18(%rbp)
41
mov    -0x10(%rbp),%rax
mov    %eax,-0x1c(%rbp)
jmp    115b <__floatsidf+0x5b>
cmpq   $0x0,-0x10(%rbp)
jge    1149 <__floatsidf+0x49>
mov    $0xc1d00000,%eax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
sub    -0x10(%rbp),%rax
mov    %eax,-0x1c(%rbp)
jmp    1156 <__floatsidf+0x56>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1205 <__floatsidf+0x105>
jmp    115b <__floatsidf+0x5b>
jmp    1160 <__floatsidf+0x60>
cmpl   $0x1000000,-0x1c(%rbp)
jge    1189 <__floatsidf+0x89>
mov    -0x1c(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x800000,%rax
mov    %rax,-0x18(%rbp)
jmp    1160 <__floatsidf+0x60>
cmpl   $0x10000000,-0x1c(%rbp)
jge    11ad <__floatsidf+0xad>
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x400000,%rax
mov    %rax,-0x18(%rbp)
jmp    11b2 <__floatsidf+0xb2>
cmpl   $0x80000000,-0x1c(%rbp)
jae    11db <__floatsidf+0xdb>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x100000,%rax
mov    %rax,-0x18(%rbp)
jmp    11b2 <__floatsidf+0xb2>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sar    $0xb,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x15,%eax
cltq
mov    %rax,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<__floatsidf>:
test   %rdi,%rdi
jle    1145 <__floatsidf+0x45>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %edi,%eax
shl    $0x8,%edi
cmp    $0x1000000,%eax
jl     1110 <__floatsidf+0x10>
mov    %eax,%ecx
shl    $0x4,%ecx
cmp    $0x10000000,%eax
cmovae %eax,%ecx
nopl   0x0(%rax)
mov    %ecx,%eax
lea    (%rax,%rax,1),%ecx
test   %eax,%eax
jns    1130 <__floatsidf+0x30>
shl    $0x15,%eax
cltq
movq   %rax,%xmm0
jmp    114b <__floatsidf+0x4b>
pxor   %xmm0,%xmm0
js     114c <__floatsidf+0x4c>
ret
neg    %edi
jmp    1110 <__floatsidf+0x10>

LLVM IR (-O0):
define double @__floatsidf(i64 %0) {
%2 = alloca double
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca [2 x i64]
store i64 %0, i64* %3
%7 = load i64, i64* %3
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
store i64 1104150528, i64* %4
%10 = load i64, i64* %3
%11 = trunc i64 %10 to i32
store i32 %11, i32* %5
br label %21
12: ; preds = %1
%13 = load i64, i64* %3
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
store i64 3251634176, i64* %4
%16 = load i64, i64* %3
%17 = sub nsw i64 0, %16
%18 = trunc i64 %17 to i32
store i32 %18, i32* %5
br label %20
19: ; preds = %12
store double 0.000000e+00, double* %2
br label %61
20: ; preds = %15
br label %21
21: ; preds = %20, %9
br label %22
22: ; preds = %25, %21
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 16777216
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* %5
%27 = shl i32 %26, 8
store i32 %27, i32* %5
%28 = load i64, i64* %4
%29 = sub nsw i64 %28, 8388608
store i64 %29, i64* %4
br label %22
30: ; preds = %22
%31 = load i32, i32* %5
%32 = icmp slt i32 %31, 268435456
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load i32, i32* %5
%35 = shl i32 %34, 4
store i32 %35, i32* %5
%36 = load i64, i64* %4
%37 = sub nsw i64 %36, 4194304
store i64 %37, i64* %4
br label %38
38: ; preds = %33, %30
br label %39
39: ; preds = %42, %38
%40 = load i32, i32* %5
%41 = icmp ult i32 %40, -2147483648
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load i32, i32* %5
%44 = shl i32 %43, 1
store i32 %44, i32* %5
%45 = load i64, i64* %4
%46 = sub nsw i64 %45, 1048576
store i64 %46, i64* %4
br label %39
47: ; preds = %39
%48 = load i64, i64* %4
%49 = load i32, i32* %5
%50 = ashr i32 %49, 11
%51 = sext i32 %50 to i64
%52 = add nsw i64 %48, %51
%53 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 1
store i64 %52, i64* %53
%54 = load i32, i32* %5
%55 = shl i32 %54, 21
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 0
store i64 %56, i64* %57
%58 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 0
%59 = bitcast i64* %58 to double*
%60 = load double, double* %59
store double %60, double* %2
br label %61
61: ; preds = %47, %19
%62 = load double, double* %2
ret double %62
}

LLVM IR (-O2):
define double @__floatsidf(i64 %0) {
%2 = icmp sgt i64 %0, 0
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = trunc i64 %0 to i32
br label %10
5: ; preds = %1
%6 = icmp slt i64 %0, 0
br i1 %6, label %7, label %28
7: ; preds = %5
%8 = trunc i64 %0 to i32
%9 = sub i32 0, %8
br label %10
10: ; preds = %7, %3
%11 = phi i32 [ %9, %7 ], [ %4, %3 ]
br label %12
12: ; preds = %10, %12
%13 = phi i32 [ %15, %12 ], [ %11, %10 ]
%14 = icmp slt i32 %13, 16777216
%15 = shl i32 %13, 8
br i1 %14, label %12, label %16
16: ; preds = %12
%17 = icmp ult i32 %13, 268435456
%18 = shl i32 %13, 4
%19 = select i1 %17, i32 %18, i32 %13
br label %20
20: ; preds = %16, %20
%21 = phi i32 [ %23, %20 ], [ %19, %16 ]
%22 = icmp sgt i32 %21, -1
%23 = shl nuw i32 %21, 1
br i1 %22, label %20, label %24
24: ; preds = %20
%25 = shl i32 %21, 21
%26 = sext i32 %25 to i64
%27 = bitcast i64 %26 to double
br label %28
28: ; preds = %5, %24
%29 = phi double [ %27, %24 ], [ 0.000000e+00, %5 ]
ret double %29
}