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

/* Variables and functions */
int /*<<< orphan*/ POLLIN;
int /*<<< orphan*/ barf(char *);
int poll(struct pollfd *, int, int);
int write(int, char *, int);
void ready(int ready_out, int wakefd) {
  char dummy = '*';
  struct pollfd pollfd = {.fd = wakefd, .events = POLLIN};
  if (write(ready_out, &dummy, 1) != 1)
    barf("CLIENT: ready write");
  if (poll(&pollfd, 1, -1) != 1)
    barf("poll");
}


x86 assembly (clang, -O0):
<ready>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movb   $0x2a,-0x9(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
je     117a <ready+0x4a>
lea    0xe8b(%rip),%rdi
call   1030 <barf@plt>
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1050 <poll@plt>
cmp    $0x1,%eax
je     11a2 <ready+0x72>
lea    0xe77(%rip),%rdi
call   1030 <barf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ready>:
sub    $0x18,%rsp
movb   $0x2a,0xf(%rsp)
mov    %esi,0x10(%rsp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
je     116a <ready+0x3a>
lea    0xe9b(%rip),%rdi
call   1030 <barf@plt>
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1050 <poll@plt>
cmp    $0x1,%eax
je     118f <ready+0x5f>
lea    0xe8a(%rip),%rdi
call   1030 <barf@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
@POLLIN = global i32 0
@.str = [20 x i8] c"CLIENT: ready write\00"
@.str.1 = [5 x i8] c"poll\00"
define void @ready(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca %struct.pollfd
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8 42, i8* %5
%7 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %6, i32 0, i32 0
%8 = load i32, i32* %4
store i32 %8, i32* %7
%9 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %6, i32 0, i32 1
%10 = load i32, i32* @POLLIN
store i32 %10, i32* %9
%11 = load i32, i32* %3
%12 = call i32 @write(i32 %11, i8* %5, i32 1)
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @barf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = call i32 @poll(%struct.pollfd* %6, i32 1, i32 -1)
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @barf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
ret void
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
@POLLIN = global i32 0
@.str = [20 x i8] c"CLIENT: ready write\00"
@.str.1 = [5 x i8] c"poll\00"
define void @ready(i32 %0, i32 %1) {
%3 = alloca i8
%4 = alloca %struct.pollfd
store i8 42, i8* %3
%5 = bitcast %struct.pollfd* %4 to i8*
%6 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i64 0, i32 0
store i32 %1, i32* %6
%7 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i64 0, i32 1
%8 = load i32, i32* @POLLIN
store i32 %8, i32* %7
%9 = call i32 @write(i32 %0, i8* %3, i32 1)
%10 = icmp eq i32 %9, 1
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = tail call i32 @barf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = call i32 @poll(%struct.pollfd* %4, i32 1, i32 -1)
%15 = icmp eq i32 %14, 1
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = call i32 @barf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
ret void
}