#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;
int /*<<< orphan*/ ENOMEM;
char EOF;
char *calloc(int const, int);
int /*<<< orphan*/ errno;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ isalnum(char);
int /*<<< orphan*/ isblank(char);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *strtok(char *, char *);
int IsWordIn(FILE *stream, int (*isWord)(const char *)) {
  if (!stream || !isWord) {
    errno = EINVAL;
    return 0;
  }
  const int DEFAULT_BUFFER_CAPACITY = 4;
  const int CAPACITY_MULTIPLIER = 2;
  char *buffer = calloc(DEFAULT_BUFFER_CAPACITY, sizeof(char));
  if (!buffer) {
    errno = ENOMEM;
    return 0;
  }
  int capacity = DEFAULT_BUFFER_CAPACITY;
  int count = 0;
  char c;
  while ((c = fgetc(stream)) != EOF && c != '\0') {
    if (!isblank(c) && !isalnum(c)) {
      continue;
    }
    if (count >= capacity - 1) {
      capacity = (capacity > 0) ? capacity * CAPACITY_MULTIPLIER
                                : DEFAULT_BUFFER_CAPACITY;
      char *newBuffer = calloc(capacity, sizeof(char));
      if (!newBuffer) {
        errno = ENOMEM;
        return 0;
      }
      memcpy(newBuffer, buffer, count);
      free(buffer);
      buffer = newBuffer;
    }
    buffer[count] = c;
    ++count;
  }
  buffer[count] = '\0';
  ++count;
  char *word = strtok(buffer, " ");
  while (word != NULL) {
    if (isWord(word)) {
      return 1;
    }
    word = strtok(NULL, " ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<IsWordIn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1196 <IsWordIn+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    11b4 <IsWordIn+0x44>
mov    0x2e2b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e2a(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    139e <IsWordIn+0x22e>
movl   $0x4,-0x1c(%rbp)
movl   $0x2,-0x20(%rbp)
mov    $0x4,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11fe <IsWordIn+0x8e>
mov    0x2df1(%rip),%rax
mov    (%rax),%ecx
mov    0x2de0(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    139e <IsWordIn+0x22e>
movl   $0x4,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x31(%rbp)
movsbl %al,%ecx
mov    0x2dc6(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x49(%rbp)
je     123f <IsWordIn+0xcf>
movsbl -0x31(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    124f <IsWordIn+0xdf>
jmp    132b <IsWordIn+0x1bb>
movsbl -0x31(%rbp),%edi
call   1050 <isblank@plt>
cmp    $0x0,%eax
jne    1278 <IsWordIn+0x108>
movsbl -0x31(%rbp),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%eax
jne    1278 <IsWordIn+0x108>
jmp    120c <IsWordIn+0x9c>
mov    -0x30(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     130f <IsWordIn+0x19f>
cmpl   $0x0,-0x2c(%rbp)
jle    12a1 <IsWordIn+0x131>
mov    -0x2c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    12ae <IsWordIn+0x13e>
mov    $0x4,%eax
mov    %eax,-0x50(%rbp)
jmp    12ae <IsWordIn+0x13e>
mov    -0x50(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12ee <IsWordIn+0x17e>
mov    0x2d01(%rip),%rax
mov    (%rax),%ecx
mov    0x2cf0(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    139e <IsWordIn+0x22e>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x31(%rbp),%dl
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    120c <IsWordIn+0x9c>
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xcb5(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1397 <IsWordIn+0x227>
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rdi
call   *%rax
cmp    $0x0,%eax
je     137e <IsWordIn+0x20e>
movl   $0x1,-0x4(%rbp)
jmp    139e <IsWordIn+0x22e>
xor    %eax,%eax
mov    %eax,%edi
lea    0xc77(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x48(%rbp)
jmp    1354 <IsWordIn+0x1e4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IsWordIn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e43(%rip),%rcx
test   %rdi,%rdi
je     12ea <IsWordIn+0x17a>
mov    %rsi,%rbx
test   %rsi,%rsi
je     12ea <IsWordIn+0x17a>
mov    %rdi,%r12
mov    $0x4,%r15d
mov    $0x4,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    0x2e1f(%rip),%rcx
test   %rax,%rax
je     12ea <IsWordIn+0x17a>
mov    %rax,0x8(%rsp)
mov    %rbx,0x10(%rsp)
xor    %eax,%eax
mov    %rax,(%rsp)
mov    0x2e0f(%rip),%r14
mov    $0x4,%r13d
nop
mov    %r12,%rdi
call   1060 <fgetc@plt>
test   %al,%al
je     1294 <IsWordIn+0x124>
mov    %eax,%ebx
cmp    (%r14),%al
je     1294 <IsWordIn+0x124>
movsbl %bl,%ebp
mov    %ebp,%edi
call   1050 <isblank@plt>
test   %eax,%eax
jne    1214 <IsWordIn+0xa4>
mov    %ebp,%edi
call   1040 <isalnum@plt>
test   %eax,%eax
je     11e0 <IsWordIn+0x70>
lea    -0x1(%r13),%eax
cltq
mov    (%rsp),%rcx
cmp    %rax,%rcx
jge    122a <IsWordIn+0xba>
mov    0x8(%rsp),%rax
jmp    127f <IsWordIn+0x10f>
test   %r13d,%r13d
lea    0x0(%r13,%r13,1),%eax
mov    %eax,%r13d
cmovle %r15d,%r13d
mov    %r13d,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
test   %rax,%rax
je     12e3 <IsWordIn+0x173>
mov    %rax,%r15
mov    %rax,%rdi
mov    0x8(%rsp),%rbp
mov    %rbp,%rsi
mov    (%rsp),%rdx
mov    %rdx,(%rsp)
call   1080 <memcpy@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    (%rsp),%rcx
mov    %r15,%rax
mov    $0x4,%r15d
mov    %rax,0x8(%rsp)
mov    %bl,(%rax,%rcx,1)
add    $0x1,%rcx
mov    %rcx,(%rsp)
jmp    11e0 <IsWordIn+0x70>
mov    (%rsp),%eax
mov    0x8(%rsp),%rdi
movb   $0x0,(%rdi,%rax,1)
lea    0xd59(%rip),%rsi
call   1090 <strtok@plt>
test   %rax,%rax
je     12f5 <IsWordIn+0x185>
lea    0xd48(%rip),%r14
mov    0x10(%rsp),%rbx
nopl   (%rax)
mov    %rax,%rdi
call   *%rbx
test   %eax,%eax
jne    12dc <IsWordIn+0x16c>
xor    %ebp,%ebp
xor    %edi,%edi
mov    %r14,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
jne    12c0 <IsWordIn+0x150>
jmp    12f7 <IsWordIn+0x187>
mov    $0x1,%ebp
jmp    12f7 <IsWordIn+0x187>
mov    0x2cee(%rip),%rcx
mov    (%rcx),%eax
mov    0x2cdd(%rip),%rcx
mov    %eax,(%rcx)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
@ENOMEM = global i32 0
@EOF = global i8 0
@.str = [2 x i8] c" \00"
define i32 @IsWordIn(i32* %0, i32 (i8*)* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32 (i8*)*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i8*
%13 = alloca i8*
store i32* %0, i32** %4
store i32 (i8*)* %1, i32 (i8*)** %5
%14 = load i32*, i32** %4
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32 (i8*)*, i32 (i8*)** %5
%18 = icmp ne i32 (i8*)* %17, null
br i1 %18, label %21, label %19
19: ; preds = %16, %2
%20 = load i32, i32* @EINVAL
store i32 %20, i32* @errno
store i32 0, i32* %3
br label %107
21: ; preds = %16
store i32 4, i32* %6
store i32 2, i32* %7
%22 = call i8* @calloc(i32 4, i32 1)
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = icmp ne i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = load i32, i32* @ENOMEM
store i32 %26, i32* @errno
store i32 0, i32* %3
br label %107
27: ; preds = %21
store i32 4, i32* %9
store i32 0, i32* %10
br label %28
28: ; preds = %78, %49, %27
%29 = load i32*, i32** %4
%30 = call signext i8 @fgetc(i32* %29)
store i8 %30, i8* %11
%31 = sext i8 %30 to i32
%32 = load i8, i8* @EOF
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %31, %33
br i1 %34, label %35, label %39
35: ; preds = %28
%36 = load i8, i8* %11
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 0
br label %39
39: ; preds = %35, %28
%40 = phi i1 [ false, %28 ], [ %38, %35 ]
br i1 %40, label %41, label %86
41: ; preds = %39
%42 = load i8, i8* %11
%43 = call i32 @isblank(i8 signext %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %50, label %45
45: ; preds = %41
%46 = load i8, i8* %11
%47 = call i32 @isalnum(i8 signext %46)
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %45
br label %28
50: ; preds = %45, %41
%51 = load i32, i32* %10
%52 = load i32, i32* %9
%53 = sub nsw i32 %52, 1
%54 = icmp sge i32 %51, %53
br i1 %54, label %55, label %78
55: ; preds = %50
%56 = load i32, i32* %9
%57 = icmp sgt i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32, i32* %9
%60 = mul nsw i32 %59, 2
br label %62
61: ; preds = %55
br label %62
62: ; preds = %61, %58
%63 = phi i32 [ %60, %58 ], [ 4, %61 ]
store i32 %63, i32* %9
%64 = load i32, i32* %9
%65 = call i8* @calloc(i32 %64, i32 1)
store i8* %65, i8** %12
%66 = load i8*, i8** %12
%67 = icmp ne i8* %66, null
br i1 %67, label %70, label %68
68: ; preds = %62
%69 = load i32, i32* @ENOMEM
store i32 %69, i32* @errno
store i32 0, i32* %3
br label %107
70: ; preds = %62
%71 = load i8*, i8** %12
%72 = load i8*, i8** %8
%73 = load i32, i32* %10
%74 = call i32 @memcpy(i8* %71, i8* %72, i32 %73)
%75 = load i8*, i8** %8
%76 = call i32 @free(i8* %75)
%77 = load i8*, i8** %12
store i8* %77, i8** %8
br label %78
78: ; preds = %70, %50
%79 = load i8, i8* %11
%80 = load i8*, i8** %8
%81 = load i32, i32* %10
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
store i8 %79, i8* %83
%84 = load i32, i32* %10
%85 = add nsw i32 %84, 1
store i32 %85, i32* %10
br label %28
86: ; preds = %39
%87 = load i8*, i8** %8
%88 = load i32, i32* %10
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %87, i64 %89
store i8 0, i8* %90
%91 = load i32, i32* %10
%92 = add nsw i32 %91, 1
store i32 %92, i32* %10
%93 = load i8*, i8** %8
%94 = call i8* @strtok(i8* %93, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %94, i8** %13
br label %95
95: ; preds = %104, %86
%96 = load i8*, i8** %13
%97 = icmp ne i8* %96, null
br i1 %97, label %98, label %106
98: ; preds = %95
%99 = load i32 (i8*)*, i32 (i8*)** %5
%100 = load i8*, i8** %13
%101 = call i32 %99(i8* %100)
%102 = icmp ne i32 %101, 0
br i1 %102, label %103, label %104
103: ; preds = %98
store i32 1, i32* %3
br label %107
104: ; preds = %98
%105 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %105, i8** %13
br label %95
106: ; preds = %95
store i32 0, i32* %3
br label %107
107: ; preds = %106, %103, %68, %25, %19
%108 = load i32, i32* %3
ret i32 %108
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
@ENOMEM = global i32 0
@EOF = global i8 0
@.str = [2 x i8] c" \00"
define i32 @IsWordIn(i32* %0, i32 (i8*)* %1) {
%3 = icmp ne i32* %0, null
%4 = icmp ne i32 (i8*)* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %56
6: ; preds = %2
%7 = tail call dereferenceable_or_null(4) i8* @calloc(i32 4, i32 1)
%8 = icmp eq i8* %7, null
br i1 %8, label %56, label %40
9: ; preds = %40, %18
%10 = tail call signext i8 @fgetc(i32* %0)
%11 = load i8, i8* @EOF
%12 = icmp ne i8 %10, %11
%13 = icmp ne i8 %10, 0
%14 = and i1 %13, %12
br i1 %14, label %15, label %44
15: ; preds = %9
%16 = tail call i32 @isblank(i8 signext %10)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call i32 @isalnum(i8 signext %10)
%20 = icmp eq i32 %19, 0
br i1 %20, label %9, label %21
21: ; preds = %18, %15
%22 = add nsw i32 %42, -1
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %41, %23
br i1 %24, label %35, label %25
25: ; preds = %21
%26 = icmp sgt i32 %42, 0
%27 = shl nsw i32 %42, 1
%28 = select i1 %26, i32 %27, i32 4
%29 = tail call i8* @calloc(i32 %28, i32 1)
%30 = icmp eq i8* %29, null
br i1 %30, label %56, label %31
31: ; preds = %25
%32 = trunc i64 %41 to i32
%33 = tail call i32 @memcpy(i8* %29, i8* %43, i32 %32)
%34 = tail call i32 @free(i8* %43)
br label %35
35: ; preds = %31, %21
%36 = phi i32 [ %28, %31 ], [ %42, %21 ]
%37 = phi i8* [ %29, %31 ], [ %43, %21 ]
%38 = getelementptr inbounds i8, i8* %37, i64 %41
store i8 %10, i8* %38
%39 = add nuw i64 %41, 1
br label %40
40: ; preds = %6, %35
%41 = phi i64 [ %39, %35 ], [ 0, %6 ]
%42 = phi i32 [ %36, %35 ], [ 4, %6 ]
%43 = phi i8* [ %37, %35 ], [ %7, %6 ]
br label %9
44: ; preds = %9
%45 = and i64 %41, 4294967295
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 0, i8* %46
%47 = tail call i8* @strtok(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%48 = icmp eq i8* %47, null
br i1 %48, label %59, label %49
49: ; preds = %44, %53
%50 = phi i8* [ %54, %53 ], [ %47, %44 ]
%51 = tail call i32 %1(i8* %50)
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %49
%54 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%55 = icmp eq i8* %54, null
br i1 %55, label %59, label %49
56: ; preds = %25, %6, %2
%57 = phi i32* [ @EINVAL, %2 ], [ @ENOMEM, %6 ], [ @ENOMEM, %25 ]
%58 = load i32, i32* %57
store i32 %58, i32* @errno
br label %59
59: ; preds = %53, %49, %56, %44
%60 = phi i32 [ 0, %44 ], [ 0, %56 ], [ 0, %53 ], [ 1, %49 ]
ret i32 %60
}