int main() {
  unsigned char status_reg = 0, error_reg = 1;
  char ptr[512] = {0};
  printf("%x\n", get_drive_head(0, 0));
  printf("%x\n", test(0xAB));
  printf("%x\n", test1(0xBA));
  printf("%x\n", test2(0xCA));
  printf("ptr=%x %x\n", ptr, pio_read(0xA, 0xB, 0xC, 0xD, ptr));
  printf("%x\n", 0xC + 0x4);
  printf("%x\n", 0x10 + 0x4);
  status_reg = 1;
  if (status_check(0, error_reg, status_reg) == 0) {
    printf("status_check:: no error\n");
  }
  if (bit_test(status_reg) == 1) {
    printf("bit_test:: error\n");
  } else {
    printf("bit_test:: no error\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
movb   $0x1,-0x6(%rbp)
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
xor    %esi,%esi
mov    %esi,%edi
mov    $0x0,%al
call   1060 <get_drive_head@plt>
mov    %eax,%esi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xab,%edi
mov    $0x0,%al
call   10b0 <test@plt>
mov    %eax,%esi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xba,%edi
mov    $0x0,%al
call   1030 <test1@plt>
mov    %eax,%esi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xca,%edi
mov    $0x0,%al
call   1070 <test2@plt>
mov    %eax,%esi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x218(%rbp)
lea    -0x210(%rbp),%r8
mov    $0xa,%edi
mov    $0xb,%esi
mov    $0xc,%edx
mov    $0xd,%ecx
mov    $0x0,%al
call   1090 <pio_read@plt>
mov    -0x218(%rbp),%rsi
mov    %eax,%edx
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd8d(%rip),%rdi
mov    $0x10,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd7a(%rip),%rdi
mov    $0x14,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x1,-0x5(%rbp)
movzbl -0x6(%rbp),%esi
movzbl -0x5(%rbp),%edx
xor    %edi,%edi
mov    $0x0,%al
call   10a0 <status_check@plt>
cmp    $0x0,%eax
jne    12c5 <main+0x135>
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movzbl -0x5(%rbp),%edi
mov    $0x0,%al
call   1080 <bit_test@plt>
cmp    $0x1,%eax
jne    12ec <main+0x15c>
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12fa <main+0x16a>
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsp,%r14
mov    $0x200,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
xor    %edi,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1070 <get_drive_head@plt>
lea    0xe39(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xab,%edi
xor    %eax,%eax
call   10c0 <test@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xba,%edi
xor    %eax,%eax
call   1040 <test1@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xca,%edi
xor    %eax,%eax
call   1080 <test2@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
mov    $0xb,%esi
mov    $0xc,%edx
mov    $0xd,%ecx
mov    %r14,%r8
xor    %eax,%eax
call   10a0 <pio_read@plt>
lea    0xdb9(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
mov    $0x1,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   10b0 <status_check@plt>
test   %eax,%eax
jne    1294 <main+0xf4>
lea    0xda1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
xor    %eax,%eax
call   1090 <bit_test@plt>
cmp    $0x1,%eax
lea    0xd75(%rip),%rax
lea    0xd5a(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%x\0A\00"
@.str.1 = [11 x i8] c"ptr=%x %x\0A\00"
@.str.2 = [25 x i8] c"status_check:: no error\0A\00"
@.str.3 = [18 x i8] c"bit_test:: error\0A\00"
@.str.4 = [21 x i8] c"bit_test:: no error\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
%4 = alloca [512 x i8]
store i32 0, i32* %1
store i8 0, i8* %2
store i8 1, i8* %3
%5 = bitcast [512 x i8]* %4 to i8*
%6 = call i32 (i32, i32, ...) bitcast (i32 (...)* @get_drive_head to i32 (i32, i32, ...)*)(i32 0, i32 0)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 (i32, ...) bitcast (i32 (...)* @test to i32 (i32, ...)*)(i32 171)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 (i32, ...) bitcast (i32 (...)* @test1 to i32 (i32, ...)*)(i32 186)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 (i32, ...) bitcast (i32 (...)* @test2 to i32 (i32, ...)*)(i32 202)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%16 = call i32 (i32, i32, i32, i32, i8*, ...) bitcast (i32 (...)* @pio_read to i32 (i32, i32, i32, i32, i8*, ...)*)(i32 10, i32 11, i32 12, i32 13, i8* %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 16)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 20)
store i8 1, i8* %2
%20 = load i8, i8* %3
%21 = zext i8 %20 to i32
%22 = load i8, i8* %2
%23 = zext i8 %22 to i32
%24 = call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @status_check to i32 (i32, i32, i32, ...)*)(i32 0, i32 %21, i32 %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %0
%29 = load i8, i8* %2
%30 = zext i8 %29 to i32
%31 = call i32 (i32, ...) bitcast (i32 (...)* @bit_test to i32 (i32, ...)*)(i32 %30)
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %37
35: ; preds = %28
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %37
37: ; preds = %35, %33
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%x\0A\00"
@.str.1 = [11 x i8] c"ptr=%x %x\0A\00"
@str = [20 x i8] c"bit_test:: no error\00"
@str.5 = [17 x i8] c"bit_test:: error\00"
@str.6 = [24 x i8] c"status_check:: no error\00"
define i32 @main() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @get_drive_head to i32 (i32, i32, ...)*)(i32 0, i32 0)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 (i32, ...) bitcast (i32 (...)* @test to i32 (i32, ...)*)(i32 171)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 (i32, ...) bitcast (i32 (...)* @test1 to i32 (i32, ...)*)(i32 186)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 (i32, ...) bitcast (i32 (...)* @test2 to i32 (i32, ...)*)(i32 202)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 (i32, i32, i32, i32, i8*, ...) bitcast (i32 (...)* @pio_read to i32 (i32, i32, i32, i32, i8*, ...)*)(i32 10, i32 11, i32 12, i32 13, i8* %2)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 16)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 20)
%15 = call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @status_check to i32 (i32, i32, i32, ...)*)(i32 0, i32 1, i32 1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.6, i64 0, i64 0))
br label %19
19: ; preds = %17, %0
%20 = call i32 (i32, ...) bitcast (i32 (...)* @bit_test to i32 (i32, ...)*)(i32 1)
%21 = icmp eq i32 %20, 1
%22 = select i1 %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0)
%23 = call i32 @puts(i8* dereferenceable(1) %22)
ret i32 0
}