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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int Accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int BUFSIZ;
int /*<<< orphan*/ Bind(int, struct sockaddr *, int);
int /*<<< orphan*/ Close(int);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ Listen(int, int);
int /*<<< orphan*/ SOCK_STREAM;
int Socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ Write(int, char *, int /*<<< orphan*/);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  int listenfd, connfd;
  struct sockaddr_in servaddr;
  char buf[BUFSIZ];
  time_t ticks;
  listenfd = Socket(AF_INET, SOCK_STREAM, 0);
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servaddr.sin_port = htons(13);
  Bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  Listen(listenfd, 1024);
  for (;;) {
    connfd = Accept(listenfd, NULL, NULL);
    ticks = time(NULL);
    snprintf(buf, sizeof(buf), "%.24s\r\n", ctime(&ticks));
    Write(connfd, buf, strlen(buf));
    Close(connfd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <Socket@plt>
mov    %eax,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x14(%rbp)
mov    $0xd,%edi
call   1060 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <Bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x400,%esi
call   10c0 <Listen@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1030 <Accept@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,-0x2c(%rbp)
mov    %eax,-0x48(%rbp)
lea    -0x2c(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0x48(%rbp),%esi
mov    -0x38(%rbp),%rdi
mov    %rax,%rcx
lea    0xd3c(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
call   1050 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   10a0 <Write@plt>
mov    -0xc(%rbp),%edi
call   10e0 <Close@plt>
jmp    1283 <main+0xb3>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2de0(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2de2(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <Socket@plt>
mov    %eax,%r15d
lea    -0x38(%rbp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x0(%r13),%eax
mov    %eax,-0x30(%rbp)
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x34(%rbp)
mov    $0xd,%edi
call   1060 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   10d0 <Bind@plt>
mov    %r15d,%edi
mov    $0x400,%esi
call   10c0 <Listen@plt>
lea    0xd87(%rip),%r13
nopl   0x0(%rax)
mov    %r15d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <Accept@plt>
mov    %eax,%r12d
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x2c(%rbp),%rdi
call   1040 <ctime@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r13,%rdx
mov    %rax,%rcx
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   10a0 <Write@plt>
mov    %r12d,%edi
call   10e0 <Close@plt>
jmp    1280 <main+0xb0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str = [8 x i8] c"%.24s\0D\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %1
%8 = load i32, i32* @BUFSIZ
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
%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 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %16, i32* %17
%18 = load i32, i32* @INADDR_ANY
%19 = call i32 @htonl(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = call i32 @htons(i32 13)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %22, i32* %23
%24 = load i32, i32* %2
%25 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%26 = call i32 @Bind(i32 %24, %struct.sockaddr* %25, i32 12)
%27 = load i32, i32* %2
%28 = call i32 @Listen(i32 %27, i32 1024)
br label %29
29: ; preds = %29, %0
%30 = load i32, i32* %2
%31 = call i32 @Accept(i32 %30, i32* null, i32* null)
store i32 %31, i32* %3
%32 = call i32 @time(i32* null)
store i32 %32, i32* %7
%33 = trunc i64 %9 to i32
%34 = call i8* @ctime(i32* %7)
%35 = call i32 @snprintf(i8* %11, i32 %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %34)
%36 = load i32, i32* %3
%37 = call i32 @strlen(i8* %11)
%38 = call i32 @Write(i32 %36, i8* %11, i32 %37)
%39 = load i32, i32* %3
%40 = call i32 @Close(i32 %39)
br label %29
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str = [8 x i8] c"%.24s\0D\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast i32* %2 to i8*
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = tail call i32 @Socket(i32 %8, i32 %9, i32 0)
%11 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %12, i32* %13
%14 = load i32, i32* @INADDR_ANY
%15 = call i32 @htonl(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %15, i32* %16
%17 = call i32 @htons(i32 13)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %17, i32* %18
%19 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%20 = call i32 @Bind(i32 %10, %struct.sockaddr* %19, i32 12)
%21 = call i32 @Listen(i32 %10, i32 1024)
br label %22
22: ; preds = %22, %0
%23 = call i32 @Accept(i32 %10, i32* null, i32* null)
%24 = call i32 @time(i32* null)
store i32 %24, i32* %2
%25 = call i8* @ctime(i32* %2)
%26 = call i32 @snprintf(i8* %6, i32 %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = call i32 @strlen(i8* %6)
%28 = call i32 @Write(i32 %23, i8* %6, i32 %27)
%29 = call i32 @Close(i32 %23)
br label %22
}