#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 */
int /*<<< orphan*/ bufferevent_enable(struct bufferevent *, int);
int /*<<< orphan*/ bufferevent_write(struct bufferevent *, unsigned char *,
                                     int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ puts(char *);
void client_event_cb(struct bufferevent *bev, short events, void *ctx) {
  if (events & 0x80) {
    unsigned char tmp = 'A';
    bufferevent_write(bev, &tmp, 1);
  } else if (events & 0x20) {
    puts("Client socket got error!");
    exit(2);
  }
  bufferevent_enable(bev, 0x02);
}


x86 assembly (clang, -O0):
<client_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
and    $0x80,%eax
cmp    $0x0,%eax
je     1184 <client_event_cb+0x44>
movb   $0x41,-0x19(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1060 <bufferevent_write@plt>
jmp    11af <client_event_cb+0x6f>
movswl -0xa(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     11aa <client_event_cb+0x6a>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1050 <exit@plt>
jmp    11af <client_event_cb+0x6f>
mov    -0x8(%rbp),%rdi
mov    $0x2,%esi
call   1040 <bufferevent_enable@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_event_cb>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
test   $0x80,%sil
jne    116b <client_event_cb+0x2b>
movzwl %si,%eax
test   $0x20,%al
je     1182 <client_event_cb+0x42>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1050 <exit@plt>
movb   $0x41,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1060 <bufferevent_write@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1040 <bufferevent_enable@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
@.str = [25 x i8] c"Client socket got error!\00"
define void @client_event_cb(%struct.bufferevent* %0, i16 signext %1, i8* %2) {
%4 = alloca %struct.bufferevent*
%5 = alloca i16
%6 = alloca i8*
%7 = alloca i8
store %struct.bufferevent* %0, %struct.bufferevent** %4
store i16 %1, i16* %5
store i8* %2, i8** %6
%8 = load i16, i16* %5
%9 = sext i16 %8 to i32
%10 = and i32 %9, 128
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %3
store i8 65, i8* %7
%13 = load %struct.bufferevent*, %struct.bufferevent** %4
%14 = call i32 @bufferevent_write(%struct.bufferevent* %13, i8* %7, i32 1)
br label %24
15: ; preds = %3
%16 = load i16, i16* %5
%17 = sext i16 %16 to i32
%18 = and i32 %17, 32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 2)
unreachable
23: ; preds = %15
br label %24
24: ; preds = %23, %12
%25 = load %struct.bufferevent*, %struct.bufferevent** %4
%26 = call i32 @bufferevent_enable(%struct.bufferevent* %25, i32 2)
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
@.str = [25 x i8] c"Client socket got error!\00"
define void @client_event_cb(%struct.bufferevent* %0, i16 signext %1, i8* nocapture readnone %2) {
%4 = alloca i8
%5 = zext i16 %1 to i32
%6 = and i32 %5, 128
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %3
store i8 65, i8* %4
%9 = call i32 @bufferevent_write(%struct.bufferevent* %0, i8* %4, i32 1)
br label %16
10: ; preds = %3
%11 = and i32 %5, 32
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 2)
unreachable
16: ; preds = %10, %8
%17 = call i32 @bufferevent_enable(%struct.bufferevent* %0, i32 2)
ret void
}