#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ inquirydata;
typedef int /*<<< orphan*/ command;

/* Variables and functions */
int /*<<< orphan*/ SG_DXFER_FROM_DEV;
int memcmp(int *, char *, int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int scsi_command(int, int /*<<< orphan*/, int const *, int, int *, int, int *,
                 int /*<<< orphan*/);
int kvss905c_detect(int fd) {
  uint8_t requestsense[20];
  uint8_t inquirydata[96];
  memset(inquirydata, 0, sizeof(inquirydata));
  static const uint8_t command[] = {0x12, 0, 0, 0, 0x60, 0};
  const int r = scsi_command(fd, SG_DXFER_FROM_DEV, command, sizeof(command),
                             inquirydata, sizeof(inquirydata), requestsense, 0);
  if (r)
    return r;
  return memcmp(inquirydata + 16, "KV-", 3);
}


x86 assembly (clang, -O0):
<kvss905c_detect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x1e0(%rbp),%rdi
xor    %esi,%esi
mov    $0x180,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
lea    -0x1e0(%rbp),%r8
lea    -0x60(%rbp),%rax
lea    0xe91(%rip),%rdx
mov    $0x18,%ecx
mov    $0x180,%r9d
xor    %r10d,%r10d
mov    %rax,(%rsp)
movl   $0x0,0x8(%rsp)
call   1050 <scsi_command@plt>
mov    %eax,-0x1e4(%rbp)
cmpl   $0x0,-0x1e4(%rbp)
je     11af <kvss905c_detect+0x7f>
mov    -0x1e4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ce <kvss905c_detect+0x9e>
lea    -0x1e0(%rbp),%rdi
add    $0x40,%rdi
lea    0xe57(%rip),%rsi
mov    $0x3,%edx
call   1040 <memcmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x200,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kvss905c_detect>:
push   %r14
push   %rbx
sub    $0x1d8,%rsp
mov    %edi,%ebx
lea    0x50(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x180,%edx
call   1030 <memset@plt>
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rax
lea    0xe9d(%rip),%rdx
mov    %ebx,%edi
mov    $0x18,%ecx
mov    %r14,%r8
mov    $0x180,%r9d
push   $0x0
push   %rax
call   1050 <scsi_command@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    119c <kvss905c_detect+0x6c>
lea    0x90(%rsp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x3,%edx
call   1040 <memcmp@plt>
add    $0x1d8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@kvss905c_detect.command = internal constant [6 x i32] [i32 18, i32 0, i32 0, i32 0, i32 96, i32 0]
@SG_DXFER_FROM_DEV = global i32 0
@.str = [4 x i8] c"KV-\00"
define i32 @kvss905c_detect(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [20 x i32]
%5 = alloca [96 x i32]
%6 = alloca i32
store i32 %0, i32* %3
%7 = getelementptr inbounds [96 x i32], [96 x i32]* %5, i64 0, i64 0
%8 = call i32 @memset(i32* %7, i32 0, i32 384)
%9 = load i32, i32* %3
%10 = load i32, i32* @SG_DXFER_FROM_DEV
%11 = getelementptr inbounds [96 x i32], [96 x i32]* %5, i64 0, i64 0
%12 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 0
%13 = call i32 @scsi_command(i32 %9, i32 %10, i32* getelementptr inbounds ([6 x i32], [6 x i32]* @kvss905c_detect.command, i64 0, i64 0), i32 24, i32* %11, i32 384, i32* %12, i32 0)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = load i32, i32* %6
store i32 %17, i32* %2
br label %22
18: ; preds = %1
%19 = getelementptr inbounds [96 x i32], [96 x i32]* %5, i64 0, i64 0
%20 = getelementptr inbounds i32, i32* %19, i64 16
%21 = call i32 @memcmp(i32* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
store i32 %21, i32* %2
br label %22
22: ; preds = %18, %16
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@kvss905c_detect.command = internal constant [6 x i32] [i32 18, i32 0, i32 0, i32 0, i32 96, i32 0]
@SG_DXFER_FROM_DEV = global i32 0
@.str = [4 x i8] c"KV-\00"
define i32 @kvss905c_detect(i32 %0) {
%2 = alloca [20 x i32]
%3 = alloca [96 x i32]
%4 = bitcast [20 x i32]* %2 to i8*
%5 = bitcast [96 x i32]* %3 to i8*
%6 = getelementptr inbounds [96 x i32], [96 x i32]* %3, i64 0, i64 0
%7 = call i32 @memset(i32* %6, i32 0, i32 384)
%8 = load i32, i32* @SG_DXFER_FROM_DEV
%9 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%10 = call i32 @scsi_command(i32 %0, i32 %8, i32* getelementptr inbounds ([6 x i32], [6 x i32]* @kvss905c_detect.command, i64 0, i64 0), i32 24, i32* %6, i32 384, i32* %9, i32 0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = getelementptr inbounds [96 x i32], [96 x i32]* %3, i64 0, i64 16
%14 = call i32 @memcmp(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
br label %15
15: ; preds = %1, %12
%16 = phi i32 [ %14, %12 ], [ %10, %1 ]
ret i32 %16
}