#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int fd;
};
struct TYPE_3__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_2__ data;
  int /*<<< orphan*/ events;
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct epoll_event {
  TYPE_2__ data;
  int /*<<< orphan*/ events;
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
typedef int /*<<< orphan*/ srv_addr;
typedef int /*<<< orphan*/ e;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ INADDR_ANY;
int SOCK_NONBLOCK;
int SOCK_STREAM;
int /*<<< orphan*/ close(int);
int epoll_create(int);
scalar_t__ epoll_ctl(int, int /*<<< orphan*/, int, struct sockaddr_in *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
scalar_t__ os_bind(int, struct sockaddr *, int);
int /*<<< orphan*/ os_close(int);
scalar_t__ os_listen(int, int);
int os_socket(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int init_server(int *s, int *e) {
  int srv_fd = -1;
  int epoll_fd = -1;
  struct sockaddr_in srv_addr;
  struct epoll_event ee;
  memset(&srv_addr, 0, sizeof(struct sockaddr_in));
  memset(&ee, 0, sizeof(e));
  srv_fd = os_socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
  if (srv_fd < 0) {
    printf("Cannot create socket\n");
    return 1;
  }
  srv_addr.sin_family = AF_INET;
  srv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  srv_addr.sin_port = htons(5557);
  if (os_bind(srv_fd, (struct sockaddr *)&srv_addr, sizeof(srv_addr)) < 0) {
    printf("Cannot bind socket\n");
    close(srv_fd);
    return 1;
  }
  if (os_listen(srv_fd, 1) < 0) {
    printf("Cannot listen\n");
    close(srv_fd);
    return 1;
  }
  epoll_fd = epoll_create(1000 + 1);
  if (epoll_fd < 0) {
    printf("Cannot create epoll\n");
    close(srv_fd);
    return 1;
  }
  ee.events = EPOLLIN;
  ee.data.fd = srv_fd;
  if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, srv_fd, &ee) < 0) {
    printf("Cannot add server socket to epoll\n");
    os_close(epoll_fd);
    os_close(srv_fd);
    return 1;
  }
  *s = srv_fd;
  *e = epoll_fd;
  return 0;
}


x86 assembly (clang, -O0):
<init_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
mov    0x2db9(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   10b0 <os_socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1235 <init_server+0x85>
lea    0xddc(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    137d <init_server+0x1cd>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x15b5,%edi
call   1040 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x14,%edx
call   10c0 <os_bind@plt>
cmp    $0x0,%rax
jge    129a <init_server+0xea>
lea    0xd95(%rip),%rdi
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    137d <init_server+0x1cd>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   10a0 <os_listen@plt>
cmp    $0x0,%rax
jge    12d1 <init_server+0x121>
lea    0xd72(%rip),%rdi
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    137d <init_server+0x1cd>
mov    $0x3e9,%edi
call   10d0 <epoll_create@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1308 <init_server+0x158>
lea    0xd4a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    137d <init_server+0x1cd>
mov    0x2cd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2cb4(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
lea    -0x50(%rbp),%rcx
call   1090 <epoll_ctl@plt>
cmp    $0x0,%rax
jge    1364 <init_server+0x1b4>
lea    0xd0b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%edi
call   1030 <os_close@plt>
mov    -0x1c(%rbp),%edi
call   1030 <os_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    137d <init_server+0x1cd>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_server>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    0x2dff(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dc6(%rip),%rax
mov    0x2dc7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
xor    %edx,%edx
call   10b0 <os_socket@plt>
test   %eax,%eax
js     12a7 <init_server+0xf7>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x15b5,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x14,%edx
call   10c0 <os_bind@plt>
test   %rax,%rax
js     12b5 <init_server+0x105>
mov    $0x1,%ebx
mov    %ebp,%edi
mov    $0x1,%esi
call   10a0 <os_listen@plt>
test   %rax,%rax
js     12be <init_server+0x10e>
mov    $0x3e9,%edi
call   10d0 <epoll_create@plt>
test   %eax,%eax
js     12d3 <init_server+0x123>
mov    %eax,%ebx
mov    0x2d69(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
mov    %ebp,0x20(%rsp)
mov    0x2d50(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rcx
mov    %ebx,%edi
mov    %ebp,%edx
call   1090 <epoll_ctl@plt>
test   %rax,%rax
js     12f8 <init_server+0x148>
mov    %ebp,(%r15)
mov    %ebx,(%r14)
xor    %ebx,%ebx
jmp    12eb <init_server+0x13b>
lea    0xda9(%rip),%rdi
call   1040 <puts@plt>
jmp    12e6 <init_server+0x136>
lea    0xd88(%rip),%rdi
jmp    12da <init_server+0x12a>
lea    0xd71(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   1080 <close@plt>
jmp    12eb <init_server+0x13b>
lea    0xd48(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd01(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1030 <os_close@plt>
mov    %ebp,%edi
call   1030 <os_close@plt>
jmp    12e6 <init_server+0x136>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_4__, i32, i32, %struct.TYPE_3__, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.TYPE_3__ = type { i32 }
%struct.epoll_event = type { %struct.TYPE_4__, i32, i32, %struct.TYPE_3__, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOCK_NONBLOCK = global i32 0
@.str = [22 x i8] c"Cannot create socket\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [20 x i8] c"Cannot bind socket\0A\00"
@.str.2 = [15 x i8] c"Cannot listen\0A\00"
@.str.3 = [21 x i8] c"Cannot create epoll\0A\00"
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.4 = [35 x i8] c"Cannot add server socket to epoll\0A\00"
define i32 @init_server(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.epoll_event
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 -1, i32* %6
store i32 -1, i32* %7
%10 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 20)
%11 = bitcast %struct.epoll_event* %9 to %struct.sockaddr_in*
%12 = call i32 @memset(%struct.sockaddr_in* %11, i32 0, i32 8)
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = load i32, i32* @SOCK_NONBLOCK
%16 = or i32 %14, %15
%17 = call i32 @os_socket(i32 %13, i32 %16, i32 0)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %78
22: ; preds = %2
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 4
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = call i32 @htonl(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 3
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %27, i32 0, i32 0
store i32 %26, i32* %28
%29 = call i32 @htons(i32 5557)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %29, i32* %30
%31 = load i32, i32* %6
%32 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%33 = call i64 @os_bind(i32 %31, %struct.sockaddr* %32, i32 20)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %22
%36 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* %6
%38 = call i32 @close(i32 %37)
store i32 1, i32* %3
br label %78
39: ; preds = %22
%40 = load i32, i32* %6
%41 = call i64 @os_listen(i32 %40, i32 1)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32, i32* %6
%46 = call i32 @close(i32 %45)
store i32 1, i32* %3
br label %78
47: ; preds = %39
%48 = call i32 @epoll_create(i32 1001)
store i32 %48, i32* %7
%49 = load i32, i32* %7
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%53 = load i32, i32* %6
%54 = call i32 @close(i32 %53)
store i32 1, i32* %3
br label %78
55: ; preds = %47
%56 = load i32, i32* @EPOLLIN
%57 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i32 0, i32 1
store i32 %56, i32* %57
%58 = load i32, i32* %6
%59 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i32 0, i32 0
%60 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %59, i32 0, i32 0
store i32 %58, i32* %60
%61 = load i32, i32* %7
%62 = load i32, i32* @EPOLL_CTL_ADD
%63 = load i32, i32* %6
%64 = bitcast %struct.epoll_event* %9 to %struct.sockaddr_in*
%65 = call i64 @epoll_ctl(i32 %61, i32 %62, i32 %63, %struct.sockaddr_in* %64)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %73
67: ; preds = %55
%68 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%69 = load i32, i32* %7
%70 = call i32 @os_close(i32 %69)
%71 = load i32, i32* %6
%72 = call i32 @os_close(i32 %71)
store i32 1, i32* %3
br label %78
73: ; preds = %55
%74 = load i32, i32* %6
%75 = load i32*, i32** %4
store i32 %74, i32* %75
%76 = load i32, i32* %7
%77 = load i32*, i32** %5
store i32 %76, i32* %77
store i32 0, i32* %3
br label %78
78: ; preds = %73, %67, %51, %43, %35, %20
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_4__, i32, i32, %struct.TYPE_3__, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.TYPE_3__ = type { i32 }
%struct.epoll_event = type { %struct.TYPE_4__, i32, i32, %struct.TYPE_3__, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOCK_NONBLOCK = global i32 0
@INADDR_ANY = global i32 0
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@str = [34 x i8] c"Cannot add server socket to epoll\00"
@str.5 = [20 x i8] c"Cannot create epoll\00"
@str.6 = [14 x i8] c"Cannot listen\00"
@str.7 = [19 x i8] c"Cannot bind socket\00"
@str.8 = [21 x i8] c"Cannot create socket\00"
define i32 @init_server(i32* nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.epoll_event
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = bitcast %struct.epoll_event* %4 to i8*
%7 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 20)
%8 = bitcast %struct.epoll_event* %4 to %struct.sockaddr_in*
%9 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 8)
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = load i32, i32* @SOCK_NONBLOCK
%13 = or i32 %12, %11
%14 = call i32 @os_socket(i32 %10, i32 %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.8, i64 0, i64 0))
br label %56
18: ; preds = %2
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 4
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = call i32 @htonl(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3, i32 0
store i32 %22, i32* %23
%24 = call i32 @htons(i32 5557)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %24, i32* %25
%26 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%27 = call i64 @os_bind(i32 %14, %struct.sockaddr* %26, i32 20)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %18
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0))
%31 = call i32 @close(i32 %14)
br label %56
32: ; preds = %18
%33 = call i64 @os_listen(i32 %14, i32 1)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0))
%37 = call i32 @close(i32 %14)
br label %56
38: ; preds = %32
%39 = call i32 @epoll_create(i32 1001)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
%43 = call i32 @close(i32 %14)
br label %56
44: ; preds = %38
%45 = load i32, i32* @EPOLLIN
%46 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i64 0, i32 1
store i32 %45, i32* %46
%47 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i64 0, i32 0, i32 0
store i32 %14, i32* %47
%48 = load i32, i32* @EPOLL_CTL_ADD
%49 = call i64 @epoll_ctl(i32 %39, i32 %48, i32 %14, %struct.sockaddr_in* %8)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %44
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%53 = call i32 @os_close(i32 %39)
%54 = call i32 @os_close(i32 %14)
br label %56
55: ; preds = %44
store i32 %14, i32* %0
store i32 %39, i32* %1
br label %56
56: ; preds = %55, %51, %41, %35, %29, %16
%57 = phi i32 [ 1, %16 ], [ 1, %29 ], [ 1, %35 ], [ 1, %41 ], [ 1, %51 ], [ 0, %55 ]
ret i32 %57
}