// File: /workspace/github_c_makefile_star2_O1/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 0x4f84(%rip), %rsi      # 0x7102
leaq 0x569c(%rip), %rdx      # 0x7821
movq %r15, %rdi
callq 0x63a3
movq %rax, %r14
testq %rax, %rax
jne 0x21a6
leaq 0x4f6b(%rip), %rdi      # 0x7107
movq %r15, %rsi
xorl %eax, %eax
callq 0x614c
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x4898
movq %r14, %rdi
callq 0x1090
leaq 0x4f67(%rip), %rsi      # 0x7127
leaq 0x565a(%rip), %rdx      # 0x7821
movq %r15, %rdi
callq 0x63a3
movq %rax, %r14
testq %rax, %rax
jne 0x21e8
leaq 0x4f4d(%rip), %rdi      # 0x712b
movq %r15, %rsi
xorl %eax, %eax
callq 0x614c
leaq 0x4f5b(%rip), %rdi      # 0x714a
movl $0x8, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x11f0
cmpq $0x1, %rax
je 0x2215
leaq 0x4f44(%rip), %rdi      # 0x7152
xorl %eax, %eax
callq 0x614c
leaq 0xc(%rbx), %r15
movl 0xc(%rbx), %eax
leaq 0xc(%rsp), %rdi
movl %eax, (%rdi)
movl $0x4, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x11f0
cmpq $0x1, %rax
je 0x2249
leaq 0x4f31(%rip), %rdi      # 0x7173
xorl %eax, %eax
callq 0x614c
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x11f0
cmpq $0x1, %rax
je 0x2272
leaq 0x4f1d(%rip), %rdi      # 0x7188
xorl %eax, %eax
callq 0x614c
movq 0x10(%rbx), %rdi
movl 0xc(%rsp), %r15d
movl $0x4, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11f0
cmpq %r15, %rax
je 0x229e
leaq 0x4f05(%rip), %rdi      # 0x719c
xorl %eax, %eax
callq 0x614c
movq 0x18(%rbx), %rdi
movl $0x4, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11f0
cmpq %r15, %rax
je 0x22c5
leaq 0x4ef5(%rip), %rdi      # 0x71b3
xorl %eax, %eax
callq 0x614c
movq 0x20(%rbx), %rdi
movl $0x4, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11f0
cmpq %r15, %rax
je 0x22ec
leaq 0x4ee6(%rip), %rdi      # 0x71cb
xorl %eax, %eax
callq 0x614c
movq (%rbx), %rax
movq 0x28(%rbx), %rdi
movl 0x40(%rax), %edx
incl %edx
movl $0x4, %esi
movq %r14, %rcx
callq 0x11f0
movq (%rbx), %rcx
movl 0x40(%rcx), %ecx
incl %ecx
cmpq %rcx, %rax
je 0x2320
leaq 0x4ec6(%rip), %rdi      # 0x71df
xorl %eax, %eax
callq 0x614c
movq 0x30(%rbx), %rdi
movl $0x4, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11f0
cmpq %r15, %rax
je 0x2347
leaq 0x4eaa(%rip), %rdi      # 0x71ea
xorl %eax, %eax
callq 0x614c
movq (%rbx), %rax
movq 0x38(%rbx), %rdi
movl 0x40(%rax), %edx
incl %edx
movl $0x4, %esi
movq %r14, %rcx
callq 0x11f0
movq (%rbx), %rcx
movl 0x40(%rcx), %ecx
incl %ecx
cmpq %rcx, %rax
je 0x237b
leaq 0x4e7f(%rip), %rdi      # 0x71f3
xorl %eax, %eax
callq 0x614c
movq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x5d55
testb %al, %al
jne 0x2399
leaq 0x4e6a(%rip), %rdi      # 0x71fc
xorl %eax, %eax
callq 0x614c
movq 0x40(%rbx), %rdi
movq %r14, %rsi
callq 0x5460
testb %al, %al
jne 0x23b7
leaq 0x4e61(%rip), %rdi      # 0x7211
xorl %eax, %eax
callq 0x614c
movq %r14, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x1090