#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 read_char();
void read_word(char *word, int len) {
  int ch, pos = 0;
  while ((ch = read_char()) == ' ') {
  }
  while (ch != ' ' && ch != EOF) {
    if (pos < len)
      word[pos++] = ch;
    ch = read_char();
  }
  word[pos] = '\0';
}


x86 assembly (clang, -O0):
<read_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1030 <read_char@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x20,%eax
jne    113e <read_word+0x2e>
jmp    1126 <read_word+0x16>
jmp    1143 <read_word+0x33>
xor    %eax,%eax
cmpl   $0x20,-0x10(%rbp)
mov    %al,-0x15(%rbp)
je     1164 <read_word+0x54>
mov    -0x10(%rbp),%eax
mov    0x2e8c(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1174 <read_word+0x64>
jmp    11a9 <read_word+0x99>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119a <read_word+0x8a>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    $0x0,%al
call   1030 <read_char@plt>
mov    %eax,-0x10(%rbp)
jmp    1143 <read_word+0x33>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_word>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <read_char@plt>
cmp    $0x20,%eax
je     1120 <read_word+0x10>
mov    0x2eb5(%rip),%r15
xor    %ebx,%ebx
cmp    (%r15),%eax
je     115f <read_word+0x4f>
xor    %ebx,%ebx
nopl   0x0(%rax)
cmp    %ebp,%ebx
jge    114e <read_word+0x3e>
movslq %ebx,%rcx
add    $0x1,%ebx
mov    %al,(%r14,%rcx,1)
xor    %eax,%eax
call   1030 <read_char@plt>
cmp    $0x20,%eax
je     115f <read_word+0x4f>
cmp    (%r15),%eax
jne    1140 <read_word+0x30>
movslq %ebx,%rax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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