// File: /workspace/github_c_makefile_star2_O3/nh13[P]ksw/src/parasail/src/memory.c
// Function: parasail_matrix_convert_square_to_pssm
parasail_matrix_t* parasail_matrix_convert_square_to_pssm(
        const parasail_matrix_t *matrix,
        const char *s1,
        int s1Len)
{
    parasail_matrix_t *retval = NULL;
    size_t matrix_size = matrix->size*s1Len;
    size_t alphabet_size = matrix->size+1;
    int *new_mapper = NULL;
    int *new_matrix = NULL;
    char *new_alphabet = NULL;
    char *new_query = NULL;
    int i;

    PARASAIL_CHECK_NULL(matrix);

    if (matrix->type != PARASAIL_MATRIX_TYPE_SQUARE) {
        fprintf(stderr, "%s: attempted to convert non-square matrix to pssm\n", __func__);
        return NULL;
    }

    PARASAIL_NEW(retval, parasail_matrix_t);

    PARASAIL_CALLOC(new_mapper, int, 256);
    (void)memcpy(new_mapper, matrix->mapper, sizeof(int)*256);

    PARASAIL_CALLOC(new_matrix, int, matrix_size);

    PARASAIL_CALLOC(new_alphabet, char, alphabet_size);
    (void)memcpy(new_alphabet, matrix->alphabet, sizeof(char)*alphabet_size);

    PARASAIL_CALLOC(new_query, char, s1Len+1);
    (void)memcpy(new_query, s1, sizeof(char)*(s1Len+1));

    for (i=0; i<s1Len; ++i) {
        (void)memcpy(
                &new_matrix[matrix->size*i],
                &matrix->matrix[matrix->size*matrix->mapper[(unsigned char)s1[i]]],
                sizeof(int)*matrix->size);
    }

    retval->name = matrix->name;
    retval->matrix = new_matrix;
    retval->mapper = new_mapper;
    retval->size = matrix->size;
    retval->max = matrix->max;
    retval->min = matrix->min;
    retval->user_matrix = new_matrix;
    retval->type = PARASAIL_MATRIX_TYPE_PSSM;
    retval->length = s1Len;
    retval->alphabet = new_alphabet;
    retval->query = new_query;

    return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
cmpl $0x0, 0x30(%rdi)
jne 0x20baea
movl %edx, %r12d
movq %rsi, %r13
movq %rdi, %rbp
movl 0x18(%rdi), %r15d
movl $0x48, %edi
callq 0x19e150
testq %rax, %rax
je 0x20baf1
movq %rax, %rbx
movl $0x400, %edi            # imm = 0x400
callq 0x19e150
testq %rax, %rax
je 0x20baf8
movl %r15d, %ecx
imull %r12d, %ecx
movslq %ecx, %r14
movq 0x10(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
movq %rax, 0x48(%rsp)
movq %rax, %rdi
movq %rsi, 0x40(%rsp)
callq 0x19e0c0
shlq $0x2, %r14
movq %r14, %rdi
callq 0x19e150
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x20bacb
movslq %r15d, %rax
movq %rax, 0x20(%rsp)
leaq 0x1(%rax), %r14
movq %r14, %rdi
callq 0x19e150
testq %rax, %rax
je 0x20bacb
movl %r15d, 0x4(%rsp)
movq %r13, %r15
movq 0x38(%rbp), %rsi
movq %rax, 0x38(%rsp)
movq %rax, %rdi
movq %r14, %rdx
callq 0x19e0c0
leal 0x1(%r12), %eax
movslq %eax, %r13
movq %r13, %rdi
callq 0x19e150
testq %rax, %rax
je 0x20bb01
movq %rbp, 0x8(%rsp)
movq %rbx, 0x30(%rsp)
movq %rax, 0x28(%rsp)
movq %rax, %rdi
movq %r15, %rsi
movq %r15, 0x50(%rsp)
movq %r13, %rdx
callq 0x19e0c0
movq %r12, 0x10(%rsp)
testl %r12d, %r12d
movq 0x40(%rsp), %r15
movq 0x20(%rsp), %rcx
jle 0x20ba63
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rbx
leaq (,%rcx,4), %r13
movl 0x10(%rsp), %r12d
xorl %ebp, %ebp
movq 0x18(%rsp), %r14
movq 0x50(%rsp), %rax
movzbl (%rax,%rbp), %eax
movslq (%r15,%rax,4), %rax
imulq %rcx, %rax
leaq (%rbx,%rax,4), %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0x19e0c0
movq 0x20(%rsp), %rcx
incq %rbp
addq %r13, %r14
cmpq %rbp, %r12
jne 0x20ba33
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movq 0x30(%rsp), %rbx
movq %rax, (%rbx)
movq 0x18(%rsp), %rdx
movq %rdx, 0x8(%rbx)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rbx)
movl 0x4(%rsp), %eax
movl %eax, 0x18(%rbx)
movq 0x1c(%rcx), %rax
movq %rax, 0x1c(%rbx)
movq %rdx, 0x28(%rbx)
movl $0x1, 0x30(%rbx)
movq 0x10(%rsp), %rax
movl %eax, 0x34(%rbx)
movq 0x38(%rsp), %rax
movq %rax, 0x38(%rbx)
movq 0x28(%rsp), %rax
movq %rax, 0x40(%rbx)
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5cc506(%rip), %rax    # 0x7d7fd8
movq (%rax), %rdi
leaq 0x41d461(%rip), %rsi    # 0x628f3d
leaq 0x41d5ad(%rip), %rdx    # 0x629090
xorl %ebx, %ebx
movq %r14, %rcx
jmp 0x20bb1e
callq 0x19ed09
jmp 0x20bafd
callq 0x19ed4c
jmp 0x20bafd
callq 0x19ed28
xorl %ebx, %ebx
jmp 0x20bab9
movq 0x5cc4d0(%rip), %rax    # 0x7d7fd8
movq (%rax), %rdi
leaq 0x41d42b(%rip), %rsi    # 0x628f3d
leaq 0x41d577(%rip), %rdx    # 0x629090
xorl %ebx, %ebx
movq %r13, %rcx
xorl %eax, %eax
callq 0x19e180
jmp 0x20bab9