#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*/ dStrHex(char const *, int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
void decode_proto_lu_vpd(unsigned char *buff, int len, int do_hex) {
  int k, bump, rel_port, desc_len, proto;
  unsigned char *ucp;
  if (1 == do_hex) {
    dStrHex((const char *)buff, len, 0);
    return;
  }
  if (len < 4) {
    fprintf(stderr,
            "Protocol-specific logical unit information VPD "
            "page length too short=%d\n",
            len);
    return;
  }
  len -= 4;
  ucp = buff + 4;
  for (k = 0; k < len; k += bump, ucp += bump) {
    rel_port = (ucp[0] << 8) + ucp[1];
    printf("Relative port=%d\n", rel_port);
    proto = ucp[2] & 0xf;
    desc_len = (ucp[6] << 8) + ucp[7];
    bump = 8 + desc_len;
    if ((k + bump) > len) {
      fprintf(stderr,
              "Protocol-specific logical unit information VPD "
              "page, short descriptor length=%d, left=%d\n",
              bump, (len - k));
      return;
    }
    if (0 == desc_len)
      continue;
    if (2 == do_hex)
      dStrHex((const char *)ucp + 8, desc_len, 1);
    else if (do_hex > 2)
      dStrHex((const char *)ucp, bump, 1);
    else {
      switch (proto) {
      case 6:
        printf(" Protocol identifier: SAS\n");
        printf(" TLR control supported: %d\n", !!(ucp[8] & 0x1));
        break;
      default:
        fprintf(stderr, "Unexpected proto=%d\n", proto);
        dStrHex((const char *)ucp, bump, 1);
        break;
      }
    }
  }
}


x86 assembly (clang, -O0):
<decode_proto_lu_vpd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    $0x1,%eax
cmp    -0x10(%rbp),%eax
jne    1163 <decode_proto_lu_vpd+0x33>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
xor    %edx,%edx
call   1030 <dStrHex@plt>
jmp    133c <decode_proto_lu_vpd+0x20c>
cmpl   $0x4,-0xc(%rbp)
jge    118c <decode_proto_lu_vpd+0x5c>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    133c <decode_proto_lu_vpd+0x20c>
mov    -0xc(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    133c <decode_proto_lu_vpd+0x20c>
mov    -0x30(%rbp),%rax
movzbl (%rax),%eax
shl    $0x8,%eax
mov    -0x30(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0xf,%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rax
movzbl 0x6(%rax),%eax
shl    $0x8,%eax
mov    -0x30(%rbp),%rcx
movzbl 0x7(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    123f <decode_proto_lu_vpd+0x10f>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0xc(%rbp),%ecx
sub    -0x14(%rbp),%ecx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    133c <decode_proto_lu_vpd+0x20c>
xor    %eax,%eax
cmp    -0x20(%rbp),%eax
jne    124f <decode_proto_lu_vpd+0x11f>
jmp    131d <decode_proto_lu_vpd+0x1ed>
mov    $0x2,%eax
cmp    -0x10(%rbp),%eax
jne    1277 <decode_proto_lu_vpd+0x147>
mov    -0x30(%rbp),%rdi
add    $0x8,%rdi
mov    -0x20(%rbp),%esi
mov    $0x1,%edx
call   1030 <dStrHex@plt>
jmp    1318 <decode_proto_lu_vpd+0x1e8>
cmpl   $0x2,-0x10(%rbp)
jle    1297 <decode_proto_lu_vpd+0x167>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x1,%edx
call   1030 <dStrHex@plt>
jmp    1313 <decode_proto_lu_vpd+0x1e3>
mov    -0x24(%rbp),%eax
sub    $0x6,%eax
jne    12e3 <decode_proto_lu_vpd+0x1b3>
jmp    12a8 <decode_proto_lu_vpd+0x178>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
movzbl 0x8(%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    130e <decode_proto_lu_vpd+0x1de>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x1,%edx
call   1030 <dStrHex@plt>
jmp    1313 <decode_proto_lu_vpd+0x1e3>
jmp    1318 <decode_proto_lu_vpd+0x1e8>
jmp    131d <decode_proto_lu_vpd+0x1ed>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    11a8 <decode_proto_lu_vpd+0x78>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_proto_lu_vpd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
cmp    $0x1,%edx
jne    116f <decode_proto_lu_vpd+0x2f>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <dStrHex@plt>
cmp    $0x3,%ebp
jg     119b <decode_proto_lu_vpd+0x5b>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fprintf@plt>
cmp    $0x4,%ebp
jne    11af <decode_proto_lu_vpd+0x6f>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edx,%r14d
add    $0xfffffffc,%ebp
add    $0x4,%rbx
xor    %r12d,%r12d
jmp    11d6 <decode_proto_lu_vpd+0x96>
xchg   %ax,%ax
lea    0x8(%rbx),%rdi
mov    $0x1,%edx
call   1040 <dStrHex@plt>
add    %r13,%rbx
cmp    %r12d,%ebp
jle    11a0 <decode_proto_lu_vpd+0x60>
mov    %r12d,%r15d
movzwl (%rbx),%esi
shl    $0x10,%esi
bswap  %esi
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0x6(%rbx),%esi
shl    $0x30,%rsi
bswap  %rsi
lea    0x8(%rsi),%r13
lea    (%r15,%r13,1),%r12d
cmp    %ebp,%r12d
jg     1264 <decode_proto_lu_vpd+0x124>
test   %esi,%esi
je     11ce <decode_proto_lu_vpd+0x8e>
cmp    $0x2,%r14d
je     11c0 <decode_proto_lu_vpd+0x80>
jg     1259 <decode_proto_lu_vpd+0x119>
movzbl 0x2(%rbx),%edx
and    $0xf,%edx
cmp    $0x6,%dl
jne    1242 <decode_proto_lu_vpd+0x102>
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
movzbl 0x8(%rbx),%esi
and    $0x1,%esi
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11ce <decode_proto_lu_vpd+0x8e>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r13d,%esi
jmp    11c4 <decode_proto_lu_vpd+0x84>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
sub    %r15d,%ebp
lea    0xde4(%rip),%rsi
mov    %r13d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [73 x i8] c"Protocol-specific logical unit information VPD page length too short=%d\0A\00"
@.str.1 = [18 x i8] c"Relative port=%d\0A\00"
@.str.2 = [90 x i8] c"Protocol-specific logical unit information VPD page, short descriptor length=%d, left=%d\0A\00"
@.str.3 = [27 x i8] c" Protocol identifier: SAS\0A\00"
@.str.4 = [28 x i8] c" TLR control supported: %d\0A\00"
@.str.5 = [21 x i8] c"Unexpected proto=%d\0A\00"
define void @decode_proto_lu_vpd(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 1, %13
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i8*, i8** %4
%17 = load i32, i32* %5
%18 = call i32 @dStrHex(i8* %16, i32 %17, i32 0)
br label %128
19: ; preds = %3
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 4
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = load i32, i32* %5
%25 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %128
26: ; preds = %19
%27 = load i32, i32* %5
%28 = sub nsw i32 %27, 4
store i32 %28, i32* %5
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i64 4
store i8* %30, i8** %12
store i32 0, i32* %7
br label %31
31: ; preds = %120, %26
%32 = load i32, i32* %7
%33 = load i32, i32* %5
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %128
35: ; preds = %31
%36 = load i8*, i8** %12
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = shl i32 %39, 8
%41 = load i8*, i8** %12
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = add nsw i32 %40, %44
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i8*, i8** %12
%49 = getelementptr inbounds i8, i8* %48, i64 2
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = and i32 %51, 15
store i32 %52, i32* %11
%53 = load i8*, i8** %12
%54 = getelementptr inbounds i8, i8* %53, i64 6
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = shl i32 %56, 8
%58 = load i8*, i8** %12
%59 = getelementptr inbounds i8, i8* %58, i64 7
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = add nsw i32 %57, %61
store i32 %62, i32* %10
%63 = load i32, i32* %10
%64 = add nsw i32 8, %63
store i32 %64, i32* %8
%65 = load i32, i32* %7
%66 = load i32, i32* %8
%67 = add nsw i32 %65, %66
%68 = load i32, i32* %5
%69 = icmp sgt i32 %67, %68
br i1 %69, label %70, label %77
70: ; preds = %35
%71 = load i32, i32* @stderr
%72 = load i32, i32* %8
%73 = load i32, i32* %5
%74 = load i32, i32* %7
%75 = sub nsw i32 %73, %74
%76 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.2, i64 0, i64 0), i32 %72, i32 %75)
br label %128
77: ; preds = %35
%78 = load i32, i32* %10
%79 = icmp eq i32 0, %78
br i1 %79, label %80, label %81
80: ; preds = %77
br label %120
81: ; preds = %77
%82 = load i32, i32* %6
%83 = icmp eq i32 2, %82
br i1 %83, label %84, label %89
84: ; preds = %81
%85 = load i8*, i8** %12
%86 = getelementptr inbounds i8, i8* %85, i64 8
%87 = load i32, i32* %10
%88 = call i32 @dStrHex(i8* %86, i32 %87, i32 1)
br label %119
89: ; preds = %81
%90 = load i32, i32* %6
%91 = icmp sgt i32 %90, 2
br i1 %91, label %92, label %96
92: ; preds = %89
%93 = load i8*, i8** %12
%94 = load i32, i32* %8
%95 = call i32 @dStrHex(i8* %93, i32 %94, i32 1)
br label %118
96: ; preds = %89
%97 = load i32, i32* %11
switch i32 %97, label %110 [
i32 6, label %98
]
98: ; preds = %96
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%100 = load i8*, i8** %12
%101 = getelementptr inbounds i8, i8* %100, i64 8
%102 = load i8, i8* %101
%103 = zext i8 %102 to i32
%104 = and i32 %103, 1
%105 = icmp ne i32 %104, 0
%106 = xor i1 %105, true
%107 = xor i1 %106, true
%108 = zext i1 %107 to i32
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %108)
br label %117
110: ; preds = %96
%111 = load i32, i32* @stderr
%112 = load i32, i32* %11
%113 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %112)
%114 = load i8*, i8** %12
%115 = load i32, i32* %8
%116 = call i32 @dStrHex(i8* %114, i32 %115, i32 1)
br label %117
117: ; preds = %110, %98
br label %118
118: ; preds = %117, %92
br label %119
119: ; preds = %118, %84
br label %120
120: ; preds = %119, %80
%121 = load i32, i32* %8
%122 = load i32, i32* %7
%123 = add nsw i32 %122, %121
store i32 %123, i32* %7
%124 = load i32, i32* %8
%125 = load i8*, i8** %12
%126 = sext i32 %124 to i64
%127 = getelementptr inbounds i8, i8* %125, i64 %126
store i8* %127, i8** %12
br label %31
128: ; preds = %15, %22, %70, %31
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [73 x i8] c"Protocol-specific logical unit information VPD page length too short=%d\0A\00"
@.str.1 = [18 x i8] c"Relative port=%d\0A\00"
@.str.2 = [90 x i8] c"Protocol-specific logical unit information VPD page, short descriptor length=%d, left=%d\0A\00"
@.str.4 = [28 x i8] c" TLR control supported: %d\0A\00"
@.str.5 = [21 x i8] c"Unexpected proto=%d\0A\00"
@str = [26 x i8] c" Protocol identifier: SAS\00"
define void @decode_proto_lu_vpd(i8* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 1
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @dStrHex(i8* %0, i32 %1, i32 0)
br label %75
7: ; preds = %3
%8 = icmp slt i32 %1, 4
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %75
12: ; preds = %7
%13 = add nsw i32 %1, -4
%14 = icmp eq i32 %1, 4
br i1 %14, label %75, label %15
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %0, i64 4
%17 = icmp eq i32 %2, 2
%18 = icmp sgt i32 %2, 2
br label %19
19: ; preds = %15, %71
%20 = phi i8* [ %16, %15 ], [ %73, %71 ]
%21 = phi i32 [ 0, %15 ], [ %43, %71 ]
%22 = load i8, i8* %20
%23 = zext i8 %22 to i32
%24 = shl nuw nsw i32 %23, 8
%25 = getelementptr inbounds i8, i8* %20, i64 1
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = or i32 %24, %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds i8, i8* %20, i64 2
%31 = load i8, i8* %30
%32 = and i8 %31, 15
%33 = zext i8 %32 to i32
%34 = getelementptr inbounds i8, i8* %20, i64 6
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = shl nuw nsw i32 %36, 8
%38 = getelementptr inbounds i8, i8* %20, i64 7
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = or i32 %37, %40
%42 = add nuw nsw i32 %41, 8
%43 = add nuw nsw i32 %42, %21
%44 = icmp sgt i32 %43, %13
br i1 %44, label %45, label %49
45: ; preds = %19
%46 = load i32, i32* @stderr
%47 = sub nsw i32 %13, %21
%48 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.2, i64 0, i64 0), i32 %42, i32 %47)
br label %75
49: ; preds = %19
%50 = icmp eq i32 %41, 0
br i1 %50, label %71, label %51
51: ; preds = %49
br i1 %17, label %52, label %55
52: ; preds = %51
%53 = getelementptr inbounds i8, i8* %20, i64 8
%54 = tail call i32 @dStrHex(i8* %53, i32 %41, i32 1)
br label %71
55: ; preds = %51
br i1 %18, label %56, label %58
56: ; preds = %55
%57 = tail call i32 @dStrHex(i8* %20, i32 %42, i32 1)
br label %71
58: ; preds = %55
%59 = icmp eq i8 %32, 6
br i1 %59, label %60, label %67
60: ; preds = %58
%61 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%62 = getelementptr inbounds i8, i8* %20, i64 8
%63 = load i8, i8* %62
%64 = and i8 %63, 1
%65 = zext i8 %64 to i32
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %65)
br label %71
67: ; preds = %58
%68 = load i32, i32* @stderr
%69 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %33)
%70 = tail call i32 @dStrHex(i8* %20, i32 %42, i32 1)
br label %71
71: ; preds = %52, %60, %67, %56, %49
%72 = zext i32 %42 to i64
%73 = getelementptr inbounds i8, i8* %20, i64 %72
%74 = icmp sgt i32 %13, %43
br i1 %74, label %19, label %75
75: ; preds = %71, %12, %45, %9, %5
ret void
}