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


x86 assembly (clang, -O0):
<get_file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <fseek@plt>
cmp    $0xffffffff,%eax
jne    1173 <get_file_size+0x43>
lea    0xe9e(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <get_file_size+0x8c>
mov    -0x10(%rbp),%rdi
call   1030 <ftell@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <fseek@plt>
cmp    $0xffffffff,%eax
jne    11b6 <get_file_size+0x86>
lea    0xe5b(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <get_file_size+0x8c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_size>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eab(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
cmp    $0xffffffff,%eax
je     1176 <get_file_size+0x46>
mov    %rbx,%rdi
call   1030 <ftell@plt>
mov    %eax,%ebp
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
cmp    $0xffffffff,%eax
je     1176 <get_file_size+0x46>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe83(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%ebp
jmp    116d <get_file_size+0x3d>

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [6 x i8] c"fseek\00"
@SEEK_SET = global i32 0
define i32 @get_file_size(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = load i32, i32* @SEEK_END
%7 = call i32 @fseek(i32* %5, i64 0, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %22
11: ; preds = %1
%12 = load i32*, i32** %3
%13 = call i32 @ftell(i32* %12)
store i32 %13, i32* %4
%14 = load i32*, i32** %3
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @fseek(i32* %14, i64 0, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %22
20: ; preds = %11
%21 = load i32, i32* %4
store i32 %21, i32* %2
br label %22
22: ; preds = %20, %18, %9
%23 = load i32, i32* %2
ret i32 %23
}

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