#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*/ srvaddr;
typedef int socklen_t;
typedef int /*<<< orphan*/ cliaddr;
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int Accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ Bind(int, struct sockaddr *, int);
int /*<<< orphan*/ Close(int);
int /*<<< orphan*/ INADDR_ANY;
char *Inet_ntop(int /*<<< orphan*/, TYPE_1__ *, char *, int);
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 ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  int listenfd, connfd;
  socklen_t len;
  struct sockaddr_in srvaddr, cliaddr;
  char buff[1024];
  time_t ticks;
  listenfd = Socket(AF_INET, SOCK_STREAM, 0);
  memset(&srvaddr, 0, sizeof(srvaddr));
  srvaddr.sin_family = AF_INET;
  srvaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  srvaddr.sin_port = htons(13);
  Bind(listenfd, (struct sockaddr *)&srvaddr, sizeof(srvaddr));
  Listen(listenfd, 1024);
  for (;;) {
    len = sizeof(cliaddr);
    connfd = Accept(listenfd, (struct sockaddr *)&cliaddr, &len);
    printf("connection from %s, port %d\n",
           Inet_ntop(AF_INET, &cliaddr.sin_addr, buff, sizeof(buff)),
           ntohs(cliaddr.sin_port));
    ticks = time(NULL);
    snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));
    Write(connfd, buff, strlen(buff));
    Close(connfd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <Socket@plt>
mov    %eax,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xd,%edi
call   1060 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1100 <Bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x400,%esi
call   10e0 <Listen@plt>
movl   $0xc,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1030 <Accept@plt>
mov    %eax,-0xc(%rbp)
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
add    $0x4,%rsi
mov    %rsi,-0x460(%rbp)
lea    -0x430(%rbp),%rdx
mov    $0x400,%ecx
call   10c0 <Inet_ntop@plt>
mov    %rax,-0x458(%rbp)
mov    -0x30(%rbp),%edi
call   10f0 <ntohs@plt>
mov    -0x458(%rbp),%rsi
mov    %eax,%edx
lea    0xd18(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <time@plt>
mov    %eax,-0x434(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x450(%rbp)
lea    -0x434(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0x450(%rbp),%rdi
mov    %rax,%rcx
mov    $0x400,%esi
lea    0xcf1(%rip),%rdx
call   1080 <snprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x444(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x440(%rbp)
lea    -0x430(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x444(%rbp),%edi
mov    -0x440(%rbp),%rsi
mov    %eax,%edx
call   10b0 <Write@plt>
mov    -0xc(%rbp),%edi
call   1110 <Close@plt>
jmp    1286 <main+0x86>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    0x2dd0(%rip),%rbx
mov    (%rbx),%edi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <Socket@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0xd,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1100 <Bind@plt>
mov    %ebp,%edi
mov    $0x400,%esi
call   10e0 <Listen@plt>
lea    0x30(%rsp),%rbx
lea    0x8(%rsp),%r14
lea    0xd8b(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movl   $0xc,0xc(%rsp)
mov    %ebp,%edi
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1030 <Accept@plt>
mov    %eax,%r12d
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
lea    0x24(%rsp),%rsi
mov    %rbx,%rdx
mov    $0x400,%ecx
call   10c0 <Inet_ntop@plt>
mov    %rax,%r13
mov    0x20(%rsp),%edi
call   10f0 <ntohs@plt>
lea    0xd16(%rip),%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   1070 <printf@plt>
xor    %edi,%edi
call   10d0 <time@plt>
mov    %eax,0x8(%rsp)
mov    %r14,%rdi
call   1040 <ctime@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   10b0 <Write@plt>
mov    %r12d,%edi
call   1110 <Close@plt>
jmp    12a0 <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 = [29 x i8] c"connection from %s, port %d\0A\00"
@.str.1 = [8 x i8] c"%.24s\0D\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca [1024 x i8]
%8 = alloca i32
store i32 0, i32* %1
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @Socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %2
%12 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 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* %5, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = call i32 @htons(i32 13)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* %2
%22 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%23 = call i32 @Bind(i32 %21, %struct.sockaddr* %22, i32 12)
%24 = load i32, i32* %2
%25 = call i32 @Listen(i32 %24, i32 1024)
br label %26
26: ; preds = %26, %0
store i32 12, i32* %4
%27 = load i32, i32* %2
%28 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%29 = call i32 @Accept(i32 %27, %struct.sockaddr* %28, i32* %4)
store i32 %29, i32* %3
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%33 = call i8* @Inet_ntop(i32 %30, %struct.TYPE_2__* %31, i8* %32, i32 1024)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @ntohs(i32 %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %33, i32 %36)
%38 = call i32 @time(i32* null)
store i32 %38, i32* %8
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%40 = call i8* @ctime(i32* %8)
%41 = call i32 @snprintf(i8* %39, i32 1024, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %40)
%42 = load i32, i32* %3
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%45 = call i32 @strlen(i8* %44)
%46 = call i32 @Write(i32 %42, i8* %43, i32 %45)
%47 = load i32, i32* %3
%48 = call i32 @Close(i32 %47)
br label %26
}

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