#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;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memcpy(unsigned short *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int, 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 open_file;
  int byte_read;
  int fd_ts;
  unsigned short pid;
  unsigned char adaptation_field;
  unsigned char packet[188];
  unsigned char pid_cc_table[8192];
  unsigned char previous_cc_table[8192];
  if (argc >= 2) {
    open_file = 1;
    fd_ts = open(argv[open_file], O_RDONLY);
    if (fd_ts < 0) {
      fprintf(stderr, "Can't find file %s\n", argv[open_file]);
      return 2;
    }
  } else {
    fprintf(stderr,
            "Usage: 'tsloop filename1.ts filename2.ts ... filenameN.ts'\n");
    return 2;
  }
  memset(pid_cc_table, 0x10, 8192);
  memset(previous_cc_table, 0x10, 8192);
  while (1) {
    byte_read = 0;
    byte_read = read(fd_ts, packet, 188);
    if (byte_read < 188) {
      open_file %= argc - 1;
      open_file += 1;
      close(fd_ts);
      memset(previous_cc_table, 0x10, 8192);
      fd_ts = open(argv[open_file], O_RDONLY);
      if (fd_ts < 0) {
        fprintf(stderr, "Can't find file %s\n", argv[open_file]);
        return 2;
      }
      byte_read = read(fd_ts, packet, 188);
      if (byte_read <= 0) {
        return 2;
      }
    }
    memcpy(&pid, packet + 1, 2);
    pid = ntohs(pid);
    pid = pid & 0x1fff;
    if (pid < 8192) {
      if (pid_cc_table[pid] == 0x10) {
        fprintf(stderr, "new pid entry %d\n", pid);
        pid_cc_table[pid] = packet[3] & 0x0f;
        previous_cc_table[pid] = packet[3] & 0x0f;
      } else {
        adaptation_field = (packet[3] & 0x30) >> 4;
        if (adaptation_field == 0x0 || adaptation_field == 0x2) {
          packet[3] = (pid_cc_table[pid] | (packet[3] & 0xf0));
        } else if ((adaptation_field == 0x1) &&
                   ((packet[3] & 0x0f) == previous_cc_table[pid])) {
          packet[3] = (pid_cc_table[pid] | (packet[3] & 0xf0));
          previous_cc_table[pid] = 0x10;
        } else if ((adaptation_field == 0x3) &&
                   ((packet[3] & 0x0f) == previous_cc_table[pid])) {
          packet[3] = (pid_cc_table[pid] | (packet[3] & 0xf0));
          previous_cc_table[pid] = 0x10;
        } else {
          previous_cc_table[pid] = packet[3] & 0x0f;
          pid_cc_table[pid] = (pid_cc_table[pid] + 1) % 0x10;
          packet[3] = (pid_cc_table[pid] | (packet[3] & 0xf0));
        }
      }
    }
    write(STDOUT_FILENO, packet, 188);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1205 <main+0x85>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1200 <main+0x80>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    157b <main+0x3fb>
jmp    1228 <main+0xa8>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    157b <main+0x3fb>
lea    -0x20e0(%rbp),%rdi
mov    $0x10,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
lea    -0x40e0(%rbp),%rdi
mov    $0x10,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0xbc,%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xbc,-0x18(%rbp)
jge    133d <main+0x1bd>
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x14(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
lea    -0x40e0(%rbp),%rdi
mov    $0x10,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d18(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    130b <main+0x18b>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd08(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    157b <main+0x3fb>
mov    -0x1c(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0xbc,%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     1338 <main+0x1b8>
movl   $0x2,-0x4(%rbp)
jmp    157b <main+0x3fb>
jmp    133d <main+0x1bd>
lea    -0xe0(%rbp),%rsi
add    $0x1,%rsi
lea    -0x1e(%rbp),%rdi
mov    $0x2,%edx
call   1080 <memcpy@plt>
movzwl -0x1e(%rbp),%edi
call   1090 <ntohs@plt>
mov    %ax,-0x1e(%rbp)
movzwl -0x1e(%rbp),%eax
and    $0x1fff,%eax
mov    %ax,-0x1e(%rbp)
movzwl -0x1e(%rbp),%eax
cmp    $0x2000,%eax
jge    155c <main+0x3dc>
movzwl -0x1e(%rbp),%eax
movzbl -0x20e0(%rbp,%rax,1),%eax
ff
cmp    $0x10,%eax
jne    13e2 <main+0x262>
mov    0x2c35(%rip),%rax
mov    (%rax),%edi
movzwl -0x1e(%rbp),%edx
lea    0xca8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movzbl -0xdd(%rbp),%eax
and    $0xf,%eax
mov    %al,%cl
movzwl -0x1e(%rbp),%eax
mov    %cl,-0x20e0(%rbp,%rax,1)
movzbl -0xdd(%rbp),%eax
and    $0xf,%eax
mov    %al,%cl
movzwl -0x1e(%rbp),%eax
mov    %cl,-0x40e0(%rbp,%rax,1)
jmp    1557 <main+0x3d7>
movzbl -0xdd(%rbp),%eax
and    $0x30,%eax
sar    $0x4,%eax
mov    %al,-0x1f(%rbp)
movzbl -0x1f(%rbp),%eax
cmp    $0x0,%eax
je     140c <main+0x28c>
movzbl -0x1f(%rbp),%eax
cmp    $0x2,%eax
jne    1432 <main+0x2b2>
movzwl -0x1e(%rbp),%eax
movzbl -0x20e0(%rbp,%rax,1),%eax
ff
movzbl -0xdd(%rbp),%ecx
and    $0xf0,%ecx
or     %ecx,%eax
mov    %al,-0xdd(%rbp)
jmp    1552 <main+0x3d2>
movzbl -0x1f(%rbp),%eax
cmp    $0x1,%eax
jne    148f <main+0x30f>
movzbl -0xdd(%rbp),%eax
and    $0xf,%eax
movzwl -0x1e(%rbp),%ecx
movzbl -0x40e0(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
jne    148f <main+0x30f>
movzwl -0x1e(%rbp),%eax
movzbl -0x20e0(%rbp,%rax,1),%eax
ff
movzbl -0xdd(%rbp),%ecx
and    $0xf0,%ecx
or     %ecx,%eax
mov    %al,-0xdd(%rbp)
movzwl -0x1e(%rbp),%eax
movb   $0x10,-0x40e0(%rbp,%rax,1)
10
jmp    154d <main+0x3cd>
movzbl -0x1f(%rbp),%eax
cmp    $0x3,%eax
jne    14ec <main+0x36c>
movzbl -0xdd(%rbp),%eax
and    $0xf,%eax
movzwl -0x1e(%rbp),%ecx
movzbl -0x40e0(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
jne    14ec <main+0x36c>
movzwl -0x1e(%rbp),%eax
movzbl -0x20e0(%rbp,%rax,1),%eax
ff
movzbl -0xdd(%rbp),%ecx
and    $0xf0,%ecx
or     %ecx,%eax
mov    %al,-0xdd(%rbp)
movzwl -0x1e(%rbp),%eax
movb   $0x10,-0x40e0(%rbp,%rax,1)
10
jmp    1548 <main+0x3c8>
movzbl -0xdd(%rbp),%eax
and    $0xf,%eax
mov    %al,%cl
movzwl -0x1e(%rbp),%eax
mov    %cl,-0x40e0(%rbp,%rax,1)
movzwl -0x1e(%rbp),%eax
movzbl -0x20e0(%rbp,%rax,1),%eax
ff
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %dl,%cl
movzwl -0x1e(%rbp),%eax
mov    %cl,-0x20e0(%rbp,%rax,1)
movzwl -0x1e(%rbp),%eax
movzbl -0x20e0(%rbp,%rax,1),%eax
ff
movzbl -0xdd(%rbp),%ecx
and    $0xf0,%ecx
or     %ecx,%eax
mov    %al,-0xdd(%rbp)
jmp    154d <main+0x3cd>
jmp    1552 <main+0x3d2>
jmp    1557 <main+0x3d7>
jmp    155c <main+0x3dc>
mov    0x2a8d(%rip),%rax
mov    (%rax),%edi
lea    -0xe0(%rbp),%rsi
mov    $0xbc,%edx
call   1030 <write@plt>
jmp    1254 <main+0xd4>
mov    -0x4(%rbp),%eax
add    $0x40e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40d8,%rsp
mov    %edi,0x4(%rsp)
cmp    $0x2,%edi
jl     137c <main+0x1fc>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
test   %eax,%eax
js     1395 <main+0x215>
mov    %eax,%r15d
mov    %rbx,0x8(%rsp)
lea    0x20d0(%rsp),%rdi
mov    $0x10,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
lea    0xd0(%rsp),%rdi
mov    $0x10,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
addl   $0xffffffff,0x4(%rsp)
mov    $0x1,%r14d
lea    0x11(%rsp),%r12
lea    0x10(%rsp),%rbp
lea    0x2(%rsp),%r13
jmp    1257 <main+0xd7>
nopl   (%rax)
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
movzbl 0x13(%rsp),%eax
and    $0xf,%al
movzwl 0x2(%rsp),%ecx
mov    %al,0x20d0(%rsp,%rcx,1)
mov    %al,0xd0(%rsp,%rcx,1)
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rsi
mov    $0xbc,%edx
call   1030 <write@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0xbc,%edx
call   1060 <read@plt>
cmp    $0xbb,%eax
jg     12df <main+0x15f>
mov    %r12,%rbx
mov    %r14d,%eax
cltd
idivl  0x4(%rsp)
mov    %edx,%r14d
movslq %edx,%r12
mov    %r15d,%edi
call   1050 <close@plt>
lea    0xd0(%rsp),%rdi
mov    $0x10,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
mov    0x8(%rsp),%rax
mov    0x8(%rax,%r12,8),%rdi
mov    0x2d31(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
test   %eax,%eax
js     13a4 <main+0x224>
mov    %eax,%r15d
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0xbc,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    13c8 <main+0x248>
mov    %rbx,%r12
add    $0x1,%r14d
mov    %r13,%rdi
mov    %r12,%rsi
mov    $0x2,%edx
call   1080 <memcpy@plt>
movzwl 0x2(%rsp),%edi
call   1090 <ntohs@plt>
movzwl %ax,%edx
and    $0x1fff,%edx
mov    %dx,0x2(%rsp)
movzbl 0x20d0(%rsp,%rdx,1),%eax
cmp    $0x10,%al
je     1210 <main+0x90>
movzbl 0x13(%rsp),%ebx
test   $0x10,%bl
je     136e <main+0x1ee>
mov    %ebx,%ecx
shr    $0x4,%cl
and    $0x3,%cl
cmp    $0x1,%cl
je     1333 <main+0x1b3>
cmp    $0x3,%cl
jne    1357 <main+0x1d7>
mov    %ebx,%ecx
and    $0xf,%cl
cmp    0xd0(%rsp,%rdx,1),%cl
jne    135c <main+0x1dc>
and    $0xf0,%bl
or     %al,%bl
mov    %bl,0x13(%rsp)
movb   $0x10,0xd0(%rsp,%rdx,1)
10
jmp    1241 <main+0xc1>
mov    %ebx,%ecx
and    $0xf,%cl
mov    %cl,0xd0(%rsp,%rdx,1)
add    $0x1,%al
and    $0xf,%al
mov    %al,0x20d0(%rsp,%rdx,1)
and    $0xf0,%bl
or     %al,%bl
mov    %bl,0x13(%rsp)
jmp    1241 <main+0xc1>
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
lea    0xc88(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    13c8 <main+0x248>
mov    0x2c34(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
jmp    13ba <main+0x23a>
add    $0x1,%r12
mov    0x2c21(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rax
mov    (%rax,%r12,8),%rdx
lea    0xc3f(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x2,%eax
add    $0x40d8,%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 = [20 x i8] c"Can't find file %s\0A\00"
@.str.1 = [60 x i8] c"Usage: 'tsloop filename1.ts filename2.ts ... filenameN.ts'\0A\00"
@.str.2 = [18 x i8] c"new pid entry %d\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 i16
%10 = alloca i8
%11 = alloca [188 x i8]
%12 = alloca [8192 x i8]
%13 = alloca [8192 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp sge i32 %14, 2
br i1 %15, label %16, label %35
16: ; preds = %2
store i32 1, i32* %6
%17 = load i8**, i8*** %5
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %16
%27 = load i32, i32* @stderr
%28 = load i8**, i8*** %5
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %32)
store i32 2, i32* %3
br label %255
34: ; preds = %16
br label %38
35: ; preds = %2
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %255
38: ; preds = %34
%39 = getelementptr inbounds [8192 x i8], [8192 x i8]* %12, i64 0, i64 0
%40 = call i32 @memset(i8* %39, i32 16, i32 8192)
%41 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 0
%42 = call i32 @memset(i8* %41, i32 16, i32 8192)
br label %43
43: ; preds = %38, %251
store i32 0, i32* %7
%44 = load i32, i32* %8
%45 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 0
%46 = call i32 @read(i32 %44, i8* %45, i32 188)
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = icmp slt i32 %47, 188
br i1 %48, label %49, label %85
49: ; preds = %43
%50 = load i32, i32* %4
%51 = sub nsw i32 %50, 1
%52 = load i32, i32* %6
%53 = srem i32 %52, %51
store i32 %53, i32* %6
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 1
store i32 %55, i32* %6
%56 = load i32, i32* %8
%57 = call i32 @close(i32 %56)
%58 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 0
%59 = call i32 @memset(i8* %58, i32 16, i32 8192)
%60 = load i8**, i8*** %5
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %60, i64 %62
%64 = load i8*, i8** %63
%65 = load i32, i32* @O_RDONLY
%66 = call i32 @open(i8* %64, i32 %65)
store i32 %66, i32* %8
%67 = load i32, i32* %8
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %77
69: ; preds = %49
%70 = load i32, i32* @stderr
%71 = load i8**, i8*** %5
%72 = load i32, i32* %6
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8*, i8** %71, i64 %73
%75 = load i8*, i8** %74
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %75)
store i32 2, i32* %3
br label %255
77: ; preds = %49
%78 = load i32, i32* %8
%79 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 0
%80 = call i32 @read(i32 %78, i8* %79, i32 188)
store i32 %80, i32* %7
%81 = load i32, i32* %7
%82 = icmp sle i32 %81, 0
br i1 %82, label %83, label %84
83: ; preds = %77
store i32 2, i32* %3
br label %255
84: ; preds = %77
br label %85
85: ; preds = %84, %43
%86 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 0
%87 = getelementptr inbounds i8, i8* %86, i64 1
%88 = call i32 @memcpy(i16* %9, i8* %87, i32 2)
%89 = load i16, i16* %9
%90 = call zeroext i16 @ntohs(i16 zeroext %89)
store i16 %90, i16* %9
%91 = load i16, i16* %9
%92 = zext i16 %91 to i32
%93 = and i32 %92, 8191
%94 = trunc i32 %93 to i16
store i16 %94, i16* %9
%95 = load i16, i16* %9
%96 = zext i16 %95 to i32
%97 = icmp slt i32 %96, 8192
br i1 %97, label %98, label %251
98: ; preds = %85
%99 = load i16, i16* %9
%100 = zext i16 %99 to i64
%101 = getelementptr inbounds [8192 x i8], [8192 x i8]* %12, i64 0, i64 %100
%102 = load i8, i8* %101
%103 = zext i8 %102 to i32
%104 = icmp eq i32 %103, 16
br i1 %104, label %105, label %126
105: ; preds = %98
%106 = load i32, i32* @stderr
%107 = load i16, i16* %9
%108 = zext i16 %107 to i32
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %108)
%110 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%111 = load i8, i8* %110
%112 = zext i8 %111 to i32
%113 = and i32 %112, 15
%114 = trunc i32 %113 to i8
%115 = load i16, i16* %9
%116 = zext i16 %115 to i64
%117 = getelementptr inbounds [8192 x i8], [8192 x i8]* %12, i64 0, i64 %116
store i8 %114, i8* %117
%118 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%119 = load i8, i8* %118
%120 = zext i8 %119 to i32
%121 = and i32 %120, 15
%122 = trunc i32 %121 to i8
%123 = load i16, i16* %9
%124 = zext i16 %123 to i64
%125 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 %124
store i8 %122, i8* %125
br label %250
126: ; preds = %98
%127 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%128 = load i8, i8* %127
%129 = zext i8 %128 to i32
%130 = and i32 %129, 48
%131 = ashr i32 %130, 4
%132 = trunc i32 %131 to i8
store i8 %132, i8* %10
%133 = load i8, i8* %10
%134 = zext i8 %133 to i32
%135 = icmp eq i32 %134, 0
br i1 %135, label %140, label %136
136: ; preds = %126
%137 = load i8, i8* %10
%138 = zext i8 %137 to i32
%139 = icmp eq i32 %138, 2
br i1 %139, label %140, label %153
140: ; preds = %136, %126
%141 = load i16, i16* %9
%142 = zext i16 %141 to i64
%143 = getelementptr inbounds [8192 x i8], [8192 x i8]* %12, i64 0, i64 %142
%144 = load i8, i8* %143
%145 = zext i8 %144 to i32
%146 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%147 = load i8, i8* %146
%148 = zext i8 %147 to i32
%149 = and i32 %148, 240
%150 = or i32 %145, %149
%151 = trunc i32 %150 to i8
%152 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
store i8 %151, i8* %152
br label %249
153: ; preds = %136
%154 = load i8, i8* %10
%155 = zext i8 %154 to i32
%156 = icmp eq i32 %155, 1
br i1 %156, label %157, label %184
157: ; preds = %153
%158 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%159 = load i8, i8* %158
%160 = zext i8 %159 to i32
%161 = and i32 %160, 15
%162 = load i16, i16* %9
%163 = zext i16 %162 to i64
%164 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 %163
%165 = load i8, i8* %164
%166 = zext i8 %165 to i32
%167 = icmp eq i32 %161, %166
br i1 %167, label %168, label %184
168: ; preds = %157
%169 = load i16, i16* %9
%170 = zext i16 %169 to i64
%171 = getelementptr inbounds [8192 x i8], [8192 x i8]* %12, i64 0, i64 %170
%172 = load i8, i8* %171
%173 = zext i8 %172 to i32
%174 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%175 = load i8, i8* %174
%176 = zext i8 %175 to i32
%177 = and i32 %176, 240
%178 = or i32 %173, %177
%179 = trunc i32 %178 to i8
%180 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
store i8 %179, i8* %180
%181 = load i16, i16* %9
%182 = zext i16 %181 to i64
%183 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 %182
store i8 16, i8* %183
br label %248
184: ; preds = %157, %153
%185 = load i8, i8* %10
%186 = zext i8 %185 to i32
%187 = icmp eq i32 %186, 3
br i1 %187, label %188, label %215
188: ; preds = %184
%189 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%190 = load i8, i8* %189
%191 = zext i8 %190 to i32
%192 = and i32 %191, 15
%193 = load i16, i16* %9
%194 = zext i16 %193 to i64
%195 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 %194
%196 = load i8, i8* %195
%197 = zext i8 %196 to i32
%198 = icmp eq i32 %192, %197
br i1 %198, label %199, label %215
199: ; preds = %188
%200 = load i16, i16* %9
%201 = zext i16 %200 to i64
%202 = getelementptr inbounds [8192 x i8], [8192 x i8]* %12, i64 0, i64 %201
%203 = load i8, i8* %202
%204 = zext i8 %203 to i32
%205 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%206 = load i8, i8* %205
%207 = zext i8 %206 to i32
%208 = and i32 %207, 240
%209 = or i32 %204, %208
%210 = trunc i32 %209 to i8
%211 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
store i8 %210, i8* %211
%212 = load i16, i16* %9
%213 = zext i16 %212 to i64
%214 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 %213
store i8 16, i8* %214
br label %247
215: ; preds = %188, %184
%216 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%217 = load i8, i8* %216
%218 = zext i8 %217 to i32
%219 = and i32 %218, 15
%220 = trunc i32 %219 to i8
%221 = load i16, i16* %9
%222 = zext i16 %221 to i64
%223 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 %222
store i8 %220, i8* %223
%224 = load i16, i16* %9
%225 = zext i16 %224 to i64
%226 = getelementptr inbounds [8192 x i8], [8192 x i8]* %12, i64 0, i64 %225
%227 = load i8, i8* %226
%228 = zext i8 %227 to i32
%229 = add nsw i32 %228, 1
%230 = srem i32 %229, 16
%231 = trunc i32 %230 to i8
%232 = load i16, i16* %9
%233 = zext i16 %232 to i64
%234 = getelementptr inbounds [8192 x i8], [8192 x i8]* %12, i64 0, i64 %233
store i8 %231, i8* %234
%235 = load i16, i16* %9
%236 = zext i16 %235 to i64
%237 = getelementptr inbounds [8192 x i8], [8192 x i8]* %12, i64 0, i64 %236
%238 = load i8, i8* %237
%239 = zext i8 %238 to i32
%240 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%241 = load i8, i8* %240
%242 = zext i8 %241 to i32
%243 = and i32 %242, 240
%244 = or i32 %239, %243
%245 = trunc i32 %244 to i8
%246 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
store i8 %245, i8* %246
br label %247
247: ; preds = %215, %199
br label %248
248: ; preds = %247, %168
br label %249
249: ; preds = %248, %140
br label %250
250: ; preds = %249, %105
br label %251
251: ; preds = %250, %85
%252 = load i32, i32* @STDOUT_FILENO
%253 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 0
%254 = call i32 @write(i32 %252, i8* %253, i32 188)
br label %43
255: ; preds = %83, %69, %35, %26
%256 = load i32, i32* %3
ret i32 %256
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"Can't find file %s\0A\00"
@.str.1 = [60 x i8] c"Usage: 'tsloop filename1.ts filename2.ts ... filenameN.ts'\0A\00"
@.str.2 = [18 x i8] c"new pid entry %d\0A\00"
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = alloca [188 x i8]
%5 = alloca [8192 x i8]
%6 = alloca [8192 x i8]
%7 = bitcast i16* %3 to i8*
%8 = getelementptr inbounds [188 x i8], [188 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 0
%11 = icmp sgt i32 %0, 1
br i1 %11, label %12, label %22
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 %18, label %25
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %13
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %114
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
br label %114
25: ; preds = %12
%26 = call i32 @memset(i8* %9, i32 16, i32 8192)
%27 = call i32 @memset(i8* %10, i32 16, i32 8192)
%28 = add nsw i32 %0, -1
%29 = getelementptr inbounds [188 x i8], [188 x i8]* %4, i64 0, i64 1
%30 = getelementptr inbounds [188 x i8], [188 x i8]* %4, i64 0, i64 3
br label %31
31: ; preds = %111, %25
%32 = phi i32 [ 1, %25 ], [ %56, %111 ]
%33 = phi i32 [ %16, %25 ], [ %57, %111 ]
%34 = call i32 @read(i32 %33, i8* %8, i32 188)
%35 = icmp slt i32 %34, 188
br i1 %35, label %36, label %55
36: ; preds = %31
%37 = srem i32 %32, %28
%38 = add nsw i32 %37, 1
%39 = call i32 @close(i32 %33)
%40 = call i32 @memset(i8* %10, i32 16, i32 8192)
%41 = sext i32 %38 to i64
%42 = getelementptr inbounds i8*, i8** %1, i64 %41
%43 = load i8*, i8** %42
%44 = load i32, i32* @O_RDONLY
%45 = call i32 @open(i8* %43, i32 %44)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %36
%48 = getelementptr inbounds i8*, i8** %1, i64 %41
%49 = load i32, i32* @stderr
%50 = load i8*, i8** %48
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %50)
br label %114
52: ; preds = %36
%53 = call i32 @read(i32 %45, i8* %8, i32 188)
%54 = icmp slt i32 %53, 1
br i1 %54, label %114, label %55
55: ; preds = %52, %31
%56 = phi i32 [ %38, %52 ], [ %32, %31 ]
%57 = phi i32 [ %45, %52 ], [ %33, %31 ]
%58 = call i32 @memcpy(i16* %3, i8* %29, i32 2)
%59 = load i16, i16* %3
%60 = call zeroext i16 @ntohs(i16 zeroext %59)
%61 = and i16 %60, 8191
store i16 %61, i16* %3
%62 = zext i16 %61 to i64
%63 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 %62
%64 = load i8, i8* %63
%65 = icmp eq i8 %64, 16
br i1 %65, label %66, label %76
66: ; preds = %55
%67 = zext i16 %61 to i32
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %67)
%70 = load i8, i8* %30
%71 = and i8 %70, 15
%72 = load i16, i16* %3
%73 = zext i16 %72 to i64
%74 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 %73
store i8 %71, i8* %74
%75 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 %73
store i8 %71, i8* %75
br label %111
76: ; preds = %55
%77 = load i8, i8* %30
%78 = and i8 %77, 16
%79 = icmp eq i8 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %76
%81 = and i8 %77, -16
%82 = or i8 %81, %64
store i8 %82, i8* %30
br label %111
83: ; preds = %76
%84 = lshr i8 %77, 4
%85 = and i8 %84, 3
switch i8 %85, label %86 [
i8 1, label %88
i8 3, label %96
]
86: ; preds = %83
%87 = and i8 %77, 15
br label %104
88: ; preds = %83
%89 = and i8 %77, 15
%90 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 %62
%91 = load i8, i8* %90
%92 = icmp eq i8 %89, %91
br i1 %92, label %93, label %104
93: ; preds = %88
%94 = and i8 %77, -16
%95 = or i8 %94, %64
store i8 %95, i8* %30
store i8 16, i8* %90
br label %111
96: ; preds = %83
%97 = and i8 %77, 15
%98 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 %62
%99 = load i8, i8* %98
%100 = icmp eq i8 %97, %99
br i1 %100, label %101, label %104
101: ; preds = %96
%102 = and i8 %77, -16
%103 = or i8 %102, %64
store i8 %103, i8* %30
store i8 16, i8* %98
br label %111
104: ; preds = %86, %88, %96
%105 = phi i8 [ %87, %86 ], [ %89, %88 ], [ %97, %96 ]
%106 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 %62
store i8 %105, i8* %106
%107 = add i8 %64, 1
%108 = and i8 %107, 15
store i8 %108, i8* %63
%109 = and i8 %77, -16
%110 = or i8 %109, %108
store i8 %110, i8* %30
br label %111
111: ; preds = %66, %93, %104, %101, %80
%112 = load i32, i32* @STDOUT_FILENO
%113 = call i32 @write(i32 %112, i8* %8, i32 188)
br label %31
114: ; preds = %52, %47, %22, %18
ret i32 2
}