#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 */
scalar_t__ EAGAIN;
scalar_t__ EWOULDBLOCK;
scalar_t__ errno;
int read(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
void empty_fd(int fd) {
  int res;
  char buf[10];
  do {
    errno = 0;
    res = read(fd, buf, strlen("RABIT"));
  } while (res > 0 && errno != EAGAIN && errno != EWOULDBLOCK);
}


x86 assembly (clang, -O0):
<empty_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2eae(%rip),%rax
movq   $0x0,(%rax)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x12(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xeb2(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1040 <read@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x25(%rbp)
jle    11ac <empty_fd+0x8c>
mov    0x2e66(%rip),%rax
mov    (%rax),%rcx
xor    %eax,%eax
mov    0x2e42(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x25(%rbp)
je     11ac <empty_fd+0x8c>
mov    0x2e47(%rip),%rax
mov    (%rax),%rax
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    112b <empty_fd+0xb>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<empty_fd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    0x2ea9(%rip),%r12
lea    0xec2(%rip),%r14
lea    0xe(%rsp),%r15
mov    0x2e7e(%rip),%r13
mov    0x2e87(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movq   $0x0,(%r12)
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    1190 <empty_fd+0x70>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1190 <empty_fd+0x70>
cmp    0x0(%rbp),%rax
jne    1160 <empty_fd+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [6 x i8] c"RABIT\00"
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
define void @empty_fd(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i8]
store i32 %0, i32* %2
br label %5
5: ; preds = %21, %1
store i64 0, i64* @errno
%6 = load i32, i32* %2
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%8 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @read(i32 %6, i8* %7, i32 %8)
store i32 %9, i32* %3
br label %10
10: ; preds = %5
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load i64, i64* @errno
%15 = load i64, i64* @EAGAIN
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i64, i64* @errno
%19 = load i64, i64* @EWOULDBLOCK
%20 = icmp ne i64 %18, %19
br label %21
21: ; preds = %17, %13, %10
%22 = phi i1 [ false, %13 ], [ false, %10 ], [ %20, %17 ]
br i1 %22, label %5, label %23
23: ; preds = %21
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [6 x i8] c"RABIT\00"
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
define void @empty_fd(i32 %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %8, %1
store i64 0, i64* @errno
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @read(i32 %0, i8* %3, i32 %5)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %4
%9 = load i64, i64* @errno
%10 = load i64, i64* @EAGAIN
%11 = icmp eq i64 %9, %10
%12 = load i64, i64* @EWOULDBLOCK
%13 = icmp eq i64 %9, %12
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %15, label %4
15: ; preds = %4, %8
ret void
}