#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;
short BEV_EVENT_TIMEOUT;
int /*<<< orphan*/ bufferevent_free(struct bufferevent *);
int /*<<< orphan*/ perror(char *);
void __attribute__((weak))
client_event_cb(struct bufferevent *bev, short events, void *ctx) {
  if (events & BEV_EVENT_ERROR)
    perror("Error from bufferevent");
  if (events & (BEV_EVENT_EOF | BEV_EVENT_TIMEOUT | BEV_EVENT_ERROR)) {
    bufferevent_free(bev);
  }
}


x86 assembly (clang, -O0):
<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)
movswl -0xa(%rbp),%eax
mov    0x2eae(%rip),%rcx
movswl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     115c <client_event_cb+0x3c>
lea    0xea9(%rip),%rdi
call   1040 <perror@plt>
movswl -0xa(%rbp),%eax
mov    0x2e79(%rip),%rcx
movswl (%rcx),%ecx
mov    0x2e5f(%rip),%rdx
movswl (%rdx),%edx
or     %edx,%ecx
mov    0x2e73(%rip),%rdx
movswl (%rdx),%edx
or     %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1196 <client_event_cb+0x76>
mov    -0x8(%rbp),%rdi
call   1030 <bufferevent_free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_event_cb>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2ec0(%rip),%r14
movzwl (%r14),%eax
test   %bp,%ax
jne    1165 <client_event_cb+0x45>
mov    0x2ea0(%rip),%rcx
mov    0x2e89(%rip),%rdx
movzwl (%rdx),%edx
or     (%rcx),%dx
or     %edx,%eax
test   %bp,%ax
je     1160 <client_event_cb+0x40>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <bufferevent_free@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe94(%rip),%rdi
call   1040 <perror@plt>
movzwl (%r14),%eax
jmp    1139 <client_event_cb+0x19>

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
@BEV_EVENT_ERROR = global i16 0
@.str = [23 x i8] c"Error from bufferevent\00"
@BEV_EVENT_EOF = global i16 0
@BEV_EVENT_TIMEOUT = global i16 0
define weak void @client_event_cb(%struct.bufferevent* %0, i16 signext %1, i8* %2) {
%4 = alloca %struct.bufferevent*
%5 = alloca i16
%6 = alloca i8*
store %struct.bufferevent* %0, %struct.bufferevent** %4
store i16 %1, i16* %5
store i8* %2, i8** %6
%7 = load i16, i16* %5
%8 = sext i16 %7 to i32
%9 = load i16, i16* @BEV_EVENT_ERROR
%10 = sext i16 %9 to i32
%11 = and i32 %8, %10
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %3
%16 = load i16, i16* %5
%17 = sext i16 %16 to i32
%18 = load i16, i16* @BEV_EVENT_EOF
%19 = sext i16 %18 to i32
%20 = load i16, i16* @BEV_EVENT_TIMEOUT
%21 = sext i16 %20 to i32
%22 = or i32 %19, %21
%23 = load i16, i16* @BEV_EVENT_ERROR
%24 = sext i16 %23 to i32
%25 = or i32 %22, %24
%26 = and i32 %17, %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %15
%29 = load %struct.bufferevent*, %struct.bufferevent** %4
%30 = call i32 @bufferevent_free(%struct.bufferevent* %29)
br label %31
31: ; preds = %28, %15
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
@BEV_EVENT_ERROR = global i16 0
@.str = [23 x i8] c"Error from bufferevent\00"
@BEV_EVENT_EOF = global i16 0
@BEV_EVENT_TIMEOUT = global i16 0
define weak void @client_event_cb(%struct.bufferevent* %0, i16 signext %1, i8* %2) {
%4 = load i16, i16* @BEV_EVENT_ERROR
%5 = and i16 %4, %1
%6 = icmp eq i16 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%9 = load i16, i16* @BEV_EVENT_ERROR
br label %10
10: ; preds = %7, %3
%11 = phi i16 [ %9, %7 ], [ %4, %3 ]
%12 = load i16, i16* @BEV_EVENT_EOF
%13 = load i16, i16* @BEV_EVENT_TIMEOUT
%14 = or i16 %13, %12
%15 = or i16 %14, %11
%16 = and i16 %15, %1
%17 = icmp eq i16 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %10
%19 = tail call i32 @bufferevent_free(%struct.bufferevent* %0)
br label %20
20: ; preds = %18, %10
ret void
}