// File: /workspace/github_c_makefile_star2_O0/jflatow[P]jfdb/src/db.c
// Function: JFDB_mmap_file
static int JFDB_mmap_file(JFDB *db, int kv, size_t cover, int factor) {
  // if the mmap already includes cover, do nothing
  // otherwise increase the mapping by a size of factor
  JFDB_MMap *m = kv == JFDB_KEYS ? &db->kmap : &db->vmap;
  if (m->size >= cover)
    return 0;

  // we need to remap the memory, there are some open questions and TODOs:
  //  - if we munmap before mmapping again:
  //     we temporarily release the references to the underlying memory
  //     potentially allowing us to re-use the address range
  //     potentially avoiding TLB misses if the OS hasn't released the memory
  //     there's a lot of potential but it could just as easily work against us
  //  - if we mmap again before munmapping:
  //     we ensure that we always retain a reference to the memory
  //     however we are guaranteed to get a different address range
  //  - XXX: we should be taking advantage of mremap when it's available
  //  - alternatively, we could impose an upper bound on the file size and map it once
  //    but its not polite (at best) for a library to hog the address space like that
  //  - we map nearest multiple of PAGESIZE, for which we will anyway incur the cost
  int prot = kv == JFDB_KEYS ? PROT_READ | PROT_WRITE : PROT_READ;
  if (m->size)
    munmap(m->map, m->size);
  m->size = RTM(cover * factor, sysconf(_SC_PAGESIZE));
  m->map = mmap(NULL, m->size, prot, MAP_SHARED, m->fd, 0);
  if (m->map == MAP_FAILED)
    JFDB_set_error(db, JFDB_EMMAP, "cannot mmap %s", kv == JFDB_KEYS ? "keys" : "vals");
  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
cmpl $0x1, -0x14(%rbp)
jne 0x259c
movq -0x10(%rbp), %rax
addq $0x90, %rax
movq %rax, -0x40(%rbp)
jmp 0x25aa
movq -0x10(%rbp), %rax
addq $0xa8, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x20(%rbp), %rax
jb 0x25cc
movl $0x0, -0x4(%rbp)
jmp 0x26d8
movl -0x14(%rbp), %edx
movl $0x1, %eax
movl $0x3, %ecx
cmpl $0x1, %edx
cmovel %ecx, %eax
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2602
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x1170
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq %rcx, %rax
movq %rax, -0x58(%rbp)
movl $0x1e, %edi
callq 0x11a0
movq %rax, %rcx
movq -0x58(%rbp), %rax
addq %rcx, %rax
subq $0x1, %rax
movq %rax, -0x50(%rbp)
movl $0x1e, %edi
callq 0x11a0
movq %rax, %rcx
movq -0x50(%rbp), %rax
xorl %edx, %edx
divq %rcx
movq %rax, -0x48(%rbp)
movl $0x1e, %edi
callq 0x11a0
movq -0x48(%rbp), %rcx
imulq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x34(%rbp), %edx
movq -0x30(%rbp), %rax
movl (%rax), %r8d
xorl %eax, %eax
movl %eax, %r9d
movl $0x1, %ecx
movq %r9, %rdi
callq 0x10b0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq $-0x1, %rcx
cmpq %rcx, 0x8(%rax)
jne 0x26d1
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %edx
leaq 0x6b0e(%rip), %rcx      # 0x91be
leaq 0x6b1c(%rip), %rax      # 0x91d3
cmpl $0x1, %edx
cmoveq %rax, %rcx
movl $0x5, %esi
leaq 0x6c79(%rip), %rdx      # 0x9343
movb $0x0, %al
callq 0x2320
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)