int is_drv_busy(void) {
  unsigned int i;
  for (i = 0; i < 10000; i++) {
    if (0x40 == (({
                   unsigned char _v;
                   __asm__ volatile("inb %%dx,%%al\n"
                                    "\tjmp 1f\n"
                                    "1:\tjmp 1f\n"
                                    "1:"
                                    : "=a"(_v)
                                    : "d"(0x1f7));
                   _v;
                 }) &
                 (0x80 | 0x40)))
      break;
  }
  i = ({
    unsigned char _v;
    __asm__ volatile("inb %%dx, %%al" : "=a"(_v) : "d"(0x1f7));
    _v;
  });
  i &= 0x80 | 0x40 | 0x10;
  if (i == 0x40 | 0x10)
    return (0);
  printf("HD controller times out\n\r");
  return (1);
}


x86 assembly (clang, -O0):
<is_drv_busy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
cmpl   $0x2710,-0x8(%rbp)
jae    1174 <is_drv_busy+0x64>
mov    $0x1f7,%edx
in     (%dx),%al
jmp    1137 <is_drv_busy+0x27>
jmp    113c <is_drv_busy+0x2c>
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0xa(%rbp)
movzbl -0xa(%rbp),%ecx
and    $0xc0,%ecx
mov    $0x40,%eax
cmp    %ecx,%eax
jne    1161 <is_drv_busy+0x51>
jmp    1174 <is_drv_busy+0x64>
jmp    1166 <is_drv_busy+0x56>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    111f <is_drv_busy+0xf>
mov    $0x1f7,%edx
in     (%dx),%al
mov    %al,-0xb(%rbp)
mov    -0xb(%rbp),%al
mov    %al,-0xc(%rbp)
movzbl -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xd0,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x40,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
or     $0x10,%eax
cmp    $0x0,%eax
je     11b9 <is_drv_busy+0xa9>
movl   $0x0,-0x4(%rbp)
jmp    11ce <is_drv_busy+0xbe>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_drv_busy>:
mov    $0x270f,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1f7,%edx
in     (%dx),%al
jmp    1118 <is_drv_busy+0x18>
jmp    111a <is_drv_busy+0x1a>
and    $0xc0,%al
sub    $0x1,%ecx
setb   %dl
cmp    $0x40,%al
je     112a <is_drv_busy+0x2a>
test   %dl,%dl
je     1110 <is_drv_busy+0x10>
mov    $0x1f7,%edx
in     (%dx),%al
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [26 x i8] c"HD controller times out\0A\0D\00"
define i32 @is_drv_busy() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
store i32 0, i32* %2
br label %7
7: ; preds = %19, %0
%8 = load i32, i32* %2
%9 = icmp ult i32 %8, 10000
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = call i8 asm sideeffect "inb %dx,%al\0A\09jmp 1f\0A1:\09jmp 1f\0A1:", "={ax},{dx},~{dirflag},~{fpsr},~{flags}"(i32 503)
store i8 %11, i8* %3
%12 = load i8, i8* %3
store i8 %12, i8* %4
%13 = load i8, i8* %4
%14 = zext i8 %13 to i32
%15 = and i32 %14, 192
%16 = icmp eq i32 64, %15
br i1 %16, label %17, label %18
17: ; preds = %10
br label %22
18: ; preds = %10
br label %19
19: ; preds = %18
%20 = load i32, i32* %2
%21 = add i32 %20, 1
store i32 %21, i32* %2
br label %7
22: ; preds = %17, %7
%23 = call i8 asm sideeffect "inb %dx, %al", "={ax},{dx},~{dirflag},~{fpsr},~{flags}"(i32 503)
store i8 %23, i8* %5
%24 = load i8, i8* %5
store i8 %24, i8* %6
%25 = load i8, i8* %6
%26 = zext i8 %25 to i32
store i32 %26, i32* %2
%27 = load i32, i32* %2
%28 = and i32 %27, 208
store i32 %28, i32* %2
%29 = load i32, i32* %2
%30 = icmp eq i32 %29, 64
%31 = zext i1 %30 to i32
%32 = or i32 %31, 16
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %22
store i32 0, i32* %1
br label %37
35: ; preds = %22
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %37
37: ; preds = %35, %34
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
define i32 @is_drv_busy() {
br label %1
1: ; preds = %1, %0
%2 = phi i32 [ 0, %0 ], [ %6, %1 ]
%3 = tail call i8 asm sideeffect "inb %dx,%al\0A\09jmp 1f\0A1:\09jmp 1f\0A1:", "={ax},{dx},~{dirflag},~{fpsr},~{flags}"(i32 503)
%4 = and i8 %3, -64
%5 = icmp eq i8 %4, 64
%6 = add nuw nsw i32 %2, 1
%7 = icmp eq i32 %6, 10000
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %9, label %1
9: ; preds = %1
%10 = tail call i8 asm sideeffect "inb %dx, %al", "={ax},{dx},~{dirflag},~{fpsr},~{flags}"(i32 503)
ret i32 0
}