// File: /workspace/github_cpp_makefile_star2_O3/lukasz-wiecaszek[P]h264iframedecoder/h264_decoder.cpp
// Function: ymn::h264_decoder::init_dequant4x4_coeff_table()
void h264_decoder::init_dequant4x4_coeff_table()
{
    int i, j;
    const int depth = m_active_sps->bit_depth_luma_minus8;
    const int max_qp = 51 + 6 * depth;

    static const uint8_t v[6][3] =
    {
        {10, 13, 16},
        {11, 14, 18},
        {13, 16, 20},
        {14, 18, 23},
        {16, 20, 25},
        {18, 23, 29},
    };

    for (i = 0; i < SL_4x4_NUM; ++i) {
        m_dequant4x4_coeff[i] = &m_dequant4x4_buffer[i];
        for (j = 0; j < i; ++j) {
            if (0 == std::memcmp(m_active_pps->sm.scaling_matrices_4x4[j].scaling_list,
                                 m_active_pps->sm.scaling_matrices_4x4[i].scaling_list, 16)) {
                m_dequant4x4_coeff[i] = &m_dequant4x4_buffer[j];
                break;
            }
        }
        if (j < i)
            continue;

        for (int q = 0; q < max_qp + 1; ++q) {
            int shift = q / 6;
            int idx   = q % 6;
            for (int x = 0; x < 16; ++x) {
                uint8_t idx2 = (x & 1) + ((x >> 2) & 1);
                uint8_t level_scale_4x4 =
                    m_active_pps->sm.scaling_matrices_4x4[i].scaling_list[x] * v[idx][idx2];
                (*m_dequant4x4_coeff[i])[q][x] = level_scale_4x4 << shift;
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x88358(%rdi), %rax
movq 0x88360(%rdi), %r15
movl 0x18(%rax), %eax
movq %rax, -0x8(%rsp)
leal (%rax,%rax,2), %eax
leaq 0x88370(%rdi), %r8
leal 0x33(,%rax,2), %r9d
xorl %r10d, %r10d
testl %r9d, %r9d
cmovlel %r10d, %r9d
leaq 0x468(%r15), %rax
movq %rax, -0x18(%rsp)
incl %r9d
addq $0x478, %r15            # imm = 0x478
movl $0xaaaaaaab, %ebx       # imm = 0xAAAAAAAB
leaq 0x13134(%rip), %r14     # 0x1b420
movq %r15, -0x10(%rsp)
movq %r8, %r12
xorl %r13d, %r13d
movq %r13, %rax
shlq $0xc, %rax
addq %r8, %rax
movq %rax, 0xa6370(%rdi,%r13,8)
testq %r13, %r13
je 0x834f
movq %r13, %rax
shlq $0x5, %rax
movq -0x18(%rsp), %rcx
addq %rcx, %rax
addq $0x10, %rax
movdqu (%rax), %xmm0
movq -0x10(%rsp), %rcx
xorl %eax, %eax
movdqu (%rcx), %xmm1
pcmpeqb %xmm0, %xmm1
pmovmskb %xmm1, %edx
cmpl $0xffff, %edx           # imm = 0xFFFF
je 0x83af
addq $-0x1000, %rax          # imm = 0xF000
addq $0x20, %rcx
cmpq %rax, %r10
jne 0x832c
cmpl $-0x8, -0x8(%rsp)
jl 0x83bd
movq %r12, %rbp
xorl %r11d, %r11d
movl %r11d, %ecx
imulq %rbx, %rcx
shrq $0x22, %rcx
leal (%rcx,%rcx), %eax
leal (%rax,%rax,2), %eax
movl %r11d, %edx
subl %eax, %edx
leaq (%rdx,%rdx,2), %rsi
addq %r14, %rsi
xorl %edx, %edx
movl %edx, %eax
andl $0x1, %eax
btl $0x2, %edx
adcq $0x0, %rax
movb (%rax,%rsi), %al
mulb (%r15,%rdx)
movzbl %al, %eax
shll %cl, %eax
movl %eax, (%rbp,%rdx,4)
incq %rdx
cmpq $0x10, %rdx
jne 0x837b
incq %r11
addq $0x40, %rbp
cmpq %r9, %r11
jne 0x835c
jmp 0x83bd
movq %r8, %rcx
subq %rax, %rcx
movq %rcx, 0xa6370(%rdi,%r13,8)
incq %r13
addq $-0x1000, %r10          # imm = 0xF000
addq $0x1000, %r12           # imm = 0x1000
addq $0x20, %r15
cmpq $0x6, %r13
jne 0x82f7
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop