#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 /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int ReadWord(char *word, FILE *fin) {
  int a = 0, ch;
  while (!feof(fin)) {
    ch = fgetc(fin);
    if (ch == 13)
      continue;
    if ((ch == ' ') || (ch == '\t') || (ch == '\n')) {
      if (a > 0) {
        if (ch == '\n')
          ungetc(ch, fin);
        break;
      }
      if (ch == '\n') {
        strcpy(word, (char *)"
");
        return 4;
      } else
        continue;
    }
    word[a] = ch;
    a++;
    if (a >= 1000 - 1)
      a--;
  }
  word[a] = 0;
  return a;
}


x86 assembly (clang, -O0):
<ReadWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1175 <ReadWord+0x35>
jmp    1232 <ReadWord+0xf2>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xd,-0x20(%rbp)
jne    1190 <ReadWord+0x50>
jmp    1157 <ReadWord+0x17>
cmpl   $0x20,-0x20(%rbp)
je     11ae <ReadWord+0x6e>
cmpl   $0x9,-0x20(%rbp)
je     11ae <ReadWord+0x6e>
cmpl   $0xa,-0x20(%rbp)
jne    11fe <ReadWord+0xbe>
cmpl   $0x0,-0x1c(%rbp)
jle    11d3 <ReadWord+0x93>
cmpl   $0xa,-0x20(%rbp)
jne    11ce <ReadWord+0x8e>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <ungetc@plt>
jmp    1232 <ReadWord+0xf2>
cmpl   $0xa,-0x20(%rbp)
jne    11f9 <ReadWord+0xb9>
mov    -0x10(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x4,-0x4(%rbp)
jmp    1244 <ReadWord+0x104>
jmp    1157 <ReadWord+0x17>
mov    -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x3e7,-0x1c(%rbp)
jl     122d <ReadWord+0xed>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1157 <ReadWord+0x17>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadWord>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     1170 <ReadWord+0x30>
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
movabs $0x100000600,%r15
jmp    119c <ReadWord+0x5c>
mov    %ebp,%ecx
mov    %al,(%r14,%rcx,1)
cmp    $0x3e6,%ebp
adc    $0x0,%ebp
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    115b <ReadWord+0x1b>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    $0xd,%eax
je     1190 <ReadWord+0x50>
cmp    $0x20,%eax
ja     117e <ReadWord+0x3e>
mov    %eax,%ecx
bt     %rcx,%r15
jae    117e <ReadWord+0x3e>
test   %ebp,%ebp
jne    11d5 <ReadWord+0x95>
cmp    $0xa,%eax
jne    1190 <ReadWord+0x50>
lea    0xe3a(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    $0x4,%ebp
jmp    1163 <ReadWord+0x23>
cmp    $0xa,%eax
jne    115b <ReadWord+0x1b>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1060 <ungetc@plt>
jmp    115b <ReadWord+0x1b>

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

LLVM IR (-O2):
@.str = [5 x i8] c"
\00"
define i32 @ReadWord(i8* %0, i32* nocapture %1) {
%3 = tail call i32 @feof(i32* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %32
5: ; preds = %2, %23
%6 = phi i32 [ %29, %23 ], [ 0, %2 ]
%7 = icmp eq i32 %6, 0
br label %8
8: ; preds = %5, %11
%9 = tail call i32 @fgetc(i32* %1)
%10 = icmp eq i32 %9, 13
br i1 %10, label %11, label %14
11: ; preds = %8, %20
%12 = tail call i32 @feof(i32* %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %8, label %32
14: ; preds = %8
%15 = icmp eq i32 %9, 10
switch i32 %9, label %23 [
i32 32, label %16
i32 10, label %16
i32 9, label %16
]
16: ; preds = %14, %14, %14
br i1 %7, label %20, label %17
17: ; preds = %16
br i1 %15, label %18, label %32
18: ; preds = %17
%19 = tail call i32 @ungetc(i32 10, i32* %1)
br label %32
20: ; preds = %16
br i1 %15, label %21, label %11
21: ; preds = %20
%22 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %36
23: ; preds = %14
%24 = trunc i32 %9 to i8
%25 = zext i32 %6 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 %24, i8* %26
%27 = icmp ult i32 %6, 998
%28 = zext i1 %27 to i32
%29 = add nuw nsw i32 %6, %28
%30 = tail call i32 @feof(i32* %1)
%31 = icmp eq i32 %30, 0
br i1 %31, label %5, label %32
32: ; preds = %23, %11, %2, %17, %18
%33 = phi i32 [ %6, %17 ], [ %6, %18 ], [ 0, %2 ], [ %6, %11 ], [ %29, %23 ]
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %0, i64 %34
store i8 0, i8* %35
br label %36
36: ; preds = %32, %21
%37 = phi i32 [ %33, %32 ], [ 4, %21 ]
ret i32 %37
}