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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%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    1248 <main+0x58>
lea    0xdcb(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    $0xd,%edi
call   1060 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    12b5 <main+0xc5>
lea    0xd6d(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x80,%esi
call   10b0 <listen@plt>
cmp    $0x0,%rax
jge    12e6 <main+0xf6>
lea    0xd49(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
jmp    12eb <main+0xfb>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10f0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1320 <main+0x130>
lea    0xd1e(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,-0x1034(%rbp)
lea    -0x1030(%rbp),%rax
mov    %rax,-0x1050(%rbp)
lea    -0x1034(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0x1050(%rbp),%rdi
mov    %rax,%rcx
mov    $0x1000,%esi
lea    0xcdb(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1044(%rbp)
lea    -0x1030(%rbp),%rax
mov    %rax,-0x1040(%rbp)
lea    -0x1030(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1044(%rbp),%edi
mov    -0x1040(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
jmp    12eb <main+0xfb>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1020,%rsp
mov    0x2de2(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
test   %eax,%eax
jns    1229 <main+0x39>
lea    0xddc(%rip),%rdi
jmp    132a <main+0x13a>
mov    %eax,%r12d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0xd,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jns    1286 <main+0x96>
lea    0xd8e(%rip),%rdi
jmp    132a <main+0x13a>
mov    %r12d,%edi
mov    $0x80,%esi
call   10b0 <listen@plt>
test   %rax,%rax
jns    12a4 <main+0xb4>
lea    0xd7d(%rip),%rdi
jmp    132a <main+0x13a>
mov    %r12d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10f0 <accept@plt>
test   %eax,%eax
js     1323 <main+0x133>
mov    %eax,%ebp
lea    0xc(%rsp),%r14
lea    0xd78(%rip),%r15
lea    0x20(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,0xc(%rsp)
mov    %r14,%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>
mov    %ebp,%edi
call   1090 <close@plt>
mov    %r12d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10f0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    12d0 <main+0xe0>
lea    0xd01(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c92(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

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

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