#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__ isspace(int);
char *getword(FILE *fp) {
  static char word[1024 + 1];
  char *p = word;
  int c;
  while ((c = fgetc(fp)) != EOF && isspace(c))
    ;
  if (c == EOF)
    return (NULL);
  *p++ = c;
  while ((c = fgetc(fp)) != EOF && !isspace(c) && p != &(word[1024])) {
    *p++ = c;
  }
  *p = '\0';
  return ((c == EOF) ? NULL : word);
}


x86 assembly (clang, -O0):
<getword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0x2f0d(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
mov    0x2e9a(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x1d(%rbp)
je     116b <getword+0x4b>
mov    -0x1c(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    117b <getword+0x5b>
jmp    1180 <getword+0x60>
jmp    1137 <getword+0x17>
mov    -0x1c(%rbp),%eax
mov    0x2e5e(%rip),%rcx
cmp    (%rcx),%eax
jne    119f <getword+0x7f>
movq   $0x0,-0x8(%rbp)
jmp    1259 <getword+0x139>
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
mov    0x2e1c(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x1e(%rbp)
je     1208 <getword+0xe8>
mov    -0x1c(%rbp),%edi
call   1040 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1e(%rbp)
jne    1208 <getword+0xe8>
lea    0x2e48(%rip),%rax
add    $0x400,%rax
cmp    %rax,-0x18(%rbp)
setne  %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    1218 <getword+0xf8>
jmp    1233 <getword+0x113>
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    11b5 <getword+0x95>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1c(%rbp),%edx
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
lea    0x2df3(%rip),%rax
xor    %ecx,%ecx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getword>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eb3(%rip),%r15
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
cmp    (%r15),%eax
je     11e8 <getword+0xc8>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    1140 <getword+0x20>
cmp    (%r15),%ebp
jne    116c <getword+0x4c>
xor    %r14d,%r14d
jmp    11e8 <getword+0xc8>
mov    %bpl,0x2ecd(%rip)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r13d
cmp    (%r15),%eax
jne    118c <getword+0x6c>
lea    0x2eb7(%rip),%r12
jmp    11d2 <getword+0xb2>
mov    $0x1,%ebp
lea    0x2ea8(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r13d,%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    11cf <getword+0xaf>
cmp    $0x400,%rbp
je     11cf <getword+0xaf>
mov    %r13b,0x0(%rbp,%r12,1)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r13d
add    $0x1,%rbp
cmp    (%r15),%eax
jne    11a0 <getword+0x80>
add    %rbp,%r12
xor    %r14d,%r14d
cmp    (%r15),%r13d
movb   $0x0,(%r12)
lea    0x2e5c(%rip),%rax
cmovne %rax,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@getword.word = internal global [1025 x i8] zeroinitializer
@EOF = global i32 0
define i8* @getword(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
store i32* %0, i32** %3
store i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @getword.word, i64 0, i64 0), i8** %4
br label %6
6: ; preds = %17, %1
%7 = load i32*, i32** %3
%8 = call i32 @fgetc(i32* %7)
store i32 %8, i32* %5
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = load i32, i32* %5
%13 = call i64 @isspace(i32 %12)
%14 = icmp ne i64 %13, 0
br label %15
15: ; preds = %11, %6
%16 = phi i1 [ false, %6 ], [ %14, %11 ]
br i1 %16, label %17, label %18
17: ; preds = %15
br label %6
18: ; preds = %15
%19 = load i32, i32* %5
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %18
store i8* null, i8** %2
br label %54
23: ; preds = %18
%24 = load i32, i32* %5
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
store i8 %25, i8* %26
br label %28
28: ; preds = %42, %23
%29 = load i32*, i32** %3
%30 = call i32 @fgetc(i32* %29)
store i32 %30, i32* %5
%31 = load i32, i32* @EOF
%32 = icmp ne i32 %30, %31
br i1 %32, label %33, label %40
33: ; preds = %28
%34 = load i32, i32* %5
%35 = call i64 @isspace(i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %33
%38 = load i8*, i8** %4
%39 = icmp ne i8* %38, getelementptr inbounds ([1025 x i8], [1025 x i8]* @getword.word, i64 0, i64 1024)
br label %40
40: ; preds = %37, %33, %28
%41 = phi i1 [ false, %33 ], [ false, %28 ], [ %39, %37 ]
br i1 %41, label %42, label %47
42: ; preds = %40
%43 = load i32, i32* %5
%44 = trunc i32 %43 to i8
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %4
store i8 %44, i8* %45
br label %28
47: ; preds = %40
%48 = load i8*, i8** %4
store i8 0, i8* %48
%49 = load i32, i32* %5
%50 = load i32, i32* @EOF
%51 = icmp eq i32 %49, %50
%52 = zext i1 %51 to i64
%53 = select i1 %51, i8* null, i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @getword.word, i64 0, i64 0)
store i8* %53, i8** %2
br label %54
54: ; preds = %47, %22
%55 = load i8*, i8** %2
ret i8* %55
}

LLVM IR (-O2):
@getword.word = internal global [1025 x i8] zeroinitializer
@EOF = global i32 0
define i8* @getword(i32* nocapture %0) {
br label %2
2: ; preds = %6, %1
%3 = tail call i32 @fgetc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %36, label %6
6: ; preds = %2
%7 = tail call i64 @isspace(i32 %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %2
9: ; preds = %6
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %3, %10
br i1 %11, label %36, label %12
12: ; preds = %9
%13 = trunc i32 %3 to i8
store i8 %13, i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @getword.word, i64 0, i64 0)
%14 = tail call i32 @fgetc(i32* %0)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %30, label %17
17: ; preds = %12, %24
%18 = phi i32 [ %27, %24 ], [ %14, %12 ]
%19 = phi i8* [ %26, %24 ], [ getelementptr inbounds ([1025 x i8], [1025 x i8]* @getword.word, i64 0, i64 1), %12 ]
%20 = tail call i64 @isspace(i32 %18)
%21 = icmp eq i64 %20, 0
%22 = icmp ne i8* %19, getelementptr inbounds ([1025 x i8], [1025 x i8]* @getword.word, i64 0, i64 1024)
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = trunc i32 %18 to i8
%26 = getelementptr inbounds i8, i8* %19, i64 1
store i8 %25, i8* %19
%27 = tail call i32 @fgetc(i32* %0)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %17
30: ; preds = %17, %24, %12
%31 = phi i8* [ getelementptr inbounds ([1025 x i8], [1025 x i8]* @getword.word, i64 0, i64 1), %12 ], [ %26, %24 ], [ %19, %17 ]
%32 = phi i32 [ %14, %12 ], [ %27, %24 ], [ %18, %17 ]
store i8 0, i8* %31
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
%35 = select i1 %34, i8* null, i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @getword.word, i64 0, i64 0)
br label %36
36: ; preds = %2, %9, %30
%37 = phi i8* [ %35, %30 ], [ null, %9 ], [ null, %2 ]
ret i8* %37
}