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

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
char *malloc(int);
int zstrlen(char *);
int fzlen(const char *path) {
  FILE *f = fopen(path, "r");
  char *buff = malloc(1024);
  int ret = 0;
  while ((fgets(buff, sizeof(buff), f))) {
    ret = (ret + zstrlen(buff));
  }
  return ret;
}


x86 assembly (clang, -O0):
<fzlen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x8,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     11af <fzlen+0x6f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <zstrlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    1175 <fzlen+0x35>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fzlen>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x8,%esi
mov    %r14,%rdx
call   1030 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     119f <fzlen+0x5f>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <zstrlen@plt>
add    %eax,%ebp
mov    %rbx,%rdi
mov    $0x8,%esi
mov    %r14,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
jne    1180 <fzlen+0x40>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @fzlen(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = call i8* @malloc(i32 1024)
store i8* %8, i8** %4
store i32 0, i32* %5
br label %9
9: ; preds = %14, %1
%10 = load i8*, i8** %4
%11 = load i32*, i32** %3
%12 = call i64 @fgets(i8* %10, i32 8, i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i32, i32* %5
%16 = load i8*, i8** %4
%17 = call i32 @zstrlen(i8* %16)
%18 = add nsw i32 %15, %17
store i32 %18, i32* %5
br label %9
19: ; preds = %9
%20 = load i32, i32* %5
ret i32 %20
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @fzlen(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%4 = tail call i64 @fgets(i8* %3, i32 8, i32* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %1, %6
%7 = phi i32 [ %9, %6 ], [ 0, %1 ]
%8 = tail call i32 @zstrlen(i8* %3)
%9 = add nsw i32 %8, %7
%10 = tail call i64 @fgets(i8* %3, i32 8, i32* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %6
12: ; preds = %6, %1
%13 = phi i32 [ 0, %1 ], [ %9, %6 ]
ret i32 %13
}