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

/* Variables and functions */
int completion_code(int /*<<< orphan*/);
int /*<<< orphan*/ memset(int *, int, int);
int scsi_device_read_capacity(int, int, int *, int *, int /*<<< orphan*/ *);
int /*<<< orphan*/ scsi_device_sense(int, int);
int /*<<< orphan*/ scsi_device_type_data(int, int, int *, int *);
int /*<<< orphan*/ x54x_log(char *, int, int, int, int, int, int);
int x54x_bios_command_15(uint8_t id, uint8_t lun, uint8_t *buffer) {
  uint8_t cdb[12] = {0x25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  uint8_t rcbuf[8] = {0, 0, 0, 0, 0, 0, 0, 0};
  uint32_t len = 0;
  int i, ret, sc;
  ret = scsi_device_read_capacity(id, lun, cdb, rcbuf, &len);
  sc = completion_code(scsi_device_sense(id, lun));
  memset(buffer, 0x00, 6);
  for (i = 0; i < 4; i++)
    buffer[i] = (ret == 0) ? 0 : rcbuf[i];
  scsi_device_type_data(id, lun, &(buffer[4]), &(buffer[5]));
  x54x_log("BIOS Command 0x15: %02X %02X %02X %02X %02X %02X\n", buffer[0],
           buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);
  return (sc);
}


x86 assembly (clang, -O0):
<x54x_bios_command_15>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
movl   $0x25,-0x40(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
movl   $0x0,-0x64(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x40(%rbp),%rdx
lea    -0x60(%rbp),%rcx
lea    -0x64(%rbp),%r8
call   1070 <scsi_device_read_capacity@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <scsi_device_sense@plt>
mov    %eax,%edi
call   1050 <completion_code@plt>
mov    %eax,-0x70(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1040 <memset@plt>
movl   $0x0,-0x68(%rbp)
cmpl   $0x4,-0x68(%rbp)
jge    122e <x54x_bios_command_15+0xce>
cmpl   $0x0,-0x6c(%rbp)
jne    1207 <x54x_bios_command_15+0xa7>
xor    %eax,%eax
mov    %eax,-0x74(%rbp)
jmp    1212 <x54x_bios_command_15+0xb2>
movslq -0x68(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%eax
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x68(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    11e9 <x54x_bios_command_15+0x89>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
add    $0x10,%rdx
mov    -0x10(%rbp),%rcx
add    $0x14,%rcx
call   1060 <scsi_device_type_data@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%r8d
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r9d
mov    -0x10(%rbp),%rax
mov    0x14(%rax),%eax
lea    0xd85(%rip),%rdi
mov    %eax,(%rsp)
call   1080 <x54x_log@plt>
mov    -0x70(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<x54x_bios_command_15>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%r13d
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movl   $0x25,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
lea    0x30(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1070 <scsi_device_read_capacity@plt>
mov    %eax,%r12d
mov    %r13d,%edi
mov    %r14d,%esi
call   1030 <scsi_device_sense@plt>
mov    %eax,%edi
call   1050 <completion_code@plt>
mov    %eax,%r15d
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1040 <memset@plt>
test   %r12d,%r12d
je     11ff <x54x_bios_command_15+0x9f>
mov    0x10(%rsp),%eax
mov    %eax,(%rbx)
mov    0x14(%rsp),%eax
mov    %eax,0x4(%rbx)
mov    0x18(%rsp),%eax
mov    %eax,0x8(%rbx)
mov    0x1c(%rsp),%ebp
jmp    120d <x54x_bios_command_15+0xad>
movq   $0x0,(%rbx)
movl   $0x0,0x8(%rbx)
mov    %ebp,0xc(%rbx)
lea    0x10(%rbx),%rdx
lea    0x14(%rbx),%rcx
mov    %r13d,%edi
mov    %r14d,%esi
call   1060 <scsi_device_type_data@plt>
mov    (%rbx),%esi
mov    0x4(%rbx),%edx
mov    0x8(%rbx),%ecx
mov    0xc(%rbx),%r8d
mov    0x10(%rbx),%r9d
mov    0x14(%rbx),%eax
mov    %eax,(%rsp)
lea    0xdc0(%rip),%rdi
call   1080 <x54x_log@plt>
mov    %r15d,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"BIOS Command 0x15: %02X %02X %02X %02X %02X %02X\0A\00"
define i32 @x54x_bios_command_15(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [12 x i32]
%8 = alloca [8 x i32]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%13 = bitcast [12 x i32]* %7 to i8*
%14 = bitcast i8* %13 to <{ i32, [11 x i32] }>*
%15 = getelementptr inbounds <{ i32, [11 x i32] }>, <{ i32, [11 x i32] }>* %14, i32 0, i32 0
store i32 37, i32* %15
%16 = bitcast [8 x i32]* %8 to i8*
store i32 0, i32* %9
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = getelementptr inbounds [12 x i32], [12 x i32]* %7, i64 0, i64 0
%20 = getelementptr inbounds [8 x i32], [8 x i32]* %8, i64 0, i64 0
%21 = call i32 @scsi_device_read_capacity(i32 %17, i32 %18, i32* %19, i32* %20, i32* %9)
store i32 %21, i32* %11
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = call i32 @scsi_device_sense(i32 %22, i32 %23)
%25 = call i32 @completion_code(i32 %24)
store i32 %25, i32* %12
%26 = load i32*, i32** %6
%27 = call i32 @memset(i32* %26, i32 0, i32 6)
store i32 0, i32* %10
br label %28
28: ; preds = %46, %3
%29 = load i32, i32* %10
%30 = icmp slt i32 %29, 4
br i1 %30, label %31, label %49
31: ; preds = %28
%32 = load i32, i32* %11
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %31
br label %40
35: ; preds = %31
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [8 x i32], [8 x i32]* %8, i64 0, i64 %37
%39 = load i32, i32* %38
br label %40
40: ; preds = %35, %34
%41 = phi i32 [ 0, %34 ], [ %39, %35 ]
%42 = load i32*, i32** %6
%43 = load i32, i32* %10
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
store i32 %41, i32* %45
br label %46
46: ; preds = %40
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
br label %28
49: ; preds = %28
%50 = load i32, i32* %4
%51 = load i32, i32* %5
%52 = load i32*, i32** %6
%53 = getelementptr inbounds i32, i32* %52, i64 4
%54 = load i32*, i32** %6
%55 = getelementptr inbounds i32, i32* %54, i64 5
%56 = call i32 @scsi_device_type_data(i32 %50, i32 %51, i32* %53, i32* %55)
%57 = load i32*, i32** %6
%58 = getelementptr inbounds i32, i32* %57, i64 0
%59 = load i32, i32* %58
%60 = load i32*, i32** %6
%61 = getelementptr inbounds i32, i32* %60, i64 1
%62 = load i32, i32* %61
%63 = load i32*, i32** %6
%64 = getelementptr inbounds i32, i32* %63, i64 2
%65 = load i32, i32* %64
%66 = load i32*, i32** %6
%67 = getelementptr inbounds i32, i32* %66, i64 3
%68 = load i32, i32* %67
%69 = load i32*, i32** %6
%70 = getelementptr inbounds i32, i32* %69, i64 4
%71 = load i32, i32* %70
%72 = load i32*, i32** %6
%73 = getelementptr inbounds i32, i32* %72, i64 5
%74 = load i32, i32* %73
%75 = call i32 @x54x_log(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %59, i32 %62, i32 %65, i32 %68, i32 %71, i32 %74)
%76 = load i32, i32* %12
ret i32 %76
}

LLVM IR (-O2):
@.str = [50 x i8] c"BIOS Command 0x15: %02X %02X %02X %02X %02X %02X\0A\00"
define i32 @x54x_bios_command_15(i32 %0, i32 %1, i32* %2) {
%4 = alloca [12 x i32]
%5 = alloca [8 x i32]
%6 = alloca i32
%7 = bitcast [12 x i32]* %4 to i8*
%8 = getelementptr inbounds [12 x i32], [12 x i32]* %4, i64 0, i64 0
store i32 37, i32* %8
%9 = bitcast [8 x i32]* %5 to i8*
%10 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%11 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 0
%12 = call i32 @scsi_device_read_capacity(i32 %0, i32 %1, i32* %8, i32* %11, i32* %6)
%13 = call i32 @scsi_device_sense(i32 %0, i32 %1)
%14 = call i32 @completion_code(i32 %13)
%15 = call i32 @memset(i32* %2, i32 0, i32 6)
%16 = icmp eq i32 %12, 0
br i1 %16, label %17, label %20
17: ; preds = %3
store i32 0, i32* %2
%18 = getelementptr inbounds i32, i32* %2, i64 1
store i32 0, i32* %18
%19 = getelementptr inbounds i32, i32* %2, i64 2
store i32 0, i32* %19
br label %30
20: ; preds = %3
%21 = load i32, i32* %11
store i32 %21, i32* %2
%22 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds i32, i32* %2, i64 1
store i32 %23, i32* %24
%25 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 2
%26 = load i32, i32* %25
%27 = getelementptr inbounds i32, i32* %2, i64 2
store i32 %26, i32* %27
%28 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 3
%29 = load i32, i32* %28
br label %30
30: ; preds = %17, %20
%31 = phi i32* [ %27, %20 ], [ %19, %17 ]
%32 = phi i32* [ %24, %20 ], [ %18, %17 ]
%33 = phi i32 [ %29, %20 ], [ 0, %17 ]
%34 = getelementptr inbounds i32, i32* %2, i64 3
store i32 %33, i32* %34
%35 = getelementptr inbounds i32, i32* %2, i64 4
%36 = getelementptr inbounds i32, i32* %2, i64 5
%37 = call i32 @scsi_device_type_data(i32 %0, i32 %1, i32* %35, i32* %36)
%38 = load i32, i32* %2
%39 = load i32, i32* %32
%40 = load i32, i32* %31
%41 = load i32, i32* %34
%42 = load i32, i32* %35
%43 = load i32, i32* %36
%44 = call i32 @x54x_log(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %38, i32 %39, i32 %40, i32 %41, i32 %42, i32 %43)
ret i32 %14
}