#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);
int scanf(char *, char **);
int strlen(char *);
int main() {
  char s[500];
  int i, j, sum;
  while (scanf("%s", &s) == 1) {
    int len = strlen(s);
    if (len == 1 && s[0] == '0')
      break;
    sum = 0;
    for (i = len - 1, j = 1; i >= 0; i--, j++) {
      if (s[i] == '0') {
        sum += 0;
      } else if (s[i] == '1') {
        sum += (pow(2, j) - 1);
      } else if (s[i] == '2') {
        sum += (2 * (pow(2, j) - 1));
      }
    }
    printf("%d\n", sum);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x200(%rbp),%rsi
lea    0xea0(%rip),%rdi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    12bd <main+0x17d>
lea    -0x200(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x210(%rbp)
cmpl   $0x1,-0x210(%rbp)
jne    11a2 <main+0x62>
movsbl -0x200(%rbp),%eax
cmp    $0x30,%eax
jne    11a2 <main+0x62>
jmp    12bd <main+0x17d>
movl   $0x0,-0x20c(%rbp)
mov    -0x210(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x204(%rbp)
movl   $0x1,-0x208(%rbp)
cmpl   $0x0,-0x204(%rbp)
jl     12a6 <main+0x166>
movslq -0x204(%rbp),%rax
movsbl -0x200(%rbp,%rax,1),%eax
ff
cmp    $0x30,%eax
jne    11fe <main+0xbe>
mov    -0x20c(%rbp),%eax
add    $0x0,%eax
mov    %eax,-0x20c(%rbp)
jmp    127e <main+0x13e>
movslq -0x204(%rbp),%rax
movsbl -0x200(%rbp,%rax,1),%eax
ff
cmp    $0x31,%eax
jne    123a <main+0xfa>
mov    -0x208(%rbp),%esi
mov    $0x2,%edi
call   1060 <pow@plt>
sub    $0x1,%eax
add    -0x20c(%rbp),%eax
mov    %eax,-0x20c(%rbp)
jmp    1279 <main+0x139>
movslq -0x204(%rbp),%rax
movsbl -0x200(%rbp,%rax,1),%eax
ff
cmp    $0x32,%eax
jne    1274 <main+0x134>
mov    -0x208(%rbp),%esi
mov    $0x2,%edi
call   1060 <pow@plt>
sub    $0x1,%eax
shl    $0x1,%eax
add    -0x20c(%rbp),%eax
mov    %eax,-0x20c(%rbp)
jmp    1279 <main+0x139>
jmp    127e <main+0x13e>
jmp    1283 <main+0x143>
mov    -0x204(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x204(%rbp)
mov    -0x208(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x208(%rbp)
jmp    11c5 <main+0x85>
mov    -0x20c(%rbp),%esi
lea    0xd50(%rip),%rdi
call   1040 <printf@plt>
jmp    1152 <main+0x12>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f8,%rsp
lea    0xea8(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1210 <main+0xd0>
mov    %rsp,%r12
lea    0xe90(%rip),%r14
lea    0xe86(%rip),%r15
jmp    119e <main+0x5e>
nopl   0x0(%rax)
xor    %r13d,%r13d
mov    %r14,%rdi
mov    %r13d,%esi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1210 <main+0xd0>
mov    %r12,%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jne    11b1 <main+0x71>
cmpb   $0x30,(%rsp)
je     1210 <main+0xd0>
test   %eax,%eax
jle    1180 <main+0x40>
mov    %eax,%ebx
add    $0xffffffffffffffff,%rbx
mov    $0x1,%ebp
xor    %r13d,%r13d
jmp    11ed <main+0xad>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x2,%edi
mov    %ebp,%esi
call   1060 <pow@plt>
lea    -0x2(%r13,%rax,2),%r13d
add    $0x1,%ebp
add    $0xffffffffffffffff,%rbx
cmp    $0xffffffff,%ebx
je     1183 <main+0x43>
mov    %ebx,%eax
movzbl (%rsp,%rax,1),%eax
cmp    $0x32,%al
je     11d0 <main+0x90>
cmp    $0x31,%al
jne    11e1 <main+0xa1>
mov    $0x2,%edi
mov    %ebp,%esi
call   1060 <pow@plt>
add    %eax,%r13d
add    $0xffffffff,%r13d
jmp    11e1 <main+0xa1>
xor    %eax,%eax
add    $0x1f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [500 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
br label %7
7: ; preds = %73, %0
%8 = bitcast [500 x i8]* %2 to i8**
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %8)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %76
11: ; preds = %7
%12 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 48
br i1 %20, label %21, label %22
21: ; preds = %16
br label %76
22: ; preds = %16, %11
store i32 0, i32* %5
%23 = load i32, i32* %6
%24 = sub nsw i32 %23, 1
store i32 %24, i32* %3
store i32 1, i32* %4
br label %25
25: ; preds = %68, %22
%26 = load i32, i32* %3
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %73
28: ; preds = %25
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 48
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 0
store i32 %37, i32* %5
br label %67
38: ; preds = %28
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 49
br i1 %44, label %45, label %51
45: ; preds = %38
%46 = load i32, i32* %4
%47 = call i32 @pow(i32 2, i32 %46)
%48 = sub nsw i32 %47, 1
%49 = load i32, i32* %5
%50 = add nsw i32 %49, %48
store i32 %50, i32* %5
br label %66
51: ; preds = %38
%52 = load i32, i32* %3
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 50
br i1 %57, label %58, label %65
58: ; preds = %51
%59 = load i32, i32* %4
%60 = call i32 @pow(i32 2, i32 %59)
%61 = sub nsw i32 %60, 1
%62 = mul nsw i32 2, %61
%63 = load i32, i32* %5
%64 = add nsw i32 %63, %62
store i32 %64, i32* %5
br label %65
65: ; preds = %58, %51
br label %66
66: ; preds = %65, %45
br label %67
67: ; preds = %66, %35
br label %68
68: ; preds = %67
%69 = load i32, i32* %3
%70 = add nsw i32 %69, -1
store i32 %70, i32* %3
%71 = load i32, i32* %4
%72 = add nsw i32 %71, 1
store i32 %72, i32* %4
br label %25
73: ; preds = %25
%74 = load i32, i32* %5
%75 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %74)
br label %7
76: ; preds = %21, %7
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [500 x i8]
%2 = getelementptr inbounds [500 x i8], [500 x i8]* %1, i64 0, i64 0
%3 = bitcast [500 x i8]* %1 to i8**
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %3)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %42
6: ; preds = %0, %37
%7 = call i32 @strlen(i8* %2)
%8 = icmp eq i32 %7, 1
%9 = load i8, i8* %2
%10 = icmp eq i8 %9, 48
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %42, label %12
12: ; preds = %6
%13 = icmp sgt i32 %7, 0
br i1 %13, label %14, label %37
14: ; preds = %12
%15 = zext i32 %7 to i64
br label %16
16: ; preds = %14, %33
%17 = phi i64 [ %15, %14 ], [ %20, %33 ]
%18 = phi i32 [ 0, %14 ], [ %34, %33 ]
%19 = phi i32 [ 1, %14 ], [ %35, %33 ]
%20 = add nsw i64 %17, -1
%21 = and i64 %20, 4294967295
%22 = getelementptr inbounds [500 x i8], [500 x i8]* %1, i64 0, i64 %21
%23 = load i8, i8* %22
switch i8 %23, label %33 [
i8 50, label %28
i8 49, label %24
]
24: ; preds = %16
%25 = call i32 @pow(i32 2, i32 %19)
%26 = add i32 %18, -1
%27 = add i32 %26, %25
br label %33
28: ; preds = %16
%29 = call i32 @pow(i32 2, i32 %19)
%30 = shl i32 %29, 1
%31 = add i32 %18, -2
%32 = add i32 %31, %30
br label %33
33: ; preds = %16, %28, %24
%34 = phi i32 [ %27, %24 ], [ %32, %28 ], [ %18, %16 ]
%35 = add nuw i32 %19, 1
%36 = icmp eq i32 %19, %7
br i1 %36, label %37, label %16
37: ; preds = %33, %12
%38 = phi i32 [ 0, %12 ], [ %34, %33 ]
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %3)
%41 = icmp eq i32 %40, 1
br i1 %41, label %6, label %42
42: ; preds = %37, %6, %0
ret i32 0
}