// File: /workspace/github_cpp_makefile_star2_O2/vsklad[P]cgen/./bal/cnf/cnf/cnfclauses.hpp
// Function: bal::ca_insert_last_literal_sorted(unsigned short&, unsigned short&, unsigned int*)
inline void ca_insert_last_literal_sorted(uint16_t& flags, clause_size_t& literals_size, literalid_t* const literals) {
        clause_size_t index = 0;
        while (index < literals_size) {
            if (literals[literals_size] <= literals[index]) {
                break;
            };
            index++;
        };
        if (index == literals_size) {
            // new literal is the last one, nothing else to do
            literals_size++;
        } else if (literals[literals_size] == literals[index]) {
            // nothing to insert, transform flags
            switch((index << 4) | literals_size) {
                case 0x01: // l0 = l1
                    flags = (flags & 0x0001) | (flags & 0x0018) >> 2 |
                    (flags & 0x0180) >> 4 | (flags & 0x1800) >> 6 | (flags & 0x8000) >> 8;
                    break;
                case 0x02: // l0 = l2
                    flags = (flags & 0x0005) | (flags & 0x05A0) >> 4 | (flags & 0xA000) >> 8;
                    break;
                case 0x03: // l0 = l3
                    flags = (flags & 0x0055) | (flags & 0xAA00) >> 8;
                    break;
                case 0x12: // l1 = l2
                    flags = (flags & 0x0003) | (flags & 0x03C0) >> 4 | (flags & 0xC000) >> 8;
                    break;
                case 0x13: // l1 = l3
                    flags = (flags & 0x0033) | (flags & 0xCC00) >> 8;
                    break;
                case 0x23: // l2 = l3
                    flags = (flags & 0x000F) | (flags & 0xF000) >> 8;
                    break;
            };
        } else {
            // insert into index position and update flags
            switch((index << 4) | literals_size) {
                case 0x01: // l1 = l0
                    flags = (flags & 0x9999) | (flags & 0x2222) << 1 | (flags & 0x4444) >> 1; \
                    std::swap(literals[0], literals[1]);
                    break;
                case 0x02: // l2 = l0
                    flags = (flags & 0x8181) |
                    (flags & 0x0202) << 1 | (flags & 0x0404) << 2 | (flags & 0x0808) << 3 |
                    (flags & 0x1010) >> 3 | (flags & 0x2020) >> 2 | (flags & 0x4040) >> 1;
                    std::swap(literals[1], literals[2]);
                    std::swap(literals[0], literals[1]);
                    break;
                case 0x03: // l3 = l0
                    flags = (flags & 0x8001) |
                    (flags & 0x0002) << 1 | (flags & 0x0004) << 2 |
                    (flags & 0x0008) << 3 | (flags & 0x0010) << 4 |
                    (flags & 0x0020) << 5 | (flags & 0x0040) << 6 |
                    (flags & 0x0080) << 7 | (flags & 0x0100) >> 7 |
                    (flags & 0x0200) >> 6 | (flags & 0x0400) >> 5 |
                    (flags & 0x0800) >> 4 | (flags & 0x1000) >> 3 |
                    (flags & 0x2000) >> 2 | (flags & 0x4000) >> 1;
                    
                    std::swap(literals[2], literals[3]);
                    std::swap(literals[1], literals[2]);
                    std::swap(literals[0], literals[1]);
                    break;
                case 0x12: // l2 = l1
                    flags = (flags & 0xC3C3) | (flags & 0x0C0C) << 2 | (flags & 0x3030) >> 2;
                    std::swap(literals[1], literals[2]);
                    break;
                case 0x13: // l3 = l1
                    flags = (flags & 0xC003) |
                    (flags & 0x000C) << 2 | (flags & 0x0030) << 4 | (flags & 0x00C0) << 6 |
                    (flags & 0x0300) >> 6 | (flags & 0x0C00) >> 4 | (flags & 0x3000) >> 2;
                    std::swap(literals[2], literals[3]);
                    std::swap(literals[1], literals[2]);
                    break;
                case 0x23: // l3 -> l2
                    flags = (flags & 0xF00F) | (flags & 0x00F0) << 4 | (flags & 0x0F00) >> 4;
                    std::swap(literals[2], literals[3]);
                    break;
            };
            literals_size++;
        };
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
movzwl (%rsi), %ecx
xorl %eax, %eax
xorl %r8d, %r8d
cmpq %r8, %rcx
je 0x11a2c
movl (%rdx,%rcx,4), %r9d
cmpl (%rdx,%r8,4), %r9d
jbe 0x11a26
incq %r8
addl $0x10, %eax
jmp 0x11a0f
cmpw %r8w, %cx
jne 0x11a33
incl %ecx
movw %cx, (%rsi)
popq %rbp
retq
movl (%rdx,%rcx,4), %r9d
orl %ecx, %eax
cmpl (%rdx,%r8,4), %r9d
jne 0x11aa2
cmpl $0x23, %eax
je 0x11d51
cmpl $0x2, %eax
je 0x11cc6
cmpl $0x3, %eax
je 0x11b02
cmpl $0x12, %eax
je 0x11c7c
cmpl $0x13, %eax
je 0x11bf7
cmpl $0x1, %eax
jne 0x11a31
movzwl (%rdi), %eax
movl %eax, %ecx
andl $0x1, %ecx
movl %eax, %edx
shrl $0x2, %edx
andl $0x6, %edx
orl %ecx, %edx
movl %eax, %ecx
shrl $0x4, %ecx
andl $0x18, %ecx
orl %edx, %ecx
movl %eax, %edx
shrl $0x6, %edx
andl $0x60, %edx
orl %ecx, %edx
shrl $0x8, %eax
andl $-0x80, %eax
jmp 0x11cde
cmpl $0x23, %eax
je 0x11d69
cmpl $0x2, %eax
je 0x11ce2
cmpl $0x3, %eax
je 0x11b15
cmpl $0x12, %eax
je 0x11c96
cmpl $0x13, %eax
je 0x11c0a
cmpl $0x1, %eax
jne 0x11d98
movzwl (%rdi), %eax
movl %eax, %ecx
andl $0x9999, %ecx           # imm = 0x9999
movl $0x2222, %r8d           # imm = 0x2222
movl %eax, %r9d
andl %r8d, %r9d
leal (%rcx,%r9,2), %ecx
shrl %eax
andl %r8d, %eax
orl %ecx, %eax
movw %ax, (%rdi)
rolq $0x20, (%rdx)
jmp 0x11d98
movzwl (%rdi), %eax
movl %eax, %ecx
andl $0x55, %ecx
shrl $0x8, %eax
andl $-0x56, %eax
jmp 0x11d5f
movzwl (%rdi), %eax
movl %eax, %ecx
andl $0x8001, %ecx           # imm = 0x8001
movl %eax, %r8d
andl $0x2, %r8d
leal (%rcx,%r8,2), %ecx
movl %eax, %r8d
andl $0x4, %r8d
leal (%rcx,%r8,4), %ecx
movl %eax, %r8d
andl $0x8, %r8d
leal (%rcx,%r8,8), %ecx
movl %eax, %r8d
andl $0x10, %r8d
shll $0x4, %r8d
orl %ecx, %r8d
movl %eax, %r9d
andl $0x20, %r9d
shll $0x5, %r9d
orl %r8d, %r9d
movl %eax, %ecx
andl $0x40, %ecx
shll $0x6, %ecx
orl %r9d, %ecx
movl %eax, %r8d
shll $0x7, %r8d
andl $0x4000, %r8d           # imm = 0x4000
movl %eax, %r9d
shrl $0x7, %r9d
andl $0x2, %r9d
orl %r8d, %r9d
movl %eax, %r8d
shrl $0x6, %r8d
andl $0x8, %r8d
orl %r9d, %r8d
movl %eax, %r9d
shrl $0x5, %r9d
andl $0x20, %r9d
orl %r8d, %r9d
movl %eax, %r8d
shrl $0x4, %r8d
andl $0x80, %r8d
orl %r9d, %r8d
movl %eax, %r9d
shrl $0x3, %r9d
andl $0x200, %r9d            # imm = 0x200
orl %r8d, %r9d
orl %ecx, %r9d
movl %eax, %ecx
shrl $0x2, %ecx
andl $0x800, %ecx            # imm = 0x800
shrl %eax
andl $0x2000, %eax           # imm = 0x2000
orl %ecx, %eax
orl %r9d, %eax
movw %ax, (%rdi)
movl 0x8(%rdx), %eax
movl 0xc(%rdx), %ecx
movl %eax, 0xc(%rdx)
movl (%rdx), %eax
movl 0x4(%rdx), %edi
movl %edi, 0x8(%rdx)
movl %ecx, (%rdx)
jmp 0x11d4c
movzwl (%rdi), %eax
movl %eax, %ecx
andl $0x33, %ecx
shrl $0x8, %eax
andl $-0x34, %eax
jmp 0x11d5f
movzwl (%rdi), %eax
movl %eax, %ecx
andl $0xc003, %ecx           # imm = 0xC003
movl %eax, %r8d
andl $0xc, %r8d
leal (%rcx,%r8,4), %ecx
movl %eax, %r8d
andl $0x30, %r8d
shll $0x4, %r8d
orl %ecx, %r8d
movl %eax, %ecx
shll $0x6, %ecx
andl $0x3000, %ecx           # imm = 0x3000
orl %r8d, %ecx
movl %eax, %r8d
shrl $0x6, %r8d
andl $0xc, %r8d
orl %ecx, %r8d
movl %eax, %ecx
shrl $0x4, %ecx
andl $0xc0, %ecx
orl %r8d, %ecx
shrl $0x2, %eax
andl $0xc00, %eax            # imm = 0xC00
orl %ecx, %eax
movw %ax, (%rdi)
movl 0x4(%rdx), %eax
movl 0x8(%rdx), %ecx
movl 0xc(%rdx), %edi
movl %ecx, 0xc(%rdx)
movl %edi, 0x4(%rdx)
movl %eax, 0x8(%rdx)
jmp 0x11d98
movzwl (%rdi), %eax
movl %eax, %ecx
andl $0x3, %ecx
movl %eax, %edx
shrl $0x4, %edx
andl $0x3c, %edx
orl %ecx, %edx
shrl $0x8, %eax
andl $-0x40, %eax
jmp 0x11cde
movzwl (%rdi), %eax
movl %eax, %ecx
andl $0xc3c3, %ecx           # imm = 0xC3C3
movl $0xc0c, %r8d            # imm = 0xC0C
movl %eax, %r9d
andl %r8d, %r9d
leal (%rcx,%r9,4), %ecx
shrl $0x2, %eax
andl %r8d, %eax
orl %ecx, %eax
movw %ax, (%rdi)
rolq $0x20, 0x4(%rdx)
jmp 0x11d98
movzwl (%rdi), %eax
movl %eax, %ecx
andl $0x5, %ecx
movl %eax, %edx
shrl $0x4, %edx
andl $0x5a, %edx
orl %ecx, %edx
shrl $0x8, %eax
andl $-0x60, %eax
orl %edx, %eax
jmp 0x11d61
movzwl (%rdi), %eax
movl %eax, %ecx
andl $0x8181, %ecx           # imm = 0x8181
movl $0x202, %r8d            # imm = 0x202
movl %eax, %r9d
andl %r8d, %r9d
leal (%rcx,%r9,2), %ecx
movl %eax, %r9d
andl $0x404, %r9d            # imm = 0x404
leal (%rcx,%r9,4), %ecx
movl $0x808, %r9d            # imm = 0x808
movl %eax, %r10d
andl %r9d, %r10d
leal (%rcx,%r10,8), %ecx
movl %eax, %r10d
shrl $0x3, %r10d
andl %r8d, %r10d
orl %ecx, %r10d
movl %eax, %ecx
shrl $0x2, %ecx
andl %r9d, %ecx
orl %r10d, %ecx
shrl %eax
andl $0x2020, %eax           # imm = 0x2020
orl %ecx, %eax
movw %ax, (%rdi)
movl (%rdx), %eax
movl 0x4(%rdx), %ecx
movl 0x8(%rdx), %edi
movl %ecx, 0x8(%rdx)
movl %edi, (%rdx)
movl %eax, 0x4(%rdx)
jmp 0x11d98
movzwl (%rdi), %eax
movl %eax, %ecx
andl $0xf, %ecx
shrl $0x8, %eax
andl $-0x10, %eax
orl %ecx, %eax
movw %ax, (%rdi)
jmp 0x11a31
movzwl (%rdi), %eax
movl %eax, %ecx
andl $0xf00f, %ecx           # imm = 0xF00F
movl %eax, %r8d
shll $0x4, %r8d
andl $0xf00, %r8d            # imm = 0xF00
orl %ecx, %r8d
shrl $0x4, %eax
andl $0xf0, %eax
orl %r8d, %eax
movw %ax, (%rdi)
rolq $0x20, 0x8(%rdx)
incw (%rsi)
jmp 0x11a31