#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 /*<<< orphan*/ cdb;

/* Variables and functions */
int /*<<< orphan*/ SG_DXFER_FROM_DEV;
int /*<<< orphan*/ print_sense_data(unsigned char *, unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int scsi_io(int, unsigned char *, int, int /*<<< orphan*/, unsigned char *,
            unsigned int *, unsigned char *, unsigned int *);
int scsi_persistent_reserve_in_read_full_status(int fd) {
  unsigned char cdb[] = {0x5e, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  unsigned int data_size = 0x00ff;
  unsigned char data[data_size];
  unsigned int sense_len = 32;
  unsigned char sense[sense_len];
  unsigned char service_action = 3;
  int res;
  unsigned long prgeneration, additional_length;
  cdb[1] = service_action;
  cdb[7] = (data_size >> 8) & 0xff;
  cdb[8] = data_size & 0xff;
  printf("PERSISTENT RESERVE IN: READ FULL STATUS\n");
  res = scsi_io(fd, cdb, sizeof(cdb), SG_DXFER_FROM_DEV, data, &data_size,
                sense, &sense_len);
  if (res) {
    printf("SCSI_IO failed\n");
    return -1;
  }
  if (sense_len) {
    print_sense_data(sense, sense_len);
    return -1;
  }
  prgeneration = data[0];
  prgeneration <<= 8;
  prgeneration |= data[1];
  prgeneration <<= 8;
  prgeneration |= data[2];
  prgeneration <<= 8;
  prgeneration |= data[3];
  printf("PRGeneration:%lu\n", prgeneration);
  additional_length = data[4];
  additional_length <<= 8;
  additional_length |= data[5];
  additional_length <<= 8;
  additional_length |= data[6];
  additional_length <<= 8;
  additional_length |= data[7];
  printf("Additional Length:%lu\n", additional_length);
  return 0;
}


x86 assembly (clang, -O0):
<scsi_persistent_reserve_in_read_full_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    0xec6(%rip),%ax
mov    %ax,-0x10(%rbp)
mov    0xeb3(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0xff,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x20,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
movb   $0x3,-0x41(%rbp)
mov    -0x41(%rbp),%al
mov    %al,-0x17(%rbp)
mov    -0x1c(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x11(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x10(%rbp)
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x70(%rbp),%r8
mov    -0x68(%rbp),%r10
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    0x2dfd(%rip),%rax
mov    (%rax),%ecx
mov    $0xa,%edx
lea    -0x1c(%rbp),%r9
lea    -0x34(%rbp),%rax
sub    $0x10,%rsp
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <scsi_io@plt>
add    $0x10,%rsp
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
je     123e <scsi_persistent_reserve_in_read_full_status+0x10e>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    1340 <scsi_persistent_reserve_in_read_full_status+0x210>
cmpl   $0x0,-0x34(%rbp)
je     1267 <scsi_persistent_reserve_in_read_full_status+0x137>
mov    -0x68(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1050 <print_sense_data@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    1340 <scsi_persistent_reserve_in_read_full_status+0x210>
mov    -0x70(%rbp),%rax
movzbl (%rax),%ecx
mov    %rcx,-0x50(%rbp)
mov    -0x50(%rbp),%rcx
shl    $0x8,%rcx
mov    %rcx,-0x50(%rbp)
movzbl 0x1(%rax),%ecx
or     -0x50(%rbp),%rcx
mov    %rcx,-0x50(%rbp)
mov    -0x50(%rbp),%rcx
shl    $0x8,%rcx
mov    %rcx,-0x50(%rbp)
movzbl 0x2(%rax),%ecx
or     -0x50(%rbp),%rcx
mov    %rcx,-0x50(%rbp)
mov    -0x50(%rbp),%rcx
shl    $0x8,%rcx
mov    %rcx,-0x50(%rbp)
movzbl 0x3(%rax),%eax
or     -0x50(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rsi
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x70(%rbp),%rax
movzbl 0x4(%rax),%ecx
mov    %rcx,-0x58(%rbp)
mov    -0x58(%rbp),%rcx
shl    $0x8,%rcx
mov    %rcx,-0x58(%rbp)
movzbl 0x5(%rax),%ecx
or     -0x58(%rbp),%rcx
mov    %rcx,-0x58(%rbp)
mov    -0x58(%rbp),%rcx
shl    $0x8,%rcx
mov    %rcx,-0x58(%rbp)
movzbl 0x6(%rax),%ecx
or     -0x58(%rbp),%rcx
mov    %rcx,-0x58(%rbp)
mov    -0x58(%rbp),%rcx
shl    $0x8,%rcx
mov    %rcx,-0x58(%rbp)
movzbl 0x7(%rax),%eax
or     -0x58(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rsi
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scsi_persistent_reserve_in_read_full_status>:
push   %r14
push   %rbx
sub    $0x148,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
movzwl 0xeb2(%rip),%eax
mov    %ax,0x18(%rsp)
mov    0xe9e(%rip),%rax
mov    %rax,0x10(%rsp)
movl   $0xff,0x1c(%rsp)
movl   $0x20,0xc(%rsp)
movb   $0x3,0x11(%rsp)
movw   $0xff00,0x17(%rsp)
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%ecx
lea    0xc(%rsp),%rax
lea    0x20(%rsp),%r10
lea    0x10(%rsp),%rsi
lea    0x40(%rsp),%r8
lea    0x1c(%rsp),%r9
mov    %ebx,%edi
mov    $0xa,%edx
push   %rax
push   %r10
call   1050 <scsi_io@plt>
add    $0x10,%rsp
test   %eax,%eax
je     11db <scsi_persistent_reserve_in_read_full_status+0x9b>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    1228 <scsi_persistent_reserve_in_read_full_status+0xe8>
mov    0xc(%rsp),%esi
test   %esi,%esi
je     11f4 <scsi_persistent_reserve_in_read_full_status+0xb4>
lea    0x20(%rsp),%rdi
call   1060 <print_sense_data@plt>
mov    $0xffffffff,%ebx
jmp    1228 <scsi_persistent_reserve_in_read_full_status+0xe8>
mov    0x40(%rsp),%esi
shl    $0x20,%rsi
bswap  %rsi
lea    0xe04(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x44(%rsp),%esi
shl    $0x20,%rsi
bswap  %rsi
lea    0xdfb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rsp
mov    %ebx,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.scsi_persistent_reserve_in_read_full_status.cdb = <{ i8, [9 x i8] }> <{ i8 94, [9 x i8] zeroinitializer }>
@.str = [41 x i8] c"PERSISTENT RESERVE IN: READ FULL STATUS\0A\00"
@SG_DXFER_FROM_DEV = global i32 0
@.str.1 = [16 x i8] c"SCSI_IO failed\0A\00"
@.str.2 = [18 x i8] c"PRGeneration:%lu\0A\00"
@.str.3 = [23 x i8] c"Additional Length:%lu\0A\00"
define i32 @scsi_persistent_reserve_in_read_full_status(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca i32
store i32 %0, i32* %3
%15 = bitcast [10 x i8]* %4 to i8*
store i32 255, i32* %5
%16 = load i32, i32* %5
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %6
%19 = alloca i8, i64 %17
store i64 %17, i64* %7
store i32 32, i32* %8
%20 = load i32, i32* %8
%21 = zext i32 %20 to i64
%22 = alloca i8, i64 %21
store i64 %21, i64* %9
store i8 3, i8* %10
%23 = load i8, i8* %10
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 1
store i8 %23, i8* %24
%25 = load i32, i32* %5
%26 = lshr i32 %25, 8
%27 = and i32 %26, 255
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 7
store i8 %28, i8* %29
%30 = load i32, i32* %5
%31 = and i32 %30, 255
%32 = trunc i32 %31 to i8
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 8
store i8 %32, i8* %33
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%35 = load i32, i32* %3
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%37 = load i32, i32* @SG_DXFER_FROM_DEV
%38 = call i32 @scsi_io(i32 %35, i8* %36, i32 10, i32 %37, i8* %19, i32* %5, i8* %22, i32* %8)
store i32 %38, i32* %11
%39 = load i32, i32* %11
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %1
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
store i32 1, i32* %14
br label %102
43: ; preds = %1
%44 = load i32, i32* %8
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* %8
%48 = call i32 @print_sense_data(i8* %22, i32 %47)
store i32 -1, i32* %2
store i32 1, i32* %14
br label %102
49: ; preds = %43
%50 = getelementptr inbounds i8, i8* %19, i64 0
%51 = load i8, i8* %50
%52 = zext i8 %51 to i64
store i64 %52, i64* %12
%53 = load i64, i64* %12
%54 = shl i64 %53, 8
store i64 %54, i64* %12
%55 = getelementptr inbounds i8, i8* %19, i64 1
%56 = load i8, i8* %55
%57 = zext i8 %56 to i64
%58 = load i64, i64* %12
%59 = or i64 %58, %57
store i64 %59, i64* %12
%60 = load i64, i64* %12
%61 = shl i64 %60, 8
store i64 %61, i64* %12
%62 = getelementptr inbounds i8, i8* %19, i64 2
%63 = load i8, i8* %62
%64 = zext i8 %63 to i64
%65 = load i64, i64* %12
%66 = or i64 %65, %64
store i64 %66, i64* %12
%67 = load i64, i64* %12
%68 = shl i64 %67, 8
store i64 %68, i64* %12
%69 = getelementptr inbounds i8, i8* %19, i64 3
%70 = load i8, i8* %69
%71 = zext i8 %70 to i64
%72 = load i64, i64* %12
%73 = or i64 %72, %71
store i64 %73, i64* %12
%74 = load i64, i64* %12
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 %74)
%76 = getelementptr inbounds i8, i8* %19, i64 4
%77 = load i8, i8* %76
%78 = zext i8 %77 to i64
store i64 %78, i64* %13
%79 = load i64, i64* %13
%80 = shl i64 %79, 8
store i64 %80, i64* %13
%81 = getelementptr inbounds i8, i8* %19, i64 5
%82 = load i8, i8* %81
%83 = zext i8 %82 to i64
%84 = load i64, i64* %13
%85 = or i64 %84, %83
store i64 %85, i64* %13
%86 = load i64, i64* %13
%87 = shl i64 %86, 8
store i64 %87, i64* %13
%88 = getelementptr inbounds i8, i8* %19, i64 6
%89 = load i8, i8* %88
%90 = zext i8 %89 to i64
%91 = load i64, i64* %13
%92 = or i64 %91, %90
store i64 %92, i64* %13
%93 = load i64, i64* %13
%94 = shl i64 %93, 8
store i64 %94, i64* %13
%95 = getelementptr inbounds i8, i8* %19, i64 7
%96 = load i8, i8* %95
%97 = zext i8 %96 to i64
%98 = load i64, i64* %13
%99 = or i64 %98, %97
store i64 %99, i64* %13
%100 = load i64, i64* %13
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i64 %100)
store i32 0, i32* %2
store i32 1, i32* %14
br label %102
102: ; preds = %49, %46, %41
%103 = load i8*, i8** %6
%104 = load i32, i32* %2
ret i32 %104
}

LLVM IR (-O2):
@__const.scsi_persistent_reserve_in_read_full_status.cdb = <{ i8, [9 x i8] }> <{ i8 94, [9 x i8] zeroinitializer }>
@SG_DXFER_FROM_DEV = global i32 0
@.str.2 = [18 x i8] c"PRGeneration:%lu\0A\00"
@.str.3 = [23 x i8] c"Additional Length:%lu\0A\00"
@str = [40 x i8] c"PERSISTENT RESERVE IN: READ FULL STATUS\00"
@str.4 = [15 x i8] c"SCSI_IO failed\00"
define i32 @scsi_persistent_reserve_in_read_full_status(i32 %0) {
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
store i32 255, i32* %3
%7 = tail call i8* @llvm.stacksave()
%8 = alloca [255 x i8]
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%10 = bitcast i32* %4 to i8*
store i32 32, i32* %4
%11 = alloca [32 x i8]
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 1
store i8 3, i8* %13
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 7
store i8 0, i8* %14
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 8
store i8 -1, i8* %15
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%17 = load i32, i32* @SG_DXFER_FROM_DEV
%18 = call i32 @scsi_io(i32 %0, i8* %5, i32 10, i32 %17, i8* %9, i32* %3, i8* %12, i32* %4)
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %1
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.4, i64 0, i64 0))
br label %65
22: ; preds = %1
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = call i32 @print_sense_data(i8* %12, i32 %23)
br label %65
27: ; preds = %22
%28 = load i8, i8* %9
%29 = zext i8 %28 to i64
%30 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 1
%31 = load i8, i8* %30
%32 = zext i8 %31 to i64
%33 = shl nuw nsw i64 %29, 16
%34 = shl nuw nsw i64 %32, 8
%35 = or i64 %34, %33
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 2
%37 = load i8, i8* %36
%38 = zext i8 %37 to i64
%39 = or i64 %35, %38
%40 = shl nuw nsw i64 %39, 8
%41 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 3
%42 = load i8, i8* %41
%43 = zext i8 %42 to i64
%44 = or i64 %40, %43
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 %44)
%46 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 4
%47 = load i8, i8* %46
%48 = zext i8 %47 to i64
%49 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 5
%50 = load i8, i8* %49
%51 = zext i8 %50 to i64
%52 = shl nuw nsw i64 %48, 16
%53 = shl nuw nsw i64 %51, 8
%54 = or i64 %53, %52
%55 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 6
%56 = load i8, i8* %55
%57 = zext i8 %56 to i64
%58 = or i64 %54, %57
%59 = shl nuw nsw i64 %58, 8
%60 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 7
%61 = load i8, i8* %60
%62 = zext i8 %61 to i64
%63 = or i64 %59, %62
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i64 %63)
br label %65
65: ; preds = %27, %25, %20
%66 = phi i32 [ -1, %20 ], [ -1, %25 ], [ 0, %27 ]
ret i32 %66
}