#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ server_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, struct sockaddr const *, int);
int /*<<< orphan*/ close(int);
int epoll_create(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int epoll_fd = -1;
  int server_fd = -1;
  struct sockaddr_in server_addr;
  struct sockaddr_in client_addr;
  server_fd = socket(AF_INET, SOCK_STREAM, 0);
  if (server_fd < 0) {
    perror("socket()");
    goto out;
  }
  memset(&server_addr, 0, sizeof(struct sockaddr_in));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(1234);
  server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(server_fd, (const struct sockaddr *)&server_addr,
           sizeof(server_addr)) < 0) {
    perror("bind()");
    goto out;
  }
  if (listen(server_fd, 10) < 0) {
    perror("listen()");
    goto out;
  }
  epoll_fd = epoll_create(11);
  if (epoll_fd < 0) {
    perror("epoll_create()");
    goto out;
  }
out:
  if (server_fd > 0)
    close(server_fd);
  if (epoll_fd > 0)
    close(epoll_fd);
  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   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11eb <main+0x5b>
lea    0xe1f(%rip),%rdi
call   1090 <perror@plt>
jmp    12a6 <main+0x116>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x4d2,%edi
call   1030 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    1251 <main+0xc1>
lea    0xdc2(%rip),%rdi
call   1090 <perror@plt>
jmp    12a6 <main+0x116>
mov    -0x18(%rbp),%edi
mov    $0xa,%esi
call   1070 <listen@plt>
cmp    $0x0,%rax
jge    1279 <main+0xe9>
lea    0xda1(%rip),%rdi
call   1090 <perror@plt>
jmp    12a6 <main+0x116>
mov    $0xb,%edi
call   10a0 <epoll_create@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12a1 <main+0x111>
lea    0xd82(%rip),%rdi
call   1090 <perror@plt>
jmp    12a6 <main+0x116>
jmp    12a6 <main+0x116>
cmpl   $0x0,-0x18(%rbp)
jle    12b8 <main+0x128>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x0,-0x14(%rbp)
jle    12ca <main+0x13a>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e49(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     124f <main+0xbf>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    $0x4d2,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
js     125d <main+0xcd>
mov    %ebx,%edi
mov    $0xa,%esi
call   1070 <listen@plt>
test   %rax,%rax
js     1266 <main+0xd6>
mov    $0xb,%edi
call   10a0 <epoll_create@plt>
mov    %eax,%ebp
test   %eax,%eax
js     126f <main+0xdf>
test   %ebx,%ebx
je     1239 <main+0xa9>
mov    %ebx,%edi
call   1060 <close@plt>
test   %ebp,%ebp
jle    1244 <main+0xb4>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdaa(%rip),%rdi
call   1090 <perror@plt>
jmp    1244 <main+0xb4>
lea    0xda5(%rip),%rdi
jmp    1276 <main+0xe6>
lea    0xda3(%rip),%rdi
jmp    1276 <main+0xe6>
lea    0xda3(%rip),%rdi
call   1090 <perror@plt>
test   %ebx,%ebx
jne    1232 <main+0xa2>
jmp    1239 <main+0xa9>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [9 x i8] c"socket()\00"
@INADDR_ANY = global i32 0
@.str.1 = [7 x i8] c"bind()\00"
@.str.2 = [9 x i8] c"listen()\00"
@.str.3 = [15 x i8] c"epoll_create()\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 -1, i32* %7
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %46
17: ; preds = %2
%18 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %19, i32* %20
%21 = call i32 @htons(i32 1234)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = call i32 @htonl(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = load i32, i32* %7
%28 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%29 = call i64 @bind(i32 %27, %struct.sockaddr* %28, i32 12)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %17
%32 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %46
33: ; preds = %17
%34 = load i32, i32* %7
%35 = call i64 @listen(i32 %34, i32 10)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %46
39: ; preds = %33
%40 = call i32 @epoll_create(i32 11)
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %46
45: ; preds = %39
br label %46
46: ; preds = %45, %43, %37, %31, %15
%47 = load i32, i32* %7
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32, i32* %7
%51 = call i32 @close(i32 %50)
br label %52
52: ; preds = %49, %46
%53 = load i32, i32* %6
%54 = icmp sgt i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32, i32* %6
%57 = call i32 @close(i32 %56)
br label %58
58: ; preds = %55, %52
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [9 x i8] c"socket()\00"
@INADDR_ANY = global i32 0
@.str.1 = [7 x i8] c"bind()\00"
@.str.2 = [9 x i8] c"listen()\00"
@.str.3 = [15 x i8] c"epoll_create()\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %42
11: ; preds = %2
%12 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @htons(i32 1234)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* @INADDR_ANY
%18 = call i32 @htonl(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%21 = call i64 @bind(i32 %7, %struct.sockaddr* %20, i32 12)
%22 = icmp slt i64 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %11
%24 = call i64 @listen(i32 %7, i32 10)
%25 = icmp slt i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = call i32 @epoll_create(i32 11)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %26, %23, %11
%30 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %11 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), %23 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %26 ]
%31 = phi i32 [ -1, %11 ], [ -1, %23 ], [ %27, %26 ]
%32 = call i32 @perror(i8* %30)
br label %33
33: ; preds = %29, %26
%34 = phi i32 [ %27, %26 ], [ %31, %29 ]
%35 = icmp eq i32 %7, 0
br i1 %35, label %38, label %36
36: ; preds = %33
%37 = call i32 @close(i32 %7)
br label %38
38: ; preds = %36, %33
%39 = icmp sgt i32 %34, 0
br i1 %39, label %40, label %42
40: ; preds = %38
%41 = call i32 @close(i32 %34)
br label %42
42: ; preds = %9, %40, %38
ret i32 0
}