// File: 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
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x21b0
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x2140
jmp 0x2a07
leaq 0x725(%rip), %rsi       # 0x3133
leaq -0x268(%rbp), %rdi
movl $0x8, %edx
callq 0x20d0
jmp 0x2a21
leaq -0x268(%rbp), %rdi
callq 0x2210
movb %al, -0x2bd(%rbp)
jmp 0x2a35
movb -0x2bd(%rbp), %al
testb $0x1, %al
jne 0x2a44
jmp 0x2d6d
jmp 0x2a46
leaq -0x268(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x2050
movq %rax, -0x2c8(%rbp)
jmp 0x2a5f
movq -0x2c8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2180
movb %al, -0x2c9(%rbp)
jmp 0x2a7d
movb -0x2c9(%rbp), %al
testb $0x1, %al
jne 0x2a8c
jmp 0x2c82
cmpl $0x0, -0x44(%rbp)
je 0x2c45
leaq -0x40(%rbp), %rdi
callq 0x21e0
cmpq $0x1, %rax
jne 0x2afa
leaq -0x40(%rbp), %rdi
callq 0x20a0
movsbl (%rax), %edi
callq 0x2220
cmpl $0x0, %eax
je 0x2afa
jmp 0x2c82
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x270(%rbp)
movl %eax, -0x274(%rbp)
jmp 0x2dc9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x270(%rbp)
movl %eax, -0x274(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x2080
jmp 0x2dc9
leaq 0x644(%rip), %rsi       # 0x3145
leaq -0x40(%rbp), %rdi
callq 0x2250
jmp 0x2b0c
movq -0x10(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x2260
jmp 0x2b1b
movl $0xffffffff, -0x50(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
leaq -0x40(%rbp), %rdi
leaq 0x59c(%rip), %rsi       # 0x30d0
xorl %eax, %eax
movl %eax, %edx
callq 0x2280
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
leaq -0x40(%rbp), %rdi
leaq 0x57c(%rip), %rsi       # 0x30d0
callq 0x2280
movl %eax, -0x54(%rbp)
cmpl $-0x1, -0x50(%rbp)
je 0x2c43
cmpl $-0x1, -0x54(%rbp)
je 0x2c43
movslq -0x50(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x298(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x2120
jmp 0x2b8a
leaq -0x298(%rbp), %rdi
movq %rdi, -0x2d8(%rbp)
callq 0x20a0
movq %rax, %rdi
callq 0x2200
movq -0x2d8(%rbp), %rdi
movl %eax, -0x58(%rbp)
callq 0x20c0
movl -0x50(%rbp), %eax
movl %eax, %ecx
incl %ecx
movslq %ecx, %rdx
movl -0x54(%rbp), %ecx
notl %eax
addl %ecx, %eax
movslq %eax, %rcx
leaq -0x2b8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x2120
jmp 0x2bda
leaq -0x2b8(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
callq 0x2200
movl %eax, -0x5c(%rbp)
leaq -0x2b8(%rbp), %rdi
callq 0x20c0
movl -0x58(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x2c0e
movl $0x1, -0x48(%rbp)
jmp 0x2c1f
movl -0x58(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x2c1d
movl $0x1, -0x4c(%rbp)
jmp 0x2c1f
movl -0x5c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x2c30
movl $0x1, -0x48(%rbp)
jmp 0x2c41
movl -0x5c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x2c3f
movl $0x1, -0x4c(%rbp)
jmp 0x2c41
jmp 0x2c43
jmp 0x2c7d
leaq -0x40(%rbp), %rdi
leaq -0x11(%rbp), %rsi
callq 0x2090
cmpl $0x0, %eax
jne 0x2c7b
movl $0x1, -0x44(%rbp)
movq -0x10(%rbp), %rdi
callq 0x21a0
movq -0x10(%rbp), %rdi
leaq 0x4cc(%rip), %rsi       # 0x313e
callq 0x2250
jmp 0x2c79
jmp 0x2c7b
jmp 0x2c7d
jmp 0x2a46
leaq -0x268(%rbp), %rdi
callq 0x2060
jmp 0x2c90
cmpl $0x1, -0x44(%rbp)
jne 0x2cb8
cmpl $0x1, -0x48(%rbp)
jne 0x2cb8
cmpl $0x1, -0x4c(%rbp)
jne 0x2cb8
movl $0x1, -0x4(%rbp)
movl $0x1, -0x2bc(%rbp)
jmp 0x2da8
movq -0x10(%rbp), %rdi
callq 0x21a0
cmpl $0x0, -0x44(%rbp)
jne 0x2cdb
movq -0x10(%rbp), %rdi
leaq 0x475(%rip), %rsi       # 0x3147
callq 0x2250
jmp 0x2cd9
jmp 0x2d41
cmpl $0x0, -0x48(%rbp)
jne 0x2cfb
cmpl $0x0, -0x4c(%rbp)
je 0x2cfb
movq -0x10(%rbp), %rdi
leaq 0x45f(%rip), %rsi       # 0x3151
callq 0x2250
jmp 0x2cf9
jmp 0x2d3f
cmpl $0x0, -0x48(%rbp)
je 0x2d1b
cmpl $0x0, -0x4c(%rbp)
jne 0x2d1b
movq -0x10(%rbp), %rdi
leaq 0x449(%rip), %rsi       # 0x315b
callq 0x2250
jmp 0x2d19
jmp 0x2d3d
cmpl $0x0, -0x48(%rbp)
jne 0x2d3b
cmpl $0x0, -0x4c(%rbp)
jne 0x2d3b
movq -0x10(%rbp), %rdi
leaq 0x433(%rip), %rsi       # 0x3165
callq 0x2250
jmp 0x2d39
jmp 0x2d3b
jmp 0x2d3d
jmp 0x2d3f
jmp 0x2d41
cmpl $0x0, -0x44(%rbp)
je 0x2d5a
movl $0x1, -0x4(%rbp)
movl $0x1, -0x2bc(%rbp)
jmp 0x2da8
movl $0x0, -0x4(%rbp)
movl $0x1, -0x2bc(%rbp)
jmp 0x2da8
movq 0x225c(%rip), %rdi      # 0x4fd0
leaq 0x3f4(%rip), %rsi       # 0x316f
callq 0x2110
movq %rax, -0x2e0(%rbp)
jmp 0x2d89
movq -0x2e0(%rbp), %rdi
movq 0x2229(%rip), %rsi      # 0x4fc0
callq 0x2130
jmp 0x2d9e
movl $0x1, %edi
callq 0x2160
leaq -0x268(%rbp), %rdi
callq 0x2080
leaq -0x40(%rbp), %rdi
callq 0x20c0
movl -0x4(%rbp), %eax
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x20c0
movq -0x270(%rbp), %rdi
callq 0x2230