#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 {
  TYPE_1__ sin_addr;
  scalar_t__ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  char *h_name;
};
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ client;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int ConnexWriteIP(int, unsigned char *, scalar_t__);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, unsigned int *);
char *asctime(struct tm *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyaddr(char *, int, int /*<<< orphan*/);
scalar_t__ getsockname(int, struct sockaddr *, unsigned int *);
scalar_t__ htons(int);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ listen(int, int);
struct tm *localtime(int /*<<< orphan*/ *);
int ntohs(scalar_t__);
int /*<<< orphan*/ perror(char *);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/,
                  int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
scalar_t__ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int sock, outs, size;
  unsigned int length;
  unsigned int clength;
  int port = 0;
  fd_set ready;
  struct sockaddr_in server;
  struct sockaddr_in client;
  struct hostent *gethostbyname();
  struct hostent *cname;
  time_t ltime;
  struct tm *time_of_day;
  char *date;
  int status = 0;
  sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    perror("opening stream socket");
    exit(1);
  }
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = INADDR_ANY;
  if (port != 0)
    server.sin_port = htons(port);
  else
    server.sin_port = 0;
  if (bind(sock, (struct sockaddr *)&server, sizeof(server))) {
    perror("binding stream socket");
    exit(1);
  }
  length = sizeof(server);
  if (getsockname(sock, (struct sockaddr *)&server, &length)) {
    perror("getting socket name");
    exit(1);
  }
  fprintf(stdout, "Socket has port #%d\n", ntohs(server.sin_port));
  listen(sock, 5);
  do {
    FD_ZERO(&ready);
    FD_SET(sock, &ready);
    if (select(sock + 1, &ready, 0, 0, NULL) < 0) {
      perror("while testing for connections");
      continue;
    }
    fprintf(stdout, "Accepting a new connection...\n");
    clength = sizeof(client);
    outs = accept(sock, (struct sockaddr *)&client, &clength);
    if (outs == -1) {
      perror("accept");
      continue;
    }
    cname = gethostbyaddr((char *)&client.sin_addr, sizeof(client.sin_addr),
                          AF_INET);
    if ((cname != NULL) && (cname->h_name != NULL))
      fprintf(stdout, "[%s (%s)]\n", cname->h_name, inet_ntoa(client.sin_addr));
    else
      fprintf(stdout, "[%s]\n", inet_ntoa(client.sin_addr));
    if (fork() == 0) {
      close(sock);
      do {
        time(&ltime);
        time_of_day = localtime(&ltime);
        date = asctime(time_of_day);
        fprintf(stdout, "Sending message.\n");
        size = ConnexWriteIP(outs, (unsigned char *)date, strlen(date) + 1);
        sleep(1);
      } while (status != -1);
      fprintf(stdout, "Connection closes.\n");
      close(outs);
      break;
    }
    close(outs);
  } while (1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x84(%rbp)
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1190 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12d6 <main+0x66>
lea    0xd39(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2cf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1309 <main+0x99>
mov    -0x28(%rbp),%edi
call   1080 <htons@plt>
mov    %rax,-0x40(%rbp)
jmp    1311 <main+0xa1>
movq   $0x0,-0x40(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0x18,%edx
call   1100 <bind@plt>
cmp    $0x0,%rax
je     1342 <main+0xd2>
lea    0xce3(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
movl   $0x18,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1130 <getsockname@plt>
cmp    $0x0,%rax
je     1379 <main+0x109>
lea    0xcc2(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    0x2c48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    -0x40(%rbp),%rdi
call   10f0 <ntohs@plt>
mov    -0x88(%rbp),%edi
mov    %eax,%edx
lea    0xca0(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10e0 <listen@plt>
lea    -0x2c(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   1160 <FD_SET@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
lea    -0x2c(%rbp),%rsi
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
mov    %ecx,%edx
call   10d0 <select@plt>
cmp    $0x0,%rax
jge    13fc <main+0x18c>
lea    0xc63(%rip),%rdi
call   1110 <perror@plt>
jmp    15c1 <main+0x351>
mov    0x2bc5(%rip),%rax
mov    (%rax),%edi
lea    0xc67(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x18,-0x24(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1120 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1448 <main+0x1d8>
lea    0xc54(%rip),%rdi
call   1110 <perror@plt>
jmp    15c1 <main+0x351>
lea    -0x60(%rbp),%rdi
mov    0x2b95(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1140 <gethostbyaddr@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     14c4 <main+0x254>
mov    -0x68(%rbp),%rax
cmpq   $0x0,(%rax)
je     14c4 <main+0x254>
mov    0x2b45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    -0x68(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x90(%rbp)
mov    -0x60(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    -0x94(%rbp),%edi
mov    -0x90(%rbp),%rdx
mov    %rax,%rcx
lea    0xbe1(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    14f2 <main+0x282>
mov    0x2afd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
mov    -0x60(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    -0x98(%rbp),%edi
mov    %rax,%rdx
lea    0xbb9(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x0,%al
call   1180 <fork@plt>
cmp    $0x0,%rax
jne    15b9 <main+0x349>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
lea    -0x6c(%rbp),%rdi
call   10b0 <time@plt>
lea    -0x6c(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
call   1070 <asctime@plt>
mov    %rax,-0x80(%rbp)
mov    0x2a93(%rip),%rax
mov    (%rax),%edi
lea    0xb6c(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0xa4(%rbp)
mov    -0x80(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x80(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xa4(%rbp),%edi
mov    -0xa0(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <ConnexWriteIP@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x1,%edi
call   1170 <sleep@plt>
cmpl   $0xffffffff,-0x84(%rbp)
jne    150b <main+0x29b>
mov    0x2a2c(%rip),%rax
mov    (%rax),%edi
lea    0xb17(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
jmp    15d0 <main+0x360>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
mov    $0x1,%al
test   $0x1,%al
jne    13b4 <main+0x144>
jmp    15d0 <main+0x360>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    0x2d73(%rip),%r15
mov    (%r15),%edi
mov    0x2d51(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
test   %eax,%eax
js     149c <main+0x23c>
mov    %eax,%ebp
mov    (%r15),%eax
mov    %eax,0x20(%rsp)
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x18,%edx
call   10f0 <bind@plt>
test   %rax,%rax
jne    14a5 <main+0x245>
movl   $0x18,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
call   1120 <getsockname@plt>
test   %rax,%rax
jne    14ae <main+0x24e>
mov    0x2cd6(%rip),%r13
mov    0x0(%r13),%r14d
mov    0x18(%rsp),%rdi
call   10e0 <ntohs@plt>
lea    0xd39(%rip),%rsi
mov    %r14d,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %ebp,%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
mov    %ebp,%eax
add    $0x1,%eax
mov    %eax,0x4(%rsp)
jmp    1340 <main+0xe0>
lea    0xd24(%rip),%rdi
call   1100 <perror@plt>
cs nopw 0x0(%rax,%rax,1)
lea    0x2c(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <FD_ZERO@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1150 <FD_SET@plt>
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10c0 <select@plt>
test   %rax,%rax
js     132a <main+0xca>
mov    0x0(%r13),%edi
lea    0xcf9(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
movl   $0x18,0x8(%rsp)
mov    %ebp,%edi
lea    0x30(%rsp),%rbx
mov    %rbx,%rsi
lea    0x8(%rsp),%rdx
call   1110 <accept@plt>
cmp    $0xffffffff,%eax
je     142c <main+0x1cc>
mov    %eax,%r12d
mov    %r15,%r14
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1130 <gethostbyaddr@plt>
test   %rax,%rax
je     13f0 <main+0x190>
mov    (%rax),%r15
test   %r15,%r15
je     13f0 <main+0x190>
mov    0x0(%r13),%ebx
mov    0x30(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %ebx,%edi
lea    0xcba(%rip),%rsi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1410 <main+0x1b0>
xchg   %ax,%ax
mov    0x0(%r13),%ebx
mov    0x30(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %ebx,%edi
lea    0xc9e(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
xor    %eax,%eax
call   1170 <fork@plt>
test   %rax,%rax
je     143d <main+0x1dd>
mov    %r12d,%edi
call   1080 <close@plt>
mov    %r14,%r15
jmp    1340 <main+0xe0>
lea    0xc5f(%rip),%rdi
call   1100 <perror@plt>
jmp    1340 <main+0xe0>
mov    %ebp,%edi
call   1080 <close@plt>
lea    0x28(%rsp),%rbx
lea    0xc5a(%rip),%r14
mov    %rbx,%rdi
call   10a0 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
mov    %rax,%rdi
call   1070 <asctime@plt>
mov    %rax,%rbp
mov    0x0(%r13),%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r12d,%edi
mov    %rbp,%rsi
call   1040 <ConnexWriteIP@plt>
mov    $0x1,%edi
call   1160 <sleep@plt>
jmp    1450 <main+0x1f0>
lea    0xb5d(%rip),%rdi
jmp    14b5 <main+0x255>
lea    0xb6a(%rip),%rdi
jmp    14b5 <main+0x255>
lea    0xb77(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i8* }
%struct.tm = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"opening stream socket\00"
@INADDR_ANY = global i32 0
@.str.1 = [22 x i8] c"binding stream socket\00"
@.str.2 = [20 x i8] c"getting socket name\00"
@stdout = global i32 0
@.str.3 = [21 x i8] c"Socket has port #%d\0A\00"
@.str.4 = [30 x i8] c"while testing for connections\00"
@.str.5 = [31 x i8] c"Accepting a new connection...\0A\00"
@.str.6 = [7 x i8] c"accept\00"
@.str.7 = [11 x i8] c"[%s (%s)]\0A\00"
@.str.8 = [6 x i8] c"[%s]\0A\00"
@.str.9 = [18 x i8] c"Sending message.\0A\00"
@.str.10 = [20 x i8] c"Connection closes.\0A\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 i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.sockaddr_in
%14 = alloca %struct.sockaddr_in
%15 = alloca %struct.hostent*
%16 = alloca i32
%17 = alloca %struct.tm*
%18 = alloca i8*
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
store i32 0, i32* %19
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %2
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
store i32 %29, i32* %30
%31 = load i32, i32* @INADDR_ANY
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
%33 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %32, i32 0, i32 0
store i32 %31, i32* %33
%34 = load i32, i32* %11
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %28
%37 = load i32, i32* %11
%38 = call i64 @htons(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
store i64 %38, i64* %39
br label %42
40: ; preds = %28
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
store i64 0, i64* %41
br label %42
42: ; preds = %40, %36
%43 = load i32, i32* %6
%44 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%45 = call i64 @bind(i32 %43, %struct.sockaddr* %44, i32 24)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %42
store i32 24, i32* %9
%51 = load i32, i32* %6
%52 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%53 = call i64 @getsockname(i32 %51, %struct.sockaddr* %52, i32* %9)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %50
%59 = load i32, i32* @stdout
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
%61 = load i64, i64* %60
%62 = call i32 @ntohs(i64 %61)
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %62)
%64 = load i32, i32* %6
%65 = call i32 @listen(i32 %64, i32 5)
br label %66
66: ; preds = %146, %58
%67 = call i32 @FD_ZERO(i32* %12)
%68 = load i32, i32* %6
%69 = call i32 @FD_SET(i32 %68, i32* %12)
%70 = load i32, i32* %6
%71 = add nsw i32 %70, 1
%72 = call i64 @select(i32 %71, i32* %12, i32 0, i32 0, i32* null)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %66
%75 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %146
76: ; preds = %66
%77 = load i32, i32* @stdout
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
store i32 24, i32* %10
%79 = load i32, i32* %6
%80 = bitcast %struct.sockaddr_in* %14 to %struct.sockaddr*
%81 = call i32 @accept(i32 %79, %struct.sockaddr* %80, i32* %10)
store i32 %81, i32* %7
%82 = load i32, i32* %7
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %86
84: ; preds = %76
%85 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %146
86: ; preds = %76
%87 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 0
%88 = bitcast %struct.TYPE_2__* %87 to i8*
%89 = load i32, i32* @AF_INET
%90 = call %struct.hostent* @gethostbyaddr(i8* %88, i32 4, i32 %89)
store %struct.hostent* %90, %struct.hostent** %15
%91 = load %struct.hostent*, %struct.hostent** %15
%92 = icmp ne %struct.hostent* %91, null
br i1 %92, label %93, label %108
93: ; preds = %86
%94 = load %struct.hostent*, %struct.hostent** %15
%95 = getelementptr inbounds %struct.hostent, %struct.hostent* %94, i32 0, i32 0
%96 = load i8*, i8** %95
%97 = icmp ne i8* %96, null
br i1 %97, label %98, label %108
98: ; preds = %93
%99 = load i32, i32* @stdout
%100 = load %struct.hostent*, %struct.hostent** %15
%101 = getelementptr inbounds %struct.hostent, %struct.hostent* %100, i32 0, i32 0
%102 = load i8*, i8** %101
%103 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 0
%104 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %103, i32 0, i32 0
%105 = load i32, i32* %104
%106 = call i8* @inet_ntoa(i32 %105)
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %102, i8* %106)
br label %115
108: ; preds = %93, %86
%109 = load i32, i32* @stdout
%110 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 0
%111 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %110, i32 0, i32 0
%112 = load i32, i32* %111
%113 = call i8* @inet_ntoa(i32 %112)
%114 = call i32 (i32, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i8* %113)
br label %115
115: ; preds = %108, %98
%116 = call i64 (...) @fork()
%117 = icmp eq i64 %116, 0
br i1 %117, label %118, label %143
118: ; preds = %115
%119 = load i32, i32* %6
%120 = call i32 @close(i32 %119)
br label %121
121: ; preds = %135, %118
%122 = call i32 @time(i32* %16)
%123 = call %struct.tm* @localtime(i32* %16)
store %struct.tm* %123, %struct.tm** %17
%124 = load %struct.tm*, %struct.tm** %17
%125 = call i8* @asctime(%struct.tm* %124)
store i8* %125, i8** %18
%126 = load i32, i32* @stdout
%127 = call i32 (i32, i8*, ...) @fprintf(i32 %126, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%128 = load i32, i32* %7
%129 = load i8*, i8** %18
%130 = load i8*, i8** %18
%131 = call i64 @strlen(i8* %130)
%132 = add nsw i64 %131, 1
%133 = call i32 @ConnexWriteIP(i32 %128, i8* %129, i64 %132)
store i32 %133, i32* %8
%134 = call i32 @sleep(i32 1)
br label %135
135: ; preds = %121
%136 = load i32, i32* %19
%137 = icmp ne i32 %136, -1
br i1 %137, label %121, label %138
138: ; preds = %135
%139 = load i32, i32* @stdout
%140 = call i32 (i32, i8*, ...) @fprintf(i32 %139, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
%141 = load i32, i32* %7
%142 = call i32 @close(i32 %141)
br label %147
143: ; preds = %115
%144 = load i32, i32* %7
%145 = call i32 @close(i32 %144)
br label %146
146: ; preds = %143, %84, %74
br i1 true, label %66, label %147
147: ; preds = %146, %138
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
%struct.hostent = type { i8* }
%struct.tm = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"opening stream socket\00"
@INADDR_ANY = global i32 0
@.str.1 = [22 x i8] c"binding stream socket\00"
@.str.2 = [20 x i8] c"getting socket name\00"
@stdout = global i32 0
@.str.3 = [21 x i8] c"Socket has port #%d\0A\00"
@.str.4 = [30 x i8] c"while testing for connections\00"
@.str.5 = [31 x i8] c"Accepting a new connection...\0A\00"
@.str.6 = [7 x i8] c"accept\00"
@.str.7 = [11 x i8] c"[%s (%s)]\0A\00"
@.str.8 = [6 x i8] c"[%s]\0A\00"
@.str.9 = [18 x i8] c"Sending message.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast %struct.sockaddr_in* %6 to i8*
%13 = bitcast %struct.sockaddr_in* %7 to i8*
%14 = bitcast i32* %8 to i8*
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0, i32 0
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
store i64 0, i64* %27
%28 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%29 = call i64 @bind(i32 %17, %struct.sockaddr* %28, i32 24)
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %22
%32 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %22
store i32 24, i32* %3
%35 = call i64 @getsockname(i32 %17, %struct.sockaddr* %28, i32* %3)
%36 = icmp eq i64 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %34
%38 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %34
%41 = load i32, i32* @stdout
%42 = load i64, i64* %27
%43 = call i32 @ntohs(i64 %42)
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%45 = call i32 @listen(i32 %17, i32 5)
%46 = add nuw nsw i32 %17, 1
%47 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0, i32 0
br label %49
49: ; preds = %98, %40
%50 = call i32 @FD_ZERO(i32* %5)
%51 = call i32 @FD_SET(i32 %17, i32* %5)
%52 = call i64 @select(i32 %46, i32* %5, i32 0, i32 0, i32* null)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %98
56: ; preds = %49
%57 = load i32, i32* @stdout
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
store i32 24, i32* %4
%59 = call i32 @accept(i32 %17, %struct.sockaddr* %47, i32* %4)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %63
61: ; preds = %56
%62 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %98
63: ; preds = %56
%64 = load i32, i32* @AF_INET
%65 = call %struct.hostent* @gethostbyaddr(i8* %13, i32 4, i32 %64)
%66 = icmp eq %struct.hostent* %65, null
br i1 %66, label %76, label %67
67: ; preds = %63
%68 = getelementptr inbounds %struct.hostent, %struct.hostent* %65, i64 0, i32 0
%69 = load i8*, i8** %68
%70 = icmp eq i8* %69, null
br i1 %70, label %76, label %71
71: ; preds = %67
%72 = load i32, i32* @stdout
%73 = load i32, i32* %48
%74 = call i8* @inet_ntoa(i32 %73)
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %69, i8* %74)
br label %81
76: ; preds = %67, %63
%77 = load i32, i32* @stdout
%78 = load i32, i32* %48
%79 = call i8* @inet_ntoa(i32 %78)
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i8* %79)
br label %81
81: ; preds = %76, %71
%82 = call i64 (...) @fork()
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %96
84: ; preds = %81
%85 = call i32 @close(i32 %17)
br label %86
86: ; preds = %86, %84
%87 = call i32 @time(i32* %8)
%88 = call %struct.tm* @localtime(i32* %8)
%89 = call i8* @asctime(%struct.tm* %88)
%90 = load i32, i32* @stdout
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%92 = call i64 @strlen(i8* dereferenceable(1) %89)
%93 = add nsw i64 %92, 1
%94 = call i32 @ConnexWriteIP(i32 %59, i8* %89, i64 %93)
%95 = call i32 @sleep(i32 1)
br label %86
96: ; preds = %81
%97 = call i32 @close(i32 %59)
br label %98
98: ; preds = %96, %61, %54
br label %49
}