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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
void *ftell(int /*<<< orphan*/ *);
size_t fsize(FILE *pFile) {
  long cbFile;
  off_t Pos = ftell(pFile);
  if (Pos >= 0 && !fseek(pFile, 0, SEEK_END)) {
    cbFile = ftell(pFile);
    if (cbFile >= 0 && !fseek(pFile, 0, SEEK_SET))
      return cbFile;
  }
  return 0;
}


x86 assembly (clang, -O0):
<fsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ftell@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jl     11a8 <fsize+0x88>
mov    -0x10(%rbp),%rdi
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
cmp    $0x0,%eax
jne    11a8 <fsize+0x88>
mov    -0x10(%rbp),%rdi
call   1030 <ftell@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jl     11a3 <fsize+0x83>
mov    -0x10(%rbp),%rdi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
cmp    $0x0,%eax
jne    11a3 <fsize+0x83>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b0 <fsize+0x90>
jmp    11a8 <fsize+0x88>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsize>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <ftell@plt>
test   %rax,%rax
js     116f <fsize+0x4f>
mov    0x2eb0(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
test   %eax,%eax
jne    116f <fsize+0x4f>
mov    %r14,%rdi
call   1030 <ftell@plt>
test   %rax,%rax
js     116f <fsize+0x4f>
mov    %rax,%rbx
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
test   %eax,%eax
je     1171 <fsize+0x51>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i64 @fsize(i32* %0) {
%2 = alloca i64
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = call i8* @ftell(i32* %6)
%8 = ptrtoint i8* %7 to i64
store i64 %8, i64* %5
%9 = load i64, i64* %5
%10 = icmp sge i64 %9, 0
br i1 %10, label %11, label %30
11: ; preds = %1
%12 = load i32*, i32** %3
%13 = load i32, i32* @SEEK_END
%14 = call i32 @fseek(i32* %12, i32 0, i32 %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %30, label %16
16: ; preds = %11
%17 = load i32*, i32** %3
%18 = call i8* @ftell(i32* %17)
%19 = ptrtoint i8* %18 to i64
store i64 %19, i64* %4
%20 = load i64, i64* %4
%21 = icmp sge i64 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %16
%23 = load i32*, i32** %3
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @fseek(i32* %23, i32 0, i32 %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %22
%28 = load i64, i64* %4
store i64 %28, i64* %2
br label %31
29: ; preds = %22, %16
br label %30
30: ; preds = %29, %11, %1
store i64 0, i64* %2
br label %31
31: ; preds = %30, %27
%32 = load i64, i64* %2
ret i64 %32
}

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