#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 x45_Tag_DescriptorParser(unsigned int type, unsigned char *buff) {
  unsigned int i = 0, j = 0;
  unsigned char tmplen = 0;
  unsigned char *data = NULL;
  if (NULL == buff) {
    return -1;
  }
  Parser_DisplayTagInfo(type, buff[0]);
  Parser_TsPacketLog(type, "Descriptor_length = 0x%x\n", buff[1]);
  data = buff;
  data += 2;
  for (i = 0; i < buff[1]; i++) {
    Parser_TsPacketLog(type, "data_service_id = 0x%x\n", data[0]);
    tmplen = data[1];
    Parser_TsPacketLog(type, "data_service_descriptor_length = 0x%x\n", tmplen);
    if ((data[0] == 0x01) || (data[0] == 0x02) || (data[0] == 0x04) ||
        (data[0] == 0x05) || (data[0] == 0x06) || (data[0] == 0x07)) {
      data += 2;
      for (j = 0; j < tmplen; j++) {
        Parser_TsPacketLog(type, "field_parity = 0x%x\n",
                           (data[j] & 0x40) >> 5);
        Parser_TsPacketLog(type, "line_offset = 0x%x\n", data[j] & 0x1F);
      }
    } else {
      data += 2;
      Parser_TsPacketLog(type, "reserved = 0x%x ...\n", data[0]);
    }
    data += tmplen;
  }
  Parser_TsPacketLog(type, "******END******\n");
  return buff[1];
}


x86 assembly (clang, -O0):
<x45_Tag_DescriptorParser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
movq   $0x0,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1161 <x45_Tag_DescriptorParser+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    1324 <x45_Tag_DescriptorParser+0x204>
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    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
cmp    %ecx,%eax
jae    1308 <x45_Tag_DescriptorParser+0x1e8>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rax
movzbl (%rax),%edx
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x28(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%edi
movzbl -0x19(%rbp),%edx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x1,%eax
je     124e <x45_Tag_DescriptorParser+0x12e>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2,%eax
je     124e <x45_Tag_DescriptorParser+0x12e>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x4,%eax
je     124e <x45_Tag_DescriptorParser+0x12e>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x5,%eax
je     124e <x45_Tag_DescriptorParser+0x12e>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x6,%eax
je     124e <x45_Tag_DescriptorParser+0x12e>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7,%eax
jne    12c4 <x45_Tag_DescriptorParser+0x1a4>
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
movzbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jae    12bf <x45_Tag_DescriptorParser+0x19f>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%ecx
movzbl (%rax,%rcx,1),%edx
and    $0x40,%edx
sar    $0x5,%edx
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%ecx
movzbl (%rax,%rcx,1),%edx
and    $0x1f,%edx
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1261 <x45_Tag_DescriptorParser+0x141>
jmp    12e8 <x45_Tag_DescriptorParser+0x1c8>
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rax
movzbl (%rax),%edx
lea    0xda1(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
movzbl -0x19(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a4 <x45_Tag_DescriptorParser+0x84>
mov    -0x8(%rbp),%edi
lea    0xd85(%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    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<x45_Tag_DescriptorParser>:
test   %rsi,%rsi
je     126f <x45_Tag_DescriptorParser+0x14f>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movzbl (%rsi),%esi
call   1040 <Parser_DisplayTagInfo@plt>
movzbl 0x1(%r14),%edx
lea    0xeb0(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
cmpb   $0x0,0x1(%r14)
je     124b <x45_Tag_DescriptorParser+0x12b>
lea    0x2(%r14),%r15
lea    0xeea(%rip),%rbx
lea    0xef8(%rip),%r12
xor    %ecx,%ecx
mov    %r14,0x10(%rsp)
jmp    11c0 <x45_Tag_DescriptorParser+0xa0>
movzbl 0x2(%r15),%edx
mov    %ebp,%edi
lea    0xef5(%rip),%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    %r14,%r15
add    $0x2,%r15
mov    0xc(%rsp),%ecx
add    $0x1,%ecx
mov    0x10(%rsp),%r14
movzbl 0x1(%r14),%eax
cmp    %eax,%ecx
jae    124b <x45_Tag_DescriptorParser+0x12b>
mov    %ecx,0xc(%rsp)
movzbl (%r15),%edx
mov    %ebp,%edi
lea    0xe49(%rip),%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x1(%r15),%r14d
mov    %ebp,%edi
lea    0xe4c(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
mov    (%r15),%al
cmp    $0x7,%al
ja     117f <x45_Tag_DescriptorParser+0x5f>
movzbl %al,%eax
mov    $0xf6,%ecx
bt     %eax,%ecx
jae    117f <x45_Tag_DescriptorParser+0x5f>
test   %r14,%r14
je     11a0 <x45_Tag_DescriptorParser+0x80>
xor    %r13d,%r13d
movzbl 0x2(%r15,%r13,1),%edx
shr    $0x5,%edx
and    $0x2,%edx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x2(%r15,%r13,1),%edx
and    $0x1f,%edx
mov    %ebp,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
add    $0x1,%r13
cmp    %r13,%r14
jne    1210 <x45_Tag_DescriptorParser+0xf0>
jmp    11a0 <x45_Tag_DescriptorParser+0x80>
lea    0xe45(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x1(%r14),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 = [24 x i8] c"data_service_id = 0x%x\0A\00"
@.str.2 = [39 x i8] c"data_service_descriptor_length = 0x%x\0A\00"
@.str.3 = [21 x i8] c"field_parity = 0x%x\0A\00"
@.str.4 = [20 x i8] c"line_offset = 0x%x\0A\00"
@.str.5 = [21 x i8] c"reserved = 0x%x ...\0A\00"
@.str.6 = [17 x i8] c"******END******\0A\00"
define i32 @x45_Tag_DescriptorParser(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i8 0, i8* %8
store i8* null, i8** %9
%10 = load i8*, i8** %5
%11 = icmp eq i8* null, %10
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %141
13: ; preds = %2
%14 = load i32, i32* %4
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = call i32 @Parser_DisplayTagInfo(i32 %14, i8 zeroext %17)
%19 = load i32, i32* %4
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %19, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i8*, i8** %5
store i8* %25, i8** %9
%26 = load i8*, i8** %9
%27 = getelementptr inbounds i8, i8* %26, i64 2
store i8* %27, i8** %9
store i32 0, i32* %6
br label %28
28: ; preds = %131, %13
%29 = load i32, i32* %6
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = icmp ult i32 %29, %33
br i1 %34, label %35, label %134
35: ; preds = %28
%36 = load i32, i32* %4
%37 = load i8*, i8** %9
%38 = getelementptr inbounds i8, i8* %37, i64 0
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %36, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = load i8*, i8** %9
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %43
store i8 %44, i8* %8
%45 = load i32, i32* %4
%46 = load i8, i8* %8
%47 = zext i8 %46 to i32
%48 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %45, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %47)
%49 = load i8*, i8** %9
%50 = getelementptr inbounds i8, i8* %49, i64 0
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = icmp eq i32 %52, 1
br i1 %53, label %84, label %54
54: ; preds = %35
%55 = load i8*, i8** %9
%56 = getelementptr inbounds i8, i8* %55, i64 0
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = icmp eq i32 %58, 2
br i1 %59, label %84, label %60
60: ; preds = %54
%61 = load i8*, i8** %9
%62 = getelementptr inbounds i8, i8* %61, i64 0
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = icmp eq i32 %64, 4
br i1 %65, label %84, label %66
66: ; preds = %60
%67 = load i8*, i8** %9
%68 = getelementptr inbounds i8, i8* %67, i64 0
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = icmp eq i32 %70, 5
br i1 %71, label %84, label %72
72: ; preds = %66
%73 = load i8*, i8** %9
%74 = getelementptr inbounds i8, i8* %73, i64 0
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = icmp eq i32 %76, 6
br i1 %77, label %84, label %78
78: ; preds = %72
%79 = load i8*, i8** %9
%80 = getelementptr inbounds i8, i8* %79, i64 0
%81 = load i8, i8* %80
%82 = zext i8 %81 to i32
%83 = icmp eq i32 %82, 7
br i1 %83, label %84, label %116
84: ; preds = %78, %72, %66, %60, %54, %35
%85 = load i8*, i8** %9
%86 = getelementptr inbounds i8, i8* %85, i64 2
store i8* %86, i8** %9
store i32 0, i32* %7
br label %87
87: ; preds = %112, %84
%88 = load i32, i32* %7
%89 = load i8, i8* %8
%90 = zext i8 %89 to i32
%91 = icmp ult i32 %88, %90
br i1 %91, label %92, label %115
92: ; preds = %87
%93 = load i32, i32* %4
%94 = load i8*, i8** %9
%95 = load i32, i32* %7
%96 = zext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %94, i64 %96
%98 = load i8, i8* %97
%99 = zext i8 %98 to i32
%100 = and i32 %99, 64
%101 = ashr i32 %100, 5
%102 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %93, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %101)
%103 = load i32, i32* %4
%104 = load i8*, i8** %9
%105 = load i32, i32* %7
%106 = zext i32 %105 to i64
%107 = getelementptr inbounds i8, i8* %104, i64 %106
%108 = load i8, i8* %107
%109 = zext i8 %108 to i32
%110 = and i32 %109, 31
%111 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %103, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %110)
br label %112
112: ; preds = %92
%113 = load i32, i32* %7
%114 = add i32 %113, 1
store i32 %114, i32* %7
br label %87
115: ; preds = %87
br label %125
116: ; preds = %78
%117 = load i8*, i8** %9
%118 = getelementptr inbounds i8, i8* %117, i64 2
store i8* %118, i8** %9
%119 = load i32, i32* %4
%120 = load i8*, i8** %9
%121 = getelementptr inbounds i8, i8* %120, i64 0
%122 = load i8, i8* %121
%123 = zext i8 %122 to i32
%124 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %119, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %123)
br label %125
125: ; preds = %116, %115
%126 = load i8, i8* %8
%127 = zext i8 %126 to i32
%128 = load i8*, i8** %9
%129 = sext i32 %127 to i64
%130 = getelementptr inbounds i8, i8* %128, i64 %129
store i8* %130, i8** %9
br label %131
131: ; preds = %125
%132 = load i32, i32* %6
%133 = add i32 %132, 1
store i32 %133, i32* %6
br label %28
134: ; preds = %28
%135 = load i32, i32* %4
%136 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %135, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%137 = load i8*, i8** %5
%138 = getelementptr inbounds i8, i8* %137, i64 1
%139 = load i8, i8* %138
%140 = zext i8 %139 to i32
store i32 %140, i32* %3
br label %141
141: ; preds = %134, %12
%142 = load i32, i32* %3
ret i32 %142
}

LLVM IR (-O2):
@.str = [26 x i8] c"Descriptor_length = 0x%x\0A\00"
@.str.1 = [24 x i8] c"data_service_id = 0x%x\0A\00"
@.str.2 = [39 x i8] c"data_service_descriptor_length = 0x%x\0A\00"
@.str.3 = [21 x i8] c"field_parity = 0x%x\0A\00"
@.str.4 = [20 x i8] c"line_offset = 0x%x\0A\00"
@.str.5 = [21 x i8] c"reserved = 0x%x ...\0A\00"
@.str.6 = [17 x i8] c"******END******\0A\00"
define i32 @x45_Tag_DescriptorParser(i32 %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %62, 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 = load i8, i8* %7
%12 = icmp eq i8 %11, 0
br i1 %12, label %58, label %13
13: ; preds = %4
%14 = getelementptr inbounds i8, i8* %1, i64 2
br label %15
15: ; preds = %13, %50
%16 = phi i8* [ %53, %50 ], [ %14, %13 ]
%17 = phi i32 [ %54, %50 ], [ 0, %13 ]
%18 = load i8, i8* %16
%19 = zext i8 %18 to i32
%20 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds i8, i8* %16, i64 1
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i8, i8* %16
switch i8 %25, label %45 [
i8 1, label %26
i8 2, label %26
i8 4, label %26
i8 5, label %26
i8 6, label %26
i8 7, label %26
]
26: ; preds = %15, %15, %15, %15, %15, %15
%27 = getelementptr inbounds i8, i8* %16, i64 2
%28 = icmp eq i8 %22, 0
br i1 %28, label %50, label %29
29: ; preds = %26
%30 = zext i8 %22 to i64
br label %31
31: ; preds = %29, %31
%32 = phi i64 [ 0, %29 ], [ %43, %31 ]
%33 = getelementptr inbounds i8, i8* %27, i64 %32
%34 = load i8, i8* %33
%35 = lshr i8 %34, 5
%36 = and i8 %35, 2
%37 = zext i8 %36 to i32
%38 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = load i8, i8* %33
%40 = and i8 %39, 31
%41 = zext i8 %40 to i32
%42 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = add nuw nsw i64 %32, 1
%44 = icmp eq i64 %43, %30
br i1 %44, label %50, label %31
45: ; preds = %15
%46 = getelementptr inbounds i8, i8* %16, i64 2
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %31, %26, %45
%51 = getelementptr inbounds i8, i8* %16, i64 2
%52 = zext i8 %22 to i64
%53 = getelementptr inbounds i8, i8* %51, i64 %52
%54 = add nuw nsw i32 %17, 1
%55 = load i8, i8* %7
%56 = zext i8 %55 to i32
%57 = icmp ult i32 %54, %56
br i1 %57, label %15, label %58
58: ; preds = %50, %4
%59 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%60 = load i8, i8* %7
%61 = zext i8 %60 to i32
br label %62
62: ; preds = %2, %58
%63 = phi i32 [ %61, %58 ], [ -1, %2 ]
ret i32 %63
}