#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 sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
struct event_base {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ clientaddr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ accept_client_data(int const, struct event_base *,
                                      struct sockaddr_in *, int, char *, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int recvfrom(int const, char *, int, int /*<<< orphan*/, struct sockaddr *,
             int /*<<< orphan*/ *);
void xkcp_rcv_cb(const int sock, short int which, void *arg) {
  struct event_base *base = arg;
  struct sockaddr_in clientaddr;
  int clientlen = sizeof(clientaddr);
  memset(&clientaddr, 0, clientlen);
  char buf[1500] = {0};
  int len = recvfrom(sock, buf, sizeof(buf) - 1, 0,
                     (struct sockaddr *)&clientaddr, (socklen_t *)&clientlen);
  if (len > 0) {
    accept_client_data(sock, base, &clientaddr, clientlen, buf, len);
  }
}


x86 assembly (clang, -O0):
<xkcp_rcv_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x610,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x4,-0x24(%rbp)
mov    -0x24(%rbp),%edx
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1030 <memset@plt>
lea    -0x600(%rbp),%rdi
xor    %esi,%esi
mov    $0x5dc,%edx
call   1030 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x600(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x5db,%edx
xor    %ecx,%ecx
lea    -0x24(%rbp),%r9
call   1040 <recvfrom@plt>
mov    %eax,-0x604(%rbp)
cmpl   $0x0,-0x604(%rbp)
jle    11cb <xkcp_rcv_cb+0x9b>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%ecx
lea    -0x600(%rbp),%r8
mov    -0x604(%rbp),%r9d
lea    -0x20(%rbp),%rdx
call   1050 <accept_client_data@plt>
add    $0x610,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xkcp_rcv_cb>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x5f8,%rsp
mov    %rdx,%r14
mov    %edi,%ebp
movl   $0x4,0x4(%rsp)
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
lea    0x10(%rsp),%rbx
mov    $0x5dc,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
lea    0x4(%rsp),%r9
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x5db,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1040 <recvfrom@plt>
test   %eax,%eax
jle    11aa <xkcp_rcv_cb+0x7a>
mov    0x4(%rsp),%ecx
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%r8
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%r9d
call   1050 <accept_client_data@plt>
add    $0x5f8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.event_base = type { i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
define void @xkcp_rcv_cb(i32 %0, i16 signext %1, i8* %2) {
%4 = alloca i32
%5 = alloca i16
%6 = alloca i8*
%7 = alloca %struct.event_base*
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca [1500 x i8]
%11 = alloca i32
store i32 %0, i32* %4
store i16 %1, i16* %5
store i8* %2, i8** %6
%12 = load i8*, i8** %6
%13 = bitcast i8* %12 to %struct.event_base*
store %struct.event_base* %13, %struct.event_base** %7
store i32 4, i32* %9
%14 = load i32, i32* %9
%15 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 %14)
%16 = bitcast [1500 x i8]* %10 to i8*
%17 = load i32, i32* %4
%18 = getelementptr inbounds [1500 x i8], [1500 x i8]* %10, i64 0, i64 0
%19 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%20 = call i32 @recvfrom(i32 %17, i8* %18, i32 1499, i32 0, %struct.sockaddr* %19, i32* %9)
store i32 %20, i32* %11
%21 = load i32, i32* %11
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %3
%24 = load i32, i32* %4
%25 = load %struct.event_base*, %struct.event_base** %7
%26 = load i32, i32* %9
%27 = getelementptr inbounds [1500 x i8], [1500 x i8]* %10, i64 0, i64 0
%28 = load i32, i32* %11
%29 = call i32 @accept_client_data(i32 %24, %struct.event_base* %25, %struct.sockaddr_in* %8, i32 %26, i8* %27, i32 %28)
br label %30
30: ; preds = %23, %3
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
%struct.event_base = type { i32 }
define void @xkcp_rcv_cb(i32 %0, i16 signext %1, i8* %2) {
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [1500 x i8]
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = bitcast i32* %5 to i8*
store i32 4, i32* %5
%9 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 4)
%10 = getelementptr inbounds [1500 x i8], [1500 x i8]* %6, i64 0, i64 0
%11 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%12 = call i32 @recvfrom(i32 %0, i8* %10, i32 1499, i32 0, %struct.sockaddr* %11, i32* %5)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = bitcast i8* %2 to %struct.event_base*
%16 = load i32, i32* %5
%17 = call i32 @accept_client_data(i32 %0, %struct.event_base* %15, %struct.sockaddr_in* %4, i32 %16, i8* %10, i32 %12)
br label %18
18: ; preds = %14, %3
ret void
}