#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_SET;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int getXrefLocation(int /*<<< orphan*/ *);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, ...);
int *readXrefTable(FILE *file, int *entryCount) {
  int xrefStart = getXrefLocation(file) + 5;
  fseek(file, xrefStart, SEEK_SET);
  char nums[6];
  fread(nums, 5, 1, file);
  nums[5] = '\0';
  int start, count;
  sscanf(nums, "%d %d\x0a", &start, &count);
  if (start == 0 && count == 0)
    return NULL;
  int *offsets = (int *)calloc(count, sizeof(int));
  char nextEntry[20];
  int offset, generation;
  char usageFlag;
  for (int i = 0; i < count; i++) {
    fread(nextEntry, 20, 1, file);
    sscanf(nextEntry, "%d %d %c", &offset, &generation, &usageFlag);
    if (usageFlag == 'n')
      offsets[i] = offset;
  }
  *entryCount = count;
  return offsets;
}


x86 assembly (clang, -O0):
<readXrefTable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getXrefLocation@plt>
add    $0x5,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
lea    -0x22(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x5,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
movb   $0x0,-0x1d(%rbp)
lea    -0x22(%rbp),%rdi
lea    0xe56(%rip),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
mov    $0x0,%al
call   1060 <sscanf@plt>
cmpl   $0x0,-0x28(%rbp)
jne    11da <readXrefTable+0x8a>
cmpl   $0x0,-0x2c(%rbp)
jne    11da <readXrefTable+0x8a>
movq   $0x0,-0x8(%rbp)
jmp    1272 <readXrefTable+0x122>
mov    -0x2c(%rbp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1261 <readXrefTable+0x111>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x14,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
lea    -0x50(%rbp),%rdi
lea    0xde7(%rip),%rsi
lea    -0x54(%rbp),%rdx
lea    -0x58(%rbp),%rcx
lea    -0x59(%rbp),%r8
mov    $0x0,%al
call   1060 <sscanf@plt>
movsbl -0x59(%rbp),%eax
cmp    $0x6e,%eax
jne    124e <readXrefTable+0xfe>
mov    -0x54(%rbp),%edx
mov    -0x38(%rbp),%rax
movslq -0x60(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1253 <readXrefTable+0x103>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    11f2 <readXrefTable+0xa2>
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readXrefTable>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <getXrefLocation@plt>
lea    0x5(%rax),%esi
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
call   1070 <fseek@plt>
lea    0x1a(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
movb   $0x0,0x1f(%rsp)
lea    0xe5d(%rip),%rsi
xor    %ebp,%ebp
lea    0xc(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <sscanf@plt>
mov    0x4(%rsp),%edi
mov    0xc(%rsp),%eax
or     %edi,%eax
je     1270 <readXrefTable+0x120>
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%rbp
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    126d <readXrefTable+0x11d>
mov    %rbp,0x10(%rsp)
mov    %r14,0x20(%rsp)
lea    0x30(%rsp),%rbx
lea    0x8(%rsp),%rbp
lea    0x2c(%rsp),%r14
lea    0x3(%rsp),%r15
xor    %r13d,%r13d
jmp    121e <readXrefTable+0xce>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r13
movslq 0x4(%rsp),%rax
cmp    %rax,%r13
jge    1263 <readXrefTable+0x113>
mov    %rbx,%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
lea    0xdca(%rip),%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1060 <sscanf@plt>
cmpb   $0x6e,0x3(%rsp)
jne    1210 <readXrefTable+0xc0>
mov    0x8(%rsp),%eax
mov    0x10(%rsp),%rcx
mov    %eax,(%rcx,%r13,4)
jmp    1210 <readXrefTable+0xc0>
mov    0x20(%rsp),%r14
mov    0x10(%rsp),%rbp
mov    %eax,(%r14)
mov    %rbp,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [7 x i8] c"%d %d\0A\00"
@.str.1 = [9 x i8] c"%d %d %c\00"
define i32* @readXrefTable(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [6 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca [20 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
%15 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%16 = load i32*, i32** %4
%17 = call i32 @getXrefLocation(i32* %16)
%18 = add nsw i32 %17, 5
store i32 %18, i32* %6
%19 = load i32*, i32** %4
%20 = load i32, i32* %6
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @fseek(i32* %19, i32 %20, i32 %21)
%23 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%24 = load i32*, i32** %4
%25 = call i32 @fread(i8* %23, i32 5, i32 1, i32* %24)
%26 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 5
store i8 0, i8* %26
%27 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%28 = call i32 (i8*, i8*, i32*, i32*, ...) @sscanf(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %9)
%29 = load i32, i32* %8
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %2
%32 = load i32, i32* %9
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %31
store i32* null, i32** %3
br label %66
35: ; preds = %31, %2
%36 = load i32, i32* %9
%37 = call i64 @calloc(i32 %36, i32 4)
%38 = inttoptr i64 %37 to i32*
store i32* %38, i32** %10
store i32 0, i32* %15
br label %39
39: ; preds = %59, %35
%40 = load i32, i32* %15
%41 = load i32, i32* %9
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %62
43: ; preds = %39
%44 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%45 = load i32*, i32** %4
%46 = call i32 @fread(i8* %44, i32 20, i32 1, i32* %45)
%47 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%48 = call i32 (i8*, i8*, i32*, i32*, ...) @sscanf(i8* %47, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %12, i32* %13, i8* %14)
%49 = load i8, i8* %14
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 110
br i1 %51, label %52, label %58
52: ; preds = %43
%53 = load i32, i32* %12
%54 = load i32*, i32** %10
%55 = load i32, i32* %15
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
store i32 %53, i32* %57
br label %58
58: ; preds = %52, %43
br label %59
59: ; preds = %58
%60 = load i32, i32* %15
%61 = add nsw i32 %60, 1
store i32 %61, i32* %15
br label %39
62: ; preds = %39
%63 = load i32, i32* %9
%64 = load i32*, i32** %5
store i32 %63, i32* %64
%65 = load i32*, i32** %10
store i32* %65, i32** %3
br label %66
66: ; preds = %62, %34
%67 = load i32*, i32** %3
ret i32* %67
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [7 x i8] c"%d %d\0A\00"
@.str.1 = [9 x i8] c"%d %d %c\00"
define i32* @readXrefTable(i32* %0, i32* nocapture writeonly %1) {
%3 = alloca [6 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca [20 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = tail call i32 @getXrefLocation(i32* %0)
%11 = add nsw i32 %10, 5
%12 = load i32, i32* @SEEK_SET
%13 = tail call i32 @fseek(i32* %0, i32 %11, i32 %12)
%14 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%15 = call i32 @fread(i8* %14, i32 5, i32 1, i32* %0)
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 5
store i8 0, i8* %16
%17 = bitcast i32* %4 to i8*
%18 = bitcast i32* %5 to i8*
%19 = call i32 (i8*, i8*, i32*, i32*, ...) @sscanf(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5)
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 0
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, 0
%24 = select i1 %21, i1 %23, i1 false
br i1 %24, label %49, label %25
25: ; preds = %2
%26 = call i64 @calloc(i32 %22, i32 4)
%27 = inttoptr i64 %26 to i32*
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%29 = bitcast i32* %7 to i8*
%30 = bitcast i32* %8 to i8*
%31 = load i32, i32* %5
%32 = icmp sgt i32 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %44, %25
%34 = phi i32 [ %31, %25 ], [ %46, %44 ]
store i32 %34, i32* %1
br label %49
35: ; preds = %25, %44
%36 = phi i64 [ %45, %44 ], [ 0, %25 ]
%37 = call i32 @fread(i8* %28, i32 20, i32 1, i32* %0)
%38 = call i32 (i8*, i8*, i32*, i32*, ...) @sscanf(i8* %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %7, i32* %8, i8* %9)
%39 = load i8, i8* %9
%40 = icmp eq i8 %39, 110
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = load i32, i32* %7
%43 = getelementptr inbounds i32, i32* %27, i64 %36
store i32 %42, i32* %43
br label %44
44: ; preds = %35, %41
%45 = add nuw nsw i64 %36, 1
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = icmp slt i64 %45, %47
br i1 %48, label %35, label %33
49: ; preds = %2, %33
%50 = phi i32* [ %27, %33 ], [ null, %2 ]
ret i32* %50
}