#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");
    bufferevent_free(bev);
  }
  if (events & BEV_EVENT_EOF) {
    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     1165 <echo_event_cb+0x45>
lea    0xea9(%rip),%rdi
call   1040 <perror@plt>
mov    -0x8(%rbp),%rdi
call   1030 <bufferevent_free@plt>
movswl -0xa(%rbp),%eax
mov    0x2e70(%rip),%rcx
movswl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1187 <echo_event_cb+0x67>
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   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2ec1(%rip),%rax
test   %bp,(%rax)
jne    1155 <echo_event_cb+0x35>
mov    0x2ea5(%rip),%rax
test   %bp,(%rax)
je     114e <echo_event_cb+0x2e>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <bufferevent_free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xea4(%rip),%rdi
call   1040 <perror@plt>
mov    %rbx,%rdi
call   1030 <bufferevent_free@plt>
jmp    1134 <echo_event_cb+0x14>

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
@BEV_EVENT_ERROR = global i16 0
@.str = [6 x i8] c"Error\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 %17
13: ; preds = %3
%14 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = load %struct.bufferevent*, %struct.bufferevent** %4
%16 = call i32 @bufferevent_free(%struct.bufferevent* %15)
br label %17
17: ; preds = %13, %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 = and i32 %19, %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load %struct.bufferevent*, %struct.bufferevent** %4
%26 = call i32 @bufferevent_free(%struct.bufferevent* %25)
br label %27
27: ; preds = %24, %17
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
@BEV_EVENT_ERROR = global i16 0
@.str = [6 x i8] c"Error\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 ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @bufferevent_free(%struct.bufferevent* %0)
br label %10
10: ; preds = %7, %3
%11 = load i16, i16* @BEV_EVENT_EOF
%12 = and i16 %11, %1
%13 = icmp eq i16 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @bufferevent_free(%struct.bufferevent* %0)
br label %16
16: ; preds = %14, %10
ret void
}