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

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int lexeme(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *file = fopen("sample.txt", "r");
  char line[256];
  int linenumber = 0;
  while (fgets(line, sizeof(line), file)) {
    printf("%s", line);
    linenumber++;
    if (lexeme(line, linenumber) == -1) {
      if (fgets(line, sizeof(line), file) != NULL) {
        printf("%s\n", line);
        printf("\"end:\" keyword must be placed at the end of the program.\n");
        exit(0);
      }
    }
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1244 <main+0xe4>
lea    -0x110(%rbp),%rsi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x114(%rbp),%esi
call   1070 <lexeme@plt>
cmp    $0xffffffff,%eax
jne    123f <main+0xdf>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     123a <main+0xda>
lea    -0x110(%rbp),%rsi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    123f <main+0xdf>
jmp    1193 <main+0x33>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
lea    0xe7c(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1224 <main+0xb4>
mov    $0x1,%ebp
lea    0xe59(%rip),%r14
mov    %rsp,%rbx
jmp    11d8 <main+0x68>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
add    $0x1,%ebp
test   %rax,%rax
je     1224 <main+0xb4>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <lexeme@plt>
cmp    $0xffffffff,%eax
jne    11c0 <main+0x50>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11c0 <main+0x50>
mov    %rsp,%rdi
call   1030 <puts@plt>
lea    0xdf8(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"sample.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [58 x i8] c"\22end:\22 keyword must be placed at the end of the program.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [256 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
store i32 0, i32* %4
br label %6
6: ; preds = %31, %0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = load i32*, i32** %2
%9 = call i32* @fgets(i8* %7, i32 256, i32* %8)
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %32
11: ; preds = %6
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%17 = load i32, i32* %4
%18 = call i32 @lexeme(i8* %16, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %31
20: ; preds = %11
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%22 = load i32*, i32** %2
%23 = call i32* @fgets(i8* %21, i32 256, i32* %22)
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %20
br label %31
31: ; preds = %30, %11
br label %6
32: ; preds = %6
%33 = load i32*, i32** %2
%34 = call i32 @fclose(i32* %33)
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [11 x i8] c"sample.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@str = [57 x i8] c"\22end:\22 keyword must be placed at the end of the program.\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = call i32* @fgets(i8* %3, i32 256, i32* %2)
%5 = icmp eq i32* %4, null
br i1 %5, label %22, label %6
6: ; preds = %0, %19
%7 = phi i32 [ %9, %19 ], [ 0, %0 ]
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%9 = add nuw nsw i32 %7, 1
%10 = call i32 @lexeme(i8* %3, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %19
12: ; preds = %6
%13 = call i32* @fgets(i8* %3, i32 256, i32* %2)
%14 = icmp eq i32* %13, null
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = call i32 @puts(i8* %3)
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %12, %6
%20 = call i32* @fgets(i8* %3, i32 256, i32* %2)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %6
22: ; preds = %19, %0
%23 = call i32 @fclose(i32* %2)
ret i32 0
}