#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*/ convert_to_binary(int, char *, int);
int get_input();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int decimal, i;
  int bit_sig = 15;
  char binary[16];
  for (i = 0; i < 15; i++)
    binary[i] = '0';
  binary[bit_sig--] = '\0';
  printf("\n");
  decimal = get_input();
  convert_to_binary(decimal, binary, bit_sig);
  printf("The binary form of %d is %s\n\n", decimal, binary);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xf,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xf,-0xc(%rbp)
jge    116e <main+0x3e>
movslq -0xc(%rbp),%rax
movb   $0x30,-0x20(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114d <main+0x1d>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
cltq
movb   $0x0,-0x20(%rbp,%rax,1)
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <get_input@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <convert_to_binary@plt>
mov    -0x8(%rbp),%esi
lea    -0x20(%rbp),%rdx
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movabs $0x3030303030303030,%rax
30 30 30
mov    %rax,0x7(%rsp)
mov    %rax,(%rsp)
movb   $0x0,0xf(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1060 <get_input@plt>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0xe,%edx
call   1040 <convert_to_binary@plt>
lea    0xe75(%rip),%rdi
mov    %ebx,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [30 x i8] c"The binary form of %d is %s\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [16 x i8]
store i32 0, i32* %1
store i32 15, i32* %4
store i32 0, i32* %3
br label %6
6: ; preds = %13, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 15
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 %11
store i8 48, i8* %12
br label %13
13: ; preds = %9
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
br label %6
16: ; preds = %6
%17 = load i32, i32* %4
%18 = add nsw i32 %17, -1
store i32 %18, i32* %4
%19 = sext i32 %17 to i64
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 %19
store i8 0, i8* %20
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = call i32 (...) @get_input()
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%25 = load i32, i32* %4
%26 = call i32 @convert_to_binary(i32 %23, i8* %24, i32 %25)
%27 = load i32, i32* %2
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %27, i8* %28)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"The binary form of %d is %s\0A\0A\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 15
store i8 0, i8* %4
%5 = tail call i32 @putchar(i32 10)
%6 = tail call i32 (...) @get_input()
%7 = call i32 @convert_to_binary(i32 %6, i8* %3, i32 14)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %6, i8* %3)
ret i32 0
}