#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 */
scalar_t__ getchar();
int get_word(char *word) {
  int i = 0;
  while ((word[i] = (char)getchar()) != ' ') {
    if (word[i] == '\n') {
      word[i] = '\0';
      return 1;
    }
    i += 1;
  }
  word[i] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<get_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
mov    %al,(%rcx,%rdx,1)
movsbl %al,%eax
cmp    $0x20,%eax
je     117c <get_word+0x6c>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    116e <get_word+0x5e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
jmp    118f <get_word+0x7f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1123 <get_word+0x13>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_word>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %al,(%r14,%rbx,1)
cmp    $0xa,%al
je     1139 <get_word+0x29>
cmp    $0x20,%al
je     1140 <get_word+0x30>
add    $0x1,%rbx
jmp    1120 <get_word+0x10>
mov    $0x1,%eax
jmp    1142 <get_word+0x32>
xor    %eax,%eax
mov    %ebx,%ecx
movb   $0x0,(%r14,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @get_word(i8* nocapture writeonly %0) {
br label %2
2: ; preds = %7, %1
%3 = phi i64 [ %8, %7 ], [ 0, %1 ]
%4 = tail call i64 (...) @getchar()
%5 = trunc i64 %4 to i8
%6 = getelementptr inbounds i8, i8* %0, i64 %3
store i8 %5, i8* %6
switch i8 %5, label %7 [
i8 32, label %9
i8 10, label %10
]
7: ; preds = %2
%8 = add nuw i64 %3, 1
br label %2
9: ; preds = %2
br label %10
10: ; preds = %2, %9
%11 = phi i32 [ 0, %9 ], [ 1, %2 ]
%12 = and i64 %3, 4294967295
%13 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 0, i8* %13
ret i32 %11
}