// File: /workspace/github_c_makefile_star2_O3/videolan[P]bitstream/examples/mpeg_restamp.c
// Function: main
int main(int i_argc, char **ppsz_argv)
{
    if (i_argc > 2 || i_argc < 1 ||
        (!strcmp(ppsz_argv[1], "-h") || !strcmp(ppsz_argv[1], "--help")))
        usage(ppsz_argv[0]);

    unsigned int i_mtu = TS_SIZE;
    if (i_argc == 2) {
        i_mtu = strtoul(ppsz_argv[1], NULL, 0);
        if (!i_mtu)
            usage(ppsz_argv[0]);
    }

    for ( ; ; ) {
        uint8_t p_buffer[i_mtu];
        ssize_t i_read = read(STDIN_FILENO, p_buffer, i_mtu);
        uint64_t date = get_date();
        if (i_read == -1) {
            if (errno == EAGAIN || errno == EWOULDBLOCK)
                continue;
            exit(EXIT_FAILURE);
        }

        if (!i_read)
            exit(EXIT_SUCCESS);

        uint8_t *p_ts = p_buffer;
        while (p_ts < p_buffer + i_mtu && ts_validate(p_ts)) {
            if (ts_has_adaptation(p_ts) && ts_get_adaptation(p_ts) &&
                tsaf_has_pcr(p_ts))
                handle_pcr(p_ts, date);

            uint16_t header_size = TS_HEADER_SIZE +
                                   (ts_has_adaptation(p_ts) ? 1 : 0) +
                                   ts_get_adaptation(p_ts);
            if (ts_get_unitstart(p_ts) && ts_has_payload(p_ts) &&
                header_size + PES_HEADER_SIZE_PTS <= TS_SIZE &&
                pes_validate(p_ts + header_size) &&
                pes_get_streamid(p_ts + header_size) !=
                    PES_STREAM_ID_PRIVATE_2 &&
                pes_validate_header(p_ts + header_size) &&
                pes_has_pts(p_ts + header_size) &&
                pes_validate_pts(p_ts + header_size)) {
                pes_set_pts(p_ts + header_size,
                            handle_ts(pes_get_pts(p_ts + header_size)));

                if (header_size + PES_HEADER_SIZE_PTSDTS <= TS_SIZE &&
                    pes_has_dts(p_ts + header_size) &&
                    pes_validate_dts(p_ts + header_size))
                    pes_set_dts(p_ts + header_size,
                                handle_ts(pes_get_dts(p_ts + header_size)));
            }

            p_ts += TS_SIZE;
        }

        ssize_t i_written = write(STDOUT_FILENO, p_buffer, i_mtu);
        if (i_written == -1) {
            if (errno == EAGAIN || errno == EWOULDBLOCK)
                continue;
            exit(EXIT_FAILURE);
        }
    }

    return EXIT_FAILURE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movl %edi, %r15d
leal -0x3(%r15), %eax
cmpl $-0x2, %eax
jb 0x11f7
movq 0x8(%rbx), %r14
cmpb $0x2d, (%r14)
jne 0x11e4
cmpb $0x68, 0x1(%r14)
jne 0x11e4
cmpb $0x0, 0x2(%r14)
je 0x11f7
leaq 0xe19(%rip), %rsi       # 0x2004
movq %r14, %rdi
callq 0x1070
testl %eax, %eax
jne 0x121c
movq (%rbx), %rdx
movq 0x2df7(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xe00(%rip), %rsi       # 0x200b
xorl %eax, %eax
callq 0x1080
movl $0x1, %edi
callq 0x10a0
movl $0xbc, %r13d
movl $0xbc, %eax
cmpl $0x2, %r15d
jne 0x123d
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1090
testl %eax, %eax
je 0x11f7
movl %eax, %ebx
leaq 0xf(%rbx), %rax
andq $-0x10, %rax
movq %rax, -0x68(%rbp)
movq %rbx, -0x48(%rbp)
movq %rsp, -0x70(%rbp)
movq %rsp, %r15
subq -0x68(%rbp), %r15
movq %r15, %rsp
xorl %edi, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1060
movq %rax, %r12
movl $0x1, %edi
leaq -0x80(%rbp), %rsi
callq 0x1040
cmpl $0x16, %eax
jne 0x128b
xorl %edi, %edi
leaq -0x80(%rbp), %rsi
callq 0x1040
movq -0x78(%rbp), %rax
leaq (%rax,%rax,8), %rax
shrq $0x5, %rax
movabsq $0xa7c5ac471b47843, %rcx # imm = 0xA7C5AC471B47843
mulq %rcx
cmpq $-0x1, %r12
je 0x16cf
testq %r12, %r12
je 0x16e6
testq %rbx, %rbx
je 0x16b9
imulq $0x15f90, -0x80(%rbp), %rax # imm = 0x15F90
shrq $0x7, %rdx
addq %rax, %rdx
leaq (%r15,%rbx), %rax
movq 0x2da6(%rip), %r9       # 0x4080
movq 0x2d97(%rip), %rcx      # 0x4078
movq %rcx, -0x50(%rbp)
movq 0x2d7c(%rip), %rsi      # 0x4068
leaq 0x9(%r15), %rcx
cmpb $0x47, -0x9(%rcx)
jne 0x16b9
leaq -0x9(%rcx), %rdi
movb 0x3(%rdi), %r11b
movb 0x4(%rdi), %r10b
movl $0x4, %r12d
testb $0x20, %r11b
je 0x1427
movl $0x5, %r12d
testb %r10b, %r10b
je 0x1393
movb -0x4(%rcx), %r14b
testb $0x10, %r14b
je 0x1427
movq %r9, %r13
movzbl -0x3(%rcx), %r8d
shlq $0x19, %r8
movzbl -0x2(%rcx), %ebx
shll $0x11, %ebx
orq %r8, %rbx
movzbl -0x1(%rcx), %r8d
shll $0x9, %r8d
orq %rbx, %r8
movzbl (%rcx), %ebx
leaq (%r8,%rbx,2), %rbx
movzbl 0x1(%rcx), %r8d
shrl $0x7, %r8d
orq %rbx, %r8
movabsq $0x1ffffffff, %r9       # imm = 0x1FFFFFFFF
leaq 0x1(%r9), %rbx
cmpq %rbx, %rsi
je 0x138e
testb %r14b, %r14b
js 0x139b
movq %r8, %rbx
subq %rsi, %rbx
andq %r9, %rbx
cmpq $0x2329, %rbx           # imm = 0x2329
jae 0x139b
movq %r13, %r9
jmp 0x13c2
xorl %r10d, %r10d
jmp 0x1427
addq %rdx, %rsi
movq -0x50(%rbp), %r9
addq %r8, %r9
subq %r9, %rsi
addq %r13, %rsi
movabsq $0x1ffffffff, %r9       # imm = 0x1FFFFFFFF
andq %r9, %rsi
movq %rsi, 0x2cc1(%rip)      # 0x4080
movq %rsi, %r9
movq %r8, 0x2c9f(%rip)       # 0x4068
movq %rdx, 0x2ca8(%rip)      # 0x4078
testq %r9, %r9
movl $0xbc, %r13d
je 0x1419
leaq (%r9,%r8), %rsi
movq %rsi, %rbx
shrq $0x19, %rbx
movb %bl, -0x3(%rcx)
movl %esi, %ebx
shrl $0x11, %ebx
movb %bl, -0x2(%rcx)
movl %esi, %ebx
shrl $0x9, %ebx
movb %bl, -0x1(%rcx)
movl %esi, %ebx
shrl %ebx
movb %bl, (%rcx)
shlb $0x7, %sil
orb $0x7e, %sil
movb %sil, 0x1(%rcx)
movb $0x0, 0x2(%rcx)
andb $0x7f, %r14b
movb %r14b, -0x4(%rcx)
jmp 0x141c
xorl %r9d, %r9d
movq %rdx, -0x50(%rbp)
movq %r8, %rsi
movq -0x48(%rbp), %rbx
testb $0x40, 0x1(%rdi)
je 0x16aa
testb $0x10, %r11b
je 0x16aa
movl %r12d, %r8d
movzbl %r10b, %r10d
addq %r8, %r10
cmpl $0xae, %r10d
ja 0x16aa
cmpb $0x0, -0x9(%rcx,%r10)
jne 0x16aa
cmpb $0x0, -0x8(%rcx,%r10)
jne 0x16aa
cmpb $0x1, -0x7(%rcx,%r10)
jne 0x16aa
movb -0x6(%rcx,%r10), %r8b
cmpb $-0x44, %r8b
setb %r11b
cmpb $-0x41, %r8b
sete %r8b
orb %r11b, %r8b
jne 0x16aa
movb -0x3(%rcx,%r10), %r8b
andb $-0x40, %r8b
negb %r8b
jno 0x16aa
movb -0x2(%rcx,%r10), %r11b
testb %r11b, %r11b
jns 0x16aa
movzbl (%rcx,%r10), %r12d
movl %r12d, %r8d
andb $-0x1f, %r8b
cmpb $0x21, %r8b
jne 0x16aa
movzbl 0x2(%rcx,%r10), %r8d
testb $0x1, %r8b
je 0x16aa
movzbl 0x4(%rcx,%r10), %r14d
testb $0x1, %r14b
je 0x16aa
movb -0x1(%rcx,%r10), %bl
cmpb $0x4, %bl
ja 0x14fc
movb $0x5, -0x1(%rcx,%r10)
movb $0x5, %bl
movb %bl, -0x29(%rbp)
andl $0xe, %r12d
shlq $0x1d, %r12
movzbl 0x1(%rcx,%r10), %ebx
shll $0x16, %ebx
orq %r12, %rbx
andl $-0x2, %r8d
shll $0xe, %r8d
orq %rbx, %r8
movzbl 0x3(%rcx,%r10), %ebx
shll $0x7, %ebx
orq %r8, %rbx
shrl %r14d
addq %r9, %r14
addq %rbx, %r14
xorl %r12d, %r12d
cmpb $-0x40, %r11b
setae %r12b
movq %r14, %r8
shrq $0x1d, %r8
andl $0xe, %r8d
shll $0x4, %r12d
orl %r8d, %r12d
orb $0x21, %r12b
movb %r12b, (%rcx,%r10)
movl %r14d, %r8d
shrl $0x16, %r8d
movb %r8b, 0x1(%rcx,%r10)
movl %r14d, %r8d
shrl $0xe, %r8d
orb $0x1, %r8b
movb %r8b, 0x2(%rcx,%r10)
movl %r14d, %r8d
shrl $0x7, %r8d
movb %r8b, 0x3(%rcx,%r10)
addb %r14b, %r14b
incb %r14b
movb %r14b, 0x4(%rcx,%r10)
cmpl $0xa9, %r10d
movq -0x48(%rbp), %rbx
ja 0x16aa
cmpb $-0x40, %r11b
jb 0x16aa
movl %r12d, %r8d
andb $0x10, %r8b
je 0x16aa
movzbl 0x5(%rcx,%r10), %r14d
movl %r14d, %r8d
andb $-0xf, %r8b
cmpb $0x11, %r8b
jne 0x16aa
movzbl 0x7(%rcx,%r10), %r8d
movq %r8, -0x40(%rbp)
testb $0x1, %r8b
je 0x16aa
movzbl 0x9(%rcx,%r10), %r8d
testb $0x1, %r8b
je 0x16aa
movq %r8, -0x60(%rbp)
movzbl 0x6(%rcx,%r10), %r8d
movq %r8, -0x58(%rbp)
movzbl 0x8(%rcx,%r10), %r8d
movq %r8, -0x38(%rbp)
movb %r11b, -0x2(%rcx,%r10)
cmpb $0x9, -0x29(%rbp)
ja 0x1617
movb $0xa, -0x1(%rcx,%r10)
andl $0xe, %r14d
shlq $0x1d, %r14
movq -0x58(%rbp), %r8
shll $0x16, %r8d
movq -0x40(%rbp), %r11
andl $-0x2, %r11d
shll $0xe, %r11d
movq %r11, -0x40(%rbp)
movq -0x38(%rbp), %r11
shll $0x7, %r11d
movq %r11, -0x38(%rbp)
movq -0x40(%rbp), %r11
addq %r11, -0x38(%rbp)
movq -0x60(%rbp), %r11
shrl %r11d
addq %r9, %r8
addq %r14, %r8
addq -0x38(%rbp), %r8
addq %r11, %r8
movb %r12b, (%rcx,%r10)
movq %r8, %r11
shrq $0x1d, %r11
andb $0xe, %r11b
orb $0x11, %r11b
movb %r11b, 0x5(%rcx,%r10)
movl %r8d, %r11d
shrl $0x16, %r11d
movb %r11b, 0x6(%rcx,%r10)
movl %r8d, %r11d
shrl $0xe, %r11d
orb $0x1, %r11b
movb %r11b, 0x7(%rcx,%r10)
movl %r8d, %r11d
shrl $0x7, %r11d
movb %r11b, 0x8(%rcx,%r10)
addb %r8b, %r8b
incb %r8b
movb %r8b, 0x9(%rcx,%r10)
addq %r13, %rcx
addq %r13, %rdi
cmpq %rax, %rdi
jb 0x12f0
movl $0x1, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1050
cmpq $-0x1, %rax
jne 0x16dd
callq 0x1030
cmpl $0xb, (%rax)
jne 0x1212
movq -0x70(%rbp), %rsp
jmp 0x124f
xorl %edi, %edi
callq 0x10a0