#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*/ u_short;
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 /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ optval;
typedef int /*<<< orphan*/ client_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
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*/ close(int);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int listen(int, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char const *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int main(void) {
  int soc;
  struct sockaddr_in server_addr;
  int optval = 1;
  int acc;
  struct sockaddr_in client_addr;
  int client_addr_len;
  char *client_ip_addr_str;
  u_short client_port;
  char buf[256];
  int exit_flg = 0;
  int recv_len;
  soc = socket(AF_INET, SOCK_STREAM, 0);
  if (soc == -1) {
    printf("socket error!\n");
    return -1;
  }
  printf("soc = %d\n", soc);
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(3000);
  server_addr.sin_addr.s_addr = INADDR_ANY;
  if (setsockopt(soc, SOL_SOCKET, SO_REUSEADDR, (const char *)&optval,
                 sizeof(optval)) == -1) {
    printf("setsockopt(SO_REUSEADDR) error!\n");
    close(soc);
    return -1;
  }
  printf("setsockopt(SO_REUSEADDR) success.\n");
  if (bind(soc, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) {
    printf("bind error!\n");
    close(soc);
    return -1;
  }
  printf("bind success.\n");
  if (listen(soc, 5) == -1) {
    printf("listen error!\n");
    close(soc);
    return -1;
  }
  printf("listen success.\n");
  client_addr_len = sizeof(client_addr);
  acc = accept(soc, (struct sockaddr *)&client_addr, &client_addr_len);
  if (acc == -1) {
    printf("accept error!\n");
    close(soc);
    return -1;
  }
  client_ip_addr_str = inet_ntoa(client_addr.sin_addr);
  client_port = ntohs(client_addr.sin_port);
  printf("accept!(IPAddress = %s, Port = %hu)\n", client_ip_addr_str,
         client_port);
  memset(buf, 0, sizeof(char) * 256);
  while (!exit_flg) {
    recv_len = recv(acc, buf, sizeof(char) * 256, 0);
    buf[recv_len - 1] = '\0';
    buf[recv_len - 2] = '\0';
    if (strcmp(buf, "end") == 0) {
      exit_flg = 1;
    } else {
      printf("%s\n", buf);
    }
  }
  close(acc);
  close(soc);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x154(%rbp)
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1233 <main+0x63>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1493 <main+0x2c3>
mov    -0x8(%rbp),%esi
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0xbb8,%edi
call   1060 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d75(%rip),%rax
mov    (%rax),%esi
mov    0x2d44(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    12b8 <main+0xe8>
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1493 <main+0x2c3>
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1302 <main+0x132>
lea    0xd76(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1493 <main+0x2c3>
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1348 <main+0x178>
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1493 <main+0x2c3>
lea    0xd39(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xc,-0x34(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    139c <main+0x1cc>
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1493 <main+0x2c3>
mov    -0x2c(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%edi
call   10c0 <ntohs@plt>
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%edx
lea    0xce7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x150(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
cmpl   $0x0,-0x154(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    13f4 <main+0x224>
jmp    147c <main+0x2ac>
mov    -0x20(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x158(%rbp)
mov    -0x158(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x150(%rbp,%rax,1)
mov    -0x158(%rbp),%eax
sub    $0x2,%eax
cltq
movb   $0x0,-0x150(%rbp,%rax,1)
lea    -0x150(%rbp),%rdi
lea    0xc89(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1462 <main+0x292>
movl   $0x1,-0x154(%rbp)
jmp    1477 <main+0x2a7>
lea    -0x150(%rbp),%rsi
lea    0xc61(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    13db <main+0x20b>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x138,%rsp
movl   $0x1,0xc(%rsp)
mov    0x2de4(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
je     1374 <main+0x194>
mov    %eax,%r14d
lea    0xddf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    $0xbb8,%edi
call   1070 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
mov    0x2d65(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1382 <main+0x1a2>
lea    0xdb3(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0xffffffff,%eax
je     138b <main+0x1ab>
lea    0xdae(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
cmp    $0xffffffff,%eax
je     13a7 <main+0x1c7>
lea    0xd9a(%rip),%rdi
call   1040 <puts@plt>
movl   $0xc,0x8(%rsp)
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
call   10f0 <accept@plt>
cmp    $0xffffffff,%eax
je     13b0 <main+0x1d0>
mov    %eax,%ebp
mov    0x24(%rsp),%edi
call   1060 <inet_ntoa@plt>
mov    %rax,%rbx
mov    0x20(%rsp),%edi
call   10d0 <ntohs@plt>
lea    0xcfb(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1090 <memset@plt>
lea    0xcf9(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movw   $0x0,-0x2(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     1394 <main+0x1b4>
mov    %rbx,%rdi
call   1040 <puts@plt>
jmp    1340 <main+0x160>
lea    0xd40(%rip),%rdi
call   1040 <puts@plt>
jmp    13c4 <main+0x1e4>
lea    0xd12(%rip),%rdi
jmp    13b7 <main+0x1d7>
lea    0xcfd(%rip),%rdi
jmp    13b7 <main+0x1d7>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
xor    %eax,%eax
jmp    13c9 <main+0x1e9>
lea    0xcd3(%rip),%rdi
jmp    13b7 <main+0x1d7>
lea    0xcbc(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
mov    $0xffffffff,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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 = [15 x i8] c"socket error!\0A\00"
@.str.1 = [10 x i8] c"soc = %d\0A\00"
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [33 x i8] c"setsockopt(SO_REUSEADDR) error!\0A\00"
@.str.3 = [35 x i8] c"setsockopt(SO_REUSEADDR) success.\0A\00"
@.str.4 = [13 x i8] c"bind error!\0A\00"
@.str.5 = [15 x i8] c"bind success.\0A\00"
@.str.6 = [15 x i8] c"listen error!\0A\00"
@.str.7 = [17 x i8] c"listen success.\0A\00"
@.str.8 = [15 x i8] c"accept error!\0A\00"
@.str.9 = [37 x i8] c"accept!(IPAddress = %s, Port = %hu)\0A\00"
@.str.10 = [4 x i8] c"end\00"
@.str.11 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [256 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %4
store i32 0, i32* %11
%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* %2
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %112
20: ; preds = %0
%21 = load i32, i32* %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %23, i32* %24
%25 = call i32 @htons(i32 3000)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* @INADDR_ANY
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i32, i32* %2
%31 = load i32, i32* @SOL_SOCKET
%32 = load i32, i32* @SO_REUSEADDR
%33 = bitcast i32* %4 to i8*
%34 = call i32 @setsockopt(i32 %30, i32 %31, i32 %32, i8* %33, i32 4)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %40
36: ; preds = %20
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* %2
%39 = call i32 @close(i32 %38)
store i32 -1, i32* %1
br label %112
40: ; preds = %20
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%42 = load i32, i32* %2
%43 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%44 = call i32 @bind(i32 %42, %struct.sockaddr* %43, i32 12)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %50
46: ; preds = %40
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%48 = load i32, i32* %2
%49 = call i32 @close(i32 %48)
store i32 -1, i32* %1
br label %112
50: ; preds = %40
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%52 = load i32, i32* %2
%53 = call i32 @listen(i32 %52, i32 5)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %59
55: ; preds = %50
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%57 = load i32, i32* %2
%58 = call i32 @close(i32 %57)
store i32 -1, i32* %1
br label %112
59: ; preds = %50
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
store i32 12, i32* %7
%61 = load i32, i32* %2
%62 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%63 = call i32 @accept(i32 %61, %struct.sockaddr* %62, i32* %7)
store i32 %63, i32* %5
%64 = load i32, i32* %5
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %70
66: ; preds = %59
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%68 = load i32, i32* %2
%69 = call i32 @close(i32 %68)
store i32 -1, i32* %1
br label %112
70: ; preds = %59
%71 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%72 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %71, i32 0, i32 0
%73 = load i32, i32* %72
%74 = call i8* @inet_ntoa(i32 %73)
store i8* %74, i8** %8
%75 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%76 = load i32, i32* %75
%77 = call i32 @ntohs(i32 %76)
store i32 %77, i32* %9
%78 = load i8*, i8** %8
%79 = load i32, i32* %9
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i8* %78, i32 %79)
%81 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%82 = call i32 @memset(i8* %81, i32 0, i32 256)
br label %83
83: ; preds = %106, %70
%84 = load i32, i32* %11
%85 = icmp ne i32 %84, 0
%86 = xor i1 %85, true
br i1 %86, label %87, label %107
87: ; preds = %83
%88 = load i32, i32* %5
%89 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%90 = call i32 @recv(i32 %88, i8* %89, i32 256, i32 0)
store i32 %90, i32* %12
%91 = load i32, i32* %12
%92 = sub nsw i32 %91, 1
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %93
store i8 0, i8* %94
%95 = load i32, i32* %12
%96 = sub nsw i32 %95, 2
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %97
store i8 0, i8* %98
%99 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%100 = call i64 @strcmp(i8* %99, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%101 = icmp eq i64 %100, 0
br i1 %101, label %102, label %103
102: ; preds = %87
store i32 1, i32* %11
br label %106
103: ; preds = %87
%104 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %104)
br label %106
106: ; preds = %103, %102
br label %83
107: ; preds = %83
%108 = load i32, i32* %5
%109 = call i32 @close(i32 %108)
%110 = load i32, i32* %2
%111 = call i32 @close(i32 %110)
store i32 0, i32* %1
br label %112
112: ; preds = %107, %66, %55, %46, %36, %18
%113 = load i32, i32* %1
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
@.str.1 = [10 x i8] c"soc = %d\0A\00"
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.9 = [37 x i8] c"accept!(IPAddress = %s, Port = %hu)\0A\00"
@.str.10 = [4 x i8] c"end\00"
@str = [34 x i8] c"setsockopt(SO_REUSEADDR) success.\00"
@str.12 = [14 x i8] c"bind success.\00"
@str.13 = [16 x i8] c"listen success.\00"
@str.14 = [14 x i8] c"accept error!\00"
@str.15 = [14 x i8] c"listen error!\00"
@str.16 = [12 x i8] c"bind error!\00"
@str.17 = [32 x i8] c"setsockopt(SO_REUSEADDR) error!\00"
@str.18 = [14 x i8] c"socket error!\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = bitcast %struct.sockaddr_in* %1 to i8*
%7 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.18, i64 0, i64 0))
br label %79
17: ; preds = %0
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %19, i32* %20
%21 = tail call i32 @htons(i32 3000)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_REUSEADDR
%27 = call i32 @setsockopt(i32 %13, i32 %25, i32 %26, i8* %7, i32 4)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %17
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.17, i64 0, i64 0))
%31 = call i32 @close(i32 %13)
br label %79
32: ; preds = %17
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%34 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%35 = call i32 @bind(i32 %13, %struct.sockaddr* %34, i32 12)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.16, i64 0, i64 0))
%39 = call i32 @close(i32 %13)
br label %79
40: ; preds = %32
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.12, i64 0, i64 0))
%42 = call i32 @listen(i32 %13, i32 5)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.15, i64 0, i64 0))
%46 = call i32 @close(i32 %13)
br label %79
47: ; preds = %40
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.13, i64 0, i64 0))
store i32 12, i32* %4
%49 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%50 = call i32 @accept(i32 %13, %struct.sockaddr* %49, i32* %4)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.14, i64 0, i64 0))
%54 = call i32 @close(i32 %13)
br label %79
55: ; preds = %47
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%57 = load i32, i32* %56
%58 = call i8* @inet_ntoa(i32 %57)
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%60 = load i32, i32* %59
%61 = call i32 @ntohs(i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i8* %58, i32 %61)
%63 = call i32 @memset(i8* %10, i32 0, i32 256)
br label %64
64: ; preds = %74, %55
%65 = call i32 @recv(i32 %50, i8* %10, i32 256, i32 0)
%66 = add nsw i32 %65, -1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %67
store i8 0, i8* %68
%69 = add nsw i32 %65, -2
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %70
store i8 0, i8* %71
%72 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%73 = icmp eq i64 %72, 0
br i1 %73, label %76, label %74
74: ; preds = %64
%75 = call i32 @puts(i8* %10)
br label %64
76: ; preds = %64
%77 = call i32 @close(i32 %50)
%78 = call i32 @close(i32 %13)
br label %79
79: ; preds = %76, %52, %44, %37, %29, %15
%80 = phi i32 [ -1, %15 ], [ -1, %29 ], [ -1, %37 ], [ -1, %44 ], [ -1, %52 ], [ 0, %76 ]
ret i32 %80
}