#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() {
  int i, count = 0;
  char ch[100];
  printf("Type a sentence\n");
  scanf("%[^\n]s", ch);
  for (i = 0; ch[i] != '\0'; i++) {
    if (ch[i] == ' ') {
      count++;
    }
  }
  printf("Number of words in the sentence=%d\n", count + 1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x8(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xec9(%rip),%rdi
call   1040 <scanf@plt>
movl   $0x0,-0x4(%rbp)
movslq -0x4(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     1194 <main+0x74>
movslq -0x4(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x20,%eax
jne    1181 <main+0x61>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1186 <main+0x66>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1154 <main+0x34>
mov    -0x8(%rbp),%esi
add    $0x1,%esi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb8(%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    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Type a sentence\0A\00"
@.str.1 = [7 x i8] c"%[^\0A]s\00"
@.str.2 = [36 x i8] c"Number of words in the sentence=%d\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i8]
store i32 0, i32* %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, 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* %1
br label %7
7: ; preds = %25, %0
%8 = load i32, i32* %1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %3, 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* %1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, 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* %1
%27 = add nsw i32 %26, 1
store i32 %27, i32* %1
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 ([36 x i8], [36 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 = [36 x i8] c"Number of words in the sentence=%d\0A\00"
@str = [16 x i8] c"Type a sentence\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 ([16 x i8], [16 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 [100 x i8], [100 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 ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %16)
ret void
}