#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ S_IRUSR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int ft_file_len(char *argv) {
  int i;
  int fd;
  char buf[1];
  i = 0;
  fd = open(argv, O_RDONLY, S_IRUSR);
  if (fd == -1)
    return (0);
  while (read(fd, buf, 1)) {
    i++;
  }
  close(fd);
  return (i + 1);
}


x86 assembly (clang, -O0):
<ft_file_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1177 <ft_file_len+0x47>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <ft_file_len+0x86>
jmp    117c <ft_file_len+0x4c>
mov    -0x18(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
je     11a5 <ft_file_len+0x75>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117c <ft_file_len+0x4c>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_file_len>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
mov    (%rax),%edx
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1180 <ft_file_len+0x50>
mov    %eax,%ebp
xor    %ebx,%ebx
lea    0xf(%rsp),%r14
nopl   (%rax)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    1160 <ft_file_len+0x30>
mov    %ebp,%edi
call   1030 <close@plt>
jmp    1182 <ft_file_len+0x52>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@O_RDONLY = global i32 0
@S_IRUSR = global i32 0
define i32 @ft_file_len(i8* nocapture %0) {
%2 = alloca [1 x i8]
%3 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDONLY
%5 = load i32, i32* @S_IRUSR
%6 = tail call i32 @open(i8* %0, i32 %4, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %15, label %8
8: ; preds = %1, %8
%9 = phi i32 [ %12, %8 ], [ 1, %1 ]
%10 = call i64 @read(i32 %6, i8* %3, i32 1)
%11 = icmp eq i64 %10, 0
%12 = add i32 %9, 1
br i1 %11, label %13, label %8
13: ; preds = %8
%14 = tail call i32 @close(i32 %6)
br label %15
15: ; preds = %1, %13
%16 = phi i32 [ %9, %13 ], [ 0, %1 ]
ret i32 %16
}