#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 */

/* Variables and functions */
int /*<<< orphan*/ SOMAXCONN;
int /*<<< orphan*/ add_event_poll(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ close_event_poll();
int /*<<< orphan*/ evt_loop(int);
scalar_t__ init_event_poll();
int init_socket(int *);
int listen(int, int /*<<< orphan*/);
int make_socket_non_blocking(int *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  int serverfd;
  int ret;
  ret = init_socket(&serverfd);
  if (ret < 0) {
    printf("Init server socket failed\n");
    return -1;
  }
  ret = make_socket_non_blocking(&serverfd);
  if (ret < 0) {
    printf("Make socket non blocking failed\n");
    goto closeServSock;
  }
  ret = listen(serverfd, SOMAXCONN);
  if (ret < 0) {
    printf("Listen socket failed\n");
    goto closeServSock;
  }
  if (init_event_poll() < 0) {
    printf("Event poll init failed");
    goto closeServSock;
  }
  add_event_poll(serverfd);
  evt_loop(serverfd);
  close_event_poll();
closeServSock:
  close(serverfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   10a0 <init_socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11d4 <main+0x44>
lea    0xe3d(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1272 <main+0xe2>
lea    -0x14(%rbp),%rdi
call   1030 <make_socket_non_blocking@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11fb <main+0x6b>
lea    0xe2a(%rip),%rdi
call   1060 <printf@plt>
jmp    1263 <main+0xd3>
mov    -0x14(%rbp),%edi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
call   1090 <listen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    122a <main+0x9a>
lea    0xe1c(%rip),%rdi
call   1060 <printf@plt>
jmp    1263 <main+0xd3>
mov    $0x0,%al
call   1040 <init_event_poll@plt>
cmp    $0x0,%rax
jge    124c <main+0xbc>
lea    0xe10(%rip),%rdi
call   1060 <printf@plt>
jmp    1263 <main+0xd3>
mov    -0x14(%rbp),%edi
call   1050 <add_event_poll@plt>
mov    -0x14(%rbp),%edi
call   10b0 <evt_loop@plt>
mov    $0x0,%al
call   1070 <close_event_poll@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0x4(%rsp),%rdi
call   10b0 <init_socket@plt>
test   %eax,%eax
js     11fa <main+0x5a>
lea    0x4(%rsp),%rdi
call   1040 <make_socket_non_blocking@plt>
test   %eax,%eax
js     120d <main+0x6d>
mov    0x4(%rsp),%edi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
call   10a0 <listen@plt>
test   %eax,%eax
js     121b <main+0x7b>
xor    %eax,%eax
call   1050 <init_event_poll@plt>
test   %rax,%rax
js     1229 <main+0x89>
mov    0x4(%rsp),%edi
call   1060 <add_event_poll@plt>
mov    0x4(%rsp),%edi
call   10c0 <evt_loop@plt>
xor    %eax,%eax
call   1080 <close_event_poll@plt>
jmp    1235 <main+0x95>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
jmp    1235 <main+0x95>
lea    0xdf5(%rip),%rdi
call   1030 <puts@plt>
jmp    1235 <main+0x95>
lea    0xdd0(%rip),%rdi
call   1070 <printf@plt>
mov    0x4(%rsp),%edi
call   1090 <close@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Init server socket failed\0A\00"
@.str.1 = [33 x i8] c"Make socket non blocking failed\0A\00"
@SOMAXCONN = global i32 0
@.str.2 = [22 x i8] c"Listen socket failed\0A\00"
@.str.3 = [23 x i8] c"Event poll init failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @init_socket(i32* %6)
store i32 %8, i32* %7
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %41
13: ; preds = %2
%14 = call i32 @make_socket_non_blocking(i32* %6)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %38
19: ; preds = %13
%20 = load i32, i32* %6
%21 = load i32, i32* @SOMAXCONN
%22 = call i32 @listen(i32 %20, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %38
27: ; preds = %19
%28 = call i64 (...) @init_event_poll()
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %38
32: ; preds = %27
%33 = load i32, i32* %6
%34 = call i32 @add_event_poll(i32 %33)
%35 = load i32, i32* %6
%36 = call i32 @evt_loop(i32 %35)
%37 = call i32 (...) @close_event_poll()
br label %38
38: ; preds = %32, %30, %25, %17
%39 = load i32, i32* %6
%40 = call i32 @close(i32 %39)
store i32 0, i32* %3
br label %41
41: ; preds = %38, %11
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@SOMAXCONN = global i32 0
@.str.3 = [23 x i8] c"Event poll init failed\00"
@str = [21 x i8] c"Listen socket failed\00"
@str.4 = [32 x i8] c"Make socket non blocking failed\00"
@str.5 = [26 x i8] c"Init server socket failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @init_socket(i32* %3)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0))
br label %35
9: ; preds = %2
%10 = call i32 @make_socket_non_blocking(i32* %3)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.4, i64 0, i64 0))
br label %32
14: ; preds = %9
%15 = load i32, i32* %3
%16 = load i32, i32* @SOMAXCONN
%17 = call i32 @listen(i32 %15, i32 %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %32
21: ; preds = %14
%22 = call i64 (...) @init_event_poll()
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %32
26: ; preds = %21
%27 = load i32, i32* %3
%28 = call i32 @add_event_poll(i32 %27)
%29 = load i32, i32* %3
%30 = call i32 @evt_loop(i32 %29)
%31 = call i32 (...) @close_event_poll()
br label %32
32: ; preds = %26, %24, %19, %12
%33 = load i32, i32* %3
%34 = call i32 @close(i32 %33)
br label %35
35: ; preds = %32, %7
%36 = phi i32 [ -1, %7 ], [ 0, %32 ]
ret i32 %36
}