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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *strerror(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 = socket(AF_INET, SOCK_STREAM, 0);
  if (-1 == listenfd) {
    printf("socket error: %s", strerror(errno));
    exit(0);
  }
  int reuse = 1;
  if (0 >
      (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)))) {
    printf("setsockopt error: %s\n", strerror(errno));
  }
  struct sockaddr_in servaddr;
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servaddr.sin_port = htons((13));
  if (-1 == bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr))) {
    perror("bind error");
    close(listenfd);
    exit(0);
  }
  if (-1 == listen(listenfd, (5))) {
    perror("listen error");
    close(listenfd);
    exit(0);
  }
  int connfd;
  time_t ticks;
  char buff[(50)];
  for (;;) {
    connfd = accept(listenfd, (struct sockaddr *)NULL, NULL);
    if (-1 == connfd) {
      perror("accept error");
      exit(0);
    }
    ticks = time(NULL);
    snprintf(buff, sizeof(buff), "%s", ctime(&ticks));
    write(connfd, buff, strlen(buff));
    close(connfd);
  }
  close(listenfd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
mov    0x2d7f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    1287 <main+0x67>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xd85(%rip),%rdi
call   1080 <printf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d50(%rip),%rax
mov    (%rax),%esi
mov    0x2d17(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    12dd <main+0xbd>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xd39(%rip),%rdi
call   1080 <printf@plt>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    0x2cee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    $0xd,%edi
call   1070 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1350 <main+0x130>
lea    0xceb(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1387 <main+0x167>
lea    0xcbf(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
xor    %edi,%edi
call   1120 <exit@plt>
jmp    138c <main+0x16c>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1110 <accept@plt>
mov    %eax,-0x2c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x2c(%rbp),%eax
jne    13bf <main+0x19f>
lea    0xc8c(%rip),%rdi
call   10f0 <perror@plt>
xor    %edi,%edi
call   1120 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x30(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <ctime@plt>
mov    -0x88(%rbp),%rdi
mov    %rax,%rcx
mov    $0x32,%esi
lea    0xc19(%rip),%rdx
call   1090 <snprintf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x7c(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x2c(%rbp),%edi
call   10b0 <close@plt>
jmp    138c <main+0x16c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    0x2dad(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
cmp    $0xffffffff,%eax
jne    126f <main+0x4f>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xda0(%rip),%rdi
mov    %rax,%rsi
call   1080 <printf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    %eax,%r14d
movl   $0x1,0xc(%rsp)
mov    0x2d67(%rip),%rax
mov    (%rax),%esi
mov    0x2d2e(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jns    12c1 <main+0xa1>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xd58(%rip),%rdi
mov    %rax,%rsi
call   1080 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0xd,%edi
call   1070 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1318 <main+0xf8>
lea    0xd11(%rip),%rdi
jmp    1331 <main+0x111>
mov    %r14d,%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1345 <main+0x125>
lea    0xd01(%rip),%rdi
call   10f0 <perror@plt>
mov    %r14d,%edi
call   10b0 <close@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1110 <accept@plt>
cmp    $0xffffffff,%eax
je     13c4 <main+0x1a4>
mov    %eax,%ebp
lea    0x8(%rsp),%r15
lea    0xcaa(%rip),%r12
lea    0x20(%rsp),%rbx
nopl   0x0(%rax)
xor    %edi,%edi
call   10c0 <time@plt>
mov    %eax,0x8(%rsp)
mov    %r15,%rdi
call   1050 <ctime@plt>
mov    %rbx,%rdi
mov    $0x32,%esi
mov    %r12,%rdx
mov    %rax,%rcx
call   1090 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   10b0 <close@plt>
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1110 <accept@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1370 <main+0x150>
lea    0xc74(%rip),%rdi
call   10f0 <perror@plt>
xor    %edi,%edi
call   1120 <exit@plt>

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
@.str = [17 x i8] c"socket error: %s\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [22 x i8] c"setsockopt error: %s\0A\00"
@INADDR_ANY = global i32 0
@.str.2 = [11 x i8] c"bind error\00"
@.str.3 = [13 x i8] c"listen error\00"
@.str.4 = [13 x i8] c"accept error\00"
@.str.5 = [3 x i8] c"%s\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 i32
%10 = alloca i32
%11 = alloca [50 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp eq i32 -1, %15
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %2
store i32 1, i32* %7
%23 = load i32, i32* %6
%24 = load i32, i32* @SOL_SOCKET
%25 = load i32, i32* @SO_REUSEADDR
%26 = call i64 @setsockopt(i32 %23, i32 %24, i32 %25, i32* %7, i32 4)
%27 = icmp sgt i64 0, %26
br i1 %27, label %28, label %32
28: ; preds = %22
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %28, %22
%33 = call i32 @bzero(%struct.sockaddr_in* %8, i32 12)
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %34, i32* %35
%36 = load i32, i32* @INADDR_ANY
%37 = call i32 @htonl(i32 %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%39 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %38, i32 0, i32 0
store i32 %37, i32* %39
%40 = call i32 @htons(i32 13)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %40, i32* %41
%42 = load i32, i32* %6
%43 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%44 = call i32 @bind(i32 %42, %struct.sockaddr* %43, i32 12)
%45 = icmp eq i32 -1, %44
br i1 %45, label %46, label %51
46: ; preds = %32
%47 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%48 = load i32, i32* %6
%49 = call i32 @close(i32 %48)
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %32
%52 = load i32, i32* %6
%53 = call i32 @listen(i32 %52, i32 5)
%54 = icmp eq i32 -1, %53
br i1 %54, label %55, label %60
55: ; preds = %51
%56 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%57 = load i32, i32* %6
%58 = call i32 @close(i32 %57)
%59 = call i32 @exit(i32 0)
unreachable
60: ; preds = %51
br label %61
61: ; preds = %69, %60
%62 = load i32, i32* %6
%63 = call i32 @accept(i32 %62, %struct.sockaddr* null, i32* null)
store i32 %63, i32* %9
%64 = load i32, i32* %9
%65 = icmp eq i32 -1, %64
br i1 %65, label %66, label %69
66: ; preds = %61
%67 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%68 = call i32 @exit(i32 0)
unreachable
69: ; preds = %61
%70 = call i32 @time(i32* null)
store i32 %70, i32* %10
%71 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%72 = call i8* @ctime(i32* %10)
%73 = call i32 @snprintf(i8* %71, i32 50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %72)
%74 = load i32, i32* %9
%75 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%76 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%77 = call i32 @strlen(i8* %76)
%78 = call i32 @write(i32 %74, i8* %75, i32 %77)
%79 = load i32, i32* %9
%80 = call i32 @close(i32 %79)
br label %61
}

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
@.str = [17 x i8] c"socket error: %s\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [22 x i8] c"setsockopt error: %s\0A\00"
@INADDR_ANY = global i32 0
@.str.2 = [11 x i8] c"bind error\00"
@.str.3 = [13 x i8] c"listen error\00"
@.str.4 = [13 x i8] c"accept error\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [50 x i8]
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_REUSEADDR
%20 = call i64 @setsockopt(i32 %9, i32 %18, i32 %19, i32* %3, i32 4)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %22, %16
%27 = bitcast %struct.sockaddr_in* %4 to i8*
%28 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %29, i32* %30
%31 = load i32, i32* @INADDR_ANY
%32 = call i32 @htonl(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %32, i32* %33
%34 = call i32 @htons(i32 13)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %34, i32* %35
%36 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%37 = call i32 @bind(i32 %9, %struct.sockaddr* %36, i32 12)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %43
39: ; preds = %26
%40 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @close(i32 %9)
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %26
%44 = call i32 @listen(i32 %9, i32 5)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%48 = call i32 @close(i32 %9)
%49 = call i32 @exit(i32 0)
unreachable
50: ; preds = %43
%51 = bitcast i32* %5 to i8*
%52 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%53 = call i32 @accept(i32 %9, %struct.sockaddr* null, i32* null)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %58
55: ; preds = %58, %50
%56 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%57 = call i32 @exit(i32 0)
unreachable
58: ; preds = %50, %58
%59 = phi i32 [ %66, %58 ], [ %53, %50 ]
%60 = call i32 @time(i32* null)
store i32 %60, i32* %5
%61 = call i8* @ctime(i32* %5)
%62 = call i32 @snprintf(i8* %52, i32 50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %61)
%63 = call i32 @strlen(i8* %52)
%64 = call i32 @write(i32 %59, i8* %52, i32 %63)
%65 = call i32 @close(i32 %59)
%66 = call i32 @accept(i32 %9, %struct.sockaddr* null, i32* null)
%67 = icmp eq i32 %66, -1
br i1 %67, label %55, label %58
}