#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 getc(int /*<<< orphan*/ *);
scalar_t__ isalnumde(int);
int fgetword(FILE *fp, char *word, int count) {
  int c, i;
  char *w;
  w = word;
  i = 0;
  while (isalnumde(c = getc(fp))) {
    *w++ = c;
    ++i;
    if (count != 0 && i == count)
      break;
  }
  *w = '\0';
  return c;
}


x86 assembly (clang, -O0):
<fgetword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,%edi
mov    %edi,-0x18(%rbp)
call   1030 <isalnumde@plt>
cmp    $0x0,%rax
je     119e <fgetword+0x7e>
mov    -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1199 <fgetword+0x79>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1199 <fgetword+0x79>
jmp    119e <fgetword+0x7e>
jmp    1142 <fgetword+0x22>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgetword>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
lea    -0x1(%r14),%r12d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1040 <getc@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <isalnumde@plt>
test   %rax,%rax
je     1175 <fgetword+0x55>
lea    0x1(%rbx),%rax
sub    $0x1,%r12d
setb   %cl
mov    %bpl,(%rbx)
mov    %rax,%rbx
test   %r14d,%r14d
je     1140 <fgetword+0x20>
mov    %rax,%rbx
test   %cl,%cl
je     1140 <fgetword+0x20>
jmp    1178 <fgetword+0x58>
mov    %rbx,%rax
movb   $0x0,(%rax)
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fgetword(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
store i8* %10, i8** %9
store i32 0, i32* %8
br label %11
11: ; preds = %30, %3
%12 = load i32*, i32** %4
%13 = call i32 @getc(i32* %12)
store i32 %13, i32* %7
%14 = call i64 @isalnumde(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %31
16: ; preds = %11
%17 = load i32, i32* %7
%18 = trunc i32 %17 to i8
%19 = load i8*, i8** %9
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %9
store i8 %18, i8* %19
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 1
store i32 %22, i32* %8
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %16
%26 = load i32, i32* %8
%27 = load i32, i32* %6
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %25
br label %31
30: ; preds = %25, %16
br label %11
31: ; preds = %29, %11
%32 = load i8*, i8** %9
store i8 0, i8* %32
%33 = load i32, i32* %7
ret i32 %33
}

LLVM IR (-O2):
define i32 @fgetword(i32* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = icmp ne i32 %2, 0
br label %5
5: ; preds = %11, %3
%6 = phi i32 [ 0, %3 ], [ %14, %11 ]
%7 = phi i8* [ %1, %3 ], [ %13, %11 ]
%8 = tail call i32 @getc(i32* %0)
%9 = tail call i64 @isalnumde(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %5
%12 = trunc i32 %8 to i8
%13 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %12, i8* %7
%14 = add nuw nsw i32 %6, 1
%15 = icmp eq i32 %14, %2
%16 = select i1 %4, i1 %15, i1 false
br i1 %16, label %17, label %5
17: ; preds = %11, %5
%18 = phi i8* [ %7, %5 ], [ %13, %11 ]
store i8 0, i8* %18
ret i32 %8
}