// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/extended/golomb.c
// Function: gt_golomb_encode
GtBittab* gt_golomb_encode(const GtGolomb *golomb, GtUword x)
{
  GtUword quotient,
                remain,
                mask,
                idx_i;
  GtBittab *code;
  gt_assert(golomb);

  quotient = x / golomb->median;
  remain = x - quotient * golomb->median;

  if (golomb->len == 0) {
    code = gt_bittab_new((quotient + 1) + 1);
  }
  else if (remain < golomb->two_pow_len - golomb->median) {
    code = gt_bittab_new((quotient + 1) + (golomb->len - 1));

    mask = 1UL << (golomb->len - 2);
    for (idx_i = 0; idx_i < golomb->len - 1; idx_i++) {
      if (remain & mask)
        gt_bittab_set_bit(code, quotient + 1 + idx_i);
      mask >>= 1;
    }
  }
  else {
    code = gt_bittab_new((quotient + 1) + golomb->len);

    remain = remain + (golomb->two_pow_len) - golomb->median;

    mask = 1UL << (golomb->len - 1);
    for (idx_i = 0; idx_i < golomb->len; idx_i++) {
      if (remain & mask)
        gt_bittab_set_bit(code, quotient + 1 + idx_i);
      mask >>= 1;
    }
  }

  /* write quotient 1s */
  /* for (idx_i = gt_bittab_size(code) - 1;
       idx_i >= gt_bittab_size(code) - quotient;
       idx_i--)
    gt_bittab_set_bit(code, idx_i); */
  for (idx_i = 0; idx_i < quotient; idx_i++)
    gt_bittab_set_bit(code, idx_i);
  return code;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x18140e
movq 0x4babc3(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x394c2c(%rip), %rsi    # 0x516013
leaq 0x3d3141(%rip), %rdx    # 0x55452f
leaq 0x3d3151(%rip), %rcx    # 0x554546
leaq 0x3d311d(%rip), %r8     # 0x554519
movl $0x47, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x181410
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
xorl %edx, %edx
divq (%rcx)
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
movq 0x20(%rsp), %rcx
movq 0x30(%rsp), %rdx
imulq (%rdx), %rcx
subq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x181466
movq 0x20(%rsp), %rdi
addq $0x1, %rdi
addq $0x1, %rdi
callq 0x89a20
movq %rax, (%rsp)
jmp 0x1815db
movq 0x18(%rsp), %rax
movq 0x30(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq 0x30(%rsp), %rdx
subq (%rdx), %rcx
cmpq %rcx, %rax
jae 0x18152a
movq 0x20(%rsp), %rdi
addq $0x1, %rdi
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rax
subq $0x1, %rax
addq %rax, %rdi
callq 0x89a20
movq %rax, (%rsp)
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rcx
subq $0x2, %rcx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq 0x30(%rsp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x181525
movq 0x18(%rsp), %rax
andq 0x10(%rsp), %rax
cmpq $0x0, %rax
je 0x181508
movq (%rsp), %rdi
movq 0x20(%rsp), %rsi
addq $0x1, %rsi
addq 0x8(%rsp), %rsi
callq 0x89b00
movq 0x10(%rsp), %rax
shrq %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
jmp 0x1814ca
jmp 0x1815d9
movq 0x20(%rsp), %rdi
addq $0x1, %rdi
movq 0x30(%rsp), %rax
addq 0x8(%rax), %rdi
callq 0x89a20
movq %rax, (%rsp)
movq 0x18(%rsp), %rax
movq 0x30(%rsp), %rcx
addq 0x10(%rcx), %rax
movq 0x30(%rsp), %rcx
subq (%rcx), %rax
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rcx
subq $0x1, %rcx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq 0x30(%rsp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x1815d7
movq 0x18(%rsp), %rax
andq 0x10(%rsp), %rax
cmpq $0x0, %rax
je 0x1815ba
movq (%rsp), %rdi
movq 0x20(%rsp), %rsi
addq $0x1, %rsi
addq 0x8(%rsp), %rsi
callq 0x89b00
movq 0x10(%rsp), %rax
shrq %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
jmp 0x181583
jmp 0x1815d9
jmp 0x1815db
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rax
cmpq 0x20(%rsp), %rax
jae 0x18160e
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x89b00
movq 0x8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
jmp 0x1815e4
movq (%rsp), %rax
addq $0x38, %rsp
retq
nopw (%rax,%rax)