#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 timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct event_base {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ event_base_dispatch(struct event_base *);
int /*<<< orphan*/ event_base_free(struct event_base *);
int /*<<< orphan*/ event_base_loopexit(struct event_base *, struct timeval *);
struct event_base *event_base_new();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *host;
  int port;
  struct event_base *base;
  struct timeval two_sec;
  two_sec.tv_sec = 2;
  two_sec.tv_usec = 0;
  base = event_base_new();
  if (!base) {
    fprintf(stderr, "Error creating event_base!\n");
    exit(-1);
  }
  printf("Starting event loop\n");
  event_base_loopexit(base, &two_sec);
  event_base_dispatch(base);
  event_base_free(base);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <event_base_new@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ca <main+0x5a>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    0xe4b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <event_base_loopexit@plt>
mov    -0x28(%rbp),%rdi
call   1080 <event_base_dispatch@plt>
mov    -0x28(%rbp),%rdi
call   1060 <event_base_free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x2,(%rsp)
movq   $0x0,0x8(%rsp)
xor    %eax,%eax
call   1030 <event_base_new@plt>
test   %rax,%rax
je     11c3 <main+0x53>
mov    %rax,%rbx
lea    0xe81(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <event_base_loopexit@plt>
mov    %rbx,%rdi
call   1080 <event_base_dispatch@plt>
mov    %rbx,%rdi
call   1060 <event_base_free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.event_base = type { i32 }
%struct.timeval = type { i32, i64 }
@stderr = global i32 0
@.str = [28 x i8] c"Error creating event_base!\0A\00"
@.str.1 = [21 x i8] c"Starting event loop\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.event_base*
%9 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
store i32 2, i32* %10
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
store i64 0, i64* %11
%12 = call %struct.event_base* (...) @event_base_new()
store %struct.event_base* %12, %struct.event_base** %8
%13 = load %struct.event_base*, %struct.event_base** %8
%14 = icmp ne %struct.event_base* %13, null
br i1 %14, label %19, label %15
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %2
%20 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%21 = load %struct.event_base*, %struct.event_base** %8
%22 = call i32 @event_base_loopexit(%struct.event_base* %21, %struct.timeval* %9)
%23 = load %struct.event_base*, %struct.event_base** %8
%24 = call i32 @event_base_dispatch(%struct.event_base* %23)
%25 = load %struct.event_base*, %struct.event_base** %8
%26 = call i32 @event_base_free(%struct.event_base* %25)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
%struct.event_base = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"Error creating event_base!\0A\00"
@str = [20 x i8] c"Starting event loop\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i32 2, i32* %5
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store i64 0, i64* %6
%7 = tail call %struct.event_base* (...) @event_base_new()
%8 = icmp eq %struct.event_base* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%15 = call i32 @event_base_loopexit(%struct.event_base* %7, %struct.timeval* %3)
%16 = call i32 @event_base_dispatch(%struct.event_base* %7)
%17 = call i32 @event_base_free(%struct.event_base* %7)
ret i32 0
}