#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 */
double atof(char *);
int checkarg(int, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memcpy(unsigned long *, double *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  double data;
  unsigned long buf;
  int i;
  char s[67];
  int rc;
  rc = checkarg(argc, argv);
  if (rc == 1) {
    printf("Usage: ./double-desc double-number\n");
    exit(1);
  } else {
    data = atof(argv[1]);
  }
  memcpy(&buf, &data, 8);
  for (i = 65; i >= 0; i--) {
    if (i == 1 || i == 13) {
      s[i] = '-';
    } else {
      if (buf % 2 == 1) {
        s[i] = '1';
      } else {
        s[i] = '0';
      }
      buf /= 2;
    }
  }
  s[66] = '\0';
  printf("%s\n", s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <checkarg@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x1,-0x74(%rbp)
jne    119a <main+0x4a>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1060 <memcpy@plt>
movl   $0x41,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1239 <main+0xe9>
cmpl   $0x1,-0x24(%rbp)
je     11e3 <main+0x93>
cmpl   $0xd,-0x24(%rbp)
jne    11f1 <main+0xa1>
movslq -0x24(%rbp),%rax
movb   $0x2d,-0x70(%rbp,%rax,1)
jmp    1226 <main+0xd6>
mov    -0x20(%rbp),%rax
and    $0x1,%rax
cmp    $0x1,%rax
jne    1211 <main+0xc1>
movslq -0x24(%rbp),%rax
movb   $0x31,-0x70(%rbp,%rax,1)
jmp    121a <main+0xca>
movslq -0x24(%rbp),%rax
movb   $0x30,-0x70(%rbp,%rax,1)
mov    -0x20(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    122b <main+0xdb>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    11c5 <main+0x75>
movb   $0x0,-0x2e(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x60,%rsp
mov    %rsi,%rbx
call   1050 <checkarg@plt>
cmp    $0x1,%eax
je     120d <main+0xbd>
mov    0x8(%rbx),%rdi
call   1040 <atof@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
call   1060 <memcpy@plt>
mov    $0x41,%ecx
mov    (%rsp),%rax
jmp    11ae <main+0x5e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x2d,0xf(%rsp,%rcx,1)
sub    $0x1,%rdx
mov    %rdx,%rcx
jb     11f6 <main+0xa6>
cmp    $0xd,%ecx
je     11b8 <main+0x68>
cmp    $0x1,%ecx
jne    11c0 <main+0x70>
movb   $0x2d,0x10(%rsp,%rcx,1)
jmp    11d3 <main+0x83>
nop
mov    %eax,%edx
and    $0x1,%dl
or     $0x30,%dl
mov    %dl,0x10(%rsp,%rcx,1)
shr    %rax
mov    %rax,(%rsp)
lea    -0x1(%rcx),%rdx
cmp    $0xd,%edx
je     11a0 <main+0x50>
cmp    $0x1,%edx
je     11a0 <main+0x50>
mov    %eax,%ebx
and    $0x1,%bl
or     $0x30,%bl
mov    %bl,0xf(%rsp,%rcx,1)
shr    %rax
mov    %rax,(%rsp)
jmp    11a5 <main+0x55>
movb   $0x0,0x52(%rsp)
lea    0x10(%rsp),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
ret
lea    0xdec(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"Usage: ./double-desc double-number\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca i64
%8 = alloca i32
%9 = alloca [67 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @checkarg(i32 %11, i8** %12)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call double @atof(i8* %22)
store double %23, double* %6
br label %24
24: ; preds = %19
%25 = call i32 @memcpy(i64* %7, double* %6, i32 8)
store i32 65, i32* %8
br label %26
26: ; preds = %55, %24
%27 = load i32, i32* %8
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %58
29: ; preds = %26
%30 = load i32, i32* %8
%31 = icmp eq i32 %30, 1
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i32, i32* %8
%34 = icmp eq i32 %33, 13
br i1 %34, label %35, label %39
35: ; preds = %32, %29
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [67 x i8], [67 x i8]* %9, i64 0, i64 %37
store i8 45, i8* %38
br label %54
39: ; preds = %32
%40 = load i64, i64* %7
%41 = urem i64 %40, 2
%42 = icmp eq i64 %41, 1
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [67 x i8], [67 x i8]* %9, i64 0, i64 %45
store i8 49, i8* %46
br label %51
47: ; preds = %39
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [67 x i8], [67 x i8]* %9, i64 0, i64 %49
store i8 48, i8* %50
br label %51
51: ; preds = %47, %43
%52 = load i64, i64* %7
%53 = udiv i64 %52, 2
store i64 %53, i64* %7
br label %54
54: ; preds = %51, %35
br label %55
55: ; preds = %54
%56 = load i32, i32* %8
%57 = add nsw i32 %56, -1
store i32 %57, i32* %8
br label %26
58: ; preds = %26
%59 = getelementptr inbounds [67 x i8], [67 x i8]* %9, i64 0, i64 66
store i8 0, i8* %59
%60 = getelementptr inbounds [67 x i8], [67 x i8]* %9, i64 0, i64 0
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %60)
ret i32 0
}

LLVM IR (-O2):
@str = [35 x i8] c"Usage: ./double-desc double-number\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca double
%4 = alloca i64
%5 = alloca [67 x i8]
%6 = bitcast double* %3 to i8*
%7 = bitcast i64* %4 to i8*
%8 = getelementptr inbounds [67 x i8], [67 x i8]* %5, i64 0, i64 0
%9 = tail call i32 @checkarg(i32 %0, i8** %1)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call double @atof(i8* %16)
store double %17, double* %3
%18 = call i32 @memcpy(i64* %4, double* %3, i32 8)
%19 = load i64, i64* %4
br label %20
20: ; preds = %44, %14
%21 = phi i64 [ 65, %14 ], [ %46, %44 ]
%22 = phi i64 [ %19, %14 ], [ %45, %44 ]
%23 = trunc i64 %21 to i32
switch i32 %23, label %26 [
i32 13, label %24
i32 1, label %24
]
24: ; preds = %20, %20
%25 = getelementptr inbounds [67 x i8], [67 x i8]* %5, i64 0, i64 %21
store i8 45, i8* %25
br label %32
26: ; preds = %20
%27 = and i64 %22, 1
%28 = icmp eq i64 %27, 0
%29 = select i1 %28, i8 48, i8 49
%30 = getelementptr inbounds [67 x i8], [67 x i8]* %5, i64 0, i64 %21
store i8 %29, i8* %30
%31 = lshr i64 %22, 1
store i64 %31, i64* %4
br label %32
32: ; preds = %24, %26
%33 = phi i64 [ %22, %24 ], [ %31, %26 ]
%34 = add nsw i64 %21, -1
%35 = trunc i64 %34 to i32
switch i32 %35, label %38 [
i32 13, label %36
i32 1, label %36
]
36: ; preds = %32, %32
%37 = getelementptr inbounds [67 x i8], [67 x i8]* %5, i64 0, i64 %34
store i8 45, i8* %37
br label %44
38: ; preds = %32
%39 = and i64 %33, 1
%40 = icmp eq i64 %39, 0
%41 = select i1 %40, i8 48, i8 49
%42 = getelementptr inbounds [67 x i8], [67 x i8]* %5, i64 0, i64 %34
store i8 %41, i8* %42
%43 = lshr i64 %33, 1
store i64 %43, i64* %4
br label %44
44: ; preds = %38, %36
%45 = phi i64 [ %33, %36 ], [ %43, %38 ]
%46 = add nsw i64 %21, -2
%47 = icmp eq i64 %34, 0
br i1 %47, label %48, label %20
48: ; preds = %44
%49 = getelementptr inbounds [67 x i8], [67 x i8]* %5, i64 0, i64 66
store i8 0, i8* %49
%50 = call i32 @puts(i8* %8)
ret i32 0
}