#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 {
  int dummy;
};
typedef scalar_t__ nfds_t;

/* Variables and functions */
scalar_t__ _syscall5(int, void *, void *, void *, void *, void *);
int errno;
int poll(struct pollfd *fds, nfds_t nfds, int timeout) {
  int ret = (int)_syscall5(41, (void *)fds, (void *)nfds, (void *)timeout,
                           ((void *)0), ((void *)0));
  if (ret < 0) {
    errno = -ret;
    return -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<poll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
movslq -0x1c(%rbp),%rcx
mov    $0x29,%edi
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1030 <_syscall5@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1168 <poll+0x58>
xor    %ecx,%ecx
sub    -0x20(%rbp),%ecx
mov    0x2e86(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    116e <poll+0x5e>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poll>:
push   %rax
mov    %rsi,%rax
mov    %rdi,%rsi
movslq %edx,%rcx
mov    $0x29,%edi
mov    %rax,%rdx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <_syscall5@plt>
test   %eax,%eax
js     1133 <poll+0x23>
pop    %rcx
ret
neg    %eax
mov    0x2ea4(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.pollfd = type { i32 }
@errno = global i32 0
define i32 @poll(%struct.pollfd* %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.pollfd*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store %struct.pollfd* %0, %struct.pollfd** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%9 = load %struct.pollfd*, %struct.pollfd** %5
%10 = bitcast %struct.pollfd* %9 to i8*
%11 = load i64, i64* %6
%12 = inttoptr i64 %11 to i8*
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i8*
%16 = call i64 @_syscall5(i32 41, i8* %10, i8* %12, i8* %15, i8* null, i8* null)
%17 = trunc i64 %16 to i32
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %3
%21 = load i32, i32* %8
%22 = sub nsw i32 0, %21
store i32 %22, i32* @errno
store i32 -1, i32* %4
br label %25
23: ; preds = %3
%24 = load i32, i32* %8
store i32 %24, i32* %4
br label %25
25: ; preds = %23, %20
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
%struct.pollfd = type { i32 }
@errno = global i32 0
define i32 @poll(%struct.pollfd* %0, i64 %1, i32 %2) {
%4 = bitcast %struct.pollfd* %0 to i8*
%5 = inttoptr i64 %1 to i8*
%6 = sext i32 %2 to i64
%7 = inttoptr i64 %6 to i8*
%8 = tail call i64 @_syscall5(i32 41, i8* %4, i8* %5, i8* %7, i8* null, i8* null)
%9 = trunc i64 %8 to i32
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = sub nsw i32 0, %9
store i32 %12, i32* @errno
br label %13
13: ; preds = %3, %11
%14 = phi i32 [ -1, %11 ], [ %9, %3 ]
ret i32 %14
}