#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*/ exit(int /*<<< orphan*/);
void quit_sent_event(struct bufferevent *buf, void *arg) {
  struct evbuffer *output = bufferevent_get_output(buf);
  if (evbuffer_get_length(output) == 0) {
    bufferevent_free(buf);
    int *count = (int *)arg;
    if (--(*count) == 0)
      exit(0);
  };
}


x86 assembly (clang, -O0):
<quit_sent_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <bufferevent_get_output@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <evbuffer_get_length@plt>
cmp    $0x0,%rax
jne    11a1 <quit_sent_event+0x61>
mov    -0x8(%rbp),%rdi
call   1050 <bufferevent_free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    (%rcx),%eax
add    $0xffffffff,%eax
mov    %eax,(%rcx)
cmp    $0x0,%eax
jne    119c <quit_sent_event+0x5c>
xor    %edi,%edi
call   1060 <exit@plt>
jmp    11a1 <quit_sent_event+0x61>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quit_sent_event>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <bufferevent_get_output@plt>
mov    %rax,%rdi
call   1040 <evbuffer_get_length@plt>
test   %rax,%rax
jne    116a <quit_sent_event+0x2a>
mov    %rbx,%rdi
call   1050 <bufferevent_free@plt>
addl   $0xffffffff,(%r14)
je     1172 <quit_sent_event+0x32>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
%struct.evbuffer = type { i32 }
define void @quit_sent_event(%struct.bufferevent* %0, i8* %1) {
%3 = alloca %struct.bufferevent*
%4 = alloca i8*
%5 = alloca %struct.evbuffer*
%6 = alloca i32*
store %struct.bufferevent* %0, %struct.bufferevent** %3
store i8* %1, i8** %4
%7 = load %struct.bufferevent*, %struct.bufferevent** %3
%8 = call %struct.evbuffer* @bufferevent_get_output(%struct.bufferevent* %7)
store %struct.evbuffer* %8, %struct.evbuffer** %5
%9 = load %struct.evbuffer*, %struct.evbuffer** %5
%10 = call i64 @evbuffer_get_length(%struct.evbuffer* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %2
%13 = load %struct.bufferevent*, %struct.bufferevent** %3
%14 = call i32 @bufferevent_free(%struct.bufferevent* %13)
%15 = load i8*, i8** %4
%16 = bitcast i8* %15 to i32*
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = load i32, i32* %17
%19 = add nsw i32 %18, -1
store i32 %19, i32* %17
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %12
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %12
br label %24
24: ; preds = %23, %2
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
%struct.evbuffer = type { i32 }
define void @quit_sent_event(%struct.bufferevent* %0, i8* nocapture %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 %14
6: ; preds = %2
%7 = tail call i32 @bufferevent_free(%struct.bufferevent* %0)
%8 = bitcast i8* %1 to i32*
%9 = load i32, i32* %8
%10 = add nsw i32 %9, -1
store i32 %10, i32* %8
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %6, %2
ret void
}