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


x86 assembly (clang, -O0):
<x4B_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 <x4B_Tag_DescriptorParser+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    1274 <x4B_Tag_DescriptorParser+0x154>
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)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
cmp    %ecx,%eax
jae    1258 <x4B_Tag_DescriptorParser+0x138>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rax
movzbl (%rax),%edx
and    $0xff,%edx
shl    $0x8,%edx
mov    -0x20(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0xff,%eax
or     %eax,%edx
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rax
movzbl 0x2(%rax),%edx
and    $0xff,%edx
shl    $0x8,%edx
mov    -0x20(%rbp),%rax
movzbl 0x3(%rax),%eax
and    $0xff,%eax
or     %eax,%edx
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rax
movzbl 0x4(%rax),%edx
and    $0xff,%edx
shl    $0x8,%edx
mov    -0x20(%rbp),%rax
movzbl 0x5(%rax),%eax
and    $0xff,%eax
or     %eax,%edx
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x20(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x14(%rbp)
jmp    1199 <x4B_Tag_DescriptorParser+0x79>
mov    -0x8(%rbp),%edi
lea    0xe03(%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):
<x4B_Tag_DescriptorParser>:
test   %rsi,%rsi
je     11f5 <x4B_Tag_DescriptorParser+0xd5>
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     11d1 <x4B_Tag_DescriptorParser+0xb1>
lea    0xeb6(%rip),%r14
lea    0xecb(%rip),%r15
lea    0xee0(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzwl 0x2(%rbx,%rbp,1),%edx
shl    $0x10,%edx
bswap  %edx
mov    %r13d,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzwl 0x4(%rbx,%rbp,1),%edx
shl    $0x10,%edx
bswap  %edx
mov    %r13d,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzwl 0x6(%rbx,%rbp,1),%edx
shl    $0x10,%edx
bswap  %edx
mov    %r13d,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x1(%rbx),%eax
add    $0x6,%rbp
cmp    %eax,%ebp
jb     1180 <x4B_Tag_DescriptorParser+0x60>
lea    0xe8d(%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 = [28 x i8] c"transport_stream_id = 0x%x\0A\00"
@.str.2 = [28 x i8] c"original_network_id = 0x%x\0A\00"
@.str.3 = [19 x i8] c"service_id = 0x%x\0A\00"
@.str.4 = [17 x i8] c"******END******\0A\00"
define i32 @x4B_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 %88
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
store i32 0, i32* %6
br label %26
26: ; preds = %78, %11
%27 = load i32, i32* %6
%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 ult i32 %27, %31
br i1 %32, label %33, label %81
33: ; preds = %26
%34 = load i32, i32* %4
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = and i32 %38, 255
%40 = shl i32 %39, 8
%41 = load i8*, i8** %7
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = and i32 %44, 255
%46 = or i32 %40, %45
%47 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %34, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %4
%49 = load i8*, i8** %7
%50 = getelementptr inbounds i8, i8* %49, i64 2
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = and i32 %52, 255
%54 = shl i32 %53, 8
%55 = load i8*, i8** %7
%56 = getelementptr inbounds i8, i8* %55, i64 3
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = and i32 %58, 255
%60 = or i32 %54, %59
%61 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %48, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %4
%63 = load i8*, i8** %7
%64 = getelementptr inbounds i8, i8* %63, i64 4
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = and i32 %66, 255
%68 = shl i32 %67, 8
%69 = load i8*, i8** %7
%70 = getelementptr inbounds i8, i8* %69, i64 5
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = and i32 %72, 255
%74 = or i32 %68, %73
%75 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %62, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %74)
%76 = load i8*, i8** %7
%77 = getelementptr inbounds i8, i8* %76, i64 6
store i8* %77, i8** %7
br label %78
78: ; preds = %33
%79 = load i32, i32* %6
%80 = add i32 %79, 6
store i32 %80, i32* %6
br label %26
81: ; preds = %26
%82 = load i32, i32* %4
%83 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %82, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%84 = load i8*, i8** %5
%85 = getelementptr inbounds i8, i8* %84, i64 1
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
store i32 %87, i32* %3
br label %88
88: ; preds = %81, %10
%89 = load i32, i32* %3
ret i32 %89
}

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