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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EINTR;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, unsigned int *);
scalar_t__ bind(int, struct sockaddr const *, int);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
long recv(int, char *, int, int /*<<< orphan*/);
long send(int, char *, unsigned long, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int main() {
  int flag = 0;
  int listenSocket;
  int fromClientsock;
  unsigned long sendlen;
  long retlen;
  char *pbuf;
  char sendbuf[100];
  char recvbuf[100];
  struct sockaddr_in *serverAddr =
      (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in));
  struct sockaddr_in *clientAddr =
      (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in));
  unsigned int clientSocketLength = sizeof(*clientAddr);
  serverAddr->sin_family = AF_INET;
  serverAddr->sin_port = htons(3500);
  serverAddr->sin_addr.s_addr = htonl(INADDR_ANY);
  listenSocket = socket(AF_INET, SOCK_STREAM, 0);
  if (listenSocket < 0) {
    printf("CREATE SOCKET ERROR\n");
    return 0;
  }
  if (bind(listenSocket, (const struct sockaddr *)serverAddr,
           sizeof(*serverAddr)) < 0) {
    printf("BIND SOCKET ERROR\n");
    return 0;
    ;
  }
  if (listen(listenSocket, 5) < 0) {
    printf("LISTEN ERROR\n");
    return 0;
    ;
  }
  fromClientsock =
      accept(listenSocket, (struct sockaddr *)clientAddr, &clientSocketLength);
  if (fromClientsock < 0) {
    printf("ACCEPTATION ERROR\n");
    exit(1);
  }
  printf("THIS IS SERVER：D\n");
  while (1) {
    if (!flag) {
      pbuf = recvbuf;
      retlen = recv(fromClientsock, pbuf, 100, 0);
      if (*pbuf == 'q' || *pbuf == 'Q') {
        char clientDisconnect[] = "!@clientDisconnect";
        pbuf = clientDisconnect;
        send(fromClientsock, pbuf, strlen(clientDisconnect) + 1, 0);
        close(fromClientsock);
        close(listenSocket);
        break;
      }
      if (retlen < 0) {
        if (errno == EINTR)
          retlen = 0;
        else {
          close(listenSocket);
          printf("\nRECEIVE DATA ERROR!");
          return 0;
        }
      }
      printf("\nMESSAGE FROM CILENT: %s", recvbuf);
      flag = 1;
    } else {
      printf("\nSERVER('q OR Q' TO QUIT): ");
      fgets(sendbuf, 100, stdin);
      sendlen = strlen(sendbuf) + 1;
      pbuf = sendbuf;
      retlen = send(fromClientsock, pbuf, sendlen, 0);
      if (retlen < 0) {
        if (errno == EINTR)
          retlen = 0;
        else {
          close(listenSocket);
          return 0;
        }
      }
      if (*pbuf == 'q' || *pbuf == 'Q') {
        printf("\n...\n");
        pbuf = recvbuf;
        recv(fromClientsock, pbuf, 100, 0);
        if (!strcmp(recvbuf, "!@serverDisconnect")) {
          close(fromClientsock);
          close(listenSocket);
          break;
        } else
          printf("\nOH! QUIT ERROR!");
      }
      flag = 0;
    }
  }
  printf("\nProgram by Ming Zhang, obey MIT LICENSE:D\nBye~\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0xc,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x108(%rbp)
mov    $0xc,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x110(%rbp)
movl   $0xc,-0x114(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%ecx
mov    -0x108(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    $0xdac,%edi
call   1050 <htons@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    12b7 <main+0xc7>
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1619 <main+0x429>
mov    -0xc(%rbp),%edi
mov    -0x108(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0x0,%rax
jge    12ef <main+0xff>
lea    0xd39(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1619 <main+0x429>
mov    -0xc(%rbp),%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
cmp    $0x0,%rax
jge    1320 <main+0x130>
lea    0xd1b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1619 <main+0x429>
mov    -0xc(%rbp),%edi
mov    -0x110(%rbp),%rsi
lea    -0x114(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    135b <main+0x16b>
lea    0xcec(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xce7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    14bf <main+0x2cf>
lea    -0x100(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x71,%eax
je     13b5 <main+0x1c5>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x51,%eax
jne    1445 <main+0x255>
mov    0xd54(%rip),%rax
mov    %rax,-0x130(%rbp)
mov    0xd4e(%rip),%rax
mov    %rax,-0x128(%rbp)
mov    0xd48(%rip),%ax
mov    %ax,-0x120(%rbp)
mov    0xd3d(%rip),%al
mov    %al,-0x11e(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x13c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x13c(%rbp),%edi
mov    -0x138(%rbp),%rsi
add    $0x1,%eax
movslq %eax,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x10(%rbp),%edi
call   1090 <close@plt>
mov    -0xc(%rbp),%edi
call   1090 <close@plt>
jmp    1604 <main+0x414>
cmpq   $0x0,-0x20(%rbp)
jge    149e <main+0x2ae>
mov    0x2b69(%rip),%rax
mov    (%rax),%rax
mov    0x2b57(%rip),%rcx
cmp    (%rcx),%rax
jne    1477 <main+0x287>
movq   $0x0,-0x20(%rbp)
jmp    1499 <main+0x2a9>
mov    -0xc(%rbp),%edi
call   1090 <close@plt>
lea    0xbd7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1619 <main+0x429>
jmp    149e <main+0x2ae>
lea    -0x100(%rbp),%rsi
lea    0xbc6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x8(%rbp)
jmp    15ff <main+0x40f>
lea    0xbc5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    0x2b05(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   10a0 <fgets@plt>
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1568 <main+0x378>
mov    0x2a91(%rip),%rax
mov    (%rax),%rax
mov    0x2a7f(%rip),%rcx
cmp    (%rcx),%rax
jne    154f <main+0x35f>
movq   $0x0,-0x20(%rbp)
jmp    1563 <main+0x373>
mov    -0xc(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1619 <main+0x429>
jmp    1568 <main+0x378>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x71,%eax
je     1588 <main+0x398>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x51,%eax
jne    15f8 <main+0x408>
lea    0xb18(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x100(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x100(%rbp),%rdi
lea    0xaeb(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%eax
jne    15e5 <main+0x3f5>
mov    -0x10(%rbp),%edi
call   1090 <close@plt>
mov    -0xc(%rbp),%edi
call   1090 <close@plt>
jmp    1604 <main+0x414>
lea    0xad4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    15f8 <main+0x408>
movl   $0x0,-0x8(%rbp)
jmp    1369 <main+0x179>
lea    0xac6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    $0xc,%edi
call   10c0 <malloc@plt>
mov    %rax,%rbp
mov    $0xc,%edi
call   10c0 <malloc@plt>
mov    %rax,%r15
movl   $0xc,0xc(%rsp)
mov    0x2dbe(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rbp)
mov    $0xdac,%edi
call   1060 <htons@plt>
mov    %eax,0x4(%rbp)
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x0(%rbp)
mov    (%rbx),%edi
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
test   %eax,%eax
js     13f2 <main+0x202>
mov    %eax,%r14d
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
test   %rax,%rax
js     13fb <main+0x20b>
mov    %r14d,%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
test   %rax,%rax
js     1404 <main+0x214>
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
mov    %r15,%rsi
call   10f0 <accept@plt>
test   %eax,%eax
js     1493 <main+0x2a3>
mov    %eax,%ebp
lea    0xde8(%rip),%rdi
call   1040 <puts@plt>
lea    0x30(%rsp),%r13
lea    0xd97(%rip),%r12
mov    0x2d0f(%rip),%r15
lea    0xa0(%rsp),%rbx
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
movzbl 0x30(%rsp),%ecx
or     $0x20,%cl
cmp    $0x71,%cl
je     140d <main+0x21d>
test   %rax,%rax
jns    1321 <main+0x131>
mov    0x2cb2(%rip),%rax
mov    (%rax),%rax
mov    0x2ca0(%rip),%rcx
cmp    (%rcx),%rax
jne    1471 <main+0x281>
lea    0xd20(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   10b0 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1070 <send@plt>
test   %rax,%rax
jns    1385 <main+0x195>
mov    0x2c4e(%rip),%rax
mov    (%rax),%rax
mov    0x2c3c(%rip),%rcx
cmp    (%rcx),%rax
jne    1489 <main+0x299>
movzbl 0xa0(%rsp),%eax
or     $0x20,%al
cmp    $0x71,%al
jne    12e0 <main+0xf0>
lea    0xd47(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
movdqu 0x33(%rsp),%xmm0
pcmpeqb 0xc3e(%rip),%xmm0
movdqa 0x30(%rsp),%xmm1
pcmpeqb 0xc40(%rip),%xmm1
pand   %xmm0,%xmm1
pmovmskb %xmm1,%eax
cmp    $0xffff,%eax
je     1442 <main+0x252>
lea    0xcaa(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    12e0 <main+0xf0>
lea    0xd22(%rip),%rdi
jmp    1458 <main+0x268>
lea    0xd07(%rip),%rdi
jmp    1458 <main+0x268>
lea    0xcf1(%rip),%rdi
jmp    1458 <main+0x268>
movdqa 0xc0b(%rip),%xmm0
movdqa %xmm0,0x10(%rsp)
movl   $0x746365,0x1f(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
lea    0xc5c(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14d,%edi
call   10a0 <close@plt>
lea    0xbb3(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    145d <main+0x26d>
mov    %r14d,%edi
call   10a0 <close@plt>
jmp    145d <main+0x26d>
lea    0xc50(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@.str = [21 x i8] c"CREATE SOCKET ERROR\0A\00"
@.str.1 = [19 x i8] c"BIND SOCKET ERROR\0A\00"
@.str.2 = [14 x i8] c"LISTEN ERROR\0A\00"
@.str.3 = [19 x i8] c"ACCEPTATION ERROR\0A\00"
@.str.4 = [20 x i8] c"THIS IS SERVER\EF\BC\9AD\0A\00"
@__const.main.clientDisconnect = [19 x i8] c"!@clientDisconnect\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.5 = [21 x i8] c"\0ARECEIVE DATA ERROR!\00"
@.str.6 = [25 x i8] c"\0AMESSAGE FROM CILENT: %s\00"
@.str.7 = [28 x i8] c"\0ASERVER('q OR Q' TO QUIT): \00"
@stdin = global i32 0
@.str.8 = [6 x i8] c"\0A...\0A\00"
@.str.9 = [19 x i8] c"!@serverDisconnect\00"
@.str.10 = [17 x i8] c"\0AOH! QUIT ERROR!\00"
@.str.11 = [50 x i8] c"\0AProgram by Ming Zhang, obey MIT LICENSE:D\0ABye~\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca [100 x i8]
%9 = alloca [100 x i8]
%10 = alloca %struct.sockaddr_in*
%11 = alloca %struct.sockaddr_in*
%12 = alloca i32
%13 = alloca [19 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
%14 = call i64 @malloc(i32 12)
%15 = inttoptr i64 %14 to %struct.sockaddr_in*
store %struct.sockaddr_in* %15, %struct.sockaddr_in** %10
%16 = call i64 @malloc(i32 12)
%17 = inttoptr i64 %16 to %struct.sockaddr_in*
store %struct.sockaddr_in* %17, %struct.sockaddr_in** %11
store i32 12, i32* %12
%18 = load i32, i32* @AF_INET
%19 = load %struct.sockaddr_in*, %struct.sockaddr_in** %10
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 2
store i32 %18, i32* %20
%21 = call i32 @htons(i32 3500)
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %10
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 1
store i32 %21, i32* %23
%24 = load i32, i32* @INADDR_ANY
%25 = call i32 @htonl(i32 %24)
%26 = load %struct.sockaddr_in*, %struct.sockaddr_in** %10
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %26, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
store i32 %25, i32* %28
%29 = load i32, i32* @AF_INET
%30 = load i32, i32* @SOCK_STREAM
%31 = call i32 @socket(i32 %29, i32 %30, i32 0)
store i32 %31, i32* %3
%32 = load i32, i32* %3
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %165
36: ; preds = %0
%37 = load i32, i32* %3
%38 = load %struct.sockaddr_in*, %struct.sockaddr_in** %10
%39 = bitcast %struct.sockaddr_in* %38 to %struct.sockaddr*
%40 = call i64 @bind(i32 %37, %struct.sockaddr* %39, i32 12)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %165
44: ; preds = %36
%45 = load i32, i32* %3
%46 = call i64 @listen(i32 %45, i32 5)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %165
50: ; preds = %44
%51 = load i32, i32* %3
%52 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
%53 = bitcast %struct.sockaddr_in* %52 to %struct.sockaddr*
%54 = call i32 @accept(i32 %51, %struct.sockaddr* %53, i32* %12)
store i32 %54, i32* %4
%55 = load i32, i32* %4
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %50
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %50
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %62
62: ; preds = %60, %162
%63 = load i32, i32* %2
%64 = icmp ne i32 %63, 0
br i1 %64, label %109, label %65
65: ; preds = %62
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
store i8* %66, i8** %7
%67 = load i32, i32* %4
%68 = load i8*, i8** %7
%69 = call i64 @recv(i32 %67, i8* %68, i32 100, i32 0)
store i64 %69, i64* %6
%70 = load i8*, i8** %7
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 113
br i1 %73, label %79, label %74
74: ; preds = %65
%75 = load i8*, i8** %7
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp eq i32 %77, 81
br i1 %78, label %79, label %93
79: ; preds = %74, %65
%80 = bitcast [19 x i8]* %13 to i8*
%81 = getelementptr inbounds [19 x i8], [19 x i8]* %13, i64 0, i64 0
store i8* %81, i8** %7
%82 = load i32, i32* %4
%83 = load i8*, i8** %7
%84 = getelementptr inbounds [19 x i8], [19 x i8]* %13, i64 0, i64 0
%85 = call i32 @strlen(i8* %84)
%86 = add nsw i32 %85, 1
%87 = sext i32 %86 to i64
%88 = call i64 @send(i32 %82, i8* %83, i64 %87, i32 0)
%89 = load i32, i32* %4
%90 = call i32 @close(i32 %89)
%91 = load i32, i32* %3
%92 = call i32 @close(i32 %91)
br label %163
93: ; preds = %74
%94 = load i64, i64* %6
%95 = icmp slt i64 %94, 0
br i1 %95, label %96, label %106
96: ; preds = %93
%97 = load i64, i64* @errno
%98 = load i64, i64* @EINTR
%99 = icmp eq i64 %97, %98
br i1 %99, label %100, label %101
100: ; preds = %96
store i64 0, i64* %6
br label %105
101: ; preds = %96
%102 = load i32, i32* %3
%103 = call i32 @close(i32 %102)
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %165
105: ; preds = %100
br label %106
106: ; preds = %105, %93
%107 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %107)
store i32 1, i32* %2
br label %162
109: ; preds = %62
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%111 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%112 = load i32, i32* @stdin
%113 = call i32 @fgets(i8* %111, i32 100, i32 %112)
%114 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%115 = call i32 @strlen(i8* %114)
%116 = add nsw i32 %115, 1
%117 = sext i32 %116 to i64
store i64 %117, i64* %5
%118 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
store i8* %118, i8** %7
%119 = load i32, i32* %4
%120 = load i8*, i8** %7
%121 = load i64, i64* %5
%122 = call i64 @send(i32 %119, i8* %120, i64 %121, i32 0)
store i64 %122, i64* %6
%123 = load i64, i64* %6
%124 = icmp slt i64 %123, 0
br i1 %124, label %125, label %134
125: ; preds = %109
%126 = load i64, i64* @errno
%127 = load i64, i64* @EINTR
%128 = icmp eq i64 %126, %127
br i1 %128, label %129, label %130
129: ; preds = %125
store i64 0, i64* %6
br label %133
130: ; preds = %125
%131 = load i32, i32* %3
%132 = call i32 @close(i32 %131)
store i32 0, i32* %1
br label %165
133: ; preds = %129
br label %134
134: ; preds = %133, %109
%135 = load i8*, i8** %7
%136 = load i8, i8* %135
%137 = sext i8 %136 to i32
%138 = icmp eq i32 %137, 113
br i1 %138, label %144, label %139
139: ; preds = %134
%140 = load i8*, i8** %7
%141 = load i8, i8* %140
%142 = sext i8 %141 to i32
%143 = icmp eq i32 %142, 81
br i1 %143, label %144, label %161
144: ; preds = %139, %134
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%146 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
store i8* %146, i8** %7
%147 = load i32, i32* %4
%148 = load i8*, i8** %7
%149 = call i64 @recv(i32 %147, i8* %148, i32 100, i32 0)
%150 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%151 = call i32 @strcmp(i8* %150, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
%152 = icmp ne i32 %151, 0
br i1 %152, label %158, label %153
153: ; preds = %144
%154 = load i32, i32* %4
%155 = call i32 @close(i32 %154)
%156 = load i32, i32* %3
%157 = call i32 @close(i32 %156)
br label %163
158: ; preds = %144
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
br label %160
160: ; preds = %158
br label %161
161: ; preds = %160, %139
store i32 0, i32* %2
br label %162
162: ; preds = %161, %106
br label %62
163: ; preds = %153, %79
%164 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.11, i64 0, i64 0))
store i32 0, i32* %1
br label %165
165: ; preds = %163, %130, %101, %48, %42, %34
%166 = load i32, i32* %1
ret i32 %166
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@__const.main.clientDisconnect = [19 x i8] c"!@clientDisconnect\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.5 = [21 x i8] c"\0ARECEIVE DATA ERROR!\00"
@.str.6 = [25 x i8] c"\0AMESSAGE FROM CILENT: %s\00"
@.str.7 = [28 x i8] c"\0ASERVER('q OR Q' TO QUIT): \00"
@stdin = global i32 0
@.str.9 = [19 x i8] c"!@serverDisconnect\00"
@.str.10 = [17 x i8] c"\0AOH! QUIT ERROR!\00"
@str = [19 x i8] c"THIS IS SERVER\EF\BC\9AD\00"
@str.12 = [49 x i8] c"\0AProgram by Ming Zhang, obey MIT LICENSE:D\0ABye~\0A\00"
@str.13 = [5 x i8] c"\0A...\00"
@str.14 = [18 x i8] c"ACCEPTATION ERROR\00"
@str.15 = [13 x i8] c"LISTEN ERROR\00"
@str.16 = [18 x i8] c"BIND SOCKET ERROR\00"
@str.17 = [20 x i8] c"CREATE SOCKET ERROR\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = alloca [19 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = tail call i64 @malloc(i32 12)
%8 = inttoptr i64 %7 to %struct.sockaddr_in*
%9 = tail call i64 @malloc(i32 12)
%10 = bitcast i32* %3 to i8*
store i32 12, i32* %3
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 2
store i32 %11, i32* %12
%13 = tail call i32 @htons(i32 3500)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 1
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = tail call i32 @htonl(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = tail call i32 @socket(i32 %18, i32 %19, i32 0)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.17, i64 0, i64 0))
br label %94
24: ; preds = %0
%25 = inttoptr i64 %7 to %struct.sockaddr*
%26 = tail call i64 @bind(i32 %20, %struct.sockaddr* %25, i32 12)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.16, i64 0, i64 0))
br label %94
30: ; preds = %24
%31 = tail call i64 @listen(i32 %20, i32 5)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.15, i64 0, i64 0))
br label %94
35: ; preds = %30
%36 = inttoptr i64 %9 to %struct.sockaddr*
%37 = call i32 @accept(i32 %20, %struct.sockaddr* %36, i32* %3)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.14, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %35
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %44
44: ; preds = %80, %90, %42
%45 = call i64 @recv(i32 %37, i8* %6, i32 100, i32 0)
%46 = load i8, i8* %6
switch i8 %46, label %55 [
i8 113, label %47
i8 81, label %47
]
47: ; preds = %44, %44
%48 = getelementptr inbounds [19 x i8], [19 x i8]* %4, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = add nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = call i64 @send(i32 %37, i8* %48, i64 %51, i32 0)
%53 = call i32 @close(i32 %37)
%54 = call i32 @close(i32 %20)
br label %92
55: ; preds = %44
%56 = icmp slt i64 %45, 0
br i1 %56, label %57, label %64
57: ; preds = %55
%58 = load i64, i64* @errno
%59 = load i64, i64* @EINTR
%60 = icmp eq i64 %58, %59
br i1 %60, label %64, label %61
61: ; preds = %57
%62 = call i32 @close(i32 %20)
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %94
64: ; preds = %57, %55
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%67 = load i32, i32* @stdin
%68 = call i32 @fgets(i8* %5, i32 100, i32 %67)
%69 = call i32 @strlen(i8* %5)
%70 = add nsw i32 %69, 1
%71 = sext i32 %70 to i64
%72 = call i64 @send(i32 %37, i8* %5, i64 %71, i32 0)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %80
74: ; preds = %64
%75 = load i64, i64* @errno
%76 = load i64, i64* @EINTR
%77 = icmp eq i64 %75, %76
br i1 %77, label %80, label %78
78: ; preds = %74
%79 = call i32 @close(i32 %20)
br label %94
80: ; preds = %74, %64
%81 = load i8, i8* %5
switch i8 %81, label %44 [
i8 113, label %82
i8 81, label %82
]
82: ; preds = %80, %80
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.13, i64 0, i64 0))
%84 = call i64 @recv(i32 %37, i8* %6, i32 100, i32 0)
%85 = call i32 @bcmp(i8* dereferenceable(19) %6, i8* dereferenceable(19) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i64 19)
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %90
87: ; preds = %82
%88 = call i32 @close(i32 %37)
%89 = call i32 @close(i32 %20)
br label %92
90: ; preds = %82
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
br label %44
92: ; preds = %87, %47
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.12, i64 0, i64 0))
br label %94
94: ; preds = %92, %78, %61, %33, %28, %22
ret i32 0
}