#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*/ bufferevent_event_cb;
typedef int /*<<< orphan*/ bufferevent_data_cb;

/* Variables and functions */
int /*<<< orphan*/ bufferevent_free(struct bufferevent *);
int /*<<< orphan*/ bufferevent_get_output(struct bufferevent *);
int /*<<< orphan*/ bufferevent_setcb(struct bufferevent *, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/, int /*<<< orphan*/,
                                     int /*<<< orphan*/ *);
scalar_t__ evbuffer_get_length(int /*<<< orphan*/);
void BufferEventFreeOnWrite(struct bufferevent *In) {
  if (evbuffer_get_length(bufferevent_get_output(In)))
    bufferevent_setcb(In, NULL, (bufferevent_data_cb)bufferevent_free,
                      (bufferevent_event_cb)bufferevent_free, NULL);
  else
    bufferevent_free(In);
}


x86 assembly (clang, -O0):
<BufferEventFreeOnWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <bufferevent_get_output@plt>
mov    %eax,%edi
call   1040 <evbuffer_get_length@plt>
cmp    $0x0,%rax
je     1177 <BufferEventFreeOnWrite+0x47>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%r8d
mov    0x2e82(%rip),%rax
mov    %eax,%ecx
mov    %r8,%rsi
mov    %ecx,%edx
call   1050 <bufferevent_setcb@plt>
jmp    1180 <BufferEventFreeOnWrite+0x50>
mov    -0x8(%rbp),%rdi
call   1060 <bufferevent_free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BufferEventFreeOnWrite>:
push   %rbx
mov    %rdi,%rbx
call   1030 <bufferevent_get_output@plt>
mov    %eax,%edi
call   1040 <evbuffer_get_length@plt>
test   %rax,%rax
je     115b <BufferEventFreeOnWrite+0x2b>
mov    0x2e9d(%rip),%ecx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ecx,%edx
xor    %r8d,%r8d
pop    %rbx
jmp    1050 <bufferevent_setcb@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1060 <bufferevent_free@plt>

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
define void @BufferEventFreeOnWrite(%struct.bufferevent* %0) {
%2 = alloca %struct.bufferevent*
store %struct.bufferevent* %0, %struct.bufferevent** %2
%3 = load %struct.bufferevent*, %struct.bufferevent** %2
%4 = call i32 @bufferevent_get_output(%struct.bufferevent* %3)
%5 = call i64 @evbuffer_get_length(i32 %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load %struct.bufferevent*, %struct.bufferevent** %2
%9 = call i32 @bufferevent_setcb(%struct.bufferevent* %8, i32* null, i32 ptrtoint (i32 (%struct.bufferevent*)* @bufferevent_free to i32), i32 ptrtoint (i32 (%struct.bufferevent*)* @bufferevent_free to i32), i32* null)
br label %13
10: ; preds = %1
%11 = load %struct.bufferevent*, %struct.bufferevent** %2
%12 = call i32 @bufferevent_free(%struct.bufferevent* %11)
br label %13
13: ; preds = %10, %7
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
define void @BufferEventFreeOnWrite(%struct.bufferevent* %0) {
%2 = tail call i32 @bufferevent_get_output(%struct.bufferevent* %0)
%3 = tail call i64 @evbuffer_get_length(i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 @bufferevent_setcb(%struct.bufferevent* %0, i32* null, i32 ptrtoint (i32 (%struct.bufferevent*)* @bufferevent_free to i32), i32 ptrtoint (i32 (%struct.bufferevent*)* @bufferevent_free to i32), i32* null)
br label %9
7: ; preds = %1
%8 = tail call i32 @bufferevent_free(%struct.bufferevent* %0)
br label %9
9: ; preds = %7, %5
ret void
}