#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 *, unsigned char, ...);
int /*<<< orphan*/ stderr;
int decode_proto_port_vpd(unsigned char *buff, int len) {
  int k, j, bump, rel_port, desc_len, proto;
  unsigned char *ucp;
  unsigned char *pidp;
  if (len < 4) {
    fprintf(stderr,
            "Protocol-specific port 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 port information VPD "
              "page, short descriptor length=%d, left=%d\n",
              bump, (len - k));
      return 97;
    }
    if (desc_len > 0) {
      switch (proto) {
      case 6:
        printf(" pwr_d_s=%d\n", !!(ucp[3] & 0x1));
        pidp = ucp + 8;
        for (j = 0; j < desc_len; j += 4, pidp += 4)
          printf("  phy id=%d, ssp persistent capable=%d\n", pidp[1],
                 (0x1 & pidp[2]));
        break;
      default:
        fprintf(stderr, "Unexpected proto=%d\n", proto);
        dStrHex((const char *)ucp, bump, 1);
        break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<decode_proto_port_vpd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    116f <decode_proto_port_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    132e <decode_proto_port_vpd+0x1fe>
mov    -0x14(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1327 <decode_proto_port_vpd+0x1f7>
mov    -0x38(%rbp),%rax
movzbl (%rax),%eax
shl    $0x8,%eax
mov    -0x38(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
lea    0xe89(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0xf,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rax
movzbl 0x6(%rax),%eax
shl    $0x8,%eax
mov    -0x38(%rbp),%rcx
movzbl 0x7(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    122c <decode_proto_port_vpd+0xfc>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
mov    -0x14(%rbp),%ecx
sub    -0x18(%rbp),%ecx
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x61,-0x4(%rbp)
jmp    132e <decode_proto_port_vpd+0x1fe>
cmpl   $0x0,-0x28(%rbp)
jle    1303 <decode_proto_port_vpd+0x1d3>
mov    -0x2c(%rbp),%eax
sub    $0x6,%eax
jne    12d3 <decode_proto_port_vpd+0x1a3>
jmp    1247 <decode_proto_port_vpd+0x117>
mov    -0x38(%rbp),%rax
movzbl 0x3(%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
lea    0xe3d(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    12ce <decode_proto_port_vpd+0x19e>
mov    -0x40(%rbp),%rax
mov    0x1(%rax),%al
mov    -0x40(%rbp),%rcx
movzbl 0x2(%rcx),%edx
and    $0x1,%edx
lea    0xe08(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x40(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x40(%rbp)
jmp    1285 <decode_proto_port_vpd+0x155>
jmp    12fe <decode_proto_port_vpd+0x1ce>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    $0x1,%edx
call   1030 <dStrHex@plt>
jmp    1303 <decode_proto_port_vpd+0x1d3>
jmp    1308 <decode_proto_port_vpd+0x1d8>
mov    -0x20(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
jmp    118b <decode_proto_port_vpd+0x5b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_proto_port_vpd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
cmp    $0x3,%esi
jg     1160 <decode_proto_port_vpd+0x30>
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1268 <decode_proto_port_vpd+0x138>
xor    %eax,%eax
cmp    $0x4,%ebp
je     126d <decode_proto_port_vpd+0x13d>
mov    %rdi,%rbx
add    $0xfffffffc,%ebp
add    $0x4,%rbx
xor    %r13d,%r13d
mov    %ebp,0x4(%rsp)
jmp    11b7 <decode_proto_port_vpd+0x87>
xchg   %ax,%ax
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xf4a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
call   1030 <dStrHex@plt>
add    %r15,%rbx
mov    0x4(%rsp),%ebp
cmp    %r13d,%ebp
jle    1245 <decode_proto_port_vpd+0x115>
mov    %r13d,%r12d
movzbl 0x1(%rbx),%esi
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzwl 0x6(%rbx),%r14d
shl    $0x30,%r14
bswap  %r14
lea    0x8(%r14),%r15
lea    (%r15,%r12,1),%r13d
cmp    %ebp,%r13d
jg     1249 <decode_proto_port_vpd+0x119>
test   %r14d,%r14d
je     11a7 <decode_proto_port_vpd+0x77>
movzbl 0x2(%rbx),%edx
and    $0xf,%edx
cmp    $0x6,%dl
jne    1180 <decode_proto_port_vpd+0x50>
movzbl 0x3(%rbx),%esi
and    $0x1,%esi
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ebp,%ebp
lea    0xe9e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x9(%rbx,%rbp,1),%esi
movzbl 0xa(%rbx,%rbp,1),%edx
and    $0x1,%edx
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x4,%rbp
cmp    %r14d,%ebp
jb     1220 <decode_proto_port_vpd+0xf0>
jmp    11a7 <decode_proto_port_vpd+0x77>
xor    %eax,%eax
jmp    126d <decode_proto_port_vpd+0x13d>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
sub    %r12d,%ebp
lea    0xdf7(%rip),%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <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 = [65 x i8] c"Protocol-specific port information VPD page length too short=%d\0A\00"
@.str.1 = [18 x i8] c"Relative port=%d\0A\00"
@.str.2 = [82 x i8] c"Protocol-specific port information VPD page, short descriptor length=%d, left=%d\0A\00"
@.str.3 = [13 x i8] c" pwr_d_s=%d\0A\00"
@.str.4 = [40 x i8] c" phy id=%d, ssp persistent capable=%d\0A\00"
@.str.5 = [21 x i8] c"Unexpected proto=%d\0A\00"
define i32 @decode_proto_port_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 i32
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 4
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i32, i32* %5
%19 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 97, i32* %3
br label %129
20: ; preds = %2
%21 = load i32, i32* %5
%22 = sub nsw i32 %21, 4
store i32 %22, i32* %5
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i64 4
store i8* %24, i8** %12
store i32 0, i32* %6
br label %25
25: ; preds = %120, %20
%26 = load i32, i32* %6
%27 = load i32, i32* %5
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %128
29: ; preds = %25
%30 = load i8*, i8** %12
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = shl i32 %33, 8
%35 = load i8*, i8** %12
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = add nsw i32 %34, %38
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = trunc i32 %40 to i8
%42 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %41)
%43 = load i8*, i8** %12
%44 = getelementptr inbounds i8, i8* %43, i64 2
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = and i32 %46, 15
store i32 %47, i32* %11
%48 = load i8*, i8** %12
%49 = getelementptr inbounds i8, i8* %48, i64 6
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = shl i32 %51, 8
%53 = load i8*, i8** %12
%54 = getelementptr inbounds i8, i8* %53, i64 7
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = add nsw i32 %52, %56
store i32 %57, i32* %10
%58 = load i32, i32* %10
%59 = add nsw i32 8, %58
store i32 %59, i32* %8
%60 = load i32, i32* %6
%61 = load i32, i32* %8
%62 = add nsw i32 %60, %61
%63 = load i32, i32* %5
%64 = icmp sgt i32 %62, %63
br i1 %64, label %65, label %72
65: ; preds = %29
%66 = load i32, i32* @stderr
%67 = load i32, i32* %8
%68 = load i32, i32* %5
%69 = load i32, i32* %6
%70 = sub nsw i32 %68, %69
%71 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0), i32 %67, i32 %70)
store i32 97, i32* %3
br label %129
72: ; preds = %29
%73 = load i32, i32* %10
%74 = icmp sgt i32 %73, 0
br i1 %74, label %75, label %119
75: ; preds = %72
%76 = load i32, i32* %11
switch i32 %76, label %111 [
i32 6, label %77
]
77: ; preds = %75
%78 = load i8*, i8** %12
%79 = getelementptr inbounds i8, i8* %78, i64 3
%80 = load i8, i8* %79
%81 = zext i8 %80 to i32
%82 = and i32 %81, 1
%83 = icmp ne i32 %82, 0
%84 = xor i1 %83, true
%85 = xor i1 %84, true
%86 = zext i1 %85 to i32
%87 = trunc i32 %86 to i8
%88 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %87)
%89 = load i8*, i8** %12
%90 = getelementptr inbounds i8, i8* %89, i64 8
store i8* %90, i8** %13
store i32 0, i32* %7
br label %91
91: ; preds = %105, %77
%92 = load i32, i32* %7
%93 = load i32, i32* %10
%94 = icmp slt i32 %92, %93
br i1 %94, label %95, label %110
95: ; preds = %91
%96 = load i8*, i8** %13
%97 = getelementptr inbounds i8, i8* %96, i64 1
%98 = load i8, i8* %97
%99 = load i8*, i8** %13
%100 = getelementptr inbounds i8, i8* %99, i64 2
%101 = load i8, i8* %100
%102 = zext i8 %101 to i32
%103 = and i32 1, %102
%104 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %98, i32 %103)
br label %105
105: ; preds = %95
%106 = load i32, i32* %7
%107 = add nsw i32 %106, 4
store i32 %107, i32* %7
%108 = load i8*, i8** %13
%109 = getelementptr inbounds i8, i8* %108, i64 4
store i8* %109, i8** %13
br label %91
110: ; preds = %91
br label %118
111: ; preds = %75
%112 = load i32, i32* @stderr
%113 = load i32, i32* %11
%114 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %113)
%115 = load i8*, i8** %12
%116 = load i32, i32* %8
%117 = call i32 @dStrHex(i8* %115, i32 %116, i32 1)
br label %118
118: ; preds = %111, %110
br label %119
119: ; preds = %118, %72
br label %120
120: ; preds = %119
%121 = load i32, i32* %8
%122 = load i32, i32* %6
%123 = add nsw i32 %122, %121
store i32 %123, i32* %6
%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 %25
128: ; preds = %25
store i32 0, i32* %3
br label %129
129: ; preds = %128, %65, %16
%130 = load i32, i32* %3
ret i32 %130
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [65 x i8] c"Protocol-specific port information VPD page length too short=%d\0A\00"
@.str.1 = [18 x i8] c"Relative port=%d\0A\00"
@.str.2 = [82 x i8] c"Protocol-specific port information VPD page, short descriptor length=%d, left=%d\0A\00"
@.str.3 = [13 x i8] c" pwr_d_s=%d\0A\00"
@.str.4 = [40 x i8] c" phy id=%d, ssp persistent capable=%d\0A\00"
@.str.5 = [21 x i8] c"Unexpected proto=%d\0A\00"
define i32 @decode_proto_port_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 ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %68
7: ; preds = %2
%8 = add nsw i32 %1, -4
%9 = icmp eq i32 %1, 4
br i1 %9, label %68, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %0, i64 4
br label %12
12: ; preds = %10, %64
%13 = phi i8* [ %66, %64 ], [ %11, %10 ]
%14 = phi i32 [ %31, %64 ], [ 0, %10 ]
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = load i8, i8* %15
%17 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %16)
%18 = getelementptr inbounds i8, i8* %13, i64 2
%19 = load i8, i8* %18
%20 = and i8 %19, 15
%21 = zext i8 %20 to i32
%22 = getelementptr inbounds i8, i8* %13, i64 6
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = shl nuw nsw i32 %24, 8
%26 = getelementptr inbounds i8, i8* %13, i64 7
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = or i32 %25, %28
%30 = add nuw nsw i32 %29, 8
%31 = add nuw nsw i32 %30, %14
%32 = icmp sgt i32 %31, %8
br i1 %32, label %33, label %37
33: ; preds = %12
%34 = load i32, i32* @stderr
%35 = sub nsw i32 %8, %14
%36 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %35)
br label %68
37: ; preds = %12
%38 = icmp eq i32 %29, 0
br i1 %38, label %64, label %39
39: ; preds = %37
%40 = icmp eq i8 %20, 6
br i1 %40, label %41, label %60
41: ; preds = %39
%42 = getelementptr inbounds i8, i8* %13, i64 3
%43 = load i8, i8* %42
%44 = and i8 %43, 1
%45 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %44)
%46 = getelementptr inbounds i8, i8* %13, i64 8
br label %47
47: ; preds = %41, %47
%48 = phi i8* [ %46, %41 ], [ %58, %47 ]
%49 = phi i32 [ 0, %41 ], [ %57, %47 ]
%50 = getelementptr inbounds i8, i8* %48, i64 1
%51 = load i8, i8* %50
%52 = getelementptr inbounds i8, i8* %48, i64 2
%53 = load i8, i8* %52
%54 = and i8 %53, 1
%55 = zext i8 %54 to i32
%56 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %51, i32 %55)
%57 = add nuw nsw i32 %49, 4
%58 = getelementptr inbounds i8, i8* %48, i64 4
%59 = icmp ult i32 %57, %29
br i1 %59, label %47, label %64
60: ; preds = %39
%61 = load i32, i32* @stderr
%62 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%63 = tail call i32 @dStrHex(i8* %13, i32 %30, i32 1)
br label %64
64: ; preds = %47, %37, %60
%65 = zext i32 %30 to i64
%66 = getelementptr inbounds i8, i8* %13, i64 %65
%67 = icmp sgt i32 %8, %31
br i1 %67, label %12, label %68
68: ; preds = %64, %7, %33, %4
%69 = phi i32 [ 97, %4 ], [ 97, %33 ], [ 0, %7 ], [ 0, %64 ]
ret i32 %69
}