#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;
typedef int /*<<< orphan*/ time_buf;
struct sockaddr_storage {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ ss;
typedef int socklen_t;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int LOG_DAEMON;
int LOG_INFO;
int /*<<< orphan*/ close(int /*<<< orphan*/);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ daemon_inetd(char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ getpeername(int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ print_connection_info(struct sockaddr_storage *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ strerror(scalar_t__);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ syslog(int, char *, ...);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
scalar_t__ write(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  time_t ticks;
  ssize_t n;
  socklen_t len;
  struct sockaddr_storage ss;
  char time_buf[256] = {'\0'};
  if (1 != argc) {
    syslog(LOG_INFO | LOG_DAEMON, "USAGE : %s\n", argv[0]);
  }
  daemon_inetd(argv[0], 0);
  len = sizeof(ss);
  if (getpeername(0, (struct sockaddr *)&ss, &len)) {
    syslog(LOG_INFO | LOG_DAEMON, "getpeername : %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  print_connection_info(&ss);
  ticks = time(NULL);
  snprintf(time_buf, sizeof(time_buf), "%.24s\r\n", ctime(&ticks));
  syslog(LOG_INFO | LOG_DAEMON, "time is %s\n", time_buf);
  n = write(0, time_buf, strlen(time_buf));
  if (n < 0 && EINTR == errno) {
    syslog(LOG_INFO | LOG_DAEMON, "write");
    exit(EXIT_FAILURE);
  }
  close(0);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
mov    $0x1,%eax
cmp    -0x8(%rbp),%eax
je     1231 <main+0x61>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    0x2dce(%rip),%rax
or     (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdd6(%rip),%rsi
mov    $0x0,%al
call   10b0 <syslog@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
xor    %esi,%esi
call   10d0 <daemon_inetd@plt>
movl   $0x4,-0x24(%rbp)
lea    -0x28(%rbp),%rsi
xor    %edi,%edi
lea    -0x24(%rbp),%rdx
call   1040 <getpeername@plt>
cmp    $0x0,%rax
je     12aa <main+0xda>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
mov    0x2d79(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x134(%rbp)
mov    0x2d5a(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x134(%rbp),%edi
mov    %eax,%edx
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   10b0 <syslog@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0x28(%rbp),%rdi
call   10c0 <print_connection_info@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x148(%rbp)
lea    -0x14(%rbp),%rdi
call   1050 <ctime@plt>
mov    -0x148(%rbp),%rdi
mov    %rax,%rcx
mov    $0x100,%esi
lea    0xd32(%rip),%rdx
call   1070 <snprintf@plt>
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
mov    0x2ce7(%rip),%rax
or     (%rax),%edi
lea    -0x130(%rbp),%rdx
lea    0xd15(%rip),%rsi
mov    $0x0,%al
call   10b0 <syslog@plt>
lea    -0x130(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    -0x130(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x140(%rbp),%rsi
mov    %eax,%edx
xor    %edi,%edi
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1399 <main+0x1c9>
mov    0x2c70(%rip),%rax
mov    (%rax),%rax
mov    0x2c76(%rip),%rcx
cmp    (%rcx),%rax
jne    1399 <main+0x1c9>
mov    0x2c46(%rip),%rax
mov    (%rax),%edi
mov    0x2c6d(%rip),%rax
or     (%rax),%edi
lea    0xcae(%rip),%rsi
mov    $0x0,%al
call   10b0 <syslog@plt>
mov    0x2c3e(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
xor    %edi,%edi
call   1090 <close@plt>
mov    0x2c19(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %rsi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
cmp    $0x1,%edi
je     1265 <main+0xa5>
mov    0x2d6f(%rip),%rax
mov    0x2d98(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
mov    (%rbx),%rdx
lea    0xda2(%rip),%rsi
xor    %eax,%eax
call   10a0 <syslog@plt>
mov    (%rbx),%rdi
xor    %esi,%esi
call   10c0 <daemon_inetd@plt>
movl   $0x4,0x8(%rsp)
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1040 <getpeername@plt>
test   %rax,%rax
jne    1332 <main+0x172>
mov    %rsp,%rdi
call   10b0 <print_connection_info@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1050 <ctime@plt>
lea    0xd6b(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rax,%rcx
call   1070 <snprintf@plt>
mov    0x2ce9(%rip),%r14
mov    0x2d12(%rip),%r15
mov    (%r15),%edi
or     (%r14),%edi
lea    0xd43(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10a0 <syslog@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
jns    1373 <main+0x1b3>
mov    0x2cbb(%rip),%rax
mov    (%rax),%rax
mov    0x2cc1(%rip),%rcx
cmp    (%rcx),%rax
jne    1373 <main+0x1b3>
mov    (%r15),%edi
or     (%r14),%edi
lea    0xd09(%rip),%rsi
xor    %eax,%eax
call   10a0 <syslog@plt>
jmp    1365 <main+0x1a5>
mov    0x2c7f(%rip),%rax
mov    0x2ca8(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2c8d(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
lea    0xcb2(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <syslog@plt>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
xor    %edi,%edi
call   1080 <close@plt>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@LOG_INFO = global i32 0
@LOG_DAEMON = global i32 0
@.str = [12 x i8] c"USAGE : %s\0A\00"
@.str.1 = [18 x i8] c"getpeername : %s\0A\00"
@errno = global i64 0
@EXIT_FAILURE = global i32 0
@.str.2 = [8 x i8] c"%.24s\0D\0A\00"
@.str.3 = [12 x i8] c"time is %s\0A\00"
@EINTR = global i64 0
@.str.4 = [6 x i8] c"write\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca %struct.sockaddr_storage
%10 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [256 x i8]* %10 to i8*
%12 = load i32, i32* %4
%13 = icmp ne i32 1, %12
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32, i32* @LOG_INFO
%16 = load i32, i32* @LOG_DAEMON
%17 = or i32 %15, %16
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @syslog(i32 %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %14, %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @daemon_inetd(i8* %25, i32 0)
store i32 4, i32* %8
%27 = bitcast %struct.sockaddr_storage* %9 to %struct.sockaddr*
%28 = call i64 @getpeername(i32 0, %struct.sockaddr* %27, i32* %8)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %22
%31 = load i32, i32* @LOG_INFO
%32 = load i32, i32* @LOG_DAEMON
%33 = or i32 %31, %32
%34 = load i64, i64* @errno
%35 = call i32 @strerror(i64 %34)
%36 = call i32 (i32, i8*, ...) @syslog(i32 %33, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %22
%40 = call i32 @print_connection_info(%struct.sockaddr_storage* %9)
%41 = call i32 @time(i32* null)
store i32 %41, i32* %6
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%43 = call i8* @ctime(i32* %6)
%44 = call i32 @snprintf(i8* %42, i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %43)
%45 = load i32, i32* @LOG_INFO
%46 = load i32, i32* @LOG_DAEMON
%47 = or i32 %45, %46
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%49 = call i32 (i32, i8*, ...) @syslog(i32 %47, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %48)
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%52 = call i32 @strlen(i8* %51)
%53 = call i64 @write(i32 0, i8* %50, i32 %52)
store i64 %53, i64* %7
%54 = load i64, i64* %7
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %67
56: ; preds = %39
%57 = load i64, i64* @EINTR
%58 = load i64, i64* @errno
%59 = icmp eq i64 %57, %58
br i1 %59, label %60, label %67
60: ; preds = %56
%61 = load i32, i32* @LOG_INFO
%62 = load i32, i32* @LOG_DAEMON
%63 = or i32 %61, %62
%64 = call i32 (i32, i8*, ...) @syslog(i32 %63, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %56, %39
%68 = call i32 @close(i32 0)
%69 = load i32, i32* @EXIT_SUCCESS
%70 = call i32 @exit(i32 %69)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@LOG_INFO = global i32 0
@LOG_DAEMON = global i32 0
@.str = [12 x i8] c"USAGE : %s\0A\00"
@.str.1 = [18 x i8] c"getpeername : %s\0A\00"
@errno = global i64 0
@EXIT_FAILURE = global i32 0
@.str.2 = [8 x i8] c"%.24s\0D\0A\00"
@.str.3 = [12 x i8] c"time is %s\0A\00"
@EINTR = global i64 0
@.str.4 = [6 x i8] c"write\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_storage
%6 = alloca [256 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast %struct.sockaddr_storage* %5 to i8*
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = icmp eq i32 %0, 1
br i1 %11, label %18, label %12
12: ; preds = %2
%13 = load i32, i32* @LOG_INFO
%14 = load i32, i32* @LOG_DAEMON
%15 = or i32 %14, %13
%16 = load i8*, i8** %1
%17 = tail call i32 (i32, i8*, ...) @syslog(i32 %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %12, %2
%19 = load i8*, i8** %1
%20 = tail call i32 @daemon_inetd(i8* %19, i32 0)
store i32 4, i32* %4
%21 = bitcast %struct.sockaddr_storage* %5 to %struct.sockaddr*
%22 = call i64 @getpeername(i32 0, %struct.sockaddr* %21, i32* %4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %18
%25 = load i32, i32* @LOG_INFO
%26 = load i32, i32* @LOG_DAEMON
%27 = or i32 %26, %25
%28 = load i64, i64* @errno
%29 = call i32 @strerror(i64 %28)
%30 = call i32 (i32, i8*, ...) @syslog(i32 %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %18
%34 = call i32 @print_connection_info(%struct.sockaddr_storage* %5)
%35 = call i32 @time(i32* null)
store i32 %35, i32* %3
%36 = call i8* @ctime(i32* %3)
%37 = call i32 @snprintf(i8* %10, i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = load i32, i32* @LOG_INFO
%39 = load i32, i32* @LOG_DAEMON
%40 = or i32 %39, %38
%41 = call i32 (i32, i8*, ...) @syslog(i32 %40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%42 = call i32 @strlen(i8* %10)
%43 = call i64 @write(i32 0, i8* %10, i32 %42)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %56
45: ; preds = %33
%46 = load i64, i64* @EINTR
%47 = load i64, i64* @errno
%48 = icmp eq i64 %46, %47
br i1 %48, label %49, label %56
49: ; preds = %45
%50 = load i32, i32* @LOG_INFO
%51 = load i32, i32* @LOG_DAEMON
%52 = or i32 %51, %50
%53 = call i32 (i32, i8*, ...) @syslog(i32 %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %45, %33
%57 = call i32 @close(i32 0)
%58 = load i32, i32* @EXIT_SUCCESS
%59 = call i32 @exit(i32 %58)
unreachable
}