#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 x49_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]);
  Parser_TsPacketLog(type, "country_availability_flag = 0x%x\n",
                     (buff[2] & 0x80) >> 7);
  for (i = 1; i < buff[1]; i += 3) {
    Parser_TsPacketLog(type, "country_code = 0x%x\n",
                       ((buff[i + 2] & 0xFF) << 16) |
                           ((buff[i + 3] & 0xFF) << 8) | (buff[i + 4] & 0xFF));
    Parser_TsPacketLog(type, "country_code : %c%c%c\n", (buff[i + 2] & 0xFF),
                       (buff[i + 3] & 0xFF), (buff[i + 4] & 0xFF));
  }
  Parser_TsPacketLog(type, "******END******\n");
  return buff[1];
}


x86 assembly (clang, -O0):
<x49_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 <x49_Tag_DescriptorParser+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    128c <x49_Tag_DescriptorParser+0x16c>
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>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%edx
and    $0x80,%edx
sar    $0x7,%edx
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
cmp    %ecx,%eax
jae    1270 <x49_Tag_DescriptorParser+0x150>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%edx
and    $0xff,%edx
shl    $0x10,%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x3,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%eax
and    $0xff,%eax
shl    $0x8,%eax
or     %eax,%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x4,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%eax
and    $0xff,%eax
or     %eax,%edx
lea    0xe36(%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    $0xff,%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x3,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%esi
add    $0x4,%esi
mov    %esi,%esi
movzbl (%rax,%rsi,1),%r8d
and    $0xff,%r8d
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1030 <Parser_TsPacketLog@plt>
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x14(%rbp)
jmp    119f <x49_Tag_DescriptorParser+0x7f>
mov    -0x8(%rbp),%edi
lea    0xdee(%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):
<x49_Tag_DescriptorParser>:
test   %rsi,%rsi
je     1203 <x49_Tag_DescriptorParser+0xe3>
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>
movzbl 0x2(%rbx),%edx
shr    $0x7,%edx
lea    0xeb8(%rip),%rsi
mov    %r12d,%edi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
cmpb   $0x2,0x1(%rbx)
jb     11e5 <x49_Tag_DescriptorParser+0xc5>
mov    $0x5,%ebp
lea    0xebe(%rip),%r14
lea    0xecc(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
movzbl -0x2(%rbx,%rbp,1),%eax
shl    $0x10,%eax
movzbl -0x1(%rbx,%rbp,1),%ecx
shl    $0x8,%ecx
or     %eax,%ecx
movzbl (%rbx,%rbp,1),%edx
or     %ecx,%edx
mov    %r12d,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl -0x2(%rbx,%rbp,1),%edx
movzbl -0x1(%rbx,%rbp,1),%ecx
movzbl (%rbx,%rbp,1),%r8d
mov    %r12d,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <Parser_TsPacketLog@plt>
movzbl 0x1(%rbx),%eax
lea    0x3(%rbp),%rcx
add    $0xffffffffffffffff,%rbp
cmp    %rax,%rbp
mov    %rcx,%rbp
jb     1190 <x49_Tag_DescriptorParser+0x70>
lea    0xe7c(%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 = [34 x i8] c"country_availability_flag = 0x%x\0A\00"
@.str.2 = [21 x i8] c"country_code = 0x%x\0A\00"
@.str.3 = [23 x i8] c"country_code : %c%c%c\0A\00"
@.str.4 = [17 x i8] c"******END******\0A\00"
define i32 @x49_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 %104
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)
%22 = load i32, i32* %4
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 2
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = and i32 %26, 128
%28 = ashr i32 %27, 7
%29 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %22, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %28)
store i32 1, i32* %6
br label %30
30: ; preds = %94, %10
%31 = load i32, i32* %6
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = icmp ult i32 %31, %35
br i1 %36, label %37, label %97
37: ; preds = %30
%38 = load i32, i32* %4
%39 = load i8*, i8** %5
%40 = load i32, i32* %6
%41 = add i32 %40, 2
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = and i32 %45, 255
%47 = shl i32 %46, 16
%48 = load i8*, i8** %5
%49 = load i32, i32* %6
%50 = add i32 %49, 3
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = and i32 %54, 255
%56 = shl i32 %55, 8
%57 = or i32 %47, %56
%58 = load i8*, i8** %5
%59 = load i32, i32* %6
%60 = add i32 %59, 4
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %58, i64 %61
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = and i32 %64, 255
%66 = or i32 %57, %65
%67 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %38, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %66)
%68 = load i32, i32* %4
%69 = load i8*, i8** %5
%70 = load i32, i32* %6
%71 = add i32 %70, 2
%72 = zext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %69, i64 %72
%74 = load i8, i8* %73
%75 = zext i8 %74 to i32
%76 = and i32 %75, 255
%77 = load i8*, i8** %5
%78 = load i32, i32* %6
%79 = add i32 %78, 3
%80 = zext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %77, i64 %80
%82 = load i8, i8* %81
%83 = zext i8 %82 to i32
%84 = and i32 %83, 255
%85 = load i8*, i8** %5
%86 = load i32, i32* %6
%87 = add i32 %86, 4
%88 = zext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %85, i64 %88
%90 = load i8, i8* %89
%91 = zext i8 %90 to i32
%92 = and i32 %91, 255
%93 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %68, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %76, i32 %84, i32 %92)
br label %94
94: ; preds = %37
%95 = load i32, i32* %6
%96 = add i32 %95, 3
store i32 %96, i32* %6
br label %30
97: ; preds = %30
%98 = load i32, i32* %4
%99 = call i32 (i32, i8*, ...) @Parser_TsPacketLog(i32 %98, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%100 = load i8*, i8** %5
%101 = getelementptr inbounds i8, i8* %100, i64 1
%102 = load i8, i8* %101
%103 = zext i8 %102 to i32
store i32 %103, i32* %3
br label %104
104: ; preds = %97, %9
%105 = load i32, i32* %3
ret i32 %105
}

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