#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*/ clearerr(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ isalpha(int);
int read_word(FILE *fp, char *buff, int size) {
  int n, c;
  clearerr(fp);
  for (n = 0; n < size - 1; ++n) {
    c = fgetc(fp);
    if (!isalpha(c))
      break;
    buff[n] = c;
  }
  if (ferror(fp) || feof(fp))
    return -1;
  buff[n] = '\0';
  return n;
}


x86 assembly (clang, -O0):
<read_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <clearerr@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11c4 <read_word+0x74>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1070 <isalpha@plt>
cmp    $0x0,%eax
jne    11a6 <read_word+0x56>
jmp    11c4 <read_word+0x74>
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1173 <read_word+0x23>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
jne    11ea <read_word+0x9a>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     11f6 <read_word+0xa6>
movl   $0xffffffff,-0x4(%rbp)
jmp    1208 <read_word+0xb8>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_word>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
call   1060 <clearerr@plt>
xor    %ebx,%ebx
cmp    $0x2,%r15d
jl     11a5 <read_word+0x55>
add    $0xffffffff,%r15d
mov    %r15d,%r13d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1070 <isalpha@plt>
test   %eax,%eax
je     11a5 <read_word+0x55>
mov    %bpl,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1180 <read_word+0x30>
mov    %r15d,%ebx
mov    %r12,%rdi
call   1030 <ferror@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    11cd <read_word+0x7d>
mov    %r12,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    11cd <read_word+0x7d>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_word(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i32*, i32** %5
%11 = call i32 @clearerr(i32* %10)
store i32 0, i32* %8
br label %12
12: ; preds = %31, %3
%13 = load i32, i32* %8
%14 = load i32, i32* %7
%15 = sub nsw i32 %14, 1
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %34
17: ; preds = %12
%18 = load i32*, i32** %5
%19 = call i32 @fgetc(i32* %18)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = call i32 @isalpha(i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %17
br label %34
24: ; preds = %17
%25 = load i32, i32* %9
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %6
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 %26, i8* %30
br label %31
31: ; preds = %24
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %12
34: ; preds = %23, %12
%35 = load i32*, i32** %5
%36 = call i64 @ferror(i32* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %34
%39 = load i32*, i32** %5
%40 = call i64 @feof(i32* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %38, %34
store i32 -1, i32* %4
br label %49
43: ; preds = %38
%44 = load i8*, i8** %6
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 0, i8* %47
%48 = load i32, i32* %8
store i32 %48, i32* %4
br label %49
49: ; preds = %43, %42
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
define i32 @read_word(i32* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = tail call i32 @clearerr(i32* %0)
%5 = add i32 %2, -1
%6 = icmp sgt i32 %2, 1
br i1 %6, label %7, label %21
7: ; preds = %3
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %14
%10 = phi i64 [ 0, %7 ], [ %17, %14 ]
%11 = tail call i32 @fgetc(i32* %0)
%12 = tail call i32 @isalpha(i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = trunc i32 %11 to i8
%16 = getelementptr inbounds i8, i8* %1, i64 %10
store i8 %15, i8* %16
%17 = add nuw nsw i64 %10, 1
%18 = icmp eq i64 %17, %8
br i1 %18, label %21, label %9
19: ; preds = %9
%20 = trunc i64 %10 to i32
br label %21
21: ; preds = %14, %19, %3
%22 = phi i32 [ 0, %3 ], [ %20, %19 ], [ %5, %14 ]
%23 = tail call i64 @ferror(i32* %0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = tail call i64 @feof(i32* %0)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = zext i32 %22 to i64
%30 = getelementptr inbounds i8, i8* %1, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %21, %25, %28
%32 = phi i32 [ %22, %28 ], [ -1, %25 ], [ -1, %21 ]
ret i32 %32
}