#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;
short BEV_EVENT_TIMEOUT;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
void xbt_tcp_handshake_error(struct bufferevent *be, short error, void *arg) {
  fprintf(stderr, "error\n");
  if (error & BEV_EVENT_EOF) {
    fprintf(stderr, "connection has been closed");
  } else if (error & BEV_EVENT_ERROR) {
    fprintf(stderr, "check errno");
  } else if (error & BEV_EVENT_TIMEOUT) {
    fprintf(stderr, "must be a timeout event handle");
  }
}


x86 assembly (clang, -O0):
<xbt_tcp_handshake_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    0x2ea2(%rip),%rax
mov    (%rax),%edi
lea    0xec9(%rip),%rsi
call   1030 <fprintf@plt>
movswl -0xa(%rbp),%eax
mov    0x2e99(%rip),%rcx
movswl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     116f <xbt_tcp_handshake_error+0x5f>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xea2(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11da <xbt_tcp_handshake_error+0xca>
movswl -0xa(%rbp),%eax
mov    0x2e76(%rip),%rcx
movswl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11a2 <xbt_tcp_handshake_error+0x92>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11d5 <xbt_tcp_handshake_error+0xc5>
movswl -0xa(%rbp),%eax
mov    0x2e1b(%rip),%rcx
movswl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11d0 <xbt_tcp_handshake_error+0xc0>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11d5 <xbt_tcp_handshake_error+0xc5>
jmp    11da <xbt_tcp_handshake_error+0xca>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xbt_tcp_handshake_error>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    0x2eb3(%rip),%r14
mov    (%r14),%edi
lea    0xed9(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2ead(%rip),%rax
test   %bx,(%rax)
je     1141 <xbt_tcp_handshake_error+0x31>
lea    0xec8(%rip),%rsi
jmp    1169 <xbt_tcp_handshake_error+0x59>
mov    0x2ea8(%rip),%rax
test   %bx,(%rax)
je     1156 <xbt_tcp_handshake_error+0x46>
lea    0xece(%rip),%rsi
jmp    1169 <xbt_tcp_handshake_error+0x59>
mov    0x2e6b(%rip),%rax
test   %bx,(%rax)
je     1178 <xbt_tcp_handshake_error+0x68>
lea    0xec5(%rip),%rsi
mov    (%r14),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
@stderr = global i32 0
@.str = [7 x i8] c"error\0A\00"
@BEV_EVENT_EOF = global i16 0
@.str.1 = [27 x i8] c"connection has been closed\00"
@BEV_EVENT_ERROR = global i16 0
@.str.2 = [12 x i8] c"check errno\00"
@BEV_EVENT_TIMEOUT = global i16 0
@.str.3 = [31 x i8] c"must be a timeout event handle\00"
define void @xbt_tcp_handshake_error(%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 i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = load i16, i16* %5
%10 = sext i16 %9 to i32
%11 = load i16, i16* @BEV_EVENT_EOF
%12 = sext i16 %11 to i32
%13 = and i32 %10, %12
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %40
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 %28
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %39
28: ; preds = %18
%29 = load i16, i16* %5
%30 = sext i16 %29 to i32
%31 = load i16, i16* @BEV_EVENT_TIMEOUT
%32 = sext i16 %31 to i32
%33 = and i32 %30, %32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %35, %28
br label %39
39: ; preds = %38, %25
br label %40
40: ; preds = %39, %15
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
@stderr = global i32 0
@.str = [7 x i8] c"error\0A\00"
@BEV_EVENT_EOF = global i16 0
@.str.1 = [27 x i8] c"connection has been closed\00"
@BEV_EVENT_ERROR = global i16 0
@.str.2 = [12 x i8] c"check errno\00"
@BEV_EVENT_TIMEOUT = global i16 0
@.str.3 = [31 x i8] c"must be a timeout event handle\00"
define void @xbt_tcp_handshake_error(%struct.bufferevent* nocapture readnone %0, i16 signext %1, i8* nocapture readnone %2) {
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = load i16, i16* @BEV_EVENT_EOF
%7 = and i16 %6, %1
%8 = icmp eq i16 %7, 0
br i1 %8, label %9, 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 %13, label %17
13: ; preds = %9
%14 = load i16, i16* @BEV_EVENT_TIMEOUT
%15 = and i16 %14, %1
%16 = icmp eq i16 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %13, %9, %3
%18 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), %3 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %9 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), %13 ]
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* %18)
br label %21
21: ; preds = %17, %13
ret void
}