#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 */
int /*<<< orphan*/ bufferevent_free(struct bufferevent *);
struct evbuffer *bufferevent_get_output(struct bufferevent *);
scalar_t__ evbuffer_get_length(struct evbuffer *);
int /*<<< orphan*/ printf(char *);
void conn_writecb(struct bufferevent *bev, void *user_data) {
  struct evbuffer *output = bufferevent_get_output(bev);
  if (evbuffer_get_length(output) == 0) {
    printf("flushed answer\n");
    bufferevent_free(bev);
  }
}


x86 assembly (clang, -O0):
<conn_writecb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <bufferevent_get_output@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <evbuffer_get_length@plt>
cmp    $0x0,%rax
jne    1185 <conn_writecb+0x45>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <bufferevent_free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conn_writecb>:
push   %rbx
mov    %rdi,%rbx
call   1040 <bufferevent_get_output@plt>
mov    %rax,%rdi
call   1050 <evbuffer_get_length@plt>
test   %rax,%rax
je     1158 <conn_writecb+0x18>
pop    %rbx
ret
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1060 <bufferevent_free@plt>

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
%struct.evbuffer = type { i32 }
@.str = [16 x i8] c"flushed answer\0A\00"
define void @conn_writecb(%struct.bufferevent* %0, i8* %1) {
%3 = alloca %struct.bufferevent*
%4 = alloca i8*
%5 = alloca %struct.evbuffer*
store %struct.bufferevent* %0, %struct.bufferevent** %3
store i8* %1, i8** %4
%6 = load %struct.bufferevent*, %struct.bufferevent** %3
%7 = call %struct.evbuffer* @bufferevent_get_output(%struct.bufferevent* %6)
store %struct.evbuffer* %7, %struct.evbuffer** %5
%8 = load %struct.evbuffer*, %struct.evbuffer** %5
%9 = call i64 @evbuffer_get_length(%struct.evbuffer* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%13 = load %struct.bufferevent*, %struct.bufferevent** %3
%14 = call i32 @bufferevent_free(%struct.bufferevent* %13)
br label %15
15: ; preds = %11, %2
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
%struct.evbuffer = type { i32 }
@str = [15 x i8] c"flushed answer\00"
define void @conn_writecb(%struct.bufferevent* %0, i8* nocapture readnone %1) {
%3 = tail call %struct.evbuffer* @bufferevent_get_output(%struct.bufferevent* %0)
%4 = tail call i64 @evbuffer_get_length(%struct.evbuffer* %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @bufferevent_free(%struct.bufferevent* %0)
br label %9
9: ; preds = %6, %2
ret void
}