#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 */

/* Variables and functions */
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int fcntl(int /*<<< orphan*/, int /*<<< orphan*/, int);
scalar_t__ read(int /*<<< orphan*/, char *, int);
void mfm_drain_input() {
  char c;
  int fs = fcntl(0, F_GETFL, 0);
  fcntl(0, F_SETFL, fs | O_NONBLOCK);
  while (read(0, &c, 1) > 0)
    ;
  fcntl(0, F_SETFL, fs);
}


x86 assembly (clang, -O0):
<mfm_drain_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    %edx,%edi
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e98(%rip),%rax
or     (%rax),%edx
xor    %edi,%edi
call   1030 <fcntl@plt>
xor    %edi,%edi
lea    -0x1(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jle    1178 <mfm_drain_input+0x58>
jmp    1159 <mfm_drain_input+0x39>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
xor    %edi,%edi
call   1030 <fcntl@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mfm_drain_input>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,%ebp
mov    0x2e95(%rip),%r14
mov    (%r14),%esi
mov    0x2e9b(%rip),%rax
mov    %ebp,%edx
or     (%rax),%edx
xor    %edi,%edi
call   1030 <fcntl@plt>
lea    0xf(%rsp),%rbx
nopl   (%rax)
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %rax,%rax
jg     1160 <mfm_drain_input+0x40>
mov    (%r14),%esi
xor    %edi,%edi
mov    %ebp,%edx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fcntl@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define void @mfm_drain_input() {
%1 = alloca i8
%2 = alloca i32
%3 = load i32, i32* @F_GETFL
%4 = call i32 @fcntl(i32 0, i32 %3, i32 0)
store i32 %4, i32* %2
%5 = load i32, i32* @F_SETFL
%6 = load i32, i32* %2
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %6, %7
%9 = call i32 @fcntl(i32 0, i32 %5, i32 %8)
br label %10
10: ; preds = %13, %0
%11 = call i64 @read(i32 0, i8* %1, i32 1)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
br label %10
14: ; preds = %10
%15 = load i32, i32* @F_SETFL
%16 = load i32, i32* %2
%17 = call i32 @fcntl(i32 0, i32 %15, i32 %16)
ret void
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define void @mfm_drain_input() {
%1 = alloca i8
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 @fcntl(i32 0, i32 %2, i32 0)
%4 = load i32, i32* @F_SETFL
%5 = load i32, i32* @O_NONBLOCK
%6 = or i32 %5, %3
%7 = tail call i32 @fcntl(i32 0, i32 %4, i32 %6)
br label %8
8: ; preds = %8, %0
%9 = call i64 @read(i32 0, i8* %1, i32 1)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %8, label %11
11: ; preds = %8
%12 = load i32, i32* @F_SETFL
%13 = tail call i32 @fcntl(i32 0, i32 %12, i32 %3)
ret void
}