#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*/);
void *ftell(int /*<<< orphan*/ *);
int CPNumberOfBytesInFile(FILE *fileRef, unsigned long *numBytesPtr) {
  long originalPos;
  originalPos = ftell(fileRef);
  if (fseek(fileRef, 0, SEEK_END) != 0)
    return 10005;
  *numBytesPtr = ftell(fileRef);
  if (*numBytesPtr == -1L)
    return 10005;
  if (fseek(fileRef, originalPos, SEEK_SET) != 0)
    return 10005;
  return 0;
}


x86 assembly (clang, -O0):
<CPNumberOfBytesInFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea0(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <fseek@plt>
cmp    $0x0,%rax
je     1169 <CPNumberOfBytesInFile+0x49>
movl   $0x2715,-0x4(%rbp)
jmp    11c9 <CPNumberOfBytesInFile+0xa9>
mov    -0x10(%rbp),%rdi
call   1030 <ftell@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0xffffffffffffffff,(%rax)
jne    1196 <CPNumberOfBytesInFile+0x76>
movl   $0x2715,-0x4(%rbp)
jmp    11c9 <CPNumberOfBytesInFile+0xa9>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
cmp    $0x0,%rax
je     11c2 <CPNumberOfBytesInFile+0xa2>
movl   $0x2715,-0x4(%rbp)
jmp    11c9 <CPNumberOfBytesInFile+0xa9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CPNumberOfBytesInFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <ftell@plt>
mov    %rax,%r14
mov    0x2eac(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
mov    $0x2715,%ebp
test   %rax,%rax
jne    1184 <CPNumberOfBytesInFile+0x64>
mov    %rbx,%rdi
call   1030 <ftell@plt>
mov    %rax,(%r15)
cmp    $0xffffffffffffffff,%rax
je     1184 <CPNumberOfBytesInFile+0x64>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <fseek@plt>
xor    %ecx,%ecx
test   %rax,%rax
mov    $0x2715,%ebp
cmove  %ecx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @CPNumberOfBytesInFile(i32* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64*
%6 = alloca i64
store i32* %0, i32** %4
store i64* %1, i64** %5
%7 = load i32*, i32** %4
%8 = call i8* @ftell(i32* %7)
%9 = ptrtoint i8* %8 to i64
store i64 %9, i64* %6
%10 = load i32*, i32** %4
%11 = load i32, i32* @SEEK_END
%12 = call i64 @fseek(i32* %10, i64 0, i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 10005, i32* %3
br label %32
15: ; preds = %2
%16 = load i32*, i32** %4
%17 = call i8* @ftell(i32* %16)
%18 = ptrtoint i8* %17 to i64
%19 = load i64*, i64** %5
store i64 %18, i64* %19
%20 = load i64*, i64** %5
%21 = load i64, i64* %20
%22 = icmp eq i64 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %15
store i32 10005, i32* %3
br label %32
24: ; preds = %15
%25 = load i32*, i32** %4
%26 = load i64, i64* %6
%27 = load i32, i32* @SEEK_SET
%28 = call i64 @fseek(i32* %25, i64 %26, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
store i32 10005, i32* %3
br label %32
31: ; preds = %24
store i32 0, i32* %3
br label %32
32: ; preds = %31, %30, %23, %14
%33 = load i32, i32* %3
ret i32 %33
}

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