#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 uint32_t;
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*/ buff;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int atoi(int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int getopt(int, char **, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ *optarg;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int opt;
  uint32_t port = 8989;
  while ((opt = getopt(argc, argv, "hp:")) != -1) {
    switch (opt) {
    case 'h':
      usage();
      exit(0);
    case 'p':
      if (optarg != NULL) {
        port = atoi(optarg);
      }
      break;
    default:
      usage();
      exit(1);
    }
  }
  int listenfd, connfd;
  struct sockaddr_in servaddr;
  char buff[80];
  time_t tick;
  listenfd = socket(AF_INET, SOCK_STREAM, 0);
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servaddr.sin_port = htons(port);
  if (bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
    printf("bind error, abort\n");
    return 1;
  }
  listen(listenfd, 10);
  for (;;) {
    connfd = accept(listenfd, (struct sockaddr *)NULL, NULL);
    tick = time(NULL);
    snprintf(buff, sizeof(buff), "%.24s\n", ctime(&tick));
    printf("time=%s", buff);
    fflush(stdout);
    write(connfd, buff, strlen(buff));
    close(connfd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x231d,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xda2(%rip),%rdx
call   1110 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12e6 <main+0xb6>
mov    -0x14(%rbp),%eax
mov    %eax,-0x88(%rbp)
sub    $0x68,%eax
je     129a <main+0x6a>
jmp    1286 <main+0x56>
mov    -0x88(%rbp),%eax
sub    $0x70,%eax
je     12a8 <main+0x78>
jmp    12d0 <main+0xa0>
mov    $0x0,%al
call   10f0 <usage@plt>
xor    %edi,%edi
call   1140 <exit@plt>
mov    0x2d49(%rip),%rax
cmpq   $0x0,(%rax)
je     12cb <main+0x9b>
mov    0x2d38(%rip),%rax
mov    (%rax),%rdi
call   1130 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    12e1 <main+0xb1>
mov    $0x0,%al
call   10f0 <usage@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
jmp    1250 <main+0x20>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
mov    0x2cd2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1100 <bind@plt>
cmp    $0x0,%rax
jge    1371 <main+0x141>
lea    0xca8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%eax
add    $0xa0,%rsp
pop    %rbp
ret
mov    -0x1c(%rbp),%edi
mov    $0xa,%esi
call   10e0 <listen@plt>
mov    -0x1c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1120 <accept@plt>
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x84(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x84(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0xa0(%rbp),%rdi
mov    %rax,%rcx
mov    $0x50,%esi
lea    0xc4b(%rip),%rdx
call   1080 <snprintf@plt>
lea    -0x80(%rbp),%rsi
lea    0xc42(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2bd6(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x94(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x94(%rbp),%edi
mov    -0x90(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x20(%rbp),%edi
call   10b0 <close@plt>
jmp    137e <main+0x14e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x231d,%r14d
lea    0xda0(%rip),%r15
mov    0x2d91(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1120 <getopt@plt>
cmp    $0x70,%eax
jne    1295 <main+0x55>
mov    (%r12),%rdi
test   %rdi,%rdi
je     1270 <main+0x30>
call   1140 <atoi@plt>
mov    %eax,%r14d
jmp    1270 <main+0x30>
cmp    $0xffffffff,%eax
jne    13c8 <main+0x188>
mov    0x2d3b(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d19(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,%r13d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10b0 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    %r14d,%edi
call   1070 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1110 <bind@plt>
test   %rax,%rax
js     13a8 <main+0x168>
mov    %r13d,%edi
mov    $0xa,%esi
call   10f0 <listen@plt>
lea    0xce3(%rip),%r15
lea    0x20(%rsp),%rbp
lea    0xcde(%rip),%r12
mov    0x2c8c(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1130 <accept@plt>
mov    %eax,%ebx
xor    %edi,%edi
call   10d0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1050 <ctime@plt>
mov    %rbp,%rdi
mov    $0x50,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   1090 <snprintf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r14),%edi
call   10e0 <fflush@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   10c0 <close@plt>
jmp    1340 <main+0x100>
lea    0xc64(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x68,%eax
jne    13db <main+0x19b>
xor    %eax,%eax
call   1100 <usage@plt>
xor    %edi,%edi
call   1150 <exit@plt>
xor    %eax,%eax
call   1100 <usage@plt>
mov    $0x1,%edi
call   1150 <exit@plt>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [4 x i8] c"hp:\00"
@optarg = global i32* null
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [7 x i8] c"%.24s\0A\00"
@.str.3 = [8 x i8] c"time=%s\00"
@stdout = global i32 0
@str = [18 x i8] c"bind error, abort\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [80 x i8]
%5 = alloca i32
br label %6
6: ; preds = %16, %2
%7 = phi i32 [ %17, %16 ], [ 8989, %2 ]
br label %8
8: ; preds = %6, %13
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %9, label %18 [
i32 -1, label %21
i32 104, label %10
i32 112, label %13
]
10: ; preds = %8
%11 = tail call i32 (...) @usage()
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %8
%14 = load i32*, i32** @optarg
%15 = icmp eq i32* %14, null
br i1 %15, label %8, label %16
16: ; preds = %13
%17 = tail call i32 @atoi(i32* %14)
br label %6
18: ; preds = %8
%19 = tail call i32 (...) @usage()
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %8
%22 = bitcast %struct.sockaddr_in* %3 to i8*
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%24 = bitcast i32* %5 to i8*
%25 = load i32, i32* @AF_INET
%26 = load i32, i32* @SOCK_STREAM
%27 = tail call i32 @socket(i32 %25, i32 %26, i32 0)
%28 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, 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* %3, i64 0, i32 1, i32 0
store i32 %32, i32* %33
%34 = call i32 @htons(i32 %7)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %34, i32* %35
%36 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%37 = call i64 @bind(i32 %27, %struct.sockaddr* %36, i32 12)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %21
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
ret i32 1
41: ; preds = %21
%42 = call i32 @listen(i32 %27, i32 10)
br label %43
43: ; preds = %43, %41
%44 = call i32 @accept(i32 %27, %struct.sockaddr* null, i32* null)
%45 = call i32 @time(i32* null)
store i32 %45, i32* %5
%46 = call i8* @ctime(i32* %5)
%47 = call i32 @snprintf(i8* %23, i32 80, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %46)
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%49 = load i32, i32* @stdout
%50 = call i32 @fflush(i32 %49)
%51 = call i32 @strlen(i8* %23)
%52 = call i32 @write(i32 %44, i8* %23, i32 %51)
%53 = call i32 @close(i32 %44)
br label %43
}