#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 */
typedef int /*<<< orphan*/ svr_addr;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ remaddr;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SETSIZE;
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, unsigned char *, int, int /*<<< orphan*/);
int select(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ send(int, unsigned char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int s = 0;
  struct sockaddr_in svr_addr;
  struct sockaddr_in remaddr;
  socklen_t addrlen = sizeof(remaddr);
  int recvlen;
  int rqst;
  unsigned char buf[1024];
  fd_set readset;
  int selectRet;
  if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("cannot create socket.\n");
    return 0;
  }
  memset((char *)&svr_addr, 0, sizeof(svr_addr));
  svr_addr.sin_family = AF_INET;
  svr_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  svr_addr.sin_port = htons(11111);
  if (bind(s, (struct sockaddr *)&svr_addr, sizeof(svr_addr)) < 0) {
    printf("bind failed.\n");
    close(s);
    return 0;
  }
  if (listen(s, 5) < 0) {
    printf("listen error\n");
    close(s);
    return 0;
  }
  printf("waiting on port(11111).\n");
  FD_ZERO(&readset);
  FD_SET(s, &readset);
  selectRet = select(FD_SETSIZE, &readset, NULL, NULL, NULL);
  switch (selectRet) {
  case 0:
    printf("select timeout\n");
    break;
  case -1:
    perror("select");
    break;
  default:
    if (FD_ISSET(s, &readset)) {
      if ((rqst = accept(s, (struct sockaddr *)&remaddr, &addrlen)) < 0)
        printf("connect fail\n");
      else
        printf("got connect\n");
      recvlen = recv(rqst, buf, 1024, 0);
      if (recvlen < 0) {
        perror("recv\n");
      } else if (recvlen == 0) {
        printf("received close\n");
        close(rqst);
      } else {
        printf("received %d bytes\n", recvlen);
      }
      if (recvlen > 0) {
        buf[recvlen] = 0;
        printf("received message:%s.\n", buf);
        send(rqst, buf, recvlen, 0);
        close(rqst);
      }
    }
    break;
  }
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0xc,-0x34(%rbp)
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1266 <main+0x66>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14eb <main+0x2eb>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x2b67,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0x0,%rax
jge    12dd <main+0xdd>
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    14eb <main+0x2eb>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
cmp    $0x0,%rax
jge    1316 <main+0x116>
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    14eb <main+0x2eb>
lea    0xd16(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x450(%rbp)
call   1070 <printf@plt>
lea    -0x444(%rbp),%rdi
mov    %rdi,-0x458(%rbp)
call   10b0 <FD_ZERO@plt>
mov    -0x458(%rbp),%rsi
mov    -0x14(%rbp),%edi
call   1110 <FD_SET@plt>
mov    -0x458(%rbp),%rsi
mov    -0x450(%rbp),%eax
mov    0x2c68(%rip),%rcx
mov    (%rcx),%edi
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10c0 <select@plt>
mov    %eax,-0x448(%rbp)
mov    -0x448(%rbp),%eax
mov    %eax,-0x44c(%rbp)
sub    $0xffffffff,%eax
je     13b6 <main+0x1b6>
jmp    1390 <main+0x190>
mov    -0x44c(%rbp),%eax
test   %eax,%eax
jne    13c7 <main+0x1c7>
jmp    13a3 <main+0x1a3>
lea    0xca2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14dc <main+0x2dc>
lea    0xc9f(%rip),%rdi
call   10f0 <perror@plt>
jmp    14dc <main+0x2dc>
mov    -0x14(%rbp),%edi
lea    -0x444(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%eax
je     14d7 <main+0x2d7>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jge    140e <main+0x20e>
lea    0xc61(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    141c <main+0x21c>
lea    0xc5c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x3c(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    1450 <main+0x250>
lea    0xc38(%rip),%rdi
call   10f0 <perror@plt>
jmp    148b <main+0x28b>
cmpl   $0x0,-0x38(%rbp)
jne    1475 <main+0x275>
lea    0xc23(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x3c(%rbp),%edi
call   10a0 <close@plt>
jmp    1486 <main+0x286>
mov    -0x38(%rbp),%esi
lea    0xc15(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    148b <main+0x28b>
cmpl   $0x0,-0x38(%rbp)
jle    14d2 <main+0x2d2>
movslq -0x38(%rbp),%rax
movb   $0x0,-0x440(%rbp,%rax,1)
lea    -0x440(%rbp),%rsi
lea    0xbf8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x3c(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    -0x38(%rbp),%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x3c(%rbp),%edi
call   10a0 <close@plt>
jmp    14d7 <main+0x2d7>
jmp    14dc <main+0x2dc>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x430,%rsp
movl   $0xc,0xc(%rsp)
mov    0x2dba(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
test   %eax,%eax
js     13a2 <main+0x192>
mov    %eax,%r12d
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x2b67,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
test   %rax,%rax
js     13b0 <main+0x1a0>
mov    %r12d,%edi
mov    $0x5,%esi
call   10e0 <listen@plt>
test   %rax,%rax
js     13be <main+0x1ae>
lea    0xd7b(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   10c0 <FD_ZERO@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
call   1120 <FD_SET@plt>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10d0 <select@plt>
test   %eax,%eax
je     13cc <main+0x1bc>
cmp    $0xffffffff,%eax
je     1408 <main+0x1f8>
lea    0x8(%rsp),%rsi
mov    %r12d,%edi
call   1050 <FD_ISSET@plt>
test   %eax,%eax
je     13ee <main+0x1de>
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r12d,%edi
call   1110 <accept@plt>
mov    %eax,%r14d
test   %eax,%eax
lea    0xd44(%rip),%rax
lea    0xd22(%rip),%rdi
cmovs  %rax,%rdi
call   1040 <puts@plt>
lea    0x30(%rsp),%rsi
mov    %r14d,%edi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     1416 <main+0x206>
je     13da <main+0x1ca>
mov    %eax,%ebp
lea    0xca2(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebp,%eax
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xc9e(%rip),%rdi
lea    0x30(%rsp),%r15
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
jmp    13e6 <main+0x1d6>
lea    0xcf6(%rip),%rdi
call   1040 <puts@plt>
jmp    13f6 <main+0x1e6>
lea    0xcdb(%rip),%rdi
call   1040 <puts@plt>
jmp    13ee <main+0x1de>
lea    0xcc0(%rip),%rdi
call   1040 <puts@plt>
jmp    13ee <main+0x1de>
lea    0xc7b(%rip),%rdi
call   1040 <puts@plt>
jmp    13ee <main+0x1de>
lea    0xc88(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
call   10b0 <close@plt>
mov    %r12d,%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbf1(%rip),%rdi
call   1100 <perror@plt>
jmp    13ee <main+0x1de>
lea    0xbea(%rip),%rdi
call   1100 <perror@plt>
jmp    13ee <main+0x1de>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@FD_SETSIZE = global i32 0
@.str.5 = [7 x i8] c"select\00"
@.str.8 = [6 x i8] c"recv\0A\00"
@.str.10 = [19 x i8] c"received %d bytes\0A\00"
@.str.11 = [22 x i8] c"received message:%s.\0A\00"
@str = [24 x i8] c"waiting on port(11111).\00"
@str.12 = [15 x i8] c"select timeout\00"
@str.13 = [12 x i8] c"got connect\00"
@str.14 = [15 x i8] c"received close\00"
@str.15 = [13 x i8] c"connect fail\00"
@str.16 = [13 x i8] c"listen error\00"
@str.17 = [13 x i8] c"bind failed.\00"
@str.18 = [22 x i8] c"cannot create socket.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = bitcast i32* %5 to i8*
store i32 12, i32* %5
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = bitcast i32* %7 to i8*
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.18, i64 0, i64 0))
br label %77
19: ; preds = %2
%20 = call i32 @memset(i8* %8, i32 0, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
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* %3, i64 0, i32 1, i32 0
store i32 %24, i32* %25
%26 = call i32 @htons(i32 11111)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %26, i32* %27
%28 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%29 = call i64 @bind(i32 %15, %struct.sockaddr* %28, i32 12)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %19
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.17, i64 0, i64 0))
%33 = call i32 @close(i32 %15)
br label %77
34: ; preds = %19
%35 = call i64 @listen(i32 %15, i32 5)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.16, i64 0, i64 0))
%39 = call i32 @close(i32 %15)
br label %77
40: ; preds = %34
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%42 = call i32 @FD_ZERO(i32* %7)
%43 = call i32 @FD_SET(i32 %15, i32* %7)
%44 = load i32, i32* @FD_SETSIZE
%45 = call i32 @select(i32 %44, i32* %7, i32* null, i32* null, i32* null)
switch i32 %45, label %50 [
i32 0, label %46
i32 -1, label %48
]
46: ; preds = %40
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.12, i64 0, i64 0))
br label %75
48: ; preds = %40
%49 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %75
50: ; preds = %40
%51 = call i32 @FD_ISSET(i32 %15, i32* %7)
%52 = icmp eq i32 %51, 0
br i1 %52, label %75, label %53
53: ; preds = %50
%54 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%55 = call i32 @accept(i32 %15, %struct.sockaddr* %54, i32* %5)
%56 = icmp slt i32 %55, 0
%57 = select i1 %56, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str.15, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0)
%58 = call i32 @puts(i8* dereferenceable(1) %57)
%59 = call i32 @recv(i32 %55, i8* %11, i32 1024, i32 0)
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %53
%62 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
br label %75
63: ; preds = %53
%64 = icmp eq i32 %59, 0
br i1 %64, label %65, label %68
65: ; preds = %63
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.14, i64 0, i64 0))
%67 = call i32 @close(i32 %55)
br label %75
68: ; preds = %63
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i32 %59)
%70 = zext i32 %59 to i64
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %70
store i8 0, i8* %71
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i8* %11)
%73 = call i32 @send(i32 %55, i8* %11, i32 %59, i32 0)
%74 = call i32 @close(i32 %55)
br label %75
75: ; preds = %61, %65, %50, %68, %48, %46
%76 = call i32 @close(i32 %15)
br label %77
77: ; preds = %75, %37, %31, %17
ret i32 0
}