#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
char EOF;
int /*<<< orphan*/ errno;
char fgetc(int /*<<< orphan*/ *);
scalar_t__ isalnum(char);
int CountWords(FILE *stream) {
  if (!stream) {
    errno = EINVAL;
    return 0;
  }
  int count = 0;
  char c;
  while (1) {
    c = fgetc(stream);
    if (isalnum(c)) {
      ++count;
      while (isalnum(c)) {
        c = fgetc(stream);
      }
    }
    if (c == EOF || c == '\0') {
      break;
    }
  }
  return count;
}


x86 assembly (clang, -O0):
<CountWords>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1155 <CountWords+0x35>
mov    0x2e92(%rip),%rax
mov    (%rax),%ecx
mov    0x2e91(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11e0 <CountWords+0xc0>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
je     11ad <CountWords+0x8d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movsbl -0x15(%rbp),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
je     11a8 <CountWords+0x88>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x15(%rbp)
jmp    1184 <CountWords+0x64>
jmp    11ad <CountWords+0x8d>
movsbl -0x15(%rbp),%eax
mov    0x2e30(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11d0 <CountWords+0xb0>
movsbl -0x15(%rbp),%eax
cmp    $0x0,%eax
jne    11d5 <CountWords+0xb5>
jmp    11da <CountWords+0xba>
jmp    115c <CountWords+0x3c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CountWords>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     119c <CountWords+0x7c>
mov    %rdi,%rbp
xor    %r14d,%r14d
mov    0x2eae(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
movsbl %al,%r15d
mov    %r15d,%edi
call   1030 <isalnum@plt>
test   %rax,%rax
je     1190 <CountWords+0x70>
add    $0x1,%r14d
mov    %r15d,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1030 <isalnum@plt>
test   %rax,%rax
je     1190 <CountWords+0x70>
mov    %rbp,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
movsbl %al,%edi
jmp    1170 <CountWords+0x50>
nopl   0x0(%rax)
test   %bl,%bl
je     11b1 <CountWords+0x91>
cmp    (%r12),%bl
jne    1140 <CountWords+0x20>
jmp    11b1 <CountWords+0x91>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    0x2e2c(%rip),%rcx
mov    %eax,(%rcx)
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
@EOF = global i8 0
define i32 @CountWords(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = load i32, i32* @EINVAL
store i32 %9, i32* @errno
store i32 0, i32* %2
br label %42
10: ; preds = %1
store i32 0, i32* %4
br label %11
11: ; preds = %10, %39
%12 = load i32*, i32** %3
%13 = call signext i8 @fgetc(i32* %12)
store i8 %13, i8* %5
%14 = load i8, i8* %5
%15 = call i64 @isalnum(i8 signext %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %11
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %20
20: ; preds = %24, %17
%21 = load i8, i8* %5
%22 = call i64 @isalnum(i8 signext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32*, i32** %3
%26 = call signext i8 @fgetc(i32* %25)
store i8 %26, i8* %5
br label %20
27: ; preds = %20
br label %28
28: ; preds = %27, %11
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
%31 = load i8, i8* @EOF
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %30, %32
br i1 %33, label %38, label %34
34: ; preds = %28
%35 = load i8, i8* %5
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34, %28
br label %40
39: ; preds = %34
br label %11
40: ; preds = %38
%41 = load i32, i32* %4
store i32 %41, i32* %2
br label %42
42: ; preds = %40, %8
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
@EOF = global i8 0
define i32 @CountWords(i32* %0) {
%2 = icmp eq i32* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = load i32, i32* @EINVAL
store i32 %4, i32* @errno
br label %25
5: ; preds = %1, %18
%6 = phi i32 [ %19, %18 ], [ 0, %1 ]
%7 = tail call signext i8 @fgetc(i32* %0)
%8 = tail call i64 @isalnum(i8 signext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %5
%11 = add nsw i32 %6, 1
%12 = tail call i64 @isalnum(i8 signext %7)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10, %14
%15 = tail call signext i8 @fgetc(i32* %0)
%16 = tail call i64 @isalnum(i8 signext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %14
18: ; preds = %14, %10, %5
%19 = phi i32 [ %6, %5 ], [ %11, %10 ], [ %11, %14 ]
%20 = phi i8 [ %7, %5 ], [ %7, %10 ], [ %15, %14 ]
%21 = load i8, i8* @EOF
%22 = icmp eq i8 %20, %21
%23 = icmp eq i8 %20, 0
%24 = or i1 %23, %22
br i1 %24, label %25, label %5
25: ; preds = %18, %3
%26 = phi i32 [ 0, %3 ], [ %19, %18 ]
ret i32 %26
}