// File: /workspace/github_c_makefile_star2_O0/videolan[P]bitstream/examples/dvb_ecmg.c
// Function: handle_cw
static void handle_cw(uint8_t *p_tlv)
{
    uint16_t i_wanted_channelid = ecmg_find_channelid(p_tlv, 0);
    uint16_t i_streamid = ecmg_find_streamid(p_tlv, 0);
    stream_t *p_stream;
    uint16_t i_cp_number, i_cw_cp_number;
    uint16_t i_cw_length;
    uint8_t *p_cw_param, *p_accesscrit_param;
    uint8_t *ppi_cw[2] = {NULL, NULL};

    if (i_wanted_channelid != i_channelid) {
        send_channel_error(i_wanted_channelid, 0x6);
        return;
    }

    if ((p_stream = find_stream(i_streamid)) == NULL) {
        send_stream_error(i_streamid, 0x7);
        return;
    }

    if (tlv_count_param(p_tlv, ECMG_PARAM_CWENCRYPT)) {
        send_stream_error(i_streamid, 0xe);
        return;
    }

    if (tlv_count_param(p_tlv, ECMG_PARAM_CPCWCOMB) != 2) {
        send_stream_error(i_streamid, 0xb);
        return;
    }

    i_cp_number = ecmg_find_cpnumber(p_tlv, 0);

    p_cw_param = tlv_find_data(p_tlv, ECMG_PARAM_CPCWCOMB, 0, &i_cw_length);
    if (i_cw_length != 10) {
        send_stream_error(i_streamid, 0xf);
        return;
    }
    i_cw_cp_number = ecmgcw_get_cpnum(p_cw_param);
    ppi_cw[i_cw_cp_number & 0x1] = ecmgcw_get_cw(p_cw_param);

    p_cw_param = tlv_find_data(p_tlv, ECMG_PARAM_CPCWCOMB, 1, &i_cw_length);
    if (i_cw_length != 10) {
        send_stream_error(i_streamid, 0xf);
        return;
    }
    i_cw_cp_number = ecmgcw_get_cpnum(p_cw_param);
    ppi_cw[i_cw_cp_number & 0x1] = ecmgcw_get_cw(p_cw_param);

    if (ppi_cw[0] == NULL || ppi_cw[1] == NULL) {
        send_stream_error(i_streamid, 0xb);
        return;
    }

    p_accesscrit_param = tlv_find_param(p_tlv, ECMG_PARAM_ACCESSCRIT, 0);

    build_ecm(p_stream, i_cp_number, ppi_cw, p_accesscrit_param);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x2a70
movw %ax, -0xa(%rbp)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x34b0
movw %ax, -0xc(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1060
movzwl -0xa(%rbp), %eax
movzwl 0x5da3(%rip), %ecx      # 0x8088
cmpl %ecx, %eax
je 0x22fc
movl $0x6, %esi
movzwl -0xa(%rbp), %edi
callq 0x18c0
jmp 0x2481
movzwl -0xc(%rbp), %edi
callq 0x3540
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x2322
movl $0x7, %esi
movzwl -0xc(%rbp), %edi
callq 0x35c0
jmp 0x2481
movq -0x8(%rbp), %rdi
movl $0x18, %esi
callq 0x2a00
cmpw $0x0, %ax
je 0x2349
movl $0xe, %esi
movzwl -0xc(%rbp), %edi
callq 0x35c0
jmp 0x2481
movq -0x8(%rbp), %rdi
movl $0x14, %esi
callq 0x2a00
movzwl %ax, %eax
cmpl $0x2, %eax
je 0x2372
movl $0xb, %esi
movzwl -0xc(%rbp), %edi
callq 0x35c0
jmp 0x2481
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x3c90
movw %ax, -0x1a(%rbp)
movq -0x8(%rbp), %rdi
movl $0x14, %esi
xorl %edx, %edx
leaq -0x1e(%rbp), %rcx
callq 0x3d20
movq %rax, -0x28(%rbp)
movzwl -0x1e(%rbp), %eax
cmpl $0xa, %eax
je 0x23b5
movl $0xf, %esi
movzwl -0xc(%rbp), %edi
callq 0x35c0
jmp 0x2481
movq -0x28(%rbp), %rdi
callq 0x3d80
movw %ax, -0x1c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x3da0
movq %rax, %rcx
movzwl -0x1c(%rbp), %eax
andl $0x1, %eax
cltq
movq %rcx, -0x40(%rbp,%rax,8)
movq -0x8(%rbp), %rdi
movl $0x14, %esi
movl $0x1, %edx
leaq -0x1e(%rbp), %rcx
callq 0x3d20
movq %rax, -0x28(%rbp)
movzwl -0x1e(%rbp), %eax
cmpl $0xa, %eax
je 0x2410
movl $0xf, %esi
movzwl -0xc(%rbp), %edi
callq 0x35c0
jmp 0x2481
movq -0x28(%rbp), %rdi
callq 0x3d80
movw %ax, -0x1c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x3da0
movq %rax, %rcx
movzwl -0x1c(%rbp), %eax
andl $0x1, %eax
cltq
movq %rcx, -0x40(%rbp,%rax,8)
cmpq $0x0, -0x40(%rbp)
je 0x2445
cmpq $0x0, -0x38(%rbp)
jne 0x2455
movl $0xb, %esi
movzwl -0xc(%rbp), %edi
callq 0x35c0
jmp 0x2481
movq -0x8(%rbp), %rdi
movl $0xd, %esi
xorl %edx, %edx
callq 0x2620
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movw -0x1a(%rbp), %ax
leaq -0x40(%rbp), %rdx
movq -0x30(%rbp), %rcx
movzwl %ax, %esi
callq 0x3dc0
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)