// File: /workspace/github_c_makefile_star2_O2/richarddurbin[P]hash10x/moshmap.c
// Function: referenceWrite
void referenceWrite (Reference *ref, char *root)
{
  FILE *f ;
  if (!(f = fopenTag (root, "mosh", "w"))) die ("failed to open %s.mosh to write", root) ;
  moshsetWrite (ref->ms, f) ;
  fclose (f) ;
  if (!(f = fopenTag (root, "ref", "w"))) die ("failed to open %s.ref to write", root) ;
  if (fwrite ("RFMSHv1",8,1,f) != 1) die ("failed to write reference header") ;
  U32 size = ref->max ; if (fwrite (&size,sizeof(U32),1,f) != 1) die ("failed to write size") ;
  if (fwrite (&ref->max,sizeof(U32),1,f) != 1) die ("failed to write max") ;
  if (fwrite (ref->index,sizeof(U32),size,f) != size) die ("failed write ref index") ;
  if (fwrite (ref->offset,sizeof(U32),size,f) != size) die ("failed write ref offset") ;
  if (fwrite (ref->id,sizeof(U32),size,f) != size) die ("failed write ref id") ;
  if (fwrite (ref->depth,sizeof(U32),ref->ms->max+1,f) != ref->ms->max+1) die ("fail depth") ;
  if (fwrite (ref->rev,sizeof(U32),size,f) != size) die ("fail rev") ;
  if (fwrite (ref->loc,sizeof(U32),ref->ms->max+1,f) != ref->ms->max+1) die ("fail loc") ;
  if (!arrayWrite (ref->len, f)) die ("failed write ref len") ;
  if (!dictWrite (ref->dict, f)) die ("failed write ref dict") ;
  /* write the dict last, because it can terminate in arbitrary byte alignment */
  fclose (f) ;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x48ea(%rip), %rsi      # 0x6102
leaq 0x4e59(%rip), %rdx      # 0x6678
movq %r15, %rdi
callq 0x5d89
movq %rax, %r14
testq %rax, %rax
jne 0x1840
leaq 0x48d1(%rip), %rdi      # 0x6107
movq %r15, %rsi
xorl %eax, %eax
callq 0x5b50
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x43e1
movq %r14, %rdi
callq 0x1090
leaq 0x48cd(%rip), %rsi      # 0x6127
leaq 0x4e17(%rip), %rdx      # 0x6678
movq %r15, %rdi
callq 0x5d89
movq %rax, %r14
testq %rax, %rax
jne 0x1882
leaq 0x48b3(%rip), %rdi      # 0x612b
movq %r15, %rsi
xorl %eax, %eax
callq 0x5b50
leaq 0x48c1(%rip), %rdi      # 0x614a
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x11f0
cmpq $0x1, %rax
je 0x18ab
leaq 0x48ae(%rip), %rdi      # 0x6152
xorl %eax, %eax
callq 0x5b50
leaq 0xc(%rbx), %r15
movl 0xc(%rbx), %eax
leaq 0xc(%rsp), %rdi
movl %eax, (%rdi)
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x11f0
cmpq $0x1, %rax
je 0x18db
leaq 0x489f(%rip), %rdi      # 0x6173
xorl %eax, %eax
callq 0x5b50
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %r14, %rcx
callq 0x11f0
cmpq $0x1, %rax
je 0x1900
leaq 0x488f(%rip), %rdi      # 0x6188
xorl %eax, %eax
callq 0x5b50
movq 0x10(%rbx), %rdi
movl 0xc(%rsp), %r15d
pushq $0x4
popq %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11f0
cmpq %r15, %rax
je 0x192a
leaq 0x4879(%rip), %rdi      # 0x619c
xorl %eax, %eax
callq 0x5b50
movq 0x18(%rbx), %rdi
pushq $0x4
popq %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11f0
cmpq %r15, %rax
je 0x194f
leaq 0x486b(%rip), %rdi      # 0x61b3
xorl %eax, %eax
callq 0x5b50
movq 0x20(%rbx), %rdi
pushq $0x4
popq %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11f0
cmpq %r15, %rax
je 0x1974
leaq 0x485e(%rip), %rdi      # 0x61cb
xorl %eax, %eax
callq 0x5b50
movq (%rbx), %rax
movq 0x28(%rbx), %rdi
movl 0x40(%rax), %edx
incl %edx
pushq $0x4
popq %rsi
movq %r14, %rcx
callq 0x11f0
movq (%rbx), %rcx
movl 0x40(%rcx), %ecx
incl %ecx
cmpq %rcx, %rax
je 0x19a6
leaq 0x4840(%rip), %rdi      # 0x61df
xorl %eax, %eax
callq 0x5b50
movq 0x30(%rbx), %rdi
pushq $0x4
popq %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11f0
cmpq %r15, %rax
je 0x19cb
leaq 0x4826(%rip), %rdi      # 0x61ea
xorl %eax, %eax
callq 0x5b50
movq (%rbx), %rax
movq 0x38(%rbx), %rdi
movl 0x40(%rax), %edx
incl %edx
pushq $0x4
popq %rsi
movq %r14, %rcx
callq 0x11f0
movq (%rbx), %rcx
movl 0x40(%rcx), %ecx
incl %ecx
cmpq %rcx, %rax
je 0x19fd
leaq 0x47fd(%rip), %rdi      # 0x61f3
xorl %eax, %eax
callq 0x5b50
movq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x575a
testb %al, %al
jne 0x1a1b
leaq 0x47e8(%rip), %rdi      # 0x61fc
xorl %eax, %eax
callq 0x5b50
movq 0x40(%rbx), %rdi
movq %r14, %rsi
callq 0x4ec4
testb %al, %al
jne 0x1a39
leaq 0x47df(%rip), %rdi      # 0x6211
xorl %eax, %eax
callq 0x5b50
movq %r14, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x1090