#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 /*<<< orphan*/ fd_set;

/* Variables and functions */
int EINTR;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int errno;
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int wait_data(int readfd) {
  do {
    do {
    } while (0);
  } while (0);
  fd_set fds;
  FD_ZERO(&fds);
  FD_SET(readfd, &fds);
  int ret;
  while ((ret = select(readfd + 1, &fds, NULL, NULL, NULL)) <= 0) {
    if (ret < 0) {
      int e = errno;
      if (e == EINTR)
        continue;
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<wait_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
jmp    1140 <wait_data+0x10>
jmp    1145 <wait_data+0x15>
jmp    114a <wait_data+0x1a>
lea    -0xc(%rbp),%rdi
call   1030 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1050 <FD_SET@plt>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1040 <select@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jg     11c3 <wait_data+0x93>
cmpl   $0x0,-0x10(%rbp)
jge    11be <wait_data+0x8e>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%eax
jne    11b2 <wait_data+0x82>
jmp    115f <wait_data+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    11ca <wait_data+0x9a>
jmp    115f <wait_data+0x2f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_data>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xc(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1050 <FD_SET@plt>
add    $0x1,%ebx
mov    %ebx,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <select@plt>
mov    $0x1,%r14d
test   %eax,%eax
jle    1183 <wait_data+0x53>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e56(%rip),%r15
mov    0x2e47(%rip),%r12
lea    0xc(%rsp),%rbp
jmp    11b5 <wait_data+0x85>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <select@plt>
test   %eax,%eax
jg     1173 <wait_data+0x43>
test   %eax,%eax
jns    11a0 <wait_data+0x70>
mov    (%r15),%eax
cmp    (%r12),%eax
je     11a0 <wait_data+0x70>
xor    %r14d,%r14d
jmp    1173 <wait_data+0x43>

LLVM IR (-O0):
@errno = global i32 0
@EINTR = global i32 0
define i32 @wait_data(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
br label %7
7: ; preds = %1
br label %8
8: ; preds = %7
br label %9
9: ; preds = %8
br label %10
10: ; preds = %9
%11 = call i32 @FD_ZERO(i32* %4)
%12 = load i32, i32* %3
%13 = call i32 @FD_SET(i32 %12, i32* %4)
br label %14
14: ; preds = %29, %27, %10
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
%17 = call i32 @select(i32 %16, i32* %4, i32* null, i32* null, i32* null)
store i32 %17, i32* %5
%18 = icmp sle i32 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %14
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i32, i32* @errno
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = load i32, i32* @EINTR
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %22
br label %14
28: ; preds = %22
store i32 0, i32* %2
br label %31
29: ; preds = %19
br label %14
30: ; preds = %14
store i32 1, i32* %2
br label %31
31: ; preds = %30, %28
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@errno = global i32 0
@EINTR = global i32 0
define i32 @wait_data(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @FD_ZERO(i32* %2)
%5 = call i32 @FD_SET(i32 %0, i32* %2)
%6 = add nsw i32 %0, 1
%7 = call i32 @select(i32 %6, i32* %2, i32* null, i32* null, i32* null)
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %19
9: ; preds = %1, %16
%10 = phi i32 [ %17, %16 ], [ %7, %1 ]
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* @errno
%14 = load i32, i32* @EINTR
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12, %9
%17 = call i32 @select(i32 %6, i32* %2, i32* null, i32* null, i32* null)
%18 = icmp slt i32 %17, 1
br i1 %18, label %9, label %19
19: ; preds = %12, %16, %1
%20 = phi i32 [ 1, %1 ], [ 1, %16 ], [ 0, %12 ]
ret i32 %20
}