#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 ssize_t;

/* Variables and functions */
#define EAGAIN 129
#define EINTR 128
int errno;
int read(int, char *, int);
ssize_t get_token(int fd, char *token, size_t max_len) {
  char *c = token;
  int rv;
  ssize_t len = 0;
  int in_string = 0;
  while (1) {
    rv = read(fd, c, 1);
    if (rv == 0) {
      return 0;
    } else if (rv < 1) {
      switch (errno) {
      case EINTR:
      case EAGAIN:
        continue;
      default:
        return -errno;
      }
    }
    switch (*c) {
    case ' ':
    case '\t':
    case '\r':
    case '\n':
      if (c == token) {
        continue;
      }
      if (!in_string) {
        *c = '\0';
        return len;
      }
      break;
    case '\"':
      if (c == token) {
        in_string = 1;
        continue;
      }
      *c = '\0';
      return len;
    }
    len++;
    c++;
    if (len == (ssize_t)max_len) {
      *c = '\0';
      return len;
    }
  }
}


x86 assembly (clang, -O0):
<get_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1163 <get_token+0x53>
movl   $0x0,-0x4(%rbp)
jmp    128d <get_token+0x17d>
cmpl   $0x1,-0x24(%rbp)
jge    119f <get_token+0x8f>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
sub    $0x1,%eax
ja     118c <get_token+0x7c>
jmp    1187 <get_token+0x77>
jmp    1139 <get_token+0x29>
xor    %eax,%eax
mov    0x2e4b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    128d <get_token+0x17d>
jmp    11a4 <get_token+0x94>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x30(%rbp)
add    $0xfffffff7,%eax
sub    $0x2,%eax
jb     11f2 <get_token+0xe2>
jmp    11bf <get_token+0xaf>
mov    -0x30(%rbp),%eax
sub    $0xd,%eax
je     11f2 <get_token+0xe2>
jmp    11d0 <get_token+0xc0>
mov    -0x30(%rbp),%eax
sub    $0x20,%eax
je     11f2 <get_token+0xe2>
jmp    11e1 <get_token+0xd1>
mov    -0x30(%rbp),%eax
sub    $0x22,%eax
je     1226 <get_token+0x116>
jmp    1252 <get_token+0x142>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1205 <get_token+0xf5>
jmp    1139 <get_token+0x29>
cmpl   $0x0,-0x2c(%rbp)
jne    1221 <get_token+0x111>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128d <get_token+0x17d>
jmp    1252 <get_token+0x142>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1240 <get_token+0x130>
movl   $0x1,-0x2c(%rbp)
jmp    1139 <get_token+0x29>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128d <get_token+0x17d>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    %ecx,%eax
jne    1288 <get_token+0x178>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128d <get_token+0x17d>
jmp    1139 <get_token+0x29>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_token>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,%r12
mov    %edi,%ebp
xor    %r15d,%r15d
mov    0x2eae(%rip),%r13
movabs $0x100002600,%r14
mov    %rsi,%rbx
movl   $0x0,0xc(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
jne    1184 <get_token+0x74>
jmp    11cb <get_token+0xbb>
nopl   0x0(%rax)
mov    0x0(%r13),%eax
mov    %eax,%ecx
and    $0xfffffffe,%ecx
cmp    $0x80,%ecx
jne    11d0 <get_token+0xc0>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
je     11cb <get_token+0xbb>
test   %eax,%eax
jle    1160 <get_token+0x50>
movsbl (%rbx),%eax
cmp    $0x22,%eax
ja     11a2 <get_token+0x92>
bt     %rax,%r14
jae    11b3 <get_token+0xa3>
cmp    %r12,%rbx
je     1171 <get_token+0x61>
cmpl   $0x0,0xc(%rsp)
je     11c6 <get_token+0xb6>
add    $0x1,%r15d
add    $0x1,%rbx
cmp    0x10(%rsp),%r15d
jne    1147 <get_token+0x37>
jmp    11e7 <get_token+0xd7>
cmp    $0x22,%rax
jne    11a2 <get_token+0x92>
movl   $0x1,0xc(%rsp)
cmp    %r12,%rbx
je     1147 <get_token+0x37>
movb   $0x0,(%rbx)
jmp    11d5 <get_token+0xc5>
xor    %r15d,%r15d
jmp    11d5 <get_token+0xc5>
neg    %eax
mov    %eax,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movb   $0x0,(%rbx)
mov    0x10(%rsp),%rax
mov    %eax,%r15d
jmp    11d5 <get_token+0xc5>

LLVM IR (-O0):
@errno = global i32 0
define i32 @get_token(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%12 = load i8*, i8** %6
store i8* %12, i8** %8
store i32 0, i32* %10
store i32 0, i32* %11
br label %13
13: ; preds = %3, %25, %38, %50, %66
%14 = load i32, i32* %5
%15 = load i8*, i8** %8
%16 = call i32 @read(i32 %14, i8* %15, i32 1)
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 0, i32* %4
br label %67
20: ; preds = %13
%21 = load i32, i32* %9
%22 = icmp slt i32 %21, 1
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i32, i32* @errno
switch i32 %24, label %26 [
i32 128, label %25
i32 129, label %25
]
25: ; preds = %23, %23
br label %13
26: ; preds = %23
%27 = load i32, i32* @errno
%28 = sub nsw i32 0, %27
store i32 %28, i32* %4
br label %67
29: ; preds = %20
br label %30
30: ; preds = %29
%31 = load i8*, i8** %8
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
switch i32 %33, label %54 [
i32 32, label %34
i32 9, label %34
i32 13, label %34
i32 10, label %34
i32 34, label %46
]
34: ; preds = %30, %30, %30, %30
%35 = load i8*, i8** %8
%36 = load i8*, i8** %6
%37 = icmp eq i8* %35, %36
br i1 %37, label %38, label %39
38: ; preds = %34
br label %13
39: ; preds = %34
%40 = load i32, i32* %11
%41 = icmp ne i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = load i8*, i8** %8
store i8 0, i8* %43
%44 = load i32, i32* %10
store i32 %44, i32* %4
br label %67
45: ; preds = %39
br label %54
46: ; preds = %30
%47 = load i8*, i8** %8
%48 = load i8*, i8** %6
%49 = icmp eq i8* %47, %48
br i1 %49, label %50, label %51
50: ; preds = %46
store i32 1, i32* %11
br label %13
51: ; preds = %46
%52 = load i8*, i8** %8
store i8 0, i8* %52
%53 = load i32, i32* %10
store i32 %53, i32* %4
br label %67
54: ; preds = %30, %45
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
%57 = load i8*, i8** %8
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %8
%59 = load i32, i32* %10
%60 = load i64, i64* %7
%61 = trunc i64 %60 to i32
%62 = icmp eq i32 %59, %61
br i1 %62, label %63, label %66
63: ; preds = %54
%64 = load i8*, i8** %8
store i8 0, i8* %64
%65 = load i32, i32* %10
store i32 %65, i32* %4
br label %67
66: ; preds = %54
br label %13
67: ; preds = %63, %51, %42, %26, %19
%68 = load i32, i32* %4
ret i32 %68
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @get_token(i32 %0, i8* %1, i64 %2) {
%4 = trunc i64 %2 to i32
br label %5
5: ; preds = %35, %3
%6 = phi i8* [ %37, %35 ], [ %1, %3 ]
%7 = phi i32 [ %36, %35 ], [ 0, %3 ]
%8 = phi i32 [ %11, %35 ], [ 0, %3 ]
%9 = icmp eq i8* %6, %1
br label %10
10: ; preds = %5, %33
%11 = phi i32 [ %8, %5 ], [ 1, %33 ]
%12 = tail call i32 @read(i32 %0, i8* %6, i32 1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %40, label %14
14: ; preds = %10, %27
%15 = phi i32 [ %28, %27 ], [ %12, %10 ]
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load i32, i32* @errno
%19 = and i32 %18, -2
%20 = icmp eq i32 %19, 128
br i1 %20, label %27, label %21
21: ; preds = %17
%22 = sub nsw i32 0, %18
br label %40
23: ; preds = %14
%24 = load i8, i8* %6
%25 = sext i8 %24 to i32
switch i32 %25, label %35 [
i32 32, label %26
i32 9, label %26
i32 13, label %26
i32 10, label %26
i32 34, label %33
]
26: ; preds = %23, %23, %23, %23
br i1 %9, label %27, label %30
27: ; preds = %26, %17
%28 = tail call i32 @read(i32 %0, i8* %6, i32 1)
%29 = icmp eq i32 %28, 0
br i1 %29, label %40, label %14
30: ; preds = %26
%31 = icmp eq i32 %11, 0
br i1 %31, label %32, label %35
32: ; preds = %30
store i8 0, i8* %6
br label %40
33: ; preds = %23
br i1 %9, label %10, label %34
34: ; preds = %33
store i8 0, i8* %6
br label %40
35: ; preds = %23, %30
%36 = add nuw nsw i32 %7, 1
%37 = getelementptr inbounds i8, i8* %6, i64 1
%38 = icmp eq i32 %36, %4
br i1 %38, label %39, label %5
39: ; preds = %35
store i8 0, i8* %37
br label %40
40: ; preds = %10, %27, %39, %34, %32, %21
%41 = phi i32 [ %22, %21 ], [ %4, %39 ], [ %7, %34 ], [ %7, %32 ], [ 0, %27 ], [ 0, %10 ]
ret i32 %41
}