#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_CONNECTED;
short BEV_EVENT_EOF;
short BEV_EVENT_ERROR;
short BEV_EVENT_TIMEOUT;
int EV_READ;
int EV_WRITE;
int /*<<< orphan*/ bufferevent_enable(struct bufferevent *, int);
int /*<<< orphan*/ puts(char *);
void control_event_callback(struct bufferevent *bev, short events, void *ctx) {
  if (events & BEV_EVENT_CONNECTED) {
    puts("Connected\n");
  } else if (events & BEV_EVENT_EOF) {
    puts("Connection closed.\n");
  } else if (events & BEV_EVENT_ERROR) {
    puts("Got an error on the connection ");
  } else if (events & BEV_EVENT_TIMEOUT) {
    bufferevent_enable(bev, EV_WRITE | EV_READ);
    puts("Timeout : Server connection\n");
  }
}


x86 assembly (clang, -O0):
<control_event_callback>:
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    0x2e7e(%rip),%rcx
movswl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1161 <control_event_callback+0x41>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
jmp    1204 <control_event_callback+0xe4>
movswl -0xa(%rbp),%eax
mov    0x2e6c(%rip),%rcx
movswl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     118b <control_event_callback+0x6b>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
jmp    11ff <control_event_callback+0xdf>
movswl -0xa(%rbp),%eax
mov    0x2e5a(%rip),%rcx
movswl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11b5 <control_event_callback+0x95>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
jmp    11fa <control_event_callback+0xda>
movswl -0xa(%rbp),%eax
mov    0x2e08(%rip),%rcx
movswl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11f5 <control_event_callback+0xd5>
mov    -0x8(%rbp),%rdi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
mov    0x2dfe(%rip),%rax
or     (%rax),%esi
call   1040 <bufferevent_enable@plt>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
jmp    11fa <control_event_callback+0xda>
jmp    11ff <control_event_callback+0xdf>
jmp    1204 <control_event_callback+0xe4>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<control_event_callback>:
push   %rax
mov    0x2e98(%rip),%rax
test   %si,(%rax)
je     113a <control_event_callback+0x1a>
lea    0xecc(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>
mov    0x2e97(%rip),%rax
test   %si,(%rax)
je     1153 <control_event_callback+0x33>
lea    0xebe(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>
mov    0x2e96(%rip),%rax
test   %si,(%rax)
je     116c <control_event_callback+0x4c>
lea    0xeb9(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>
mov    0x2e55(%rip),%rax
test   %si,(%rax)
je     119c <control_event_callback+0x7c>
mov    0x2e31(%rip),%rax
mov    0x2e5a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1040 <bufferevent_enable@plt>
lea    0xea9(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>
pop    %rax
ret

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
@BEV_EVENT_CONNECTED = global i16 0
@.str = [11 x i8] c"Connected\0A\00"
@BEV_EVENT_EOF = global i16 0
@.str.1 = [20 x i8] c"Connection closed.\0A\00"
@BEV_EVENT_ERROR = global i16 0
@.str.2 = [32 x i8] c"Got an error on the connection \00"
@BEV_EVENT_TIMEOUT = global i16 0
@EV_WRITE = global i32 0
@EV_READ = global i32 0
@.str.3 = [29 x i8] c"Timeout : Server connection\0A\00"
define void @control_event_callback(%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_CONNECTED
%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 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %50
15: ; preds = %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 = and i32 %17, %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %49
24: ; preds = %15
%25 = load i16, i16* %5
%26 = sext i16 %25 to i32
%27 = load i16, i16* @BEV_EVENT_ERROR
%28 = sext i16 %27 to i32
%29 = and i32 %26, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 @puts(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %48
33: ; preds = %24
%34 = load i16, i16* %5
%35 = sext i16 %34 to i32
%36 = load i16, i16* @BEV_EVENT_TIMEOUT
%37 = sext i16 %36 to i32
%38 = and i32 %35, %37
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %33
%41 = load %struct.bufferevent*, %struct.bufferevent** %4
%42 = load i32, i32* @EV_WRITE
%43 = load i32, i32* @EV_READ
%44 = or i32 %42, %43
%45 = call i32 @bufferevent_enable(%struct.bufferevent* %41, i32 %44)
%46 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %40, %33
br label %48
48: ; preds = %47, %31
br label %49
49: ; preds = %48, %22
br label %50
50: ; preds = %49, %13
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
@BEV_EVENT_CONNECTED = global i16 0
@.str = [11 x i8] c"Connected\0A\00"
@BEV_EVENT_EOF = global i16 0
@.str.1 = [20 x i8] c"Connection closed.\0A\00"
@BEV_EVENT_ERROR = global i16 0
@.str.2 = [32 x i8] c"Got an error on the connection \00"
@BEV_EVENT_TIMEOUT = global i16 0
@EV_WRITE = global i32 0
@EV_READ = global i32 0
@.str.3 = [29 x i8] c"Timeout : Server connection\0A\00"
define void @control_event_callback(%struct.bufferevent* %0, i16 signext %1, i8* nocapture readnone %2) {
%4 = load i16, i16* @BEV_EVENT_CONNECTED
%5 = and i16 %4, %1
%6 = icmp eq i16 %5, 0
br i1 %6, label %7, label %24
7: ; preds = %3
%8 = load i16, i16* @BEV_EVENT_EOF
%9 = and i16 %8, %1
%10 = icmp eq i16 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %7
%12 = load i16, i16* @BEV_EVENT_ERROR
%13 = and i16 %12, %1
%14 = icmp eq i16 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = load i16, i16* @BEV_EVENT_TIMEOUT
%17 = and i16 %16, %1
%18 = icmp eq i16 %17, 0
br i1 %18, label %27, label %19
19: ; preds = %15
%20 = load i32, i32* @EV_WRITE
%21 = load i32, i32* @EV_READ
%22 = or i32 %21, %20
%23 = tail call i32 @bufferevent_enable(%struct.bufferevent* %0, i32 %22)
br label %24
24: ; preds = %11, %7, %3, %19
%25 = phi i8* [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), %19 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %7 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), %11 ]
%26 = tail call i32 @puts(i8* dereferenceable(1) %25)
br label %27
27: ; preds = %24, %15
ret void
}