#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;
int fgetc(int /*<<< orphan*/ *);
scalar_t__ isalnum(int);
scalar_t__ isspace(int);
scalar_t__ strdup(char *);
int tolower(int);
char *getNextWord(FILE *fd) {
  int index = 0;
  int charValue;
  char word[256];
  while ((charValue = fgetc(fd)) != EOF) {
    if (isspace(charValue)) {
      word[index] = '\0';
      return (char *)strdup(word);
    } else if (((index + 1) != (256 - 1)) && (isalnum(charValue))) {
      charValue = tolower(charValue);
      word[index] = charValue;
    } else {
      word[index] = '\0';
      return (char *)strdup(word);
    }
    index++;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<getNextWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e6f(%rip),%rcx
cmp    (%rcx),%eax
je     122b <getNextWord+0xdb>
mov    -0x18(%rbp),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     11b4 <getNextWord+0x64>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1233 <getNextWord+0xe3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cmp    $0xff,%eax
je     11f7 <getNextWord+0xa7>
mov    -0x18(%rbp),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
je     11f7 <getNextWord+0xa7>
mov    -0x18(%rbp),%edi
call   1060 <tolower@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0x120(%rbp,%rax,1)
jmp    1218 <getNextWord+0xc8>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1233 <getNextWord+0xe3>
jmp    121d <getNextWord+0xcd>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1166 <getNextWord+0x16>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNextWord>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%r12
call   1040 <fgetc@plt>
mov    0x2e7a(%rip),%r15
cmp    (%r15),%eax
jne    1178 <getNextWord+0x28>
xor    %r14d,%r14d
jmp    11cf <getNextWord+0x7f>
mov    %eax,%ebp
xor    %r14d,%r14d
xor    %ebx,%ebx
nop
mov    %ebp,%edi
call   1050 <isspace@plt>
test   %rax,%rax
jne    11c0 <getNextWord+0x70>
cmp    $0xfe,%rbx
je     11c0 <getNextWord+0x70>
mov    %ebp,%edi
call   1030 <isalnum@plt>
test   %rax,%rax
je     11c0 <getNextWord+0x70>
mov    %ebp,%edi
call   1060 <tolower@plt>
mov    %al,(%rsp,%rbx,1)
mov    %r12,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
add    $0x1,%rbx
cmp    (%r15),%eax
jne    1180 <getNextWord+0x30>
jmp    11cf <getNextWord+0x7f>
movb   $0x0,(%rsp,%rbx,1)
mov    %rsp,%rdi
call   1070 <strdup@plt>
mov    %rax,%r14
mov    %r14,%rax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i8* @getNextWord(i32* nocapture %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @fgetc(i32* %0)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %30, label %7
7: ; preds = %1, %18
%8 = phi i64 [ %13, %18 ], [ 0, %1 ]
%9 = phi i32 [ %22, %18 ], [ %4, %1 ]
%10 = tail call i64 @isspace(i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %7
%13 = add nuw nsw i64 %8, 1
%14 = icmp eq i64 %13, 255
br i1 %14, label %25, label %15
15: ; preds = %12
%16 = tail call i64 @isalnum(i32 %9)
%17 = icmp eq i64 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = tail call i32 @tolower(i32 %9)
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %8
store i8 %20, i8* %21
%22 = tail call i32 @fgetc(i32* %0)
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %30, label %7
25: ; preds = %12, %15, %7
%26 = and i64 %8, 4294967295
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %26
store i8 0, i8* %27
%28 = call i64 @strdup(i8* %3)
%29 = inttoptr i64 %28 to i8*
br label %30
30: ; preds = %18, %25, %1
%31 = phi i8* [ null, %1 ], [ %29, %25 ], [ null, %18 ]
ret i8* %31
}