#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_CUR;
int /*<<< orphan*/ SEEK_END;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int, int);
scalar_t__ strcmp(char *, char *);
scalar_t__ strtol(char *, char **, int);
int getXrefLocation(FILE *file) {
  fseek(file, -(24), SEEK_END);
  char *xrefBuf = (char *)calloc(9, 1);
  fread(xrefBuf, 9, 1, file);
  int result = 0;
  if (strcmp(xrefBuf, "startxref") == 0) {
    memset(xrefBuf, 0x00, 8);
    fseek(file, 1, SEEK_CUR);
    fread(xrefBuf, 6, 1, file);
    result = (int)strtol(xrefBuf, (char **)NULL, 10);
  }
  free(xrefBuf);
  return result;
}


x86 assembly (clang, -O0):
<getXrefLocation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffe8,%esi
call   1090 <fseek@plt>
mov    $0x9,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x9,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1231 <getXrefLocation+0xc1>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1090 <fseek@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x6,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getXrefLocation>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffe8,%esi
call   1090 <fseek@plt>
mov    $0x9,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x9,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
lea    0xe47(%rip),%rsi
mov    %r15,%rdi
call   1070 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    1214 <getXrefLocation+0xa4>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0x1,%esi
call   1090 <fseek@plt>
mov    %r15,%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [10 x i8] c"startxref\00"
@SEEK_CUR = global i32 0
define i32 @getXrefLocation(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = load i32, i32* @SEEK_END
%7 = call i32 @fseek(i32* %5, i32 -24, i32 %6)
%8 = call i64 @calloc(i32 9, i32 1)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = load i32*, i32** %2
%12 = call i32 @fread(i8* %10, i32 9, i32 1, i32* %11)
store i32 0, i32* %4
%13 = load i8*, i8** %3
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = call i32 @memset(i8* %17, i32 0, i32 8)
%19 = load i32*, i32** %2
%20 = load i32, i32* @SEEK_CUR
%21 = call i32 @fseek(i32* %19, i32 1, i32 %20)
%22 = load i8*, i8** %3
%23 = load i32*, i32** %2
%24 = call i32 @fread(i8* %22, i32 6, i32 1, i32* %23)
%25 = load i8*, i8** %3
%26 = call i64 @strtol(i8* %25, i8** null, i32 10)
%27 = trunc i64 %26 to i32
store i32 %27, i32* %4
br label %28
28: ; preds = %16, %1
%29 = load i8*, i8** %3
%30 = call i32 @free(i8* %29)
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@.str = [10 x i8] c"startxref\00"
@SEEK_CUR = global i32 0
define i32 @getXrefLocation(i32* nocapture %0) {
%2 = load i32, i32* @SEEK_END
%3 = tail call i32 @fseek(i32* %0, i32 -24, i32 %2)
%4 = tail call i64 @calloc(i32 9, i32 1)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @fread(i8* %5, i32 9, i32 1, i32* %0)
%7 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = tail call i32 @memset(i8* %5, i32 0, i32 8)
%11 = load i32, i32* @SEEK_CUR
%12 = tail call i32 @fseek(i32* %0, i32 1, i32 %11)
%13 = tail call i32 @fread(i8* %5, i32 6, i32 1, i32* %0)
%14 = tail call i64 @strtol(i8* nocapture %5, i8** null, i32 10)
%15 = trunc i64 %14 to i32
br label %16
16: ; preds = %9, %1
%17 = phi i32 [ %15, %9 ], [ 0, %1 ]
%18 = tail call i32 @free(i8* %5)
ret i32 %17
}