#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 timespec {
  int tv_sec;
  long tv_nsec;
};
struct pollfd {
  int dummy;
};
typedef int /*<<< orphan*/ nfds_t;

/* Variables and functions */
int /*<<< orphan*/ __NR_ppoll;
int syscall(int /*<<< orphan*/, struct pollfd *, int /*<<< orphan*/,
            struct timespec *, int /*<<< orphan*/);
__attribute__((always_)) int _syscall_poll(struct pollfd fds[], nfds_t nfds,
                                           int timeout) {
  struct timespec tmo;
  if (timeout > -1) {
    tmo.tv_sec = timeout / 1000;
    tmo.tv_nsec = 1000000L * (timeout % 1000);
  }
  return syscall(__NR_ppoll, fds, nfds, ((timeout > -1) ? (&tmo) : 0), 0);
}


x86 assembly (clang, -O0):
<_syscall_poll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jle    1153 <_syscall_poll+0x43>
mov    -0x10(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
imul   $0xf4240,%rax,%rax
mov    %rax,-0x18(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jle    1184 <_syscall_poll+0x74>
lea    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    118f <_syscall_poll+0x7f>
xor    %eax,%eax
mov    %rax,-0x40(%rbp)
jmp    118f <_syscall_poll+0x7f>
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edi
mov    -0x40(%rbp),%rcx
xor    %r8d,%r8d
call   1030 <syscall@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_syscall_poll>:
sub    $0x18,%rsp
mov    %edx,%eax
mov    %esi,%edx
mov    %rdi,%rsi
test   %eax,%eax
js     114a <_syscall_poll+0x3a>
mov    %eax,%ecx
imul   $0x10624dd3,%rcx,%rcx
shr    $0x26,%rcx
mov    %ecx,0x8(%rsp)
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
imul   $0xf4240,%eax,%eax
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rcx
jmp    114c <_syscall_poll+0x3c>
xor    %ecx,%ecx
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
xor    %r8d,%r8d
call   1030 <syscall@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.pollfd = type { i32 }
%struct.timespec = type { i32, i64 }
@__NR_ppoll = global i32 0
define i32 @_syscall_poll(%struct.pollfd* %0, i32 %1, i32 %2) {
%4 = alloca %struct.pollfd*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.timespec
store %struct.pollfd* %0, %struct.pollfd** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %19
10: ; preds = %3
%11 = load i32, i32* %6
%12 = sdiv i32 %11, 1000
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* %6
%15 = srem i32 %14, 1000
%16 = sext i32 %15 to i64
%17 = mul nsw i64 1000000, %16
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
store i64 %17, i64* %18
br label %19
19: ; preds = %10, %3
%20 = load i32, i32* @__NR_ppoll
%21 = load %struct.pollfd*, %struct.pollfd** %4
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = icmp sgt i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %19
br label %27
26: ; preds = %19
br label %27
27: ; preds = %26, %25
%28 = phi %struct.timespec* [ %7, %25 ], [ null, %26 ]
%29 = call i32 @syscall(i32 %20, %struct.pollfd* %21, i32 %22, %struct.timespec* %28, i32 0)
ret i32 %29
}

LLVM IR (-O2):
%struct.pollfd = type { i32 }
%struct.timespec = type { i32, i64 }
@__NR_ppoll = global i32 0
define i32 @_syscall_poll(%struct.pollfd* %0, i32 %1, i32 %2) {
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %4 to i8*
%6 = icmp sgt i32 %2, -1
br i1 %6, label %7, label %14
7: ; preds = %3
%8 = udiv i32 %2, 1000
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
store i32 %8, i32* %9
%10 = urem i32 %2, 1000
%11 = mul nuw nsw i32 %10, 1000000
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
store i64 %12, i64* %13
br label %14
14: ; preds = %7, %3
%15 = phi %struct.timespec* [ %4, %7 ], [ null, %3 ]
%16 = load i32, i32* @__NR_ppoll
%17 = call i32 @syscall(i32 %16, %struct.pollfd* %0, i32 %1, %struct.timespec* %15, i32 0)
ret i32 %17
}