#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 x41_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]);
  data = buff;
  data += 2;
  if (0 != buff[1]) {
    for (i = 0; i < buff[1]; i += 3) {
      Parser_TsPacketLog(type, "service_id = 0x%x\n",
                         ((data[i] & 0xFF) << 8) | (data[i + 1] & 0xFF));
      Parser_TsPacketLog(type, "service_type = 0x%x\n", data[i + 2]);
    }
  }
  Parser_TsPacketLog(type, "******END******\n");
  return buff[1];
}


x86 assembly (clang, -O0):
<x41_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 <x41_Tag_DescriptorParser+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    124a <x41_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    -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),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     122e <x41_Tag_DescriptorParser+0x10e>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
cmp    %ecx,%eax
jae    1229 <x41_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    0xe27(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%edx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x14(%rbp)
jmp    11ab <x41_Tag_DescriptorParser+0x8b>
jmp    122e <x41_Tag_DescriptorParser+0x10e>
mov    -0x8(%rbp),%edi
lea    0xe0a(%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):
<x41_Tag_DescriptorParser>:
test   %rsi,%rsi
je     11c4 <x41_Tag_DescriptorParser+0xa4>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r12d
movzbl (%rsi),%esi
call   1040 <Parser_DisplayTagInfo@plt>
movzbl 0x1(%rbx),%edx
lea    0xeb6(%rip),%rsi
mov    %r12d,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
cmpb   $0x0,0x1(%rbx)
je     11a6 <x41_Tag_DescriptorParser+0x86>
lea    0xeb9(%rip),%r14
lea    0xec5(%rip),%r15
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movzwl 0x2(%rbx,%rbp,1),%edx
shl    $0x10,%edx
bswap  %edx
mov    %r12d,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x4(%rbx,%rbp,1),%edx
mov    %r12d,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
add    $0x3,%rbp
movzbl 0x1(%rbx),%eax
cmp    %rax,%rbp
jb     1170 <x41_Tag_DescriptorParser+0x50>
lea    0xe95(%rip),%rsi
mov    %r12d,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x1(%rbx),%eax
pop    %rbx
pop    %r12
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 = [19 x i8] c"service_id = 0x%x\0A\00"
@.str.2 = [21 x i8] c"service_type = 0x%x\0A\00"
@.str.3 = [17 x i8] c"******END******\0A\00"
define i32 @x41_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 %79
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 i8*, i8** %5
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i64 2
store i8* %25, i8** %7
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = icmp ne i32 0, %29
br i1 %30, label %31, label %72
31: ; preds = %11
store i32 0, i32* %6
br label %32
32: ; preds = %68, %31
%33 = load i32, i32* %6
%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 ult i32 %33, %37
br i1 %38, label %39, label %71
39: ; preds = %32
%40 = load i32, i32* %4
%41 = load i8*, i8** %7
%42 = load i32, i32* %6
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = and i32 %46, 255
%48 = shl i32 %47, 8
%49 = load i8*, i8** %7
%50 = load i32, i32* %6
%51 = add i32 %50, 1
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %49, i64 %52
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = and i32 %55, 255
%57 = or i32 %48, %56
%58 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %40, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %4
%60 = load i8*, i8** %7
%61 = load i32, i32* %6
%62 = add i32 %61, 2
%63 = zext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %60, i64 %63
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %59, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %39
%69 = load i32, i32* %6
%70 = add i32 %69, 3
store i32 %70, i32* %6
br label %32
71: ; preds = %32
br label %72
72: ; preds = %71, %11
%73 = load i32, i32* %4
%74 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %73, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%75 = load i8*, i8** %5
%76 = getelementptr inbounds i8, i8* %75, i64 1
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
store i32 %78, i32* %3
br label %79
79: ; preds = %72, %10
%80 = load i32, i32* %3
ret i32 %80
}

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