#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 */
struct floppy_controller {
  int dummy;
};

/* Variables and functions */
scalar_t__ floppy_controller_can_write_data_non_dma(struct floppy_controller *);
int /*<<< orphan*/ floppy_controller_read_status(struct floppy_controller *);
int /*<<< orphan*/ t8254_us2ticks(int);
int /*<<< orphan*/ t8254_wait(int /*<<< orphan*/);
int floppy_controller_wait_data_write_non_dma_ready(
    struct floppy_controller *fdc, unsigned int timeout) {
  do {
    floppy_controller_read_status(fdc);
    if (floppy_controller_can_write_data_non_dma(fdc))
      return 1;
    t8254_wait(t8254_us2ticks(1000));
  } while (--timeout != 0);
  return 0;
}


x86 assembly (clang, -O0):
<floppy_controller_wait_data_write_non_dma_ready>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <floppy_controller_read_status@plt>
mov    -0x10(%rbp),%rdi
call   1060 <floppy_controller_can_write_data_non_dma@plt>
cmp    $0x0,%rax
je     1177 <floppy_controller_wait_data_write_non_dma_ready+0x37>
movl   $0x1,-0x4(%rbp)
jmp    11a1 <floppy_controller_wait_data_write_non_dma_ready+0x61>
mov    $0x3e8,%edi
call   1030 <t8254_us2ticks@plt>
mov    %eax,%edi
call   1050 <t8254_wait@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    114f <floppy_controller_wait_data_write_non_dma_ready+0xf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<floppy_controller_wait_data_write_non_dma_ready>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <floppy_controller_read_status@plt>
mov    %r14,%rdi
call   1060 <floppy_controller_can_write_data_non_dma@plt>
test   %rax,%rax
jne    117f <floppy_controller_wait_data_write_non_dma_ready+0x3f>
mov    $0x3e8,%edi
call   1030 <t8254_us2ticks@plt>
mov    %eax,%edi
call   1050 <t8254_wait@plt>
add    $0xffffffff,%ebx
jne    1150 <floppy_controller_wait_data_write_non_dma_ready+0x10>
xor    %eax,%eax
jmp    1184 <floppy_controller_wait_data_write_non_dma_ready+0x44>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.floppy_controller = type { i32 }
define i32 @floppy_controller_wait_data_write_non_dma_ready(%struct.floppy_controller* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.floppy_controller*
%5 = alloca i32
store %struct.floppy_controller* %0, %struct.floppy_controller** %4
store i32 %1, i32* %5
br label %6
6: ; preds = %16, %2
%7 = load %struct.floppy_controller*, %struct.floppy_controller** %4
%8 = call i32 @floppy_controller_read_status(%struct.floppy_controller* %7)
%9 = load %struct.floppy_controller*, %struct.floppy_controller** %4
%10 = call i64 @floppy_controller_can_write_data_non_dma(%struct.floppy_controller* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %6
store i32 1, i32* %3
br label %21
13: ; preds = %6
%14 = call i32 @t8254_us2ticks(i32 1000)
%15 = call i32 @t8254_wait(i32 %14)
br label %16
16: ; preds = %13
%17 = load i32, i32* %5
%18 = add i32 %17, -1
store i32 %18, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %6, label %20
20: ; preds = %16
store i32 0, i32* %3
br label %21
21: ; preds = %20, %12
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.floppy_controller = type { i32 }
define i32 @floppy_controller_wait_data_write_non_dma_ready(%struct.floppy_controller* %0, i32 %1) {
br label %3
3: ; preds = %8, %2
%4 = phi i32 [ %1, %2 ], [ %11, %8 ]
%5 = tail call i32 @floppy_controller_read_status(%struct.floppy_controller* %0)
%6 = tail call i64 @floppy_controller_can_write_data_non_dma(%struct.floppy_controller* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = tail call i32 @t8254_us2ticks(i32 1000)
%10 = tail call i32 @t8254_wait(i32 %9)
%11 = add i32 %4, -1
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %3
13: ; preds = %8, %3
%14 = phi i32 [ 1, %3 ], [ 0, %8 ]
ret i32 %14
}