#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*/ errno;
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
void conn_eventcb(struct bufferevent *bev, short events, void *user_data) {
  if (events & BEV_EVENT_EOF) {
    printf("Connection closed.\n");
  } else if (events & BEV_EVENT_ERROR) {
    printf("Got an error on the connection: %s\n", strerror(errno));
  }
  bufferevent_free(bev);
}


x86 assembly (clang, -O0):
<conn_eventcb>:
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    0x2e8e(%rip),%rcx
movswl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1173 <conn_eventcb+0x43>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b0 <conn_eventcb+0x80>
movswl -0xa(%rbp),%eax
mov    0x2e72(%rip),%rcx
movswl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11ab <conn_eventcb+0x7b>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b0 <conn_eventcb+0x80>
mov    -0x8(%rbp),%rdi
call   1040 <bufferevent_free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conn_eventcb>:
push   %rbx
mov    %rdi,%rbx
mov    0x2e95(%rip),%rax
test   %si,(%rax)
je     115e <conn_eventcb+0x1e>
lea    0xecd(%rip),%rdi
call   1030 <puts@plt>
jmp    1189 <conn_eventcb+0x49>
mov    0x2e8b(%rip),%rax
test   %si,(%rax)
je     1189 <conn_eventcb+0x49>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe81(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <bufferevent_free@plt>

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
@BEV_EVENT_EOF = global i16 0
@.str = [20 x i8] c"Connection closed.\0A\00"
@BEV_EVENT_ERROR = global i16 0
@.str.1 = [36 x i8] c"Got an error on the connection: %s\0A\00"
@errno = global i32 0
define void @conn_eventcb(%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_EOF
%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 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %27
15: ; preds = %3
%16 = load i16, i16* %5
%17 = sext i16 %16 to i32
%18 = load i16, i16* @BEV_EVENT_ERROR
%19 = sext i16 %18 to i32
%20 = and i32 %17, %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %22, %15
br label %27
27: ; preds = %26, %13
%28 = load %struct.bufferevent*, %struct.bufferevent** %4
%29 = call i32 @bufferevent_free(%struct.bufferevent* %28)
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
@BEV_EVENT_EOF = global i16 0
@BEV_EVENT_ERROR = global i16 0
@.str.1 = [36 x i8] c"Got an error on the connection: %s\0A\00"
@errno = global i32 0
@str = [19 x i8] c"Connection closed.\00"
define void @conn_eventcb(%struct.bufferevent* %0, i16 signext %1, i8* nocapture readnone %2) {
%4 = load i16, i16* @BEV_EVENT_EOF
%5 = and i16 %4, %1
%6 = icmp eq i16 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %17
9: ; preds = %3
%10 = load i16, i16* @BEV_EVENT_ERROR
%11 = and i16 %10, %1
%12 = icmp eq i16 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %9, %13, %7
%18 = tail call i32 @bufferevent_free(%struct.bufferevent* %0)
ret void
}