#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 event_base {
  int dummy;
};
typedef scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ event_base_loopexit(struct event_base *,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ evutil_closesocket(int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ send(int, char *, scalar_t__, int /*<<< orphan*/);
scalar_t__ strlen(char *);
void write_handler(int fd, short what, void *arg) {
  ssize_t n;
  struct event_base *eb = (struct event_base *)arg;
  n = send(fd, "HelloWorld", strlen("HelloWorld"), 0);
  assert(n == strlen("HelloWorld"));
  printf("[server] send: %s\n", "HelloWorld");
  evutil_closesocket(fd);
  event_base_loopexit(eb, NULL);
}


x86 assembly (clang, -O0):
<write_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    0xe75(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xe63(%rip),%rsi
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe49(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xe31(%rip),%rdi
lea    0xe1f(%rip),%rsi
call   1060 <printf@plt>
mov    -0x4(%rbp),%edi
call   1080 <evutil_closesocket@plt>
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <event_base_loopexit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_handler>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %edi,%ebp
lea    0xea0(%rip),%r14
mov    $0xa,%edx
mov    %r14,%rsi
xor    %ecx,%ecx
call   1040 <send@plt>
xor    %edi,%edi
cmp    $0xa,%rax
sete   %dil
call   1060 <assert@plt>
lea    0xe86(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %ebp,%edi
call   1070 <evutil_closesocket@plt>
mov    %rbx,%rdi
xor    %esi,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <event_base_loopexit@plt>

LLVM IR (-O0):
%struct.event_base = type { i32 }
@.str = [11 x i8] c"HelloWorld\00"
@.str.1 = [19 x i8] c"[server] send: %s\0A\00"
define void @write_handler(i32 %0, i16 signext %1, i8* %2) {
%4 = alloca i32
%5 = alloca i16
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.event_base*
store i32 %0, i32* %4
store i16 %1, i16* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = bitcast i8* %9 to %struct.event_base*
store %struct.event_base* %10, %struct.event_base** %8
%11 = load i32, i32* %4
%12 = call i64 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%13 = call i64 @send(i32 %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64 %12, i32 0)
store i64 %13, i64* %7
%14 = load i64, i64* %7
%15 = call i64 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %14, %15
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %4
%21 = call i32 @evutil_closesocket(i32 %20)
%22 = load %struct.event_base*, %struct.event_base** %8
%23 = call i32 @event_base_loopexit(%struct.event_base* %22, i32* null)
ret void
}

LLVM IR (-O2):
%struct.event_base = type { i32 }
@.str = [11 x i8] c"HelloWorld\00"
@.str.1 = [19 x i8] c"[server] send: %s\0A\00"
define void @write_handler(i32 %0, i16 signext %1, i8* %2) {
%4 = bitcast i8* %2 to %struct.event_base*
%5 = tail call i64 @send(i32 %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64 10, i32 0)
%6 = icmp eq i64 %5, 10
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @evutil_closesocket(i32 %0)
%11 = tail call i32 @event_base_loopexit(%struct.event_base* %4, i32* null)
ret void
}