#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;
  int revents;
};

/* Variables and functions */
int POLLOUT;
int /*<<< orphan*/ poll(struct pollfd *, int, int);
int socketCanWrite(int sock) {
  if (sock < 0) {
    return 0;
  }
  struct pollfd PFD;
  PFD.fd = sock;
  PFD.events = POLLOUT;
  PFD.revents = 0;
  poll(&PFD, 1, 5);
  if ((PFD.revents & POLLOUT) == POLLOUT) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<socketCanWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1131 <socketCanWrite+0x21>
movl   $0x0,-0x4(%rbp)
jmp    118b <socketCanWrite+0x7b>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2eba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1030 <poll@plt>
mov    -0x10(%rbp),%eax
mov    0x2e91(%rip),%rcx
and    (%rcx),%eax
mov    0x2e88(%rip),%rcx
cmp    (%rcx),%eax
jne    1184 <socketCanWrite+0x74>
movl   $0x1,-0x4(%rbp)
jmp    118b <socketCanWrite+0x7b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socketCanWrite>:
test   %edi,%edi
js     1156 <socketCanWrite+0x46>
push   %rbx
sub    $0x10,%rsp
mov    %edi,(%rsp)
mov    0x2ed5(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x4(%rsp)
movl   $0x0,0x8(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1030 <poll@plt>
mov    0x8(%rsp),%ecx
not    %ecx
xor    %eax,%eax
and    (%rbx),%ecx
sete   %al
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@POLLOUT = global i32 0
define i32 @socketCanWrite(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.pollfd
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 0, i32* %2
br label %23
8: ; preds = %1
%9 = load i32, i32* %3
%10 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* @POLLOUT
%12 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 1
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 2
store i32 0, i32* %13
%14 = call i32 @poll(%struct.pollfd* %4, i32 1, i32 5)
%15 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 2
%16 = load i32, i32* %15
%17 = load i32, i32* @POLLOUT
%18 = and i32 %16, %17
%19 = load i32, i32* @POLLOUT
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %8
store i32 1, i32* %2
br label %23
22: ; preds = %8
store i32 0, i32* %2
br label %23
23: ; preds = %22, %21, %7
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@POLLOUT = global i32 0
define i32 @socketCanWrite(i32 %0) {
%2 = alloca %struct.pollfd
%3 = icmp slt i32 %0, 0
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = bitcast %struct.pollfd* %2 to i8*
%6 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 0
store i32 %0, i32* %6
%7 = load i32, i32* @POLLOUT
%8 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 1
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 2
store i32 0, i32* %9
%10 = call i32 @poll(%struct.pollfd* %2, i32 1, i32 5)
%11 = load i32, i32* %9
%12 = load i32, i32* @POLLOUT
%13 = and i32 %12, %11
%14 = icmp eq i32 %13, %12
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %1, %4
%17 = phi i32 [ %15, %4 ], [ 0, %1 ]
ret i32 %17
}