// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/extended/encdesc.c
// Function: encdesc_write_encoding
static int encdesc_write_encoding(GtEncdesc *encdesc,
                                  GtCstrIterator *cstr_iterator,
                                  FILE *fp, GtError *err)
{
  int had_err = 0, str_iter_ret;
  const char *descbuffer;
  GtUword desc_counter = 0,
          page_counter = 0,
          idx = 0,
          bits_left_in_page;
  EncdescWriteInfo *info = gt_calloc((size_t) 1, sizeof (*info));
  GtBitOutStream *bitstream;

  bits_left_in_page = (GtUword) encdesc->pagesize * 8UL;

  info->codes = gt_malloc(sizeof (*info->codes));
  info->cur_desc = 0;
  GT_INITARRAY(info->codes, EncdescCode);

  bitstream = gt_bitoutstream_new(fp);

  had_err = gt_cstr_iterator_reset(cstr_iterator, err);
  if (!had_err) {

    for (idx = 0; idx < encdesc->num_of_fields; idx++)
      encdesc->fields[idx].prev_value = 0;

    for (str_iter_ret = gt_cstr_iterator_next(cstr_iterator,
                                              &descbuffer, err);
         str_iter_ret > 0;
         str_iter_ret = gt_cstr_iterator_next(cstr_iterator,
                                              &descbuffer, err)) {
      gt_free(info->descbuffer);
      info->descbuffer = gt_cstr_dup(descbuffer);
      info->sample = false;

      /* count bits, needed for checking of sampling */
      prepare_write_data_and_count_bits(encdesc,
                                        info);

      /* check if a new sample has to be added */
      if (encdesc->sampling != NULL) {
        info->sample =
          gt_sampling_is_next_element_sample(encdesc->sampling,
                                             page_counter,
                                             desc_counter,
                                             info->total_bits_prepared,
                                             bits_left_in_page);
        if (info->sample) {
          gt_log_log("sampling at description " GT_WU,
                     info->cur_desc);
          /* retrieve the unmodified buffer, as the '\0' in the other one would
             be complicated */
          gt_free(info->descbuffer);
          info->descbuffer = gt_cstr_dup(descbuffer);
          /* sampled size and type of codes is different from unsampled */
          info->codes->nextfreeEncdescCode = 0;
          prepare_write_data_and_count_bits(encdesc,
                                            info);
          gt_bitoutstream_flush_advance(bitstream);

          gt_sampling_add_sample(encdesc->sampling,
                                 (size_t) gt_bitoutstream_pos(bitstream),
                                 info->cur_desc);

          desc_counter = 0;
          page_counter = 0;
          bits_left_in_page = (GtUword) encdesc->pagesize * 8;
        }
      }

      while (bits_left_in_page < info->total_bits_prepared) {
        page_counter++;
        info->total_bits_prepared -= bits_left_in_page;
        bits_left_in_page = (GtUword) encdesc->pagesize * 8;
      }
      bits_left_in_page -= info->total_bits_prepared;
      /* always set first page as written */
      if (page_counter == 0)
        page_counter++;
      desc_counter++;
      info->cur_desc++;

      append_data_to_bitstream_and_reset_info(info, bitstream);
    }
    if (str_iter_ret != 0) {
      had_err = str_iter_ret;
      gt_assert(gt_error_is_set(err));
    }
  }

  if (!had_err) {
    gt_bitoutstream_flush(bitstream);
    encdesc->start_of_samplingtab = ftell(fp);

    if (encdesc->sampling != NULL)
      gt_sampling_write(encdesc->sampling, fp);
  }
  gt_bitoutstream_delete(bitstream);
  GT_FREEARRAY(info->codes, EncdescCode);
  gt_free(info->codes);
  gt_free(info->descbuffer);
  gt_free(info);
  return had_err;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movl $0x1, %edi
movl $0x40, %esi
leaq 0x3ecdcc(%rip), %rdx    # 0x54e268
movl $0x2c3, %ecx            # imm = 0x2C3
callq 0xe83c0
movq %rax, 0x10(%rsp)
movq 0x60(%rsp), %rax
movq 0x50(%rax), %rax
shlq $0x3, %rax
movq %rax, 0x18(%rsp)
movl $0x18, %edi
leaq 0x3ecd9f(%rip), %rsi    # 0x54e268
movl $0x2c8, %edx            # imm = 0x2C8
callq 0xe80f0
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, (%rax)
movq 0x10(%rsp), %rax
movq $0x0, 0x30(%rax)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq $0x0, (%rax)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq $0x0, 0x10(%rax)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq $0x0, 0x8(%rax)
movq 0x50(%rsp), %rdi
callq 0x489ee0
movq %rax, 0x8(%rsp)
movq 0x58(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x48e960
movl %eax, 0x44(%rsp)
cmpl $0x0, 0x44(%rsp)
jne 0x16182a
movq $0x0, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq 0x60(%rsp), %rcx
cmpq 0x40(%rcx), %rax
jae 0x161590
movq 0x60(%rsp), %rax
movq 0x18(%rax), %rax
imulq $0xc8, 0x20(%rsp), %rcx
addq %rcx, %rax
movq $0x0, 0xa0(%rax)
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0x161550
movq 0x58(%rsp), %rdi
movq 0x48(%rsp), %rdx
leaq 0x38(%rsp), %rsi
callq 0x48ea50
movl %eax, 0x40(%rsp)
cmpl $0x0, 0x40(%rsp)
jle 0x1617cf
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x3ecca5(%rip), %rsi    # 0x54e268
movl $0x2d9, %edx            # imm = 0x2D9
callq 0xe88c0
movq 0x38(%rsp), %rdi
callq 0xa2db0
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movb $0x0, 0x38(%rax)
movq 0x60(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x1638f0
movq 0x60(%rsp), %rax
cmpq $0x0, 0x28(%rax)
je 0x16170f
movq 0x60(%rsp), %rax
movq 0x28(%rax), %rdi
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0x18(%rsp), %r8
callq 0x1d0da0
movb %al, %cl
movq 0x10(%rsp), %rax
andb $0x1, %cl
movb %cl, 0x38(%rax)
movq 0x10(%rsp), %rax
testb $0x1, 0x38(%rax)
je 0x16170d
movq 0x10(%rsp), %rax
movq 0x30(%rax), %rsi
leaq 0x3ed38c(%rip), %rdi    # 0x54e9e9
movb $0x0, %al
callq 0xe7740
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x3ecbf4(%rip), %rsi    # 0x54e268
movl $0x2ee, %edx            # imm = 0x2EE
callq 0xe88c0
movq 0x38(%rsp), %rdi
callq 0xa2db0
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq $0x0, 0x10(%rax)
movq 0x60(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x1638f0
movq 0x8(%rsp), %rdi
callq 0x48a200
movq 0x60(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, (%rsp)
movq 0x8(%rsp), %rdi
callq 0x48a2d0
movq (%rsp), %rdi
movq %rax, %rsi
movq 0x10(%rsp), %rax
movq 0x30(%rax), %rdx
callq 0x1d0b50
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x60(%rsp), %rax
movq 0x50(%rax), %rax
shlq $0x3, %rax
movq %rax, 0x18(%rsp)
jmp 0x16170f
jmp 0x161711
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x161758
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x10(%rax)
movq 0x60(%rsp), %rax
movq 0x50(%rax), %rax
shlq $0x3, %rax
movq %rax, 0x18(%rsp)
jmp 0x161711
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0x18(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x161784
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
movq 0x10(%rsp), %rax
movq 0x30(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x30(%rax)
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x163b40
movq 0x58(%rsp), %rdi
movq 0x48(%rsp), %rdx
leaq 0x38(%rsp), %rsi
callq 0x48ea50
movl %eax, 0x40(%rsp)
jmp 0x1615a8
cmpl $0x0, 0x40(%rsp)
je 0x161828
movl 0x40(%rsp), %eax
movl %eax, 0x44(%rsp)
movq 0x48(%rsp), %rdi
callq 0xd8a60
testb $0x1, %al
jne 0x161824
movq 0x4da7ad(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3b4816(%rip), %rsi    # 0x516013
leaq 0x3d8783(%rip), %rdx    # 0x539f87
leaq 0x3ed1fa(%rip), %rcx    # 0x54ea05
leaq 0x3eca56(%rip), %r8     # 0x54e268
movl $0x310, %r9d            # imm = 0x310
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x161826
jmp 0x161828
jmp 0x16182a
cmpl $0x0, 0x44(%rsp)
jne 0x161872
movq 0x8(%rsp), %rdi
callq 0x48a160
movq 0x50(%rsp), %rdi
callq 0x19030
movq %rax, %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x58(%rax)
movq 0x60(%rsp), %rax
cmpq $0x0, 0x28(%rax)
je 0x161870
movq 0x60(%rsp), %rax
movq 0x28(%rax), %rdi
movq 0x50(%rsp), %rsi
callq 0x1cffc0
jmp 0x161872
movq 0x8(%rsp), %rdi
callq 0x48a2f0
movq 0x10(%rsp), %rax
movq (%rax), %rax
cmpq $0x0, (%rax)
je 0x1618d5
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rdi
leaq 0x3ec9cc(%rip), %rsi    # 0x54e268
movl $0x31c, %edx            # imm = 0x31C
callq 0xe88c0
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq $0x0, 0x8(%rax)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq $0x0, 0x10(%rax)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq $0x0, (%rax)
jmp 0x1618d7
movq 0x10(%rsp), %rax
movq (%rax), %rdi
leaq 0x3ec982(%rip), %rsi    # 0x54e268
movl $0x31d, %edx            # imm = 0x31D
callq 0xe88c0
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x3ec968(%rip), %rsi    # 0x54e268
movl $0x31e, %edx            # imm = 0x31E
callq 0xe88c0
movq 0x10(%rsp), %rdi
leaq 0x3ec952(%rip), %rsi    # 0x54e268
movl $0x31f, %edx            # imm = 0x31F
callq 0xe88c0
movl 0x44(%rsp), %eax
addq $0x68, %rsp
retq
nopl (%rax)