#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*/ *);
int /*<<< orphan*/ perror(char *);
long get_file_size(FILE *fin) {
  long size, pos;
  pos = ftell(fin);
  if (fseek(fin, 0, SEEK_END) != 0) {
    perror("seek");
    return -1;
  }
  size = ftell(fin);
  if (fseek(fin, pos, SEEK_SET) != 0) {
    perror("seek");
    return -1;
  }
  return size;
}


x86 assembly (clang, -O0):
<get_file_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)
mov    -0x10(%rbp),%rdi
mov    0x2e94(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <fseek@plt>
cmp    $0x0,%rax
je     1182 <get_file_size+0x52>
lea    0xe90(%rip),%rdi
call   1050 <perror@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11d0 <get_file_size+0xa0>
mov    -0x10(%rbp),%rdi
call   1030 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
cmp    $0x0,%rax
je     11c8 <get_file_size+0x98>
lea    0xe4a(%rip),%rdi
call   1050 <perror@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11d0 <get_file_size+0xa0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_size>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <ftell@plt>
mov    %rax,%r14
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
test   %rax,%rax
jne    1185 <get_file_size+0x55>
mov    %rbx,%rdi
call   1030 <ftell@plt>
mov    %rax,%r15
mov    0x2e6e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <fseek@plt>
test   %rax,%rax
jne    1185 <get_file_size+0x55>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe74(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffffffffffff,%r15
jmp    117c <get_file_size+0x4c>

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [5 x i8] c"seek\00"
@SEEK_SET = global i32 0
define i64 @get_file_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 i32*, i32** %3
%9 = load i32, i32* @SEEK_END
%10 = call i64 @fseek(i32* %8, i64 0, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i64 -1, i64* %2
br label %26
14: ; preds = %1
%15 = load i32*, i32** %3
%16 = call i64 @ftell(i32* %15)
store i64 %16, i64* %4
%17 = load i32*, i32** %3
%18 = load i64, i64* %5
%19 = load i32, i32* @SEEK_SET
%20 = call i64 @fseek(i32* %17, i64 %18, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i64 -1, i64* %2
br label %26
24: ; preds = %14
%25 = load i64, i64* %4
store i64 %25, i64* %2
br label %26
26: ; preds = %24, %22, %12
%27 = load i64, i64* %2
ret i64 %27
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@.str = [5 x i8] c"seek\00"
@SEEK_SET = global i32 0
define i64 @get_file_size(i32* nocapture %0) {
%2 = tail call i64 @ftell(i32* %0)
%3 = load i32, i32* @SEEK_END
%4 = tail call i64 @fseek(i32* %0, i64 0, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = tail call i64 @ftell(i32* %0)
%8 = load i32, i32* @SEEK_SET
%9 = tail call i64 @fseek(i32* %0, i64 %2, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %6, %1
%12 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %6
%14 = phi i64 [ %7, %6 ], [ -1, %11 ]
ret i64 %14
}