#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 */

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct in_addr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EINTR;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
scalar_t__ errno;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, struct in_addr *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
long recv(int, char *, int, int /*<<< orphan*/);
long send(int, char *, int, 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 clientSocket;
  long retlen;
  unsigned long sendlen;
  char *pbuf;
  char recvbuf[100];
  char sendbuf[100];
  struct sockaddr_in *serverAddr =
      (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in));
  serverAddr->sin_family = AF_INET;
  inet_aton("127.0.0.1", (struct in_addr *)&(serverAddr->sin_addr));
  serverAddr->sin_port = htons(3500);
  clientSocket = socket(AF_INET, SOCK_STREAM, 0);
  if (clientSocket < 0) {
    printf("CREATE SOCKET ERROR\n");
    return 0;
  }
  if (connect(clientSocket, (struct sockaddr *)serverAddr,
              sizeof(*serverAddr)) < 0) {
    printf("CONNECT ERROR\n");
    return 0;
  }
  printf("THIS IS CLIENT：D\n");
  while (1) {
    if (!flag) {
      pbuf = sendbuf;
      printf("\nCLIENT('q OR Q' TO QUIT): ");
      fgets(sendbuf, 100, stdin);
      sendlen = strlen(sendbuf) + 1;
      retlen = send(clientSocket, pbuf, sendlen, 0);
      if (retlen < 0) {
        if (errno == EINTR)
          retlen = 0;
        else {
          close(clientSocket);
          return 0;
        }
      }
      if (*pbuf == 'q' || *pbuf == 'Q') {
        printf("\n...\n");
        pbuf = recvbuf;
        recv(clientSocket, pbuf, 100, 0);
        if (!strcmp(recvbuf, "!@clientDisconnect")) {
          close(clientSocket);
          break;
        } else
          printf("\nOH! QUIT ERROR!");
      }
      flag = 1;
    } else {
      pbuf = recvbuf;
      retlen = recv(clientSocket, pbuf, 100, 0);
      if (*pbuf == 'q' || *pbuf == 'Q') {
        char serverDisconnect[] = "!@serverDisconnect";
        pbuf = serverDisconnect;
        send(clientSocket, pbuf, strlen(serverDisconnect) + 1, 0);
        close(clientSocket);
        break;
      }
      if (retlen < 0) {
        if (errno == EINTR)
          retlen = 0;
        else {
          close(clientSocket);
          printf("\nRECEIVE DATA ERROR!");
          return 0;
        }
      }
      printf("\nMESSAGE FROM SERVER: %s", recvbuf);
      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    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0xc,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x108(%rbp)
mov    0x2df7(%rip),%rax
mov    (%rax),%ecx
mov    -0x108(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x108(%rbp),%rsi
add    $0x4,%rsi
lea    0xdf1(%rip),%rdi
call   10b0 <inet_aton@plt>
mov    $0xdac,%edi
call   1050 <htons@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1269 <main+0xa9>
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1550 <main+0x390>
mov    -0xc(%rbp),%edi
mov    -0x108(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    12a1 <main+0xe1>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1550 <main+0x390>
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    13f8 <main+0x238>
lea    -0x100(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x100(%rbp),%rdi
mov    0x2d00(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1090 <fgets@plt>
lea    -0x100(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1364 <main+0x1a4>
mov    0x2c9d(%rip),%rax
mov    (%rax),%rax
mov    0x2c8b(%rip),%rcx
cmp    (%rcx),%rax
jne    134b <main+0x18b>
movq   $0x0,-0x18(%rbp)
jmp    135f <main+0x19f>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1550 <main+0x390>
jmp    1364 <main+0x1a4>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x71,%eax
je     1384 <main+0x1c4>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x51,%eax
jne    13ec <main+0x22c>
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x90(%rbp),%rdi
lea    0xca6(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    13d9 <main+0x219>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
jmp    153b <main+0x37b>
lea    0xc97(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    13ec <main+0x22c>
movl   $0x1,-0x8(%rbp)
jmp    1536 <main+0x376>
lea    -0x90(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x71,%eax
je     143a <main+0x27a>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x51,%eax
jne    14c1 <main+0x301>
mov    0xcaf(%rip),%rax
mov    %rax,-0x120(%rbp)
mov    0xca9(%rip),%rax
mov    %rax,-0x118(%rbp)
mov    0xca3(%rip),%ax
mov    %ax,-0x110(%rbp)
mov    0xc98(%rip),%al
mov    %al,-0x10e(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x12c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x12c(%rbp),%edi
mov    -0x128(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
jmp    153b <main+0x37b>
cmpq   $0x0,-0x18(%rbp)
jge    151a <main+0x35a>
mov    0x2af5(%rip),%rax
mov    (%rax),%rax
mov    0x2ae3(%rip),%rcx
cmp    (%rcx),%rax
jne    14f3 <main+0x333>
movq   $0x0,-0x18(%rbp)
jmp    1515 <main+0x355>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
lea    0xb86(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1550 <main+0x390>
jmp    151a <main+0x35a>
lea    -0x90(%rbp),%rsi
lea    0xb75(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x8(%rbp)
jmp    12af <main+0xef>
lea    0xb74(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
mov    $0xc,%edi
call   10c0 <malloc@plt>
mov    %rax,%rbp
mov    0x2e03(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rbp)
lea    0x4(%rbp),%rsi
lea    0xe2b(%rip),%rdi
call   10b0 <inet_aton@plt>
mov    $0xdac,%edi
call   1060 <htons@plt>
mov    %eax,0x0(%rbp)
mov    (%rbx),%edi
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     138d <main+0x1cd>
mov    %eax,%ebx
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %rax,%rax
js     1396 <main+0x1d6>
lea    0xe56(%rip),%rdi
call   1040 <puts@plt>
lea    0xddc(%rip),%r14
mov    0x2d8b(%rip),%rbp
lea    0x90(%rsp),%r15
lea    0x20(%rsp),%r13
lea    0xe16(%rip),%r12
jmp    127d <main+0xbd>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x0(%rbp),%edx
mov    %r15,%rdi
mov    $0x64,%esi
call   10a0 <fgets@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebx,%edi
mov    %r15,%rsi
xor    %ecx,%ecx
call   1070 <send@plt>
test   %rax,%rax
jns    12cd <main+0x10d>
mov    0x2d0e(%rip),%rax
mov    (%rax),%rax
mov    0x2cfc(%rip),%rcx
cmp    (%rcx),%rax
jne    13f5 <main+0x235>
movzbl 0x90(%rsp),%eax
or     $0x20,%al
cmp    $0x71,%al
jne    1335 <main+0x175>
lea    0xdc9(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
movdqu 0x23(%rsp),%xmm0
pcmpeqb 0xcfa(%rip),%xmm0
movdqa 0x20(%rsp),%xmm1
pcmpeqb 0xcfc(%rip),%xmm1
pand   %xmm0,%xmm1
pmovmskb %xmm1,%eax
cmp    $0xffff,%eax
je     13ce <main+0x20e>
lea    0xd2b(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
movzbl 0x20(%rsp),%ecx
or     $0x20,%cl
cmp    $0x71,%cl
je     139f <main+0x1df>
test   %rax,%rax
jns    1270 <main+0xb0>
mov    0x2c65(%rip),%rax
mov    (%rax),%rax
mov    0x2c53(%rip),%rcx
cmp    (%rcx),%rax
je     1270 <main+0xb0>
mov    %ebx,%edi
call   1090 <close@plt>
lea    0xce6(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    13e1 <main+0x221>
lea    0xd5b(%rip),%rdi
jmp    13dc <main+0x21c>
lea    0xd44(%rip),%rdi
jmp    13dc <main+0x21c>
movdqa 0xd69(%rip),%xmm0
movdqa %xmm0,(%rsp)
movl   $0x746365,0xf(%rsp)
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebx,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %ebx,%edi
call   1090 <close@plt>
lea    0xcd4(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%edi
call   1090 <close@plt>
jmp    13e1 <main+0x221>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"CREATE SOCKET ERROR\0A\00"
@.str.2 = [15 x i8] c"CONNECT ERROR\0A\00"
@.str.3 = [20 x i8] c"THIS IS CLIENT\EF\BC\9AD\0A\00"
@.str.4 = [28 x i8] c"\0ACLIENT('q OR Q' TO QUIT): \00"
@stdin = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str.5 = [6 x i8] c"\0A...\0A\00"
@.str.6 = [19 x i8] c"!@clientDisconnect\00"
@.str.7 = [17 x i8] c"\0AOH! QUIT ERROR!\00"
@__const.main.serverDisconnect = [19 x i8] c"!@serverDisconnect\00"
@.str.8 = [21 x i8] c"\0ARECEIVE DATA ERROR!\00"
@.str.9 = [25 x i8] c"\0AMESSAGE FROM SERVER: %s\00"
@.str.10 = [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 i64
%5 = alloca i64
%6 = alloca i8*
%7 = alloca [100 x i8]
%8 = alloca [100 x i8]
%9 = alloca %struct.sockaddr_in*
%10 = alloca [19 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
%11 = call i64 @malloc(i32 12)
%12 = inttoptr i64 %11 to %struct.sockaddr_in*
store %struct.sockaddr_in* %12, %struct.sockaddr_in** %9
%13 = load i32, i32* @AF_INET
%14 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 2
store i32 %13, i32* %15
%16 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 1
%18 = bitcast i32* %17 to %struct.in_addr*
%19 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.in_addr* %18)
%20 = call i32 @htons(i32 3500)
%21 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
store i32 %25, i32* %3
%26 = load i32, i32* %3
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %139
30: ; preds = %0
%31 = load i32, i32* %3
%32 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%33 = bitcast %struct.sockaddr_in* %32 to %struct.sockaddr*
%34 = call i64 @connect(i32 %31, %struct.sockaddr* %33, i32 12)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %139
38: ; preds = %30
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %136
%41 = load i32, i32* %2
%42 = icmp ne i32 %41, 0
br i1 %42, label %95, label %43
43: ; preds = %40
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
store i8* %44, i8** %6
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%47 = load i32, i32* @stdin
%48 = call i32 @fgets(i8* %46, i32 100, i32 %47)
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
store i64 %52, i64* %5
%53 = load i32, i32* %3
%54 = load i8*, i8** %6
%55 = load i64, i64* %5
%56 = trunc i64 %55 to i32
%57 = call i64 @send(i32 %53, i8* %54, i32 %56, i32 0)
store i64 %57, i64* %4
%58 = load i64, i64* %4
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %69
60: ; preds = %43
%61 = load i64, i64* @errno
%62 = load i64, i64* @EINTR
%63 = icmp eq i64 %61, %62
br i1 %63, label %64, label %65
64: ; preds = %60
store i64 0, i64* %4
br label %68
65: ; preds = %60
%66 = load i32, i32* %3
%67 = call i32 @close(i32 %66)
store i32 0, i32* %1
br label %139
68: ; preds = %64
br label %69
69: ; preds = %68, %43
%70 = load i8*, i8** %6
%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 = %69
%75 = load i8*, i8** %6
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp eq i32 %77, 81
br i1 %78, label %79, label %94
79: ; preds = %74, %69
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%81 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
store i8* %81, i8** %6
%82 = load i32, i32* %3
%83 = load i8*, i8** %6
%84 = call i64 @recv(i32 %82, i8* %83, i32 100, i32 0)
%85 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%86 = call i32 @strcmp(i8* %85, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%87 = icmp ne i32 %86, 0
br i1 %87, label %91, label %88
88: ; preds = %79
%89 = load i32, i32* %3
%90 = call i32 @close(i32 %89)
br label %137
91: ; preds = %79
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
br label %93
93: ; preds = %91
br label %94
94: ; preds = %93, %74
store i32 1, i32* %2
br label %136
95: ; preds = %40
%96 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
store i8* %96, i8** %6
%97 = load i32, i32* %3
%98 = load i8*, i8** %6
%99 = call i64 @recv(i32 %97, i8* %98, i32 100, i32 0)
store i64 %99, i64* %4
%100 = load i8*, i8** %6
%101 = load i8, i8* %100
%102 = sext i8 %101 to i32
%103 = icmp eq i32 %102, 113
br i1 %103, label %109, label %104
104: ; preds = %95
%105 = load i8*, i8** %6
%106 = load i8, i8* %105
%107 = sext i8 %106 to i32
%108 = icmp eq i32 %107, 81
br i1 %108, label %109, label %120
109: ; preds = %104, %95
%110 = bitcast [19 x i8]* %10 to i8*
%111 = getelementptr inbounds [19 x i8], [19 x i8]* %10, i64 0, i64 0
store i8* %111, i8** %6
%112 = load i32, i32* %3
%113 = load i8*, i8** %6
%114 = getelementptr inbounds [19 x i8], [19 x i8]* %10, i64 0, i64 0
%115 = call i32 @strlen(i8* %114)
%116 = add nsw i32 %115, 1
%117 = call i64 @send(i32 %112, i8* %113, i32 %116, i32 0)
%118 = load i32, i32* %3
%119 = call i32 @close(i32 %118)
br label %137
120: ; preds = %104
%121 = load i64, i64* %4
%122 = icmp slt i64 %121, 0
br i1 %122, label %123, label %133
123: ; preds = %120
%124 = load i64, i64* @errno
%125 = load i64, i64* @EINTR
%126 = icmp eq i64 %124, %125
br i1 %126, label %127, label %128
127: ; preds = %123
store i64 0, i64* %4
br label %132
128: ; preds = %123
%129 = load i32, i32* %3
%130 = call i32 @close(i32 %129)
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %1
br label %139
132: ; preds = %127
br label %133
133: ; preds = %132, %120
%134 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i8* %134)
store i32 0, i32* %2
br label %136
136: ; preds = %133, %94
br label %40
137: ; preds = %109, %88
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %1
br label %139
139: ; preds = %137, %128, %65, %36, %28
%140 = load i32, i32* %1
ret i32 %140
}

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