#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 x7F_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, "descriptor_tag_extension = 0x%x\n", buff[2]);
  if (buff[1] > 1) {
    Parser_TsPacketLog(type, "selector_byte:");
    for (i = 1; i < buff[1]; i++) {
      Parser_TsPacketLog(type, " 0x%02x", buff[i + 2]);
    }
    Parser_TsPacketLog(type, "\n");
  }
  Parser_TsPacketLog(type, "******END******\n");
  return buff[1];
}


x86 assembly (clang, -O0):
<x7F_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 <x7F_Tag_DescriptorParser+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1227 <x7F_Tag_DescriptorParser+0x107>
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
lea    0xe92(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x1,%eax
jle    120b <x7F_Tag_DescriptorParser+0xeb>
mov    -0x8(%rbp),%edi
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
cmp    %ecx,%eax
jae    11fa <x7F_Tag_DescriptorParser+0xda>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%edx
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b8 <x7F_Tag_DescriptorParser+0x98>
mov    -0x8(%rbp),%edi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x8(%rbp),%edi
lea    0xe3d(%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):
<x7F_Tag_DescriptorParser>:
test   %rsi,%rsi
je     11f0 <x7F_Tag_DescriptorParser+0xd0>
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>
movzbl 0x2(%rbx),%edx
lea    0xebc(%rip),%rsi
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
cmpb   $0x2,0x1(%rbx)
jb     11d0 <x7F_Tag_DescriptorParser+0xb0>
lea    0xec6(%rip),%rsi
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
cmpb   $0x2,0x1(%rbx)
jb     11bf <x7F_Tag_DescriptorParser+0x9f>
mov    $0x1,%ebp
lea    0xeb9(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x2(%rbx,%rbp,1),%edx
mov    %r15d,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
add    $0x1,%rbp
movzbl 0x1(%rbx),%eax
cmp    %rax,%rbp
jb     11a0 <x7F_Tag_DescriptorParser+0x80>
lea    0xe9b(%rip),%rsi
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
lea    0xe7b(%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 = [33 x i8] c"descriptor_tag_extension = 0x%x\0A\00"
@.str.2 = [15 x i8] c"selector_byte:\00"
@.str.3 = [8 x i8] c" 0x%02x\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [17 x i8] c"******END******\0A\00"
define i32 @x7F_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 %66
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 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %22, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = icmp sgt i32 %31, 1
br i1 %32, label %33, label %59
33: ; preds = %10
%34 = load i32, i32* %4
%35 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %34, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %6
br label %36
36: ; preds = %53, %33
%37 = load i32, i32* %6
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = icmp ult i32 %37, %41
br i1 %42, label %43, label %56
43: ; preds = %36
%44 = load i32, i32* %4
%45 = load i8*, i8** %5
%46 = load i32, i32* %6
%47 = add i32 %46, 2
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %44, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %43
%54 = load i32, i32* %6
%55 = add i32 %54, 1
store i32 %55, i32* %6
br label %36
56: ; preds = %36
%57 = load i32, i32* %4
%58 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %56, %10
%60 = load i32, i32* %4
%61 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %60, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%62 = load i8*, i8** %5
%63 = getelementptr inbounds i8, i8* %62, i64 1
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
store i32 %65, i32* %3
br label %66
66: ; preds = %59, %9
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str = [26 x i8] c"Descriptor_length = 0x%x\0A\00"
@.str.1 = [33 x i8] c"descriptor_tag_extension = 0x%x\0A\00"
@.str.2 = [15 x i8] c"selector_byte:\00"
@.str.3 = [8 x i8] c" 0x%02x\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [17 x i8] c"******END******\0A\00"
define i32 @x7F_Tag_DescriptorParser(i32 %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %38, 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 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i8, i8* %7
%16 = icmp ugt i8 %15, 1
br i1 %16, label %17, label %34
17: ; preds = %4
%18 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%19 = load i8, i8* %7
%20 = icmp ugt i8 %19, 1
br i1 %20, label %21, label %32
21: ; preds = %17, %21
%22 = phi i64 [ %28, %21 ], [ 1, %17 ]
%23 = add nuw nsw i64 %22, 2
%24 = getelementptr inbounds i8, i8* %1, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = add nuw nsw i64 %22, 1
%29 = load i8, i8* %7
%30 = zext i8 %29 to i64
%31 = icmp ult i64 %28, %30
br i1 %31, label %21, label %32
32: ; preds = %21, %17
%33 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %4
%35 = tail call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%36 = load i8, i8* %7
%37 = zext i8 %36 to i32
br label %38
38: ; preds = %2, %34
%39 = phi i32 [ %37, %34 ], [ -1, %2 ]
ret i32 %39
}