// File: /workspace/github_c_makefile_star2_O0/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
subq $0x80, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jg 0x1207
cmpl $0x1, -0x8(%rbp)
jl 0x1207
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xe20(%rip), %rsi       # 0x2004
callq 0x1070
cmpl $0x0, %eax
je 0x1207
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xe0a(%rip), %rsi       # 0x2007
callq 0x1070
cmpl $0x0, %eax
jne 0x1213
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x1560
movl $0xbc, -0x14(%rbp)
cmpl $0x2, -0x8(%rbp)
jne 0x124a
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1090
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x1248
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x1560
jmp 0x124a
jmp 0x124c
movl -0x14(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x20(%rbp)
movq %rax, %rcx
addq $0xf, %rcx
andq $-0x10, %rcx
movq %rsp, %rsi
subq %rcx, %rsi
movq %rsi, -0x60(%rbp)
movq %rsi, %rsp
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %edx
xorl %edi, %edi
callq 0x1060
movq %rax, -0x30(%rbp)
callq 0x15a0
movq %rax, -0x38(%rbp)
cmpq $-0x1, -0x30(%rbp)
jne 0x12bc
callq 0x1030
cmpl $0xb, (%rax)
je 0x12a6
callq 0x1030
cmpl $0xb, (%rax)
jne 0x12b2
movl $0x3, -0x3c(%rbp)
jmp 0x1544
movl $0x1, %edi
callq 0x10a0
cmpq $0x0, -0x30(%rbp)
jne 0x12ca
xorl %edi, %edi
callq 0x10a0
movq -0x60(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x60(%rbp), %rdx
movq -0x48(%rbp), %rcx
movl -0x14(%rbp), %eax
addq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x61(%rbp)
jae 0x12f6
movq -0x48(%rbp), %rdi
callq 0x1600
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x1302
jmp 0x14f8
movq -0x48(%rbp), %rdi
callq 0x1620
testb $0x1, %al
jne 0x1311
jmp 0x133e
movq -0x48(%rbp), %rdi
callq 0x1650
movzbl %al, %eax
cmpl $0x0, %eax
je 0x133e
movq -0x48(%rbp), %rdi
callq 0x1670
testb $0x1, %al
jne 0x1331
jmp 0x133e
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x16a0
movq -0x48(%rbp), %rdi
callq 0x1620
movb %al, %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
addl $0x4, %eax
movl %eax, -0x68(%rbp)
movq -0x48(%rbp), %rdi
callq 0x1650
movb %al, %cl
movl -0x68(%rbp), %eax
movzbl %cl, %ecx
addl %ecx, %eax
movw %ax, -0x4a(%rbp)
movq -0x48(%rbp), %rdi
callq 0x1810
testb $0x1, %al
jne 0x1385
jmp 0x14e5
movq -0x48(%rbp), %rdi
callq 0x1840
testb $0x1, %al
jne 0x1397
jmp 0x14e5
movzwl -0x4a(%rbp), %eax
addl $0xe, %eax
cmpl $0xbc, %eax
jg 0x14e5
movq -0x48(%rbp), %rdi
movzwl -0x4a(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x1870
testb $0x1, %al
jne 0x13c4
jmp 0x14e5
movq -0x48(%rbp), %rdi
movzwl -0x4a(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x18d0
movzbl %al, %eax
cmpl $0xbf, %eax
je 0x14e5
movq -0x48(%rbp), %rdi
movzwl -0x4a(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x18f0
testb $0x1, %al
jne 0x13ff
jmp 0x14e5
movq -0x48(%rbp), %rdi
movzwl -0x4a(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x1920
testb $0x1, %al
jne 0x141a
jmp 0x14e5
movq -0x48(%rbp), %rdi
movzwl -0x4a(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x1950
testb $0x1, %al
jne 0x1435
jmp 0x14e5
movq -0x48(%rbp), %rax
movzwl -0x4a(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rdi
movzwl -0x4a(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x1ab0
movq %rax, %rdi
callq 0x1a80
movq -0x70(%rbp), %rdi
movq %rax, %rsi
callq 0x19a0
movzwl -0x4a(%rbp), %eax
addl $0x13, %eax
cmpl $0xbc, %eax
jg 0x14e3
movq -0x48(%rbp), %rdi
movzwl -0x4a(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x1b20
testb $0x1, %al
jne 0x1493
jmp 0x14e3
movq -0x48(%rbp), %rdi
movzwl -0x4a(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x1b50
testb $0x1, %al
jne 0x14ab
jmp 0x14e3
movq -0x48(%rbp), %rax
movzwl -0x4a(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x48(%rbp), %rdi
movzwl -0x4a(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x1c90
movq %rax, %rdi
callq 0x1a80
movq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x1bc0
jmp 0x14e5
movq -0x48(%rbp), %rax
addq $0xbc, %rax
movq %rax, -0x48(%rbp)
jmp 0x12d2
movq -0x60(%rbp), %rsi
movl -0x14(%rbp), %eax
movl %eax, %edx
movl $0x1, %edi
callq 0x1050
movq %rax, -0x58(%rbp)
cmpq $-0x1, -0x58(%rbp)
jne 0x153d
callq 0x1030
cmpl $0xb, (%rax)
je 0x152a
callq 0x1030
cmpl $0xb, (%rax)
jne 0x1533
movl $0x3, -0x3c(%rbp)
jmp 0x1544
movl $0x1, %edi
callq 0x10a0
movl $0x0, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movq %rax, %rsp
movl -0x3c(%rbp), %eax
testl %eax, %eax
je 0x1559
jmp 0x1554
jmp 0x124c
jmp 0x124c
nop