// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %rbx
movl %edi, %ebp
leaq 0xc89d(%rip), %r15      # 0xebd6
leaq 0x18760(%rip), %r12     # 0x1aaa0
movq 0x18c91(%rip), %r13     # 0x1afd8
movq $0x0, 0x10(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
xorl %r8d, %r8d
callq 0x20b0
cmpl $0x78, %eax
jne 0x23a4
movq (%r13), %r14
movq %r14, %rdi
leaq 0x10aac(%rip), %rsi     # 0x12e22
callq 0x2120
testl %eax, %eax
je 0x239b
movq %r14, %rdi
leaq 0xc854(%rip), %rsi      # 0xebdd
callq 0x2120
testl %eax, %eax
jne 0x23c2
movb $0x1, 0x18da7(%rip)     # 0x1b140
jmp 0x2350
movb $0x0, 0x18d9e(%rip)     # 0x1b140
jmp 0x2350
cmpl $-0x1, %eax
je 0x23e2
cmpl $0x54, %eax
jne 0x2973
movq (%r13), %rdi
callq 0x2200
movq %rax, 0x10(%rsp)
jmp 0x2350
movq 0x18c2f(%rip), %rax     # 0x1aff8
movq (%rax), %rdi
leaq 0xc80e(%rip), %rsi      # 0xebe1
movq %r14, %rdx
xorl %eax, %eax
callq 0x2130
jmp 0x2350
movq 0x18be7(%rip), %rax     # 0x1afd0
cmpl %ebp, (%rax)
jl 0x299f
movq 0x18bc8(%rip), %rax     # 0x1afc0
movq (%rax), %rdi
pushq $0x1
popq %rbp
xorl %esi, %esi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x21c0
leaq 0x18d40(%rip), %rbx     # 0x1b150
movl $0x30000, %edx          # imm = 0x30000
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2110
pushq $0x10
popq %rax
cmpq $0x30010, %rax          # imm = 0x30010
je 0x2440
movb $-0x1, -0xc(%rax,%rbx)
andq $0x0, -0x8(%rax,%rbx)
andw $0x0, (%rax,%rbx)
addq $0x18, %rax
jmp 0x2422
movl %ebp, 0x18d0a(%rip)     # 0x1b150
movl %ebp, 0x18d1c(%rip)     # 0x1b168
movl %ebp, 0x18d2e(%rip)     # 0x1b180
movl %ebp, 0x18e78(%rip)     # 0x1b2d0
movl $0x2, 0x18e86(%rip)     # 0x1b2e8
movl %ebp, 0x18e98(%rip)     # 0x1b300
movl %ebp, 0x18ec2(%rip)     # 0x1b330
movl %ebp, 0x18ea4(%rip)     # 0x1b318
movl %ebp, 0x18fa6(%rip)     # 0x1b420
movl %ebp, 0x18fb8(%rip)     # 0x1b438
leaq 0x48cc9(%rip), %rdi     # 0x4b150
callq 0x29cb
leaq 0x494bd(%rip), %rdi     # 0x4b950
callq 0x29cb
leaq 0x49cb1(%rip), %rdi     # 0x4c150
callq 0x29cb
leaq 0x4a4a5(%rip), %rdi     # 0x4c950
callq 0x29cb
leaq 0x4ac99(%rip), %rdi     # 0x4d150
callq 0x29cb
leaq 0x4b48d(%rip), %rdi     # 0x4d950
callq 0x29cb
leaq 0x4bc81(%rip), %rdi     # 0x4e150
callq 0x29cb
leaq 0x4c475(%rip), %rdi     # 0x4e950
callq 0x29cb
leaq 0x4cc69(%rip), %rdi     # 0x4f150
callq 0x29cb
leaq 0x4d45d(%rip), %rdi     # 0x4f950
callq 0x29cb
leaq 0x4dc51(%rip), %r15     # 0x50150
cmpq $0x0, 0x10(%rsp)
je 0x295d
xorl %eax, %eax
cmpq $0xf, %rax
je 0x251d
movb $0x0, (%rax,%r15)
incq %rax
jmp 0x250d
leaq 0xbf8c(%rip), %rbp      # 0xe4b0
movq 0x10(%rsp), %r14
movq %r14, %rdi
pushq $0x2c
popq %rsi
callq 0x20c0
testq %rax, %rax
je 0x2544
movq %rax, %r13
incq %r13
movb $0x0, (%rax)
jmp 0x2547
xorl %r13d, %r13d
movq %rbp, %r12
xorl %ebx, %ebx
cmpq $0xf, %rbx
je 0x2573
movslq (%r12), %rsi
addq %rbp, %rsi
movq %r14, %rdi
callq 0x2040
testl %eax, %eax
jne 0x256a
movb $0x1, (%rbx,%r15)
incq %rbx
addq $0x4, %r12
jmp 0x254c
movq %r13, %r14
testq %r13, %r13
jne 0x2529
movq 0x10(%rsp), %rdi
callq 0x2030
cmpb $0x1, 0x18bb4(%rip)     # 0x1b140
jne 0x25a6
leaq 0x14bb6(%rip), %rdi     # 0x1714b
callq 0x2070
leaq 0x14bd1(%rip), %rdi     # 0x17172
callq 0x2070
xorl %ebp, %ebp
movq 0x18a19(%rip), %r14     # 0x1afc8
pushq $0x1
popq %r15
movq (%r14), %rdi
callq 0x2140
testl %eax, %eax
jne 0x27e7
movq (%r14), %r12
movq %r12, %rdi
callq 0x2080
testl %eax, %eax
jne 0x27e7
movl $0xbc, %esi
leaq 0x20(%rsp), %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0x2090
cmpq $0x1, %rax
jne 0x25b3
cmpb $0x47, 0x20(%rsp)
jne 0x26eb
movzbl 0x21(%rsp), %r12d
movl %r12d, %eax
andl $0x1f, %eax
shll $0x8, %eax
movzbl 0x22(%rsp), %r13d
orq %rax, %r13
imulq $0x18, %r13, %rax
leaq 0x18b31(%rip), %rcx     # 0x1b150
leaq (%rcx,%rax), %rbx
cmpl $0x0, (%rax,%rcx)
movb 0x23(%rsp), %al
je 0x27db
testb $0x10, %al
je 0x27db
movl %eax, %edx
andb $0xf, %dl
movb 0x4(%rbx), %cl
cmpb %dl, %cl
je 0x27db
movzbl %cl, %ecx
cmpl $0xff, %ecx
je 0x2672
movzbl %al, %eax
subl %eax, %ecx
incl %ecx
testb $0xf, %cl
je 0x2672
leaq 0x8(%rbx), %rdi
leaq 0x10(%rbx), %rsi
callq 0x2a09
movb 0x21(%rsp), %r12b
leaq 0x20(%rsp), %rdi
callq 0x5b01
movzbl %r12b, %ecx
btl $0x6, %ecx
adcq $0x0, %rax
movq %rax, 0x18(%rsp)
leaq 0xdc(%rsp), %rcx
subl %eax, %ecx
movb %cl, 0xf(%rsp)
leaq 0x8(%rbx), %rbp
leaq 0x10(%rbx), %r12
cmpq $0x0, 0x8(%rbx)
movzwl %r13w, %r13d
je 0x26d3
movq %rbp, %rdi
movq %r12, %rsi
leaq 0x18(%rsp), %rdx
leaq 0xf(%rsp), %rcx
callq 0x2a2b
testq %rax, %rax
je 0x26d3
movl %r13d, %edi
movq %rax, %rsi
callq 0x2b04
testb $0x40, 0x21(%rsp)
jne 0x2770
leaq 0xdc(%rsp), %rcx
jmp 0x279a
testb $0x1, %bpl
jne 0x270f
cmpb $0x0, 0x18a48(%rip)     # 0x1b140
leaq 0x14a78(%rip), %rdi     # 0x17177
leaq 0x14a83(%rip), %rax     # 0x17189
cmovneq %rax, %rdi
callq 0x2070
movl $0xbb, %r13d
movq %r15, %r12
movl $0xbb, %ebp
subq $0x1, %rbp
jb 0x2768
cmpb $0x47, 0x20(%rsp,%r12)
jne 0x2760
leaq (%rsp,%r12), %rsi
addq $0x20, %rsi
leaq 0x20(%rsp), %rdi
movq %r13, %rdx
callq 0x21d0
leaq (%rsp,%r13), %rdi
addq $0x20, %rdi
movq (%r14), %rcx
movq %r12, %rsi
movq %r15, %rdx
callq 0x2090
cmpq $0x1, %rax
je 0x25fc
incq %r12
movq %rbp, %r13
jmp 0x271d
movb $0x1, %bpl
jmp 0x25b3
leaq 0x20(%rsp), %rdi
callq 0x5b01
leaq 0xdc(%rsp), %rcx
cmpq %rcx, %rax
jae 0x279a
movzbl (%rax), %ecx
addq %rcx, %rax
incq %rax
leaq 0xdc(%rsp), %rcx
jmp 0x279d
movq %rcx, %rax
movq %rax, 0x18(%rsp)
subl %eax, %ecx
movb %cl, 0xf(%rsp)
testb %cl, %cl
je 0x27d7
movq %rbp, %rdi
movq %r12, %rsi
leaq 0x18(%rsp), %rdx
leaq 0xf(%rsp), %rcx
callq 0x2a2b
testq %rax, %rax
je 0x27d1
movl %r13d, %edi
movq %rax, %rsi
callq 0x2b04
movb 0xf(%rsp), %cl
jmp 0x27a8
movb 0x23(%rsp), %al
andb $0xf, %al
movb %al, 0x4(%rbx)
xorl %ebp, %ebp
jmp 0x25b3
cmpb $0x1, 0x18952(%rip)     # 0x1b140
jne 0x27fc
leaq 0x149ad(%rip), %rdi     # 0x171a4
callq 0x2070
movq 0x1891d(%rip), %rdi     # 0x1b120
cmpq $-0x1, %rdi
je 0x280e
callq 0x21a0
leaq 0x4893b(%rip), %rdi     # 0x4b150
callq 0x29e0
leaq 0x4912f(%rip), %rdi     # 0x4b950
callq 0x29e0
leaq 0x49923(%rip), %rdi     # 0x4c150
callq 0x29e0
leaq 0x4a117(%rip), %rdi     # 0x4c950
callq 0x29e0
leaq 0x4a90b(%rip), %rdi     # 0x4d150
callq 0x29e0
leaq 0x4b0ff(%rip), %rdi     # 0x4d950
callq 0x29e0
leaq 0x4b8f3(%rip), %rdi     # 0x4e150
callq 0x29e0
leaq 0x4c0e7(%rip), %rdi     # 0x4e950
callq 0x29e0
leaq 0x4c8db(%rip), %rdi     # 0x4f150
callq 0x29e0
leaq 0x4d0cf(%rip), %rdi     # 0x4f950
callq 0x29e0
xorl %ebx, %ebx
movl $0x808, %r14d           # imm = 0x808
movslq 0x4d8cb(%rip), %rax     # 0x50160
movq 0x4d8cc(%rip), %rdi     # 0x50168
cmpq %rax, %rbx
jge 0x28d6
movq (%rdi,%rbx,8), %rdi
addq $0x8, %rdi
callq 0x29e0
movq 0x4d8b3(%rip), %rax     # 0x50168
movq (%rax,%rbx,8), %rdi
addq %r14, %rdi
callq 0x29e0
movq 0x4d8a0(%rip), %rax     # 0x50168
movq (%rax,%rbx,8), %rdi
callq 0x2030
incq %rbx
jmp 0x288e
callq 0x2030
xorl %ebx, %ebx
movslq 0x4d88c(%rip), %rax     # 0x50170
movq 0x4d88d(%rip), %rdi     # 0x50178
cmpq %rax, %rbx
jge 0x291f
movq (%rdi,%rbx,8), %rdi
addq $0x10, %rdi
callq 0x29e0
movq 0x4d874(%rip), %r14     # 0x50178
movq (%r14,%rbx,8), %rax
movq 0x8(%rax), %rdi
callq 0x2030
movq (%r14,%rbx,8), %rdi
callq 0x2030
incq %rbx
jmp 0x28dd
callq 0x2030
movl $0x2000, %r14d          # imm = 0x2000
leaq 0x1882f(%rip), %rbx     # 0x1b160
subq $0x1, %r14
jb 0x2949
leaq -0x8(%rbx), %rdi
movq %rbx, %rsi
callq 0x2a09
addq $0x18, %rbx
jmp 0x2931
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
cmpq $0xf, %rax
je 0x2585
movb $0x1, (%rax,%r15)
incq %rax
jmp 0x295f
cmpl $0x56, %eax
jne 0x299f
movq 0x18679(%rip), %rax     # 0x1aff8
movq (%rax), %rdi
leaq 0xc274(%rip), %rsi      # 0xebfd
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x2130
xorl %edi, %edi
callq 0x21f0
movq (%rbx), %rdi
callq 0x29a7