#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 strlen(char *);
int decimal_value(char *str) {
  int n = 0;
  int size = strlen(str) - 1;
  int count = 0;
  while (*str != '\0') {
    if (*str == '1')
      n = n + pow(2, size - count);
    count++;
    str++;
  }
  return n;
}


x86 assembly (clang, -O0):
<decimal_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a3 <decimal_value+0x83>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x31,%eax
jne    1189 <decimal_value+0x69>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%esi
sub    -0x14(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1149 <decimal_value+0x29>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decimal_value>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
add    $0xffffffff,%ebp
xor    %r14d,%r14d
jmp    1156 <decimal_value+0x36>
cs nopw 0x0(%rax,%rax,1)
mov    $0x2,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
add    %eax,%r14d
add    $0x1,%rbx
add    $0xffffffff,%ebp
movzbl (%rbx),%eax
cmp    $0x31,%al
je     1140 <decimal_value+0x20>
test   %al,%al
jne    114f <decimal_value+0x2f>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @decimal_value(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = sub nsw i32 %7, 1
store i32 %8, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %26, %1
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %9
%15 = load i8*, i8** %2
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 49
br i1 %18, label %19, label %26
19: ; preds = %14
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = sub nsw i32 %21, %22
%24 = call i32 @pow(i32 2, i32 %23)
%25 = add nsw i32 %20, %24
store i32 %25, i32* %3
br label %26
26: ; preds = %19, %14
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
%29 = load i8*, i8** %2
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %2
br label %9
31: ; preds = %9
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
define i32 @decimal_value(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
br label %3
3: ; preds = %13, %1
%4 = phi i32 [ 0, %1 ], [ %14, %13 ]
%5 = phi i8* [ %0, %1 ], [ %16, %13 ]
%6 = phi i32 [ 0, %1 ], [ %15, %13 ]
%7 = load i8, i8* %5
switch i8 %7, label %13 [
i8 0, label %17
i8 49, label %8
]
8: ; preds = %3
%9 = xor i32 %6, -1
%10 = add i32 %2, %9
%11 = tail call i32 @pow(i32 2, i32 %10)
%12 = add nsw i32 %11, %4
br label %13
13: ; preds = %3, %8
%14 = phi i32 [ %12, %8 ], [ %4, %3 ]
%15 = add nuw nsw i32 %6, 1
%16 = getelementptr inbounds i8, i8* %5, i64 1
br label %3
17: ; preds = %3
ret i32 %4
}