#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int binary_number = 0;
  int decimal_number = 0;
  int digit = 0;
  int counter = 0;
  int weight = 1;
  printf("please Enter binary number at most 5 digits:");
  scanf("%d", &binary_number);
  for (counter = 0; counter < 5; counter++) {
    if (counter == 0) {
      digit = binary_number % 10;
    } else {
      binary_number = binary_number / 10;
      digit = binary_number % 10;
    }
    decimal_number = decimal_number + digit * weight;
    weight = weight * 2;
  }
  printf("%d\n", decimal_number);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    11e0 <main+0xc0>
cmpl   $0x0,-0x14(%rbp)
jne    119e <main+0x7e>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
jmp    11ba <main+0x9a>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1177 <main+0x57>
mov    -0xc(%rbp),%esi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xed0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeef(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
movslq 0x4(%rsp),%r8
imul   $0x51eb851f,%r8,%rsi
mov    %rsi,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rsi
add    %ecx,%esi
imul   $0x10624dd3,%r8,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rdx
add    %ecx,%edx
imul   $0x68db8bad,%r8,%rcx
mov    %rcx,%rdi
shr    $0x3f,%rdi
sar    $0x2c,%rcx
add    %edi,%ecx
mov    %ecx,0x4(%rsp)
movslq %ecx,%rcx
imul   $0x66666667,%rcx,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
shr    $0x22,%rdi
add    %eax,%edi
add    %edi,%edi
lea    (%rdi,%rdi,4),%eax
sub    %eax,%ecx
shl    $0x4,%ecx
movslq %edx,%r9
imul   $0x66666667,%r9,%rax
mov    %rax,%rdi
shr    $0x3f,%rdi
shr    $0x22,%rax
add    %edi,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r9d
movslq %esi,%rsi
imul   $0x66666667,%rsi,%rax
mov    %rax,%rdi
shr    $0x3f,%rdi
shr    $0x22,%rax
add    %edi,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%esi
imul   $0x66666667,%r8,%rax
mov    %rax,%rdi
shr    $0x3f,%rdi
sar    $0x22,%rax
add    %edi,%eax
cltq
imul   $0x66666667,%rax,%rdi
mov    %rdi,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rdi
add    %edx,%edi
add    %edi,%edi
lea    (%rdi,%rdi,4),%edx
mov    %eax,%edi
sub    %edx,%edi
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r8d
lea    (%r8,%rdi,2),%eax
lea    (%rax,%rsi,4),%eax
lea    (%rax,%r9,8),%esi
add    %ecx,%esi
lea    0xdf6(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [45 x i8] c"please Enter binary number at most 5 digits:\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
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 1, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 0, i32* %5
br label %9
9: ; preds = %31, %0
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 5
br i1 %11, label %12, label %34
12: ; preds = %9
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* %2
%17 = srem i32 %16, 10
store i32 %17, i32* %4
br label %23
18: ; preds = %12
%19 = load i32, i32* %2
%20 = sdiv i32 %19, 10
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = srem i32 %21, 10
store i32 %22, i32* %4
br label %23
23: ; preds = %18, %15
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = load i32, i32* %6
%27 = mul nsw i32 %25, %26
%28 = add nsw i32 %24, %27
store i32 %28, i32* %3
%29 = load i32, i32* %6
%30 = mul nsw i32 %29, 2
store i32 %30, i32* %6
br label %31
31: ; preds = %23
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %9
34: ; preds = %9
%35 = load i32, i32* %3
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %35)
ret i32 0
}

LLVM IR (-O2):
@.str = [45 x i8] c"please Enter binary number at most 5 digits:\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*
store i32 0, i32* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 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 = sdiv i32 %5, 10
%7 = sdiv i32 %5, 100
%8 = sdiv i32 %5, 1000
%9 = sdiv i32 %5, 10000
store i32 %9, i32* %1
%10 = srem i32 %9, 10
%11 = shl nsw i32 %10, 4
%12 = srem i32 %8, 10
%13 = shl nsw i32 %12, 3
%14 = srem i32 %7, 10
%15 = shl nsw i32 %14, 2
%16 = srem i32 %6, 10
%17 = shl nsw i32 %16, 1
%18 = srem i32 %5, 10
%19 = add nsw i32 %17, %18
%20 = add nsw i32 %15, %19
%21 = add nsw i32 %13, %20
%22 = add nsw i32 %11, %21
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %22)
ret i32 0
}