#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ fseek_err(int /*<<< orphan*/ *, unsigned long,
                             int /*<<< orphan*/);
unsigned long ftell_err(int /*<<< orphan*/ *);
unsigned long GetFileEndPos(FILE *fp) {
  unsigned long originalpos, endpos;
  (assert(fp != NULL));
  originalpos = ftell_err(fp);
  (void)fseek(fp, 0, SEEK_END);
  endpos = ftell_err(fp);
  fseek_err(fp, originalpos, SEEK_SET);
  return endpos;
}


x86 assembly (clang, -O0):
<GetFileEndPos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ftell_err@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ftell_err@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
call   1030 <fseek_err@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetFileEndPos>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1040 <ftell_err@plt>
mov    %rax,%r14
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rbx,%rdi
call   1040 <ftell_err@plt>
mov    %rax,%r15
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <fseek_err@plt>
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 @GetFileEndPos(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i64
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i32*, i32** %2
%10 = call i64 @ftell_err(i32* %9)
store i64 %10, i64* %3
%11 = load i32*, i32** %2
%12 = load i32, i32* @SEEK_END
%13 = call i32 @fseek(i32* %11, i32 0, i32 %12)
%14 = load i32*, i32** %2
%15 = call i64 @ftell_err(i32* %14)
store i64 %15, i64* %4
%16 = load i32*, i32** %2
%17 = load i64, i64* %3
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @fseek_err(i32* %16, i64 %17, i32 %18)
%20 = load i64, i64* %4
ret i64 %20
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i64 @GetFileEndPos(i32* %0) {
%2 = icmp ne i32* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i64 @ftell_err(i32* %0)
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @fseek(i32* %0, i32 0, i32 %6)
%8 = tail call i64 @ftell_err(i32* %0)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseek_err(i32* %0, i64 %5, i32 %9)
ret i64 %8
}