#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 *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char *str = malloc(100);
  int now = 0, pos = 0;
  printf("Enter any string: ");
  gets(str);
  while (*str != '\0') {
    if (pos == 0) {
      pos = 1;
      ++now;
    } else if (*str == ' ') {
      pos = 0;
    }
    str++;
  }
  printf("The number of words: %d", now);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <gets@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ce <main+0x9e>
cmpl   $0x0,-0x18(%rbp)
jne    11a1 <main+0x71>
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11bd <main+0x8d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    11b8 <main+0x88>
movl   $0x0,-0x18(%rbp)
jmp    11bd <main+0x8d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1172 <main+0x42>
mov    -0x14(%rbp),%esi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xeb9(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <gets@plt>
mov    (%rbx),%al
test   %al,%al
je     118f <main+0x5f>
add    $0x1,%rbx
xor    %ecx,%ecx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
test   %ecx,%ecx
sete   %dl
cmp    $0x20,%al
setne  %al
xor    $0x1,%ecx
add    %ecx,%ebp
or     %dl,%al
movzbl %al,%ecx
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1170 <main+0x40>
lea    0xe7d(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [19 x i8] c"Enter any string: \00"
@.str.1 = [24 x i8] c"The number of words: %d\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @gets(i8* %1)
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %20, label %6
6: ; preds = %0, %6
%7 = phi i8 [ %18, %6 ], [ %4, %0 ]
%8 = phi i32 [ %16, %6 ], [ 0, %0 ]
%9 = phi i32 [ %14, %6 ], [ 0, %0 ]
%10 = phi i8* [ %17, %6 ], [ %1, %0 ]
%11 = icmp eq i32 %8, 0
%12 = icmp ne i8 %7, 32
%13 = xor i32 %8, 1
%14 = add nuw nsw i32 %13, %9
%15 = select i1 %11, i1 true, i1 %12
%16 = zext i1 %15 to i32
%17 = getelementptr inbounds i8, i8* %10, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %6
20: ; preds = %6, %0
%21 = phi i32 [ 0, %0 ], [ %14, %6 ]
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %21)
ret i32 0
}