#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 find_file_size(FILE *fp) {
  long file_size;
  if (fseek(fp, 0L, SEEK_END)) {
    return -1;
  }
  file_size = ftell(fp);
  if (file_size < 0) {
    return -2;
  }
  if (fseek(fp, 0L, SEEK_SET)) {
    return -3;
  }
  return file_size;
}


x86 assembly (clang, -O0):
<find_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 <find_file_size+0x39>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11b3 <find_file_size+0x93>
mov    -0x10(%rbp),%rdi
call   1030 <ftell@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    117e <find_file_size+0x5e>
movq   $0xfffffffffffffffe,-0x8(%rbp)
ff
jmp    11b3 <find_file_size+0x93>
mov    -0x10(%rbp),%rdi
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <fseek@plt>
cmp    $0x0,%rax
je     11ab <find_file_size+0x8b>
movq   $0xfffffffffffffffd,-0x8(%rbp)
ff
jmp    11b3 <find_file_size+0x93>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_file_size>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eba(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
mov    %rax,%rcx
mov    $0xffffffffffffffff,%rax
test   %rcx,%rcx
jne    1180 <find_file_size+0x60>
mov    %rbx,%rdi
call   1030 <ftell@plt>
test   %rax,%rax
js     1179 <find_file_size+0x59>
mov    %rax,%r14
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
test   %rax,%rax
mov    $0xfffffffffffffffd,%rax
cmove  %r14,%rax
jmp    1180 <find_file_size+0x60>
mov    $0xfffffffffffffffe,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i64 @find_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 %24
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = call i64 @ftell(i32* %11)
store i64 %12, i64* %4
%13 = load i64, i64* %4
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
store i64 -2, i64* %2
br label %24
16: ; preds = %10
%17 = load i32*, i32** %3
%18 = load i32, i32* @SEEK_SET
%19 = call i64 @fseek(i32* %17, i64 0, i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i64 -3, i64* %2
br label %24
22: ; preds = %16
%23 = load i64, i64* %4
store i64 %23, i64* %2
br label %24
24: ; preds = %22, %21, %15, %9
%25 = load i64, i64* %2
ret i64 %25
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i64 @find_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 slt i64 %6, 0
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 -3
br label %13
13: ; preds = %8, %5, %1
%14 = phi i64 [ -1, %1 ], [ -2, %5 ], [ %12, %8 ]
ret i64 %14
}