#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_optimized.txt", "r");
  register int i;
  register int variableFrequency = 0;
  register int numOutcomes = 0;
  register int codeLength;
  register 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];
      variableFrequency = 0;
    } else {
      variableFrequency++;
    }
  }
  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    0xe94(%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    0xe49(%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    126a <main+0x10a>
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
mov    -0x1c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
cltq
mov    %cl,-0x870(%rbp,%rax,1)
movl   $0x0,-0x18(%rbp)
jmp    1257 <main+0xf7>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    125c <main+0xfc>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1202 <main+0xa2>
lea    -0x870(%rbp),%rsi
lea    0xd9e(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x870,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x850,%rsp
lea    0xe8e(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
lea    0x460(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x3e8,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
lea    0xe65(%rip),%rsi
mov    %r14,%rdi
call   1080 <strtok@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %ebp,%ebp
jle    1201 <main+0xa1>
mov    %ebp,%eax
cmp    $0x1,%ebp
jne    1220 <main+0xc0>
xor    %ecx,%ecx
xor    %edi,%edi
xor    %edx,%edx
test   $0x1,%al
je     1201 <main+0xa1>
cmpb   $0x30,0x460(%rsp,%rcx,1)
30
jne    1201 <main+0xa1>
movslq %edi,%rax
mov    (%rsp,%rax,1),%al
movslq %edx,%rcx
mov    %al,0x70(%rsp,%rcx,1)
lea    0xe0e(%rip),%rdi
lea    0x70(%rsp),%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x850,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %eax,%esi
and    $0xfffffffe,%esi
xor    %ecx,%ecx
xor    %edi,%edi
xor    %edx,%edx
jmp    124c <main+0xec>
nopl   (%rax)
movslq %edi,%rdi
movzbl (%rsp,%rdi,1),%ebx
movslq %edx,%rdi
add    $0x1,%edx
mov    %bl,0x70(%rsp,%rdi,1)
xor    %edi,%edi
add    $0x2,%rcx
cmp    %rcx,%rsi
je     11e6 <main+0x86>
cmpb   $0x30,0x460(%rsp,%rcx,1)
30
jne    1280 <main+0x120>
movslq %edi,%rdi
movzbl (%rsp,%rdi,1),%ebx
movslq %edx,%rdi
add    $0x1,%edx
mov    %bl,0x70(%rsp,%rdi,1)
xor    %edi,%edi
cmpb   $0x30,0x461(%rsp,%rcx,1)
30
je     1230 <main+0xd0>
jmp    128d <main+0x12d>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%edi
cmpb   $0x30,0x461(%rsp,%rcx,1)
30
je     1230 <main+0xd0>
add    $0x1,%edi
jmp    1243 <main+0xe3>

LLVM IR (-O0):
@.str = [20 x i8] c"input_optimized.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 ([20 x i8], [20 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 = %50, %0
%27 = load i32, i32* %3
%28 = load i32, i32* %6
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %53
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 %46
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 = add nsw i32 %42, 1
store i32 %43, i32* %5
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 %44
store i8 %41, i8* %45
store i32 0, i32* %4
br label %49
46: ; preds = %30
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %4
br label %49
49: ; preds = %46, %37
br label %50
50: ; preds = %49
%51 = load i32, i32* %3
%52 = add nsw i32 %51, 1
store i32 %52, i32* %3
br label %26
53: ; preds = %26
%54 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%55 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %54)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"input_optimized.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 ([20 x i8], [20 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 %75
15: ; preds = %0
%16 = zext i32 %11 to i64
%17 = and i64 %16, 1
%18 = icmp eq i32 %11, 1
br i1 %18, label %60, label %19
19: ; preds = %15
%20 = and i64 %16, 4294967294
br label %21
21: ; preds = %54, %19
%22 = phi i64 [ 0, %19 ], [ %57, %54 ]
%23 = phi i32 [ 0, %19 ], [ %56, %54 ]
%24 = phi i32 [ 0, %19 ], [ %55, %54 ]
%25 = phi i64 [ 0, %19 ], [ %58, %54 ]
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %22
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 48
br i1 %28, label %29, label %36
29: ; preds = %21
%30 = sext i32 %23 to i64
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = add nsw i32 %24, 1
%34 = sext i32 %24 to i64
%35 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %34
store i8 %32, i8* %35
br label %38
36: ; preds = %21
%37 = add nsw i32 %23, 1
br label %38
38: ; preds = %29, %36
%39 = phi i32 [ %33, %29 ], [ %24, %36 ]
%40 = phi i32 [ 0, %29 ], [ %37, %36 ]
%41 = or i64 %22, 1
%42 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = icmp eq i8 %43, 48
br i1 %44, label %47, label %45
45: ; preds = %38
%46 = add nsw i32 %40, 1
br label %54
47: ; preds = %38
%48 = sext i32 %40 to i64
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = add nsw i32 %39, 1
%52 = sext i32 %39 to i64
%53 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %52
store i8 %50, i8* %53
br label %54
54: ; preds = %47, %45
%55 = phi i32 [ %51, %47 ], [ %39, %45 ]
%56 = phi i32 [ 0, %47 ], [ %46, %45 ]
%57 = add nuw nsw i64 %22, 2
%58 = add i64 %25, 2
%59 = icmp eq i64 %58, %20
br i1 %59, label %60, label %21
60: ; preds = %54, %15
%61 = phi i64 [ 0, %15 ], [ %57, %54 ]
%62 = phi i32 [ 0, %15 ], [ %56, %54 ]
%63 = phi i32 [ 0, %15 ], [ %55, %54 ]
%64 = icmp eq i64 %17, 0
br i1 %64, label %75, label %65
65: ; preds = %60
%66 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %61
%67 = load i8, i8* %66
%68 = icmp eq i8 %67, 48
br i1 %68, label %69, label %75
69: ; preds = %65
%70 = sext i32 %62 to i64
%71 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %70
%72 = load i8, i8* %71
%73 = sext i32 %63 to i64
%74 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %73
store i8 %72, i8* %74
br label %75
75: ; preds = %60, %65, %69, %0
%76 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %7)
ret i32 0
}