#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 uint8_t;
typedef size_t uint16_t;

/* Variables and functions */
int /*<<< orphan*/ parse_ttx(int const *, size_t);
int /*<<< orphan*/ printf(char *, unsigned int, ...);
size_t read_be16(int const *);
void parse_ttx_pes(const uint8_t *pes, size_t size, void *user_data) {
  unsigned int *ttx_pes_pkt_no = user_data;
  ++(*ttx_pes_pkt_no);
  do {
    printf("TTX_PES[%u] : "
           "Received PES packet of size %zu.\n",
           *ttx_pes_pkt_no - 1, size);
  } while (0);
  if (pes[0] != 0x00 || pes[1] != 0x00 || pes[2] != 0x01) {
    do {
      printf("TTX_PES[%u] : "
             "PES magic number incorrect : %hhx%hhx%hhx.\n",
             *ttx_pes_pkt_no - 1, pes[0], pes[1], pes[2]);
    } while (0);
    return;
  }
  if (pes[3] != 0xBD) {
    do {
      printf("TTX_PES[%u] : "
             "PES stream ID incorrect : %hhx.\n",
             *ttx_pes_pkt_no - 1, pes[3]);
    } while (0);
    return;
  }
  uint16_t pes_pkt_len = read_be16(pes + 4);
  if (pes_pkt_len != size - 6) {
    do {
      printf("TTX_PES[%u] : "
             "PES packet length mismatch : %hu.\n",
             *ttx_pes_pkt_no - 1, pes_pkt_len);
    } while (0);
    return;
  }
  if (((pes_pkt_len + 6) % 184) != 0) {
    do {
      printf("TTX_PES[%u] : "
             "Declared PES packet length incorrect.\n",
             *ttx_pes_pkt_no - 1);
    } while (0);
    return;
  }
  if (!(pes[6] & 0x04)) {
    do {
      printf("TTX_PES[%u] : "
             "Data alignment indicator set to zero.\n",
             *ttx_pes_pkt_no - 1);
    } while (0);
    return;
  }
  if (pes[8] != 0x24) {
    do {
      printf("TTX_PES[%u] : "
             "Header length %hhu different from expected (%hhu).\n",
             *ttx_pes_pkt_no - 1, pes[8], 0x24);
    } while (0);
    return;
  }
  parse_ttx(pes + 9 + 0x24, size - 9 - 0x24);
  do {
    printf("TTX_PES[%u] : "
           "Finished.\n",
           *ttx_pes_pkt_no - 1);
  } while (0);
}


x86 assembly (clang, -O0):
<parse_ttx_pes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%rdx
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jne    119b <parse_ttx_pes+0x6b>
mov    -0x8(%rbp),%rax
cmpl   $0x0,0x4(%rax)
jne    119b <parse_ttx_pes+0x6b>
mov    -0x8(%rbp),%rax
cmpl   $0x1,0x8(%rax)
je     11d1 <parse_ttx_pes+0xa1>
jmp    11a0 <parse_ttx_pes+0x70>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
sub    $0x1,%esi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%r8d
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1338 <parse_ttx_pes+0x208>
mov    -0x8(%rbp),%rax
cmpl   $0xbd,0xc(%rax)
je     120a <parse_ttx_pes+0xda>
jmp    11e7 <parse_ttx_pes+0xb7>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
sub    $0x1,%esi
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%edx
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1338 <parse_ttx_pes+0x208>
mov    -0x8(%rbp),%rdi
add    $0x10,%rdi
call   1030 <read_be16@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x6,%rcx
cmp    %rcx,%rax
je     1255 <parse_ttx_pes+0x125>
jmp    1235 <parse_ttx_pes+0x105>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
sub    $0x1,%esi
mov    -0x28(%rbp),%rdx
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1338 <parse_ttx_pes+0x208>
mov    -0x28(%rbp),%rax
add    $0x6,%rax
mov    $0xb8,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
je     1292 <parse_ttx_pes+0x162>
jmp    1276 <parse_ttx_pes+0x146>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
sub    $0x1,%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1338 <parse_ttx_pes+0x208>
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%eax
and    $0x4,%eax
cmp    $0x0,%eax
jne    12c6 <parse_ttx_pes+0x196>
jmp    12aa <parse_ttx_pes+0x17a>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
sub    $0x1,%esi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1338 <parse_ttx_pes+0x208>
mov    -0x8(%rbp),%rax
cmpl   $0x24,0x20(%rax)
je     1301 <parse_ttx_pes+0x1d1>
jmp    12d9 <parse_ttx_pes+0x1a9>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
sub    $0x1,%esi
mov    -0x8(%rbp),%rax
mov    0x20(%rax),%edx
lea    0xe44(%rip),%rdi
mov    $0x24,%ecx
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1338 <parse_ttx_pes+0x208>
mov    -0x8(%rbp),%rdi
add    $0x24,%rdi
add    $0x90,%rdi
mov    -0x10(%rbp),%rsi
sub    $0x9,%rsi
sub    $0x24,%rsi
call   1050 <parse_ttx@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
sub    $0x1,%esi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ttx_pes>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    (%rdx),%esi
lea    0x1(%rsi),%eax
mov    %eax,(%rdx)
lea    0xeb4(%rip),%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%edx
mov    0x4(%rbx),%ecx
mov    %edx,%eax
or     %ecx,%eax
jne    11c9 <parse_ttx_pes+0x99>
cmpl   $0x1,0x8(%rbx)
mov    $0x0,%ecx
jne    11c9 <parse_ttx_pes+0x99>
mov    0xc(%rbx),%edx
cmp    $0xbd,%edx
jne    11e6 <parse_ttx_pes+0xb6>
lea    0x10(%rbx),%rdi
call   1030 <read_be16@plt>
lea    -0x6(%r15),%rcx
cmp    %rcx,%rax
jne    11ff <parse_ttx_pes+0xcf>
movabs $0xd37a6f4de9bd37a7,%rcx
6f 7a d3
imul   %rcx,%rax
movabs $0xf4de9bd37a6f4dea,%rcx
9b de f4
add    %rax,%rcx
ror    $0x3,%rcx
movabs $0x1642c8590b21643,%rax
2c 64 01
cmp    %rax,%rcx
jb     121b <parse_ttx_pes+0xeb>
mov    (%r14),%esi
add    $0xffffffff,%esi
lea    0xf06(%rip),%rdi
jmp    125b <parse_ttx_pes+0x12b>
mov    (%r14),%esi
add    $0xffffffff,%esi
mov    0x8(%rbx),%r8d
lea    0xe56(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <printf@plt>
mov    (%r14),%esi
add    $0xffffffff,%esi
lea    0xe77(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <printf@plt>
mov    (%r14),%esi
add    $0xffffffff,%esi
lea    0xe8d(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <printf@plt>
testb  $0x4,0x18(%rbx)
jne    1230 <parse_ttx_pes+0x100>
mov    (%r14),%esi
add    $0xffffffff,%esi
lea    0xed1(%rip),%rdi
jmp    125b <parse_ttx_pes+0x12b>
mov    0x20(%rbx),%edx
cmp    $0x24,%edx
jne    1267 <parse_ttx_pes+0x137>
add    $0xb4,%rbx
add    $0xffffffffffffffd3,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <parse_ttx@plt>
mov    (%r14),%esi
add    $0xffffffff,%esi
lea    0xf1b(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <printf@plt>
mov    (%r14),%esi
add    $0xffffffff,%esi
lea    0xec0(%rip),%rdi
mov    $0x24,%ecx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [48 x i8] c"TTX_PES[%u] : Received PES packet of size %zu.\0A\00"
@.str.1 = [58 x i8] c"TTX_PES[%u] : PES magic number incorrect : %hhx%hhx%hhx.\0A\00"
@.str.2 = [47 x i8] c"TTX_PES[%u] : PES stream ID incorrect : %hhx.\0A\00"
@.str.3 = [49 x i8] c"TTX_PES[%u] : PES packet length mismatch : %hu.\0A\00"
@.str.4 = [53 x i8] c"TTX_PES[%u] : Declared PES packet length incorrect.\0A\00"
@.str.5 = [53 x i8] c"TTX_PES[%u] : Data alignment indicator set to zero.\0A\00"
@.str.6 = [66 x i8] c"TTX_PES[%u] : Header length %hhu different from expected (%hhu).\0A\00"
@.str.7 = [25 x i8] c"TTX_PES[%u] : Finished.\0A\00"
define void @parse_ttx_pes(i32* %0, i64 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i64
store i32* %0, i32** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = bitcast i8* %9 to i32*
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = load i32, i32* %11
%13 = add i32 %12, 1
store i32 %13, i32* %11
br label %14
14: ; preds = %3
%15 = load i32*, i32** %7
%16 = load i32, i32* %15
%17 = sub i32 %16, 1
%18 = load i64, i64* %5
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %17, i64 %18)
br label %20
20: ; preds = %14
%21 = load i32*, i32** %4
%22 = getelementptr inbounds i32, i32* %21, i64 0
%23 = load i32, i32* %22
%24 = icmp ne i32 %23, 0
br i1 %24, label %35, label %25
25: ; preds = %20
%26 = load i32*, i32** %4
%27 = getelementptr inbounds i32, i32* %26, i64 1
%28 = load i32, i32* %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %25
%31 = load i32*, i32** %4
%32 = getelementptr inbounds i32, i32* %31, i64 2
%33 = load i32, i32* %32
%34 = icmp ne i32 %33, 1
br i1 %34, label %35, label %51
35: ; preds = %30, %25, %20
br label %36
36: ; preds = %35
%37 = load i32*, i32** %7
%38 = load i32, i32* %37
%39 = sub i32 %38, 1
%40 = load i32*, i32** %4
%41 = getelementptr inbounds i32, i32* %40, i64 0
%42 = load i32, i32* %41
%43 = load i32*, i32** %4
%44 = getelementptr inbounds i32, i32* %43, i64 1
%45 = load i32, i32* %44
%46 = load i32*, i32** %4
%47 = getelementptr inbounds i32, i32* %46, i64 2
%48 = load i32, i32* %47
%49 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %39, i32 %42, i32 %45, i32 %48)
br label %50
50: ; preds = %36
br label %135
51: ; preds = %30
%52 = load i32*, i32** %4
%53 = getelementptr inbounds i32, i32* %52, i64 3
%54 = load i32, i32* %53
%55 = icmp ne i32 %54, 189
br i1 %55, label %56, label %66
56: ; preds = %51
br label %57
57: ; preds = %56
%58 = load i32*, i32** %7
%59 = load i32, i32* %58
%60 = sub i32 %59, 1
%61 = load i32*, i32** %4
%62 = getelementptr inbounds i32, i32* %61, i64 3
%63 = load i32, i32* %62
%64 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %60, i32 %63)
br label %65
65: ; preds = %57
br label %135
66: ; preds = %51
%67 = load i32*, i32** %4
%68 = getelementptr inbounds i32, i32* %67, i64 4
%69 = call i64 @read_be16(i32* %68)
store i64 %69, i64* %8
%70 = load i64, i64* %8
%71 = load i64, i64* %5
%72 = sub i64 %71, 6
%73 = icmp ne i64 %70, %72
br i1 %73, label %74, label %82
74: ; preds = %66
br label %75
75: ; preds = %74
%76 = load i32*, i32** %7
%77 = load i32, i32* %76
%78 = sub i32 %77, 1
%79 = load i64, i64* %8
%80 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32 %78, i64 %79)
br label %81
81: ; preds = %75
br label %135
82: ; preds = %66
%83 = load i64, i64* %8
%84 = add i64 %83, 6
%85 = urem i64 %84, 184
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %94
87: ; preds = %82
br label %88
88: ; preds = %87
%89 = load i32*, i32** %7
%90 = load i32, i32* %89
%91 = sub i32 %90, 1
%92 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %91)
br label %93
93: ; preds = %88
br label %135
94: ; preds = %82
%95 = load i32*, i32** %4
%96 = getelementptr inbounds i32, i32* %95, i64 6
%97 = load i32, i32* %96
%98 = and i32 %97, 4
%99 = icmp ne i32 %98, 0
br i1 %99, label %107, label %100
100: ; preds = %94
br label %101
101: ; preds = %100
%102 = load i32*, i32** %7
%103 = load i32, i32* %102
%104 = sub i32 %103, 1
%105 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), i32 %104)
br label %106
106: ; preds = %101
br label %135
107: ; preds = %94
%108 = load i32*, i32** %4
%109 = getelementptr inbounds i32, i32* %108, i64 8
%110 = load i32, i32* %109
%111 = icmp ne i32 %110, 36
br i1 %111, label %112, label %122
112: ; preds = %107
br label %113
113: ; preds = %112
%114 = load i32*, i32** %7
%115 = load i32, i32* %114
%116 = sub i32 %115, 1
%117 = load i32*, i32** %4
%118 = getelementptr inbounds i32, i32* %117, i64 8
%119 = load i32, i32* %118
%120 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.6, i64 0, i64 0), i32 %116, i32 %119, i32 36)
br label %121
121: ; preds = %113
br label %135
122: ; preds = %107
%123 = load i32*, i32** %4
%124 = getelementptr inbounds i32, i32* %123, i64 9
%125 = getelementptr inbounds i32, i32* %124, i64 36
%126 = load i64, i64* %5
%127 = sub i64 %126, 9
%128 = sub i64 %127, 36
%129 = call i32 @parse_ttx(i32* %125, i64 %128)
br label %130
130: ; preds = %122
%131 = load i32*, i32** %7
%132 = load i32, i32* %131
%133 = sub i32 %132, 1
%134 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %133)
br label %135
135: ; preds = %50, %65, %81, %93, %106, %121, %130
ret void
}

LLVM IR (-O2):
@.str = [48 x i8] c"TTX_PES[%u] : Received PES packet of size %zu.\0A\00"
@.str.1 = [58 x i8] c"TTX_PES[%u] : PES magic number incorrect : %hhx%hhx%hhx.\0A\00"
@.str.2 = [47 x i8] c"TTX_PES[%u] : PES stream ID incorrect : %hhx.\0A\00"
@.str.3 = [49 x i8] c"TTX_PES[%u] : PES packet length mismatch : %hu.\0A\00"
@.str.4 = [53 x i8] c"TTX_PES[%u] : Declared PES packet length incorrect.\0A\00"
@.str.5 = [53 x i8] c"TTX_PES[%u] : Data alignment indicator set to zero.\0A\00"
@.str.6 = [66 x i8] c"TTX_PES[%u] : Header length %hhu different from expected (%hhu).\0A\00"
@.str.7 = [25 x i8] c"TTX_PES[%u] : Finished.\0A\00"
define void @parse_ttx_pes(i32* %0, i64 %1, i8* nocapture %2) {
%4 = bitcast i8* %2 to i32*
%5 = load i32, i32* %4
%6 = add i32 %5, 1
store i32 %6, i32* %4
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %5, i64 %1)
%8 = load i32, i32* %0
%9 = icmp eq i32 %8, 0
%10 = getelementptr inbounds i32, i32* %0, i64 1
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 0
%13 = select i1 %9, i1 %12, i1 false
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = getelementptr inbounds i32, i32* %0, i64 2
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, 1
br i1 %17, label %25, label %18
18: ; preds = %3, %14
%19 = phi i32 [ 0, %14 ], [ %11, %3 ]
%20 = load i32, i32* %4
%21 = add i32 %20, -1
%22 = getelementptr inbounds i32, i32* %0, i64 2
%23 = load i32, i32* %22
%24 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %8, i32 %19, i32 %23)
br label %74
25: ; preds = %14
%26 = getelementptr inbounds i32, i32* %0, i64 3
%27 = load i32, i32* %26
%28 = icmp eq i32 %27, 189
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = load i32, i32* %4
%31 = add i32 %30, -1
%32 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %31, i32 %27)
br label %74
33: ; preds = %25
%34 = getelementptr inbounds i32, i32* %0, i64 4
%35 = tail call i64 @read_be16(i32* %34)
%36 = add i64 %1, -6
%37 = icmp eq i64 %35, %36
br i1 %37, label %42, label %38
38: ; preds = %33
%39 = load i32, i32* %4
%40 = add i32 %39, -1
%41 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32 %40, i64 %35)
br label %74
42: ; preds = %33
%43 = add i64 %35, 6
%44 = urem i64 %43, 184
%45 = icmp eq i64 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %42
%47 = load i32, i32* %4
%48 = add i32 %47, -1
%49 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %48)
br label %74
50: ; preds = %42
%51 = getelementptr inbounds i32, i32* %0, i64 6
%52 = load i32, i32* %51
%53 = and i32 %52, 4
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %50
%56 = load i32, i32* %4
%57 = add i32 %56, -1
%58 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), i32 %57)
br label %74
59: ; preds = %50
%60 = getelementptr inbounds i32, i32* %0, i64 8
%61 = load i32, i32* %60
%62 = icmp eq i32 %61, 36
br i1 %62, label %67, label %63
63: ; preds = %59
%64 = load i32, i32* %4
%65 = add i32 %64, -1
%66 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.6, i64 0, i64 0), i32 %65, i32 %61, i32 36)
br label %74
67: ; preds = %59
%68 = getelementptr inbounds i32, i32* %0, i64 45
%69 = add i64 %1, -45
%70 = tail call i32 @parse_ttx(i32* %68, i64 %69)
%71 = load i32, i32* %4
%72 = add i32 %71, -1
%73 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %72)
br label %74
74: ; preds = %38, %46, %55, %63, %67, %29, %18
ret void
}