#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getc(int /*<<< orphan*/ *);
scalar_t__ isalnum(int);
int /*<<< orphan*/ stderr;
int get_word(char *buf, int buf_size, FILE *fp) {
  int len;
  int ch;
  while ((ch = getc(fp)) != EOF && !isalnum(ch))
    ;
  if (ch == EOF)
    return EOF;
  len = 0;
  do {
    buf[len] = ch;
    len++;
    if (len >= buf_size) {
      fprintf(stderr, "word too long.\n");
      exit(1);
    }
  } while ((ch == getc(fp)) != EOF && isalnum(ch));
  buf[len] = '\0';
  return len;
}


x86 assembly (clang, -O0):
<get_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,%ecx
mov    %ecx,-0x28(%rbp)
xor    %eax,%eax
mov    0x2e7e(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x29(%rbp)
je     1189 <get_word+0x49>
mov    -0x28(%rbp),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1199 <get_word+0x59>
jmp    119e <get_word+0x5e>
jmp    1153 <get_word+0x13>
mov    -0x28(%rbp),%eax
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%eax
jne    11c1 <get_word+0x81>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1272 <get_word+0x132>
movl   $0x0,-0x24(%rbp)
mov    -0x28(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     120c <get_word+0xcc>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    1211 <get_word+0xd1>
mov    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%ecx
xor    %eax,%eax
mov    0x2db0(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x2a(%rbp)
je     1255 <get_word+0x115>
mov    -0x28(%rbp),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
test   $0x1,%al
jne    11c8 <get_word+0x88>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_word>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r14
mov    0x2e8e(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1060 <getc@plt>
mov    %eax,%ebp
cmp    (%r12),%eax
je     11de <get_word+0x9e>
mov    %ebp,%edi
call   1030 <isalnum@plt>
test   %rax,%rax
je     1160 <get_word+0x20>
cmp    (%r12),%ebp
je     11de <get_word+0x9e>
cmp    $0x2,%ebx
mov    $0x1,%r13d
cmovge %ebx,%r13d
add    $0xffffffff,%r13d
neg    %r13
mov    $0x1,%ecx
nopl   0x0(%rax,%rax,1)
lea    (%rcx,%r13,1),%rax
mov    %bpl,-0x1(%r14,%rcx,1)
cmp    $0x1,%rax
je     11ef <get_word+0xaf>
mov    %rcx,%rbx
mov    %r15,%rdi
call   1060 <getc@plt>
xor    %ecx,%ecx
cmp    %eax,%ebp
sete   %cl
cmp    %ecx,(%r12)
je     11d7 <get_word+0x97>
mov    %ebp,%edi
call   1030 <isalnum@plt>
lea    0x1(%rbx),%rcx
test   %rax,%rax
jne    11a0 <get_word+0x60>
movb   $0x0,(%r14,%rbx,1)
mov    %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
@stderr = global i32 0
@.str = [16 x i8] c"word too long.\0A\00"
define i32 @get_word(i8* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
br label %10
10: ; preds = %22, %3
%11 = load i32*, i32** %7
%12 = call i32 @getc(i32* %11)
store i32 %12, i32* %9
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i32, i32* %9
%17 = call i64 @isalnum(i32 %16)
%18 = icmp ne i64 %17, 0
%19 = xor i1 %18, true
br label %20
20: ; preds = %15, %10
%21 = phi i1 [ false, %10 ], [ %19, %15 ]
br i1 %21, label %22, label %23
22: ; preds = %20
br label %10
23: ; preds = %20
%24 = load i32, i32* %9
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = load i32, i32* @EOF
store i32 %28, i32* %4
br label %67
29: ; preds = %23
store i32 0, i32* %8
br label %30
30: ; preds = %59, %29
%31 = load i32, i32* %9
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %5
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 %32, i8* %36
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = load i32, i32* %6
%41 = icmp sge i32 %39, %40
br i1 %41, label %42, label %46
42: ; preds = %30
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %30
br label %47
47: ; preds = %46
%48 = load i32, i32* %9
%49 = load i32*, i32** %7
%50 = call i32 @getc(i32* %49)
%51 = icmp eq i32 %48, %50
%52 = zext i1 %51 to i32
%53 = load i32, i32* @EOF
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %59
55: ; preds = %47
%56 = load i32, i32* %9
%57 = call i64 @isalnum(i32 %56)
%58 = icmp ne i64 %57, 0
br label %59
59: ; preds = %55, %47
%60 = phi i1 [ false, %47 ], [ %58, %55 ]
br i1 %60, label %30, label %61
61: ; preds = %59
%62 = load i8*, i8** %5
%63 = load i32, i32* %8
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
store i8 0, i8* %65
%66 = load i32, i32* %8
store i32 %66, i32* %4
br label %67
67: ; preds = %61, %27
%68 = load i32, i32* %4
ret i32 %68
}

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