#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 bin, digit, i, decimal;
  i = decimal = 0;
  printf("Enter a binary number: ");
  scanf("%d", &bin);
  while (bin) {
    digit = bin % 10;
    bin /= 10;
    decimal += digit * pow(2, i);
    i++;
  }
  printf("The number in decimal is: %d", decimal);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
je     11c0 <main+0x90>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%esi
mov    $0x2,%edi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
imul   %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116b <main+0x3b>
mov    -0x14(%rbp),%esi
lea    0xe4e(%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    0xee2(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     11b0 <main+0x80>
xor    %r14d,%r14d
xor    %ebp,%ebp
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    0xe61(%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 = [24 x i8] c"Enter a binary number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"The number in decimal is: %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* %5
store i32 0, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %8
8: ; preds = %11, %0
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = load i32, i32* %2
%13 = srem i32 %12, 10
store i32 %13, i32* %3
%14 = load i32, i32* %2
%15 = sdiv i32 %14, 10
store i32 %15, i32* %2
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = call i32 @pow(i32 2, i32 %17)
%19 = mul nsw i32 %16, %18
%20 = load i32, i32* %5
%21 = add nsw i32 %20, %19
store i32 %21, i32* %5
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %8
24: ; preds = %8
%25 = load i32, i32* %5
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"Enter a binary number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"The number in decimal is: %d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 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 [ %15, %7 ], [ 0, %0 ]
%10 = phi i32 [ %16, %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 %10)
%14 = mul nsw i32 %13, %11
%15 = add nsw i32 %14, %9
%16 = add nuw nsw i32 %10, 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 ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %20)
ret i32 0
}