// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/extended/scorehandler.c
// Function: gt_scorehandler2costhandler
GtScoreHandler *gt_scorehandler2costhandler(const GtScoreHandler *scorehandler)
{
  GtScoreHandler *costhandler;

  gt_assert(scorehandler != NULL);
  if (scorehandler->scorematrix == NULL)
  {
    GtWord matchscore, mismatchscore, gap_extension, gap_opening,
           maxscore = GT_MAX(GT_MAX(GT_DIV2(scorehandler->matchscore+1),
                         GT_DIV2(scorehandler->mismatchscore+1)),
                     GT_MAX(1 + scorehandler->gap_extension,0));

    matchscore = 2 * maxscore - scorehandler->matchscore;
    mismatchscore = 2 * maxscore - scorehandler->mismatchscore;
    gap_extension = maxscore - scorehandler->gap_extension;
    gap_opening = -scorehandler->gap_opening;
    costhandler = gt_scorehandler_new(matchscore,
                                      mismatchscore,
                                      gap_opening,
                                      gap_extension);
    if (!scorehandler->mappedsequence)
    {
      gt_scorehandler_plain(costhandler);
    }
  } else
  {
    int maxscore;
    GtWord gap_extension, gap_opening;
    unsigned int i, j,
                 dim = gt_score_matrix_get_dimension(scorehandler->scorematrix);
    GtScoreMatrix *costmatrix
      = gt_score_matrix_clone_empty(scorehandler->scorematrix);

    for (maxscore = 0, i = 0; i < dim; i++)
    {
      for (j = 0; j < dim; j++)
      {
        int val = gt_score_matrix_get_score(scorehandler->scorematrix, i, j);

        if (val > maxscore)
        {
          maxscore = val;
        }
      }
    }
    maxscore = GT_MAX(GT_DIV2(maxscore+1), 1 + scorehandler->gap_extension);
    for (i = 0; i < dim; i++)
    {
      for (j = 0; j < dim; j++)
      {
        /* translate */
        int score = gt_score_matrix_get_score(scorehandler->scorematrix,i,j);
        gt_score_matrix_set_score(costmatrix, i, j, 2 * maxscore - score);
      }
    }
    gap_extension = maxscore - scorehandler->gap_extension;
    gap_opening = -scorehandler->gap_opening;
    costhandler = gt_scorehandler_new( 0,0, gap_opening, gap_extension);
    gt_scorehandler_add_scorematrix(costhandler,costmatrix);
  }
  return costhandler;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x114d75
movq %rdi, %rbx
movq 0x20(%rdi), %rdi
testq %rdi, %rdi
je 0x114d05
callq 0xa52e1
movl %eax, %ebp
movq 0x20(%rbx), %rdi
callq 0xa4ada
movq %rax, %r14
xorl %r15d, %r15d
xorl %r13d, %r13d
cmpl %ebp, %r15d
je 0x114c86
xorl %r12d, %r12d
cmpl %r12d, %ebp
je 0x114c81
movq 0x20(%rbx), %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0xa5323
cmpl %r13d, %eax
cmovgl %eax, %r13d
incl %r12d
jmp 0x114c61
incl %r15d
jmp 0x114c59
incl %r13d
shrl %r13d
movq 0x18(%rbx), %rax
incq %rax
cmpq %r13, %rax
cmovll %r13d, %eax
movq %rax, (%rsp)
leal (%rax,%rax), %r13d
xorl %r15d, %r15d
cmpl %ebp, %r15d
je 0x114cde
xorl %r12d, %r12d
cmpl %r12d, %ebp
je 0x114cd9
movq 0x20(%rbx), %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0xa5323
movl %r13d, %ecx
subl %eax, %ecx
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0xa53c4
incl %r12d
jmp 0x114cad
incl %r15d
jmp 0x114ca5
movslq (%rsp), %rcx
subq 0x18(%rbx), %rcx
xorl %edx, %edx
subq 0x10(%rbx), %rdx
xorl %edi, %edi
xorl %esi, %esi
callq 0x1148f4
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x114940
jmp 0x114d63
movq (%rbx), %rax
movq 0x8(%rbx), %r8
leaq 0x1(%rax), %rcx
sarq %rcx
leaq 0x1(%r8), %rsi
sarq %rsi
cmpq %rsi, %rcx
cmovgq %rcx, %rsi
movq 0x18(%rbx), %r9
leaq 0x1(%r9), %rcx
xorl %edx, %edx
testq %r9, %r9
cmovsq %rdx, %rcx
cmpq %rcx, %rsi
cmovgq %rsi, %rcx
leaq (%rcx,%rcx), %rsi
movq %rsi, %rdi
subq %rax, %rdi
subq %r8, %rsi
subq %r9, %rcx
subq 0x10(%rbx), %rdx
callq 0x1148f4
movq %rax, %r15
cmpb $0x0, 0x28(%rbx)
jne 0x114d63
movq %r15, %rdi
callq 0x114981
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3231ec(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1d028d(%rip), %rsi    # 0x2e5013
leaq 0x21d5dc(%rip), %rdx    # 0x332369
leaq 0x21d6f4(%rip), %rcx    # 0x332488
leaq 0x21d5b2(%rip), %r8     # 0x33234d
movl $0x85, %r9d
xorl %eax, %eax
callq 0x17a50
callq 0x17390