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

/* Variables and functions */
int abs(int);
scalar_t__ pow(int, int);
double ftod(int32_t in) {
  double out = 0, sig;
  int i;
  if (in >> 31 != 0) {
    sig = -1.0;
  } else {
    sig = 1.0;
  }
  in = abs(in);
  for (i = -24; i < 7; i++) {
    if ((in & 0x1) == 0x1) {
      out += pow(2, i);
    }
    in = in >> 1;
  }
  return out * sig;
}


x86 assembly (clang, -O0):
<ftod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x1f,%eax
cmp    $0x0,%eax
je     1154 <ftod+0x34>
movsd  0xebe(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1161 <ftod+0x41>
movsd  0xea4(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x4(%rbp)
movl   $0xffffffe8,-0x1c(%rbp)
cmpl   $0x7,-0x1c(%rbp)
jge    11bf <ftod+0x9f>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x1,%eax
jne    11a8 <ftod+0x88>
mov    -0x1c(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1173 <ftod+0x53>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftod>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
mov    %edi,%ebp
neg    %ebp
cmovs  %edi,%ebp
xorps  %xmm0,%xmm0
mov    $0xffffffe2,%ebx
jmp    1136 <ftod+0x26>
nopl   0x0(%rax)
shr    $0x2,%ebp
add    $0x2,%ebx
test   $0x1,%bpl
je     1167 <ftod+0x57>
lea    0x6(%rbx),%esi
mov    $0x2,%edi
movaps %xmm0,(%rsp)
call   1030 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movapd (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movaps (%rsp),%xmm0
test   %ebx,%ebx
je     119e <ftod+0x8e>
test   $0x2,%bpl
je     1130 <ftod+0x20>
lea    0x7(%rbx),%esi
mov    $0x2,%edi
movaps %xmm0,(%rsp)
call   1030 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movapd (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movaps (%rsp),%xmm0
jmp    1130 <ftod+0x20>
test   %r14d,%r14d
jns    11aa <ftod+0x9a>
xorps  0xe56(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @ftod(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store i32 %0, i32* %2
store double 0.000000e+00, double* %3
%6 = load i32, i32* %2
%7 = ashr i32 %6, 31
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store double -1.000000e+00, double* %4
br label %11
10: ; preds = %1
store double 1.000000e+00, double* %4
br label %11
11: ; preds = %10, %9
%12 = load i32, i32* %2
%13 = call i32 @abs(i32 %12)
store i32 %13, i32* %2
store i32 -24, i32* %5
br label %14
14: ; preds = %30, %11
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 7
br i1 %16, label %17, label %33
17: ; preds = %14
%18 = load i32, i32* %2
%19 = and i32 %18, 1
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i32, i32* %5
%23 = call i64 @pow(i32 2, i32 %22)
%24 = sitofp i64 %23 to double
%25 = load double, double* %3
%26 = fadd double %25, %24
store double %26, double* %3
br label %27
27: ; preds = %21, %17
%28 = load i32, i32* %2
%29 = ashr i32 %28, 1
store i32 %29, i32* %2
br label %30
30: ; preds = %27
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %14
33: ; preds = %14
%34 = load double, double* %3
%35 = load double, double* %4
%36 = fmul double %34, %35
ret double %36
}

LLVM IR (-O2):
define double @ftod(i32 %0) {
%2 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
br label %3
3: ; preds = %25, %1
%4 = phi i32 [ -24, %1 ], [ %27, %25 ]
%5 = phi double [ 0.000000e+00, %1 ], [ %26, %25 ]
%6 = phi i32 [ %2, %1 ], [ %15, %25 ]
%7 = and i32 %6, 1
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %3
%10 = tail call i64 @pow(i32 2, i32 %4)
%11 = sitofp i64 %10 to double
%12 = fadd double %5, %11
br label %13
13: ; preds = %9, %3
%14 = phi double [ %12, %9 ], [ %5, %3 ]
%15 = lshr i32 %6, 2
%16 = or i32 %4, 1
%17 = icmp eq i32 %16, 7
br i1 %17, label %28, label %18
18: ; preds = %13
%19 = and i32 %6, 2
%20 = icmp eq i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = tail call i64 @pow(i32 2, i32 %16)
%23 = sitofp i64 %22 to double
%24 = fadd double %14, %23
br label %25
25: ; preds = %21, %18
%26 = phi double [ %24, %21 ], [ %14, %18 ]
%27 = add nsw i32 %4, 2
br label %3
28: ; preds = %13
%29 = icmp sgt i32 %0, -1
%30 = fneg double %14
%31 = select i1 %29, double %14, double %30
ret double %31
}