#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__ count_words(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read_line(char *);
int main(void) {
  char text[81];
  int total_words = 0;
  int end_of_text = 0;
  printf("Enter a short sentence:\n\n");
  while (end_of_text == 0) {
    read_line(text);
    if (text[0] == '\0') {
      end_of_text = 1;
    } else {
      total_words += count_words(text);
    }
  }
  printf("\nThere were %i words in the text above.\n", total_words);
  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   1040 <printf@plt>
cmpl   $0x0,-0x68(%rbp)
jne    11a2 <main+0x72>
lea    -0x60(%rbp),%rdi
call   1050 <read_line@plt>
movsbl -0x60(%rbp),%eax
cmp    $0x0,%eax
jne    1187 <main+0x57>
movl   $0x1,-0x68(%rbp)
jmp    119d <main+0x6d>
lea    -0x60(%rbp),%rdi
call   1030 <count_words@plt>
mov    %rax,%rcx
movslq -0x64(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x64(%rbp)
jmp    115b <main+0x2b>
mov    -0x64(%rbp),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
lea    0xedb(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rdi
call   1060 <read_line@plt>
cmpb   $0x0,(%rsp)
je     118a <main+0x4a>
xor    %ebx,%ebx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <count_words@plt>
add    %eax,%ebx
mov    %r14,%rdi
call   1060 <read_line@plt>
cmpb   $0x0,(%rsp)
jne    1170 <main+0x30>
jmp    118c <main+0x4c>
xor    %ebx,%ebx
lea    0xe6d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Enter a short sentence:\0A\0A\00"
@.str.1 = [41 x i8] c"\0AThere were %i words in the text above.\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 ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %24, %0
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %6
%10 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%11 = call i32 @read_line(i8* %10)
%12 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %9
store i32 1, i32* %4
br label %24
17: ; preds = %9
%18 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%19 = call i64 @count_words(i8* %18)
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = add nsw i64 %21, %19
%23 = trunc i64 %22 to i32
store i32 %23, i32* %3
br label %24
24: ; preds = %17, %16
br label %6
25: ; preds = %6
%26 = load i32, i32* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [41 x i8] c"\0AThere were %i words in the text above.\0A\00"
@str = [25 x i8] c"Enter a short sentence:\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 ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%4 = call i32 @read_line(i8* %2)
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %11, %7 ], [ 0, %0 ]
%9 = call i64 @count_words(i8* %2)
%10 = trunc i64 %9 to i32
%11 = add i32 %8, %10
%12 = call i32 @read_line(i8* %2)
%13 = load i8, i8* %2
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %7
15: ; preds = %7, %0
%16 = phi i32 [ 0, %0 ], [ %11, %7 ]
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %16)
ret i32 0
}