#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__ {
  void *s_addr;
};
struct sockaddr_in {
  void *sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
char *ctime(long *);
int /*<<< orphan*/ exit(int);
void *htons(int);
scalar_t__ listen(int, int);
int ntohs(void *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
long time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int servfd, clifd;
  struct sockaddr_in servaddr, cliaddr;
  if ((servfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf(" create socket error!\n ");
    exit(1);
  }
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(20000);
  servaddr.sin_addr.s_addr = htons(INADDR_ANY);
  if (bind(servfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
    printf(" bind to port %d failure!\n ", 20000);
    exit(1);
  }
  if (listen(servfd, 10) < 0) {
    printf(" call listen failure!\n ");
    exit(1);
  }
  while (1) {
    char buf[1255];
    long timestamp;
    socklen_t length = sizeof(cliaddr);
    clifd = accept(servfd, (struct sockaddr *)&cliaddr, &length);
    if (clifd < 0) {
      printf(" error comes when call accept!\n ");
      break;
    }
    strcpy(buf, "welcome to connect the server. ");
    printf("Port:%d\n ", ntohs(cliaddr.sin_port));
    timestamp = time(NULL);
    strcat(buf, " timestamp in server: ");
    strcat(buf, ctime(&timestamp));
    send(clifd, buf, 1255, 0);
    close(clifd);
  }
  close(servfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x550,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1246 <main+0x56>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    -0x30(%rbp),%rdi
mov    $0x18,%esi
call   10d0 <bzero@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x4e20,%edi
call   1050 <htons@plt>
mov    %rax,-0x30(%rbp)
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   1050 <htons@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    12b8 <main+0xc8>
lea    0xd76(%rip),%rdi
mov    $0x4e20,%esi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
cmp    $0x0,%rax
jge    12e7 <main+0xf7>
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    12ec <main+0xfc>
movl   $0x18,-0x53c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x53c(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1329 <main+0x139>
lea    0xd2f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    13c4 <main+0x1d4>
lea    -0x530(%rbp),%rdi
lea    0xd36(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x48(%rbp),%rdi
call   10b0 <ntohs@plt>
mov    %eax,%esi
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %rax,-0x538(%rbp)
lea    -0x530(%rbp),%rdi
lea    0xd24(%rip),%rsi
call   10f0 <strcat@plt>
lea    -0x530(%rbp),%rax
mov    %rax,-0x548(%rbp)
lea    -0x538(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0x548(%rbp),%rdi
mov    %rax,%rsi
call   10f0 <strcat@plt>
mov    -0x18(%rbp),%edi
lea    -0x530(%rbp),%rsi
mov    $0x4e7,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
jmp    12ec <main+0xfc>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x550,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x528,%rsp
mov    0x2de0(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
test   %eax,%eax
js     138a <main+0x19a>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x18,%esi
call   10d0 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x20(%rsp)
mov    $0x4e20,%edi
call   1050 <htons@plt>
mov    %rax,0x10(%rsp)
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1050 <htons@plt>
mov    %rax,0x18(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x18,%edx
call   10c0 <bind@plt>
test   %rax,%rax
js     1393 <main+0x1a3>
mov    %ebp,%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
test   %rax,%rax
js     13b0 <main+0x1c0>
movl   $0x18,0x4(%rsp)
lea    0x28(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
call   10e0 <accept@plt>
test   %eax,%eax
js     1361 <main+0x171>
mov    %eax,%r14d
lea    0x40(%rsp),%rbx
lea    0x8(%rsp),%r13
lea    0x28(%rsp),%r15
lea    0x4(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
lea    0xd93(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x28(%rsp),%rdi
call   10b0 <ntohs@plt>
lea    0xd9d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %rax,0x8(%rsp)
mov    %rbx,%rdi
lea    0xd88(%rip),%rsi
call   10f0 <strcat@plt>
mov    %r13,%rdi
call   1040 <ctime@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   10f0 <strcat@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x4e7,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %r14d,%edi
call   1080 <close@plt>
movl   $0x18,0x4(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   10e0 <accept@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    12d0 <main+0xe0>
lea    0xce4(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x528,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc6f(%rip),%rdi
jmp    13b7 <main+0x1c7>
lea    0xc7e(%rip),%rdi
mov    $0x4e20,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xc7d(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [24 x i8] c" create socket error!\0A \00"
@INADDR_ANY = global i32 0
@.str.1 = [28 x i8] c" bind to port %d failure!\0A \00"
@.str.2 = [24 x i8] c" call listen failure!\0A \00"
@.str.3 = [33 x i8] c" error comes when call accept!\0A \00"
@.str.4 = [32 x i8] c"welcome to connect the server. \00"
@.str.5 = [10 x i8] c"Port:%d\0A \00"
@.str.6 = [23 x i8] c" timestamp in server: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca [1255 x i8]
%11 = alloca i64
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = call i32 @bzero(%struct.sockaddr_in* %8, i32 24)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %22, i32* %23
%24 = call i8* @htons(i32 20000)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i8* %24, i8** %25
%26 = load i32, i32* @INADDR_ANY
%27 = call i8* @htons(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i8* %27, i8** %29
%30 = load i32, i32* %6
%31 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%32 = call i64 @bind(i32 %30, %struct.sockaddr* %31, i32 24)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %20
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 20000)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %20
%38 = load i32, i32* %6
%39 = call i64 @listen(i32 %38, i32 10)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %37
br label %45
45: ; preds = %44, %53
store i32 24, i32* %12
%46 = load i32, i32* %6
%47 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%48 = call i32 @accept(i32 %46, %struct.sockaddr* %47, i32* %12)
store i32 %48, i32* %7
%49 = load i32, i32* %7
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %71
53: ; preds = %45
%54 = getelementptr inbounds [1255 x i8], [1255 x i8]* %10, i64 0, i64 0
%55 = call i32 @strcpy(i8* %54, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%57 = load i8*, i8** %56
%58 = call i32 @ntohs(i8* %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %58)
%60 = call i64 @time(i32* null)
store i64 %60, i64* %11
%61 = getelementptr inbounds [1255 x i8], [1255 x i8]* %10, i64 0, i64 0
%62 = call i32 @strcat(i8* %61, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%63 = getelementptr inbounds [1255 x i8], [1255 x i8]* %10, i64 0, i64 0
%64 = call i8* @ctime(i64* %11)
%65 = call i32 @strcat(i8* %63, i8* %64)
%66 = load i32, i32* %7
%67 = getelementptr inbounds [1255 x i8], [1255 x i8]* %10, i64 0, i64 0
%68 = call i32 @send(i32 %66, i8* %67, i32 1255, i32 0)
%69 = load i32, i32* %7
%70 = call i32 @close(i32 %69)
br label %45
71: ; preds = %51
%72 = load i32, i32* %6
%73 = call i32 @close(i32 %72)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [24 x i8] c" create socket error!\0A \00"
@INADDR_ANY = global i32 0
@.str.1 = [28 x i8] c" bind to port %d failure!\0A \00"
@.str.2 = [24 x i8] c" call listen failure!\0A \00"
@.str.3 = [33 x i8] c" error comes when call accept!\0A \00"
@.str.4 = [32 x i8] c"welcome to connect the server. \00"
@.str.5 = [10 x i8] c"Port:%d\0A \00"
@.str.6 = [23 x i8] c" timestamp in server: \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca [1255 x i8]
%6 = alloca i64
%7 = alloca i32
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = call i32 @bzero(%struct.sockaddr_in* %3, i32 24)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %19, i32* %20
%21 = tail call i8* @htons(i32 20000)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i8* %21, i8** %22
%23 = load i32, i32* @INADDR_ANY
%24 = tail call i8* @htons(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i8* %24, i8** %25
%26 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%27 = call i64 @bind(i32 %12, %struct.sockaddr* %26, i32 24)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %17
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 20000)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %17
%33 = call i64 @listen(i32 %12, i32 10)
%34 = icmp slt i64 %33, 0
br i1 %34, label %44, label %35
35: ; preds = %32
%36 = getelementptr inbounds [1255 x i8], [1255 x i8]* %5, i64 0, i64 0
%37 = bitcast i64* %6 to i8*
%38 = bitcast i32* %7 to i8*
%39 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
store i32 24, i32* %7
%40 = call i32 @accept(i32 %12, %struct.sockaddr* %39, i32* %7)
%41 = icmp slt i32 %40, 0
br i1 %41, label %61, label %42
42: ; preds = %35
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
br label %47
44: ; preds = %32
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %42, %47
%48 = phi i32 [ %40, %42 ], [ %59, %47 ]
%49 = call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%50 = load i8*, i8** %43
%51 = call i32 @ntohs(i8* %50)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %51)
%53 = call i64 @time(i32* null)
store i64 %53, i64* %6
%54 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%55 = call i8* @ctime(i64* %6)
%56 = call i32 @strcat(i8* %36, i8* %55)
%57 = call i32 @send(i32 %48, i8* %36, i32 1255, i32 0)
%58 = call i32 @close(i32 %48)
store i32 24, i32* %7
%59 = call i32 @accept(i32 %12, %struct.sockaddr* %39, i32* %7)
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %47
61: ; preds = %47, %35
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%63 = call i32 @close(i32 %12)
ret i32 0
}