#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;
struct iovec {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ ILLEGAL_REQUEST;
int /*<<< orphan*/ memcpy(int *, char *, int);
int /*<<< orphan*/ memset(int *, int, int);
int /*<<< orphan*/ tcmu_memcpy_into_iovec(struct iovec *, size_t, int *, int);
int tcmu_set_sense_data(int *, int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int fbo_emulate_inquiry(uint8_t *cdb, struct iovec *iovec, size_t iov_cnt,
                        uint8_t *sense) {
  uint8_t buf[36];
  if ((cdb[1] & 0x01) || cdb[2])
    return tcmu_set_sense_data(sense, ILLEGAL_REQUEST, 0x2400, NULL);
  memset(buf, 0, sizeof(buf));
  buf[0] = 0x05;
  buf[1] = 0x80;
  buf[2] = 0x05;
  buf[3] = 0x02;
  buf[7] = 0x02;
  memcpy(&buf[8], "LIO-ORG ", 8);
  memset(&buf[16], 0x20, 16);
  memcpy(&buf[16], "VOPTA", 5);
  memcpy(&buf[32], "0001", 4);
  buf[4] = 31;
  tcmu_memcpy_into_iovec(iovec, iov_cnt, buf, sizeof(buf));
  return 0x00;
}


x86 assembly (clang, -O0):
<fbo_emulate_inquiry>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    117c <fbo_emulate_inquiry+0x3c>
mov    -0x10(%rbp),%rax
cmpl   $0x0,0x8(%rax)
je     119f <fbo_emulate_inquiry+0x5f>
mov    -0x28(%rbp),%rdi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    $0x2400,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <tcmu_set_sense_data@plt>
mov    %eax,-0x4(%rbp)
jmp    127f <fbo_emulate_inquiry+0x13f>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x90,%edx
call   1030 <memset@plt>
movl   $0x5,-0xc0(%rbp)
movl   $0x80,-0xbc(%rbp)
movl   $0x5,-0xb8(%rbp)
movl   $0x2,-0xb4(%rbp)
movl   $0x2,-0xa4(%rbp)
lea    -0xc0(%rbp),%rdi
add    $0x20,%rdi
lea    0xe0a(%rip),%rsi
mov    $0x8,%edx
call   1050 <memcpy@plt>
lea    -0xc0(%rbp),%rdi
add    $0x40,%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    -0xc0(%rbp),%rdi
add    $0x40,%rdi
lea    0xddd(%rip),%rsi
mov    $0x5,%edx
call   1050 <memcpy@plt>
lea    -0xc0(%rbp),%rdi
add    $0x80,%rdi
lea    0xdc4(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
movl   $0x1f,-0xb0(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0xc0(%rbp),%rdx
mov    $0x90,%ecx
call   1040 <tcmu_memcpy_into_iovec@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fbo_emulate_inquiry>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x98,%rsp
testb  $0x1,0x4(%rdi)
jne    115a <fbo_emulate_inquiry+0x1a>
cmpl   $0x0,0x8(%rdi)
je     1180 <fbo_emulate_inquiry+0x40>
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
mov    %rcx,%rdi
mov    $0x2400,%edx
xor    %ecx,%ecx
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <tcmu_set_sense_data@plt>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x90,%edx
call   1030 <memset@plt>
movaps 0xe61(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x2,0x1c(%rsp)
lea    0x20(%rsp),%rdi
lea    0xe59(%rip),%rsi
mov    $0x8,%edx
call   1050 <memcpy@plt>
lea    0x40(%rsp),%r12
mov    %r12,%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    0xe3a(%rip),%rsi
mov    %r12,%rdi
mov    $0x5,%edx
call   1050 <memcpy@plt>
lea    0x80(%rsp),%rdi
lea    0xe24(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
movl   $0x1f,0x10(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    $0x90,%ecx
call   1040 <tcmu_memcpy_into_iovec@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.iovec = type { i32 }
@ILLEGAL_REQUEST = global i32 0
@.str = [9 x i8] c"LIO-ORG \00"
@.str.1 = [6 x i8] c"VOPTA\00"
@.str.2 = [5 x i8] c"0001\00"
define i32 @fbo_emulate_inquiry(i32* %0, %struct.iovec* %1, i64 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca %struct.iovec*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca [36 x i32]
store i32* %0, i32** %6
store %struct.iovec* %1, %struct.iovec** %7
store i64 %2, i64* %8
store i32* %3, i32** %9
%11 = load i32*, i32** %6
%12 = getelementptr inbounds i32, i32* %11, i64 1
%13 = load i32, i32* %12
%14 = and i32 %13, 1
%15 = icmp ne i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %4
%17 = load i32*, i32** %6
%18 = getelementptr inbounds i32, i32* %17, i64 2
%19 = load i32, i32* %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16, %4
%22 = load i32*, i32** %9
%23 = load i32, i32* @ILLEGAL_REQUEST
%24 = call i32 @tcmu_set_sense_data(i32* %22, i32 %23, i32 9216, i32* null)
store i32 %24, i32* %5
br label %46
25: ; preds = %16
%26 = getelementptr inbounds [36 x i32], [36 x i32]* %10, i64 0, i64 0
%27 = call i32 @memset(i32* %26, i32 0, i32 144)
%28 = getelementptr inbounds [36 x i32], [36 x i32]* %10, i64 0, i64 0
store i32 5, i32* %28
%29 = getelementptr inbounds [36 x i32], [36 x i32]* %10, i64 0, i64 1
store i32 128, i32* %29
%30 = getelementptr inbounds [36 x i32], [36 x i32]* %10, i64 0, i64 2
store i32 5, i32* %30
%31 = getelementptr inbounds [36 x i32], [36 x i32]* %10, i64 0, i64 3
store i32 2, i32* %31
%32 = getelementptr inbounds [36 x i32], [36 x i32]* %10, i64 0, i64 7
store i32 2, i32* %32
%33 = getelementptr inbounds [36 x i32], [36 x i32]* %10, i64 0, i64 8
%34 = call i32 @memcpy(i32* %33, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%35 = getelementptr inbounds [36 x i32], [36 x i32]* %10, i64 0, i64 16
%36 = call i32 @memset(i32* %35, i32 32, i32 16)
%37 = getelementptr inbounds [36 x i32], [36 x i32]* %10, i64 0, i64 16
%38 = call i32 @memcpy(i32* %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%39 = getelementptr inbounds [36 x i32], [36 x i32]* %10, i64 0, i64 32
%40 = call i32 @memcpy(i32* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%41 = getelementptr inbounds [36 x i32], [36 x i32]* %10, i64 0, i64 4
store i32 31, i32* %41
%42 = load %struct.iovec*, %struct.iovec** %7
%43 = load i64, i64* %8
%44 = getelementptr inbounds [36 x i32], [36 x i32]* %10, i64 0, i64 0
%45 = call i32 @tcmu_memcpy_into_iovec(%struct.iovec* %42, i64 %43, i32* %44, i32 144)
store i32 0, i32* %5
br label %46
46: ; preds = %25, %21
%47 = load i32, i32* %5
ret i32 %47
}

LLVM IR (-O2):
%struct.iovec = type { i32 }
@ILLEGAL_REQUEST = global i32 0
@.str = [9 x i8] c"LIO-ORG \00"
@.str.1 = [6 x i8] c"VOPTA\00"
@.str.2 = [5 x i8] c"0001\00"
define i32 @fbo_emulate_inquiry(i32* nocapture %0, %struct.iovec* %1, i64 %2, i32* %3) {
%5 = alloca [36 x i32]
%6 = bitcast [36 x i32]* %5 to i8*
%7 = getelementptr inbounds i32, i32* %0, i64 1
%8 = load i32, i32* %7
%9 = and i32 %8, 1
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = getelementptr inbounds i32, i32* %0, i64 2
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11, %4
%16 = load i32, i32* @ILLEGAL_REQUEST
%17 = tail call i32 @tcmu_set_sense_data(i32* %3, i32 %16, i32 9216, i32* null)
br label %32
18: ; preds = %11
%19 = getelementptr inbounds [36 x i32], [36 x i32]* %5, i64 0, i64 0
%20 = call i32 @memset(i32* %19, i32 0, i32 144)
%21 = bitcast [36 x i32]* %5 to <4 x i32>*
store <4 x i32> <i32 5, i32 128, i32 5, i32 2>, <4 x i32>* %21
%22 = getelementptr inbounds [36 x i32], [36 x i32]* %5, i64 0, i64 7
store i32 2, i32* %22
%23 = getelementptr inbounds [36 x i32], [36 x i32]* %5, i64 0, i64 8
%24 = call i32 @memcpy(i32* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%25 = getelementptr inbounds [36 x i32], [36 x i32]* %5, i64 0, i64 16
%26 = call i32 @memset(i32* %25, i32 32, i32 16)
%27 = call i32 @memcpy(i32* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%28 = getelementptr inbounds [36 x i32], [36 x i32]* %5, i64 0, i64 32
%29 = call i32 @memcpy(i32* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%30 = getelementptr inbounds [36 x i32], [36 x i32]* %5, i64 0, i64 4
store i32 31, i32* %30
%31 = call i32 @tcmu_memcpy_into_iovec(%struct.iovec* %1, i64 %2, i32* %19, i32 144)
br label %32
32: ; preds = %18, %15
%33 = phi i32 [ %17, %15 ], [ 0, %18 ]
ret i32 %33
}