#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_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int sa_family;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ ip;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
scalar_t__ EINTR;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int LOG_DAEMON;
int LOG_INFO;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ daemon_init(char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ inet_ntop(int const, int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ syslog(int, char *, ...);
int tcp_listen(char *, char *, int *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int listenfd, connfd, n;
  socklen_t len, addrlen;
  char ip[256] = {'\0'};
  char time_buf[256] = {'\0'};
  time_t ticks;
  struct sockaddr_storage cliaddr;
  struct sockaddr *sa;
  struct sockaddr_in *sin4;
  struct sockaddr_in6 *sin6;
  if (argc < 2 || argc > 3) {
    printf("USAGE: %s [host] <service/port>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  daemon_init(argv[0], 0);
  if (2 == argc) {
    listenfd = tcp_listen(NULL, argv[1], &addrlen);
  } else if (3 == argc) {
    listenfd = tcp_listen(argv[1], argv[2], &addrlen);
  }
  while (1) {
    len = sizeof(cliaddr);
    connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &len);
    if (connfd < 0) {
      if (EINTR == errno) {
        continue;
      }
      syslog(LOG_INFO | LOG_DAEMON, "accept");
      exit(EXIT_FAILURE);
    }
    sa = (struct sockaddr *)&cliaddr;
    switch (sa->sa_family) {
    case AF_INET:
      sin4 = (struct sockaddr_in *)&cliaddr;
      syslog(LOG_INFO | LOG_DAEMON, "connection from %s\n",
             inet_ntop(AF_INET, &(sin4->sin_addr), ip, sizeof(ip)));
      break;
    case AF_INET6:
      sin6 = (struct sockaddr_in6 *)&cliaddr;
      syslog(LOG_INFO | LOG_DAEMON, "connection from %s\n",
             inet_ntop(AF_INET6, &(sin6->sin6_addr), ip, sizeof(ip)));
      break;
    default:
      syslog(LOG_INFO | LOG_DAEMON, "unknown type.\n");
      continue;
    }
    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(connfd, time_buf, strlen(time_buf));
    if (n < 0) {
      if (EINTR == errno) {
        continue;
      }
      syslog(LOG_INFO | LOG_DAEMON, "write");
      exit(EXIT_FAILURE);
    }
    close(connfd);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x280,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1090 <memset@plt>
lea    -0x230(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1090 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
jl     1233 <main+0x53>
cmpl   $0x3,-0x8(%rbp)
jle    1254 <main+0x74>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdbf(%rip),%rdi
call   1070 <printf@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
xor    %esi,%esi
call   10b0 <daemon_init@plt>
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jne    128d <main+0xad>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x24(%rbp),%rdx
call   10d0 <tcp_listen@plt>
mov    %eax,-0x14(%rbp)
jmp    12bc <main+0xdc>
mov    $0x3,%eax
cmp    -0x8(%rbp),%eax
jne    12b7 <main+0xd7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x24(%rbp),%rdx
call   10d0 <tcp_listen@plt>
mov    %eax,-0x14(%rbp)
jmp    12bc <main+0xdc>
jmp    12c1 <main+0xe1>
movl   $0x4,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x238(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1335 <main+0x155>
mov    0x2cd9(%rip),%rax
mov    (%rax),%rax
mov    0x2cdf(%rip),%rcx
cmp    (%rcx),%rax
jne    1307 <main+0x127>
jmp    12c1 <main+0xe1>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
mov    0x2cd1(%rip),%rax
or     (%rax),%edi
lea    0xd01(%rip),%rsi
mov    $0x0,%al
call   10e0 <syslog@plt>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    -0x238(%rbp),%rax
mov    %rax,-0x240(%rbp)
mov    -0x240(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x254(%rbp)
sub    $0x80,%eax
je     13d6 <main+0x1f6>
jmp    1362 <main+0x182>
mov    -0x254(%rbp),%eax
sub    $0x81,%eax
jne    1434 <main+0x254>
jmp    1378 <main+0x198>
lea    -0x238(%rbp),%rax
mov    %rax,-0x248(%rbp)
mov    0x2c33(%rip),%rax
mov    (%rax),%eax
mov    0x2c52(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x258(%rbp)
mov    -0x248(%rbp),%rsi
lea    -0x130(%rbp),%rdx
mov    $0x81,%edi
mov    $0x100,%ecx
call   1030 <inet_ntop@plt>
mov    -0x258(%rbp),%edi
mov    %eax,%edx
lea    0xc5e(%rip),%rsi
mov    $0x0,%al
call   10e0 <syslog@plt>
jmp    1459 <main+0x279>
lea    -0x238(%rbp),%rax
mov    %rax,-0x250(%rbp)
mov    0x2bd5(%rip),%rax
mov    (%rax),%eax
mov    0x2bf4(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x25c(%rbp)
mov    -0x250(%rbp),%rsi
lea    -0x130(%rbp),%rdx
mov    $0x80,%edi
mov    $0x100,%ecx
call   1030 <inet_ntop@plt>
mov    -0x25c(%rbp),%edi
mov    %eax,%edx
lea    0xc00(%rip),%rsi
mov    $0x0,%al
call   10e0 <syslog@plt>
jmp    1459 <main+0x279>
mov    0x2b85(%rip),%rax
mov    (%rax),%edi
mov    0x2ba4(%rip),%rax
or     (%rax),%edi
lea    0xbef(%rip),%rsi
mov    $0x0,%al
call   10e0 <syslog@plt>
jmp    12c1 <main+0xe1>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x234(%rbp)
lea    -0x230(%rbp),%rax
mov    %rax,-0x278(%rbp)
lea    -0x234(%rbp),%rdi
call   1050 <ctime@plt>
mov    -0x278(%rbp),%rdi
mov    %rax,%rcx
mov    $0x100,%esi
lea    0xbb3(%rip),%rdx
call   1080 <snprintf@plt>
mov    0x2b1c(%rip),%rax
mov    (%rax),%edi
mov    0x2b3b(%rip),%rax
or     (%rax),%edi
lea    -0x230(%rbp),%rdx
lea    0xb96(%rip),%rsi
mov    $0x0,%al
call   10e0 <syslog@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x26c(%rbp)
lea    -0x230(%rbp),%rax
mov    %rax,-0x268(%rbp)
lea    -0x230(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x26c(%rbp),%edi
mov    -0x268(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1555 <main+0x375>
mov    0x2ab9(%rip),%rax
mov    (%rax),%rax
mov    0x2abf(%rip),%rcx
cmp    (%rcx),%rax
jne    1527 <main+0x347>
jmp    12c1 <main+0xe1>
mov    0x2a92(%rip),%rax
mov    (%rax),%edi
mov    0x2ab1(%rip),%rax
or     (%rax),%edi
lea    0xb1f(%rip),%rsi
mov    $0x0,%al
call   10e0 <syslog@plt>
mov    0x2a82(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
jmp    12c1 <main+0xe1>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0x210(%rsp)
movaps %xmm0,0x200(%rsp)
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
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)
lea    -0x4(%rbp),%eax
mov    (%rsi),%rsi
cmp    $0xfffffffd,%eax
ja     12f3 <main+0x123>
lea    0xd17(%rip),%rdi
call   1070 <printf@plt>
jmp    14bf <main+0x2ef>
mov    %rsi,%rdi
xor    %esi,%esi
call   10a0 <daemon_init@plt>
mov    0x8(%rbx),%rax
cmp    $0x2,%ebp
jne    1312 <main+0x142>
lea    0x1c(%rsp),%rdx
xor    %edi,%edi
mov    %rax,%rsi
jmp    131e <main+0x14e>
mov    0x10(%rbx),%rsi
lea    0x1c(%rsp),%rdx
mov    %rax,%rdi
call   10c0 <tcp_listen@plt>
mov    %eax,%ebx
lea    0xc(%rsp),%rbp
lea    0x20(%rsp),%r13
jmp    135a <main+0x18a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2c81(%rip),%rax
mov    (%rax),%rax
mov    0x2c87(%rip),%rcx
cmp    (%rcx),%rax
jne    149f <main+0x2cf>
movl   $0x4,0xc(%rsp)
mov    %ebx,%edi
lea    0x10(%rsp),%rsi
mov    %rbp,%rdx
call   10e0 <accept@plt>
test   %eax,%eax
js     1340 <main+0x170>
mov    %eax,%r12d
mov    0x10(%rsp),%edi
cmp    $0x81,%edi
je     1395 <main+0x1c5>
cmp    $0x80,%edi
jne    1440 <main+0x270>
mov    $0x80,%edi
mov    0x2c4c(%rip),%r14
mov    (%r14),%ebp
mov    0x2c1a(%rip),%r15
or     (%r15),%ebp
lea    0x10(%rsp),%rsi
lea    0x120(%rsp),%rdx
mov    $0x100,%ecx
call   1030 <inet_ntop@plt>
mov    %ebp,%edi
lea    0xc5f(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10d0 <syslog@plt>
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,0x18(%rsp)
lea    0x18(%rsp),%rdi
call   1050 <ctime@plt>
mov    %r13,%rdi
mov    $0x100,%esi
lea    0xc55(%rip),%rdx
mov    %rax,%rcx
call   1080 <snprintf@plt>
mov    (%r14),%edi
or     (%r15),%edi
lea    0xc48(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   10d0 <syslog@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
js     1465 <main+0x295>
mov    %r12d,%edi
call   1090 <close@plt>
lea    0xc(%rsp),%rbp
jmp    135a <main+0x18a>
mov    0x2ba1(%rip),%rax
mov    (%rax),%edi
mov    0x2b70(%rip),%rax
or     (%rax),%edi
lea    0xbe3(%rip),%rsi
xor    %eax,%eax
call   10d0 <syslog@plt>
jmp    135a <main+0x18a>
mov    0x2b5c(%rip),%rax
mov    (%rax),%rax
mov    0x2b62(%rip),%rcx
cmp    (%rcx),%rax
lea    0xc(%rsp),%rbp
je     135a <main+0x18a>
mov    0x2b5d(%rip),%rax
mov    (%rax),%edi
mov    0x2b2c(%rip),%rax
or     (%rax),%edi
lea    0xbc2(%rip),%rsi
jmp    14b8 <main+0x2e8>
mov    0x2b42(%rip),%rax
mov    (%rax),%edi
mov    0x2b11(%rip),%rax
or     (%rax),%edi
lea    0xb69(%rip),%rsi
xor    %eax,%eax
call   10d0 <syslog@plt>
mov    0x2b0a(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@.str = [33 x i8] c"USAGE: %s [host] <service/port>\0A\00"
@EXIT_FAILURE = global i32 0
@EINTR = global i64 0
@errno = global i64 0
@LOG_INFO = global i32 0
@LOG_DAEMON = global i32 0
@.str.1 = [7 x i8] c"accept\00"
@.str.2 = [20 x i8] c"connection from %s\0A\00"
@.str.3 = [15 x i8] c"unknown type.\0A\00"
@.str.4 = [8 x i8] c"%.24s\0D\0A\00"
@.str.5 = [12 x i8] c"time is %s\0A\00"
@.str.6 = [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 i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [256 x i8]
%12 = alloca [256 x i8]
%13 = alloca i32
%14 = alloca %struct.sockaddr_storage
%15 = alloca %struct.sockaddr*
%16 = alloca %struct.sockaddr_in*
%17 = alloca %struct.sockaddr_in6*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = bitcast [256 x i8]* %11 to i8*
%19 = bitcast [256 x i8]* %12 to i8*
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 2
br i1 %21, label %25, label %22
22: ; preds = %2
%23 = load i32, i32* %4
%24 = icmp sgt i32 %23, 3
br i1 %24, label %25, label %32
25: ; preds = %22, %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %22
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @daemon_init(i8* %35, i32 0)
%37 = load i32, i32* %4
%38 = icmp eq i32 2, %37
br i1 %38, label %39, label %44
39: ; preds = %32
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @tcp_listen(i8* null, i8* %42, i32* %10)
store i32 %43, i32* %6
br label %56
44: ; preds = %32
%45 = load i32, i32* %4
%46 = icmp eq i32 3, %45
br i1 %46, label %47, label %55
47: ; preds = %44
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %52
%54 = call i32 @tcp_listen(i8* %50, i8* %53, i32* %10)
store i32 %54, i32* %6
br label %55
55: ; preds = %47, %44
br label %56
56: ; preds = %55, %39
br label %57
57: ; preds = %56, %67, %100, %126, %134
store i32 4, i32* %9
%58 = load i32, i32* %6
%59 = bitcast %struct.sockaddr_storage* %14 to %struct.sockaddr*
%60 = call i32 @accept(i32 %58, %struct.sockaddr* %59, i32* %9)
store i32 %60, i32* %7
%61 = load i32, i32* %7
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %75
63: ; preds = %57
%64 = load i64, i64* @EINTR
%65 = load i64, i64* @errno
%66 = icmp eq i64 %64, %65
br i1 %66, label %67, label %68
67: ; preds = %63
br label %57
68: ; preds = %63
%69 = load i32, i32* @LOG_INFO
%70 = load i32, i32* @LOG_DAEMON
%71 = or i32 %69, %70
%72 = call i32 (i32, i8*, ...) @syslog(i32 %71, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %57
%76 = bitcast %struct.sockaddr_storage* %14 to %struct.sockaddr*
store %struct.sockaddr* %76, %struct.sockaddr** %15
%77 = load %struct.sockaddr*, %struct.sockaddr** %15
%78 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %77, i32 0, i32 0
%79 = load i32, i32* %78
switch i32 %79, label %100 [
i32 129, label %80
i32 128, label %90
]
80: ; preds = %75
%81 = bitcast %struct.sockaddr_storage* %14 to %struct.sockaddr_in*
store %struct.sockaddr_in* %81, %struct.sockaddr_in** %16
%82 = load i32, i32* @LOG_INFO
%83 = load i32, i32* @LOG_DAEMON
%84 = or i32 %82, %83
%85 = load %struct.sockaddr_in*, %struct.sockaddr_in** %16
%86 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %85, i32 0, i32 0
%87 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%88 = call i32 @inet_ntop(i32 129, i32* %86, i8* %87, i32 256)
%89 = call i32 (i32, i8*, ...) @syslog(i32 %84, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %88)
br label %105
90: ; preds = %75
%91 = bitcast %struct.sockaddr_storage* %14 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %91, %struct.sockaddr_in6** %17
%92 = load i32, i32* @LOG_INFO
%93 = load i32, i32* @LOG_DAEMON
%94 = or i32 %92, %93
%95 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %17
%96 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %95, i32 0, i32 0
%97 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%98 = call i32 @inet_ntop(i32 128, i32* %96, i8* %97, i32 256)
%99 = call i32 (i32, i8*, ...) @syslog(i32 %94, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %98)
br label %105
100: ; preds = %75
%101 = load i32, i32* @LOG_INFO
%102 = load i32, i32* @LOG_DAEMON
%103 = or i32 %101, %102
%104 = call i32 (i32, i8*, ...) @syslog(i32 %103, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %57
105: ; preds = %90, %80
%106 = call i32 @time(i32* null)
store i32 %106, i32* %13
%107 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%108 = call i8* @ctime(i32* %13)
%109 = call i32 @snprintf(i8* %107, i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %108)
%110 = load i32, i32* @LOG_INFO
%111 = load i32, i32* @LOG_DAEMON
%112 = or i32 %110, %111
%113 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%114 = call i32 (i32, i8*, ...) @syslog(i32 %112, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %113)
%115 = load i32, i32* %7
%116 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%117 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%118 = call i32 @strlen(i8* %117)
%119 = call i32 @write(i32 %115, i8* %116, i32 %118)
store i32 %119, i32* %8
%120 = load i32, i32* %8
%121 = icmp slt i32 %120, 0
br i1 %121, label %122, label %134
122: ; preds = %105
%123 = load i64, i64* @EINTR
%124 = load i64, i64* @errno
%125 = icmp eq i64 %123, %124
br i1 %125, label %126, label %127
126: ; preds = %122
br label %57
127: ; preds = %122
%128 = load i32, i32* @LOG_INFO
%129 = load i32, i32* @LOG_DAEMON
%130 = or i32 %128, %129
%131 = call i32 (i32, i8*, ...) @syslog(i32 %130, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%132 = load i32, i32* @EXIT_FAILURE
%133 = call i32 @exit(i32 %132)
unreachable
134: ; preds = %105
%135 = load i32, i32* %7
%136 = call i32 @close(i32 %135)
br label %57
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [33 x i8] c"USAGE: %s [host] <service/port>\0A\00"
@EXIT_FAILURE = global i32 0
@EINTR = global i64 0
@errno = global i64 0
@LOG_INFO = global i32 0
@LOG_DAEMON = global i32 0
@.str.1 = [7 x i8] c"accept\00"
@.str.2 = [20 x i8] c"connection from %s\0A\00"
@.str.3 = [15 x i8] c"unknown type.\0A\00"
@.str.4 = [8 x i8] c"%.24s\0D\0A\00"
@.str.5 = [12 x i8] c"time is %s\0A\00"
@.str.6 = [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 [256 x i8]
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca %struct.sockaddr_storage
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%13 = bitcast i32* %7 to i8*
%14 = bitcast %struct.sockaddr_storage* %8 to i8*
%15 = add i32 %0, -4
%16 = icmp ult i32 %15, -2
%17 = load i8*, i8** %1
br i1 %16, label %18, label %22
18: ; preds = %2
%19 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %17)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = tail call i32 @daemon_init(i8* %17, i32 0)
%24 = icmp eq i32 %0, 2
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
br i1 %24, label %27, label %29
27: ; preds = %22
%28 = call i32 @tcp_listen(i8* null, i8* %26, i32* %4)
br label %33
29: ; preds = %22
%30 = getelementptr inbounds i8*, i8** %1, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @tcp_listen(i8* %26, i8* %31, i32* %4)
br label %33
33: ; preds = %29, %27
%34 = phi i32 [ %28, %27 ], [ %32, %29 ]
%35 = bitcast %struct.sockaddr_storage* %8 to %struct.sockaddr*
%36 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %8, i64 0, i32 0
br label %37
37: ; preds = %59, %33
store i32 4, i32* %3
%38 = call i32 @accept(i32 %34, %struct.sockaddr* %35, i32* %3)
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %51
40: ; preds = %37
%41 = load i64, i64* @EINTR
%42 = load i64, i64* @errno
%43 = icmp eq i64 %41, %42
br i1 %43, label %59, label %44
44: ; preds = %40
%45 = load i32, i32* @LOG_INFO
%46 = load i32, i32* @LOG_DAEMON
%47 = or i32 %46, %45
%48 = call i32 (i32, i8*, ...) @syslog(i32 %47, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %37
%52 = load i32, i32* %36
switch i32 %52, label %54 [
i32 129, label %60
i32 128, label %53
]
53: ; preds = %51
br label %60
54: ; preds = %51
%55 = load i32, i32* @LOG_INFO
%56 = load i32, i32* @LOG_DAEMON
%57 = or i32 %56, %55
%58 = call i32 (i32, i8*, ...) @syslog(i32 %57, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %59
59: ; preds = %54, %88, %40, %77
br label %37
60: ; preds = %51, %53
%61 = phi i32 [ 128, %53 ], [ %52, %51 ]
%62 = load i32, i32* @LOG_INFO
%63 = load i32, i32* @LOG_DAEMON
%64 = or i32 %63, %62
%65 = call i32 @inet_ntop(i32 %61, i32* %36, i8* %11, i32 256)
%66 = call i32 (i32, i8*, ...) @syslog(i32 %64, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %65)
%67 = call i32 @time(i32* null)
store i32 %67, i32* %7
%68 = call i8* @ctime(i32* %7)
%69 = call i32 @snprintf(i8* %12, i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %68)
%70 = load i32, i32* @LOG_INFO
%71 = load i32, i32* @LOG_DAEMON
%72 = or i32 %71, %70
%73 = call i32 (i32, i8*, ...) @syslog(i32 %72, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %12)
%74 = call i32 @strlen(i8* %12)
%75 = call i32 @write(i32 %38, i8* %12, i32 %74)
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %88
77: ; preds = %60
%78 = load i64, i64* @EINTR
%79 = load i64, i64* @errno
%80 = icmp eq i64 %78, %79
br i1 %80, label %59, label %81
81: ; preds = %77
%82 = load i32, i32* @LOG_INFO
%83 = load i32, i32* @LOG_DAEMON
%84 = or i32 %83, %82
%85 = call i32 (i32, i8*, ...) @syslog(i32 %84, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%86 = load i32, i32* @EXIT_FAILURE
%87 = call i32 @exit(i32 %86)
unreachable
88: ; preds = %60
%89 = call i32 @close(i32 %38)
br label %59
}