// File: /workspace/github_cpp_makefile_star2_O2/XuhuiSun95[P]Ticket-Booking-Service/client/UserInterface.cpp
// Function: UserInterface::BuyTickets()
void UserInterface::BuyTickets() {

    std::cout << "Processing..." << std::endl;

    ClientSocket *client = new ClientSocket();

    //  Randomly connect to one server from the list
    std::random_device rd;
    std::mt19937 mt(rd());
    std::uniform_int_distribution<int> dist(0, mServers-1);
    int server = dist(mt);

    client->Init(mServerList[server].first, mServerList[server].second);

    if(client->Valid()) {

        std::string request;
        std::size_t ws;

        std::cout << "Please enter the request in the follow form:" << std::endl;
        std::cout << "<movies, n> or <plays, n>" << std::endl;

        while(true) {

            std::getline(std::cin >> std::ws, request);
            ws = request.find(" ");

            if((request.find("movies")!=std::string::npos
               || request.find("plays")!=std::string::npos)
               && ws!=std::string::npos
               && std::all_of(request.begin()+ws+1, request.end(), ::isdigit)) {
                break;
            } else {
                std::cout << "Invalid input! Please enter the request again." << std::endl;
                request.clear();
            }
        }

        client->RequestTicket(request);
    }
    else {

        std::cout << "Socket Init Error! Please check your environment." << std::endl;
        std::cout << std::endl;

        mServers = -1;
        mServerList.clear();
    }

    delete client;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2748, %rsp           # imm = 0x2748
movq %rdi, %r14
movq 0x34de(%rip), %rdi      # 0x5fd0
leaq 0x16a4(%rip), %rsi      # 0x419d
callq 0x2180
movq %rax, %rdi
callq 0x20c0
movl $0x41c, %edi            # imm = 0x41C
callq 0x2190
movq %rax, %r15
movq %rax, %rdi
callq 0x240c
leaq -0x13e0(%rbp), %rbx
movq %rbx, %rdi
callq 0x2d78
movq %rbx, %rdi
callq 0x21d0
movl %eax, %esi
leaq -0x2768(%rbp), %rdi
callq 0x3060
movl 0x4(%r14), %eax
decl %eax
leaq -0x58(%rbp), %rdi
andl $0x0, (%rdi)
movl %eax, 0x4(%rdi)
leaq -0x2768(%rbp), %rsi
callq 0x2dce
cltq
movq 0x8(%r14), %rcx
imulq $0x28, %rax, %rax
leaq (%rcx,%rax), %rsi
leaq (%rcx,%rax), %rdx
addq $0x20, %rdx
movq %r15, %rdi
callq 0x2446
movq %r15, %rdi
callq 0x2504
testb %al, %al
je 0x2c93
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x342f(%rip), %rdi      # 0x5fd0
leaq 0x1603(%rip), %rsi      # 0x41ab
callq 0x2180
movq %rax, %rdi
callq 0x20c0
movq 0x3414(%rip), %rdi      # 0x5fd0
leaq 0x1615(%rip), %rsi      # 0x41d8
callq 0x2180
movq %rax, %rdi
callq 0x20c0
movq %r15, -0x50(%rbp)
leaq -0x48(%rbp), %r15
leaq 0x1613(%rip), %r13      # 0x41f2
movq 0x33ea(%rip), %rbx      # 0x5fd0
leaq 0x1612(%rip), %r14      # 0x41ff
movq 0x33ec(%rip), %rdi      # 0x5fe0
callq 0x2140
movq %rax, %rdi
movq %r15, %rsi
callq 0x2040
movq %r15, %rdi
leaq 0x1551(%rip), %rsi      # 0x415f
xorl %edx, %edx
callq 0x2260
movq %rax, %r12
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x2260
cmpq $-0x1, %rax
je 0x2c33
cmpq $-0x1, %r12
jne 0x2c50
jmp 0x2c6f
movq %r15, %rdi
leaq 0x15bc(%rip), %rsi      # 0x41f9
xorl %edx, %edx
callq 0x2260
cmpq $-0x1, %r12
je 0x2c6f
cmpq $-0x1, %rax
je 0x2c6f
movq -0x48(%rbp), %rsi
leaq (%rsi,%r12), %rdi
incq %rdi
addq -0x40(%rbp), %rsi
movq 0x3362(%rip), %rdx      # 0x5fc8
callq 0x2ddb
testb %al, %al
jne 0x2ccd
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2180
movq %rax, %rdi
callq 0x20c0
andq $0x0, -0x40(%rbp)
movq -0x48(%rbp), %rax
movb $0x0, (%rax)
jmp 0x2bed
movq 0x3336(%rip), %rdi      # 0x5fd0
leaq 0x158d(%rip), %rsi      # 0x422e
callq 0x2180
movq %rax, %rdi
callq 0x20c0
movq 0x331b(%rip), %rdi      # 0x5fd0
callq 0x20c0
orl $-0x1, 0x4(%r14)
addq $0x8, %r14
movq %r14, %rdi
callq 0x2df6
jmp 0x2ce6
leaq -0x48(%rbp), %rsi
movq -0x50(%rbp), %r15
movq %r15, %rdi
callq 0x250c
leaq -0x48(%rbp), %rdi
callq 0x20b0
movq %r15, %rdi
callq 0x2430
movq %r15, %rdi
callq 0x2170
leaq -0x13e0(%rbp), %rdi
callq 0x2e04
addq $0x2748, %rsp           # imm = 0x2748
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r15, %rdi
callq 0x2170
jmp 0x2d44
jmp 0x2d25
jmp 0x2d2c
movq %rax, %rbx
jmp 0x2d38
jmp 0x2d2c
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x20b0
leaq -0x13e0(%rbp), %rdi
callq 0x2e04
movq %rbx, %rdi
callq 0x2230