// File: billDrett[P]Bulletin-Boards/boardServer.cpp
// Function: BoardServer::nextState(char*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
int BoardServer::nextState(char* buff, int nread, std::string str1, std::string str2, std::string str3, std::string& commandRest) //mporei na exw panw apo mia entolh sto idio read 'h na min exw kamia
{                                                                                                                                 // prepei na parw thn prwth pou tha sinantisw
    char* tmp1 = findSubstring(buff, str1.c_str(), nread);
    char* tmp2 = findSubstring(buff, str2.c_str(), nread);
    char* tmp3 = findSubstring(buff, str3.c_str(), nread);


    if(tmp1 == NULL)tmp1 = buff + nread; //vazw thn megaliteri thmi se periptwsh poun dn yparxei
    if(tmp2 == NULL)tmp2 = buff + nread;
    if(tmp3 == NULL)tmp3 = buff + nread;

    if(tmp1 > tmp2) //prepei na parw thn pio mikri timh
    {
        if(tmp2 > tmp3) return 3;
        else return 2;
    }
    else //tmp1 <= tmp2
    {
        if(tmp1> tmp3) return 3;
        else //tmp1 <= tmp2 and tmp1 <=tmp3
        {
            if(tmp1 == (buff + nread)) //mporei na einai ola isa tote dn yparxei kanena
            {
                if((tmp1 = getAfterTag(buff, "<", nread)) != NULL) //apothikeuw meros tou string
                {
                    commandRest.assign(tmp1-1, nread+1); // -1 giati thelw na krathsw kai to "< kai +1 sto read gia na to symperilavw
                }

                return -1;
            }
            return 1;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %r9, -0x60(%rbp)
movq %r8, -0x70(%rbp)
movq %rcx, -0x80(%rbp)
movq %rdi, %rax
movq -0x80(%rbp), %rdi
movq 0x10(%rbp), %rcx
movq %rax, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rdi, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
callq 0x3130
movq -0x78(%rbp), %rdi
movq %rax, %rsi
movl -0x1c(%rbp), %edx
callq 0x8d20
movq -0x70(%rbp), %rdi
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
callq 0x3130
movq -0x68(%rbp), %rdi
movq %rax, %rsi
movl -0x1c(%rbp), %edx
callq 0x8d20
movq -0x60(%rbp), %rdi
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
callq 0x3130
movq -0x58(%rbp), %rdi
movq %rax, %rsi
movl -0x1c(%rbp), %edx
callq 0x8d20
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x79f7
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x7a0d
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x7a23
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jbe 0x7a49
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jbe 0x7a40
movl $0x3, -0x4(%rbp)
jmp 0x7ab8
movl $0x2, -0x4(%rbp)
jmp 0x7ab8
movq -0x40(%rbp), %rax
cmpq -0x50(%rbp), %rax
jbe 0x7a5c
movl $0x3, -0x4(%rbp)
jmp 0x7ab8
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jne 0x7ab1
movq -0x18(%rbp), %rdi
leaq 0x3698(%rip), %rsi      # 0xb113
leaq -0x1c(%rbp), %rdx
callq 0x8de0
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x7aa8
movq 0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $-0x1, %rsi
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
callq 0x33c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7ab8
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)