#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 binaryStringToInteger(char *);
int getInteger();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ toBinaryString(char *, int);
int main() {
  int i, result;
  char bin[17];
  printf("Enter a number ? ");
  i = getInteger();
  toBinaryString(bin, i);
  printf("Binary version = %s\n", bin);
  result = binaryStringToInteger(bin);
  printf("Result = %d\n", result);
  printf("Hex = %X\n", result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <getInteger@plt>
mov    %eax,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <toBinaryString@plt>
lea    -0x20(%rbp),%rsi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1060 <binaryStringToInteger@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <getInteger@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <toBinaryString@plt>
lea    0xea4(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <binaryStringToInteger@plt>
mov    %eax,%ebx
lea    0xe9e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Enter a number ? \00"
@.str.1 = [21 x i8] c"Binary version = %s\0A\00"
@.str.2 = [13 x i8] c"Result = %d\0A\00"
@.str.3 = [10 x i8] c"Hex = %X\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [17 x i8]
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (...) @getInteger()
store i32 %6, i32* %2
%7 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* %2
%9 = call i32 @toBinaryString(i8* %7, i32 %8)
%10 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%13 = call i32 @binaryStringToInteger(i8* %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %16)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Enter a number ? \00"
@.str.1 = [21 x i8] c"Binary version = %s\0A\00"
@.str.2 = [13 x i8] c"Result = %d\0A\00"
@.str.3 = [10 x i8] c"Hex = %X\0A\00"
define i32 @main() {
%1 = alloca [17 x i8]
%2 = getelementptr inbounds [17 x i8], [17 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (...) @getInteger()
%5 = call i32 @toBinaryString(i8* %2, i32 %4)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%7 = call i32 @binaryStringToInteger(i8* %2)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %7)
ret i32 0
}