#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strtok(char *, char *);
int main(void) {
  FILE *file = fopen("input.txt", "r");
  int i;
  int variableFrequency = 0;
  int numOutcomes = 0;
  int codeLength;
  int numVariables;
  char code[1000];
  char variables[100];
  char output[1000];
  fgets(variables, sizeof variables, file);
  fgets(code, sizeof code, file);
  strtok(variables, "\n");
  codeLength = strlen(code);
  numVariables = strlen(variables);
  fclose(file);
  for (i = 0; i < codeLength; i++) {
    if (code[i] == '0') {
      output[numOutcomes] = variables[variableFrequency];
      numOutcomes = numOutcomes + 1;
      variableFrequency = 0;
    } else {
      variableFrequency = variableFrequency + 1;
      if (variableFrequency == numVariables - 1) {
        output[numOutcomes] = variables[variableFrequency];
        numOutcomes = numOutcomes + 1;
        variableFrequency = 0;
      }
    }
  }
  printf("%s\n", output);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x870,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x480(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3e8,%esi
call   1060 <fgets@plt>
lea    -0x480(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1080 <strtok@plt>
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
lea    -0x480(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12a6 <main+0x146>
movslq -0x14(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0x30,%eax
jne    124e <main+0xee>
movslq -0x18(%rbp),%rax
mov    -0x480(%rbp,%rax,1),%cl
movslq -0x1c(%rbp),%rax
mov    %cl,-0x870(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    1293 <main+0x133>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    128e <main+0x12e>
movslq -0x18(%rbp),%rax
mov    -0x480(%rbp,%rax,1),%cl
movslq -0x1c(%rbp),%rax
mov    %cl,-0x870(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    1293 <main+0x133>
jmp    1298 <main+0x138>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1202 <main+0xa2>
lea    -0x870(%rbp),%rsi
lea    0xd58(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x870,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x848,%rsp
lea    0xe8c(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
lea    0x460(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x3e8,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
lea    0xe59(%rip),%rsi
mov    %r15,%rdi
call   1080 <strtok@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <fclose@plt>
test   %ebx,%ebx
jle    1223 <main+0xc3>
add    $0xffffffff,%ebp
mov    %ebx,%eax
xor    %ecx,%ecx
xor    %esi,%esi
xor    %edx,%edx
jmp    120e <main+0xae>
nopw   0x0(%rax,%rax,1)
mov    %esi,%edi
movslq %edi,%rsi
movzbl (%rsp,%rsi,1),%ebx
movslq %edx,%rdx
mov    %bl,0x70(%rsp,%rdx,1)
add    $0x1,%edx
xor    %esi,%esi
add    $0x1,%rcx
cmp    %rcx,%rax
je     1223 <main+0xc3>
cmpb   $0x30,0x460(%rsp,%rcx,1)
30
je     11f0 <main+0x90>
add    $0x1,%esi
mov    %ebp,%edi
cmp    %ebp,%esi
je     11f2 <main+0x92>
jmp    1205 <main+0xa5>
lea    0xde2(%rip),%rdi
lea    0x70(%rsp),%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x848,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = alloca [100 x i8]
%3 = alloca [1000 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%8 = call i32 @fgets(i8* %6, i32 100, i32* %4)
%9 = call i32 @fgets(i8* %5, i32 1000, i32* %4)
%10 = call i32 @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @strlen(i8* %5)
%12 = call i32 @strlen(i8* %6)
%13 = call i32 @fclose(i32* %4)
%14 = icmp sgt i32 %11, 0
br i1 %14, label %15, label %41
15: ; preds = %0
%16 = add nsw i32 %12, -1
%17 = zext i32 %11 to i64
br label %18
18: ; preds = %15, %36
%19 = phi i64 [ 0, %15 ], [ %39, %36 ]
%20 = phi i32 [ 0, %15 ], [ %38, %36 ]
%21 = phi i32 [ 0, %15 ], [ %37, %36 ]
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %19
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 48
br i1 %24, label %28, label %25
25: ; preds = %18
%26 = add nsw i32 %20, 1
%27 = icmp eq i32 %26, %16
br i1 %27, label %28, label %36
28: ; preds = %18, %25
%29 = phi i32 [ %16, %25 ], [ %20, %18 ]
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i32 %21 to i64
%34 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %33
store i8 %32, i8* %34
%35 = add nsw i32 %21, 1
br label %36
36: ; preds = %28, %25
%37 = phi i32 [ %21, %25 ], [ %35, %28 ]
%38 = phi i32 [ %26, %25 ], [ 0, %28 ]
%39 = add nuw nsw i64 %19, 1
%40 = icmp eq i64 %39, %17
br i1 %40, label %41, label %18
41: ; preds = %36, %0
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %7)
ret i32 0
}