#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;
};
typedef int /*<<< orphan*/ acBuf;

/* Variables and functions */
int ECONNRESET;
int EPOLLIN;
int ETIMEDOUT;
int /*<<< orphan*/ MM_Epoll_Delete(int /*<<< orphan*/);
int /*<<< orphan*/ MSG_DONTWAIT;
int /*<<< orphan*/ close(int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ printf(char *, ...);
int recv(int /*<<< orphan*/, char *, int, int /*<<< orphan*/);
int MM_MSG_RecvMsg(struct epoll_event *pstEvent) {
  char acBuf[4096];
  int iRecvNum;
  if (EPOLLIN & pstEvent->events) {
    while ((iRecvNum = recv(pstEvent->data.fd, acBuf, sizeof(acBuf),
                            MSG_DONTWAIT)) > 0) {
      printf("%s\r\n", acBuf);
    }
    printf("ReadOver %d, %d\r\n", iRecvNum, errno);
    if (iRecvNum < 0) {
      if (errno == ECONNRESET || errno == ETIMEDOUT) {
        MM_Epoll_Delete(pstEvent->data.fd);
        close(pstEvent->data.fd);
      }
    } else if (iRecvNum == 0) {
      MM_Epoll_Delete(pstEvent->data.fd);
      close(pstEvent->data.fd);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<MM_MSG_RecvMsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     125c <MM_MSG_RecvMsg+0x11c>
jmp    116c <MM_MSG_RecvMsg+0x2c>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x1010(%rbp),%rsi
mov    0x2e47(%rip),%rax
mov    (%rax),%ecx
mov    $0x1000,%edx
call   1030 <recv@plt>
mov    %eax,-0x1014(%rbp)
cmp    $0x0,%eax
jle    11b6 <MM_MSG_RecvMsg+0x76>
lea    -0x1010(%rbp),%rsi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    116c <MM_MSG_RecvMsg+0x2c>
mov    -0x1014(%rbp),%esi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x1014(%rbp)
jge    122d <MM_MSG_RecvMsg+0xed>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    0x2de8(%rip),%rcx
cmp    (%rcx),%eax
je     1210 <MM_MSG_RecvMsg+0xd0>
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    0x2db8(%rip),%rcx
cmp    (%rcx),%eax
jne    1228 <MM_MSG_RecvMsg+0xe8>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1060 <MM_Epoll_Delete@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <close@plt>
jmp    1257 <MM_MSG_RecvMsg+0x117>
cmpl   $0x0,-0x1014(%rbp)
jne    1252 <MM_MSG_RecvMsg+0x112>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1060 <MM_Epoll_Delete@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <close@plt>
jmp    1257 <MM_MSG_RecvMsg+0x117>
jmp    125c <MM_MSG_RecvMsg+0x11c>
xor    %eax,%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MM_MSG_RecvMsg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1000,%rsp
mov    0x2e92(%rip),%rax
mov    (%rdi),%ecx
test   %ecx,(%rax)
je     11e7 <MM_MSG_RecvMsg+0xa7>
mov    %rdi,%r15
mov    0x4(%rdi),%edi
mov    0x2e5b(%rip),%r12
mov    (%r12),%ecx
mov    %rsp,%rsi
mov    $0x1000,%edx
call   1030 <recv@plt>
test   %eax,%eax
jle    11b6 <MM_MSG_RecvMsg+0x76>
lea    0xe77(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%r15),%edi
mov    (%r12),%ecx
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1030 <recv@plt>
test   %eax,%eax
jg     1190 <MM_MSG_RecvMsg+0x50>
mov    %eax,%ebp
mov    0x2e11(%rip),%rbx
mov    (%rbx),%edx
lea    0xe3d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
js     11f9 <MM_MSG_RecvMsg+0xb9>
mov    0x4(%r15),%edi
call   1060 <MM_Epoll_Delete@plt>
mov    0x4(%r15),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%eax
mov    0x2dd6(%rip),%rcx
cmp    (%rcx),%eax
je     11d5 <MM_MSG_RecvMsg+0x95>
mov    0x2db3(%rip),%rcx
cmp    (%rcx),%eax
jne    11e7 <MM_MSG_RecvMsg+0xa7>
jmp    11d5 <MM_MSG_RecvMsg+0x95>

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
@MSG_DONTWAIT = global i32 0
@.str = [5 x i8] c"%s\0D\0A\00"
@.str.1 = [18 x i8] c"ReadOver %d, %d\0D\0A\00"
@errno = global i32 0
@ECONNRESET = global i32 0
@ETIMEDOUT = global i32 0
define i32 @MM_MSG_RecvMsg(%struct.epoll_event* %0) {
%2 = alloca %struct.epoll_event*
%3 = alloca [4096 x i8]
%4 = alloca i32
store %struct.epoll_event* %0, %struct.epoll_event** %2
%5 = load i32, i32* @EPOLLIN
%6 = load %struct.epoll_event*, %struct.epoll_event** %2
%7 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = and i32 %5, %8
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %66
11: ; preds = %1
br label %12
12: ; preds = %21, %11
%13 = load %struct.epoll_event*, %struct.epoll_event** %2
%14 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %13, i32 0, i32 1
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%18 = load i32, i32* @MSG_DONTWAIT
%19 = call i32 @recv(i32 %16, i8* %17, i32 4096, i32 %18)
store i32 %19, i32* %4
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %12
24: ; preds = %12
%25 = load i32, i32* %4
%26 = load i32, i32* @errno
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %26)
%28 = load i32, i32* %4
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %50
30: ; preds = %24
%31 = load i32, i32* @errno
%32 = load i32, i32* @ECONNRESET
%33 = icmp eq i32 %31, %32
br i1 %33, label %38, label %34
34: ; preds = %30
%35 = load i32, i32* @errno
%36 = load i32, i32* @ETIMEDOUT
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %49
38: ; preds = %34, %30
%39 = load %struct.epoll_event*, %struct.epoll_event** %2
%40 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %39, i32 0, i32 1
%41 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i32 @MM_Epoll_Delete(i32 %42)
%44 = load %struct.epoll_event*, %struct.epoll_event** %2
%45 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %44, i32 0, i32 1
%46 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 @close(i32 %47)
br label %49
49: ; preds = %38, %34
br label %65
50: ; preds = %24
%51 = load i32, i32* %4
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %64
53: ; preds = %50
%54 = load %struct.epoll_event*, %struct.epoll_event** %2
%55 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %54, i32 0, i32 1
%56 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %55, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @MM_Epoll_Delete(i32 %57)
%59 = load %struct.epoll_event*, %struct.epoll_event** %2
%60 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %59, i32 0, i32 1
%61 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %60, i32 0, i32 0
%62 = load i32, i32* %61
%63 = call i32 @close(i32 %62)
br label %64
64: ; preds = %53, %50
br label %65
65: ; preds = %64, %49
br label %66
66: ; preds = %65, %1
ret i32 0
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
@MSG_DONTWAIT = global i32 0
@.str = [5 x i8] c"%s\0D\0A\00"
@.str.1 = [18 x i8] c"ReadOver %d, %d\0D\0A\00"
@errno = global i32 0
@ECONNRESET = global i32 0
@ETIMEDOUT = global i32 0
define i32 @MM_MSG_RecvMsg(%struct.epoll_event* nocapture %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @EPOLLIN
%5 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = and i32 %6, %4
%8 = icmp eq i32 %7, 0
br i1 %8, label %38, 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 = load i32, i32* @MSG_DONTWAIT
%13 = call i32 @recv(i32 %11, i8* %3, i32 4096, i32 %12)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %9, %15
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %3)
%17 = load i32, i32* %10
%18 = load i32, i32* @MSG_DONTWAIT
%19 = call i32 @recv(i32 %17, i8* %3, i32 4096, i32 %18)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %15, label %21
21: ; preds = %15, %9
%22 = phi i32 [ %13, %9 ], [ %19, %15 ]
%23 = load i32, i32* @errno
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %23)
%25 = icmp slt i32 %22, 0
br i1 %25, label %26, label %33
26: ; preds = %21
%27 = load i32, i32* @errno
%28 = load i32, i32* @ECONNRESET
%29 = icmp eq i32 %27, %28
%30 = load i32, i32* @ETIMEDOUT
%31 = icmp eq i32 %27, %30
%32 = select i1 %29, i1 true, i1 %31
br i1 %32, label %33, label %38
33: ; preds = %21, %26
%34 = load i32, i32* %10
%35 = call i32 @MM_Epoll_Delete(i32 %34)
%36 = load i32, i32* %10
%37 = call i32 @close(i32 %36)
br label %38
38: ; preds = %33, %26, %1
ret i32 0
}