#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*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int decode_block_dev_chars_vpd(unsigned char *buff, int len) {
  unsigned int u;
  if (len < 64) {
    fprintf(stderr,
            "Block device capabilities VPD page length too "
            "short=%d\n",
            len);
    return 97;
  }
  u = (buff[4] << 8) | buff[5];
  if (0 == u)
    printf("  Medium rotation rate is not reported\n");
  else if (1 == u)
    printf("  Non-rotating medium (e.g. solid state)\n");
  else if ((u < 0x401) || (0xffff == u))
    printf("  Reserved [0x%x]\n", u);
  else
    printf("  Nominal rotation rate: %d rpm\n", u);
  return 0;
}


x86 assembly (clang, -O0):
<decode_block_dev_chars_vpd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x40,-0x14(%rbp)
jge    115d <decode_block_dev_chars_vpd+0x3d>
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xeb4(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x61,-0x4(%rbp)
jmp    1207 <decode_block_dev_chars_vpd+0xe7>
mov    -0x10(%rbp),%rax
movzbl 0x4(%rax),%eax
shl    $0x8,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x5(%rcx),%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jne    1193 <decode_block_dev_chars_vpd+0x73>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1200 <decode_block_dev_chars_vpd+0xe0>
mov    $0x1,%eax
cmp    -0x18(%rbp),%eax
jne    11b4 <decode_block_dev_chars_vpd+0x94>
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fb <decode_block_dev_chars_vpd+0xdb>
cmpl   $0x401,-0x18(%rbp)
jb     11cf <decode_block_dev_chars_vpd+0xaf>
mov    $0xffff,%eax
cmp    -0x18(%rbp),%eax
jne    11e5 <decode_block_dev_chars_vpd+0xc5>
mov    -0x18(%rbp),%esi
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f6 <decode_block_dev_chars_vpd+0xd6>
mov    -0x18(%rbp),%esi
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fb <decode_block_dev_chars_vpd+0xdb>
jmp    1200 <decode_block_dev_chars_vpd+0xe0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_block_dev_chars_vpd>:
push   %rbx
cmp    $0x3f,%esi
jg     1154 <decode_block_dev_chars_vpd+0x24>
mov    %esi,%edx
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
lea    0xeb8(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x61,%ebx
jmp    11aa <decode_block_dev_chars_vpd+0x7a>
movzwl 0x4(%rdi),%esi
shl    $0x10,%esi
bswap  %esi
cmp    $0x1,%si
je     1171 <decode_block_dev_chars_vpd+0x41>
test   %si,%si
jne    1181 <decode_block_dev_chars_vpd+0x51>
lea    0xf26(%rip),%rdi
jmp    1178 <decode_block_dev_chars_vpd+0x48>
lea    0xef4(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    11aa <decode_block_dev_chars_vpd+0x7a>
cmp    $0x401,%esi
jb     119a <decode_block_dev_chars_vpd+0x6a>
cmp    $0xffff,%esi
je     119a <decode_block_dev_chars_vpd+0x6a>
lea    0xeb3(%rip),%rdi
jmp    11a1 <decode_block_dev_chars_vpd+0x71>
lea    0xe97(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [56 x i8] c"Block device capabilities VPD page length too short=%d\0A\00"
@.str.1 = [40 x i8] c" Medium rotation rate is not reported\0A\00"
@.str.2 = [42 x i8] c" Non-rotating medium (e.g. solid state)\0A\00"
@.str.3 = [19 x i8] c" Reserved [0x%x]\0A\00"
@.str.4 = [33 x i8] c" Nominal rotation rate: %d rpm\0A\00"
define i32 @decode_block_dev_chars_vpd(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 64
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i32, i32* %5
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 97, i32* %3
br label %48
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 4
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = shl i32 %17, 8
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 5
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = or i32 %18, %22
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp eq i32 0, %24
br i1 %25, label %26, label %28
26: ; preds = %13
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %47
28: ; preds = %13
%29 = load i32, i32* %6
%30 = icmp eq i32 1, %29
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %46
33: ; preds = %28
%34 = load i32, i32* %6
%35 = icmp ult i32 %34, 1025
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = load i32, i32* %6
%38 = icmp eq i32 65535, %37
br i1 %38, label %39, label %42
39: ; preds = %36, %33
%40 = load i32, i32* %6
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %45
42: ; preds = %36
%43 = load i32, i32* %6
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %42, %39
br label %46
46: ; preds = %45, %31
br label %47
47: ; preds = %46, %26
store i32 0, i32* %3
br label %48
48: ; preds = %47, %9
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [56 x i8] c"Block device capabilities VPD page length too short=%d\0A\00"
@.str.3 = [19 x i8] c" Reserved [0x%x]\0A\00"
@.str.4 = [33 x i8] c" Nominal rotation rate: %d rpm\0A\00"
@str = [41 x i8] c" Non-rotating medium (e.g. solid state)\00"
@str.5 = [39 x i8] c" Medium rotation rate is not reported\00"
define i32 @decode_block_dev_chars_vpd(i8* nocapture %0, i32 %1) {
%3 = icmp slt i32 %1, 64
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %29
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %0, i64 4
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = shl nuw nsw i32 %10, 8
%12 = getelementptr inbounds i8, i8* %0, i64 5
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = or i32 %11, %14
%16 = trunc i32 %15 to i16
switch i16 %16, label %21 [
i16 0, label %17
i16 1, label %19
]
17: ; preds = %7
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.5, i64 0, i64 0))
br label %29
19: ; preds = %7
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %29
21: ; preds = %7
%22 = icmp ult i32 %15, 1025
%23 = icmp eq i32 %15, 65535
%24 = or i1 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %15)
br label %29
27: ; preds = %21
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %15)
br label %29
29: ; preds = %17, %25, %27, %19, %4
%30 = phi i32 [ 97, %4 ], [ 0, %19 ], [ 0, %27 ], [ 0, %25 ], [ 0, %17 ]
ret i32 %30
}