#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*/ FIONREAD;
int /*<<< orphan*/ ioctl(int /*<<< orphan*/, int /*<<< orphan*/, int *);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
void flushall(void) {
  char cc;
  int ic;
  for (;;) {
    ioctl(0, FIONREAD, &ic);
    if (ic <= 0)
      return;
    while (ic > 0) {
      read(0, &cc, 1);
      --ic;
    }
  }
}


x86 assembly (clang, -O0):
<flushall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2eb9(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
cmpl   $0x0,-0x8(%rbp)
jg     114c <flushall+0x2c>
add    $0x10,%rsp
pop    %rbp
ret
jmp    1151 <flushall+0x31>
cmpl   $0x0,-0x8(%rbp)
jle    1179 <flushall+0x59>
xor    %edi,%edi
lea    -0x1(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1151 <flushall+0x31>
jmp    1128 <flushall+0x8>

x86 assembly (clang, -O2):
<flushall>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2eb8(%rip),%r15
mov    (%r15),%esi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1030 <ioctl@plt>
cmpl   $0x0,0x8(%rsp)
jle    1183 <flushall+0x63>
lea    0xf(%rsp),%rbx
lea    0x8(%rsp),%r14
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    0x8(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x8(%rsp)
cmp    $0x1,%eax
jg     1150 <flushall+0x30>
mov    (%r15),%esi
xor    %edi,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
cmpl   $0x0,0x8(%rsp)
jg     1150 <flushall+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@FIONREAD = global i32 0
define void @flushall() {
%1 = alloca i8
%2 = alloca i32
br label %3
3: ; preds = %17, %0
%4 = load i32, i32* @FIONREAD
%5 = call i32 @ioctl(i32 0, i32 %4, i32* %2)
%6 = load i32, i32* %2
%7 = icmp sle i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %3
ret void
9: ; preds = %3
br label %10
10: ; preds = %13, %9
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = call i32 @read(i32 0, i8* %1, i32 1)
%15 = load i32, i32* %2
%16 = add nsw i32 %15, -1
store i32 %16, i32* %2
br label %10
17: ; preds = %10
br label %3
}

LLVM IR (-O2):
@FIONREAD = global i32 0
define void @flushall() {
%1 = alloca i8
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @FIONREAD
%5 = call i32 @ioctl(i32 0, i32 %4, i32* %2)
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 1
br i1 %7, label %13, label %14
8: ; preds = %14
%9 = load i32, i32* @FIONREAD
%10 = call i32 @ioctl(i32 0, i32 %9, i32* %2)
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %19
13: ; preds = %8, %0
ret void
14: ; preds = %0, %19
%15 = call i32 @read(i32 0, i8* %1, i32 1)
%16 = load i32, i32* %2
%17 = add nsw i32 %16, -1
store i32 %17, i32* %2
%18 = icmp sgt i32 %16, 1
br i1 %18, label %19, label %8
19: ; preds = %14, %8
br label %14
}