#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 */
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *get_next_token(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *lexer_test() {
  FILE *fd = fopen("resources/testfile1.txt", "r");
  char endchar;
  do {
    if (!(fd != NULL))
      return "Couldn't open file in lexer_test\n";
  } while (0);
  char *ftoken = get_next_token(fd, &endchar);
  do {
    if (!(strcmp(ftoken, "John") == 0)) {
      free(ftoken);
      return "Got the wrong token in lexer_test";
    }
  } while (0);
  free(ftoken);
  do {
    if (!(endchar == ' '))
      return "Didn't correctly detect the end symbol in lexer_test";
  } while (0);
  char *stoken = get_next_token(fd, &endchar);
  do {
    if (!(strcmp(stoken, "Lennon") == 0)) {
      free(stoken);
      return "Got the wrong second token in lexer_test";
    }
  } while (0);
  free(stoken);
  do {
    if (!(endchar == ','))
      return "Didn't correctly detect the second end symbol in lexer_test";
  } while (0);
  if (fclose(fd) != 0) {
    fprintf(stderr, "Couldn't properly close file in lexer_test\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<lexer_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe91(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119a <lexer_test+0x3a>
lea    0xe89(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12b7 <lexer_test+0x157>
jmp    119f <lexer_test+0x3f>
mov    -0x10(%rbp),%rdi
lea    -0x11(%rbp),%rsi
call   1070 <get_next_token@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11e3 <lexer_test+0x83>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xe67(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12b7 <lexer_test+0x157>
jmp    11e8 <lexer_test+0x88>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x20,%eax
je     120e <lexer_test+0xae>
lea    0xe5e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12b7 <lexer_test+0x157>
jmp    1213 <lexer_test+0xb3>
mov    -0x10(%rbp),%rdi
lea    -0x11(%rbp),%rsi
call   1070 <get_next_token@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1257 <lexer_test+0xf7>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    0xe51(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12b7 <lexer_test+0x157>
jmp    125c <lexer_test+0xfc>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x2c,%eax
je     1282 <lexer_test+0x122>
lea    0xe4f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12b7 <lexer_test+0x157>
jmp    1287 <lexer_test+0x127>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     12af <lexer_test+0x14f>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lexer_test>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe90(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11bc <lexer_test+0x5c>
mov    %rax,%r14
lea    0xf(%rsp),%rsi
mov    %rax,%rdi
call   1070 <get_next_token@plt>
mov    %rax,%rbx
lea    0xea1(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcmp@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r15,%r15
je     11c5 <lexer_test+0x65>
lea    0xe87(%rip),%rax
jmp    120b <lexer_test+0xab>
lea    0xe57(%rip),%rax
jmp    120b <lexer_test+0xab>
cmpb   $0x20,0xf(%rsp)
jne    1204 <lexer_test+0xa4>
lea    0xf(%rsp),%rsi
mov    %r14,%rdi
call   1070 <get_next_token@plt>
mov    %rax,%rbx
lea    0xeb5(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcmp@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r15,%r15
je     1215 <lexer_test+0xb5>
lea    0xe9d(%rip),%rax
jmp    120b <lexer_test+0xab>
lea    0xe58(%rip),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
cmpb   $0x2c,0xf(%rsp)
jne    1242 <lexer_test+0xe2>
mov    %r14,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     123e <lexer_test+0xde>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xecb(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
jmp    120b <lexer_test+0xab>
lea    0xe7f(%rip),%rax
jmp    120b <lexer_test+0xab>

LLVM IR (-O0):
@.str = [24 x i8] c"resources/testfile1.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"Couldn't open file in lexer_test\0A\00"
@.str.3 = [5 x i8] c"John\00"
@.str.4 = [34 x i8] c"Got the wrong token in lexer_test\00"
@.str.5 = [53 x i8] c"Didn't correctly detect the end symbol in lexer_test\00"
@.str.6 = [7 x i8] c"Lennon\00"
@.str.7 = [41 x i8] c"Got the wrong second token in lexer_test\00"
@.str.8 = [60 x i8] c"Didn't correctly detect the second end symbol in lexer_test\00"
@stderr = global i32 0
@.str.9 = [44 x i8] c"Couldn't properly close file in lexer_test\0A\00"
define i8* @lexer_test() {
%1 = alloca i8*
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8*
%6 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
br label %7
7: ; preds = %0
%8 = load i32*, i32** %2
%9 = icmp ne i32* %8, null
br i1 %9, label %11, label %10
10: ; preds = %7
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8** %1
br label %60
11: ; preds = %7
br label %12
12: ; preds = %11
%13 = load i32*, i32** %2
%14 = call i8* @get_next_token(i32* %13, i8* %3)
store i8* %14, i8** %4
br label %15
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8** %1
br label %60
22: ; preds = %15
br label %23
23: ; preds = %22
%24 = load i8*, i8** %4
%25 = call i32 @free(i8* %24)
br label %26
26: ; preds = %23
%27 = load i8, i8* %3
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 32
br i1 %29, label %31, label %30
30: ; preds = %26
store i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), i8** %1
br label %60
31: ; preds = %26
br label %32
32: ; preds = %31
%33 = load i32*, i32** %2
%34 = call i8* @get_next_token(i32* %33, i8* %3)
store i8* %34, i8** %5
br label %35
35: ; preds = %32
%36 = load i8*, i8** %5
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %35
%40 = load i8*, i8** %5
%41 = call i32 @free(i8* %40)
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i8** %1
br label %60
42: ; preds = %35
br label %43
43: ; preds = %42
%44 = load i8*, i8** %5
%45 = call i32 @free(i8* %44)
br label %46
46: ; preds = %43
%47 = load i8, i8* %3
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 44
br i1 %49, label %51, label %50
50: ; preds = %46
store i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.8, i64 0, i64 0), i8** %1
br label %60
51: ; preds = %46
br label %52
52: ; preds = %51
%53 = load i32*, i32** %2
%54 = call i64 @fclose(i32* %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0))
br label %59
59: ; preds = %56, %52
store i8* null, i8** %1
br label %60
60: ; preds = %59, %50, %39, %30, %19, %10
%61 = load i8*, i8** %1
ret i8* %61
}

LLVM IR (-O2):
@.str = [24 x i8] c"resources/testfile1.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"Couldn't open file in lexer_test\0A\00"
@.str.3 = [5 x i8] c"John\00"
@.str.4 = [34 x i8] c"Got the wrong token in lexer_test\00"
@.str.5 = [53 x i8] c"Didn't correctly detect the end symbol in lexer_test\00"
@.str.6 = [7 x i8] c"Lennon\00"
@.str.7 = [41 x i8] c"Got the wrong second token in lexer_test\00"
@.str.8 = [60 x i8] c"Didn't correctly detect the second end symbol in lexer_test\00"
@stderr = global i32 0
@.str.9 = [44 x i8] c"Couldn't properly close file in lexer_test\0A\00"
define i8* @lexer_test() {
%1 = alloca i8
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %26, label %4
4: ; preds = %0
%5 = call i8* @get_next_token(i32* %2, i8* %1)
%6 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
%8 = call i32 @free(i8* %5)
br i1 %7, label %9, label %26
9: ; preds = %4
%10 = load i8, i8* %1
%11 = icmp eq i8 %10, 32
br i1 %11, label %12, label %26
12: ; preds = %9
%13 = call i8* @get_next_token(i32* %2, i8* %1)
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
%16 = call i32 @free(i8* %13)
br i1 %15, label %17, label %26
17: ; preds = %12
%18 = load i8, i8* %1
%19 = icmp eq i8 %18, 44
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = call i64 @fclose(i32* %2)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0))
br label %26
26: ; preds = %12, %4, %9, %20, %23, %17, %0
%27 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), %0 ], [ getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), %9 ], [ getelementptr inbounds ([60 x i8], [60 x i8]* @.str.8, i64 0, i64 0), %17 ], [ null, %23 ], [ null, %20 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), %4 ], [ getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), %12 ]
ret i8* %27
}