// File: /workspace/github_cpp_makefile_star2_O1/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 0x3c56
movq (%r14), %rax
movq 0x8(%r14), %r12
subq %rax, %r12
shrq $0x2, %r12
decl %r12d
jne 0x40ed
movl (%rax), %eax
testq %rax, %rax
je 0x451f
cmpl $0x33, %r12d
jle 0x4113
movq 0x8(%rbx), %rdx
leaq 0x1136(%rip), %rcx      # 0x5234
movl $0xe, %r8d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2190
jmp 0x453b
testl %r12d, %r12d
js 0x453b
movl $0x0, -0x4c(%rbp)
leaq 0x33e6(%rip), %r13      # 0x7510
leaq 0xf2d(%rip), %r15       # 0x505e
movq %rbx, -0x58(%rbp)
movl %r12d, %r12d
movq (%r14), %rax
cmpl $0x0, (%rax,%r12,4)
je 0x41db
cmpq $0x0, 0x8(%rbx)
je 0x4158
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2220
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 0x4243
cmpl $0x1, %eax
jne 0x42bc
movq (%r14), %rax
movslq (%rax,%r12,4), %rax
shlq $0x5, %rax
leaq 0x2fbd(%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 0x4511
addq %r13, %rdx
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x4666
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %rbx, %rdi
callq 0x2060
jmp 0x42a2
testb $0x1, -0x4c(%rbp)
jne 0x4511
cmpl $0x4, %r12d
jl 0x4511
cmpq $0x0, 0x8(%rbx)
je 0x4511
movq %r12, %rdx
shlq $0x5, %rdx
addq %r13, %rdx
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x4666
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 0x4239
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2140
movb $0x1, %al
movl %eax, -0x4c(%rbp)
jmp 0x4511
cmpl $0x2, %r12d
jg 0x4346
movq (%r14), %rax
movslq (%rax,%r12,4), %rax
shlq $0x5, %rax
leaq 0x2ef1(%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 0x4511
addq %r13, %rdx
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x4666
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 0x4511
movq -0x38(%rbp), %rsi
jmp 0x4509
movq (%r14), %rcx
movslq (%rcx,%r12,4), %rax
cmpq $0x1, %rax
jg 0x43ca
leaq (%rax,%rax,4), %rax
movslq -0x4(%rcx,%r12,4), %rcx
leaq (%rcx,%rax,2), %rax
shlq $0x5, %rax
leaq 0x2e6b(%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 0x433d
addq %r13, %rdx
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x4666
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 0x433d
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2140
addl $-0x2, %r12d
jmp 0x4514
movq %r13, %rbx
movq (%r14), %rax
movslq (%rax,%r12,4), %rax
shlq $0x5, %rax
leaq -0x70(%rbp), %rcx
movq %rcx, -0x80(%rbp)
leaq 0x2ded(%rip), %rcx      # 0x7150
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
addq %rsi, %rdx
leaq -0x80(%rbp), %r13
movq %r13, %rdi
callq 0x3bbc
movq %r13, %rdi
movq %r15, %rsi
callq 0x2220
movq 0x31c3(%rip), %rsi      # 0x7550
movq 0x31c4(%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 0x44ae
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x44b4
leal 0x14(%rax), %ecx
cmpl $0x2, %eax
movl $0x14, %eax
cmovel %eax, %ecx
shlq $0x5, %rcx
leaq 0x2d6d(%rip), %rax      # 0x7150
movq (%rcx,%rax), %rsi
movq 0x8(%rcx,%rax), %rdx
movq %rbx, %rdi
callq 0x2060
movq %r13, %r15
movslq %r12d, %rcx
leaq -0x1(%rcx), %r13
movq (%r14), %rax
cmpl $0x0, -0x4(%rax,%rcx,4)
je 0x4453
movslq (%rax,%r13,4), %rdx
shlq $0x5, %rdx
leaq 0x2d39(%rip), %rax      # 0x7150
addq %rax, %rdx
leaq -0x48(%rbp), %rdi
leaq 0xe1e(%rip), %rsi       # 0x5243
callq 0x4666
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 0x4453
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2140
shlq $0x5, %r13
cmpq $0x0, 0x8(%r13,%r15)
je 0x449e
addq %r15, %r13
leaq -0x48(%rbp), %rdi
leaq 0xbf1(%rip), %rsi       # 0x505e
movq %r13, %rdx
callq 0x4666
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 0x449e
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2140
addl $-0x2, %r12d
movq %r15, %r13
leaq 0xbb2(%rip), %r15       # 0x505e
jmp 0x4514
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 0x44f8
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x4511
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2140
decl %r12d
testl %r12d, %r12d
jns 0x4135
jmp 0x453b
shlq $0x5, %rax
leaq 0x2c26(%rip), %rcx      # 0x7150
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
movq %rbx, %rdi
callq 0x2060
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x459f
jmp 0x45bf
jmp 0x459f
jmp 0x45bf
jmp 0x459f
jmp 0x45bf
jmp 0x459f
jmp 0x45bf
movq %rbx, -0x58(%rbp)
jmp 0x45bf
jmp 0x459f
jmp 0x45bf
movq %rax, %r14
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x458a
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2140
jmp 0x458a
jmp 0x4587
movq %rax, %r14
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x45c2
movq -0x70(%rbp), %rsi
jmp 0x45b3
jmp 0x45bf
movq %rax, %r14
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x45c2
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2140
jmp 0x45c2
jmp 0x45bf
movq %rax, %r14
movq -0x58(%rbp), %rax
movq (%rax), %rdi
cmpq -0x60(%rbp), %rdi
je 0x45de
movq -0x60(%rbp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x2140
movq %r14, %rdi
callq 0x2200