// File: /workspace/github_c_makefile_star2_O2/richarddurbin[P]hash10x/moshmap.c
// Function: referenceRead
Reference *referenceRead (char *root)
{
  FILE *f ;
  if (!(f = fopenTag (root, "mosh", "r"))) die ("failed to open %s.mosh to read", root) ;
  Moshset *ms = moshsetRead (f) ;
  fclose (f) ;
  if (!(f = fopenTag (root, "ref", "r"))) die ("failed to open %s.ref to read", root) ;
  char name[8] ;
  if (fread (name,8,1,f) != 1) die ("failed to read reference header") ;
  if (strcmp (name, "RFMSHv1")) die ("bad reference header") ;
  U32 size ; if (fread (&size,sizeof(U32),1,f) != 1) die ("failed to read size") ;
  Reference *ref = referenceCreate (ms, size) ;
  if (fread (&ref->max,sizeof(U32),1,f) != 1) die ("failed to read max") ;
  if (fread (ref->index,sizeof(U32),size,f) != size) die ("failed read ref index") ;
  if (fread (ref->offset,sizeof(U32),size,f) != size) die ("failed read ref offset") ;
  if (fread (ref->id,sizeof(U32),size,f) != size) die ("failed read ref id") ;
  if (fread (ref->depth,sizeof(U32),ref->ms->max+1,f) != ref->ms->max+1) die ("fail depth") ;
  ref->rev = new (size, U32) ; ref->loc = new (ref->ms->max+1, U32) ;
  if (fread (ref->rev,sizeof(U32),size,f) != size) die ("fail rev") ;
  if (fread (ref->loc,sizeof(U32),ref->ms->max+1,f) != ref->ms->max+1) die ("fail loc") ;
  arrayDestroy (ref->len) ; if (!(ref->len = arrayRead (f))) die ("failed read ref len") ;
  dictDestroy (ref->dict) ; if (!(ref->dict = dictRead (f))) die ("failed read ref dict") ;
  fclose (f) ;
  return ref ;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %r15
leaq 0x46a5(%rip), %rsi      # 0x6102
leaq 0x4833(%rip), %rdx      # 0x6297
callq 0x5d89
movq %rax, %rbx
testq %rax, %rax
jne 0x1a82
leaq 0x47af(%rip), %rdi      # 0x6227
movq %r15, %rsi
xorl %eax, %eax
callq 0x5b50
movq %rbx, %rdi
callq 0x452d
movq %rax, %r14
movq %rbx, %rdi
callq 0x1090
leaq 0x468b(%rip), %rsi      # 0x6127
leaq 0x47f4(%rip), %rdx      # 0x6297
movq %r15, %rdi
callq 0x5d89
movq %rax, %rbx
testq %rax, %rax
jne 0x1ac4
leaq 0x478c(%rip), %rdi      # 0x6246
movq %r15, %rsi
xorl %eax, %eax
callq 0x5b50
leaq 0x8(%rsp), %rdi
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x1080
cmpq $0x1, %rax
je 0x1aeb
leaq 0x4780(%rip), %rdi      # 0x6264
xorl %eax, %eax
callq 0x5b50
movabsq $0x317648534d4652, %rax # imm = 0x317648534D4652
cmpq %rax, 0x8(%rsp)
je 0x1b0a
leaq 0x4781(%rip), %rdi      # 0x6284
xorl %eax, %eax
callq 0x5b50
leaq 0x4(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x1080
cmpq $0x1, %rax
je 0x1b31
leaq 0x476f(%rip), %rdi      # 0x6299
xorl %eax, %eax
callq 0x5b50
movl 0x4(%rsp), %r15d
movq %r14, %rdi
movl %r15d, %esi
callq 0x131c
movq %rax, %r14
leaq 0xc(%rax), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x1080
cmpq $0x1, %rax
je 0x1b6a
leaq 0x474a(%rip), %rdi      # 0x62ad
xorl %eax, %eax
callq 0x5b50
movq 0x10(%r14), %rdi
pushq $0x4
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x1080
cmpq %r15, %rax
je 0x1b8f
leaq 0x4738(%rip), %rdi      # 0x62c0
xorl %eax, %eax
callq 0x5b50
movq 0x18(%r14), %rdi
pushq $0x4
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x1080
cmpq %r15, %rax
je 0x1bb4
leaq 0x4729(%rip), %rdi      # 0x62d6
xorl %eax, %eax
callq 0x5b50
movq 0x20(%r14), %rdi
pushq $0x4
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x1080
cmpq %r15, %rax
je 0x1bd9
leaq 0x471b(%rip), %rdi      # 0x62ed
xorl %eax, %eax
callq 0x5b50
movq (%r14), %rax
movq 0x28(%r14), %rdi
movl 0x40(%rax), %edx
incl %edx
pushq $0x4
popq %rsi
movq %rbx, %rcx
callq 0x1080
movq (%r14), %rcx
movl 0x40(%rcx), %ecx
incl %ecx
cmpq %rcx, %rax
je 0x1c0b
leaq 0x45db(%rip), %rdi      # 0x61df
xorl %eax, %eax
callq 0x5b50
leaq (,%r15,4), %rdi
callq 0x5c10
movq %rax, 0x30(%r14)
movq (%r14), %rax
movl 0x40(%rax), %edi
incl %edi
shlq $0x2, %rdi
callq 0x5c10
movq %rax, 0x38(%r14)
movq 0x30(%r14), %rdi
pushq $0x4
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x1080
cmpq %r15, %rax
je 0x1c56
leaq 0x459b(%rip), %rdi      # 0x61ea
xorl %eax, %eax
callq 0x5b50
movq (%r14), %rax
movq 0x38(%r14), %rdi
movl 0x40(%rax), %edx
incl %edx
pushq $0x4
popq %rsi
movq %rbx, %rcx
callq 0x1080
movq (%r14), %rcx
movl 0x40(%rcx), %ecx
incl %ecx
cmpq %rcx, %rax
je 0x1c88
leaq 0x4572(%rip), %rdi      # 0x61f3
xorl %eax, %eax
callq 0x5b50
movq 0x48(%r14), %rdi
callq 0x551c
movq %rbx, %rdi
callq 0x57a2
movq %rax, 0x48(%r14)
testq %rax, %rax
jne 0x1cb0
leaq 0x4657(%rip), %rdi      # 0x6300
xorl %eax, %eax
callq 0x5b50
movq 0x40(%r14), %rdi
callq 0x4e82
movq %rbx, %rdi
callq 0x4fc2
movq %rax, 0x40(%r14)
testq %rax, %rax
jne 0x1cd8
leaq 0x4643(%rip), %rdi      # 0x6314
xorl %eax, %eax
callq 0x5b50
movq %rbx, %rdi
callq 0x1090
movq %r14, %rax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq