#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*/ *, int, int /*<<< orphan*/);
void *ftell(int /*<<< orphan*/ *);
unsigned int STEAM_FileSize(FILE *file) {
  unsigned int iRet;
  if (!file) {
    iRet = 0;
  } else {
    int iPos;
    iPos = ftell(file);
    fseek(file, 0, SEEK_END);
    iRet = ftell(file);
    fseek(file, iPos, SEEK_SET);
  }
  return iRet;
}


x86 assembly (clang, -O0):
<STEAM_FileSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1143 <STEAM_FileSize+0x23>
movl   $0x0,-0xc(%rbp)
jmp    1184 <STEAM_FileSize+0x64>
mov    -0x8(%rbp),%rdi
call   1030 <ftell@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e8e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1030 <ftell@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<STEAM_FileSize>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1169 <STEAM_FileSize+0x49>
mov    %rdi,%rbx
call   1030 <ftell@plt>
mov    %rax,%r15
mov    0x2eac(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
mov    %rbx,%rdi
call   1030 <ftell@plt>
mov    %rax,%r14
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <fseek@plt>
jmp    116c <STEAM_FileSize+0x4c>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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