// File: saumya-prakash[P]AssemblerEmulator/Assembler.cpp
// Function: Assembler::valid_number(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
bool Assembler::valid_number(const string& s) const
{
    string::const_iterator it = s.begin();

    if(*it=='+' || *it=='-')
        ++it;

    if(it==s.end())     // only sign with no digit(s) not allowed
        return false;


    if(*it=='0')       // probably octal or hex
    {
        ++it;

        if(it==s.end())
            return true;    // represnts 0/ +0/ -0

        if(*it=='x' || *it=='X')       // a hex
        {
            it++;

            while(it!=s.end())
            {
                switch(*it)
                {   case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
                    case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
                    case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
                                it++;
                                break;
                    

                    default:    return false;    
                }
            }

            return true;    // a valid hexadecimal number
        }

        else        // octal
        {
            while(it!=s.end())
            {
                switch(*it)
                {
                    case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7':
                            it++;
                            break;
                    
                    default:    return false;
                }
            }
        }
        
    }


    while(it!=s.end())      // a decimal number
    {
        if(isdigit(*it)==0)
            return false;

        it++;
    }

    return true;
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movq 0x60(%rsp), %rdi
callq 0x3260
movq %rax, 0x58(%rsp)
leaq 0x58(%rsp), %rdi
callq 0xc0e0
movsbl (%rax), %eax
cmpl $0x2b, %eax
je 0x60a1
leaq 0x58(%rsp), %rdi
callq 0xc0e0
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x60ab
leaq 0x58(%rsp), %rdi
callq 0xc0f0
movq 0x60(%rsp), %rdi
callq 0x34c0
movq %rax, 0x50(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0xc110
testb $0x1, %al
jne 0x60cf
jmp 0x60d9
movb $0x0, 0x77(%rsp)
jmp 0x629d
leaq 0x58(%rsp), %rdi
callq 0xc0e0
movsbl (%rax), %eax
cmpl $0x30, %eax
jne 0x6241
leaq 0x58(%rsp), %rdi
callq 0xc0f0
movq 0x60(%rsp), %rdi
callq 0x34c0
movq %rax, 0x48(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0xc110
testb $0x1, %al
jne 0x611d
jmp 0x6127
movb $0x1, 0x77(%rsp)
jmp 0x629d
leaq 0x58(%rsp), %rdi
callq 0xc0e0
movsbl (%rax), %eax
cmpl $0x78, %eax
je 0x614f
leaq 0x58(%rsp), %rdi
callq 0xc0e0
movsbl (%rax), %eax
cmpl $0x58, %eax
jne 0x61e4
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
callq 0xc150
movq %rax, 0x40(%rsp)
movq 0x60(%rsp), %rdi
callq 0x34c0
movq %rax, 0x38(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0xc190
testb $0x1, %al
jne 0x6184
jmp 0x61da
leaq 0x58(%rsp), %rdi
callq 0xc0e0
movsbl (%rax), %eax
movl %eax, 0xc(%rsp)
addl $-0x30, %eax
subl $0xa, %eax
jb 0x61bb
jmp 0x619f
movl 0xc(%rsp), %eax
addl $-0x41, %eax
subl $0x6, %eax
jb 0x61bb
jmp 0x61ad
movl 0xc(%rsp), %eax
addl $-0x61, %eax
subl $0x5, %eax
ja 0x61ce
jmp 0x61bb
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
callq 0xc150
movq %rax, 0x30(%rsp)
jmp 0x61d8
movb $0x0, 0x77(%rsp)
jmp 0x629d
jmp 0x6160
movb $0x1, 0x77(%rsp)
jmp 0x629d
jmp 0x61e6
movq 0x60(%rsp), %rdi
callq 0x34c0
movq %rax, 0x28(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xc190
testb $0x1, %al
jne 0x620a
jmp 0x623d
leaq 0x58(%rsp), %rdi
callq 0xc0e0
movsbl (%rax), %eax
addl $-0x30, %eax
subl $0x7, %eax
ja 0x6234
jmp 0x6221
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
callq 0xc150
movq %rax, 0x20(%rsp)
jmp 0x623b
movb $0x0, 0x77(%rsp)
jmp 0x629d
jmp 0x61e6
jmp 0x623f
jmp 0x6241
jmp 0x6243
movq 0x60(%rsp), %rdi
callq 0x34c0
movq %rax, 0x18(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0xc190
testb $0x1, %al
jne 0x6267
jmp 0x6298
leaq 0x58(%rsp), %rdi
callq 0xc0e0
movsbl (%rax), %edi
callq 0x3250
cmpl $0x0, %eax
jne 0x6285
movb $0x0, 0x77(%rsp)
jmp 0x629d
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
callq 0xc150
movq %rax, 0x10(%rsp)
jmp 0x6243
movb $0x1, 0x77(%rsp)
movb 0x77(%rsp), %al
andb $0x1, %al
addq $0x78, %rsp
retq
nopl (%rax,%rax)