#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 fd;
  int events;
};
typedef size_t nfds_t;

/* Variables and functions */
int POLLERR;
int POLLHUP;
int POLLIN;
void add_poll(struct pollfd *fds, nfds_t *nfds, int fd) {
  fds[*nfds].fd = fd;
  fds[*nfds].events = POLLIN | POLLERR | POLLHUP;
  (*nfds)++;
}


x86 assembly (clang, -O0):
<add_poll>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
mov    %edx,(%rax,%rcx,8)
mov    0x2eb1(%rip),%rax
mov    (%rax),%edx
mov    0x2eb0(%rip),%rax
or     (%rax),%edx
mov    0x2eaf(%rip),%rax
or     (%rax),%edx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
mov    %edx,0x4(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_poll>:
mov    (%rsi),%rax
mov    %edx,(%rdi,%rax,8)
mov    0x2ecb(%rip),%rcx
mov    0x2ecc(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2ec9(%rip),%rcx
or     (%rcx),%edx
mov    %edx,0x4(%rdi,%rax,8)
add    $0x1,%rax
mov    %rax,(%rsi)
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
@POLLIN = global i32 0
@POLLERR = global i32 0
@POLLHUP = global i32 0
define void @add_poll(%struct.pollfd* %0, i64* %1, i32 %2) {
%4 = alloca %struct.pollfd*
%5 = alloca i64*
%6 = alloca i32
store %struct.pollfd* %0, %struct.pollfd** %4
store i64* %1, i64** %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = load %struct.pollfd*, %struct.pollfd** %4
%9 = load i64*, i64** %5
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %8, i64 %10
%12 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %11, i32 0, i32 0
store i32 %7, i32* %12
%13 = load i32, i32* @POLLIN
%14 = load i32, i32* @POLLERR
%15 = or i32 %13, %14
%16 = load i32, i32* @POLLHUP
%17 = or i32 %15, %16
%18 = load %struct.pollfd*, %struct.pollfd** %4
%19 = load i64*, i64** %5
%20 = load i64, i64* %19
%21 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %18, i64 %20
%22 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %21, i32 0, i32 1
store i32 %17, i32* %22
%23 = load i64*, i64** %5
%24 = load i64, i64* %23
%25 = add i64 %24, 1
store i64 %25, i64* %23
ret void
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
@POLLIN = global i32 0
@POLLERR = global i32 0
@POLLHUP = global i32 0
define void @add_poll(%struct.pollfd* nocapture writeonly %0, i64* nocapture %1, i32 %2) {
%4 = load i64, i64* %1
%5 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %4, i32 0
store i32 %2, i32* %5
%6 = load i32, i32* @POLLIN
%7 = load i32, i32* @POLLERR
%8 = or i32 %7, %6
%9 = load i32, i32* @POLLHUP
%10 = or i32 %8, %9
%11 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %4, i32 1
store i32 %10, i32* %11
%12 = add i64 %4, 1
store i64 %12, i64* %1
ret void
}