// File: vsklad[P]cgen/./bal/variables/variablesio.cpp
// Function: bal::get_variables_range_sequence_(unsigned int const*, unsigned long, unsigned long, unsigned long&, int&)
inline void get_variables_range_sequence_(const literalid_t* const data, const size_t size,
                                                    const size_t range_size,
                                                    size_t& sequence_size, int& sequence_step) {
        assert(size % range_size == 0); // data size is a multiple of range_size
        
        sequence_size = size > 0 ? 1 : 0;
        sequence_step = 0;
        
        if (size > range_size) {
            // assume the step from the first pair of variables from the first and second ranges
            // stop when this step is not the same at any point
            // non-zero step is only applicable to variables; it is zero for everything else
            bool b_first_variable_found = false;
            const literalid_t* p_prev = data;
            const literalid_t* p_curr = p_prev + range_size;
            
            while (p_curr < data + size) {
                bool b_sequence_step_ok = true;
                const literalid_t* p_next = p_curr + range_size;
                
                while(p_curr < p_next) {
                    if (literal_t__is_variable(*p_curr) && literal_t__is_variable(*p_prev)) {
                        if (!b_first_variable_found) {
                            sequence_step = *p_curr - *p_prev;
                            b_first_variable_found = true;
                        } else if (*p_curr - *p_prev != sequence_step) {
                            b_sequence_step_ok = false;
                            break;
                        };
                    } else if (*p_curr != *p_prev) {
                        b_sequence_step_ok = false;
                        break;
                    };
                    p_prev++;
                    p_curr++;
                };
                
                if (!b_sequence_step_ok) {
                    break;
                };
                
                sequence_size++;
                p_next += range_size;
            };
            
            // 2 between literals, 1 between variables
            sequence_step >>= 1;
        };
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x18(%rbp)
cmpq $0x0, %rdx
jne 0x59890
jmp 0x598af
leaq 0xed43(%rip), %rdi      # 0x685da
leaq 0xecd0(%rip), %rsi      # 0x6856e
movl $0x43, %edx
leaq 0xed47(%rip), %rcx      # 0x685f1
callq 0xd1c0
movq -0x10(%rbp), %rdx
xorl %eax, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmoval %ecx, %eax
movslq %eax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
cmpq -0x18(%rbp), %rax
jbe 0x59a2f
movb $0x0, -0x29(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x8(%rbp), %rcx
movq -0x10(%rbp), %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x59a25
movb $0x1, -0x41(%rbp)
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x599fa
movq -0x40(%rbp), %rcx
xorl %eax, %eax
cmpl $0x1, (%rcx)
movb %al, -0x51(%rbp)
jbe 0x5995e
movq -0x40(%rbp), %rax
cmpl $-0x2, (%rax)
setbe %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x59967
jmp 0x599c7
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpl $0x1, (%rcx)
movb %al, -0x52(%rbp)
jbe 0x59982
movq -0x38(%rbp), %rax
cmpl $-0x2, (%rax)
setbe %al
movb %al, -0x52(%rbp)
movb -0x52(%rbp), %al
testb $0x1, %al
jne 0x5998b
jmp 0x599c7
testb $0x1, -0x29(%rbp)
jne 0x599a9
movq -0x40(%rbp), %rax
movl (%rax), %ecx
movq -0x38(%rbp), %rax
subl (%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movb $0x1, -0x29(%rbp)
jmp 0x599c5
movq -0x40(%rbp), %rax
movl (%rax), %eax
movq -0x38(%rbp), %rcx
subl (%rcx), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
je 0x599c3
movb $0x0, -0x41(%rbp)
jmp 0x599fa
jmp 0x599c5
jmp 0x599dd
movq -0x40(%rbp), %rax
movl (%rax), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
je 0x599db
movb $0x0, -0x41(%rbp)
jmp 0x599fa
jmp 0x599dd
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x40(%rbp)
jmp 0x59935
testb $0x1, -0x41(%rbp)
jne 0x59a02
jmp 0x59a25
movq -0x20(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
shlq $0x2, %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x59902
movq -0x28(%rbp), %rax
movl (%rax), %ecx
sarl %ecx
movl %ecx, (%rax)
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop