int sys_get_hd_info() {
  int i, drive;
  unsigned char cmos_disks;
  struct partition *p;
  int hd_nr = 0;
  if ((cmos_disks = ({
         __asm__("outb %%al,%%dx\n"
                 "\tjmp 1f\n"
                 "1:\tjmp 1f\n"
                 "1:" ::"a"(0x80 | 0x12),
                 "d"(0x70));
         ({
           unsigned char _v;
           __asm__ volatile("inb %%dx,%%al\n"
                            "\tjmp 1f\n"
                            "1:\tjmp 1f\n"
                            "1:"
                            : "=a"(_v)
                            : "d"(0x71));
           _v;
         });
       })) &
      0xf0) {
    if (cmos_disks & 0x0f)
      hd_nr = 2;
    else
      hd_nr = 1;
  } else {
    hd_nr = 0;
  }
  return hd_nr;
}


x86 assembly (clang, -O0):
<sys_get_hd_info>:
push   %rbp
mov    %rsp,%rbp
movl   $0x0,-0x1c(%rbp)
mov    $0x92,%eax
mov    $0x70,%edx
out    %al,(%dx)
jmp    111b <sys_get_hd_info+0x1b>
jmp    1120 <sys_get_hd_info+0x20>
mov    $0x71,%edx
in     (%dx),%al
jmp    112b <sys_get_hd_info+0x2b>
jmp    1130 <sys_get_hd_info+0x30>
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
mov    %al,-0x1f(%rbp)
mov    -0x1f(%rbp),%al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
mov    %al,-0x9(%rbp)
movzbl %al,%eax
and    $0xf0,%eax
cmp    $0x0,%eax
je     117e <sys_get_hd_info+0x7e>
movzbl -0x9(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
je     1172 <sys_get_hd_info+0x72>
movl   $0x2,-0x1c(%rbp)
jmp    1179 <sys_get_hd_info+0x79>
movl   $0x1,-0x1c(%rbp)
jmp    1185 <sys_get_hd_info+0x85>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_get_hd_info>:
mov    $0x92,%eax
mov    $0x70,%edx
out    %al,(%dx)
jmp    110d <sys_get_hd_info+0xd>
jmp    110f <sys_get_hd_info+0xf>
mov    $0x71,%edx
in     (%dx),%al
jmp    1117 <sys_get_hd_info+0x17>
jmp    1119 <sys_get_hd_info+0x19>
movzbl %al,%eax
mov    %eax,%ecx
and    $0xfffffff0,%ecx
and    $0xf,%eax
cmp    $0x1,%eax
mov    $0x2,%eax
sbb    $0x0,%eax
test   %ecx,%ecx
cmove  %ecx,%eax
ret

LLVM IR (-O0):
%struct.partition = type opaque
define i32 @sys_get_hd_info() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca %struct.partition*
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
store i32 0, i32* %5
%9 = call i8 asm sideeffect "inb %dx,%al\0A\09jmp 1f\0A1:\09jmp 1f\0A1:", "={ax},{dx},~{dirflag},~{fpsr},~{flags}"(i32 113)
store i8 %9, i8* %7
%10 = load i8, i8* %7
store i8 %10, i8* %8
%11 = load i8, i8* %8
store i8 %11, i8* %6
%12 = load i8, i8* %6
store i8 %12, i8* %3
%13 = zext i8 %12 to i32
%14 = and i32 %13, 240
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %0
%17 = load i8, i8* %3
%18 = zext i8 %17 to i32
%19 = and i32 %18, 15
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 2, i32* %5
br label %23
22: ; preds = %16
store i32 1, i32* %5
br label %23
23: ; preds = %22, %21
br label %25
24: ; preds = %0
store i32 0, i32* %5
br label %25
25: ; preds = %24, %23
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
%struct.partition = type opaque
define i32 @sys_get_hd_info() {
tail call void asm sideeffect "outb %al,%dx\0A\09jmp 1f\0A1:\09jmp 1f\0A1:", "{ax},{dx},~{dirflag},~{fpsr},~{flags}"(i32 146, i32 112)
%1 = tail call i8 asm sideeffect "inb %dx,%al\0A\09jmp 1f\0A1:\09jmp 1f\0A1:", "={ax},{dx},~{dirflag},~{fpsr},~{flags}"(i32 113)
%2 = zext i8 %1 to i32
%3 = and i32 %2, 240
%4 = icmp eq i32 %3, 0
%5 = and i32 %2, 15
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i32 1, i32 2
%8 = select i1 %4, i32 0, i32 %7
ret i32 %8
}