void read_lba48(unsigned int lba_low, unsigned int lba_high,
                unsigned short count, unsigned char *buf) {
  unsigned char c;
  unsigned int i0, i1;
  int i;
  outb(0x1f0 + 6, (1 << 6));
  outb(0x1f0 + 2, (count >> 8) & 0xff);
  outb(0x1f0 + 3, (lba_low >> 24) & 0xff);
  outb(0x1f0 + 4, lba_high & 0xff);
  outb(0x1f0 + 5, (lba_high >> 8) & 0xff);
  outb(0x1f0 + 2, count & 0xff);
  outb(0x1f0 + 3, lba_low & 0xff);
  outb(0x1f0 + 4, (lba_low >> 8) & 0xff);
  outb(0x1f0 + 5, (lba_low >> 16) & 0xff);
  outb(0x1f0 + 7, 0x24);
  for (i = 0; i < count; ++i) {
    (void)inb(0x3f6);
    (void)inb(0x3f6);
    (void)inb(0x3f6);
    (void)inb(0x3f6);
    do {
      c = inb(0x3f6);
      if ((c & (1 << 0)) || (c & (1 << 5)))
        break;
    } while ((c & (1 << 7)) && !(c & (1 << 3)));
    if ((c & (1 << 0)) || (c & (1 << 5)))
      print("ata: drive error\n");
    asm volatile("cld \n\t"
                 "rep insw"
                 : "=&D"(i0), "=&c"(i1)
                 : "0"(buf), "1"(256), "d"(0x1f0 + 0)
                 : "memory");
    buf += 512;
  }
}


x86 assembly (clang, -O0):
<read_lba48>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dx,%ax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %rcx,-0x18(%rbp)
mov    $0x1f6,%edi
mov    $0x40,%esi
mov    $0x0,%al
call   1030 <outb@plt>
movzwl -0xa(%rbp),%esi
sar    $0x8,%esi
and    $0xff,%esi
mov    $0x1f2,%edi
mov    $0x0,%al
call   1030 <outb@plt>
mov    -0x4(%rbp),%esi
shr    $0x18,%esi
and    $0xff,%esi
mov    $0x1f3,%edi
mov    $0x0,%al
call   1030 <outb@plt>
mov    -0x8(%rbp),%esi
and    $0xff,%esi
mov    $0x1f4,%edi
mov    $0x0,%al
call   1030 <outb@plt>
mov    -0x8(%rbp),%esi
shr    $0x8,%esi
and    $0xff,%esi
mov    $0x1f5,%edi
mov    $0x0,%al
call   1030 <outb@plt>
movzwl -0xa(%rbp),%esi
and    $0xff,%esi
mov    $0x1f2,%edi
mov    $0x0,%al
call   1030 <outb@plt>
mov    -0x4(%rbp),%esi
and    $0xff,%esi
mov    $0x1f3,%edi
mov    $0x0,%al
call   1030 <outb@plt>
mov    -0x4(%rbp),%esi
shr    $0x8,%esi
and    $0xff,%esi
mov    $0x1f4,%edi
mov    $0x0,%al
call   1030 <outb@plt>
mov    -0x4(%rbp),%esi
shr    $0x10,%esi
and    $0xff,%esi
mov    $0x1f5,%edi
mov    $0x0,%al
call   1030 <outb@plt>
mov    $0x1f7,%edi
mov    $0x24,%esi
mov    $0x0,%al
call   1030 <outb@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
movzwl -0xa(%rbp),%ecx
cmp    %ecx,%eax
jge    133c <read_lba48+0x20c>
mov    $0x3f6,%edi
mov    $0x0,%al
call   1050 <inb@plt>
mov    $0x3f6,%edi
mov    $0x0,%al
call   1050 <inb@plt>
mov    $0x3f6,%edi
mov    $0x0,%al
call   1050 <inb@plt>
mov    $0x3f6,%edi
mov    $0x0,%al
call   1050 <inb@plt>
mov    $0x3f6,%edi
mov    $0x0,%al
call   1050 <inb@plt>
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1299 <read_lba48+0x169>
movzbl -0x19(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     129e <read_lba48+0x16e>
jmp    12d8 <read_lba48+0x1a8>
jmp    12a3 <read_lba48+0x173>
movzbl -0x19(%rbp),%ecx
and    $0x80,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     12cd <read_lba48+0x19d>
movzbl -0x19(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    126a <read_lba48+0x13a>
movzbl -0x19(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    12f8 <read_lba48+0x1c8>
movzbl -0x19(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     1306 <read_lba48+0x1d6>
lea    0xd01(%rip),%rdi
mov    $0x0,%al
call   1040 <print@plt>
mov    -0x18(%rbp),%rdi
mov    $0x100,%ecx
mov    $0x1f0,%edx
cld
rep insw (%dx),%es:(%rdi)
mov    %edi,%eax
mov    %eax,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x18(%rbp),%rax
add    $0x200,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    122b <read_lba48+0xfb>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_lba48>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%r15d
mov    %esi,%r14d
mov    %edi,%ebp
mov    $0x1f6,%edi
mov    $0x40,%esi
xor    %eax,%eax
call   1030 <outb@plt>
mov    %r15d,%esi
shr    $0x8,%esi
mov    $0x1f2,%edi
xor    %eax,%eax
call   1030 <outb@plt>
mov    %ebp,%eax
shr    $0x18,%eax
mov    $0x1f3,%edi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <outb@plt>
movzbl %r14b,%esi
mov    $0x1f4,%edi
xor    %eax,%eax
call   1030 <outb@plt>
mov    %r14d,%eax
movzbl %ah,%esi
mov    $0x1f5,%edi
xor    %eax,%eax
call   1030 <outb@plt>
movzbl %r15b,%esi
mov    $0x1f2,%edi
xor    %eax,%eax
call   1030 <outb@plt>
movzbl %bpl,%esi
mov    $0x1f3,%edi
xor    %eax,%eax
call   1030 <outb@plt>
mov    %ebp,%eax
movzbl %ah,%esi
mov    $0x1f4,%edi
xor    %eax,%eax
call   1030 <outb@plt>
shr    $0x10,%ebp
movzbl %bpl,%esi
mov    $0x1f5,%edi
xor    %eax,%eax
call   1030 <outb@plt>
mov    $0x1f7,%edi
mov    $0x24,%esi
xor    %eax,%eax
call   1030 <outb@plt>
test   %r15d,%r15d
je     128c <read_lba48+0x15c>
lea    0xe01(%rip),%r14
xor    %ebp,%ebp
jmp    1230 <read_lba48+0x100>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1f0,%edx
mov    %rbx,%rdi
mov    $0x100,%ecx
cld
rep insw (%dx),%es:(%rdi)
add    $0x200,%rbx
add    $0x1,%ebp
cmp    %r15d,%ebp
je     128c <read_lba48+0x15c>
mov    $0x3f6,%edi
xor    %eax,%eax
call   1050 <inb@plt>
mov    $0x3f6,%edi
xor    %eax,%eax
call   1050 <inb@plt>
mov    $0x3f6,%edi
xor    %eax,%eax
call   1050 <inb@plt>
mov    $0x3f6,%edi
xor    %eax,%eax
call   1050 <inb@plt>
mov    $0x3f6,%edi
xor    %eax,%eax
call   1050 <inb@plt>
mov    %eax,%ecx
and    $0xa9,%ecx
cmp    $0x80,%ecx
je     1260 <read_lba48+0x130>
test   $0x21,%al
je     1210 <read_lba48+0xe0>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <print@plt>
jmp    1210 <read_lba48+0xe0>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"ata: drive error\0A\00"
define void @read_lba48(i32 %0, i32 %1, i16 zeroext %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i16
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i16 %2, i16* %7
store i8* %3, i8** %8
%13 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 502, i32 64)
%14 = load i16, i16* %7
%15 = zext i16 %14 to i32
%16 = ashr i32 %15, 8
%17 = and i32 %16, 255
%18 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 498, i32 %17)
%19 = load i32, i32* %5
%20 = lshr i32 %19, 24
%21 = and i32 %20, 255
%22 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 499, i32 %21)
%23 = load i32, i32* %6
%24 = and i32 %23, 255
%25 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 500, i32 %24)
%26 = load i32, i32* %6
%27 = lshr i32 %26, 8
%28 = and i32 %27, 255
%29 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 501, i32 %28)
%30 = load i16, i16* %7
%31 = zext i16 %30 to i32
%32 = and i32 %31, 255
%33 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 498, i32 %32)
%34 = load i32, i32* %5
%35 = and i32 %34, 255
%36 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 499, i32 %35)
%37 = load i32, i32* %5
%38 = lshr i32 %37, 8
%39 = and i32 %38, 255
%40 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 500, i32 %39)
%41 = load i32, i32* %5
%42 = lshr i32 %41, 16
%43 = and i32 %42, 255
%44 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 501, i32 %43)
%45 = call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 503, i32 36)
store i32 0, i32* %12
br label %46
46: ; preds = %104, %4
%47 = load i32, i32* %12
%48 = load i16, i16* %7
%49 = zext i16 %48 to i32
%50 = icmp slt i32 %47, %49
br i1 %50, label %51, label %107
51: ; preds = %46
%52 = call i32 (i32, ...) bitcast (i32 (...)* @inb to i32 (i32, ...)*)(i32 1014)
%53 = call i32 (i32, ...) bitcast (i32 (...)* @inb to i32 (i32, ...)*)(i32 1014)
%54 = call i32 (i32, ...) bitcast (i32 (...)* @inb to i32 (i32, ...)*)(i32 1014)
%55 = call i32 (i32, ...) bitcast (i32 (...)* @inb to i32 (i32, ...)*)(i32 1014)
br label %56
56: ; preds = %81, %51
%57 = call i32 (i32, ...) bitcast (i32 (...)* @inb to i32 (i32, ...)*)(i32 1014)
%58 = trunc i32 %57 to i8
store i8 %58, i8* %9
%59 = load i8, i8* %9
%60 = zext i8 %59 to i32
%61 = and i32 %60, 1
%62 = icmp ne i32 %61, 0
br i1 %62, label %68, label %63
63: ; preds = %56
%64 = load i8, i8* %9
%65 = zext i8 %64 to i32
%66 = and i32 %65, 32
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %69
68: ; preds = %63, %56
br label %83
69: ; preds = %63
br label %70
70: ; preds = %69
%71 = load i8, i8* %9
%72 = zext i8 %71 to i32
%73 = and i32 %72, 128
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %81
75: ; preds = %70
%76 = load i8, i8* %9
%77 = zext i8 %76 to i32
%78 = and i32 %77, 8
%79 = icmp ne i32 %78, 0
%80 = xor i1 %79, true
br label %81
81: ; preds = %75, %70
%82 = phi i1 [ false, %70 ], [ %80, %75 ]
br i1 %82, label %56, label %83
83: ; preds = %81, %68
%84 = load i8, i8* %9
%85 = zext i8 %84 to i32
%86 = and i32 %85, 1
%87 = icmp ne i32 %86, 0
br i1 %87, label %93, label %88
88: ; preds = %83
%89 = load i8, i8* %9
%90 = zext i8 %89 to i32
%91 = and i32 %90, 32
%92 = icmp ne i32 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %88, %83
%94 = call i32 (i8*, ...) bitcast (i32 (...)* @print to i32 (i8*, ...)*)(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %95
95: ; preds = %93, %88
%96 = load i8*, i8** %8
%97 = call { i8*, i32 } asm sideeffect "cld \0A\09rep insw", "=&{di},=&{cx},0,1,{dx},~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %96, i32 256, i32 496)
%98 = extractvalue { i8*, i32 } %97, 0
%99 = extractvalue { i8*, i32 } %97, 1
%100 = ptrtoint i8* %98 to i64
%101 = trunc i64 %100 to i32
store i32 %101, i32* %10
store i32 %99, i32* %11
%102 = load i8*, i8** %8
%103 = getelementptr inbounds i8, i8* %102, i64 512
store i8* %103, i8** %8
br label %104
104: ; preds = %95
%105 = load i32, i32* %12
%106 = add nsw i32 %105, 1
store i32 %106, i32* %12
br label %46
107: ; preds = %46
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"ata: drive error\0A\00"
define void @read_lba48(i32 %0, i32 %1, i16 zeroext %2, i8* %3) {
%5 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 502, i32 64)
%6 = zext i16 %2 to i32
%7 = lshr i32 %6, 8
%8 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 498, i32 %7)
%9 = lshr i32 %0, 24
%10 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 499, i32 %9)
%11 = and i32 %1, 255
%12 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 500, i32 %11)
%13 = lshr i32 %1, 8
%14 = and i32 %13, 255
%15 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 501, i32 %14)
%16 = and i32 %6, 255
%17 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 498, i32 %16)
%18 = and i32 %0, 255
%19 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 499, i32 %18)
%20 = lshr i32 %0, 8
%21 = and i32 %20, 255
%22 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 500, i32 %21)
%23 = lshr i32 %0, 16
%24 = and i32 %23, 255
%25 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 501, i32 %24)
%26 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @outb to i32 (i32, i32, ...)*)(i32 503, i32 36)
%27 = icmp eq i16 %2, 0
br i1 %27, label %49, label %28
28: ; preds = %4, %44
%29 = phi i32 [ %47, %44 ], [ 0, %4 ]
%30 = phi i8* [ %46, %44 ], [ %3, %4 ]
%31 = tail call i32 (i32, ...) bitcast (i32 (...)* @inb to i32 (i32, ...)*)(i32 1014)
%32 = tail call i32 (i32, ...) bitcast (i32 (...)* @inb to i32 (i32, ...)*)(i32 1014)
%33 = tail call i32 (i32, ...) bitcast (i32 (...)* @inb to i32 (i32, ...)*)(i32 1014)
%34 = tail call i32 (i32, ...) bitcast (i32 (...)* @inb to i32 (i32, ...)*)(i32 1014)
br label %35
35: ; preds = %35, %28
%36 = tail call i32 (i32, ...) bitcast (i32 (...)* @inb to i32 (i32, ...)*)(i32 1014)
%37 = and i32 %36, 169
%38 = icmp eq i32 %37, 128
br i1 %38, label %35, label %39
39: ; preds = %35
%40 = and i32 %36, 33
%41 = icmp eq i32 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %39
%43 = tail call i32 (i8*, ...) bitcast (i32 (...)* @print to i32 (i8*, ...)*)(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %44
44: ; preds = %39, %42
%45 = tail call { i8*, i32 } asm sideeffect "cld \0A\09rep insw", "=&{di},=&{cx},0,1,{dx},~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %30, i32 256, i32 496)
%46 = getelementptr inbounds i8, i8* %30, i64 512
%47 = add nuw nsw i32 %29, 1
%48 = icmp eq i32 %47, %6
br i1 %48, label %49, label %28
49: ; preds = %44, %4
ret void
}