#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 */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int wnum = 0;
  int frgChar;
  char c;
  printf("Input a string\n");
  frgChar = 0;
  while ((c = getchar()) != '\n') {
    if (c > ' ') {
      if (!frgChar) {
        frgChar = 1;
        wnum++;
      }
    } else {
      frgChar = 0;
    }
  }
  printf("#words: %d\n", wnum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0xd(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     1199 <main+0x79>
movsbl -0xd(%rbp),%eax
cmp    $0x20,%eax
jle    118d <main+0x6d>
cmpl   $0x0,-0xc(%rbp)
jne    1188 <main+0x68>
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1194 <main+0x74>
movl   $0x0,-0xc(%rbp)
jmp    114b <main+0x2b>
mov    -0x8(%rbp),%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     117e <main+0x4e>
xor    %r14d,%r14d
xor    %ebx,%ebx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    $0x1,%ecx
xor    %ebp,%ebp
cmp    $0x21,%al
setge  %bpl
cmovl  %r14d,%ecx
add    %ecx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %ebp,%ecx
cmp    $0xa,%al
jne    1160 <main+0x30>
lea    0xe7b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Input a string\0A\00"
@.str.1 = [12 x i8] c"#words: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %6
6: ; preds = %22, %0
%7 = call signext i8 (...) @getchar()
store i8 %7, i8* %4
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 10
br i1 %9, label %10, label %23
10: ; preds = %6
%11 = load i8, i8* %4
%12 = sext i8 %11 to i32
%13 = icmp sgt i32 %12, 32
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = load i32, i32* %3
%16 = icmp ne i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
store i32 1, i32* %3
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %20
20: ; preds = %17, %14
br label %22
21: ; preds = %10
store i32 0, i32* %3
br label %22
22: ; preds = %21, %20
br label %6
23: ; preds = %6
%24 = load i32, i32* %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %24)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"#words: %d\0A\00"
@str = [15 x i8] c"Input a string\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%2 = tail call signext i8 (...) @getchar()
%3 = icmp eq i8 %2, 10
br i1 %3, label %15, label %4
4: ; preds = %0, %4
%5 = phi i8 [ %13, %4 ], [ %2, %0 ]
%6 = phi i32 [ %12, %4 ], [ 0, %0 ]
%7 = phi i32 [ %10, %4 ], [ 0, %0 ]
%8 = icmp sgt i8 %5, 32
%9 = xor i32 %7, 1
%10 = zext i1 %8 to i32
%11 = select i1 %8, i32 %9, i32 0
%12 = add nuw nsw i32 %11, %6
%13 = tail call signext i8 (...) @getchar()
%14 = icmp eq i8 %13, 10
br i1 %14, label %15, label %4
15: ; preds = %4, %0
%16 = phi i32 [ 0, %0 ], [ %12, %4 ]
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %16)
ret i32 0
}