// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq 0x88358(%rdi), %rax
movq 0x88360(%rdi), %rbp
movl 0x18(%rax), %eax
movq %rax, 0x40(%rsp)
leal (%rax,%rax,2), %eax
movq %rdi, 0x18(%rsp)
leaq 0x8e370(%rdi), %rcx
leaq 0x528(%rbp), %rdx
movq %rdx, 0x28(%rsp)
leal 0x33(,%rax,2), %r10d
xorl %r12d, %r12d
testl %r10d, %r10d
cmovlel %r12d, %r10d
incl %r10d
addq $0x538, %rbp            # imm = 0x538
leaq 0x12ee6(%rip), %rbx     # 0x1b330
movq %rbp, 0x30(%rsp)
movq %rcx, 0x10(%rsp)
movq %rcx, %r15
xorl %r13d, %r13d
movq %r10, 0x38(%rsp)
movq %r15, 0x20(%rsp)
movq %r13, %rax
shlq $0xe, %rax
addq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rax, 0xa63a0(%rcx,%r13,8)
movq %r13, 0x8(%rsp)
testq %r13, %r13
je 0x84d1
movq 0x8(%rsp), %rax
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax), %r14
addq $0x10, %r14
movq 0x30(%rsp), %r15
xorl %r13d, %r13d
movl $0x40, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x21a0
testl %eax, %eax
je 0x855e
addq $-0x4000, %r13          # imm = 0xC000
addq $0x50, %r15
cmpq %r13, %r12
jne 0x84a9
cmpl $-0x8, 0x40(%rsp)
movq 0x38(%rsp), %r10
movl $0xaaaaaaab, %r11d      # imm = 0xAAAAAAAB
leaq 0x12f58(%rip), %r14     # 0x1b440
movq 0x20(%rsp), %r15
movq 0x8(%rsp), %r13
jl 0x857d
movq %r15, %rdx
xorl %esi, %esi
movl %esi, %ecx
imulq %r11, %rcx
shrq $0x22, %rcx
leal (%rcx,%rcx), %eax
leal (%rax,%rax,2), %eax
movl %esi, %edi
subl %eax, %edi
leaq (%rdi,%rdi,2), %rax
leaq (%r14,%rax,2), %rdi
xorl %r8d, %r8d
movl %r8d, %eax
shrl %eax
andl $0xc, %eax
movl %r8d, %r9d
andl $0x3, %r9d
orq %rax, %r9
movzbl (%rbx,%r9), %eax
movb (%rax,%rdi), %al
mulb (%rbp,%r8)
movzbl %al, %eax
shll %cl, %eax
movl %eax, (%rdx,%r8,4)
incq %r8
cmpq $0x40, %r8
jne 0x851c
incq %rsi
addq $0x100, %rdx            # imm = 0x100
cmpq %r10, %rsi
jne 0x84fd
jmp 0x857d
movq 0x10(%rsp), %rax
subq %r13, %rax
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %r13
movq %rax, 0xa63a0(%rcx,%r13,8)
movq 0x20(%rsp), %r15
incq %r13
addq $-0x4000, %r12          # imm = 0xC000
addq $0x4000, %r15           # imm = 0x4000
addq $0x50, %rbp
cmpq $0x6, %r13
jne 0x845f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop