#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 *);
int main(int argc, const char *argv[]) {
  char ch[50];
  int i, count = 0, num = 0;
  printf("This Program count words in a string\n\n");
  printf("Please enter a string:\n");
  for (i = 0; i < 49; i++) {
    scanf("%c", &ch[i]);
    if (ch[i] != ' ') {
      count++;
    } else {
      if (count != 0) {
        num++;
      }
      count = 0;
    }
    if (ch[i] == '\n') {
      if (count != 0 && ch[i - 1] != ' ') {
        num++;
      }
      break;
    }
  }
  printf("The words count in the string is: %d\n", num);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0x31,-0x54(%rbp)
jge    1215 <main+0xf5>
movslq -0x54(%rbp),%rax
lea    -0x50(%rbp),%rsi
add    %rax,%rsi
lea    0xebc(%rip),%rdi
call   1040 <scanf@plt>
movslq -0x54(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0x20,%eax
je     11a8 <main+0x88>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11c2 <main+0xa2>
cmpl   $0x0,-0x58(%rbp)
je     11bb <main+0x9b>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
movl   $0x0,-0x58(%rbp)
movslq -0x54(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    1202 <main+0xe2>
cmpl   $0x0,-0x58(%rbp)
je     11fd <main+0xdd>
mov    -0x54(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0x20,%eax
je     11fd <main+0xdd>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1215 <main+0xf5>
jmp    1207 <main+0xe7>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1167 <main+0x47>
mov    -0x5c(%rbp),%esi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xee4(%rip),%rdi
call   1030 <puts@plt>
lea    0xefe(%rip),%rdi
call   1030 <puts@plt>
movabs $0xffffffff00000000,%r13
ff ff ff
lea    0xe99(%rip),%r14
movabs $0x100000000,%r12
xor    %ebx,%ebx
xor    %esi,%esi
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %esi,%r15d
lea    (%rsp,%rbx,1),%rsi
mov    %r14,%rdi
call   1050 <scanf@plt>
movzbl (%rsp,%rbx,1),%eax
test   %ebp,%ebp
lea    0x1(%rbp),%ecx
setne  %sil
cmp    $0x20,%al
sete   %dl
mov    %ecx,%ebp
mov    $0x0,%ecx
cmove  %ecx,%ebp
and    %sil,%dl
movzbl %dl,%esi
add    %r15d,%esi
cmp    $0xa,%al
je     11c7 <main+0x97>
add    $0x1,%rbx
add    %r12,%r13
cmp    $0x31,%rbx
jne    1180 <main+0x50>
jmp    11db <main+0xab>
test   %ebp,%ebp
je     11db <main+0xab>
sar    $0x20,%r13
xor    %eax,%eax
cmpb   $0x20,(%rsp,%r13,1)
setne  %al
add    %eax,%esi
lea    0xe21(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"This Program count words in a string\0A\0A\00"
@.str.1 = [24 x i8] c"Please enter a string:\0A\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [38 x i8] c"The words count in the string is: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [50 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %9
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %7
br label %12
12: ; preds = %59, %2
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 49
br i1 %14, label %15, label %62
15: ; preds = %12
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 %17
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 32
br i1 %25, label %26, label %29
26: ; preds = %15
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %36
29: ; preds = %15
%30 = load i32, i32* %8
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %35
35: ; preds = %32, %29
store i32 0, i32* %8
br label %36
36: ; preds = %35, %26
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 10
br i1 %42, label %43, label %58
43: ; preds = %36
%44 = load i32, i32* %8
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %57
46: ; preds = %43
%47 = load i32, i32* %7
%48 = sub nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 32
br i1 %53, label %54, label %57
54: ; preds = %46
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %57
57: ; preds = %54, %46, %43
br label %62
58: ; preds = %36
br label %59
59: ; preds = %58
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 1
store i32 %61, i32* %7
br label %12
62: ; preds = %57, %12
%63 = load i32, i32* %9
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %63)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [38 x i8] c"The words count in the string is: %d\0A\00"
@str = [38 x i8] c"This Program count words in a string\0A\00"
@str.4 = [23 x i8] c"Please enter a string:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [50 x i8]
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.4, i64 0, i64 0))
br label %7
7: ; preds = %2, %33
%8 = phi i64 [ 0, %2 ], [ %34, %33 ]
%9 = phi i32 [ 0, %2 ], [ %20, %33 ]
%10 = phi i32 [ 0, %2 ], [ %17, %33 ]
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %8
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = load i8, i8* %11
%14 = icmp eq i8 %13, 32
%15 = add nsw i32 %10, 1
%16 = icmp ne i32 %10, 0
%17 = select i1 %14, i32 0, i32 %15
%18 = select i1 %14, i1 %16, i1 false
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %9, %19
%21 = icmp eq i8 %13, 10
br i1 %21, label %22, label %33
22: ; preds = %7
%23 = icmp eq i32 %17, 0
br i1 %23, label %36, label %24
24: ; preds = %22
%25 = shl i64 %8, 32
%26 = add i64 %25, -4294967296
%27 = ashr exact i64 %26, 32
%28 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = icmp ne i8 %29, 32
%31 = zext i1 %30 to i32
%32 = add nuw nsw i32 %20, %31
br label %36
33: ; preds = %7
%34 = add nuw nsw i64 %8, 1
%35 = icmp eq i64 %34, 49
br i1 %35, label %36, label %7
36: ; preds = %33, %24, %22
%37 = phi i32 [ %20, %22 ], [ %32, %24 ], [ %20, %33 ]
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %37)
ret i32 0
}