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

/* Variables and functions */
int /*<<< orphan*/ POLLOUT;
int io_op_timeout(struct pollfd *, int (*)(int, void *, size_t), void *, size_t,
                  int);
scalar_t__ write;
ssize_t write_timeout(int fd, void *buf, size_t buflen, int timeout_ms) {
  struct pollfd fds;
  int ret;
  fds.fd = fd;
  fds.events = POLLOUT;
  ret = io_op_timeout(&fds, (ssize_t(*)(int, void *, size_t))write, buf, buflen,
                      timeout_ms);
  return ret;
}


x86 assembly (clang, -O0):
<write_timeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2ec5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    -0x28(%rbp),%rdi
call   1030 <io_op_timeout@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_timeout>:
push   %rax
mov    %ecx,%r8d
mov    %rdx,%rcx
mov    %rsi,%rdx
mov    %edi,(%rsp)
mov    0x2ed4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2eaf(%rip),%rax
mov    (%rax),%rsi
mov    %rsp,%rdi
call   1030 <io_op_timeout@plt>
pop    %rcx
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
@POLLOUT = global i32 0
@write = global i64 0
define i32 @write_timeout(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca %struct.pollfd
%10 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 %3, i32* %8
%11 = load i32, i32* %5
%12 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %9, i32 0, i32 0
store i32 %11, i32* %12
%13 = load i32, i32* @POLLOUT
%14 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %9, i32 0, i32 1
store i32 %13, i32* %14
%15 = load i64, i64* @write
%16 = inttoptr i64 %15 to i32 (i32, i8*, i64)*
%17 = load i8*, i8** %6
%18 = load i64, i64* %7
%19 = load i32, i32* %8
%20 = call i32 @io_op_timeout(%struct.pollfd* %9, i32 (i32, i8*, i64)* %16, i8* %17, i64 %18, i32 %19)
store i32 %20, i32* %10
%21 = load i32, i32* %10
ret i32 %21
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
@POLLOUT = global i32 0
@write = global i64 0
define i32 @write_timeout(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca %struct.pollfd
%6 = bitcast %struct.pollfd* %5 to i8*
%7 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 0, i32 0
store i32 %0, i32* %7
%8 = load i32, i32* @POLLOUT
%9 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 0, i32 1
store i32 %8, i32* %9
%10 = load i64, i64* @write
%11 = inttoptr i64 %10 to i32 (i32, i8*, i64)*
%12 = call i32 @io_op_timeout(%struct.pollfd* %5, i32 (i32, i8*, i64)* %11, i8* %1, i64 %2, i32 %3)
ret i32 %12
}