#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 dummy;
};

/* Variables and functions */
struct evbuffer *bufferevent_get_input(struct bufferevent *);
struct evbuffer *bufferevent_get_output(struct bufferevent *);
int /*<<< orphan*/ evbuffer_add(struct evbuffer *, unsigned char *, size_t);
int /*<<< orphan*/ evbuffer_drain(struct evbuffer *, size_t);
size_t evbuffer_get_length(struct evbuffer *);
unsigned char *evbuffer_pullup(struct evbuffer *, size_t);
void read_cb(struct bufferevent *bev, void *user_data) {
  struct evbuffer *input = bufferevent_get_input(bev);
  size_t len = evbuffer_get_length(input);
  unsigned char *data = evbuffer_pullup(input, len);
  struct evbuffer *output = bufferevent_get_output(bev);
  evbuffer_add(output, data, len);
  evbuffer_drain(input, len);
}


x86 assembly (clang, -O0):
<read_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <bufferevent_get_input@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <evbuffer_get_length@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <evbuffer_pullup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <bufferevent_get_output@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <evbuffer_add@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <evbuffer_drain@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_cb>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <bufferevent_get_input@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <evbuffer_get_length@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1030 <evbuffer_pullup@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1040 <bufferevent_get_output@plt>
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <evbuffer_add@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1080 <evbuffer_drain@plt>

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
%struct.evbuffer = type { i32 }
define void @read_cb(%struct.bufferevent* %0, i8* %1) {
%3 = alloca %struct.bufferevent*
%4 = alloca i8*
%5 = alloca %struct.evbuffer*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca %struct.evbuffer*
store %struct.bufferevent* %0, %struct.bufferevent** %3
store i8* %1, i8** %4
%9 = load %struct.bufferevent*, %struct.bufferevent** %3
%10 = call %struct.evbuffer* @bufferevent_get_input(%struct.bufferevent* %9)
store %struct.evbuffer* %10, %struct.evbuffer** %5
%11 = load %struct.evbuffer*, %struct.evbuffer** %5
%12 = call i64 @evbuffer_get_length(%struct.evbuffer* %11)
store i64 %12, i64* %6
%13 = load %struct.evbuffer*, %struct.evbuffer** %5
%14 = load i64, i64* %6
%15 = call i8* @evbuffer_pullup(%struct.evbuffer* %13, i64 %14)
store i8* %15, i8** %7
%16 = load %struct.bufferevent*, %struct.bufferevent** %3
%17 = call %struct.evbuffer* @bufferevent_get_output(%struct.bufferevent* %16)
store %struct.evbuffer* %17, %struct.evbuffer** %8
%18 = load %struct.evbuffer*, %struct.evbuffer** %8
%19 = load i8*, i8** %7
%20 = load i64, i64* %6
%21 = call i32 @evbuffer_add(%struct.evbuffer* %18, i8* %19, i64 %20)
%22 = load %struct.evbuffer*, %struct.evbuffer** %5
%23 = load i64, i64* %6
%24 = call i32 @evbuffer_drain(%struct.evbuffer* %22, i64 %23)
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
%struct.evbuffer = type { i32 }
define void @read_cb(%struct.bufferevent* %0, i8* nocapture readnone %1) {
%3 = tail call %struct.evbuffer* @bufferevent_get_input(%struct.bufferevent* %0)
%4 = tail call i64 @evbuffer_get_length(%struct.evbuffer* %3)
%5 = tail call i8* @evbuffer_pullup(%struct.evbuffer* %3, i64 %4)
%6 = tail call %struct.evbuffer* @bufferevent_get_output(%struct.bufferevent* %0)
%7 = tail call i32 @evbuffer_add(%struct.evbuffer* %6, i8* %5, i64 %4)
%8 = tail call i32 @evbuffer_drain(%struct.evbuffer* %3, i64 %4)
ret void
}