#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;

/* Variables and functions */
int hdd_image_get_last_sector(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int scsi_hd_read_capacity(uint8_t id, uint8_t *cdb, uint8_t *buffer,
                          uint32_t *len) {
  int size = 0;
  size = hdd_image_get_last_sector(id);
  memset(buffer, 0, 8);
  buffer[0] = (size >> 24) & 0xff;
  buffer[1] = (size >> 16) & 0xff;
  buffer[2] = (size >> 8) & 0xff;
  buffer[3] = size & 0xff;
  buffer[6] = 2;
  *len = 8;
  return 1;
}


x86 assembly (clang, -O0):
<scsi_hd_read_capacity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <hdd_image_get_last_sector@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x24(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x24(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x24(%rbp),%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x18(%rbp),%rax
movl   $0x2,0x18(%rax)
mov    -0x20(%rbp),%rax
movl   $0x8,(%rax)
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scsi_hd_read_capacity>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
call   1030 <hdd_image_get_last_sector@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    %ebp,%ecx
mov    %ebp,%eax
shr    $0x18,%eax
mov    %eax,(%rbx)
mov    %ebp,%eax
shr    $0x10,%eax
movzbl %al,%eax
mov    %eax,0x4(%rbx)
movzbl %ch,%eax
mov    %eax,0x8(%rbx)
movzbl %cl,%eax
mov    %eax,0xc(%rbx)
movl   $0x2,0x18(%rbx)
movl   $0x8,(%r14)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @scsi_hd_read_capacity(i32 %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i32 0, i32* %9
%10 = load i32, i32* %5
%11 = call i32 @hdd_image_get_last_sector(i32 %10)
store i32 %11, i32* %9
%12 = load i32*, i32** %7
%13 = call i32 @memset(i32* %12, i32 0, i32 8)
%14 = load i32, i32* %9
%15 = ashr i32 %14, 24
%16 = and i32 %15, 255
%17 = load i32*, i32** %7
%18 = getelementptr inbounds i32, i32* %17, i64 0
store i32 %16, i32* %18
%19 = load i32, i32* %9
%20 = ashr i32 %19, 16
%21 = and i32 %20, 255
%22 = load i32*, i32** %7
%23 = getelementptr inbounds i32, i32* %22, i64 1
store i32 %21, i32* %23
%24 = load i32, i32* %9
%25 = ashr i32 %24, 8
%26 = and i32 %25, 255
%27 = load i32*, i32** %7
%28 = getelementptr inbounds i32, i32* %27, i64 2
store i32 %26, i32* %28
%29 = load i32, i32* %9
%30 = and i32 %29, 255
%31 = load i32*, i32** %7
%32 = getelementptr inbounds i32, i32* %31, i64 3
store i32 %30, i32* %32
%33 = load i32*, i32** %7
%34 = getelementptr inbounds i32, i32* %33, i64 6
store i32 2, i32* %34
%35 = load i32*, i32** %8
store i32 8, i32* %35
ret i32 1
}

LLVM IR (-O2):
define i32 @scsi_hd_read_capacity(i32 %0, i32* nocapture readnone %1, i32* %2, i32* nocapture writeonly %3) {
%5 = tail call i32 @hdd_image_get_last_sector(i32 %0)
%6 = tail call i32 @memset(i32* %2, i32 0, i32 8)
%7 = lshr i32 %5, 24
store i32 %7, i32* %2
%8 = lshr i32 %5, 16
%9 = and i32 %8, 255
%10 = getelementptr inbounds i32, i32* %2, i64 1
store i32 %9, i32* %10
%11 = lshr i32 %5, 8
%12 = and i32 %11, 255
%13 = getelementptr inbounds i32, i32* %2, i64 2
store i32 %12, i32* %13
%14 = and i32 %5, 255
%15 = getelementptr inbounds i32, i32* %2, i64 3
store i32 %14, i32* %15
%16 = getelementptr inbounds i32, i32* %2, i64 6
store i32 2, i32* %16
store i32 8, i32* %3
ret i32 1
}