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

/* Variables and functions */
int /*<<< orphan*/ bufferevent_get_input(struct bufferevent *);
int /*<<< orphan*/ bufferevent_read(struct bufferevent *, unsigned char *, int);
int /*<<< orphan*/ bufferevent_write(struct bufferevent *, unsigned char *,
                                     int);
scalar_t__ evbuffer_get_length(int /*<<< orphan*/);
void server_read_cb(struct bufferevent *bev, void *ctx) {
  while (evbuffer_get_length(bufferevent_get_input(bev))) {
    unsigned char tmp;
    bufferevent_read(bev, &tmp, 1);
    bufferevent_write(bev, &tmp, 1);
  }
}


x86 assembly (clang, -O0):
<server_read_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <bufferevent_get_input@plt>
mov    %eax,%edi
call   1050 <evbuffer_get_length@plt>
cmp    $0x0,%rax
je     1193 <server_read_cb+0x53>
mov    -0x8(%rbp),%rdi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <bufferevent_read@plt>
mov    -0x8(%rbp),%rdi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1060 <bufferevent_write@plt>
jmp    1150 <server_read_cb+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server_read_cb>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <bufferevent_get_input@plt>
mov    %eax,%edi
call   1050 <evbuffer_get_length@plt>
test   %rax,%rax
je     1194 <server_read_cb+0x54>
lea    0x7(%rsp),%r14
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <bufferevent_read@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1060 <bufferevent_write@plt>
mov    %rbx,%rdi
call   1040 <bufferevent_get_input@plt>
mov    %eax,%edi
call   1050 <evbuffer_get_length@plt>
test   %rax,%rax
jne    1160 <server_read_cb+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
define void @server_read_cb(%struct.bufferevent* %0, i8* %1) {
%3 = alloca %struct.bufferevent*
%4 = alloca i8*
%5 = alloca i8
store %struct.bufferevent* %0, %struct.bufferevent** %3
store i8* %1, i8** %4
br label %6
6: ; preds = %11, %2
%7 = load %struct.bufferevent*, %struct.bufferevent** %3
%8 = call i32 @bufferevent_get_input(%struct.bufferevent* %7)
%9 = call i64 @evbuffer_get_length(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %6
%12 = load %struct.bufferevent*, %struct.bufferevent** %3
%13 = call i32 @bufferevent_read(%struct.bufferevent* %12, i8* %5, i32 1)
%14 = load %struct.bufferevent*, %struct.bufferevent** %3
%15 = call i32 @bufferevent_write(%struct.bufferevent* %14, i8* %5, i32 1)
br label %6
16: ; preds = %6
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
define void @server_read_cb(%struct.bufferevent* %0, i8* nocapture readnone %1) {
%3 = alloca i8
%4 = call i32 @bufferevent_get_input(%struct.bufferevent* %0)
%5 = call i64 @evbuffer_get_length(i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %2, %7
%8 = call i32 @bufferevent_read(%struct.bufferevent* %0, i8* %3, i32 1)
%9 = call i32 @bufferevent_write(%struct.bufferevent* %0, i8* %3, i32 1)
%10 = call i32 @bufferevent_get_input(%struct.bufferevent* %0)
%11 = call i64 @evbuffer_get_length(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %7
13: ; preds = %7, %2
ret void
}