// File: /workspace/github_c_makefile_star2_O0/videolan[P]bitstream/examples/dvb_ecmg.c
// Function: handle_stream_setup
static void handle_stream_setup(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;
    int i;

    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, 0x14);
        return;
    }

    if (i_version >= 2 && tlv_count_param(p_tlv, ECMG_PARAM_ECMID) != 1) {
        send_stream_error(i_streamid, 0x10);
        return;
    }

    p_stream = malloc(sizeof(stream_t));

    for (i = 0; i < i_nb_streams; i++) {
        if (pp_streams[i] == NULL) {
            pp_streams[i] = p_stream;
            break;
        }
    }

    if (i == i_nb_streams) {
        pp_streams = realloc(pp_streams, ++i_nb_streams * sizeof(stream_t *));
        pp_streams[i_nb_streams - 1] = p_stream;
    }

    p_stream->i_streamid = i_streamid;
    if (i_version >= 2)
        p_stream->i_ecmid = ecmg_find_ecmid(p_tlv, 0);
    else
        p_stream->i_ecmid = 0;
    p_stream->i_cp_duration = ecmg_find_nomcpdur(p_tlv, 0);
    fprintf(stderr,
            "starting new stream id=0x%hx ecmid=0x%hx CP duration=%u ms\n",
            p_stream->i_streamid, p_stream->i_ecmid,
            p_stream->i_cp_duration * 100);

    send_stream_status(p_stream);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %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)
movzwl -0xa(%rbp), %eax
movzwl 0x6183(%rip), %ecx      # 0x8088
cmpl %ecx, %eax
je 0x1f1c
movl $0x6, %esi
movzwl -0xa(%rbp), %edi
callq 0x18c0
jmp 0x20a5
movzwl -0xc(%rbp), %edi
callq 0x3540
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x1f42
movl $0x14, %esi
movzwl -0xc(%rbp), %edi
callq 0x35c0
jmp 0x20a5
movzbl 0x6130(%rip), %eax      # 0x8079
cmpl $0x2, %eax
jl 0x1f77
movq -0x8(%rbp), %rdi
movl $0x19, %esi
callq 0x2a00
movzwl %ax, %eax
cmpl $0x1, %eax
je 0x1f77
movl $0x10, %esi
movzwl -0xc(%rbp), %edi
callq 0x35c0
jmp 0x20a5
movl $0x6, %edi
callq 0x10b0
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x60fb(%rip), %eax      # 0x8090
jge 0x1fcb
movq 0x60fa(%rip), %rax      # 0x8098
movslq -0x1c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x1fbe
movq -0x18(%rbp), %rdx
movq 0x60e4(%rip), %rax      # 0x8098
movslq -0x1c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x1fcb
jmp 0x1fc0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1f8c
movl -0x1c(%rbp), %eax
cmpl 0x60bc(%rip), %eax      # 0x8090
jne 0x201a
movq 0x60bb(%rip), %rdi      # 0x8098
movl 0x60ad(%rip), %eax      # 0x8090
addl $0x1, %eax
movl %eax, 0x60a4(%rip)      # 0x8090
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x10c0
movq %rax, 0x6099(%rip)      # 0x8098
movq -0x18(%rbp), %rdx
movq 0x608e(%rip), %rax      # 0x8098
movl 0x6080(%rip), %ecx      # 0x8090
subl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movw -0xc(%rbp), %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movzbl 0x604d(%rip), %eax      # 0x8079
cmpl $0x2, %eax
jl 0x2049
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x36f0
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x2(%rax)
jmp 0x2053
movq -0x18(%rbp), %rax
movw $0x0, 0x2(%rax)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x3780
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x4(%rax)
movq 0x5f88(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movzwl (%rax), %edx
movq -0x18(%rbp), %rax
movzwl 0x2(%rax), %ecx
movq -0x18(%rbp), %rax
movzwl 0x4(%rax), %eax
imull $0x64, %eax, %r8d
leaq 0x30b6(%rip), %rsi      # 0x514b
movb $0x0, %al
callq 0x1080
movq -0x18(%rbp), %rdi
callq 0x3810
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)