#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 /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char text[81];
  int totalWords = 0;
  int countWords(const char string[]);
  void readLine(char buffer[]);
  bool endOfText = false;
  printf("Type in your text.\n");
  printf("When you are done, press 'RETURN'.\n\n");
  while (!endOfText) {
    readLine(text);
    if (text[0] == '\0')
      endOfText = true;
    else
      totalWords += countWords(text);
  }
  printf("\nThere are %i words in the above text.\n", totalWords);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x68(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    117f <main+0x4f>
jmp    11b5 <main+0x85>
lea    -0x60(%rbp),%rdi
call   1050 <readLine@plt>
movsbl -0x60(%rbp),%eax
cmp    $0x0,%eax
jne    11a1 <main+0x71>
movl   $0x1,-0x68(%rbp)
jmp    11b0 <main+0x80>
lea    -0x60(%rbp),%rdi
call   1040 <countWords@plt>
add    -0x64(%rbp),%eax
mov    %eax,-0x64(%rbp)
jmp    1169 <main+0x39>
mov    -0x64(%rbp),%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
lea    0xeda(%rip),%rdi
call   1030 <puts@plt>
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1060 <readLine@plt>
cmpb   $0x0,(%rsp)
je     119a <main+0x5a>
xor    %ebx,%ebx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1050 <countWords@plt>
add    %eax,%ebx
mov    %r14,%rdi
call   1060 <readLine@plt>
cmpb   $0x0,(%rsp)
jne    1180 <main+0x40>
jmp    119c <main+0x5c>
xor    %ebx,%ebx
lea    0xe5d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Type in your text.\0A\00"
@.str.1 = [37 x i8] c"When you are done, press 'RETURN'.\0A\0A\00"
@.str.2 = [40 x i8] c"\0AThere are %i words in the above text.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [81 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %23, %0
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
%10 = xor i1 %9, true
br i1 %10, label %11, label %24
11: ; preds = %7
%12 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%13 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11
store i32 1, i32* %4
br label %23
18: ; preds = %11
%19 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%20 = call i32 @countWords(i8* %19)
%21 = load i32, i32* %3
%22 = add nsw i32 %21, %20
store i32 %22, i32* %3
br label %23
23: ; preds = %18, %17
br label %7
24: ; preds = %7
%25 = load i32, i32* %3
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %25)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [40 x i8] c"\0AThere are %i words in the above text.\0A\00"
@str = [19 x i8] c"Type in your text.\00"
@str.3 = [36 x i8] c"When you are done, press 'RETURN'.\0A\00"
define i32 @main() {
%1 = alloca [81 x i8]
%2 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0))
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %10, %7 ], [ 0, %0 ]
%9 = call i32 @countWords(i8* %2)
%10 = add nsw i32 %9, %8
%11 = load i8, i8* %2
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %7
13: ; preds = %7, %0
%14 = phi i32 [ 0, %0 ], [ %10, %7 ]
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %14)
ret i32 0
}