#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;
int fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
long int fsize(FILE *stream) {
  long int size;
  if (fseek(stream, 0, SEEK_END) == -1) {
    return -1;
  }
  size = ftell(stream);
  if (size == -1) {
    return -1;
  }
  if (fseek(stream, 0, SEEK_SET) == -1) {
    return -1;
  }
  return size;
}


x86 assembly (clang, -O0):
<fsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2eb1(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
cmp    $0xffffffff,%eax
jne    1156 <fsize+0x36>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11ad <fsize+0x8d>
mov    -0x10(%rbp),%rdi
call   1030 <ftell@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    117b <fsize+0x5b>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11ad <fsize+0x8d>
mov    -0x10(%rbp),%rdi
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
cmp    $0xffffffff,%eax
jne    11a5 <fsize+0x85>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11ad <fsize+0x8d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsize>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x2eb9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
mov    $0xffffffffffffffff,%r15
cmp    $0xffffffff,%eax
je     1179 <fsize+0x59>
mov    %rbx,%rdi
call   1030 <ftell@plt>
cmp    $0xffffffffffffffff,%rax
je     1179 <fsize+0x59>
mov    %rax,%r14
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
cmp    $0xffffffff,%eax
mov    $0xffffffffffffffff,%rax
cmove  %rax,%r14
mov    %r14,%r15
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
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
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = load i32, i32* @SEEK_END
%7 = call i32 @fseek(i32* %5, i32 0, i32 %6)
%8 = icmp eq i32 %7, -1
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 eq i64 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %10
store i64 -1, i64* %2
br label %24
16: ; preds = %10
%17 = load i32*, i32** %3
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @fseek(i32* %17, i32 0, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %16
store i64 -1, 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 @fsize(i32* nocapture %0) {
%2 = load i32, i32* @SEEK_END
%3 = tail call i32 @fseek(i32* %0, i32 0, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %13, label %5
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 i32 @fseek(i32* %0, i32 0, i32 %9)
%11 = icmp eq i32 %10, -1
%12 = select i1 %11, i64 -1, i64 %6
br label %13
13: ; preds = %8, %5, %1
%14 = phi i64 [ -1, %1 ], [ -1, %5 ], [ %12, %8 ]
ret i64 %14
}