// File: /workspace/github_cpp_makefile_star2_O2/lukasz-wiecaszek[P]h264iframedecoder/h264_decoder.cpp
// Function: ymn::h264_decoder::init_dequant8x8_coeff_table()
void h264_decoder::init_dequant8x8_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][6] =
    {
        {20, 18, 32, 19, 25, 24},
        {22, 19, 35, 21, 28, 26},
        {26, 23, 42, 24, 33, 31},
        {28, 25, 45, 26, 35, 33},
        {32, 28, 51, 30, 40, 38},
        {36, 32, 58, 34, 46, 43},
    };

    static const uint8_t v_scan[16] =
    {
        0, 3, 4, 3, 3, 1, 5, 1, 4, 5, 2, 5, 3, 1, 5, 1
    };

    for (i = 0; i < SL_8x8_NUM; ++i) {
        m_dequant8x8_coeff[i] = &m_dequant8x8_buffer[i];
        for (j = 0; j < i; ++j) {
            if (0 == std::memcmp(m_active_pps->sm.scaling_matrices_8x8[j].scaling_list,
                                 m_active_pps->sm.scaling_matrices_8x8[i].scaling_list, 64)) {
                m_dequant8x8_coeff[i] = &m_dequant8x8_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 < 64; ++x) {
                uint8_t idx2 = v_scan[((x >> 1) & 12) | (x & 3)];
                uint8_t level_scale_8x8 =
                    m_active_pps->sm.scaling_matrices_8x8[i].scaling_list[x] * v[idx][idx2];
                (*m_dequant8x8_coeff[i])[q][x] = level_scale_8x8 << shift;
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq 0x88358(%rdi), %rax
imull $0x6, 0x18(%rax), %r10d
leaq 0x8e370(%rdi), %rax
addl $0x34, %r10d
xorl %r11d, %r11d
testl %r10d, %r10d
cmovlel %r11d, %r10d
movq %rdi, (%rsp)
leaq 0x8a370(%rdi), %rcx
movq %rcx, 0x20(%rsp)
movq $-0x4000, %r13          # imm = 0xC000
movl $0x538, %r14d           # imm = 0x538
leaq 0x10131(%rip), %rbp     # 0x173c0
movq %rax, 0x30(%rsp)
movq %rax, 0x8(%rsp)
movq %r10, 0x28(%rsp)
cmpq $0x6, %r11
je 0x73c1
movq %r14, 0x10(%rsp)
movq %r11, %rax
shlq $0xe, %rax
addq 0x30(%rsp), %rax
movq (%rsp), %rcx
movq %rax, 0xa63a0(%rcx,%r11,8)
movq 0x88360(%rcx), %rbx
movq %r11, 0x18(%rsp)
imulq $0x50, %r11, %rax
leaq (%rbx,%rax), %r15
addq $0x538, %r15            # imm = 0x538
leaq 0x538(%rbx), %rdi
xorl %r14d, %r14d
addq $-0x4000, %r14          # imm = 0xC000
cmpq %r14, %r13
je 0x7346
leaq 0x50(%rdi), %r12
movq %r15, %rsi
pushq $0x40
popq %rdx
callq 0x2150
movq %r12, %rdi
testl %eax, %eax
jne 0x72ea
movq 0x20(%rsp), %rax
subq %r14, %rax
movq (%rsp), %rcx
movq 0x18(%rsp), %r11
movq %rax, 0xa63a0(%rcx,%r11,8)
movq 0x10(%rsp), %r14
incq %r11
addq $-0x4000, %r13          # imm = 0xC000
addq $0x4000, 0x8(%rsp)      # imm = 0x4000
addq $0x50, %r14
jmp 0x729e
movq 0x10(%rsp), %r14
addq %r14, %rbx
movq 0x8(%rsp), %rdi
xorl %esi, %esi
movq 0x28(%rsp), %r10
movq 0x18(%rsp), %r11
pushq $0x6
popq %r15
leaq 0x10166(%rip), %r12     # 0x174d0
cmpq %r10, %rsi
je 0x732a
movl %esi, %eax
xorl %edx, %edx
divl %r15d
movl %eax, %ecx
imulq $0x6, %rdx, %rdx
addq %r12, %rdx
xorl %r8d, %r8d
cmpq $0x40, %r8
je 0x73b5
movl %r8d, %eax
shrl %eax
andl $0xc, %eax
movl %r8d, %r9d
andl $0x3, %r9d
orq %rax, %r9
movzbl (%rbp,%r9), %eax
movb (%rax,%rdx), %al
mulb (%rbx,%r8)
movzbl %al, %eax
shll %cl, %eax
movl %eax, (%rdi,%r8,4)
incq %r8
jmp 0x7382
incq %rsi
addq $0x100, %rdi            # imm = 0x100
jmp 0x736a
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq