#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*/ Parser_DisplayTagInfo(unsigned int, unsigned char);
int /*<<< orphan*/ Parser_TsPacketLog(unsigned int, char *, ...);
int x09_Tag_DescriptorParser(unsigned int type, unsigned char *buff) {
  unsigned int i = 0;
  if (NULL == buff) {
    return -1;
  }
  Parser_DisplayTagInfo(type, buff[0]);
  Parser_TsPacketLog(type, "Descriptor_length = 0x%x\n", buff[1]);
  Parser_TsPacketLog(type, "Ca_system_id = 0x%x\n",
                     ((buff[2] & 0xFF) << 8) | (buff[3] & 0xFF));
  Parser_TsPacketLog(type, "Ca_pid = 0x%x\n",
                     ((buff[4] & 0x1F) << 8) | (buff[5] & 0xFF));
  if (buff[1] > 4) {
    Parser_TsPacketLog(type, "Descriptor_data:");
    for (i = 0; i < buff[1] - 4; i++) {
      Parser_TsPacketLog(type, " 0x%x", buff[6 + i]);
    }
    Parser_TsPacketLog(type, "\n");
  }
  Parser_TsPacketLog(type, "******END******\n");
  return buff[1];
}


x86 assembly (clang, -O0):
<x09_Tag_DescriptorParser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    114e <x09_Tag_DescriptorParser+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <x09_Tag_DescriptorParser+0x150>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
movzbl (%rax),%esi
call   1040 <Parser_DisplayTagInfo@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%edx
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%edx
and    $0xff,%edx
shl    $0x8,%edx
mov    -0x10(%rbp),%rax
movzbl 0x3(%rax),%eax
and    $0xff,%eax
or     %eax,%edx
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
movzbl 0x4(%rax),%edx
and    $0x1f,%edx
shl    $0x8,%edx
mov    -0x10(%rbp),%rax
movzbl 0x5(%rax),%eax
and    $0xff,%eax
or     %eax,%edx
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x4,%eax
jle    1254 <x09_Tag_DescriptorParser+0x134>
mov    -0x8(%rbp),%edi
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
sub    $0x4,%ecx
cmp    %ecx,%eax
jae    1243 <x09_Tag_DescriptorParser+0x123>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x6,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%edx
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11fe <x09_Tag_DescriptorParser+0xde>
mov    -0x8(%rbp),%edi
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x8(%rbp),%edi
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<x09_Tag_DescriptorParser>:
test   %rsi,%rsi
je     121b <x09_Tag_DescriptorParser+0xfb>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r15d
movzbl (%rsi),%esi
call   1040 <Parser_DisplayTagInfo@plt>
movzbl 0x1(%rbx),%edx
lea    0xeb7(%rip),%rsi
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzwl 0x2(%rbx),%edx
shl    $0x10,%edx
bswap  %edx
lea    0xeb7(%rip),%rsi
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x4(%rbx),%eax
and    $0x1f,%eax
shl    $0x8,%eax
movzbl 0x5(%rbx),%edx
or     %eax,%edx
lea    0xeab(%rip),%rsi
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
cmpb   $0x5,0x1(%rbx)
jb     11fb <x09_Tag_DescriptorParser+0xdb>
lea    0xea3(%rip),%rsi
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
cmpb   $0x4,0x1(%rbx)
je     11ea <x09_Tag_DescriptorParser+0xca>
mov    $0x6,%ebp
lea    0xe98(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %ebp,%eax
movzbl (%rbx,%rax,1),%edx
mov    %r15d,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x1(%rbx),%eax
add    $0xfffffffc,%eax
lea    0x1(%rbp),%rcx
add    $0xfffffffffffffffb,%rbp
cmp    %rax,%rbp
mov    %rcx,%rbp
jb     11c0 <x09_Tag_DescriptorParser+0xa0>
lea    0xe73(%rip),%rsi
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
lea    0xe53(%rip),%rsi
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x1(%rbx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Descriptor_length = 0x%x\0A\00"
@.str.1 = [21 x i8] c"Ca_system_id = 0x%x\0A\00"
@.str.2 = [15 x i8] c"Ca_pid = 0x%x\0A\00"
@.str.3 = [17 x i8] c"Descriptor_data:\00"
@.str.4 = [6 x i8] c" 0x%x\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [17 x i8] c"******END******\0A\00"
define i32 @x09_Tag_DescriptorParser(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %6
%7 = load i8*, i8** %5
%8 = icmp eq i8* null, %7
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %89
10: ; preds = %2
%11 = load i32, i32* %4
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = call i32 @Parser_DisplayTagInfo(i32 %11, i8 zeroext %14)
%16 = load i32, i32* %4
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %4
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 2
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = and i32 %26, 255
%28 = shl i32 %27, 8
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i64 3
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = and i32 %32, 255
%34 = or i32 %28, %33
%35 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %22, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %4
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 4
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = and i32 %40, 31
%42 = shl i32 %41, 8
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i64 5
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = and i32 %46, 255
%48 = or i32 %42, %47
%49 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %36, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%50 = load i8*, i8** %5
%51 = getelementptr inbounds i8, i8* %50, i64 1
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = icmp sgt i32 %53, 4
br i1 %54, label %55, label %82
55: ; preds = %10
%56 = load i32, i32* %4
%57 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %56, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %58
58: ; preds = %76, %55
%59 = load i32, i32* %6
%60 = load i8*, i8** %5
%61 = getelementptr inbounds i8, i8* %60, i64 1
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = sub nsw i32 %63, 4
%65 = icmp ult i32 %59, %64
br i1 %65, label %66, label %79
66: ; preds = %58
%67 = load i32, i32* %4
%68 = load i8*, i8** %5
%69 = load i32, i32* %6
%70 = add i32 6, %69
%71 = zext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %68, i64 %71
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %67, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %66
%77 = load i32, i32* %6
%78 = add i32 %77, 1
store i32 %78, i32* %6
br label %58
79: ; preds = %58
%80 = load i32, i32* %4
%81 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %80, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %82
82: ; preds = %79, %10
%83 = load i32, i32* %4
%84 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %83, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%85 = load i8*, i8** %5
%86 = getelementptr inbounds i8, i8* %85, i64 1
%87 = load i8, i8* %86
%88 = zext i8 %87 to i32
store i32 %88, i32* %3
br label %89
89: ; preds = %82, %9
%90 = load i32, i32* %3
ret i32 %90
}

LLVM IR (-O2):
@.str = [26 x i8] c"Descriptor_length = 0x%x\0A\00"
@.str.1 = [21 x i8] c"Ca_system_id = 0x%x\0A\00"
@.str.2 = [15 x i8] c"Ca_pid = 0x%x\0A\00"
@.str.3 = [17 x i8] c"Descriptor_data:\00"
@.str.4 = [6 x i8] c" 0x%x\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [17 x i8] c"******END******\0A\00"
define i32 @x09_Tag_DescriptorParser(i32 %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %56, label %4
4: ; preds = %2
%5 = load i8, i8* %1
%6 = tail call i32 @Parser_DisplayTagInfo(i32 %0, i8 zeroext %5)
%7 = getelementptr inbounds i8, i8* %1, i64 1
%8 = load i8, i8* %7
%9 = zext i8 %8 to i32
%10 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds i8, i8* %1, i64 2
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = shl nuw nsw i32 %13, 8
%15 = getelementptr inbounds i8, i8* %1, i64 3
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = or i32 %14, %17
%19 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds i8, i8* %1, i64 4
%21 = load i8, i8* %20
%22 = and i8 %21, 31
%23 = zext i8 %22 to i32
%24 = shl nuw nsw i32 %23, 8
%25 = getelementptr inbounds i8, i8* %1, i64 5
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = or i32 %24, %27
%29 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i8, i8* %7
%31 = icmp ugt i8 %30, 4
br i1 %31, label %32, label %52
32: ; preds = %4
%33 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%34 = load i8, i8* %7
%35 = icmp eq i8 %34, 4
br i1 %35, label %50, label %36
36: ; preds = %32, %36
%37 = phi i64 [ %44, %36 ], [ 0, %32 ]
%38 = add nuw i64 %37, 6
%39 = and i64 %38, 4294967295
%40 = getelementptr inbounds i8, i8* %1, i64 %39
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = add nuw nsw i64 %37, 1
%45 = load i8, i8* %7
%46 = zext i8 %45 to i64
%47 = add nuw nsw i64 %46, 4294967292
%48 = and i64 %47, 4294967295
%49 = icmp ult i64 %44, %48
br i1 %49, label %36, label %50
50: ; preds = %36, %32
%51 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %52
52: ; preds = %50, %4
%53 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%54 = load i8, i8* %7
%55 = zext i8 %54 to i32
br label %56
56: ; preds = %2, %52
%57 = phi i32 [ %55, %52 ], [ -1, %2 ]
ret i32 %57
}