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

/* Type definitions */
typedef int /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};
struct sockaddr_storage {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
char *asctime(struct tm *);
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int listen_socket(int);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  struct sockaddr_storage addr;
  socklen_t addrlen = sizeof addr;
  int sock, server;
  time_t t;
  struct tm *tm;
  char *timestr;
  server = listen_socket(argc > 1 ? atoi(argv[1]) : 13);
  sock = accept(server, (struct sockaddr *)&addr, &addrlen);
  if (sock < 0) {
    perror("accept(2)");
    exit(1);
  }
  time(&t);
  tm = localtime(&t);
  timestr = asctime(tm);
  write(sock, timestr, strlen(timestr));
  close(sock);
  close(server);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11ec <main+0x3c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x3c(%rbp)
jmp    11f9 <main+0x49>
mov    $0xd,%eax
mov    %eax,-0x3c(%rbp)
jmp    11f9 <main+0x49>
mov    -0x3c(%rbp),%edi
call   1080 <listen_socket@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1237 <main+0x87>
lea    0xdd8(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x28(%rbp),%rdi
call   1090 <time@plt>
lea    -0x28(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <asctime@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x20(%rbp),%edi
call   1070 <close@plt>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%eax
movl   $0x4,0xc(%rsp)
mov    $0xd,%edi
cmp    $0x2,%eax
jl     11d9 <main+0x29>
mov    0x8(%rsi),%rdi
call   10c0 <atoi@plt>
mov    %eax,%edi
call   1080 <listen_socket@plt>
mov    %eax,%r15d
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %eax,%edi
call   10b0 <accept@plt>
test   %eax,%eax
jns    120c <main+0x5c>
lea    0xe03(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    %eax,%ebp
lea    0x14(%rsp),%r14
mov    %r14,%rdi
call   1090 <time@plt>
mov    %r14,%rdi
call   1030 <localtime@plt>
mov    %rax,%rdi
call   1060 <asctime@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r15d,%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.tm = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"accept(2)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_storage
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.tm*
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %7
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
br label %21
20: ; preds = %2
br label %21
21: ; preds = %20, %15
%22 = phi i32 [ %19, %15 ], [ 13, %20 ]
%23 = call i32 @listen_socket(i32 %22)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
%26 = call i32 @accept(i32 %24, %struct.sockaddr* %25, i32* %7)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %21
%33 = call i32 @time(i32* %10)
%34 = call %struct.tm* @localtime(i32* %10)
store %struct.tm* %34, %struct.tm** %11
%35 = load %struct.tm*, %struct.tm** %11
%36 = call i8* @asctime(%struct.tm* %35)
store i8* %36, i8** %12
%37 = load i32, i32* %8
%38 = load i8*, i8** %12
%39 = load i8*, i8** %12
%40 = call i32 @strlen(i8* %39)
%41 = call i32 @write(i32 %37, i8* %38, i32 %40)
%42 = load i32, i32* %8
%43 = call i32 @close(i32 %42)
%44 = load i32, i32* %9
%45 = call i32 @close(i32 %44)
%46 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
%struct.tm = type { i32 }
@.str = [10 x i8] c"accept(2)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_storage
%4 = alloca i32
%5 = alloca i32
%6 = bitcast %struct.sockaddr_storage* %3 to i8*
%7 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%8 = bitcast i32* %5 to i8*
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
br label %14
14: ; preds = %2, %10
%15 = phi i32 [ %13, %10 ], [ 13, %2 ]
%16 = tail call i32 @listen_socket(i32 %15)
%17 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%18 = call i32 @accept(i32 %16, %struct.sockaddr* %17, i32* %4)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = call i32 @time(i32* %5)
%25 = call %struct.tm* @localtime(i32* %5)
%26 = call i8* @asctime(%struct.tm* %25)
%27 = call i32 @strlen(i8* %26)
%28 = call i32 @write(i32 %18, i8* %26, i32 %27)
%29 = call i32 @close(i32 %18)
%30 = call i32 @close(i32 %16)
%31 = call i32 @exit(i32 0)
unreachable
}