// File: LiGaCu[P]Distributed_System_to_Compute_the_Shortest_Path/aws.cpp
// Function: main
int main(void)
{
    int TCPfath_fd,TCPchld_fd, UDP_fd;
    struct addrinfo hints, *servinfo, *servinfoA, *servinfoB, *servinfoC;
    struct sigaction sa;

    int rv;

    char buf[MAXDATASIZE];int numbytes;
    std::string mapbuff, mapinfo;
    char mapid; int srcVtxid,dstVtxid,filesize;
    float Tt,Tp;
    int path[11]; float mindistan;

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    if ((rv = getaddrinfo("127.0.0.1", TCPPORT, &hints, &servinfo)) != 0) 
    {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        return 1;
    }
    TCPfath_fd = getTCPsockandbind(servinfo);
    freeaddrinfo(servinfo);

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC; // set to AF_INET to force IPv4
    hints.ai_socktype = SOCK_DGRAM;
    if ((rv = getaddrinfo("127.0.0.1", UDPPORT, &hints, &servinfo)) != 0) 
    {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        return 1;
    }
    UDP_fd = getUDPsockandbind(servinfo);
    freeaddrinfo(servinfo);

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC; // set to AF_INET to force IPv4
    hints.ai_socktype = SOCK_DGRAM;
    if ((rv = getaddrinfo("127.0.0.1", AUDPPORT, &hints, &servinfoA)) != 0) 
    {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        return 1;
    }

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC; // set to AF_INET to force IPv4
    hints.ai_socktype = SOCK_DGRAM;
    if ((rv = getaddrinfo("127.0.0.1", BUDPPORT, &hints, &servinfoB)) != 0) 
    {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        return 1;
    }

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC; // set to AF_INET to force IPv4
    hints.ai_socktype = SOCK_DGRAM;
    if ((rv = getaddrinfo("127.0.0.1", CUDPPORT, &hints, &servinfoC)) != 0) 
    {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        return 1;
    }

    if (listen(TCPfath_fd, BACKLOG) == -1) 
    {
        perror("listen");
        exit(1);
    }

    // The following lines of sigaction() thing is from Beej's Tutorial
    sa.sa_handler = sigchld_handler; // reap all dead processes
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_RESTART;
    if (sigaction(SIGCHLD, &sa, NULL) == -1) 
    {
        perror("sigaction");
        exit(1);
    }

    std::cout << "The AWS is up and ranning" << "\n" << std::endl;
    
    while(1)
    {
        TCPchld_fd = accept(TCPfath_fd,(struct sockaddr *)NULL,NULL);
        if (TCPchld_fd == -1) 
        {
            perror("accept");
            continue;
        }

        if (!fork()) 
        { // this is the child process
            close(TCPfath_fd);
            if ((numbytes = recv(TCPchld_fd, buf, MAXDATASIZE-1, 0)) == -1) 
            {
                perror("recvTCP");
                exit(1);
            }

            //decode the massage received from the client
            mapid = buf[0];
            memcpy(&srcVtxid,buf+1,sizeof(int));
            memcpy(&dstVtxid,buf+1+sizeof(int),sizeof(int));
            memcpy(&filesize,buf+1+2*sizeof(int),sizeof(int));

            std::cout << "The AWS has recieved map ID " << mapid << ", start vertex " << srcVtxid << ", destination vertex " << dstVtxid
             << " and file size " << filesize << " from the client using TCP over port " << TCPPORT << "\n" << std::endl;

            if ((numbytes = sendto(UDP_fd, buf, numbytes, 0, servinfoA->ai_addr, servinfoA->ai_addrlen)) == -1) 
            {
                perror("talker: sendtoA");
                exit(1);
            }
            std::cout << "The AWS has sent map ID to server A using UDP over port " << UDPPORT << "\n" << std::endl;

            if ((numbytes = sendto(UDP_fd, buf, numbytes, 0, servinfoB->ai_addr, servinfoB->ai_addrlen)) == -1) 
            {
                perror("talker: sendtoB");
                exit(1);
            }
            std::cout << "The AWS has sent map ID to server B using UDP over port " << UDPPORT << "\n" << std::endl;

            if ((numbytes = recvfrom(UDP_fd, buf, MAXDATASIZE-1 , 0, (struct sockaddr *) NULL, NULL)) == -1) 
            {
                perror("recvfromA/B");
                exit(1);
            }
            mapbuff.assign(buf, numbytes);
            
            int receivedA = 0, receivedB = 0;
            char msgA = '\0', msgB = '\0';

            interpUDPmsg(mapbuff, mapinfo, &receivedA, &receivedB, &msgA, &msgB);
            if(!receivedA || !receivedB)
            {
                if ((numbytes = recvfrom(UDP_fd, buf, MAXDATASIZE-1 , 0, (struct sockaddr *) NULL, NULL)) == -1) 
                {
                    perror("recvfromA/B");
                    exit(1);
                }
                mapbuff.assign(buf, numbytes);
                interpUDPmsg(mapbuff, mapinfo, &receivedA, &receivedB, &msgA, &msgB);
            }

            char matchstate = mapsearchresult(msgA, msgB, mapid, srcVtxid, dstVtxid);

            if (matchstate == 'y') // all map id, source vertex index and destination vertex index are found
            {
                memcpy(buf, &srcVtxid, sizeof(int));
                memcpy(buf+sizeof(int), &dstVtxid, sizeof(int));
                memcpy(buf+2*sizeof(int), &filesize, sizeof(int));
                memcpy(buf+3*sizeof(int), &mapid, sizeof(char));
                mapinfo.insert(0, buf, 3*sizeof(int)+sizeof(char));

                //send required information to serverC
                if ((numbytes = sendto(UDP_fd, mapinfo.data(), mapinfo.length(), 0, servinfoC->ai_addr, servinfoC->ai_addrlen)) == -1) 
                {
                    perror("talker: sendtoC");
                    exit(1);
                }
                std::cout << "The AWS has sent map, source ID, destination ID, propagation speed and transmission speed to" <<
                 "server C using UDP over port " << UDPPORT << "\n" << std::endl;
                //receive calculated results from serverC
                if ((numbytes = recvfrom(UDP_fd, buf, MAXDATASIZE-1 , 0, (struct sockaddr *) NULL, NULL)) == -1) 
                {
                    perror("recvfromC");
                    exit(1);
                }
                memcpy(&mindistan, buf                  , sizeof(float));
                memcpy(&Tt       , buf + sizeof(float)  , sizeof(float));
                memcpy(&Tp       , buf + sizeof(float)*2, sizeof(float));
                memcpy(path      , buf + sizeof(float)*3, sizeof(path));
                //show the result
                std::cout << "The AWS has received results from serverC:\n" <<  "Shortest path: ";
                for (int i =0 ; i< 11; i++)
                {
                    if(path[i] == 2333)
                        break;
                    
                    if (i==0)
                        std::cout << path[i];
                    else
                        std::cout << " -- " << path[i];

                }
                std::cout << "\nShortest Distance: " << mindistan << " km\nTransmission Delay: " << Tt << " s\nPropagation Delay: " << Tp << " s\n" << std::endl;
                //send calculated results to client
                std::string tempstr("y");
                tempstr.append(buf,numbytes);
                if (send(TCPchld_fd, tempstr.data(), tempstr.length(), 0) == -1)
                    perror("sendTCP");
                std::cout << "The AWS has sent calculated results to client using TCP over port " << TCPPORT << "\n" << std::endl;
            }
            else if(matchstate == 'e') // abnormal map1 and map2 state
            {
                perror("storedmapswrong");
            }
            else // map id, source vertex index or destination vertex index is not found
            {
                std::string tempstr("!");
                tempstr.append(1,matchstate);
                if (send(TCPchld_fd, tempstr.data(), 2, 0) == -1)
                    perror("sendTCP");
            }

            close(TCPchld_fd);
            exit(0);
        }

        //close(TCPchld_fd);
    }

    close(TCPfath_fd);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x800, %rsp            # imm = 0x800
movl $0x0, -0x4(%rbp)
leaq -0x518(%rbp), %rdi
callq 0x22d0
leaq -0x538(%rbp), %rdi
callq 0x22d0
xorps %xmm0, %xmm0
movaps %xmm0, -0x20(%rbp)
movaps %xmm0, -0x30(%rbp)
movaps %xmm0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x1, -0x38(%rbp)
leaq 0x2a96(%rip), %rdi      # 0x5004
leaq 0x2a99(%rip), %rsi      # 0x500e
leaq -0x40(%rbp), %rdx
leaq -0x48(%rbp), %rcx
callq 0x22a0
movl %eax, -0x5f8(%rbp)
jmp 0x258a
movl -0x5f8(%rbp), %eax
movl %eax, -0xfc(%rbp)
cmpl $0x0, %eax
je 0x25fc
movq 0x4a36(%rip), %rax      # 0x6fd8
movq (%rax), %rax
movq %rax, -0x600(%rbp)
movl -0xfc(%rbp), %edi
callq 0x22e0
movq -0x600(%rbp), %rdi
movq %rax, %rdx
leaq 0x2a4c(%rip), %rsi      # 0x5014
movb $0x0, %al
callq 0x22f0
movl $0x1, -0x4(%rbp)
movl $0x1, -0x598(%rbp)
jmp 0x351b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x590(%rbp)
movl %eax, -0x594(%rbp)
jmp 0x353f
movq -0x48(%rbp), %rdi
callq 0x3570
movl %eax, -0x604(%rbp)
jmp 0x260d
movl -0x604(%rbp), %eax
movl %eax, -0x8(%rbp)
movq -0x48(%rbp), %rdi
callq 0x22b0
xorps %xmm0, %xmm0
movaps %xmm0, -0x20(%rbp)
movaps %xmm0, -0x30(%rbp)
movaps %xmm0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x2, -0x38(%rbp)
leaq 0x29c1(%rip), %rdi      # 0x5004
leaq 0x29db(%rip), %rsi      # 0x5025
leaq -0x40(%rbp), %rdx
leaq -0x48(%rbp), %rcx
callq 0x22a0
movl %eax, -0x608(%rbp)
jmp 0x265f
movl -0x608(%rbp), %eax
movl %eax, -0xfc(%rbp)
cmpl $0x0, %eax
je 0x26ba
movq 0x4961(%rip), %rax      # 0x6fd8
movq (%rax), %rax
movq %rax, -0x610(%rbp)
movl -0xfc(%rbp), %edi
callq 0x22e0
movq -0x610(%rbp), %rdi
movq %rax, %rdx
leaq 0x2977(%rip), %rsi      # 0x5014
movb $0x0, %al
callq 0x22f0
movl $0x1, -0x4(%rbp)
movl $0x1, -0x598(%rbp)
jmp 0x351b
movq -0x48(%rbp), %rdi
callq 0x3680
movl %eax, -0x614(%rbp)
jmp 0x26cb
movl -0x614(%rbp), %eax
movl %eax, -0x10(%rbp)
movq -0x48(%rbp), %rdi
callq 0x22b0
xorps %xmm0, %xmm0
movaps %xmm0, -0x20(%rbp)
movaps %xmm0, -0x30(%rbp)
movaps %xmm0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x2, -0x38(%rbp)
leaq 0x2903(%rip), %rdi      # 0x5004
leaq 0x2923(%rip), %rsi      # 0x502b
leaq -0x40(%rbp), %rdx
leaq -0x50(%rbp), %rcx
callq 0x22a0
movl %eax, -0x618(%rbp)
jmp 0x271d
movl -0x618(%rbp), %eax
movl %eax, -0xfc(%rbp)
cmpl $0x0, %eax
je 0x2778
movq 0x48a3(%rip), %rax      # 0x6fd8
movq (%rax), %rax
movq %rax, -0x620(%rbp)
movl -0xfc(%rbp), %edi
callq 0x22e0
movq -0x620(%rbp), %rdi
movq %rax, %rdx
leaq 0x28b9(%rip), %rsi      # 0x5014
movb $0x0, %al
callq 0x22f0
movl $0x1, -0x4(%rbp)
movl $0x1, -0x598(%rbp)
jmp 0x351b
xorps %xmm0, %xmm0
movaps %xmm0, -0x20(%rbp)
movaps %xmm0, -0x30(%rbp)
movaps %xmm0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x2, -0x38(%rbp)
leaq 0x2868(%rip), %rdi      # 0x5004
leaq 0x288e(%rip), %rsi      # 0x5031
leaq -0x40(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x22a0
movl %eax, -0x624(%rbp)
jmp 0x27b8
movl -0x624(%rbp), %eax
movl %eax, -0xfc(%rbp)
cmpl $0x0, %eax
je 0x2813
movq 0x4808(%rip), %rax      # 0x6fd8
movq (%rax), %rax
movq %rax, -0x630(%rbp)
movl -0xfc(%rbp), %edi
callq 0x22e0
movq -0x630(%rbp), %rdi
movq %rax, %rdx
leaq 0x281e(%rip), %rsi      # 0x5014
movb $0x0, %al
callq 0x22f0
movl $0x1, -0x4(%rbp)
movl $0x1, -0x598(%rbp)
jmp 0x351b
xorps %xmm0, %xmm0
movaps %xmm0, -0x20(%rbp)
movaps %xmm0, -0x30(%rbp)
movaps %xmm0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x2, -0x38(%rbp)
leaq 0x27cd(%rip), %rdi      # 0x5004
leaq 0x27f9(%rip), %rsi      # 0x5037
leaq -0x40(%rbp), %rdx
leaq -0x60(%rbp), %rcx
callq 0x22a0
movl %eax, -0x634(%rbp)
jmp 0x2853
movl -0x634(%rbp), %eax
movl %eax, -0xfc(%rbp)
cmpl $0x0, %eax
je 0x28ae
movq 0x476d(%rip), %rax      # 0x6fd8
movq (%rax), %rax
movq %rax, -0x640(%rbp)
movl -0xfc(%rbp), %edi
callq 0x22e0
movq -0x640(%rbp), %rdi
movq %rax, %rdx
leaq 0x2783(%rip), %rsi      # 0x5014
movb $0x0, %al
callq 0x22f0
movl $0x1, -0x4(%rbp)
movl $0x1, -0x598(%rbp)
jmp 0x351b
movl -0x8(%rbp), %edi
movl $0xa, %esi
callq 0x2230
cmpl $-0x1, %eax
jne 0x28d8
leaq 0x2776(%rip), %rdi      # 0x503d
callq 0x2180
jmp 0x28ce
movl $0x1, %edi
callq 0x2250
leaq 0xeb1(%rip), %rax       # 0x3790
movq %rax, -0xf8(%rbp)
leaq -0xf8(%rbp), %rdi
addq $0x8, %rdi
callq 0x2280
movl $0x10000000, -0x70(%rbp) # imm = 0x10000000
movl $0x11, %edi
leaq -0xf8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2290
cmpl $-0x1, %eax
jne 0x292f
leaq 0x2726(%rip), %rdi      # 0x5044
callq 0x2180
jmp 0x2925
movl $0x1, %edi
callq 0x2250
movq 0x469a(%rip), %rdi      # 0x6fd0
leaq 0x2711(%rip), %rsi      # 0x504e
callq 0x21b0
movq %rax, -0x648(%rbp)
jmp 0x294b
movq -0x648(%rbp), %rdi
leaq 0x28f4(%rip), %rsi      # 0x524d
callq 0x21b0
movq %rax, -0x650(%rbp)
jmp 0x2967
movq -0x650(%rbp), %rdi
movq 0x464b(%rip), %rsi      # 0x6fc0
callq 0x21d0
jmp 0x297c
jmp 0x297e
jmp 0x2980
movl -0x8(%rbp), %edi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x20b0
movl %eax, -0x654(%rbp)
jmp 0x2997
movl -0x654(%rbp), %eax
movl %eax, -0xc(%rbp)
cmpl $-0x1, -0xc(%rbp)
jne 0x29b6
leaq 0x26bb(%rip), %rdi      # 0x5068
callq 0x2180
jmp 0x29b4
jmp 0x297e
callq 0x2090
cmpl $0x0, %eax
jne 0x3516
movl -0x8(%rbp), %edi
callq 0x23a0
jmp 0x29ce
movl -0xc(%rbp), %edi
leaq -0x4f0(%rbp), %rsi
movl $0x3e7, %edx            # imm = 0x3E7
xorl %ecx, %ecx
callq 0x20c0
movq %rax, -0x660(%rbp)
jmp 0x29ed
movq -0x660(%rbp), %rax
movl %eax, -0x4f4(%rbp)
cmpl $-0x1, %eax
jne 0x2a17
leaq 0x2669(%rip), %rdi      # 0x506f
callq 0x2180
jmp 0x2a0d
movl $0x1, %edi
callq 0x2250
movb -0x4f0(%rbp), %al
movb %al, -0x539(%rbp)
movl -0x4ef(%rbp), %eax
movl %eax, -0x540(%rbp)
movl -0x4eb(%rbp), %eax
movl %eax, -0x544(%rbp)
movl -0x4e7(%rbp), %eax
movl %eax, -0x548(%rbp)
movq 0x4582(%rip), %rdi      # 0x6fd0
leaq 0x2622(%rip), %rsi      # 0x5077
callq 0x21b0
movq %rax, -0x668(%rbp)
jmp 0x2a63
movq -0x668(%rbp), %rdi
movsbl -0x539(%rbp), %esi
callq 0x2240
movq %rax, -0x670(%rbp)
jmp 0x2a7f
movq -0x670(%rbp), %rdi
leaq 0x2607(%rip), %rsi      # 0x5094
callq 0x21b0
movq %rax, -0x678(%rbp)
jmp 0x2a9b
movq -0x678(%rbp), %rdi
movl -0x540(%rbp), %esi
callq 0x2340
movq %rax, -0x680(%rbp)
jmp 0x2ab6
movq -0x680(%rbp), %rdi
leaq 0x25e0(%rip), %rsi      # 0x50a4
callq 0x21b0
movq %rax, -0x688(%rbp)
jmp 0x2ad2
movq -0x688(%rbp), %rdi
movl -0x544(%rbp), %esi
callq 0x2340
movq %rax, -0x690(%rbp)
jmp 0x2aed
movq -0x690(%rbp), %rdi
leaq 0x25bf(%rip), %rsi      # 0x50ba
callq 0x21b0
movq %rax, -0x698(%rbp)
jmp 0x2b09
movq -0x698(%rbp), %rdi
movl -0x548(%rbp), %esi
callq 0x2340
movq %rax, -0x6a0(%rbp)
jmp 0x2b24
movq -0x6a0(%rbp), %rdi
leaq 0x2598(%rip), %rsi      # 0x50ca
callq 0x21b0
movq %rax, -0x6a8(%rbp)
jmp 0x2b40
movq -0x6a8(%rbp), %rdi
leaq 0x24c0(%rip), %rsi      # 0x500e
callq 0x21b0
movq %rax, -0x6b0(%rbp)
jmp 0x2b5c
movq -0x6b0(%rbp), %rdi
leaq 0x26e3(%rip), %rsi      # 0x524d
callq 0x21b0
movq %rax, -0x6b8(%rbp)
jmp 0x2b78
movq -0x6b8(%rbp), %rdi
movq 0x443a(%rip), %rsi      # 0x6fc0
callq 0x21d0
jmp 0x2b8d
movl -0x10(%rbp), %edi
movslq -0x4f4(%rbp), %rdx
movq -0x50(%rbp), %rax
movq 0x18(%rax), %r8
movl 0x10(%rax), %r9d
leaq -0x4f0(%rbp), %rsi
xorl %ecx, %ecx
callq 0x2040
movq %rax, -0x6c0(%rbp)
jmp 0x2bba
movq -0x6c0(%rbp), %rax
movl %eax, -0x4f4(%rbp)
cmpl $-0x1, %eax
jne 0x2be4
leaq 0x251d(%rip), %rdi      # 0x50f0
callq 0x2180
jmp 0x2bda
movl $0x1, %edi
callq 0x2250
movq 0x43e5(%rip), %rdi      # 0x6fd0
leaq 0x250e(%rip), %rsi      # 0x5100
callq 0x21b0
movq %rax, -0x6c8(%rbp)
jmp 0x2c00
movq -0x6c8(%rbp), %rdi
leaq 0x2417(%rip), %rsi      # 0x5025
callq 0x21b0
movq %rax, -0x6d0(%rbp)
jmp 0x2c1c
movq -0x6d0(%rbp), %rdi
leaq 0x2623(%rip), %rsi      # 0x524d
callq 0x21b0
movq %rax, -0x6d8(%rbp)
jmp 0x2c38
movq -0x6d8(%rbp), %rdi
movq 0x437a(%rip), %rsi      # 0x6fc0
callq 0x21d0
jmp 0x2c4d
movl -0x10(%rbp), %edi
movslq -0x4f4(%rbp), %rdx
movq -0x58(%rbp), %rax
movq 0x18(%rax), %r8
movl 0x10(%rax), %r9d
leaq -0x4f0(%rbp), %rsi
xorl %ecx, %ecx
callq 0x2040
movq %rax, -0x6e0(%rbp)
jmp 0x2c7a
movq -0x6e0(%rbp), %rax
movl %eax, -0x4f4(%rbp)
cmpl $-0x1, %eax
jne 0x2ca4
leaq 0x24a6(%rip), %rdi      # 0x5139
callq 0x2180
jmp 0x2c9a
movl $0x1, %edi
callq 0x2250
movq 0x4325(%rip), %rdi      # 0x6fd0
leaq 0x2497(%rip), %rsi      # 0x5149
callq 0x21b0
movq %rax, -0x6e8(%rbp)
jmp 0x2cc0
movq -0x6e8(%rbp), %rdi
leaq 0x2357(%rip), %rsi      # 0x5025
callq 0x21b0
movq %rax, -0x6f0(%rbp)
jmp 0x2cdc
movq -0x6f0(%rbp), %rdi
leaq 0x2563(%rip), %rsi      # 0x524d
callq 0x21b0
movq %rax, -0x6f8(%rbp)
jmp 0x2cf8
movq -0x6f8(%rbp), %rdi
movq 0x42ba(%rip), %rsi      # 0x6fc0
callq 0x21d0
jmp 0x2d0d
movl -0x10(%rbp), %edi
xorl %ecx, %ecx
movl %ecx, %r9d
leaq -0x4f0(%rbp), %rsi
movl $0x3e7, %edx            # imm = 0x3E7
movq %r9, %r8
callq 0x2150
movq %rax, -0x700(%rbp)
jmp 0x2d32
movq -0x700(%rbp), %rax
movl %eax, -0x4f4(%rbp)
cmpl $-0x1, %eax
jne 0x2d5c
leaq 0x2437(%rip), %rdi      # 0x5182
callq 0x2180
jmp 0x2d52
movl $0x1, %edi
callq 0x2250
movslq -0x4f4(%rbp), %rdx
leaq -0x518(%rbp), %rdi
leaq -0x4f0(%rbp), %rsi
callq 0x22c0
jmp 0x2d78
movl $0x0, -0x59c(%rbp)
movl $0x0, -0x5a0(%rbp)
movb $0x0, -0x5a1(%rbp)
movb $0x0, -0x5a2(%rbp)
leaq -0x518(%rbp), %rdi
leaq -0x538(%rbp), %rsi
leaq -0x59c(%rbp), %rdx
leaq -0x5a0(%rbp), %rcx
leaq -0x5a1(%rbp), %r8
leaq -0x5a2(%rbp), %r9
callq 0x37e0
jmp 0x2dcb
cmpl $0x0, -0x59c(%rbp)
je 0x2de1
cmpl $0x0, -0x5a0(%rbp)
jne 0x2e7f
movl -0x10(%rbp), %edi
xorl %ecx, %ecx
movl %ecx, %r9d
leaq -0x4f0(%rbp), %rsi
movl $0x3e7, %edx            # imm = 0x3E7
movq %r9, %r8
callq 0x2150
movq %rax, -0x708(%rbp)
jmp 0x2e06
movq -0x708(%rbp), %rax
movl %eax, -0x4f4(%rbp)
cmpl $-0x1, %eax
jne 0x2e30
leaq 0x2363(%rip), %rdi      # 0x5182
callq 0x2180
jmp 0x2e26
movl $0x1, %edi
callq 0x2250
movslq -0x4f4(%rbp), %rdx
leaq -0x518(%rbp), %rdi
leaq -0x4f0(%rbp), %rsi
callq 0x22c0
jmp 0x2e4c
leaq -0x518(%rbp), %rdi
leaq -0x538(%rbp), %rsi
leaq -0x59c(%rbp), %rdx
leaq -0x5a0(%rbp), %rcx
leaq -0x5a1(%rbp), %r8
leaq -0x5a2(%rbp), %r9
callq 0x37e0
jmp 0x2e7d
jmp 0x2e7f
movsbl -0x5a1(%rbp), %edi
movsbl -0x5a2(%rbp), %esi
movsbl -0x539(%rbp), %edx
movl -0x540(%rbp), %ecx
movl -0x544(%rbp), %r8d
callq 0x3bc0
movb %al, -0x709(%rbp)
jmp 0x2eae
movb -0x709(%rbp), %al
movb %al, -0x5a3(%rbp)
movsbl -0x5a3(%rbp), %eax
cmpl $0x79, %eax
jne 0x33f3
movl -0x540(%rbp), %eax
movl %eax, -0x4f0(%rbp)
movl -0x544(%rbp), %eax
movl %eax, -0x4ec(%rbp)
movl -0x548(%rbp), %eax
movl %eax, -0x4e8(%rbp)
movb -0x539(%rbp), %al
movb %al, -0x4e4(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x538(%rbp), %rdi
leaq -0x4f0(%rbp), %rdx
movl $0xd, %ecx
callq 0x2380
jmp 0x2f18
movl -0x10(%rbp), %eax
movl %eax, -0x724(%rbp)
leaq -0x538(%rbp), %rdi
movq %rdi, -0x730(%rbp)
callq 0x2100
movq -0x730(%rbp), %rdi
movq %rax, -0x720(%rbp)
callq 0x2310
movl -0x724(%rbp), %edi
movq -0x720(%rbp), %rsi
movq %rax, %rdx
movq -0x60(%rbp), %rax
movq 0x18(%rax), %r8
movl 0x10(%rax), %r9d
xorl %ecx, %ecx
callq 0x2040
movq %rax, -0x718(%rbp)
jmp 0x2f73
movq -0x718(%rbp), %rax
movl %eax, -0x4f4(%rbp)
cmpl $-0x1, %eax
jne 0x2f9d
leaq 0x2202(%rip), %rdi      # 0x518e
callq 0x2180
jmp 0x2f93
movl $0x1, %edi
callq 0x2250
movq 0x402c(%rip), %rdi      # 0x6fd0
leaq 0x21f3(%rip), %rsi      # 0x519e
callq 0x21b0
movq %rax, -0x738(%rbp)
jmp 0x2fb9
movq -0x738(%rbp), %rdi
leaq 0x2234(%rip), %rsi      # 0x51fb
callq 0x21b0
movq %rax, -0x740(%rbp)
jmp 0x2fd5
movq -0x740(%rbp), %rdi
leaq 0x2042(%rip), %rsi      # 0x5025
callq 0x21b0
movq %rax, -0x748(%rbp)
jmp 0x2ff1
movq -0x748(%rbp), %rdi
leaq 0x224e(%rip), %rsi      # 0x524d
callq 0x21b0
movq %rax, -0x750(%rbp)
jmp 0x300d
movq -0x750(%rbp), %rdi
movq 0x3fa5(%rip), %rsi      # 0x6fc0
callq 0x21d0
jmp 0x3022
movl -0x10(%rbp), %edi
xorl %ecx, %ecx
movl %ecx, %r9d
leaq -0x4f0(%rbp), %rsi
movl $0x3e7, %edx            # imm = 0x3E7
movq %r9, %r8
callq 0x2150
movq %rax, -0x758(%rbp)
jmp 0x3047
movq -0x758(%rbp), %rax
movl %eax, -0x4f4(%rbp)
cmpl $-0x1, %eax
jne 0x3071
leaq 0x21b9(%rip), %rdi      # 0x5219
callq 0x2180
jmp 0x3067
movl $0x1, %edi
callq 0x2250
movl -0x4f0(%rbp), %eax
movl %eax, -0x584(%rbp)
movl -0x4ec(%rbp), %eax
movl %eax, -0x54c(%rbp)
movl -0x4e8(%rbp), %eax
movl %eax, -0x550(%rbp)
movups -0x4e4(%rbp), %xmm0
movups -0x4d4(%rbp), %xmm1
movups -0x4c8(%rbp), %xmm2
movups %xmm2, -0x564(%rbp)
movaps %xmm1, -0x570(%rbp)
movaps %xmm0, -0x580(%rbp)
movq 0x3f0a(%rip), %rdi      # 0x6fd0
leaq 0x2156(%rip), %rsi      # 0x5223
callq 0x21b0
movq %rax, -0x760(%rbp)
jmp 0x30db
movq -0x760(%rbp), %rdi
leaq 0x2166(%rip), %rsi      # 0x524f
callq 0x21b0
jmp 0x30f0
movl $0x0, -0x5a8(%rbp)
cmpl $0xb, -0x5a8(%rbp)
jge 0x3194
movslq -0x5a8(%rbp), %rax
cmpl $0x91d, -0x580(%rbp,%rax,4) # imm = 0x91D
jne 0x311d
jmp 0x3194
cmpl $0x0, -0x5a8(%rbp)
jne 0x3144
movslq -0x5a8(%rbp), %rax
movl -0x580(%rbp,%rax,4), %esi
movq 0x3e95(%rip), %rdi      # 0x6fd0
callq 0x2340
jmp 0x3142
jmp 0x317e
movq 0x3e85(%rip), %rdi      # 0x6fd0
leaq 0x210d(%rip), %rsi      # 0x525f
callq 0x21b0
movq %rax, -0x768(%rbp)
jmp 0x3160
movq -0x768(%rbp), %rdi
movslq -0x5a8(%rbp), %rax
movl -0x580(%rbp,%rax,4), %esi
callq 0x2340
jmp 0x317c
jmp 0x317e
jmp 0x3180
movl -0x5a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5a8(%rbp)
jmp 0x30fa
movq 0x3e35(%rip), %rdi      # 0x6fd0
leaq 0x20c2(%rip), %rsi      # 0x5264
callq 0x21b0
movq %rax, -0x770(%rbp)
jmp 0x31b0
movq -0x770(%rbp), %rdi
movss -0x584(%rbp), %xmm0
callq 0x2140
movq %rax, -0x778(%rbp)
jmp 0x31cd
movq -0x778(%rbp), %rdi
leaq 0x209e(%rip), %rsi      # 0x5279
callq 0x21b0
movq %rax, -0x780(%rbp)
jmp 0x31e9
movq -0x780(%rbp), %rdi
movss -0x54c(%rbp), %xmm0
callq 0x2140
movq %rax, -0x788(%rbp)
jmp 0x3206
movq -0x788(%rbp), %rdi
leaq 0x207e(%rip), %rsi      # 0x5292
callq 0x21b0
movq %rax, -0x790(%rbp)
jmp 0x3222
movq -0x790(%rbp), %rdi
movss -0x550(%rbp), %xmm0
callq 0x2140
movq %rax, -0x798(%rbp)
jmp 0x323f
movq -0x798(%rbp), %rdi
leaq 0x205c(%rip), %rsi      # 0x52a9
callq 0x21b0
movq %rax, -0x7a0(%rbp)
jmp 0x325b
movq -0x7a0(%rbp), %rdi
movq 0x3d57(%rip), %rsi      # 0x6fc0
callq 0x21d0
jmp 0x3270
leaq -0x5c9(%rbp), %rdi
movq %rdi, -0x7a8(%rbp)
callq 0x2360
movq -0x7a8(%rbp), %rdx
leaq 0x201c(%rip), %rsi      # 0x52ad
leaq -0x5c8(%rbp), %rdi
callq 0x4190
jmp 0x329f
leaq -0x5c9(%rbp), %rdi
callq 0x2200
movslq -0x4f4(%rbp), %rdx
leaq -0x5c8(%rbp), %rdi
leaq -0x4f0(%rbp), %rsi
callq 0x2050
jmp 0x32c7
movl -0xc(%rbp), %eax
movl %eax, -0x7bc(%rbp)
leaq -0x5c8(%rbp), %rdi
movq %rdi, -0x7c8(%rbp)
callq 0x2100
movq -0x7c8(%rbp), %rdi
movq %rax, -0x7b8(%rbp)
callq 0x2310
movl -0x7bc(%rbp), %edi
movq -0x7b8(%rbp), %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x20f0
movq %rax, -0x7b0(%rbp)
jmp 0x3316
movq -0x7b0(%rbp), %rax
cmpq $-0x1, %rax
jne 0x3379
leaq 0x1f85(%rip), %rdi      # 0x52af
callq 0x2180
jmp 0x3331
jmp 0x3379
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x590(%rbp)
movl %eax, -0x594(%rbp)
leaq -0x5c9(%rbp), %rdi
callq 0x2200
jmp 0x353f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x590(%rbp)
movl %eax, -0x594(%rbp)
leaq -0x5c8(%rbp), %rdi
callq 0x2110
jmp 0x353f
movq 0x3c50(%rip), %rdi      # 0x6fd0
leaq 0x1f30(%rip), %rsi      # 0x52b7
callq 0x21b0
movq %rax, -0x7d0(%rbp)
jmp 0x3395
movq -0x7d0(%rbp), %rdi
leaq 0x1c6b(%rip), %rsi      # 0x500e
callq 0x21b0
movq %rax, -0x7d8(%rbp)
jmp 0x33b1
movq -0x7d8(%rbp), %rdi
leaq 0x1e8e(%rip), %rsi      # 0x524d
callq 0x21b0
movq %rax, -0x7e0(%rbp)
jmp 0x33cd
movq -0x7e0(%rbp), %rdi
movq 0x3be5(%rip), %rsi      # 0x6fc0
callq 0x21d0
jmp 0x33e2
leaq -0x5c8(%rbp), %rdi
callq 0x2110
jmp 0x3505
movsbl -0x5a3(%rbp), %eax
cmpl $0x65, %eax
jne 0x3412
leaq 0x1ef4(%rip), %rdi      # 0x52fa
callq 0x2180
jmp 0x340d
jmp 0x3503
leaq -0x5f1(%rbp), %rdi
movq %rdi, -0x7e8(%rbp)
callq 0x2360
movq -0x7e8(%rbp), %rdx
leaq 0x1ed7(%rip), %rsi      # 0x530a
leaq -0x5f0(%rbp), %rdi
callq 0x4190
jmp 0x3441
leaq -0x5f1(%rbp), %rdi
callq 0x2200
movsbl -0x5a3(%rbp), %edx
leaq -0x5f0(%rbp), %rdi
movl $0x1, %esi
callq 0x21f0
jmp 0x3467
movl -0xc(%rbp), %eax
movl %eax, -0x7f4(%rbp)
leaq -0x5f0(%rbp), %rdi
callq 0x2100
movl -0x7f4(%rbp), %edi
movq %rax, %rsi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x20f0
movq %rax, -0x7f0(%rbp)
jmp 0x349a
movq -0x7f0(%rbp), %rax
cmpq $-0x1, %rax
jne 0x34f7
leaq 0x1e01(%rip), %rdi      # 0x52af
callq 0x2180
jmp 0x34b5
jmp 0x34f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x590(%rbp)
movl %eax, -0x594(%rbp)
leaq -0x5f1(%rbp), %rdi
callq 0x2200
jmp 0x353f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x590(%rbp)
movl %eax, -0x594(%rbp)
leaq -0x5f0(%rbp), %rdi
callq 0x2110
jmp 0x353f
leaq -0x5f0(%rbp), %rdi
callq 0x2110
jmp 0x3505
movl -0xc(%rbp), %edi
callq 0x23a0
jmp 0x350f
xorl %edi, %edi
callq 0x2250
jmp 0x297e
leaq -0x538(%rbp), %rdi
callq 0x2110
leaq -0x518(%rbp), %rdi
callq 0x2110
movl -0x4(%rbp), %eax
addq $0x800, %rsp            # imm = 0x800
popq %rbp
retq
leaq -0x538(%rbp), %rdi
callq 0x2110
leaq -0x518(%rbp), %rdi
callq 0x2110
movq -0x590(%rbp), %rdi
callq 0x2350
nopw %cs:(%rax,%rax)