#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 evbuffer {
  int dummy;
};
struct bufferevent {
  int /*<<< orphan*/ input;
};

/* Variables and functions */
int /*<<< orphan*/ bufferevent_write_buffer(struct bufferevent *,
                                            struct evbuffer *);
int /*<<< orphan*/ evbuffer_add_printf(struct evbuffer *, char *, char *);
int /*<<< orphan*/ evbuffer_free(struct evbuffer *);
struct evbuffer *evbuffer_new();
char *evbuffer_readline(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
void buf_read_callback(struct bufferevent *incoming, void *arg) {
  struct evbuffer *evreturn;
  char *req;
  req = evbuffer_readline(incoming->input);
  if (req == NULL)
    return;
  evreturn = evbuffer_new();
  evbuffer_add_printf(evreturn, "You said %s\n", req);
  bufferevent_write_buffer(incoming, evreturn);
  evbuffer_free(evreturn);
  free(req);
}


x86 assembly (clang, -O0):
<buf_read_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1050 <evbuffer_readline@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118f <buf_read_callback+0x2f>
jmp    11cd <buf_read_callback+0x6d>
mov    $0x0,%al
call   1080 <evbuffer_new@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe57(%rip),%rsi
call   1070 <evbuffer_add_printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <bufferevent_write_buffer@plt>
mov    -0x18(%rbp),%rdi
call   1060 <evbuffer_free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buf_read_callback>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    (%rdi),%edi
call   1050 <evbuffer_readline@plt>
test   %rax,%rax
je     11b3 <buf_read_callback+0x53>
mov    %rax,%r15
xor    %eax,%eax
call   1080 <evbuffer_new@plt>
mov    %rax,%rbx
lea    0xe78(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
call   1070 <evbuffer_add_printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <bufferevent_write_buffer@plt>
mov    %rbx,%rdi
call   1060 <evbuffer_free@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
%struct.evbuffer = type { i32 }
@.str = [13 x i8] c"You said %s\0A\00"
define void @buf_read_callback(%struct.bufferevent* %0, i8* %1) {
%3 = alloca %struct.bufferevent*
%4 = alloca i8*
%5 = alloca %struct.evbuffer*
%6 = alloca i8*
store %struct.bufferevent* %0, %struct.bufferevent** %3
store i8* %1, i8** %4
%7 = load %struct.bufferevent*, %struct.bufferevent** %3
%8 = getelementptr inbounds %struct.bufferevent, %struct.bufferevent* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = call i8* @evbuffer_readline(i32 %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
br label %26
14: ; preds = %2
%15 = call %struct.evbuffer* (...) @evbuffer_new()
store %struct.evbuffer* %15, %struct.evbuffer** %5
%16 = load %struct.evbuffer*, %struct.evbuffer** %5
%17 = load i8*, i8** %6
%18 = call i32 @evbuffer_add_printf(%struct.evbuffer* %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load %struct.bufferevent*, %struct.bufferevent** %3
%20 = load %struct.evbuffer*, %struct.evbuffer** %5
%21 = call i32 @bufferevent_write_buffer(%struct.bufferevent* %19, %struct.evbuffer* %20)
%22 = load %struct.evbuffer*, %struct.evbuffer** %5
%23 = call i32 @evbuffer_free(%struct.evbuffer* %22)
%24 = load i8*, i8** %6
%25 = call i32 @free(i8* %24)
br label %26
26: ; preds = %14, %13
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
%struct.evbuffer = type { i32 }
@.str = [13 x i8] c"You said %s\0A\00"
define void @buf_read_callback(%struct.bufferevent* %0, i8* nocapture readnone %1) {
%3 = getelementptr inbounds %struct.bufferevent, %struct.bufferevent* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = tail call i8* @evbuffer_readline(i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = tail call %struct.evbuffer* (...) @evbuffer_new()
%9 = tail call i32 @evbuffer_add_printf(%struct.evbuffer* %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %5)
%10 = tail call i32 @bufferevent_write_buffer(%struct.bufferevent* %0, %struct.evbuffer* %8)
%11 = tail call i32 @evbuffer_free(%struct.evbuffer* %8)
%12 = tail call i32 @free(i8* %5)
br label %13
13: ; preds = %2, %7
ret void
}