#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*/ bufferevent_free(struct bufferevent *);
int /*<<< orphan*/ perror(char *);
void echo_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_ERROR)) {
    bufferevent_free(bev);
  }
}


x86 assembly (clang, -O0):
<echo_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 <echo_event_cb+0x3c>
lea    0xea9(%rip),%rdi
call   1040 <perror@plt>
movswl -0xa(%rbp),%eax
mov    0x2e79(%rip),%rcx
movswl (%rcx),%ecx
mov    0x2e7f(%rip),%rdx
movswl (%rdx),%edx
or     %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     118a <echo_event_cb+0x6a>
mov    -0x8(%rbp),%rdi
call   1030 <bufferevent_free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<echo_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    1159 <echo_event_cb+0x39>
mov    0x2ea0(%rip),%rcx
or     (%rcx),%ax
test   %bp,%ax
je     1154 <echo_event_cb+0x34>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <bufferevent_free@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xea0(%rip),%rdi
call   1040 <perror@plt>
movzwl (%r14),%eax
jmp    1139 <echo_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
define void @echo_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_ERROR
%21 = sext i16 %20 to i32
%22 = or i32 %19, %21
%23 = and i32 %17, %22
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %15
%26 = load %struct.bufferevent*, %struct.bufferevent** %4
%27 = call i32 @bufferevent_free(%struct.bufferevent* %26)
br label %28
28: ; preds = %25, %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
define void @echo_event_cb(%struct.bufferevent* %0, i16 signext %1, i8* nocapture readnone %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 = or i16 %11, %12
%14 = and i16 %13, %1
%15 = icmp eq i16 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = tail call i32 @bufferevent_free(%struct.bufferevent* %0)
br label %18
18: ; preds = %16, %10
ret void
}