#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 append_char(char **, char, int, int);
int /*<<< orphan*/ free(char *);
char getc(int /*<<< orphan*/ *);
char *malloc(int);
char *get_next_token(FILE *filedesc, char *endsymb) {
  int current_size = sizeof(char) * 8;
  char *token = malloc(current_size);
  int tokenpos = 0;
  char c = 0;
  while ((c = getc(filedesc)) != EOF) {
    switch (c) {
    case 0:
    case '\n':
    case ' ':
    case ',':
    case '.':
    case '!':
    case '?':
    case ':':
    case ';':
    case '-':
    case '(':
    case ')':
    case '"':
      if (tokenpos) {
        append_char(&token, 0, tokenpos, current_size);
        *endsymb = c;
        return token;
      }
      free(token);
      *endsymb = 0;
      return 0;
      break;
    default:
      current_size = append_char(&token, c, tokenpos, current_size);
      tokenpos++;
    }
  }
  *endsymb = EOF;
  if (tokenpos == 0) {
    free(token);
    return 0;
  }
  return token;
}


x86 assembly (clang, -O0):
<get_next_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x8,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movb   $0x0,-0x2d(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
mov    %al,-0x2d(%rbp)
movsbl %al,%eax
mov    0x2e64(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1289 <get_next_token+0x149>
movsbl -0x2d(%rbp),%eax
mov    %eax,-0x34(%rbp)
test   %eax,%eax
je     1215 <get_next_token+0xd5>
jmp    11a3 <get_next_token+0x63>
mov    -0x34(%rbp),%eax
sub    $0xa,%eax
je     1215 <get_next_token+0xd5>
jmp    11b4 <get_next_token+0x74>
mov    -0x34(%rbp),%eax
add    $0xffffffe0,%eax
sub    $0x3,%eax
jb     1215 <get_next_token+0xd5>
jmp    11c8 <get_next_token+0x88>
mov    -0x34(%rbp),%eax
add    $0xffffffd8,%eax
sub    $0x2,%eax
jb     1215 <get_next_token+0xd5>
jmp    11dc <get_next_token+0x9c>
mov    -0x34(%rbp),%eax
add    $0xffffffd4,%eax
sub    $0x3,%eax
jb     1215 <get_next_token+0xd5>
jmp    11f0 <get_next_token+0xb0>
mov    -0x34(%rbp),%eax
add    $0xffffffc6,%eax
sub    $0x2,%eax
jb     1215 <get_next_token+0xd5>
jmp    1204 <get_next_token+0xc4>
mov    -0x34(%rbp),%eax
sub    $0x3f,%eax
jne    1263 <get_next_token+0x123>
jmp    1215 <get_next_token+0xd5>
cmpl   $0x0,-0x2c(%rbp)
je     1246 <get_next_token+0x106>
mov    -0x2c(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1040 <append_char@plt>
mov    -0x2d(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12c0 <get_next_token+0x180>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    12c0 <get_next_token+0x180>
mov    -0x2d(%rbp),%al
mov    -0x2c(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    -0x28(%rbp),%rdi
movsbl %al,%esi
call   1040 <append_char@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    116e <get_next_token+0x2e>
mov    0x2d58(%rip),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
cmpl   $0x0,-0x2c(%rbp)
jne    12b8 <get_next_token+0x178>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12c0 <get_next_token+0x180>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_token>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
mov    $0x8,%ebp
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    %r15,%rdi
call   1060 <getc@plt>
mov    %eax,%r13d
mov    0x2e6e(%rip),%r14
mov    (%r14),%cl
cmp    %cl,%al
jne    1193 <get_next_token+0x53>
mov    %r13b,(%rbx)
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    1221 <get_next_token+0xe1>
mov    %cl,0x7(%rsp)
mov    %rbx,0x10(%rsp)
xor    %ebx,%ebx
mov    %r13d,%r12d
jmp    11d3 <get_next_token+0x93>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x8(%rsp),%rdi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1040 <append_char@plt>
mov    %eax,%ebp
add    $0x1,%ebx
mov    %r15,%rdi
call   1060 <getc@plt>
mov    %eax,%r12d
cmp    (%r14),%al
je     1232 <get_next_token+0xf2>
movsbl %r12b,%esi
cmp    $0x3f,%esi
ja     11b0 <get_next_token+0x70>
movabs $0x8c00730700000401,%rcx
bt     %rsi,%rcx
jae    11b0 <get_next_token+0x70>
test   %ebx,%ebx
je     120f <get_next_token+0xcf>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1040 <append_char@plt>
mov    0x10(%rsp),%rax
mov    %r12b,(%rax)
mov    0x8(%rsp),%rax
jmp    1223 <get_next_token+0xe3>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rax
movb   $0x0,(%rax)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rsp),%rax
mov    %r12b,(%rax)
cmp    0x7(%rsp),%r13b
je     1184 <get_next_token+0x44>
jmp    1208 <get_next_token+0xc8>

LLVM IR (-O0):
@EOF = global i8 0
define i8* @get_next_token(i32* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 8, i32* %6
%10 = load i32, i32* %6
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %7
store i32 0, i32* %8
store i8 0, i8* %9
br label %12
12: ; preds = %43, %2
%13 = load i32*, i32** %4
%14 = call signext i8 @getc(i32* %13)
store i8 %14, i8* %9
%15 = sext i8 %14 to i32
%16 = load i8, i8* @EOF
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %15, %17
br i1 %18, label %19, label %44
19: ; preds = %12
%20 = load i8, i8* %9
%21 = sext i8 %20 to i32
switch i32 %21, label %36 [
i32 0, label %22
i32 10, label %22
i32 32, label %22
i32 44, label %22
i32 46, label %22
i32 33, label %22
i32 63, label %22
i32 58, label %22
i32 59, label %22
i32 45, label %22
i32 40, label %22
i32 41, label %22
i32 34, label %22
]
22: ; preds = %19, %19, %19, %19, %19, %19, %19, %19, %19, %19, %19, %19, %19
%23 = load i32, i32* %8
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i32, i32* %8
%27 = load i32, i32* %6
%28 = call i32 @append_char(i8** %7, i8 signext 0, i32 %26, i32 %27)
%29 = load i8, i8* %9
%30 = load i8*, i8** %5
store i8 %29, i8* %30
%31 = load i8*, i8** %7
store i8* %31, i8** %3
br label %54
32: ; preds = %22
%33 = load i8*, i8** %7
%34 = call i32 @free(i8* %33)
%35 = load i8*, i8** %5
store i8 0, i8* %35
store i8* null, i8** %3
br label %54
36: ; preds = %19
%37 = load i8, i8* %9
%38 = load i32, i32* %8
%39 = load i32, i32* %6
%40 = call i32 @append_char(i8** %7, i8 signext %37, i32 %38, i32 %39)
store i32 %40, i32* %6
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %43
43: ; preds = %36
br label %12
44: ; preds = %12
%45 = load i8, i8* @EOF
%46 = load i8*, i8** %5
store i8 %45, i8* %46
%47 = load i32, i32* %8
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = load i8*, i8** %7
%51 = call i32 @free(i8* %50)
store i8* null, i8** %3
br label %54
52: ; preds = %44
%53 = load i8*, i8** %7
store i8* %53, i8** %3
br label %54
54: ; preds = %52, %49, %32, %25
%55 = load i8*, i8** %3
ret i8* %55
}

LLVM IR (-O2):
@EOF = global i8 0
define i8* @get_next_token(i32* nocapture %0, i8* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
store i8* %5, i8** %3
%6 = call signext i8 @getc(i32* %0)
%7 = load i8, i8* @EOF
%8 = icmp eq i8 %6, %7
br i1 %8, label %9, label %10
9: ; preds = %2
store i8 %6, i8* %1
br label %30
10: ; preds = %2, %23
%11 = phi i8 [ %26, %23 ], [ %6, %2 ]
%12 = phi i32 [ %25, %23 ], [ 0, %2 ]
%13 = phi i32 [ %24, %23 ], [ 8, %2 ]
%14 = sext i8 %11 to i32
switch i32 %14, label %23 [
i32 0, label %15
i32 10, label %15
i32 32, label %15
i32 44, label %15
i32 46, label %15
i32 33, label %15
i32 63, label %15
i32 58, label %15
i32 59, label %15
i32 45, label %15
i32 40, label %15
i32 41, label %15
i32 34, label %15
]
15: ; preds = %10, %10, %10, %10, %10, %10, %10, %10, %10, %10, %10, %10, %10
%16 = icmp eq i32 %12, 0
br i1 %16, label %20, label %17
17: ; preds = %15
%18 = call i32 @append_char(i8** %3, i8 signext 0, i32 %12, i32 %13)
store i8 %11, i8* %1
%19 = load i8*, i8** %3
br label %35
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = call i32 @free(i8* %21)
store i8 0, i8* %1
br label %35
23: ; preds = %10
%24 = call i32 @append_char(i8** %3, i8 signext %11, i32 %12, i32 %13)
%25 = add nuw nsw i32 %12, 1
%26 = call signext i8 @getc(i32* %0)
%27 = load i8, i8* @EOF
%28 = icmp eq i8 %26, %27
br i1 %28, label %29, label %10
29: ; preds = %23
store i8 %26, i8* %1
br i1 %8, label %30, label %33
30: ; preds = %9, %29
%31 = load i8*, i8** %3
%32 = call i32 @free(i8* %31)
br label %35
33: ; preds = %29
%34 = load i8*, i8** %3
br label %35
35: ; preds = %33, %30, %20, %17
%36 = phi i8* [ %19, %17 ], [ null, %20 ], [ null, %30 ], [ %34, %33 ]
ret i8* %36
}