// File: /workspace/github_cpp_makefile_star2_O3/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 0x29fa
movq %rsi, %r15
movq 0x8(%rsi), %rsi
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x2f8a
movq 0x8(%rsp), %r12
callq 0x2050
movq %rax, %rbx
movl (%rax), %ebp
movl $0x0, (%rax)
leaq 0xb8(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
movl $0xa, %edx
callq 0x2350
cmpq %r12, (%r13)
je 0x2e15
movslq %eax, %rcx
movq %rax, 0x40(%rsp)
cmpq %rax, %rcx
jne 0x2e21
movl (%rbx), %eax
cmpl $0x22, %eax
je 0x2e21
testl %eax, %eax
jne 0x2865
movl %ebp, (%rbx)
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2880
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2290
movq 0x10(%r15), %rsi
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x2f8a
movq 0x8(%rsp), %r12
movl (%rbx), %ebp
movl $0x0, (%rbx)
leaq 0xb8(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
movl $0xa, %edx
callq 0x2350
cmpq %r12, (%r13)
je 0x2e2d
movabsq $-0x100000000, %r14     # imm = 0xFFFFFFFF00000000
leaq -0x80000000(%rax), %rcx
cmpq %r14, %rcx
jb 0x2e39
movq %rax, %r12
movl (%rbx), %eax
cmpl $0x22, %eax
je 0x2e39
testl %eax, %eax
jne 0x28f0
movl %ebp, (%rbx)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x290c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2290
movq %r12, 0xf8(%rsp)
movq 0x18(%r15), %rsi
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x2f8a
movq 0x8(%rsp), %r12
movl (%rbx), %ebp
movl $0x0, (%rbx)
leaq 0xb8(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
movl $0xa, %edx
callq 0x2350
cmpq %r12, (%r13)
je 0x2e45
leaq -0x80000000(%rax), %rcx
cmpq %r14, %rcx
jb 0x2e51
movq %rax, %r14
movl (%rbx), %eax
cmpl $0x22, %eax
je 0x2e51
testl %eax, %eax
jne 0x297a
movl %ebp, (%rbx)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2996
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2290
movq 0x20(%r15), %rsi
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x2f8a
movq %r14, 0x70(%rsp)
movq 0x8(%rsp), %r15
movl (%rbx), %ebp
movl $0x0, (%rbx)
leaq 0xb8(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x21e0
cmpq %r15, (%r12)
je 0x2e5d
movl (%rbx), %eax
testl %eax, %eax
movq 0x40(%rsp), %r13
movsd %xmm0, 0x38(%rsp)
je 0x2a1c
cmpl $0x22, %eax
jne 0x2a1e
leaq 0x2693(%rip), %rdi      # 0x5088
callq 0x2360
movq 0x45cf(%rip), %rdi      # 0x6fd0
leaq 0x2608(%rip), %rsi      # 0x5010
movl $0x17, %edx
callq 0x22f0
movl $0x1, %eax
jmp 0x2dd8
movl %ebp, (%rbx)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2a3a
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 0x2fc8
movl $0x1a0a, (%rax)         # imm = 0x1A0A
leaq 0xb8(%rsp), %rsi
movl $0x1, (%rsi)
leaq 0x8(%rsp), %rdi
callq 0x2fc8
movq %rbx, %r12
movl $0x1a0b, (%rax)         # imm = 0x1A0B
leaq 0xb8(%rsp), %rsi
movl $0x2, (%rsi)
leaq 0x8(%rsp), %rdi
callq 0x2fc8
movl $0x1a0c, (%rax)         # imm = 0x1A0C
cvttsd2si 0x38(%rsp), %eax
movl %eax, 0x4c(%rsp)
testl %eax, %eax
jle 0x2dcc
movq 0x70(%rsp), %rcx
movl %ecx, %eax
imulq $0x10624dd3, %rax, %rax # imm = 0x10624DD3
shrq $0x26, %rax
movq %rax, 0xf0(%rsp)
imulq $-0x3e8, %rax, %rax     # imm = 0xFC18
addq %rcx, %rax
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
movq %rax, 0xe8(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movl $0x3, %ebx
leaq 0x100(%rsp), %r14
leaq 0x108(%rsp), %rbp
callq 0x2340
movq %r14, %rdi
movq %rax, 0x40(%rsp)
callq 0x35e8
leaq 0xb8(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
movl %r13d, %edx
movl $0x4cf, %ecx            # imm = 0x4CF
callq 0x3bf4
leaq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0x3e90
xorl %edi, %edi
callq 0x2230
movl %eax, %edi
callq 0x2250
testl %ebx, %ebx
je 0x2dea
callq 0x2090
cltd
idivl %ebx
movl %edx, 0x4(%rsp)
movl $0x10, %edx
movq 0x4459(%rip), %rdi      # 0x6fd0
leaq 0x24d2(%rip), %rsi      # 0x5050
callq 0x22f0
movq 0x4446(%rip), %rdi      # 0x6fd0
movl %r13d, %esi
callq 0x23b0
movq %rax, %r15
movl $0xb, %edx
movq %rax, %rdi
leaq 0x24bd(%rip), %rsi      # 0x5061
callq 0x22f0
movl 0x4(%rsp), %esi
movq %r15, %rdi
callq 0x23b0
movl $0xb, %edx
movq 0x440f(%rip), %rdi      # 0x6fd0
leaq 0x24a5(%rip), %rsi      # 0x506d
callq 0x22f0
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x43f2(%rip), %rdi      # 0x6fd0
callq 0x22f0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2260
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
leaq 0xa8(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0x98(%rsp), %rdi
leaq 0x244d(%rip), %rsi      # 0x5079
leaq 0x244f(%rip), %rdx      # 0x5082
callq 0x3184
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x302e
movl (%rax), %edx
movq %r14, %rdi
leaq 0x98(%rsp), %rsi
callq 0x35f6
movl %eax, %r15d
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x2c81
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2290
testl %r15d, %r15d
js 0x2d55
leaq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x30ee
movq %r14, %rdi
leaq 0x78(%rsp), %rsi
callq 0x377e
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x2cdd
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2290
movq %r14, %rdi
callq 0x3a38
cmpq $0x0, 0x70(%rsp)
jle 0x2d24
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 0x2d24
cmpl $0x4, (%r12)
je 0x2d0d
addl 0xf8(%rsp), %r13d
callq 0x2340
subq 0x40(%rsp), %rax
cvtsi2sd %rax, %xmm0
divsd 0x22c5(%rip), %xmm0     # 0x5008
movsd 0x38(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
jmp 0x2d73
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x34c4
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x3542
decl %ebx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x2d8f
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2290
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x2db4
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x2290
movq %r14, %rdi
callq 0x3a40
cvttsd2si 0x38(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jl 0x2b10
leaq 0x8(%rsp), %rdi
callq 0x309e
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x41df(%rip), %rdi      # 0x6fd0
leaq 0x2230(%rip), %rsi      # 0x5028
movl $0x27, %edx
callq 0x22f0
movq 0x41c7(%rip), %rdi      # 0x6fd0
callq 0x2120
xorl %edi, %edi
callq 0x2310
leaq 0x2267(%rip), %rdi      # 0x5083
callq 0x2170
leaq 0x225b(%rip), %rdi      # 0x5083
callq 0x2360
leaq 0x224f(%rip), %rdi      # 0x5083
callq 0x2170
leaq 0x2243(%rip), %rdi      # 0x5083
callq 0x2360
leaq 0x2237(%rip), %rdi      # 0x5083
callq 0x2170
leaq 0x222b(%rip), %rdi      # 0x5083
callq 0x2360
leaq 0x2224(%rip), %rdi      # 0x5088
callq 0x2170
jmp 0x2ee6
jmp 0x2ee6
jmp 0x2ee6
jmp 0x2e75
jmp 0x2e75
jmp 0x2e75
movq %rax, %r14
jmp 0x2f81
jmp 0x2e81
jmp 0x2e81
movq %rax, %r14
cmpl $0x0, (%rbx)
jne 0x2e8b
movl %ebp, (%rbx)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
jmp 0x2eaa
movq %rax, %r14
cmpl $0x0, (%rbx)
jne 0x2ea1
movl %ebp, (%rbx)
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f81
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2290
jmp 0x2f81
movq %rax, %r14
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x2f29
movq 0x88(%rsp), %rsi
jmp 0x2f1a
jmp 0x2f26
movq %rax, %r14
jmp 0x2f77
movq %rax, %r14
jmp 0x2f6a
movq %rax, %r14
jmp 0x2f45
jmp 0x2f26
movq %rax, %r14
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x2f29
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2290
jmp 0x2f29
jmp 0x2f26
movq %rax, %r14
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x2f45
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2290
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x2f6a
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x2290
leaq 0x100(%rsp), %rdi
callq 0x3a40
leaq 0x8(%rsp), %rdi
callq 0x309e
movq %r14, %rdi
callq 0x23c0
nop