#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;
};
struct pollfd {
  int fd;
  int events;
  int revents;
};
typedef int /*<<< orphan*/ address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ INADDR_ANY;
int O_NONBLOCK;
int POLLIN;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    printf("Can't create socket.\n");
    return 1;
  }
  fcntl(sock, F_SETFL, (fcntl(sock, F_GETFL, 0)) | O_NONBLOCK);
  struct sockaddr_in address;
  address.sin_family = AF_INET;
  address.sin_port = htons(1337);
  address.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(sock, (struct sockaddr *)&address, sizeof(address)) < 0) {
    printf("Can't bind.\n");
    return 1;
  };
  struct pollfd clients[10];
  for (int i = 0; i < 10; i++) {
    clients[i].fd = -1;
    clients[i].events = POLLIN;
  }
  char buf[1024];
  listen(sock, 10);
  printf("Server started.\n");
  while (1) {
    int new_client = accept(sock, NULL, NULL);
    if (new_client >= 0) {
      int i = 0;
      while (i < 10 && clients[i].fd != -1)
        i++;
      if (i < 10) {
        clients[i].fd = new_client;
        printf("Connected client %d.\n", i);
      } else {
        printf("There is no place for new client.\n");
        shutdown(new_client, 2);
        close(new_client);
      }
    }
    int poll_ret = poll(clients, 10, 1000);
    if (poll_ret > 0) {
      for (int i = 0; i < 10; i++) {
        if (clients[i].revents & POLLIN) {
          int bytes_read = recv(clients[i].fd, buf, 1024, 0);
          if (bytes_read == 0) {
            printf("Disconnected client %d.\n", i);
            close(clients[i].fd);
            clients[i].fd = -1;
          } else {
            printf("Got message from client %d.\n", i);
            send(clients[i].fd, buf, bytes_read, 0);
          }
          break;
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1222 <main+0x52>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a2 <main+0x3d2>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4bc(%rbp)
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4b8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    -0x4bc(%rbp),%edi
mov    -0x4b8(%rbp),%esi
mov    %eax,%edx
mov    0x2d7e(%rip),%rax
or     (%rax),%edx
call   1040 <fcntl@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x539,%edi
call   1060 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
jge    12c8 <main+0xf8>
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a2 <main+0x3d2>
movl   $0x0,-0x94(%rbp)
cmpl   $0xa,-0x94(%rbp)
jge    132f <main+0x15f>
movslq -0x94(%rbp),%rcx
lea    -0x90(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0xffffffff,(%rax)
mov    0x2ccf(%rip),%rax
mov    (%rax),%ecx
movslq -0x94(%rbp),%rdx
lea    -0x90(%rbp),%rax
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,0x4(%rax)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    12d2 <main+0x102>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
lea    0xce0(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10e0 <accept@plt>
mov    %eax,-0x4a4(%rbp)
cmpl   $0x0,-0x4a4(%rbp)
jl     1444 <main+0x274>
movl   $0x0,-0x4a8(%rbp)
xor    %eax,%eax
cmpl   $0xa,-0x4a8(%rbp)
mov    %al,-0x4bd(%rbp)
jge    13ac <main+0x1dc>
movslq -0x4a8(%rbp),%rcx
lea    -0x90(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
cmpl   $0xffffffff,(%rax)
setne  %al
mov    %al,-0x4bd(%rbp)
mov    -0x4bd(%rbp),%al
test   $0x1,%al
jne    13bf <main+0x1ef>
jmp    13d3 <main+0x203>
mov    -0x4a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4a8(%rbp)
jmp    1376 <main+0x1a6>
cmpl   $0xa,-0x4a8(%rbp)
jge    1416 <main+0x246>
mov    -0x4a4(%rbp),%ecx
movslq -0x4a8(%rbp),%rdx
lea    -0x90(%rbp),%rax
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,(%rax)
mov    -0x4a8(%rbp),%esi
lea    0xc2a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    143f <main+0x26f>
lea    0xc2d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x4a4(%rbp),%edi
mov    $0x2,%esi
call   1050 <shutdown@plt>
mov    -0x4a4(%rbp),%edi
call   10a0 <close@plt>
jmp    1444 <main+0x274>
lea    -0x90(%rbp),%rdi
mov    $0xa,%esi
mov    $0x3e8,%edx
call   10c0 <poll@plt>
mov    %eax,-0x4ac(%rbp)
cmpl   $0x0,-0x4ac(%rbp)
jle    159d <main+0x3cd>
movl   $0x0,-0x4b0(%rbp)
cmpl   $0xa,-0x4b0(%rbp)
jge    1598 <main+0x3c8>
movslq -0x4b0(%rbp),%rcx
lea    -0x90(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%eax
mov    0x2b2d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     157f <main+0x3af>
movslq -0x4b0(%rbp),%rcx
lea    -0x90(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edi
lea    -0x4a0(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x4b4(%rbp)
cmpl   $0x0,-0x4b4(%rbp)
jne    153b <main+0x36b>
mov    -0x4b0(%rbp),%esi
lea    0xb75(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movslq -0x4b0(%rbp),%rcx
lea    -0x90(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edi
call   10a0 <close@plt>
movslq -0x4b0(%rbp),%rcx
lea    -0x90(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0xffffffff,(%rax)
jmp    157a <main+0x3aa>
mov    -0x4b0(%rbp),%esi
lea    0xb3e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movslq -0x4b0(%rbp),%rcx
lea    -0x90(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edi
lea    -0x4a0(%rbp),%rsi
mov    -0x4b4(%rbp),%edx
xor    %ecx,%ecx
call   1070 <send@plt>
jmp    1598 <main+0x3c8>
jmp    1584 <main+0x3b4>
mov    -0x4b0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4b0(%rbp)
jmp    1477 <main+0x2a7>
jmp    159d <main+0x3cd>
jmp    134a <main+0x17a>
mov    -0x4(%rbp),%eax
add    $0x4c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x498,%rsp
mov    0x2df0(%rip),%r14
mov    (%r14),%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     1588 <main+0x3a8>
mov    %eax,%ebx
mov    0x2da4(%rip),%rax
mov    (%rax),%ebp
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <fcntl@plt>
mov    0x2da9(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   1050 <fcntl@plt>
mov    (%r14),%eax
mov    %eax,0x88(%rsp)
mov    $0x539,%edi
call   1070 <htons@plt>
mov    %eax,0x84(%rsp)
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,0x80(%rsp)
lea    0x80(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10e0 <bind@plt>
test   %rax,%rax
js     1591 <main+0x3b1>
mov    0x2d38(%rip),%rax
mov    (%rax),%eax
movl   $0xffffffff,(%rsp)
mov    %eax,0x4(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
mov    %eax,0x10(%rsp)
movl   $0xffffffff,0x18(%rsp)
ff
mov    %eax,0x1c(%rsp)
movl   $0xffffffff,0x24(%rsp)
ff
mov    %eax,0x28(%rsp)
movl   $0xffffffff,0x30(%rsp)
ff
mov    %eax,0x34(%rsp)
movl   $0xffffffff,0x3c(%rsp)
ff
mov    %eax,0x40(%rsp)
movl   $0xffffffff,0x48(%rsp)
ff
mov    %eax,0x4c(%rsp)
movl   $0xffffffff,0x54(%rsp)
ff
mov    %eax,0x58(%rsp)
movl   $0xffffffff,0x60(%rsp)
mov    %eax,0x64(%rsp)
movl   $0xffffffff,0x6c(%rsp)
ff
mov    %eax,0x70(%rsp)
mov    %ebx,%edi
mov    $0xa,%esi
call   10c0 <listen@plt>
lea    0xd28(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%r14
lea    0x90(%rsp),%r13
jmp    1363 <main+0x183>
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%r12d
lea    0xce5(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    (%r15),%edi
mov    %r13,%rsi
mov    %r12d,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10f0 <accept@plt>
test   %eax,%eax
js     14a0 <main+0x2c0>
mov    %eax,%ebp
cmpl   $0xffffffff,(%rsp)
je     1410 <main+0x230>
cmpl   $0xffffffff,0xc(%rsp)
je     1417 <main+0x237>
cmpl   $0xffffffff,0x18(%rsp)
je     1423 <main+0x243>
cmpl   $0xffffffff,0x24(%rsp)
je     142f <main+0x24f>
cmpl   $0xffffffff,0x30(%rsp)
je     143b <main+0x25b>
cmpl   $0xffffffff,0x3c(%rsp)
je     1447 <main+0x267>
cmpl   $0xffffffff,0x48(%rsp)
je     1453 <main+0x273>
cmpl   $0xffffffff,0x54(%rsp)
je     145f <main+0x27f>
cmpl   $0xffffffff,0x60(%rsp)
je     146b <main+0x28b>
cmpl   $0xffffffff,0x6c(%rsp)
je     1477 <main+0x297>
lea    0xc70(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
mov    $0x2,%esi
call   1060 <shutdown@plt>
mov    %ebp,%edi
call   10b0 <close@plt>
jmp    14a0 <main+0x2c0>
nopl   0x0(%rax)
xor    %esi,%esi
mov    %r14,%rax
jmp    1490 <main+0x2b0>
mov    $0x1,%esi
lea    0xc(%rsp),%rax
jmp    1490 <main+0x2b0>
mov    $0x2,%esi
lea    0x18(%rsp),%rax
jmp    1490 <main+0x2b0>
mov    $0x3,%esi
lea    0x24(%rsp),%rax
jmp    1490 <main+0x2b0>
mov    $0x4,%esi
lea    0x30(%rsp),%rax
jmp    1490 <main+0x2b0>
mov    $0x5,%esi
lea    0x3c(%rsp),%rax
jmp    1490 <main+0x2b0>
mov    $0x6,%esi
lea    0x48(%rsp),%rax
jmp    1490 <main+0x2b0>
mov    $0x7,%esi
lea    0x54(%rsp),%rax
jmp    1490 <main+0x2b0>
mov    $0x8,%esi
lea    0x60(%rsp),%rax
jmp    1490 <main+0x2b0>
mov    $0x9,%esi
lea    0x6c(%rsp),%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,(%rax)
lea    0xb67(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r14,%rdi
mov    $0xa,%esi
mov    $0x3e8,%edx
call   10d0 <poll@plt>
test   %eax,%eax
jle    1363 <main+0x183>
mov    0x2b0f(%rip),%rax
mov    (%rax),%eax
xor    %ebp,%ebp
test   %eax,0x8(%rsp)
jne    1540 <main+0x360>
mov    $0x1,%ebp
test   %eax,0x14(%rsp)
jne    1540 <main+0x360>
mov    $0x2,%ebp
test   %eax,0x20(%rsp)
jne    1540 <main+0x360>
mov    $0x3,%ebp
test   %eax,0x2c(%rsp)
jne    1540 <main+0x360>
mov    $0x4,%ebp
test   %eax,0x38(%rsp)
jne    1540 <main+0x360>
mov    $0x5,%ebp
test   %eax,0x44(%rsp)
jne    1540 <main+0x360>
mov    $0x6,%ebp
test   %eax,0x50(%rsp)
jne    1540 <main+0x360>
mov    $0x7,%ebp
test   %eax,0x5c(%rsp)
jne    1540 <main+0x360>
mov    $0x8,%ebp
test   %eax,0x68(%rsp)
jne    1540 <main+0x360>
mov    $0x9,%ebp
test   %eax,0x74(%rsp)
je     1363 <main+0x183>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%eax
lea    (%rax,%rax,2),%rax
lea    (%rsp,%rax,4),%r15
mov    (%rsp,%rax,4),%edi
mov    %r13,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jne    1340 <main+0x160>
lea    0xaab(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    (%r15),%edi
call   10b0 <close@plt>
movl   $0xffffffff,(%r15)
jmp    1363 <main+0x183>
lea    0xafb(%rip),%rdi
jmp    1598 <main+0x3b8>
lea    0xae6(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x498,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.pollfd = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"Can't create socket.\0A\00"
@F_SETFL = global i32 0
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [13 x i8] c"Can't bind.\0A\00"
@POLLIN = global i32 0
@.str.2 = [17 x i8] c"Server started.\0A\00"
@.str.3 = [22 x i8] c"Connected client %d.\0A\00"
@.str.4 = [35 x i8] c"There is no place for new client.\0A\00"
@.str.5 = [25 x i8] c"Disconnected client %d.\0A\00"
@.str.6 = [29 x i8] c"Got message from client %d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [10 x %struct.pollfd]
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %161
19: ; preds = %0
%20 = load i32, i32* %2
%21 = load i32, i32* @F_SETFL
%22 = load i32, i32* %2
%23 = load i32, i32* @F_GETFL
%24 = call i32 @fcntl(i32 %22, i32 %23, i32 0)
%25 = load i32, i32* @O_NONBLOCK
%26 = or i32 %24, %25
%27 = call i32 @fcntl(i32 %20, i32 %21, i32 %26)
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %28, i32* %29
%30 = call i32 @htons(i32 1337)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %30, i32* %31
%32 = load i32, i32* @INADDR_ANY
%33 = call i32 @htonl(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
store i32 %33, i32* %35
%36 = load i32, i32* %2
%37 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%38 = call i64 @bind(i32 %36, %struct.sockaddr* %37, i32 12)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %19
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %161
42: ; preds = %19
store i32 0, i32* %5
br label %43
43: ; preds = %56, %42
%44 = load i32, i32* %5
%45 = icmp slt i32 %44, 10
br i1 %45, label %46, label %59
46: ; preds = %43
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %4, i64 0, i64 %48
%50 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %49, i32 0, i32 0
store i32 -1, i32* %50
%51 = load i32, i32* @POLLIN
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %4, i64 0, i64 %53
%55 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %54, i32 0, i32 1
store i32 %51, i32* %55
br label %56
56: ; preds = %46
%57 = load i32, i32* %5
%58 = add nsw i32 %57, 1
store i32 %58, i32* %5
br label %43
59: ; preds = %43
%60 = load i32, i32* %2
%61 = call i32 @listen(i32 %60, i32 10)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %63
63: ; preds = %59, %160
%64 = load i32, i32* %2
%65 = call i32 @accept(i32 %64, i32* null, i32* null)
store i32 %65, i32* %7
%66 = load i32, i32* %7
%67 = icmp sge i32 %66, 0
br i1 %67, label %68, label %102
68: ; preds = %63
store i32 0, i32* %8
br label %69
69: ; preds = %81, %68
%70 = load i32, i32* %8
%71 = icmp slt i32 %70, 10
br i1 %71, label %72, label %79
72: ; preds = %69
%73 = load i32, i32* %8
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %4, i64 0, i64 %74
%76 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %75, i32 0, i32 0
%77 = load i32, i32* %76
%78 = icmp ne i32 %77, -1
br label %79
79: ; preds = %72, %69
%80 = phi i1 [ false, %69 ], [ %78, %72 ]
br i1 %80, label %81, label %84
81: ; preds = %79
%82 = load i32, i32* %8
%83 = add nsw i32 %82, 1
store i32 %83, i32* %8
br label %69
84: ; preds = %79
%85 = load i32, i32* %8
%86 = icmp slt i32 %85, 10
br i1 %86, label %87, label %95
87: ; preds = %84
%88 = load i32, i32* %7
%89 = load i32, i32* %8
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %4, i64 0, i64 %90
%92 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %91, i32 0, i32 0
store i32 %88, i32* %92
%93 = load i32, i32* %8
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %93)
br label %101
95: ; preds = %84
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%97 = load i32, i32* %7
%98 = call i32 @shutdown(i32 %97, i32 2)
%99 = load i32, i32* %7
%100 = call i32 @close(i32 %99)
br label %101
101: ; preds = %95, %87
br label %102
102: ; preds = %101, %63
%103 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %4, i64 0, i64 0
%104 = call i32 @poll(%struct.pollfd* %103, i32 10, i32 1000)
store i32 %104, i32* %9
%105 = load i32, i32* %9
%106 = icmp sgt i32 %105, 0
br i1 %106, label %107, label %160
107: ; preds = %102
store i32 0, i32* %10
br label %108
108: ; preds = %156, %107
%109 = load i32, i32* %10
%110 = icmp slt i32 %109, 10
br i1 %110, label %111, label %159
111: ; preds = %108
%112 = load i32, i32* %10
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %4, i64 0, i64 %113
%115 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %114, i32 0, i32 2
%116 = load i32, i32* %115
%117 = load i32, i32* @POLLIN
%118 = and i32 %116, %117
%119 = icmp ne i32 %118, 0
br i1 %119, label %120, label %155
120: ; preds = %111
%121 = load i32, i32* %10
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %4, i64 0, i64 %122
%124 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %123, i32 0, i32 0
%125 = load i32, i32* %124
%126 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%127 = call i32 @recv(i32 %125, i8* %126, i32 1024, i32 0)
store i32 %127, i32* %11
%128 = load i32, i32* %11
%129 = icmp eq i32 %128, 0
br i1 %129, label %130, label %143
130: ; preds = %120
%131 = load i32, i32* %10
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %131)
%133 = load i32, i32* %10
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %4, i64 0, i64 %134
%136 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %135, i32 0, i32 0
%137 = load i32, i32* %136
%138 = call i32 @close(i32 %137)
%139 = load i32, i32* %10
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %4, i64 0, i64 %140
%142 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %141, i32 0, i32 0
store i32 -1, i32* %142
br label %154
143: ; preds = %120
%144 = load i32, i32* %10
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %144)
%146 = load i32, i32* %10
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %4, i64 0, i64 %147
%149 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %148, i32 0, i32 0
%150 = load i32, i32* %149
%151 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%152 = load i32, i32* %11
%153 = call i32 @send(i32 %150, i8* %151, i32 %152, i32 0)
br label %154
154: ; preds = %143, %130
br label %159
155: ; preds = %111
br label %156
156: ; preds = %155
%157 = load i32, i32* %10
%158 = add nsw i32 %157, 1
store i32 %158, i32* %10
br label %108
159: ; preds = %154, %108
br label %160
160: ; preds = %159, %102
br label %63
161: ; preds = %40, %17
%162 = load i32, i32* %1
ret i32 %162
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.pollfd = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@F_SETFL = global i32 0
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@INADDR_ANY = global i32 0
@POLLIN = global i32 0
@.str.3 = [22 x i8] c"Connected client %d.\0A\00"
@.str.5 = [25 x i8] c"Disconnected client %d.\0A\00"
@.str.6 = [29 x i8] c"Got message from client %d.\0A\00"
@str = [16 x i8] c"Server started.\00"
@str.7 = [34 x i8] c"There is no place for new client.\00"
@str.8 = [12 x i8] c"Can't bind.\00"
@str.9 = [21 x i8] c"Can't create socket.\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [10 x %struct.pollfd]
%3 = alloca [1024 x i8]
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0))
br label %168
10: ; preds = %0
%11 = load i32, i32* @F_SETFL
%12 = load i32, i32* @F_GETFL
%13 = tail call i32 @fcntl(i32 %6, i32 %12, i32 0)
%14 = load i32, i32* @O_NONBLOCK
%15 = or i32 %14, %13
%16 = tail call i32 @fcntl(i32 %6, i32 %11, i32 %15)
%17 = bitcast %struct.sockaddr_in* %1 to i8*
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %18, i32* %19
%20 = tail call i32 @htons(i32 1337)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %20, i32* %21
%22 = load i32, i32* @INADDR_ANY
%23 = tail call i32 @htonl(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %23, i32* %24
%25 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%26 = call i64 @bind(i32 %6, %struct.sockaddr* %25, i32 12)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %10
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
br label %168
30: ; preds = %10
%31 = bitcast [10 x %struct.pollfd]* %2 to i8*
%32 = load i32, i32* @POLLIN
%33 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 0, i32 0
store i32 -1, i32* %33
%34 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 0, i32 1
store i32 %32, i32* %34
%35 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 1, i32 0
store i32 -1, i32* %35
%36 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 1, i32 1
store i32 %32, i32* %36
%37 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 2, i32 0
store i32 -1, i32* %37
%38 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 2, i32 1
store i32 %32, i32* %38
%39 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 3, i32 0
store i32 -1, i32* %39
%40 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 3, i32 1
store i32 %32, i32* %40
%41 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 4, i32 0
store i32 -1, i32* %41
%42 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 4, i32 1
store i32 %32, i32* %42
%43 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 5, i32 0
store i32 -1, i32* %43
%44 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 5, i32 1
store i32 %32, i32* %44
%45 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 6, i32 0
store i32 -1, i32* %45
%46 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 6, i32 1
store i32 %32, i32* %46
%47 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 7, i32 0
store i32 -1, i32* %47
%48 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 7, i32 1
store i32 %32, i32* %48
%49 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 8, i32 0
store i32 -1, i32* %49
%50 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 8, i32 1
store i32 %32, i32* %50
%51 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 9, i32 0
store i32 -1, i32* %51
%52 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 9, i32 1
store i32 %32, i32* %52
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%54 = call i32 @listen(i32 %6, i32 10)
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%56 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 0
%57 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 0, i32 2
%58 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 1, i32 2
%59 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 2, i32 2
%60 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 3, i32 2
%61 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 4, i32 2
%62 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 5, i32 2
%63 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 6, i32 2
%64 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 7, i32 2
%65 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 8, i32 2
%66 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 9, i32 2
br label %67
67: ; preds = %167, %30
%68 = call i32 @accept(i32 %6, i32* null, i32* null)
%69 = icmp sgt i32 %68, -1
br i1 %69, label %70, label %108
70: ; preds = %67
%71 = load i32, i32* %33
%72 = icmp eq i32 %71, -1
br i1 %72, label %104, label %73
73: ; preds = %70
%74 = load i32, i32* %35
%75 = icmp eq i32 %74, -1
br i1 %75, label %104, label %76
76: ; preds = %73
%77 = load i32, i32* %37
%78 = icmp eq i32 %77, -1
br i1 %78, label %104, label %79
79: ; preds = %76
%80 = load i32, i32* %39
%81 = icmp eq i32 %80, -1
br i1 %81, label %104, label %82
82: ; preds = %79
%83 = load i32, i32* %41
%84 = icmp eq i32 %83, -1
br i1 %84, label %104, label %85
85: ; preds = %82
%86 = load i32, i32* %43
%87 = icmp eq i32 %86, -1
br i1 %87, label %104, label %88
88: ; preds = %85
%89 = load i32, i32* %45
%90 = icmp eq i32 %89, -1
br i1 %90, label %104, label %91
91: ; preds = %88
%92 = load i32, i32* %47
%93 = icmp eq i32 %92, -1
br i1 %93, label %104, label %94
94: ; preds = %91
%95 = load i32, i32* %49
%96 = icmp eq i32 %95, -1
br i1 %96, label %104, label %97
97: ; preds = %94
%98 = load i32, i32* %51
%99 = icmp eq i32 %98, -1
br i1 %99, label %104, label %100
100: ; preds = %97
%101 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.7, i64 0, i64 0))
%102 = call i32 @shutdown(i32 %68, i32 2)
%103 = call i32 @close(i32 %68)
br label %108
104: ; preds = %97, %94, %91, %88, %85, %82, %79, %76, %73, %70
%105 = phi i32 [ 0, %70 ], [ 1, %73 ], [ 2, %76 ], [ 3, %79 ], [ 4, %82 ], [ 5, %85 ], [ 6, %88 ], [ 7, %91 ], [ 8, %94 ], [ 9, %97 ]
%106 = phi i32* [ %33, %70 ], [ %35, %73 ], [ %37, %76 ], [ %39, %79 ], [ %41, %82 ], [ %43, %85 ], [ %45, %88 ], [ %47, %91 ], [ %49, %94 ], [ %51, %97 ]
store i32 %68, i32* %106
%107 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %105)
br label %108
108: ; preds = %104, %100, %67
%109 = call i32 @poll(%struct.pollfd* %56, i32 10, i32 1000)
%110 = icmp sgt i32 %109, 0
br i1 %110, label %111, label %167
111: ; preds = %108
%112 = load i32, i32* @POLLIN
%113 = load i32, i32* %57
%114 = and i32 %112, %113
%115 = icmp eq i32 %114, 0
br i1 %115, label %131, label %116
116: ; preds = %163, %159, %155, %151, %147, %143, %139, %135, %131, %111
%117 = phi i32 [ 0, %111 ], [ 1, %131 ], [ 2, %135 ], [ 3, %139 ], [ 4, %143 ], [ 5, %147 ], [ 6, %151 ], [ 7, %155 ], [ 8, %159 ], [ 9, %163 ]
%118 = zext i32 %117 to i64
%119 = getelementptr inbounds [10 x %struct.pollfd], [10 x %struct.pollfd]* %2, i64 0, i64 %118, i32 0
%120 = load i32, i32* %119
%121 = call i32 @recv(i32 %120, i8* %53, i32 1024, i32 0)
%122 = icmp eq i32 %121, 0
br i1 %122, label %123, label %127
123: ; preds = %116
%124 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %117)
%125 = load i32, i32* %119
%126 = call i32 @close(i32 %125)
store i32 -1, i32* %119
br label %167
127: ; preds = %116
%128 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %117)
%129 = load i32, i32* %119
%130 = call i32 @send(i32 %129, i8* %53, i32 %121, i32 0)
br label %167
131: ; preds = %111
%132 = load i32, i32* %58
%133 = and i32 %112, %132
%134 = icmp eq i32 %133, 0
br i1 %134, label %135, label %116
135: ; preds = %131
%136 = load i32, i32* %59
%137 = and i32 %112, %136
%138 = icmp eq i32 %137, 0
br i1 %138, label %139, label %116
139: ; preds = %135
%140 = load i32, i32* %60
%141 = and i32 %112, %140
%142 = icmp eq i32 %141, 0
br i1 %142, label %143, label %116
143: ; preds = %139
%144 = load i32, i32* %61
%145 = and i32 %112, %144
%146 = icmp eq i32 %145, 0
br i1 %146, label %147, label %116
147: ; preds = %143
%148 = load i32, i32* %62
%149 = and i32 %112, %148
%150 = icmp eq i32 %149, 0
br i1 %150, label %151, label %116
151: ; preds = %147
%152 = load i32, i32* %63
%153 = and i32 %112, %152
%154 = icmp eq i32 %153, 0
br i1 %154, label %155, label %116
155: ; preds = %151
%156 = load i32, i32* %64
%157 = and i32 %112, %156
%158 = icmp eq i32 %157, 0
br i1 %158, label %159, label %116
159: ; preds = %155
%160 = load i32, i32* %65
%161 = and i32 %112, %160
%162 = icmp eq i32 %161, 0
br i1 %162, label %163, label %116
163: ; preds = %159
%164 = load i32, i32* %66
%165 = and i32 %112, %164
%166 = icmp eq i32 %165, 0
br i1 %166, label %167, label %116
167: ; preds = %163, %127, %123, %108
br label %67
168: ; preds = %28, %8
ret i32 1
}