#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*/ timeout;
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ client_addr;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ SO_REUSEPORT;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int htons(int);
char *inet_ntoa(TYPE_1__);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int server_socket;
  if ((server_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket()");
    exit(1);
  }
  int yes = 1;
  if (setsockopt(server_socket, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(int)) ==
      -1) {
    perror("setsockopt()");
    exit(1);
  }
  struct timeval timeout;
  timeout.tv_sec = 10;
  timeout.tv_usec = 0;
  if (setsockopt(server_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,
                 sizeof(timeout)) == -1) {
    perror("setsockopt()");
    exit(1);
  }
  struct sockaddr_in server_addr;
  memset((void *)&server_addr, 0, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(5555);
  server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(server_socket, (struct sockaddr *)&server_addr,
           sizeof(server_addr)) < 0) {
    perror("bind()");
    exit(1);
  }
  if (listen(server_socket, 5) < 0) {
    perror("listen()");
    exit(1);
  }
  int accept_socket;
  struct sockaddr_in client_addr;
  int client_addr_len = sizeof(client_addr);
  char buffer[1024];
  int iDataNum;
  while (1) {
    printf("accept() ... start\n");
    accept_socket = accept(server_socket, (struct sockaddr *)&client_addr,
                           (socklen_t *)&client_addr_len);
    if (accept_socket < 0) {
      perror("accept()");
      break;
    } else {
      printf("accept() ... done\n");
      printf("Server socket fd = %d\n", server_socket);
      printf("Accept socket fd = %d\n", accept_socket);
    }
    struct timeval timeout;
    timeout.tv_sec = 6;
    timeout.tv_usec = 0;
    if (setsockopt(accept_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,
                   sizeof(timeout)) == -1) {
      perror("setsockopt()");
      exit(1);
    }
    printf("recv() ... start\n");
    iDataNum = recv(accept_socket, buffer, sizeof(buffer), 0);
    if (iDataNum < 0) {
      perror("recv()");
      close(accept_socket);
      continue;
    } else {
      printf("recv() ... done\n");
    }
    printf("IP is %s\n", inet_ntoa(client_addr.sin_addr));
    printf("Port is %d\n", htons(client_addr.sin_port));
    printf("Recv length is %d\n", iDataNum);
    printf("Recv Data   is %s\n\n", buffer);
    send(accept_socket, buffer, sizeof(buffer), 0);
    printf("close client connect ... start\n");
    close(accept_socket);
    printf("close client connect ... done\n");
    if (strcmp(buffer, "quit") == 0) {
      break;
    }
  }
  printf("close server socket ... start\n");
  close(server_socket);
  printf("close server socket ... done\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1254 <main+0x54>
lea    0xdbb(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
mov    0x2d6a(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    12a0 <main+0xa0>
lea    0xd78(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
movl   $0xa,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d2f(%rip),%rax
mov    (%rax),%esi
mov    0x2cfe(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rcx
mov    $0x10,%r8d
mov    $0x0,%al
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    12f4 <main+0xf4>
lea    0xd24(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x2cd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    $0x15b3,%edi
call   1060 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0x0,%rax
jge    135f <main+0x15f>
lea    0xcc6(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
cmp    $0x0,%rax
jge    138c <main+0x18c>
lea    0xca0(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
movl   $0xc,-0x4c(%rbp)
lea    0xc8c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    13cf <main+0x1cf>
lea    0xc75(%rip),%rdi
call   10f0 <perror@plt>
jmp    1575 <main+0x375>
lea    0xc6d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xc6f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x3c(%rbp),%esi
lea    0xc75(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x6,-0x468(%rbp)
movq   $0x0,-0x460(%rbp)
mov    -0x3c(%rbp),%edi
mov    0x2bca(%rip),%rax
mov    (%rax),%esi
mov    0x2b99(%rip),%rax
mov    (%rax),%edx
lea    -0x468(%rbp),%rcx
mov    $0x10,%r8d
mov    $0x0,%al
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    145c <main+0x25c>
lea    0xbbc(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xc21(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x3c(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x454(%rbp)
cmpl   $0x0,-0x454(%rbp)
jge    14ac <main+0x2ac>
lea    0xbfc(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x3c(%rbp),%edi
call   10b0 <close@plt>
jmp    1393 <main+0x193>
lea    0xbea(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x44(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xbe2(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x48(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,%esi
lea    0xbd4(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x454(%rbp),%esi
lea    0xbcc(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x450(%rbp),%rsi
lea    0xbca(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x3c(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
lea    0xbba(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x3c(%rbp),%edi
call   10b0 <close@plt>
lea    0xbc4(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x450(%rbp),%rdi
lea    0xbce(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1570 <main+0x370>
jmp    1575 <main+0x375>
jmp    1393 <main+0x193>
lea    0xbb3(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
lea    0xbbc(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x458,%rsp
mov    0x2db8(%rip),%r14
mov    (%r14),%edi
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
test   %eax,%eax
js     1531 <main+0x321>
mov    %eax,%ebx
movl   $0x1,0xc(%rsp)
mov    0x2d94(%rip),%rbp
mov    0x0(%rbp),%esi
mov    0x2d7a(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    $0x4,%r8d
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     151b <main+0x30b>
movl   $0xa,0x40(%rsp)
movq   $0x0,0x48(%rsp)
mov    0x0(%rbp),%esi
mov    0x2d28(%rip),%rax
mov    (%rax),%edx
lea    0x40(%rsp),%rcx
mov    $0x10,%r8d
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     151b <main+0x30b>
lea    0x20(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10b0 <memset@plt>
mov    (%r14),%eax
mov    %eax,0x28(%rsp)
mov    $0x15b3,%edi
call   1070 <htons@plt>
mov    %eax,0x20(%rsp)
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,0x24(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
test   %rax,%rax
js     153a <main+0x32a>
mov    %ebx,%edi
mov    $0x5,%esi
call   10e0 <listen@plt>
test   %rax,%rax
js     1543 <main+0x333>
movl   $0xc,0x8(%rsp)
lea    0xd78(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1110 <accept@plt>
test   %eax,%eax
js     150d <main+0x2fd>
mov    %eax,%r13d
lea    0x50(%rsp),%r14
jmp    139b <main+0x18b>
lea    0xd00(%rip),%rdi
call   1100 <perror@plt>
mov    %r13d,%edi
call   10c0 <close@plt>
nopw   0x0(%rax,%rax,1)
lea    0xd2f(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1110 <accept@plt>
mov    %eax,%r13d
test   %eax,%eax
mov    %r15,%rbp
js     150d <main+0x2fd>
lea    0xd17(%rip),%rdi
call   1040 <puts@plt>
lea    0xc81(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xc88(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1090 <printf@plt>
movl   $0x6,0x30(%rsp)
movq   $0x0,0x38(%rsp)
mov    %rbp,%r15
mov    0x0(%rbp),%esi
mov    0x2bda(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%r8d
mov    %r13d,%edi
lea    0x30(%rsp),%rcx
xor    %eax,%eax
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     151b <main+0x30b>
lea    0xcbe(%rip),%rdi
call   1040 <puts@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     1356 <main+0x146>
mov    %eax,%r12d
lea    0xca6(%rip),%rdi
call   1040 <puts@plt>
mov    0x14(%rsp),%edi
call   1060 <inet_ntoa@plt>
lea    0xc19(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x10(%rsp),%edi
call   1070 <htons@plt>
lea    0xc09(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xc05(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xc07(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
lea    0xc43(%rip),%rdi
call   1040 <puts@plt>
mov    %r13d,%edi
call   10c0 <close@plt>
lea    0xc4e(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
lea    0xbd5(%rip),%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
jne    1370 <main+0x160>
lea    0xc48(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   10c0 <close@plt>
lea    0xc53(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x458,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb12(%rip),%rdi
call   1100 <perror@plt>
jmp    14da <main+0x2ca>
lea    0xae7(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    0xac8(%rip),%rdi
jmp    1522 <main+0x312>
lea    0xad5(%rip),%rdi
jmp    1522 <main+0x312>
lea    0xad3(%rip),%rdi
jmp    1522 <main+0x312>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
%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 = [9 x i8] c"socket()\00"
@SOL_SOCKET = global i32 0
@SO_REUSEPORT = global i32 0
@.str.1 = [13 x i8] c"setsockopt()\00"
@SO_RCVTIMEO = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [7 x i8] c"bind()\00"
@.str.3 = [9 x i8] c"listen()\00"
@.str.4 = [20 x i8] c"accept() ... start\0A\00"
@.str.5 = [9 x i8] c"accept()\00"
@.str.6 = [19 x i8] c"accept() ... done\0A\00"
@.str.7 = [23 x i8] c"Server socket fd = %d\0A\00"
@.str.8 = [23 x i8] c"Accept socket fd = %d\0A\00"
@.str.9 = [18 x i8] c"recv() ... start\0A\00"
@.str.10 = [7 x i8] c"recv()\00"
@.str.11 = [17 x i8] c"recv() ... done\0A\00"
@.str.12 = [10 x i8] c"IP is %s\0A\00"
@.str.13 = [12 x i8] c"Port is %d\0A\00"
@.str.14 = [19 x i8] c"Recv length is %d\0A\00"
@.str.15 = [20 x i8] c"Recv Data is %s\0A\0A\00"
@.str.16 = [32 x i8] c"close client connect ... start\0A\00"
@.str.17 = [31 x i8] c"close client connect ... done\0A\00"
@.str.18 = [5 x i8] c"quit\00"
@.str.19 = [31 x i8] c"close server socket ... start\0A\00"
@.str.20 = [30 x i8] c"close server socket ... done\0A\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.timeval
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
%13 = alloca [1024 x i8]
%14 = alloca i32
%15 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
store i32 1, i32* %7
%24 = load i32, i32* %6
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_REUSEPORT
%27 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %24, i32 %25, i32 %26, i32* %7, i64 4)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %23
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
store i32 10, i32* %33
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
store i64 0, i64* %34
%35 = load i32, i32* %6
%36 = load i32, i32* @SOL_SOCKET
%37 = load i32, i32* @SO_RCVTIMEO
%38 = bitcast %struct.timeval* %8 to i8*
%39 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %35, i32 %36, i32 %37, i8* %38, i64 16)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %32
%42 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %32
%45 = bitcast %struct.sockaddr_in* %9 to i8*
%46 = call i32 @memset(i8* %45, i32 0, i32 12)
%47 = load i32, i32* @AF_INET
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %47, i32* %48
%49 = call i32 @htons(i32 5555)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %49, i32* %50
%51 = load i32, i32* @INADDR_ANY
%52 = call i32 @htonl(i32 %51)
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%54 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %53, i32 0, i32 0
store i32 %52, i32* %54
%55 = load i32, i32* %6
%56 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%57 = call i64 @bind(i32 %55, %struct.sockaddr* %56, i32 12)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %44
%60 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %44
%63 = load i32, i32* %6
%64 = call i64 @listen(i32 %63, i32 5)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %62
%67 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %62
store i32 12, i32* %12
br label %70
70: ; preds = %69, %104, %135
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%72 = load i32, i32* %6
%73 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%74 = call i32 @accept(i32 %72, %struct.sockaddr* %73, i32* %12)
store i32 %74, i32* %10
%75 = load i32, i32* %10
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %70
%78 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %136
79: ; preds = %70
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%81 = load i32, i32* %6
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %81)
%83 = load i32, i32* %10
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %83)
br label %85
85: ; preds = %79
%86 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
store i32 6, i32* %86
%87 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
store i64 0, i64* %87
%88 = load i32, i32* %10
%89 = load i32, i32* @SOL_SOCKET
%90 = load i32, i32* @SO_RCVTIMEO
%91 = bitcast %struct.timeval* %15 to i8*
%92 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %88, i32 %89, i32 %90, i8* %91, i64 16)
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %97
94: ; preds = %85
%95 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %85
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%99 = load i32, i32* %10
%100 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%101 = call i32 @recv(i32 %99, i8* %100, i32 1024, i32 0)
store i32 %101, i32* %14
%102 = load i32, i32* %14
%103 = icmp slt i32 %102, 0
br i1 %103, label %104, label %108
104: ; preds = %97
%105 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%106 = load i32, i32* %10
%107 = call i32 @close(i32 %106)
br label %70
108: ; preds = %97
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
br label %110
110: ; preds = %108
%111 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%112 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %111, i32 0, i32 0
%113 = load i32, i32* %112
%114 = call i8* @inet_ntoa(i32 %113)
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0), i8* %114)
%116 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%117 = load i32, i32* %116
%118 = call i32 @htons(i32 %117)
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0), i32 %118)
%120 = load i32, i32* %14
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.14, i64 0, i64 0), i32 %120)
%122 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.15, i64 0, i64 0), i8* %122)
%124 = load i32, i32* %10
%125 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%126 = call i32 @send(i32 %124, i8* %125, i32 1024, i32 0)
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.16, i64 0, i64 0))
%128 = load i32, i32* %10
%129 = call i32 @close(i32 %128)
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.17, i64 0, i64 0))
%131 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%132 = call i64 @strcmp(i8* %131, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.18, i64 0, i64 0))
%133 = icmp eq i64 %132, 0
br i1 %133, label %134, label %135
134: ; preds = %110
br label %136
135: ; preds = %110
br label %70
136: ; preds = %134, %77
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.19, i64 0, i64 0))
%138 = load i32, i32* %6
%139 = call i32 @close(i32 %138)
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.20, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
%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 = [9 x i8] c"socket()\00"
@SOL_SOCKET = global i32 0
@SO_REUSEPORT = global i32 0
@.str.1 = [13 x i8] c"setsockopt()\00"
@SO_RCVTIMEO = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [7 x i8] c"bind()\00"
@.str.3 = [9 x i8] c"listen()\00"
@.str.5 = [9 x i8] c"accept()\00"
@.str.7 = [23 x i8] c"Server socket fd = %d\0A\00"
@.str.8 = [23 x i8] c"Accept socket fd = %d\0A\00"
@.str.10 = [7 x i8] c"recv()\00"
@.str.12 = [10 x i8] c"IP is %s\0A\00"
@.str.13 = [12 x i8] c"Port is %d\0A\00"
@.str.14 = [19 x i8] c"Recv length is %d\0A\00"
@.str.15 = [20 x i8] c"Recv Data is %s\0A\0A\00"
@.str.18 = [5 x i8] c"quit\00"
@str = [19 x i8] c"accept() ... start\00"
@str.21 = [18 x i8] c"accept() ... done\00"
@str.22 = [17 x i8] c"recv() ... start\00"
@str.23 = [16 x i8] c"recv() ... done\00"
@str.24 = [31 x i8] c"close client connect ... start\00"
@str.25 = [30 x i8] c"close client connect ... done\00"
@str.26 = [30 x i8] c"close server socket ... start\00"
@str.27 = [29 x i8] c"close server socket ... done\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca %struct.timeval
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%19 = load i32, i32* @SOL_SOCKET
%20 = load i32, i32* @SO_REUSEPORT
%21 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %12, i32 %19, i32 %20, i32* %3, i64 4)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %17
%27 = bitcast %struct.timeval* %4 to i8*
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 10, i32* %28
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i64 0, i64* %29
%30 = load i32, i32* @SOL_SOCKET
%31 = load i32, i32* @SO_RCVTIMEO
%32 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %12, i32 %30, i32 %31, %struct.timeval* %4, i64 16)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %26
%38 = bitcast %struct.sockaddr_in* %5 to i8*
%39 = call i32 @memset(i8* %38, i32 0, i32 12)
%40 = load i32, i32* @AF_INET
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %40, i32* %41
%42 = call i32 @htons(i32 5555)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %42, i32* %43
%44 = load i32, i32* @INADDR_ANY
%45 = call i32 @htonl(i32 %44)
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %45, i32* %46
%47 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%48 = call i64 @bind(i32 %12, %struct.sockaddr* %47, i32 12)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %37
%51 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %37
%54 = call i64 @listen(i32 %12, i32 5)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %53
%60 = bitcast %struct.sockaddr_in* %6 to i8*
%61 = bitcast i32* %7 to i8*
store i32 12, i32* %7
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%63 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%64 = bitcast %struct.timeval* %9 to i8*
%65 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i64 0, i32 0
%66 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i64 0, i32 1
%67 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1, i32 0
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%70 = call i32 @accept(i32 %12, %struct.sockaddr* %63, i32* %7)
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %109, %59
%73 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %114
74: ; preds = %59, %109
%75 = phi i32 [ %111, %109 ], [ %70, %59 ]
%76 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.21, i64 0, i64 0))
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %12)
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %75)
store i32 6, i32* %65
store i64 0, i64* %66
%79 = load i32, i32* @SOL_SOCKET
%80 = load i32, i32* @SO_RCVTIMEO
%81 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %75, i32 %79, i32 %80, %struct.timeval* %9, i64 16)
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %86
83: ; preds = %74
%84 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %74
%87 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.22, i64 0, i64 0))
%88 = call i32 @recv(i32 %75, i8* %62, i32 1024, i32 0)
%89 = icmp slt i32 %88, 0
br i1 %89, label %90, label %93
90: ; preds = %86
%91 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%92 = call i32 @close(i32 %75)
br label %109
93: ; preds = %86
%94 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.23, i64 0, i64 0))
%95 = load i32, i32* %67
%96 = call i8* @inet_ntoa(i32 %95)
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0), i8* %96)
%98 = load i32, i32* %68
%99 = call i32 @htons(i32 %98)
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0), i32 %99)
%101 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.14, i64 0, i64 0), i32 %88)
%102 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.15, i64 0, i64 0), i8* %62)
%103 = call i32 @send(i32 %75, i8* %62, i32 1024, i32 0)
%104 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.24, i64 0, i64 0))
%105 = call i32 @close(i32 %75)
%106 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.25, i64 0, i64 0))
%107 = call i64 @strcmp(i8* %62, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.18, i64 0, i64 0))
%108 = icmp eq i64 %107, 0
br i1 %108, label %113, label %109
109: ; preds = %93, %90
%110 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%111 = call i32 @accept(i32 %12, %struct.sockaddr* %63, i32* %7)
%112 = icmp slt i32 %111, 0
br i1 %112, label %72, label %74
113: ; preds = %93
br label %114
114: ; preds = %113, %72
%115 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.26, i64 0, i64 0))
%116 = call i32 @close(i32 %12)
%117 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.27, i64 0, i64 0))
ret i32 0
}