#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 int uint16_t;

/* Variables and functions */
const uint8_t *parse_ts_packet(const uint8_t *tspkt, uint16_t pid,
                               unsigned int *pusi) {
  uint16_t this_pid;
  if (tspkt[0] != 0x47)
    return NULL;
  if ((tspkt[1] & 0x80))
    return NULL;
  *pusi = (tspkt[1] & 0x40);
  this_pid = (((tspkt[1] & 0x1f) << 8) | tspkt[2]);
  if (this_pid != pid)
    return NULL;
  if ((tspkt[3] & 0xc0))
    return NULL;
  if (((tspkt[3] & 0x30) >> 4) != 1)
    return NULL;
  return tspkt + 4;
}


x86 assembly (clang, -O0):
<parse_ts_packet>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x47,(%rax)
je     1129 <parse_ts_packet+0x29>
movq   $0x0,-0x8(%rbp)
jmp    11dc <parse_ts_packet+0xdc>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     114b <parse_ts_packet+0x4b>
movq   $0x0,-0x8(%rbp)
jmp    11dc <parse_ts_packet+0xdc>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
and    $0x40,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
and    $0x1f,%eax
shl    $0x8,%eax
mov    -0x10(%rbp),%rcx
or     0x8(%rcx),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     118b <parse_ts_packet+0x8b>
movq   $0x0,-0x8(%rbp)
jmp    11dc <parse_ts_packet+0xdc>
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
and    $0xc0,%eax
cmp    $0x0,%eax
je     11ad <parse_ts_packet+0xad>
movq   $0x0,-0x8(%rbp)
jmp    11dc <parse_ts_packet+0xdc>
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
and    $0x30,%eax
sar    $0x4,%eax
cmp    $0x1,%eax
je     11d0 <parse_ts_packet+0xd0>
movq   $0x0,-0x8(%rbp)
jmp    11dc <parse_ts_packet+0xdc>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ts_packet>:
cmpl   $0x47,(%rdi)
jne    1137 <parse_ts_packet+0x37>
mov    0x4(%rdi),%eax
test   $0x80,%al
jne    1137 <parse_ts_packet+0x37>
and    $0x40,%eax
mov    %eax,(%rdx)
mov    0x4(%rdi),%eax
and    $0x1f,%eax
shl    $0x8,%eax
or     0x8(%rdi),%eax
cmp    %esi,%eax
jne    1137 <parse_ts_packet+0x37>
mov    $0xf0,%ecx
and    0xc(%rdi),%ecx
add    $0x10,%rdi
xor    %eax,%eax
cmp    $0x10,%ecx
cmove  %rdi,%rax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32* @parse_ts_packet(i32* %0, i32 %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%9 = load i32*, i32** %5
%10 = getelementptr inbounds i32, i32* %9, i64 0
%11 = load i32, i32* %10
%12 = icmp ne i32 %11, 71
br i1 %12, label %13, label %14
13: ; preds = %3
store i32* null, i32** %4
br label %58
14: ; preds = %3
%15 = load i32*, i32** %5
%16 = getelementptr inbounds i32, i32* %15, i64 1
%17 = load i32, i32* %16
%18 = and i32 %17, 128
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
store i32* null, i32** %4
br label %58
21: ; preds = %14
%22 = load i32*, i32** %5
%23 = getelementptr inbounds i32, i32* %22, i64 1
%24 = load i32, i32* %23
%25 = and i32 %24, 64
%26 = load i32*, i32** %7
store i32 %25, i32* %26
%27 = load i32*, i32** %5
%28 = getelementptr inbounds i32, i32* %27, i64 1
%29 = load i32, i32* %28
%30 = and i32 %29, 31
%31 = shl i32 %30, 8
%32 = load i32*, i32** %5
%33 = getelementptr inbounds i32, i32* %32, i64 2
%34 = load i32, i32* %33
%35 = or i32 %31, %34
store i32 %35, i32* %8
%36 = load i32, i32* %8
%37 = load i32, i32* %6
%38 = icmp ne i32 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %21
store i32* null, i32** %4
br label %58
40: ; preds = %21
%41 = load i32*, i32** %5
%42 = getelementptr inbounds i32, i32* %41, i64 3
%43 = load i32, i32* %42
%44 = and i32 %43, 192
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %40
store i32* null, i32** %4
br label %58
47: ; preds = %40
%48 = load i32*, i32** %5
%49 = getelementptr inbounds i32, i32* %48, i64 3
%50 = load i32, i32* %49
%51 = and i32 %50, 48
%52 = ashr i32 %51, 4
%53 = icmp ne i32 %52, 1
br i1 %53, label %54, label %55
54: ; preds = %47
store i32* null, i32** %4
br label %58
55: ; preds = %47
%56 = load i32*, i32** %5
%57 = getelementptr inbounds i32, i32* %56, i64 4
store i32* %57, i32** %4
br label %58
58: ; preds = %55, %54, %46, %39, %20, %13
%59 = load i32*, i32** %4
ret i32* %59
}

LLVM IR (-O2):
define i32* @parse_ts_packet(i32* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = load i32, i32* %0
%5 = icmp eq i32 %4, 71
br i1 %5, label %6, label %27
6: ; preds = %3
%7 = getelementptr inbounds i32, i32* %0, i64 1
%8 = load i32, i32* %7
%9 = and i32 %8, 128
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %6
%12 = and i32 %8, 64
store i32 %12, i32* %2
%13 = load i32, i32* %7
%14 = shl i32 %13, 8
%15 = and i32 %14, 7936
%16 = getelementptr inbounds i32, i32* %0, i64 2
%17 = load i32, i32* %16
%18 = or i32 %15, %17
%19 = icmp eq i32 %18, %1
br i1 %19, label %20, label %27
20: ; preds = %11
%21 = getelementptr inbounds i32, i32* %0, i64 3
%22 = load i32, i32* %21
%23 = and i32 %22, 240
%24 = icmp eq i32 %23, 16
%25 = getelementptr inbounds i32, i32* %0, i64 4
%26 = select i1 %24, i32* %25, i32* null
br label %27
27: ; preds = %20, %11, %6, %3
%28 = phi i32* [ null, %3 ], [ null, %6 ], [ null, %11 ], [ %26, %20 ]
ret i32* %28
}