#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 /*<<< orphan*/ assert(int /*<<< orphan*/);
char fgetc(int /*<<< orphan*/ *);
scalar_t__ isalnum(char);
scalar_t__ isalpha(char);
scalar_t__ isspace(char);
char *strdup(char *);
char tolower(char);
char *getNextWord(FILE *fd) {
  char ch;
  char wordBuffer[256];
  int putChar = 0;
  assert(fd != NULL);
  while ((ch = fgetc(fd)) != EOF) {
    if (isalpha(ch))
      break;
  }
  if (ch == EOF)
    return NULL;
  wordBuffer[putChar++] = tolower(ch);
  while ((ch = fgetc(fd)) != EOF) {
    if (isspace(ch) || putChar >= 256 - 1)
      break;
    if (isalnum(ch)) {
      wordBuffer[putChar++] = tolower(ch);
    }
  }
  wordBuffer[putChar] = '\0';
  return strdup(wordBuffer);
}


x86 assembly (clang, -O0):
<getNextWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x124(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e37(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11d9 <getNextWord+0x69>
movsbl -0x11(%rbp),%edi
call   1080 <isalpha@plt>
cmp    $0x0,%rax
je     11d4 <getNextWord+0x64>
jmp    11d9 <getNextWord+0x69>
jmp    119b <getNextWord+0x2b>
movsbl -0x11(%rbp),%eax
mov    0x2e04(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11fc <getNextWord+0x8c>
movq   $0x0,-0x8(%rbp)
jmp    12c6 <getNextWord+0x156>
movsbl -0x11(%rbp),%edi
call   1070 <tolower@plt>
mov    %al,%cl
mov    -0x124(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x124(%rbp)
cltq
mov    %cl,-0x120(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2db1(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12a7 <getNextWord+0x137>
movsbl -0x11(%rbp),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
jne    1265 <getNextWord+0xf5>
cmpl   $0xff,-0x124(%rbp)
jl     126a <getNextWord+0xfa>
jmp    12a7 <getNextWord+0x137>
movsbl -0x11(%rbp),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
je     12a2 <getNextWord+0x132>
movsbl -0x11(%rbp),%edi
call   1070 <tolower@plt>
mov    %al,%cl
mov    -0x124(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x124(%rbp)
cltq
mov    %cl,-0x120(%rbp,%rax,1)
jmp    1221 <getNextWord+0xb1>
movslq -0x124(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNextWord>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1060 <assert@plt>
mov    0x2e51(%rip),%r12
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <fgetc@plt>
cmp    (%r12),%al
je     11f9 <getNextWord+0x89>
mov    %eax,%ebx
movsbl %al,%ebp
mov    %ebp,%edi
call   1080 <isalpha@plt>
test   %rax,%rax
je     11a0 <getNextWord+0x30>
cmp    (%r12),%bl
jne    11ca <getNextWord+0x5a>
xor    %r14d,%r14d
jmp    11f9 <getNextWord+0x89>
mov    %ebp,%edi
call   1070 <tolower@plt>
mov    %al,(%rsp)
mov    %r15,%rdi
call   1040 <fgetc@plt>
mov    $0x1,%ebx
cmp    (%r12),%al
jne    120c <getNextWord+0x9c>
movslq %ebx,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1090 <strdup@plt>
mov    %rax,%r14
mov    %r14,%rax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebx
jmp    122e <getNextWord+0xbe>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1040 <fgetc@plt>
cmp    (%r12),%al
je     11e7 <getNextWord+0x77>
movsbl %al,%ebp
mov    %ebp,%edi
call   1050 <isspace@plt>
test   %rax,%rax
jne    11e7 <getNextWord+0x77>
cmp    $0xfe,%ebx
jg     11e7 <getNextWord+0x77>
mov    %ebp,%edi
call   1030 <isalnum@plt>
test   %rax,%rax
je     1220 <getNextWord+0xb0>
mov    %ebp,%edi
call   1070 <tolower@plt>
movslq %ebx,%rcx
add    $0x1,%ebx
mov    %al,(%rsp,%rcx,1)
jmp    1220 <getNextWord+0xb0>

LLVM IR (-O0):
@EOF = global i8 0
define i8* @getNextWord(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8
%5 = alloca [256 x i8]
%6 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %6
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
br label %11
11: ; preds = %23, %1
%12 = load i32*, i32** %3
%13 = call signext i8 @fgetc(i32* %12)
store i8 %13, i8* %4
%14 = sext i8 %13 to i32
%15 = load i8, i8* @EOF
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %14, %16
br i1 %17, label %18, label %24
18: ; preds = %11
%19 = load i8, i8* %4
%20 = call i64 @isalpha(i8 signext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
br label %24
23: ; preds = %18
br label %11
24: ; preds = %22, %11
%25 = load i8, i8* %4
%26 = sext i8 %25 to i32
%27 = load i8, i8* @EOF
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %26, %28
br i1 %29, label %30, label %31
30: ; preds = %24
store i8* null, i8** %2
br label %71
31: ; preds = %24
%32 = load i8, i8* %4
%33 = call signext i8 @tolower(i8 signext %32)
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %36
store i8 %33, i8* %37
br label %38
38: ; preds = %64, %31
%39 = load i32*, i32** %3
%40 = call signext i8 @fgetc(i32* %39)
store i8 %40, i8* %4
%41 = sext i8 %40 to i32
%42 = load i8, i8* @EOF
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %41, %43
br i1 %44, label %45, label %65
45: ; preds = %38
%46 = load i8, i8* %4
%47 = call i64 @isspace(i8 signext %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %52, label %49
49: ; preds = %45
%50 = load i32, i32* %6
%51 = icmp sge i32 %50, 255
br i1 %51, label %52, label %53
52: ; preds = %49, %45
br label %65
53: ; preds = %49
%54 = load i8, i8* %4
%55 = call i64 @isalnum(i8 signext %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %64
57: ; preds = %53
%58 = load i8, i8* %4
%59 = call signext i8 @tolower(i8 signext %58)
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 1
store i32 %61, i32* %6
%62 = sext i32 %60 to i64
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %62
store i8 %59, i8* %63
br label %64
64: ; preds = %57, %53
br label %38
65: ; preds = %52, %38
%66 = load i32, i32* %6
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %67
store i8 0, i8* %68
%69 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%70 = call i8* @strdup(i8* %69)
store i8* %70, i8** %2
br label %71
71: ; preds = %65, %30
%72 = load i8*, i8** %2
ret i8* %72
}

LLVM IR (-O2):
@EOF = global i8 0
define noalias i8* @getNextWord(i32* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = icmp ne i32* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
br label %7
7: ; preds = %11, %1
%8 = tail call signext i8 @fgetc(i32* %0)
%9 = load i8, i8* @EOF
%10 = icmp eq i8 %8, %9
br i1 %10, label %47, label %11
11: ; preds = %7
%12 = tail call i64 @isalpha(i8 signext %8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %7, label %14
14: ; preds = %11
%15 = load i8, i8* @EOF
%16 = icmp eq i8 %8, %15
br i1 %16, label %47, label %17
17: ; preds = %14
%18 = tail call signext i8 @tolower(i8 signext %8)
store i8 %18, i8* %3
%19 = tail call signext i8 @fgetc(i32* %0)
%20 = load i8, i8* @EOF
%21 = icmp eq i8 %19, %20
br i1 %21, label %42, label %22
22: ; preds = %17, %37
%23 = phi i8 [ %39, %37 ], [ %19, %17 ]
%24 = phi i32 [ %38, %37 ], [ 1, %17 ]
%25 = tail call i64 @isspace(i8 signext %23)
%26 = icmp ne i64 %25, 0
%27 = icmp sgt i32 %24, 254
%28 = select i1 %26, i1 true, i1 %27
br i1 %28, label %42, label %29
29: ; preds = %22
%30 = tail call i64 @isalnum(i8 signext %23)
%31 = icmp eq i64 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %29
%33 = tail call signext i8 @tolower(i8 signext %23)
%34 = add nsw i32 %24, 1
%35 = sext i32 %24 to i64
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %35
store i8 %33, i8* %36
br label %37
37: ; preds = %32, %29
%38 = phi i32 [ %34, %32 ], [ %24, %29 ]
%39 = tail call signext i8 @fgetc(i32* %0)
%40 = load i8, i8* @EOF
%41 = icmp eq i8 %39, %40
br i1 %41, label %42, label %22
42: ; preds = %37, %22, %17
%43 = phi i32 [ 1, %17 ], [ %24, %22 ], [ %38, %37 ]
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %44
store i8 0, i8* %45
%46 = call i8* @strdup(i8* %3)
br label %47
47: ; preds = %7, %14, %42
%48 = phi i8* [ %46, %42 ], [ null, %14 ], [ null, %7 ]
ret i8* %48
}