#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 EOF;
int /*<<< orphan*/ error(char *, size_t);
int getc(int /*<<< orphan*/ *);
int read_token(int c, char *buf, size_t bufsize, FILE *fin, size_t lineno) {
  unsigned i = 0;
  do {
    switch (c) {
    case ' ':
    case '\t':
    case '\n':
      if (i < bufsize)
        buf[i] = '\0';
      else {
        error("Unexpected end-of-file at line %lu when reading token\n",
              lineno);
        return EOF;
      }
      return c;
    default:
      if (i < bufsize - 1)
        buf[i++] = c;
      else {
        error("Unexpected end-of-file at line %lu when reading token\n",
              lineno);
        return EOF;
      }
    }
  } while ((c = getc(fin)) != EOF);
  error("Unexpected end-of-file at line %lu when reading token\n", lineno);
  return EOF;
}


x86 assembly (clang, -O0):
<read_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x30(%rbp)
add    $0xfffffff7,%eax
sub    $0x2,%eax
jb     116a <read_token+0x4a>
jmp    1159 <read_token+0x39>
mov    -0x30(%rbp),%eax
sub    $0x20,%eax
jne    11b3 <read_token+0x93>
jmp    116a <read_token+0x4a>
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%rax
jae    1187 <read_token+0x67>
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
jmp    11a8 <read_token+0x88>
mov    -0x28(%rbp),%rsi
lea    0xe6e(%rip),%rdi
call   1030 <error@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1247 <read_token+0x127>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1247 <read_token+0x127>
mov    -0x2c(%rbp),%eax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11e5 <read_token+0xc5>
mov    -0x8(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
jmp    1206 <read_token+0xe6>
mov    -0x28(%rbp),%rsi
lea    0xe10(%rip),%rdi
call   1030 <error@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1247 <read_token+0x127>
jmp    120b <read_token+0xeb>
jmp    1210 <read_token+0xf0>
mov    -0x20(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x8(%rbp)
mov    0x2dc5(%rip),%rcx
cmp    (%rcx),%eax
jne    1142 <read_token+0x22>
mov    -0x28(%rbp),%rsi
lea    0xdca(%rip),%rdi
call   1030 <error@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_token>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x8(%rsp)
mov    %rcx,%rbx
mov    %rsi,%r12
mov    %edi,%eax
mov    %rdx,0x10(%rsp)
lea    -0x1(%rdx),%rbp
xor    %r14d,%r14d
mov    0x2e9a(%rip),%r13
movabs $0x100000600,%r15
nopl   0x0(%rax,%rax,1)
mov    %r14d,%ecx
cmp    $0x20,%eax
ja     1170 <read_token+0x50>
mov    %eax,%edx
bt     %rdx,%r15
jb     118d <read_token+0x6d>
cmp    %rcx,%rbp
jbe    119b <read_token+0x7b>
add    $0x1,%r14d
mov    %al,(%r12,%rcx,1)
mov    %rbx,%rdi
call   1040 <getc@plt>
cmp    0x0(%r13),%eax
jne    1160 <read_token+0x40>
jmp    119b <read_token+0x7b>
cmp    0x10(%rsp),%rcx
jae    119b <read_token+0x7b>
movb   $0x0,(%r12,%rcx,1)
jmp    11b0 <read_token+0x90>
lea    0xe5e(%rip),%rdi
mov    0x8(%rsp),%rsi
call   1030 <error@plt>
mov    0x0(%r13),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [55 x i8] c"Unexpected end-of-file at line %lu when reading token\0A\00"
@EOF = global i32 0
define i32 @read_token(i32 %0, i8* %1, i64 %2, i32* %3, i64 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i32
store i32 %0, i32* %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i32* %3, i32** %10
store i64 %4, i64* %11
store i32 0, i32* %12
br label %13
13: ; preds = %51, %5
%14 = load i32, i32* %7
switch i32 %14, label %31 [
i32 32, label %15
i32 9, label %15
i32 10, label %15
]
15: ; preds = %13, %13, %13
%16 = load i32, i32* %12
%17 = zext i32 %16 to i64
%18 = load i64, i64* %9
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i8*, i8** %8
%22 = load i32, i32* %12
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
br label %29
25: ; preds = %15
%26 = load i64, i64* %11
%27 = call i32 @error(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i64 %26)
%28 = load i32, i32* @EOF
store i32 %28, i32* %6
br label %60
29: ; preds = %20
%30 = load i32, i32* %7
store i32 %30, i32* %6
br label %60
31: ; preds = %13
%32 = load i32, i32* %12
%33 = zext i32 %32 to i64
%34 = load i64, i64* %9
%35 = sub i64 %34, 1
%36 = icmp ult i64 %33, %35
br i1 %36, label %37, label %45
37: ; preds = %31
%38 = load i32, i32* %7
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %8
%41 = load i32, i32* %12
%42 = add i32 %41, 1
store i32 %42, i32* %12
%43 = zext i32 %41 to i64
%44 = getelementptr inbounds i8, i8* %40, i64 %43
store i8 %39, i8* %44
br label %49
45: ; preds = %31
%46 = load i64, i64* %11
%47 = call i32 @error(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i64 %46)
%48 = load i32, i32* @EOF
store i32 %48, i32* %6
br label %60
49: ; preds = %37
br label %50
50: ; preds = %49
br label %51
51: ; preds = %50
%52 = load i32*, i32** %10
%53 = call i32 @getc(i32* %52)
store i32 %53, i32* %7
%54 = load i32, i32* @EOF
%55 = icmp ne i32 %53, %54
br i1 %55, label %13, label %56
56: ; preds = %51
%57 = load i64, i64* %11
%58 = call i32 @error(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i64 %57)
%59 = load i32, i32* @EOF
store i32 %59, i32* %6
br label %60
60: ; preds = %56, %45, %29, %25
%61 = load i32, i32* %6
ret i32 %61
}

LLVM IR (-O2):
@.str = [55 x i8] c"Unexpected end-of-file at line %lu when reading token\0A\00"
@EOF = global i32 0
define i32 @read_token(i32 %0, i8* nocapture writeonly %1, i64 %2, i32* nocapture %3, i64 %4) {
%6 = add i64 %2, -1
br label %7
7: ; preds = %21, %5
%8 = phi i32 [ %0, %5 ], [ %25, %21 ]
%9 = phi i32 [ 0, %5 ], [ %23, %21 ]
switch i32 %8, label %18 [
i32 32, label %10
i32 9, label %10
i32 10, label %10
]
10: ; preds = %7, %7, %7
%11 = zext i32 %9 to i64
%12 = icmp ult i64 %11, %2
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %1, i64 %11
store i8 0, i8* %14
br label %34
15: ; preds = %10
%16 = tail call i32 @error(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i64 %4)
%17 = load i32, i32* @EOF
br label %34
18: ; preds = %7
%19 = zext i32 %9 to i64
%20 = icmp ugt i64 %6, %19
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = trunc i32 %8 to i8
%23 = add i32 %9, 1
%24 = getelementptr inbounds i8, i8* %1, i64 %19
store i8 %22, i8* %24
%25 = tail call i32 @getc(i32* %3)
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %31, label %7
28: ; preds = %18
%29 = tail call i32 @error(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i64 %4)
%30 = load i32, i32* @EOF
br label %34
31: ; preds = %21
%32 = tail call i32 @error(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i64 %4)
%33 = load i32, i32* @EOF
br label %34
34: ; preds = %31, %28, %13, %15
%35 = phi i32 [ %33, %31 ], [ %30, %28 ], [ %8, %13 ], [ %17, %15 ]
ret i32 %35
}