#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;
};
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ rebuf;
typedef int /*<<< orphan*/ client;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int listen(int, int);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, char, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  int listenfd;
  int addrlen;
  struct sockaddr_in server;
  struct sockaddr_in client;
  memset(&client, '\0', sizeof(client));
  memset(&server, '\0', sizeof(server));
  if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket() error\n");
    exit(1);
  }
  server.sin_family = AF_INET;
  server.sin_port = htons(8888);
  server.sin_addr.s_addr = inet_addr("0.0.0.0");
  if (bind(listenfd, (struct sockaddr *)&server, sizeof(server)) == -1) {
    perror("bind() error\n");
    exit(1);
  }
  if (listen(listenfd, 5) == -1) {
    perror("listen() error\n");
    exit(1);
  }
  addrlen = sizeof(client);
  int connetfd;
  if ((connetfd = accept(listenfd, (struct sockaddr *)&client, &addrlen)) ==
      -1) {
    perror("accept() error\n");
    exit(1);
  }
  printf("connect successful!\n");
  int serial = 0;
  char rebuf[100];
  int revlen;
  while (1) {
    bzero(rebuf, sizeof(rebuf));
    revlen = read(connetfd, rebuf, sizeof(rebuf));
    if ((memcmp("bye", rebuf, 3)) == 0) {
      printf("Bye-bye then close the connect...\n");
      break;
    }
    if (revlen <= 0) {
      break;
    }
    rebuf[revlen] = '\0';
    printf("[client]:%s", rebuf);
  }
  close(connetfd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    124d <main+0x6d>
lea    0xdc2(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x22b8,%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    0xda3(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12a5 <main+0xc5>
lea    0xd82(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    12d1 <main+0xf1>
lea    0xd64(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
movl   $0xc,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    130a <main+0x12a>
lea    0xd3b(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x30(%rbp)
lea    -0xa0(%rbp),%rdi
mov    $0x64,%esi
call   10d0 <bzero@plt>
mov    -0x2c(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    %eax,-0xa4(%rbp)
lea    -0xa0(%rbp),%rsi
lea    0xd03(%rip),%rdi
mov    $0x3,%edx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
jne    137f <main+0x19f>
lea    0xcec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13ba <main+0x1da>
cmpl   $0x0,-0xa4(%rbp)
jg     1391 <main+0x1b1>
jmp    13ba <main+0x1da>
movslq -0xa4(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rsi
lea    0xcd4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    131f <main+0x13f>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa0,%rsp
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2dc0(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
cmp    $0xffffffff,%eax
je     1392 <main+0x1a2>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0x22b8,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xdae(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
je     139b <main+0x1ab>
mov    %ebx,%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
cmp    $0xffffffff,%eax
je     13a4 <main+0x1b4>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10f0 <accept@plt>
cmp    $0xffffffff,%eax
je     13ad <main+0x1bd>
mov    %eax,%r12d
lea    0xd90(%rip),%rdi
call   1030 <puts@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   10e0 <bzero@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1080 <read@plt>
mov    %eax,%ebp
lea    0xd50(%rip),%rdi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1090 <memcmp@plt>
test   %rax,%rax
je     136c <main+0x17c>
lea    0xd3b(%rip),%r14
lea    0x30(%rsp),%rbx
lea    0xd2b(%rip),%r15
nopl   0x0(%rax,%rax,1)
test   %ebp,%ebp
jle    1378 <main+0x188>
mov    %ebp,%eax
movb   $0x0,0x30(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
call   10e0 <bzero@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1080 <read@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1090 <memcmp@plt>
test   %rax,%rax
jne    1320 <main+0x130>
lea    0xcf7(%rip),%rdi
call   1030 <puts@plt>
mov    %r12d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc67(%rip),%rdi
jmp    13b4 <main+0x1c4>
lea    0xc76(%rip),%rdi
jmp    13b4 <main+0x1c4>
lea    0xc7b(%rip),%rdi
jmp    13b4 <main+0x1c4>
lea    0xc82(%rip),%rdi
call   10d0 <perror@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
@SOCK_STREAM = global i32 0
@.str = [16 x i8] c"socket() error\0A\00"
@.str.1 = [8 x i8] c"0.0.0.0\00"
@.str.2 = [14 x i8] c"bind() error\0A\00"
@.str.3 = [16 x i8] c"listen() error\0A\00"
@.str.4 = [16 x i8] c"accept() error\0A\00"
@.str.5 = [21 x i8] c"connect successful!\0A\00"
@.str.6 = [4 x i8] c"bye\00"
@.str.7 = [35 x i8] c"Bye-bye then close the connect...\0A\00"
@.str.8 = [12 x i8] c"[client]:%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 @memset(%struct.sockaddr_in* %5, i8 signext 0, i32 12)
%11 = call i32 @memset(%struct.sockaddr_in* %4, i8 signext 0, i32 12)
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %2
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %0
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @htons(i32 8888)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %22, i32* %23
%24 = call i32 @inet_addr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = load i32, i32* %2
%28 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%29 = call i32 @bind(i32 %27, %struct.sockaddr* %28, i32 12)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %19
%32 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %19
%35 = load i32, i32* %2
%36 = call i32 @listen(i32 %35, i32 5)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %34
store i32 12, i32* %3
%42 = load i32, i32* %2
%43 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%44 = call i32 @accept(i32 %42, %struct.sockaddr* %43, i32* %3)
store i32 %44, i32* %6
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %41
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %7
br label %51
51: ; preds = %49, %66
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%53 = call i32 @bzero(i8* %52, i32 100)
%54 = load i32, i32* %6
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%56 = call i32 @read(i32 %54, i8* %55, i32 100)
store i32 %56, i32* %9
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%58 = call i64 @memcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %57, i32 3)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %51
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0))
br label %72
62: ; preds = %51
%63 = load i32, i32* %9
%64 = icmp sle i32 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %62
br label %72
66: ; preds = %62
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %68
store i8 0, i8* %69
%70 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %70)
br label %51
72: ; preds = %65, %60
%73 = load i32, i32* %6
%74 = call i32 @close(i32 %73)
%75 = load i32, i32* %1
ret i32 %75
}

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
@SOCK_STREAM = global i32 0
@.str = [16 x i8] c"socket() error\0A\00"
@.str.1 = [8 x i8] c"0.0.0.0\00"
@.str.2 = [14 x i8] c"bind() error\0A\00"
@.str.3 = [16 x i8] c"listen() error\0A\00"
@.str.4 = [16 x i8] c"accept() error\0A\00"
@.str.6 = [4 x i8] c"bye\00"
@.str.8 = [12 x i8] c"[client]:%s\00"
@str = [20 x i8] c"connect successful!\00"
@str.9 = [34 x i8] c"Bye-bye then close the connect...\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca [100 x i8]
%5 = bitcast i32* %1 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = call i32 @memset(%struct.sockaddr_in* %3, i8 signext 0, i32 12)
%9 = call i32 @memset(%struct.sockaddr_in* %2, i8 signext 0, i32 12)
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 8888)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %20, i32* %21
%22 = call i32 @inet_addr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %22, i32* %23
%24 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%25 = call i32 @bind(i32 %12, %struct.sockaddr* %24, i32 12)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %17
%28 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
%31 = call i32 @listen(i32 %12, i32 5)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %30
store i32 12, i32* %1
%37 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%38 = call i32 @accept(i32 %12, %struct.sockaddr* %37, i32* %1)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %36
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%46 = call i32 @bzero(i8* %45, i32 100)
%47 = call i32 @read(i32 %38, i8* %45, i32 100)
%48 = call i64 @memcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %45, i32 3)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %55, %43
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.9, i64 0, i64 0))
br label %63
52: ; preds = %43, %55
%53 = phi i32 [ %60, %55 ], [ %47, %43 ]
%54 = icmp slt i32 %53, 1
br i1 %54, label %63, label %55
55: ; preds = %52
%56 = zext i32 %53 to i64
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %56
store i8 0, i8* %57
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %45)
%59 = call i32 @bzero(i8* %45, i32 100)
%60 = call i32 @read(i32 %38, i8* %45, i32 100)
%61 = call i64 @memcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %45, i32 3)
%62 = icmp eq i64 %61, 0
br i1 %62, label %50, label %52
63: ; preds = %52, %50
%64 = call i32 @close(i32 %38)
ret i32 0
}