// File: 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
subq $0x2810, %rsp           # imm = 0x2810
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2798(%rbp)
movq 0x5d1f(%rip), %rdi      # 0x8fd0
leaq 0x2ed9(%rip), %rsi      # 0x6191
callq 0x21d0
movq %rax, %rdi
movq 0x5ce9(%rip), %rsi      # 0x8fb0
callq 0x21f0
movl $0x41c, %edi            # imm = 0x41C
callq 0x21e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x2790(%rbp)
callq 0x24f0
jmp 0x32ea
movq -0x2790(%rbp), %rax
movq %rax, -0x10(%rbp)
leaq -0x13a8(%rbp), %rdi
movq %rdi, -0x27a8(%rbp)
callq 0x38b0
movq -0x27a8(%rbp), %rdi
callq 0x3950
movl %eax, -0x279c(%rbp)
jmp 0x331c
movl -0x279c(%rbp), %eax
movl %eax, %eax
movl %eax, %esi
leaq -0x2730(%rbp), %rdi
callq 0x3970
jmp 0x3334
movq -0x2798(%rbp), %rax
movl 0x4(%rax), %edx
decl %edx
leaq -0x2738(%rbp), %rdi
xorl %esi, %esi
callq 0x39a0
jmp 0x3350
leaq -0x2738(%rbp), %rdi
leaq -0x2730(%rbp), %rsi
callq 0x39d0
movl %eax, -0x27ac(%rbp)
jmp 0x336b
movq -0x2798(%rbp), %rdi
movl -0x27ac(%rbp), %eax
movl %eax, -0x273c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x27c0(%rbp)
addq $0x8, %rdi
movq %rdi, -0x27c8(%rbp)
movslq -0x273c(%rbp), %rsi
callq 0x3a00
movq -0x27c8(%rbp), %rdi
movq %rax, -0x27b8(%rbp)
movslq -0x273c(%rbp), %rsi
callq 0x3a00
movq -0x27c0(%rbp), %rdi
movq -0x27b8(%rbp), %rsi
movq %rax, %rdx
addq $0x20, %rdx
callq 0x2560
jmp 0x33d6
movq -0x10(%rbp), %rdi
callq 0x2690
movb %al, -0x27c9(%rbp)
jmp 0x33e7
movb -0x27c9(%rbp), %al
testb $0x1, %al
jne 0x33f6
jmp 0x3663
leaq -0x2760(%rbp), %rdi
callq 0x2250
movq 0x5bc7(%rip), %rdi      # 0x8fd0
leaq 0x2d8f(%rip), %rsi      # 0x619f
callq 0x21d0
movq %rax, -0x27d8(%rbp)
jmp 0x341e
movq -0x27d8(%rbp), %rdi
movq 0x5b84(%rip), %rsi      # 0x8fb0
callq 0x21f0
jmp 0x3433
movq 0x5b96(%rip), %rdi      # 0x8fd0
leaq 0x2d8b(%rip), %rsi      # 0x61cc
callq 0x21d0
movq %rax, -0x27e0(%rbp)
jmp 0x344f
movq -0x27e0(%rbp), %rdi
movq 0x5b53(%rip), %rsi      # 0x8fb0
callq 0x21f0
jmp 0x3464
jmp 0x3466
jmp 0x3468
movq 0x5b71(%rip), %rdi      # 0x8fe0
movq 0x5b4a(%rip), %rsi      # 0x8fc0
callq 0x20a0
movq %rax, -0x27e8(%rbp)
jmp 0x3484
movq -0x27e8(%rbp), %rdi
leaq -0x2760(%rbp), %rsi
callq 0x2050
jmp 0x3499
leaq -0x2760(%rbp), %rdi
leaq 0x2cac(%rip), %rsi      # 0x6153
xorl %eax, %eax
movl %eax, %edx
callq 0x2320
movq %rax, -0x2768(%rbp)
leaq -0x2760(%rbp), %rdi
leaq 0x2d21(%rip), %rsi      # 0x61e6
xorl %eax, %eax
movl %eax, %edx
callq 0x2320
cmpq $-0x1, %rax
jne 0x3500
leaq -0x2760(%rbp), %rdi
leaq 0x2d0b(%rip), %rsi      # 0x61ed
xorl %eax, %eax
movl %eax, %edx
callq 0x2320
movq %rax, %rcx
xorl %eax, %eax
cmpq $-0x1, %rcx
movb %al, -0x27e9(%rbp)
je 0x35a5
xorl %eax, %eax
cmpq $-0x1, -0x2768(%rbp)
movb %al, -0x27e9(%rbp)
je 0x35a5
leaq -0x2760(%rbp), %rdi
movq %rdi, -0x27f8(%rbp)
callq 0x2190
movq %rax, -0x2780(%rbp)
movq -0x2768(%rbp), %rsi
leaq -0x2780(%rbp), %rdi
callq 0x3a70
movq %rax, -0x2778(%rbp)
leaq -0x2778(%rbp), %rdi
movl $0x1, %esi
callq 0x3a70
movq -0x27f8(%rbp), %rdi
movq %rax, -0x2770(%rbp)
callq 0x2120
movq %rax, -0x2788(%rbp)
movq -0x2770(%rbp), %rdi
movq -0x2788(%rbp), %rsi
movq 0x5a3e(%rip), %rdx      # 0x8fc8
callq 0x3a20
movb %al, -0x27ea(%rbp)
jmp 0x3597
movb -0x27ea(%rbp), %al
movb %al, -0x27e9(%rbp)
jmp 0x35a5
movb -0x27e9(%rbp), %al
testb $0x1, %al
jne 0x35b1
jmp 0x3601
jmp 0x3643
movq -0x2790(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x21c0
jmp 0x370a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x36fe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x2760(%rbp), %rdi
callq 0x2150
jmp 0x36fe
movq 0x59c8(%rip), %rdi      # 0x8fd0
leaq 0x2be4(%rip), %rsi      # 0x61f3
callq 0x21d0
movq %rax, -0x2800(%rbp)
jmp 0x361d
movq -0x2800(%rbp), %rdi
movq 0x5985(%rip), %rsi      # 0x8fb0
callq 0x21f0
jmp 0x3632
leaq -0x2760(%rbp), %rdi
callq 0x2230
jmp 0x3466
movq -0x10(%rbp), %rdi
leaq -0x2760(%rbp), %rsi
callq 0x26b0
jmp 0x3655
leaq -0x2760(%rbp), %rdi
callq 0x2150
jmp 0x36c0
movq 0x5966(%rip), %rdi      # 0x8fd0
leaq 0x2bb1(%rip), %rsi      # 0x6222
callq 0x21d0
movq %rax, -0x2808(%rbp)
jmp 0x367f
movq -0x2808(%rbp), %rdi
movq 0x5923(%rip), %rsi      # 0x8fb0
callq 0x21f0
jmp 0x3694
movq 0x5935(%rip), %rdi      # 0x8fd0
movq 0x590e(%rip), %rsi      # 0x8fb0
callq 0x21f0
jmp 0x36a9
movq -0x2798(%rbp), %rdi
movl $0xffffffff, 0x4(%rdi)  # imm = 0xFFFFFFFF
addq $0x8, %rdi
callq 0x3ab0
movq -0x10(%rbp), %rax
movq %rax, -0x2810(%rbp)
cmpq $0x0, %rax
je 0x36e9
movq -0x2810(%rbp), %rdi
callq 0x2530
movq -0x2810(%rbp), %rdi
callq 0x21c0
leaq -0x13a8(%rbp), %rdi
callq 0x3ad0
addq $0x2810, %rsp           # imm = 0x2810
popq %rbp
retq
leaq -0x13a8(%rbp), %rdi
callq 0x3ad0
movq -0x18(%rbp), %rdi
callq 0x22e0
nopw %cs:(%rax,%rax)
nopl (%rax)