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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strncmp(char *, char *, int);
int main() {
  int sockfd;
  int acc_fd;
  int recv_sz;
  long addr_len;
  char buffer[128];
  char client_addr_a[10];
  struct sockaddr_in server_addr;
  struct sockaddr_in client_addr;
  if (-1 == (sockfd = socket(AF_INET, SOCK_STREAM, 0))) {
    printf("Create socket fail!\n");
    exit(1);
  }
  bzero(&server_addr, sizeof(struct sockaddr_in));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(3333);
  server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  bind(sockfd, (struct sockaddr *)(&server_addr), sizeof(struct sockaddr));
  listen(sockfd, 5);
  while (1) {
    addr_len = sizeof(struct sockaddr);
    if (-1 == (acc_fd = accept(sockfd, (struct sockaddr *)(&client_addr),
                               (socklen_t *)(&addr_len)))) {
      printf("Create server connect fail!\n");
      exit(1);
    }
    printf("The server has connect with %s\n", inet_ntoa(client_addr.sin_addr));
    recv_sz = recv(acc_fd, buffer, 128, 0);
    buffer[recv_sz] = '\0';
    if (0 == strncmp(buffer, "quit", 4)) {
      close(acc_fd);
      break;
    }
    printf("Server has received the message is : %s\n", buffer);
    close(acc_fd);
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1225 <main+0x55>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0xb8(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb0(%rbp)
mov    $0xd05,%edi
call   1060 <htons@plt>
mov    %eax,-0xb4(%rbp)
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0xb8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xb8(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
movq   $0x4,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc8(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    12cf <main+0xff>
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0xc8(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rdi
lea    0xd34(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1343 <main+0x173>
mov    -0xc(%rbp),%edi
call   1090 <close@plt>
jmp    1365 <main+0x195>
lea    -0xa0(%rbp),%rsi
lea    0xd06(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xc(%rbp),%edi
call   1090 <close@plt>
jmp    128a <main+0xba>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    0x2df0(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
je     1366 <main+0x186>
mov    %eax,%r15d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0xd05,%edi
call   1070 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x10(%rsp)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   10c0 <bind@plt>
mov    %r15d,%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
movq   $0x4,0x8(%rsp)
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r15d,%edi
call   10e0 <accept@plt>
cmp    $0xffffffff,%eax
je     132d <main+0x14d>
mov    %eax,%ebp
lea    0x30(%rsp),%rbx
lea    0xd81(%rip),%r12
lea    0x20(%rsp),%r14
lea    0x8(%rsp),%r13
nopl   0x0(%rax)
mov    0x20(%rsp),%edi
call   1060 <inet_ntoa@plt>
lea    0xd40(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1343 <main+0x163>
lea    0xd27(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
movq   $0x4,0x8(%rsp)
mov    %r15d,%edi
mov    %r14,%rsi
mov    %r13,%rdx
call   10e0 <accept@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    12b0 <main+0xd0>
lea    0xd1a(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcfd(%rip),%rdi
jmp    1334 <main+0x154>

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 = [21 x i8] c"Create socket fail!\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [29 x i8] c"Create server connect fail!\0A\00"
@.str.2 = [32 x i8] c"The server has connect with %s\0A\00"
@.str.3 = [5 x i8] c"quit\00"
@.str.4 = [41 x i8] c"Server has received the message is : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca [128 x i8]
%7 = alloca [10 x i8]
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %2
%13 = icmp eq i32 -1, %12
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = call i32 @bzero(%struct.sockaddr_in* %8, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %19, i32* %20
%21 = call i32 @htons(i32 3333)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = call i32 @htonl(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, 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* %8 to %struct.sockaddr*
%29 = call i32 @bind(i32 %27, %struct.sockaddr* %28, i32 4)
%30 = load i32, i32* %2
%31 = call i32 @listen(i32 %30, i32 5)
br label %32
32: ; preds = %17, %59
store i64 4, i64* %5
%33 = load i32, i32* %2
%34 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%35 = bitcast i64* %5 to i32*
%36 = call i32 @accept(i32 %33, %struct.sockaddr* %34, i32* %35)
store i32 %36, i32* %3
%37 = icmp eq i32 -1, %36
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %32
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%43 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i8* @inet_ntoa(i32 %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %45)
%47 = load i32, i32* %3
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%49 = call i32 @recv(i32 %47, i8* %48, i32 128, i32 0)
store i32 %49, i32* %4
%50 = load i32, i32* %4
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 %51
store i8 0, i8* %52
%53 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%54 = call i64 @strncmp(i8* %53, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%55 = icmp eq i64 0, %54
br i1 %55, label %56, label %59
56: ; preds = %41
%57 = load i32, i32* %3
%58 = call i32 @close(i32 %57)
br label %64
59: ; preds = %41
%60 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %60)
%62 = load i32, i32* %3
%63 = call i32 @close(i32 %62)
br label %32
64: ; preds = %56
%65 = load i32, i32* %2
%66 = call i32 @close(i32 %65)
ret i32 0
}

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
@INADDR_ANY = global i32 0
@.str.2 = [32 x i8] c"The server has connect with %s\0A\00"
@.str.3 = [5 x i8] c"quit\00"
@.str.4 = [41 x i8] c"Server has received the message is : %s\0A\00"
@str = [28 x i8] c"Create server connect fail!\00"
@str.5 = [20 x i8] c"Create socket fail!\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [128 x i8]
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = bitcast i64* %1 to i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%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 eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %18, i32* %19
%20 = tail call i32 @htons(i32 3333)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %20, i32* %21
%22 = load i32, i32* @INADDR_ANY
%23 = tail call i32 @htonl(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %23, i32* %24
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%26 = call i32 @bind(i32 %11, %struct.sockaddr* %25, i32 4)
%27 = call i32 @listen(i32 %11, i32 5)
%28 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%29 = bitcast i64* %1 to i32*
store i64 4, i64* %1
%30 = call i32 @accept(i32 %11, %struct.sockaddr* %28, i32* %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %34, label %32
32: ; preds = %16
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
br label %37
34: ; preds = %50, %16
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %32, %50
%38 = phi i32 [ %30, %32 ], [ %53, %50 ]
%39 = load i32, i32* %33
%40 = call i8* @inet_ntoa(i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = call i32 @recv(i32 %38, i8* %6, i32 128, i32 0)
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %43
store i8 0, i8* %44
%45 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %37
%48 = call i32 @close(i32 %38)
%49 = call i32 @close(i32 %11)
ret i32 0
50: ; preds = %37
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%52 = call i32 @close(i32 %38)
store i64 4, i64* %1
%53 = call i32 @accept(i32 %11, %struct.sockaddr* %28, i32* %29)
%54 = icmp eq i32 %53, -1
br i1 %54, label %34, label %37
}