#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 /*<<< orphan*/ ata_wait_for_rdy();
int ata_spindown(int time) {
  (*((volatile unsigned short *)0x05FFFFC4)) |= 0x0280;
  (*((volatile unsigned short *)0x05FFFFC0)) |= 0x0200;
  (*((volatile unsigned short *)0x05FFFFCA)) &= 0xBFFF;
  (*((volatile unsigned short *)0x05FFFFC0)) &= ~0x80;
  if (!ata_wait_for_rdy())
    return -1;
  if (time == -1) {
    (*((volatile unsigned char *)0x06100107)) = 0xE0;
  } else {
    if (time > 255)
      return -1;
    (*((volatile unsigned char *)0x06100102)) = time & 0xff;
    (*((volatile unsigned char *)0x06100107)) = 0xE2;
  }
  if (!ata_wait_for_rdy())
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<ata_spindown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x5ffffc4,%eax
mov    (%rax),%ax
movzwl %ax,%eax
or     $0x280,%eax
mov    %ax,%cx
mov    $0x5ffffc4,%eax
mov    %cx,(%rax)
mov    $0x5ffffc0,%eax
mov    (%rax),%ax
movzwl %ax,%eax
or     $0x200,%eax
mov    %ax,%cx
mov    $0x5ffffc0,%eax
mov    %cx,(%rax)
mov    $0x5ffffca,%eax
mov    (%rax),%ax
movzwl %ax,%eax
and    $0xbfff,%eax
mov    %ax,%cx
mov    $0x5ffffca,%eax
mov    %cx,(%rax)
mov    $0x5ffffc0,%eax
mov    (%rax),%ax
movzwl %ax,%eax
and    $0xffffff7f,%eax
mov    %ax,%cx
mov    $0x5ffffc0,%eax
mov    %cx,(%rax)
mov    $0x0,%al
call   1030 <ata_wait_for_rdy@plt>
cmp    $0x0,%eax
jne    11a3 <ata_spindown+0x93>
movl   $0xffffffff,-0x4(%rbp)
jmp    120f <ata_spindown+0xff>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11ba <ata_spindown+0xaa>
mov    $0x6100107,%eax
movb   $0xe0,(%rax)
jmp    11ec <ata_spindown+0xdc>
cmpl   $0xff,-0x8(%rbp)
jle    11d3 <ata_spindown+0xc3>
movl   $0xffffffff,-0x4(%rbp)
jmp    120f <ata_spindown+0xff>
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    $0x6100102,%eax
mov    %cl,(%rax)
mov    $0x6100107,%eax
movb   $0xe2,(%rax)
mov    $0x0,%al
call   1030 <ata_wait_for_rdy@plt>
cmp    $0x0,%eax
jne    1208 <ata_spindown+0xf8>
movl   $0xffffffff,-0x4(%rbp)
jmp    120f <ata_spindown+0xff>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ata_spindown>:
push   %rbx
orw    $0x280,0x5ffffc4
05 80 02
orw    $0x200,0x5ffffc0
andw   $0xbfff,0x5ffffca
05 ff bf
mov    %edi,%ebx
andw   $0xff7f,0x5ffffc0
05 7f ff
xor    %eax,%eax
call   1030 <ata_wait_for_rdy@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
je     117a <ata_spindown+0x6a>
cmp    $0xffffffff,%ebx
je     1165 <ata_spindown+0x55>
cmp    $0xff,%ebx
jg     117a <ata_spindown+0x6a>
mov    %bl,0x6100102
mov    $0xe2,%al
jmp    1167 <ata_spindown+0x57>
mov    $0xe0,%al
mov    %al,0x6100107
xor    %eax,%eax
call   1030 <ata_wait_for_rdy@plt>
cmp    $0x1,%eax
sbb    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @ata_spindown(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load volatile i16, i16* inttoptr (i64 100663236 to i16*)
%5 = zext i16 %4 to i32
%6 = or i32 %5, 640
%7 = trunc i32 %6 to i16
store volatile i16 %7, i16* inttoptr (i64 100663236 to i16*)
%8 = load volatile i16, i16* inttoptr (i64 100663232 to i16*)
%9 = zext i16 %8 to i32
%10 = or i32 %9, 512
%11 = trunc i32 %10 to i16
store volatile i16 %11, i16* inttoptr (i64 100663232 to i16*)
%12 = load volatile i16, i16* inttoptr (i64 100663242 to i16*)
%13 = zext i16 %12 to i32
%14 = and i32 %13, 49151
%15 = trunc i32 %14 to i16
store volatile i16 %15, i16* inttoptr (i64 100663242 to i16*)
%16 = load volatile i16, i16* inttoptr (i64 100663232 to i16*)
%17 = zext i16 %16 to i32
%18 = and i32 %17, -129
%19 = trunc i32 %18 to i16
store volatile i16 %19, i16* inttoptr (i64 100663232 to i16*)
%20 = call i32 (...) @ata_wait_for_rdy()
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %1
store i32 -1, i32* %2
br label %40
23: ; preds = %1
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %23
store volatile i8 -32, i8* inttoptr (i64 101712135 to i8*)
br label %35
27: ; preds = %23
%28 = load i32, i32* %3
%29 = icmp sgt i32 %28, 255
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 -1, i32* %2
br label %40
31: ; preds = %27
%32 = load i32, i32* %3
%33 = and i32 %32, 255
%34 = trunc i32 %33 to i8
store volatile i8 %34, i8* inttoptr (i64 101712130 to i8*)
store volatile i8 -30, i8* inttoptr (i64 101712135 to i8*)
br label %35
35: ; preds = %31, %26
%36 = call i32 (...) @ata_wait_for_rdy()
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %35
store i32 -1, i32* %2
br label %40
39: ; preds = %35
store i32 0, i32* %2
br label %40
40: ; preds = %39, %38, %30, %22
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
define i32 @ata_spindown(i32 %0) {
%2 = load volatile i16, i16* inttoptr (i64 100663236 to i16*)
%3 = or i16 %2, 640
store volatile i16 %3, i16* inttoptr (i64 100663236 to i16*)
%4 = load volatile i16, i16* inttoptr (i64 100663232 to i16*)
%5 = or i16 %4, 512
store volatile i16 %5, i16* inttoptr (i64 100663232 to i16*)
%6 = load volatile i16, i16* inttoptr (i64 100663242 to i16*)
%7 = and i16 %6, -16385
store volatile i16 %7, i16* inttoptr (i64 100663242 to i16*)
%8 = load volatile i16, i16* inttoptr (i64 100663232 to i16*)
%9 = and i16 %8, -129
store volatile i16 %9, i16* inttoptr (i64 100663232 to i16*)
%10 = tail call i32 (...) @ata_wait_for_rdy()
%11 = icmp eq i32 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %1
%13 = icmp eq i32 %0, -1
br i1 %13, label %18, label %14
14: ; preds = %12
%15 = icmp sgt i32 %0, 255
br i1 %15, label %23, label %16
16: ; preds = %14
%17 = trunc i32 %0 to i8
store volatile i8 %17, i8* inttoptr (i64 101712130 to i8*)
br label %18
18: ; preds = %12, %16
%19 = phi i8 [ -30, %16 ], [ -32, %12 ]
store volatile i8 %19, i8* inttoptr (i64 101712135 to i8*)
%20 = tail call i32 (...) @ata_wait_for_rdy()
%21 = icmp eq i32 %20, 0
%22 = sext i1 %21 to i32
br label %23
23: ; preds = %18, %14, %1
%24 = phi i32 [ -1, %1 ], [ -1, %14 ], [ %22, %18 ]
ret i32 %24
}