#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 num;
  int i;
  int sum = 0;
  printf("Enter an integer binary number: ");
  scanf("%d", &num);
  for (i = 0; num >= 1; i++) {
    sum = ((num % 10) * pow(2, i)) + sum;
    num = num / 10;
  }
  printf("The decimal form is %d", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeda(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     11ba <main+0x8a>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0xc(%rbp),%esi
mov    $0x2,%edi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
imul   %ecx,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116b <main+0x3b>
mov    -0x10(%rbp),%esi
lea    0xe5d(%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   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec2(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee6(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%ebx
test   %ebx,%ebx
jle    11b9 <main+0x89>
xor    %r14d,%r14d
mov    $0xcccccccd,%r15d
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %ebx,%eax
imul   %r15,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
mov    $0x2,%edi
mov    %ebp,%esi
call   1050 <pow@plt>
imul   %ebx,%eax
add    %eax,%r14d
movslq 0x4(%rsp),%rax
imul   $0x66666667,%rax,%rbx
mov    %rbx,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rbx
add    %ecx,%ebx
add    $0x1,%ebp
mov    %ebx,0x4(%rsp)
cmp    $0x9,%rax
jg     1170 <main+0x40>
lea    0xe61(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [33 x i8] c"Enter an integer binary number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"The decimal form 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 ([33 x i8], [33 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 sgt i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %0, %7
%8 = phi i32 [ %14, %7 ], [ 0, %0 ]
%9 = phi i32 [ %17, %7 ], [ 0, %0 ]
%10 = phi i32 [ %16, %7 ], [ %5, %0 ]
%11 = urem i32 %10, 10
%12 = call i32 @pow(i32 2, i32 %9)
%13 = mul nsw i32 %12, %11
%14 = add nsw i32 %13, %8
%15 = load i32, i32* %1
%16 = sdiv i32 %15, 10
store i32 %16, i32* %1
%17 = add nuw nsw i32 %9, 1
%18 = icmp sgt i32 %15, 9
br i1 %18, label %7, label %19
19: ; preds = %7, %0
%20 = phi i32 [ 0, %0 ], [ %14, %7 ]
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %20)
ret i32 0
}