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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x186d0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x186b0(%rbp),%rsi
lea    0xea0(%rip),%rdi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    124f <main+0x10f>
movsbl -0x186b0(%rbp),%eax
cmp    $0x30,%eax
jne    1183 <main+0x43>
jmp    124f <main+0x10f>
lea    -0x186b0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x186b4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x186c8(%rbp)
ff
movl   $0x0,-0x186b8(%rbp)
mov    -0x186b4(%rbp),%eax
mov    %eax,-0x186bc(%rbp)
cmpl   $0x0,-0x186bc(%rbp)
jl     1236 <main+0xf6>
movsd  -0x186c8(%rbp),%xmm0
ff
movsd  %xmm0,-0x186d0(%rbp)
ff
mov    -0x186bc(%rbp),%esi
mov    $0x2,%edi
call   1060 <pow@plt>
movsd  -0x186d0(%rbp),%xmm0
ff
sub    $0x1,%eax
movslq -0x186b8(%rbp),%rcx
movsbl -0x186b0(%rbp,%rcx,1),%ecx
ff
sub    $0x30,%ecx
imul   %ecx,%eax
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x186c8(%rbp)
ff
mov    -0x186b8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x186b8(%rbp)
mov    -0x186bc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x186bc(%rbp)
jmp    11b6 <main+0x76>
movsd  -0x186c8(%rbp),%xmm0
ff
lea    0xdbe(%rip),%rdi
call   1040 <printf@plt>
jmp    1152 <main+0x12>
xor    %eax,%eax
add    $0x186d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x186b8,%rsp
lea    0xea8(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    12bc <main+0x17c>
cmpb   $0x30,0x10(%rsp)
je     12bc <main+0x17c>
lea    0x10(%rsp),%r12
lea    0xe81(%rip),%r13
lea    0xe77(%rip),%r15
nopl   0x0(%rax)
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
js     1240 <main+0x100>
mov    %eax,%ebx
lea    0x1(%rbx),%r14d
test   %eax,%eax
je     1250 <main+0x110>
mov    %r15,%r12
mov    %r13,%r15
mov    %r14d,%r13d
and    $0xfffffffe,%r13d
xorps  %xmm0,%xmm0
xor    %ebp,%ebp
movsd  %xmm0,0x8(%rsp)
mov    $0x2,%edi
mov    %ebx,%esi
call   1060 <pow@plt>
add    $0xffffffff,%eax
movsbl 0x10(%rsp,%rbp,1),%ecx
add    $0xffffffd0,%ecx
imul   %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    -0x1(%rbx),%esi
mov    $0x2,%edi
call   1060 <pow@plt>
add    $0xffffffff,%eax
movsbl 0x11(%rsp,%rbp,1),%ecx
add    $0xffffffd0,%ecx
imul   %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x2,%rbp
add    $0xfffffffe,%ebx
cmp    %rbp,%r13
jne    11c0 <main+0x80>
mov    %r15,%r13
mov    %r12,%r15
lea    0x10(%rsp),%r12
test   $0x1,%r14b
jne    125c <main+0x11c>
jmp    1299 <main+0x159>
nopw   0x0(%rax,%rax,1)
xorpd  %xmm0,%xmm0
jmp    1299 <main+0x159>
cs nopw 0x0(%rax,%rax,1)
xorpd  %xmm0,%xmm0
xor    %ebp,%ebp
test   $0x1,%r14b
je     1299 <main+0x159>
mov    $0x2,%edi
mov    %ebx,%esi
movsd  %xmm0,0x8(%rsp)
call   1060 <pow@plt>
add    $0xffffffff,%eax
movsbl 0x10(%rsp,%rbp,1),%ecx
add    $0xffffffd0,%ecx
imul   %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
mov    %r13,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    12bc <main+0x17c>
cmpb   $0x30,0x10(%rsp)
jne    1190 <main+0x50>
xor    %eax,%eax
add    $0x186b8,%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 = [7 x i8] c"%.0lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100000 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
store i32 0, i32* %1
br label %7
7: ; preds = %50, %0
%8 = getelementptr inbounds [100000 x i8], [100000 x i8]* %2, i64 0, i64 0
%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 %51
11: ; preds = %7
%12 = getelementptr inbounds [100000 x i8], [100000 x i8]* %2, i64 0, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 48
br i1 %15, label %16, label %17
16: ; preds = %11
br label %51
17: ; preds = %11
%18 = getelementptr inbounds [100000 x i8], [100000 x i8]* %2, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %3
store double 0.000000e+00, double* %6
store i32 0, i32* %4
%20 = load i32, i32* %3
store i32 %20, i32* %5
br label %21
21: ; preds = %42, %17
%22 = load i32, i32* %4
%23 = load i32, i32* %3
%24 = icmp slt i32 %22, %23
%25 = zext i1 %24 to i32
%26 = load i32, i32* %5
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %47
28: ; preds = %21
%29 = load double, double* %6
%30 = load i32, i32* %5
%31 = call i32 @pow(i32 2, i32 %30)
%32 = sub nsw i32 %31, 1
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [100000 x i8], [100000 x i8]* %2, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = sub nsw i32 %37, 48
%39 = mul nsw i32 %32, %38
%40 = sitofp i32 %39 to double
%41 = fadd double %29, %40
store double %41, double* %6
br label %42
42: ; preds = %28
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
%45 = load i32, i32* %5
%46 = add nsw i32 %45, -1
store i32 %46, i32* %5
br label %21
47: ; preds = %21
%48 = load double, double* %6
%49 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %48)
br label %50
50: ; preds = %47
br label %7
51: ; preds = %16, %7
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [7 x i8] c"%.0lf\0A\00"
define i32 @main() {
%1 = alloca [100000 x i8]
%2 = getelementptr inbounds [100000 x i8], [100000 x i8]* %1, i64 0, i64 0
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = icmp ne i32 %3, 1
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 48
%7 = select i1 %4, i1 true, i1 %6
br i1 %7, label %71, label %8
8: ; preds = %0, %63
%9 = call i32 @strlen(i8* %2)
%10 = icmp sgt i32 %9, -1
br i1 %10, label %11, label %63
11: ; preds = %8
%12 = add nuw i32 %9, 1
%13 = zext i32 %12 to i64
%14 = and i64 %13, 1
%15 = icmp eq i32 %9, 0
br i1 %15, label %47, label %16
16: ; preds = %11
%17 = and i64 %13, 4294967294
br label %18
18: ; preds = %18, %16
%19 = phi i64 [ 0, %16 ], [ %43, %18 ]
%20 = phi double [ 0.000000e+00, %16 ], [ %42, %18 ]
%21 = phi i32 [ %9, %16 ], [ %44, %18 ]
%22 = phi i64 [ 0, %16 ], [ %45, %18 ]
%23 = call i32 @pow(i32 2, i32 %21)
%24 = add nsw i32 %23, -1
%25 = getelementptr inbounds [100000 x i8], [100000 x i8]* %1, i64 0, i64 %19
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = add nsw i32 %27, -48
%29 = mul nsw i32 %28, %24
%30 = sitofp i32 %29 to double
%31 = fadd double %20, %30
%32 = or i64 %19, 1
%33 = add nsw i32 %21, -1
%34 = call i32 @pow(i32 2, i32 %33)
%35 = add nsw i32 %34, -1
%36 = getelementptr inbounds [100000 x i8], [100000 x i8]* %1, i64 0, i64 %32
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = add nsw i32 %38, -48
%40 = mul nsw i32 %39, %35
%41 = sitofp i32 %40 to double
%42 = fadd double %31, %41
%43 = add nuw nsw i64 %19, 2
%44 = add nsw i32 %21, -2
%45 = add i64 %22, 2
%46 = icmp eq i64 %45, %17
br i1 %46, label %47, label %18
47: ; preds = %18, %11
%48 = phi double [ undef, %11 ], [ %42, %18 ]
%49 = phi i64 [ 0, %11 ], [ %43, %18 ]
%50 = phi double [ 0.000000e+00, %11 ], [ %42, %18 ]
%51 = phi i32 [ %9, %11 ], [ %44, %18 ]
%52 = icmp eq i64 %14, 0
br i1 %52, label %63, label %53
53: ; preds = %47
%54 = call i32 @pow(i32 2, i32 %51)
%55 = add nsw i32 %54, -1
%56 = getelementptr inbounds [100000 x i8], [100000 x i8]* %1, i64 0, i64 %49
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = add nsw i32 %58, -48
%60 = mul nsw i32 %59, %55
%61 = sitofp i32 %60 to double
%62 = fadd double %50, %61
br label %63
63: ; preds = %53, %47, %8
%64 = phi double [ 0.000000e+00, %8 ], [ %48, %47 ], [ %62, %53 ]
%65 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %64)
%66 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%67 = icmp ne i32 %66, 1
%68 = load i8, i8* %2
%69 = icmp eq i8 %68, 48
%70 = select i1 %67, i1 true, i1 %69
br i1 %70, label %71, label %8
71: ; preds = %63, %0
ret i32 0
}