#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 */
typedef int u_short;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
unsigned int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memcpy(int *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned long long *, int /*<<< orphan*/, int);
int ntohs(int);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int fd_ts;
  u_short pid;
  int byte_read;
  unsigned int pcr_ext = 0;
  unsigned int ibits = 0;
  unsigned long long int pcr_base = 0;
  unsigned long long int ts_packet_count;
  unsigned long long int new_pcr = 0;
  unsigned long long int new_pcr_index = 0;
  unsigned long long int pid_pcr_table[8192];
  unsigned long long int pid_pcr_index_table[8192];
  unsigned char ts_packet[188];
  if (argc == 3)
    fd_ts = open(argv[1], O_RDONLY);
  else {
    fprintf(stderr, "Usage: 'tspcrmeasure input.ts expected_bit/s'\n");
    return 2;
  }
  if (fd_ts < 0) {
    fprintf(stderr, "Can't find file %s\n", argv[1]);
    return 2;
  }
  ibits = atoi(argv[2]);
  if (ibits == 0) {
    fprintf(stderr, "Expected bit/s is zero\n");
    return 2;
  }
  memset(pid_pcr_table, 0, 8192 * (sizeof(unsigned long long int)));
  memset(pid_pcr_index_table, 0, 8192 * (sizeof(unsigned long long int)));
  ts_packet_count = 0;
  byte_read = 1;
  while (byte_read) {
    byte_read = read(fd_ts, ts_packet, 188);
    memcpy(&pid, ts_packet + 1, 2);
    pid = ntohs(pid);
    pid = pid & 0x1fff;
    if (pid < 8192) {
      if ((ts_packet[3] & 0x20) && (ts_packet[4] != 0) &&
          (ts_packet[5] & 0x10)) {
        pcr_base = (((unsigned long long int)ts_packet[6]) << 25) +
                   (ts_packet[7] << 17) + (ts_packet[8] << 9) +
                   (ts_packet[9] << 1) + (ts_packet[10] >> 7);
        pcr_ext = ((ts_packet[10] & 1) << 8) + ts_packet[11];
        if (pid_pcr_table[pid] == 0) {
          pid_pcr_table[pid] = pcr_base * 300 + pcr_ext;
          pid_pcr_index_table[pid] = (ts_packet_count * 188) + 10;
          fprintf(stdout, "%llu: pid %d, new pcr is %llu (%f sec)\n",
                  pid_pcr_index_table[pid], pid, pid_pcr_table[pid],
                  ((double)(pid_pcr_table[pid]) / 27000000));
        } else {
          new_pcr = pcr_base * 300 + pcr_ext;
          new_pcr_index = (ts_packet_count * 188) + 10;
          fprintf(stdout,
                  "%llu: pid %d, new pcr is %llu (%f sec), pcr delta is %llu, "
                  "(%f ms), indices delta is %llu bytes,( %f ms), pcr accuracy "
                  "is %.10f, instant ts bit rate is %.10f\n",
                  new_pcr_index, pid, new_pcr, ((double)(new_pcr) / 27000000),
                  new_pcr - pid_pcr_table[pid],
                  ((double)((new_pcr - pid_pcr_table[pid]) * 1000)) / 27000000,
                  new_pcr_index - pid_pcr_index_table[pid],
                  ((double)((new_pcr_index - pid_pcr_index_table[pid]) * 8 *
                            1000)) /
                      ibits,
                  (((double)(new_pcr - pid_pcr_table[pid])) / 27000000) -
                      (((double)(new_pcr_index - pid_pcr_index_table[pid])) *
                       8 / ibits),
                  (((double)(new_pcr_index - pid_pcr_index_table[pid])) * 8 *
                   27000000) /
                      ((double)(new_pcr - pid_pcr_table[pid])));
          pid_pcr_table[pid] = new_pcr;
          pid_pcr_index_table[pid] = new_pcr_index;
        }
      }
      ts_packet_count++;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    11d7 <main+0x67>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
jmp    11fa <main+0x8a>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    15d5 <main+0x465>
cmpl   $0x0,-0x14(%rbp)
jge    122f <main+0xbf>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    15d5 <main+0x465>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    126c <main+0xfc>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    15d5 <main+0x465>
lea    -0x10050(%rbp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1030 <memset@plt>
lea    -0x20050(%rbp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1030 <memset@plt>
movq   $0x0,-0x38(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     15ce <main+0x45e>
mov    -0x14(%rbp),%edi
lea    -0x20110(%rbp),%rsi
mov    $0xbc,%edx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x20110(%rbp),%rsi
add    $0x1,%rsi
lea    -0x18(%rbp),%rdi
mov    $0x2,%edx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%edi
call   1070 <ntohs@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x1fff,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x2000,-0x18(%rbp)
jge    15c9 <main+0x459>
movzbl -0x2010d(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     15bd <main+0x44d>
movzbl -0x2010c(%rbp),%eax
cmp    $0x0,%eax
je     15bd <main+0x44d>
movzbl -0x2010b(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     15bd <main+0x44d>
movzbl -0x2010a(%rbp),%eax
shl    $0x19,%rax
movzbl -0x20109(%rbp),%ecx
shl    $0x11,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
movzbl -0x20108(%rbp),%ecx
shl    $0x9,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
movzbl -0x20107(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
movzbl -0x20106(%rbp),%ecx
sar    $0x7,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
movzbl -0x20106(%rbp),%eax
and    $0x1,%eax
shl    $0x8,%eax
movzbl -0x20105(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
movslq -0x18(%rbp),%rax
cmpq   $0x0,-0x10050(%rbp,%rax,8)
jne    144c <main+0x2dc>
mov    -0x30(%rbp),%rax
imul   $0x12c,%rax,%rcx
mov    -0x20(%rbp),%eax
add    %rax,%rcx
movslq -0x18(%rbp),%rax
mov    %rcx,-0x10050(%rbp,%rax,8)
ff
mov    -0x38(%rbp),%rax
imul   $0xbc,%rax,%rcx
add    $0xa,%rcx
movslq -0x18(%rbp),%rax
mov    %rcx,-0x20050(%rbp,%rax,8)
ff
mov    0x2be2(%rip),%rax
mov    (%rax),%edi
movslq -0x18(%rbp),%rax
mov    %eax,%ecx
mov    -0x20050(%rbp,%rax,8),%rdx
ff
mov    -0x10050(%rbp,%rax,8),%r8
ff
movq   %r8,%xmm0
movaps 0xbee(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xbf2(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xbeb(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xc4b(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
jmp    15b8 <main+0x448>
mov    -0x30(%rbp),%rax
imul   $0x12c,%rax,%rax
mov    -0x20(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
imul   $0xbc,%rax,%rax
add    $0xa,%rax
mov    %rax,-0x48(%rbp)
mov    0x2b55(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rdx
movslq -0x18(%rbp),%rax
mov    %eax,%ecx
mov    -0x40(%rbp),%r8
movq   %r8,%xmm0
movaps 0xb68(%rip),%xmm9
punpckldq %xmm9,%xmm0
movapd 0xb6b(%rip),%xmm7
subpd  %xmm7,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xb64(%rip),%xmm6
divsd  %xmm6,%xmm0
mov    -0x10050(%rbp,%rax,8),%rsi
ff
mov    %r8,%r9
sub    %rsi,%r9
imul   $0x3e8,%r9,%rsi
movq   %rsi,%xmm1
punpckldq %xmm9,%xmm1
subpd  %xmm7,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm6,%xmm1
mov    -0x20050(%rbp,%rax,8),%rsi
ff
mov    %rdx,%rax
sub    %rsi,%rax
imul   $0x1f40,%rax,%rsi
movq   %rsi,%xmm2
punpckldq %xmm9,%xmm2
subpd  %xmm7,%xmm2
movaps %xmm2,%xmm3
unpckhpd %xmm2,%xmm2
addsd  %xmm3,%xmm2
mov    -0x24(%rbp),%esi
cvtsi2sd %rsi,%xmm8
divsd  %xmm8,%xmm2
movq   %r9,%xmm5
punpckldq %xmm9,%xmm5
subpd  %xmm7,%xmm5
movaps %xmm5,%xmm3
unpckhpd %xmm5,%xmm5
addsd  %xmm3,%xmm5
movaps %xmm5,%xmm3
divsd  %xmm6,%xmm3
movq   %rax,%xmm4
punpckldq %xmm9,%xmm4
subpd  %xmm7,%xmm4
movaps %xmm4,%xmm7
unpckhpd %xmm4,%xmm4
addsd  %xmm7,%xmm4
movsd  0xaba(%rip),%xmm7
mulsd  %xmm7,%xmm4
movaps %xmm4,%xmm7
divsd  %xmm8,%xmm7
subsd  %xmm7,%xmm3
mulsd  %xmm6,%xmm4
divsd  %xmm5,%xmm4
lea    0xb26(%rip),%rsi
mov    %rax,(%rsp)
mov    $0x5,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rcx
movslq -0x18(%rbp),%rax
mov    %rcx,-0x10050(%rbp,%rax,8)
ff
mov    -0x48(%rbp),%rcx
movslq -0x18(%rbp),%rax
mov    %rcx,-0x20050(%rbp,%rax,8)
ff
jmp    15bd <main+0x44d>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    12a1 <main+0x131>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x200f8,%rsp
cmp    $0x3,%edi
jne    1478 <main+0x308>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     148e <main+0x31e>
mov    %eax,%r12d
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
test   %eax,%eax
je     14ab <main+0x33b>
mov    %eax,%ebx
lea    0x100f0(%rsp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1030 <memset@plt>
lea    0xf0(%rsp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1030 <memset@plt>
lea    0x31(%rsp),%r14
mov    %ebx,%eax
cvtsi2sd %rax,%xmm0
movapd 0xe07(%rip),%xmm1
movapd %xmm0,0x20(%rsp)
unpcklpd %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
mov    $0xa,%ebx
mov    $0x13880,%r15d
lea    0x30(%rsp),%rbp
jmp    1367 <main+0x1f7>
mov    0x2dab(%rip),%rsi
mov    (%rsi),%edi
movq   %r14,%xmm1
movdqa 0xddc(%rip),%xmm4
punpckldq %xmm4,%xmm1
movapd 0xde0(%rip),%xmm6
subpd  %xmm6,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdd8(%rip),%xmm7
divsd  %xmm7,%xmm0
mov    %r14,%r9
sub    %rdx,%r9
imul   $0x3e8,%r9,%rdx
movq   %rdx,%xmm2
punpckldq %xmm4,%xmm2
subpd  %xmm6,%xmm2
movapd %xmm2,%xmm1
unpckhpd %xmm2,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm7,%xmm1
mov    0xf0(%rsp,%rcx,8),%rdx
mov    %rbx,%rcx
sub    %rdx,%rcx
imul   $0xffffffffffffe0c0,%rdx,%rdx
add    %r15,%rdx
movq   %rdx,%xmm3
punpckldq %xmm4,%xmm3
subpd  %xmm6,%xmm3
movapd %xmm3,%xmm2
unpckhpd %xmm3,%xmm2
addsd  %xmm3,%xmm2
divsd  0x20(%rsp),%xmm2
movq   %r9,%xmm3
punpckldq %xmm4,%xmm3
subpd  %xmm6,%xmm3
movapd %xmm3,%xmm5
unpckhpd %xmm3,%xmm5
addpd  %xmm3,%xmm5
movq   %rcx,%xmm3
punpckldq %xmm4,%xmm3
subpd  %xmm6,%xmm3
movapd %xmm3,%xmm4
unpckhpd %xmm3,%xmm4
addsd  %xmm3,%xmm4
mulsd  0xd41(%rip),%xmm4
movapd %xmm5,%xmm3
unpcklpd %xmm4,%xmm3
divpd  0x10(%rsp),%xmm3
movapd %xmm3,%xmm6
unpckhpd %xmm3,%xmm6
subsd  %xmm6,%xmm3
mulsd  %xmm7,%xmm4
divsd  %xmm5,%xmm4
mov    %rcx,(%rsp)
lea    0xd9f(%rip),%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
mov    %r14,%r8
mov    $0x5,%al
call   1050 <fprintf@plt>
movslq 0xc(%rsp),%rax
mov    %r14,0x100f0(%rsp,%rax,8)
mov    %rbx,0xf0(%rsp,%rax,8)
mov    %rbp,%r14
lea    0x30(%rsp),%rbp
add    $0xbc,%rbx
add    $0x16f300,%r15
test   %r13d,%r13d
je     148a <main+0x31a>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0xbc,%edx
call   1040 <read@plt>
mov    %eax,%r13d
lea    0xc(%rsp),%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1060 <memcpy@plt>
mov    0xc(%rsp),%edi
call   1070 <ntohs@plt>
and    $0x1fff,%eax
mov    %eax,0xc(%rsp)
testb  $0x20,0x33(%rsp)
je     1350 <main+0x1e0>
cmpb   $0x0,0x34(%rsp)
je     1350 <main+0x1e0>
testb  $0x10,0x35(%rsp)
je     1350 <main+0x1e0>
mov    %r14,%rbp
movzbl 0x36(%rsp),%ecx
shl    $0x19,%rcx
movzbl 0x37(%rsp),%edx
shl    $0x11,%rdx
or     %rcx,%rdx
movzbl 0x38(%rsp),%ecx
shl    $0x9,%rcx
or     %rdx,%rcx
movzbl 0x39(%rsp),%edx
lea    (%rcx,%rdx,2),%rcx
movzbl 0x3a(%rsp),%edx
mov    %rdx,%rsi
shr    $0x7,%rsi
or     %rcx,%rsi
and    $0x1,%edx
shl    $0x8,%rdx
movzbl 0x3b(%rsp),%edi
or     %rdx,%rdi
mov    %eax,%ecx
mov    0x100f0(%rsp,%rcx,8),%rdx
imul   $0x12c,%rsi,%r14
add    %rdi,%r14
test   %rdx,%rdx
jne    121e <main+0xae>
mov    %r14,0x100f0(%rsp,%rcx,8)
mov    %rbx,0xf0(%rsp,%rcx,8)
mov    0x2b9e(%rip),%rcx
mov    (%rcx),%edi
movq   %r14,%xmm1
punpckldq 0xbcf(%rip),%xmm1
subpd  0xbd7(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
divsd  0xbd3(%rip),%xmm0
lea    0xc37(%rip),%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
mov    %r14,%r8
mov    $0x1,%al
call   1050 <fprintf@plt>
jmp    1348 <main+0x1d8>
mov    0x2b59(%rip),%rax
mov    (%rax),%edi
lea    0xbb8(%rip),%rsi
jmp    14bb <main+0x34b>
xor    %eax,%eax
jmp    14c7 <main+0x357>
mov    0x2b43(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xbcd(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    14c2 <main+0x352>
mov    0x2b26(%rip),%rax
mov    (%rax),%edi
lea    0xbc8(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x2,%eax
add    $0x200f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [47 x i8] c"Usage: 'tspcrmeasure input.ts expected_bit/s'\0A\00"
@.str.1 = [20 x i8] c"Can't find file %s\0A\00"
@.str.2 = [24 x i8] c"Expected bit/s is zero\0A\00"
@stdout = global i32 0
@.str.3 = [40 x i8] c"%llu: pid %d, new pcr is %llu (%f sec)\0A\00"
@.str.4 = [159 x i8] c"%llu: pid %d, new pcr is %llu (%f sec), pcr delta is %llu, (%f ms), indices delta is %llu bytes,( %f ms), pcr accuracy is %.10f, instant ts bit rate is %.10f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [8192 x i64]
%5 = alloca [8192 x i64]
%6 = alloca [188 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast [8192 x i64]* %4 to i8*
%9 = bitcast [8192 x i64]* %5 to i8*
%10 = getelementptr inbounds [188 x i8], [188 x i8]* %6, i64 0, i64 0
%11 = icmp eq i32 %0, 3
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 @open(i8* %14, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %21, label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %143
21: ; preds = %12
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %13
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %143
25: ; preds = %12
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = tail call i32 @atoi(i8* %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %143
33: ; preds = %25
%34 = getelementptr inbounds [8192 x i64], [8192 x i64]* %4, i64 0, i64 0
%35 = call i32 @memset(i64* %34, i32 0, i32 65536)
%36 = getelementptr inbounds [8192 x i64], [8192 x i64]* %5, i64 0, i64 0
%37 = call i32 @memset(i64* %36, i32 0, i32 65536)
%38 = getelementptr inbounds [188 x i8], [188 x i8]* %6, i64 0, i64 1
%39 = getelementptr inbounds [188 x i8], [188 x i8]* %6, i64 0, i64 3
%40 = getelementptr inbounds [188 x i8], [188 x i8]* %6, i64 0, i64 4
%41 = getelementptr inbounds [188 x i8], [188 x i8]* %6, i64 0, i64 5
%42 = getelementptr inbounds [188 x i8], [188 x i8]* %6, i64 0, i64 6
%43 = getelementptr inbounds [188 x i8], [188 x i8]* %6, i64 0, i64 7
%44 = getelementptr inbounds [188 x i8], [188 x i8]* %6, i64 0, i64 8
%45 = getelementptr inbounds [188 x i8], [188 x i8]* %6, i64 0, i64 9
%46 = getelementptr inbounds [188 x i8], [188 x i8]* %6, i64 0, i64 10
%47 = getelementptr inbounds [188 x i8], [188 x i8]* %6, i64 0, i64 11
%48 = uitofp i32 %28 to double
%49 = insertelement <2 x double> <double 2.700000e+07, double poison>, double %48, i64 1
br label %50
50: ; preds = %33, %140
%51 = phi i64 [ 0, %33 ], [ %141, %140 ]
%52 = call i32 @read(i32 %16, i8* %10, i32 188)
%53 = call i32 @memcpy(i32* %3, i8* %38, i32 2)
%54 = load i32, i32* %3
%55 = call i32 @ntohs(i32 %54)
%56 = and i32 %55, 8191
store i32 %56, i32* %3
%57 = load i8, i8* %39
%58 = and i8 %57, 32
%59 = icmp ne i8 %58, 0
%60 = load i8, i8* %40
%61 = icmp ne i8 %60, 0
%62 = select i1 %59, i1 %61, i1 false
br i1 %62, label %63, label %140
63: ; preds = %50
%64 = load i8, i8* %41
%65 = and i8 %64, 16
%66 = icmp eq i8 %65, 0
br i1 %66, label %140, label %67
67: ; preds = %63
%68 = load i8, i8* %42
%69 = zext i8 %68 to i64
%70 = shl nuw nsw i64 %69, 25
%71 = load i8, i8* %43
%72 = zext i8 %71 to i64
%73 = shl nuw nsw i64 %72, 17
%74 = or i64 %73, %70
%75 = load i8, i8* %44
%76 = zext i8 %75 to i64
%77 = shl nuw nsw i64 %76, 9
%78 = or i64 %74, %77
%79 = load i8, i8* %45
%80 = zext i8 %79 to i64
%81 = shl nuw nsw i64 %80, 1
%82 = or i64 %78, %81
%83 = load i8, i8* %46
%84 = zext i8 %83 to i32
%85 = lshr i32 %84, 7
%86 = zext i32 %85 to i64
%87 = or i64 %82, %86
%88 = shl nuw nsw i32 %84, 8
%89 = and i32 %88, 256
%90 = load i8, i8* %47
%91 = zext i8 %90 to i32
%92 = or i32 %89, %91
%93 = zext i32 %56 to i64
%94 = getelementptr inbounds [8192 x i64], [8192 x i64]* %4, i64 0, i64 %93
%95 = load i64, i64* %94
%96 = icmp eq i64 %95, 0
%97 = mul nuw nsw i64 %87, 300
%98 = zext i32 %92 to i64
%99 = add i64 %97, %98
br i1 %96, label %100, label %108
100: ; preds = %67
store i64 %99, i64* %94
%101 = mul i64 %51, 188
%102 = add i64 %101, 10
%103 = getelementptr inbounds [8192 x i64], [8192 x i64]* %5, i64 0, i64 %93
store i64 %102, i64* %103
%104 = load i32, i32* @stdout
%105 = uitofp i64 %99 to double
%106 = fdiv double %105, 2.700000e+07
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i64 %102, i32 %56, i64 %99, double %106)
br label %140
108: ; preds = %67
%109 = mul i64 %51, 188
%110 = add i64 %109, 10
%111 = load i32, i32* @stdout
%112 = uitofp i64 %99 to double
%113 = fdiv double %112, 2.700000e+07
%114 = sub i64 %99, %95
%115 = mul i64 %114, 1000
%116 = uitofp i64 %115 to double
%117 = fdiv double %116, 2.700000e+07
%118 = getelementptr inbounds [8192 x i64], [8192 x i64]* %5, i64 0, i64 %93
%119 = load i64, i64* %118
%120 = sub i64 %110, %119
%121 = mul i64 %120, 8000
%122 = uitofp i64 %121 to double
%123 = fdiv double %122, %48
%124 = uitofp i64 %114 to double
%125 = uitofp i64 %120 to double
%126 = fmul double %125, 8.000000e+00
%127 = insertelement <2 x double> poison, double %124, i64 0
%128 = insertelement <2 x double> %127, double %126, i64 1
%129 = fdiv <2 x double> %128, %49
%130 = shufflevector <2 x double> %129, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%131 = fsub <2 x double> %129, %130
%132 = extractelement <2 x double> %131, i64 0
%133 = fmul double %126, 2.700000e+07
%134 = fdiv double %133, %124
%135 = call i32 (i32, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str.4, i64 0, i64 0), i64 %110, i32 %56, i64 %99, double %113, i64 %114, double %117, i64 %120, double %123, double %132, double %134)
%136 = load i32, i32* %3
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds [8192 x i64], [8192 x i64]* %4, i64 0, i64 %137
store i64 %99, i64* %138
%139 = getelementptr inbounds [8192 x i64], [8192 x i64]* %5, i64 0, i64 %137
store i64 %110, i64* %139
br label %140
140: ; preds = %50, %63, %108, %100
%141 = add i64 %51, 1
%142 = icmp eq i32 %52, 0
br i1 %142, label %143, label %50
143: ; preds = %140, %30, %21, %18
%144 = phi i32 [ 2, %21 ], [ 2, %30 ], [ 2, %18 ], [ 0, %140 ]
ret i32 %144
}