#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 /*<<< orphan*/ revents;
  int /*<<< orphan*/ events;
  int /*<<< orphan*/ fd;
};

/* Variables and functions */
int /*<<< orphan*/ test_msg(char *, size_t, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
void show_pollfd(struct pollfd *fds, size_t nfds) {
  size_t i;
  for (i = 0; i < nfds; i++) {
    test_msg("%2zu) fd: %2d events %2x revents %2x\n", i, fds[i].fd,
             fds[i].events, fds[i].revents);
  }
}


x86 assembly (clang, -O0):
<show_pollfd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1184 <show_pollfd+0x74>
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rax
imul   $0xc,-0x18(%rbp),%rcx
add    %rcx,%rax
mov    0x8(%rax),%edx
mov    -0x8(%rbp),%rax
imul   $0xc,-0x18(%rbp),%rcx
add    %rcx,%rax
mov    0x4(%rax),%ecx
mov    -0x8(%rbp),%rax
imul   $0xc,-0x18(%rbp),%rdi
add    %rdi,%rax
mov    (%rax),%r8d
lea    0xe92(%rip),%rdi
call   1030 <test_msg@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <show_pollfd+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_pollfd>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     1161 <show_pollfd+0x51>
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0x8,%rbx
xor    %r15d,%r15d
lea    0xecf(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%edx
mov    -0x8(%rbx),%r8d
mov    -0x4(%rbx),%ecx
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <test_msg@plt>
add    $0x1,%r15
add    $0xc,%rbx
cmp    %r15,%r14
jne    1140 <show_pollfd+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@.str = [38 x i8] c"%2zu) fd: %2d events %2x revents %2x\0A\00"
define void @show_pollfd(%struct.pollfd* %0, i64 %1) {
%3 = alloca %struct.pollfd*
%4 = alloca i64
%5 = alloca i64
store %struct.pollfd* %0, %struct.pollfd** %3
store i64 %1, i64* %4
store i64 0, i64* %5
br label %6
6: ; preds = %28, %2
%7 = load i64, i64* %5
%8 = load i64, i64* %4
%9 = icmp ult i64 %7, %8
br i1 %9, label %10, label %31
10: ; preds = %6
%11 = load i64, i64* %5
%12 = load %struct.pollfd*, %struct.pollfd** %3
%13 = load i64, i64* %5
%14 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %12, i64 %13
%15 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %14, i32 0, i32 2
%16 = load i32, i32* %15
%17 = load %struct.pollfd*, %struct.pollfd** %3
%18 = load i64, i64* %5
%19 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %17, i64 %18
%20 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load %struct.pollfd*, %struct.pollfd** %3
%23 = load i64, i64* %5
%24 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %22, i64 %23
%25 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @test_msg(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 %11, i32 %16, i32 %21, i32 %26)
br label %28
28: ; preds = %10
%29 = load i64, i64* %5
%30 = add i64 %29, 1
store i64 %30, i64* %5
br label %6
31: ; preds = %6
ret void
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@.str = [38 x i8] c"%2zu) fd: %2d events %2x revents %2x\0A\00"
define void @show_pollfd(%struct.pollfd* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %15, label %4
4: ; preds = %2, %4
%5 = phi i64 [ %13, %4 ], [ 0, %2 ]
%6 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %5, i32 2
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %5, i32 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %5, i32 0
%11 = load i32, i32* %10
%12 = tail call i32 @test_msg(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 %5, i32 %7, i32 %9, i32 %11)
%13 = add nuw i64 %5, 1
%14 = icmp eq i64 %13, %1
br i1 %14, label %15, label %4
15: ; preds = %4, %2
ret void
}