#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 sg_io_v4 {
  char guard;
  int request_len;
  uintptr_t request;
  int max_response_len;
  uintptr_t response;
  size_t const din_xfer_len;
  uintptr_t din_xferp;
  int timeout;
  char interface_id;
  unsigned char *cmdp;
  int cmd_len;
  void *const dxferp;
  size_t const dxfer_len;
  int *sbp;
  int mx_sb_len;
  int /*<<< orphan*/ dxfer_direction;
  int /*<<< orphan*/ subprotocol;
  int /*<<< orphan*/ protocol;
};
struct sg_io_hdr {
  char guard;
  int request_len;
  uintptr_t request;
  int max_response_len;
  uintptr_t response;
  size_t const din_xfer_len;
  uintptr_t din_xferp;
  int timeout;
  char interface_id;
  unsigned char *cmdp;
  int cmd_len;
  void *const dxferp;
  size_t const dxfer_len;
  int *sbp;
  int mx_sb_len;
  int /*<<< orphan*/ dxfer_direction;
  int /*<<< orphan*/ subprotocol;
  int /*<<< orphan*/ protocol;
};
typedef int /*<<< orphan*/ sense;
typedef int /*<<< orphan*/ cdb;

/* Variables and functions */
int /*<<< orphan*/ BSG_PROTOCOL_SCSI;
int /*<<< orphan*/ BSG_SUB_PROTOCOL_SCSI_CMD;
scalar_t__ EINVAL;
scalar_t__ EIO;
int /*<<< orphan*/ SG_DXFER_FROM_DEV;
int /*<<< orphan*/ SG_IO;
scalar_t__ errno;
int ioctl(int const, int /*<<< orphan*/, struct sg_io_v4 *);
int disk_identify_packet_device_command(const int fd, void *const buf,
                                        const size_t buf_len) {
  uint8_t cdb[16] = {
      [0] = 0x85, [1] = 4 << 1, [2] = 0x2e,  [3] = 0,  [4] = 0,  [5] = 0,
      [6] = 1,    [7] = 0,      [8] = 0,     [9] = 0,  [10] = 0, [11] = 0,
      [12] = 0,   [13] = 0,     [14] = 0xA1, [15] = 0,
  };
  uint8_t sense[32] = {0};
  uint8_t *desc = sense + 8;
  struct sg_io_v4 io_v4 = {
      .guard = 'Q',
      .protocol = BSG_PROTOCOL_SCSI,
      .subprotocol = BSG_SUB_PROTOCOL_SCSI_CMD,
      .request_len = sizeof(cdb),
      .request = (uintptr_t)cdb,
      .max_response_len = sizeof(sense),
      .response = (uintptr_t)sense,
      .din_xfer_len = buf_len,
      .din_xferp = (uintptr_t)buf,
      .timeout = (30 * 1000),
  };
  int ret;
  ret = ioctl(fd, SG_IO, &io_v4);
  if (ret != 0) {
    if (errno == EINVAL) {
      struct sg_io_hdr io_hdr = {
          .interface_id = 'S',
          .cmdp = (unsigned char *)cdb,
          .cmd_len = sizeof(cdb),
          .dxferp = buf,
          .dxfer_len = buf_len,
          .sbp = sense,
          .mx_sb_len = sizeof(sense),
          .dxfer_direction = SG_DXFER_FROM_DEV,
          .timeout = (30 * 1000),
      };
      ret = ioctl(fd, SG_IO, &io_hdr);
      if (ret != 0) {
        return ret;
      }
    } else {
      return ret;
    }
  }
  if (!(sense[0] == 0x72 && desc[0] == 0x9 && desc[1] == 0x0c)) {
    errno = EIO;
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<disk_identify_packet_device_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
movl   $0x85,-0x60(%rbp)
movl   $0x8,-0x5c(%rbp)
movl   $0x2e,-0x58(%rbp)
movl   $0x1,-0x48(%rbp)
movl   $0xa1,-0x28(%rbp)
lea    -0xe0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1030 <memset@plt>
lea    -0xe0(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0xe8(%rbp)
movb   $0x51,-0x158(%rbp)
movl   $0x40,-0x154(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x150(%rbp)
movl   $0x80,-0x148(%rbp)
lea    -0xe0(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x130(%rbp)
movl   $0x7530,-0x128(%rbp)
movb   $0x0,-0x124(%rbp)
movq   $0x0,-0x120(%rbp)
movl   $0x0,-0x118(%rbp)
movq   $0x0,-0x110(%rbp)
movq   $0x0,-0x108(%rbp)
movq   $0x0,-0x100(%rbp)
movl   $0x0,-0xf8(%rbp)
movl   $0x0,-0xf4(%rbp)
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf0(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xec(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d6d(%rip),%rax
mov    (%rax),%esi
lea    -0x158(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x15c(%rbp)
cmpl   $0x0,-0x15c(%rbp)
je     13a5 <disk_identify_packet_device_command+0x285>
mov    0x2d3d(%rip),%rax
mov    (%rax),%rax
mov    0x2d2b(%rip),%rcx
cmp    (%rcx),%rax
jne    1392 <disk_identify_packet_device_command+0x272>
movb   $0x0,-0x1d0(%rbp)
movl   $0x0,-0x1cc(%rbp)
movq   $0x0,-0x1c8(%rbp)
movl   $0x0,-0x1c0(%rbp)
movq   $0x0,-0x1b8(%rbp)
movq   $0x0,-0x1b0(%rbp)
movq   $0x0,-0x1a8(%rbp)
movl   $0x7530,-0x1a0(%rbp)
movb   $0x53,-0x19c(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x198(%rbp)
movl   $0x40,-0x190(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x188(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x180(%rbp)
lea    -0xe0(%rbp),%rax
mov    %rax,-0x178(%rbp)
movl   $0x80,-0x170(%rbp)
mov    0x2ca8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x16c(%rbp)
movl   $0x0,-0x168(%rbp)
movl   $0x0,-0x164(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2c6a(%rip),%rax
mov    (%rax),%esi
lea    -0x1d0(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x15c(%rbp)
cmpl   $0x0,-0x15c(%rbp)
je     138d <disk_identify_packet_device_command+0x26d>
mov    -0x15c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13fa <disk_identify_packet_device_command+0x2da>
jmp    13a0 <disk_identify_packet_device_command+0x280>
mov    -0x15c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13fa <disk_identify_packet_device_command+0x2da>
jmp    13a5 <disk_identify_packet_device_command+0x285>
cmpl   $0x72,-0xe0(%rbp)
jne    13d3 <disk_identify_packet_device_command+0x2b3>
mov    -0xe8(%rbp),%rax
cmpl   $0x9,(%rax)
jne    13d3 <disk_identify_packet_device_command+0x2b3>
mov    -0xe8(%rbp),%rax
cmpl   $0xc,0x4(%rax)
je     13f3 <disk_identify_packet_device_command+0x2d3>
mov    0x2bf6(%rip),%rax
mov    (%rax),%rcx
mov    0x2bdc(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    13fa <disk_identify_packet_device_command+0x2da>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disk_identify_packet_device_command>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1a8,%rsp
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r14d
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movabs $0x800000085,%rax
mov    %rax,0x70(%rsp)
movl   $0x2e,0x78(%rsp)
movl   $0x1,0x88(%rsp)
movl   $0xa1,0xa8(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movb   $0x51,(%rsp)
movl   $0x40,0x4(%rsp)
lea    0x70(%rsp),%r12
mov    %r12,0x8(%rsp)
movl   $0x80,0x10(%rsp)
lea    0x120(%rsp),%r15
mov    %r15,0x18(%rsp)
mov    %rdx,0x20(%rsp)
mov    %rsi,0x28(%rsp)
movl   $0x7530,0x30(%rsp)
movb   $0x0,0x34(%rsp)
movq   $0x0,0x38(%rsp)
movl   $0x0,0x40(%rsp)
movups %xmm0,0x48(%rsp)
movups %xmm0,0x58(%rsp)
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x68(%rsp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x6c(%rsp)
mov    0x2d93(%rip),%r13
mov    0x0(%r13),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
test   %eax,%eax
je     1307 <disk_identify_packet_device_command+0x1f7>
mov    0x2d70(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2d5e(%rip),%rdx
cmp    (%rdx),%rcx
jne    1340 <disk_identify_packet_device_command+0x230>
movb   $0x0,0xb0(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0xb4(%rsp)
movups %xmm0,0xc8(%rsp)
movq   $0x0,0xd8(%rsp)
movl   $0x7530,0xe0(%rsp)
movb   $0x53,0xe4(%rsp)
53
mov    %r12,0xe8(%rsp)
movl   $0x40,0xf0(%rsp)
mov    %rbp,0xf8(%rsp)
mov    %rbx,0x100(%rsp)
mov    %r15,0x108(%rsp)
movl   $0x80,0x110(%rsp)
mov    0x2d06(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x114(%rsp)
movq   $0x0,0x118(%rsp)
mov    0x0(%r13),%esi
lea    0xb0(%rsp),%rdx
mov    %r14d,%edi
call   1030 <ioctl@plt>
test   %eax,%eax
jne    1340 <disk_identify_packet_device_command+0x230>
cmpl   $0x72,0x120(%rsp)
72
jne    1327 <disk_identify_packet_device_command+0x217>
cmpl   $0x9,0x140(%rsp)
09
jne    1327 <disk_identify_packet_device_command+0x217>
xor    %eax,%eax
cmpl   $0xc,0x144(%rsp)
0c
je     1340 <disk_identify_packet_device_command+0x230>
mov    0x2ca2(%rip),%rax
mov    (%rax),%rax
mov    0x2c88(%rip),%rcx
mov    %rax,(%rcx)
mov    $0xffffffff,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sg_io_v4 = type { i8, i32, i64, i32, i64, i64, i64, i32, i8, i8*, i32, i8*, i64, i32*, i32, i32, i32, i32 }
%struct.sg_io_hdr = type { i8, i32, i64, i32, i64, i64, i64, i32, i8, i8*, i32, i8*, i64, i32*, i32, i32, i32, i32 }
@BSG_SUB_PROTOCOL_SCSI_CMD = global i32 0
@BSG_PROTOCOL_SCSI = global i32 0
@SG_IO = global i32 0
@errno = global i64 0
@EINVAL = global i64 0
@SG_DXFER_FROM_DEV = global i32 0
@EIO = global i64 0
define i32 @disk_identify_packet_device_command(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [16 x i32]
%9 = alloca [32 x i32]
%10 = alloca i32*
%11 = alloca %struct.sg_io_v4
%12 = alloca i32
%13 = alloca %struct.sg_io_hdr
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%14 = bitcast [16 x i32]* %8 to i8*
%15 = bitcast i8* %14 to [16 x i32]*
%16 = getelementptr inbounds [16 x i32], [16 x i32]* %15, i32 0, i32 0
store i32 133, i32* %16
%17 = getelementptr inbounds [16 x i32], [16 x i32]* %15, i32 0, i32 1
store i32 8, i32* %17
%18 = getelementptr inbounds [16 x i32], [16 x i32]* %15, i32 0, i32 2
store i32 46, i32* %18
%19 = getelementptr inbounds [16 x i32], [16 x i32]* %15, i32 0, i32 6
store i32 1, i32* %19
%20 = getelementptr inbounds [16 x i32], [16 x i32]* %15, i32 0, i32 14
store i32 161, i32* %20
%21 = bitcast [32 x i32]* %9 to i8*
%22 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 0
%23 = getelementptr inbounds i32, i32* %22, i64 8
store i32* %23, i32** %10
%24 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 0
store i8 81, i8* %24
%25 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 1
store i32 64, i32* %25
%26 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 2
%27 = getelementptr inbounds [16 x i32], [16 x i32]* %8, i64 0, i64 0
%28 = ptrtoint i32* %27 to i64
store i64 %28, i64* %26
%29 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 3
store i32 128, i32* %29
%30 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 4
%31 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 0
%32 = ptrtoint i32* %31 to i64
store i64 %32, i64* %30
%33 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 5
%34 = load i64, i64* %7
store i64 %34, i64* %33
%35 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 6
%36 = load i8*, i8** %6
%37 = ptrtoint i8* %36 to i64
store i64 %37, i64* %35
%38 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 7
store i32 30000, i32* %38
%39 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 8
store i8 0, i8* %39
%40 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 9
store i8* null, i8** %40
%41 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 10
store i32 0, i32* %41
%42 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 11
store i8* null, i8** %42
%43 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 12
store i64 0, i64* %43
%44 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 13
store i32* null, i32** %44
%45 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 14
store i32 0, i32* %45
%46 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 15
store i32 0, i32* %46
%47 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 16
%48 = load i32, i32* @BSG_SUB_PROTOCOL_SCSI_CMD
store i32 %48, i32* %47
%49 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %11, i32 0, i32 17
%50 = load i32, i32* @BSG_PROTOCOL_SCSI
store i32 %50, i32* %49
%51 = load i32, i32* %5
%52 = load i32, i32* @SG_IO
%53 = call i32 @ioctl(i32 %51, i32 %52, %struct.sg_io_v4* %11)
store i32 %53, i32* %12
%54 = load i32, i32* %12
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %97
56: ; preds = %3
%57 = load i64, i64* @errno
%58 = load i64, i64* @EINVAL
%59 = icmp eq i64 %57, %58
br i1 %59, label %60, label %94
60: ; preds = %56
%61 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 0
store i8 0, i8* %61
%62 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 1
store i32 0, i32* %62
%63 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 2
store i64 0, i64* %63
%64 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 3
store i32 0, i32* %64
%65 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 4
store i64 0, i64* %65
%66 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 5
store i64 0, i64* %66
%67 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 6
store i64 0, i64* %67
%68 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 7
store i32 30000, i32* %68
%69 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 8
store i8 83, i8* %69
%70 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 9
%71 = getelementptr inbounds [16 x i32], [16 x i32]* %8, i64 0, i64 0
%72 = bitcast i32* %71 to i8*
store i8* %72, i8** %70
%73 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 10
store i32 64, i32* %73
%74 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 11
%75 = load i8*, i8** %6
store i8* %75, i8** %74
%76 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 12
%77 = load i64, i64* %7
store i64 %77, i64* %76
%78 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 13
%79 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 0
store i32* %79, i32** %78
%80 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 14
store i32 128, i32* %80
%81 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 15
%82 = load i32, i32* @SG_DXFER_FROM_DEV
store i32 %82, i32* %81
%83 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 16
store i32 0, i32* %83
%84 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %13, i32 0, i32 17
store i32 0, i32* %84
%85 = load i32, i32* %5
%86 = load i32, i32* @SG_IO
%87 = bitcast %struct.sg_io_hdr* %13 to %struct.sg_io_v4*
%88 = call i32 @ioctl(i32 %85, i32 %86, %struct.sg_io_v4* %87)
store i32 %88, i32* %12
%89 = load i32, i32* %12
%90 = icmp ne i32 %89, 0
br i1 %90, label %91, label %93
91: ; preds = %60
%92 = load i32, i32* %12
store i32 %92, i32* %4
br label %114
93: ; preds = %60
br label %96
94: ; preds = %56
%95 = load i32, i32* %12
store i32 %95, i32* %4
br label %114
96: ; preds = %93
br label %97
97: ; preds = %96, %3
%98 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 0
%99 = load i32, i32* %98
%100 = icmp eq i32 %99, 114
br i1 %100, label %101, label %111
101: ; preds = %97
%102 = load i32*, i32** %10
%103 = getelementptr inbounds i32, i32* %102, i64 0
%104 = load i32, i32* %103
%105 = icmp eq i32 %104, 9
br i1 %105, label %106, label %111
106: ; preds = %101
%107 = load i32*, i32** %10
%108 = getelementptr inbounds i32, i32* %107, i64 1
%109 = load i32, i32* %108
%110 = icmp eq i32 %109, 12
br i1 %110, label %113, label %111
111: ; preds = %106, %101, %97
%112 = load i64, i64* @EIO
store i64 %112, i64* @errno
store i32 -1, i32* %4
br label %114
113: ; preds = %106
store i32 0, i32* %4
br label %114
114: ; preds = %113, %111, %94, %91
%115 = load i32, i32* %4
ret i32 %115
}

LLVM IR (-O2):
%struct.sg_io_v4 = type { i8, i32, i64, i32, i64, i64, i64, i32, i8, i8*, i32, i8*, i64, i32*, i32, i32, i32, i32 }
%struct.sg_io_hdr = type { i8, i32, i64, i32, i64, i64, i64, i32, i8, i8*, i32, i8*, i64, i32*, i32, i32, i32, i32 }
@BSG_SUB_PROTOCOL_SCSI_CMD = global i32 0
@BSG_PROTOCOL_SCSI = global i32 0
@SG_IO = global i32 0
@errno = global i64 0
@EINVAL = global i64 0
@SG_DXFER_FROM_DEV = global i32 0
@EIO = global i64 0
define i32 @disk_identify_packet_device_command(i32 %0, i8* %1, i64 %2) {
%4 = alloca [16 x i32]
%5 = alloca [32 x i32]
%6 = alloca %struct.sg_io_v4
%7 = alloca %struct.sg_io_hdr
%8 = bitcast [16 x i32]* %4 to i8*
%9 = getelementptr inbounds [16 x i32], [16 x i32]* %4, i64 0, i64 0
store i32 133, i32* %9
%10 = getelementptr inbounds [16 x i32], [16 x i32]* %4, i64 0, i64 1
store i32 8, i32* %10
%11 = getelementptr inbounds [16 x i32], [16 x i32]* %4, i64 0, i64 2
store i32 46, i32* %11
%12 = getelementptr inbounds [16 x i32], [16 x i32]* %4, i64 0, i64 6
store i32 1, i32* %12
%13 = getelementptr inbounds [16 x i32], [16 x i32]* %4, i64 0, i64 14
store i32 161, i32* %13
%14 = bitcast [32 x i32]* %5 to i8*
%15 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 0
%16 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 8
%17 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %6, i64 0, i32 0
store i8 81, i8* %17
%18 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %6, i64 0, i32 1
store i32 64, i32* %18
%19 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %6, i64 0, i32 2
%20 = ptrtoint [16 x i32]* %4 to i64
store i64 %20, i64* %19
%21 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %6, i64 0, i32 3
store i32 128, i32* %21
%22 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %6, i64 0, i32 4
%23 = ptrtoint [32 x i32]* %5 to i64
store i64 %23, i64* %22
%24 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %6, i64 0, i32 5
store i64 %2, i64* %24
%25 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %6, i64 0, i32 6
%26 = ptrtoint i8* %1 to i64
store i64 %26, i64* %25
%27 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %6, i64 0, i32 7
store i32 30000, i32* %27
%28 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %6, i64 0, i32 8
store i8 0, i8* %28
%29 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %6, i64 0, i32 9
store i8* null, i8** %29
%30 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %6, i64 0, i32 10
store i32 0, i32* %30
%31 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %6, i64 0, i32 11
%32 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %6, i64 0, i32 16
%33 = bitcast i8** %31 to i8*
%34 = load i32, i32* @BSG_SUB_PROTOCOL_SCSI_CMD
store i32 %34, i32* %32
%35 = getelementptr inbounds %struct.sg_io_v4, %struct.sg_io_v4* %6, i64 0, i32 17
%36 = load i32, i32* @BSG_PROTOCOL_SCSI
store i32 %36, i32* %35
%37 = load i32, i32* @SG_IO
%38 = call i32 @ioctl(i32 %0, i32 %37, %struct.sg_io_v4* %6)
%39 = icmp eq i32 %38, 0
br i1 %39, label %67, label %40
40: ; preds = %3
%41 = load i64, i64* @errno
%42 = load i64, i64* @EINVAL
%43 = icmp eq i64 %41, %42
br i1 %43, label %44, label %79
44: ; preds = %40
%45 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %7, i64 0, i32 0
store i8 0, i8* %45
%46 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %7, i64 0, i32 1
%47 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %7, i64 0, i32 4
%48 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %7, i64 0, i32 7
%49 = bitcast i32* %46 to i8*
%50 = bitcast i64* %47 to i8*
store i32 30000, i32* %48
%51 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %7, i64 0, i32 8
store i8 83, i8* %51
%52 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %7, i64 0, i32 9
%53 = bitcast i8** %52 to [16 x i32]**
store [16 x i32]* %4, [16 x i32]** %53
%54 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %7, i64 0, i32 10
store i32 64, i32* %54
%55 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %7, i64 0, i32 11
store i8* %1, i8** %55
%56 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %7, i64 0, i32 12
store i64 %2, i64* %56
%57 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %7, i64 0, i32 13
store i32* %15, i32** %57
%58 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %7, i64 0, i32 14
store i32 128, i32* %58
%59 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %7, i64 0, i32 15
%60 = load i32, i32* @SG_DXFER_FROM_DEV
store i32 %60, i32* %59
%61 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %7, i64 0, i32 16
store i32 0, i32* %61
%62 = getelementptr inbounds %struct.sg_io_hdr, %struct.sg_io_hdr* %7, i64 0, i32 17
store i32 0, i32* %62
%63 = load i32, i32* @SG_IO
%64 = bitcast %struct.sg_io_hdr* %7 to %struct.sg_io_v4*
%65 = call i32 @ioctl(i32 %0, i32 %63, %struct.sg_io_v4* %64)
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %79
67: ; preds = %44, %3
%68 = load i32, i32* %15
%69 = icmp eq i32 %68, 114
%70 = load i32, i32* %16
%71 = icmp eq i32 %70, 9
%72 = select i1 %69, i1 %71, i1 false
%73 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 9
%74 = load i32, i32* %73
%75 = icmp eq i32 %74, 12
%76 = select i1 %72, i1 %75, i1 false
br i1 %76, label %79, label %77
77: ; preds = %67
%78 = load i64, i64* @EIO
store i64 %78, i64* @errno
br label %79
79: ; preds = %67, %40, %44, %77
%80 = phi i32 [ -1, %77 ], [ %65, %44 ], [ %38, %40 ], [ 0, %67 ]
ret i32 %80
}