#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 i = 1, rem, n, temp, sum = 0, bin;
  sum = 0;
  i = 0;
  printf("Enter number to convert to decimal: ");
  scanf("%d", &temp);
  while (temp != 0) {
    rem = temp % 10;
    temp /= 10;
    bin = pow(2, i);
    sum = sum + rem * bin;
    i++;
  }
  printf("%d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x14(%rbp)
je     11cc <main+0x9c>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%esi
mov    $0x2,%edi
call   1050 <pow@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1179 <main+0x49>
mov    -0x18(%rbp),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
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    0xec1(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed5(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     11b0 <main+0x80>
xor    %ebp,%ebp
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
movslq %eax,%rbx
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
lea    (%rax,%rax,1),%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%ebx
mov    %eax,0xc(%rsp)
mov    $0x2,%edi
mov    %ebp,%esi
call   1050 <pow@plt>
imul   %ebx,%eax
add    %eax,%r14d
add    $0x1,%ebp
mov    0xc(%rsp),%eax
test   %eax,%eax
jne    1170 <main+0x40>
lea    0xe71(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Enter number to convert to decimal: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\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
store i32 0, i32* %1
store i32 1, i32* %2
store i32 0, i32* %6
store i32 0, i32* %6
store i32 0, i32* %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
br label %10
10: ; preds = %13, %0
%11 = load i32, i32* %5
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %27
13: ; preds = %10
%14 = load i32, i32* %5
%15 = srem i32 %14, 10
store i32 %15, i32* %3
%16 = load i32, i32* %5
%17 = sdiv i32 %16, 10
store i32 %17, i32* %5
%18 = load i32, i32* %2
%19 = call i32 @pow(i32 2, i32 %18)
store i32 %19, i32* %7
%20 = load i32, i32* %6
%21 = load i32, i32* %3
%22 = load i32, i32* %7
%23 = mul nsw i32 %21, %22
%24 = add nsw i32 %20, %23
store i32 %24, i32* %6
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %10
27: ; preds = %10
%28 = load i32, i32* %6
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %28)
ret i32 0
}

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