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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ FD_CLR(int, int /*<<< orphan*/ *);
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int FD_SETSIZE;
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  struct sockaddr_in server_sockaddr, client_sockaddr;
  int sin_size, count;
  fd_set inset, tmp_inset;
  int sockfd, client_fd, fd;
  char buf[1024];
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  server_sockaddr.sin_family = AF_INET;
  server_sockaddr.sin_port = htons(4321);
  server_sockaddr.sin_addr.s_addr = INADDR_ANY;
  bzero(&(server_sockaddr.sin_zero), 8);
  int i = 1;
  setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
  if (bind(sockfd, (struct sockaddr *)&server_sockaddr,
           sizeof(struct sockaddr)) == -1) {
    perror("bind");
    exit(1);
  }
  if (listen(sockfd, 5) == -1) {
    perror("listen");
    exit(1);
  }
  printf("listening....\n");
  FD_ZERO(&inset);
  FD_SET(sockfd, &inset);
  while (1) {
    tmp_inset = inset;
    sin_size = sizeof(struct sockaddr_in);
    memset(buf, 0, sizeof(buf));
    if (!(select(FD_SETSIZE, &tmp_inset, NULL, NULL, NULL) > 0)) {
      perror("select");
      close(sockfd);
      exit(1);
    }
    for (fd = 0; fd < FD_SETSIZE; fd++) {
      if (FD_ISSET(fd, &tmp_inset) > 0) {
        if (fd == sockfd) {
          if ((client_fd = accept(sockfd, (struct sockaddr *)&client_sockaddr,
                                  &sin_size)) == -1) {
            perror("accept");
            exit(1);
          }
          FD_SET(client_fd, &inset);
          printf("New connection from %d(socket)\n", client_fd);
        } else {
          if ((count = recv(fd, buf, 1024, 0)) > 0) {
            printf("Received a message from %d: %s\n", fd, buf);
          } else {
            close(fd);
            FD_CLR(fd, &inset);
            printf("Client %d(socket) has left\n", fd);
          }
        }
      }
    }
  }
  close(sockfd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    126d <main+0x4d>
lea    0xda2(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x10e1,%edi
call   1060 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    0x2d4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
call   10f0 <bzero@plt>
movl   $0x1,-0x454(%rbp)
mov    -0x3c(%rbp),%edi
mov    0x2d34(%rip),%rax
mov    (%rax),%esi
mov    0x2cfb(%rip),%rax
mov    (%rax),%edx
lea    -0x454(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    -0x3c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   10d0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1301 <main+0xe1>
lea    0xd15(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x3c(%rbp),%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
cmp    $0xffffffff,%eax
jne    132d <main+0x10d>
lea    0xcee(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    0xcdf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x34(%rbp),%rdi
call   10a0 <FD_ZERO@plt>
mov    -0x3c(%rbp),%edi
lea    -0x34(%rbp),%rsi
call   1130 <FD_SET@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
movl   $0x10,-0x2c(%rbp)
lea    -0x450(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10b0 <select@plt>
cmp    $0x0,%rax
jg     13b5 <main+0x195>
lea    0xc84(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x3c(%rbp),%edi
call   1090 <close@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    0x2bfa(%rip),%rcx
cmp    (%rcx),%eax
jge    14c5 <main+0x2a5>
mov    -0x44(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
jle    14b2 <main+0x292>
mov    -0x44(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jne    1444 <main+0x224>
mov    -0x3c(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x40(%rbp)
cmp    $0xffffffff,%eax
jne    1422 <main+0x202>
lea    0xc16(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x40(%rbp),%edi
lea    -0x34(%rbp),%rsi
call   1130 <FD_SET@plt>
mov    -0x40(%rbp),%esi
lea    0xbf8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14ad <main+0x28d>
mov    -0x44(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jle    1483 <main+0x263>
mov    -0x44(%rbp),%esi
lea    -0x450(%rbp),%rdx
lea    0xbd9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14a8 <main+0x288>
mov    -0x44(%rbp),%edi
call   1090 <close@plt>
mov    -0x44(%rbp),%edi
lea    -0x34(%rbp),%rsi
call   1110 <FD_CLR@plt>
mov    -0x44(%rbp),%esi
lea    0xbcf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14ad <main+0x28d>
jmp    14b2 <main+0x292>
jmp    14b7 <main+0x297>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    13bc <main+0x19c>
jmp    1350 <main+0x130>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    0x2d98(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d76(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
cmp    $0xffffffff,%eax
jne    126c <main+0x3c>
lea    0xd99(%rip),%rdi
jmp    1497 <main+0x267>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x1c(%rsp)
mov    $0x10e1,%edi
call   1070 <htons@plt>
mov    %eax,0x18(%rsp)
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x8,%esi
call   1100 <bzero@plt>
movl   $0x1,0xc(%rsp)
mov    0x2d37(%rip),%rax
mov    (%rax),%esi
mov    0x2cfe(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   10e0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12ee <main+0xbe>
lea    0xd1e(%rip),%rdi
jmp    1497 <main+0x267>
mov    %ebx,%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
cmp    $0xffffffff,%eax
jne    130b <main+0xdb>
lea    0xd06(%rip),%rdi
jmp    1497 <main+0x267>
lea    0xd6b(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
call   10b0 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1140 <FD_SET@plt>
mov    (%rsp),%eax
mov    %eax,0x4(%rsp)
movl   $0x10,0x8(%rsp)
lea    0x30(%rsp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
mov    0x2c6d(%rip),%r13
mov    0x0(%r13),%edi
lea    0x4(%rsp),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10c0 <select@plt>
test   %rax,%rax
jle    1473 <main+0x243>
lea    0x4(%rsp),%r14
lea    0x30(%rsp),%r15
jmp    13ba <main+0x18a>
nopl   (%rax)
mov    (%rsp),%eax
mov    %eax,0x4(%rsp)
movl   $0x10,0x8(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
mov    0x0(%r13),%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10c0 <select@plt>
test   %rax,%rax
jle    1473 <main+0x243>
cmpl   $0x0,0x0(%r13)
jle    1380 <main+0x150>
xor    %r12d,%r12d
jmp    13f4 <main+0x1c4>
mov    %r12d,%edi
call   10a0 <close@plt>
mov    %r12d,%edi
mov    %rsp,%rsi
call   1120 <FD_CLR@plt>
lea    0xc81(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
add    $0x1,%r12d
cmp    0x0(%r13),%r12d
jge    1380 <main+0x150>
mov    %r12d,%edi
mov    %r14,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
jle    13ea <main+0x1ba>
cmp    %r12d,%ebx
jne    1440 <main+0x210>
mov    %ebx,%edi
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1110 <accept@plt>
cmp    $0xffffffff,%eax
je     1490 <main+0x260>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rsp,%rsi
call   1140 <FD_SET@plt>
lea    0xbef(%rip),%rdi
mov    %ebp,%esi
jmp    13e3 <main+0x1b3>
cs nopw 0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    13c6 <main+0x196>
lea    0xbe0(%rip),%rdi
mov    %r12d,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    13ea <main+0x1ba>
lea    0xb99(%rip),%rdi
call   10f0 <perror@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    0xb83(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %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 = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [7 x i8] c"listen\00"
@.str.3 = [15 x i8] c"listening....\0A\00"
@FD_SETSIZE = global i32 0
@.str.4 = [7 x i8] c"select\00"
@.str.5 = [7 x i8] c"accept\00"
@.str.6 = [32 x i8] c"New connection from %d(socket)\0A\00"
@.str.7 = [32 x i8] c"Received a message from %d: %s\0A\00"
@.str.8 = [28 x i8] c"Client %d(socket) has left\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1024 x i8]
%12 = alloca i32
store i32 0, i32* %1
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %8
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 3
store i32 %21, i32* %22
%23 = call i32 @htons(i32 4321)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
%29 = call i32 @bzero(i32* %28, i32 8)
store i32 1, i32* %12
%30 = load i32, i32* %8
%31 = load i32, i32* @SOL_SOCKET
%32 = load i32, i32* @SO_REUSEADDR
%33 = call i32 @setsockopt(i32 %30, i32 %31, i32 %32, i32* %12, i32 4)
%34 = load i32, i32* %8
%35 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%36 = call i32 @bind(i32 %34, %struct.sockaddr* %35, i32 4)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %20
%39 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %20
%42 = load i32, i32* %8
%43 = call i32 @listen(i32 %42, i32 5)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %41
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%50 = call i32 @FD_ZERO(i32* %6)
%51 = load i32, i32* %8
%52 = call i32 @FD_SET(i32 %51, i32* %6)
br label %53
53: ; preds = %48, %113
%54 = load i32, i32* %6
store i32 %54, i32* %7
store i32 16, i32* %4
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%56 = call i32 @memset(i8* %55, i32 0, i32 1024)
%57 = load i32, i32* @FD_SETSIZE
%58 = call i64 @select(i32 %57, i32* %7, i32* null, i32* null, i32* null)
%59 = icmp sgt i64 %58, 0
br i1 %59, label %65, label %60
60: ; preds = %53
%61 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%62 = load i32, i32* %8
%63 = call i32 @close(i32 %62)
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %53
store i32 0, i32* %10
br label %66
66: ; preds = %110, %65
%67 = load i32, i32* %10
%68 = load i32, i32* @FD_SETSIZE
%69 = icmp slt i32 %67, %68
br i1 %69, label %70, label %113
70: ; preds = %66
%71 = load i32, i32* %10
%72 = call i64 @FD_ISSET(i32 %71, i32* %7)
%73 = icmp sgt i64 %72, 0
br i1 %73, label %74, label %109
74: ; preds = %70
%75 = load i32, i32* %10
%76 = load i32, i32* %8
%77 = icmp eq i32 %75, %76
br i1 %77, label %78, label %91
78: ; preds = %74
%79 = load i32, i32* %8
%80 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%81 = call i32 @accept(i32 %79, %struct.sockaddr* %80, i32* %4)
store i32 %81, i32* %9
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %86
83: ; preds = %78
%84 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %78
%87 = load i32, i32* %9
%88 = call i32 @FD_SET(i32 %87, i32* %6)
%89 = load i32, i32* %9
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %89)
br label %108
91: ; preds = %74
%92 = load i32, i32* %10
%93 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%94 = call i32 @recv(i32 %92, i8* %93, i32 1024, i32 0)
store i32 %94, i32* %5
%95 = icmp sgt i32 %94, 0
br i1 %95, label %96, label %100
96: ; preds = %91
%97 = load i32, i32* %10
%98 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %97, i8* %98)
br label %107
100: ; preds = %91
%101 = load i32, i32* %10
%102 = call i32 @close(i32 %101)
%103 = load i32, i32* %10
%104 = call i32 @FD_CLR(i32 %103, i32* %6)
%105 = load i32, i32* %10
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i32 %105)
br label %107
107: ; preds = %100, %96
br label %108
108: ; preds = %107, %86
br label %109
109: ; preds = %108, %70
br label %110
110: ; preds = %109
%111 = load i32, i32* %10
%112 = add nsw i32 %111, 1
store i32 %112, i32* %10
br label %66
113: ; preds = %66
br label %53
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %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 = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [7 x i8] c"listen\00"
@FD_SETSIZE = global i32 0
@.str.4 = [7 x i8] c"select\00"
@.str.5 = [7 x i8] c"accept\00"
@.str.6 = [32 x i8] c"New connection from %d(socket)\0A\00"
@.str.7 = [32 x i8] c"Received a message from %d: %s\0A\00"
@.str.8 = [28 x i8] c"Client %d(socket) has left\0A\00"
@str = [14 x i8] c"listening....\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = bitcast %struct.sockaddr_in* %1 to i8*
%9 = bitcast %struct.sockaddr_in* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %0
%19 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %0
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 3
store i32 %22, i32* %23
%24 = tail call i32 @htons(i32 4321)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %24, i32* %25
%26 = load i32, i32* @INADDR_ANY
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%29 = call i32 @bzero(i32* %28, i32 8)
%30 = bitcast i32* %7 to i8*
store i32 1, i32* %7
%31 = load i32, i32* @SOL_SOCKET
%32 = load i32, i32* @SO_REUSEADDR
%33 = call i32 @setsockopt(i32 %16, i32 %31, i32 %32, i32* %7, i32 4)
%34 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%35 = call i32 @bind(i32 %16, %struct.sockaddr* %34, i32 4)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %21
%38 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %21
%41 = call i32 @listen(i32 %16, i32 5)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %40
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%48 = call i32 @FD_ZERO(i32* %4)
%49 = call i32 @FD_SET(i32 %16, i32* %4)
%50 = load i32, i32* %4
store i32 %50, i32* %5
store i32 16, i32* %3
%51 = call i32 @memset(i8* %13, i32 0, i32 1024)
%52 = load i32, i32* @FD_SETSIZE
%53 = call i64 @select(i32 %52, i32* %5, i32* null, i32* null, i32* null)
%54 = icmp sgt i64 %53, 0
br i1 %54, label %55, label %66
55: ; preds = %46
%56 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
br label %63
57: ; preds = %94, %63
%58 = load i32, i32* %4
store i32 %58, i32* %5
store i32 16, i32* %3
%59 = call i32 @memset(i8* %13, i32 0, i32 1024)
%60 = load i32, i32* @FD_SETSIZE
%61 = call i64 @select(i32 %60, i32* %5, i32* null, i32* null, i32* null)
%62 = icmp sgt i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %55, %57
%64 = load i32, i32* @FD_SETSIZE
%65 = icmp sgt i32 %64, 0
br i1 %65, label %70, label %57
66: ; preds = %57, %46
%67 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%68 = call i32 @close(i32 %16)
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %63, %94
%71 = phi i32 [ %95, %94 ], [ 0, %63 ]
%72 = call i64 @FD_ISSET(i32 %71, i32* %5)
%73 = icmp sgt i64 %72, 0
br i1 %73, label %74, label %94
74: ; preds = %70
%75 = icmp eq i32 %71, %16
br i1 %75, label %76, label %85
76: ; preds = %74
%77 = call i32 @accept(i32 %16, %struct.sockaddr* %56, i32* %3)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %82
79: ; preds = %76
%80 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %76
%83 = call i32 @FD_SET(i32 %77, i32* %4)
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %77)
br label %94
85: ; preds = %74
%86 = call i32 @recv(i32 %71, i8* %13, i32 1024, i32 0)
%87 = icmp sgt i32 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %85
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %71, i8* %13)
br label %94
90: ; preds = %85
%91 = call i32 @close(i32 %71)
%92 = call i32 @FD_CLR(i32 %71, i32* %4)
%93 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i32 %71)
br label %94
94: ; preds = %70, %88, %90, %82
%95 = add nuw nsw i32 %71, 1
%96 = load i32, i32* @FD_SETSIZE
%97 = icmp slt i32 %95, %96
br i1 %97, label %70, label %57
}