// File: /workspace/github_c_makefile_star2_O3/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 0x1716cb
movq %rdi, %rbx
movq 0x20(%rdi), %rdi
testq %rdi, %rdi
je 0x1715cd
callq 0x113ace
movl %eax, %ebp
movq 0x20(%rbx), %rdi
callq 0x113461
movq %rax, %r14
testl %ebp, %ebp
je 0x17165c
xorl %r13d, %r13d
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x20(%rbx), %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x113add
cmpl %r13d, %eax
cmovgl %eax, %r13d
incl %r12d
cmpl %r12d, %ebp
jne 0x171546
incl %r15d
cmpl %ebp, %r15d
jne 0x171543
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
xorl %r12d, %r12d
movq 0x20(%rbx), %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x113add
movl %r13d, %ecx
subl %eax, %ecx
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x113b22
incl %r12d
cmpl %r12d, %ebp
jne 0x17158e
incl %r15d
cmpl %ebp, %r15d
jne 0x17158b
movq 0x18(%rbx), %rax
movq (%rsp), %rdx
jmp 0x17166c
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
leaq 0x1(%rax), %rdx
sarq %rdx
leaq 0x1(%rcx), %rsi
sarq %rsi
cmpq %rsi, %rdx
cmovgq %rdx, %rsi
movq 0x18(%rbx), %rdx
leaq 0x1(%rdx), %r14
xorl %r12d, %r12d
testq %rdx, %rdx
cmovsq %r12, %r14
cmpq %r14, %rsi
cmovgq %rsi, %r14
leaq (%r14,%r14), %r13
movq %r13, %rbp
subq %rax, %rbp
subq %rcx, %r13
subq %rdx, %r14
subq 0x10(%rbx), %r12
leaq 0x2209f0(%rip), %rsi    # 0x39200d
movl $0x30, %edi
movl $0x29, %edx
callq 0x104226
movq %rax, %r15
movq $0x0, 0x20(%rax)
movw $0x1, 0x28(%rax)
movq %rbp, (%rax)
movq %r13, 0x8(%rax)
movq %r12, 0x10(%rax)
movq %r14, 0x18(%rax)
cmpb $0x0, 0x28(%rbx)
jne 0x1716b9
movq %r15, %rdi
callq 0x1713df
jmp 0x1716b9
movq 0x18(%rbx), %rax
leal 0x1(%rax), %ecx
xorl %edx, %edx
cmpq $-0x1, %rax
cmovgel %ecx, %edx
movslq %edx, %r12
subq %rax, %r12
xorl %r13d, %r13d
subq 0x10(%rbx), %r13
leaq 0x22098d(%rip), %rsi    # 0x39200d
movl $0x30, %edi
movl $0x29, %edx
callq 0x104226
movq %rax, %r15
movq $0x0, 0x20(%rax)
movw $0x1, 0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %r13, 0x10(%rax)
movq %r12, 0x18(%rax)
movq %rax, %rdi
movq %r14, %rsi
callq 0x1713cf
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x536b6