#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
void main() {
  char string[81];
  int i, num = 0, word = 0;
  char c;
  printf("Please input some words:");
  gets(string);
  for (i = 0; (c = string[i]) != '\0'; i++) {
    if (c == ' ')
      word = 0;
    else if (word == 0) {
      word = 1;
      num++;
    }
  }
  printf("There are %d words in the line.\n", num);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x60(%rbp),%rdi
call   1040 <gets@plt>
movl   $0x0,-0x64(%rbp)
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,1),%al
mov    %al,-0x6d(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     11b6 <main+0x96>
movsbl -0x6d(%rbp),%eax
cmp    $0x20,%eax
jne    1184 <main+0x64>
movl   $0x0,-0x6c(%rbp)
jmp    11a3 <main+0x83>
cmpl   $0x0,-0x6c(%rbp)
jne    119e <main+0x7e>
movl   $0x1,-0x6c(%rbp)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    11a3 <main+0x83>
jmp    11a8 <main+0x88>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1154 <main+0x34>
mov    -0x68(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
lea    0xed3(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <gets@plt>
xor    %eax,%eax
jmp    1156 <main+0x36>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
add    $0x1,%rbx
movzbl (%rbx),%ecx
cmp    $0x20,%cl
je     1150 <main+0x30>
test   %cl,%cl
je     1173 <main+0x53>
cmp    $0x1,%eax
adc    $0x0,%ebp
mov    $0x1,%eax
add    $0x1,%rbx
jmp    1156 <main+0x36>
lea    0xe9f(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Please input some words:\00"
@.str.1 = [33 x i8] c"There are %d words in the line.\0A\00"
define void @main() {
%1 = alloca [81 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 0, i32* %3
store i32 0, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 0
%8 = call i32 @gets(i8* %7)
store i32 0, i32* %2
br label %9
9: ; preds = %29, %0
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 %11
%13 = load i8, i8* %12
store i8 %13, i8* %5
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %32
16: ; preds = %9
%17 = load i8, i8* %5
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 32
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 0, i32* %4
br label %28
21: ; preds = %16
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
store i32 1, i32* %4
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %27
27: ; preds = %24, %21
br label %28
28: ; preds = %27, %20
br label %29
29: ; preds = %28
%30 = load i32, i32* %2
%31 = add nsw i32 %30, 1
store i32 %31, i32* %2
br label %9
32: ; preds = %9
%33 = load i32, i32* %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %33)
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"Please input some words:\00"
@.str.1 = [33 x i8] c"There are %d words in the line.\0A\00"
define void @main() {
%1 = alloca [81 x i8]
%2 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @gets(i8* %2)
br label %5
5: ; preds = %15, %0
%6 = phi i64 [ %18, %15 ], [ 0, %0 ]
%7 = phi i32 [ %16, %15 ], [ 0, %0 ]
%8 = phi i32 [ %17, %15 ], [ 0, %0 ]
%9 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 %6
%10 = load i8, i8* %9
switch i8 %10, label %11 [
i8 0, label %19
i8 32, label %15
]
11: ; preds = %5
%12 = icmp eq i32 %8, 0
%13 = zext i1 %12 to i32
%14 = add nsw i32 %7, %13
br label %15
15: ; preds = %11, %5
%16 = phi i32 [ %7, %5 ], [ %14, %11 ]
%17 = phi i32 [ 0, %5 ], [ 1, %11 ]
%18 = add nuw i64 %6, 1
br label %5
19: ; preds = %5
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %7)
ret void
}