#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 evbuffer {
  int dummy;
};
struct bufferevent {
  int dummy;
};

/* Variables and functions */
short BEV_EVENT_CONNECTED;
int /*<<< orphan*/ bufferevent_free(struct bufferevent *);
struct evbuffer *bufferevent_get_output(struct bufferevent *);
int /*<<< orphan*/ evbuffer_add(struct evbuffer *, char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
void eventcb(struct bufferevent *bev, short events, void *ptr) {
  int *i = ptr;
  if (events & BEV_EVENT_CONNECTED) {
    struct evbuffer *output = bufferevent_get_output(bev);
    evbuffer_add(output, "init", 4);
    printf("connected %d\n", *i);
  } else {
    fprintf(stderr, "couldn't connect %d\n", *i);
    bufferevent_free(bev);
    free(ptr);
  }
}


x86 assembly (clang, -O0):
<eventcb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movswl -0xa(%rbp),%eax
mov    0x2e4e(%rip),%rcx
movswl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11d1 <eventcb+0x71>
mov    -0x8(%rbp),%rdi
call   1050 <bufferevent_get_output@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe50(%rip),%rsi
mov    $0x4,%edx
call   1070 <evbuffer_add@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdi
call   1040 <printf@plt>
jmp    11fe <eventcb+0x9e>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
lea    0xe2c(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1080 <bufferevent_free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eventcb>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
mov    0x2e67(%rip),%rax
test   %si,(%rax)
je     11a8 <eventcb+0x48>
mov    %rbx,%rdi
call   1050 <bufferevent_get_output@plt>
lea    0xe7b(%rip),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1070 <evbuffer_add@plt>
mov    (%r14),%esi
lea    0xe69(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%edx
lea    0xe58(%rip),%rsi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <bufferevent_free@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
%struct.evbuffer = type { i32 }
@BEV_EVENT_CONNECTED = global i16 0
@.str = [5 x i8] c"init\00"
@.str.1 = [14 x i8] c"connected %d\0A\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"couldn't connect %d\0A\00"
define void @eventcb(%struct.bufferevent* %0, i16 signext %1, i8* %2) {
%4 = alloca %struct.bufferevent*
%5 = alloca i16
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca %struct.evbuffer*
store %struct.bufferevent* %0, %struct.bufferevent** %4
store i16 %1, i16* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = bitcast i8* %9 to i32*
store i32* %10, i32** %7
%11 = load i16, i16* %5
%12 = sext i16 %11 to i32
%13 = load i16, i16* @BEV_EVENT_CONNECTED
%14 = sext i16 %13 to i32
%15 = and i32 %12, %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %3
%18 = load %struct.bufferevent*, %struct.bufferevent** %4
%19 = call %struct.evbuffer* @bufferevent_get_output(%struct.bufferevent* %18)
store %struct.evbuffer* %19, %struct.evbuffer** %8
%20 = load %struct.evbuffer*, %struct.evbuffer** %8
%21 = call i32 @evbuffer_add(%struct.evbuffer* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%22 = load i32*, i32** %7
%23 = load i32, i32* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %34
25: ; preds = %3
%26 = load i32, i32* @stderr
%27 = load i32*, i32** %7
%28 = load i32, i32* %27
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load %struct.bufferevent*, %struct.bufferevent** %4
%31 = call i32 @bufferevent_free(%struct.bufferevent* %30)
%32 = load i8*, i8** %6
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %25, %17
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
%struct.evbuffer = type { i32 }
@BEV_EVENT_CONNECTED = global i16 0
@.str = [5 x i8] c"init\00"
@.str.1 = [14 x i8] c"connected %d\0A\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"couldn't connect %d\0A\00"
define void @eventcb(%struct.bufferevent* %0, i16 signext %1, i8* nocapture %2) {
%4 = bitcast i8* %2 to i32*
%5 = load i16, i16* @BEV_EVENT_CONNECTED
%6 = and i16 %5, %1
%7 = icmp eq i16 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = tail call %struct.evbuffer* @bufferevent_get_output(%struct.bufferevent* %0)
%10 = tail call i32 @evbuffer_add(%struct.evbuffer* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%11 = load i32, i32* %4
%12 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %19
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = load i32, i32* %4
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = tail call i32 @bufferevent_free(%struct.bufferevent* %0)
%18 = tail call i32 @free(i8* %2)
br label %19
19: ; preds = %13, %8
ret void
}