#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 */
typedef int /*<<< orphan*/ time_t;
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*/ servaddr;
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ 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(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int listenfd;
  int connfd;
  struct sockaddr_in servaddr;
  struct sockaddr_in cliaddr;
  int lenstruct;
  char buff[4096];
  time_t ticks;
  listenfd = socket(AF_INET, SOCK_STREAM, 0);
  if (listenfd < 0) {
    perror("socket error");
    return 1;
  }
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(60000);
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  lenstruct = sizeof(servaddr);
  if ((bind(listenfd, (struct sockaddr *)&servaddr, lenstruct)) < 0) {
    perror("bind error");
    return 1;
  }
  if (listen(listenfd, 10) < 0) {
    perror("listen error");
    return 1;
  }
  for (;;) {
    connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &lenstruct);
    if (connfd < 0) {
      perror("accept error");
      return 1;
    }
    ticks = time(NULL);
    snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));
    if (write(connfd, buff, strlen(buff)) < 0) {
      fprintf(stderr, "write error\n");
      return 1;
    }
    close(connfd);
  }
  close(listenfd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1060,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1247 <main+0x57>
lea    0xdca(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d3 <main+0x1e3>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0xea60,%edi
call   1060 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x28(%rbp)
movl   $0xc,-0x3c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
jge    12b7 <main+0xc7>
lea    0xd67(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d3 <main+0x1e3>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   10c0 <listen@plt>
cmp    $0x0,%rax
jge    12e6 <main+0xf6>
lea    0xd43(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d3 <main+0x1e3>
jmp    12eb <main+0xfb>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1320 <main+0x130>
lea    0xd16(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d3 <main+0x1e3>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,-0x1044(%rbp)
lea    -0x1040(%rbp),%rax
mov    %rax,-0x1060(%rbp)
lea    -0x1044(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0x1060(%rbp),%rdi
mov    %rax,%rcx
mov    $0x1000,%esi
lea    0xcd3(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1054(%rbp)
lea    -0x1040(%rbp),%rax
mov    %rax,-0x1050(%rbp)
lea    -0x1040(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1054(%rbp),%edi
mov    -0x1050(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    13c6 <main+0x1d6>
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
lea    0xc85(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d3 <main+0x1e3>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
jmp    12eb <main+0xfb>
mov    -0x4(%rbp),%eax
add    $0x1060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1038,%rsp
mov    0x2de0(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
test   %eax,%eax
js     134c <main+0x15c>
mov    %eax,%r12d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0xea60,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x10(%rsp)
movl   $0xc,0x8(%rsp)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
test   %rax,%rax
js     1355 <main+0x165>
mov    %r12d,%edi
mov    $0xa,%esi
call   10c0 <listen@plt>
test   %rax,%rax
js     135e <main+0x16e>
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r12d,%edi
call   1100 <accept@plt>
test   %eax,%eax
js     132c <main+0x13c>
mov    %eax,%ebp
lea    0xd79(%rip),%r15
lea    0x30(%rsp),%rbx
lea    0x20(%rsp),%r13
lea    0x8(%rsp),%r14
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <ctime@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1335 <main+0x145>
mov    %ebp,%edi
call   1090 <close@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    %r14,%rdx
call   1100 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    12d0 <main+0xe0>
lea    0xcf2(%rip),%rdi
jmp    1365 <main+0x175>
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
lea    0xcf5(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    136a <main+0x17a>
lea    0xcad(%rip),%rdi
jmp    1365 <main+0x175>
lea    0xcb1(%rip),%rdi
jmp    1365 <main+0x175>
lea    0xcb3(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%eax
add    $0x1038,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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 = [13 x i8] c"socket error\00"
@INADDR_ANY = global i32 0
@.str.1 = [11 x i8] c"bind error\00"
@.str.2 = [13 x i8] c"listen error\00"
@.str.3 = [13 x i8] c"accept error\00"
@.str.4 = [8 x i8] c"%.24s\0D\0A\00"
@stderr = global i32 0
@.str.5 = [13 x i8] c"write error\0A\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 i32
%11 = alloca [4096 x i8]
%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 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %69
20: ; preds = %2
%21 = call i32 @bzero(%struct.sockaddr_in* %8, i32 12)
%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 i32 @htons(i32 60000)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* @INADDR_ANY
%27 = call i32 @htonl(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
store i32 12, i32* %10
%30 = load i32, i32* %6
%31 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%32 = load i32, i32* %10
%33 = call i64 @bind(i32 %30, %struct.sockaddr* %31, i32 %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %20
%36 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %69
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 %43
41: ; preds = %37
%42 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %69
43: ; preds = %37
br label %44
44: ; preds = %66, %43
%45 = load i32, i32* %6
%46 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%47 = call i32 @accept(i32 %45, %struct.sockaddr* %46, i32* %10)
store i32 %47, i32* %7
%48 = load i32, i32* %7
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %69
52: ; preds = %44
%53 = call i32 @time(i32* null)
store i32 %53, i32* %12
%54 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%55 = call i8* @ctime(i32* %12)
%56 = call i32 @snprintf(i8* %54, i32 4096, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %55)
%57 = load i32, i32* %7
%58 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%59 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%60 = call i32 @strlen(i8* %59)
%61 = call i64 @write(i32 %57, i8* %58, i32 %60)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %52
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %69
66: ; preds = %52
%67 = load i32, i32* %7
%68 = call i32 @close(i32 %67)
br label %44
69: ; preds = %63, %50, %41, %35, %18
%70 = load i32, i32* %3
ret i32 %70
}

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 = [13 x i8] c"socket error\00"
@INADDR_ANY = global i32 0
@.str.1 = [11 x i8] c"bind error\00"
@.str.2 = [13 x i8] c"listen error\00"
@.str.3 = [13 x i8] c"accept error\00"
@.str.4 = [8 x i8] c"%.24s\0D\0A\00"
@stderr = global i32 0
@.str.5 = [13 x i8] c"write error\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [4096 x i8]
%7 = alloca i32
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%12 = bitcast i32* %7 to i8*
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %59
19: ; preds = %2
%20 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = tail call i32 @htons(i32 60000)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = tail call i32 @htonl(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %26, i32* %27
store i32 12, i32* %5
%28 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%29 = call i64 @bind(i32 %15, %struct.sockaddr* %28, i32 12)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %19
%32 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %59
33: ; preds = %19
%34 = call i64 @listen(i32 %15, i32 10)
%35 = icmp slt i64 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %33
%37 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%38 = call i32 @accept(i32 %15, %struct.sockaddr* %37, i32* %5)
%39 = icmp slt i32 %38, 0
br i1 %39, label %42, label %44
40: ; preds = %33
%41 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %59
42: ; preds = %55, %36
%43 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %59
44: ; preds = %36, %55
%45 = phi i32 [ %57, %55 ], [ %38, %36 ]
%46 = call i32 @time(i32* null)
store i32 %46, i32* %7
%47 = call i8* @ctime(i32* %7)
%48 = call i32 @snprintf(i8* %11, i32 4096, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%49 = call i32 @strlen(i8* %11)
%50 = call i64 @write(i32 %45, i8* %11, i32 %49)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %44
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %59
55: ; preds = %44
%56 = call i32 @close(i32 %45)
%57 = call i32 @accept(i32 %15, %struct.sockaddr* %37, i32* %5)
%58 = icmp slt i32 %57, 0
br i1 %58, label %42, label %44
59: ; preds = %52, %42, %40, %31, %17
ret i32 1
}