#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 pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int input = 0, rem = 0, counter_digit = 0, msb_zero = 0, reverse = 0,
      counter_second = 0, result = 0, tmp = 0;
  printf("Please enter a positive integer. \n");
  scanf("%d", &input);
  while (input != 0) {
    rem = input % 2;
    input = input / 2;
    counter_digit++;
    reverse = (reverse * 10) + rem;
  }
  tmp = reverse;
  while (reverse != 0) {
    reverse = reverse / 10;
    counter_second++;
  }
  msb_zero = counter_digit - counter_second;
  while (tmp != 0) {
    rem = tmp % 10;
    tmp = tmp / 10;
    result = (result * 10) + rem;
  }
  result = (int)result * pow(10, msb_zero);
  printf("The binary representation is %d.", result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe97(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
je     11d3 <main+0xa3>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
imul   $0xa,-0x18(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1195 <main+0x65>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11ff <main+0xcf>
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d9 <main+0xa9>
mov    -0x10(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     123d <main+0x10d>
mov    -0x24(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x24(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
imul   $0xa,-0x20(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1208 <main+0xd8>
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%esi
mov    $0xa,%edi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
lea    0xea1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
je     1223 <main+0xe3>
xor    %eax,%eax
xor    %esi,%esi
nopl   0x0(%rax)
mov    %ecx,%edx
mov    %ecx,%edi
shr    $0x1f,%edi
add    %ecx,%edi
mov    %edi,%ecx
sar    %ecx
and    $0xfffffffe,%edi
mov    %edx,%ebx
sub    %edi,%ebx
add    $0x1,%esi
lea    (%rax,%rax,4),%eax
lea    (%rbx,%rax,2),%eax
add    $0x1,%edx
cmp    $0x3,%edx
jae    1180 <main+0x40>
mov    %ecx,0x4(%rsp)
xor    %ecx,%ecx
test   %eax,%eax
je     1227 <main+0xe7>
mov    %eax,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movslq %edx,%rdi
imul   $0x66666667,%rdi,%rdx
mov    %rdx,%rbx
shr    $0x3f,%rbx
sar    $0x22,%rdx
add    %ebx,%edx
add    $0x1,%ecx
add    $0x9,%edi
cmp    $0x13,%edi
jae    11c0 <main+0x80>
xor    %r14d,%r14d
test   %eax,%eax
je     122a <main+0xea>
nopl   0x0(%rax)
movslq %eax,%rbx
imul   $0x66666667,%rbx,%rax
mov    %rax,%rdi
shr    $0x3f,%rdi
sar    $0x22,%rax
add    %edi,%eax
lea    (%rax,%rax,1),%edi
lea    (%rdi,%rdi,4),%edi
mov    %ebx,%edx
sub    %edi,%edx
lea    (%r14,%r14,4),%edi
lea    (%rdx,%rdi,2),%r14d
add    $0x9,%ebx
cmp    $0x12,%ebx
ja     11f0 <main+0xb0>
jmp    122a <main+0xea>
xor    %ecx,%ecx
xor    %esi,%esi
xor    %r14d,%r14d
sub    %ecx,%esi
mov    $0xa,%edi
call   1060 <pow@plt>
imul   %eax,%r14d
lea    0xdc2(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Please enter a positive integer. \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"The binary representation is %d.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %12
12: ; preds = %15, %0
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = load i32, i32* %2
%17 = srem i32 %16, 2
store i32 %17, i32* %3
%18 = load i32, i32* %2
%19 = sdiv i32 %18, 2
store i32 %19, i32* %2
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
%22 = load i32, i32* %6
%23 = mul nsw i32 %22, 10
%24 = load i32, i32* %3
%25 = add nsw i32 %23, %24
store i32 %25, i32* %6
br label %12
26: ; preds = %12
%27 = load i32, i32* %6
store i32 %27, i32* %9
br label %28
28: ; preds = %31, %26
%29 = load i32, i32* %6
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load i32, i32* %6
%33 = sdiv i32 %32, 10
store i32 %33, i32* %6
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %28
36: ; preds = %28
%37 = load i32, i32* %4
%38 = load i32, i32* %7
%39 = sub nsw i32 %37, %38
store i32 %39, i32* %5
br label %40
40: ; preds = %43, %36
%41 = load i32, i32* %9
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %52
43: ; preds = %40
%44 = load i32, i32* %9
%45 = srem i32 %44, 10
store i32 %45, i32* %3
%46 = load i32, i32* %9
%47 = sdiv i32 %46, 10
store i32 %47, i32* %9
%48 = load i32, i32* %8
%49 = mul nsw i32 %48, 10
%50 = load i32, i32* %3
%51 = add nsw i32 %49, %50
store i32 %51, i32* %8
br label %40
52: ; preds = %40
%53 = load i32, i32* %8
%54 = load i32, i32* %5
%55 = call i32 @pow(i32 10, i32 %54)
%56 = mul nsw i32 %53, %55
store i32 %56, i32* %8
%57 = load i32, i32* %8
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %57)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"The binary representation is %d.\00"
@str = [34 x i8] c"Please enter a positive integer. \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, 0
br i1 %6, label %37, label %9
7: ; preds = %9
store i32 %14, i32* %1
%8 = icmp eq i32 %17, 0
br i1 %8, label %37, label %21
9: ; preds = %0, %9
%10 = phi i32 [ %17, %9 ], [ 0, %0 ]
%11 = phi i32 [ %15, %9 ], [ 0, %0 ]
%12 = phi i32 [ %14, %9 ], [ %5, %0 ]
%13 = srem i32 %12, 2
%14 = sdiv i32 %12, 2
%15 = add nuw nsw i32 %11, 1
%16 = mul nsw i32 %10, 10
%17 = add nsw i32 %16, %13
%18 = add i32 %12, 1
%19 = icmp ult i32 %18, 3
br i1 %19, label %7, label %9
20: ; preds = %21
br i1 %8, label %37, label %28
21: ; preds = %7, %21
%22 = phi i32 [ %25, %21 ], [ 0, %7 ]
%23 = phi i32 [ %24, %21 ], [ %17, %7 ]
%24 = sdiv i32 %23, 10
%25 = add nuw nsw i32 %22, 1
%26 = add i32 %23, 9
%27 = icmp ult i32 %26, 19
br i1 %27, label %20, label %21
28: ; preds = %20, %28
%29 = phi i32 [ %32, %28 ], [ %17, %20 ]
%30 = phi i32 [ %34, %28 ], [ 0, %20 ]
%31 = srem i32 %29, 10
%32 = sdiv i32 %29, 10
%33 = mul nsw i32 %30, 10
%34 = add nsw i32 %31, %33
%35 = add i32 %29, 9
%36 = icmp ult i32 %35, 19
br i1 %36, label %37, label %28
37: ; preds = %28, %0, %7, %20
%38 = phi i32 [ %25, %20 ], [ 0, %7 ], [ 0, %0 ], [ %25, %28 ]
%39 = phi i32 [ %15, %20 ], [ %15, %7 ], [ 0, %0 ], [ %15, %28 ]
%40 = phi i32 [ 0, %20 ], [ 0, %7 ], [ 0, %0 ], [ %34, %28 ]
%41 = sub nsw i32 %39, %38
%42 = call i32 @pow(i32 10, i32 %41)
%43 = mul nsw i32 %42, %40
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %43)
ret i32 0
}