#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);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int num, sum = 0, last_bit;
  scanf("%d", &num);
  int digit = 0;
  while (num) {
    last_bit = num % 2;
    num = num / 2;
    sum = last_bit * pow(10, digit) + sum;
    digit = digit + 1;
  }
  printf("sum = %d", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeb9(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11b2 <main+0x82>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    $0xa,%edi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
imul   %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115d <main+0x2d>
mov    -0xc(%rbp),%esi
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec7(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%ebx
test   %ebx,%ebx
je     1193 <main+0x63>
xor    %ebp,%ebp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
mov    %eax,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%ebx
sar    %eax
mov    %eax,0xc(%rsp)
mov    $0xa,%edi
mov    %ebp,%esi
call   1050 <pow@plt>
imul   %ebx,%eax
add    %eax,%r14d
add    $0x1,%ebp
mov    0xc(%rsp),%ebx
test   %ebx,%ebx
jne    1160 <main+0x30>
jmp    1196 <main+0x66>
xor    %r14d,%r14d
lea    0xe63(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"sum = %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %5
br label %7
7: ; preds = %10, %0
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = load i32, i32* %2
%12 = srem i32 %11, 2
store i32 %12, i32* %4
%13 = load i32, i32* %2
%14 = sdiv i32 %13, 2
store i32 %14, i32* %2
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = call i32 @pow(i32 10, i32 %16)
%18 = mul nsw i32 %15, %17
%19 = load i32, i32* %3
%20 = add nsw i32 %18, %19
store i32 %20, i32* %3
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %7
23: ; preds = %7
%24 = load i32, i32* %3
%25 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"sum = %d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = icmp eq i32 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %0, %6
%7 = phi i32 [ %16, %6 ], [ %4, %0 ]
%8 = phi i32 [ %15, %6 ], [ 0, %0 ]
%9 = phi i32 [ %14, %6 ], [ 0, %0 ]
%10 = srem i32 %7, 2
%11 = sdiv i32 %7, 2
store i32 %11, i32* %1
%12 = call i32 @pow(i32 10, i32 %8)
%13 = mul nsw i32 %12, %10
%14 = add nsw i32 %13, %9
%15 = add nuw nsw i32 %8, 1
%16 = load i32, i32* %1
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %6, %0
%19 = phi i32 [ 0, %0 ], [ %14, %6 ]
%20 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %19)
ret i32 0
}