// File: /workspace/github_c_makefile_star2_O2/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 0x1212
movq 0x8(%rbx), %r14
cmpb $0x2d, (%r14)
jne 0x11e4
cmpb $0x68, 0x1(%r14)
jne 0x11e4
cmpb $0x0, 0x2(%r14)
je 0x1212
leaq 0xe19(%rip), %rsi       # 0x2004
movq %r14, %rdi
callq 0x1070
testl %eax, %eax
je 0x1212
movl $0xbc, %eax
cmpl $0x2, %r15d
jne 0x121a
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1090
testl %eax, %eax
jne 0x121a
movq (%rbx), %rdi
callq 0x16ba
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
leaq 0xf(%rcx), %rax
andq $-0x10, %rax
movq %rax, -0x60(%rbp)
pushq $0x4
popq %rbx
pushq $0x5
popq %r14
movq %rsp, -0x68(%rbp)
movq %rsp, %rsi
subq -0x60(%rbp), %rsi
movq %rsi, %rsp
xorl %edi, %edi
movq %rsi, -0x40(%rbp)
movq -0x38(%rbp), %rdx
callq 0x1060
movq %rax, %r13
pushq $0x1
popq %rdi
leaq -0x78(%rbp), %rsi
callq 0x1040
cmpl $0x16, %eax
jne 0x126f
xorl %edi, %edi
leaq -0x78(%rbp), %rsi
callq 0x1040
imulq $0x9, -0x70(%rbp), %rax
xorl %edx, %edx
movl $0x186a0, %ecx          # imm = 0x186A0
divq %rcx
cmpq $-0x1, %r13
je 0x1698
testq %r13, %r13
je 0x16b3
imulq $0x15f90, -0x78(%rbp), %rcx # imm = 0x15F90
addq %rcx, %rax
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %rdx
addq %rdx, %rcx
movq 0x2dba(%rip), %rdi      # 0x4068
movq 0x2dc3(%rip), %r8       # 0x4078
movq 0x2dc4(%rip), %rsi      # 0x4080
cmpq %rcx, %rdx
jae 0x1682
cmpb $0x47, (%rdx)
jne 0x1682
movb 0x3(%rdx), %r10b
movb 0x4(%rdx), %r9b
testb $0x20, %r10b
jne 0x12e4
movl %ebx, %r11d
jmp 0x1406
testb %r9b, %r9b
je 0x13f0
movb 0x5(%rdx), %r11b
testb $0x10, %r11b
je 0x13f3
movl %r14d, %r12d
movl %ebx, %r14d
movzbl 0x6(%rdx), %r13d
shlq $0x19, %r13
movzbl 0x7(%rdx), %r15d
shll $0x11, %r15d
orq %r13, %r15
movzbl 0x8(%rdx), %r13d
shll $0x9, %r13d
orq %r15, %r13
movzbl 0x9(%rdx), %r15d
leaq (,%r15,2), %r15
addq %r13, %r15
movzbl 0xa(%rdx), %r13d
shrl $0x7, %r13d
orq %r15, %r13
movabsq $0x1ffffffff, %rbx      # imm = 0x1FFFFFFFF
leaq 0x1(%rbx), %r15
cmpq %r15, %rdi
je 0x138b
testb %r11b, %r11b
js 0x1368
movq %r13, %r15
subq %rdi, %r15
andq %rbx, %r15
cmpq $0x2329, %r15           # imm = 0x2329
jb 0x138b
addq %rax, %rdi
addq %r13, %r8
subq %r8, %rdi
addq %rsi, %rdi
movabsq $0x1ffffffff, %rsi      # imm = 0x1FFFFFFFF
andq %rsi, %rdi
movq %rdi, 0x2cf8(%rip)      # 0x4080
movq %rdi, %rsi
movq %r13, 0x2cd6(%rip)      # 0x4068
movq %rax, 0x2cdf(%rip)      # 0x4078
testq %rsi, %rsi
movl %r14d, %ebx
je 0x13f8
leaq (%rsi,%r13), %rdi
movq %rdi, %r8
shrq $0x19, %r8
movb %r8b, 0x6(%rdx)
movl %edi, %r8d
shrl $0x11, %r8d
movb %r8b, 0x7(%rdx)
movl %edi, %r8d
shrl $0x9, %r8d
movb %r8b, 0x8(%rdx)
movl %edi, %r8d
shrl %r8d
movb %r8b, 0x9(%rdx)
shlb $0x7, %dil
orb $0x7e, %dil
movb %dil, 0xa(%rdx)
movb $0x0, 0xb(%rdx)
andb $0x7f, %r11b
movb %r11b, 0x5(%rdx)
movl %r12d, %r14d
movl %r12d, %r11d
jmp 0x1400
xorl %r9d, %r9d
movl %r14d, %r11d
jmp 0x1406
movl %r12d, %r14d
movl %r12d, %r11d
xorl %esi, %esi
movq %rax, %r8
movq %r13, %rdi
testb $0x40, 0x1(%rdx)
je 0x1676
testb $0x10, %r10b
je 0x1676
movl %r11d, %r10d
movzbl %r9b, %r9d
addq %r10, %r9
cmpl $0xae, %r9d
ja 0x1676
cmpb $0x0, (%rdx,%r9)
jne 0x1676
cmpb $0x0, 0x1(%rdx,%r9)
jne 0x1676
cmpb $0x1, 0x2(%rdx,%r9)
jne 0x1676
movb 0x3(%rdx,%r9), %r10b
cmpb $-0x44, %r10b
setb %r11b
cmpb $-0x41, %r10b
sete %r10b
orb %r11b, %r10b
jne 0x1676
movb 0x6(%rdx,%r9), %r10b
andb $-0x40, %r10b
negb %r10b
jno 0x1676
movb 0x7(%rdx,%r9), %r10b
testb %r10b, %r10b
jns 0x1676
movzbl 0x9(%rdx,%r9), %r11d
movl %r11d, %r15d
andb $-0x1f, %r15b
cmpb $0x21, %r15b
jne 0x1676
movzbl 0xb(%rdx,%r9), %r13d
testb $0x1, %r13b
je 0x1676
movzbl 0xd(%rdx,%r9), %r12d
testb $0x1, %r12b
je 0x1676
movb 0x8(%rdx,%r9), %r15b
cmpb $0x4, %r15b
ja 0x14dd
movb $0x5, 0x8(%rdx,%r9)
movb $0x5, %r15b
movb %r15b, -0x29(%rbp)
andl $0xe, %r11d
shlq $0x1d, %r11
movzbl 0xa(%rdx,%r9), %r15d
shll $0x16, %r15d
orq %r11, %r15
andl $-0x2, %r13d
shll $0xe, %r13d
orq %r15, %r13
movzbl 0xc(%rdx,%r9), %r11d
shll $0x7, %r11d
orq %r13, %r11
shrl %r12d
addq %rsi, %r12
addq %r11, %r12
xorl %r13d, %r13d
cmpb $-0x40, %r10b
setae %r13b
movq %r12, %r11
shrq $0x1d, %r11
andl $0xe, %r11d
shll $0x4, %r13d
orl %r11d, %r13d
orb $0x21, %r13b
movb %r13b, 0x9(%rdx,%r9)
movl %r12d, %r11d
shrl $0x16, %r11d
movb %r11b, 0xa(%rdx,%r9)
movl %r12d, %r11d
shrl $0xe, %r11d
orb $0x1, %r11b
movb %r11b, 0xb(%rdx,%r9)
movl %r12d, %r11d
shrl $0x7, %r11d
movb %r11b, 0xc(%rdx,%r9)
addb %r12b, %r12b
incb %r12b
movb %r12b, 0xd(%rdx,%r9)
cmpl $0xa9, %r9d
ja 0x1676
cmpb $-0x40, %r10b
jb 0x1676
movl %r13d, %r11d
andb $0x10, %r11b
je 0x1676
movzbl 0xe(%rdx,%r9), %r11d
movl %r11d, %r15d
andb $-0xf, %r15b
cmpb $0x11, %r15b
jne 0x1676
movzbl 0x10(%rdx,%r9), %r15d
testb $0x1, %r15b
je 0x1676
movzbl 0x12(%rdx,%r9), %r12d
testb $0x1, %r12b
je 0x1676
movq %r12, -0x48(%rbp)
movq %r15, -0x58(%rbp)
movzbl 0xf(%rdx,%r9), %r15d
movzbl 0x11(%rdx,%r9), %r12d
movq %r12, -0x50(%rbp)
movb %r10b, 0x7(%rdx,%r9)
cmpb $0x9, -0x29(%rbp)
ja 0x15f4
movb $0xa, 0x8(%rdx,%r9)
andl $0xe, %r11d
shlq $0x1d, %r11
shll $0x16, %r15d
movq -0x58(%rbp), %r10
andl $-0x2, %r10d
shll $0xe, %r10d
movq -0x50(%rbp), %r12
shll $0x7, %r12d
addq %r10, %r12
movq -0x48(%rbp), %r10
shrl %r10d
addq %rsi, %r15
addq %r11, %r15
addq %r12, %r15
addq %r10, %r15
movb %r13b, 0x9(%rdx,%r9)
movq %r15, %r10
shrq $0x1d, %r10
andb $0xe, %r10b
orb $0x11, %r10b
movb %r10b, 0xe(%rdx,%r9)
movl %r15d, %r10d
shrl $0x16, %r10d
movb %r10b, 0xf(%rdx,%r9)
movl %r15d, %r10d
shrl $0xe, %r10d
orb $0x1, %r10b
movb %r10b, 0x10(%rdx,%r9)
movl %r15d, %r10d
shrl $0x7, %r10d
movb %r10b, 0x11(%rdx,%r9)
addb %r15b, %r15b
incb %r15b
movb %r15b, 0x12(%rdx,%r9)
addq $0xbc, %rdx
jmp 0x12bc
pushq $0x1
popq %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x1050
cmpq $-0x1, %rax
jne 0x16a2
callq 0x1030
cmpl $0xb, (%rax)
jne 0x16ab
movq -0x68(%rbp), %rsp
jmp 0x1233
pushq $0x1
popq %rdi
callq 0x10a0
xorl %edi, %edi
callq 0x10a0