void get_drive_parameters(int drive_no, int *num_heads, int *num_sectors) {
  unsigned int dx, cx;
  unsigned char carry_flag;
  __asm__ __volatile__("mov %0, %%es" : : "r"(0));
  __asm__ __volatile__("int $0x13\n"
                       "setc %0"
                       : "=r"(carry_flag), "=d"(dx), "=c"(cx)
                       : "a"(0x0800), "1"(drive_no), "D"(0));
  *num_heads = ((dx >> 8) & 0xFF) + 1;
  *num_sectors = cx & 0x3F;
  if (carry_flag) {
    print("Could not get drive parameters");
    forever_hlt();
  }
}


x86 assembly (clang, -O0):
<get_drive_parameters>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%es
mov    -0x4(%rbp),%edx
mov    $0x800,%eax
xor    %edi,%edi
int    $0x13
setb   %al
mov    %al,-0x21(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x1c(%rbp),%ecx
shr    $0x8,%ecx
and    $0xff,%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%ecx
and    $0x3f,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpb   $0x0,-0x21(%rbp)
je     118f <get_drive_parameters+0x6f>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <print@plt>
mov    $0x0,%al
call   1040 <forever_hlt@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_drive_parameters>:
push   %rax
mov    %rdx,%r8
mov    %edi,%edx
xor    %eax,%eax
mov    %eax,%es
mov    $0x800,%eax
xor    %edi,%edi
int    $0x13
setb   %al
movzbl %dh,%edx
add    $0x1,%edx
mov    %edx,(%rsi)
and    $0x3f,%ecx
mov    %ecx,(%r8)
test   %al,%al
je     115e <get_drive_parameters+0x3e>
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
call   1030 <print@plt>
xor    %eax,%eax
pop    %rcx
jmp    1040 <forever_hlt@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Could not get drive parameters\00"
define void @get_drive_parameters(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%10 = load i32, i32* %4
%11 = call { i8, i32, i32 } asm sideeffect "int $$0x13\0Asetc $0", "=r,={dx},={cx},{ax},1,{di},~{dirflag},~{fpsr},~{flags}"(i32 2048, i32 %10, i32 0)
%12 = extractvalue { i8, i32, i32 } %11, 0
%13 = extractvalue { i8, i32, i32 } %11, 1
%14 = extractvalue { i8, i32, i32 } %11, 2
store i8 %12, i8* %9
store i32 %13, i32* %7
store i32 %14, i32* %8
%15 = load i32, i32* %7
%16 = lshr i32 %15, 8
%17 = and i32 %16, 255
%18 = add i32 %17, 1
%19 = load i32*, i32** %5
store i32 %18, i32* %19
%20 = load i32, i32* %8
%21 = and i32 %20, 63
%22 = load i32*, i32** %6
store i32 %21, i32* %22
%23 = load i8, i8* %9
%24 = icmp ne i8 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %3
%26 = call i32 (i8*, ...) bitcast (i32 (...)* @print to i32 (i8*, ...)*)(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%27 = call i32 (...) @forever_hlt()
br label %28
28: ; preds = %25, %3
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"Could not get drive parameters\00"
define void @get_drive_parameters(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
tail call void asm sideeffect "mov $0, %es", "r,~{dirflag},~{fpsr},~{flags}"(i32 0)
%4 = tail call { i8, i32, i32 } asm sideeffect "int $$0x13\0Asetc $0", "=r,={dx},={cx},{ax},1,{di},~{dirflag},~{fpsr},~{flags}"(i32 2048, i32 %0, i32 0)
%5 = extractvalue { i8, i32, i32 } %4, 0
%6 = extractvalue { i8, i32, i32 } %4, 1
%7 = extractvalue { i8, i32, i32 } %4, 2
%8 = lshr i32 %6, 8
%9 = and i32 %8, 255
%10 = add nuw nsw i32 %9, 1
store i32 %10, i32* %1
%11 = and i32 %7, 63
store i32 %11, i32* %2
%12 = icmp eq i8 %5, 0
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = tail call i32 (i8*, ...) bitcast (i32 (...)* @print to i32 (i8*, ...)*)(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 (...) @forever_hlt()
br label %16
16: ; preds = %13, %3
ret void
}