#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 */
scalar_t__ ide_wait_ready();
int ide_write_command_packet(char *cmd, int dma) {
  int i, status;
  unsigned short *spkt = (unsigned short *)cmd;
  unsigned short length = 8;
  if (ide_wait_ready())
    return 1;
  ((*((volatile unsigned char *)(0xA05F7000 + 0x084))) = (dma));
  ((*((volatile unsigned char *)(0xA05F7000 + 0x088))) = (0));
  ((*((volatile unsigned char *)(0xA05F7000 + 0x08C))) = (0));
  ((*((volatile unsigned char *)(0xA05F7000 + 0x090))) = ((length & 0xFF)));
  ((*((volatile unsigned char *)(0xA05F7000 + 0x094))) =
       ((length >> 8) & 0xFF));
  ((*((volatile unsigned char *)(0xA05F7000 + 0x098))) = (0));
  ((*((volatile unsigned char *)(0xA05F7000 + 0x09C))) = (0xA0));
  status = (unsigned int)(*((volatile unsigned char *)(0xA05F7000 + 0x018)));
  if (ide_wait_ready())
    return 1;
  for (i = 0; i < 6; i++) {
    ((*((volatile unsigned short *)(0xA05F7000 + 0x080))) = (spkt[i]));
  }
}


x86 assembly (clang, -O0):
<ide_write_command_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movw   $0x8,-0x2a(%rbp)
mov    $0x0,%al
call   1030 <ide_wait_ready@plt>
cmp    $0x0,%rax
je     114a <ide_write_command_packet+0x3a>
movl   $0x1,-0x4(%rbp)
jmp    11fa <ide_write_command_packet+0xea>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    $0xa05f7084,%eax
mov    %cl,(%rax)
mov    $0xa05f7088,%eax
movb   $0x0,(%rax)
mov    $0xa05f708c,%eax
movb   $0x0,(%rax)
movzwl -0x2a(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    $0xa05f7090,%eax
mov    %cl,(%rax)
movzwl -0x2a(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    $0xa05f7094,%eax
mov    %cl,(%rax)
mov    $0xa05f7098,%eax
movb   $0x0,(%rax)
mov    $0xa05f709c,%eax
movb   $0xa0,(%rax)
mov    $0xa05f7018,%eax
mov    (%rax),%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <ide_wait_ready@plt>
cmp    $0x0,%rax
je     11c7 <ide_write_command_packet+0xb7>
movl   $0x1,-0x4(%rbp)
jmp    11fa <ide_write_command_packet+0xea>
movl   $0x0,-0x18(%rbp)
cmpl   $0x6,-0x18(%rbp)
jge    11fa <ide_write_command_packet+0xea>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,2),%cx
mov    $0xa05f7080,%eax
mov    %cx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ce <ide_write_command_packet+0xbe>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ide_write_command_packet>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <ide_wait_ready@plt>
test   %rax,%rax
jne    1184 <ide_write_command_packet+0x74>
mov    $0xa05f7080,%ebx
mov    %bpl,0x4(%rbx)
movb   $0x0,0x8(%rbx)
movb   $0x0,0xc(%rbx)
movb   $0x8,0x10(%rbx)
movb   $0x0,0x14(%rbx)
movb   $0x0,0x18(%rbx)
movb   $0xa0,0x1c(%rbx)
mov    -0x68(%rbx),%al
xor    %eax,%eax
call   1030 <ide_wait_ready@plt>
test   %rax,%rax
jne    1184 <ide_write_command_packet+0x74>
movzwl (%r14),%eax
mov    %ax,(%rbx)
movzwl 0x2(%r14),%eax
mov    %ax,(%rbx)
movzwl 0x4(%r14),%eax
mov    %ax,(%rbx)
movzwl 0x6(%r14),%eax
mov    %ax,(%rbx)
movzwl 0x8(%r14),%eax
mov    %ax,(%rbx)
movzwl 0xa(%r14),%eax
mov    %ax,(%rbx)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ide_write_command_packet(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i16*
%9 = alloca i16
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i8*, i8** %4
%11 = bitcast i8* %10 to i16*
store i16* %11, i16** %8
store i16 8, i16* %9
%12 = call i64 (...) @ide_wait_ready()
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %45
15: ; preds = %2
%16 = load i32, i32* %5
%17 = trunc i32 %16 to i8
store volatile i8 %17, i8* inttoptr (i64 2690609284 to i8*)
store volatile i8 0, i8* inttoptr (i64 2690609288 to i8*)
store volatile i8 0, i8* inttoptr (i64 2690609292 to i8*)
%18 = load i16, i16* %9
%19 = zext i16 %18 to i32
%20 = and i32 %19, 255
%21 = trunc i32 %20 to i8
store volatile i8 %21, i8* inttoptr (i64 2690609296 to i8*)
%22 = load i16, i16* %9
%23 = zext i16 %22 to i32
%24 = ashr i32 %23, 8
%25 = and i32 %24, 255
%26 = trunc i32 %25 to i8
store volatile i8 %26, i8* inttoptr (i64 2690609300 to i8*)
store volatile i8 0, i8* inttoptr (i64 2690609304 to i8*)
store volatile i8 -96, i8* inttoptr (i64 2690609308 to i8*)
%27 = load volatile i8, i8* inttoptr (i64 2690609176 to i8*)
%28 = zext i8 %27 to i32
store i32 %28, i32* %7
%29 = call i64 (...) @ide_wait_ready()
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %15
store i32 1, i32* %3
br label %45
32: ; preds = %15
store i32 0, i32* %6
br label %33
33: ; preds = %42, %32
%34 = load i32, i32* %6
%35 = icmp slt i32 %34, 6
br i1 %35, label %36, label %45
36: ; preds = %33
%37 = load i16*, i16** %8
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i16, i16* %37, i64 %39
%41 = load i16, i16* %40
store volatile i16 %41, i16* inttoptr (i64 2690609280 to i16*)
br label %42
42: ; preds = %36
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %33
45: ; preds = %14, %31, %33
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
define i32 @ide_write_command_packet(i8* nocapture %0, i32 %1) {
%3 = bitcast i8* %0 to i16*
%4 = tail call i64 (...) @ide_wait_ready()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %28
6: ; preds = %2
%7 = trunc i32 %1 to i8
store volatile i8 %7, i8* inttoptr (i64 2690609284 to i8*)
store volatile i8 0, i8* inttoptr (i64 2690609288 to i8*)
store volatile i8 0, i8* inttoptr (i64 2690609292 to i8*)
store volatile i8 8, i8* inttoptr (i64 2690609296 to i8*)
store volatile i8 0, i8* inttoptr (i64 2690609300 to i8*)
store volatile i8 0, i8* inttoptr (i64 2690609304 to i8*)
store volatile i8 -96, i8* inttoptr (i64 2690609308 to i8*)
%8 = load volatile i8, i8* inttoptr (i64 2690609176 to i8*)
%9 = tail call i64 (...) @ide_wait_ready()
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %6
%12 = load i16, i16* %3
store volatile i16 %12, i16* inttoptr (i64 2690609280 to i16*)
%13 = getelementptr inbounds i8, i8* %0, i64 2
%14 = bitcast i8* %13 to i16*
%15 = load i16, i16* %14
store volatile i16 %15, i16* inttoptr (i64 2690609280 to i16*)
%16 = getelementptr inbounds i8, i8* %0, i64 4
%17 = bitcast i8* %16 to i16*
%18 = load i16, i16* %17
store volatile i16 %18, i16* inttoptr (i64 2690609280 to i16*)
%19 = getelementptr inbounds i8, i8* %0, i64 6
%20 = bitcast i8* %19 to i16*
%21 = load i16, i16* %20
store volatile i16 %21, i16* inttoptr (i64 2690609280 to i16*)
%22 = getelementptr inbounds i8, i8* %0, i64 8
%23 = bitcast i8* %22 to i16*
%24 = load i16, i16* %23
store volatile i16 %24, i16* inttoptr (i64 2690609280 to i16*)
%25 = getelementptr inbounds i8, i8* %0, i64 10
%26 = bitcast i8* %25 to i16*
%27 = load i16, i16* %26
store volatile i16 %27, i16* inttoptr (i64 2690609280 to i16*)
br label %28
28: ; preds = %11, %6, %2
ret i32 1
}