// File: /workspace/github_cpp_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
cmpl $0x5, %edi
jne 0x29fc
movq %rsi, %r15
movq 0x8(%rsi), %rsi
leaq 0x8(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x2fba
movq 0x8(%rsp), %r14
callq 0x2050
movq %rax, %rbx
movl (%rax), %ebp
movl $0x0, (%rax)
leaq 0xb8(%rsp), %r12
movq %r14, %rdi
movq %r12, %rsi
movl $0xa, %edx
callq 0x2350
cmpq %r14, (%r12)
je 0x2e26
movslq %eax, %rcx
cmpq %rax, %rcx
jne 0x2e32
movq %rax, %r14
movl (%rbx), %eax
cmpl $0x22, %eax
je 0x2e32
testl %eax, %eax
jne 0x2863
movl %ebp, (%rbx)
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x287e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2290
movq %r14, 0x48(%rsp)
movq 0x10(%r15), %rsi
leaq 0x8(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x2fba
movq 0x8(%rsp), %r14
movl (%rbx), %r13d
movl $0x0, (%rbx)
leaq 0xb8(%rsp), %r12
movq %r14, %rdi
movq %r12, %rsi
movl $0xa, %edx
callq 0x2350
cmpq %r14, (%r12)
je 0x2e3e
movabsq $-0x100000000, %rbp     # imm = 0xFFFFFFFF00000000
leaq -0x80000000(%rax), %rcx
cmpq %rbp, %rcx
jb 0x2e4a
movq %rax, %r14
movl (%rbx), %eax
cmpl $0x22, %eax
je 0x2e4a
testl %eax, %eax
jne 0x28f5
movl %r13d, (%rbx)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2911
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2290
movq %r14, 0xf8(%rsp)
movq 0x18(%r15), %rsi
leaq 0x8(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x2fba
movq 0x8(%rsp), %r14
movl (%rbx), %r12d
movl $0x0, (%rbx)
leaq 0xb8(%rsp), %r13
movq %r14, %rdi
movq %r13, %rsi
movl $0xa, %edx
callq 0x2350
cmpq %r14, (%r13)
je 0x2e56
movq %rax, 0x40(%rsp)
addq $-0x80000000, %rax      # imm = 0x80000000
cmpq %rbp, %rax
jb 0x2e62
movl (%rbx), %eax
cmpl $0x22, %eax
je 0x2e62
testl %eax, %eax
jne 0x2982
movl %r12d, (%rbx)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x299e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2290
movq 0x20(%r15), %rsi
leaq 0x8(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x2fba
movq 0x8(%rsp), %r14
movl (%rbx), %ebp
movl $0x0, (%rbx)
leaq 0xb8(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x21e0
cmpq %r14, (%r15)
je 0x2e6e
movl (%rbx), %eax
testl %eax, %eax
movq 0x48(%rsp), %r13
movsd %xmm0, 0x38(%rsp)
je 0x2a1e
cmpl $0x22, %eax
jne 0x2a20
leaq 0x2691(%rip), %rdi      # 0x5088
callq 0x2360
movq 0x45cd(%rip), %rdi      # 0x6fd0
leaq 0x2606(%rip), %rsi      # 0x5010
movl $0x17, %edx
callq 0x22f0
movl $0x1, %eax
jmp 0x2de9
movl %ebp, (%rbx)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2a3c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2290
leaq 0x10(%rsp), %rax
xorl %ecx, %ecx
movl %ecx, (%rax)
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
leaq 0xb8(%rsp), %rsi
movl %ecx, (%rsi)
leaq 0x8(%rsp), %rdi
callq 0x2ff8
movl $0x1a0a, (%rax)         # imm = 0x1A0A
leaq 0xb8(%rsp), %rsi
movl $0x1, (%rsi)
leaq 0x8(%rsp), %rdi
callq 0x2ff8
movq %rbx, %r15
movl $0x1a0b, (%rax)         # imm = 0x1A0B
leaq 0xb8(%rsp), %rsi
movl $0x2, (%rsi)
leaq 0x8(%rsp), %rdi
callq 0x2ff8
movl $0x1a0c, (%rax)         # imm = 0x1A0C
cvttsd2si 0x38(%rsp), %eax
movl %eax, 0x54(%rsp)
testl %eax, %eax
jle 0x2ddd
movslq 0x40(%rsp), %rsi
movq %rsi, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
shrq $0x4, %rdx
movq %rdx, 0xf0(%rsp)
imulq $-0x3e8, %rdx, %rax     # imm = 0xFC18
movq %rsi, 0x40(%rsp)
addq %rsi, %rax
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
movq %rax, 0xe8(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movl $0x3, %ebx
leaq 0x100(%rsp), %r12
leaq 0x108(%rsp), %rbp
callq 0x2340
movq %r12, %rdi
movq %rax, 0x48(%rsp)
callq 0x3608
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
movl %r13d, %edx
movl $0x4cf, %ecx            # imm = 0x4CF
callq 0x3c10
leaq 0x58(%rsp), %rdi
movq %r14, %rsi
callq 0x3eac
xorl %edi, %edi
callq 0x2230
movl %eax, %edi
callq 0x2250
testl %ebx, %ebx
je 0x2dfb
callq 0x2090
cltd
idivl %ebx
movl %edx, 0x4(%rsp)
movl $0x10, %edx
movq 0x4447(%rip), %rdi      # 0x6fd0
leaq 0x24c0(%rip), %rsi      # 0x5050
callq 0x22f0
movq 0x4434(%rip), %rdi      # 0x6fd0
movl %r13d, %esi
callq 0x23b0
movq %rax, %r14
movl $0xb, %edx
movq %rax, %rdi
leaq 0x24ab(%rip), %rsi      # 0x5061
callq 0x22f0
movl 0x4(%rsp), %esi
movq %r14, %rdi
callq 0x23b0
movl $0xb, %edx
movq 0x43fd(%rip), %rdi      # 0x6fd0
leaq 0x2493(%rip), %rsi      # 0x506d
callq 0x22f0
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x43e0(%rip), %rdi      # 0x6fd0
callq 0x22f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2260
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
leaq 0xa8(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0x98(%rsp), %rdi
leaq 0x243b(%rip), %rsi      # 0x5079
leaq 0x243d(%rip), %rdx      # 0x5082
callq 0x31ac
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x305c
movl (%rax), %edx
movq %r12, %rdi
leaq 0x98(%rsp), %rsi
callq 0x3616
movl %eax, %r14d
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x2c93
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2290
testl %r14d, %r14d
js 0x2d66
leaq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x311c
movq %r12, %rdi
leaq 0x78(%rsp), %rsi
callq 0x379e
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x2cef
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2290
movq %r12, %rdi
callq 0x3a54
cmpq $0x0, 0x40(%rsp)
jle 0x2d35
movq 0xf0(%rsp), %rax
movq %rax, 0x108(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x110(%rsp)
movq %rbp, %rdi
movq %rbp, %rsi
callq 0x20b0
cmpl $-0x1, %eax
jne 0x2d35
cmpl $0x4, (%r15)
je 0x2d1f
addl 0xf8(%rsp), %r13d
callq 0x2340
subq 0x48(%rsp), %rax
cvtsi2sd %rax, %xmm0
divsd 0x22b4(%rip), %xmm0     # 0x5008
movsd 0x38(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
jmp 0x2d84
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x34e8
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x3560
decl %ebx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x2da0
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2290
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x2dc5
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x2290
movq %r12, %rdi
callq 0x3a5c
cvttsd2si 0x38(%rsp), %eax
cmpl 0x54(%rsp), %eax
jl 0x2b22
leaq 0x8(%rsp), %rdi
callq 0x30cc
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x41ce(%rip), %rdi      # 0x6fd0
leaq 0x221f(%rip), %rsi      # 0x5028
movl $0x27, %edx
callq 0x22f0
movq 0x41b6(%rip), %rdi      # 0x6fd0
callq 0x2120
xorl %edi, %edi
callq 0x2310
leaq 0x2256(%rip), %rdi      # 0x5083
callq 0x2170
leaq 0x224a(%rip), %rdi      # 0x5083
callq 0x2360
leaq 0x223e(%rip), %rdi      # 0x5083
callq 0x2170
leaq 0x2232(%rip), %rdi      # 0x5083
callq 0x2360
leaq 0x2226(%rip), %rdi      # 0x5083
callq 0x2170
leaq 0x221a(%rip), %rdi      # 0x5083
callq 0x2360
leaq 0x2213(%rip), %rdi      # 0x5088
callq 0x2170
jmp 0x2f16
jmp 0x2f16
jmp 0x2f16
jmp 0x2e8f
jmp 0x2e8f
jmp 0x2e8f
movq %rax, %r14
jmp 0x2fb1
movq %rax, %r14
cmpl $0x0, (%rbx)
jne 0x2ebb
movl %ebp, (%rbx)
jmp 0x2ebb
movq %rax, %r14
cmpl $0x0, (%rbx)
jne 0x2ebb
movl %r12d, (%rbx)
jmp 0x2ebb
movq %rax, %r14
cmpl $0x0, (%rbx)
jne 0x2ebb
movl %r13d, (%rbx)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
jmp 0x2eda
movq %rax, %r14
cmpl $0x0, (%rbx)
jne 0x2ed1
movl %ebp, (%rbx)
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2fb1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2290
jmp 0x2fb1
movq %rax, %r14
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x2f59
movq 0x88(%rsp), %rsi
jmp 0x2f4a
jmp 0x2f56
movq %rax, %r14
jmp 0x2fa7
movq %rax, %r14
jmp 0x2f9a
movq %rax, %r14
jmp 0x2f75
jmp 0x2f56
movq %rax, %r14
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x2f59
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2290
jmp 0x2f59
jmp 0x2f56
movq %rax, %r14
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x2f75
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2290
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x2f9a
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x2290
leaq 0x100(%rsp), %rdi
callq 0x3a5c
leaq 0x8(%rsp), %rdi
callq 0x30cc
movq %r14, %rdi
callq 0x23c0
nop