// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rsi, %rbx
movl %edi, %r15d
leal -0x3(%r15), %eax
cmpl $-0x2, %eax
jb 0x11f6
movq 0x8(%rbx), %r14
leaq 0xe2d(%rip), %rsi       # 0x2004
movq %r14, %rdi
callq 0x1070
testl %eax, %eax
je 0x11f6
leaq 0xe1d(%rip), %rsi       # 0x2007
movq %r14, %rdi
callq 0x1070
testl %eax, %eax
jne 0x121b
movq (%rbx), %rdx
movq 0x2df8(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xe04(%rip), %rsi       # 0x200e
xorl %eax, %eax
callq 0x1080
movl $0x1, %edi
callq 0x10a0
movl $0xbc, %r13d
movl $0xbc, %eax
cmpl $0x2, %r15d
jne 0x123c
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1090
testl %eax, %eax
je 0x11f6
movl %eax, %ebx
leaq 0xf(%rbx), %rax
andq $-0x10, %rax
movq %rax, -0x58(%rbp)
movq %rsp, %r14
movq %rsp, %r15
subq -0x58(%rbp), %r15
movq %r15, %rsp
xorl %edi, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1060
movq %rax, %r12
movl $0x1, %edi
leaq -0x68(%rbp), %rsi
callq 0x1040
cmpl $0x16, %eax
jne 0x1285
xorl %edi, %edi
leaq -0x68(%rbp), %rsi
callq 0x1040
movq -0x60(%rbp), %rax
leaq (%rax,%rax,8), %rax
shrq $0x5, %rax
movabsq $0xa7c5ac471b47843, %rcx # imm = 0xA7C5AC471B47843
mulq %rcx
cmpq $-0x1, %r12
je 0x1703
testq %r12, %r12
je 0x1719
testq %rbx, %rbx
je 0x16ed
imulq $0x15f90, -0x68(%rbp), %rax # imm = 0x15F90
shrq $0x7, %rdx
addq %rax, %rdx
leaq (%r15,%rbx), %rax
movq 0x2dac(%rip), %rsi      # 0x4080
movq 0x2d9d(%rip), %r8       # 0x4078
movq 0x2d86(%rip), %rcx      # 0x4068
movq %rcx, -0x38(%rbp)
leaq 0x9(%r15), %rcx
cmpb $0x47, -0x9(%rcx)
jne 0x16ed
leaq -0x9(%rcx), %rdi
testb $0x20, 0x3(%rdi)
je 0x1412
cmpb $0x0, -0x5(%rcx)
je 0x1412
movb -0x4(%rcx), %r10b
testb $0x10, %r10b
je 0x1412
movq %r8, %r9
movzbl -0x3(%rcx), %r11d
shlq $0x19, %r11
movzbl -0x2(%rcx), %r12d
shll $0x11, %r12d
orq %r11, %r12
movzbl -0x1(%rcx), %r11d
shll $0x9, %r11d
orq %r12, %r11
movzbl (%rcx), %r12d
leaq (%r11,%r12,2), %r12
movzbl 0x1(%rcx), %r11d
shrl $0x7, %r11d
orq %r12, %r11
movabsq $0x1ffffffff, %r8       # imm = 0x1FFFFFFFF
leaq 0x1(%r8), %r12
cmpq %r12, -0x38(%rbp)
je 0x13b2
testb %r10b, %r10b
js 0x137e
movq %r11, %r12
subq -0x38(%rbp), %r12
andq %r8, %r12
cmpq $0x2329, %r12           # imm = 0x2329
jb 0x13b2
movq %rdx, %r12
subq %r9, %r12
addq -0x38(%rbp), %r12
movq %r12, %r8
movabsq $0x1ffffffff, %r9       # imm = 0x1FFFFFFFF
andq %r9, %r8
movq %r8, 0x2cc9(%rip)       # 0x4068
subq %r11, %r12
addq %rsi, %r12
andq %r9, %r12
movq %r12, 0x2cd1(%rip)      # 0x4080
movq %r12, %rsi
movq %r11, 0x2caf(%rip)      # 0x4068
movq %rdx, 0x2cb8(%rip)      # 0x4078
testq %rsi, %rsi
je 0x140b
leaq (%rsi,%r11), %r8
movq %r8, %r9
shrq $0x19, %r9
movb %r9b, -0x3(%rcx)
movl %r8d, %r9d
shrl $0x11, %r9d
movb %r9b, -0x2(%rcx)
movl %r8d, %r9d
shrl $0x9, %r9d
movb %r9b, -0x1(%rcx)
movl %r8d, %r9d
shrl %r9d
movb %r9b, (%rcx)
shlb $0x7, %r8b
orb $0x7e, %r8b
movb %r8b, 0x1(%rcx)
movb $0x0, 0x2(%rcx)
andb $0x7f, %r10b
movb %r10b, -0x4(%rcx)
movq %rdx, %r8
movq %r11, -0x38(%rbp)
movb 0x3(%rdi), %r11b
movl %r11d, %r10d
andb $0x20, %r10b
cmpb $0x1, %r10b
movl $0x5, %r10d
sbbl $0x0, %r10d
testb $0x40, 0x1(%rdi)
je 0x16de
testb $0x10, %r11b
je 0x16de
movzbl 0x4(%rdi), %r11d
addq %r11, %r10
cmpl $0xae, %r10d
ja 0x16de
cmpb $0x0, -0x9(%rcx,%r10)
jne 0x16de
cmpb $0x0, -0x8(%rcx,%r10)
jne 0x16de
cmpb $0x1, -0x7(%rcx,%r10)
jne 0x16de
cmpb $-0x44, -0x6(%rcx,%r10)
jb 0x16de
cmpb $-0x41, -0x6(%rcx,%r10)
je 0x16de
movb -0x3(%rcx,%r10), %r11b
andb $-0x40, %r11b
negb %r11b
jno 0x16de
movb -0x2(%rcx,%r10), %r12b
testb %r12b, %r12b
jns 0x16de
movzbl (%rcx,%r10), %r9d
movl %r9d, %r11d
andb $-0x1f, %r11b
cmpb $0x21, %r11b
jne 0x16de
testb $0x1, 0x2(%rcx,%r10)
je 0x16de
testb $0x1, 0x4(%rcx,%r10)
je 0x16de
movzbl 0x1(%rcx,%r10), %r11d
movq %r11, -0x40(%rbp)
movzbl 0x2(%rcx,%r10), %r11d
movq %r11, -0x50(%rbp)
movzbl 0x3(%rcx,%r10), %r11d
movq %r11, -0x30(%rbp)
movzbl 0x4(%rcx,%r10), %r11d
movq %r11, -0x48(%rbp)
movb %r12b, -0x2(%rcx,%r10)
cmpb $0x4, -0x1(%rcx,%r10)
ja 0x1519
movb $0x5, -0x1(%rcx,%r10)
andl $0xe, %r9d
shlq $0x1d, %r9
movq -0x40(%rbp), %r11
shll $0x16, %r11d
orq %r9, %r11
movq %r11, %r9
movq -0x50(%rbp), %r11
andl $-0x2, %r11d
shll $0xe, %r11d
orq %r9, %r11
movq -0x30(%rbp), %r9
shll $0x7, %r9d
orq %r11, %r9
movq -0x48(%rbp), %r11
shrl %r11d
addq %rsi, %r11
addq %r9, %r11
xorl %r9d, %r9d
cmpb $-0x40, %r12b
setae %r9b
movq %r11, %r12
shrq $0x1d, %r11
andl $0xe, %r11d
shll $0x4, %r9d
orl %r11d, %r9d
orb $0x21, %r9b
movl %r9d, -0x30(%rbp)
movb %r9b, (%rcx,%r10)
movl %r12d, %r11d
shrl $0x16, %r11d
movb %r11b, 0x1(%rcx,%r10)
movl %r12d, %r11d
shrl $0xe, %r11d
orb $0x1, %r11b
movb %r11b, 0x2(%rcx,%r10)
movl %r12d, %r11d
shrl $0x7, %r11d
movb %r11b, 0x3(%rcx,%r10)
addb %r12b, %r12b
incb %r12b
movb %r12b, 0x4(%rcx,%r10)
cmpl $0xa9, %r10d
ja 0x16de
movb -0x2(%rcx,%r10), %r9b
cmpb $-0x40, %r9b
jb 0x16de
movl -0x30(%rbp), %r11d
andb $0x10, %r11b
je 0x16de
movb 0x5(%rcx,%r10), %r11b
andb $-0xf, %r11b
cmpb $0x11, %r11b
jne 0x16de
testb $0x1, 0x7(%rcx,%r10)
je 0x16de
testb $0x1, 0x9(%rcx,%r10)
je 0x16de
movzbl 0x5(%rcx,%r10), %r11d
movq %r11, -0x30(%rbp)
movzbl 0x6(%rcx,%r10), %r11d
movzbl 0x7(%rcx,%r10), %r12d
movq %r12, -0x40(%rbp)
movzbl 0x8(%rcx,%r10), %r12d
movq %r12, -0x48(%rbp)
movzbl 0x9(%rcx,%r10), %r12d
movq %r12, -0x50(%rbp)
movb %r9b, -0x2(%rcx,%r10)
cmpb $0x9, -0x1(%rcx,%r10)
ja 0x1648
movb $0xa, -0x1(%rcx,%r10)
movq -0x30(%rbp), %r9
andl $0xe, %r9d
shlq $0x1d, %r9
movq %r9, -0x30(%rbp)
shll $0x16, %r11d
movq -0x40(%rbp), %r9
andl $-0x2, %r9d
shll $0xe, %r9d
movq -0x48(%rbp), %r12
shll $0x7, %r12d
addq %r9, %r12
movq -0x50(%rbp), %r9
shrl %r9d
addq %rsi, %r11
addq -0x30(%rbp), %r11
addq %r12, %r11
addq %r9, %r11
movb (%rcx,%r10), %r12b
andb $0xf, %r12b
orb $0x30, %r12b
movb %r12b, (%rcx,%r10)
movq %r11, %r12
shrq $0x1d, %r12
andb $0xe, %r12b
orb $0x11, %r12b
movb %r12b, 0x5(%rcx,%r10)
movl %r11d, %r12d
shrl $0x16, %r12d
movb %r12b, 0x6(%rcx,%r10)
movl %r11d, %r12d
shrl $0xe, %r12d
orb $0x1, %r12b
movb %r12b, 0x7(%rcx,%r10)
movl %r11d, %r12d
shrl $0x7, %r12d
movb %r12b, 0x8(%rcx,%r10)
addb %r11b, %r11b
incb %r11b
movb %r11b, 0x9(%rcx,%r10)
addq %r13, %rcx
addq %r13, %rdi
cmpq %rax, %rdi
jb 0x12ea
movl $0x1, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1050
cmpq $-0x1, %rax
jne 0x1711
callq 0x1030
cmpl $0xb, (%rax)
jne 0x1211
movq %r14, %rsp
jmp 0x124a
xorl %edi, %edi
callq 0x10a0