// File: /workspace/github_cpp_makefile_star2_O2/rohitrangan[P]3PC/src/client.cpp
// Function: main
int main(int argc, char* argv[])
{
    if (argc != 5)
    {
        cout << "Not enough parameters.\n";
        return 1;
    }

    int transactionId = stoi (string (argv[1]));
    int add_v = stoi (string (argv[2]));
    int sleep_time = stoi (string (argv[3]));
    double send_till = stod (string (argv[4]));
    int site_id = 1231;
    double time_elapsed = 0.0;
    int mod_sites = 3;
    map<int, int> sites;
    sites[0] = 6666;
    sites[1] = 6667;
    sites[2] = 6668;

    while ((int)time_elapsed < (int)send_till)
    {
        auto t1 = chrono::steady_clock::now ();
        Socket transaction_gen;
        Message msg (TRANSACTION,transactionId, site_id);
        string str = msg.createMessage();
        srand (time(NULL));
        if (mod_sites == 0)
        {
            cout << "Cannot connect to any server. Exiting.." << endl;
            exit (0);
        }
        int cur_site = rand() % mod_sites;
        cout << "Transaction ID: " << transactionId << ", Site ID :" <<cur_site;
        cout << ", message: " << str << endl;
        if (transaction_gen.connect("localhost", sites[cur_site]) < 0)
        {
            sites.erase (cur_site);
            --mod_sites;
            continue;
        }
        transaction_gen.send(str);
        transactionId += add_v;
        transaction_gen.close ();
        this_thread::sleep_for (chrono::milliseconds(sleep_time));
        auto t2 = chrono::steady_clock::now ();
        chrono::duration<double> time_span = chrono::\
                        duration_cast<chrono::duration<double>>(t2 - t1);
        time_elapsed += time_span.count ();
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
cmpl $0x5, %edi
jne 0x2a1c
movq %rsi, %r14
movq 0x8(%rsi), %rsi
leaq 0x18(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x2b20
leaq 0x18(%rsp), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x2b04
movl %eax, (%rsp)
leaq 0x18(%rsp), %rdi
callq 0x2110
movq 0x10(%r14), %rsi
leaq 0x18(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x2b20
leaq 0x18(%rsp), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x2b04
movl %eax, 0x48(%rsp)
leaq 0x18(%rsp), %rdi
callq 0x2110
movq 0x18(%r14), %rsi
leaq 0x18(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x2b20
leaq 0x18(%rsp), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x2b04
movl %eax, %ebp
leaq 0x18(%rsp), %rdi
callq 0x2110
movq 0x20(%r14), %rsi
leaq 0x18(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x2b20
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x2b5b
movsd %xmm0, 0x8(%rsp)
leaq 0x18(%rsp), %rdi
callq 0x2110
leaq 0x20(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x68(%rsp), %rsi
andl $0x0, (%rsi)
leaq 0x18(%rsp), %rdi
callq 0x2b74
movl $0x1a0a, (%rax)         # imm = 0x1A0A
leaq 0x68(%rsp), %rsi
movl $0x1, (%rsi)
leaq 0x18(%rsp), %rdi
callq 0x2b74
movl $0x1a0b, (%rax)         # imm = 0x1A0B
leaq 0x68(%rsp), %rsi
movl $0x2, (%rsi)
leaq 0x18(%rsp), %rdi
callq 0x2b74
movl $0x1a0c, (%rax)         # imm = 0x1A0C
cvttsd2si 0x8(%rsp), %eax
movl %eax, 0x4c(%rsp)
movslq %ebp, %rax
movq %rax, 0x58(%rsp)
pushq $0x3
popq %r12
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x10(%rsp), %rbp
leaq 0x68(%rsp), %r14
leaq 0xd8(%rsp), %rbx
leaq 0xb8(%rsp), %r15
cvttsd2si 0x8(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jge 0x2a34
callq 0x2320
movq %rbp, %rdi
movq %rax, 0x60(%rsp)
callq 0x336c
movq %r14, %rdi
xorl %esi, %esi
movl (%rsp), %edx
movl $0x4cf, %ecx            # imm = 0x4CF
callq 0x388e
movq %r15, %rbp
leaq 0x98(%rsp), %rdi
movq %r14, %rsi
callq 0x39ac
xorl %edi, %edi
callq 0x2220
movl %eax, %edi
callq 0x2240
testl %r12d, %r12d
je 0x2a52
callq 0x2080
cltd
idivl %r12d
movl %edx, 0x4(%rsp)
movq 0x470f(%rip), %rdi      # 0x6fc8
leaq 0x1790(%rip), %rsi      # 0x4050
callq 0x2250
movq %rax, %rdi
movl (%rsp), %esi
callq 0x2390
movq %rax, %rdi
leaq 0x1787(%rip), %rsi      # 0x4061
callq 0x2250
movl 0x4(%rsp), %esi
movq %rax, %rdi
callq 0x2390
movq 0x46d6(%rip), %rdi      # 0x6fc8
leaq 0x1774(%rip), %rsi      # 0x406d
callq 0x2250
movq %rax, %rdi
leaq 0x98(%rsp), %rsi
callq 0x2210
movq %rax, %rdi
callq 0x2120
movq %rbx, %rdi
leaq 0x1759(%rip), %rsi      # 0x4079
leaq 0x50(%rsp), %rdx
callq 0x2b20
movq %r14, %r13
leaq 0x18(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x2bc2
movq %rbx, %r15
movl (%rax), %edx
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x337a
movl %eax, %r14d
movq %r15, %rdi
callq 0x2110
testl %r14d, %r14d
js 0x29db
movq %rbp, %rdi
leaq 0x98(%rsp), %rsi
callq 0x2330
movq %r13, %r14
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %rbp, %r13
movq %rbp, %rsi
callq 0x34b0
movq %r13, %rdi
callq 0x2110
movq %r15, %rdi
callq 0x371a
movq 0x58(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x2c10
movl (%rsp), %eax
addl 0x48(%rsp), %eax
movl %eax, (%rsp)
callq 0x2320
subq 0x60(%rsp), %rax
cvtsi2sd %rax, %xmm0
divsd 0x163f(%rip), %xmm0     # 0x4008
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x29f0
leaq 0x18(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x31e6
movq %r13, %r14
decl %r12d
movq %rbp, %r15
leaq 0x98(%rsp), %rdi
callq 0x2110
leaq 0x78(%rsp), %rdi
callq 0x2110
leaq 0x10(%rsp), %rbp
movq %rbp, %rdi
callq 0x3722
jmp 0x2847
movq 0x45a5(%rip), %rdi      # 0x6fc8
leaq 0x15e6(%rip), %rsi      # 0x4010
callq 0x2250
pushq $0x1
popq %rax
jmp 0x2a40
leaq 0x18(%rsp), %rdi
callq 0x2de8
xorl %eax, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x456f(%rip), %rdi      # 0x6fc8
leaq 0x15c8(%rip), %rsi      # 0x4028
callq 0x2250
movq %rax, %rdi
callq 0x2120
xorl %edi, %edi
callq 0x22e0
jmp 0x2aad
jmp 0x2aad
jmp 0x2aad
jmp 0x2a86
jmp 0x2a95
jmp 0x2a86
jmp 0x2a95
jmp 0x2a86
jmp 0x2a95
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x2110
jmp 0x2afc
movq %rax, %rbx
jmp 0x2afc
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
jmp 0x2ac7
jmp 0x2ace
jmp 0x2ace
jmp 0x2ace
movq %rax, %rbx
jmp 0x2af2
movq %rax, %rbx
jmp 0x2ade
movq %rax, %rbx
jmp 0x2ae8
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x2110
jmp 0x2ad1
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x2110
leaq 0x78(%rsp), %rdi
callq 0x2110
leaq 0x10(%rsp), %rdi
callq 0x3722
leaq 0x18(%rsp), %rdi
callq 0x2de8
movq %rbx, %rdi
callq 0x23a0