#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 */

/* Variables and functions */
int /*<<< orphan*/ EPOLLIN;
int /*<<< orphan*/ EPOLLOUT;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ delete_event(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ modify_event(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
void do_write(int epollfd, int fd, char *buf) {
  int nwrite;
  nwrite = write(fd, buf, strlen(buf));
  if (nwrite == -1) {
    perror("write error:");
    close(fd);
    delete_event(epollfd, fd, EPOLLOUT);
  } else
    modify_event(epollfd, fd, EPOLLIN);
  memset(buf, 0, 1024);
}


x86 assembly (clang, -O0):
<do_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11e1 <do_write+0x71>
lea    0xe45(%rip),%rdi
call   1090 <perror@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
call   1050 <delete_event@plt>
jmp    11f5 <do_write+0x85>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
call   1080 <modify_event@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_write>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %edi,%r14d
mov    %rdx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     11bb <do_write+0x4b>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
mov    %ebp,%esi
call   1080 <modify_event@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <memset@plt>
lea    0xe3e(%rip),%rdi
call   1090 <perror@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
mov    %ebp,%esi
call   1050 <delete_event@plt>
jmp    11a8 <do_write+0x38>

LLVM IR (-O0):
@.str = [13 x i8] c"write error:\00"
@EPOLLOUT = global i32 0
@EPOLLIN = global i32 0
define void @do_write(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i32, i32* %5
%9 = load i8*, i8** %6
%10 = load i8*, i8** %6
%11 = call i32 @strlen(i8* %10)
%12 = call i32 @write(i32 %8, i8* %9, i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %23
15: ; preds = %3
%16 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %5
%18 = call i32 @close(i32 %17)
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = load i32, i32* @EPOLLOUT
%22 = call i32 @delete_event(i32 %19, i32 %20, i32 %21)
br label %28
23: ; preds = %3
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = load i32, i32* @EPOLLIN
%27 = call i32 @modify_event(i32 %24, i32 %25, i32 %26)
br label %28
28: ; preds = %23, %15
%29 = load i8*, i8** %6
%30 = call i32 @memset(i8* %29, i32 0, i32 1024)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"write error:\00"
@EPOLLOUT = global i32 0
@EPOLLIN = global i32 0
define void @do_write(i32 %0, i32 %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = tail call i32 @write(i32 %1, i8* %2, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @close(i32 %1)
%10 = load i32, i32* @EPOLLOUT
%11 = tail call i32 @delete_event(i32 %0, i32 %1, i32 %10)
br label %15
12: ; preds = %3
%13 = load i32, i32* @EPOLLIN
%14 = tail call i32 @modify_event(i32 %0, i32 %1, i32 %13)
br label %15
15: ; preds = %12, %7
%16 = tail call i32 @memset(i8* %2, i32 0, i32 1024)
ret void
}