// File: /workspace/github_c_makefile_star2_O1/KhuramAli[P]JAM-Benchmark/lock_and_lockfree/code13.cpp
// Function: main
int main(int argc, char** argv)
    {
    
      if (argc < 5)
        return -1;
      int numthreads = atoi(argv[1]);
      count = atol(argv[2]);
      int factor = atoi(argv[3]);
      int type = atoi(argv[4]);
      int readerCount = 0;
      int writerCount = 0;
      double ticStart;
    
      jobs Jobs [] = {
        JOB(unlocked,               unlocked_read),
        JOB(mutex,                  mutex_read),
        JOB(rwlock,                 rwlock_read_wr),
        JOB(rwlock,                 rwlock_read_rd),
        JOB(atomic,                 atomic_read),
        JOB(atomic_set_release,     atomic_read_consume),
        JOB(atomic_set_release,     atomic_read_acquire),
        JOB(atomic_set_cst,         atomic_read_consume),
        JOB(atomic_set_cst,         atomic_read_acquire),
        JOB(atomic_set_relaxed,     atomic_read_consume),
        JOB(atomic_set_relaxed,     atomic_read_acquire),
        JOB(atomic_weak,            atomic_read_consume),
        JOB(atomic_weak,            atomic_read_acquire)
      };
    
    #ifdef WIN32
    InitializeSRWLock(&srwlock);
    #endif
    
      atomic_uint = 1;
      if (type >= sizeof(Jobs)/sizeof(jobs)) {
        std::cout << "type not supported.\n";
        exit(1);
      }
    
      for (int i = 0; i < numthreads; i++) {
        if (i % factor == 0) {
          writerCount ++;
          threads.push_back(std::thread(Jobs[type].Write));
        }
        else {
          readerCount ++;
          threads.push_back(std::thread(Jobs[type].Read));
        }
      }
    
      ready = true;
      ticStart = TRI_microtime();
      halt.notify_all();
    
      for (int i = 0; i < numthreads; i++) {
        threads[i].join();
      }
      std::cout
        << "Threads: "
        << numthreads
        <<" count:   "
        << count
        << " Readers: "
        << readerCount
        << " Writers: "
        << writerCount
        << " atomic_uint is now: " 
        << atomic_uint
        << " flat_uint is now: "
        << flat_uint
        << " Test: "
        << Jobs[type].ReadStr
        << " + "
        << Jobs[type].WriteStr
        << " test Duration: "
        << (float) (TRI_microtime() - ticStart)
        << "\n";
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $0x5, %edi
jl 0x30a0
movq %rsi, %r12
movq 0x8(%rsi), %rdi
callq 0x21f0
movl %eax, %ebx
movq 0x10(%r12), %rdi
callq 0x2180
movq %rax, 0x349a(%rip)      # 0x61d0
movq 0x18(%r12), %rdi
callq 0x21f0
movl %eax, %r15d
movq 0x20(%r12), %rdi
callq 0x21f0
movl %eax, %ebp
leaq 0x2e7a(%rip), %rsi      # 0x5bd0
leaq 0x30(%rsp), %rdi
movl $0x1a0, %edx            # imm = 0x1A0
callq 0x20f0
movl $0x1, %eax
xchgq %rax, 0x3457(%rip)      # 0x61c8
cmpl $0xc, %ebp
ja 0x30b5
movslq %ebp, %rax
testl %ebx, %ebx
movq %rax, 0x28(%rsp)
jle 0x2e1c
shlq $0x5, %rax
leaq (%rsp,%rax), %r12
addq $0x40, %r12
addq %rsp, %rax
addq $0x30, %rax
movq %rax, (%rsp)
xorl %r13d, %r13d
leaq 0x10(%rsp), %rbp
movl $0x0, 0xc(%rsp)
xorl %r14d, %r14d
movl %r13d, %eax
cltd
idivl %r15d
movq %rbp, %rdi
testl %edx, %edx
je 0x2dea
movq %r12, %rsi
callq 0x3134
leaq 0x3467(%rip), %rdi      # 0x6238
movq %rbp, %rsi
callq 0x3236
cmpq $0x0, 0x10(%rsp)
jne 0x30e4
incl %r14d
jmp 0x2e12
movq (%rsp), %rsi
callq 0x3134
leaq 0x343e(%rip), %rdi      # 0x6238
movq %rbp, %rsi
callq 0x3236
cmpq $0x0, 0x10(%rsp)
jne 0x30e4
incl 0xc(%rsp)
incl %r13d
cmpl %r13d, %ebx
jne 0x2db4
jmp 0x2e27
xorl %r14d, %r14d
movl $0x0, 0xc(%rsp)
movb $0x1, 0x3402(%rip)      # 0x6230
leaq 0x10(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x2210
cvtsi2sdq (%r15), %xmm0
movsd %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdq 0x8(%r15), %xmm0
movsd %xmm0, (%rsp)
leaq 0x33a3(%rip), %rdi      # 0x6200
callq 0x2230
testl %ebx, %ebx
jle 0x2e88
movl %ebx, %r15d
shlq $0x3, %r15
xorl %r12d, %r12d
movq 0x33c1(%rip), %rdi      # 0x6238
addq %r12, %rdi
callq 0x2240
addq $0x8, %r12
cmpq %r12, %r15
jne 0x2e70
movsd (%rsp), %xmm0
divsd 0x1173(%rip), %xmm0     # 0x4008
movsd %xmm0, (%rsp)
movq 0x312f(%rip), %r15      # 0x5fd0
leaq 0x1277(%rip), %rsi      # 0x411f
movl $0x9, %edx
movq %r15, %rdi
callq 0x2170
movq %r15, %rdi
movl %ebx, %esi
callq 0x2250
movq %rax, %rbx
leaq 0x1260(%rip), %rsi      # 0x4129
movl $0xa, %edx
movq %rax, %rdi
callq 0x2170
movq 0x32f3(%rip), %rsi      # 0x61d0
movq %rbx, %rdi
callq 0x2140
movq %rax, %rbx
leaq 0x1245(%rip), %rsi      # 0x4134
movl $0xa, %edx
movq %rax, %rdi
callq 0x2170
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2250
movq %rax, %rbx
leaq 0x122e(%rip), %rsi      # 0x413f
movl $0xa, %edx
movq %rax, %rdi
callq 0x2170
movq %rbx, %rdi
movl 0xc(%rsp), %esi
callq 0x2250
movq %rax, %rbx
leaq 0x1216(%rip), %rsi      # 0x414a
movl $0x15, %edx
movq %rax, %rdi
callq 0x2170
movq 0x3280(%rip), %rsi      # 0x61c8
movq %rbx, %rdi
callq 0x20c0
movq %rax, %rbx
leaq 0x1206(%rip), %rsi      # 0x4160
movl $0x13, %edx
movq %rax, %rdi
callq 0x2170
movq 0x31da(%rip), %rsi      # 0x6148
movq %rbx, %rdi
callq 0x20c0
movq %rax, %rbx
leaq 0x11f4(%rip), %rsi      # 0x4174
movl $0x7, %edx
movq %rax, %rdi
callq 0x2170
movq 0x28(%rsp), %rax
shlq $0x5, %rax
leaq (%rsp,%rax), %r15
addq $0x30, %r15
movq 0x18(%r15), %r14
testq %r14, %r14
je 0x2fbf
movq %r14, %rdi
callq 0x2080
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2170
jmp 0x2fd6
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2220
movsd (%rsp), %xmm0
addsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rsp)
leaq 0x118f(%rip), %rsi      # 0x417c
movl $0x3, %edx
movq %rbx, %rdi
callq 0x2170
movq 0x8(%r15), %r14
testq %r14, %r14
je 0x301b
movq %r14, %rdi
callq 0x2080
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2170
jmp 0x3034
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq %rbx, %rdi
addq %rax, %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2220
leaq 0x1145(%rip), %rsi      # 0x4180
movl $0x10, %edx
movq %rbx, %rdi
callq 0x2170
xorl %r14d, %r14d
leaq 0x10(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x2210
xorps %xmm0, %xmm0
cvtsi2sdq (%r15), %xmm0
cvtsi2sdq 0x8(%r15), %xmm1
divsd 0xf98(%rip), %xmm1      # 0x4008
addsd %xmm0, %xmm1
subsd (%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movq %rbx, %rdi
callq 0x2200
leaq 0x108a(%rip), %rsi      # 0x411d
movl $0x1, %edx
movq %rax, %rdi
callq 0x2170
movl %r14d, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2f14(%rip), %rdi      # 0x5fd0
leaq 0x1047(%rip), %rsi      # 0x410a
callq 0x2150
movl $0x1, %edi
callq 0x2190
jmp 0x30d4
cmpq $0x0, 0x10(%rsp)
jne 0x30e4
movq %rax, %rdi
callq 0x2260
callq 0x2040
nop