#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 */
size_t S(char);
size_t bintodec(char *, char);
scalar_t__ get(char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ judge(char *);
int /*<<< orphan*/ putchar(char);
scalar_t__ scan(char, char *);
scalar_t__ scanf(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int main() {
  char header[1000], binary[1000], len;
  while (get(header)) {
    while (scanf("%3s", binary), strncmp(binary, "000", 3)) {
      len = bintodec(binary, 3);
      while (scan(len, binary), judge(binary))
        putchar(header[S(len - 1) + bintodec(binary, len)]);
    }
    putchar('\n');
    getchar();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x3f0(%rbp),%rdi
call   1080 <get@plt>
cmp    $0x0,%rax
je     1298 <main+0x108>
jmp    11bd <main+0x2d>
lea    -0x7e0(%rbp),%rsi
lea    0xe35(%rip),%rdi
call   10a0 <scanf@plt>
lea    -0x7e0(%rbp),%rdi
lea    0xe26(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
je     1282 <main+0xf2>
lea    -0x7e0(%rbp),%rdi
mov    $0x3,%esi
call   1050 <bintodec@plt>
mov    %al,-0x7e1(%rbp)
mov    -0x7e1(%rbp),%al
lea    -0x7e0(%rbp),%rsi
movsbl %al,%edi
call   10b0 <scan@plt>
lea    -0x7e0(%rbp),%rdi
call   1070 <judge@plt>
cmp    $0x0,%eax
je     127d <main+0xed>
movsbl -0x7e1(%rbp),%eax
sub    $0x1,%eax
movsbl %al,%edi
call   1090 <S@plt>
mov    %rax,-0x7f0(%rbp)
lea    -0x7e0(%rbp),%rdi
movsbl -0x7e1(%rbp),%esi
call   1050 <bintodec@plt>
mov    %rax,%rcx
mov    -0x7f0(%rbp),%rax
add    %rcx,%rax
movsbl -0x3f0(%rbp,%rax,1),%edi
ff
call   1030 <putchar@plt>
jmp    1208 <main+0x78>
jmp    11bd <main+0x2d>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
jmp    11a2 <main+0x12>
xor    %eax,%eax
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7d8,%rsp
mov    %rsp,%rdi
call   1080 <get@plt>
test   %rax,%rax
je     1283 <main+0xf3>
lea    0x3f0(%rsp),%r13
lea    0xe43(%rip),%r15
jmp    11f0 <main+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %rsp,%rdi
call   1080 <get@plt>
test   %rax,%rax
je     1283 <main+0xf3>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe09(%rip),%rdi
mov    %r13,%rsi
call   10a0 <scanf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     11c3 <main+0x33>
mov    %r13,%rdi
mov    $0x3,%esi
call   1050 <bintodec@plt>
mov    %rax,%rbx
movsbl %bl,%edi
mov    %r13,%rsi
call   10b0 <scan@plt>
mov    %r13,%rdi
call   1070 <judge@plt>
test   %eax,%eax
je     11f0 <main+0x60>
lea    -0x1(%rbx),%r14d
xchg   %ax,%ax
movsbl %r14b,%edi
call   1090 <S@plt>
mov    %rax,%rbp
movsbl %bl,%r12d
mov    %r13,%rdi
mov    %r12d,%esi
call   1050 <bintodec@plt>
add    %rbp,%rax
movsbl (%rsp,%rax,1),%edi
call   1030 <putchar@plt>
mov    %r12d,%edi
mov    %r13,%rsi
call   10b0 <scan@plt>
mov    %r13,%rdi
call   1070 <judge@plt>
test   %eax,%eax
jne    1240 <main+0xb0>
jmp    11f0 <main+0x60>
xor    %eax,%eax
add    $0x7d8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%3s\00"
@.str.1 = [4 x i8] c"000\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = alloca [1000 x i8]
%4 = alloca i8
store i32 0, i32* %1
br label %5
5: ; preds = %41, %0
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%7 = call i64 @get(i8* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %44
9: ; preds = %5
br label %10
10: ; preds = %40, %9
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%12 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%14 = call i32 @strncmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %41
16: ; preds = %10
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%18 = call i64 @bintodec(i8* %17, i8 signext 3)
%19 = trunc i64 %18 to i8
store i8 %19, i8* %4
br label %20
20: ; preds = %27, %16
%21 = load i8, i8* %4
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%23 = call i64 @scan(i8 signext %21, i8* %22)
%24 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%25 = call i32 @judge(i8* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %40
27: ; preds = %20
%28 = load i8, i8* %4
%29 = sext i8 %28 to i32
%30 = sub nsw i32 %29, 1
%31 = trunc i32 %30 to i8
%32 = call i64 @S(i8 signext %31)
%33 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%34 = load i8, i8* %4
%35 = call i64 @bintodec(i8* %33, i8 signext %34)
%36 = add i64 %32, %35
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = call i32 @putchar(i8 signext %38)
br label %20
40: ; preds = %20
br label %10
41: ; preds = %10
%42 = call i32 @putchar(i8 signext 10)
%43 = call i32 (...) @getchar()
br label %5
44: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%3s\00"
@.str.1 = [4 x i8] c"000\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%5 = call i64 @get(i8* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %38, label %7
7: ; preds = %0, %33
%8 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%9 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %33, label %15
11: ; preds = %23, %15
%12 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%13 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%14 = icmp eq i32 %13, 0
br i1 %14, label %33, label %15
15: ; preds = %7, %11
%16 = call i64 @bintodec(i8* %4, i8 signext 3)
%17 = trunc i64 %16 to i8
%18 = call i64 @scan(i8 signext %17, i8* %4)
%19 = call i32 @judge(i8* %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %11, label %21
21: ; preds = %15
%22 = add i8 %17, -1
br label %23
23: ; preds = %21, %23
%24 = call i64 @S(i8 signext %22)
%25 = call i64 @bintodec(i8* %4, i8 signext %17)
%26 = add i64 %25, %24
%27 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = call i32 @putchar(i8 signext %28)
%30 = call i64 @scan(i8 signext %17, i8* %4)
%31 = call i32 @judge(i8* %4)
%32 = icmp eq i32 %31, 0
br i1 %32, label %11, label %23
33: ; preds = %11, %7
%34 = call i32 @putchar(i8 signext 10)
%35 = call i32 (...) @getchar()
%36 = call i64 @get(i8* %3)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %7
38: ; preds = %33, %0
ret i32 0
}