// File: /workspace/github_c_makefile_star2_O0/jflatow[P]jfdb/test/../src/db.h
// Function: JFDB_region_map_gaps
static inline void JFDB_region_map_gaps(JFDB_RegionMap *map, JFDB_Region *regions) {
  // initialize the counters and the min, clear the regions
  uint32_t block = 0, count = 0, size;
  JFDB_Region *minMax = &regions[0];
  memset(regions, 0, JFDB_NUM_GAPS * sizeof(JFDB_Region));
  for (size_t i = 0; i < map->size; i++) {
    uint64_t word = map->data[i];
    if (word == 0) {
      count += 64;
    } else if (word == -1) {
      // skip bits
    } else {
      for (int b = ffsll(word), pos = b; pos < 64; pos += (b = ffsll(word >> pos))) {
        if (b) {
          // found the next bit, add leading zeroes (end region)
          // position is right after the bit
          count += b - 1;
          // possibly find / replace min
          if ((size = count * JFDB_BLOCK_SIZE) > minMax->size) {
            minMax->size = size;
            minMax->block = block + map->begin;
            minMax = &regions[0];
            for (int j = 1; j < JFDB_NUM_GAPS; j++)
              if (regions[j].size < minMax->size)
                minMax = &regions[j];
          }
          // find the next zero bit, reset the count (begin region)
          // guaranteed to be a zero since we shifted at least one in
          // position right before the zero
          pos += ffsll(~(word >> pos)) - 1;
          block = 64 * i + pos;
          count = 0;
        } else {
          // add the trailing zeroes to the count
          count += 64 - pos;
          break;
        }
      }
    }
  }
  // possibly find / replace the min with the trailing region
  if ((size = count * JFDB_BLOCK_SIZE) > minMax->size) {
    minMax->size = size;
    minMax->block = block + map->begin;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x10f0
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x4(%rcx), %ecx
cmpq %rcx, %rax
jae 0x19f8
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x1898
movl -0x18(%rbp), %eax
addl $0x40, %eax
movl %eax, -0x18(%rbp)
jmp 0x19e5
cmpq $-0x1, -0x38(%rbp)
jne 0x18a4
jmp 0x19e3
movq -0x38(%rbp), %rdx
tzcntq %rdx, %rax
addq $0x1, %rax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmoveq %rcx, %rax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpl $0x40, -0x40(%rbp)
jge 0x19e1
cmpl $0x0, -0x3c(%rbp)
je 0x19a2
movl -0x3c(%rbp), %eax
subl $0x1, %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x1c(%rbp)
movq -0x28(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x195b
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rax
addl (%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x1, -0x44(%rbp)
cmpl $0x8, -0x44(%rbp)
jge 0x1959
movq -0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
movl 0x4(%rax,%rcx,8), %eax
movq -0x28(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x194c
movq -0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
jmp 0x194e
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x191e
jmp 0x195b
movq -0x38(%rbp), %rdx
movl -0x40(%rbp), %eax
movl %eax, %ecx
shrq %cl, %rdx
xorq $-0x1, %rdx
tzcntq %rdx, %rax
addq $0x1, %rax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmoveq %rcx, %rax
subl $0x1, %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x30(%rbp), %rax
shlq $0x6, %rax
movslq -0x40(%rbp), %rcx
addq %rcx, %rax
movl %eax, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
jmp 0x19b2
movl $0x40, %eax
subl -0x40(%rbp), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0x19e1
jmp 0x19b4
movq -0x38(%rbp), %rdx
movl -0x40(%rbp), %eax
movl %eax, %ecx
shrq %cl, %rdx
tzcntq %rdx, %rax
addq $0x1, %rax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmoveq %rcx, %rax
movl %eax, -0x3c(%rbp)
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x18c4
jmp 0x19e3
jmp 0x19e5
jmp 0x19e7
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x185e
movl -0x18(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x1c(%rbp)
movq -0x28(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x1a23
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rax
addl (%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)