#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 tm {
  int dummy;
};
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 socklen_t;
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ client_addr;
typedef int /*<<< orphan*/ buff;
typedef int /*<<< orphan*/ addr_buff;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
char *inet_ntop(int /*<<< orphan*/, TYPE_1__ *, char *, int);
int listen(int, int);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int listenfd, connfd;
  int retval;
  struct sockaddr_in client_addr, server_addr;
  socklen_t client_addr_len, server_addr_len;
  char buff[256];
  char addr_buff[256];
  time_t rawtime;
  struct tm *timeinfo;
  if (argc != 2) {
    fprintf(stderr, "Invocation: %s <PORT>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  listenfd = socket(PF_INET, SOCK_STREAM, 0);
  if (listenfd == -1) {
    perror("socket()");
    exit(EXIT_FAILURE);
  }
  memset(&server_addr, 0, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  server_addr.sin_port = htons(atoi(argv[1]));
  server_addr_len = sizeof(server_addr);
  if (bind(listenfd, (struct sockaddr *)&server_addr, server_addr_len) == -1) {
    perror("bind()");
    exit(EXIT_FAILURE);
  }
  if (listen(listenfd, 2) == -1) {
    perror("listen()");
    exit(EXIT_FAILURE);
  }
  fprintf(stdout, "Server is listening for incoming connection...\n");
  client_addr_len = sizeof(client_addr);
  connfd = accept(listenfd, (struct sockaddr *)&client_addr, &client_addr_len);
  if (connfd == -1) {
    perror("accept()");
    exit(EXIT_FAILURE);
  }
  fprintf(
      stdout, "TCP connection accepted from %s:%d\n",
      inet_ntop(AF_INET, &client_addr.sin_addr, addr_buff, sizeof(addr_buff)),
      ntohs(client_addr.sin_port));
  sleep(6);
  fprintf(stdout, "Sending current date and time...\n");
  sleep(2);
  time(&rawtime);
  timeinfo = localtime(&rawtime);
  strftime(buff, sizeof(buff), "%Y-%m-%d %H:%M:%S %Z", timeinfo);
  retval = write(connfd, buff, strlen(buff));
  retval = read(connfd, buff, sizeof(buff));
  if (retval == 0) {
    sleep(4);
    fprintf(
        stdout,
        "Connection terminated by client "
        "(received FIN, entering CLOSE_WAIT state on connected socked)...\n");
  }
  sleep(12);
  fprintf(stdout, "Closing connected socket (sending FIN to client)...\n");
  close(connfd);
  sleep(5);
  fprintf(stdout, "Closing listening socket and terminating server...\n");
  close(listenfd);
  sleep(3);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     129f <main+0x4f>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd76(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
call   1150 <exit@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
mov    0x2d19(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12df <main+0x8f>
lea    0xd4b(%rip),%rdi
call   1120 <perror@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
call   1150 <exit@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2cf2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1140 <atoi@plt>
mov    %eax,%edi
call   1070 <htons@plt>
mov    %eax,-0x38(%rbp)
movl   $0xc,-0x40(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%edx
call   1100 <bind@plt>
cmp    $0xffffffff,%eax
jne    135c <main+0x10c>
lea    0xcd7(%rip),%rdi
call   1120 <perror@plt>
mov    0x2c63(%rip),%rax
mov    (%rax),%edi
call   1150 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
jne    138c <main+0x13c>
lea    0xcae(%rip),%rdi
call   1120 <perror@plt>
mov    0x2c33(%rip),%rax
mov    (%rax),%edi
call   1150 <exit@plt>
mov    0x2c1d(%rip),%rax
mov    (%rax),%edi
lea    0xc94(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0xc,-0x3c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   1130 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    13e1 <main+0x191>
lea    0xc92(%rip),%rdi
call   1120 <perror@plt>
mov    0x2bde(%rip),%rax
mov    (%rax),%edi
call   1150 <exit@plt>
mov    0x2bc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x26c(%rbp)
mov    0x2bf1(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
add    $0x4,%rsi
lea    -0x240(%rbp),%rdx
mov    $0x100,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,-0x268(%rbp)
mov    -0x28(%rbp),%edi
call   10f0 <ntohs@plt>
mov    -0x26c(%rbp),%edi
mov    -0x268(%rbp),%rdx
mov    %eax,%ecx
lea    0xc32(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x6,%edi
call   1160 <sleep@plt>
mov    0x2b61(%rip),%rax
mov    (%rax),%edi
lea    0xc35(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x2,%edi
call   1160 <sleep@plt>
lea    -0x244(%rbp),%rdi
call   10d0 <time@plt>
lea    -0x244(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x250(%rbp)
lea    -0x140(%rbp),%rdi
mov    -0x250(%rbp),%rcx
mov    $0x100,%esi
lea    0xc0d(%rip),%rdx
call   1110 <strftime@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x25c(%rbp)
lea    -0x140(%rbp),%rax
mov    %rax,-0x258(%rbp)
lea    -0x140(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x25c(%rbp),%edi
mov    -0x258(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x100,%edx
call   10b0 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1523 <main+0x2d3>
mov    $0x4,%edi
call   1160 <sleep@plt>
mov    0x2a9d(%rip),%rax
mov    (%rax),%edi
lea    0xba8(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0xc,%edi
call   1160 <sleep@plt>
mov    0x2a7c(%rip),%rax
mov    (%rax),%edi
lea    0xbe9(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
mov    $0x5,%edi
call   1160 <sleep@plt>
mov    0x2a53(%rip),%rax
mov    (%rax),%edi
lea    0xbf5(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
mov    $0x3,%edi
call   1160 <sleep@plt>
mov    0x2a22(%rip),%rax
mov    (%rax),%edi
call   1150 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x238,%rsp
mov    %rsi,%rbp
cmp    $0x2,%edi
jne    1293 <main+0x43>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
cmp    $0xffffffff,%eax
jne    12b3 <main+0x63>
lea    0xd89(%rip),%rdi
jmp    1377 <main+0x127>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xd59(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    137c <main+0x12c>
mov    %eax,%r14d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2d17(%rip),%r13
mov    0x0(%r13),%eax
mov    %eax,0x18(%rsp)
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    0x8(%rbp),%rdi
call   1140 <atoi@plt>
mov    %eax,%edi
call   1070 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1100 <bind@plt>
cmp    $0xffffffff,%eax
jne    131d <main+0xcd>
lea    0xd05(%rip),%rdi
jmp    1377 <main+0x127>
mov    %r14d,%edi
mov    $0x2,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1338 <main+0xe8>
lea    0xcf1(%rip),%rdi
jmp    1377 <main+0x127>
mov    0x2c71(%rip),%r12
mov    (%r12),%edi
lea    0xce6(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
call   1130 <accept@plt>
cmp    $0xffffffff,%eax
jne    138a <main+0x13a>
lea    0xce9(%rip),%rdi
call   1120 <perror@plt>
mov    0x2c35(%rip),%rax
mov    (%rax),%edi
call   1150 <exit@plt>
mov    %eax,%ebp
mov    (%r12),%r15d
mov    0x0(%r13),%edi
lea    0x24(%rsp),%rsi
lea    0x30(%rsp),%rdx
mov    $0x100,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rbx
mov    0x20(%rsp),%edi
call   10f0 <ntohs@plt>
lea    0xcae(%rip),%rsi
mov    %r15d,%edi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x6,%edi
call   1160 <sleep@plt>
mov    (%r12),%edi
lea    0xcae(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x2,%edi
call   1160 <sleep@plt>
lea    0x2c(%rsp),%rbx
mov    %rbx,%rdi
call   10d0 <time@plt>
mov    %rbx,%rdi
call   1040 <localtime@plt>
lea    0xca3(%rip),%rdx
lea    0x130(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rax,%rcx
call   1110 <strftime@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   10b0 <read@plt>
test   %eax,%eax
jne    1467 <main+0x217>
mov    $0x4,%edi
call   1160 <sleep@plt>
mov    (%r12),%edi
lea    0xc64(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0xc,%edi
call   1160 <sleep@plt>
mov    (%r12),%edi
lea    0xcaa(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    $0x5,%edi
call   1160 <sleep@plt>
mov    (%r12),%edi
lea    0xcbc(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
mov    $0x3,%edi
call   1160 <sleep@plt>
mov    0x2ae9(%rip),%rax
mov    (%rax),%edi
call   1150 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.tm = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Invocation: %s <PORT>\0A\00"
@EXIT_FAILURE = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [9 x i8] c"socket()\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [7 x i8] c"bind()\00"
@.str.3 = [9 x i8] c"listen()\00"
@stdout = global i32 0
@.str.4 = [48 x i8] c"Server is listening for incoming connection...\0A\00"
@.str.5 = [9 x i8] c"accept()\00"
@.str.6 = [36 x i8] c"TCP connection accepted from %s:%d\0A\00"
@.str.7 = [34 x i8] c"Sending current date and time...\0A\00"
@.str.8 = [21 x i8] c"%Y-%m-%d %H:%M:%S %Z\00"
@.str.9 = [98 x i8] c"Connection terminated by client (received FIN, entering CLOSE_WAIT state on connected socked)...\0A\00"
@.str.10 = [53 x i8] c"Closing connected socket (sending FIN to client)...\0A\00"
@.str.11 = [52 x i8] c"Closing listening socket and terminating server...\0A\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 %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca i32
%13 = alloca [256 x i8]
%14 = alloca [256 x i8]
%15 = alloca i32
%16 = alloca %struct.tm*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 2
br i1 %18, label %19, label %27
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %2
%28 = load i32, i32* @PF_INET
%29 = load i32, i32* @SOCK_STREAM
%30 = call i32 @socket(i32 %28, i32 %29, i32 0)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %27
%34 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %27
%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 i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32 @atoi(i8* %47)
%49 = call i32 @htons(i32 %48)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %49, i32* %50
store i32 12, i32* %12
%51 = load i32, i32* %6
%52 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%53 = load i32, i32* %12
%54 = call i32 @bind(i32 %51, %struct.sockaddr* %52, i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %60
56: ; preds = %37
%57 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %37
%61 = load i32, i32* %6
%62 = call i32 @listen(i32 %61, i32 2)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %68
64: ; preds = %60
%65 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %60
%69 = load i32, i32* @stdout
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
store i32 12, i32* %11
%71 = load i32, i32* %6
%72 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%73 = call i32 @accept(i32 %71, %struct.sockaddr* %72, i32* %11)
store i32 %73, i32* %7
%74 = load i32, i32* %7
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %80
76: ; preds = %68
%77 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%78 = load i32, i32* @EXIT_FAILURE
%79 = call i32 @exit(i32 %78)
unreachable
80: ; preds = %68
%81 = load i32, i32* @stdout
%82 = load i32, i32* @AF_INET
%83 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%84 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%85 = call i8* @inet_ntop(i32 %82, %struct.TYPE_2__* %83, i8* %84, i32 256)
%86 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%87 = load i32, i32* %86
%88 = call i32 @ntohs(i32 %87)
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i8* %85, i32 %88)
%90 = call i32 @sleep(i32 6)
%91 = load i32, i32* @stdout
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
%93 = call i32 @sleep(i32 2)
%94 = call i32 @time(i32* %15)
%95 = call %struct.tm* @localtime(i32* %15)
store %struct.tm* %95, %struct.tm** %16
%96 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%97 = load %struct.tm*, %struct.tm** %16
%98 = call i32 @strftime(i8* %96, i32 256, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), %struct.tm* %97)
%99 = load i32, i32* %7
%100 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%101 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%102 = call i32 @strlen(i8* %101)
%103 = call i32 @write(i32 %99, i8* %100, i32 %102)
store i32 %103, i32* %8
%104 = load i32, i32* %7
%105 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%106 = call i32 @read(i32 %104, i8* %105, i32 256)
store i32 %106, i32* %8
%107 = load i32, i32* %8
%108 = icmp eq i32 %107, 0
br i1 %108, label %109, label %113
109: ; preds = %80
%110 = call i32 @sleep(i32 4)
%111 = load i32, i32* @stdout
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.9, i64 0, i64 0))
br label %113
113: ; preds = %109, %80
%114 = call i32 @sleep(i32 12)
%115 = load i32, i32* @stdout
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.10, i64 0, i64 0))
%117 = load i32, i32* %7
%118 = call i32 @close(i32 %117)
%119 = call i32 @sleep(i32 5)
%120 = load i32, i32* @stdout
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.11, i64 0, i64 0))
%122 = load i32, i32* %6
%123 = call i32 @close(i32 %122)
%124 = call i32 @sleep(i32 3)
%125 = load i32, i32* @EXIT_SUCCESS
%126 = call i32 @exit(i32 %125)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
%struct.tm = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Invocation: %s <PORT>\0A\00"
@EXIT_FAILURE = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [9 x i8] c"socket()\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [7 x i8] c"bind()\00"
@.str.3 = [9 x i8] c"listen()\00"
@stdout = global i32 0
@.str.4 = [48 x i8] c"Server is listening for incoming connection...\0A\00"
@.str.5 = [9 x i8] c"accept()\00"
@.str.6 = [36 x i8] c"TCP connection accepted from %s:%d\0A\00"
@.str.7 = [34 x i8] c"Sending current date and time...\0A\00"
@.str.8 = [21 x i8] c"%Y-%m-%d %H:%M:%S %Z\00"
@.str.9 = [98 x i8] c"Connection terminated by client (received FIN, entering CLOSE_WAIT state on connected socked)...\0A\00"
@.str.10 = [53 x i8] c"Closing connected socket (sending FIN to client)...\0A\00"
@.str.11 = [52 x i8] c"Closing listening socket and terminating server...\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = bitcast %struct.sockaddr_in* %3 to i8*
%10 = bitcast %struct.sockaddr_in* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%14 = bitcast i32* %8 to i8*
%15 = icmp eq i32 %0, 2
br i1 %15, label %22, label %16
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %1
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = load i32, i32* @PF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = tail call i32 @socket(i32 %23, i32 %24, i32 0)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %22
%32 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %33, i32* %34
%35 = load i32, i32* @INADDR_ANY
%36 = call i32 @htonl(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %36, i32* %37
%38 = getelementptr inbounds i8*, i8** %1, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
%41 = call i32 @htons(i32 %40)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %41, i32* %42
%43 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%44 = call i32 @bind(i32 %25, %struct.sockaddr* %43, i32 12)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %50
46: ; preds = %31
%47 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %31
%51 = call i32 @listen(i32 %25, i32 2)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %57
53: ; preds = %50
%54 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %50
%58 = load i32, i32* @stdout
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
store i32 12, i32* %5
%60 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%61 = call i32 @accept(i32 %25, %struct.sockaddr* %60, i32* %5)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %67
63: ; preds = %57
%64 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %57
%68 = load i32, i32* @stdout
%69 = load i32, i32* @AF_INET
%70 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%71 = call i8* @inet_ntop(i32 %69, %struct.TYPE_2__* %70, i8* %13, i32 256)
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%73 = load i32, i32* %72
%74 = call i32 @ntohs(i32 %73)
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i8* %71, i32 %74)
%76 = call i32 @sleep(i32 6)
%77 = load i32, i32* @stdout
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
%79 = call i32 @sleep(i32 2)
%80 = call i32 @time(i32* %8)
%81 = call %struct.tm* @localtime(i32* %8)
%82 = call i32 @strftime(i8* %12, i32 256, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), %struct.tm* %81)
%83 = call i32 @strlen(i8* %12)
%84 = call i32 @write(i32 %61, i8* %12, i32 %83)
%85 = call i32 @read(i32 %61, i8* %12, i32 256)
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %91
87: ; preds = %67
%88 = call i32 @sleep(i32 4)
%89 = load i32, i32* @stdout
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.9, i64 0, i64 0))
br label %91
91: ; preds = %87, %67
%92 = call i32 @sleep(i32 12)
%93 = load i32, i32* @stdout
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.10, i64 0, i64 0))
%95 = call i32 @close(i32 %61)
%96 = call i32 @sleep(i32 5)
%97 = load i32, i32* @stdout
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.11, i64 0, i64 0))
%99 = call i32 @close(i32 %25)
%100 = call i32 @sleep(i32 3)
%101 = load i32, i32* @EXIT_SUCCESS
%102 = call i32 @exit(i32 %101)
unreachable
}