#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ stolower(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int wcount(FILE *fp, char *word) {
  char buf[1024];
  int count = 0;
  if (fp == NULL || word == NULL)
    return 0;
  while (!feof(fp)) {
    fscanf(fp, "%s", buf);
    strcpy(buf, stolower(buf));
    if (strcmp(buf, word) == 0)
      count++;
  }
  return count;
}


x86 assembly (clang, -O0):
<wcount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x424(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1183 <wcount+0x33>
cmpq   $0x0,-0x18(%rbp)
jne    118f <wcount+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    1228 <wcount+0xd8>
jmp    1194 <wcount+0x44>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b2 <wcount+0x62>
jmp    121f <wcount+0xcf>
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xe3c(%rip),%rsi
call   1040 <fscanf@plt>
lea    -0x420(%rbp),%rax
mov    %rax,-0x430(%rbp)
lea    -0x420(%rbp),%rdi
call   1070 <stolower@plt>
mov    -0x430(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    121a <wcount+0xca>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    1194 <wcount+0x44>
mov    -0x424(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcount>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
xor    %ebx,%ebx
test   %rdi,%rdi
je     11ce <wcount+0x7e>
mov    %rsi,%r14
test   %rsi,%rsi
je     11ce <wcount+0x7e>
mov    %rdi,%r15
call   1060 <feof@plt>
test   %eax,%eax
jne    11ce <wcount+0x7e>
xor    %ebx,%ebx
lea    0xe7c(%rip),%r12
mov    %rsp,%r13
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1040 <fscanf@plt>
mov    %r13,%rdi
call   1070 <stolower@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
cmp    $0x1,%rax
adc    $0x0,%ebx
mov    %r15,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1190 <wcount+0x40>
mov    %ebx,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i32 @wcount(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 0, i32* %7
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %10, %2
store i32 0, i32* %3
br label %38
14: ; preds = %10
br label %15
15: ; preds = %35, %14
%16 = load i32*, i32** %4
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %36
20: ; preds = %15
%21 = load i32*, i32** %4
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = call i32 @stolower(i8* %25)
%27 = call i32 @strcpy(i8* %24, i32 %26)
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%29 = load i8*, i8** %5
%30 = call i64 @strcmp(i8* %28, i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %20
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %35
35: ; preds = %32, %20
br label %15
36: ; preds = %15
%37 = load i32, i32* %7
store i32 %37, i32* %3
br label %38
38: ; preds = %36, %13
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @wcount(i32* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32* %0, null
%6 = icmp eq i8* %1, null
%7 = or i1 %5, %6
br i1 %7, label %22, label %8
8: ; preds = %2
%9 = call i32 @feof(i32* %0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %8, %11
%12 = phi i32 [ %19, %11 ], [ 0, %8 ]
%13 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%14 = call i32 @stolower(i8* %4)
%15 = call i32 @strcpy(i8* %4, i32 %14)
%16 = call i64 @strcmp(i8* %4, i8* %1)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %12, %18
%20 = call i32 @feof(i32* %0)
%21 = icmp eq i32 %20, 0
br i1 %21, label %11, label %22
22: ; preds = %11, %8, %2
%23 = phi i32 [ 0, %2 ], [ 0, %8 ], [ %19, %11 ]
ret i32 %23
}