#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 x46_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 += 5) {
    Parser_TsPacketLog(type, "ISO_639_language_code = 0x%x : %c%c%c\n",
                       ((data[0] & 0xFF) << 16) | ((buff[1] & 0xFF) << 8) |
                           (buff[2] & 0xFF),
                       data[0], data[1], data[2]);
    Parser_TsPacketLog(type, "teletext_type = 0x%x\n", (data[3] & 0xF8) >> 3);
    Parser_TsPacketLog(type, "teletext_magazine_number = 0x%x\n",
                       data[3] & 0x07);
    Parser_TsPacketLog(type, "teletext_page_number = 0x%x\n", data[4]);
    data += 5;
  }
  Parser_TsPacketLog(type, "******END******\n");
  return buff[1];
}


x86 assembly (clang, -O0):
<x46_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 <x46_Tag_DescriptorParser+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    1294 <x46_Tag_DescriptorParser+0x174>
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    1278 <x46_Tag_DescriptorParser+0x158>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rax
movzbl (%rax),%edx
and    $0xff,%edx
shl    $0x10,%edx
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0xff,%eax
shl    $0x8,%eax
or     %eax,%edx
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0xff,%eax
or     %eax,%edx
mov    -0x20(%rbp),%rax
movzbl (%rax),%ecx
mov    -0x20(%rbp),%rax
movzbl 0x1(%rax),%r8d
mov    -0x20(%rbp),%rax
movzbl 0x2(%rax),%r9d
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rax
movzbl 0x3(%rax),%edx
and    $0xf8,%edx
sar    $0x3,%edx
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rax
movzbl 0x3(%rax),%edx
and    $0x7,%edx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rax
movzbl 0x4(%rax),%edx
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x20(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x14(%rbp)
jmp    1199 <x46_Tag_DescriptorParser+0x79>
mov    -0x8(%rbp),%edi
lea    0xe13(%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):
<x46_Tag_DescriptorParser>:
test   %rsi,%rsi
je     121e <x46_Tag_DescriptorParser+0xfe>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
movzbl (%rsi),%esi
call   1040 <Parser_DisplayTagInfo@plt>
movzbl 0x1(%rbx),%edx
lea    0xeb4(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x1(%rbx),%eax
test   %eax,%eax
je     11fb <x46_Tag_DescriptorParser+0xdb>
lea    0xed9(%rip),%r15
lea    0xee8(%rip),%r12
lea    0xf02(%rip),%r13
xor    %r14d,%r14d
nopl   0x0(%rax)
movzbl 0x2(%rbx,%r14,1),%ecx
mov    %ecx,%edx
shl    $0x10,%edx
shl    $0x8,%eax
or     %edx,%eax
movzbl 0x2(%rbx),%edx
or     %eax,%edx
movzbl 0x3(%rbx,%r14,1),%r8d
movzbl 0x4(%rbx,%r14,1),%r9d
mov    %ebp,%edi
lea    0xe6f(%rip),%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x5(%rbx,%r14,1),%edx
shr    $0x3,%edx
mov    %ebp,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x5(%rbx,%r14,1),%edx
and    $0x7,%edx
mov    %ebp,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x6(%rbx,%r14,1),%edx
mov    %ebp,%edi
mov    %r13,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x1(%rbx),%eax
add    $0x5,%r14
cmp    %eax,%r14d
jb     1180 <x46_Tag_DescriptorParser+0x60>
lea    0xe93(%rip),%rsi
mov    %ebp,%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 = [39 x i8] c"ISO_639_language_code = 0x%x : %c%c%c\0A\00"
@.str.2 = [22 x i8] c"teletext_type = 0x%x\0A\00"
@.str.3 = [33 x i8] c"teletext_magazine_number = 0x%x\0A\00"
@.str.4 = [29 x i8] c"teletext_page_number = 0x%x\0A\00"
@.str.5 = [17 x i8] c"******END******\0A\00"
define i32 @x46_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 %100
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 = %90, %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 %93
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, 16
%41 = load i8*, i8** %5
%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 = shl i32 %45, 8
%47 = or i32 %40, %46
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 2
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = and i32 %51, 255
%53 = or i32 %47, %52
%54 = load i8*, i8** %7
%55 = getelementptr inbounds i8, i8* %54, i64 0
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = load i8*, i8** %7
%59 = getelementptr inbounds i8, i8* %58, i64 1
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = load i8*, i8** %7
%63 = getelementptr inbounds i8, i8* %62, i64 2
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %34, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %53, i32 %57, i32 %61, i32 %65)
%67 = load i32, i32* %4
%68 = load i8*, i8** %7
%69 = getelementptr inbounds i8, i8* %68, i64 3
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = and i32 %71, 248
%73 = ashr i32 %72, 3
%74 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %67, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %73)
%75 = load i32, i32* %4
%76 = load i8*, i8** %7
%77 = getelementptr inbounds i8, i8* %76, i64 3
%78 = load i8, i8* %77
%79 = zext i8 %78 to i32
%80 = and i32 %79, 7
%81 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %75, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %80)
%82 = load i32, i32* %4
%83 = load i8*, i8** %7
%84 = getelementptr inbounds i8, i8* %83, i64 4
%85 = load i8, i8* %84
%86 = zext i8 %85 to i32
%87 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %82, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %86)
%88 = load i8*, i8** %7
%89 = getelementptr inbounds i8, i8* %88, i64 5
store i8* %89, i8** %7
br label %90
90: ; preds = %33
%91 = load i32, i32* %6
%92 = add i32 %91, 5
store i32 %92, i32* %6
br label %26
93: ; preds = %26
%94 = load i32, i32* %4
%95 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %94, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%96 = load i8*, i8** %5
%97 = getelementptr inbounds i8, i8* %96, i64 1
%98 = load i8, i8* %97
%99 = zext i8 %98 to i32
store i32 %99, i32* %3
br label %100
100: ; preds = %93, %10
%101 = load i32, i32* %3
ret i32 %101
}

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