#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;
char *allocateMsg(int, char *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ isspace(int);
char *reallocateMsg(char *, int, char *);
int /*<<< orphan*/ skipWhiteSpace(int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
char *readToken(FILE *fp) {
  int ch, index;
  char *buffer;
  int size = 80;
  skipWhiteSpace(fp);
  ch = fgetc(fp);
  if (ch == EOF)
    return 0;
  buffer = allocateMsg(size, "readToken");
  index = 0;
  while (!isspace(ch)) {
    if (ch == EOF)
      break;
    if (index > size - 2) {
      ++size;
      buffer = reallocateMsg(buffer, size, "readToken");
    }
    buffer[index] = ch;
    ++index;
    ch = fgetc(fp);
  }
  ungetc(ch, fp);
  buffer[index] = '\0';
  return buffer;
}


x86 assembly (clang, -O0):
<readToken>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x50,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <skipWhiteSpace@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%eax
jne    11a7 <readToken+0x47>
movq   $0x0,-0x8(%rbp)
jmp    1270 <readToken+0x110>
mov    -0x24(%rbp),%edi
lea    0xe4f(%rip),%rsi
call   1030 <allocateMsg@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <isspace@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11de <readToken+0x7e>
jmp    1250 <readToken+0xf0>
mov    -0x14(%rbp),%eax
mov    0x2e00(%rip),%rcx
cmp    (%rcx),%eax
jne    11f5 <readToken+0x95>
jmp    1250 <readToken+0xf0>
mov    -0x18(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jle    1226 <readToken+0xc6>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
lea    0xde3(%rip),%rdx
call   1080 <reallocateMsg@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
jmp    11c1 <readToken+0x61>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <ungetc@plt>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readToken>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <skipWhiteSpace@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    0x2e66(%rip),%r13
cmp    0x0(%r13),%eax
jne    1190 <readToken+0x30>
xor    %r15d,%r15d
jmp    1226 <readToken+0xc6>
mov    %eax,%ebp
lea    0xe67(%rip),%rsi
mov    $0x50,%edi
call   1030 <allocateMsg@plt>
mov    %rax,%r15
mov    %ebp,%edi
call   1060 <isspace@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    1217 <readToken+0xb7>
cmp    0x0(%r13),%ebp
je     1217 <readToken+0xb7>
mov    $0x50,%ebx
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%eax
cltq
cmp    %rax,%r12
jle    11f1 <readToken+0x91>
add    $0x1,%ebx
mov    %r15,%rdi
mov    %ebx,%esi
lea    0xe17(%rip),%rdx
call   1080 <reallocateMsg@plt>
mov    %rax,%r15
mov    %bpl,(%r15,%r12,1)
add    $0x1,%r12
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <isspace@plt>
test   %eax,%eax
jne    1214 <readToken+0xb4>
cmp    0x0(%r13),%ebp
jne    11d0 <readToken+0x70>
mov    %r12d,%ebx
mov    %ebp,%edi
mov    %r14,%rsi
call   1070 <ungetc@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
@.str = [10 x i8] c"readToken\00"
define i8* @readToken(i32* %0) {
%2 = tail call i32 @skipWhiteSpace(i32* %0)
%3 = tail call i32 @fgetc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %44, label %6
6: ; preds = %1
%7 = tail call i8* @allocateMsg(i32 80, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @isspace(i32 %3)
%9 = icmp ne i32 %8, 0
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %3, %10
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %38, label %13
13: ; preds = %6, %24
%14 = phi i64 [ %29, %24 ], [ 0, %6 ]
%15 = phi i32 [ %26, %24 ], [ 80, %6 ]
%16 = phi i8* [ %25, %24 ], [ %7, %6 ]
%17 = phi i32 [ %30, %24 ], [ %3, %6 ]
%18 = add nsw i32 %15, -2
%19 = sext i32 %18 to i64
%20 = icmp sgt i64 %14, %19
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = add nsw i32 %15, 1
%23 = tail call i8* @reallocateMsg(i8* %16, i32 %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %21, %13
%25 = phi i8* [ %23, %21 ], [ %16, %13 ]
%26 = phi i32 [ %22, %21 ], [ %15, %13 ]
%27 = trunc i32 %17 to i8
%28 = getelementptr inbounds i8, i8* %25, i64 %14
store i8 %27, i8* %28
%29 = add nuw i64 %14, 1
%30 = tail call i32 @fgetc(i32* %0)
%31 = tail call i32 @isspace(i32 %30)
%32 = icmp ne i32 %31, 0
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %30, %33
%35 = select i1 %32, i1 true, i1 %34
br i1 %35, label %36, label %13
36: ; preds = %24
%37 = and i64 %29, 4294967295
br label %38
38: ; preds = %36, %6
%39 = phi i32 [ %3, %6 ], [ %30, %36 ]
%40 = phi i64 [ 0, %6 ], [ %37, %36 ]
%41 = phi i8* [ %7, %6 ], [ %25, %36 ]
%42 = tail call i32 @ungetc(i32 %39, i32* %0)
%43 = getelementptr inbounds i8, i8* %41, i64 %40
store i8 0, i8* %43
br label %44
44: ; preds = %1, %38
%45 = phi i8* [ %41, %38 ], [ null, %1 ]
ret i8* %45
}