#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 {
  int sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ clientAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int htons(int);
char *inet_ntoa(TYPE_1__);
scalar_t__ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int main() {
  int code;
  int serverSocket = 0;
  int clientSocket = 0;
  struct sockaddr_in server_addr;
  struct sockaddr_in clientAddr;
  int addr_len = sizeof(clientAddr);
  char buffer[200];
  ssize_t iDataNum;
  if ((serverSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    code = 1;
    goto ENDSOCKET;
  }
  bzero(&server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(5556);
  server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(serverSocket, (struct sockaddr *)&server_addr, sizeof(server_addr)) <
      0) {
    code = 2;
    goto ENDSOCKET;
  }
  if (listen(serverSocket, 5) < 0) {
    code = 3;
    goto ENDSOCKET;
  }
  while (1) {
    printf("Listening on port: %d\n", 5556);
    clientSocket = accept(serverSocket, (struct sockaddr *)&clientAddr,
                          (socklen_t *)&addr_len);
    if (clientSocket < 0) {
      code = 4;
      goto ENDSOCKET;
    }
    printf("\nrecv client data...n");
    printf("IP is %s\n", inet_ntoa(clientAddr.sin_addr));
    printf("Port is %d\n", htons(clientAddr.sin_port));
    int isClose = 0;
    while (1) {
      iDataNum = recv(clientSocket, buffer, 1024, 0);
      if (iDataNum < 0) {
        perror("recv error.");
        continue;
      }
      printf("buffer=%s,iDataNum=%d\n", buffer, iDataNum);
      buffer[iDataNum] = '\0';
      printf("222 buffer=%s\n", buffer);
      if (strcmp(buffer, "quit") == 0) {
        isClose = -1;
        break;
      }
      printf("%ld recv data is %s\n", iDataNum, buffer);
      send(clientSocket, buffer, iDataNum, 0);
    }
  }
ENDSOCKET:
  if (code == 1) {
    perror("socket init error.");
  } else if (code == 2) {
    perror("connect error.");
  } else if (code == 3) {
    perror("listen error.");
  } else if (code == 4) {
    perror("accept error.");
  }
  close(serverSocket);
  close(clientSocket);
  return code;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0xc,-0x34(%rbp)
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1238 <main+0x58>
movl   $0x1,-0x8(%rbp)
jmp    1425 <main+0x245>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x15b4,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    1297 <main+0xb7>
movl   $0x2,-0x8(%rbp)
jmp    1425 <main+0x245>
mov    -0xc(%rbp),%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
cmp    $0x0,%rax
jge    12ba <main+0xda>
movl   $0x3,-0x8(%rbp)
jmp    1425 <main+0x245>
jmp    12bf <main+0xdf>
lea    0xd3a(%rip),%rdi
mov    $0x15b4,%esi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    12fb <main+0x11b>
movl   $0x4,-0x8(%rbp)
jmp    1425 <main+0x245>
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xd12(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x30(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,%esi
lea    0xd04(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x108(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x104(%rbp)
cmpl   $0x0,-0x104(%rbp)
jge    137e <main+0x19e>
lea    0xccf(%rip),%rdi
call   10d0 <perror@plt>
jmp    1344 <main+0x164>
lea    -0x100(%rbp),%rsi
mov    -0x104(%rbp),%edx
lea    0xcbd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movslq -0x104(%rbp),%rax
movb   $0x0,-0x100(%rbp,%rax,1)
lea    -0x100(%rbp),%rsi
lea    0xcb0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x100(%rbp),%rdi
lea    0xcaa(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    13e9 <main+0x209>
movl   $0xffffffff,-0x108(%rbp)
ff ff ff
jmp    1420 <main+0x240>
mov    -0x104(%rbp),%esi
lea    -0x100(%rbp),%rdx
lea    0xc7d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    -0x104(%rbp),%edx
xor    %ecx,%ecx
call   1060 <send@plt>
jmp    1344 <main+0x164>
jmp    12bf <main+0xdf>
cmpl   $0x1,-0x8(%rbp)
jne    1440 <main+0x260>
lea    0xc59(%rip),%rdi
call   10d0 <perror@plt>
jmp    149b <main+0x2bb>
cmpl   $0x2,-0x8(%rbp)
jne    145b <main+0x27b>
lea    0xc51(%rip),%rdi
call   10d0 <perror@plt>
jmp    1496 <main+0x2b6>
cmpl   $0x3,-0x8(%rbp)
jne    1476 <main+0x296>
lea    0xc45(%rip),%rdi
call   10d0 <perror@plt>
jmp    1491 <main+0x2b1>
cmpl   $0x4,-0x8(%rbp)
jne    148c <main+0x2ac>
lea    0xc38(%rip),%rdi
call   10d0 <perror@plt>
jmp    1491 <main+0x2b1>
jmp    1496 <main+0x2b6>
jmp    149b <main+0x2bb>
mov    -0xc(%rbp),%edi
call   1090 <close@plt>
mov    -0x10(%rbp),%edi
call   1090 <close@plt>
mov    -0x8(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
movl   $0xc,0x8(%rsp)
mov    0x2de8(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    1231 <main+0x51>
lea    0xe6d(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%ebx
jmp    12f6 <main+0x116>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x28(%rsp)
mov    $0x15b4,%edi
call   1050 <htons@plt>
mov    %eax,0x20(%rsp)
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x24(%rsp)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jns    1293 <main+0xb3>
lea    0xe1d(%rip),%rdi
call   10d0 <perror@plt>
xor    %ebp,%ebp
mov    $0x2,%ebx
jmp    12f6 <main+0x116>
mov    %r15d,%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
test   %rax,%rax
jns    12ba <main+0xda>
lea    0xe05(%rip),%rdi
call   10d0 <perror@plt>
xor    %ebp,%ebp
mov    $0x3,%ebx
jmp    12f6 <main+0x116>
lea    0xd3f(%rip),%rdi
mov    $0x15b4,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r15d,%edi
call   10f0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1319 <main+0x139>
lea    0xdd3(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x4,%ebx
mov    %r15d,%edi
call   1090 <close@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    %ebx,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x30(%rsp),%rbx
lea    0xd41(%rip),%r12
lea    0xd49(%rip),%r13
lea    0xd47(%rip),%r14
mov    %r15d,0xc(%rsp)
jmp    1374 <main+0x194>
nopw   0x0(%rax,%rax,1)
lea    0xcb9(%rip),%rdi
mov    $0x15b4,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0xc(%rsp),%r15d
mov    %r15d,%edi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   10f0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
js     12e5 <main+0x105>
lea    0xc9c(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x14(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0xc9b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x10(%rsp),%edi
call   1050 <htons@plt>
lea    0xc8b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    13d0 <main+0x1f0>
lea    0xc85(%rip),%rdi
call   10d0 <perror@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     13b7 <main+0x1d7>
mov    %eax,%r15d
lea    0xc60(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%eax
movb   $0x0,0x30(%rsp,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1340 <main+0x160>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
jmp    13d0 <main+0x1f0>

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
@INADDR_ANY = global i32 0
@.str = [23 x i8] c"Listening on port: %d\0A\00"
@.str.1 = [22 x i8] c"\0Arecv client data...n\00"
@.str.2 = [10 x i8] c"IP is %s\0A\00"
@.str.3 = [12 x i8] c"Port is %d\0A\00"
@.str.4 = [12 x i8] c"recv error.\00"
@.str.5 = [23 x i8] c"buffer=%s,iDataNum=%d\0A\00"
@.str.6 = [15 x i8] c"222 buffer=%s\0A\00"
@.str.7 = [5 x i8] c"quit\00"
@.str.8 = [21 x i8] c"%ld recv data is %s\0A\00"
@.str.9 = [19 x i8] c"socket init error.\00"
@.str.10 = [15 x i8] c"connect error.\00"
@.str.11 = [14 x i8] c"listen error.\00"
@.str.12 = [14 x i8] c"accept error.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca [200 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
store i32 12, i32* %7
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %3
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %0
store i32 1, i32* %2
br label %86
16: ; preds = %0
%17 = call i32 @bzero(%struct.sockaddr_in* %5, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 5556)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i32 %20, i32* %21
%22 = load i32, i32* @INADDR_ANY
%23 = call i32 @htonl(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = load i32, i32* %3
%27 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%28 = call i64 @bind(i32 %26, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %16
store i32 2, i32* %2
br label %86
31: ; preds = %16
%32 = load i32, i32* %3
%33 = call i64 @listen(i32 %32, i32 5)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 3, i32* %2
br label %86
36: ; preds = %31
br label %37
37: ; preds = %36, %85
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 5556)
%39 = load i32, i32* %3
%40 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%41 = call i32 @accept(i32 %39, %struct.sockaddr* %40, i32* %7)
store i32 %41, i32* %4
%42 = load i32, i32* %4
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %37
store i32 4, i32* %2
br label %86
45: ; preds = %37
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%48 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i8* @inet_ntoa(i32 %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %50)
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%53 = load i32, i32* %52
%54 = call i32 @htons(i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %54)
store i32 0, i32* %10
br label %56
56: ; preds = %45, %62, %77
%57 = load i32, i32* %4
%58 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%59 = call i32 @recv(i32 %57, i8* %58, i32 1024, i32 0)
store i32 %59, i32* %9
%60 = load i32, i32* %9
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %56
%63 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %56
64: ; preds = %56
%65 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%66 = load i32, i32* %9
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %65, i32 %66)
%68 = load i32, i32* %9
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 %69
store i8 0, i8* %70
%71 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %71)
%73 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%74 = call i64 @strcmp(i8* %73, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%75 = icmp eq i64 %74, 0
br i1 %75, label %76, label %77
76: ; preds = %64
store i32 -1, i32* %10
br label %85
77: ; preds = %64
%78 = load i32, i32* %9
%79 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 %78, i8* %79)
%81 = load i32, i32* %4
%82 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%83 = load i32, i32* %9
%84 = call i32 @send(i32 %81, i8* %82, i32 %83, i32 0)
br label %56
85: ; preds = %76
br label %37
86: ; preds = %44, %35, %30, %15
%87 = load i32, i32* %2
%88 = icmp eq i32 %87, 1
br i1 %88, label %89, label %91
89: ; preds = %86
%90 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
br label %109
91: ; preds = %86
%92 = load i32, i32* %2
%93 = icmp eq i32 %92, 2
br i1 %93, label %94, label %96
94: ; preds = %91
%95 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
br label %108
96: ; preds = %91
%97 = load i32, i32* %2
%98 = icmp eq i32 %97, 3
br i1 %98, label %99, label %101
99: ; preds = %96
%100 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
br label %107
101: ; preds = %96
%102 = load i32, i32* %2
%103 = icmp eq i32 %102, 4
br i1 %103, label %104, label %106
104: ; preds = %101
%105 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
br label %106
106: ; preds = %104, %101
br label %107
107: ; preds = %106, %99
br label %108
108: ; preds = %107, %94
br label %109
109: ; preds = %108, %89
%110 = load i32, i32* %3
%111 = call i32 @close(i32 %110)
%112 = load i32, i32* %4
%113 = call i32 @close(i32 %112)
%114 = load i32, i32* %2
ret i32 %114
}

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
@INADDR_ANY = global i32 0
@.str = [23 x i8] c"Listening on port: %d\0A\00"
@.str.1 = [22 x i8] c"\0Arecv client data...n\00"
@.str.2 = [10 x i8] c"IP is %s\0A\00"
@.str.3 = [12 x i8] c"Port is %d\0A\00"
@.str.4 = [12 x i8] c"recv error.\00"
@.str.5 = [23 x i8] c"buffer=%s,iDataNum=%d\0A\00"
@.str.6 = [15 x i8] c"222 buffer=%s\0A\00"
@.str.7 = [5 x i8] c"quit\00"
@.str.8 = [21 x i8] c"%ld recv data is %s\0A\00"
@.str.9 = [19 x i8] c"socket init error.\00"
@.str.10 = [15 x i8] c"connect error.\00"
@.str.11 = [14 x i8] c"listen error.\00"
@.str.12 = [14 x i8] c"accept error.\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [200 x i8]
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast i32* %3 to i8*
store i32 12, i32* %3
%8 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %65, label %13
13: ; preds = %0
%14 = call i32 @bzero(%struct.sockaddr_in* %1, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 5556)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* @INADDR_ANY
%20 = tail call i32 @htonl(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%23 = call i64 @bind(i32 %11, %struct.sockaddr* %22, i32 12)
%24 = icmp slt i64 %23, 0
br i1 %24, label %67, label %25
25: ; preds = %13
%26 = call i64 @listen(i32 %11, i32 5)
%27 = icmp slt i64 %26, 0
br i1 %27, label %69, label %28
28: ; preds = %25
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 5556)
%30 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%31 = call i32 @accept(i32 %11, %struct.sockaddr* %30, i32* %3)
%32 = icmp slt i32 %31, 0
br i1 %32, label %71, label %33
33: ; preds = %28
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
br label %40
36: ; preds = %55
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 5556)
%38 = call i32 @accept(i32 %11, %struct.sockaddr* %30, i32* %3)
%39 = icmp slt i32 %38, 0
br i1 %39, label %71, label %40
40: ; preds = %33, %36
%41 = phi i32 [ %31, %33 ], [ %38, %36 ]
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32, i32* %34
%44 = call i8* @inet_ntoa(i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = load i32, i32* %35
%47 = call i32 @htons(i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %54, %40
%50 = call i32 @recv(i32 %41, i8* %8, i32 1024, i32 0)
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %52, %62
br label %49
55: ; preds = %49
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %8, i32 %50)
%57 = zext i32 %50 to i64
%58 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 %57
store i8 0, i8* %58
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %8)
%60 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %36, label %62
62: ; preds = %55
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 %50, i8* %8)
%64 = call i32 @send(i32 %41, i8* %8, i32 %50, i32 0)
br label %54
65: ; preds = %0
%66 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
br label %74
67: ; preds = %13
%68 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
br label %74
69: ; preds = %25
%70 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
br label %74
71: ; preds = %36, %28
%72 = phi i32 [ %31, %28 ], [ %38, %36 ]
%73 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
br label %74
74: ; preds = %67, %71, %69, %65
%75 = phi i32 [ 2, %67 ], [ 4, %71 ], [ 3, %69 ], [ 1, %65 ]
%76 = phi i32 [ 0, %67 ], [ %72, %71 ], [ 0, %69 ], [ 0, %65 ]
%77 = call i32 @close(i32 %11)
%78 = call i32 @close(i32 %76)
ret i32 %75
}