#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
void main() {
  char str[100];
  int i, wrd;
  printf("\n\nContar cuantas palabras hay en un string :\n");
  printf("------------------------------------------------------\n");
  printf("Input the string : ");
  fgets(str, sizeof str, stdin);
  i = 0;
  wrd = 1;
  while (str[i] != '\0') {
    if (str[i] == ' ' || str[i] == '\n' || str[i] == '\t') {
      wrd++;
    }
    i++;
  }
  printf("El numero total de palabras es : %d\n", wrd - 1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1040 <fgets@plt>
movl   $0x0,-0x74(%rbp)
movl   $0x1,-0x78(%rbp)
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11d9 <main+0xb9>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x20,%eax
je     11c2 <main+0xa2>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0xa,%eax
je     11c2 <main+0xa2>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x9,%eax
jne    11cb <main+0xab>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    117a <main+0x5a>
mov    -0x78(%rbp),%esi
sub    $0x1,%esi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
lea    0xefd(%rip),%rdi
call   1030 <puts@plt>
lea    0xf1e(%rip),%rdi
call   1030 <puts@plt>
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e86(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <fgets@plt>
mov    $0x1,%esi
jmp    1187 <main+0x57>
nopl   0x0(%rax,%rax,1)
add    $0x1,%esi
add    $0x1,%rbx
movzbl (%rbx),%eax
lea    -0x9(%rax),%ecx
cmp    $0x2,%cl
jb     1180 <main+0x50>
cmp    $0x20,%al
je     1180 <main+0x50>
test   %al,%al
jne    1183 <main+0x53>
add    $0xffffffff,%esi
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [46 x i8] c"\0A\0AContar cuantas palabras hay en un string :\0A\00"
@.str.1 = [56 x i8] c"------------------------------------------------------\0A\00"
@.str.2 = [20 x i8] c"Input the string : \00"
@stdin = global i32 0
@.str.3 = [37 x i8] c"El numero total de palabras es : %d\0A\00"
define void @main() {
%1 = alloca [100 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 100, i32 %8)
store i32 0, i32* %2
store i32 1, i32* %3
br label %10
10: ; preds = %41, %0
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %44
17: ; preds = %10
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 32
br i1 %23, label %38, label %24
24: ; preds = %17
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 10
br i1 %30, label %38, label %31
31: ; preds = %24
%32 = load i32, i32* %2
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 9
br i1 %37, label %38, label %41
38: ; preds = %31, %24, %17
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %41
41: ; preds = %38, %31
%42 = load i32, i32* %2
%43 = add nsw i32 %42, 1
store i32 %43, i32* %2
br label %10
44: ; preds = %10
%45 = load i32, i32* %3
%46 = sub nsw i32 %45, 1
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %46)
ret void
}

LLVM IR (-O2):
@.str.2 = [20 x i8] c"Input the string : \00"
@stdin = global i32 0
@.str.3 = [37 x i8] c"El numero total de palabras es : %d\0A\00"
@str = [45 x i8] c"\0A\0AContar cuantas palabras hay en un string :\00"
@str.4 = [55 x i8] c"------------------------------------------------------\00"
define void @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.4, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %2, i32 100, i32 %6)
br label %8
8: ; preds = %15, %0
%9 = phi i64 [ %17, %15 ], [ 0, %0 ]
%10 = phi i32 [ %16, %15 ], [ 1, %0 ]
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %9
%12 = load i8, i8* %11
switch i8 %12, label %15 [
i8 0, label %18
i8 32, label %13
i8 10, label %13
i8 9, label %13
]
13: ; preds = %8, %8, %8
%14 = add nsw i32 %10, 1
br label %15
15: ; preds = %8, %13
%16 = phi i32 [ %14, %13 ], [ %10, %8 ]
%17 = add nuw i64 %9, 1
br label %8
18: ; preds = %8
%19 = add nsw i32 %10, -1
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %19)
ret void
}