#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*/ x54x_log(char *, int, int, int, int, int, int);
uint8_t x54x_bios_command_08(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));
  if (ret == 0)
    return (sc);
  memset(buffer, 0x00, 6);
  for (i = 0; i < 4; i++)
    buffer[i] = rcbuf[i];
  for (i = 4; i < 6; i++)
    buffer[i] = rcbuf[(i + 2) ^ 1];
  x54x_log("BIOS Command 0x08: %02X %02X %02X %02X %02X %02X\n", buffer[0],
           buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);
  return (0);
}


x86 assembly (clang, -O0):
<x54x_bios_command_08>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
movl   $0x25,-0x50(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
movl   $0x0,-0x74(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0x50(%rbp),%rdx
lea    -0x70(%rbp),%rcx
lea    -0x74(%rbp),%r8
call   1060 <scsi_device_read_capacity@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <scsi_device_sense@plt>
mov    %eax,%edi
call   1050 <completion_code@plt>
mov    %eax,-0x80(%rbp)
cmpl   $0x0,-0x7c(%rbp)
jne    11d7 <x54x_bios_command_08+0x87>
mov    -0x80(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1293 <x54x_bios_command_08+0x143>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1040 <memset@plt>
movl   $0x0,-0x78(%rbp)
cmpl   $0x4,-0x78(%rbp)
jge    1219 <x54x_bios_command_08+0xc9>
movslq -0x78(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%edx
mov    -0x18(%rbp),%rax
movslq -0x78(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    11ee <x54x_bios_command_08+0x9e>
movl   $0x4,-0x78(%rbp)
cmpl   $0x6,-0x78(%rbp)
jge    1252 <x54x_bios_command_08+0x102>
mov    -0x78(%rbp),%eax
add    $0x2,%eax
xor    $0x1,%eax
cltq
mov    -0x70(%rbp,%rax,4),%edx
mov    -0x18(%rbp),%rax
movslq -0x78(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1220 <x54x_bios_command_08+0xd0>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%r8d
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%r9d
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%eax
lea    0xd7c(%rip),%rdi
mov    %eax,(%rsp)
call   1070 <x54x_log@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<x54x_bios_command_08>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
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   1060 <scsi_device_read_capacity@plt>
mov    %eax,%r15d
mov    %ebp,%edi
mov    %r14d,%esi
call   1030 <scsi_device_sense@plt>
mov    %eax,%edi
call   1050 <completion_code@plt>
test   %r15d,%r15d
je     1201 <x54x_bios_command_08+0xb1>
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1040 <memset@plt>
movaps 0x10(%rsp),%xmm0
movups %xmm0,(%rbx)
mov    0x2c(%rsp),%r9d
mov    %r9d,0x10(%rbx)
mov    0x28(%rsp),%eax
mov    %eax,0x14(%rbx)
mov    (%rbx),%esi
mov    0x4(%rbx),%edx
mov    0x8(%rbx),%ecx
mov    0xc(%rbx),%r8d
mov    %eax,(%rsp)
lea    0xe06(%rip),%rdi
call   1070 <x54x_log@plt>
jmp    1203 <x54x_bios_command_08+0xb3>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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