#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 */

/* Variables and functions */
char EOF;
char getch();
int /*<<< orphan*/ isalnum(char);
scalar_t__ isspace(char);
int /*<<< orphan*/ ungetch(char);
int getword(char *word, int lim) {
  char c;
  char *w = word;
  while (isspace(c = getch()))
    ;
  if (c != EOF)
    *w++ = c;
  else
    return EOF;
  for (; --lim > 0; w++)
    if (!isalnum(*w = getch())) {
      ungetch(*w);
      break;
    }
  *w = '\0';
  return word[0];
}


x86 assembly (clang, -O0):
<getword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <getch@plt>
mov    %al,-0x15(%rbp)
movsbl %al,%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1178 <getword+0x38>
jmp    1157 <getword+0x17>
movsbl -0x15(%rbp),%eax
mov    0x2e65(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11a7 <getword+0x67>
mov    -0x15(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    11b9 <getword+0x79>
mov    0x2e3a(%rip),%rax
movsbl (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1226 <getword+0xe6>
jmp    11be <getword+0x7e>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    1215 <getword+0xd5>
mov    $0x0,%al
call   1060 <getch@plt>
mov    -0x20(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%edi
call   1030 <isalnum@plt>
cmp    $0x0,%eax
jne    11ff <getword+0xbf>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1050 <ungetch@plt>
jmp    1215 <getword+0xd5>
jmp    1204 <getword+0xc4>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11be <getword+0x7e>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getword>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <getch@plt>
mov    %eax,%ebx
movsbl %al,%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    1150 <getword+0x10>
mov    0x2e7b(%rip),%rax
cmp    (%rax),%bl
je     11b3 <getword+0x73>
mov    %bl,(%r14)
lea    0x1(%r14),%rcx
nopl   0x0(%rax,%rax,1)
mov    %rcx,%rbx
cmp    $0x2,%ebp
jl     11ad <getword+0x6d>
add    $0xffffffff,%ebp
xor    %eax,%eax
call   1060 <getch@plt>
mov    %al,(%rbx)
movsbl %al,%edi
call   1030 <isalnum@plt>
lea    0x1(%rbx),%rcx
test   %eax,%eax
jne    1180 <getword+0x40>
movsbl -0x1(%rcx),%edi
call   1050 <ungetch@plt>
movb   $0x0,(%rbx)
mov    (%r14),%bl
movsbl %bl,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i8 0
define i32 @getword(i8* nocapture %0, i32 %1) {
br label %3
3: ; preds = %3, %2
%4 = tail call signext i8 (...) @getch()
%5 = tail call i64 @isspace(i8 signext %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %3
7: ; preds = %3
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %4, %8
br i1 %9, label %26, label %10
10: ; preds = %7
store i8 %4, i8* %0
br label %11
11: ; preds = %16, %10
%12 = phi i32 [ %1, %10 ], [ %17, %16 ]
%13 = phi i8* [ %0, %10 ], [ %14, %16 ]
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = icmp sgt i32 %12, 1
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = add nsw i32 %12, -1
%18 = tail call signext i8 (...) @getch()
store i8 %18, i8* %14
%19 = tail call i32 @isalnum(i8 signext %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %11
21: ; preds = %16
%22 = load i8, i8* %14
%23 = tail call i32 @ungetch(i8 signext %22)
br label %24
24: ; preds = %11, %21
store i8 0, i8* %14
%25 = load i8, i8* %0
br label %26
26: ; preds = %7, %24
%27 = phi i8 [ %25, %24 ], [ %4, %7 ]
%28 = sext i8 %27 to i32
ret i32 %28
}