// File: /workspace/github_c_makefile_star2_O3/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
subq $0x18, %rsp
movq %rdx, -0x38(%rbp)
movl %esi, -0x2c(%rbp)
movl %ecx, %r14d
movq %rsp, %r13
leal 0x40b(%rcx), %eax
andl $-0x10, %eax
subq %rax, %r13
movq %r13, %rsp
leaq 0x1(%r13), %r15
movb 0x2b6b(%rip), %al       # 0x6078
movb %al, (%r13)
leaq 0x5(%r13), %r12
movw $0x0, 0x5(%r13)
movw $0x202, 0x1(%r13)       # imm = 0x202
movl %ecx, %esi
addl $0x3f7, %esi            # imm = 0x3F7
movl %esi, %r8d
shrl $0x8, %r8d
movb %r8b, 0x3(%r13)
movb %sil, 0x4(%r13)
movzwl 0x2b49(%rip), %eax      # 0x608a
movzwl %si, %r10d
xorl %r11d, %r11d
movq %r12, %rdx
testb %r11b, %r11b
je 0x357a
movzbl %r11b, %r9d
movq %r12, %rdx
movq %rdx, %rbx
subq %r15, %rbx
cmpq %r10, %rbx
jg 0x3597
movzwl 0x2(%rdx), %ebx
rolw $0x8, %bx
movzwl %bx, %ebx
addq %rbx, %rdx
addq $0x4, %rdx
decw %r9w
jne 0x3557
movq %rdx, %r9
subq %r15, %r9
addq $-0x4, %r9
cmpq %r10, %r9
jge 0x3597
incb %r11b
movb 0x1(%rdx), %r9b
orb (%rdx), %r9b
jne 0x3548
jmp 0x3599
xorl %edx, %edx
movq %rdx, %r9
subq %r15, %r9
addq $0x4, %r9
cmpq %r10, %r9
jg 0x35c2
movl $0x2000e00, (%rdx)      # imm = 0x2000E00
movb %ah, 0x4(%rdx)
movb %al, 0x5(%rdx)
movw $0x0, 0x6(%rdx)
movb 0x3(%r13), %r8b
movb 0x4(%r13), %sil
movzwl (%rdi), %eax
movzbl %r8b, %edx
shll $0x8, %edx
movzbl %sil, %edi
orq %rdx, %rdi
xorl %r8d, %r8d
movq %r12, %rsi
testb %r8b, %r8b
je 0x3608
movzbl %r8b, %r9d
movq %r12, %rsi
movq %rsi, %rdx
subq %r15, %rdx
cmpq %rdi, %rdx
jg 0x3623
movzwl 0x2(%rsi), %edx
rolw $0x8, %dx
movzwl %dx, %edx
addq %rdx, %rsi
addq $0x4, %rsi
decw %r9w
jne 0x35e5
movq %rsi, %rdx
subq %r15, %rdx
addq $-0x4, %rdx
cmpq %rdi, %rdx
jge 0x3623
incb %r8b
movb 0x1(%rsi), %dl
orb (%rsi), %dl
jne 0x35d6
jmp 0x3625
xorl %esi, %esi
movq %rsi, %rdx
subq %r15, %rdx
addq $0x4, %rdx
cmpq %rdi, %rdx
jg 0x3652
movl $0x2000f00, (%rsi)      # imm = 0x2000F00
movb %ah, 0x4(%rsi)
movb %al, 0x5(%rsi)
movw $0x0, 0x6(%rsi)
movzwl 0x3(%r13), %eax
rolw $0x8, %ax
movzwl %ax, %edi
xorl %esi, %esi
movq %r12, %rax
testb %sil, %sil
je 0x3686
movzbl %sil, %r8d
movq %r12, %rax
movq %rax, %rdx
subq %r15, %rdx
cmpq %rdi, %rdx
jg 0x36a1
movzwl 0x2(%rax), %edx
rolw $0x8, %dx
movzwl %dx, %edx
addq %rdx, %rax
addq $0x4, %rax
decw %r8w
jne 0x3663
movq %rax, %rdx
subq %r15, %rdx
addq $-0x4, %rdx
cmpq %rdi, %rdx
jge 0x36a1
incb %sil
movb 0x1(%rax), %dl
orb (%rax), %dl
jne 0x3654
jmp 0x36a3
xorl %eax, %eax
movq %rax, %rdx
subq %r15, %rdx
addq $0x4, %rdx
cmpq %rdi, %rdx
jg 0x36d3
movl $0x2001200, (%rax)      # imm = 0x2001200
movl -0x2c(%rbp), %edx
movb %dh, 0x4(%rax)
movb %dl, 0x5(%rax)
movw $0x0, 0x6(%rax)
movzwl 0x3(%r13), %eax
rolw $0x8, %ax
movzwl %ax, %edi
xorl %eax, %eax
movq %r12, %rbx
testb %al, %al
je 0x3704
movzbl %al, %edx
movq %r12, %rbx
movq %rbx, %rsi
subq %r15, %rsi
cmpq %rdi, %rsi
jg 0x371e
movzwl 0x2(%rbx), %esi
rolw $0x8, %si
movzwl %si, %esi
addq %rsi, %rbx
addq $0x4, %rbx
decw %dx
jne 0x36e2
movq %rbx, %rdx
subq %r15, %rdx
addq $-0x4, %rdx
cmpq %rdi, %rdx
jge 0x371e
incb %al
movb 0x1(%rbx), %dl
orb (%rbx), %dl
jne 0x36d5
jmp 0x3720
xorl %ebx, %ebx
leal 0x2(%rcx), %eax
movzwl %ax, %eax
addq %rbx, %rax
subq %r15, %rax
cmpq %rdi, %rax
jg 0x3760
movw $0x1500, (%rbx)         # imm = 0x1500
movb %ch, 0x2(%rbx)
movb %cl, 0x3(%rbx)
leaq 0x4(%rbx), %rdi
movq -0x38(%rbp), %rsi
movq %r14, %rdx
callq 0x1080
movw $0x0, 0x4(%rbx,%r14)
movzwl 0x3(%r13), %eax
rolw $0x8, %ax
movzwl %ax, %edi
xorl %eax, %eax
movq %r12, %rsi
testb %al, %al
je 0x3791
movzbl %al, %ecx
movq %r12, %rsi
movq %rsi, %rdx
subq %r15, %rdx
cmpq %rdi, %rdx
jg 0x37ab
movzwl 0x2(%rsi), %edx
rolw $0x8, %dx
movzwl %dx, %edx
addq %rdx, %rsi
addq $0x4, %rsi
decw %cx
jne 0x376f
movq %rsi, %rcx
subq %r15, %rcx
addq $-0x4, %rcx
cmpq %rdi, %rcx
jge 0x37ab
incb %al
movb 0x1(%rsi), %cl
orb (%rsi), %cl
jne 0x3762
jmp 0x37ad
xorl %esi, %esi
movl %esi, %eax
subl %r15d, %eax
addl $-0x4, %eax
rolw $0x8, %ax
movw %ax, 0x3(%r13)
subq %r13, %rsi
movq %r13, %rdi
callq 0x195e
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq