#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*/ printf(char *);
void to_binary(double input) {
  if (input < 0 || input >= 1) {
    printf("Unsupported input.");
  }
  printf("0.");
  double frac = 1.0;
  for (int i = 0; i < 32; i++) {
    if (input == 0)
      break;
    frac /= 2;
    if (input >= frac) {
      input -= frac;
      printf("1");
    } else {
      printf("0");
    }
  }
  printf("\n");
  if (input > 0)
    printf("Overflow error\n");
}


x86 assembly (clang, -O0):
<to_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
ja     1142 <to_binary+0x32>
movsd  -0x8(%rbp),%xmm0
movsd  0xec8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     114e <to_binary+0x3e>
lea    0xec7(%rip),%rdi
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
call   1030 <printf@plt>
movsd  0xe9e(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x20,-0x14(%rbp)
jge    11fe <to_binary+0xee>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1195 <to_binary+0x85>
jp     1195 <to_binary+0x85>
jmp    11fe <to_binary+0xee>
movsd  -0x10(%rbp),%xmm0
movsd  0xe66(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     11df <to_binary+0xcf>
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
jmp    11eb <to_binary+0xdb>
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
jmp    11f0 <to_binary+0xe0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116e <to_binary+0x5e>
lea    0xe33(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1228 <to_binary+0x118>
lea    0xe07(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_binary>:
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
movsd  %xmm0,(%rsp)
ja     114e <to_binary+0x1e>
ucomisd 0xeb4(%rip),%xmm0
jb     115a <to_binary+0x2a>
lea    0xec3(%rip),%rdi
call   1050 <printf@plt>
lea    0xeca(%rip),%rdi
call   1050 <printf@plt>
movsd  (%rsp),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1177 <to_binary+0x47>
jnp    11f0 <to_binary+0xc0>
movsd  0xe81(%rip),%xmm2
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mulsd  0xe70(%rip),%xmm2
ucomisd %xmm2,%xmm1
mov    $0x31,%edi
sbb    $0x0,%edi
ucomisd %xmm2,%xmm1
xorpd  %xmm0,%xmm0
jb     11b2 <to_binary+0x82>
movapd %xmm2,%xmm0
movsd  %xmm2,0x8(%rsp)
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
call   1030 <putchar@plt>
cmp    $0x1e,%ebx
ja     11eb <to_binary+0xbb>
add    $0x1,%ebx
movsd  (%rsp),%xmm0
ucomisd 0xe35(%rip),%xmm0
movapd %xmm0,%xmm1
movsd  0x8(%rsp),%xmm2
jne    1190 <to_binary+0x60>
jp     1190 <to_binary+0x60>
jmp    11f0 <to_binary+0xc0>
movsd  (%rsp),%xmm1
movsd  %xmm1,(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  (%rsp),%xmm0
ucomisd 0xe04(%rip),%xmm0
jbe    121f <to_binary+0xef>
lea    0xe19(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1040 <puts@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Unsupported input.\00"
@.str.1 = [3 x i8] c"0.\00"
@.str.2 = [2 x i8] c"1\00"
@.str.3 = [2 x i8] c"0\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [16 x i8] c"Overflow error\0A\00"
define void @to_binary(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
store double %0, double* %2
%5 = load double, double* %2
%6 = fcmp olt double %5, 0.000000e+00
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load double, double* %2
%9 = fcmp oge double %8, 1.000000e+00
br i1 %9, label %10, label %12
10: ; preds = %7, %1
%11 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store double 1.000000e+00, double* %3
store i32 0, i32* %4
br label %14
14: ; preds = %35, %12
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 32
br i1 %16, label %17, label %38
17: ; preds = %14
%18 = load double, double* %2
%19 = fcmp oeq double %18, 0.000000e+00
br i1 %19, label %20, label %21
20: ; preds = %17
br label %38
21: ; preds = %17
%22 = load double, double* %3
%23 = fdiv double %22, 2.000000e+00
store double %23, double* %3
%24 = load double, double* %2
%25 = load double, double* %3
%26 = fcmp oge double %24, %25
br i1 %26, label %27, label %32
27: ; preds = %21
%28 = load double, double* %3
%29 = load double, double* %2
%30 = fsub double %29, %28
store double %30, double* %2
%31 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %34
32: ; preds = %21
%33 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
br label %35
35: ; preds = %34
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %14
38: ; preds = %20, %14
%39 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%40 = load double, double* %2
%41 = fcmp ogt double %40, 0.000000e+00
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"Unsupported input.\00"
@.str.1 = [3 x i8] c"0.\00"
@str = [15 x i8] c"Overflow error\00"
define void @to_binary(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
%3 = fcmp oge double %0, 1.000000e+00
%4 = or i1 %2, %3
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %1, %5
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = fcmp oeq double %0, 0.000000e+00
br i1 %9, label %24, label %10
10: ; preds = %7, %10
%11 = phi i32 [ %20, %10 ], [ 0, %7 ]
%12 = phi double [ %14, %10 ], [ 1.000000e+00, %7 ]
%13 = phi double [ %18, %10 ], [ %0, %7 ]
%14 = fmul double %12, 5.000000e-01
%15 = fcmp ult double %13, %14
%16 = select i1 %15, i32 48, i32 49
%17 = select i1 %15, double 0.000000e+00, double %14
%18 = fsub double %13, %17
%19 = tail call i32 @putchar(i32 %16)
%20 = add nuw nsw i32 %11, 1
%21 = icmp ugt i32 %11, 30
%22 = fcmp oeq double %18, 0.000000e+00
%23 = select i1 %21, i1 true, i1 %22
br i1 %23, label %24, label %10
24: ; preds = %10, %7
%25 = phi double [ %0, %7 ], [ %18, %10 ]
%26 = tail call i32 @putchar(i32 10)
%27 = fcmp ogt double %25, 0.000000e+00
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
ret void
}