// File: /workspace/github_c_makefile_star2_O1/videolan[P]bitstream/examples/dvb_ecmg.c
// Function: send_ecm
static void send_ecm(stream_t *p_stream, uint16_t i_cp_number,
                     const uint8_t *p_ecm, uint16_t i_length)
{
    uint8_t p_tlv_h[MAX_TLV_SIZE + i_length]; /* this is oversized */
    uint8_t *p_tlv = tlvh_get_tlv(p_tlv_h);
    uint8_t *p_tlv_n;

    tlvh_set_version(p_tlv_h, i_version);
    ecmg_init(p_tlv);
    tlv_set_type(p_tlv, ECMG_TYPE_ECM);
    /* length will be written at the end */
    tlv_set_length(p_tlv, MAX_TLV_SIZE - TLV_HEADER_SIZE - TLVH_HEADER_SIZE
                           + i_length);

    ecmg_append_channelid(p_tlv, i_channelid);
    ecmg_append_streamid(p_tlv, p_stream->i_streamid);
    ecmg_append_cpnumber(p_tlv, i_cp_number);
    tlv_append_data(p_tlv, ECMG_PARAM_ECM, p_ecm, i_length);

    p_tlv_n = tlv_find_param(p_tlv, TLV_PARAM_EMPTY, 0);
    tlv_set_length(p_tlv, p_tlv_n - p_tlv - TLV_HEADER_SIZE);
    write_wrapper(p_tlv_h, p_tlv_n - p_tlv_h);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %eax
movq %rsp, %rbx
leal 0x40b(%rax), %ecx
andl $-0x10, %ecx
subq %rcx, %rbx
movq %rbx, %rsp
leaq 0x1(%rbx), %r15
movb 0x32bf(%rip), %cl       # 0x7078
movb %cl, (%rbx)
leaq 0x5(%rbx), %r12
movw $0x0, 0x5(%rbx)
movw $0x202, 0x1(%rbx)       # imm = 0x202
movl %eax, %ecx
addl $0x3f7, %ecx            # imm = 0x3F7
movb %ch, 0x3(%rbx)
movq %rbx, %r13
movb %cl, 0x4(%rbx)
movzwl 0x32a6(%rip), %r8d      # 0x708a
movzwl %cx, %ecx
xorl %r10d, %r10d
xorl %r11d, %r11d
movq %r12, %r9
testb %r11b, %r11b
je 0x3e21
movzbl %r11b, %ebx
movq %r12, %r9
movq %r9, %r14
subq %r15, %r14
cmpq %rcx, %r14
jg 0x3e34
movzwl 0x2(%r9), %r14d
rolw $0x8, %r14w
movzwl %r14w, %r14d
addq %r14, %r9
addq $0x4, %r9
decw %bx
jne 0x3dfc
movq %r9, %rbx
subq %r15, %rbx
addq $-0x4, %rbx
cmpq %rcx, %rbx
cmovgeq %r10, %r9
jmp 0x3e37
xorl %r9d, %r9d
testq %r9, %r9
je 0x3e4a
incb %r11b
movb 0x1(%r9), %bl
orb (%r9), %bl
jne 0x3ded
jmp 0x3e4d
xorl %r9d, %r9d
movq %r9, %r10
subq %r15, %r10
addq $0x4, %r10
cmpq %rcx, %r10
jg 0x3e92
movl $0x2000e00, (%r9)       # imm = 0x2000E00
leaq 0x4(%r9), %r10
movl $0x8, %ecx
movl %r8d, %r11d
shrl %cl, %r11d
movb %r11b, (%r10)
incq %r10
addq $-0x8, %rcx
je 0x3e6c
movzwl 0x2(%r9), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
movw $0x0, 0x4(%r9,%rcx)
movzwl 0x3(%r13), %ecx
rolw $0x8, %cx
movzwl (%rdi), %edi
movzwl %cx, %ecx
xorl %r9d, %r9d
xorl %r10d, %r10d
movq %r12, %r8
testb %r10b, %r10b
je 0x3eda
movzbl %r10b, %r11d
movq %r12, %r8
movq %r8, %rbx
subq %r15, %rbx
cmpq %rcx, %rbx
jg 0x3eed
movzwl 0x2(%r8), %ebx
rolw $0x8, %bx
movzwl %bx, %ebx
addq %rbx, %r8
addq $0x4, %r8
decw %r11w
jne 0x3eb6
movq %r8, %r11
subq %r15, %r11
addq $-0x4, %r11
cmpq %rcx, %r11
cmovgeq %r9, %r8
jmp 0x3ef0
xorl %r8d, %r8d
testq %r8, %r8
je 0x3f03
incb %r10b
movb 0x1(%r8), %r11b
orb (%r8), %r11b
jne 0x3ea7
jmp 0x3f06
xorl %r8d, %r8d
movq %r8, %r9
subq %r15, %r9
addq $0x4, %r9
cmpq %rcx, %r9
jg 0x3f4b
movl $0x2000f00, (%r8)       # imm = 0x2000F00
leaq 0x4(%r8), %r9
movl $0x8, %ecx
movl %edi, %r10d
shrl %cl, %r10d
movb %r10b, (%r9)
incq %r9
addq $-0x8, %rcx
je 0x3f25
movzwl 0x2(%r8), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
movw $0x0, 0x4(%r8,%rcx)
movzwl 0x3(%r13), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
movq %r12, %rdi
testb %r9b, %r9b
je 0x3f92
movzbl %r9b, %r10d
movq %r12, %rdi
movq %rdi, %r11
subq %r15, %r11
cmpq %rcx, %r11
jg 0x3fa5
movzwl 0x2(%rdi), %r11d
rolw $0x8, %r11w
movzwl %r11w, %r11d
addq %r11, %rdi
addq $0x4, %rdi
decw %r10w
jne 0x3f6c
movq %rdi, %r10
subq %r15, %r10
addq $-0x4, %r10
cmpq %rcx, %r10
cmovgeq %r8, %rdi
jmp 0x3fa7
xorl %edi, %edi
testq %rdi, %rdi
je 0x3fba
incb %r9b
movb 0x1(%rdi), %r10b
orb (%rdi), %r10b
jne 0x3f5d
jmp 0x3fbc
xorl %edi, %edi
movq %rdi, %r8
subq %r15, %r8
addq $0x4, %r8
cmpq %rcx, %r8
jg 0x4001
movl $0x2001200, (%rdi)      # imm = 0x2001200
movzwl %si, %esi
leaq 0x4(%rdi), %r8
movl $0x8, %ecx
movl %esi, %r9d
shrl %cl, %r9d
movb %r9b, (%r8)
incq %r8
addq $-0x8, %rcx
je 0x3fdd
movzwl 0x2(%rdi), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
movw $0x0, 0x4(%rdi,%rcx)
movzwl 0x3(%r13), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
xorl %esi, %esi
xorl %edi, %edi
movq %r12, %rbx
testb %dil, %dil
je 0x4046
movzbl %dil, %r8d
movq %r12, %rbx
movq %rbx, %r9
subq %r15, %r9
cmpq %rcx, %r9
jg 0x4059
movzwl 0x2(%rbx), %r9d
rolw $0x8, %r9w
movzwl %r9w, %r9d
addq %r9, %rbx
addq $0x4, %rbx
decw %r8w
jne 0x4020
movq %rbx, %r8
subq %r15, %r8
addq $-0x4, %r8
cmpq %rcx, %r8
cmovgeq %rsi, %rbx
jmp 0x405b
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x406e
incb %dil
movb 0x1(%rbx), %r8b
orb (%rbx), %r8b
jne 0x4011
jmp 0x4070
xorl %ebx, %ebx
leal 0x2(%rax), %esi
movzwl %si, %esi
addq %rbx, %rsi
subq %r15, %rsi
cmpq %rcx, %rsi
jg 0x40a7
movw $0x1500, (%rbx)         # imm = 0x1500
movb %ah, 0x2(%rbx)
movb %al, 0x3(%rbx)
leaq 0x4(%rbx), %rdi
movzwl %ax, %r14d
movq %rdx, %rsi
movq %r14, %rdx
callq 0x1080
movw $0x0, 0x4(%rbx,%r14)
movzwl 0x3(%r13), %eax
rolw $0x8, %ax
movzwl %ax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
movq %r12, %rsi
testb %dl, %dl
je 0x40e9
movzbl %dl, %edi
movq %r12, %rsi
movq %rsi, %r8
subq %r15, %r8
cmpq %rax, %r8
jg 0x40fc
movzwl 0x2(%rsi), %r8d
rolw $0x8, %r8w
movzwl %r8w, %r8d
addq %r8, %rsi
addq $0x4, %rsi
decw %di
jne 0x40c4
movq %rsi, %rdi
subq %r15, %rdi
addq $-0x4, %rdi
cmpq %rax, %rdi
cmovgeq %rcx, %rsi
jmp 0x40fe
xorl %esi, %esi
testq %rsi, %rsi
je 0x4110
incb %dl
movb 0x1(%rsi), %dil
orb (%rsi), %dil
jne 0x40b7
jmp 0x4112
xorl %esi, %esi
movl %esi, %eax
subl %r15d, %eax
addl $-0x4, %eax
rolw $0x8, %ax
movq %r13, %rdi
movw %ax, 0x3(%r13)
subq %r13, %rsi
callq 0x1c0d
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq