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

/* Variables and functions */
int /*<<< orphan*/ SG_DXFER_FROM_DEV;
int ntohl(int const);
int scsi_command(int, int /*<<< orphan*/, int const *, int, int *, int, int *,
                 int /*<<< orphan*/);
int get_data_buffer_status(int fd, uint8_t *window_id, uint32_t *length,
                           uint8_t *requestsense) {
  uint8_t buffer[12];
  static const uint8_t command[] = {0x34,           0, 0, 0, 0, 0, 0, 0,
                                    sizeof(buffer), 0};
  const int r = scsi_command(fd, SG_DXFER_FROM_DEV, command, sizeof(command),
                             buffer, sizeof(buffer), requestsense, 0);
  if (r)
    return r;
  *window_id = buffer[4];
  const uint32_t length_be = ((uint32_t)buffer[9]) << 16 |
                             ((uint32_t)buffer[10]) << 8 |
                             ((uint32_t)buffer[11]);
  *length = ntohl(length_be);
  return 0;
}


x86 assembly (clang, -O0):
<get_data_buffer_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea7(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%r8
mov    -0x20(%rbp),%rax
lea    0xeae(%rip),%rdx
mov    $0x28,%ecx
mov    $0x30,%r9d
xor    %r10d,%r10d
mov    %rax,(%rsp)
movl   $0x0,0x8(%rsp)
call   1030 <scsi_command@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     1189 <get_data_buffer_status+0x69>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11bd <get_data_buffer_status+0x9d>
mov    -0x40(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%eax
shl    $0x10,%eax
mov    -0x28(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%edi
call   1040 <ntohl@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_data_buffer_status>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rcx,%rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    0x2eb0(%rip),%rcx
mov    (%rcx),%esi
lea    0xebf(%rip),%rdx
mov    %rsp,%r8
mov    $0x28,%ecx
mov    $0x30,%r9d
push   $0x0
push   %rax
call   1030 <scsi_command@plt>
add    $0x10,%rsp
mov    %eax,%ebp
test   %eax,%eax
jne    1183 <get_data_buffer_status+0x63>
mov    0x10(%rsp),%eax
mov    %eax,(%rbx)
mov    0x24(%rsp),%eax
mov    0x28(%rsp),%edi
shl    $0x10,%eax
shl    $0x8,%edi
or     %eax,%edi
or     0x2c(%rsp),%edi
call   1040 <ntohl@plt>
mov    %eax,(%r14)
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@get_data_buffer_status.command = internal constant [10 x i32] [i32 52, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 48, i32 0]
@SG_DXFER_FROM_DEV = global i32 0
define i32 @get_data_buffer_status(i32 %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [12 x i32]
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%13 = load i32, i32* %6
%14 = load i32, i32* @SG_DXFER_FROM_DEV
%15 = getelementptr inbounds [12 x i32], [12 x i32]* %10, i64 0, i64 0
%16 = load i32*, i32** %9
%17 = call i32 @scsi_command(i32 %13, i32 %14, i32* getelementptr inbounds ([10 x i32], [10 x i32]* @get_data_buffer_status.command, i64 0, i64 0), i32 40, i32* %15, i32 48, i32* %16, i32 0)
store i32 %17, i32* %11
%18 = load i32, i32* %11
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %4
%21 = load i32, i32* %11
store i32 %21, i32* %5
br label %39
22: ; preds = %4
%23 = getelementptr inbounds [12 x i32], [12 x i32]* %10, i64 0, i64 4
%24 = load i32, i32* %23
%25 = load i32*, i32** %7
store i32 %24, i32* %25
%26 = getelementptr inbounds [12 x i32], [12 x i32]* %10, i64 0, i64 9
%27 = load i32, i32* %26
%28 = shl i32 %27, 16
%29 = getelementptr inbounds [12 x i32], [12 x i32]* %10, i64 0, i64 10
%30 = load i32, i32* %29
%31 = shl i32 %30, 8
%32 = or i32 %28, %31
%33 = getelementptr inbounds [12 x i32], [12 x i32]* %10, i64 0, i64 11
%34 = load i32, i32* %33
%35 = or i32 %32, %34
store i32 %35, i32* %12
%36 = load i32, i32* %12
%37 = call i32 @ntohl(i32 %36)
%38 = load i32*, i32** %8
store i32 %37, i32* %38
store i32 0, i32* %5
br label %39
39: ; preds = %22, %20
%40 = load i32, i32* %5
ret i32 %40
}

LLVM IR (-O2):
@get_data_buffer_status.command = internal constant [10 x i32] [i32 52, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 48, i32 0]
@SG_DXFER_FROM_DEV = global i32 0
define i32 @get_data_buffer_status(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* %3) {
%5 = alloca [12 x i32]
%6 = bitcast [12 x i32]* %5 to i8*
%7 = load i32, i32* @SG_DXFER_FROM_DEV
%8 = getelementptr inbounds [12 x i32], [12 x i32]* %5, i64 0, i64 0
%9 = call i32 @scsi_command(i32 %0, i32 %7, i32* getelementptr inbounds ([10 x i32], [10 x i32]* @get_data_buffer_status.command, i64 0, i64 0), i32 40, i32* %8, i32 48, i32* %3, i32 0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %4
%12 = getelementptr inbounds [12 x i32], [12 x i32]* %5, i64 0, i64 4
%13 = load i32, i32* %12
store i32 %13, i32* %1
%14 = getelementptr inbounds [12 x i32], [12 x i32]* %5, i64 0, i64 9
%15 = load i32, i32* %14
%16 = shl i32 %15, 16
%17 = getelementptr inbounds [12 x i32], [12 x i32]* %5, i64 0, i64 10
%18 = load i32, i32* %17
%19 = shl i32 %18, 8
%20 = or i32 %19, %16
%21 = getelementptr inbounds [12 x i32], [12 x i32]* %5, i64 0, i64 11
%22 = load i32, i32* %21
%23 = or i32 %20, %22
%24 = call i32 @ntohl(i32 %23)
store i32 %24, i32* %2
br label %25
25: ; preds = %4, %11
ret i32 %9
}