// File: /workspace/github_cpp_makefile_star2_O1/XuhuiSun95[P]Ticket-Booking-Service/server/Server.cpp
// Function: Server::ProcessTicket(int const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void Server::ProcessTicket(const int &sock, const std::string &type) {

    std::string msg = mServer->GetMessage(sock);
    std::cout << "Message Received: " << msg << std::endl;

    if(msg.find(type)!=std::string::npos) {

        std::size_t ws = msg.find(" ");
        int ticket = std::stoi(msg.substr(ws+1));
        
        mtx.lock();
        std::string reply = HandleRequest(ticket);
        mtx.unlock();
        std::cout << "Ticket left: " << mTickets << std::endl;

        mServer->SendMessage(sock, reply);
    } else {

        //  Create a new forward socket to handle the forward operation
        ServerSocket* pair = new ServerSocket();
        pair->Init(mPairInfo.first, mPairInfo.second, false);

        std::cout << "Forward Message!" << std::endl;
        std::string reply = pair->ForwardTicket(msg);
        std::cout << "Receive pair reply: " << reply << std::endl;

        delete pair;

        std::cout << "Forward reply!" << std::endl;
        mServer->SendMessage(sock, reply);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
movq 0x8(%rdi), %rsi
leaq -0x78(%rbp), %rdi
movq %rbx, %rdx
callq 0x4148
movq 0x48c7(%rip), %rdi      # 0x6fd0
leaq 0x28f4(%rip), %rsi      # 0x5004
movl $0x12, %edx
callq 0x2210
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq 0x48a7(%rip), %rdi      # 0x6fd0
callq 0x2210
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq (%r15), %rsi
movq 0x8(%r15), %rcx
leaq -0x78(%rbp), %rdi
xorl %edx, %edx
callq 0x22d0
cmpq $-0x1, %rax
je 0x28d6
movq %rbx, -0x58(%rbp)
leaq 0x2b86(%rip), %rsi      # 0x5305
leaq -0x78(%rbp), %r15
movl $0x1, %ecx
movq %r15, %rdi
xorl %edx, %edx
callq 0x22d0
leaq 0x1(%rax), %rdx
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x21f0
movq -0x50(%rbp), %r13
callq 0x2040
movq %rax, %r15
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, (%r15)
leaq -0x80(%rbp), %rbx
movq %r13, %rdi
movq %rbx, %rsi
movl $0xa, %edx
callq 0x2250
cmpq %r13, (%rbx)
je 0x2a26
movq %rax, %r12
movslq %r12d, %rax
cmpq %r12, %rax
jne 0x2a32
movl (%r15), %eax
cmpl $0x22, %eax
je 0x2a32
testl %eax, %eax
jne 0x2803
movl -0x2c(%rbp), %eax
movl %eax, (%r15)
leaq -0x40(%rbp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0x2815
callq 0x21c0
movl %r12d, -0x30(%rbp)
leaq 0x60(%r14), %r15
movq %r15, %rdi
callq 0x2280
testl %eax, %eax
jne 0x2a3e
leaq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rdx
movq %r14, %rsi
callq 0x2aaa
movq %r15, %rdi
callq 0x2170
movq 0x4784(%rip), %rdi      # 0x6fd0
leaq 0x27c4(%rip), %rsi      # 0x5017
movl $0xd, %edx
callq 0x2210
movl (%r14), %esi
movq 0x4769(%rip), %rdi      # 0x6fd0
callq 0x22c0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq 0x8(%r14), %rdi
leaq -0x50(%rbp), %rdx
movq -0x58(%rbp), %rsi
callq 0x41ae
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0x28b5
callq 0x21c0
leaq -0x68(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x28c7
callq 0x21c0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x41c, %edi            # imm = 0x41C
callq 0x21e0
movq %rax, %r15
movq %rax, %rdi
callq 0x3f30
leaq 0x38(%r14), %rsi
leaq 0x58(%r14), %rdx
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x3f6a
movq 0x46cc(%rip), %r12      # 0x6fd0
leaq 0x271a(%rip), %rsi      # 0x5025
movl $0x10, %edx
movq %r12, %rdi
callq 0x2210
movq (%r12), %rax
addq -0x18(%rax), %r12
movq %r12, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq 0x4699(%rip), %rdi      # 0x6fd0
callq 0x2030
movq %rax, %rdi
callq 0x2150
leaq -0x50(%rbp), %rdi
leaq -0x78(%rbp), %rdx
movq %r15, %rsi
callq 0x4210
movq 0x4675(%rip), %rdi      # 0x6fd0
leaq 0x26d4(%rip), %rsi      # 0x5036
movl $0x14, %edx
callq 0x2210
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq 0x4655(%rip), %rdi      # 0x6fd0
callq 0x2210
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %r15, %rdi
callq 0x3f54
movq %r15, %rdi
callq 0x21c0
movq 0x460f(%rip), %r15      # 0x6fd0
leaq 0x2683(%rip), %rsi      # 0x504b
movl $0xe, %edx
movq %r15, %rdi
callq 0x2210
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq 0x45dd(%rip), %rdi      # 0x6fd0
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq 0x8(%r14), %rdi
leaq -0x50(%rbp), %rdx
movq %rbx, %rsi
callq 0x41ae
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x28b0
jmp 0x28b5
leaq 0x2652(%rip), %rdi      # 0x507f
callq 0x2110
leaq 0x2646(%rip), %rdi      # 0x507f
callq 0x2270
movl %eax, %edi
callq 0x2140
jmp 0x2a8d
movq %rax, %rbx
movq %r15, %rdi
jmp 0x2a86
jmp 0x2a8d
jmp 0x2a8d
jmp 0x2a8d
movq %rax, %rbx
cmpl $0x0, (%r15)
jne 0x2a6b
movl -0x2c(%rbp), %eax
movl %eax, (%r15)
jmp 0x2a6b
jmp 0x2a8d
movq %rax, %rbx
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x2a86
jmp 0x2a90
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0x2a90
callq 0x21c0
jmp 0x2a90
movq %rax, %rbx
leaq -0x68(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2aa2
callq 0x21c0
movq %rbx, %rdi
callq 0x22f0