#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 *, int);
void main() {
  char str[50];
  int i = 0, count = 1;
  int in = 1, out = 0;
  gets(str);
  while (str[i] != '\0') {
    if (str[i] == ' ') {
      out = 1;
    } else {
      if (out == 1) {
        count++;
        out = 0;
      }
    }
    i++;
  }
  printf("Total Number of words : %d", count);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x44(%rbp)
movl   $0x1,-0x48(%rbp)
movl   $0x1,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <gets@plt>
movslq -0x44(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11aa <main+0x8a>
movslq -0x44(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x20,%eax
jne    117d <main+0x5d>
movl   $0x1,-0x50(%rbp)
jmp    119c <main+0x7c>
cmpl   $0x1,-0x50(%rbp)
jne    1197 <main+0x77>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
movl   $0x0,-0x50(%rbp)
jmp    119c <main+0x7c>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    114d <main+0x2d>
mov    -0x48(%rbp),%esi
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <gets@plt>
xor    %eax,%eax
mov    $0x1,%esi
jmp    1149 <main+0x29>
nopl   0x0(%rax)
mov    $0x1,%eax
add    $0x1,%rbx
movzbl (%rbx),%ecx
cmp    $0x20,%cl
je     1140 <main+0x20>
test   %cl,%cl
je     1167 <main+0x47>
xor    %ecx,%ecx
cmp    $0x1,%eax
sete   %cl
add    %ecx,%esi
xor    %eax,%eax
add    $0x1,%rbx
jmp    1149 <main+0x29>
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [27 x i8] c"Total Number of words : %d\00"
define void @main() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = call i32 @gets(i8* %2)
br label %4
4: ; preds = %14, %0
%5 = phi i64 [ %17, %14 ], [ 0, %0 ]
%6 = phi i32 [ %15, %14 ], [ 1, %0 ]
%7 = phi i32 [ %16, %14 ], [ 0, %0 ]
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %5
%9 = load i8, i8* %8
switch i8 %9, label %10 [
i8 0, label %18
i8 32, label %14
]
10: ; preds = %4
%11 = icmp eq i32 %7, 1
%12 = zext i1 %11 to i32
%13 = add nsw i32 %6, %12
br label %14
14: ; preds = %10, %4
%15 = phi i32 [ %6, %4 ], [ %13, %10 ]
%16 = phi i32 [ 1, %4 ], [ 0, %10 ]
%17 = add nuw i64 %5, 1
br label %4
18: ; preds = %4
%19 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %6)
ret void
}