#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned int, char,
                           char, char, unsigned int, unsigned int, unsigned int,
                           unsigned int, unsigned int, unsigned int);
int get16be(int const *);
void dump_ts_packet_header(FILE *fp, const uint8_t ts_packet[188]) {
  unsigned int sync_byte;
  unsigned int transport_error_indicator;
  unsigned int payload_unit_start_indicator;
  unsigned int transport_priority;
  unsigned int PID;
  unsigned int transport_scrambling_control;
  unsigned int adaptation_field_control;
  unsigned int continuity_counter;
  unsigned int header_length;
  sync_byte = ts_packet[0];
  transport_error_indicator = ts_packet[1] & 0x80;
  payload_unit_start_indicator = ts_packet[1] & 0x40;
  transport_priority = ts_packet[1] & 0x20;
  PID = get16be(ts_packet + 1) & 0x1FFF;
  transport_scrambling_control = (ts_packet[3] & 0xC0) >> 6;
  adaptation_field_control = (ts_packet[3] & 0x30) >> 4;
  continuity_counter = ts_packet[3] & 0x0F;
  if (adaptation_field_control >= 2) {
    unsigned int adaptation_field_length;
    adaptation_field_length = ts_packet[4];
    header_length = 5 + adaptation_field_length;
  } else {
    header_length = 4;
  }
  fprintf(fp, "TS packet %02x %c%c%c 0x%04x=%u %u%u%x %u\n", sync_byte,
          transport_error_indicator ? 'E' : '-',
          payload_unit_start_indicator ? 'S' : '-',
          transport_priority ? 'P' : '-', PID, PID,
          transport_scrambling_control, adaptation_field_control,
          continuity_counter, header_length);
}


x86 assembly (clang, -O0):
<dump_ts_packet_header>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%eax
and    $0x80,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%eax
and    $0x40,%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%eax
and    $0x20,%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x4,%rdi
call   1030 <get16be@plt>
and    $0x1fff,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%eax
and    $0xc0,%eax
sar    $0x6,%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%eax
and    $0x30,%eax
sar    $0x4,%eax
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%eax
and    $0xf,%eax
mov    %eax,-0x48(%rbp)
cmpl   $0x2,-0x44(%rbp)
jb     11cd <dump_ts_packet_header+0xad>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x4c(%rbp)
jmp    11d4 <dump_ts_packet_header+0xb4>
movl   $0x4,-0x4c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%esi
mov    $0x2d,%eax
mov    $0x45,%ecx
cmp    $0x0,%esi
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x34(%rbp),%r8d
mov    $0x2d,%eax
mov    $0x53,%esi
cmp    $0x0,%r8d
cmovne %esi,%eax
mov    %al,%r8b
mov    -0x38(%rbp),%r9d
mov    $0x2d,%eax
mov    $0x50,%esi
cmp    $0x0,%r9d
cmovne %esi,%eax
mov    %al,%r9b
mov    -0x3c(%rbp),%r15d
mov    -0x3c(%rbp),%r14d
mov    -0x40(%rbp),%ebx
mov    -0x44(%rbp),%r11d
mov    -0x48(%rbp),%r10d
mov    -0x4c(%rbp),%eax
lea    0xdc3(%rip),%rsi
movsbl %cl,%ecx
movsbl %r8b,%r8d
movsbl %r9b,%r9d
mov    %r15d,(%rsp)
mov    %r14d,0x8(%rsp)
mov    %ebx,0x10(%rsp)
mov    %r11d,0x18(%rsp)
mov    %r10d,0x20(%rsp)
mov    %eax,0x28(%rsp)
call   1040 <fprintf@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_ts_packet_header>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbp
mov    %rdi,%r15
mov    (%rsi),%r14d
mov    0x4(%rsi),%r12d
lea    0x4(%rsi),%rdi
call   1030 <get16be@plt>
mov    0xc(%rbp),%ebx
mov    %ebx,%r10d
shr    $0x4,%r10d
and    $0x3,%r10d
mov    $0x4,%r11d
cmp    $0x2,%r10d
jb     1160 <dump_ts_packet_header+0x40>
mov    0x10(%rbp),%r11d
add    $0x5,%r11d
mov    %ebx,%ebp
and    $0xf,%ebp
shr    $0x6,%ebx
and    $0x3,%ebx
and    $0x1fff,%eax
test   $0x40,%r12b
mov    $0x2d,%edx
mov    $0x53,%r8d
cmove  %edx,%r8d
test   $0x80,%r12b
mov    $0x45,%ecx
cmove  %edx,%ecx
test   $0x20,%r12b
mov    $0x50,%r9d
cmove  %edx,%r9d
lea    0xe5c(%rip),%rsi
mov    %r15,%rdi
mov    %r14d,%edx
push   %r11
push   %rbp
push   %r10
push   %rbx
push   %rax
push   %rax
call   1040 <fprintf@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"TS packet %02x %c%c%c 0x%04x=%u %u%u%x %u\0A\00"
define void @dump_ts_packet_header(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%15 = load i32*, i32** %4
%16 = getelementptr inbounds i32, i32* %15, i64 0
%17 = load i32, i32* %16
store i32 %17, i32* %5
%18 = load i32*, i32** %4
%19 = getelementptr inbounds i32, i32* %18, i64 1
%20 = load i32, i32* %19
%21 = and i32 %20, 128
store i32 %21, i32* %6
%22 = load i32*, i32** %4
%23 = getelementptr inbounds i32, i32* %22, i64 1
%24 = load i32, i32* %23
%25 = and i32 %24, 64
store i32 %25, i32* %7
%26 = load i32*, i32** %4
%27 = getelementptr inbounds i32, i32* %26, i64 1
%28 = load i32, i32* %27
%29 = and i32 %28, 32
store i32 %29, i32* %8
%30 = load i32*, i32** %4
%31 = getelementptr inbounds i32, i32* %30, i64 1
%32 = call i32 @get16be(i32* %31)
%33 = and i32 %32, 8191
store i32 %33, i32* %9
%34 = load i32*, i32** %4
%35 = getelementptr inbounds i32, i32* %34, i64 3
%36 = load i32, i32* %35
%37 = and i32 %36, 192
%38 = ashr i32 %37, 6
store i32 %38, i32* %10
%39 = load i32*, i32** %4
%40 = getelementptr inbounds i32, i32* %39, i64 3
%41 = load i32, i32* %40
%42 = and i32 %41, 48
%43 = ashr i32 %42, 4
store i32 %43, i32* %11
%44 = load i32*, i32** %4
%45 = getelementptr inbounds i32, i32* %44, i64 3
%46 = load i32, i32* %45
%47 = and i32 %46, 15
store i32 %47, i32* %12
%48 = load i32, i32* %11
%49 = icmp uge i32 %48, 2
br i1 %49, label %50, label %56
50: ; preds = %2
%51 = load i32*, i32** %4
%52 = getelementptr inbounds i32, i32* %51, i64 4
%53 = load i32, i32* %52
store i32 %53, i32* %14
%54 = load i32, i32* %14
%55 = add i32 5, %54
store i32 %55, i32* %13
br label %57
56: ; preds = %2
store i32 4, i32* %13
br label %57
57: ; preds = %56, %50
%58 = load i32*, i32** %3
%59 = load i32, i32* %5
%60 = load i32, i32* %6
%61 = icmp ne i32 %60, 0
%62 = zext i1 %61 to i64
%63 = select i1 %61, i32 69, i32 45
%64 = trunc i32 %63 to i8
%65 = load i32, i32* %7
%66 = icmp ne i32 %65, 0
%67 = zext i1 %66 to i64
%68 = select i1 %66, i32 83, i32 45
%69 = trunc i32 %68 to i8
%70 = load i32, i32* %8
%71 = icmp ne i32 %70, 0
%72 = zext i1 %71 to i64
%73 = select i1 %71, i32 80, i32 45
%74 = trunc i32 %73 to i8
%75 = load i32, i32* %9
%76 = load i32, i32* %9
%77 = load i32, i32* %10
%78 = load i32, i32* %11
%79 = load i32, i32* %12
%80 = load i32, i32* %13
%81 = call i32 @fprintf(i32* %58, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %59, i8 signext %64, i8 signext %69, i8 signext %74, i32 %75, i32 %76, i32 %77, i32 %78, i32 %79, i32 %80)
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"TS packet %02x %c%c%c 0x%04x=%u %u%u%x %u\0A\00"
define void @dump_ts_packet_header(i32* nocapture %0, i32* %1) {
%3 = load i32, i32* %1
%4 = getelementptr inbounds i32, i32* %1, i64 1
%5 = load i32, i32* %4
%6 = tail call i32 @get16be(i32* %4)
%7 = getelementptr inbounds i32, i32* %1, i64 3
%8 = load i32, i32* %7
%9 = lshr i32 %8, 4
%10 = and i32 %9, 3
%11 = icmp ugt i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = getelementptr inbounds i32, i32* %1, i64 4
%14 = load i32, i32* %13
%15 = add i32 %14, 5
br label %16
16: ; preds = %2, %12
%17 = phi i32 [ %15, %12 ], [ 4, %2 ]
%18 = and i32 %8, 15
%19 = lshr i32 %8, 6
%20 = and i32 %19, 3
%21 = and i32 %6, 8191
%22 = and i32 %5, 32
%23 = and i32 %5, 64
%24 = and i32 %5, 128
%25 = icmp eq i32 %24, 0
%26 = select i1 %25, i8 45, i8 69
%27 = icmp eq i32 %23, 0
%28 = select i1 %27, i8 45, i8 83
%29 = icmp eq i32 %22, 0
%30 = select i1 %29, i8 45, i8 80
%31 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %3, i8 signext %26, i8 signext %28, i8 signext %30, i32 %21, i32 %21, i32 %20, i32 %10, i32 %18, i32 %17)
ret void
}