#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 */
char EOF;
int /*<<< orphan*/ exit(int);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
scalar_t__ isspace(char);
int /*<<< orphan*/ stderr;
int parse_read_line(FILE *file, char *line_buffer, int line_buffer_len,
                    int eof_expected, char *filename, int *line_number) {
  int count = 0;
  int in_comment = 0;
  for (;;) {
    char c = fgetc(file);
    if (c == EOF) {
      line_buffer[count] = 0;
      if (eof_expected && count > 0) {
        fprintf(stderr, "%s:%d UNEXPECTED TRAILING GARBAGE\n", filename,
                *line_number);
        exit(1);
      } else if (!eof_expected) {
        fprintf(stderr, "%s:%d UNEXPECTED EOF\n", filename, *line_number);
        exit(1);
      }
      return count;
    }
    if (c == '\n') {
      (*line_number)++;
      if (count == 0) {
        in_comment = 0;
        continue;
      }
      if (eof_expected) {
        fprintf(stderr, "%s:%d UNEXPECTED TRAILING GARBAGE\n", filename,
                *line_number);
        exit(1);
      }
      line_buffer[count] = 0;
      return count;
    }
    if (isspace(c) || in_comment) {
      continue;
    }
    if (c == '*') {
      in_comment = 1;
      continue;
    }
    line_buffer[count] = c;
    count++;
    if (count >= line_buffer_len) {
      fprintf(stderr, "%s:%d LINE TOO LONG\n", filename, *line_number);
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<parse_read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x39(%rbp)
movsbl -0x39(%rbp),%eax
mov    0x2e65(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    121a <parse_read_line+0xda>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x20(%rbp)
je     11d7 <parse_read_line+0x97>
cmpl   $0x0,-0x34(%rbp)
jle    11d7 <parse_read_line+0x97>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
lea    0xe38(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
jne    120a <parse_read_line+0xca>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
lea    0xe28(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    120f <parse_read_line+0xcf>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    131e <parse_read_line+0x1de>
movsbl -0x39(%rbp),%eax
cmp    $0xa,%eax
jne    1292 <parse_read_line+0x152>
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
cmpl   $0x0,-0x34(%rbp)
jne    1248 <parse_read_line+0x108>
movl   $0x0,-0x38(%rbp)
jmp    116c <parse_read_line+0x2c>
cmpl   $0x0,-0x20(%rbp)
je     127b <parse_read_line+0x13b>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
lea    0xd94(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    131e <parse_read_line+0x1de>
movsbl -0x39(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
jne    12af <parse_read_line+0x16f>
cmpl   $0x0,-0x38(%rbp)
je     12b4 <parse_read_line+0x174>
jmp    116c <parse_read_line+0x2c>
movsbl -0x39(%rbp),%eax
cmp    $0x2a,%eax
jne    12cd <parse_read_line+0x18d>
movl   $0x1,-0x38(%rbp)
jmp    116c <parse_read_line+0x2c>
mov    -0x39(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1319 <parse_read_line+0x1d9>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
lea    0xd2f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    116c <parse_read_line+0x2c>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_read_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%rbx
mov    %r8,%r12
mov    %ecx,%r13d
mov    %edx,0x24(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbp
call   1030 <fgetc@plt>
mov    %eax,%r15d
mov    0x2e78(%rip),%rax
cmp    (%rax),%r15b
jne    118a <parse_read_line+0x4a>
movb   $0x0,(%r14)
xor    %r14d,%r14d
test   %r13d,%r13d
jne    128a <parse_read_line+0x14a>
jmp    125d <parse_read_line+0x11d>
mov    %r14,0x18(%rsp)
mov    %r13d,0xc(%rsp)
mov    %r12,0x10(%rsp)
xor    %r13d,%r13d
xor    %r14d,%r14d
jmp    11e0 <parse_read_line+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%ecx
add    $0x1,%ecx
mov    %ecx,(%rbx)
xor    %r14d,%r14d
mov    $0x0,%r13d
test   %r12d,%r12d
jne    1274 <parse_read_line+0x134>
mov    %rbp,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r15d
mov    0x2e0d(%rip),%rax
cmp    (%rax),%r15b
je     123b <parse_read_line+0xfb>
mov    %r14d,%r12d
cmp    $0xa,%r15b
je     11b0 <parse_read_line+0x70>
movsbl %r15b,%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    1208 <parse_read_line+0xc8>
test   %r13d,%r13d
jne    1208 <parse_read_line+0xc8>
mov    $0x1,%r13d
cmp    $0x2a,%r15b
jne    120d <parse_read_line+0xcd>
mov    %r12d,%r14d
jmp    11c9 <parse_read_line+0x89>
movslq %r12d,%r14
mov    0x18(%rsp),%rax
mov    %r15b,(%rax,%r14,1)
add    $0x1,%r14d
xor    %r13d,%r13d
cmp    0x24(%rsp),%r14d
jl     11c9 <parse_read_line+0x89>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%ecx
lea    0xe00(%rip),%rsi
jmp    12b9 <parse_read_line+0x179>
movslq %r14d,%rax
mov    0x18(%rsp),%rcx
movb   $0x0,(%rcx,%rax,1)
mov    0xc(%rsp),%eax
test   %eax,%eax
je     1254 <parse_read_line+0x114>
test   %r14d,%r14d
jg     129c <parse_read_line+0x15c>
test   %eax,%eax
mov    0x10(%rsp),%r12
jne    128a <parse_read_line+0x14a>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%ecx
lea    0xdb4(%rip),%rsi
mov    %r12,%rdx
jmp    12be <parse_read_line+0x17e>
cmpl   $0x0,0xc(%rsp)
jne    12a9 <parse_read_line+0x169>
movslq %r12d,%rax
mov    0x18(%rsp),%rcx
movb   $0x0,(%rcx,%rax,1)
mov    %r12d,%r14d
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%ecx
jmp    12b2 <parse_read_line+0x172>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
lea    0xd47(%rip),%rsi
mov    0x10(%rsp),%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@EOF = global i8 0
@stderr = global i32 0
@.str = [35 x i8] c"%s:%d UNEXPECTED TRAILING GARBAGE\0A\00"
@.str.1 = [22 x i8] c"%s:%d UNEXPECTED EOF\0A\00"
@.str.2 = [21 x i8] c"%s:%d LINE TOO LONG\0A\00"
define i32 @parse_read_line(i32* %0, i8* %1, i32 %2, i32 %3, i8* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8
store i32* %0, i32** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i32* %5, i32** %13
store i32 0, i32* %14
store i32 0, i32* %15
br label %17
17: ; preds = %113, %94, %89, %65, %6
%18 = load i32*, i32** %8
%19 = call signext i8 @fgetc(i32* %18)
store i8 %19, i8* %16
%20 = load i8, i8* %16
%21 = sext i8 %20 to i32
%22 = load i8, i8* @EOF
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %21, %23
br i1 %24, label %25, label %55
25: ; preds = %17
%26 = load i8*, i8** %9
%27 = load i32, i32* %14
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 0, i8* %29
%30 = load i32, i32* %11
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %25
%33 = load i32, i32* %14
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %12
%38 = load i32*, i32** %13
%39 = load i32, i32* %38
%40 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %37, i32 %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %32, %25
%43 = load i32, i32* %11
%44 = icmp ne i32 %43, 0
br i1 %44, label %52, label %45
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %12
%48 = load i32*, i32** %13
%49 = load i32, i32* %48
%50 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %47, i32 %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %42
br label %53
53: ; preds = %52
%54 = load i32, i32* %14
store i32 %54, i32* %7
br label %114
55: ; preds = %17
%56 = load i8, i8* %16
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 10
br i1 %58, label %59, label %82
59: ; preds = %55
%60 = load i32*, i32** %13
%61 = load i32, i32* %60
%62 = add nsw i32 %61, 1
store i32 %62, i32* %60
%63 = load i32, i32* %14
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %59
store i32 0, i32* %15
br label %17
66: ; preds = %59
%67 = load i32, i32* %11
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %76
69: ; preds = %66
%70 = load i32, i32* @stderr
%71 = load i8*, i8** %12
%72 = load i32*, i32** %13
%73 = load i32, i32* %72
%74 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %71, i32 %73)
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %66
%77 = load i8*, i8** %9
%78 = load i32, i32* %14
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
store i8 0, i8* %80
%81 = load i32, i32* %14
store i32 %81, i32* %7
br label %114
82: ; preds = %55
%83 = load i8, i8* %16
%84 = call i64 @isspace(i8 signext %83)
%85 = icmp ne i64 %84, 0
br i1 %85, label %89, label %86
86: ; preds = %82
%87 = load i32, i32* %15
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %90
89: ; preds = %86, %82
br label %17
90: ; preds = %86
%91 = load i8, i8* %16
%92 = sext i8 %91 to i32
%93 = icmp eq i32 %92, 42
br i1 %93, label %94, label %95
94: ; preds = %90
store i32 1, i32* %15
br label %17
95: ; preds = %90
%96 = load i8, i8* %16
%97 = load i8*, i8** %9
%98 = load i32, i32* %14
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i8, i8* %97, i64 %99
store i8 %96, i8* %100
%101 = load i32, i32* %14
%102 = add nsw i32 %101, 1
store i32 %102, i32* %14
%103 = load i32, i32* %14
%104 = load i32, i32* %10
%105 = icmp sge i32 %103, %104
br i1 %105, label %106, label %113
106: ; preds = %95
%107 = load i32, i32* @stderr
%108 = load i8*, i8** %12
%109 = load i32*, i32** %13
%110 = load i32, i32* %109
%111 = call i32 @fprintf(i32 %107, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %108, i32 %110)
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %95
br label %17
114: ; preds = %76, %53
%115 = load i32, i32* %7
ret i32 %115
}

LLVM IR (-O2):
@EOF = global i8 0
@stderr = global i32 0
@.str = [35 x i8] c"%s:%d UNEXPECTED TRAILING GARBAGE\0A\00"
@.str.1 = [22 x i8] c"%s:%d UNEXPECTED EOF\0A\00"
@.str.2 = [21 x i8] c"%s:%d LINE TOO LONG\0A\00"
define i32 @parse_read_line(i32* nocapture %0, i8* nocapture writeonly %1, i32 %2, i32 %3, i8* %4, i32* nocapture %5) {
%7 = tail call signext i8 @fgetc(i32* %0)
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %7, %8
br i1 %9, label %10, label %29
10: ; preds = %6
store i8 0, i8* %1
%11 = icmp eq i32 %3, 0
br i1 %11, label %24, label %70
12: ; preds = %64
%13 = sext i32 %65 to i64
%14 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 0, i8* %14
%15 = icmp ne i32 %3, 0
%16 = icmp sgt i32 %65, 0
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = load i32, i32* %5
%21 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %12
br i1 %15, label %70, label %24
24: ; preds = %10, %23
%25 = load i32, i32* @stderr
%26 = load i32, i32* %5
%27 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32 %26)
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %6, %64
%30 = phi i8 [ %67, %64 ], [ %7, %6 ]
%31 = phi i32 [ %66, %64 ], [ 0, %6 ]
%32 = phi i32 [ %65, %64 ], [ 0, %6 ]
%33 = icmp eq i8 %30, 10
br i1 %33, label %34, label %47
34: ; preds = %29
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
%37 = icmp eq i32 %32, 0
br i1 %37, label %64, label %38
38: ; preds = %34
%39 = icmp eq i32 %3, 0
br i1 %39, label %44, label %40
40: ; preds = %38
%41 = load i32, i32* @stderr
%42 = tail call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %36)
%43 = tail call i32 @exit(i32 1)
unreachable
44: ; preds = %38
%45 = sext i32 %32 to i64
%46 = getelementptr inbounds i8, i8* %1, i64 %45
store i8 0, i8* %46
br label %70
47: ; preds = %29
%48 = tail call i64 @isspace(i8 signext %30)
%49 = icmp ne i64 %48, 0
%50 = icmp ne i32 %31, 0
%51 = select i1 %49, i1 true, i1 %50
br i1 %51, label %64, label %52
52: ; preds = %47
%53 = icmp eq i8 %30, 42
br i1 %53, label %64, label %54
54: ; preds = %52
%55 = sext i32 %32 to i64
%56 = getelementptr inbounds i8, i8* %1, i64 %55
store i8 %30, i8* %56
%57 = add nsw i32 %32, 1
%58 = icmp slt i32 %57, %2
br i1 %58, label %64, label %59
59: ; preds = %54
%60 = load i32, i32* @stderr
%61 = load i32, i32* %5
%62 = tail call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 %61)
%63 = tail call i32 @exit(i32 1)
unreachable
64: ; preds = %54, %52, %47, %34
%65 = phi i32 [ 0, %34 ], [ %32, %47 ], [ %32, %52 ], [ %57, %54 ]
%66 = phi i32 [ 0, %34 ], [ %31, %47 ], [ 1, %52 ], [ 0, %54 ]
%67 = tail call signext i8 @fgetc(i32* %0)
%68 = load i8, i8* @EOF
%69 = icmp eq i8 %67, %68
br i1 %69, label %12, label %29
70: ; preds = %10, %44, %23
%71 = phi i32 [ %32, %44 ], [ %65, %23 ], [ 0, %10 ]
ret i32 %71
}