#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*/ 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*/ stdout;
int main(int argc, char *argv[]) {
  int open_file;
  int byte_read;
  int fd_ts;
  unsigned short pid;
  unsigned int adaptation_field;
  unsigned char packet[188];
  unsigned char pid_cc_table[8191];
  unsigned char repeated_cc_table[8191];
  unsigned long long position = 0;
  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: 'tsccc filename.ts '\n");
    fprintf(stderr, "Tsccc check continuity counter errors and warnings\n");
    return 2;
  }
  memset(pid_cc_table, 0x10, 8191);
  memset(repeated_cc_table, 0, 8191);
  while (1) {
    byte_read = 0;
    byte_read = read(fd_ts, packet, 188);
    if (byte_read < 188) {
      return 0;
    }
    memcpy(&pid, packet + 1, 2);
    pid = ntohs(pid);
    pid = pid & 0x1fff;
    if (pid < 8191) {
      adaptation_field = (packet[3] & 0x30) >> 4;
      if (pid_cc_table[pid] == 0x10) {
        fprintf(stderr, "new pid entry %d\n", pid);
      } else {
        if (((pid_cc_table[pid] + 1) % 16) != (packet[3] & 0xF)) {
          if (adaptation_field == 0x0 || adaptation_field == 0x2) {
            ;
          } else if ((adaptation_field == 0x1) &&
                     ((packet[3] & 0x0f) == pid_cc_table[pid]) &&
                     (!repeated_cc_table[pid])) {
            repeated_cc_table[pid] = 1;
          } else if ((adaptation_field == 0x3) &&
                     ((packet[3] & 0x0f) == pid_cc_table[pid]) &&
                     (!repeated_cc_table[pid])) {
            repeated_cc_table[pid] = 1;
          } else {
            fprintf(
                stdout,
                "cc warning at pid %d packet: %llu, expected %d, found %d\n",
                pid, position, ((pid_cc_table[pid] + 1) % 0xF),
                (packet[3] & 0xF));
          }
        }
      }
      pid_cc_table[pid] = packet[3] & 0xF;
    }
    position++;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40f0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x40e8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11f0 <main+0x90>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11eb <main+0x8b>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    147f <main+0x31f>
jmp    122a <main+0xca>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    147f <main+0x31f>
lea    -0x20e0(%rbp),%rdi
mov    $0x10,%esi
mov    $0x1fff,%edx
call   1030 <memset@plt>
lea    -0x40e0(%rbp),%rdi
xor    %esi,%esi
mov    $0x1fff,%edx
call   1030 <memset@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0xbc,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xbc,-0x18(%rbp)
jge    128a <main+0x12a>
movl   $0x0,-0x4(%rbp)
jmp    147f <main+0x31f>
lea    -0xe0(%rbp),%rsi
add    $0x1,%rsi
lea    -0x1e(%rbp),%rdi
mov    $0x2,%edx
call   1060 <memcpy@plt>
movzwl -0x1e(%rbp),%edi
call   1070 <ntohs@plt>
mov    %ax,-0x1e(%rbp)
movzwl -0x1e(%rbp),%eax
and    $0x1fff,%eax
mov    %ax,-0x1e(%rbp)
movzwl -0x1e(%rbp),%eax
cmp    $0x1fff,%eax
jge    1468 <main+0x308>
movzbl -0xdd(%rbp),%eax
and    $0x30,%eax
sar    $0x4,%eax
mov    %eax,-0x24(%rbp)
movzwl -0x1e(%rbp),%eax
movzbl -0x20e0(%rbp,%rax,1),%eax
ff
cmp    $0x10,%eax
jne    1311 <main+0x1b1>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
movzwl -0x1e(%rbp),%edx
lea    0xd60(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1451 <main+0x2f1>
movzwl -0x1e(%rbp),%eax
movzbl -0x20e0(%rbp,%rax,1),%eax
ff
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movzbl -0xdd(%rbp),%eax
and    $0xf,%eax
cmp    %eax,%edx
je     144c <main+0x2ec>
cmpl   $0x0,-0x24(%rbp)
je     134e <main+0x1ee>
cmpl   $0x2,-0x24(%rbp)
jne    1353 <main+0x1f3>
jmp    1447 <main+0x2e7>
cmpl   $0x1,-0x24(%rbp)
jne    139e <main+0x23e>
movzbl -0xdd(%rbp),%eax
and    $0xf,%eax
movzwl -0x1e(%rbp),%ecx
movzbl -0x20e0(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
jne    139e <main+0x23e>
movzwl -0x1e(%rbp),%eax
cmpb   $0x0,-0x40e0(%rbp,%rax,1)
jne    139e <main+0x23e>
movzwl -0x1e(%rbp),%eax
movb   $0x1,-0x40e0(%rbp,%rax,1)
01
jmp    1442 <main+0x2e2>
cmpl   $0x3,-0x24(%rbp)
jne    13e9 <main+0x289>
movzbl -0xdd(%rbp),%eax
and    $0xf,%eax
movzwl -0x1e(%rbp),%ecx
movzbl -0x20e0(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
jne    13e9 <main+0x289>
movzwl -0x1e(%rbp),%eax
cmpb   $0x0,-0x40e0(%rbp,%rax,1)
jne    13e9 <main+0x289>
movzwl -0x1e(%rbp),%eax
movb   $0x1,-0x40e0(%rbp,%rax,1)
01
jmp    143d <main+0x2dd>
mov    0x2be0(%rip),%rax
mov    (%rax),%edi
movzwl -0x1e(%rbp),%eax
mov    %eax,-0x40ec(%rbp)
mov    -0x40e8(%rbp),%rcx
movzwl -0x1e(%rbp),%eax
movzbl -0x20e0(%rbp,%rax,1),%eax
ff
add    $0x1,%eax
mov    $0xf,%esi
cltd
idiv   %esi
mov    %edx,%r8d
mov    -0x40ec(%rbp),%edx
movzbl -0xdd(%rbp),%r9d
ff
and    $0xf,%r9d
lea    0xc41(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1442 <main+0x2e2>
jmp    1447 <main+0x2e7>
jmp    144c <main+0x2ec>
jmp    1451 <main+0x2f1>
movzbl -0xdd(%rbp),%eax
and    $0xf,%eax
mov    %al,%cl
movzwl -0x1e(%rbp),%eax
mov    %cl,-0x20e0(%rbp,%rax,1)
mov    -0x40e8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40e8(%rbp)
jmp    1253 <main+0xf3>
mov    -0x4(%rbp),%eax
add    $0x40f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40d8,%rsp
cmp    $0x2,%edi
jl     132a <main+0x1ca>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     1358 <main+0x1f8>
mov    %eax,%r13d
lea    0x20d0(%rsp),%rdi
mov    $0x10,%esi
mov    $0x1fff,%edx
call   1030 <memset@plt>
lea    0xd0(%rsp),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x1fff,%edx
call   1030 <memset@plt>
lea    0x10(%rsp),%rsi
mov    %r13d,%edi
mov    $0xbc,%edx
call   1040 <read@plt>
cmp    $0xbc,%eax
jl     137c <main+0x21c>
lea    0x11(%rsp),%r14
lea    0xe(%rsp),%r15
lea    0x10(%rsp),%r12
xor    %ebp,%ebp
jmp    124b <main+0xeb>
nopw   0x0(%rax,%rax,1)
mov    0x2dd1(%rip),%rcx
mov    (%rcx),%edi
lea    0xe55(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
movzbl 0x13(%rsp),%eax
and    $0xf,%al
movzwl 0xe(%rsp),%ecx
mov    %al,0x20d0(%rsp,%rcx,1)
add    $0x1,%rbp
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0xbc,%edx
call   1040 <read@plt>
cmp    $0xbb,%eax
jle    137a <main+0x21a>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1060 <memcpy@plt>
movzwl 0xe(%rsp),%edi
call   1070 <ntohs@plt>
and    $0x1fff,%eax
mov    %ax,0xe(%rsp)
cmp    $0x1fff,%eax
je     122c <main+0xcc>
mov    %eax,%esi
movzbl 0x20d0(%rsp,%rsi,1),%edi
cmp    $0x10,%edi
je     1200 <main+0xa0>
movzbl 0x13(%rsp),%edx
test   $0x10,%dl
je     1219 <main+0xb9>
lea    0x1(%rdi),%r8d
mov    %r8d,%ecx
and    $0xf,%ecx
mov    %edx,%ebx
and    $0xf,%ebx
cmp    %ebx,%ecx
je     1219 <main+0xb9>
mov    %edx,%ecx
shr    $0x4,%ecx
and    $0x3,%ecx
cmp    $0x1,%ecx
jne    12ca <main+0x16a>
cmp    %edi,%ebx
jne    12ca <main+0x16a>
cmpb   $0x0,0xd0(%rsp,%rsi,1)
je     131d <main+0x1bd>
and    $0xf,%dl
jmp    12e1 <main+0x181>
and    $0xf,%dl
cmp    $0x3,%ecx
jne    12e1 <main+0x181>
cmp    %dil,%dl
jne    12e1 <main+0x181>
cmpb   $0x0,0xd0(%rsp,%rsi,1)
je     131d <main+0x1bd>
mov    0x2ce8(%rip),%rcx
mov    (%rcx),%edi
imul   $0x8889,%r8d,%ecx
shr    $0x13,%ecx
lea    (%rcx,%rcx,4),%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%r8d
movzwl %r8w,%r8d
movzbl %dl,%r9d
lea    0xd6b(%rip),%rsi
mov    %eax,%edx
mov    %rbp,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1219 <main+0xb9>
movb   $0x1,0xd0(%rsp,%rsi,1)
01
jmp    1219 <main+0xb9>
mov    0x2ca7(%rip),%rbx
mov    (%rbx),%edi
lea    0xcda(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xce7(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x2,%ebp
jmp    137c <main+0x21c>
mov    0x2c79(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xc94(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x2,%ebp
jmp    137c <main+0x21c>
xor    %ebp,%ebp
mov    %ebp,%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 = [29 x i8] c"Usage: 'tsccc filename.ts '\0A\00"
@.str.2 = [52 x i8] c"Tsccc check continuity counter errors and warnings\0A\00"
@.str.3 = [18 x i8] c"new pid entry %d\0A\00"
@stdout = global i32 0
@.str.4 = [58 x i8] c"cc warning at pid %d packet: %llu, expected %d, found %d\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 i16
%10 = alloca i32
%11 = alloca [188 x i8]
%12 = alloca [8191 x i8]
%13 = alloca [8191 x i8]
%14 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %14
%15 = load i32, i32* %4
%16 = icmp sge i32 %15, 2
br i1 %16, label %17, label %36
17: ; preds = %2
store i32 1, i32* %6
%18 = load i8**, i8*** %5
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %17
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %33)
store i32 2, i32* %3
br label %184
35: ; preds = %17
br label %41
36: ; preds = %2
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %184
41: ; preds = %35
%42 = getelementptr inbounds [8191 x i8], [8191 x i8]* %12, i64 0, i64 0
%43 = call i32 @memset(i8* %42, i32 16, i32 8191)
%44 = getelementptr inbounds [8191 x i8], [8191 x i8]* %13, i64 0, i64 0
%45 = call i32 @memset(i8* %44, i32 0, i32 8191)
br label %46
46: ; preds = %41, %181
store i32 0, i32* %7
%47 = load i32, i32* %8
%48 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 0
%49 = call i32 @read(i32 %47, i8* %48, i32 188)
store i32 %49, i32* %7
%50 = load i32, i32* %7
%51 = icmp slt i32 %50, 188
br i1 %51, label %52, label %53
52: ; preds = %46
store i32 0, i32* %3
br label %184
53: ; preds = %46
%54 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 0
%55 = getelementptr inbounds i8, i8* %54, i64 1
%56 = call i32 @memcpy(i16* %9, i8* %55, i32 2)
%57 = load i16, i16* %9
%58 = call zeroext i16 @ntohs(i16 zeroext %57)
store i16 %58, i16* %9
%59 = load i16, i16* %9
%60 = zext i16 %59 to i32
%61 = and i32 %60, 8191
%62 = trunc i32 %61 to i16
store i16 %62, i16* %9
%63 = load i16, i16* %9
%64 = zext i16 %63 to i32
%65 = icmp slt i32 %64, 8191
br i1 %65, label %66, label %181
66: ; preds = %53
%67 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = and i32 %69, 48
%71 = ashr i32 %70, 4
store i32 %71, i32* %10
%72 = load i16, i16* %9
%73 = zext i16 %72 to i64
%74 = getelementptr inbounds [8191 x i8], [8191 x i8]* %12, i64 0, i64 %73
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = icmp eq i32 %76, 16
br i1 %77, label %78, label %83
78: ; preds = %66
%79 = load i32, i32* @stderr
%80 = load i16, i16* %9
%81 = zext i16 %80 to i32
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %81)
br label %172
83: ; preds = %66
%84 = load i16, i16* %9
%85 = zext i16 %84 to i64
%86 = getelementptr inbounds [8191 x i8], [8191 x i8]* %12, i64 0, i64 %85
%87 = load i8, i8* %86
%88 = zext i8 %87 to i32
%89 = add nsw i32 %88, 1
%90 = srem i32 %89, 16
%91 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%92 = load i8, i8* %91
%93 = zext i8 %92 to i32
%94 = and i32 %93, 15
%95 = icmp ne i32 %90, %94
br i1 %95, label %96, label %171
96: ; preds = %83
%97 = load i32, i32* %10
%98 = icmp eq i32 %97, 0
br i1 %98, label %102, label %99
99: ; preds = %96
%100 = load i32, i32* %10
%101 = icmp eq i32 %100, 2
br i1 %101, label %102, label %103
102: ; preds = %99, %96
br label %170
103: ; preds = %99
%104 = load i32, i32* %10
%105 = icmp eq i32 %104, 1
br i1 %105, label %106, label %127
106: ; preds = %103
%107 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%108 = load i8, i8* %107
%109 = zext i8 %108 to i32
%110 = and i32 %109, 15
%111 = load i16, i16* %9
%112 = zext i16 %111 to i64
%113 = getelementptr inbounds [8191 x i8], [8191 x i8]* %12, i64 0, i64 %112
%114 = load i8, i8* %113
%115 = zext i8 %114 to i32
%116 = icmp eq i32 %110, %115
br i1 %116, label %117, label %127
117: ; preds = %106
%118 = load i16, i16* %9
%119 = zext i16 %118 to i64
%120 = getelementptr inbounds [8191 x i8], [8191 x i8]* %13, i64 0, i64 %119
%121 = load i8, i8* %120
%122 = icmp ne i8 %121, 0
br i1 %122, label %127, label %123
123: ; preds = %117
%124 = load i16, i16* %9
%125 = zext i16 %124 to i64
%126 = getelementptr inbounds [8191 x i8], [8191 x i8]* %13, i64 0, i64 %125
store i8 1, i8* %126
br label %169
127: ; preds = %117, %106, %103
%128 = load i32, i32* %10
%129 = icmp eq i32 %128, 3
br i1 %129, label %130, label %151
130: ; preds = %127
%131 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%132 = load i8, i8* %131
%133 = zext i8 %132 to i32
%134 = and i32 %133, 15
%135 = load i16, i16* %9
%136 = zext i16 %135 to i64
%137 = getelementptr inbounds [8191 x i8], [8191 x i8]* %12, i64 0, i64 %136
%138 = load i8, i8* %137
%139 = zext i8 %138 to i32
%140 = icmp eq i32 %134, %139
br i1 %140, label %141, label %151
141: ; preds = %130
%142 = load i16, i16* %9
%143 = zext i16 %142 to i64
%144 = getelementptr inbounds [8191 x i8], [8191 x i8]* %13, i64 0, i64 %143
%145 = load i8, i8* %144
%146 = icmp ne i8 %145, 0
br i1 %146, label %151, label %147
147: ; preds = %141
%148 = load i16, i16* %9
%149 = zext i16 %148 to i64
%150 = getelementptr inbounds [8191 x i8], [8191 x i8]* %13, i64 0, i64 %149
store i8 1, i8* %150
br label %168
151: ; preds = %141, %130, %127
%152 = load i32, i32* @stdout
%153 = load i16, i16* %9
%154 = zext i16 %153 to i32
%155 = load i64, i64* %14
%156 = load i16, i16* %9
%157 = zext i16 %156 to i64
%158 = getelementptr inbounds [8191 x i8], [8191 x i8]* %12, i64 0, i64 %157
%159 = load i8, i8* %158
%160 = zext i8 %159 to i32
%161 = add nsw i32 %160, 1
%162 = srem i32 %161, 15
%163 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%164 = load i8, i8* %163
%165 = zext i8 %164 to i32
%166 = and i32 %165, 15
%167 = call i32 (i32, i8*, ...) @fprintf(i32 %152, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i32 %154, i64 %155, i32 %162, i32 %166)
br label %168
168: ; preds = %151, %147
br label %169
169: ; preds = %168, %123
br label %170
170: ; preds = %169, %102
br label %171
171: ; preds = %170, %83
br label %172
172: ; preds = %171, %78
%173 = getelementptr inbounds [188 x i8], [188 x i8]* %11, i64 0, i64 3
%174 = load i8, i8* %173
%175 = zext i8 %174 to i32
%176 = and i32 %175, 15
%177 = trunc i32 %176 to i8
%178 = load i16, i16* %9
%179 = zext i16 %178 to i64
%180 = getelementptr inbounds [8191 x i8], [8191 x i8]* %12, i64 0, i64 %179
store i8 %177, i8* %180
br label %181
181: ; preds = %172, %53
%182 = load i64, i64* %14
%183 = add i64 %182, 1
store i64 %183, i64* %14
br label %46
184: ; preds = %52, %36, %27
%185 = load i32, i32* %3
ret i32 %185
}

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 = [29 x i8] c"Usage: 'tsccc filename.ts '\0A\00"
@.str.2 = [52 x i8] c"Tsccc check continuity counter errors and warnings\0A\00"
@.str.3 = [18 x i8] c"new pid entry %d\0A\00"
@stdout = global i32 0
@.str.4 = [58 x i8] c"cc warning at pid %d packet: %llu, expected %d, found %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = alloca [188 x i8]
%5 = alloca [8191 x i8]
%6 = alloca [8191 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 [8191 x i8], [8191 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [8191 x i8], [8191 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 %27
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 %103
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
br label %103
27: ; preds = %12
%28 = call i32 @memset(i8* %9, i32 16, i32 8191)
%29 = call i32 @memset(i8* %10, i32 0, i32 8191)
%30 = call i32 @read(i32 %16, i8* %8, i32 188)
%31 = icmp slt i32 %30, 188
br i1 %31, label %103, label %32
32: ; preds = %27
%33 = getelementptr inbounds [188 x i8], [188 x i8]* %4, i64 0, i64 1
%34 = getelementptr inbounds [188 x i8], [188 x i8]* %4, i64 0, i64 3
br label %35
35: ; preds = %32, %99
%36 = phi i64 [ 0, %32 ], [ %100, %99 ]
%37 = call i32 @memcpy(i16* %3, i8* %33, i32 2)
%38 = load i16, i16* %3
%39 = call zeroext i16 @ntohs(i16 zeroext %38)
%40 = and i16 %39, 8191
store i16 %40, i16* %3
%41 = zext i16 %40 to i32
%42 = icmp eq i16 %40, 8191
br i1 %42, label %99, label %43
43: ; preds = %35
%44 = load i8, i8* %34
%45 = zext i8 %44 to i32
%46 = lshr i32 %45, 4
%47 = and i32 %46, 3
%48 = zext i16 %40 to i64
%49 = getelementptr inbounds [8191 x i8], [8191 x i8]* %5, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = icmp eq i8 %50, 16
br i1 %52, label %53, label %56
53: ; preds = %43
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %41)
br label %93
56: ; preds = %43
%57 = add nuw nsw i32 %51, 1
%58 = and i32 %57, 15
%59 = and i32 %45, 15
%60 = icmp eq i32 %58, %59
%61 = and i32 %45, 16
%62 = icmp eq i32 %61, 0
%63 = or i1 %62, %60
br i1 %63, label %93, label %64
64: ; preds = %56
%65 = icmp eq i32 %47, 1
%66 = icmp eq i32 %59, %51
%67 = select i1 %65, i1 %66, i1 false
br i1 %67, label %68, label %75
68: ; preds = %64
%69 = getelementptr inbounds [8191 x i8], [8191 x i8]* %6, i64 0, i64 %48
%70 = load i8, i8* %69
%71 = icmp eq i8 %70, 0
br i1 %71, label %74, label %72
72: ; preds = %68
%73 = and i8 %44, 15
br label %85
74: ; preds = %68
store i8 1, i8* %69
br label %93
75: ; preds = %64
%76 = icmp eq i32 %47, 3
%77 = and i8 %44, 15
%78 = icmp eq i8 %77, %50
%79 = select i1 %76, i1 %78, i1 false
br i1 %79, label %80, label %85
80: ; preds = %75
%81 = getelementptr inbounds [8191 x i8], [8191 x i8]* %6, i64 0, i64 %48
%82 = load i8, i8* %81
%83 = icmp eq i8 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %80
store i8 1, i8* %81
br label %93
85: ; preds = %72, %80, %75
%86 = phi i8 [ %73, %72 ], [ %77, %80 ], [ %77, %75 ]
%87 = load i32, i32* @stdout
%88 = trunc i32 %57 to i16
%89 = urem i16 %88, 15
%90 = zext i16 %89 to i32
%91 = zext i8 %86 to i32
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i32 %41, i64 %36, i32 %90, i32 %91)
br label %93
93: ; preds = %56, %74, %85, %84, %53
%94 = load i8, i8* %34
%95 = and i8 %94, 15
%96 = load i16, i16* %3
%97 = zext i16 %96 to i64
%98 = getelementptr inbounds [8191 x i8], [8191 x i8]* %5, i64 0, i64 %97
store i8 %95, i8* %98
br label %99
99: ; preds = %93, %35
%100 = add i64 %36, 1
%101 = call i32 @read(i32 %16, i8* %8, i32 188)
%102 = icmp slt i32 %101, 188
br i1 %102, label %103, label %35
103: ; preds = %99, %27, %22, %18
%104 = phi i32 [ 2, %18 ], [ 2, %22 ], [ 0, %27 ], [ 0, %99 ]
ret i32 %104
}