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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
scalar_t__ find_count_of_lines(char *);
scalar_t__ find_count_of_words(char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int, int);
int txt_my_wc(FILE *fp, int *lines_p, int *words_p, int *chars_p) {
  int lines = 0, words = 0, chars = 0;
  char buffer[1024] = {0x00};
  size_t bytes = 0;
  fseek(fp, 0L, SEEK_SET);
  do {
    memset(buffer, 0x00, sizeof(buffer));
    bytes = fread(buffer, sizeof(char), sizeof(buffer) - 1, fp);
    if (bytes > 0) {
      lines += find_count_of_lines(buffer);
      words += find_count_of_words(buffer);
      chars += bytes;
    }
  } while (bytes > 0);
  *lines_p = lines;
  *words_p = words;
  *chars_p = chars;
  return chars;
}


x86 assembly (clang, -O0):
<txt_my_wc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
movq   $0x0,-0x438(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <fseek@plt>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x430(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3ff,%edx
call   1030 <fread@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x438(%rbp)
jbe    1239 <txt_my_wc+0xe9>
lea    -0x430(%rbp),%rdi
call   1050 <find_count_of_lines@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
lea    -0x430(%rbp),%rdi
call   1070 <find_count_of_words@plt>
mov    %rax,%rcx
movslq -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x438(%rbp),%rcx
movslq -0x2c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x2c(%rbp)
jmp    123e <txt_my_wc+0xee>
cmpq   $0x0,-0x438(%rbp)
ja     11b4 <txt_my_wc+0x64>
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<txt_my_wc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rcx,0x18(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    %rdi,%r13
lea    0x20(%rsp),%rbx
xor    %r15d,%r15d
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x3ff,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
mov    $0x0,%r12d
mov    $0x0,%ebp
test   %rax,%rax
je     1235 <txt_my_wc+0xe5>
mov    %rax,%r14
xor    %ebp,%ebp
lea    0x20(%rsp),%rbx
xor    %r12d,%r12d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <find_count_of_lines@plt>
add    %eax,%r15d
mov    %rbx,%rdi
call   1070 <find_count_of_words@plt>
add    %eax,%r12d
add    %r14d,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x3ff,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11f0 <txt_my_wc+0xa0>
mov    0x8(%rsp),%rax
mov    %r15d,(%rax)
mov    0x10(%rsp),%rax
mov    %r12d,(%rax)
mov    0x18(%rsp),%rax
mov    %ebp,(%rax)
mov    %ebp,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @txt_my_wc(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [1024 x i8]
%13 = alloca i64
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%14 = bitcast [1024 x i8]* %12 to i8*
store i64 0, i64* %13
%15 = load i32*, i32** %5
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @fseek(i32* %15, i64 0, i32 %16)
br label %18
18: ; preds = %45, %4
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 1024)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%22 = load i32*, i32** %5
%23 = call i64 @fread(i8* %21, i32 1, i32 1023, i32* %22)
store i64 %23, i64* %13
%24 = load i64, i64* %13
%25 = icmp ugt i64 %24, 0
br i1 %25, label %26, label %44
26: ; preds = %18
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%28 = call i64 @find_count_of_lines(i8* %27)
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = add nsw i64 %30, %28
%32 = trunc i64 %31 to i32
store i32 %32, i32* %9
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%34 = call i64 @find_count_of_words(i8* %33)
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = add nsw i64 %36, %34
%38 = trunc i64 %37 to i32
store i32 %38, i32* %10
%39 = load i64, i64* %13
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = add i64 %41, %39
%43 = trunc i64 %42 to i32
store i32 %43, i32* %11
br label %44
44: ; preds = %26, %18
br label %45
45: ; preds = %44
%46 = load i64, i64* %13
%47 = icmp ugt i64 %46, 0
br i1 %47, label %18, label %48
48: ; preds = %45
%49 = load i32, i32* %9
%50 = load i32*, i32** %6
store i32 %49, i32* %50
%51 = load i32, i32* %10
%52 = load i32*, i32** %7
store i32 %51, i32* %52
%53 = load i32, i32* %11
%54 = load i32*, i32** %8
store i32 %53, i32* %54
%55 = load i32, i32* %11
ret i32 %55
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @txt_my_wc(i32* nocapture %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @fseek(i32* %0, i64 0, i32 %7)
%9 = call i32 @memset(i8* %6, i32 0, i32 1024)
%10 = call i64 @fread(i8* %6, i32 1, i32 1023, i32* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %28, label %12
12: ; preds = %4, %12
%13 = phi i64 [ %26, %12 ], [ %10, %4 ]
%14 = phi i32 [ %24, %12 ], [ 0, %4 ]
%15 = phi i32 [ %22, %12 ], [ 0, %4 ]
%16 = phi i32 [ %19, %12 ], [ 0, %4 ]
%17 = call i64 @find_count_of_lines(i8* %6)
%18 = trunc i64 %17 to i32
%19 = add i32 %16, %18
%20 = call i64 @find_count_of_words(i8* %6)
%21 = trunc i64 %20 to i32
%22 = add i32 %15, %21
%23 = trunc i64 %13 to i32
%24 = add i32 %14, %23
%25 = call i32 @memset(i8* %6, i32 0, i32 1024)
%26 = call i64 @fread(i8* %6, i32 1, i32 1023, i32* %0)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %12
28: ; preds = %12, %4
%29 = phi i32 [ 0, %4 ], [ %19, %12 ]
%30 = phi i32 [ 0, %4 ], [ %22, %12 ]
%31 = phi i32 [ 0, %4 ], [ %24, %12 ]
store i32 %29, i32* %1
store i32 %30, i32* %2
store i32 %31, i32* %3
ret i32 %31
}