// File: /workspace/github_cpp_makefile_star2_O3/lemire[P]runningmaxmin/./runningmaxmin.h
// Function: lemirebitmapmaxmin::lemirebitmapmaxmin(std::vector<double, std::allocator<double>>&, unsigned int)
lemirebitmapmaxmin(std::vector<floattype> & array, const uint width)
        : maxvalues(array.size() - width + 1),
          minvalues(array.size() - width + 1) {
        assert(width <= sizeof(unsigned long) * 8);
        unsigned long maxfifo = 0;
        unsigned long minfifo = 0;
        for (uint i = 1; i < width; ++i) {
            if (array[i] > array[i - 1]) { // overshoot
                minfifo |= 1;
                minfifo <<= 1;
                maxfifo <<= 1;
                while (maxfifo != 0) {
                    const long t = maxfifo & -maxfifo;
                    const int bitpos = __builtin_popcountl(t - 1);
                    if (array[i] <= array[i - bitpos]) {
                        break;
                    }
                    maxfifo ^= t;
                }
            } else {
                maxfifo |= 1;
                minfifo <<= 1;
                maxfifo <<= 1;
                while (minfifo != 0) {
                    const long t = minfifo & -minfifo;
                    const int bitpos = __builtin_popcountl(t - 1);
                    if (array[i] >= array[i - bitpos]) {
                        break;
                    }
                    minfifo ^= t;
                }
            }
        }
        unsigned long mask = ~0l;
        if (width < sizeof(unsigned long) * 8) {
            mask = (1UL << width) - 1;
        }
        for (uint i = width; i < array.size(); ++i) {
            maxfifo &= mask;
            minfifo &= mask;
            if (maxfifo == 0)
                maxvalues[i - width] = array[i - 1];
            else {
                maxvalues[i - width] = array[i - (sizeof(unsigned long) * 8 -
                                                  __builtin_clzl(maxfifo))];
            }
            if (minfifo == 0)
                minvalues[i - width] = array[i - 1];
            else {
                minvalues[i - width] = array[i - (sizeof(unsigned long) * 8 -
                                                  __builtin_clzl(minfifo))];
            }
            if (array[i] > array[i - 1]) { // overshoot
                minfifo |= 1;
                minfifo <<= 1;
                maxfifo <<= 1;
                while (maxfifo != 0) {
                    const long t = maxfifo & -maxfifo;
                    const int bitpos = __builtin_popcountl(t - 1);
                    if (array[i] <= array[i - bitpos]) {
                        break;
                    }
                    maxfifo ^= t;
                }
            } else {
                maxfifo |= 1;
                maxfifo <<= 1;
                minfifo <<= 1;
                while (minfifo != 0) {
                    const long t = minfifo & -minfifo;
                    const int bitpos = __builtin_popcountl(t - 1);
                    if (array[i] >= array[i - bitpos]) {
                        break;
                    }
                    minfifo ^= t;
                }
            }
        }
        maxfifo = maxfifo & mask;
        minfifo = minfifo & mask;
        if (maxfifo == 0)
            maxvalues[array.size() - width] = array[array.size() - 1];
        else
            maxvalues[array.size() - width] =
                array[array.size() -
                      (sizeof(unsigned long) * 8 - __builtin_clzl(maxfifo))];
        if (minfifo == 0)
            minvalues[array.size() - width] = array[array.size() - 1];
        else
            minvalues[array.size() - width] =
                array[array.size() -
                      (sizeof(unsigned long) * 8 - __builtin_clzl(minfifo))];
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x5de5(%rip), %rax      # 0xad28
addq $0x10, %rax
movq %rax, (%rdi)
leaq 0x8(%rdi), %r14
movq 0x8(%rsi), %rsi
subq (%r12), %rsi
sarq $0x3, %rsi
movl %edx, %r15d
subq %r15, %rsi
incq %rsi
leaq 0x7(%rsp), %rdx
movq %r14, %rdi
callq 0x56be
movq 0x8(%r12), %rsi
subq (%r12), %rsi
addq $0x20, %rbx
sarq $0x3, %rsi
subq %r15, %rsi
incq %rsi
leaq 0x6(%rsp), %rdx
movq %rbx, %rdi
callq 0x56be
cmpl $0x40, %ebp
ja 0x520c
movq (%r12), %rax
cmpl $0x2, %ebp
jb 0x5049
vmovsd (%rax), %xmm0
movl $0x1, %ecx
xorl %esi, %esi
xorl %edx, %edx
vmovapd %xmm0, %xmm1
vmovsd (%rax,%rcx,8), %xmm0
addq %rdx, %rdx
vucomisd %xmm1, %xmm0
jbe 0x5001
orq $0x2, %rdx
addq %rsi, %rsi
movq %rsi, %rdi
testq %rdi, %rdi
je 0x5035
movq %rdi, %rsi
negq %rdi
andq %rsi, %rdi
leaq -0x1(%rdi), %r8
popcntq %r8, %r8
movl %ecx, %r9d
subl %r8d, %r9d
vmovsd (%rax,%r9,8), %xmm1
xorq %rsi, %rdi
vucomisd %xmm0, %xmm1
jb 0x4fd3
jmp 0x503b
addq %rsi, %rsi
orq $0x2, %rsi
testq %rdx, %rdx
je 0x5039
movq %rdx, %rdi
negq %rdx
andq %rdi, %rdx
leaq -0x1(%rdx), %r8
popcntq %r8, %r8
movl %ecx, %r9d
subl %r8d, %r9d
xorq %rdi, %rdx
vucomisd (%rax,%r9,8), %xmm0
jb 0x5008
movq %rdi, %rdx
jmp 0x503b
xorl %esi, %esi
jmp 0x503b
xorl %edx, %edx
incq %rcx
cmpq %r15, %rcx
jne 0x4fb7
jmp 0x504d
xorl %edx, %edx
xorl %esi, %esi
movq $-0x1, %r8
movl %r15d, %ecx
shlq %cl, %r8
movq $-0x1, %rcx
cmpl $0x40, %ebp
notq %r8
cmoveq %rcx, %r8
movq 0x8(%r12), %rdi
subq %rax, %rdi
movq %rdi, %r9
sarq $0x3, %r9
movq %r9, %rcx
subq %r15, %rcx
movq %rbx, 0x10(%rsp)
movq %r14, 0x8(%rsp)
jbe 0x5196
movq (%r14), %r10
movq (%rbx), %r11
movl %ebp, %r12d
andq %r8, %rsi
bsrq %rsi, %r14
notl %r14d
shll $0x3, %r14d
orq $-0x200, %r14           # imm = 0xFE00
addq %rax, %r14
leal -0x1(%r12), %r13d
testq %rsi, %rsi
leaq (%r14,%r15,8), %r14
leaq (%rax,%r13,8), %rbx
cmovneq %r14, %rbx
movl %r12d, %r14d
subl %ebp, %r14d
vmovsd (%rbx), %xmm0
vmovsd %xmm0, (%r10,%r14,8)
andq %r8, %rdx
je 0x50f5
bsrq %rdx, %rbx
notl %ebx
shll $0x3, %ebx
orq $-0x200, %rbx           # imm = 0xFE00
addq %rax, %rbx
vmovsd (%rbx,%r15,8), %xmm0
jmp 0x50fb
vmovsd (%rax,%r13,8), %xmm0
vmovsd %xmm0, (%r11,%r14,8)
vmovsd (%rax,%r15,8), %xmm0
vucomisd (%rax,%r13,8), %xmm0
jbe 0x514a
addq %rdx, %rdx
orq $0x2, %rdx
addq %rsi, %rsi
movq %rsi, %r14
testq %r14, %r14
je 0x5181
movq %r14, %rsi
negq %r14
andq %rsi, %r14
leaq -0x1(%r14), %rbx
popcntq %rbx, %rbx
movl %r12d, %r15d
subl %ebx, %r15d
vmovsd (%rax,%r15,8), %xmm1
xorq %rsi, %r14
vucomisd %xmm0, %xmm1
jb 0x511c
jmp 0x5187
addq %rsi, %rsi
orq $0x2, %rsi
addq %rdx, %rdx
movq %rdx, %r14
testq %r14, %r14
je 0x5185
movq %r14, %rdx
negq %r14
andq %rdx, %r14
leaq -0x1(%r14), %rbx
popcntq %rbx, %rbx
movl %r12d, %r15d
subl %ebx, %r15d
xorq %rdx, %r14
vucomisd (%rax,%r15,8), %xmm0
jb 0x5157
jmp 0x5187
xorl %esi, %esi
jmp 0x5187
xorl %edx, %edx
incl %r12d
movq %r12, %r15
cmpq %r12, %r9
ja 0x5099
andq %r8, %rsi
andq %r8, %rdx
bsrq %rsi, %r8
notl %r8d
shll $0x3, %r8d
movq $-0x200, %r9            # imm = 0xFE00
orq %r9, %r8
leaq (%rax,%rdi), %r10
addq %r10, %r8
testq %rsi, %rsi
leaq -0x8(%rax,%rdi), %rax
cmoveq %rax, %r8
vmovsd (%r8), %xmm0
movq 0x8(%rsp), %rsi
movq (%rsi), %rsi
bsrq %rdx, %rdi
notl %edi
shll $0x3, %edi
orq %r9, %rdi
addq %r10, %rdi
testq %rdx, %rdx
cmoveq %rax, %rdi
vmovsd %xmm0, (%rsi,%rcx,8)
vmovsd (%rdi), %xmm0
movq 0x10(%rsp), %rax
movq (%rax), %rax
vmovsd %xmm0, (%rax,%rcx,8)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x300e(%rip), %rdi      # 0x8221
leaq 0x2f7a(%rip), %rsi      # 0x8194
leaq 0x3023(%rip), %rcx      # 0x8244
movl $0x1d6, %edx            # imm = 0x1D6
callq 0x20a0
movq %rax, %rbx
movq (%r14), %rdi
testq %rdi, %rdi
je 0x523b
callq 0x20e0
movq %rbx, %rdi
callq 0x2190
nop