// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/match/shu-genomediff.c
// Function: gt_genomediff_shulen_sum
uint64_t **gt_genomediff_shulen_sum(const GtGenomediffArguments *arguments,
                                    GtShuUnitFileInfo *unit_info,
                                    GtLogger *logger,
                                    GtTimer *timer,
                                    GtError *err)
{
  int had_err = 0;
  GtUword i_idx, j_idx;
  uint64_t **shulensums = NULL;
  const GtEncseq *encseq = NULL;
  Genericindex *generic_index_subject = NULL;
  Sequentialsuffixarrayreader *ssar = NULL;

  gt_error_check(err);
  gt_assert(unit_info != NULL);

  /* prepare index */
  if (arguments->with_esa) {
    if (timer != NULL)
      gt_timer_show_progress(timer, "load sequential sa reader", stdout);

    ssar = gt_newSequentialsuffixarrayreaderfromfile(
                                    gt_str_array_get(arguments->filenames, 0),
                                    SARR_LCPTAB | SARR_SUFTAB | SARR_ESQTAB |
                                      SARR_SSPTAB,
                                    arguments->scanfile,
                                    logger, err);
    if (ssar == NULL)
      had_err = -1;

    if (!had_err) {
      encseq = gt_encseqSequentialsuffixarrayreader(ssar);
    }
  }
  else {
    gt_assert(arguments->with_pck);

    if (timer != NULL)
      gt_timer_show_progress(timer, "map generic index", stdout);

    generic_index_subject =
      genericindex_new(gt_str_array_get(arguments->filenames, 0),
                       false, true, false, true,
                       arguments->user_max_depth,
                       logger, err);
    if (generic_index_subject == NULL) {
      had_err = -1;
    }
    /*get num of genomes from unitfile or encseq and allocate shulen-matrix*/
    if (!had_err) {
      encseq = genericindex_getencseq(generic_index_subject);
    }
  }

  /*calculate sums of shulens*/
  if (!had_err) {
    gt_array2dim_calloc(shulensums,
                        unit_info->num_of_genomes,
                        unit_info->num_of_genomes);

    if (arguments->with_esa) {
      if (timer != NULL)
        gt_timer_show_progress(timer, "dfs esa index", stdout);

      had_err = gt_multiesa2shulengthdist(ssar, encseq, shulensums,
                                          unit_info, err);
    }
    else {
      const FMindex *subjectindex = NULL;
      GtUword num_of_chars,
                    total_length;
      const GtAlphabet *alphabet = gt_encseq_alphabet(unit_info->encseq);

      num_of_chars = (GtUword) gt_alphabet_num_of_chars(alphabet);
      total_length = genericindex_get_totallength(generic_index_subject);

      subjectindex = genericindex_get_packedindex(generic_index_subject);
      gt_assert(subjectindex != NULL);

      had_err = gt_pck_calculate_shulen(subjectindex,
                                        unit_info,
                                        shulensums,
                                        num_of_chars,
                                        total_length,
                                        timer,
                                        logger,
                                        err);
    }
  }

  if (arguments->with_esa) {
    if (ssar != NULL)
      gt_freeSequentialsuffixarrayreader(&ssar);
  }
  else
    genericindex_delete(generic_index_subject);

  if (had_err) {
    gt_log_log("foo");
    if (shulensums != NULL)
      gt_array2dim_delete(shulensums);
    shulensums = NULL;
  }
  else {
    gt_assert(shulensums != NULL);
    gt_log_log("sum of shulens");
    if (gt_log_enabled()) {
      for (i_idx = 0; i_idx < unit_info->num_of_genomes; i_idx++) {
        fprintf(stderr, "debug: %s\t",
                gt_str_array_get(unit_info->genome_names, i_idx));
        for (j_idx = 0; j_idx < unit_info->num_of_genomes; j_idx++) {
          if (i_idx == j_idx)
            fprintf(stderr, "0");
          else
            fprintf(stderr, Formatuint64_t"\t",
                    PRINTuint64_tcast(shulensums[i_idx][j_idx]));
        }
        fprintf(stderr, "\n");
      }
    }
  }
  return shulensums;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r15
movq %rcx, %rbx
movq %rdx, %rbp
movq %rsi, %r12
movq %rdi, %r14
movq $0x0, 0x20(%rsp)
testq %r8, %r8
je 0x1fd71b
movq %r15, %rdi
callq 0xfcc32
testb %al, %al
jne 0x1fd9e7
testq %r12, %r12
je 0x1fd9e2
cmpb $0x1, 0x2(%r14)
jne 0x1fd79f
testq %rbx, %rbx
je 0x1fd749
movq 0x2bb7a1(%rip), %rax    # 0x4b8ed8
movq (%rax), %rdx
leaq 0x1be25b(%rip), %rsi    # 0x3bb99c
movq %rbx, %rdi
callq 0x11cc90
movq %rbx, 0x10(%rsp)
movq 0x68(%r14), %rdi
xorl %esi, %esi
callq 0x11bfb3
movzbl (%r14), %edx
movq %rax, %rdi
movl $0x87, %esi
movq %rbp, %rcx
movq %r15, %r8
callq 0x1a5580
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x1fd8cb
movq %rax, %rbx
movq %rbp, 0x18(%rsp)
movq %rax, %rdi
callq 0x1a59f6
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
movq %rbx, (%rsp)
jmp 0x1fd820
cmpb $0x0, 0x3(%r14)
je 0x1fd9ec
testq %rbx, %rbx
je 0x1fd7c8
movq 0x2bb722(%rip), %rax    # 0x4b8ed8
movq (%rax), %rdx
leaq 0x1be20a(%rip), %rsi    # 0x3bb9ca
movq %rbx, %rdi
callq 0x11cc90
movq 0x68(%r14), %rdi
xorl %esi, %esi
callq 0x11bfb3
movl 0x8(%r14), %r9d
movq %rax, %rdi
xorl %esi, %esi
movl $0x1, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
pushq %r15
pushq %rbp
callq 0x1b22b6
addq $0x10, %rsp
testq %rax, %rax
je 0x1fd8cb
movq %rax, %r13
movq %rbp, 0x18(%rsp)
movq %rbx, 0x10(%rsp)
movq %rax, %rdi
callq 0x1b2295
movq %rax, 0x8(%rsp)
movq $0x0, (%rsp)
movq (%r12), %rdi
shlq $0x3, %rdi
leaq 0x1be152(%rip), %rbx    # 0x3bb981
movq %rbx, %rsi
movl $0x120, %edx            # imm = 0x120
callq 0x104226
movq %rax, %rbp
movq (%r12), %rdi
imulq %rdi, %rdi
movl $0x8, %esi
movq %rbx, %rdx
movl $0x120, %ecx            # imm = 0x120
callq 0x10436a
movq %rax, (%rbp)
movq (%r12), %rax
cmpq $0x2, %rax
jb 0x1fd88b
leaq (,%rax,8), %rcx
movq (%rbp), %rdx
addq %rcx, %rdx
movl $0x1, %esi
movq %rdx, (%rbp,%rsi,8)
incq %rsi
addq %rcx, %rdx
cmpq %rsi, %rax
jne 0x1fd87b
cmpb $0x1, 0x2(%r14)
jne 0x1fd8e0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1fd8b2
movq 0x2bb635(%rip), %rax    # 0x4b8ed8
movq (%rax), %rdx
leaq 0x1be12f(%rip), %rsi    # 0x3bb9dc
callq 0x11cc90
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x1a67d3
jmp 0x1fd936
movq $0x0, (%rsp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
xorl %ebp, %ebp
jmp 0x1fd939
movq 0x28(%r12), %rdi
callq 0xebcd9
movq %rax, %rdi
callq 0xd11be
movl %eax, %ebx
movq %r13, %rdi
callq 0x1b2e89
movq %rax, 0x8(%rsp)
movq %r13, %rdi
callq 0x1b2e79
testq %rax, %rax
je 0x1fd9f6
movl %ebx, %ecx
movq %rax, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %r9
pushq %r15
pushq 0x20(%rsp)
callq 0x32a488
addq $0x10, %rsp
movl %eax, %r15d
cmpb $0x1, 0x2(%r14)
jne 0x1fd953
cmpq $0x0, (%rsp)
je 0x1fd95b
leaq 0x20(%rsp), %rdi
callq 0x1a5698
jmp 0x1fd95b
movq %r13, %rdi
callq 0x1b224c
testl %r15d, %r15d
je 0x1fd9a0
leaq 0x16e8e6(%rip), %rdi    # 0x36c24d
xorl %eax, %eax
callq 0x103d72
testq %rbp, %rbp
je 0x1fd988
movq (%rbp), %rdi
leaq 0x1be003(%rip), %rsi    # 0x3bb981
movl $0x14a, %edx            # imm = 0x14A
callq 0x1045eb
leaq 0x1bdff2(%rip), %rsi    # 0x3bb981
movq %rbp, %rdi
movl $0x14a, %edx            # imm = 0x14A
callq 0x1045eb
xorl %ebp, %ebp
jmp 0x1fd9c3
testq %rbp, %rbp
je 0x1fd9f1
leaq 0x1be066(%rip), %rdi    # 0x3bba12
xorl %eax, %eax
callq 0x103d72
callq 0x103d66
testb %al, %al
je 0x1fd9c3
cmpq $0x0, (%r12)
jne 0x1fd9d5
movq %rbp, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
movq %rbp, %rsi
callq 0x7ea16
jmp 0x1fd9c3
callq 0x7eaf3
callq 0x7e96b
callq 0x7e9a4
callq 0x7eaba
callq 0x7e9dd