// File: Kobzol[P]sigmod-2016/src/job.h
// Function: JobQueue::add_job(JobType, unsigned int, unsigned int)
void add_job(JobType type, sigint from, sigint to)
    {
        std::unique_lock<std::mutex> guard(this->lock);

#ifdef THREAD_USE_JOB_SYNC
        while (this->size >= this->jobs.capacity)
        {
            this->bufferFull.wait(guard);
        }
#endif

        Barrier* barrier = this->barrier;
        Barrier* modifyBarrier = barrier;
        bool allocated = false;

        if (type != JobType::Query || this->barrier->modification)
        {
            Barrier* newBarrier = &BarrierMemory[BarrierIndex++];
            assert(BarrierIndex < BARRIER_BUFFER_COUNT);
            newBarrier->modification = type != JobType::Query;
            newBarrier->waiting = 1;
            modifyBarrier = newBarrier;
            this->barrier = modifyBarrier;
        }
        else if (!this->barrier->modification)
        {
            barrier->push();
        }

        this->jobs[this->end] = Job(type, from, to, barrier, modifyBarrier, allocated);
        this->end = (this->end + 1) % this->jobs.size;

        this->size++;

#ifdef THREAD_USE_JOB_SYNC
        this->bufferEmpty.notify_one();
#endif

        assert(this->size <= this->jobs.capacity);
    }

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movl %esi, 0x8c(%rsp)
movl %edx, 0x88(%rsp)
movl %ecx, 0x84(%rsp)
movq 0x90(%rsp), %rsi
movq %rsi, 0x8(%rsp)
addq $0xb0, %rsi
leaq 0x70(%rsp), %rdi
callq 0x5e40
movq 0x8(%rsp), %rcx
movq 0x98(%rcx), %rax
cmpq 0xe0(%rcx), %rax
jb 0x608f
movq 0x8(%rsp), %rdi
addq $0x130, %rdi            # imm = 0x130
leaq 0x70(%rsp), %rsi
callq 0x2080
jmp 0x6062
movq 0x8(%rsp), %rax
movq 0xf0(%rax), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x60(%rsp)
movb $0x0, 0x5f(%rsp)
cmpl $0x0, 0x8c(%rsp)
jne 0x60ce
movq 0x8(%rsp), %rax
movq 0xf0(%rax), %rax
testb $0x1, (%rax)
je 0x6163
movq 0x31850b(%rip), %rcx    # 0x31e5e0
movq %rcx, %rax
addq $0x1, %rax
movq %rax, 0x3184fd(%rip)    # 0x31e5e0
leaq 0xb0f6(%rip), %rax      # 0x111e0
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
cmpq $0x30d40, 0x3184df(%rip) # imm = 0x30D40
jae 0x6105
jmp 0x6124
leaq 0x4f56(%rip), %rdi      # 0xb062
leaq 0x4f73(%rip), %rsi      # 0xb086
movl $0x67, %edx
leaq 0x4f71(%rip), %rcx      # 0xb090
callq 0x2110
movq 0x8(%rsp), %rax
cmpl $0x0, 0x8c(%rsp)
setne %dl
movq 0x50(%rsp), %rcx
andb $0x1, %dl
movb %dl, (%rcx)
movq 0x50(%rsp), %rcx
movq $0x1, 0x8(%rcx)
movq 0x50(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movq 0x60(%rsp), %rcx
movq %rcx, 0xf0(%rax)
jmp 0x61a1
movq 0x8(%rsp), %rax
movq 0xf0(%rax), %rax
testb $0x1, (%rax)
jne 0x619f
movq 0x68(%rsp), %rdi
callq 0x9d70
jmp 0x6180
jmp 0x619f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x5fe0
jmp 0x628d
jmp 0x61a1
movl 0x8c(%rsp), %esi
movl 0x88(%rsp), %edx
movl 0x84(%rsp), %ecx
movq 0x68(%rsp), %r8
movq 0x60(%rsp), %r9
movzbl 0x5f(%rsp), %edi
andl $0x1, %edi
movq %rsp, %rax
movl %edi, (%rax)
leaq 0x10(%rsp), %rdi
callq 0x9d90
jmp 0x61d9
movq 0x8(%rsp), %rax
movq %rax, %rdi
addq $0xd8, %rdi
movq 0xa8(%rax), %rax
movl %eax, %esi
callq 0x6ad0
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
movl $0x29, %edx
callq 0x2190
movq 0x8(%rsp), %rdi
movq 0xa8(%rdi), %rax
addq $0x1, %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq 0xd8(%rdi)
movq %rdx, 0xa8(%rdi)
movq 0x98(%rdi), %rax
addq $0x1, %rax
movq %rax, 0x98(%rdi)
addq $0x68, %rdi
callq 0x20d0
movq 0x8(%rsp), %rcx
movq 0x98(%rcx), %rax
cmpq 0xe0(%rcx), %rax
ja 0x625c
jmp 0x627b
leaq 0x4e5d(%rip), %rdi      # 0xb0c0
leaq 0x4e1c(%rip), %rsi      # 0xb086
movl $0x7b, %edx
leaq 0x4e1a(%rip), %rcx      # 0xb090
callq 0x2110
leaq 0x70(%rsp), %rdi
callq 0x5fe0
addq $0x98, %rsp
retq
movq 0x48(%rsp), %rdi
callq 0x2310
nopw (%rax,%rax)