// File: /workspace/github_c_makefile_star2_O0/videolan[P]bitstream/examples/dvb_ecmg.c
// Function: main
int main(int i_argc, char **ppsz_argv)
{
    if (i_argc > 1) {
        fprintf(stderr, "usage: %s < <input stream> > <output stream>\n",
                ppsz_argv[0]);
        return EXIT_FAILURE;
    }

    for ( ; ; ) {
        uint8_t *p_tlv_h = malloc(TLVH_HEADER_SIZE + TLV_HEADER_SIZE);
        uint8_t *p_tlv = tlvh_get_tlv(p_tlv_h);
        uint16_t i_type;
        fd_set rset;
        struct timeval timeout;
        int i_ret;

        FD_ZERO(&rset);
        FD_SET(STDIN_FILENO, &rset);
        timeout.tv_sec = SELECT_TIMEOUT;
        timeout.tv_usec = 0;

        if ((i_ret = select(STDIN_FILENO + 1, &rset, NULL, NULL, &timeout)) < 0)
            return EXIT_FAILURE;
        if (!i_ret) {
            if (b_init) return EXIT_FAILURE;
            /* timeout - send a packet so that the communication is reset
             * if it is really dead */
            send_channel_test();
            continue;
        }

        if (read_wrapper(p_tlv_h, TLVH_HEADER_SIZE + TLV_HEADER_SIZE) <= 0)
            return EXIT_FAILURE;

        p_tlv_h = realloc(p_tlv_h, TLVH_HEADER_SIZE + TLV_HEADER_SIZE
                                    + tlv_get_length(p_tlv));
        p_tlv = tlvh_get_tlv(p_tlv_h);
        if (read_wrapper(p_tlv + TLV_HEADER_SIZE, tlv_get_length(p_tlv)) <= 0)
            return EXIT_FAILURE;

        if ((b_init && tlvh_get_version(p_tlv_h) > 3) ||
            (!b_init && tlvh_get_version(p_tlv_h) != i_version)) {
            send_channel_error(i_channelid, 0x2);
            free(p_tlv_h);
            continue;
        }

        i_type = tlv_get_type(p_tlv);

        if (!tlv_validate(p_tlv)) {
            send_channel_error(i_channelid, 0x1);
            free(p_tlv_h);
            continue;
        }

        if (!ecmg_validate(p_tlv)) {
            send_channel_error(i_channelid, 0xf);
            free(p_tlv_h);
            continue;
        }

        if (b_init && i_type != ECMG_TYPE_CHANNEL_SETUP) {
            send_channel_error(i_channelid, 0x6);
            free(p_tlv_h);
            continue;
        }

        switch (i_type) {
            case ECMG_TYPE_CHANNEL_SETUP:
                if (b_init)
                    i_version = tlvh_get_version(p_tlv_h);
                handle_channel_setup(p_tlv);
                break;

            case ECMG_TYPE_CHANNEL_TEST:
                handle_channel_test(p_tlv);
                break;

            case ECMG_TYPE_CHANNEL_CLOSE:
                handle_channel_close(p_tlv);
                break;

            case ECMG_TYPE_CHANNEL_ERROR:
                handle_channel_error(p_tlv);
                break;

            case ECMG_TYPE_STREAM_SETUP:
                handle_stream_setup(p_tlv);
                break;

            case ECMG_TYPE_STREAM_TEST:
                handle_stream_test(p_tlv);
                break;

            case ECMG_TYPE_STREAM_CLOSEREQ:
                handle_stream_close(p_tlv);
                break;

            case ECMG_TYPE_STREAM_ERROR:
                handle_stream_error(p_tlv);
                break;

            case ECMG_TYPE_CHANNEL_STATUS:
            case ECMG_TYPE_STREAM_STATUS:
                break;

            case ECMG_TYPE_CW:
                handle_cw(p_tlv);
                break;

            default:
                send_channel_error(i_channelid, 0x3);
                break;
        }

        free(p_tlv_h);
    }

    return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x1, -0x8(%rbp)
jle 0x138a
movq 0x6c92(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x3cd3(%rip), %rsi      # 0x504a
movb $0x0, %al
callq 0x1080
movl $0x1, -0x4(%rbp)
jmp 0x1758
jmp 0x138c
movl $0x5, %edi
callq 0x10b0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1770
movq %rax, -0x20(%rbp)
leaq -0xa8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movl $0x0, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
cmpq $0x10, %rax
jae 0x13f1
movq -0xc8(%rbp), %rax
movl -0xc0(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x13bf
jmp 0x13f3
movq -0xa8(%rbp), %rax
orq $0x1, %rax
movq %rax, -0xa8(%rbp)
movq $0xa, -0xb8(%rbp)
movq $0x0, -0xb0(%rbp)
movl $0x1, %edi
leaq -0xa8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0xb8(%rbp), %r8
movq %rcx, %rdx
callq 0x10a0
movl %eax, -0xbc(%rbp)
cmpl $0x0, %eax
jge 0x1451
movl $0x1, -0x4(%rbp)
jmp 0x1758
cmpl $0x0, -0xbc(%rbp)
jne 0x1479
testb $0x1, 0x6c17(%rip)      # 0x8078
je 0x146f
movl $0x1, -0x4(%rbp)
jmp 0x1758
callq 0x1790
jmp 0x138c
movq -0x18(%rbp), %rdi
movl $0x5, %esi
callq 0x11d0
cmpq $0x0, %rax
jg 0x1499
movl $0x1, -0x4(%rbp)
jmp 0x1758
movq -0x18(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x20(%rbp), %rdi
callq 0x1890
movq -0xd8(%rbp), %rdi
movzwl %ax, %eax
addl $0x5, %eax
movslq %eax, %rsi
callq 0x10c0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1770
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0xd0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x1890
movq -0xd0(%rbp), %rdi
movzwl %ax, %eax
movl %eax, %esi
callq 0x11d0
cmpq $0x0, %rax
jg 0x150e
movl $0x1, -0x4(%rbp)
jmp 0x1758
testb $0x1, 0x6b63(%rip)      # 0x8078
je 0x1528
movq -0x18(%rbp), %rdi
callq 0x18b0
movzbl %al, %eax
cmpl $0x3, %eax
jg 0x1548
testb $0x1, 0x6b49(%rip)      # 0x8078
jne 0x1567
movq -0x18(%rbp), %rdi
callq 0x18b0
movzbl %al, %eax
movzbl 0x6b35(%rip), %ecx      # 0x8079
cmpl %ecx, %eax
je 0x1567
movl $0x2, %esi
movzwl 0x6b34(%rip), %edi      # 0x8088
callq 0x18c0
movq -0x18(%rbp), %rdi
callq 0x1030
jmp 0x138c
movq -0x20(%rbp), %rdi
callq 0x19d0
movw %ax, -0x22(%rbp)
movq -0x20(%rbp), %rdi
callq 0x19f0
testb $0x1, %al
jne 0x15a0
movl $0x1, %esi
movzwl 0x6afb(%rip), %edi      # 0x8088
callq 0x18c0
movq -0x18(%rbp), %rdi
callq 0x1030
jmp 0x138c
movq -0x20(%rbp), %rdi
callq 0x1ab0
testb $0x1, %al
jne 0x15cc
movl $0xf, %esi
movzwl 0x6acf(%rip), %edi      # 0x8088
callq 0x18c0
movq -0x18(%rbp), %rdi
callq 0x1030
jmp 0x138c
testb $0x1, 0x6aa5(%rip)      # 0x8078
je 0x15fd
movzwl -0x22(%rbp), %eax
cmpl $0x1, %eax
je 0x15fd
movl $0x6, %esi
movzwl 0x6a9e(%rip), %edi      # 0x8088
callq 0x18c0
movq -0x18(%rbp), %rdi
callq 0x1030
jmp 0x138c
movzwl -0x22(%rbp), %eax
movl %eax, -0xdc(%rbp)
subl $0x1, %eax
je 0x16bc
jmp 0x1612
movl -0xdc(%rbp), %eax
subl $0x2, %eax
je 0x16df
jmp 0x1623
movl -0xdc(%rbp), %eax
subl $0x3, %eax
je 0x172c
jmp 0x1634
movl -0xdc(%rbp), %eax
subl $0x4, %eax
je 0x16ea
jmp 0x1645
movl -0xdc(%rbp), %eax
subl $0x5, %eax
je 0x16f5
jmp 0x1656
movl -0xdc(%rbp), %eax
subl $0x101, %eax            # imm = 0x101
je 0x1700
jmp 0x1669
movl -0xdc(%rbp), %eax
subl $0x102, %eax            # imm = 0x102
je 0x170b
jmp 0x167c
movl -0xdc(%rbp), %eax
subl $0x103, %eax            # imm = 0x103
je 0x172c
jmp 0x168f
movl -0xdc(%rbp), %eax
subl $0x104, %eax            # imm = 0x104
je 0x1716
jmp 0x169e
movl -0xdc(%rbp), %eax
subl $0x106, %eax            # imm = 0x106
je 0x1721
jmp 0x16ad
movl -0xdc(%rbp), %eax
subl $0x201, %eax            # imm = 0x201
je 0x172e
jmp 0x1739
testb $0x1, 0x69b5(%rip)      # 0x8078
je 0x16d4
movq -0x18(%rbp), %rdi
callq 0x18b0
movb %al, 0x69a5(%rip)       # 0x8079
movq -0x20(%rbp), %rdi
callq 0x1cc0
jmp 0x174a
movq -0x20(%rbp), %rdi
callq 0x1d60
jmp 0x174a
movq -0x20(%rbp), %rdi
callq 0x1db0
jmp 0x174a
movq -0x20(%rbp), %rdi
callq 0x1e70
jmp 0x174a
movq -0x20(%rbp), %rdi
callq 0x1ed0
jmp 0x174a
movq -0x20(%rbp), %rdi
callq 0x20b0
jmp 0x174a
movq -0x20(%rbp), %rdi
callq 0x2130
jmp 0x174a
movq -0x20(%rbp), %rdi
callq 0x2220
jmp 0x174a
jmp 0x174a
movq -0x20(%rbp), %rdi
callq 0x22a0
jmp 0x174a
movl $0x3, %esi
movzwl 0x6943(%rip), %edi      # 0x8088
callq 0x18c0
movq -0x18(%rbp), %rdi
callq 0x1030
jmp 0x138c
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)