// File: /workspace/github_c_makefile_star2_O3/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 0x4db5(%rip), %rsi      # 0x7102
leaq 0x5324(%rip), %rdx      # 0x7678
movq %r15, %rdi
callq 0x6637
movq %rax, %r14
testq %rax, %rax
jne 0x2375
leaq 0x4d9c(%rip), %rdi      # 0x7107
movq %r15, %rsi
xorl %eax, %eax
callq 0x63e4
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x4b54
movq %r14, %rdi
callq 0x1090
leaq 0x4d98(%rip), %rsi      # 0x7127
leaq 0x52e2(%rip), %rdx      # 0x7678
movq %r15, %rdi
callq 0x6637
movq %rax, %r14
testq %rax, %rax
jne 0x23b7
leaq 0x4d7e(%rip), %rdi      # 0x712b
movq %r15, %rsi
xorl %eax, %eax
callq 0x63e4
leaq 0x4d8c(%rip), %rdi      # 0x714a
movl $0x8, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x11f0
cmpq $0x1, %rax
je 0x23e4
leaq 0x4d75(%rip), %rdi      # 0x7152
xorl %eax, %eax
callq 0x63e4
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 0x2418
leaq 0x4d62(%rip), %rdi      # 0x7173
xorl %eax, %eax
callq 0x63e4
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x11f0
cmpq $0x1, %rax
je 0x2441
leaq 0x4d4e(%rip), %rdi      # 0x7188
xorl %eax, %eax
callq 0x63e4
movq 0x10(%rbx), %rdi
movl 0xc(%rsp), %r15d
movl $0x4, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11f0
cmpq %r15, %rax
je 0x246d
leaq 0x4d36(%rip), %rdi      # 0x719c
xorl %eax, %eax
callq 0x63e4
movq 0x18(%rbx), %rdi
movl $0x4, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11f0
cmpq %r15, %rax
je 0x2494
leaq 0x4d26(%rip), %rdi      # 0x71b3
xorl %eax, %eax
callq 0x63e4
movq 0x20(%rbx), %rdi
movl $0x4, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11f0
cmpq %r15, %rax
je 0x24bb
leaq 0x4d17(%rip), %rdi      # 0x71cb
xorl %eax, %eax
callq 0x63e4
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 0x24ef
leaq 0x4cf7(%rip), %rdi      # 0x71df
xorl %eax, %eax
callq 0x63e4
movq 0x30(%rbx), %rdi
movl $0x4, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11f0
cmpq %r15, %rax
je 0x2516
leaq 0x4cdb(%rip), %rdi      # 0x71ea
xorl %eax, %eax
callq 0x63e4
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 0x254a
leaq 0x4cb0(%rip), %rdi      # 0x71f3
xorl %eax, %eax
callq 0x63e4
movq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x6003
testb %al, %al
jne 0x2568
leaq 0x4c9b(%rip), %rdi      # 0x71fc
xorl %eax, %eax
callq 0x63e4
movq 0x40(%rbx), %rdi
movq %r14, %rsi
callq 0x571e
testb %al, %al
jne 0x2586
leaq 0x4c92(%rip), %rdi      # 0x7211
xorl %eax, %eax
callq 0x63e4
movq %r14, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x1090