#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 */
scalar_t__ EOF;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ assert_file_exist(char *);
int /*<<< orphan*/ fatal(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int lenchars_file(char *fn) {
  assert_file_exist(fn);
  FILE *fd = fopen(fn, "r");
  if (fseek(fd, 0, SEEK_END) == EOF)
    fatal("seek failed");
  int len = ftell(fd);
  fclose(fd);
  return len;
}


x86 assembly (clang, -O0):
<lenchars_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <assert_file_exist@plt>
mov    -0x8(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%rax
jne    11b9 <lenchars_file+0x59>
lea    0xe4e(%rip),%rdi
call   1080 <fatal@plt>
mov    -0x10(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lenchars_file>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <assert_file_exist@plt>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    0x2e64(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    0x2e49(%rip),%rcx
cmp    (%rcx),%rax
jne    11a8 <lenchars_file+0x48>
lea    0xe5f(%rip),%rdi
call   1080 <fatal@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@EOF = global i64 0
@.str.1 = [12 x i8] c"seek failed\00"
define i32 @lenchars_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @assert_file_exist(i8* %5)
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = load i32, i32* @SEEK_END
%11 = call i64 @fseek(i32* %9, i32 0, i32 %10)
%12 = load i64, i64* @EOF
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @fatal(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
%17 = load i32*, i32** %3
%18 = call i32 @ftell(i32* %17)
store i32 %18, i32* %4
%19 = load i32*, i32** %3
%20 = call i32 @fclose(i32* %19)
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@EOF = global i64 0
@.str.1 = [12 x i8] c"seek failed\00"
define i32 @lenchars_file(i8* %0) {
%2 = tail call i32 @assert_file_exist(i8* %0)
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @SEEK_END
%5 = tail call i64 @fseek(i32* %3, i32 0, i32 %4)
%6 = load i64, i64* @EOF
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @fatal(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = tail call i32 @ftell(i32* %3)
%12 = tail call i32 @fclose(i32* %3)
ret i32 %11
}