// File: /workspace/github_cpp_makefile_star2_O2/LiGaCu[P]Distributed_System_to_Compute_the_Shortest_Path/serverB.cpp
// Function: searchmap(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, char, int, int)
int searchmap(std::string &mapbuff,char mapid, int srcVtxid, int dstVtxid)
{
    std::string line;
    int foundmap = 0, foundsrc = 0, founddst = 0;
    int lspacepos, rspacepos, fstdgt, secdgt;

    std::ifstream map2;
    map2.open("./map2.txt");

    if (map2.is_open())
    {
        while ( getline (map2,line) )
        {
            if (foundmap)
            {
                if (line.length() == 1 && isalpha(line.c_str()[0])) // next map begins
                    break;
                line.append("\n");
                mapbuff.append(line);

                lspacepos = -1; rspacepos = -1; 
                lspacepos = line.find(" ");
                rspacepos = line.find(" ",lspacepos+1);
                if(lspacepos != -1 && rspacepos != -1)
                {
                    fstdgt = atoi(line.substr(0,lspacepos).c_str());
                    secdgt = atoi(line.substr(lspacepos+1,rspacepos-lspacepos-1).c_str());
                    if (fstdgt == srcVtxid)
                        foundsrc = 1;
                    else if (fstdgt == dstVtxid)
                        founddst = 1;

                    if (secdgt == srcVtxid)
                        foundsrc = 1;
                    else if (secdgt == dstVtxid)
                        founddst = 1;
                }
            }
            else if (line.compare(&mapid) == 0) // found the required map
            {
                foundmap = 1;
                mapbuff.clear();
                mapbuff.append("serverB\n");
            }
        }
        map2.close();

        if(foundmap == 1 && foundsrc == 1 && founddst ==1)
            return 1;
        else
        {
            mapbuff.clear();
            if (!foundmap)
                mapbuff.append("serverB!m");
            else if (!foundsrc && founddst)
                mapbuff.append("serverB!s");
            else if (foundsrc && !founddst)
                mapbuff.append("serverB!d");
            else if (!foundsrc && !founddst)
                mapbuff.append("serverB!b");

            if (foundmap)
                return 1;
            else
                return 0;
        }
    }
    else
    {
        std::cout << "Unable to open file" << std::endl;
        exit(1);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movl %ecx, 0x1c(%rsp)
movl %edx, 0x18(%rsp)
movq %rdi, 0x8(%rsp)
movb %sil, 0x3(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x60(%rsp), %rdi
callq 0x2130
leaq 0xa4a(%rip), %rsi       # 0x3133
leaq 0x60(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x20d0
leaq 0xd8(%rsp), %rdi
callq 0x2070
testb %al, %al
je 0x297a
movb $0x1, %r13b
movq $0x0, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
xorl %r15d, %r15d
leaq 0x20(%rsp), %rbx
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x28cd
testb $0x1, %r13b
je 0x278c
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
leaq 0x3(%rsp), %rsi
callq 0x20a0
movb $0x1, %r13b
xorl %r15d, %r15d
testl %eax, %eax
jne 0x2727
movq 0x8(%rsp), %rdi
andq $0x0, 0x8(%rdi)
movq (%rdi), %rax
movb $0x0, (%rax)
movb $0x1, %r15b
xorl %r13d, %r13d
leaq 0x9b9(%rip), %rsi       # 0x313e
callq 0x21f0
jmp 0x2727
cmpq $0x1, 0x28(%rsp)
jne 0x27a9
movq 0x20(%rsp), %rax
movsbl (%rax), %edi
callq 0x21c0
testl %eax, %eax
jne 0x28cd
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
leaq 0x98d(%rip), %rsi       # 0x3145
callq 0x21f0
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x2210
xorl %r13d, %r13d
movq %rbx, %rdi
leaq 0x8f9(%rip), %r15       # 0x30d0
movq %r15, %rsi
xorl %edx, %edx
callq 0x2230
movq %rax, %r12
movq %rax, %rbp
shlq $0x20, %rbp
movabsq $0x100000000, %rax      # imm = 0x100000000
leaq (%rax,%rbp), %r14
sarq $0x20, %r14
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x2230
movb $0x1, %r15b
cmpl $-0x1, %r12d
je 0x2727
movl %eax, %ecx
cmpl $-0x1, %ecx
je 0x2727
movq %rax, %r15
sarq $0x20, %rbp
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %rbp, %rcx
callq 0x2120
movq 0x10(%rsp), %r13
movq 0x40(%rsp), %rdi
callq 0x21b0
movl %eax, %ebp
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x20b0
notl %r12d
addl %r12d, %r15d
movslq %r15d, %rcx
movq %rbx, %rdi
leaq 0x20(%rsp), %rsi
movq %r14, %rdx
callq 0x2120
movq 0x40(%rsp), %rdi
callq 0x21b0
movl %eax, %r14d
movq %rbx, %rdi
callq 0x20b0
movl 0x1c(%rsp), %ecx
cmpl %ecx, %ebp
movl 0x4(%rsp), %edi
movl %edi, %eax
pushq $0x1
popq %rsi
cmovel %esi, %eax
movl 0x18(%rsp), %edx
cmpl %edx, %ebp
cmovel %edi, %eax
cmovel %esi, %r13d
cmpl %ecx, %r14d
movl %eax, %ecx
cmovel %esi, %ecx
cmpl %edx, %r14d
cmovel %esi, %r13d
movq %r13, 0x10(%rsp)
cmovel %eax, %ecx
movl %ecx, 0x4(%rsp)
movb $0x1, %r15b
xorl %r13d, %r13d
jmp 0x2722
leaq 0x60(%rsp), %rdi
callq 0x2060
movq 0x10(%rsp), %rcx
cmpl $0x1, %ecx
sete %al
andb %r15b, %al
cmpb $0x1, %al
pushq $0x1
popq %rbp
movl 0x4(%rsp), %edx
jne 0x28f5
cmpl $0x1, %edx
je 0x2934
movq 0x8(%rsp), %rax
andq $0x0, 0x8(%rax)
movq (%rax), %rax
movb $0x0, (%rax)
testb $0x1, %r15b
je 0x291c
testl %ecx, %ecx
jne 0x295c
testl %edx, %edx
je 0x295c
leaq 0x837(%rip), %rsi       # 0x3151
jmp 0x2923
leaq 0x824(%rip), %rsi       # 0x3147
movq 0x8(%rsp), %rdi
callq 0x21f0
movzbl %r15b, %ebp
andl $0x1, %ebp
leaq 0x60(%rsp), %rdi
callq 0x2090
leaq 0x20(%rsp), %rdi
callq 0x20b0
movl %ebp, %eax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %ecx, %ecx
je 0x296d
testl %edx, %edx
jne 0x296d
leaq 0x7f0(%rip), %rsi       # 0x315b
jmp 0x2923
orl %edx, %ecx
jne 0x292d
leaq 0x7ed(%rip), %rsi       # 0x3165
jmp 0x2923
movq 0x264f(%rip), %rdi      # 0x4fd0
leaq 0x7e7(%rip), %rsi       # 0x316f
callq 0x2110
movq %rax, %rdi
callq 0x20c0
pushq $0x1
popq %rdi
callq 0x2150
jmp 0x29a8
jmp 0x29a8
movq %rax, %rbx
jmp 0x29b5
jmp 0x29a8
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x2090
leaq 0x20(%rsp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x21d0