// File: VanAndelInstitute[P]intent/src/edlib.cpp
// Function: transformSequences[abi:cxx11](char const*, int, char const*, int, unsigned char**, unsigned char**)
static string transformSequences(const char* const queryOriginal, const int queryLength,
                                 const char* const targetOriginal, const int targetLength,
                                 unsigned char** const queryTransformed,
                                 unsigned char** const targetTransformed) {
    // Alphabet is constructed from letters that are present in sequences.
    // Each letter is assigned an ordinal number, starting from 0 up to alphabetLength - 1,
    // and new query and target are created in which letters are replaced with their ordinal numbers.
    // This query and target are used in all the calculations later.
    *queryTransformed = static_cast<unsigned char *>(malloc(sizeof(unsigned char) * queryLength));
    *targetTransformed = static_cast<unsigned char *>(malloc(sizeof(unsigned char) * targetLength));

    string alphabet = "";

    // Alphabet information, it is constructed on fly while transforming sequences.
    // letterIdx[c] is index of letter c in alphabet.
    unsigned char letterIdx[MAX_UCHAR + 1];
    bool inAlphabet[MAX_UCHAR + 1]; // inAlphabet[c] is true if c is in alphabet
    for (int i = 0; i < MAX_UCHAR + 1; i++) inAlphabet[i] = false;

    for (int i = 0; i < queryLength; i++) {
        unsigned char c = static_cast<unsigned char>(queryOriginal[i]);
        if (!inAlphabet[c]) {
            inAlphabet[c] = true;
            letterIdx[c] = static_cast<unsigned char>(alphabet.size());
            alphabet += queryOriginal[i];
        }
        (*queryTransformed)[i] = letterIdx[c];
    }
    for (int i = 0; i < targetLength; i++) {
        unsigned char c = static_cast<unsigned char>(targetOriginal[i]);
        if (!inAlphabet[c]) {
            inAlphabet[c] = true;
            letterIdx[c] = static_cast<unsigned char>(alphabet.size());
            alphabet += targetOriginal[i];
        }
        (*targetTransformed)[i] = letterIdx[c];
    }

    return alphabet;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movq %rdi, -0x278(%rbp)
movq %rdi, %rax
movq %rax, -0x280(%rbp)
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movslq -0x14(%rbp), %rdi
callq 0x8770
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movslq -0x24(%rbp), %rdi
callq 0x8770
movq %rax, %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movb $0x0, -0x31(%rbp)
leaq -0x32(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x8980
movq -0x278(%rbp), %rdi
movq -0x270(%rbp), %rdx
leaq 0xa113(%rip), %rsi      # 0x6f4d9
callq 0x35e90
jmp 0x653cd
leaq -0x32(%rbp), %rdi
callq 0x85e0
movl $0x0, -0x254(%rbp)
cmpl $0x100, -0x254(%rbp)    # imm = 0x100
jge 0x65426
movslq -0x254(%rbp), %rax
movb $0x0, -0x250(%rbp,%rax)
movl -0x254(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x254(%rbp)
jmp 0x653e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x32(%rbp), %rdi
callq 0x85e0
jmp 0x655df
movl $0x0, -0x258(%rbp)
movl -0x258(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x654fe
movq -0x10(%rbp), %rax
movslq -0x258(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x259(%rbp)
movzbl -0x259(%rbp), %eax
testb $0x1, -0x250(%rbp,%rax)
jne 0x654cb
movq -0x278(%rbp), %rdi
movzbl -0x259(%rbp), %eax
movb $0x1, -0x250(%rbp,%rax)
callq 0x8410
movq -0x278(%rbp), %rdi
movb %al, %cl
movzbl -0x259(%rbp), %eax
movb %cl, -0x150(%rbp,%rax)
movq -0x10(%rbp), %rax
movslq -0x258(%rbp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x83b0
jmp 0x654ac
jmp 0x654cb
movq -0x278(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x8a98
jmp 0x655df
movzbl -0x259(%rbp), %eax
movb -0x150(%rbp,%rax), %dl
movq -0x30(%rbp), %rax
movq (%rax), %rax
movslq -0x258(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x258(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x258(%rbp)
jmp 0x65430
movl $0x0, -0x260(%rbp)
movl -0x260(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x655b9
movq -0x20(%rbp), %rax
movslq -0x260(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x261(%rbp)
movzbl -0x261(%rbp), %eax
testb $0x1, -0x250(%rbp,%rax)
jne 0x65586
movq -0x278(%rbp), %rdi
movzbl -0x261(%rbp), %eax
movb $0x1, -0x250(%rbp,%rax)
callq 0x8410
movq -0x278(%rbp), %rdi
movb %al, %cl
movzbl -0x261(%rbp), %eax
movb %cl, -0x150(%rbp,%rax)
movq -0x20(%rbp), %rax
movslq -0x260(%rbp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x83b0
jmp 0x65584
jmp 0x65586
movzbl -0x261(%rbp), %eax
movb -0x150(%rbp,%rax), %dl
movq 0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x260(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x260(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x260(%rbp)
jmp 0x65508
movb $0x1, -0x31(%rbp)
testb $0x1, -0x31(%rbp)
jne 0x655cf
movq -0x278(%rbp), %rdi
callq 0x8a98
movq -0x280(%rbp), %rax
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x8970
nopl (%rax,%rax)