#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
void main() {
  char s[200];
  int count = 0, i;
  printf("enter the string\n");
  scanf("%[^\n]s", s);
  for (i = 0; s[i] != '\0'; i++) {
    if (s[i] == ' ')
      count++;
  }
  printf("number of words in given string are: %d\n", count + 1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0xd4(%rbp)
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xd0(%rbp),%rsi
lea    0xec1(%rip),%rdi
call   1040 <scanf@plt>
movl   $0x0,-0xd8(%rbp)
movslq -0xd8(%rbp),%rax
movsbl -0xd0(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     11b8 <main+0x98>
movslq -0xd8(%rbp),%rax
movsbl -0xd0(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
jne    119f <main+0x7f>
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
jmp    11a4 <main+0x84>
mov    -0xd8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd8(%rbp)
jmp    1160 <main+0x40>
mov    -0xd4(%rbp),%esi
add    $0x1,%esi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xd0,%rsp
lea    0xef1(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb5(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
xor    %esi,%esi
jmp    1167 <main+0x37>
nopw   0x0(%rax,%rax,1)
add    $0x1,%esi
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x20,%al
je     1160 <main+0x30>
test   %al,%al
jne    1163 <main+0x33>
add    $0x1,%esi
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xd0,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%[^\0A]s\00"
@.str.2 = [41 x i8] c"number of words in given string are: %d\0A\00"
@str = [17 x i8] c"enter the string\00"
define void @main() {
%1 = alloca [200 x i8]
%2 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %5
5: ; preds = %12, %0
%6 = phi i64 [ %14, %12 ], [ 0, %0 ]
%7 = phi i32 [ %13, %12 ], [ 0, %0 ]
%8 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 %6
%9 = load i8, i8* %8
switch i8 %9, label %12 [
i8 0, label %15
i8 32, label %10
]
10: ; preds = %5
%11 = add nsw i32 %7, 1
br label %12
12: ; preds = %5, %10
%13 = phi i32 [ %11, %10 ], [ %7, %5 ]
%14 = add nuw i64 %6, 1
br label %5
15: ; preds = %5
%16 = add nsw i32 %7, 1
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %16)
ret void
}