#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 */

/* Variables and functions */
#define EOF 128
int /*<<< orphan*/ exit(int);
int fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
char *realloc(char *, int);
int /*<<< orphan*/ stdin;
char *next_token(void) {
  int size = 64;
  int tail = 0;
  char *buf = malloc(64);
  if (buf == NULL) {
    {
      perror("malloc");
      exit(1);
    };
  }
  for (;;) {
    int inp = fgetc(stdin);
    switch (inp) {
    case EOF:
      if (tail != 0) {
        buf[tail] = '\0';
      } else {
        free(buf);
        buf = NULL;
      }
      return buf;
      break;
    case ' ':
    case '\t':
    case '\n':
      if (tail != 0) {
        buf[tail] = '\0';
        return buf;
      }
      break;
    default:
      buf[tail++] = inp;
      break;
    }
    if (tail > size) {
      size += 64;
      buf = realloc(buf, size);
      if (buf == NULL) {
        {
          perror("malloc");
          exit(1);
        };
      }
    }
  }
}


x86 assembly (clang, -O0):
<next_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x40,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x40,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a5 <next_token+0x45>
lea    0xe6a(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11aa <next_token+0x4a>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
add    $0xfffffff7,%eax
sub    $0x2,%eax
jb     122f <next_token+0xcf>
jmp    11d2 <next_token+0x72>
mov    -0x20(%rbp),%eax
sub    $0x20,%eax
je     122f <next_token+0xcf>
jmp    11e3 <next_token+0x83>
mov    -0x20(%rbp),%eax
sub    $0x80,%eax
jne    1257 <next_token+0xf7>
jmp    11f6 <next_token+0x96>
cmpl   $0x0,-0x10(%rbp)
je     1211 <next_token+0xb1>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1222 <next_token+0xc2>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12c1 <next_token+0x161>
cmpl   $0x0,-0x10(%rbp)
je     1252 <next_token+0xf2>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12c1 <next_token+0x161>
jmp    1271 <next_token+0x111>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    12bc <next_token+0x15c>
mov    -0xc(%rbp),%eax
add    $0x40,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12b7 <next_token+0x157>
lea    0xd58(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    12bc <next_token+0x15c>
jmp    11aa <next_token+0x4a>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_token>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x40,%r13d
mov    $0x40,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     121e <next_token+0xbe>
mov    %rax,%r14
xor    %ebp,%ebp
mov    0x2e58(%rip),%r12
movabs $0x100000600,%r15
jmp    11ad <next_token+0x4d>
nopl   0x0(%rax)
xor    %ebx,%ebx
test   %ebp,%ebp
jne    11f7 <next_token+0x97>
mov    %ebx,%ebp
cmp    %r13d,%ebx
jg     11d8 <next_token+0x78>
mov    (%r12),%edi
call   1040 <fgetc@plt>
cmp    $0x20,%eax
ja     11c3 <next_token+0x63>
mov    %eax,%ecx
bt     %rcx,%r15
jb     11a0 <next_token+0x40>
cmp    $0x80,%eax
je     11f3 <next_token+0x93>
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %al,(%r14,%rcx,1)
mov    %ebp,%ebx
jmp    11a6 <next_token+0x46>
add    $0x40,%r13d
mov    %r14,%rdi
mov    %r13d,%esi
call   1060 <realloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     121e <next_token+0xbe>
mov    %ebx,%ebp
jmp    11ad <next_token+0x4d>
test   %ebp,%ebp
je     1211 <next_token+0xb1>
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
jmp    11ff <next_token+0x9f>
lea    0xddb(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
@stdin = global i32 0
define i8* @next_token() {
%1 = tail call dereferenceable_or_null(64) i8* @malloc(i32 64)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %34
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %34, %27
%7 = phi i32 [ %28, %27 ], [ %36, %34 ]
%8 = load i32, i32* @stdin
%9 = tail call i32 @fgetc(i32 %8)
switch i32 %9, label %22 [
i32 128, label %10
i32 32, label %17
i32 9, label %17
i32 10, label %17
]
10: ; preds = %6
%11 = icmp eq i32 %7, 0
br i1 %11, label %15, label %12
12: ; preds = %10
%13 = sext i32 %7 to i64
%14 = getelementptr inbounds i8, i8* %37, i64 %13
store i8 0, i8* %14
br label %41
15: ; preds = %10
%16 = tail call i32 @free(i8* %37)
br label %41
17: ; preds = %6, %6, %6
%18 = icmp eq i32 %7, 0
br i1 %18, label %27, label %19
19: ; preds = %17
%20 = sext i32 %7 to i64
%21 = getelementptr inbounds i8, i8* %37, i64 %20
store i8 0, i8* %21
br label %41
22: ; preds = %6
%23 = trunc i32 %9 to i8
%24 = add nsw i32 %7, 1
%25 = sext i32 %7 to i64
%26 = getelementptr inbounds i8, i8* %37, i64 %25
store i8 %23, i8* %26
br label %27
27: ; preds = %17, %22
%28 = phi i32 [ %24, %22 ], [ 0, %17 ]
%29 = icmp sgt i32 %28, %35
br i1 %29, label %30, label %6
30: ; preds = %27
%31 = add nuw nsw i32 %35, 64
%32 = tail call i8* @realloc(i8* %37, i32 %31)
%33 = icmp eq i8* %32, null
br i1 %33, label %38, label %34
34: ; preds = %0, %30
%35 = phi i32 [ %31, %30 ], [ 64, %0 ]
%36 = phi i32 [ %28, %30 ], [ 0, %0 ]
%37 = phi i8* [ %32, %30 ], [ %1, %0 ]
br label %6
38: ; preds = %30
%39 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%40 = tail call i32 @exit(i32 1)
unreachable
41: ; preds = %19, %15, %12
%42 = phi i8* [ null, %15 ], [ %37, %12 ], [ %37, %19 ]
ret i8* %42
}