#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 bufferevent {
  int dummy;
};
typedef int /*<<< orphan*/ msg;

/* Variables and functions */
size_t bufferevent_read(struct bufferevent *, char *, int);
int /*<<< orphan*/ bufferevent_write(struct bufferevent *, char *,
                                     int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strlen(char *);
void socket_read_cb(struct bufferevent *event, void *arg) {
  char msg[4096];
  size_t len = bufferevent_read(event, msg, sizeof(msg) - 1);
  msg[len] = '\0';
  printf("recv data :%s", msg);
  bufferevent_write(event, msg, strlen(msg));
}


x86 assembly (clang, -O0):
<socket_read_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
mov    $0xfff,%edx
call   1030 <bufferevent_read@plt>
mov    %rax,-0x1018(%rbp)
mov    -0x1018(%rbp),%rax
movb   $0x0,-0x1010(%rbp,%rax,1)
lea    -0x1010(%rbp),%rsi
lea    0xe74(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x1028(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1020(%rbp)
lea    -0x1010(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1028(%rbp),%rdi
mov    -0x1020(%rbp),%rsi
mov    %eax,%edx
call   1060 <bufferevent_write@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_read_cb>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rdi,%rbx
mov    %rsp,%r14
mov    %r14,%rsi
mov    $0xfff,%edx
call   1030 <bufferevent_read@plt>
movb   $0x0,(%rsp,%rax,1)
lea    0xe98(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <bufferevent_write@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
@.str = [14 x i8] c"recv data :%s\00"
define void @socket_read_cb(%struct.bufferevent* %0, i8* %1) {
%3 = alloca %struct.bufferevent*
%4 = alloca i8*
%5 = alloca [4096 x i8]
%6 = alloca i64
store %struct.bufferevent* %0, %struct.bufferevent** %3
store i8* %1, i8** %4
%7 = load %struct.bufferevent*, %struct.bufferevent** %3
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%9 = call i64 @bufferevent_read(%struct.bufferevent* %7, i8* %8, i32 4095)
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 %10
store i8 0, i8* %11
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%13 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load %struct.bufferevent*, %struct.bufferevent** %3
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = call i32 @bufferevent_write(%struct.bufferevent* %14, i8* %15, i32 %17)
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
@.str = [14 x i8] c"recv data :%s\00"
define void @socket_read_cb(%struct.bufferevent* %0, i8* nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = call i64 @bufferevent_read(%struct.bufferevent* %0, i8* %4, i32 4095)
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %5
store i8 0, i8* %6
%7 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %4)
%8 = call i32 @strlen(i8* %4)
%9 = call i32 @bufferevent_write(%struct.bufferevent* %0, i8* %4, i32 %8)
ret void
}