#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 */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
long file_size(FILE *f) {
  long len;
  if (fseek(f, 0L, SEEK_END))
    return -1L;
  if ((len = ftell(f)) == -1L)
    return -1L;
  if (fseek(f, 0L, SEEK_SET))
    return -1L;
  return len;
}


x86 assembly (clang, -O0):
<file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2eb1(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <fseek@plt>
cmp    $0x0,%rax
je     1159 <file_size+0x39>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11b2 <file_size+0x92>
mov    -0x10(%rbp),%rdi
call   1030 <ftell@plt>
mov    %rax,-0x18(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    117d <file_size+0x5d>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11b2 <file_size+0x92>
mov    -0x10(%rbp),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <fseek@plt>
cmp    $0x0,%rax
je     11aa <file_size+0x8a>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11b2 <file_size+0x92>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_size>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2eb9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
mov    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1171 <file_size+0x51>
mov    %r14,%rdi
call   1030 <ftell@plt>
cmp    $0xffffffffffffffff,%rax
je     1171 <file_size+0x51>
mov    %rax,%r15
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
neg    %rax
sbb    %rbx,%rbx
or     %r15,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i64 @file_size(i32* %0) {
%2 = alloca i64
%3 = alloca i32*
%4 = alloca i64
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = load i32, i32* @SEEK_END
%7 = call i64 @fseek(i32* %5, i64 0, i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i64 -1, i64* %2
br label %23
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = call i64 @ftell(i32* %11)
store i64 %12, i64* %4
%13 = icmp eq i64 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %10
store i64 -1, i64* %2
br label %23
15: ; preds = %10
%16 = load i32*, i32** %3
%17 = load i32, i32* @SEEK_SET
%18 = call i64 @fseek(i32* %16, i64 0, i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i64 -1, i64* %2
br label %23
21: ; preds = %15
%22 = load i64, i64* %4
store i64 %22, i64* %2
br label %23
23: ; preds = %21, %20, %14, %9
%24 = load i64, i64* %2
ret i64 %24
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i64 @file_size(i32* nocapture %0) {
%2 = load i32, i32* @SEEK_END
%3 = tail call i64 @fseek(i32* %0, i64 0, i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %1
%6 = tail call i64 @ftell(i32* %0)
%7 = icmp eq i64 %6, -1
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = load i32, i32* @SEEK_SET
%10 = tail call i64 @fseek(i32* %0, i64 0, i32 %9)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i64 %6, i64 -1
br label %13
13: ; preds = %8, %5, %1
%14 = phi i64 [ -1, %1 ], [ -1, %5 ], [ %12, %8 ]
ret i64 %14
}