#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 /*<<< orphan*/ fseek(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
size_t file_get_size(FILE *file) {
  size_t pos, len;
  len = 0;
  if (file && (pos = ftell(file)) != -1) {
    len = !fseek(file, 0, SEEK_END) ? ftell(file) : 0;
    fseek(file, pos, SEEK_SET);
  }
  return len;
}


x86 assembly (clang, -O0):
<file_get_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11b0 <file_get_size+0x90>
mov    -0x8(%rbp),%rdi
call   1030 <ftell@plt>
mov    %rax,-0x10(%rbp)
cmp    $0xffffffffffffffff,%rax
je     11b0 <file_get_size+0x90>
mov    -0x8(%rbp),%rdi
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <fseek@plt>
cmp    $0x0,%eax
jne    1187 <file_get_size+0x67>
mov    -0x8(%rbp),%rdi
call   1030 <ftell@plt>
mov    %rax,-0x20(%rbp)
jmp    1192 <file_get_size+0x72>
xor    %eax,%eax
mov    %rax,-0x20(%rbp)
jmp    1192 <file_get_size+0x72>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_get_size>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1176 <file_get_size+0x56>
mov    %rdi,%rbx
call   1030 <ftell@plt>
cmp    $0xffffffffffffffff,%rax
je     1176 <file_get_size+0x56>
mov    %rax,%r15
mov    0x2ea6(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
test   %eax,%eax
jne    1160 <file_get_size+0x40>
mov    %rbx,%rdi
call   1030 <ftell@plt>
mov    %rax,%r14
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <fseek@plt>
jmp    1179 <file_get_size+0x59>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i64 @file_get_size(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i64
store i32* %0, i32** %2
store i64 0, i64* %4
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %26
7: ; preds = %1
%8 = load i32*, i32** %2
%9 = call i64 @ftell(i32* %8)
store i64 %9, i64* %3
%10 = icmp ne i64 %9, -1
br i1 %10, label %11, label %26
11: ; preds = %7
%12 = load i32*, i32** %2
%13 = load i32, i32* @SEEK_END
%14 = call i32 @fseek(i32* %12, i64 0, i32 %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = load i32*, i32** %2
%18 = call i64 @ftell(i32* %17)
br label %20
19: ; preds = %11
br label %20
20: ; preds = %19, %16
%21 = phi i64 [ %18, %16 ], [ 0, %19 ]
store i64 %21, i64* %4
%22 = load i32*, i32** %2
%23 = load i64, i64* %3
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @fseek(i32* %22, i64 %23, i32 %24)
br label %26
26: ; preds = %20, %7, %1
%27 = load i64, i64* %4
ret i64 %27
}

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