// File: /workspace/github_cpp_makefile_star2_O3/danishansari[P]NumberToText/src/NumToEnglish.cpp
// Function: NumToEnglish::getText[abi:cxx11](std::vector<int, std::allocator<int>>)
std::string NumToEnglish::getText(vector<int> digitsVec)
{
    string text = "";
    
    int i = digitsVec.size()-1;

    bool visited = false;

    // if number is zero, convert and return
    if (i == 0 && digitsVec[i] == 0)
        text += digitStr_g[digitsVec[i]];
    else if (i > 51) // if number is too big, not spported
        text = "too long input";
    else // convert number to text
    {
        // iterate for ech digits
        while (i >= 0)
        {
            if (digitsVec[i]) // if number is non-zero
            { 
                if (!text.empty())
                    text += " ";

                // switch-case to check number position, taking 3 at a time
                switch ((i+1)%3) 
                {
                    case 2: // current number at 2nd position
                    {
                        // in number is less than 2, its already there in the array
                        if (digitsVec[i] < 2)
                        {
                            // get corrsponding text
                            text += digitStr_g[digitsVec[i]*10+digitsVec[i-1]];
                            if (!placeVal_g[i].empty())
                                text += " " + placeVal_g[i];

                            i -= 2;
                        }
                        else // number is bigger, need to construct text
                        {
                            if (digitsVec[i] == 2) // if number is 2, mutiply by 10 coz 
                            {                      // is a two digit number.
                                text += digitStr_g[digitsVec[i--]*10];
                            }
                            else if (digitsVec[i]) // other number, add 20 and get the text from vector
                            {
                                text += digitStr_g[20+digitsVec[i--]];
                            }

                            if (digitsVec[i]) // remaining last digit, if non-zero
                            {
                                // get text from array
                                text += "-" + digitStr_g[digitsVec[i]];
                            }

                            // get the place value from array
                            if (!placeVal_g[i].empty())
                                text +=  " " + placeVal_g[i];

                            i --;
                        }

                        break;
                    }
                    case 1: // number is at 1st position
                    {
                        text += digitStr_g[digitsVec[i]];
                        if (!placeVal_g[i].empty())
                            text += " " + placeVal_g[i];

                        i --;
                        break;
                    }
                    case 0: // one digit number
                    {
                        if (i < 3) // if number is less than 3, get the place
                        {
                            text += digitStr_g[digitsVec[i]];
                            if (!placeVal_g[i].empty())
                                text += " " + placeVal_g[i];

                            i --;
                        }
                        else // number is bigger at that position have place value as hundred
                        {
                            text += digitStr_g[digitsVec[i--]] + " " +  placeVal_g[2];
                        }
                        break;
                    }
                }
            }
            else
            {
                // number having more than one zeros, we will visit here once.
                // e.g. 001, 100, 1000, 10000, 100000
                if (!visited && !text.empty() && i > 3)
                {
                    text +=  " " + placeVal_g[i];
                    visited = true;
                }

                i --;
            }
        }
    }

    // return converted text
    return text;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r14
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, -0x60(%rbp)
movq %rax, (%rdi)
leaq 0xf98(%rip), %rdx       # 0x505f
movq %rdx, %rsi
callq 0x3c50
movq (%r14), %rax
movq 0x8(%r14), %r12
subq %rax, %r12
shrq $0x2, %r12
decl %r12d
movq %rbx, -0x58(%rbp)
je 0x410c
cmpl $0x33, %r12d
jle 0x412c
movq 0x8(%rbx), %rdx
leaq 0x1137(%rip), %rcx      # 0x522e
movl $0xe, %r8d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2180
jmp 0x454f
cmpl $0x0, (%rax)
jne 0x4135
movq 0x3038(%rip), %rsi      # 0x7150
movq 0x3039(%rip), %rdx      # 0x7158
movq %rbx, %rdi
callq 0x2060
jmp 0x454f
testl %r12d, %r12d
js 0x454f
movl $0x0, -0x4c(%rbp)
leaq 0x33cd(%rip), %r13      # 0x7510
leaq 0xf14(%rip), %r15       # 0x505e
movl %r12d, %r12d
movq (%r14), %rax
cmpl $0x0, (%rax,%r12,4)
je 0x41f0
cmpq $0x0, 0x8(%rbx)
je 0x416d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2210
leal 0x1(%r12), %eax
movq %rax, %rcx
movl $0xaaaaaaab, %edx       # imm = 0xAAAAAAAB
imulq %rdx, %rcx
shrq $0x21, %rcx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
je 0x425a
cmpl $0x1, %eax
jne 0x42d3
movq (%r14), %rax
movslq (%rax,%r12,4), %rax
shlq $0x5, %rax
leaq 0x2fa8(%rip), %rcx      # 0x7150
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
movq %rbx, %rdi
callq 0x2060
movq %r12, %rdx
shlq $0x5, %rdx
cmpq $0x0, 0x8(%rdx,%r13)
je 0x4543
addq %r13, %rdx
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x4682
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %rbx, %rdi
callq 0x2060
jmp 0x42b9
movb $0x1, %al
testb $0x1, -0x4c(%rbp)
jne 0x424f
xorl %eax, %eax
cmpl $0x4, %r12d
jl 0x424f
cmpq $0x0, 0x8(%rbx)
je 0x424f
movq %r12, %rdx
shlq $0x5, %rdx
addq %r13, %rdx
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x4682
leaq -0x38(%rbp), %r15
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %rbx, %rdi
callq 0x2060
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x4246
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2140
movb $0x1, %al
leaq 0xe0f(%rip), %r15       # 0x505e
decl %r12d
movl %eax, -0x4c(%rbp)
jmp 0x4546
cmpl $0x2, %r12d
jg 0x435e
movq (%r14), %rax
movslq (%rax,%r12,4), %rax
shlq $0x5, %rax
leaq 0x2eda(%rip), %rcx      # 0x7150
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
movq %rbx, %rdi
callq 0x2060
movq %r12, %rdx
shlq $0x5, %rdx
cmpq $0x0, 0x8(%rdx,%r13)
je 0x4543
addq %r13, %rdx
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x4682
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %rbx, %rdi
callq 0x2060
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x4543
movq -0x38(%rbp), %rsi
jmp 0x453b
movq (%r14), %rcx
movl (%rcx,%r12,4), %eax
cmpl $0x1, %eax
jg 0x43e2
cltq
leaq (%rax,%rax,4), %rax
movslq -0x4(%rcx,%r12,4), %rcx
leaq (%rcx,%rax,2), %rax
shlq $0x5, %rax
leaq 0x2e53(%rip), %rcx      # 0x7150
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
movq %rbx, %rdi
callq 0x2060
movq %r12, %rdx
shlq $0x5, %rdx
cmpq $0x0, 0x8(%rdx,%r13)
je 0x4355
addq %r13, %rdx
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x4682
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %rbx, %rdi
callq 0x2060
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x4355
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2140
addl $-0x2, %r12d
jmp 0x4546
movq %r13, %rbx
movq (%r14), %rax
movslq (%rax,%r12,4), %rax
shlq $0x5, %rax
leaq -0x70(%rbp), %rcx
movq %rcx, -0x80(%rbp)
leaq 0x2dd5(%rip), %rcx      # 0x7150
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
addq %rsi, %rdx
leaq -0x80(%rbp), %r13
movq %r13, %rdi
callq 0x3bb2
movq %r13, %rdi
movq %r15, %rsi
callq 0x2210
movq 0x31ab(%rip), %rsi      # 0x7550
movq 0x31ac(%rip), %rdx      # 0x7558
movq %r13, %rdi
callq 0x2060
leaq -0x38(%rbp), %rsi
movq %rsi, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
movq %rbx, %r13
je 0x44e0
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x44e6
movq %rax, %rcx
shlq $0x5, %rcx
cmpq $0x2, %rax
leaq 0x2d5c(%rip), %rdx      # 0x7150
leaq 0x280(%rcx,%rdx), %rax
leaq 0x288(%rcx,%rdx), %rcx
leaq 0x2fcd(%rip), %rdx      # 0x73d8
cmoveq %rdx, %rcx
leaq 0x2fba(%rip), %rdx      # 0x73d0
cmoveq %rdx, %rax
movq (%rax), %rsi
movq (%rcx), %rdx
movq %rbx, %rdi
callq 0x2060
movq %r13, %r15
movslq %r12d, %r13
movq (%r14), %rax
movslq -0x4(%rax,%r13,4), %rdx
testq %rdx, %rdx
je 0x4482
shlq $0x5, %rdx
leaq 0x2d0a(%rip), %rax      # 0x7150
addq %rax, %rdx
leaq -0x48(%rbp), %rdi
leaq 0xde9(%rip), %rsi       # 0x523d
callq 0x4682
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %rbx, %rdi
callq 0x2060
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x4482
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2140
decq %r13
shlq $0x5, %r13
cmpq $0x0, 0x8(%r13,%r15)
je 0x44d0
addq %r15, %r13
leaq -0x48(%rbp), %rdi
leaq 0xbbf(%rip), %rsi       # 0x505e
movq %r13, %rdx
callq 0x4682
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %rbx, %rdi
callq 0x2060
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x44d0
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2140
addl $-0x2, %r12d
movq %r15, %r13
leaq 0xb80(%rip), %r15       # 0x505e
jmp 0x4546
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq -0x58(%rbp), %rbx
movq 0x8(%rax), %rdx
movq %rdx, -0x40(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %rbx, %rdi
callq 0x2060
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x452a
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x4543
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2140
decl %r12d
testl %r12d, %r12d
jns 0x414a
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x45db
jmp 0x45bb
jmp 0x45db
jmp 0x45bb
jmp 0x45db
jmp 0x45bb
jmp 0x45db
jmp 0x45bb
jmp 0x45db
movq %rax, %r14
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
jne 0x45cb
jmp 0x45de
jmp 0x45db
movq %rax, %r14
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x45a6
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2140
jmp 0x45a6
jmp 0x45a3
movq %rax, %r14
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x45de
movq -0x70(%rbp), %rsi
jmp 0x45cf
jmp 0x45db
movq %rax, %r14
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x45de
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2140
jmp 0x45de
jmp 0x45db
movq %rax, %r14
movq -0x58(%rbp), %rax
movq (%rax), %rdi
cmpq -0x60(%rbp), %rdi
je 0x45fa
movq -0x60(%rbp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x2140
movq %r14, %rdi
callq 0x21f0