#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*/);
scalar_t__ is_non_blank_line(char *);
int /*<<< orphan*/ memset(char *, int, int);
int txt_file_wc(FILE *fp, int *linesp, int *wordsp, int *charsp) {
  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);
      if (is_non_blank_line(buffer)) {
        words += find_count_of_words(buffer);
      }
      chars += bytes;
    }
  } while (bytes > 0);
  *linesp = lines;
  *wordsp = words;
  *charsp = chars;
  return lines;
}


x86 assembly (clang, -O0):
<txt_file_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    0x2e27(%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    125f <txt_file_wc+0xff>
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   1080 <is_non_blank_line@plt>
cmp    $0x0,%rax
je     124e <txt_file_wc+0xee>
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    1264 <txt_file_wc+0x104>
cmpq   $0x0,-0x438(%rbp)
ja     11c4 <txt_file_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    -0x24(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<txt_file_wc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rcx,0x10(%rsp)
mov    %rdx,0x8(%rsp)
mov    %rsi,(%rsp)
mov    %rdi,%rbp
lea    0x20(%rsp),%r14
xor    %ebx,%ebx
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x3ff,%edx
mov    %rbp,0x18(%rsp)
mov    %rbp,%rcx
call   1030 <fread@plt>
mov    $0x0,%r13d
mov    $0x0,%r12d
test   %rax,%rax
je     1259 <txt_file_wc+0xf9>
mov    %rax,%r14
xor    %r12d,%r12d
lea    0x20(%rsp),%rbp
xor    %r13d,%r13d
xor    %ebx,%ebx
jmp    1234 <txt_file_wc+0xd4>
nopw   0x0(%rax,%rax,1)
add    %r15d,%ebx
add    %r14d,%r12d
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x3ff,%edx
mov    0x18(%rsp),%rcx
call   1030 <fread@plt>
mov    %rax,%r14
test   %rax,%rax
je     1259 <txt_file_wc+0xf9>
mov    %rbp,%rdi
call   1050 <find_count_of_lines@plt>
mov    %rax,%r15
mov    %rbp,%rdi
call   1080 <is_non_blank_line@plt>
test   %rax,%rax
je     1200 <txt_file_wc+0xa0>
mov    %rbp,%rdi
call   1070 <find_count_of_words@plt>
add    %eax,%r13d
jmp    1200 <txt_file_wc+0xa0>
mov    (%rsp),%rax
mov    %ebx,(%rax)
mov    0x8(%rsp),%rax
mov    %r13d,(%rax)
mov    0x10(%rsp),%rax
mov    %r12d,(%rax)
mov    %ebx,%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_file_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 = %50, %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 %49
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 @is_non_blank_line(i8* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %26
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%38 = call i64 @find_count_of_words(i8* %37)
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = add nsw i64 %40, %38
%42 = trunc i64 %41 to i32
store i32 %42, i32* %10
br label %43
43: ; preds = %36, %26
%44 = load i64, i64* %13
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = add i64 %46, %44
%48 = trunc i64 %47 to i32
store i32 %48, i32* %11
br label %49
49: ; preds = %43, %18
br label %50
50: ; preds = %49
%51 = load i64, i64* %13
%52 = icmp ugt i64 %51, 0
br i1 %52, label %18, label %53
53: ; preds = %50
%54 = load i32, i32* %9
%55 = load i32*, i32** %6
store i32 %54, i32* %55
%56 = load i32, i32* %10
%57 = load i32*, i32** %7
store i32 %56, i32* %57
%58 = load i32, i32* %11
%59 = load i32*, i32** %8
store i32 %58, i32* %59
%60 = load i32, i32* %9
ret i32 %60
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @txt_file_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 %33, label %12
12: ; preds = %4, %26
%13 = phi i64 [ %31, %26 ], [ %10, %4 ]
%14 = phi i32 [ %29, %26 ], [ 0, %4 ]
%15 = phi i32 [ %27, %26 ], [ 0, %4 ]
%16 = phi i32 [ %19, %26 ], [ 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 @is_non_blank_line(i8* %6)
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %12
%23 = call i64 @find_count_of_words(i8* %6)
%24 = trunc i64 %23 to i32
%25 = add i32 %15, %24
br label %26
26: ; preds = %12, %22
%27 = phi i32 [ %25, %22 ], [ %15, %12 ]
%28 = trunc i64 %13 to i32
%29 = add i32 %14, %28
%30 = call i32 @memset(i8* %6, i32 0, i32 1024)
%31 = call i64 @fread(i8* %6, i32 1, i32 1023, i32* %0)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %12
33: ; preds = %26, %4
%34 = phi i32 [ 0, %4 ], [ %19, %26 ]
%35 = phi i32 [ 0, %4 ], [ %27, %26 ]
%36 = phi i32 [ 0, %4 ], [ %29, %26 ]
store i32 %34, i32* %1
store i32 %35, i32* %2
store i32 %36, i32* %3
ret i32 %34
}