#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 Bin2Dec(int a) {
  int b = a;
  int i;
  int ret = 0;
  for (i = 0; i <= 7; i++) {
    ret = ret + (b % 10) * pow(2, i);
    b = (b - (b % 10)) / 10;
  }
  return ret;
}


x86 assembly (clang, -O0):
<Bin2Dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x7,-0xc(%rbp)
jg     1199 <Bin2Dec+0x89>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0xc(%rbp),%esi
mov    $0x2,%edi
call   1030 <pow@plt>
mov    -0x1c(%rbp),%edx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
imul   %ecx,%edx
add    %edx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x14(%rbp),%eax
sub    %edx,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112f <Bin2Dec+0x1f>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Bin2Dec>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x2,%edi
xor    %esi,%esi
call   1030 <pow@plt>
mov    %eax,%r15d
movslq %ebp,%r14
imul   $0x66666667,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
lea    (%rax,%rax,1),%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %r14d,%edx
sub    %ecx,%edx
imul   %edx,%r15d
movslq %eax,%rbx
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
mov    $0x2,%edi
mov    $0x1,%esi
call   1030 <pow@plt>
mov    %eax,%ebp
imul   %ebx,%ebp
add    %r15d,%ebp
imul   $0x51eb851f,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
movslq %eax,%rbx
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
mov    $0x2,%edi
mov    $0x2,%esi
call   1030 <pow@plt>
mov    %eax,%r15d
imul   %ebx,%r15d
add    %ebp,%r15d
imul   $0x10624dd3,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
movslq %eax,%rbx
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
mov    $0x2,%edi
mov    $0x3,%esi
call   1030 <pow@plt>
mov    %eax,%ebp
imul   %ebx,%ebp
add    %r15d,%ebp
imul   $0x68db8bad,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2c,%rax
add    %ecx,%eax
movslq %eax,%rbx
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
mov    $0x2,%edi
mov    $0x4,%esi
call   1030 <pow@plt>
mov    %eax,%r15d
imul   %ebx,%r15d
add    %ebp,%r15d
imul   $0x14f8b589,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2d,%rax
add    %ecx,%eax
movswl %ax,%ecx
imul   $0x6667,%ecx,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x12,%ecx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
movswl %ax,%ebx
mov    $0x2,%edi
mov    $0x5,%esi
call   1030 <pow@plt>
mov    %eax,%ebp
imul   %ebx,%ebp
add    %r15d,%ebp
imul   $0x431bde83,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x32,%rax
add    %ecx,%eax
imul   $0x6667,%eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x12,%ecx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
movswl %ax,%r15d
mov    $0x2,%edi
mov    $0x6,%esi
call   1030 <pow@plt>
mov    %eax,%ebx
imul   %r15d,%ebx
add    %ebp,%ebx
imul   $0x6b5fca6b,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x36,%rax
add    %ecx,%eax
imul   $0x6667,%eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x12,%ecx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
movswl %ax,%ebp
mov    $0x2,%edi
mov    $0x7,%esi
call   1030 <pow@plt>
imul   %ebp,%eax
add    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @Bin2Dec(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
store i32 %6, i32* %3
store i32 0, i32* %5
store i32 0, i32* %4
br label %7
7: ; preds = %23, %1
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 7
br i1 %9, label %10, label %26
10: ; preds = %7
%11 = load i32, i32* %5
%12 = load i32, i32* %3
%13 = srem i32 %12, 10
%14 = load i32, i32* %4
%15 = call i32 @pow(i32 2, i32 %14)
%16 = mul nsw i32 %13, %15
%17 = add nsw i32 %11, %16
store i32 %17, i32* %5
%18 = load i32, i32* %3
%19 = load i32, i32* %3
%20 = srem i32 %19, 10
%21 = sub nsw i32 %18, %20
%22 = sdiv i32 %21, 10
store i32 %22, i32* %3
br label %23
23: ; preds = %10
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %7
26: ; preds = %7
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
define i32 @Bin2Dec(i32 %0) {
%2 = srem i32 %0, 10
%3 = tail call i32 @pow(i32 2, i32 0)
%4 = mul nsw i32 %3, %2
%5 = sdiv i32 %0, 10
%6 = srem i32 %5, 10
%7 = tail call i32 @pow(i32 2, i32 1)
%8 = mul nsw i32 %7, %6
%9 = add nsw i32 %8, %4
%10 = sdiv i32 %0, 100
%11 = srem i32 %10, 10
%12 = tail call i32 @pow(i32 2, i32 2)
%13 = mul nsw i32 %12, %11
%14 = add nsw i32 %13, %9
%15 = sdiv i32 %0, 1000
%16 = srem i32 %15, 10
%17 = tail call i32 @pow(i32 2, i32 3)
%18 = mul nsw i32 %17, %16
%19 = add nsw i32 %18, %14
%20 = sdiv i32 %0, 10000
%21 = srem i32 %20, 10
%22 = tail call i32 @pow(i32 2, i32 4)
%23 = mul nsw i32 %22, %21
%24 = add nsw i32 %23, %19
%25 = sdiv i32 %0, 100000
%26 = trunc i32 %25 to i16
%27 = srem i16 %26, 10
%28 = sext i16 %27 to i32
%29 = tail call i32 @pow(i32 2, i32 5)
%30 = mul nsw i32 %29, %28
%31 = add nsw i32 %30, %24
%32 = sdiv i32 %0, 1000000
%33 = trunc i32 %32 to i16
%34 = srem i16 %33, 10
%35 = sext i16 %34 to i32
%36 = tail call i32 @pow(i32 2, i32 6)
%37 = mul nsw i32 %36, %35
%38 = add nsw i32 %37, %31
%39 = sdiv i32 %0, 10000000
%40 = trunc i32 %39 to i16
%41 = srem i16 %40, 10
%42 = sext i16 %41 to i32
%43 = tail call i32 @pow(i32 2, i32 7)
%44 = mul nsw i32 %43, %42
%45 = add nsw i32 %44, %38
ret i32 %45
}