// File: 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
subq $0x160, %rsp            # imm = 0x160
movq %rdx, -0x158(%rbp)
movq %rdi, -0x148(%rbp)
movq %rdi, %rax
movq %rax, -0x150(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
leaq -0x1a(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x2360
movq -0x148(%rbp), %rdi
movq -0x140(%rbp), %rdx
leaq 0x2097(%rip), %rsi      # 0x805f
callq 0x4d50
jmp 0x5fcf
leaq -0x1a(%rbp), %rdi
callq 0x2240
movq -0x158(%rbp), %rdi
callq 0x68e0
subq $0x1, %rax
movl %eax, -0x30(%rbp)
movb $0x0, -0x31(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x6069
movq -0x158(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0x6900
cmpl $0x0, (%rax)
jne 0x6069
movq -0x158(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0x6900
movq -0x148(%rbp), %rdi
movslq (%rax), %rax
shlq $0x5, %rax
leaq 0x61f1(%rip), %rsi      # 0xc220
addq %rax, %rsi
callq 0x2280
jmp 0x6039
jmp 0x66c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x1a(%rbp), %rdi
callq 0x2240
jmp 0x66f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x66e8
cmpl $0x33, -0x30(%rbp)
jle 0x6089
movq -0x148(%rbp), %rdi
leaq 0x2201(%rip), %rsi      # 0x827e
callq 0x2290
jmp 0x6084
jmp 0x66c0
jmp 0x608b
cmpl $0x0, -0x30(%rbp)
jl 0x66be
movq -0x158(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0x6900
cmpl $0x0, (%rax)
je 0x662c
movq -0x148(%rbp), %rdi
callq 0x2320
testb $0x1, %al
jne 0x60d5
movq -0x148(%rbp), %rdi
leaq 0x1f92(%rip), %rsi      # 0x805e
callq 0x21d0
jmp 0x60d3
jmp 0x60d5
movl -0x30(%rbp), %eax
incl %eax
movslq %eax, %rcx
imulq $0x55555556, %rcx, %rdx # imm = 0x55555556
movq %rdx, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rdx
addl %ecx, %edx
movl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
movl %eax, -0x15c(%rbp)
je 0x649d
jmp 0x6106
movl -0x15c(%rbp), %eax
subl $0x1, %eax
je 0x63de
jmp 0x6117
movl -0x15c(%rbp), %eax
subl $0x2, %eax
jne 0x6627
jmp 0x6128
movq -0x158(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0x6900
cmpl $0x2, (%rax)
jge 0x6226
movq -0x158(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0x6900
movq -0x158(%rbp), %rdi
movl (%rax), %ecx
movl %ecx, %eax
leal (%rax,%rax,4), %eax
movl %eax, -0x160(%rbp)
movl -0x30(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x6900
movq -0x148(%rbp), %rdi
movq %rax, %rcx
movl -0x160(%rbp), %eax
movl (%rcx), %edx
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,2), %eax
cltq
shlq $0x5, %rax
leaq 0x6088(%rip), %rsi      # 0xc220
addq %rax, %rsi
callq 0x2280
jmp 0x61a2
movslq -0x30(%rbp), %rax
leaq 0x6433(%rip), %rdi      # 0xc5e0
shlq $0x5, %rax
addq %rax, %rdi
callq 0x2320
testb $0x1, %al
jne 0x6218
movslq -0x30(%rbp), %rax
shlq $0x5, %rax
leaq 0x6414(%rip), %rdx      # 0xc5e0
addq %rax, %rdx
leaq 0x1e88(%rip), %rsi      # 0x805e
leaq -0x58(%rbp), %rdi
callq 0x6920
jmp 0x61e1
movq -0x148(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x2280
jmp 0x61f3
leaq -0x58(%rbp), %rdi
callq 0x2110
jmp 0x6218
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x2110
jmp 0x66e8
movl -0x30(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x30(%rbp)
jmp 0x63d9
movq -0x158(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0x6900
cmpl $0x2, (%rax)
jne 0x627b
movq -0x158(%rbp), %rdi
movslq -0x30(%rbp), %rsi
movl %esi, %eax
decl %eax
movl %eax, -0x30(%rbp)
callq 0x6900
movq -0x148(%rbp), %rdi
movl (%rax), %ecx
addl %ecx, %ecx
movl %ecx, %eax
leal (%rax,%rax,4), %eax
cltq
shlq $0x5, %rax
leaq 0x5fb1(%rip), %rsi      # 0xc220
addq %rax, %rsi
callq 0x2280
jmp 0x6279
jmp 0x62cf
movq -0x158(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0x6900
cmpl $0x0, (%rax)
je 0x62cd
movq -0x158(%rbp), %rdi
movslq -0x30(%rbp), %rsi
movl %esi, %eax
decl %eax
movl %eax, -0x30(%rbp)
callq 0x6900
movq -0x148(%rbp), %rdi
movslq (%rax), %rax
shlq $0x5, %rax
leaq 0x5f64(%rip), %rcx      # 0xc220
leaq 0x280(%rax,%rcx), %rsi
callq 0x2280
jmp 0x62cb
jmp 0x62cd
jmp 0x62cf
movq -0x158(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0x6900
cmpl $0x0, (%rax)
je 0x634e
movq -0x158(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0x6900
movslq (%rax), %rax
shlq $0x5, %rax
leaq 0x5f1e(%rip), %rdx      # 0xc220
addq %rax, %rdx
leaq 0x1f81(%rip), %rsi      # 0x828d
leaq -0x78(%rbp), %rdi
callq 0x6920
jmp 0x6317
movq -0x148(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2280
jmp 0x6329
leaq -0x78(%rbp), %rdi
callq 0x2110
jmp 0x634e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x2110
jmp 0x66e8
movslq -0x30(%rbp), %rax
leaq 0x6287(%rip), %rdi      # 0xc5e0
shlq $0x5, %rax
addq %rax, %rdi
callq 0x2320
testb $0x1, %al
jne 0x63d0
movslq -0x30(%rbp), %rax
shlq $0x5, %rax
leaq 0x6268(%rip), %rdx      # 0xc5e0
addq %rax, %rdx
leaq 0x1cdc(%rip), %rsi      # 0x805e
leaq -0x98(%rbp), %rdi
callq 0x6920
jmp 0x6390
movq -0x148(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2280
jmp 0x63a5
leaq -0x98(%rbp), %rdi
callq 0x2110
jmp 0x63d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x2110
jmp 0x66e8
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x6627
movq -0x158(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0x6900
movq -0x148(%rbp), %rdi
movslq (%rax), %rax
shlq $0x5, %rax
leaq 0x5e1d(%rip), %rsi      # 0xc220
addq %rax, %rsi
callq 0x2280
jmp 0x640d
movslq -0x30(%rbp), %rax
leaq 0x61c8(%rip), %rdi      # 0xc5e0
shlq $0x5, %rax
addq %rax, %rdi
callq 0x2320
testb $0x1, %al
jne 0x648f
movslq -0x30(%rbp), %rax
shlq $0x5, %rax
leaq 0x61a9(%rip), %rdx      # 0xc5e0
addq %rax, %rdx
leaq 0x1c1d(%rip), %rsi      # 0x805e
leaq -0xb8(%rbp), %rdi
callq 0x6920
jmp 0x644f
movq -0x148(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x2280
jmp 0x6464
leaq -0xb8(%rbp), %rdi
callq 0x2110
jmp 0x648f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x2110
jmp 0x66e8
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x6627
cmpl $0x3, -0x30(%rbp)
jge 0x6566
movq -0x158(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0x6900
movq -0x148(%rbp), %rdi
movslq (%rax), %rax
shlq $0x5, %rax
leaq 0x5d54(%rip), %rsi      # 0xc220
addq %rax, %rsi
callq 0x2280
jmp 0x64d6
movslq -0x30(%rbp), %rax
leaq 0x60ff(%rip), %rdi      # 0xc5e0
shlq $0x5, %rax
addq %rax, %rdi
callq 0x2320
testb $0x1, %al
jne 0x6558
movslq -0x30(%rbp), %rax
shlq $0x5, %rax
leaq 0x60e0(%rip), %rdx      # 0xc5e0
addq %rax, %rdx
leaq 0x1b54(%rip), %rsi      # 0x805e
leaq -0xd8(%rbp), %rdi
callq 0x6920
jmp 0x6518
movq -0x148(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x2280
jmp 0x652d
leaq -0xd8(%rbp), %rdi
callq 0x2110
jmp 0x6558
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x2110
jmp 0x66e8
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x6625
movq -0x158(%rbp), %rdi
movslq -0x30(%rbp), %rsi
movl %esi, %eax
decl %eax
movl %eax, -0x30(%rbp)
callq 0x6900
movslq (%rax), %rax
shlq $0x5, %rax
leaq 0x5c95(%rip), %rsi      # 0xc220
addq %rax, %rsi
leaq 0x1ac9(%rip), %rdx      # 0x805e
leaq -0x118(%rbp), %rdi
callq 0x6a80
jmp 0x65a3
leaq 0x6076(%rip), %rdx      # 0xc620
leaq -0xf8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x6a30
jmp 0x65bf
movq -0x148(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x2280
jmp 0x65d4
leaq -0xf8(%rbp), %rdi
callq 0x2110
leaq -0x118(%rbp), %rdi
callq 0x2110
jmp 0x6625
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x6614
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x2110
leaq -0x118(%rbp), %rdi
callq 0x2110
jmp 0x66e8
jmp 0x6627
jmp 0x66b9
testb $0x1, -0x31(%rbp)
jne 0x66b0
movq -0x148(%rbp), %rdi
callq 0x2320
testb $0x1, %al
jne 0x66b0
cmpl $0x3, -0x30(%rbp)
jle 0x66b0
movslq -0x30(%rbp), %rax
shlq $0x5, %rax
leaq 0x5f89(%rip), %rdx      # 0xc5e0
addq %rax, %rdx
leaq 0x19fd(%rip), %rsi      # 0x805e
leaq -0x138(%rbp), %rdi
callq 0x6920
jmp 0x666f
movq -0x148(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x2280
jmp 0x6684
leaq -0x138(%rbp), %rdi
callq 0x2110
movb $0x1, -0x31(%rbp)
jmp 0x66b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x2110
jmp 0x66e8
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x608b
jmp 0x66c0
jmp 0x66c2
movb $0x1, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
jne 0x66d8
movq -0x148(%rbp), %rdi
callq 0x2110
movq -0x150(%rbp), %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x148(%rbp), %rdi
callq 0x2110
movq -0x28(%rbp), %rdi
callq 0x2350
nopl (%rax)