#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 */
scalar_t__ isspace(char);
int kc_count_words_in_line(const char *fp, int *count) {
  int flag = -1;
  char ch = 0;
  *count = 0;
  while ((flag < 3) && ((ch = *(fp)) != '\0')) {
    fp++;
    if ((ch == '\v') || (ch == '\r') || (ch == '\n') || (ch == '\t')) {
      if (flag == 0) {
        (*count)++;
        flag = 3;
      }
      if (flag == -1)
        flag = 3;
      else
        flag = 2;
    } else if (isspace(ch) || (ch == ',') || (ch == '!') || (ch == '(') ||
               (ch == ')') || (ch == '{') || (ch == '}') || (ch == '[') ||
               (ch == ']')) {
      if (flag == 0) {
        flag = 1;
        (*count)++;
      }
    } else if (flag == 1)
      flag = 0;
    else if (flag == 2)
      flag = 3;
    else
      flag = 0;
  }
  if (flag != -1)
    --fp;
  if (ch == '\0') {
    if (flag == 0)
      (*count)++;
    return 1;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<kc_count_words_in_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movb   $0x0,-0x1d(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
xor    %eax,%eax
cmpl   $0x3,-0x1c(%rbp)
mov    %al,-0x1e(%rbp)
jge    1159 <kc_count_words_in_line+0x49>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    1169 <kc_count_words_in_line+0x59>
jmp    12ca <kc_count_words_in_line+0x1ba>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0xb,%eax
je     11a9 <kc_count_words_in_line+0x99>
movsbl -0x1d(%rbp),%eax
cmp    $0xd,%eax
je     11a9 <kc_count_words_in_line+0x99>
movsbl -0x1d(%rbp),%eax
cmp    $0xa,%eax
je     11a9 <kc_count_words_in_line+0x99>
movsbl -0x1d(%rbp),%eax
cmp    $0x9,%eax
jne    11e7 <kc_count_words_in_line+0xd7>
cmpl   $0x0,-0x1c(%rbp)
jne    11c5 <kc_count_words_in_line+0xb5>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
movl   $0x3,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11db <kc_count_words_in_line+0xcb>
movl   $0x3,-0x1c(%rbp)
jmp    11e2 <kc_count_words_in_line+0xd2>
movl   $0x2,-0x1c(%rbp)
jmp    12c5 <kc_count_words_in_line+0x1b5>
movsbl -0x1d(%rbp),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
jne    1262 <kc_count_words_in_line+0x152>
movsbl -0x1d(%rbp),%eax
cmp    $0x2c,%eax
je     1262 <kc_count_words_in_line+0x152>
movsbl -0x1d(%rbp),%eax
cmp    $0x21,%eax
je     1262 <kc_count_words_in_line+0x152>
movsbl -0x1d(%rbp),%eax
cmp    $0x28,%eax
je     1262 <kc_count_words_in_line+0x152>
movsbl -0x1d(%rbp),%eax
cmp    $0x29,%eax
je     1262 <kc_count_words_in_line+0x152>
movsbl -0x1d(%rbp),%eax
cmp    $0x7b,%eax
je     1262 <kc_count_words_in_line+0x152>
movsbl -0x1d(%rbp),%eax
cmp    $0x7d,%eax
je     1262 <kc_count_words_in_line+0x152>
movsbl -0x1d(%rbp),%eax
cmp    $0x5b,%eax
je     1262 <kc_count_words_in_line+0x152>
movsbl -0x1d(%rbp),%eax
cmp    $0x5d,%eax
jne    1283 <kc_count_words_in_line+0x173>
cmpl   $0x0,-0x1c(%rbp)
jne    127e <kc_count_words_in_line+0x16e>
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    12c0 <kc_count_words_in_line+0x1b0>
cmpl   $0x1,-0x1c(%rbp)
jne    1299 <kc_count_words_in_line+0x189>
movl   $0x0,-0x1c(%rbp)
jmp    12bb <kc_count_words_in_line+0x1ab>
cmpl   $0x2,-0x1c(%rbp)
jne    12af <kc_count_words_in_line+0x19f>
movl   $0x3,-0x1c(%rbp)
jmp    12b6 <kc_count_words_in_line+0x1a6>
movl   $0x0,-0x1c(%rbp)
jmp    12bb <kc_count_words_in_line+0x1ab>
jmp    12c0 <kc_count_words_in_line+0x1b0>
jmp    12c5 <kc_count_words_in_line+0x1b5>
jmp    1135 <kc_count_words_in_line+0x25>
cmpl   $0xffffffff,-0x1c(%rbp)
je     12e0 <kc_count_words_in_line+0x1d0>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0x0,%eax
jne    130e <kc_count_words_in_line+0x1fe>
cmpl   $0x0,-0x1c(%rbp)
jne    1302 <kc_count_words_in_line+0x1f2>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1315 <kc_count_words_in_line+0x205>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kc_count_words_in_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,(%rsi)
mov    $0xffffffff,%r13d
movabs $0x1400000000000981,%r15
mov    $0x2e00,%r12d
jmp    1151 <kc_count_words_in_line+0x41>
nop
addl   $0x1,(%r14)
mov    %eax,%r13d
add    $0x1,%rbx
cmp    $0x3,%r13d
jge    11c7 <kc_count_words_in_line+0xb7>
movzbl (%rbx),%ebp
test   %bpl,%bpl
je     11cb <kc_count_words_in_line+0xbb>
cmp    $0xd,%bpl
ja     1181 <kc_count_words_in_line+0x71>
movzbl %bpl,%eax
bt     %rax,%r12
jae    1181 <kc_count_words_in_line+0x71>
mov    $0x2,%eax
test   %r13d,%r13d
je     1140 <kc_count_words_in_line+0x30>
cmp    $0xffffffff,%r13d
mov    $0x2,%r13d
jne    1147 <kc_count_words_in_line+0x37>
jmp    11c7 <kc_count_words_in_line+0xb7>
movsbl %bpl,%edi
call   1030 <isspace@plt>
test   %rax,%rax
jne    119f <kc_count_words_in_line+0x8f>
lea    -0x21(%rbp),%eax
cmp    $0x3c,%al
ja     11ab <kc_count_words_in_line+0x9b>
movzbl %al,%eax
bt     %rax,%r15
jae    11ab <kc_count_words_in_line+0x9b>
test   %r13d,%r13d
jne    1147 <kc_count_words_in_line+0x37>
mov    $0x1,%eax
jmp    1140 <kc_count_words_in_line+0x30>
cmp    $0x7d,%bpl
je     119f <kc_count_words_in_line+0x8f>
cmp    $0x7b,%bpl
je     119f <kc_count_words_in_line+0x8f>
xor    %eax,%eax
cmp    $0x2,%r13d
mov    $0x0,%r13d
jne    1147 <kc_count_words_in_line+0x37>
jmp    11d9 <kc_count_words_in_line+0xc9>
xor    %eax,%eax
jmp    11d9 <kc_count_words_in_line+0xc9>
mov    $0x1,%eax
test   %r13d,%r13d
jne    11d9 <kc_count_words_in_line+0xc9>
addl   $0x1,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @kc_count_words_in_line(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 -1, i32* %6
store i8 0, i8* %7
%8 = load i32*, i32** %5
store i32 0, i32* %8
br label %9
9: ; preds = %106, %2
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
store i8 %14, i8* %7
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br label %17
17: ; preds = %12, %9
%18 = phi i1 [ false, %9 ], [ %16, %12 ]
br i1 %18, label %19, label %107
19: ; preds = %17
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
%22 = load i8, i8* %7
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 11
br i1 %24, label %37, label %25
25: ; preds = %19
%26 = load i8, i8* %7
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 13
br i1 %28, label %37, label %29
29: ; preds = %25
%30 = load i8, i8* %7
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 10
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = load i8, i8* %7
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 9
br i1 %36, label %37, label %50
37: ; preds = %33, %29, %25, %19
%38 = load i32, i32* %6
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = load i32*, i32** %5
%42 = load i32, i32* %41
%43 = add nsw i32 %42, 1
store i32 %43, i32* %41
store i32 3, i32* %6
br label %44
44: ; preds = %40, %37
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %48
47: ; preds = %44
store i32 3, i32* %6
br label %49
48: ; preds = %44
store i32 2, i32* %6
br label %49
49: ; preds = %48, %47
br label %106
50: ; preds = %33
%51 = load i8, i8* %7
%52 = call i64 @isspace(i8 signext %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %86, label %54
54: ; preds = %50
%55 = load i8, i8* %7
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 44
br i1 %57, label %86, label %58
58: ; preds = %54
%59 = load i8, i8* %7
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 33
br i1 %61, label %86, label %62
62: ; preds = %58
%63 = load i8, i8* %7
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 40
br i1 %65, label %86, label %66
66: ; preds = %62
%67 = load i8, i8* %7
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 41
br i1 %69, label %86, label %70
70: ; preds = %66
%71 = load i8, i8* %7
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 123
br i1 %73, label %86, label %74
74: ; preds = %70
%75 = load i8, i8* %7
%76 = sext i8 %75 to i32
%77 = icmp eq i32 %76, 125
br i1 %77, label %86, label %78
78: ; preds = %74
%79 = load i8, i8* %7
%80 = sext i8 %79 to i32
%81 = icmp eq i32 %80, 91
br i1 %81, label %86, label %82
82: ; preds = %78
%83 = load i8, i8* %7
%84 = sext i8 %83 to i32
%85 = icmp eq i32 %84, 93
br i1 %85, label %86, label %94
86: ; preds = %82, %78, %74, %70, %66, %62, %58, %54, %50
%87 = load i32, i32* %6
%88 = icmp eq i32 %87, 0
br i1 %88, label %89, label %93
89: ; preds = %86
store i32 1, i32* %6
%90 = load i32*, i32** %5
%91 = load i32, i32* %90
%92 = add nsw i32 %91, 1
store i32 %92, i32* %90
br label %93
93: ; preds = %89, %86
br label %105
94: ; preds = %82
%95 = load i32, i32* %6
%96 = icmp eq i32 %95, 1
br i1 %96, label %97, label %98
97: ; preds = %94
store i32 0, i32* %6
br label %104
98: ; preds = %94
%99 = load i32, i32* %6
%100 = icmp eq i32 %99, 2
br i1 %100, label %101, label %102
101: ; preds = %98
store i32 3, i32* %6
br label %103
102: ; preds = %98
store i32 0, i32* %6
br label %103
103: ; preds = %102, %101
br label %104
104: ; preds = %103, %97
br label %105
105: ; preds = %104, %93
br label %106
106: ; preds = %105, %49
br label %9
107: ; preds = %17
%108 = load i32, i32* %6
%109 = icmp ne i32 %108, -1
br i1 %109, label %110, label %113
110: ; preds = %107
%111 = load i8*, i8** %4
%112 = getelementptr inbounds i8, i8* %111, i32 -1
store i8* %112, i8** %4
br label %113
113: ; preds = %110, %107
%114 = load i8, i8* %7
%115 = sext i8 %114 to i32
%116 = icmp eq i32 %115, 0
br i1 %116, label %117, label %125
117: ; preds = %113
%118 = load i32, i32* %6
%119 = icmp eq i32 %118, 0
br i1 %119, label %120, label %124
120: ; preds = %117
%121 = load i32*, i32** %5
%122 = load i32, i32* %121
%123 = add nsw i32 %122, 1
store i32 %123, i32* %121
br label %124
124: ; preds = %120, %117
store i32 1, i32* %3
br label %126
125: ; preds = %113
store i32 0, i32* %3
br label %126
126: ; preds = %125, %124
%127 = load i32, i32* %3
ret i32 %127
}

LLVM IR (-O2):
define i32 @kc_count_words_in_line(i8* nocapture %0, i32* nocapture %1) {
store i32 0, i32* %1
br label %3
3: ; preds = %2, %24
%4 = phi i32 [ -1, %2 ], [ %25, %24 ]
%5 = phi i8* [ %0, %2 ], [ %9, %24 ]
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %27, label %8
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %5, i64 1
switch i8 %6, label %11 [
i8 13, label %10
i8 11, label %10
i8 10, label %10
i8 9, label %10
]
10: ; preds = %8, %8, %8, %8
switch i32 %4, label %24 [
i32 0, label %20
i32 -1, label %32
]
11: ; preds = %8
%12 = tail call i64 @isspace(i8 signext %6)
%13 = freeze i64 %12
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
switch i8 %6, label %18 [
i8 125, label %16
i8 123, label %16
i8 93, label %16
i8 91, label %16
i8 44, label %16
i8 41, label %16
i8 40, label %16
i8 33, label %16
]
16: ; preds = %15, %15, %15, %15, %15, %15, %15, %15, %11
%17 = icmp eq i32 %4, 0
br i1 %17, label %20, label %24
18: ; preds = %15
%19 = icmp eq i32 %4, 2
br i1 %19, label %32, label %24
20: ; preds = %16, %10
%21 = phi i32 [ 2, %10 ], [ 1, %16 ]
%22 = load i32, i32* %1
%23 = add nsw i32 %22, 1
store i32 %23, i32* %1
br label %24
24: ; preds = %20, %18, %10, %16
%25 = phi i32 [ %4, %16 ], [ 0, %18 ], [ 2, %10 ], [ %21, %20 ]
%26 = icmp slt i32 %25, 3
br i1 %26, label %3, label %32
27: ; preds = %3
%28 = icmp eq i32 %4, 0
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = load i32, i32* %1
%31 = add nsw i32 %30, 1
store i32 %31, i32* %1
br label %32
32: ; preds = %18, %10, %24, %27, %29
%33 = phi i32 [ 1, %29 ], [ 1, %27 ], [ 0, %24 ], [ 0, %10 ], [ 0, %18 ]
ret i32 %33
}