// File: /workspace/github_c_makefile_star2_O0/videolan[P]bitstream/examples/dvb_print_si.c
// Function: main
int main(int i_argc, char **ppsz_argv)
{
    int i, c;
    char *psz_tables = NULL;

    static const struct option long_options[] = {
        { "print",           required_argument, NULL, 'x' },
        { "help",            no_argument,       NULL, 'h' },
        { "version",         no_argument,       NULL, 'V' },
        { "tables",          no_argument,       NULL, 'T' },
        { 0, 0, 0, 0 }
    };

    while ((c = getopt_long(i_argc, ppsz_argv, "x:hVT:", long_options, NULL)) != -1)
    {
        switch (c) {
        case 'x':
            if (!strcmp(optarg, "text"))
                i_print_type = PRINT_TEXT;
            else if (!strcmp(optarg, "xml"))
                i_print_type = PRINT_XML;
            else
                fprintf(stderr, "unrecognized print type %s\n", optarg);
            break;

        case 'T':
            psz_tables = strdup(optarg);
            break;

        case 'V':
            fprintf(stderr, "biTStream %d.%d.%d\n", BITSTREAM_VERSION_MAJOR,
                    BITSTREAM_VERSION_MINOR, BITSTREAM_VERSION_REVISION);
            exit(0);
            break;


        case 'h':
        default:
            usage(ppsz_argv[0]);
        }
    }
    if (optind < i_argc)
        usage(ppsz_argv[0]);

    setvbuf(stdout, NULL, _IOLBF, 0);

    memset(p_pids, 0, sizeof(p_pids));

    for (i = 0; i < 8192; i++) {
        p_pids[i].i_last_cc = -1;
        psi_assemble_init(&p_pids[i].p_psi_buffer,
                          &p_pids[i].i_psi_buffer_used);
    }

    p_pids[PAT_PID].i_psi_refcount++;
    p_pids[CAT_PID].i_psi_refcount++;
    p_pids[TSDT_PID].i_psi_refcount++;
    p_pids[NIT_PID].i_psi_refcount++;
    p_pids[BAT_PID].i_psi_refcount++;
    p_pids[SDT_PID].i_psi_refcount++;
    p_pids[EIT_PID].i_psi_refcount++;
    p_pids[TDT_PID].i_psi_refcount++;
    p_pids[RST_PID].i_psi_refcount++;
    p_pids[DIT_PID].i_psi_refcount++;
    p_pids[SIT_PID].i_psi_refcount++;

    psi_table_init(pp_current_pat_sections);
    psi_table_init(pp_next_pat_sections);
    psi_table_init(pp_current_cat_sections);
    psi_table_init(pp_next_cat_sections);
    psi_table_init(pp_current_tsdt_sections);
    psi_table_init(pp_next_tsdt_sections);
    psi_table_init(pp_current_nit_sections);
    psi_table_init(pp_next_nit_sections);
    psi_table_init(pp_current_sdt_sections);
    psi_table_init(pp_next_sdt_sections);

    if (psz_tables != NULL) {
        char *psz_table = psz_tables;
        for (i = 0; i < TABLE_END; i++)
            pb_print_table[i] = false;

        do {
            char *psz_next = strpbrk(psz_table, ",");
            if (psz_next != NULL) *psz_next++ = '\0';

            for (i = 0; i < TABLE_END; i++)
                if (!strcasecmp(psz_table, ppsz_all_tables[i]))
                    pb_print_table[i] = true;

            psz_table = psz_next;
        } while (psz_table != NULL);

        free(psz_tables);
    } else
        for (i = 0; i < TABLE_END; i++)
            pb_print_table[i] = true;

    switch (i_print_type) {
    case PRINT_XML:
        printf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
        printf("<TS>\n");
        break;
    default:
        break;
    }

    bool b_is_last_invalid = false;
    while (!feof(stdin) && !ferror(stdin)) {
        uint8_t p_ts[TS_SIZE];
        size_t i_ret = fread(p_ts, sizeof(p_ts), 1, stdin);
        if (i_ret != 1) continue;
        if (!ts_validate(p_ts)) {
            if (!b_is_last_invalid) {
                switch (i_print_type) {
                case PRINT_XML:
                    printf("<ERROR type=\"invalid_ts\"/>\n");
                    break;
                default:
                    printf("invalid TS packet\n");
                }
                b_is_last_invalid = true;
            }

            int i;
            for (i = 1; i < TS_SIZE; i++) {
                if (ts_validate(p_ts + i)) {
                    memmove(p_ts, p_ts + i, TS_SIZE - i);
                    i_ret = fread(p_ts + TS_SIZE - i, i, 1, stdin);
                    if (i_ret != 1) continue;
                    break;
                }
            }
            if (i == TS_SIZE)
                continue;
        }

        uint16_t i_pid = ts_get_pid(p_ts);
        ts_pid_t *p_pid = &p_pids[i_pid];
        if (p_pid->i_psi_refcount)
            handle_psi_packet(p_ts);
        p_pid->i_last_cc = ts_get_cc(p_ts);
        b_is_last_invalid = false;
    }

    switch (i_print_type) {
    case PRINT_XML:
        printf("</TS>\n");
        break;
    default:
        break;
    }

    if (iconv_handle != (iconv_t)-1)
        iconv_close(iconv_handle);

    psi_table_free(pp_current_pat_sections);
    psi_table_free(pp_next_pat_sections);
    psi_table_free(pp_current_cat_sections);
    psi_table_free(pp_next_cat_sections);
    psi_table_free(pp_current_tsdt_sections);
    psi_table_free(pp_next_tsdt_sections);
    psi_table_free(pp_current_nit_sections);
    psi_table_free(pp_next_nit_sections);
    psi_table_free(pp_current_sdt_sections);
    psi_table_free(pp_next_sdt_sections);

    for (i = 0; i < i_nb_bouquets; i++) {
        psi_table_free(pp_bouquets[i]->pp_current_bat_sections);
        psi_table_free(pp_bouquets[i]->pp_next_bat_sections);
        free(pp_bouquets[i]);
    }
    free(pp_bouquets);

    for (i = 0; i < i_nb_sids; i++) {
        psi_table_free(pp_sids[i]->pp_eit_sections);
        free(pp_sids[i]->p_current_pmt);
        free(pp_sids[i]);
    }
    free(pp_sids);

    for (i = 0; i < 8192; i++)
        psi_assemble_reset(&p_pids[i].p_psi_buffer,
                           &p_pids[i].i_psi_buffer_used);

    return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x219ab(%rip), %rdx     # 0x23cfa
leaq 0x3595a(%rip), %rcx     # 0x37cb0
xorl %eax, %eax
movl %eax, %r8d
callq 0x20a0
movl %eax, -0x18(%rbp)
cmpl $-0x1, %eax
je 0x2461
movl -0x18(%rbp), %eax
addl $-0x54, %eax
movl %eax, %ecx
movq %rcx, -0x110(%rbp)
subl $0x24, %eax
ja 0x2450
movq -0x110(%rbp), %rax
leaq 0x20c7e(%rip), %rcx     # 0x23010
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x35c2e(%rip), %rax     # 0x37fd0
movq (%rax), %rdi
leaq 0x25cb0(%rip), %rsi     # 0x2805c
callq 0x2110
cmpl $0x0, %eax
jne 0x23c2
movl $0x0, 0x35f30(%rip)     # 0x382f0
jmp 0x240d
movq 0x35c07(%rip), %rax     # 0x37fd0
movq (%rax), %rdi
leaq 0x2192e(%rip), %rsi     # 0x23d01
callq 0x2110
cmpl $0x0, %eax
jne 0x23e9
movl $0x1, 0x35f09(%rip)     # 0x382f0
jmp 0x240b
movq 0x35c00(%rip), %rax     # 0x37ff0
movq (%rax), %rdi
movq 0x35bd6(%rip), %rax     # 0x37fd0
movq (%rax), %rdx
leaq 0x21901(%rip), %rsi     # 0x23d05
movb $0x0, %al
callq 0x2120
jmp 0x240d
jmp 0x245c
movq 0x35bba(%rip), %rax     # 0x37fd0
movq (%rax), %rdi
callq 0x2200
movq %rax, -0x20(%rbp)
jmp 0x245c
movq 0x35bc5(%rip), %rax     # 0x37ff0
movq (%rax), %rdi
leaq 0x218ec(%rip), %rsi     # 0x23d21
movl $0x1, %edx
xorl %r8d, %r8d
movl %r8d, %ecx
movb $0x0, %al
callq 0x2120
xorl %edi, %edi
callq 0x21f0
jmp 0x2450
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2b40
jmp 0x2341
movq 0x35b60(%rip), %rax     # 0x37fc8
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jge 0x247b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2b40
movq 0x35b36(%rip), %rax     # 0x37fb8
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %ecx
movl $0x1, %edx
movq %rcx, %rsi
callq 0x21b0
leaq 0x35e63(%rip), %rdi     # 0x38300
xorl %esi, %esi
movl $0x30000, %edx          # imm = 0x30000
callq 0x20f0
movl $0x0, -0x14(%rbp)
cmpl $0x2000, -0x14(%rbp)    # imm = 0x2000
jge 0x250b
movslq -0x14(%rbp), %rcx
leaq 0x35e3c(%rip), %rax     # 0x38300
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movb $-0x1, 0x4(%rax)
movslq -0x14(%rbp), %rax
leaq 0x35e26(%rip), %rdi     # 0x38300
imulq $0x18, %rax, %rax
addq %rax, %rdi
addq $0x8, %rdi
movslq -0x14(%rbp), %rax
leaq 0x35e10(%rip), %rsi     # 0x38300
imulq $0x18, %rax, %rax
addq %rax, %rsi
addq $0x10, %rsi
callq 0x2b80
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x24b0
movl 0x35def(%rip), %eax     # 0x38300
addl $0x1, %eax
movl %eax, 0x35de6(%rip)     # 0x38300
movl 0x35df8(%rip), %eax     # 0x38318
addl $0x1, %eax
movl %eax, 0x35def(%rip)     # 0x38318
movl 0x35e01(%rip), %eax     # 0x38330
addl $0x1, %eax
movl %eax, 0x35df8(%rip)     # 0x38330
movl 0x35f42(%rip), %eax     # 0x38480
addl $0x1, %eax
movl %eax, 0x35f39(%rip)     # 0x38480
movl 0x35f4b(%rip), %eax     # 0x38498
addl $0x1, %eax
movl %eax, 0x35f42(%rip)     # 0x38498
movl 0x35f3c(%rip), %eax     # 0x38498
addl $0x1, %eax
movl %eax, 0x35f33(%rip)     # 0x38498
movl 0x35f45(%rip), %eax     # 0x384b0
addl $0x1, %eax
movl %eax, 0x35f3c(%rip)     # 0x384b0
movl 0x35f66(%rip), %eax     # 0x384e0
addl $0x1, %eax
movl %eax, 0x35f5d(%rip)     # 0x384e0
movl 0x35f3f(%rip), %eax     # 0x384c8
addl $0x1, %eax
movl %eax, 0x35f36(%rip)     # 0x384c8
movl 0x36038(%rip), %eax     # 0x385d0
addl $0x1, %eax
movl %eax, 0x3602f(%rip)     # 0x385d0
movl 0x36041(%rip), %eax     # 0x385e8
addl $0x1, %eax
movl %eax, 0x36038(%rip)     # 0x385e8
leaq 0x65d49(%rip), %rdi     # 0x68300
callq 0x2bb0
leaq 0x6653d(%rip), %rdi     # 0x68b00
callq 0x2bb0
leaq 0x66d31(%rip), %rdi     # 0x69300
callq 0x2bb0
leaq 0x67525(%rip), %rdi     # 0x69b00
callq 0x2bb0
leaq 0x67d19(%rip), %rdi     # 0x6a300
callq 0x2bb0
leaq 0x6850d(%rip), %rdi     # 0x6ab00
callq 0x2bb0
leaq 0x68d01(%rip), %rdi     # 0x6b300
callq 0x2bb0
leaq 0x694f5(%rip), %rdi     # 0x6bb00
callq 0x2bb0
leaq 0x69ce9(%rip), %rdi     # 0x6c300
callq 0x2bb0
leaq 0x6a4dd(%rip), %rdi     # 0x6cb00
callq 0x2bb0
cmpq $0x0, -0x20(%rbp)
je 0x26f5
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0xf, -0x14(%rbp)
jge 0x2662
movslq -0x14(%rbp), %rcx
leaq 0x6acad(%rip), %rax     # 0x6d300
movb $0x0, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2642
jmp 0x2664
movq -0x28(%rbp), %rdi
leaq 0x216c6(%rip), %rsi     # 0x23d35
callq 0x2170
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x2691
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movb $0x0, (%rax)
movl $0x0, -0x14(%rbp)
cmpl $0xf, -0x14(%rbp)
jge 0x26d7
movq -0x28(%rbp), %rdi
movslq -0x14(%rbp), %rcx
leaq 0x356a3(%rip), %rax     # 0x37d50
movq (%rax,%rcx,8), %rsi
callq 0x2040
cmpl $0x0, %eax
jne 0x26ca
movslq -0x14(%rbp), %rcx
leaq 0x6ac3a(%rip), %rax     # 0x6d300
movb $0x1, (%rax,%rcx)
jmp 0x26cc
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2698
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2664
movq -0x20(%rbp), %rdi
callq 0x2030
jmp 0x271e
movl $0x0, -0x14(%rbp)
cmpl $0xf, -0x14(%rbp)
jge 0x271c
movslq -0x14(%rbp), %rcx
leaq 0x6abf3(%rip), %rax     # 0x6d300
movb $0x1, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x26fc
jmp 0x271e
movl 0x35bcc(%rip), %eax     # 0x382f0
subl $0x1, %eax
jne 0x2749
jmp 0x272b
leaq 0x21605(%rip), %rdi     # 0x23d37
movb $0x0, %al
callq 0x20b0
leaq 0x2161f(%rip), %rdi     # 0x23d5f
movb $0x0, %al
callq 0x20b0
jmp 0x274b
jmp 0x274b
movb $0x0, -0x31(%rbp)
movq 0x3586a(%rip), %rax     # 0x37fc0
movq (%rax), %rdi
callq 0x2130
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x111(%rbp)
jne 0x278a
movq 0x3584c(%rip), %rax     # 0x37fc0
movq (%rax), %rdi
callq 0x2070
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x111(%rbp)
movb -0x111(%rbp), %al
testb $0x1, %al
jne 0x2799
jmp 0x2956
leaq -0xf0(%rbp), %rdi
movq 0x35819(%rip), %rax     # 0x37fc0
movq (%rax), %rcx
movl $0xbc, %esi
movl $0x1, %edx
callq 0x2080
movq %rax, -0xf8(%rbp)
cmpq $0x1, -0xf8(%rbp)
je 0x27cc
jmp 0x274f
leaq -0xf0(%rbp), %rdi
callq 0x2bf0
testb $0x1, %al
jne 0x28ec
testb $0x1, -0x31(%rbp)
jne 0x2815
movl 0x35b04(%rip), %eax     # 0x382f0
subl $0x1, %eax
jne 0x2803
jmp 0x27f3
leaq 0x2156b(%rip), %rdi     # 0x23d65
movb $0x0, %al
callq 0x20b0
jmp 0x2811
leaq 0x21577(%rip), %rdi     # 0x23d81
movb $0x0, %al
callq 0x20b0
movb $0x1, -0x31(%rbp)
movl $0x1, -0xfc(%rbp)
cmpl $0xbc, -0xfc(%rbp)
jge 0x28d9
leaq -0xf0(%rbp), %rdi
movslq -0xfc(%rbp), %rax
addq %rax, %rdi
callq 0x2bf0
testb $0x1, %al
jne 0x284b
jmp 0x28c3
leaq -0xf0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
movslq -0xfc(%rbp), %rax
addq %rax, %rsi
movl $0xbc, %eax
subl -0xfc(%rbp), %eax
movslq %eax, %rdx
callq 0x21c0
leaq -0xf0(%rbp), %rdi
addq $0xbc, %rdi
movslq -0xfc(%rbp), %rcx
xorl %eax, %eax
subq %rcx, %rax
addq %rax, %rdi
movslq -0xfc(%rbp), %rsi
movq 0x3571f(%rip), %rax     # 0x37fc0
movq (%rax), %rcx
movl $0x1, %edx
callq 0x2080
movq %rax, -0xf8(%rbp)
cmpq $0x1, -0xf8(%rbp)
je 0x28c1
jmp 0x28c5
jmp 0x28d9
jmp 0x28c5
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
jmp 0x281f
cmpl $0xbc, -0xfc(%rbp)
jne 0x28ea
jmp 0x274f
jmp 0x28ec
leaq -0xf0(%rbp), %rdi
callq 0x2c10
movw %ax, -0xfe(%rbp)
movzwl -0xfe(%rbp), %eax
movl %eax, %ecx
leaq 0x359f1(%rip), %rax     # 0x38300
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2935
leaq -0xf0(%rbp), %rdi
callq 0x2c40
leaq -0xf0(%rbp), %rdi
callq 0x2dc0
movb %al, %cl
movq -0x108(%rbp), %rax
movb %cl, 0x4(%rax)
movb $0x0, -0x31(%rbp)
jmp 0x274f
movl 0x35994(%rip), %eax     # 0x382f0
subl $0x1, %eax
jne 0x2973
jmp 0x2963
leaq 0x2142a(%rip), %rdi     # 0x23d94
movb $0x0, %al
callq 0x20b0
jmp 0x2975
jmp 0x2975
movq $-0x1, %rax
cmpq %rax, 0x3579d(%rip)     # 0x38120
je 0x2991
movq 0x35794(%rip), %rdi     # 0x38120
callq 0x2190
leaq 0x65968(%rip), %rdi     # 0x68300
callq 0x2de0
leaq 0x6615c(%rip), %rdi     # 0x68b00
callq 0x2de0
leaq 0x66950(%rip), %rdi     # 0x69300
callq 0x2de0
leaq 0x67144(%rip), %rdi     # 0x69b00
callq 0x2de0
leaq 0x67938(%rip), %rdi     # 0x6a300
callq 0x2de0
leaq 0x6812c(%rip), %rdi     # 0x6ab00
callq 0x2de0
leaq 0x68920(%rip), %rdi     # 0x6b300
callq 0x2de0
leaq 0x69114(%rip), %rdi     # 0x6bb00
callq 0x2de0
leaq 0x69908(%rip), %rdi     # 0x6c300
callq 0x2de0
leaq 0x6a0fc(%rip), %rdi     # 0x6cb00
callq 0x2de0
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl 0x6a8f7(%rip), %eax     # 0x6d310
jge 0x2a6d
movq 0x6a8f6(%rip), %rax     # 0x6d318
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x8, %rdi
callq 0x2de0
movq 0x6a8de(%rip), %rax     # 0x6d318
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x808, %rdi            # imm = 0x808
callq 0x2de0
movq 0x6a8c3(%rip), %rax     # 0x6d318
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2030
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2a10
movq 0x6a8a4(%rip), %rdi     # 0x6d318
callq 0x2030
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl 0x6a897(%rip), %eax     # 0x6d320
jge 0x2ada
movq 0x6a896(%rip), %rax     # 0x6d328
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x10, %rdi
callq 0x2de0
movq 0x6a87e(%rip), %rax     # 0x6d328
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdi
callq 0x2030
movq 0x6a866(%rip), %rax     # 0x6d328
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2030
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2a80
movq 0x6a847(%rip), %rdi     # 0x6d328
callq 0x2030
movl $0x0, -0x14(%rbp)
cmpl $0x2000, -0x14(%rbp)    # imm = 0x2000
jge 0x2b32
movslq -0x14(%rbp), %rax
leaq 0x357ff(%rip), %rdi     # 0x38300
imulq $0x18, %rax, %rax
addq %rax, %rdi
addq $0x8, %rdi
movslq -0x14(%rbp), %rax
leaq 0x357e9(%rip), %rsi     # 0x38300
imulq $0x18, %rax, %rax
addq %rax, %rsi
addq $0x10, %rsi
callq 0x2e20
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2aed
xorl %eax, %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopl (%rax)