#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 /*<<< orphan*/ exit(int);
int getc(int /*<<< orphan*/);
scalar_t__ isspace(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int getword(char *word) {
  int i, ch;
  ch = getc(stdin);
  while (isspace(ch))
    ch = getc(stdin);
  if (ch == EOF)
    return -1;
  if (ch == '\n')
    return 0;
  i = 0;
  while (!isspace(ch)) {
    if (++i > 50) {
      printf("error: word too long.\n");
      exit(1);
    }
    *word++ = ch;
    ch = getc(stdin);
  }
  *word = '\0';
  return i;
}


x86 assembly (clang, -O0):
<getword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
call   1060 <getc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1185 <getword+0x45>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1060 <getc@plt>
mov    %eax,-0x18(%rbp)
jmp    115d <getword+0x1d>
mov    -0x18(%rbp),%eax
mov    0x2e51(%rip),%rcx
cmp    (%rcx),%eax
jne    11a3 <getword+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    123f <getword+0xff>
cmpl   $0xa,-0x18(%rbp)
jne    11b9 <getword+0x79>
movl   $0x0,-0x4(%rbp)
jmp    123f <getword+0xff>
movl   $0x0,-0x14(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11de <getword+0x9e>
jmp    1232 <getword+0xf2>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x32,%eax
jle    1206 <getword+0xc6>
lea    0xe09(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1060 <getc@plt>
mov    %eax,-0x18(%rbp)
jmp    11c0 <getword+0x80>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getword>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e97(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edi
call   1060 <getc@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    1160 <getword+0x20>
mov    0x2e63(%rip),%rax
mov    $0xffffffff,%ebx
cmp    (%rax),%ebp
je     11ca <getword+0x8a>
xor    %ebx,%ebx
cmp    $0xa,%ebp
je     11ca <getword+0x8a>
mov    %ebp,%edi
call   1040 <isspace@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    11c6 <getword+0x86>
xor    %ebx,%ebx
nopl   (%rax)
cmp    $0x32,%ebx
je     11d7 <getword+0x97>
mov    %bpl,(%r14,%rbx,1)
mov    (%r15),%edi
call   1060 <getc@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
je     11a0 <getword+0x60>
add    %rbx,%r14
movb   $0x0,(%r14)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe22(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i32 0
@.str = [23 x i8] c"error: word too long.\0A\00"
define i32 @getword(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i32, i32* @stdin
%7 = call i32 @getc(i32 %6)
store i32 %7, i32* %5
br label %8
8: ; preds = %12, %1
%9 = load i32, i32* %5
%10 = call i64 @isspace(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* @stdin
%14 = call i32 @getc(i32 %13)
store i32 %14, i32* %5
br label %8
15: ; preds = %8
%16 = load i32, i32* %5
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 -1, i32* %2
br label %47
20: ; preds = %15
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 0, i32* %2
br label %47
24: ; preds = %20
store i32 0, i32* %4
br label %25
25: ; preds = %37, %24
%26 = load i32, i32* %5
%27 = call i64 @isspace(i32 %26)
%28 = icmp ne i64 %27, 0
%29 = xor i1 %28, true
br i1 %29, label %30, label %44
30: ; preds = %25
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
%33 = icmp sgt i32 %32, 50
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %30
%38 = load i32, i32* %5
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %3
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %3
store i8 %39, i8* %40
%42 = load i32, i32* @stdin
%43 = call i32 @getc(i32 %42)
store i32 %43, i32* %5
br label %25
44: ; preds = %25
%45 = load i8*, i8** %3
store i8 0, i8* %45
%46 = load i32, i32* %4
store i32 %46, i32* %2
br label %47
47: ; preds = %44, %23, %19
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
@str = [22 x i8] c"error: word too long.\00"
define i32 @getword(i8* nocapture writeonly %0) {
%2 = load i32, i32* @stdin
%3 = tail call i32 @getc(i32 %2)
%4 = tail call i64 @isspace(i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %1, %6
%7 = load i32, i32* @stdin
%8 = tail call i32 @getc(i32 %7)
%9 = tail call i64 @isspace(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %6
11: ; preds = %6, %1
%12 = phi i32 [ %3, %1 ], [ %8, %6 ]
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %39, label %15
15: ; preds = %11
%16 = icmp eq i32 %12, 10
br i1 %16, label %39, label %17
17: ; preds = %15
%18 = tail call i64 @isspace(i32 %12)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %36
20: ; preds = %17, %28
%21 = phi i32 [ %33, %28 ], [ %12, %17 ]
%22 = phi i32 [ %29, %28 ], [ 0, %17 ]
%23 = phi i8* [ %31, %28 ], [ %0, %17 ]
%24 = icmp eq i32 %22, 50
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = add nuw nsw i32 %22, 1
%30 = trunc i32 %21 to i8
%31 = getelementptr inbounds i8, i8* %23, i64 1
store i8 %30, i8* %23
%32 = load i32, i32* @stdin
%33 = tail call i32 @getc(i32 %32)
%34 = tail call i64 @isspace(i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %20, label %36
36: ; preds = %28, %17
%37 = phi i8* [ %0, %17 ], [ %31, %28 ]
%38 = phi i32 [ 0, %17 ], [ %29, %28 ]
store i8 0, i8* %37
br label %39
39: ; preds = %15, %11, %36
%40 = phi i32 [ %38, %36 ], [ -1, %11 ], [ 0, %15 ]
ret i32 %40
}