#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 get_size(FILE *f) {
  long size, pos;
  pos = ftell(f);
  if (pos >= 0) {
    if (fseek(f, 0, SEEK_END) < 0) {
      return -1;
    }
    size = ftell(f);
    if (fseek(f, pos, SEEK_SET) < 0) {
      return -1;
    }
    return size;
  } else {
    return pos;
  }
}


x86 assembly (clang, -O0):
<get_size>:
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     11b8 <get_size+0x98>
mov    -0x10(%rbp),%rdi
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <fseek@plt>
cmp    $0x0,%rax
jge    1171 <get_size+0x51>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11c0 <get_size+0xa0>
mov    -0x10(%rbp),%rdi
call   1030 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e4b(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
cmp    $0x0,%rax
jge    11ab <get_size+0x8b>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11c0 <get_size+0xa0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c0 <get_size+0xa0>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_size>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <ftell@plt>
mov    %rax,%rbx
test   %rax,%rax
js     1183 <get_size+0x63>
mov    0x2eac(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
test   %rax,%rax
js     117c <get_size+0x5c>
mov    %r14,%rdi
call   1030 <ftell@plt>
mov    %rax,%r15
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <fseek@plt>
test   %rax,%rax
mov    $0xffffffffffffffff,%rbx
cmovns %r15,%rbx
jmp    1183 <get_size+0x63>
mov    $0xffffffffffffffff,%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 @get_size(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 i64 @ftell(i32* %6)
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = icmp sge i64 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = load i32, i32* @SEEK_END
%13 = call i64 @fseek(i32* %11, i64 0, i32 %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
store i64 -1, i64* %2
br label %29
16: ; preds = %10
%17 = load i32*, i32** %3
%18 = call i64 @ftell(i32* %17)
store i64 %18, i64* %4
%19 = load i32*, i32** %3
%20 = load i64, i64* %5
%21 = load i32, i32* @SEEK_SET
%22 = call i64 @fseek(i32* %19, i64 %20, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %16
store i64 -1, i64* %2
br label %29
25: ; preds = %16
%26 = load i64, i64* %4
store i64 %26, i64* %2
br label %29
27: ; preds = %1
%28 = load i64, i64* %5
store i64 %28, i64* %2
br label %29
29: ; preds = %27, %25, %24, %15
%30 = load i64, i64* %2
ret i64 %30
}

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