#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;
int decode_proto_lu_vpd(unsigned char *buff, int len) {
  int k, bump, rel_port, desc_len, proto;
  unsigned char *ucp;
  if (len < 4) {
    fprintf(stderr,
            "Protocol-specific logical unit information VPD "
            "page length too short=%d\n",
            len);
    return 97;
  }
  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 97;
    }
    if (desc_len > 0) {
      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;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<decode_proto_lu_vpd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    116f <decode_proto_lu_vpd+0x3f>
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xea4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x61,-0x4(%rbp)
jmp    12da <decode_proto_lu_vpd+0x1aa>
mov    -0x14(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12d3 <decode_proto_lu_vpd+0x1a3>
mov    -0x30(%rbp),%rax
movzbl (%rax),%eax
shl    $0x8,%eax
mov    -0x30(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0xf,%eax
mov    %eax,-0x28(%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,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1229 <decode_proto_lu_vpd+0xf9>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x14(%rbp),%ecx
sub    -0x18(%rbp),%ecx
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x61,-0x4(%rbp)
jmp    12da <decode_proto_lu_vpd+0x1aa>
cmpl   $0x0,-0x24(%rbp)
jle    12af <decode_proto_lu_vpd+0x17f>
mov    -0x28(%rbp),%eax
sub    $0x6,%eax
jne    127f <decode_proto_lu_vpd+0x14f>
jmp    1244 <decode_proto_lu_vpd+0x114>
lea    0xe6a(%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    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12aa <decode_proto_lu_vpd+0x17a>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   1030 <dStrHex@plt>
jmp    12af <decode_proto_lu_vpd+0x17f>
jmp    12b4 <decode_proto_lu_vpd+0x184>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    118b <decode_proto_lu_vpd+0x5b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
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
cmp    $0x3,%esi
jg     1170 <decode_proto_lu_vpd+0x30>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1252 <decode_proto_lu_vpd+0x112>
xor    %eax,%eax
cmp    $0x4,%ebp
je     1257 <decode_proto_lu_vpd+0x117>
mov    %rdi,%rbx
add    $0xfffffffc,%ebp
add    $0x4,%rbx
lea    0xebd(%rip),%r14
xor    %r13d,%r13d
jmp    11cf <decode_proto_lu_vpd+0x8f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xf21(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
call   1040 <dStrHex@plt>
add    %r15,%rbx
cmp    %r13d,%ebp
jle    122f <decode_proto_lu_vpd+0xef>
mov    %r13d,%r12d
movzwl (%rbx),%esi
shl    $0x10,%esi
bswap  %esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzwl 0x6(%rbx),%eax
shl    $0x30,%rax
bswap  %rax
lea    0x8(%rax),%r15
lea    (%r15,%r12,1),%r13d
cmp    %ebp,%r13d
jg     1233 <decode_proto_lu_vpd+0xf3>
test   %eax,%eax
je     11c7 <decode_proto_lu_vpd+0x87>
movzbl 0x2(%rbx),%edx
and    $0xf,%edx
cmp    $0x6,%dl
jne    11a0 <decode_proto_lu_vpd+0x60>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
movzbl 0x8(%rbx),%esi
and    $0x1,%esi
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c7 <decode_proto_lu_vpd+0x87>
xor    %eax,%eax
jmp    1257 <decode_proto_lu_vpd+0x117>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
sub    %r12d,%ebp
lea    0xe15(%rip),%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x61,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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 i32 @decode_proto_lu_vpd(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i32, i32* %5
%17 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 97, i32* %3
br label %104
18: ; preds = %2
%19 = load i32, i32* %5
%20 = sub nsw i32 %19, 4
store i32 %20, i32* %5
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 4
store i8* %22, i8** %11
store i32 0, i32* %6
br label %23
23: ; preds = %95, %18
%24 = load i32, i32* %6
%25 = load i32, i32* %5
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %103
27: ; preds = %23
%28 = load i8*, i8** %11
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = shl i32 %31, 8
%33 = load i8*, i8** %11
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = add nsw i32 %32, %36
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = load i8*, i8** %11
%41 = getelementptr inbounds i8, i8* %40, i64 2
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = and i32 %43, 15
store i32 %44, i32* %10
%45 = load i8*, i8** %11
%46 = getelementptr inbounds i8, i8* %45, i64 6
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = shl i32 %48, 8
%50 = load i8*, i8** %11
%51 = getelementptr inbounds i8, i8* %50, i64 7
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = add nsw i32 %49, %53
store i32 %54, i32* %9
%55 = load i32, i32* %9
%56 = add nsw i32 8, %55
store i32 %56, i32* %7
%57 = load i32, i32* %6
%58 = load i32, i32* %7
%59 = add nsw i32 %57, %58
%60 = load i32, i32* %5
%61 = icmp sgt i32 %59, %60
br i1 %61, label %62, label %69
62: ; preds = %27
%63 = load i32, i32* @stderr
%64 = load i32, i32* %7
%65 = load i32, i32* %5
%66 = load i32, i32* %6
%67 = sub nsw i32 %65, %66
%68 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.2, i64 0, i64 0), i32 %64, i32 %67)
store i32 97, i32* %3
br label %104
69: ; preds = %27
%70 = load i32, i32* %9
%71 = icmp sgt i32 %70, 0
br i1 %71, label %72, label %94
72: ; preds = %69
%73 = load i32, i32* %10
switch i32 %73, label %86 [
i32 6, label %74
]
74: ; preds = %72
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%76 = load i8*, i8** %11
%77 = getelementptr inbounds i8, i8* %76, i64 8
%78 = load i8, i8* %77
%79 = zext i8 %78 to i32
%80 = and i32 %79, 1
%81 = icmp ne i32 %80, 0
%82 = xor i1 %81, true
%83 = xor i1 %82, true
%84 = zext i1 %83 to i32
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %84)
br label %93
86: ; preds = %72
%87 = load i32, i32* @stderr
%88 = load i32, i32* %10
%89 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %88)
%90 = load i8*, i8** %11
%91 = load i32, i32* %7
%92 = call i32 @dStrHex(i8* %90, i32 %91, i32 1)
br label %93
93: ; preds = %86, %74
br label %94
94: ; preds = %93, %69
br label %95
95: ; preds = %94
%96 = load i32, i32* %7
%97 = load i32, i32* %6
%98 = add nsw i32 %97, %96
store i32 %98, i32* %6
%99 = load i32, i32* %7
%100 = load i8*, i8** %11
%101 = sext i32 %99 to i64
%102 = getelementptr inbounds i8, i8* %100, i64 %101
store i8* %102, i8** %11
br label %23
103: ; preds = %23
store i32 0, i32* %3
br label %104
104: ; preds = %103, %62, %14
%105 = load i32, i32* %3
ret i32 %105
}

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 i32 @decode_proto_lu_vpd(i8* %0, i32 %1) {
%3 = icmp slt i32 %1, 4
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %61
7: ; preds = %2
%8 = add nsw i32 %1, -4
%9 = icmp eq i32 %1, 4
br i1 %9, label %61, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %0, i64 4
br label %12
12: ; preds = %10, %57
%13 = phi i8* [ %59, %57 ], [ %11, %10 ]
%14 = phi i32 [ %36, %57 ], [ 0, %10 ]
%15 = load i8, i8* %13
%16 = zext i8 %15 to i32
%17 = shl nuw nsw i32 %16, 8
%18 = getelementptr inbounds i8, i8* %13, i64 1
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = or i32 %17, %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds i8, i8* %13, i64 2
%24 = load i8, i8* %23
%25 = and i8 %24, 15
%26 = zext i8 %25 to i32
%27 = getelementptr inbounds i8, i8* %13, i64 6
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = shl nuw nsw i32 %29, 8
%31 = getelementptr inbounds i8, i8* %13, i64 7
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = or i32 %30, %33
%35 = add nuw nsw i32 %34, 8
%36 = add nuw nsw i32 %35, %14
%37 = icmp sgt i32 %36, %8
br i1 %37, label %38, label %42
38: ; preds = %12
%39 = load i32, i32* @stderr
%40 = sub nsw i32 %8, %14
%41 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.2, i64 0, i64 0), i32 %35, i32 %40)
br label %61
42: ; preds = %12
%43 = icmp eq i32 %34, 0
br i1 %43, label %57, label %44
44: ; preds = %42
%45 = icmp eq i8 %25, 6
br i1 %45, label %46, label %53
46: ; preds = %44
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%48 = getelementptr inbounds i8, i8* %13, i64 8
%49 = load i8, i8* %48
%50 = and i8 %49, 1
%51 = zext i8 %50 to i32
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %51)
br label %57
53: ; preds = %44
%54 = load i32, i32* @stderr
%55 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%56 = tail call i32 @dStrHex(i8* %13, i32 %35, i32 1)
br label %57
57: ; preds = %42, %53, %46
%58 = zext i32 %35 to i64
%59 = getelementptr inbounds i8, i8* %13, i64 %58
%60 = icmp sgt i32 %8, %36
br i1 %60, label %12, label %61
61: ; preds = %57, %7, %38, %4
%62 = phi i32 [ 97, %4 ], [ 97, %38 ], [ 0, %7 ], [ 0, %57 ]
ret i32 %62
}