// File: /workspace/github_cpp_makefile_star2_O1/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
movq 0x88360(%rdi), %rbp
movl 0x18(%rax), %eax
movq %rax, 0x30(%rsp)
leal (%rax,%rax,2), %eax
movq %rdi, (%rsp)
leaq 0x8e370(%rdi), %rcx
movq %rcx, 0x10(%rsp)
leal 0x33(,%rax,2), %r10d
xorl %r12d, %r12d
testl %r10d, %r10d
cmovlel %r12d, %r10d
leaq 0x528(%rbp), %rax
movq %rax, 0x18(%rsp)
incl %r10d
addq $0x538, %rbp            # imm = 0x538
leaq 0x13be4(%rip), %rbx     # 0x1c340
movq %rbp, 0x20(%rsp)
xorl %r15d, %r15d
movq %r10, 0x28(%rsp)
movq %r15, %rax
shlq $0xe, %rax
addq 0x10(%rsp), %rax
movq (%rsp), %rcx
movq %rax, 0xa63a0(%rcx,%r15,8)
movq %r15, 0x8(%rsp)
testq %r15, %r15
je 0x87d5
movq 0x8(%rsp), %rax
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax), %r14
addq $0x10, %r14
movq 0x20(%rsp), %r15
xorl %r13d, %r13d
movl $0x40, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x21a0
testl %eax, %eax
je 0x8866
addq $-0x4000, %r13          # imm = 0xC000
addq $0x50, %r15
cmpq %r13, %r12
jne 0x87ad
cmpl $-0x8, 0x30(%rsp)
movq 0x28(%rsp), %r10
movl $0xaaaaaaab, %r11d      # imm = 0xAAAAAAAB
leaq 0x13c64(%rip), %r14     # 0x1c450
movq 0x8(%rsp), %r15
jl 0x887f
movq (%rsp), %rax
movq 0xa63a0(%rax,%r15,8), %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 0x8824
incq %rsi
addq $0x100, %rdx            # imm = 0x100
cmpq %r10, %rsi
jne 0x8805
jmp 0x887f
movq 0x10(%rsp), %rax
subq %r13, %rax
movq (%rsp), %rcx
movq 0x8(%rsp), %r15
movq %rax, 0xa63a0(%rcx,%r15,8)
incq %r15
addq $-0x4000, %r12          # imm = 0xC000
addq $0x50, %rbp
cmpq $0x6, %r15
jne 0x8769
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq