// File: travisdowns[P]avx-turbo/test/../util.hpp
// Function: std::iterator_traits<__gnu_cxx::__normal_iterator<std::pair<int, int> const*, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>>>::value_type concurrency<__gnu_cxx::__normal_iterator<std::pair<int, int> const*, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>>>(__gnu_cxx::__normal_iterator<std::pair<int, int> const*, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>>, __gnu_cxx::__normal_iterator<std::pair<int, int> const*, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>>)
static inline auto concurrency(Itr start, Itr stop) -> typename std::iterator_traits<Itr>::value_type {
    if (start == stop) {
        return {0, 0}; // early out for empty range simplifies some logic below
    }

    using T1 = decltype(concurrency(start, stop).first);

    struct event {
        T1 stamp;
        enum Type { START, STOP } type;
        event(T1 stamp, Type type) : stamp{stamp}, type{type} {}
    };

    std::vector<event> events;
    events.reserve(std::distance(start, stop));
    T1 sum_top{}, sum_bottom{};
    for (Itr i = start; i != stop; i++) {
        sum_top += i->second - i->first;
        events.emplace_back(i->first, event::START);
        events.emplace_back(i->second,event::STOP);
    }

    std::sort(events.begin(), events.end(), [](event l, event r){ return l.stamp < r.stamp; });

    size_t count = 0;
    const event* last_event = nullptr;
    for (auto& event : events) {
        assert(count > 0 || event.type == event::START);
        if (count != 0) {
            assert(last_event);
            T1 period = event.stamp - last_event->stamp;
            // active interval, accumulate the numerator and denominators
            sum_bottom += period;
        }
        last_event = &event;
        count += event.type == event::START ? 1 : -1;
    }

    assert(count == 0);

    return {sum_top, sum_bottom};
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x27230
testb $0x1, %al
jne 0x15536
jmp 0x1555a
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
leaq -0x8(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
leaq -0x20(%rbp), %rdx
callq 0x25680
jmp 0x15864
leaq -0x38(%rbp), %rdi
callq 0x1cc00
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x27270
movq %rax, -0xd0(%rbp)
jmp 0x15589
movq -0xd0(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x1cc20
jmp 0x1559b
movl $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x272b0
testb $0x1, %al
jne 0x155c7
jmp 0x15679
leaq -0x68(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x272f0
movq -0xd8(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, -0xdc(%rbp)
callq 0x272f0
movl -0xdc(%rbp), %ecx
movq -0xd8(%rbp), %rdi
movl (%rax), %eax
subl %eax, %ecx
movl -0x58(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x58(%rbp)
callq 0x272f0
movq %rax, %rsi
movl $0x0, -0x6c(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x6c(%rbp), %rdx
callq 0x1cd20
jmp 0x15623
leaq -0x68(%rbp), %rdi
callq 0x272f0
movq %rax, %rsi
addq $0x4, %rsi
movl $0x1, -0x70(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x1cd20
jmp 0x15649
jmp 0x1564b
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
callq 0x27310
movq %rax, -0x78(%rbp)
jmp 0x155b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x1cec0
jmp 0x15871
leaq -0x38(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x1cde0
movq -0xe8(%rbp), %rdi
movq %rax, -0x80(%rbp)
callq 0x1ce10
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x1cda0
jmp 0x156b2
movq $0x0, -0x98(%rbp)
movq $0x0, -0xa0(%rbp)
leaq -0x38(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x1cde0
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x1ce10
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x1ce40
testb $0x1, %al
jne 0x15715
jmp 0x1581d
leaq -0xb0(%rbp), %rdi
callq 0x1ce80
movq %rax, -0xc0(%rbp)
movb $0x1, %al
cmpq $0x0, -0x98(%rbp)
movb %al, -0xe9(%rbp)
ja 0x1574e
movq -0xc0(%rbp), %rax
cmpl $0x0, 0x4(%rax)
sete %al
movb %al, -0xe9(%rbp)
movb -0xe9(%rbp), %al
testb $0x1, %al
jne 0x1575a
jmp 0x1575c
jmp 0x1577b
leaq 0xcc1a7(%rip), %rdi     # 0xe190a
leaq 0xcc1c8(%rip), %rsi     # 0xe1932
movl $0x55, %edx
leaq 0xcc1cd(%rip), %rcx     # 0xe1943
callq 0x13480
cmpq $0x0, -0x98(%rbp)
je 0x157d4
cmpq $0x0, -0xa0(%rbp)
je 0x15791
jmp 0x157b0
leaq 0xcc254(%rip), %rdi     # 0xe19ec
leaq 0xcc193(%rip), %rsi     # 0xe1932
movl $0x57, %edx
leaq 0xcc198(%rip), %rcx     # 0xe1943
callq 0x13480
movq -0xc0(%rbp), %rax
movl (%rax), %eax
movq -0xa0(%rbp), %rcx
subl (%rcx), %eax
movl %eax, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xc0(%rbp), %rax
movl 0x4(%rax), %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
cltq
addq -0x98(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x1cea0
jmp 0x156f9
cmpq $0x0, -0x98(%rbp)
jne 0x15829
jmp 0x15848
leaq 0xcc2a4(%rip), %rdi     # 0xe1ad4
leaq 0xcc0fb(%rip), %rsi     # 0xe1932
movl $0x60, %edx
leaq 0xcc100(%rip), %rcx     # 0xe1943
callq 0x13480
leaq -0x8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
leaq -0x5c(%rbp), %rdx
callq 0x27350
jmp 0x1585b
leaq -0x38(%rbp), %rdi
callq 0x1cec0
movq -0x8(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x13bf0
nopw (%rax,%rax)