#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 /*<<< orphan*/ 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;
  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);
    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(acc, buf, strlen(buf), 0);
    }
  }
  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    1512 <main+0x322>
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    1512 <main+0x322>
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    1512 <main+0x322>
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    1512 <main+0x322>
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    1512 <main+0x322>
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    14fb <main+0x30b>
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)
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    0xc69(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1482 <main+0x292>
movl   $0x1,-0x154(%rbp)
jmp    14f6 <main+0x306>
lea    -0x150(%rbp),%rsi
lea    0xc41(%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,-0x164(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x160(%rbp)
lea    -0x150(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x164(%rbp),%edi
mov    -0x160(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
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   %r12
push   %rbx
sub    $0x130,%rsp
movl   $0x1,0xc(%rsp)
mov    0x2dc2(%rip),%rbx
mov    (%rbx),%edi
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
je     13b6 <main+0x1b6>
mov    %eax,%r14d
lea    0xdbd(%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    0x2d71(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
mov    0x2d43(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     13c4 <main+0x1c4>
lea    0xd91(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1100 <bind@plt>
cmp    $0xffffffff,%eax
je     13cd <main+0x1cd>
lea    0xd8c(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
mov    $0x5,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
je     13ea <main+0x1ea>
lea    0xd78(%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     13f3 <main+0x1f3>
mov    %eax,%r12d
mov    0x24(%rsp),%edi
call   1060 <inet_ntoa@plt>
mov    %rax,%rbx
mov    0x20(%rsp),%edi
call   10f0 <ntohs@plt>
lea    0xcd8(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x30(%rsp),%rbx
lea    0xce5(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   10b0 <memset@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
movslq %eax,%rbp
movw   $0x0,-0x2(%rbp,%rbx,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
je     13d6 <main+0x1d6>
mov    %rbx,%rdi
call   1040 <puts@plt>
movb   $0xa,0x2f(%rsp,%rbp,1)
movb   $0xd,0x2e(%rsp,%rbp,1)
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
jmp    1350 <main+0x150>
lea    0xcfe(%rip),%rdi
call   1040 <puts@plt>
jmp    1407 <main+0x207>
lea    0xcd0(%rip),%rdi
jmp    13fa <main+0x1fa>
lea    0xcbb(%rip),%rdi
jmp    13fa <main+0x1fa>
mov    %r12d,%edi
call   10c0 <close@plt>
mov    %r14d,%edi
call   10c0 <close@plt>
xor    %eax,%eax
jmp    140c <main+0x20c>
lea    0xc90(%rip),%rdi
jmp    13fa <main+0x1fa>
lea    0xc79(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
call   10c0 <close@plt>
mov    $0xffffffff,%eax
add    $0x130,%rsp
pop    %rbx
pop    %r12
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 %125
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 %125
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 %125
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 %125
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 %125
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)
br label %81
81: ; preds = %119, %70
%82 = load i32, i32* %11
%83 = icmp ne i32 %82, 0
%84 = xor i1 %83, true
br i1 %84, label %85, label %120
85: ; preds = %81
%86 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%87 = call i32 @memset(i8* %86, i32 0, i32 256)
%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 = %85
store i32 1, i32* %11
br label %119
103: ; preds = %85
%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)
%106 = load i32, i32* %12
%107 = sub nsw i32 %106, 1
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %108
store i8 10, i8* %109
%110 = load i32, i32* %12
%111 = sub nsw i32 %110, 2
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %112
store i8 13, i8* %113
%114 = load i32, i32* %5
%115 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%116 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%117 = call i32 @strlen(i8* %116)
%118 = call i32 @send(i32 %114, i8* %115, i32 %117, i32 0)
br label %119
119: ; preds = %103, %102
br label %81
120: ; preds = %81
%121 = load i32, i32* %5
%122 = call i32 @close(i32 %121)
%123 = load i32, i32* %2
%124 = call i32 @close(i32 %123)
store i32 0, i32* %1
br label %125
125: ; preds = %120, %66, %55, %46, %36, %18
%126 = load i32, i32* %1
ret i32 %126
}

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 %81
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 %81
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 %81
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 %81
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 %81
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 = %74, %55
%64 = call i32 @memset(i8* %10, i32 0, i32 256)
%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 %78, label %74
74: ; preds = %63
%75 = call i32 @puts(i8* %10)
store i8 10, i8* %68
store i8 13, i8* %71
%76 = call i32 @strlen(i8* %10)
%77 = call i32 @send(i32 %50, i8* %10, i32 %76, i32 0)
br label %63
78: ; preds = %63
%79 = call i32 @close(i32 %50)
%80 = call i32 @close(i32 %13)
br label %81
81: ; preds = %78, %52, %44, %37, %29, %15
%82 = phi i32 [ -1, %15 ], [ -1, %29 ], [ -1, %37 ], [ -1, %44 ], [ -1, %52 ], [ 0, %78 ]
ret i32 %82
}