#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 x54_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]);
  for (i = 0; i < buff[1]; i += 2) {
    Parser_TsPacketLog(type, "content_nibble_level_1 = 0x%x\n",
                       ((buff[i + 2] & 0xF0) >> 4));
    Parser_TsPacketLog(type, "content_nibble_level_2 = 0x%x\n",
                       buff[i + 2] & 0x0F);
    Parser_TsPacketLog(type, "user_byte = 0x%x\n", buff[i + 3]);
  }
  Parser_TsPacketLog(type, "******END******\n");
  return buff[1];
}


x86 assembly (clang, -O0):
<x54_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 <x54_Tag_DescriptorParser+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <x54_Tag_DescriptorParser+0x109>
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>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
cmp    %ecx,%eax
jae    120d <x54_Tag_DescriptorParser+0xed>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%edx
and    $0xf0,%edx
sar    $0x4,%edx
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%edx
and    $0xf,%edx
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x3,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%edx
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    117d <x54_Tag_DescriptorParser+0x5d>
mov    -0x8(%rbp),%edi
lea    0xe53(%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):
<x54_Tag_DescriptorParser>:
test   %rsi,%rsi
je     11e4 <x54_Tag_DescriptorParser+0xc4>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r13d
movzbl (%rsi),%esi
call   1040 <Parser_DisplayTagInfo@plt>
movzbl 0x1(%rbx),%edx
lea    0xeb3(%rip),%rsi
mov    %r13d,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
cmpb   $0x0,0x1(%rbx)
je     11c0 <x54_Tag_DescriptorParser+0xa0>
lea    0xed5(%rip),%r15
lea    0xeed(%rip),%r12
xor    %ebp,%ebp
nopl   (%rax)
lea    0x2(%rbp),%r14
movzbl 0x2(%rbx,%rbp,1),%edx
shr    $0x4,%edx
mov    %r13d,%edi
lea    0xe94(%rip),%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x2(%rbx,%rbp,1),%edx
and    $0xf,%edx
mov    %r13d,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x3(%rbx,%rbp,1),%edx
mov    %r13d,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x1(%rbx),%eax
mov    %r14,%rbp
cmp    %rax,%r14
jb     1170 <x54_Tag_DescriptorParser+0x50>
lea    0xea3(%rip),%rsi
mov    %r13d,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x1(%rbx),%eax
add    $0x8,%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 = [31 x i8] c"content_nibble_level_1 = 0x%x\0A\00"
@.str.2 = [31 x i8] c"content_nibble_level_2 = 0x%x\0A\00"
@.str.3 = [18 x i8] c"user_byte = 0x%x\0A\00"
@.str.4 = [17 x i8] c"******END******\0A\00"
define i32 @x54_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 %70
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)
store i32 0, i32* %6
br label %22
22: ; preds = %60, %10
%23 = load i32, i32* %6
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = icmp ult i32 %23, %27
br i1 %28, label %29, label %63
29: ; preds = %22
%30 = load i32, i32* %4
%31 = load i8*, i8** %5
%32 = load i32, i32* %6
%33 = add i32 %32, 2
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = and i32 %37, 240
%39 = ashr i32 %38, 4
%40 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %30, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %4
%42 = load i8*, i8** %5
%43 = load i32, i32* %6
%44 = add i32 %43, 2
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = and i32 %48, 15
%50 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %41, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %4
%52 = load i8*, i8** %5
%53 = load i32, i32* %6
%54 = add i32 %53, 3
%55 = zext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %51, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %29
%61 = load i32, i32* %6
%62 = add i32 %61, 2
store i32 %62, i32* %6
br label %22
63: ; preds = %22
%64 = load i32, i32* %4
%65 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %64, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%66 = load i8*, i8** %5
%67 = getelementptr inbounds i8, i8* %66, i64 1
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
store i32 %69, i32* %3
br label %70
70: ; preds = %63, %9
%71 = load i32, i32* %3
ret i32 %71
}

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