#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 */
short BEV_EVENT_EOF;
short BEV_EVENT_ERROR;
int /*<<< orphan*/ clean_useless_client();
int /*<<< orphan*/ free(void *);
void *xkcp_tcp_event_cb(struct bufferevent *, short, void *);
void tcp_client_event_cb(struct bufferevent *bev, short what, void *ctx) {
  void *puser = xkcp_tcp_event_cb(bev, what, ctx);
  if (puser)
    free(puser);
  if (what & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
    clean_useless_client();
  }
}


x86 assembly (clang, -O0):
<tcp_client_event_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xa(%rbp),%ax
mov    -0x18(%rbp),%rdx
movswl %ax,%esi
call   1050 <xkcp_tcp_event_cb@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1173 <tcp_client_event_cb+0x43>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movswl -0xa(%rbp),%eax
mov    0x2e62(%rip),%rcx
movswl (%rcx),%ecx
mov    0x2e68(%rip),%rdx
movswl (%rdx),%edx
or     %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     119f <tcp_client_event_cb+0x6f>
mov    $0x0,%al
call   1040 <clean_useless_client@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcp_client_event_cb>:
push   %rbx
mov    %esi,%ebx
call   1050 <xkcp_tcp_event_cb@plt>
test   %rax,%rax
je     1145 <tcp_client_event_cb+0x15>
mov    %rax,%rdi
call   1030 <free@plt>
mov    0x2e94(%rip),%rax
mov    0x2e9d(%rip),%rcx
movzwl (%rcx),%ecx
or     (%rax),%cx
test   %bx,%cx
je     1166 <tcp_client_event_cb+0x36>
xor    %eax,%eax
pop    %rbx
jmp    1040 <clean_useless_client@plt>
pop    %rbx
ret

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
@BEV_EVENT_EOF = global i16 0
@BEV_EVENT_ERROR = global i16 0
define void @tcp_client_event_cb(%struct.bufferevent* %0, i16 signext %1, i8* %2) {
%4 = alloca %struct.bufferevent*
%5 = alloca i16
%6 = alloca i8*
%7 = alloca i8*
store %struct.bufferevent* %0, %struct.bufferevent** %4
store i16 %1, i16* %5
store i8* %2, i8** %6
%8 = load %struct.bufferevent*, %struct.bufferevent** %4
%9 = load i16, i16* %5
%10 = load i8*, i8** %6
%11 = call i8* @xkcp_tcp_event_cb(%struct.bufferevent* %8, i16 signext %9, i8* %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i8*, i8** %7
%16 = call i32 @free(i8* %15)
br label %17
17: ; preds = %14, %3
%18 = load i16, i16* %5
%19 = sext i16 %18 to i32
%20 = load i16, i16* @BEV_EVENT_EOF
%21 = sext i16 %20 to i32
%22 = load i16, i16* @BEV_EVENT_ERROR
%23 = sext i16 %22 to i32
%24 = or i32 %21, %23
%25 = and i32 %19, %24
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %17
%28 = call i32 (...) @clean_useless_client()
br label %29
29: ; preds = %27, %17
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
@BEV_EVENT_EOF = global i16 0
@BEV_EVENT_ERROR = global i16 0
define void @tcp_client_event_cb(%struct.bufferevent* %0, i16 signext %1, i8* %2) {
%4 = tail call i8* @xkcp_tcp_event_cb(%struct.bufferevent* %0, i16 signext %1, i8* %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @free(i8* %4)
br label %8
8: ; preds = %6, %3
%9 = load i16, i16* @BEV_EVENT_EOF
%10 = load i16, i16* @BEV_EVENT_ERROR
%11 = or i16 %10, %9
%12 = and i16 %11, %1
%13 = icmp eq i16 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %8
%15 = tail call i32 (...) @clean_useless_client()
br label %16
16: ; preds = %14, %8
ret void
}