#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 */
struct sockaddr_storage {
  int /*<<< orphan*/ ss_family;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_flags;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int /*<<< orphan*/ get_in_addr(struct sockaddr *);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
int listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_address(struct addrinfo *);
int /*<<< orphan*/ printf(char *, ...);
int send(int, char *, int, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, const char *argv[]) {
  int socket_fd, new_fd;
  struct addrinfo hints, *server_info, *iterator;
  struct sockaddr_storage their_addr;
  socklen_t sin_size;
  int yes = 1;
  char ip[INET6_ADDRSTRLEN];
  int return_code;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  if ((return_code = getaddrinfo(NULL, "3490", &hints, &server_info)) != 0) {
    fprintf(stderr, "getaddrinfo failed: %s\n", gai_strerror(return_code));
    exit(1);
  }
  for (iterator = server_info; iterator != NULL; iterator = iterator->ai_next) {
    print_address(iterator);
    if ((socket_fd = socket(iterator->ai_family, iterator->ai_socktype,
                            iterator->ai_protocol)) == -1) {
      perror("could not connect!");
      continue;
    }
    if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes) ==
        -1) {
      perror("could not reclaim socket!");
      exit(1);
    }
    if (bind(socket_fd, iterator->ai_addr, iterator->ai_addrlen) == 1) {
      close(socket_fd);
      perror("could not bind socket to address!");
    }
    break;
  }
  freeaddrinfo(server_info);
  if (iterator == NULL) {
    perror("Could not find valid address!");
    exit(1);
  }
  if (listen(socket_fd, 10) == 1) {
    perror("Could not start listening on socket!");
    exit(1);
  }
  printf("Server: Wainting for connections ...");
  while (1) {
    sin_size = sizeof their_addr;
    if ((new_fd = accept(socket_fd, (struct sockaddr *)&their_addr,
                         &sin_size)) == -1) {
      perror("Error accepting!");
      exit(1);
    }
    inet_ntop(their_addr.ss_family, get_in_addr((struct sockaddr *)&their_addr),
              ip, sizeof ip);
    printf("Server: Conneted to: %s\n", ip);
    if (fork() == 0) {
      close(socket_fd);
      if (send(new_fd, "Hello, world!", 13, 0) == -1) {
        perror("Failed to send message to connected client!");
        exit(1);
      }
      close(new_fd);
      exit(0);
    }
    close(new_fd);
  }
  return 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)
movl   $0x1,-0x60(%rbp)
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x88(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x70(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   10a0 <memset@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd3e(%rip),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1120 <getaddrinfo@plt>
mov    %eax,-0x74(%rbp)
cmp    $0x0,%eax
je     1311 <main+0xe1>
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x74(%rbp),%edi
call   1090 <gai_strerror@plt>
mov    -0x8c(%rbp),%edi
mov    %rax,%rdx
lea    0xd03(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     13ef <main+0x1bf>
mov    -0x50(%rbp),%rdi
call   1060 <print_address@plt>
mov    -0x50(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x50(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%edx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1364 <main+0x134>
lea    0xcc3(%rip),%rdi
call   10f0 <perror@plt>
jmp    13de <main+0x1ae>
mov    -0x14(%rbp),%edi
mov    0x2c7a(%rip),%rax
mov    (%rax),%esi
mov    0x2c39(%rip),%rax
mov    (%rax),%edx
lea    -0x60(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    13a7 <main+0x177>
lea    0xc98(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x50(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x50(%rbp),%rax
mov    (%rax),%edx
call   10e0 <bind@plt>
cmp    $0x1,%eax
jne    13d9 <main+0x1a9>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
lea    0xc76(%rip),%rdi
call   10f0 <perror@plt>
jmp    13ef <main+0x1bf>
mov    -0x50(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    1319 <main+0xe9>
mov    -0x48(%rbp),%rdi
call   1140 <freeaddrinfo@plt>
cmpq   $0x0,-0x50(%rbp)
jne    1419 <main+0x1e9>
lea    0xc62(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   10d0 <listen@plt>
cmp    $0x1,%eax
jne    1445 <main+0x215>
lea    0xc54(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xc63(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1458 <main+0x228>
movl   $0x4,-0x5c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x58(%rbp),%rsi
lea    -0x5c(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1491 <main+0x261>
lea    0xc52(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x58(%rbp),%eax
mov    %eax,-0x90(%rbp)
lea    -0x58(%rbp),%rdi
call   1040 <get_in_addr@plt>
mov    -0x90(%rbp),%edi
mov    -0x80(%rbp),%rdx
mov    %eax,%esi
mov    -0x88(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x80(%rbp),%rsi
lea    0xc1d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x0,%al
call   1130 <fork@plt>
cmp    $0x0,%rax
jne    152c <main+0x2fc>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
mov    -0x18(%rbp),%edi
lea    0xc0c(%rip),%rsi
mov    $0xd,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0xffffffff,%eax
jne    151d <main+0x2ed>
lea    0xbfe(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x18(%rbp),%edi
call   10b0 <close@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x18(%rbp),%edi
call   10b0 <close@plt>
jmp    1453 <main+0x223>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
movl   $0x1,-0x3c(%rbp)
mov    0x2d91(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%r13
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    -0x78(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   10a0 <memset@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2d2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2d43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
lea    0xd5f(%rip),%rsi
lea    -0x38(%rbp),%rcx
xor    %edi,%edi
mov    %rbx,%rdx
call   1120 <getaddrinfo@plt>
test   %eax,%eax
jne    12cf <main+0x9f>
mov    -0x38(%rbp),%rbx
test   %rbx,%rbx
jne    12fa <main+0xca>
xor    %edi,%edi
call   1140 <freeaddrinfo@plt>
lea    0xda2(%rip),%rdi
jmp    1477 <main+0x247>
mov    0x2cea(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1090 <gai_strerror@plt>
lea    0xd1f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xd1c(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <print_address@plt>
mov    0x10(%rbx),%edi
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%esi
call   1150 <socket@plt>
cmp    $0xffffffff,%eax
jne    1345 <main+0x115>
mov    %r14,%rdi
call   10f0 <perror@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
jne    1310 <main+0xe0>
mov    -0x38(%rbp),%rdi
jmp    12be <main+0x8e>
mov    %eax,%r12d
mov    0x2c99(%rip),%rax
mov    (%rax),%esi
mov    0x2c58(%rip),%rax
mov    (%rax),%edx
lea    -0x3c(%rbp),%rcx
mov    %r12d,%edi
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    137d <main+0x14d>
lea    0xcb8(%rip),%rdi
jmp    1477 <main+0x247>
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %r12d,%edi
call   10e0 <bind@plt>
cmp    $0x1,%eax
jne    13a3 <main+0x173>
mov    %r12d,%edi
call   10b0 <close@plt>
lea    0xcac(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x38(%rbp),%rdi
call   1140 <freeaddrinfo@plt>
mov    %r12d,%edi
mov    $0xa,%esi
call   10d0 <listen@plt>
cmp    $0x1,%eax
jne    13ca <main+0x19a>
lea    0xcc5(%rip),%rdi
jmp    1477 <main+0x247>
mov    %r13,-0x48(%rbp)
mov    %r15,-0x50(%rbp)
lea    0xcd6(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
movl   $0x4,-0x2c(%rbp)
lea    -0x30(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
mov    %r12d,%edi
call   1100 <accept@plt>
cmp    $0xffffffff,%eax
je     1470 <main+0x240>
mov    %eax,%r15d
lea    -0x30(%rbp),%r13
mov    -0x48(%rbp),%rbx
nopw   0x0(%rax,%rax,1)
mov    -0x30(%rbp),%r14d
mov    %r13,%rdi
call   1040 <get_in_addr@plt>
mov    %r14d,%edi
mov    %eax,%esi
mov    %rbx,%rdx
mov    -0x50(%rbp),%rcx
call   1030 <inet_ntop@plt>
lea    0xcb1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
call   1130 <fork@plt>
test   %rax,%rax
je     1486 <main+0x256>
mov    %r15d,%edi
call   10b0 <close@plt>
movl   $0x4,-0x2c(%rbp)
mov    %r12d,%edi
mov    %r13,%rsi
lea    -0x2c(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    1410 <main+0x1e0>
lea    0xc5d(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    %r12d,%edi
call   10b0 <close@plt>
lea    0xc69(%rip),%rsi
mov    %r15d,%edi
mov    $0xd,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0xffffffff,%eax
jne    14b2 <main+0x282>
lea    0xc5c(%rip),%rdi
jmp    1477 <main+0x247>
mov    %r15d,%edi
call   10b0 <close@plt>
xor    %edi,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"3490\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"getaddrinfo failed: %s\0A\00"
@.str.2 = [19 x i8] c"could not connect!\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [26 x i8] c"could not reclaim socket!\00"
@.str.4 = [34 x i8] c"could not bind socket to address!\00"
@.str.5 = [30 x i8] c"Could not find valid address!\00"
@.str.6 = [37 x i8] c"Could not start listening on socket!\00"
@.str.7 = [37 x i8] c"Server: Wainting for connections ...\00"
@.str.8 = [17 x i8] c"Error accepting!\00"
@.str.9 = [25 x i8] c"Server: Conneted to: %s\0A\00"
@.str.10 = [14 x i8] c"Hello, world!\00"
@.str.11 = [44 x i8] c"Failed to send message to connected client!\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.addrinfo
%9 = alloca %struct.addrinfo*
%10 = alloca %struct.addrinfo*
%11 = alloca %struct.sockaddr_storage
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %13
%17 = load i32, i32* @INET6_ADDRSTRLEN
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %14
%20 = alloca i8, i64 %18
store i64 %18, i64* %15
%21 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 40)
%22 = load i32, i32* @AF_UNSPEC
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 4
store i32 %22, i32* %23
%24 = load i32, i32* @SOCK_STREAM
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 3
store i32 %24, i32* %25
%26 = load i32, i32* @AI_PASSIVE
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 6
store i32 %26, i32* %27
%28 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %8, %struct.addrinfo** %9)
store i32 %28, i32* %16
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %2
%31 = load i32, i32* @stderr
%32 = load i32, i32* %16
%33 = call i8* @gai_strerror(i32 %32)
%34 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %2
%37 = load %struct.addrinfo*, %struct.addrinfo** %9
store %struct.addrinfo* %37, %struct.addrinfo** %10
br label %38
38: ; preds = %81, %36
%39 = load %struct.addrinfo*, %struct.addrinfo** %10
%40 = icmp ne %struct.addrinfo* %39, null
br i1 %40, label %41, label %85
41: ; preds = %38
%42 = load %struct.addrinfo*, %struct.addrinfo** %10
%43 = call i32 @print_address(%struct.addrinfo* %42)
%44 = load %struct.addrinfo*, %struct.addrinfo** %10
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i32 0, i32 4
%46 = load i32, i32* %45
%47 = load %struct.addrinfo*, %struct.addrinfo** %10
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i32 0, i32 3
%49 = load i32, i32* %48
%50 = load %struct.addrinfo*, %struct.addrinfo** %10
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 2
%52 = load i32, i32* %51
%53 = call i32 @socket(i32 %46, i32 %49, i32 %52)
store i32 %53, i32* %6
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %41
%56 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %81
57: ; preds = %41
%58 = load i32, i32* %6
%59 = load i32, i32* @SOL_SOCKET
%60 = load i32, i32* @SO_REUSEADDR
%61 = call i32 @setsockopt(i32 %58, i32 %59, i32 %60, i32* %13, i32 4)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %66
63: ; preds = %57
%64 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %57
%67 = load i32, i32* %6
%68 = load %struct.addrinfo*, %struct.addrinfo** %10
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %68, i32 0, i32 1
%70 = load i32, i32* %69
%71 = load %struct.addrinfo*, %struct.addrinfo** %10
%72 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %71, i32 0, i32 0
%73 = load i32, i32* %72
%74 = call i32 @bind(i32 %67, i32 %70, i32 %73)
%75 = icmp eq i32 %74, 1
br i1 %75, label %76, label %80
76: ; preds = %66
%77 = load i32, i32* %6
%78 = call i32 @close(i32 %77)
%79 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %80
80: ; preds = %76, %66
br label %85
81: ; preds = %55
%82 = load %struct.addrinfo*, %struct.addrinfo** %10
%83 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %82, i32 0, i32 5
%84 = load %struct.addrinfo*, %struct.addrinfo** %83
store %struct.addrinfo* %84, %struct.addrinfo** %10
br label %38
85: ; preds = %80, %38
%86 = load %struct.addrinfo*, %struct.addrinfo** %9
%87 = call i32 @freeaddrinfo(%struct.addrinfo* %86)
%88 = load %struct.addrinfo*, %struct.addrinfo** %10
%89 = icmp eq %struct.addrinfo* %88, null
br i1 %89, label %90, label %93
90: ; preds = %85
%91 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%92 = call i32 @exit(i32 1)
unreachable
93: ; preds = %85
%94 = load i32, i32* %6
%95 = call i32 @listen(i32 %94, i32 10)
%96 = icmp eq i32 %95, 1
br i1 %96, label %97, label %100
97: ; preds = %93
%98 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
%99 = call i32 @exit(i32 1)
unreachable
100: ; preds = %93
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
br label %102
102: ; preds = %134, %100
br label %103
103: ; preds = %102
store i32 4, i32* %12
%104 = load i32, i32* %6
%105 = bitcast %struct.sockaddr_storage* %11 to %struct.sockaddr*
%106 = call i32 @accept(i32 %104, %struct.sockaddr* %105, i32* %12)
store i32 %106, i32* %7
%107 = icmp eq i32 %106, -1
br i1 %107, label %108, label %111
108: ; preds = %103
%109 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%110 = call i32 @exit(i32 1)
unreachable
111: ; preds = %103
%112 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %11, i32 0, i32 0
%113 = load i32, i32* %112
%114 = bitcast %struct.sockaddr_storage* %11 to %struct.sockaddr*
%115 = call i32 @get_in_addr(%struct.sockaddr* %114)
%116 = trunc i64 %18 to i32
%117 = call i32 @inet_ntop(i32 %113, i32 %115, i8* %20, i32 %116)
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i8* %20)
%119 = call i64 (...) @fork()
%120 = icmp eq i64 %119, 0
br i1 %120, label %121, label %134
121: ; preds = %111
%122 = load i32, i32* %6
%123 = call i32 @close(i32 %122)
%124 = load i32, i32* %7
%125 = call i32 @send(i32 %124, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i32 13, i32 0)
%126 = icmp eq i32 %125, -1
br i1 %126, label %127, label %130
127: ; preds = %121
%128 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.11, i64 0, i64 0))
%129 = call i32 @exit(i32 1)
unreachable
130: ; preds = %121
%131 = load i32, i32* %7
%132 = call i32 @close(i32 %131)
%133 = call i32 @exit(i32 0)
unreachable
134: ; preds = %111
%135 = load i32, i32* %7
%136 = call i32 @close(i32 %135)
br label %102
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"3490\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"getaddrinfo failed: %s\0A\00"
@.str.2 = [19 x i8] c"could not connect!\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [26 x i8] c"could not reclaim socket!\00"
@.str.4 = [34 x i8] c"could not bind socket to address!\00"
@.str.5 = [30 x i8] c"Could not find valid address!\00"
@.str.6 = [37 x i8] c"Could not start listening on socket!\00"
@.str.7 = [37 x i8] c"Server: Wainting for connections ...\00"
@.str.8 = [17 x i8] c"Error accepting!\00"
@.str.9 = [25 x i8] c"Server: Conneted to: %s\0A\00"
@.str.10 = [14 x i8] c"Hello, world!\00"
@.str.11 = [44 x i8] c"Failed to send message to connected client!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca %struct.sockaddr_storage
%6 = alloca i32
%7 = alloca i32
%8 = bitcast %struct.addrinfo* %3 to i8*
%9 = bitcast %struct.addrinfo** %4 to i8*
%10 = bitcast %struct.sockaddr_storage* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
store i32 1, i32* %7
%13 = load i32, i32* @INET6_ADDRSTRLEN
%14 = zext i32 %13 to i64
%15 = alloca i8, i64 %14
%16 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 40)
%17 = load i32, i32* @AF_UNSPEC
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %17, i32* %18
%19 = load i32, i32* @SOCK_STREAM
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %19, i32* %20
%21 = load i32, i32* @AI_PASSIVE
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 6
store i32 %21, i32* %22
%23 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %3, %struct.addrinfo** %4)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = load %struct.addrinfo*, %struct.addrinfo** %4
%27 = icmp eq %struct.addrinfo* %26, null
br i1 %27, label %69, label %33
28: ; preds = %2
%29 = load i32, i32* @stderr
%30 = call i8* @gai_strerror(i32 %23)
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %25, %44
%34 = phi %struct.addrinfo* [ %47, %44 ], [ %26, %25 ]
%35 = call i32 @print_address(%struct.addrinfo* %34)
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 4
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 3
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 2
%41 = load i32, i32* %40
%42 = call i32 @socket(i32 %37, i32 %39, i32 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %49
44: ; preds = %33
%45 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 5
%47 = load %struct.addrinfo*, %struct.addrinfo** %46
%48 = icmp eq %struct.addrinfo* %47, null
br i1 %48, label %67, label %33
49: ; preds = %33
%50 = load i32, i32* @SOL_SOCKET
%51 = load i32, i32* @SO_REUSEADDR
%52 = call i32 @setsockopt(i32 %42, i32 %50, i32 %51, i32* %7, i32 4)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %49
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 1
%59 = load i32, i32* %58
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 0
%61 = load i32, i32* %60
%62 = call i32 @bind(i32 %42, i32 %59, i32 %61)
%63 = icmp eq i32 %62, 1
br i1 %63, label %64, label %74
64: ; preds = %57
%65 = call i32 @close(i32 %42)
%66 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %74
67: ; preds = %44
%68 = load %struct.addrinfo*, %struct.addrinfo** %4
br label %69
69: ; preds = %67, %25
%70 = phi %struct.addrinfo* [ %68, %67 ], [ null, %25 ]
%71 = call i32 @freeaddrinfo(%struct.addrinfo* %70)
%72 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %57, %64
%75 = load %struct.addrinfo*, %struct.addrinfo** %4
%76 = call i32 @freeaddrinfo(%struct.addrinfo* %75)
%77 = call i32 @listen(i32 %42, i32 10)
%78 = icmp eq i32 %77, 1
br i1 %78, label %79, label %82
79: ; preds = %74
%80 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %74
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
%84 = bitcast %struct.sockaddr_storage* %5 to %struct.sockaddr*
store i32 4, i32* %6
%85 = call i32 @accept(i32 %42, %struct.sockaddr* %84, i32* %6)
%86 = icmp eq i32 %85, -1
br i1 %86, label %89, label %87
87: ; preds = %82
%88 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %5, i64 0, i32 0
br label %92
89: ; preds = %110, %82
%90 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%91 = call i32 @exit(i32 1)
unreachable
92: ; preds = %87, %110
%93 = phi i32 [ %85, %87 ], [ %112, %110 ]
%94 = load i32, i32* %88
%95 = call i32 @get_in_addr(%struct.sockaddr* %84)
%96 = call i32 @inet_ntop(i32 %94, i32 %95, i8* %15, i32 %13)
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i8* %15)
%98 = call i64 (...) @fork()
%99 = icmp eq i64 %98, 0
br i1 %99, label %100, label %110
100: ; preds = %92
%101 = call i32 @close(i32 %42)
%102 = call i32 @send(i32 %93, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i32 13, i32 0)
%103 = icmp eq i32 %102, -1
br i1 %103, label %104, label %107
104: ; preds = %100
%105 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.11, i64 0, i64 0))
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %100
%108 = call i32 @close(i32 %93)
%109 = call i32 @exit(i32 0)
unreachable
110: ; preds = %92
%111 = call i32 @close(i32 %93)
store i32 4, i32* %6
%112 = call i32 @accept(i32 %42, %struct.sockaddr* %84, i32* %6)
%113 = icmp eq i32 %112, -1
br i1 %113, label %89, label %92
}