#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 send(int, char *, int /*<<< orphan*/, 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 /*<<< orphan*/ strlen(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;
  int send_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);
  while (!exit_flg) {
    memset(buf, 0, sizeof(char) * 256);
    recv_len = recv(acc, buf, sizeof(char) * 256, 0);
    if (recv_len <= 0) {
      break;
    }
    buf[recv_len - 1] = '\0';
    buf[recv_len - 2] = '\0';
    if (strcmp(buf, "end") == 0) {
      exit_flg = 1;
    } else {
      printf("%s\n", buf);
      buf[recv_len - 1] = '\n';
      buf[recv_len - 2] = '\r';
      send_len = send(acc, buf, strlen(buf), 0);
      if (send_len <= 0) {
        break;
      }
    }
  }
  close(acc);
  close(soc);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x154(%rbp)
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1253 <main+0x63>
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1541 <main+0x351>
mov    -0x8(%rbp),%esi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0xbb8,%edi
call   1070 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d55(%rip),%rax
mov    (%rax),%esi
mov    0x2d24(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    12d8 <main+0xe8>
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x8(%rbp),%edi
call   10b0 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1541 <main+0x351>
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1322 <main+0x132>
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x8(%rbp),%edi
call   10b0 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1541 <main+0x351>
lea    0xd41(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1368 <main+0x178>
lea    0xd2c(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x8(%rbp),%edi
call   10b0 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1541 <main+0x351>
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0xc,-0x34(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    13bc <main+0x1cc>
lea    0xcf8(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x8(%rbp),%edi
call   10b0 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1541 <main+0x351>
mov    -0x2c(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%edi
call   10e0 <ntohs@plt>
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%edx
lea    0xcc7(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
cmpl   $0x0,-0x154(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1401 <main+0x211>
jmp    152a <main+0x33a>
lea    -0x150(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   10a0 <memset@plt>
mov    -0x20(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x158(%rbp)
cmpl   $0x0,-0x158(%rbp)
jg     1442 <main+0x252>
jmp    152a <main+0x33a>
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    0xc57(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1494 <main+0x2a4>
movl   $0x1,-0x154(%rbp)
jmp    1525 <main+0x335>
lea    -0x150(%rbp),%rsi
lea    0xc2f(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x158(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0xa,-0x150(%rbp,%rax,1)
0a
mov    -0x158(%rbp),%eax
sub    $0x2,%eax
cltq
movb   $0xd,-0x150(%rbp,%rax,1)
0d
mov    -0x20(%rbp),%eax
mov    %eax,-0x16c(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x168(%rbp)
lea    -0x150(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x16c(%rbp),%edi
mov    -0x168(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    %eax,-0x15c(%rbp)
cmpl   $0x0,-0x15c(%rbp)
jg     1520 <main+0x330>
jmp    152a <main+0x33a>
jmp    1525 <main+0x335>
jmp    13e8 <main+0x1f8>
mov    -0x20(%rbp),%edi
call   10b0 <close@plt>
mov    -0x8(%rbp),%edi
call   10b0 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
movl   $0x1,0xc(%rsp)
mov    0x2dc0(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
je     13d7 <main+0x1d7>
mov    %eax,%r14d
lea    0xdbb(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    $0xbb8,%edi
call   1080 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
mov    0x2d41(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     13e5 <main+0x1e5>
lea    0xd8f(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1100 <bind@plt>
cmp    $0xffffffff,%eax
je     13ee <main+0x1ee>
lea    0xd8a(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
mov    $0x5,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
je     13f7 <main+0x1f7>
lea    0xd76(%rip),%rdi
call   1040 <puts@plt>
movl   $0xc,0x8(%rsp)
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
call   1110 <accept@plt>
cmp    $0xffffffff,%eax
je     1400 <main+0x200>
mov    %eax,%r12d
mov    0x24(%rsp),%edi
call   1060 <inet_ntoa@plt>
mov    %rax,%rbx
mov    0x20(%rsp),%edi
call   10f0 <ntohs@plt>
lea    0xcd6(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x30(%rsp),%r13
lea    0xce3(%rip),%r15
nopl   0x0(%rax)
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   10b0 <memset@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    13c3 <main+0x1c3>
lea    -0x1(%rax),%ebp
movb   $0x0,0x30(%rsp,%rbp,1)
movslq %eax,%rbx
movb   $0x0,-0x2(%rbx,%r13,1)
mov    %r13,%rdi
mov    %r15,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
je     13c3 <main+0x1c3>
mov    %r13,%rdi
call   1040 <puts@plt>
movb   $0xa,0x30(%rsp,%rbp,1)
movb   $0xd,0x2e(%rsp,%rbx,1)
mov    %r13,%rdi
call   1070 <strlen@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
test   %eax,%eax
jg     1350 <main+0x150>
mov    %r12d,%edi
call   10c0 <close@plt>
mov    %r14d,%edi
call   10c0 <close@plt>
xor    %eax,%eax
jmp    1419 <main+0x219>
lea    0xcdd(%rip),%rdi
call   1040 <puts@plt>
jmp    1414 <main+0x214>
lea    0xcaf(%rip),%rdi
jmp    1407 <main+0x207>
lea    0xc9a(%rip),%rdi
jmp    1407 <main+0x207>
lea    0xc83(%rip),%rdi
jmp    1407 <main+0x207>
lea    0xc6c(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
call   10c0 <close@plt>
mov    $0xffffffff,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
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
%13 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %4
store i32 0, i32* %11
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %0
%20 = 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 %134
21: ; preds = %0
%22 = load i32, i32* %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %24, i32* %25
%26 = call i32 @htons(i32 3000)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* @INADDR_ANY
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i32 %28, i32* %30
%31 = load i32, i32* %2
%32 = load i32, i32* @SOL_SOCKET
%33 = load i32, i32* @SO_REUSEADDR
%34 = bitcast i32* %4 to i8*
%35 = call i32 @setsockopt(i32 %31, i32 %32, i32 %33, i8* %34, i32 4)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %41
37: ; preds = %21
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* %2
%40 = call i32 @close(i32 %39)
store i32 -1, i32* %1
br label %134
41: ; preds = %21
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* %2
%44 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%45 = call i32 @bind(i32 %43, %struct.sockaddr* %44, i32 12)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %51
47: ; preds = %41
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%49 = load i32, i32* %2
%50 = call i32 @close(i32 %49)
store i32 -1, i32* %1
br label %134
51: ; preds = %41
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%53 = load i32, i32* %2
%54 = call i32 @listen(i32 %53, i32 5)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %60
56: ; preds = %51
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%58 = load i32, i32* %2
%59 = call i32 @close(i32 %58)
store i32 -1, i32* %1
br label %134
60: ; preds = %51
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
store i32 12, i32* %7
%62 = load i32, i32* %2
%63 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%64 = call i32 @accept(i32 %62, %struct.sockaddr* %63, i32* %7)
store i32 %64, i32* %5
%65 = load i32, i32* %5
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %71
67: ; preds = %60
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%69 = load i32, i32* %2
%70 = call i32 @close(i32 %69)
store i32 -1, i32* %1
br label %134
71: ; preds = %60
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%73 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %72, i32 0, i32 0
%74 = load i32, i32* %73
%75 = call i8* @inet_ntoa(i32 %74)
store i8* %75, i8** %8
%76 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%77 = load i32, i32* %76
%78 = call i32 @ntohs(i32 %77)
store i32 %78, i32* %9
%79 = load i8*, i8** %8
%80 = load i32, i32* %9
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i8* %79, i32 %80)
br label %82
82: ; preds = %128, %71
%83 = load i32, i32* %11
%84 = icmp ne i32 %83, 0
%85 = xor i1 %84, true
br i1 %85, label %86, label %129
86: ; preds = %82
%87 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%88 = call i32 @memset(i8* %87, i32 0, i32 256)
%89 = load i32, i32* %5
%90 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%91 = call i32 @recv(i32 %89, i8* %90, i32 256, i32 0)
store i32 %91, i32* %12
%92 = load i32, i32* %12
%93 = icmp sle i32 %92, 0
br i1 %93, label %94, label %95
94: ; preds = %86
br label %129
95: ; preds = %86
%96 = load i32, i32* %12
%97 = sub nsw i32 %96, 1
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %98
store i8 0, i8* %99
%100 = load i32, i32* %12
%101 = sub nsw i32 %100, 2
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %102
store i8 0, i8* %103
%104 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%105 = call i64 @strcmp(i8* %104, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%106 = icmp eq i64 %105, 0
br i1 %106, label %107, label %108
107: ; preds = %95
store i32 1, i32* %11
br label %128
108: ; preds = %95
%109 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %109)
%111 = load i32, i32* %12
%112 = sub nsw i32 %111, 1
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %113
store i8 10, i8* %114
%115 = load i32, i32* %12
%116 = sub nsw i32 %115, 2
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %117
store i8 13, i8* %118
%119 = load i32, i32* %5
%120 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%121 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%122 = call i32 @strlen(i8* %121)
%123 = call i32 @send(i32 %119, i8* %120, i32 %122, i32 0)
store i32 %123, i32* %13
%124 = load i32, i32* %13
%125 = icmp sle i32 %124, 0
br i1 %125, label %126, label %127
126: ; preds = %108
br label %129
127: ; preds = %108
br label %128
128: ; preds = %127, %107
br label %82
129: ; preds = %126, %94, %82
%130 = load i32, i32* %5
%131 = call i32 @close(i32 %130)
%132 = load i32, i32* %2
%133 = call i32 @close(i32 %132)
store i32 0, i32* %1
br label %134
134: ; preds = %129, %67, %56, %47, %37, %19
%135 = load i32, i32* %1
ret i32 %135
}

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 %84
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 %84
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 %84
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 %84
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 %84
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)
br label %63
63: ; preds = %76, %55
%64 = call i32 @memset(i8* %10, i32 0, i32 256)
%65 = call i32 @recv(i32 %50, i8* %10, i32 256, i32 0)
%66 = icmp slt i32 %65, 1
br i1 %66, label %81, label %67
67: ; preds = %63
%68 = add nsw i32 %65, -1
%69 = zext i32 %68 to i64
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %69
store i8 0, i8* %70
%71 = add nsw i32 %65, -2
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %72
store i8 0, i8* %73
%74 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%75 = icmp eq i64 %74, 0
br i1 %75, label %81, label %76
76: ; preds = %67
%77 = call i32 @puts(i8* %10)
store i8 10, i8* %70
store i8 13, i8* %73
%78 = call i32 @strlen(i8* %10)
%79 = call i32 @send(i32 %50, i8* %10, i32 %78, i32 0)
%80 = icmp slt i32 %79, 1
br i1 %80, label %81, label %63
81: ; preds = %67, %76, %63
%82 = call i32 @close(i32 %50)
%83 = call i32 @close(i32 %13)
br label %84
84: ; preds = %81, %52, %44, %37, %29, %15
%85 = phi i32 [ -1, %15 ], [ -1, %29 ], [ -1, %37 ], [ -1, %44 ], [ -1, %52 ], [ 0, %81 ]
ret i32 %85
}