#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*/ dec_to_bin(int);
int /*<<< orphan*/ printf(char *);
int scanf(char *, int *);
int /*<<< orphan*/ to_binary(int);
int main() {
  int n;
  dec_to_bin(-9);
  dec_to_bin(9);
  printf("enter a number(q to quit)!\n");
  while ((scanf("%d", &n)) == 1) {
    printf("Binary equivalent:");
    to_binary(n);
    printf("\n");
    printf("enter a number(q to quit):\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xfffffff7,%edi
call   1030 <dec_to_bin@plt>
mov    $0x9,%edi
call   1030 <dec_to_bin@plt>
lea    0xe96(%rip),%rdi
call   1050 <printf@plt>
lea    0xea6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    11b9 <main+0x79>
lea    0xe90(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <to_binary@plt>
lea    0xe77(%rip),%rdi
call   1050 <printf@plt>
lea    0xe83(%rip),%rdi
call   1050 <printf@plt>
jmp    116f <main+0x2f>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0xfffffff7,%edi
call   1050 <dec_to_bin@plt>
mov    $0x9,%edi
call   1050 <dec_to_bin@plt>
lea    0xe93(%rip),%rdi
call   1040 <puts@plt>
lea    0xe71(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
cmp    $0x1,%eax
jne    11f3 <main+0x93>
lea    0xe5e(%rip),%r14
lea    0xe85(%rip),%r15
lea    0xe4d(%rip),%r12
lea    0x4(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1070 <printf@plt>
mov    0x4(%rsp),%edi
call   1060 <to_binary@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
cmp    $0x1,%eax
je     11c0 <main+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"enter a number(q to quit)!\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"Binary equivalent:\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [28 x i8] c"enter a number(q to quit):\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @dec_to_bin(i32 -9)
%4 = call i32 @dec_to_bin(i32 9)
%5 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %9, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* %2
%12 = call i32 @to_binary(i32 %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %6
15: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"Binary equivalent:\00"
@str = [27 x i8] c"enter a number(q to quit)!\00"
@str.5 = [27 x i8] c"enter a number(q to quit):\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @dec_to_bin(i32 -9)
%4 = tail call i32 @dec_to_bin(i32 9)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %16
8: ; preds = %0, %8
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* %1
%11 = call i32 @to_binary(i32 %10)
%12 = call i32 @putchar(i32 10)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%15 = icmp eq i32 %14, 1
br i1 %15, label %8, label %16
16: ; preds = %8, %0
ret i32 0
}