// File: /workspace/github_cpp_makefile_star2_O1/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 $0x278, %rsp            # imm = 0x278
movl %ecx, 0x4c(%rsp)
movl %edx, 0x48(%rsp)
movq %rdi, 0x10(%rsp)
movb %sil, 0xb(%rsp)
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x70(%rsp), %rdi
callq 0x2150
leaq 0x8e0(%rip), %rsi       # 0x3133
leaq 0x70(%rsp), %rdi
movl $0x8, %edx
callq 0x20d0
leaq 0xe8(%rsp), %rdi
callq 0x2070
testb %al, %al
je 0x2b5c
movb $0x1, %r12b
movq $0x0, 0x38(%rsp)
movl $0x0, 0xc(%rsp)
xorl %r15d, %r15d
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0x70(%rsp), %rax
addq %rax, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %edx
leaq 0x70(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x2220
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2a98
testb $0x1, %r12b
je 0x2916
leaq 0x18(%rsp), %rdi
leaq 0xb(%rsp), %rsi
callq 0x20a0
movb $0x1, %r12b
xorl %r15d, %r15d
testl %eax, %eax
jne 0x288e
movq 0x10(%rsp), %rdi
movq $0x0, 0x8(%rdi)
movq (%rdi), %rax
movb $0x0, (%rax)
movb $0x1, %r15b
xorl %r12d, %r12d
leaq 0x832(%rip), %rsi       # 0x313e
callq 0x2230
jmp 0x288e
cmpq $0x1, 0x20(%rsp)
jne 0x2933
movq 0x18(%rsp), %rax
movsbl (%rax), %edi
callq 0x21e0
testl %eax, %eax
jne 0x2a98
leaq 0x18(%rsp), %rdi
leaq 0x806(%rip), %rsi       # 0x3145
callq 0x2230
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rdi
callq 0x20b0
xorl %r12d, %r12d
movl $0x1, %ecx
leaq 0x18(%rsp), %r15
movq %r15, %rdi
leaq 0x761(%rip), %rbp       # 0x30d0
movq %rbp, %rsi
xorl %edx, %edx
callq 0x21f0
movq %rax, %rbx
movq %rax, %r13
shlq $0x20, %r13
movabsq $0x100000000, %rax      # imm = 0x100000000
leaq (%rax,%r13), %r14
sarq $0x20, %r14
movl $0x1, %ecx
movq %r15, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x21f0
movb $0x1, %r15b
cmpl $-0x1, %ebx
je 0x288e
movq %rax, %rbp
movl %ebp, %eax
cmpl $-0x1, %eax
je 0x288e
sarq $0x20, %r13
leaq 0x50(%rsp), %rdi
leaq 0x18(%rsp), %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0x2140
movq 0x50(%rsp), %r13
movq %r13, %rdi
callq 0x21d0
movl %eax, 0x44(%rsp)
leaq 0x60(%rsp), %rax
cmpq %rax, %r13
movq 0x38(%rsp), %r15
movl 0xc(%rsp), %r12d
je 0x2a0f
movq 0x60(%rsp), %rsi
incq %rsi
movq %r13, %rdi
callq 0x2130
notl %ebx
addl %ebx, %ebp
movslq %ebp, %rcx
leaq 0x50(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq %r14, %rdx
callq 0x2140
movq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x21d0
movl %eax, %ebx
leaq 0x60(%rsp), %rax
cmpq %rax, %r14
je 0x2a51
movq 0x60(%rsp), %rsi
incq %rsi
movq %r14, %rdi
callq 0x2130
movl 0x4c(%rsp), %ecx
movl 0x44(%rsp), %edi
cmpl %ecx, %edi
movl %r12d, %eax
movl $0x1, %esi
cmovel %esi, %eax
movl 0x48(%rsp), %edx
cmpl %edx, %edi
cmovel %r12d, %eax
cmovel %esi, %r15d
cmpl %ecx, %ebx
movl %eax, %ecx
cmovel %esi, %ecx
cmpl %edx, %ebx
cmovel %esi, %r15d
movq %r15, 0x38(%rsp)
cmovel %eax, %ecx
movl %ecx, 0xc(%rsp)
movb $0x1, %r15b
xorl %r12d, %r12d
jmp 0x288e
leaq 0x70(%rsp), %rdi
callq 0x2060
movq 0x38(%rsp), %rcx
cmpl $0x1, %ecx
sete %al
andb %r15b, %al
cmpb $0x1, %al
movl 0xc(%rsp), %edx
jne 0x2ac2
movl $0x1, %ebx
cmpl $0x1, %edx
je 0x2b04
movq 0x10(%rsp), %rax
movq $0x0, 0x8(%rax)
movq (%rax), %rax
movb $0x0, (%rax)
testb $0x1, %r15b
je 0x2aec
testl %ecx, %ecx
jne 0x2b3e
testl %edx, %edx
je 0x2b3e
leaq 0x667(%rip), %rsi       # 0x3151
jmp 0x2af3
leaq 0x654(%rip), %rsi       # 0x3147
movq 0x10(%rsp), %rdi
callq 0x2230
movzbl %r15b, %ebx
andl $0x1, %ebx
leaq 0x70(%rsp), %rdi
callq 0x2090
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2b2a
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2130
movl %ebx, %eax
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %ecx, %ecx
je 0x2b4f
testl %edx, %edx
jne 0x2b4f
leaq 0x60e(%rip), %rsi       # 0x315b
jmp 0x2af3
orl %edx, %ecx
jne 0x2afd
leaq 0x60b(%rip), %rsi       # 0x3165
jmp 0x2af3
movq 0x246d(%rip), %rdi      # 0x4fd0
leaq 0x605(%rip), %rsi       # 0x316f
movl $0x13, %edx
callq 0x2160
movq 0x2455(%rip), %rdi      # 0x4fd0
callq 0x20c0
movl $0x1, %edi
callq 0x2170
jmp 0x2b95
jmp 0x2b95
movq %rax, %rbx
jmp 0x2ba2
jmp 0x2b95
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x2090
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2bbe
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2130
movq %rbx, %rdi
callq 0x2200