#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 */
int EOF;
int getch();
scalar_t__ isspace(int);
int /*<<< orphan*/ ungetch(int);
void getword(char word[]) {
  int c, i;
  while (isspace(c = getch()))
    ;
  ungetch(c);
  for (i = 0; (c = getch()) != EOF && i < 32 - 1 && !isspace(c); ++i)
    word[i] = c;
  word[i] = '\0';
  return;
}


x86 assembly (clang, -O0):
<getword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getch@plt>
mov    %eax,%edi
mov    %edi,-0xc(%rbp)
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     115c <getword+0x2c>
jmp    113c <getword+0xc>
mov    -0xc(%rbp),%edi
call   1040 <ungetch@plt>
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getch@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2e68(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x11(%rbp)
je     11ae <getword+0x7e>
xor    %eax,%eax
cmpl   $0x1f,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jge    11ae <getword+0x7e>
mov    -0xc(%rbp),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11be <getword+0x8e>
jmp    11dc <getword+0xac>
mov    -0xc(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116b <getword+0x3b>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getword>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getch@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <isspace@plt>
test   %rax,%rax
jne    1140 <getword+0x10>
mov    %ebp,%edi
call   1040 <ungetch@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getch@plt>
mov    0x2e7c(%rip),%r14
cmp    (%r14),%eax
je     11b3 <getword+0x83>
mov    %eax,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
call   1030 <isspace@plt>
test   %rax,%rax
jne    11ad <getword+0x7d>
mov    %bpl,(%r15,%rbx,1)
lea    0x1(%rbx),%r12
xor    %eax,%eax
call   1050 <getch@plt>
cmp    (%r14),%eax
je     11b0 <getword+0x80>
mov    %eax,%ebp
cmp    $0x1e,%rbx
mov    %r12,%rbx
jb     1180 <getword+0x50>
jmp    11b0 <getword+0x80>
mov    %rbx,%r12
mov    %r12d,%ebx
movb   $0x0,(%r15,%rbx,1)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define void @getword(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
br label %5
5: ; preds = %9, %1
%6 = call i32 (...) @getch()
store i32 %6, i32* %3
%7 = call i64 @isspace(i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %5
br label %5
10: ; preds = %5
%11 = load i32, i32* %3
%12 = call i32 @ungetch(i32 %11)
store i32 0, i32* %4
br label %13
13: ; preds = %34, %10
%14 = call i32 (...) @getch()
store i32 %14, i32* %3
%15 = load i32, i32* @EOF
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 31
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32, i32* %3
%22 = call i64 @isspace(i32 %21)
%23 = icmp ne i64 %22, 0
%24 = xor i1 %23, true
br label %25
25: ; preds = %20, %17, %13
%26 = phi i1 [ false, %17 ], [ false, %13 ], [ %24, %20 ]
br i1 %26, label %27, label %37
27: ; preds = %25
%28 = load i32, i32* %3
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %2
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 %29, i8* %33
br label %34
34: ; preds = %27
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %13
37: ; preds = %25
%38 = load i8*, i8** %2
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 0, i8* %41
ret void
}

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