#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 /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bind(int, struct sockaddr const *, int);
int /*<<< orphan*/ close(int);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
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 buf[80];
  time_t tick;
  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(9999);
  bind(listenfd, (const struct sockaddr *)&servaddr, sizeof(servaddr));
  listen(listenfd, 10);
  for (;;) {
    connfd = accept(listenfd, (struct sockaddr *)NULL, NULL);
    tick = time(NULL);
    snprintf(buf, sizeof(buf), "%.24s\n", ctime(&tick));
    write(connfd, buf, strlen(buf));
    close(connfd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    $0x270f,%edi
call   1060 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   10c0 <listen@plt>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10e0 <accept@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,-0x84(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x84(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0xa0(%rbp),%rdi
mov    %rax,%rcx
mov    $0x50,%esi
lea    0xd55(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x94(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x94(%rbp),%edi
mov    -0x90(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
jmp    125d <main+0x8d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    0x2e05(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%r12d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x270f,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
mov    %r12d,%edi
mov    $0xa,%esi
call   10c0 <listen@plt>
lea    0xc(%rsp),%r14
lea    0xda3(%rip),%r15
lea    0x20(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <accept@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,0xc(%rsp)
mov    %r14,%rdi
call   1040 <ctime@plt>
mov    %rbx,%rdi
mov    $0x50,%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   10a0 <close@plt>
jmp    1270 <main+0xa0>

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
@INADDR_ANY = global i32 0
@.str = [7 x i8] c"%.24s\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 [80 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 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %15, i32* %16
%17 = load i32, i32* @INADDR_ANY
%18 = call i32 @htonl(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = call i32 @htons(i32 9999)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %21, i32* %22
%23 = load i32, i32* %6
%24 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%25 = call i32 @bind(i32 %23, %struct.sockaddr* %24, i32 12)
%26 = load i32, i32* %6
%27 = call i32 @listen(i32 %26, i32 10)
br label %28
28: ; preds = %28, %2
%29 = load i32, i32* %6
%30 = call i32 @accept(i32 %29, %struct.sockaddr* null, i32* null)
store i32 %30, i32* %7
%31 = call i32 @time(i32* null)
store i32 %31, i32* %10
%32 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%33 = call i8* @ctime(i32* %10)
%34 = call i32 @snprintf(i8* %32, i32 80, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %7
%36 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%37 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%38 = call i32 @strlen(i8* %37)
%39 = call i32 @write(i32 %35, i8* %36, i32 %38)
%40 = load i32, i32* %7
%41 = call i32 @close(i32 %40)
br label %28
}

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
@INADDR_ANY = global i32 0
@.str = [7 x i8] c"%.24s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [80 x i8]
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [80 x i8], [80 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 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = call i32 @htonl(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %16, i32* %17
%18 = call i32 @htons(i32 9999)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%21 = call i32 @bind(i32 %11, %struct.sockaddr* %20, i32 12)
%22 = call i32 @listen(i32 %11, i32 10)
br label %23
23: ; preds = %23, %2
%24 = call i32 @accept(i32 %11, %struct.sockaddr* null, i32* null)
%25 = call i32 @time(i32* null)
store i32 %25, i32* %5
%26 = call i8* @ctime(i32* %5)
%27 = call i32 @snprintf(i8* %7, i32 80, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = call i32 @strlen(i8* %7)
%29 = call i32 @write(i32 %24, i8* %7, i32 %28)
%30 = call i32 @close(i32 %24)
br label %23
}