#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 fd;
};
struct epoll_event {
  int events;
  TYPE_1__ data;
};

/* Variables and functions */
int EPOLLIN;
int EPOLLRDHUP;
int /*<<< orphan*/ handleMessage(int, char *);
char *malloc(size_t);
int /*<<< orphan*/ read(int, ...);
int /*<<< orphan*/ rmUserByFd(int);
int handleClient(struct epoll_event *e) {
  size_t len = 0;
  char *buff = 0;
  if (e->events & EPOLLIN) {
    if (e->events & EPOLLRDHUP) {
      rmUserByFd(e->data.fd);
      return 1;
    }
    read(e->data.fd, &len, sizeof(size_t));
    buff = malloc(len * sizeof(char) + 1);
    read(e->data.fd, buff, len);
    buff[len + 1] = 0;
    if (len > 0) {
      handleMessage(e->data.fd, buff);
    } else {
      rmUserByFd(e->data.fd);
    }
    e->data.fd = -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<handleClient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    0x2e7f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     122a <handleClient+0xea>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    0x2e57(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11a4 <handleClient+0x64>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1060 <rmUserByFd@plt>
movl   $0x1,-0x4(%rbp)
jmp    1231 <handleClient+0xf1>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1040 <read@plt>
mov    -0x18(%rbp),%rdi
shl    $0x0,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1040 <read@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,0x1(%rax,%rcx,1)
cmpq   $0x0,-0x18(%rbp)
jbe    1213 <handleClient+0xd3>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x20(%rbp),%rsi
call   1030 <handleMessage@plt>
jmp    121f <handleClient+0xdf>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1060 <rmUserByFd@plt>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,0x4(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
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    (%rdi),%eax
mov    0x2e8d(%rip),%rcx
test   %eax,(%rcx)
je     11d7 <handleClient+0x97>
mov    %rdi,%rbx
mov    0x2e6f(%rip),%rcx
mov    0x4(%rdi),%edi
test   %eax,(%rcx)
je     117c <handleClient+0x3c>
call   1060 <rmUserByFd@plt>
mov    $0x1,%eax
jmp    11d9 <handleClient+0x99>
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   1040 <read@plt>
mov    0x8(%rsp),%r15
lea    0x1(%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>
mov    0x8(%rsp),%rax
movb   $0x0,0x1(%rax,%r14,1)
mov    0x4(%rbx),%edi
test   %rax,%rax
je     11cb <handleClient+0x8b>
mov    %r14,%rsi
call   1030 <handleMessage@plt>
jmp    11d0 <handleClient+0x90>
call   1060 <rmUserByFd@plt>
movl   $0xffffffff,0x4(%rbx)
xor    %eax,%eax
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
@EPOLLRDHUP = global i32 0
define i32 @handleClient(%struct.epoll_event* %0) {
%2 = alloca i32
%3 = alloca %struct.epoll_event*
%4 = alloca i64
%5 = alloca i8*
store %struct.epoll_event* %0, %struct.epoll_event** %3
store i64 0, i64* %4
store i8* null, i8** %5
%6 = load %struct.epoll_event*, %struct.epoll_event** %3
%7 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = load i32, i32* @EPOLLIN
%10 = and i32 %8, %9
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %65
12: ; preds = %1
%13 = load %struct.epoll_event*, %struct.epoll_event** %3
%14 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i32, i32* @EPOLLRDHUP
%17 = and i32 %15, %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %12
%20 = load %struct.epoll_event*, %struct.epoll_event** %3
%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 = call i32 @rmUserByFd(i32 %23)
store i32 1, i32* %2
br label %66
25: ; preds = %12
%26 = load %struct.epoll_event*, %struct.epoll_event** %3
%27 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %26, i32 0, i32 1
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 (i32, ...) @read(i32 %29, i64* %4, i64 8)
%31 = load i64, i64* %4
%32 = mul i64 %31, 1
%33 = add i64 %32, 1
%34 = call i8* @malloc(i64 %33)
store i8* %34, i8** %5
%35 = load %struct.epoll_event*, %struct.epoll_event** %3
%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** %5
%40 = load i64, i64* %4
%41 = call i32 (i32, ...) @read(i32 %38, i8* %39, i64 %40)
%42 = load i8*, i8** %5
%43 = load i64, i64* %4
%44 = add i64 %43, 1
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
%46 = load i64, i64* %4
%47 = icmp ugt i64 %46, 0
br i1 %47, label %48, label %55
48: ; preds = %25
%49 = load %struct.epoll_event*, %struct.epoll_event** %3
%50 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %49, i32 0, i32 1
%51 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = load i8*, i8** %5
%54 = call i32 @handleMessage(i32 %52, i8* %53)
br label %61
55: ; preds = %25
%56 = load %struct.epoll_event*, %struct.epoll_event** %3
%57 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %56, i32 0, i32 1
%58 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %57, i32 0, i32 0
%59 = load i32, i32* %58
%60 = call i32 @rmUserByFd(i32 %59)
br label %61
61: ; preds = %55, %48
%62 = load %struct.epoll_event*, %struct.epoll_event** %3
%63 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %62, i32 0, i32 1
%64 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %63, i32 0, i32 0
store i32 -1, i32* %64
br label %65
65: ; preds = %61, %1
store i32 0, i32* %2
br label %66
66: ; preds = %65, %19
%67 = load i32, i32* %2
ret i32 %67
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
@EPOLLRDHUP = global i32 0
define i32 @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 %34, label %9
9: ; preds = %1
%10 = load i32, i32* @EPOLLRDHUP
%11 = and i32 %10, %5
%12 = icmp eq i32 %11, 0
%13 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %0, i64 0, i32 1, i32 0
%14 = load i32, i32* %13
br i1 %12, label %17, label %15
15: ; preds = %9
%16 = tail call i32 @rmUserByFd(i32 %14)
br label %34
17: ; preds = %9
%18 = call i32 (i32, ...) @read(i32 %14, i64* %2, i64 8)
%19 = load i64, i64* %2
%20 = add i64 %19, 1
%21 = call i8* @malloc(i64 %20)
%22 = load i32, i32* %13
%23 = call i32 (i32, ...) @read(i32 %22, i8* %21, i64 %19)
%24 = load i64, i64* %2
%25 = add i64 %24, 1
%26 = getelementptr inbounds i8, i8* %21, i64 %25
store i8 0, i8* %26
%27 = icmp eq i64 %24, 0
%28 = load i32, i32* %13
br i1 %27, label %31, label %29
29: ; preds = %17
%30 = call i32 @handleMessage(i32 %28, i8* %21)
br label %33
31: ; preds = %17
%32 = call i32 @rmUserByFd(i32 %28)
br label %33
33: ; preds = %31, %29
store i32 -1, i32* %13
br label %34
34: ; preds = %1, %33, %15
%35 = phi i32 [ 1, %15 ], [ 0, %33 ], [ 0, %1 ]
ret i32 %35
}