#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint8_t;
typedef scalar_t__ uint16_t;

/* Variables and functions */
int inp(int);
int /*<<< orphan*/ outp(int, int);
int read_byte(int, scalar_t__);
int /*<<< orphan*/ write_byte(int, scalar_t__, int);
void floppy_reset_controller(uint16_t drive) {
  uint8_t val8;
  val8 = inp(0x03f2);
  outp(0x03f2, val8 & ~0x04);
  outp(0x03f2, val8 | 0x04);
  do {
    val8 = inp(0x3f4);
  } while ((val8 & 0xc0) != 0x80);
  val8 = read_byte(0x0040, 0x0090 + drive);
  val8 &= ~0x10;
  write_byte(0x0040, 0x90 + drive, val8);
}


x86 assembly (clang, -O0):
<floppy_reset_controller>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x3f2,%edi
call   1050 <inp@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
and    $0xfffffffb,%esi
mov    $0x3f2,%edi
call   1040 <outp@plt>
mov    -0xc(%rbp),%esi
or     $0x4,%esi
mov    $0x3f2,%edi
call   1040 <outp@plt>
mov    $0x3f4,%edi
call   1050 <inp@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
jne    1179 <floppy_reset_controller+0x39>
mov    -0x8(%rbp),%rsi
add    $0x90,%rsi
mov    $0x40,%edi
call   1030 <read_byte@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xffffffef,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
add    $0x90,%rsi
mov    -0xc(%rbp),%edx
mov    $0x40,%edi
call   1060 <write_byte@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<floppy_reset_controller>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x3f2,%edi
call   1050 <inp@plt>
mov    %eax,%ebp
mov    %eax,%esi
and    $0xfffffffb,%esi
mov    $0x3f2,%edi
call   1040 <outp@plt>
or     $0x4,%ebp
mov    $0x3f2,%edi
mov    %ebp,%esi
call   1040 <outp@plt>
mov    $0x3f4,%edi
call   1050 <inp@plt>
and    $0xc0,%eax
cmp    $0x80,%eax
jne    1170 <floppy_reset_controller+0x30>
add    $0x90,%rbx
mov    $0x40,%edi
mov    %rbx,%rsi
call   1030 <read_byte@plt>
and    $0xffffffef,%eax
mov    $0x40,%edi
mov    %rbx,%rsi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <write_byte@plt>

LLVM IR (-O0):
define void @floppy_reset_controller(i64 %0) {
%2 = alloca i64
%3 = alloca i32
store i64 %0, i64* %2
%4 = call i32 @inp(i32 1010)
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = and i32 %5, -5
%7 = call i32 @outp(i32 1010, i32 %6)
%8 = load i32, i32* %3
%9 = or i32 %8, 4
%10 = call i32 @outp(i32 1010, i32 %9)
br label %11
11: ; preds = %13, %1
%12 = call i32 @inp(i32 1012)
store i32 %12, i32* %3
br label %13
13: ; preds = %11
%14 = load i32, i32* %3
%15 = and i32 %14, 192
%16 = icmp ne i32 %15, 128
br i1 %16, label %11, label %17
17: ; preds = %13
%18 = load i64, i64* %2
%19 = add nsw i64 144, %18
%20 = call i32 @read_byte(i32 64, i64 %19)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = and i32 %21, -17
store i32 %22, i32* %3
%23 = load i64, i64* %2
%24 = add nsw i64 144, %23
%25 = load i32, i32* %3
%26 = call i32 @write_byte(i32 64, i64 %24, i32 %25)
ret void
}

LLVM IR (-O2):
define void @floppy_reset_controller(i64 %0) {
%2 = tail call i32 @inp(i32 1010)
%3 = and i32 %2, -5
%4 = tail call i32 @outp(i32 1010, i32 %3)
%5 = or i32 %2, 4
%6 = tail call i32 @outp(i32 1010, i32 %5)
br label %7
7: ; preds = %7, %1
%8 = tail call i32 @inp(i32 1012)
%9 = and i32 %8, 192
%10 = icmp eq i32 %9, 128
br i1 %10, label %11, label %7
11: ; preds = %7
%12 = add nsw i64 %0, 144
%13 = tail call i32 @read_byte(i32 64, i64 %12)
%14 = and i32 %13, -17
%15 = tail call i32 @write_byte(i32 64, i64 %12, i32 %14)
ret void
}