#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 */
char getchar();
int /*<<< orphan*/ printf(char *, int);
int main() {
  char array[1024] = {};
  int i = 0, count = 0;
  char *p = NULL;
  while ('\n' != (array[i] = getchar())) {
    i++;
  }
  array[i] = '\0';
  p = array;
  while ('\0' != *p) {
    if (' ' == *p) {
      count += 1;
    }
    p++;
  }
  count += 1;
  printf("%d words in sentence.\n", count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
movl   $0x0,-0x414(%rbp)
movl   $0x0,-0x418(%rbp)
movq   $0x0,-0x420(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
movslq -0x414(%rbp),%rcx
mov    %al,-0x410(%rbp,%rcx,1)
movsbl %al,%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
je     11ad <main+0x7d>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    1174 <main+0x44>
movslq -0x414(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rax
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     121b <main+0xeb>
mov    -0x420(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x20,%eax
cmp    %ecx,%eax
jne    1204 <main+0xd4>
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
mov    -0x420(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x420(%rbp)
jmp    11ca <main+0x9a>
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
mov    -0x418(%rbp),%esi
lea    0xdc9(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsp,%r14
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %al,0x1(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0xa,%al
jne    1160 <main+0x30>
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
xor    %esi,%esi
jmp    1187 <main+0x57>
nopl   (%rax)
add    $0x1,%esi
add    $0x1,%r14
movzbl (%r14),%eax
cmp    $0x20,%al
je     1180 <main+0x50>
test   %al,%al
jne    1183 <main+0x53>
add    $0x1,%esi
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [23 x i8] c"%d words in sentence.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = bitcast [1024 x i8]* %2 to i8*
store i32 0, i32* %3
store i32 0, i32* %4
store i8* null, i8** %5
br label %7
7: ; preds = %14, %0
%8 = call signext i8 (...) @getchar()
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %10
store i8 %8, i8* %11
%12 = sext i8 %8 to i32
%13 = icmp ne i32 10, %12
br i1 %13, label %14, label %17
14: ; preds = %7
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %7
17: ; preds = %7
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %19
store i8 0, i8* %20
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
store i8* %21, i8** %5
br label %22
22: ; preds = %35, %17
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 0, %25
br i1 %26, label %27, label %38
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 32, %30
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %35
35: ; preds = %32, %27
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %5
br label %22
38: ; preds = %22
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
%41 = load i32, i32* %4
%42 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"%d words in sentence.\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %3, %0
%4 = phi i64 [ %8, %3 ], [ 0, %0 ]
%5 = tail call signext i8 (...) @getchar()
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %4
store i8 %5, i8* %6
%7 = icmp eq i8 %5, 10
%8 = add nuw i64 %4, 1
br i1 %7, label %9, label %3
9: ; preds = %3
%10 = and i64 %4, 4294967295
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %10
store i8 0, i8* %11
br label %12
12: ; preds = %18, %9
%13 = phi i32 [ 0, %9 ], [ %19, %18 ]
%14 = phi i8* [ %2, %9 ], [ %20, %18 ]
%15 = load i8, i8* %14
switch i8 %15, label %18 [
i8 0, label %21
i8 32, label %16
]
16: ; preds = %12
%17 = add nsw i32 %13, 1
br label %18
18: ; preds = %12, %16
%19 = phi i32 [ %17, %16 ], [ %13, %12 ]
%20 = getelementptr inbounds i8, i8* %14, i64 1
br label %12
21: ; preds = %12
%22 = add nsw i32 %13, 1
%23 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %22)
ret i32 0
}