#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 /*<<< orphan*/ *gets(char *);
int pow(int, int);
int /*<<< orphan*/ printf(char *, int);
int strlen(char *);
int main() {
  char skew[1024], *ptr;
  int count, dec, len;
  while (gets(skew) != NULL && skew[0] != '0') {
    ptr = &skew[strlen(skew) - 1];
    dec = count = 0;
    while (ptr >= &skew[0]) {
      count++;
      dec = dec + (*ptr - '0') * (pow(2, count) - 1);
      ptr--;
    }
    printf("%d\n", dec);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
call   1050 <gets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x425(%rbp)
je     1186 <main+0x46>
movsbl -0x410(%rbp),%eax
cmp    $0x30,%eax
setne  %al
mov    %al,-0x425(%rbp)
mov    -0x425(%rbp),%al
test   $0x1,%al
jne    1199 <main+0x59>
jmp    126f <main+0x12f>
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
movslq %eax,%rcx
lea    -0x410(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x418(%rbp)
movl   $0x0,-0x41c(%rbp)
movl   $0x0,-0x420(%rbp)
mov    -0x418(%rbp),%rax
lea    -0x410(%rbp),%rcx
cmp    %rcx,%rax
jb     1258 <main+0x118>
mov    -0x41c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x41c(%rbp)
mov    -0x420(%rbp),%eax
mov    %eax,-0x42c(%rbp)
mov    -0x418(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x430(%rbp)
mov    -0x41c(%rbp),%esi
mov    $0x2,%edi
call   1060 <pow@plt>
mov    -0x430(%rbp),%ecx
mov    %eax,%edx
mov    -0x42c(%rbp),%eax
sub    $0x1,%edx
imul   %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x420(%rbp)
mov    -0x418(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x418(%rbp)
jmp    11d0 <main+0x90>
mov    -0x420(%rbp),%esi
lea    0xd9b(%rip),%rdi
call   1040 <printf@plt>
jmp    1152 <main+0x12>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsp,%r15
mov    %r15,%rdi
call   1050 <gets@plt>
test   %rax,%rax
je     11f1 <main+0xb1>
cmpb   $0x30,(%rsp)
je     11f1 <main+0xb1>
lea    0xe8a(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11d0 <main+0x90>
add    $0xffffffff,%eax
lea    (%rsp,%rax,1),%rbp
xor    %r12d,%r12d
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
movsbl 0x0(%rbp),%r13d
add    $0xffffffd0,%r13d
mov    $0x2,%edi
mov    %ebx,%esi
call   1060 <pow@plt>
add    $0xffffffff,%eax
imul   %r13d,%eax
add    %eax,%r12d
add    $0xffffffffffffffff,%rbp
add    $0x1,%ebx
cmp    %r15,%rbp
jae    11a0 <main+0x60>
jmp    11d3 <main+0x93>
nopl   (%rax)
xor    %r12d,%r12d
mov    %r14,%rdi
mov    %r12d,%esi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1050 <gets@plt>
test   %rax,%rax
je     11f1 <main+0xb1>
cmpb   $0x30,(%rsp)
jne    1180 <main+0x40>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
br label %7
7: ; preds = %43, %0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%9 = call i32* @gets(i8* %8)
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 48
br label %16
16: ; preds = %11, %7
%17 = phi i1 [ false, %7 ], [ %15, %11 ]
br i1 %17, label %18, label %46
18: ; preds = %16
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %22
store i8* %23, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %24
24: ; preds = %28, %18
%25 = load i8*, i8** %3
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%27 = icmp uge i8* %25, %26
br i1 %27, label %28, label %43
28: ; preds = %24
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
%31 = load i32, i32* %5
%32 = load i8*, i8** %3
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = sub nsw i32 %34, 48
%36 = load i32, i32* %4
%37 = call i32 @pow(i32 2, i32 %36)
%38 = sub nsw i32 %37, 1
%39 = mul nsw i32 %35, %38
%40 = add nsw i32 %31, %39
store i32 %40, i32* %5
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i32 -1
store i8* %42, i8** %3
br label %24
43: ; preds = %24
%44 = load i32, i32* %5
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %44)
br label %7
46: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = call i32* @gets(i8* %2)
%4 = icmp ne i32* %3, null
%5 = load i8, i8* %2
%6 = icmp ne i8 %5, 48
%7 = select i1 %4, i1 %6, i1 false
br i1 %7, label %8, label %37
8: ; preds = %0, %29
%9 = call i32 @strlen(i8* %2)
%10 = icmp slt i32 %9, 1
br i1 %10, label %29, label %11
11: ; preds = %8
%12 = add nsw i32 %9, -1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %13
br label %15
15: ; preds = %11, %15
%16 = phi i8* [ %27, %15 ], [ %14, %11 ]
%17 = phi i32 [ %26, %15 ], [ 0, %11 ]
%18 = phi i32 [ %19, %15 ], [ 0, %11 ]
%19 = add nuw nsw i32 %18, 1
%20 = load i8, i8* %16
%21 = sext i8 %20 to i32
%22 = add nsw i32 %21, -48
%23 = call i32 @pow(i32 2, i32 %19)
%24 = add nsw i32 %23, -1
%25 = mul nsw i32 %22, %24
%26 = add nsw i32 %25, %17
%27 = getelementptr inbounds i8, i8* %16, i64 -1
%28 = icmp ult i8* %27, %2
br i1 %28, label %29, label %15
29: ; preds = %15, %8
%30 = phi i32 [ 0, %8 ], [ %26, %15 ]
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = call i32* @gets(i8* %2)
%33 = icmp ne i32* %32, null
%34 = load i8, i8* %2
%35 = icmp ne i8 %34, 48
%36 = select i1 %33, i1 %35, i1 false
br i1 %36, label %8, label %37
37: ; preds = %29, %0
ret i32 0
}