// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %rdx, %r14
movq %rdi, %rbx
leaq 0xa11(%rip), %rsi       # 0x405f
leaq -0x50(%rbp), %rdx
callq 0x31ac
movq (%r14), %rax
movq 0x8(%r14), %r15
subq %rax, %r15
shrq $0x2, %r15
decl %r15d
je 0x3684
cmpl $0x33, %r15d
jle 0x368d
leaq 0xc01(%rip), %rsi       # 0x4278
movq %rbx, %rdi
callq 0x2220
jmp 0x39a0
cmpl $0x0, (%rax)
je 0x3991
movl $0x0, -0x2c(%rbp)
leaq -0x50(%rbp), %r12
testl %r15d, %r15d
js 0x39a0
movl %r15d, %r13d
movq (%r14), %rax
cmpl $0x0, (%rax,%r13,4)
je 0x393a
cmpq $0x0, 0x8(%rbx)
je 0x36c8
movq %rbx, %rdi
leaq 0x99b(%rip), %rsi       # 0x405e
callq 0x2210
leal 0x1(%r15), %eax
xorl %edx, %edx
pushq $0x3
popq %rcx
divl %ecx
testl %edx, %edx
je 0x373d
cmpl $0x1, %edx
jne 0x37ae
movq (%r14), %rax
movslq (%rax,%r13,4), %rsi
shlq $0x5, %rsi
leaq 0x3a6e(%rip), %rax      # 0x7160
addq %rax, %rsi
movq %rbx, %rdi
callq 0x2230
shlq $0x5, %r13
leaq 0x3e18(%rip), %rax      # 0x7520
cmpq $0x0, 0x8(%r13,%rax)
je 0x37a6
leaq 0x3e05(%rip), %rax      # 0x7520
addq %rax, %r13
movq %r12, %rdi
leaq 0x936(%rip), %rsi       # 0x405e
movq %r13, %rdx
callq 0x3a81
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2230
jmp 0x379e
cmpl $0x2, %r15d
ja 0x3825
movq (%r14), %rax
movslq (%rax,%r13,4), %rsi
shlq $0x5, %rsi
leaq 0x3a07(%rip), %rax      # 0x7160
addq %rax, %rsi
movq %rbx, %rdi
callq 0x2230
shlq $0x5, %r13
leaq 0x3db1(%rip), %rax      # 0x7520
cmpq $0x0, 0x8(%r13,%rax)
je 0x37a6
leaq 0x3da2(%rip), %rax      # 0x7520
addq %rax, %r13
movq %r12, %rdi
leaq 0x8d3(%rip), %rsi       # 0x405e
movq %r13, %rdx
callq 0x3a81
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2230
movq %r12, %rdi
callq 0x2090
decl %r15d
jmp 0x3698
movq (%r14), %rcx
movl (%rcx,%r13,4), %eax
cmpl $0x1, %eax
jg 0x3883
cltq
imulq $0xa, %rax, %rax
movslq -0x4(%rcx,%r13,4), %rsi
addq %rax, %rsi
shlq $0x5, %rsi
leaq 0x3989(%rip), %rax      # 0x7160
addq %rax, %rsi
movq %rbx, %rdi
callq 0x2230
shlq $0x5, %r13
leaq 0x3d33(%rip), %rax      # 0x7520
cmpq $0x0, 0x8(%r13,%rax)
je 0x3931
leaq 0x3d20(%rip), %rax      # 0x7520
addq %rax, %r13
movq %r12, %rdi
leaq 0x851(%rip), %rsi       # 0x405e
movq %r13, %rdx
callq 0x3a81
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2230
jmp 0x3929
movq (%r14), %rax
movslq (%rax,%r13,4), %rsi
shlq $0x5, %rsi
leaq 0x3929(%rip), %rax      # 0x7160
addq %rax, %rsi
leaq -0x70(%rbp), %r13
movq %r13, %rdi
leaq 0x816(%rip), %rdx       # 0x405e
callq 0x3b20
movq %r12, %rdi
movq %r13, %rsi
leaq 0x3d06(%rip), %rdx      # 0x7560
callq 0x3af7
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2230
decl %r15d
movq %r12, %rdi
callq 0x2090
leaq -0x70(%rbp), %rdi
callq 0x2090
jmp 0x3698
movq %rax, %rsi
shlq $0x5, %rsi
movl $0x280, %ecx            # imm = 0x280
addq %rcx, %rsi
cmpq $0x2, %rax
cmoveq %rcx, %rsi
leaq 0x38bf(%rip), %rax      # 0x7160
addq %rax, %rsi
movq %rbx, %rdi
callq 0x2230
movslq %r15d, %r13
movq (%r14), %rax
movslq -0x4(%rax,%r13,4), %rdx
testq %rdx, %rdx
je 0x38ec
shlq $0x5, %rdx
leaq 0x3899(%rip), %rax      # 0x7160
addq %rax, %rdx
movq %r12, %rdi
leaq 0x9b3(%rip), %rsi       # 0x4287
callq 0x3a81
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2230
movq %r12, %rdi
callq 0x2090
decq %r13
shlq $0x5, %r13
leaq 0x3c26(%rip), %rax      # 0x7520
cmpq $0x0, 0x8(%r13,%rax)
je 0x3931
leaq 0x3c17(%rip), %rax      # 0x7520
addq %rax, %r13
movq %r12, %rdi
leaq 0x748(%rip), %rsi       # 0x405e
movq %r13, %rdx
callq 0x3a81
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2230
movq %r12, %rdi
callq 0x2090
addl $-0x2, %r15d
jmp 0x3698
movb $0x1, %al
testb $0x1, -0x2c(%rbp)
jne 0x3986
xorl %eax, %eax
cmpl $0x4, %r15d
jb 0x3986
cmpq $0x0, 0x8(%rbx)
je 0x3986
shlq $0x5, %r13
leaq 0x3bc4(%rip), %rax      # 0x7520
addq %rax, %r13
movq %r12, %rdi
leaq 0x6f5(%rip), %rsi       # 0x405e
movq %r13, %rdx
callq 0x3a81
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2230
movq %r12, %rdi
callq 0x2090
movb $0x1, %al
decl %r15d
movl %eax, -0x2c(%rbp)
jmp 0x3698
leaq 0x37c8(%rip), %rsi      # 0x7160
movq %rbx, %rdi
callq 0x2230
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x39e1
jmp 0x39f1
jmp 0x39f1
jmp 0x39f1
jmp 0x39e1
jmp 0x39f1
jmp 0x39e1
jmp 0x39f1
jmp 0x39e1
jmp 0x39f1
jmp 0x39e1
movq %rax, %r14
leaq -0x50(%rbp), %rdi
callq 0x2090
jmp 0x39d9
movq %rax, %r14
leaq -0x70(%rbp), %rdi
jmp 0x39e8
jmp 0x39f1
movq %rax, %r14
leaq -0x50(%rbp), %rdi
callq 0x2090
jmp 0x39f4
jmp 0x39f1
movq %rax, %r14
movq %rbx, %rdi
callq 0x2090
movq %r14, %rdi
callq 0x21f0