#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ fd;
};
struct epoll_event {
  int events;
  TYPE_1__ data;
};

/* Variables and functions */
int EPOLLIN;
char *malloc(size_t);
int /*<<< orphan*/ read(int /*<<< orphan*/, ...);
int /*<<< orphan*/ write(int /*<<< orphan*/, ...);
void handleClient(struct epoll_event *e) {
  size_t msg_len = 0;
  char *buff = 0;
  if (e->events & EPOLLIN) {
    read(e->data.fd, &msg_len, sizeof(size_t));
    buff = malloc(msg_len * sizeof(char));
    read(e->data.fd, buff, msg_len);
    if (msg_len > 0) {
      write(e->data.fd, &msg_len, sizeof(size_t));
      write(e->data.fd, buff, msg_len);
    }
  }
}


x86 assembly (clang, -O0):
<handleClient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    0x2e8f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11df <handleClient+0xaf>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1040 <read@plt>
mov    -0x10(%rbp),%rdi
shl    $0x0,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <read@plt>
cmpq   $0x0,-0x10(%rbp)
jbe    11da <handleClient+0xaa>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1030 <write@plt>
jmp    11df <handleClient+0xaf>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handleClient>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%eax
test   %eax,(%rdi)
je     11b4 <handleClient+0x84>
mov    %rdi,%rbx
mov    0x4(%rdi),%edi
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   1040 <read@plt>
mov    0x8(%rsp),%r15
mov    %r15,%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    0x4(%rbx),%edi
mov    %rax,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <read@plt>
cmpq   $0x0,0x8(%rsp)
je     11b4 <handleClient+0x84>
mov    0x4(%rbx),%edi
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    0x4(%rbx),%edi
mov    0x8(%rsp),%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <write@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
define void @handleClient(%struct.epoll_event* %0) {
%2 = alloca %struct.epoll_event*
%3 = alloca i64
%4 = alloca i8*
store %struct.epoll_event* %0, %struct.epoll_event** %2
store i64 0, i64* %3
store i8* null, i8** %4
%5 = load %struct.epoll_event*, %struct.epoll_event** %2
%6 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i32 0, i32 0
%7 = load i32, i32* %6
%8 = load i32, i32* @EPOLLIN
%9 = and i32 %7, %8
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %43
11: ; preds = %1
%12 = load %struct.epoll_event*, %struct.epoll_event** %2
%13 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %12, i32 0, i32 1
%14 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 (i32, ...) @read(i32 %15, i64* %3, i64 8)
%17 = load i64, i64* %3
%18 = mul i64 %17, 1
%19 = call i8* @malloc(i64 %18)
store i8* %19, i8** %4
%20 = load %struct.epoll_event*, %struct.epoll_event** %2
%21 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %20, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = load i8*, i8** %4
%25 = load i64, i64* %3
%26 = call i32 (i32, ...) @read(i32 %23, i8* %24, i64 %25)
%27 = load i64, i64* %3
%28 = icmp ugt i64 %27, 0
br i1 %28, label %29, label %42
29: ; preds = %11
%30 = load %struct.epoll_event*, %struct.epoll_event** %2
%31 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %30, i32 0, i32 1
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 (i32, ...) @write(i32 %33, i64* %3, i64 8)
%35 = load %struct.epoll_event*, %struct.epoll_event** %2
%36 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %35, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
%38 = load i32, i32* %37
%39 = load i8*, i8** %4
%40 = load i64, i64* %3
%41 = call i32 (i32, ...) @write(i32 %38, i8* %39, i64 %40)
br label %42
42: ; preds = %29, %11
br label %43
43: ; preds = %42, %1
ret void
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
define void @handleClient(%struct.epoll_event* nocapture %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%4 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = load i32, i32* @EPOLLIN
%7 = and i32 %6, %5
%8 = icmp eq i32 %7, 0
br i1 %8, label %25, label %9
9: ; preds = %1
%10 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %0, i64 0, i32 1, i32 0
%11 = load i32, i32* %10
%12 = call i32 (i32, ...) @read(i32 %11, i64* %2, i64 8)
%13 = load i64, i64* %2
%14 = call i8* @malloc(i64 %13)
%15 = load i32, i32* %10
%16 = call i32 (i32, ...) @read(i32 %15, i8* %14, i64 %13)
%17 = load i64, i64* %2
%18 = icmp eq i64 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %9
%20 = load i32, i32* %10
%21 = call i32 (i32, ...) @write(i32 %20, i64* %2, i64 8)
%22 = load i32, i32* %10
%23 = load i64, i64* %2
%24 = call i32 (i32, ...) @write(i32 %22, i8* %14, i64 %23)
br label %25
25: ; preds = %9, %19, %1
ret void
}