#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;
int /*<<< orphan*/ STDOUT_FILENO;
unsigned int atoi(char *);
unsigned long long atol(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
unsigned char *malloc(unsigned int);
int /*<<< orphan*/ memcpy(int *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned long long *, long long, int);
int ntohs(int);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, unsigned int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int /*<<< orphan*/, unsigned char *, unsigned int);
int main(int argc, char *argv[]) {
  int fd_ts;
  u_short pid;
  int byte_read;
  int pcr_ext = 0;
  unsigned int i;
  unsigned int buffer_size;
  unsigned char *packet_buffer;
  unsigned char *current_packet;
  unsigned long long int trbits = 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_module = 0;
  unsigned long long int pcr_index_rounding = 0;
  unsigned long long int pcr_table[8192];
  unsigned long long int pcr_index_table[8192];
  buffer_size = 0;
  if (argc >= 3)
    fd_ts = open(argv[1], O_RDONLY);
  else {
    fprintf(stderr, "Usage: tspcrstamp input.ts transport_rate_bit/s\n");
    fprintf(stderr, "N.B: this tool will change the pcr values to fix jitter "
                    "after multiplexing\n");
    return 2;
  }
  if (fd_ts < 0) {
    fprintf(stderr, "Can't find file %s\n", argv[1]);
    return 2;
  }
  trbits = atol(argv[2]);
  if (trbits == 0) {
    fprintf(stderr, "transport_rate is 0?\n");
    return 2;
  }
  if (argv[3] != NULL) {
    buffer_size = atoi(argv[3]);
    if (buffer_size == 0) {
      fprintf(stderr, "buffer size is invalid\n");
      return 2;
    }
  } else {
    buffer_size = 1;
  }
  buffer_size *= 188;
  packet_buffer = malloc(buffer_size);
  if (packet_buffer == NULL) {
    fprintf(stderr, "out of memory\n");
    return 2;
  }
  memset(pcr_table, 0ll, 8192 * (sizeof(unsigned long long int)));
  memset(pcr_index_table, 0ll, 8192 * (sizeof(unsigned long long int)));
  ts_packet_count = 0;
  pcr_index_rounding = 0ll;
  byte_read = 1;
  while (byte_read) {
    byte_read = read(fd_ts, packet_buffer, buffer_size);
    for (i = 0; i < buffer_size; i += 188) {
      current_packet = packet_buffer + i;
      memcpy(&pid, current_packet + 1, 2);
      pid = ntohs(pid);
      pid = pid & 0x1fff;
      if ((pid < 8192) && (current_packet[3] & 0x20) &&
          (current_packet[4] != 0) && (current_packet[5] & 0x10)) {
        new_pcr = (ts_packet_count * 188) + 10;
        new_pcr *= 8;
        new_pcr *= 27000000;
        new_pcr /= trbits;
        new_pcr += pcr_index_rounding;
        new_pcr_module = new_pcr % 2576980377600ll;
        pcr_base = new_pcr_module / 300;
        pcr_ext = new_pcr_module % 300;
        current_packet[6] = (0xFF & (pcr_base >> 25));
        current_packet[7] = (0xFF & (pcr_base >> 17));
        current_packet[8] = (0xFF & (pcr_base >> 9));
        current_packet[9] = (0xFF & (pcr_base >> 1));
        current_packet[10] =
            ((0x1 & pcr_base) << 7) | 0x7E | ((0x100 & pcr_ext) >> 8);
        current_packet[11] = (0xFF & pcr_ext);
        if (ts_packet_count * 2 >= 454263790) {
          ts_packet_count = 0;
          pcr_index_rounding = new_pcr;
        }
        if (new_pcr >= 2576980377600ll) {
          ts_packet_count = 0;
          pcr_index_rounding = (new_pcr - 2576980377600ll);
        }
      }
      ts_packet_count++;
    }
    write(STDOUT_FILENO, packet_buffer, buffer_size);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20070,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     1217 <main+0x77>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
jmp    1251 <main+0xb1>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1601 <main+0x461>
cmpl   $0x0,-0x14(%rbp)
jge    1286 <main+0xe6>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1601 <main+0x461>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atol@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12c5 <main+0x125>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1601 <main+0x461>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     1316 <main+0x176>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    1311 <main+0x171>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1601 <main+0x461>
jmp    131d <main+0x17d>
movl   $0x1,-0x28(%rbp)
imul   $0xbc,-0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1361 <main+0x1c1>
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
lea    0xd71(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1601 <main+0x461>
lea    -0x10070(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10000,%edx
call   1040 <memset@plt>
lea    -0x20070(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10000,%edx
call   1040 <memset@plt>
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x68(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     15fa <main+0x45a>
mov    -0x14(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jae    15e0 <main+0x440>
mov    -0x30(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
add    $0x1,%rsi
lea    -0x18(%rbp),%rdi
mov    $0x2,%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%edi
call   1090 <ntohs@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x1fff,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x2000,-0x18(%rbp)
jge    15c4 <main+0x424>
mov    -0x38(%rbp),%rax
movzbl 0x3(%rax),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     15c4 <main+0x424>
mov    -0x38(%rbp),%rax
movzbl 0x4(%rax),%eax
cmp    $0x0,%eax
je     15c4 <main+0x424>
mov    -0x38(%rbp),%rax
movzbl 0x5(%rax),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     15c4 <main+0x424>
imul   $0xbc,-0x50(%rbp),%rax
add    $0xa,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
shl    $0x3,%rax
mov    %rax,-0x58(%rbp)
imul   $0x19bfcc0,-0x58(%rbp),%rax
01
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%rcx
mov    -0x58(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x58(%rbp)
mov    -0x68(%rbp),%rax
add    -0x58(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
movabs $0x25800000000,%rcx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    $0x12c,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x48(%rbp)
mov    -0x60(%rbp),%rax
mov    $0x12c,%ecx
xor    %edx,%edx
div    %rcx
mov    %edx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x48(%rbp),%rax
shr    $0x19,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x48(%rbp),%rax
shr    $0x11,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x48(%rbp),%rax
shr    $0x9,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,0x8(%rax)
mov    -0x48(%rbp),%rax
shr    $0x1,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,0x9(%rax)
mov    -0x48(%rbp),%rax
and    $0x1,%rax
shl    $0x7,%rax
or     $0x7e,%rax
mov    -0x20(%rbp),%ecx
and    $0x100,%ecx
sar    $0x8,%ecx
movslq %ecx,%rcx
or     %rcx,%rax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,0xa(%rax)
mov    -0x20(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,0xb(%rax)
mov    -0x50(%rbp),%rax
shl    $0x1,%rax
cmp    $0x1b1383ee,%rax
jb     158e <main+0x3ee>
movq   $0x0,-0x50(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x68(%rbp)
movabs $0x25800000000,%rax
cmp    %rax,-0x58(%rbp)
jb     15bf <main+0x41f>
movq   $0x0,-0x50(%rbp)
mov    -0x58(%rbp),%rax
movabs $0x25800000000,%rcx
sub    %rcx,%rax
mov    %rax,-0x68(%rbp)
jmp    15c4 <main+0x424>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x24(%rbp),%eax
add    $0xbc,%eax
mov    %eax,-0x24(%rbp)
jmp    13c5 <main+0x225>
mov    0x2a09(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1030 <write@plt>
jmp    13a2 <main+0x202>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20028,%rsp
cmp    $0x3,%edi
jl     1212 <main+0x72>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,0x10(%rsp)
test   %eax,%eax
js     1243 <main+0xa3>
mov    0x10(%rbx),%rdi
call   10a0 <atol@plt>
test   %rax,%rax
je     1268 <main+0xc8>
mov    0x18(%rbx),%rdi
test   %rdi,%rdi
mov    %rax,0x18(%rsp)
je     127a <main+0xda>
call   10c0 <atoi@plt>
test   %eax,%eax
jne    127f <main+0xdf>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
jmp    1232 <main+0x92>
mov    0x2db7(%rip),%rbx
mov    (%rbx),%edi
lea    0xdde(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdff(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%eax
jmp    1465 <main+0x2c5>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe26(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%eax
jmp    1465 <main+0x2c5>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
jmp    1232 <main+0x92>
mov    $0x1,%eax
imul   $0xbc,%eax,%r12d
mov    %r12d,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1477 <main+0x2d7>
mov    %rax,%rbx
lea    0x10020(%rsp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1040 <memset@plt>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1040 <memset@plt>
xor    %r14d,%r14d
xor    %r13d,%r13d
jmp    12ef <main+0x14f>
nopw   0x0(%rax,%rax,1)
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <write@plt>
cmpl   $0x0,0x14(%rsp)
je     1463 <main+0x2c3>
mov    0x10(%rsp),%edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1050 <read@plt>
test   %r12d,%r12d
mov    %eax,0x14(%rsp)
je     12d0 <main+0x130>
xor    %r15d,%r15d
jmp    1330 <main+0x190>
cmp    $0x4b,%rax
cmovae %rdx,%rcx
mov    %rsi,%r13
mov    %rcx,%r14
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13
add    $0xbc,%r15d
cmp    %r12d,%r15d
jae    12d0 <main+0x130>
mov    %r15d,%ebp
lea    (%rbx,%rbp,1),%rsi
add    $0x1,%rsi
lea    0xc(%rsp),%rdi
mov    $0x2,%edx
call   1070 <memcpy@plt>
mov    0xc(%rsp),%edi
call   1090 <ntohs@plt>
and    $0x1fff,%eax
mov    %eax,0xc(%rsp)
testb  $0x20,0x3(%rbx,%rbp,1)
je     1320 <main+0x180>
add    %rbx,%rbp
cmpb   $0x0,0x4(%rbp)
je     1320 <main+0x180>
testb  $0x10,0x5(%rbp)
je     1320 <main+0x180>
mov    %r13,%rax
movabs $0x9746ce800,%rcx
imul   %rcx,%rax
mov    $0x80befc00,%ecx
add    %rcx,%rax
mov    %rax,%rcx
mov    0x18(%rsp),%rsi
or     %rsi,%rcx
shr    $0x20,%rcx
je     13a6 <main+0x206>
xor    %edx,%edx
div    %rsi
mov    %rax,%rcx
jmp    13ac <main+0x20c>
xor    %edx,%edx
div    %esi
mov    %eax,%ecx
add    %r14,%rcx
mov    %rcx,%rax
movabs $0x6d3a06d3a06d3a07,%rdi
06 3a 6d
mul    %rdi
shr    $0x28,%rdx
movabs $0x25800000000,%rax
imul   %rax,%rdx
mov    %rcx,%rsi
sub    %rdx,%rsi
mov    %rsi,%rax
mul    %rdi
mov    %rdx,%rax
shr    $0x20,%rax
mov    %al,0x6(%rbp)
mov    %rdx,%rax
shr    $0x18,%rax
mov    %al,0x7(%rbp)
mov    %rdx,%rax
shr    $0x10,%rax
mov    %al,0x8(%rbp)
mov    %dh,0x9(%rbp)
shr    $0x7,%rdx
imul   $0x12c,%rdx,%rax
sub    %rax,%rsi
shl    $0x7,%edx
mov    %esi,%eax
shr    $0x8,%eax
or     %edx,%eax
or     $0x7e,%al
mov    %al,0xa(%rbp)
mov    %sil,0xb(%rbp)
mov    %r13,%rsi
add    %r13,%rsi
mov    %rcx,%rax
shr    $0x23,%rax
movabs $0xfffffda800000000,%rdx
fd ff ff
add    %rcx,%rdx
cmp    $0x1b1383ee,%rsi
cmovb  %r14,%rcx
mov    $0x0,%esi
cmovae %rsi,%r13
mov    $0x0,%esi
cmp    $0x4b,%eax
jae    130c <main+0x16c>
mov    %r13,%rsi
jmp    130c <main+0x16c>
xor    %eax,%eax
add    $0x20028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b52(%rip),%rax
mov    (%rax),%edi
lea    0xc38(%rip),%rsi
jmp    1232 <main+0x92>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [49 x i8] c"Usage: tspcrstamp input.ts transport_rate_bit/s\0A\00"
@.str.1 = [76 x i8] c"N.B: this tool will change the pcr values to fix jitter after multiplexing\0A\00"
@.str.2 = [20 x i8] c"Can't find file %s\0A\00"
@.str.3 = [22 x i8] c"transport_rate is 0?\0A\00"
@.str.4 = [24 x i8] c"buffer size is invalid\0A\00"
@.str.5 = [15 x i8] c"out of memory\0A\00"
@STDOUT_FILENO = global i32 0
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 i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca [8192 x i64]
%21 = alloca [8192 x i64]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i64 0, i64* %14
store i64 0, i64* %15
store i64 0, i64* %17
store i64 0, i64* %18
store i64 0, i64* %19
store i32 0, i32* %11
%22 = load i32, i32* %4
%23 = icmp sge i32 %22, 3
br i1 %23, label %24, label %30
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_RDONLY
%29 = call i32 @open(i8* %27, i32 %28)
store i32 %29, i32* %6
br label %35
30: ; preds = %2
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %218
35: ; preds = %24
%36 = load i32, i32* %6
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %42)
store i32 2, i32* %3
br label %218
44: ; preds = %35
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i64 @atol(i8* %47)
store i64 %48, i64* %14
%49 = load i64, i64* %14
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %44
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %218
54: ; preds = %44
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 3
%57 = load i8*, i8** %56
%58 = icmp ne i8* %57, null
br i1 %58, label %59, label %70
59: ; preds = %54
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 3
%62 = load i8*, i8** %61
%63 = call i32 @atoi(i8* %62)
store i32 %63, i32* %11
%64 = load i32, i32* %11
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %59
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %3
br label %218
69: ; preds = %59
br label %71
70: ; preds = %54
store i32 1, i32* %11
br label %71
71: ; preds = %70, %69
%72 = load i32, i32* %11
%73 = mul i32 %72, 188
store i32 %73, i32* %11
%74 = load i32, i32* %11
%75 = call i8* @malloc(i32 %74)
store i8* %75, i8** %12
%76 = load i8*, i8** %12
%77 = icmp eq i8* %76, null
br i1 %77, label %78, label %81
78: ; preds = %71
%79 = load i32, i32* @stderr
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %3
br label %218
81: ; preds = %71
%82 = getelementptr inbounds [8192 x i64], [8192 x i64]* %20, i64 0, i64 0
%83 = call i32 @memset(i64* %82, i64 0, i32 65536)
%84 = getelementptr inbounds [8192 x i64], [8192 x i64]* %21, i64 0, i64 0
%85 = call i32 @memset(i64* %84, i64 0, i32 65536)
store i64 0, i64* %16
store i64 0, i64* %19
store i32 1, i32* %8
br label %86
86: ; preds = %212, %81
%87 = load i32, i32* %8
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %217
89: ; preds = %86
%90 = load i32, i32* %6
%91 = load i8*, i8** %12
%92 = load i32, i32* %11
%93 = call i32 @read(i32 %90, i8* %91, i32 %92)
store i32 %93, i32* %8
store i32 0, i32* %10
br label %94
94: ; preds = %209, %89
%95 = load i32, i32* %10
%96 = load i32, i32* %11
%97 = icmp ult i32 %95, %96
br i1 %97, label %98, label %212
98: ; preds = %94
%99 = load i8*, i8** %12
%100 = load i32, i32* %10
%101 = zext i32 %100 to i64
%102 = getelementptr inbounds i8, i8* %99, i64 %101
store i8* %102, i8** %13
%103 = load i8*, i8** %13
%104 = getelementptr inbounds i8, i8* %103, i64 1
%105 = call i32 @memcpy(i32* %7, i8* %104, i32 2)
%106 = load i32, i32* %7
%107 = call i32 @ntohs(i32 %106)
store i32 %107, i32* %7
%108 = load i32, i32* %7
%109 = and i32 %108, 8191
store i32 %109, i32* %7
%110 = load i32, i32* %7
%111 = icmp slt i32 %110, 8192
br i1 %111, label %112, label %206
112: ; preds = %98
%113 = load i8*, i8** %13
%114 = getelementptr inbounds i8, i8* %113, i64 3
%115 = load i8, i8* %114
%116 = zext i8 %115 to i32
%117 = and i32 %116, 32
%118 = icmp ne i32 %117, 0
br i1 %118, label %119, label %206
119: ; preds = %112
%120 = load i8*, i8** %13
%121 = getelementptr inbounds i8, i8* %120, i64 4
%122 = load i8, i8* %121
%123 = zext i8 %122 to i32
%124 = icmp ne i32 %123, 0
br i1 %124, label %125, label %206
125: ; preds = %119
%126 = load i8*, i8** %13
%127 = getelementptr inbounds i8, i8* %126, i64 5
%128 = load i8, i8* %127
%129 = zext i8 %128 to i32
%130 = and i32 %129, 16
%131 = icmp ne i32 %130, 0
br i1 %131, label %132, label %206
132: ; preds = %125
%133 = load i64, i64* %16
%134 = mul i64 %133, 188
%135 = add i64 %134, 10
store i64 %135, i64* %17
%136 = load i64, i64* %17
%137 = mul i64 %136, 8
store i64 %137, i64* %17
%138 = load i64, i64* %17
%139 = mul i64 %138, 27000000
store i64 %139, i64* %17
%140 = load i64, i64* %14
%141 = load i64, i64* %17
%142 = udiv i64 %141, %140
store i64 %142, i64* %17
%143 = load i64, i64* %19
%144 = load i64, i64* %17
%145 = add i64 %144, %143
store i64 %145, i64* %17
%146 = load i64, i64* %17
%147 = urem i64 %146, 2576980377600
store i64 %147, i64* %18
%148 = load i64, i64* %18
%149 = udiv i64 %148, 300
store i64 %149, i64* %15
%150 = load i64, i64* %18
%151 = urem i64 %150, 300
%152 = trunc i64 %151 to i32
store i32 %152, i32* %9
%153 = load i64, i64* %15
%154 = lshr i64 %153, 25
%155 = and i64 255, %154
%156 = trunc i64 %155 to i8
%157 = load i8*, i8** %13
%158 = getelementptr inbounds i8, i8* %157, i64 6
store i8 %156, i8* %158
%159 = load i64, i64* %15
%160 = lshr i64 %159, 17
%161 = and i64 255, %160
%162 = trunc i64 %161 to i8
%163 = load i8*, i8** %13
%164 = getelementptr inbounds i8, i8* %163, i64 7
store i8 %162, i8* %164
%165 = load i64, i64* %15
%166 = lshr i64 %165, 9
%167 = and i64 255, %166
%168 = trunc i64 %167 to i8
%169 = load i8*, i8** %13
%170 = getelementptr inbounds i8, i8* %169, i64 8
store i8 %168, i8* %170
%171 = load i64, i64* %15
%172 = lshr i64 %171, 1
%173 = and i64 255, %172
%174 = trunc i64 %173 to i8
%175 = load i8*, i8** %13
%176 = getelementptr inbounds i8, i8* %175, i64 9
store i8 %174, i8* %176
%177 = load i64, i64* %15
%178 = and i64 1, %177
%179 = shl i64 %178, 7
%180 = or i64 %179, 126
%181 = load i32, i32* %9
%182 = and i32 256, %181
%183 = ashr i32 %182, 8
%184 = sext i32 %183 to i64
%185 = or i64 %180, %184
%186 = trunc i64 %185 to i8
%187 = load i8*, i8** %13
%188 = getelementptr inbounds i8, i8* %187, i64 10
store i8 %186, i8* %188
%189 = load i32, i32* %9
%190 = and i32 255, %189
%191 = trunc i32 %190 to i8
%192 = load i8*, i8** %13
%193 = getelementptr inbounds i8, i8* %192, i64 11
store i8 %191, i8* %193
%194 = load i64, i64* %16
%195 = mul i64 %194, 2
%196 = icmp uge i64 %195, 454263790
br i1 %196, label %197, label %199
197: ; preds = %132
store i64 0, i64* %16
%198 = load i64, i64* %17
store i64 %198, i64* %19
br label %199
199: ; preds = %197, %132
%200 = load i64, i64* %17
%201 = icmp uge i64 %200, 2576980377600
br i1 %201, label %202, label %205
202: ; preds = %199
store i64 0, i64* %16
%203 = load i64, i64* %17
%204 = sub i64 %203, 2576980377600
store i64 %204, i64* %19
br label %205
205: ; preds = %202, %199
br label %206
206: ; preds = %205, %125, %119, %112, %98
%207 = load i64, i64* %16
%208 = add i64 %207, 1
store i64 %208, i64* %16
br label %209
209: ; preds = %206
%210 = load i32, i32* %10
%211 = add i32 %210, 188
store i32 %211, i32* %10
br label %94
212: ; preds = %94
%213 = load i32, i32* @STDOUT_FILENO
%214 = load i8*, i8** %12
%215 = load i32, i32* %11
%216 = call i32 @write(i32 %213, i8* %214, i32 %215)
br label %86
217: ; preds = %86
store i32 0, i32* %3
br label %218
218: ; preds = %217, %78, %66, %51, %38, %30
%219 = load i32, i32* %3
ret i32 %219
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [49 x i8] c"Usage: tspcrstamp input.ts transport_rate_bit/s\0A\00"
@.str.1 = [76 x i8] c"N.B: this tool will change the pcr values to fix jitter after multiplexing\0A\00"
@.str.2 = [20 x i8] c"Can't find file %s\0A\00"
@.str.3 = [22 x i8] c"transport_rate is 0?\0A\00"
@.str.4 = [24 x i8] c"buffer size is invalid\0A\00"
@.str.5 = [15 x i8] c"out of memory\0A\00"
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [8192 x i64]
%5 = alloca [8192 x i64]
%6 = bitcast i32* %3 to i8*
%7 = bitcast [8192 x i64]* %4 to i8*
%8 = bitcast [8192 x i64]* %5 to i8*
%9 = icmp sgt i32 %0, 2
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 ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0))
br label %133
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 %133
25: ; preds = %10
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = tail call i64 @atol(i8* %27)
%29 = icmp eq i64 %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 ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %133
33: ; preds = %25
%34 = getelementptr inbounds i8*, i8** %1, i64 3
%35 = load i8*, i8** %34
%36 = icmp eq i8* %35, null
br i1 %36, label %43, label %37
37: ; preds = %33
%38 = tail call i32 @atoi(i8* %35)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %133
43: ; preds = %33, %37
%44 = phi i32 [ %38, %37 ], [ 1, %33 ]
%45 = mul i32 %44, 188
%46 = tail call i8* @malloc(i32 %45)
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = load i32, i32* @stderr
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %133
51: ; preds = %43
%52 = getelementptr inbounds [8192 x i64], [8192 x i64]* %4, i64 0, i64 0
%53 = call i32 @memset(i64* %52, i64 0, i32 65536)
%54 = getelementptr inbounds [8192 x i64], [8192 x i64]* %5, i64 0, i64 0
%55 = call i32 @memset(i64* %54, i64 0, i32 65536)
%56 = icmp eq i32 %45, 0
br label %57
57: ; preds = %51, %127
%58 = phi i64 [ 0, %51 ], [ %129, %127 ]
%59 = phi i64 [ 0, %51 ], [ %128, %127 ]
%60 = call i32 @read(i32 %14, i8* %46, i32 %45)
br i1 %56, label %127, label %61
61: ; preds = %57, %121
%62 = phi i64 [ %123, %121 ], [ %58, %57 ]
%63 = phi i64 [ %124, %121 ], [ %59, %57 ]
%64 = phi i32 [ %125, %121 ], [ 0, %57 ]
%65 = zext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %46, i64 %65
%67 = getelementptr inbounds i8, i8* %66, i64 1
%68 = call i32 @memcpy(i32* %3, i8* %67, i32 2)
%69 = load i32, i32* %3
%70 = call i32 @ntohs(i32 %69)
%71 = and i32 %70, 8191
store i32 %71, i32* %3
%72 = getelementptr inbounds i8, i8* %66, i64 3
%73 = load i8, i8* %72
%74 = and i8 %73, 32
%75 = icmp eq i8 %74, 0
br i1 %75, label %121, label %76
76: ; preds = %61
%77 = getelementptr inbounds i8, i8* %66, i64 4
%78 = load i8, i8* %77
%79 = icmp eq i8 %78, 0
br i1 %79, label %121, label %80
80: ; preds = %76
%81 = getelementptr inbounds i8, i8* %66, i64 5
%82 = load i8, i8* %81
%83 = and i8 %82, 16
%84 = icmp eq i8 %83, 0
br i1 %84, label %121, label %85
85: ; preds = %80
%86 = mul i64 %63, 40608000000
%87 = add i64 %86, 2160000000
%88 = udiv i64 %87, %28
%89 = add i64 %88, %62
%90 = urem i64 %89, 2576980377600
%91 = udiv i64 %90, 300
%92 = urem i64 %90, 300
%93 = trunc i64 %92 to i8
%94 = lshr i64 %91, 25
%95 = trunc i64 %94 to i8
%96 = getelementptr inbounds i8, i8* %66, i64 6
store i8 %95, i8* %96
%97 = lshr i64 %91, 17
%98 = trunc i64 %97 to i8
%99 = getelementptr inbounds i8, i8* %66, i64 7
store i8 %98, i8* %99
%100 = lshr i64 %91, 9
%101 = trunc i64 %100 to i8
%102 = getelementptr inbounds i8, i8* %66, i64 8
store i8 %101, i8* %102
%103 = lshr i64 %91, 1
%104 = trunc i64 %103 to i8
%105 = getelementptr inbounds i8, i8* %66, i64 9
store i8 %104, i8* %105
%106 = shl nuw nsw i64 %91, 7
%107 = lshr i64 %92, 8
%108 = or i64 %106, %107
%109 = trunc i64 %108 to i8
%110 = or i8 %109, 126
%111 = getelementptr inbounds i8, i8* %66, i64 10
store i8 %110, i8* %111
%112 = getelementptr inbounds i8, i8* %66, i64 11
store i8 %93, i8* %112
%113 = shl i64 %63, 1
%114 = icmp ugt i64 %113, 454263789
%115 = select i1 %114, i64 %89, i64 %62
%116 = icmp ugt i64 %89, 2576980377599
%117 = add i64 %89, -2576980377600
%118 = select i1 %116, i1 true, i1 %114
%119 = select i1 %118, i64 0, i64 %63
%120 = select i1 %116, i64 %117, i64 %115
br label %121
121: ; preds = %85, %80, %76, %61
%122 = phi i64 [ %63, %80 ], [ %63, %76 ], [ %63, %61 ], [ %119, %85 ]
%123 = phi i64 [ %62, %80 ], [ %62, %76 ], [ %62, %61 ], [ %120, %85 ]
%124 = add i64 %122, 1
%125 = add i32 %64, 188
%126 = icmp ult i32 %125, %45
br i1 %126, label %61, label %127
127: ; preds = %121, %57
%128 = phi i64 [ %59, %57 ], [ %124, %121 ]
%129 = phi i64 [ %58, %57 ], [ %123, %121 ]
%130 = load i32, i32* @STDOUT_FILENO
%131 = call i32 @write(i32 %130, i8* %46, i32 %45)
%132 = icmp eq i32 %60, 0
br i1 %132, label %133, label %57
133: ; preds = %127, %48, %40, %30, %21, %16
%134 = phi i32 [ 2, %21 ], [ 2, %30 ], [ 2, %40 ], [ 2, %48 ], [ 2, %16 ], [ 0, %127 ]
ret i32 %134
}