#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 */

/* Variables and functions */
int scsi_request(char *, char *, int *, int, int /*<<< orphan*/, int, int,
                 int /*<<< orphan*/, unsigned char, unsigned char,
                 unsigned char, unsigned char, int /*<<< orphan*/,
                 int /*<<< orphan*/, int, int /*<<< orphan*/);
int read_capacity(int *lba, int *bsize) {
  char buf[256];
  int r, len = 255;
  if (!lba || !bsize)
    return -1;
  r = scsi_request(
      "read_capacity", buf, &len, 10, 0, 0x01, 0x25, 0,
      ((unsigned char)(((0)) >> 24)), ((unsigned char)(((0)) >> 16)),
      ((unsigned char)(((0)) >> 8)), ((unsigned char)(0)), 0, 0, 0x00, 0);
  if (r)
    return r;
  *lba = (((((((&buf[0])[0] << 8) | (&buf[0])[1]) << 8) | (&buf[0])[2]) << 8) |
          (&buf[0])[3]);
  *bsize =
      (((((((&buf[4])[0] << 8) | (&buf[4])[1]) << 8) | (&buf[4])[2]) << 8) |
       (&buf[4])[3]);
  return 0;
}


x86 assembly (clang, -O0):
<read_capacity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0xff,-0x128(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1143 <read_capacity+0x33>
cmpq   $0x0,-0x18(%rbp)
jne    114f <read_capacity+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1250 <read_capacity+0x140>
lea    -0x120(%rbp),%rsi
lea    0xea3(%rip),%rdi
lea    -0x128(%rbp),%rdx
mov    $0xa,%ecx
xor    %r8d,%r8d
mov    $0x1,%r9d
movl   $0x25,(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x18(%rsp)
movl   $0x0,0x20(%rsp)
movl   $0x0,0x28(%rsp)
movl   $0x0,0x30(%rsp)
movl   $0x0,0x38(%rsp)
movl   $0x0,0x40(%rsp)
movl   $0x0,0x48(%rsp)
call   1030 <scsi_request@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
je     11e7 <read_capacity+0xd7>
mov    -0x124(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1250 <read_capacity+0x140>
movsbl -0x120(%rbp),%ecx
shl    $0x8,%ecx
movsbl -0x11f(%rbp),%eax
or     %eax,%ecx
shl    $0x8,%ecx
movsbl -0x11e(%rbp),%eax
or     %eax,%ecx
shl    $0x8,%ecx
movsbl -0x11d(%rbp),%eax
or     %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movsbl -0x11c(%rbp),%ecx
shl    $0x8,%ecx
movsbl -0x11b(%rbp),%eax
or     %eax,%ecx
shl    $0x8,%ecx
movsbl -0x11a(%rbp),%eax
or     %eax,%ecx
shl    $0x8,%ecx
movsbl -0x119(%rbp),%eax
or     %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_capacity>:
push   %r14
push   %rbx
sub    $0x118,%rsp
movl   $0xff,0xc(%rsp)
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     11ca <read_capacity+0xba>
mov    %rsi,%r14
test   %rsi,%rsi
je     11ca <read_capacity+0xba>
mov    %rdi,%rbx
lea    0xeba(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    $0xa,%ecx
xor    %r8d,%r8d
mov    $0x1,%r9d
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x0
push   $0x25
call   1030 <scsi_request@plt>
add    $0x50,%rsp
test   %eax,%eax
jne    11ca <read_capacity+0xba>
mov    0x10(%rsp),%eax
movsbl 0x11(%rsp),%ecx
shl    $0x10,%eax
shl    $0x8,%ecx
or     %eax,%ecx
movsbl 0x12(%rsp),%eax
or     %ecx,%eax
shl    $0x8,%eax
movsbl 0x13(%rsp),%ecx
or     %eax,%ecx
mov    %ecx,(%rbx)
mov    0x14(%rsp),%eax
movsbl 0x15(%rsp),%ecx
shl    $0x10,%eax
shl    $0x8,%ecx
or     %eax,%ecx
movsbl 0x16(%rsp),%eax
or     %ecx,%eax
shl    $0x8,%eax
movsbl 0x17(%rsp),%ecx
or     %eax,%ecx
mov    %ecx,(%r14)
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"read_capacity\00"
define i32 @read_capacity(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 255, i32* %8
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32*, i32** %5
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %11, %2
store i32 -1, i32* %3
br label %69
15: ; preds = %11
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%17 = call i32 @scsi_request(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %16, i32* %8, i32 10, i32 0, i32 1, i32 37, i32 0, i8 zeroext 0, i8 zeroext 0, i8 zeroext 0, i8 zeroext 0, i32 0, i32 0, i32 0, i32 0)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i32, i32* %7
store i32 %21, i32* %3
br label %69
22: ; preds = %15
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = shl i32 %26, 8
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = or i32 %27, %31
%33 = shl i32 %32, 8
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%35 = getelementptr inbounds i8, i8* %34, i64 2
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = or i32 %33, %37
%39 = shl i32 %38, 8
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%41 = getelementptr inbounds i8, i8* %40, i64 3
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = or i32 %39, %43
%45 = load i32*, i32** %4
store i32 %44, i32* %45
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 4
%47 = getelementptr inbounds i8, i8* %46, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = shl i32 %49, 8
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 4
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = or i32 %50, %54
%56 = shl i32 %55, 8
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 4
%58 = getelementptr inbounds i8, i8* %57, i64 2
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = or i32 %56, %60
%62 = shl i32 %61, 8
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 4
%64 = getelementptr inbounds i8, i8* %63, i64 3
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = or i32 %62, %66
%68 = load i32*, i32** %5
store i32 %67, i32* %68
store i32 0, i32* %3
br label %69
69: ; preds = %22, %20, %14
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@.str = [14 x i8] c"read_capacity\00"
define i32 @read_capacity(i32* writeonly %0, i32* writeonly %1) {
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
store i32 255, i32* %4
%7 = icmp ne i32* %0, null
%8 = icmp ne i32* %1, null
%9 = and i1 %7, %8
br i1 %9, label %10, label %49
10: ; preds = %2
%11 = call i32 @scsi_request(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %5, i32* %4, i32 10, i32 0, i32 1, i32 37, i32 0, i8 zeroext 0, i8 zeroext 0, i8 zeroext 0, i8 zeroext 0, i32 0, i32 0, i32 0, i32 0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %49
13: ; preds = %10
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = shl nsw i32 %15, 16
%20 = shl nsw i32 %18, 8
%21 = or i32 %20, %19
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 2
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = or i32 %21, %24
%26 = shl nsw i32 %25, 8
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 3
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = or i32 %26, %29
store i32 %30, i32* %0
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 4
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 5
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = shl nsw i32 %33, 16
%38 = shl nsw i32 %36, 8
%39 = or i32 %38, %37
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 6
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = or i32 %39, %42
%44 = shl nsw i32 %43, 8
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 7
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = or i32 %44, %47
store i32 %48, i32* %1
br label %49
49: ; preds = %10, %2, %13
%50 = phi i32 [ 0, %13 ], [ -1, %2 ], [ %11, %10 ]
ret i32 %50
}