#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 x72_Tag_DescriptorParser(unsigned int type, unsigned char *buff) {
  unsigned int i = 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]);
  Parser_TsPacketLog(type, "availability_flag = 0x%x\n", (buff[2] & 0x80) >> 7);
  data = buff;
  data += 2;
  if (buff[1] > 1) {
    for (i = 1; i < buff[1]; i += 2) {
      Parser_TsPacketLog(type, "cell_id = 0x%x\n",
                         ((data[i] & 0xFF) << 8) | (data[i + 1] & 0xFF));
    }
  }
  Parser_TsPacketLog(type, "******END******\n");
  return buff[1];
}


x86 assembly (clang, -O0):
<x72_Tag_DescriptorParser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1156 <x72_Tag_DescriptorParser+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    124a <x72_Tag_DescriptorParser+0x12a>
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    0xe89(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%edx
and    $0x80,%edx
sar    $0x7,%edx
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x1,%eax
jle    122e <x72_Tag_DescriptorParser+0x10e>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
cmp    %ecx,%eax
jae    1229 <x72_Tag_DescriptorParser+0x109>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
movzbl (%rax,%rcx,1),%edx
and    $0xff,%edx
shl    $0x8,%edx
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%eax
and    $0xff,%eax
or     %eax,%edx
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    11cc <x72_Tag_DescriptorParser+0xac>
jmp    122e <x72_Tag_DescriptorParser+0x10e>
mov    -0x8(%rbp),%edi
lea    0xe0c(%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):
<x72_Tag_DescriptorParser>:
test   %rsi,%rsi
je     11cb <x72_Tag_DescriptorParser+0xab>
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
shr    $0x7,%edx
lea    0xeb9(%rip),%rsi
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
cmpb   $0x2,0x1(%rbx)
jb     11ab <x72_Tag_DescriptorParser+0x8b>
mov    $0x4,%ebp
lea    0xeb7(%rip),%r14
nopl   (%rax)
movzwl -0x1(%rbx,%rbp,1),%edx
shl    $0x10,%edx
bswap  %edx
mov    %r15d,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x1(%rbx),%eax
lea    0x2(%rbp),%rcx
add    $0xffffffffffffffff,%rbp
cmp    %rax,%rbp
mov    %rcx,%rbp
jb     1180 <x72_Tag_DescriptorParser+0x60>
lea    0xe92(%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 = [26 x i8] c"availability_flag = 0x%x\0A\00"
@.str.2 = [16 x i8] c"cell_id = 0x%x\0A\00"
@.str.3 = [17 x i8] c"******END******\0A\00"
define i32 @x72_Tag_DescriptorParser(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i8* null, i8** %7
%8 = load i8*, i8** %5
%9 = icmp eq i8* null, %8
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %78
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = call i32 @Parser_DisplayTagInfo(i32 %12, i8 zeroext %15)
%17 = load i32, i32* %4
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %4
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 2
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = and i32 %27, 128
%29 = ashr i32 %28, 7
%30 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %23, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i8*, i8** %5
store i8* %31, i8** %7
%32 = load i8*, i8** %7
%33 = getelementptr inbounds i8, i8* %32, i64 2
store i8* %33, i8** %7
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = icmp sgt i32 %37, 1
br i1 %38, label %39, label %71
39: ; preds = %11
store i32 1, i32* %6
br label %40
40: ; preds = %67, %39
%41 = load i32, i32* %6
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = icmp ult i32 %41, %45
br i1 %46, label %47, label %70
47: ; preds = %40
%48 = load i32, i32* %4
%49 = load i8*, i8** %7
%50 = load i32, i32* %6
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = and i32 %54, 255
%56 = shl i32 %55, 8
%57 = load i8*, i8** %7
%58 = load i32, i32* %6
%59 = add i32 %58, 1
%60 = zext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %57, i64 %60
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = and i32 %63, 255
%65 = or i32 %56, %64
%66 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %48, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %47
%68 = load i32, i32* %6
%69 = add i32 %68, 2
store i32 %69, i32* %6
br label %40
70: ; preds = %40
br label %71
71: ; preds = %70, %11
%72 = load i32, i32* %4
%73 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %72, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%74 = load i8*, i8** %5
%75 = getelementptr inbounds i8, i8* %74, i64 1
%76 = load i8, i8* %75
%77 = zext i8 %76 to i32
store i32 %77, i32* %3
br label %78
78: ; preds = %71, %10
%79 = load i32, i32* %3
ret i32 %79
}

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