#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 my_param {
  int dummy;
};
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*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ t01_log(int, char *, ...);
int /*<<< orphan*/ zfree(struct my_param *);
void server_on_error(struct bufferevent *bev, short events, void *arg) {
  struct my_param *param = (struct my_param *)arg;
  if (events & BEV_EVENT_EOF) {
    t01_log(3, "Connection closed");
  } else if (events & BEV_EVENT_ERROR) {
    t01_log(3, "Got an error on the connection: %s", strerror(errno));
  }
  bufferevent_free(bev);
  zfree(param);
}


x86 assembly (clang, -O0):
<server_on_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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    0x2e76(%rip),%rcx
movswl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1190 <server_on_error+0x50>
mov    $0x3,%edi
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   1030 <t01_log@plt>
jmp    11d1 <server_on_error+0x91>
movswl -0xa(%rbp),%eax
mov    0x2e55(%rip),%rcx
movswl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11cc <server_on_error+0x8c>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%edx
mov    $0x3,%edi
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1030 <t01_log@plt>
jmp    11d1 <server_on_error+0x91>
mov    -0x8(%rbp),%rdi
call   1040 <bufferevent_free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <zfree@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server_on_error>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
mov    0x2e8f(%rip),%rax
test   %si,(%rax)
je     116b <server_on_error+0x2b>
lea    0xea3(%rip),%rsi
mov    $0x3,%edi
xor    %eax,%eax
call   1030 <t01_log@plt>
jmp    119a <server_on_error+0x5a>
mov    0x2e7e(%rip),%rax
test   %si,(%rax)
je     119a <server_on_error+0x5a>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe86(%rip),%rsi
mov    $0x3,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <t01_log@plt>
mov    %rbx,%rdi
call   1040 <bufferevent_free@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <zfree@plt>

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
%struct.my_param = type { i32 }
@BEV_EVENT_EOF = global i16 0
@.str = [18 x i8] c"Connection closed\00"
@BEV_EVENT_ERROR = global i16 0
@.str.1 = [35 x i8] c"Got an error on the connection: %s\00"
@errno = global i32 0
define void @server_on_error(%struct.bufferevent* %0, i16 signext %1, i8* %2) {
%4 = alloca %struct.bufferevent*
%5 = alloca i16
%6 = alloca i8*
%7 = alloca %struct.my_param*
store %struct.bufferevent* %0, %struct.bufferevent** %4
store i16 %1, i16* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = bitcast i8* %8 to %struct.my_param*
store %struct.my_param* %9, %struct.my_param** %7
%10 = load i16, i16* %5
%11 = sext i16 %10 to i32
%12 = load i16, i16* @BEV_EVENT_EOF
%13 = sext i16 %12 to i32
%14 = and i32 %11, %13
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = call i32 (i32, i8*, ...) @t01_log(i32 3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %30
18: ; preds = %3
%19 = load i16, i16* %5
%20 = sext i16 %19 to i32
%21 = load i16, i16* @BEV_EVENT_ERROR
%22 = sext i16 %21 to i32
%23 = and i32 %20, %22
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = load i32, i32* @errno
%27 = call i32 @strerror(i32 %26)
%28 = call i32 (i32, i8*, ...) @t01_log(i32 3, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %25, %18
br label %30
30: ; preds = %29, %16
%31 = load %struct.bufferevent*, %struct.bufferevent** %4
%32 = call i32 @bufferevent_free(%struct.bufferevent* %31)
%33 = load %struct.my_param*, %struct.my_param** %7
%34 = call i32 @zfree(%struct.my_param* %33)
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
%struct.my_param = type { i32 }
@BEV_EVENT_EOF = global i16 0
@.str = [18 x i8] c"Connection closed\00"
@BEV_EVENT_ERROR = global i16 0
@.str.1 = [35 x i8] c"Got an error on the connection: %s\00"
@errno = global i32 0
define void @server_on_error(%struct.bufferevent* %0, i16 signext %1, i8* %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 (i32, i8*, ...) @t01_log(i32 3, i8* getelementptr inbounds ([18 x i8], [18 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 i32 @strerror(i32 %14)
%16 = tail call i32 (i32, i8*, ...) @t01_log(i32 3, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %9, %13, %7
%18 = bitcast i8* %2 to %struct.my_param*
%19 = tail call i32 @bufferevent_free(%struct.bufferevent* %0)
%20 = tail call i32 @zfree(%struct.my_param* %18)
ret void
}