#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct event_base {
  int dummy;
};
struct bufferevent {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ BEV_OPT_CLOSE_ON_FREE;
int /*<<< orphan*/
bufferevent_setcb(struct bufferevent *, void (*)(struct bufferevent *, void *),
                  void (*)(struct bufferevent *, void *),
                  void (*)(struct bufferevent *, short, void *), void *);
int /*<<< orphan*/ bufferevent_socket_connect(struct bufferevent *,
                                              struct sockaddr *, int);
struct bufferevent *bufferevent_socket_new(struct event_base *, int,
                                           int /*<<< orphan*/);
int /*<<< orphan*/ event_base_dispatch(struct event_base *);
int /*<<< orphan*/ event_base_free(struct event_base *);
struct event_base *event_base_new();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, unsigned int);
int /*<<< orphan*/ htons(unsigned int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ stderr;
void ev_tcp_request(char *host, unsigned int port,
                    void (*cb_read)(struct bufferevent *be, void *arg),
                    void (*cb_write)(struct bufferevent *be, void *arg),
                    void (*cb_event)(struct bufferevent *be, short events,
                                     void *arg),
                    void *arg) {
  fprintf(stderr, "ip: %s, port: %d", host, port);
  struct event_base *ev_base_tcp = event_base_new();
  struct sockaddr_in addr;
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = inet_addr(host);
  addr.sin_port = htons(port);
  struct bufferevent *be =
      bufferevent_socket_new(ev_base_tcp, -1, BEV_OPT_CLOSE_ON_FREE);
  bufferevent_setcb(be, cb_read, cb_write, cb_event, arg);
  bufferevent_socket_connect(be, (struct sockaddr *)&addr,
                             sizeof(struct sockaddr_in));
  event_base_dispatch(ev_base_tcp);
  event_base_free(ev_base_tcp);
}


x86 assembly (clang, -O0):
<ev_tcp_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe3a(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x0,%al
call   1030 <event_base_new@plt>
mov    %rax,-0x38(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x44(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1050 <bufferevent_socket_new@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   10b0 <bufferevent_setcb@plt>
mov    -0x50(%rbp),%rdi
lea    -0x48(%rbp),%rsi
mov    $0xc,%edx
call   1040 <bufferevent_socket_connect@plt>
mov    -0x38(%rbp),%rdi
call   10a0 <event_base_dispatch@plt>
mov    -0x38(%rbp),%rdi
call   1080 <event_base_free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ev_tcp_request>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1090 <fprintf@plt>
xor    %eax,%eax
call   1030 <event_base_new@plt>
mov    %rax,%rbx
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %r14,%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    %ebp,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    0x2de1(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1050 <bufferevent_socket_new@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    0x10(%rsp),%r8
call   10b0 <bufferevent_setcb@plt>
mov    %rsp,%rsi
mov    %rbp,%rdi
mov    $0xc,%edx
call   1040 <bufferevent_socket_connect@plt>
mov    %rbx,%rdi
call   10a0 <event_base_dispatch@plt>
mov    %rbx,%rdi
call   1080 <event_base_free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
%struct.event_base = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [17 x i8] c"ip: %s, port: %d\00"
@AF_INET = global i32 0
@BEV_OPT_CLOSE_ON_FREE = global i32 0
define void @ev_tcp_request(i8* %0, i32 %1, void (%struct.bufferevent*, i8*)* %2, void (%struct.bufferevent*, i8*)* %3, void (%struct.bufferevent*, i16, i8*)* %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca void (%struct.bufferevent*, i8*)*
%10 = alloca void (%struct.bufferevent*, i8*)*
%11 = alloca void (%struct.bufferevent*, i16, i8*)*
%12 = alloca i8*
%13 = alloca %struct.event_base*
%14 = alloca %struct.sockaddr_in
%15 = alloca %struct.bufferevent*
store i8* %0, i8** %7
store i32 %1, i32* %8
store void (%struct.bufferevent*, i8*)* %2, void (%struct.bufferevent*, i8*)** %9
store void (%struct.bufferevent*, i8*)* %3, void (%struct.bufferevent*, i8*)** %10
store void (%struct.bufferevent*, i16, i8*)* %4, void (%struct.bufferevent*, i16, i8*)** %11
store i8* %5, i8** %12
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %7
%18 = load i32, i32* %8
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %17, i32 %18)
%20 = call %struct.event_base* (...) @event_base_new()
store %struct.event_base* %20, %struct.event_base** %13
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 2
store i32 %21, i32* %22
%23 = load i8*, i8** %7
%24 = call i32 @inet_addr(i8* %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = load i32, i32* %8
%28 = call i32 @htons(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 0
store i32 %28, i32* %29
%30 = load %struct.event_base*, %struct.event_base** %13
%31 = load i32, i32* @BEV_OPT_CLOSE_ON_FREE
%32 = call %struct.bufferevent* @bufferevent_socket_new(%struct.event_base* %30, i32 -1, i32 %31)
store %struct.bufferevent* %32, %struct.bufferevent** %15
%33 = load %struct.bufferevent*, %struct.bufferevent** %15
%34 = load void (%struct.bufferevent*, i8*)*, void (%struct.bufferevent*, i8*)** %9
%35 = load void (%struct.bufferevent*, i8*)*, void (%struct.bufferevent*, i8*)** %10
%36 = load void (%struct.bufferevent*, i16, i8*)*, void (%struct.bufferevent*, i16, i8*)** %11
%37 = load i8*, i8** %12
%38 = call i32 @bufferevent_setcb(%struct.bufferevent* %33, void (%struct.bufferevent*, i8*)* %34, void (%struct.bufferevent*, i8*)* %35, void (%struct.bufferevent*, i16, i8*)* %36, i8* %37)
%39 = load %struct.bufferevent*, %struct.bufferevent** %15
%40 = bitcast %struct.sockaddr_in* %14 to %struct.sockaddr*
%41 = call i32 @bufferevent_socket_connect(%struct.bufferevent* %39, %struct.sockaddr* %40, i32 12)
%42 = load %struct.event_base*, %struct.event_base** %13
%43 = call i32 @event_base_dispatch(%struct.event_base* %42)
%44 = load %struct.event_base*, %struct.event_base** %13
%45 = call i32 @event_base_free(%struct.event_base* %44)
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.event_base = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [17 x i8] c"ip: %s, port: %d\00"
@AF_INET = global i32 0
@BEV_OPT_CLOSE_ON_FREE = global i32 0
define void @ev_tcp_request(i8* %0, i32 %1, void (%struct.bufferevent*, i8*)* %2, void (%struct.bufferevent*, i8*)* %3, void (%struct.bufferevent*, i16, i8*)* %4, i8* %5) {
%7 = alloca %struct.sockaddr_in
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%10 = tail call %struct.event_base* (...) @event_base_new()
%11 = bitcast %struct.sockaddr_in* %7 to i8*
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2
store i32 %12, i32* %13
%14 = tail call i32 @inet_addr(i8* %0)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1, i32 0
store i32 %14, i32* %15
%16 = tail call i32 @htons(i32 %1)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* @BEV_OPT_CLOSE_ON_FREE
%19 = tail call %struct.bufferevent* @bufferevent_socket_new(%struct.event_base* %10, i32 -1, i32 %18)
%20 = tail call i32 @bufferevent_setcb(%struct.bufferevent* %19, void (%struct.bufferevent*, i8*)* %2, void (%struct.bufferevent*, i8*)* %3, void (%struct.bufferevent*, i16, i8*)* %4, i8* %5)
%21 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%22 = call i32 @bufferevent_socket_connect(%struct.bufferevent* %19, %struct.sockaddr* %21, i32 12)
%23 = call i32 @event_base_dispatch(%struct.event_base* %10)
%24 = call i32 @event_base_free(%struct.event_base* %10)
ret void
}