#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ STDOUT_FILENO;
unsigned long long atol(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memcpy(unsigned short *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
unsigned short ntohs(unsigned short);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int /*<<< orphan*/, unsigned char *, int);
int main(int argc, char *argv[]) {
  int fd_ts;
  unsigned short pid;
  int byte_read;
  unsigned long long int pcr_base = 0ll;
  unsigned long long int input_ts_packet_count = 0ll;
  unsigned long long int new_pcr = 0ll;
  unsigned long long int new_pcr_index = 0ll;
  unsigned long long int old_pcr = 0ll;
  unsigned long long int old_pcr_index = 0ll;
  unsigned char null_output_ts_packet[188];
  unsigned char input_ts_packet[4 + 188];
  unsigned long long int ibits = 0ll;
  unsigned long long int obits = 0ll;
  unsigned long long int fcounter = 0ll;
  unsigned long long int ucounter = 0ll;
  unsigned long long int last_ucounter = 0ll;
  unsigned long long int ts_packet_output = 0ll;
  if (argc > 1) {
    fd_ts = open(argv[1], O_RDONLY);
  } else {
    fprintf(stderr, "Usage: 'm2ts2cbrts input.ts [output_bit_rate]'\n");
    fprintf(stderr, "adds empty packets to input.ts to reach uniform "
                    "output_bit/s, default is 48mbps\n");
    return 2;
  }
  if (fd_ts < 0) {
    fprintf(stderr, "Can't find file %s\n", argv[1]);
    return 2;
  }
  if (argc > 2) {
    obits = atol(argv[2]);
    if (obits == 0) {
      fprintf(stderr, "0 output_bit/s?\n");
      return 2;
    }
  } else {
    obits = 48000000L;
  }
  fprintf(stderr, "output bps is %llu\n", obits);
  memset(null_output_ts_packet, 0, 188);
  null_output_ts_packet[0] = 0x47;
  null_output_ts_packet[1] = 0x1F;
  null_output_ts_packet[2] = 0xFF;
  null_output_ts_packet[3] = 0x10;
  fcounter = 0;
  ucounter = 0;
  last_ucounter = 0;
  old_pcr = 0;
  old_pcr_index = 0;
  input_ts_packet_count = 0;
  ibits = obits;
  byte_read = 1;
  while (byte_read) {
    byte_read = read(fd_ts, input_ts_packet, 4 + 188);
    memcpy(&pid, input_ts_packet + 5, 2);
    pid = ntohs(pid);
    pid = pid & 0x1fff;
    if (pid < 8191) {
      pcr_base = (input_ts_packet[0] & 0x3F) << 24;
      pcr_base += input_ts_packet[1] << 16;
      pcr_base += input_ts_packet[2] << 8;
      pcr_base += input_ts_packet[3];
      if (old_pcr_index == 0) {
        old_pcr = pcr_base;
        old_pcr_index = input_ts_packet_count * 188;
        write(STDOUT_FILENO, input_ts_packet + 4, 188);
        input_ts_packet_count++;
      } else {
        new_pcr = pcr_base;
        new_pcr_index = input_ts_packet_count * 188;
        if (new_pcr < old_pcr) {
          new_pcr += 0x40000000;
          ibits = (((double)(new_pcr_index - old_pcr_index)) * 8 * 27000000) /
                  ((double)(new_pcr - old_pcr));
          new_pcr -= 0x40000000;
        } else {
          ibits = (((double)(new_pcr_index - old_pcr_index)) * 8 * 27000000) /
                  ((double)(new_pcr - old_pcr));
        }
        if (ibits > obits) {
          fprintf(stderr,
                  "at %llu: output bit rate %llu is smaller then input bit "
                  "rate %llu\n",
                  new_pcr_index, obits, ibits);
          return 2;
        }
        if (ibits != obits) {
          fcounter += 188 * 8 * obits;
          ucounter = 188 * 8 * ibits;
          while (ucounter + (188 * 8 * ibits) < fcounter) {
            write(STDOUT_FILENO, null_output_ts_packet, 188);
            ts_packet_output++;
            last_ucounter = ucounter;
            ucounter += 188 * 8 * ibits;
            if (last_ucounter > ucounter) {
              last_ucounter = last_ucounter - fcounter;
              fcounter = 0;
              ucounter = last_ucounter + 188 * 8 * ibits;
            }
          }
          fcounter = fcounter - ucounter;
          ucounter = 0;
          last_ucounter = 0;
        }
        write(STDOUT_FILENO, input_ts_packet + 4, 188);
        input_ts_packet_count++;
        old_pcr = new_pcr;
        old_pcr_index = new_pcr_index;
      }
    } else {
      write(STDOUT_FILENO, input_ts_packet + 4, 188);
      input_ts_packet_count++;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x1d8(%rbp)
movq   $0x0,-0x1e0(%rbp)
movq   $0x0,-0x1e8(%rbp)
movq   $0x0,-0x1f0(%rbp)
movq   $0x0,-0x1f8(%rbp)
movq   $0x0,-0x200(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1233 <main+0xb3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
jmp    126d <main+0xed>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1808 <main+0x688>
cmpl   $0x0,-0x14(%rbp)
jge    12a2 <main+0x122>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1808 <main+0x688>
cmpl   $0x2,-0x8(%rbp)
jle    12f6 <main+0x176>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atol@plt>
mov    %rax,-0x1e0(%rbp)
cmpq   $0x0,-0x1e0(%rbp)
jne    12f1 <main+0x171>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1808 <main+0x688>
jmp    1301 <main+0x181>
movq   $0x2dc6c00,-0x1e0(%rbp)
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
mov    -0x1e0(%rbp),%rdx
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0xbc,%edx
call   1040 <memset@plt>
movb   $0x47,-0x110(%rbp)
movb   $0x1f,-0x10f(%rbp)
movb   $0xff,-0x10e(%rbp)
movb   $0x10,-0x10d(%rbp)
movq   $0x0,-0x1e8(%rbp)
movq   $0x0,-0x1f0(%rbp)
movq   $0x0,-0x1f8(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x1e0(%rbp),%rax
mov    %rax,-0x1d8(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1801 <main+0x681>
mov    -0x14(%rbp),%edi
lea    -0x1d0(%rbp),%rsi
mov    $0xc0,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x1d0(%rbp),%rsi
add    $0x5,%rsi
lea    -0x16(%rbp),%rdi
mov    $0x2,%edx
call   1070 <memcpy@plt>
movzwl -0x16(%rbp),%edi
call   1080 <ntohs@plt>
mov    %ax,-0x16(%rbp)
movzwl -0x16(%rbp),%eax
and    $0x1fff,%eax
mov    %ax,-0x16(%rbp)
movzwl -0x16(%rbp),%eax
cmp    $0x1fff,%eax
jge    17d2 <main+0x652>
movzbl -0x1d0(%rbp),%eax
and    $0x3f,%eax
shl    $0x18,%eax
cltq
mov    %rax,-0x28(%rbp)
movzbl -0x1cf(%rbp),%eax
shl    $0x10,%eax
cltq
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
movzbl -0x1ce(%rbp),%eax
shl    $0x8,%eax
cltq
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
movzbl -0x1cd(%rbp),%eax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1497 <main+0x317>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
imul   $0xbc,-0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2b81(%rip),%rax
mov    (%rax),%edi
lea    -0x1d0(%rbp),%rsi
add    $0x4,%rsi
mov    $0xbc,%edx
call   1030 <write@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    17cd <main+0x64d>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
imul   $0xbc,-0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x48(%rbp),%rax
jae    1578 <main+0x3f8>
mov    -0x38(%rbp),%rax
add    $0x40000000,%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x50(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xb22(%rip),%xmm3
punpckldq %xmm3,%xmm0
movapd 0xb26(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xb1f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xb1b(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
mov    -0x48(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xae1(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x1d8(%rbp)
mov    -0x38(%rbp),%rax
sub    $0x40000000,%rax
mov    %rax,-0x38(%rbp)
jmp    1616 <main+0x496>
mov    -0x40(%rbp),%rax
mov    -0x50(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xa71(%rip),%xmm3
punpckldq %xmm3,%xmm0
movapd 0xa75(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xa6e(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xa6a(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
mov    -0x48(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xa30(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x1d8(%rbp)
mov    -0x1d8(%rbp),%rax
cmp    -0x1e0(%rbp),%rax
jbe    165f <main+0x4df>
mov    0x299f(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
mov    -0x1e0(%rbp),%rcx
mov    -0x1d8(%rbp),%r8
lea    0xaa6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1808 <main+0x688>
mov    -0x1d8(%rbp),%rax
cmp    -0x1e0(%rbp),%rax
je     1793 <main+0x613>
imul   $0x5e0,-0x1e0(%rbp),%rax
add    -0x1e8(%rbp),%rax
mov    %rax,-0x1e8(%rbp)
imul   $0x5e0,-0x1d8(%rbp),%rax
mov    %rax,-0x1f0(%rbp)
mov    -0x1f0(%rbp),%rax
imul   $0x5e0,-0x1d8(%rbp),%rcx
add    %rcx,%rax
cmp    -0x1e8(%rbp),%rax
jae    1768 <main+0x5e8>
mov    0x2929(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rsi
mov    $0xbc,%edx
call   1030 <write@plt>
mov    -0x200(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x200(%rbp)
mov    -0x1f0(%rbp),%rax
mov    %rax,-0x1f8(%rbp)
imul   $0x5e0,-0x1d8(%rbp),%rax
add    -0x1f0(%rbp),%rax
mov    %rax,-0x1f0(%rbp)
mov    -0x1f8(%rbp),%rax
cmp    -0x1f0(%rbp),%rax
jbe    1763 <main+0x5e3>
mov    -0x1f8(%rbp),%rax
sub    -0x1e8(%rbp),%rax
mov    %rax,-0x1f8(%rbp)
movq   $0x0,-0x1e8(%rbp)
mov    -0x1f8(%rbp),%rax
imul   $0x5e0,-0x1d8(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x1f0(%rbp)
jmp    169e <main+0x51e>
mov    -0x1e8(%rbp),%rax
sub    -0x1f0(%rbp),%rax
mov    %rax,-0x1e8(%rbp)
movq   $0x0,-0x1f0(%rbp)
movq   $0x0,-0x1f8(%rbp)
mov    0x2856(%rip),%rax
mov    (%rax),%edi
lea    -0x1d0(%rbp),%rsi
add    $0x4,%rsi
mov    $0xbc,%edx
call   1030 <write@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    17fc <main+0x67c>
mov    0x2817(%rip),%rax
mov    (%rax),%edi
lea    -0x1d0(%rbp),%rsi
add    $0x4,%rsi
mov    $0xbc,%edx
call   1030 <write@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    139c <main+0x21c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x200,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1b8,%rsp
cmp    $0x2,%edi
jl     1438 <main+0x2b8>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,0x10(%rsp)
test   %eax,%eax
js     1465 <main+0x2e5>
mov    $0x2dc6c00,%r14d
cmp    $0x3,%ebp
jb     11dd <main+0x5d>
mov    0x10(%rbx),%rdi
call   1090 <atol@plt>
mov    %rax,%r14
test   %rax,%rax
je     14b5 <main+0x335>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xef1(%rip),%rsi
xor    %r12d,%r12d
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xf0(%rsp),%rdi
xor    %esi,%esi
mov    $0xbc,%edx
call   1040 <memset@plt>
movl   $0x10ff1f47,0xf0(%rsp)
47 1f ff 10
mov    %r14,0x28(%rsp)
imul   $0x5e0,%r14,%rax
mov    %rax,0x18(%rsp)
xor    %r15d,%r15d
xor    %ebx,%ebx
xor    %r13d,%r13d
jmp    1268 <main+0xe8>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2da9(%rip),%r14
mov    (%r14),%edi
lea    0x34(%rsp),%rsi
mov    $0xbc,%edx
call   1030 <write@plt>
add    $0x1,%r13
cmpl   $0x0,0x14(%rsp)
je     1461 <main+0x2e1>
mov    0x10(%rsp),%edi
lea    0x30(%rsp),%rsi
mov    $0xc0,%edx
call   1050 <read@plt>
mov    %eax,%ebp
lea    0x6(%rsp),%rdi
lea    0x35(%rsp),%rsi
mov    $0x2,%edx
call   1070 <memcpy@plt>
movzwl 0x6(%rsp),%edi
call   1080 <ntohs@plt>
and    $0x1fff,%eax
mov    %ax,0x6(%rsp)
cmp    $0x1fff,%eax
mov    %ebp,0x14(%rsp)
je     1240 <main+0xc0>
movzbl 0x30(%rsp),%eax
and    $0x3f,%eax
shl    $0x18,%rax
movzbl 0x31(%rsp),%ecx
shl    $0x10,%rcx
or     %rax,%rcx
movzbl 0x32(%rsp),%eax
shl    $0x8,%rax
or     %rcx,%rax
movzbl 0x33(%rsp),%edx
or     %rax,%rdx
imul   $0xbc,%r13,%rcx
test   %r15,%r15
je     139f <main+0x21f>
xor    %eax,%eax
cmp    %rbx,%rdx
setb   %al
mov    %rcx,0x8(%rsp)
sub    %r15,%rcx
movq   %rcx,%xmm1
movdqa 0xcf7(%rip),%xmm2
punpckldq %xmm2,%xmm1
movapd 0xcfb(%rip),%xmm3
subpd  %xmm3,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xcf3(%rip),%xmm0
mulsd  0xcf3(%rip),%xmm0
shl    $0x1e,%rax
sub    %rbx,%rax
add    %rdx,%rax
movq   %rax,%xmm1
punpckldq %xmm2,%xmm1
subpd  %xmm3,%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,%rcx
subsd  0xcc4(%rip),%xmm0
cvttsd2si %xmm0,%r8
sar    $0x3f,%rcx
and    %rcx,%r8
or     %rax,%r8
mov    0x28(%rsp),%rcx
cmp    %r8,%rcx
jb     1482 <main+0x302>
mov    %rdx,%rbx
jne    13b1 <main+0x231>
mov    0x2c5b(%rip),%r14
mov    0x8(%rsp),%r15
jmp    1247 <main+0xc7>
mov    0x2c4a(%rip),%r14
mov    %rcx,%r15
mov    %rdx,%rbx
jmp    1247 <main+0xc7>
mov    %rbx,0x20(%rsp)
add    0x18(%rsp),%r12
imul   $0x5e0,%r8,%r15
imul   $0xbc0,%r8,%rbp
cmp    %r12,%rbp
jae    141c <main+0x29c>
mov    %r15,%rbx
mov    0x2c18(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    (%r14),%edi
lea    0xf0(%rsp),%rsi
mov    $0xbc,%edx
call   1030 <write@plt>
mov    %r15,%rax
sub    %r12,%rax
add    %rbx,%rax
cmp    %rbp,%rbx
mov    $0x0,%ecx
cmova  %rcx,%r12
cmovbe %rbp,%rax
lea    (%rax,%r15,1),%rbp
mov    %rax,%rbx
cmp    %r12,%rbp
jb     13e0 <main+0x260>
jmp    1426 <main+0x2a6>
mov    %r15,%rax
mov    0x2bca(%rip),%r14
sub    %rax,%r12
mov    0x8(%rsp),%r15
mov    0x20(%rsp),%rbx
jmp    1247 <main+0xc7>
mov    0x2b91(%rip),%rbx
mov    (%rbx),%edi
lea    0xbf0(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xc10(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    149e <main+0x31e>
xor    %eax,%eax
jmp    14a3 <main+0x323>
mov    0x2b64(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xc40(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    149e <main+0x31e>
mov    0x2b47(%rip),%rax
mov    (%rax),%edi
lea    0xc60(%rip),%rsi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%eax
add    $0x1b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b14(%rip),%rax
mov    (%rax),%edi
lea    0xc08(%rip),%rsi
jmp    1458 <main+0x2d8>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [48 x i8] c"Usage: 'm2ts2cbrts input.ts [output_bit_rate]'\0A\00"
@.str.1 = [81 x i8] c"adds empty packets to input.ts to reach uniform output_bit/s, default is 48mbps\0A\00"
@.str.2 = [20 x i8] c"Can't find file %s\0A\00"
@.str.3 = [17 x i8] c"0 output_bit/s?\0A\00"
@.str.4 = [20 x i8] c"output bps is %llu\0A\00"
@STDOUT_FILENO = global i32 0
@.str.5 = [67 x i8] c"at %llu: output bit rate %llu is smaller then input bit rate %llu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i16
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca [188 x i8]
%16 = alloca [192 x i8]
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca i64
%21 = alloca i64
%22 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %9
store i64 0, i64* %10
store i64 0, i64* %11
store i64 0, i64* %12
store i64 0, i64* %13
store i64 0, i64* %14
store i64 0, i64* %17
store i64 0, i64* %18
store i64 0, i64* %19
store i64 0, i64* %20
store i64 0, i64* %21
store i64 0, i64* %22
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 1
br i1 %24, label %25, label %31
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = load i32, i32* @O_RDONLY
%30 = call i32 @open(i8* %28, i32 %29)
store i32 %30, i32* %6
br label %36
31: ; preds = %2
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %239
36: ; preds = %25
%37 = load i32, i32* %6
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %43)
store i32 2, i32* %3
br label %239
45: ; preds = %36
%46 = load i32, i32* %4
%47 = icmp sgt i32 %46, 2
br i1 %47, label %48, label %59
48: ; preds = %45
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = call i64 @atol(i8* %51)
store i64 %52, i64* %18
%53 = load i64, i64* %18
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %48
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %239
58: ; preds = %48
br label %60
59: ; preds = %45
store i64 48000000, i64* %18
br label %60
60: ; preds = %59, %58
%61 = load i32, i32* @stderr
%62 = load i64, i64* %18
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i64 %62)
%64 = getelementptr inbounds [188 x i8], [188 x i8]* %15, i64 0, i64 0
%65 = call i32 @memset(i8* %64, i32 0, i32 188)
%66 = getelementptr inbounds [188 x i8], [188 x i8]* %15, i64 0, i64 0
store i8 71, i8* %66
%67 = getelementptr inbounds [188 x i8], [188 x i8]* %15, i64 0, i64 1
store i8 31, i8* %67
%68 = getelementptr inbounds [188 x i8], [188 x i8]* %15, i64 0, i64 2
store i8 -1, i8* %68
%69 = getelementptr inbounds [188 x i8], [188 x i8]* %15, i64 0, i64 3
store i8 16, i8* %69
store i64 0, i64* %19
store i64 0, i64* %20
store i64 0, i64* %21
store i64 0, i64* %13
store i64 0, i64* %14
store i64 0, i64* %10
%70 = load i64, i64* %18
store i64 %70, i64* %17
store i32 1, i32* %8
br label %71
71: ; preds = %237, %60
%72 = load i32, i32* %8
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %238
74: ; preds = %71
%75 = load i32, i32* %6
%76 = getelementptr inbounds [192 x i8], [192 x i8]* %16, i64 0, i64 0
%77 = call i32 @read(i32 %75, i8* %76, i32 192)
store i32 %77, i32* %8
%78 = getelementptr inbounds [192 x i8], [192 x i8]* %16, i64 0, i64 0
%79 = getelementptr inbounds i8, i8* %78, i64 5
%80 = call i32 @memcpy(i16* %7, i8* %79, i32 2)
%81 = load i16, i16* %7
%82 = call zeroext i16 @ntohs(i16 zeroext %81)
store i16 %82, i16* %7
%83 = load i16, i16* %7
%84 = zext i16 %83 to i32
%85 = and i32 %84, 8191
%86 = trunc i32 %85 to i16
store i16 %86, i16* %7
%87 = load i16, i16* %7
%88 = zext i16 %87 to i32
%89 = icmp slt i32 %88, 8191
br i1 %89, label %90, label %230
90: ; preds = %74
%91 = getelementptr inbounds [192 x i8], [192 x i8]* %16, i64 0, i64 0
%92 = load i8, i8* %91
%93 = zext i8 %92 to i32
%94 = and i32 %93, 63
%95 = shl i32 %94, 24
%96 = sext i32 %95 to i64
store i64 %96, i64* %9
%97 = getelementptr inbounds [192 x i8], [192 x i8]* %16, i64 0, i64 1
%98 = load i8, i8* %97
%99 = zext i8 %98 to i32
%100 = shl i32 %99, 16
%101 = sext i32 %100 to i64
%102 = load i64, i64* %9
%103 = add i64 %102, %101
store i64 %103, i64* %9
%104 = getelementptr inbounds [192 x i8], [192 x i8]* %16, i64 0, i64 2
%105 = load i8, i8* %104
%106 = zext i8 %105 to i32
%107 = shl i32 %106, 8
%108 = sext i32 %107 to i64
%109 = load i64, i64* %9
%110 = add i64 %109, %108
store i64 %110, i64* %9
%111 = getelementptr inbounds [192 x i8], [192 x i8]* %16, i64 0, i64 3
%112 = load i8, i8* %111
%113 = zext i8 %112 to i64
%114 = load i64, i64* %9
%115 = add i64 %114, %113
store i64 %115, i64* %9
%116 = load i64, i64* %14
%117 = icmp eq i64 %116, 0
br i1 %117, label %118, label %128
118: ; preds = %90
%119 = load i64, i64* %9
store i64 %119, i64* %13
%120 = load i64, i64* %10
%121 = mul i64 %120, 188
store i64 %121, i64* %14
%122 = load i32, i32* @STDOUT_FILENO
%123 = getelementptr inbounds [192 x i8], [192 x i8]* %16, i64 0, i64 0
%124 = getelementptr inbounds i8, i8* %123, i64 4
%125 = call i32 @write(i32 %122, i8* %124, i32 188)
%126 = load i64, i64* %10
%127 = add i64 %126, 1
store i64 %127, i64* %10
br label %229
128: ; preds = %90
%129 = load i64, i64* %9
store i64 %129, i64* %11
%130 = load i64, i64* %10
%131 = mul i64 %130, 188
store i64 %131, i64* %12
%132 = load i64, i64* %11
%133 = load i64, i64* %13
%134 = icmp ult i64 %132, %133
br i1 %134, label %135, label %152
135: ; preds = %128
%136 = load i64, i64* %11
%137 = add i64 %136, 1073741824
store i64 %137, i64* %11
%138 = load i64, i64* %12
%139 = load i64, i64* %14
%140 = sub i64 %138, %139
%141 = uitofp i64 %140 to double
%142 = fmul double %141, 8.000000e+00
%143 = fmul double %142, 2.700000e+07
%144 = load i64, i64* %11
%145 = load i64, i64* %13
%146 = sub i64 %144, %145
%147 = uitofp i64 %146 to double
%148 = fdiv double %143, %147
%149 = fptoui double %148 to i64
store i64 %149, i64* %17
%150 = load i64, i64* %11
%151 = sub i64 %150, 1073741824
store i64 %151, i64* %11
br label %165
152: ; preds = %128
%153 = load i64, i64* %12
%154 = load i64, i64* %14
%155 = sub i64 %153, %154
%156 = uitofp i64 %155 to double
%157 = fmul double %156, 8.000000e+00
%158 = fmul double %157, 2.700000e+07
%159 = load i64, i64* %11
%160 = load i64, i64* %13
%161 = sub i64 %159, %160
%162 = uitofp i64 %161 to double
%163 = fdiv double %158, %162
%164 = fptoui double %163 to i64
store i64 %164, i64* %17
br label %165
165: ; preds = %152, %135
%166 = load i64, i64* %17
%167 = load i64, i64* %18
%168 = icmp ugt i64 %166, %167
br i1 %168, label %169, label %175
169: ; preds = %165
%170 = load i32, i32* @stderr
%171 = load i64, i64* %12
%172 = load i64, i64* %18
%173 = load i64, i64* %17
%174 = call i32 (i32, i8*, ...) @fprintf(i32 %170, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.5, i64 0, i64 0), i64 %171, i64 %172, i64 %173)
store i32 2, i32* %3
br label %239
175: ; preds = %165
%176 = load i64, i64* %17
%177 = load i64, i64* %18
%178 = icmp ne i64 %176, %177
br i1 %178, label %179, label %220
179: ; preds = %175
%180 = load i64, i64* %18
%181 = mul i64 1504, %180
%182 = load i64, i64* %19
%183 = add i64 %182, %181
store i64 %183, i64* %19
%184 = load i64, i64* %17
%185 = mul i64 1504, %184
store i64 %185, i64* %20
br label %186
186: ; preds = %215, %179
%187 = load i64, i64* %20
%188 = load i64, i64* %17
%189 = mul i64 1504, %188
%190 = add i64 %187, %189
%191 = load i64, i64* %19
%192 = icmp ult i64 %190, %191
br i1 %192, label %193, label %216
193: ; preds = %186
%194 = load i32, i32* @STDOUT_FILENO
%195 = getelementptr inbounds [188 x i8], [188 x i8]* %15, i64 0, i64 0
%196 = call i32 @write(i32 %194, i8* %195, i32 188)
%197 = load i64, i64* %22
%198 = add i64 %197, 1
store i64 %198, i64* %22
%199 = load i64, i64* %20
store i64 %199, i64* %21
%200 = load i64, i64* %17
%201 = mul i64 1504, %200
%202 = load i64, i64* %20
%203 = add i64 %202, %201
store i64 %203, i64* %20
%204 = load i64, i64* %21
%205 = load i64, i64* %20
%206 = icmp ugt i64 %204, %205
br i1 %206, label %207, label %215
207: ; preds = %193
%208 = load i64, i64* %21
%209 = load i64, i64* %19
%210 = sub i64 %208, %209
store i64 %210, i64* %21
store i64 0, i64* %19
%211 = load i64, i64* %21
%212 = load i64, i64* %17
%213 = mul i64 1504, %212
%214 = add i64 %211, %213
store i64 %214, i64* %20
br label %215
215: ; preds = %207, %193
br label %186
216: ; preds = %186
%217 = load i64, i64* %19
%218 = load i64, i64* %20
%219 = sub i64 %217, %218
store i64 %219, i64* %19
store i64 0, i64* %20
store i64 0, i64* %21
br label %220
220: ; preds = %216, %175
%221 = load i32, i32* @STDOUT_FILENO
%222 = getelementptr inbounds [192 x i8], [192 x i8]* %16, i64 0, i64 0
%223 = getelementptr inbounds i8, i8* %222, i64 4
%224 = call i32 @write(i32 %221, i8* %223, i32 188)
%225 = load i64, i64* %10
%226 = add i64 %225, 1
store i64 %226, i64* %10
%227 = load i64, i64* %11
store i64 %227, i64* %13
%228 = load i64, i64* %12
store i64 %228, i64* %14
br label %229
229: ; preds = %220, %118
br label %237
230: ; preds = %74
%231 = load i32, i32* @STDOUT_FILENO
%232 = getelementptr inbounds [192 x i8], [192 x i8]* %16, i64 0, i64 0
%233 = getelementptr inbounds i8, i8* %232, i64 4
%234 = call i32 @write(i32 %231, i8* %233, i32 188)
%235 = load i64, i64* %10
%236 = add i64 %235, 1
store i64 %236, i64* %10
br label %237
237: ; preds = %230, %229
br label %71
238: ; preds = %71
store i32 0, i32* %3
br label %239
239: ; preds = %238, %169, %55, %39, %31
%240 = load i32, i32* %3
ret i32 %240
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [48 x i8] c"Usage: 'm2ts2cbrts input.ts [output_bit_rate]'\0A\00"
@.str.1 = [81 x i8] c"adds empty packets to input.ts to reach uniform output_bit/s, default is 48mbps\0A\00"
@.str.2 = [20 x i8] c"Can't find file %s\0A\00"
@.str.3 = [17 x i8] c"0 output_bit/s?\0A\00"
@.str.4 = [20 x i8] c"output bps is %llu\0A\00"
@STDOUT_FILENO = global i32 0
@.str.5 = [67 x i8] c"at %llu: output bit rate %llu is smaller then input bit rate %llu\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = alloca [188 x i8]
%5 = alloca [192 x i8]
%6 = bitcast i16* %3 to i8*
%7 = getelementptr inbounds [188 x i8], [188 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [192 x i8], [192 x i8]* %5, i64 0, i64 0
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %21, label %25
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
br label %126
21: ; preds = %10
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %11
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %126
25: ; preds = %10
%26 = icmp ugt i32 %0, 2
br i1 %26, label %27, label %35
27: ; preds = %25
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = tail call i64 @atol(i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %126
35: ; preds = %25, %27
%36 = phi i64 [ %30, %27 ], [ 48000000, %25 ]
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i64 %36)
%39 = call i32 @memset(i8* %7, i32 0, i32 188)
store i8 71, i8* %7
%40 = getelementptr inbounds [188 x i8], [188 x i8]* %4, i64 0, i64 1
store i8 31, i8* %40
%41 = getelementptr inbounds [188 x i8], [188 x i8]* %4, i64 0, i64 2
store i8 -1, i8* %41
%42 = getelementptr inbounds [188 x i8], [188 x i8]* %4, i64 0, i64 3
store i8 16, i8* %42
%43 = getelementptr inbounds [192 x i8], [192 x i8]* %5, i64 0, i64 5
%44 = getelementptr inbounds [192 x i8], [192 x i8]* %5, i64 0, i64 1
%45 = getelementptr inbounds [192 x i8], [192 x i8]* %5, i64 0, i64 2
%46 = getelementptr inbounds [192 x i8], [192 x i8]* %5, i64 0, i64 3
%47 = mul i64 %36, 1504
%48 = getelementptr inbounds [192 x i8], [192 x i8]* %5, i64 0, i64 4
br label %49
49: ; preds = %35, %118
%50 = phi i64 [ 0, %35 ], [ %121, %118 ]
%51 = phi i64 [ 0, %35 ], [ %120, %118 ]
%52 = phi i64 [ 0, %35 ], [ %119, %118 ]
%53 = phi i64 [ 0, %35 ], [ %124, %118 ]
%54 = call i32 @read(i32 %14, i8* %8, i32 192)
%55 = call i32 @memcpy(i16* %3, i8* %43, i32 2)
%56 = load i16, i16* %3
%57 = call zeroext i16 @ntohs(i16 zeroext %56)
%58 = and i16 %57, 8191
store i16 %58, i16* %3
%59 = icmp eq i16 %58, 8191
br i1 %59, label %118, label %60
60: ; preds = %49
%61 = load i8, i8* %8
%62 = and i8 %61, 63
%63 = zext i8 %62 to i64
%64 = shl nuw nsw i64 %63, 24
%65 = load i8, i8* %44
%66 = zext i8 %65 to i64
%67 = shl nuw nsw i64 %66, 16
%68 = or i64 %64, %67
%69 = load i8, i8* %45
%70 = zext i8 %69 to i64
%71 = shl nuw nsw i64 %70, 8
%72 = or i64 %68, %71
%73 = load i8, i8* %46
%74 = zext i8 %73 to i64
%75 = or i64 %72, %74
%76 = icmp eq i64 %51, 0
%77 = mul i64 %53, 188
br i1 %76, label %118, label %78
78: ; preds = %60
%79 = icmp ult i64 %75, %52
%80 = sub i64 %77, %51
%81 = uitofp i64 %80 to double
%82 = fmul double %81, 8.000000e+00
%83 = fmul double %82, 2.700000e+07
%84 = select i1 %79, i64 1073741824, i64 0
%85 = sub i64 %84, %52
%86 = add i64 %75, %85
%87 = uitofp i64 %86 to double
%88 = fdiv double %83, %87
%89 = fptoui double %88 to i64
%90 = icmp ult i64 %36, %89
br i1 %90, label %91, label %94
91: ; preds = %78
%92 = load i32, i32* @stderr
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.5, i64 0, i64 0), i64 %77, i64 %36, i64 %89)
br label %126
94: ; preds = %78
%95 = icmp eq i64 %36, %89
br i1 %95, label %118, label %96
96: ; preds = %94
%97 = add i64 %50, %47
%98 = mul i64 %89, 1504
%99 = mul i64 %89, 3008
%100 = icmp ult i64 %99, %97
br i1 %100, label %101, label %114
101: ; preds = %96, %101
%102 = phi i64 [ %112, %101 ], [ %99, %96 ]
%103 = phi i64 [ %111, %101 ], [ %98, %96 ]
%104 = phi i64 [ %110, %101 ], [ %97, %96 ]
%105 = load i32, i32* @STDOUT_FILENO
%106 = call i32 @write(i32 %105, i8* %7, i32 188)
%107 = icmp ugt i64 %103, %102
%108 = sub i64 %98, %104
%109 = add i64 %108, %103
%110 = select i1 %107, i64 0, i64 %104
%111 = select i1 %107, i64 %109, i64 %102
%112 = add i64 %111, %98
%113 = icmp ult i64 %112, %110
br i1 %113, label %101, label %114
114: ; preds = %101, %96
%115 = phi i64 [ %97, %96 ], [ %110, %101 ]
%116 = phi i64 [ %98, %96 ], [ %111, %101 ]
%117 = sub i64 %115, %116
br label %118
118: ; preds = %49, %94, %114, %60
%119 = phi i64 [ %75, %60 ], [ %75, %114 ], [ %75, %94 ], [ %52, %49 ]
%120 = phi i64 [ %77, %60 ], [ %77, %114 ], [ %77, %94 ], [ %51, %49 ]
%121 = phi i64 [ %50, %60 ], [ %117, %114 ], [ %50, %94 ], [ %50, %49 ]
%122 = load i32, i32* @STDOUT_FILENO
%123 = call i32 @write(i32 %122, i8* %48, i32 188)
%124 = add i64 %53, 1
%125 = icmp eq i32 %54, 0
br i1 %125, label %126, label %49
126: ; preds = %118, %91, %32, %21, %16
%127 = phi i32 [ 2, %21 ], [ 2, %32 ], [ 2, %91 ], [ 2, %16 ], [ 0, %118 ]
ret i32 %127
}