#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 BasicCommandLine();
scalar_t__ BasicInterpret(int /*<<< orphan*/ *);
int EXIT_FAILURE;
int EXIT_SUCCESS;
int LexGetCurrentColumnCount();
char *LexGetCurrentLine();
int LexGetCurrentLineCount();
char *LexGetErrorMessage();
int /*<<< orphan*/ PrintErrorMessage();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int main(int argc, char *argv[]) {
  FILE *fp;
  int result;
  if (argc == 1) {
    while ((result = BasicCommandLine()) == 0) {
    }
    if (result == 1) {
      PrintErrorMessage();
    }
  } else if (argc == 2) {
    fp = fopen(argv[1], "r");
    if (!fp) {
      printf("Could not open file %s!\r\n", argv[1]);
      return EXIT_FAILURE;
    }
    printf("Running BASIC script %s\r\n", argv[1]);
    if (BasicInterpret(fp) != 0) {
      printf("Error: Line: %d, Column: %d", LexGetCurrentLineCount(),
             LexGetCurrentColumnCount());
      puts("");
      printf("%s", LexGetCurrentLine());
      int i;
      for (i = 0; i < LexGetCurrentColumnCount() - 1; i++) {
        printf(" ");
      }
      puts("^");
      puts(LexGetErrorMessage());
    }
    fclose(fp);
    puts("");
    puts("BASIC test program exited successfully.");
  } else {
    puts("Usage: ./basic [filename]");
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1203 <main+0x53>
jmp    11d5 <main+0x25>
mov    $0x0,%al
call   1080 <BasicCommandLine@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    11ed <main+0x3d>
jmp    11d5 <main+0x25>
cmpl   $0x1,-0x1c(%rbp)
jne    11fe <main+0x4e>
mov    $0x0,%al
call   10c0 <PrintErrorMessage@plt>
jmp    136b <main+0x1bb>
cmpl   $0x2,-0x8(%rbp)
jne    1349 <main+0x199>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde4(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1257 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1377 <main+0x1c7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <BasicInterpret@plt>
cmp    $0x0,%rax
je     1323 <main+0x173>
mov    $0x0,%al
call   10b0 <LexGetCurrentLineCount@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1060 <LexGetCurrentColumnCount@plt>
mov    -0x24(%rbp),%esi
mov    %eax,%edx
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd70(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   10a0 <LexGetCurrentLine@plt>
mov    %rax,%rsi
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <LexGetCurrentColumnCount@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1308 <main+0x158>
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12cf <main+0x11f>
lea    0xd48(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1030 <LexGetErrorMessage@plt>
mov    %rax,%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xce8(%rip),%rdi
call   1040 <puts@plt>
lea    0xd1a(%rip),%rdi
call   1040 <puts@plt>
jmp    1366 <main+0x1b6>
lea    0xd31(%rip),%rdi
call   1040 <puts@plt>
mov    0x2c84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1377 <main+0x1c7>
jmp    136b <main+0x1bb>
mov    0x2c66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
je     1200 <main+0x40>
cmp    $0x1,%edi
jne    12fd <main+0x13d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1090 <BasicCommandLine@plt>
test   %eax,%eax
je     11e0 <main+0x20>
cmp    $0x1,%eax
jne    12f4 <main+0x134>
xor    %eax,%eax
call   10d0 <PrintErrorMessage@plt>
jmp    12f4 <main+0x134>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xdf2(%rip),%rsi
call   10e0 <fopen@plt>
mov    0x8(%rbx),%rsi
test   %rax,%rax
je     130b <main+0x14b>
mov    %rax,%r14
lea    0xdf2(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14,%rdi
call   10a0 <BasicInterpret@plt>
test   %rax,%rax
je     12d6 <main+0x116>
xor    %eax,%eax
call   10c0 <LexGetCurrentLineCount@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <LexGetCurrentColumnCount@plt>
lea    0xddd(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   10b0 <LexGetCurrentLine@plt>
lea    0xdd6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
call   1070 <LexGetCurrentColumnCount@plt>
cmp    $0x2,%eax
jl     12bb <main+0xfb>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
xor    %eax,%eax
call   1070 <LexGetCurrentColumnCount@plt>
add    $0xffffffff,%eax
cmp    %eax,%ebx
jl     12a0 <main+0xe0>
lea    0xd93(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1040 <LexGetErrorMessage@plt>
mov    %rax,%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xd68(%rip),%rdi
call   1050 <puts@plt>
mov    0x2cdd(%rip),%rax
jmp    1320 <main+0x160>
lea    0xd7b(%rip),%rdi
call   1050 <puts@plt>
jmp    1319 <main+0x159>
lea    0xcf0(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2cc0(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"Could not open file %s!\0D\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [26 x i8] c"Running BASIC script %s\0D\0A\00"
@.str.3 = [28 x i8] c"Error: Line: %d, Column: %d\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [2 x i8] c" \00"
@.str.7 = [2 x i8] c"^\00"
@.str.8 = [40 x i8] c"BASIC test program exited successfully.\00"
@.str.9 = [26 x i8] c"Usage: ./basic [filename]\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %22
11: ; preds = %2
br label %12
12: ; preds = %15, %11
%13 = call i32 (...) @BasicCommandLine()
store i32 %13, i32* %7
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
br label %12
16: ; preds = %12
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 (...) @PrintErrorMessage()
br label %21
21: ; preds = %19, %16
br label %76
22: ; preds = %2
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 2
br i1 %24, label %25, label %72
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %29, i32** %6
%30 = load i32*, i32** %6
%31 = icmp ne i32* %30, null
br i1 %31, label %38, label %32
32: ; preds = %25
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @EXIT_FAILURE
store i32 %37, i32* %3
br label %78
38: ; preds = %25
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = load i32*, i32** %6
%44 = call i64 @BasicInterpret(i32* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %67
46: ; preds = %38
%47 = call i32 (...) @LexGetCurrentLineCount()
%48 = call i32 (...) @LexGetCurrentColumnCount()
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %47, i32 %48)
%50 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%51 = call i8* (...) @LexGetCurrentLine()
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %51)
store i32 0, i32* %8
br label %53
53: ; preds = %60, %46
%54 = load i32, i32* %8
%55 = call i32 (...) @LexGetCurrentColumnCount()
%56 = sub nsw i32 %55, 1
%57 = icmp slt i32 %54, %56
br i1 %57, label %58, label %63
58: ; preds = %53
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %60
60: ; preds = %58
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
br label %53
63: ; preds = %53
%64 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%65 = call i8* (...) @LexGetErrorMessage()
%66 = call i32 @puts(i8* %65)
br label %67
67: ; preds = %63, %38
%68 = load i32*, i32** %6
%69 = call i32 @fclose(i32* %68)
%70 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%71 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0))
br label %75
72: ; preds = %22
%73 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
store i32 %74, i32* %3
br label %78
75: ; preds = %67
br label %76
76: ; preds = %75, %21
%77 = load i32, i32* @EXIT_SUCCESS
store i32 %77, i32* %3
br label %78
78: ; preds = %76, %72, %32
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"Could not open file %s!\0D\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [26 x i8] c"Running BASIC script %s\0D\0A\00"
@.str.3 = [28 x i8] c"Error: Line: %d, Column: %d\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.7 = [2 x i8] c"^\00"
@.str.8 = [40 x i8] c"BASIC test program exited successfully.\00"
@.str.9 = [26 x i8] c"Usage: ./basic [filename]\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %43 [
i32 1, label %3
i32 2, label %7
]
3: ; preds = %2, %3
%4 = tail call i32 (...) @BasicCommandLine()
switch i32 %4, label %45 [
i32 0, label %3
i32 1, label %5
]
5: ; preds = %3
%6 = tail call i32 (...) @PrintErrorMessage()
br label %45
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
%12 = load i8*, i8** %8
br i1 %11, label %13, label %15
13: ; preds = %7
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %45
15: ; preds = %7
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%17 = tail call i64 @BasicInterpret(i32* %10)
%18 = icmp eq i64 %17, 0
br i1 %18, label %39, label %19
19: ; preds = %15
%20 = tail call i32 (...) @LexGetCurrentLineCount()
%21 = tail call i32 (...) @LexGetCurrentColumnCount()
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 %21)
%23 = tail call i32 @putchar(i32 10)
%24 = tail call i8* (...) @LexGetCurrentLine()
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %24)
%26 = tail call i32 (...) @LexGetCurrentColumnCount()
%27 = icmp sgt i32 %26, 1
br i1 %27, label %28, label %35
28: ; preds = %19, %28
%29 = phi i32 [ %31, %28 ], [ 0, %19 ]
%30 = tail call i32 @putchar(i32 32)
%31 = add nuw nsw i32 %29, 1
%32 = tail call i32 (...) @LexGetCurrentColumnCount()
%33 = add nsw i32 %32, -1
%34 = icmp slt i32 %31, %33
br i1 %34, label %28, label %35
35: ; preds = %28, %19
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%37 = tail call i8* (...) @LexGetErrorMessage()
%38 = tail call i32 @puts(i8* dereferenceable(1) %37)
br label %39
39: ; preds = %35, %15
%40 = tail call i32 @fclose(i32* %10)
%41 = tail call i32 @putchar(i32 10)
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0))
br label %45
43: ; preds = %2
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %45
45: ; preds = %3, %39, %5, %43, %13
%46 = phi i32* [ @EXIT_FAILURE, %13 ], [ @EXIT_FAILURE, %43 ], [ @EXIT_SUCCESS, %5 ], [ @EXIT_SUCCESS, %39 ], [ @EXIT_SUCCESS, %3 ]
%47 = load i32, i32* %46
ret i32 %47
}