// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
testq %rdi, %rdi
je 0x179a90
movq %rdi, %rbx
movq 0x20(%rdi), %rdi
testq %rdi, %rdi
je 0x1799f1
callq 0x1191a5
movl %eax, %ebp
movq 0x20(%rbx), %rdi
callq 0x118b01
movq %rax, %r14
xorl %r13d, %r13d
testl %ebp, %ebp
je 0x179935
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x20(%rbx), %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x1191b4
cmpl %r13d, %eax
cmovgl %eax, %r13d
incl %r12d
cmpl %r12d, %ebp
jne 0x179909
incl %r15d
cmpl %ebp, %r15d
jne 0x179906
incl %r13d
shrl %r13d
movl %r13d, %eax
movq 0x18(%rbx), %rcx
incq %rcx
cmpq %rax, %rcx
cmovll %r13d, %ecx
movq %rcx, (%rsp)
testl %ebp, %ebp
je 0x17998e
movq (%rsp), %rax
leal (%rax,%rax), %r13d
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x20(%rbx), %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x1191b4
movl %r13d, %ecx
subl %eax, %ecx
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x1191fa
incl %r12d
cmpl %r12d, %ebp
jne 0x17995c
incl %r15d
cmpl %ebp, %r15d
jne 0x179959
movslq (%rsp), %rax
movdqu 0x10(%rbx), %xmm0
movq %rax, %xmm1
pslldq $0x8, %xmm1             # xmm1 = zero,zero,zero,zero,zero,zero,zero,zero,xmm1[0,1,2,3,4,5,6,7]
psubq %xmm0, %xmm1
movdqa %xmm1, (%rsp)
leaq 0x221a7c(%rip), %rsi    # 0x39b42d
movl $0x30, %edi
movl $0x29, %edx
callq 0x1092b2
movq %rax, %r15
movq $0x0, 0x20(%rax)
movw $0x1, 0x28(%rax)
pxor %xmm0, %xmm0
movdqu %xmm0, (%rax)
movaps (%rsp), %xmm0
movups %xmm0, 0x10(%rax)
movq %rax, %rdi
movq %r14, %rsi
callq 0x179793
jmp 0x179a7e
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 0x2219ec(%rip), %rsi    # 0x39b42d
movl $0x30, %edi
movl $0x29, %edx
callq 0x1092b2
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 0x179a7e
movq %r15, %rdi
callq 0x1797a3
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5461d