#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*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int main(void) {
  char bin;
  int dec = 0;
  while (bin != '\n') {
    scanf("%c", &bin);
    if (bin == '1') {
      dec = dec * 2 + 1;
    } else if (bin == '0') {
      dec *= 2;
    }
  }
  printf("%d\n", dec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
je     1191 <main+0x71>
lea    0xeb6(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x31,%eax
jne    1171 <main+0x51>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118c <main+0x6c>
movsbl -0x5(%rbp),%eax
cmp    $0x30,%eax
jne    1187 <main+0x67>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118c <main+0x6c>
jmp    1136 <main+0x16>
mov    -0xc(%rbp),%esi
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
lea    0xece(%rip),%r14
lea    0xf(%rsp),%r15
jmp    1146 <main+0x26>
nopl   0x0(%rax)
add    %ebx,%ebx
cmp    $0xa,%al
je     1165 <main+0x45>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
movzbl 0xf(%rsp),%eax
cmp    $0x30,%al
je     1140 <main+0x20>
cmp    $0x31,%al
jne    1142 <main+0x22>
add    %ebx,%ebx
add    $0x1,%ebx
jmp    1142 <main+0x22>
lea    0xe97(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %4
4: ; preds = %25, %0
%5 = load i8, i8* %2
%6 = sext i8 %5 to i32
%7 = icmp ne i32 %6, 10
br i1 %7, label %8, label %26
8: ; preds = %4
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%10 = load i8, i8* %2
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 49
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* %3
%15 = mul nsw i32 %14, 2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %25
17: ; preds = %8
%18 = load i8, i8* %2
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 48
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* %3
%23 = mul nsw i32 %22, 2
store i32 %23, i32* %3
br label %24
24: ; preds = %21, %17
br label %25
25: ; preds = %24, %13
br label %4
26: ; preds = %4
%27 = load i32, i32* %3
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i8
br label %2
2: ; preds = %0, %11
%3 = phi i32 [ %12, %11 ], [ 0, %0 ]
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%5 = load i8, i8* %1
switch i8 %5, label %11 [
i8 49, label %6
i8 48, label %9
]
6: ; preds = %2
%7 = shl nsw i32 %3, 1
%8 = or i32 %7, 1
br label %11
9: ; preds = %2
%10 = shl nsw i32 %3, 1
br label %11
11: ; preds = %2, %9, %6
%12 = phi i32 [ %8, %6 ], [ %10, %9 ], [ %3, %2 ]
%13 = icmp eq i8 %5, 10
br i1 %13, label %14, label %2
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %12)
ret i32 0
}