#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 */
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
scalar_t__ strlen(char *);
size_t HowManyEntries(FILE *fHandle, size_t *bytes) {
  size_t entryCount = 0;
  char buf[512], *s;
  *bytes = 0;
  while ((s = fgets(buf, 512, fHandle))) {
    if (s) {
      entryCount++;
      *bytes += strlen(s);
    }
  }
  rewind(fHandle);
  return entryCount;
}


x86 assembly (clang, -O0):
<HowManyEntries>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
mov    %rax,-0x228(%rbp)
cmp    $0x0,%rax
je     11b4 <HowManyEntries+0x84>
cmpq   $0x0,-0x228(%rbp)
je     11af <HowManyEntries+0x7f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x228(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
jmp    1156 <HowManyEntries+0x26>
mov    -0x8(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x18(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HowManyEntries>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
movq   $0x0,(%rsi)
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1194 <HowManyEntries+0x64>
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rax,%rdi
call   1030 <strlen@plt>
add    %rax,(%r15)
add    $0x1,%rbx
mov    %r12,%rdi
mov    $0x200,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1170 <HowManyEntries+0x40>
mov    %r14,%rdi
call   1040 <rewind@plt>
mov    %rbx,%rax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @HowManyEntries(i32* %0, i64* %1) {
%3 = alloca i32*
%4 = alloca i64*
%5 = alloca i64
%6 = alloca [512 x i8]
%7 = alloca i8*
store i32* %0, i32** %3
store i64* %1, i64** %4
store i64 0, i64* %5
%8 = load i64*, i64** %4
store i64 0, i64* %8
br label %9
9: ; preds = %25, %2
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i8* @fgets(i8* %10, i32 512, i32* %11)
store i8* %12, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %26
14: ; preds = %9
%15 = load i8*, i8** %7
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load i64, i64* %5
%19 = add i64 %18, 1
store i64 %19, i64* %5
%20 = load i8*, i8** %7
%21 = call i64 @strlen(i8* %20)
%22 = load i64*, i64** %4
%23 = load i64, i64* %22
%24 = add i64 %23, %21
store i64 %24, i64* %22
br label %25
25: ; preds = %17, %14
br label %9
26: ; preds = %9
%27 = load i32*, i32** %3
%28 = call i32 @rewind(i32* %27)
%29 = load i64, i64* %5
ret i64 %29
}

LLVM IR (-O2):
define i64 @HowManyEntries(i32* nocapture %0, i64* nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
store i64 0, i64* %1
%5 = call i8* @fgets(i8* %4, i32 512, i32* %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %16, label %7
7: ; preds = %2, %7
%8 = phi i8* [ %14, %7 ], [ %5, %2 ]
%9 = phi i64 [ %13, %7 ], [ 0, %2 ]
%10 = call i64 @strlen(i8* %8)
%11 = load i64, i64* %1
%12 = add i64 %11, %10
store i64 %12, i64* %1
%13 = add i64 %9, 1
%14 = call i8* @fgets(i8* %4, i32 512, i32* %0)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %7
16: ; preds = %7, %2
%17 = phi i64 [ 0, %2 ], [ %13, %7 ]
%18 = call i32 @rewind(i32* %0)
ret i64 %17
}