#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*/ reg;
typedef int /*<<< orphan*/ ram;
typedef int /*<<< orphan*/ line;

/* Variables and functions */
int /*<<< orphan*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int atoi(char *);
int execute(int *, int *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  char line[1024];
  int ram[1000];
  int reg[10];
  int n_case;
  int n_case_original;
  int i;
  if (argc != 2) {
    printf("Usage: %s INPUT_FILE\n\n", argv[0]);
    exit(-1);
  }
  if (access(argv[1], F_OK)) {
    printf("Error: INPUT_FILE %s does not exist\n\n", argv[1]);
    exit(-1);
  }
  freopen(argv[1], "r", stdin);
  scanf("%d", &n_case);
  n_case_original = n_case;
  getchar();
  getchar();
  while (n_case--) {
    if (n_case + 1 != n_case_original)
      printf("\n");
    memset(ram, 0, sizeof(ram));
    memset(reg, 0, sizeof(reg));
    i = 0;
    while (fgets(line, sizeof(line), stdin)) {
      if (line[0] == '\n')
        break;
      ram[i++] = atoi(line);
    }
    printf("%d\n", execute(ram, reg));
  }
  fclose(stdin);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x13f0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
call   10b0 <access@plt>
cmp    $0x0,%rax
je     1232 <main+0x82>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2da7(%rip),%rax
mov    (%rax),%edx
lea    0xdf3(%rip),%rsi
call   1070 <freopen@plt>
lea    0xde9(%rip),%rdi
lea    -0x13e4(%rbp),%rsi
call   10a0 <scanf@plt>
mov    -0x13e4(%rbp),%eax
mov    %eax,-0x13e8(%rbp)
mov    $0x0,%al
call   1090 <getchar@plt>
mov    $0x0,%al
call   1090 <getchar@plt>
mov    -0x13e4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x13e4(%rbp)
cmp    $0x0,%eax
je     1377 <main+0x1c7>
mov    -0x13e4(%rbp),%eax
add    $0x1,%eax
cmp    -0x13e8(%rbp),%eax
je     12b9 <main+0x109>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x13b0(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa0,%edx
call   1050 <memset@plt>
lea    -0x13e0(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
movl   $0x0,-0x13ec(%rbp)
lea    -0x410(%rbp),%rdi
mov    0x2cf1(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     134f <main+0x19f>
movsbl -0x410(%rbp),%eax
cmp    $0xa,%eax
jne    1322 <main+0x172>
jmp    134f <main+0x19f>
lea    -0x410(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ecx
mov    -0x13ec(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x13ec(%rbp)
cltq
mov    %ecx,-0x13b0(%rbp,%rax,4)
jmp    12e9 <main+0x139>
lea    -0x13b0(%rbp),%rdi
lea    -0x13e0(%rbp),%rsi
call   1060 <execute@plt>
mov    %eax,%esi
lea    0xcd7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    127c <main+0xcc>
mov    0x2c6a(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x13f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x13e8,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1335 <main+0x175>
mov    0x8(%rbx),%rdi
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
call   10c0 <access@plt>
mov    0x8(%rbx),%rcx
test   %rax,%rax
jne    1341 <main+0x181>
mov    0x2de5(%rip),%r13
mov    0x0(%r13),%edx
lea    0xe2f(%rip),%rsi
mov    %rcx,%rdi
call   1080 <freopen@plt>
lea    0xe22(%rip),%rdi
lea    0xc(%rsp),%rsi
call   10b0 <scanf@plt>
mov    0xc(%rsp),%ebp
xor    %eax,%eax
call   10a0 <getchar@plt>
xor    %eax,%eax
call   10a0 <getchar@plt>
mov    0xc(%rsp),%eax
mov    %eax,%ecx
sub    $0x1,%ecx
mov    %ecx,0xc(%rsp)
jae    1265 <main+0xa5>
mov    0x0(%r13),%edi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x13e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x440(%rsp),%r12
lea    0x10(%rsp),%r14
lea    0x40(%rsp),%rbx
jmp    12aa <main+0xea>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <execute@plt>
lea    0xdb0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%eax
mov    %eax,%ecx
sub    $0x1,%ecx
mov    %ecx,0xc(%rsp)
jb     1248 <main+0x88>
cmp    %ebp,%eax
je     12b8 <main+0xf8>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0xfa0,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1090 <fgets@plt>
test   %rax,%rax
je     1280 <main+0xc0>
cmpb   $0xa,0x40(%rsp)
je     1280 <main+0xc0>
mov    %r12,%r15
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10d0 <atoi@plt>
mov    %eax,(%r15)
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1090 <fgets@plt>
test   %rax,%rax
je     1280 <main+0xc0>
add    $0x4,%r15
cmpb   $0xa,0x40(%rsp)
jne    1300 <main+0x140>
jmp    1280 <main+0xc0>
mov    (%rbx),%rsi
lea    0xcc1(%rip),%rdi
jmp    134b <main+0x18b>
lea    0xccf(%rip),%rdi
mov    %rcx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Usage: %s INPUT_FILE\0A\0A\00"
@F_OK = global i32 0
@.str.1 = [38 x i8] c"Error: INPUT_FILE %s does not exist\0A\0A\00"
@.str.2 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [1000 x i32]
%8 = alloca [10 x i32]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i32, i32* @F_OK
%25 = call i64 @access(i8* %23, i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %20
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %20
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i32, i32* @stdin
%38 = call i32 @freopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %9)
%40 = load i32, i32* %9
store i32 %40, i32* %10
%41 = call i32 (...) @getchar()
%42 = call i32 (...) @getchar()
br label %43
43: ; preds = %77, %33
%44 = load i32, i32* %9
%45 = add nsw i32 %44, -1
store i32 %45, i32* %9
%46 = icmp ne i32 %44, 0
br i1 %46, label %47, label %82
47: ; preds = %43
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
%50 = load i32, i32* %10
%51 = icmp ne i32 %49, %50
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %52, %47
%55 = getelementptr inbounds [1000 x i32], [1000 x i32]* %7, i64 0, i64 0
%56 = call i32 @memset(i32* %55, i32 0, i32 4000)
%57 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 0
%58 = call i32 @memset(i32* %57, i32 0, i32 40)
store i32 0, i32* %11
br label %59
59: ; preds = %70, %54
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%61 = load i32, i32* @stdin
%62 = call i64 @fgets(i8* %60, i32 1024, i32 %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %77
64: ; preds = %59
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %67, 10
br i1 %68, label %69, label %70
69: ; preds = %64
br label %77
70: ; preds = %64
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%72 = call i32 @atoi(i8* %71)
%73 = load i32, i32* %11
%74 = add nsw i32 %73, 1
store i32 %74, i32* %11
%75 = sext i32 %73 to i64
%76 = getelementptr inbounds [1000 x i32], [1000 x i32]* %7, i64 0, i64 %75
store i32 %72, i32* %76
br label %59
77: ; preds = %69, %59
%78 = getelementptr inbounds [1000 x i32], [1000 x i32]* %7, i64 0, i64 0
%79 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 0
%80 = call i32 @execute(i32* %78, i32* %79)
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %80)
br label %43
82: ; preds = %43
%83 = load i32, i32* @stdin
%84 = call i32 @fclose(i32 %83)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"Usage: %s INPUT_FILE\0A\0A\00"
@F_OK = global i32 0
@.str.1 = [38 x i8] c"Error: INPUT_FILE %s does not exist\0A\0A\00"
@.str.2 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1000 x i32]
%5 = alloca [10 x i32]
%6 = alloca i32
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = bitcast [1000 x i32]* %4 to i8*
%9 = bitcast [10 x i32]* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = icmp eq i32 %0, 2
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @F_OK
%20 = tail call i64 @access(i8* %18, i32 %19)
%21 = icmp eq i64 %20, 0
%22 = load i8*, i8** %17
br i1 %21, label %26, label %23
23: ; preds = %16
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%25 = tail call i32 @exit(i32 -1)
unreachable
26: ; preds = %16
%27 = load i32, i32* @stdin
%28 = tail call i32 @freopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%30 = load i32, i32* %6
%31 = call i32 (...) @getchar()
%32 = call i32 (...) @getchar()
%33 = load i32, i32* %6
%34 = add nsw i32 %33, -1
store i32 %34, i32* %6
%35 = icmp eq i32 %33, 0
br i1 %35, label %70, label %36
36: ; preds = %26
%37 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 0
%38 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 0
br label %39
39: ; preds = %36, %64
%40 = phi i32 [ %33, %36 ], [ %67, %64 ]
%41 = icmp eq i32 %40, %30
br i1 %41, label %44, label %42
42: ; preds = %39
%43 = call i32 @putchar(i32 10)
br label %44
44: ; preds = %42, %39
%45 = call i32 @memset(i32* %37, i32 0, i32 4000)
%46 = call i32 @memset(i32* %38, i32 0, i32 40)
%47 = load i32, i32* @stdin
%48 = call i64 @fgets(i8* %7, i32 1024, i32 %47)
%49 = icmp eq i64 %48, 0
%50 = load i8, i8* %7
%51 = icmp eq i8 %50, 10
%52 = select i1 %49, i1 true, i1 %51
br i1 %52, label %64, label %53
53: ; preds = %44, %53
%54 = phi i64 [ %56, %53 ], [ 0, %44 ]
%55 = call i32 @atoi(i8* %7)
%56 = add nuw i64 %54, 1
%57 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 %54
store i32 %55, i32* %57
%58 = load i32, i32* @stdin
%59 = call i64 @fgets(i8* %7, i32 1024, i32 %58)
%60 = icmp eq i64 %59, 0
%61 = load i8, i8* %7
%62 = icmp eq i8 %61, 10
%63 = select i1 %60, i1 true, i1 %62
br i1 %63, label %64, label %53
64: ; preds = %53, %44
%65 = call i32 @execute(i32* %37, i32* %38)
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %65)
%67 = load i32, i32* %6
%68 = add nsw i32 %67, -1
store i32 %68, i32* %6
%69 = icmp eq i32 %67, 0
br i1 %69, label %70, label %39
70: ; preds = %64, %26
%71 = load i32, i32* @stdin
%72 = call i32 @fclose(i32 %71)
ret i32 0
}