#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_char(char *, 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_file_number_of_char(FILE *fp, char ch) {
  int lines = 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_char(buffer, ch);
    }
  } while (bytes > 0);
  return lines;
}


x86 assembly (clang, -O0):
<txt_file_number_of_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
movq   $0x0,-0x418(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1050 <fseek@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3ff,%edx
call   1030 <fread@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jbe    11ef <txt_file_number_of_char+0xaf>
lea    -0x410(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1060 <find_count_of_char@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
jmp    11f4 <txt_file_number_of_char+0xb4>
cmpq   $0x0,-0x418(%rbp)
ja     1190 <txt_file_number_of_char+0x50>
mov    -0x10(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<txt_file_number_of_char>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
mov    %rsp,%rbp
xor    %ebx,%ebx
mov    $0x400,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x3ff,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11e6 <txt_file_number_of_char+0xa6>
xor    %ebx,%ebx
movsbl %r15b,%r15d
mov    %rsp,%rbp
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r15d,%esi
call   1060 <find_count_of_char@plt>
add    %eax,%ebx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x3ff,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    11b0 <txt_file_number_of_char+0x70>
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @txt_file_number_of_char(i32* %0, i8 signext %1) {
%3 = alloca i32*
%4 = alloca i8
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca i64
store i32* %0, i32** %3
store i8 %1, i8* %4
store i32 0, i32* %5
%8 = bitcast [1024 x i8]* %6 to i8*
store i64 0, i64* %7
%9 = load i32*, i32** %3
%10 = load i32, i32* @SEEK_SET
%11 = call i32 @fseek(i32* %9, i64 0, i32 %10)
br label %12
12: ; preds = %29, %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 1024)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = load i32*, i32** %3
%17 = call i64 @fread(i8* %15, i32 1, i32 1023, i32* %16)
store i64 %17, i64* %7
%18 = load i64, i64* %7
%19 = icmp ugt i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %12
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%22 = load i8, i8* %4
%23 = call i64 @find_count_of_char(i8* %21, i8 signext %22)
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = add nsw i64 %25, %23
%27 = trunc i64 %26 to i32
store i32 %27, i32* %5
br label %28
28: ; preds = %20, %12
br label %29
29: ; preds = %28
%30 = load i64, i64* %7
%31 = icmp ugt i64 %30, 0
br i1 %31, label %12, label %32
32: ; preds = %29
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @txt_file_number_of_char(i32* nocapture %0, i8 signext %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @SEEK_SET
%6 = tail call i32 @fseek(i32* %0, i64 0, i32 %5)
%7 = call i32 @memset(i8* %4, i32 0, i32 1024)
%8 = call i64 @fread(i8* %4, i32 1, i32 1023, i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %2, %10
%11 = phi i32 [ %14, %10 ], [ 0, %2 ]
%12 = call i64 @find_count_of_char(i8* %4, i8 signext %1)
%13 = trunc i64 %12 to i32
%14 = add i32 %11, %13
%15 = call i32 @memset(i8* %4, i32 0, i32 1024)
%16 = call i64 @fread(i8* %4, i32 1, i32 1023, i32* %0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %10
18: ; preds = %10, %2
%19 = phi i32 [ 0, %2 ], [ %14, %10 ]
ret i32 %19
}