#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 pollfd {
  scalar_t__ fd;
};

/* Variables and functions */
int readable_fd_available(struct pollfd *fds, size_t fd_cnt) {
  for (size_t fdidx = 0; fdidx < fd_cnt; ++fdidx) {
    if (fds[fdidx].fd >= 0) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<readable_fd_available>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1157 <readable_fd_available+0x57>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jl     1141 <readable_fd_available+0x41>
movl   $0x1,-0x4(%rbp)
jmp    115e <readable_fd_available+0x5e>
jmp    1146 <readable_fd_available+0x46>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1114 <readable_fd_available+0x14>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<readable_fd_available>:
test   %rsi,%rsi
je     1111 <readable_fd_available+0x11>
mov    $0x1,%eax
cmpq   $0x0,(%rdi)
js     1114 <readable_fd_available+0x14>
ret
xor    %eax,%eax
ret
mov    $0x1,%eax
nopl   0x0(%rax)
mov    %rax,%rcx
cmp    %rax,%rsi
je     1133 <readable_fd_available+0x33>
lea    0x1(%rcx),%rax
cmpq   $0x0,(%rdi,%rcx,8)
js     1120 <readable_fd_available+0x20>
xor    %eax,%eax
cmp    %rsi,%rcx
setb   %al
ret

LLVM IR (-O0):
%struct.pollfd = type { i64 }
define i32 @readable_fd_available(%struct.pollfd* %0, i64 %1) {
%3 = alloca i32
%4 = alloca %struct.pollfd*
%5 = alloca i64
%6 = alloca i64
store %struct.pollfd* %0, %struct.pollfd** %4
store i64 %1, i64* %5
store i64 0, i64* %6
br label %7
7: ; preds = %20, %2
%8 = load i64, i64* %6
%9 = load i64, i64* %5
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %23
11: ; preds = %7
%12 = load %struct.pollfd*, %struct.pollfd** %4
%13 = load i64, i64* %6
%14 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %12, i64 %13
%15 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = icmp sge i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %11
store i32 1, i32* %3
br label %24
19: ; preds = %11
br label %20
20: ; preds = %19
%21 = load i64, i64* %6
%22 = add i64 %21, 1
store i64 %22, i64* %6
br label %7
23: ; preds = %7
store i32 0, i32* %3
br label %24
24: ; preds = %23, %18
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.pollfd = type { i64 }
define i32 @readable_fd_available(%struct.pollfd* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %19, label %4
4: ; preds = %2
%5 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 0, i32 0
%6 = load i64, i64* %5
%7 = icmp sgt i64 %6, -1
br i1 %7, label %19, label %8
8: ; preds = %4, %11
%9 = phi i64 [ %15, %11 ], [ 1, %4 ]
%10 = icmp eq i64 %9, %1
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %9, i32 0
%13 = load i64, i64* %12
%14 = icmp sgt i64 %13, -1
%15 = add nuw i64 %9, 1
br i1 %14, label %16, label %8
16: ; preds = %8, %11
%17 = icmp ult i64 %9, %1
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %16, %4, %2
%20 = phi i32 [ 0, %2 ], [ 1, %4 ], [ %18, %16 ]
ret i32 %20
}