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

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int AI_ALL;
int AI_PASSIVE;
int AI_V4MAPPED;
int /*<<< orphan*/ EXIT_FAILURE;
int NI_MAXHOST;
int /*<<< orphan*/ NI_NUMERICHOST;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int getnameinfo(struct sockaddr *, int, char *, int, int /*<<< orphan*/ *,
                int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int sfd, s, ns, r;
  struct addrinfo hints;
  struct addrinfo *result, *rp;
  char buf[512];
  ssize_t nread, nwrite;
  struct sockaddr_storage from;
  socklen_t fromlen;
  char host[NI_MAXHOST];
  char *message = "Message a envoyer: ";
  if (argc != 2) {
    printf("Usage: %s  port_serveur\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_INET6;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  hints.ai_flags |= AI_V4MAPPED | AI_ALL;
  hints.ai_protocol = 0;
  s = getaddrinfo(NULL, argv[1], &hints, &result);
  if (s != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
    exit(EXIT_FAILURE);
  }
  for (rp = result; rp != NULL; rp = rp->ai_next) {
    sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
    if (sfd == -1)
      continue;
    r = bind(sfd, rp->ai_addr, rp->ai_addrlen);
    if (r == 0)
      break;
    close(sfd);
  }
  if (rp == NULL) {
    perror("bind");
    exit(EXIT_FAILURE);
  }
  freeaddrinfo(result);
  listen(sfd, 1);
  for (;;) {
    fromlen = sizeof(from);
    ns = accept(sfd, (struct sockaddr *)&from, &fromlen);
    if (ns == -1) {
      perror("accept");
      exit(EXIT_FAILURE);
    }
    s = getnameinfo((struct sockaddr *)&from, fromlen, host, NI_MAXHOST, NULL,
                    0, NI_NUMERICHOST);
    if (s == 0)
      printf("Debut avec client '%s'\n", host);
    else
      fprintf(stderr, "getnameinfo: %s\n", gai_strerror(s));
    for (;;) {
      nwrite = write(ns, message, strlen(message));
      if (nwrite < 0) {
        perror("write");
        close(ns);
        break;
      }
      nread = read(ns, buf, 512);
      if (nread == 0) {
        printf("Fin avec client '%s'\n", host);
        close(ns);
        break;
      } else if (nread < 0) {
        perror("read");
        close(ns);
        break;
      }
      buf[nread] = '\0';
      printf("Message recu '%s'\n", buf);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x288(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x2a0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x290(%rbp)
lea    0xd9b(%rip),%rax
mov    %rax,-0x298(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1297 <main+0x87>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd90(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2cfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
mov    0x2ced(%rip),%rcx
or     (%rcx),%eax
or     -0x48(%rbp),%eax
mov    %eax,-0x48(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x48(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1110 <getaddrinfo@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     134b <main+0x13b>
mov    0x2ca8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2a4(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <gai_strerror@plt>
mov    -0x2a4(%rbp),%edi
mov    %rax,%rdx
lea    0xcf5(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     13cc <main+0x1bc>
mov    -0x58(%rbp),%rax
mov    0x1c(%rax),%edi
mov    -0x58(%rbp),%rax
mov    0x18(%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%rdx
call   1130 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    138b <main+0x17b>
jmp    13bb <main+0x1ab>
mov    -0x14(%rbp),%edi
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x4(%rax),%edx
call   10d0 <bind@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    13b3 <main+0x1a3>
jmp    13cc <main+0x1bc>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    -0x58(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    1353 <main+0x143>
cmpq   $0x0,-0x58(%rbp)
jne    13f1 <main+0x1e1>
lea    0xc60(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2bbe(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x50(%rbp),%rdi
call   1120 <freeaddrinfo@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   10c0 <listen@plt>
movl   $0x4,-0x27c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x278(%rbp),%rsi
lea    -0x27c(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    144e <main+0x23e>
lea    0xc08(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2b61(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x2a0(%rbp),%rdx
lea    -0x278(%rbp),%rdi
mov    -0x27c(%rbp),%esi
mov    0x2b37(%rip),%rax
mov    (%rax),%ecx
mov    0x2b3e(%rip),%rax
mov    (%rax),%eax
xor    %r8d,%r8d
xor    %r9d,%r9d
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1090 <getnameinfo@plt>
add    $0x10,%rsp
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    14af <main+0x29f>
mov    -0x2a0(%rbp),%rsi
lea    0xba5(%rip),%rdi
call   1050 <printf@plt>
jmp    14db <main+0x2cb>
mov    0x2b0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2a8(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <gai_strerror@plt>
mov    -0x2a8(%rbp),%edi
mov    %rax,%rdx
lea    0xb8c(%rip),%rsi
call   10b0 <fprintf@plt>
jmp    14e0 <main+0x2d0>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2b4(%rbp)
mov    -0x298(%rbp),%rax
mov    %rax,-0x2b0(%rbp)
mov    -0x298(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2b4(%rbp),%edi
mov    -0x2b0(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rax,-0x270(%rbp)
cmpq   $0x0,-0x270(%rbp)
jge    1545 <main+0x335>
lea    0xb40(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
jmp    15e1 <main+0x3d1>
mov    -0x1c(%rbp),%edi
lea    -0x260(%rbp),%rsi
mov    $0x200,%edx
call   10a0 <read@plt>
mov    %rax,-0x268(%rbp)
cmpq   $0x0,-0x268(%rbp)
jne    158e <main+0x37e>
mov    -0x2a0(%rbp),%rsi
lea    0xafd(%rip),%rdi
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
jmp    15e1 <main+0x3d1>
cmpq   $0x0,-0x268(%rbp)
jge    15b5 <main+0x3a5>
lea    0xaec(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
jmp    15e1 <main+0x3d1>
jmp    15ba <main+0x3aa>
mov    -0x268(%rbp),%rax
movb   $0x0,-0x260(%rbp,%rax,1)
lea    -0x260(%rbp),%rsi
lea    0xabd(%rip),%rdi
call   1050 <printf@plt>
jmp    14e0 <main+0x2d0>
jmp    1407 <main+0x1f7>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x248,%rsp
mov    %rsi,%rbx
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
cmp    $0x2,%edi
jne    12fb <main+0xeb>
lea    -0x70(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2d48(%rip),%rax
mov    0x2d69(%rip),%rcx
mov    0x2d6a(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    (%rax),%eax
mov    0x2d3d(%rip),%rcx
or     (%rcx),%edx
mov    %eax,-0x58(%rbp)
mov    %edx,-0x70(%rbp)
movq   $0x0,-0x60(%rbp)
mov    0x8(%rbx),%rsi
lea    -0x48(%rbp),%rcx
xor    %edi,%edi
mov    %r14,%rdx
call   1110 <getaddrinfo@plt>
test   %eax,%eax
jne    130c <main+0xfc>
mov    -0x48(%rbp),%rbx
jmp    12c4 <main+0xb4>
nopw   0x0(%rax,%rax,1)
mov    0x20(%rbx),%rbx
test   %rbx,%rbx
je     132f <main+0x11f>
mov    0x1c(%rbx),%edi
mov    0x18(%rbx),%esi
mov    0x10(%rbx),%rdx
call   1130 <socket@plt>
cmp    $0xffffffff,%eax
je     12c0 <main+0xb0>
mov    %eax,%r13d
mov    0x4(%rbx),%edx
mov    0x8(%rbx),%esi
mov    %eax,%edi
call   10d0 <bind@plt>
test   %eax,%eax
je     1349 <main+0x139>
mov    %r13d,%edi
call   1080 <close@plt>
jmp    12c0 <main+0xb0>
mov    (%rbx),%rsi
lea    0xd0f(%rip),%rdi
call   1050 <printf@plt>
jmp    133b <main+0x12b>
mov    0x2cad(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1060 <gai_strerror@plt>
lea    0xd0a(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10b0 <fprintf@plt>
jmp    133b <main+0x12b>
lea    0xd08(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c66(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    %r15,-0x40(%rbp)
mov    -0x48(%rbp),%rdi
call   1120 <freeaddrinfo@plt>
mov    %r13d,%edi
mov    $0x1,%esi
call   10c0 <listen@plt>
movl   $0x4,-0x2c(%rbp)
lea    -0x30(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
mov    %r13d,%edi
call   10f0 <accept@plt>
cmp    $0xffffffff,%eax
jne    1388 <main+0x178>
lea    0xcbd(%rip),%rdi
jmp    1336 <main+0x126>
mov    %eax,%r12d
lea    -0x30(%rbp),%rdi
lea    0xc6a(%rip),%rbx
lea    -0x270(%rbp),%r15
lea    0xcf0(%rip),%r14
mov    %r13d,-0x34(%rbp)
jmp    13ed <main+0x1dd>
nopw   0x0(%rax,%rax,1)
lea    0xcc2(%rip),%rdi
mov    -0x40(%rbp),%rsi
call   1050 <printf@plt>
mov    %r12d,%edi
call   1080 <close@plt>
movl   $0x4,-0x2c(%rbp)
mov    %r13d,%edi
lea    -0x30(%rbp),%r12
mov    %r12,%rsi
lea    -0x2c(%rbp),%rdx
call   10f0 <accept@plt>
mov    %r12,%rdi
mov    %eax,%r12d
cmp    $0xffffffff,%eax
je     137f <main+0x16f>
mov    -0x2c(%rbp),%esi
mov    0x2ba9(%rip),%rax
mov    (%rax),%ecx
mov    0x2bb0(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
mov    -0x40(%rbp),%r13
mov    %r13,%rdx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %rax
call   1090 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
je     1450 <main+0x240>
mov    0x2b98(%rip),%rcx
mov    (%rcx),%r13d
mov    %eax,%edi
call   1060 <gai_strerror@plt>
mov    %r13d,%edi
lea    0xc26(%rip),%rsi
mov    %rax,%rdx
call   10b0 <fprintf@plt>
jmp    145f <main+0x24f>
cs nopw 0x0(%rax,%rax,1)
lea    0xbf3(%rip),%rdi
mov    %r13,%rsi
call   1050 <printf@plt>
mov    -0x34(%rbp),%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
js     14ba <main+0x2aa>
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x200,%edx
call   10a0 <read@plt>
test   %rax,%rax
je     13b0 <main+0x1a0>
js     14c3 <main+0x2b3>
movb   $0x0,-0x270(%rbp,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
jmp    1470 <main+0x260>
lea    0xbb2(%rip),%rdi
jmp    14ca <main+0x2ba>
lea    0xbc5(%rip),%rdi
call   10e0 <perror@plt>
jmp    13c0 <main+0x1b0>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i64, i32, i32, %struct.addrinfo* }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@.str = [20 x i8] c"Message a envoyer: \00"
@.str.1 = [25 x i8] c"Usage: %s port_serveur\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET6 = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@AI_V4MAPPED = global i32 0
@AI_ALL = global i32 0
@stderr = global i32 0
@.str.2 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"accept\00"
@NI_NUMERICHOST = global i32 0
@.str.5 = [24 x i8] c"Debut avec client '%s'\0A\00"
@.str.6 = [17 x i8] c"getnameinfo: %s\0A\00"
@.str.7 = [6 x i8] c"write\00"
@.str.8 = [22 x i8] c"Fin avec client '%s'\0A\00"
@.str.9 = [5 x i8] c"read\00"
@.str.10 = [19 x i8] c"Message recu '%s'\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 %struct.addrinfo
%11 = alloca %struct.addrinfo*
%12 = alloca %struct.addrinfo*
%13 = alloca [512 x i8]
%14 = alloca i64
%15 = alloca i64
%16 = alloca %struct.sockaddr_storage
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i64
%20 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%21 = load i32, i32* @NI_MAXHOST
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %18
%24 = alloca i8, i64 %22
store i64 %22, i64* %19
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8** %20
%25 = load i32, i32* %4
%26 = icmp ne i32 %25, 2
br i1 %26, label %27, label %34
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %2
%35 = call i32 @memset(%struct.addrinfo* %10, i32 0, i32 40)
%36 = load i32, i32* @AF_INET6
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 5
store i32 %36, i32* %37
%38 = load i32, i32* @SOCK_STREAM
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 4
store i32 %38, i32* %39
%40 = load i32, i32* @AI_PASSIVE
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 0
store i32 %40, i32* %41
%42 = load i32, i32* @AI_V4MAPPED
%43 = load i32, i32* @AI_ALL
%44 = or i32 %42, %43
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 0
%46 = load i32, i32* %45
%47 = or i32 %46, %44
store i32 %47, i32* %45
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 3
store i64 0, i64* %48
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call i32 @getaddrinfo(i32* null, i8* %51, %struct.addrinfo* %10, %struct.addrinfo** %11)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %62
55: ; preds = %34
%56 = load i32, i32* @stderr
%57 = load i32, i32* %7
%58 = call i8* @gai_strerror(i32 %57)
%59 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %58)
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %34
%63 = load %struct.addrinfo*, %struct.addrinfo** %11
store %struct.addrinfo* %63, %struct.addrinfo** %12
br label %64
64: ; preds = %96, %62
%65 = load %struct.addrinfo*, %struct.addrinfo** %12
%66 = icmp ne %struct.addrinfo* %65, null
br i1 %66, label %67, label %100
67: ; preds = %64
%68 = load %struct.addrinfo*, %struct.addrinfo** %12
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %68, i32 0, i32 5
%70 = load i32, i32* %69
%71 = load %struct.addrinfo*, %struct.addrinfo** %12
%72 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %71, i32 0, i32 4
%73 = load i32, i32* %72
%74 = load %struct.addrinfo*, %struct.addrinfo** %12
%75 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %74, i32 0, i32 3
%76 = load i64, i64* %75
%77 = call i32 @socket(i32 %70, i32 %73, i64 %76)
store i32 %77, i32* %6
%78 = load i32, i32* %6
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %81
80: ; preds = %67
br label %96
81: ; preds = %67
%82 = load i32, i32* %6
%83 = load %struct.addrinfo*, %struct.addrinfo** %12
%84 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %83, i32 0, i32 2
%85 = load i32, i32* %84
%86 = load %struct.addrinfo*, %struct.addrinfo** %12
%87 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %86, i32 0, i32 1
%88 = load i32, i32* %87
%89 = call i32 @bind(i32 %82, i32 %85, i32 %88)
store i32 %89, i32* %9
%90 = load i32, i32* %9
%91 = icmp eq i32 %90, 0
br i1 %91, label %92, label %93
92: ; preds = %81
br label %100
93: ; preds = %81
%94 = load i32, i32* %6
%95 = call i32 @close(i32 %94)
br label %96
96: ; preds = %93, %80
%97 = load %struct.addrinfo*, %struct.addrinfo** %12
%98 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %97, i32 0, i32 6
%99 = load %struct.addrinfo*, %struct.addrinfo** %98
store %struct.addrinfo* %99, %struct.addrinfo** %12
br label %64
100: ; preds = %92, %64
%101 = load %struct.addrinfo*, %struct.addrinfo** %12
%102 = icmp eq %struct.addrinfo* %101, null
br i1 %102, label %103, label %107
103: ; preds = %100
%104 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%105 = load i32, i32* @EXIT_FAILURE
%106 = call i32 @exit(i32 %105)
unreachable
107: ; preds = %100
%108 = load %struct.addrinfo*, %struct.addrinfo** %11
%109 = call i32 @freeaddrinfo(%struct.addrinfo* %108)
%110 = load i32, i32* %6
%111 = call i32 @listen(i32 %110, i32 1)
br label %112
112: ; preds = %173, %107
store i32 4, i32* %17
%113 = load i32, i32* %6
%114 = bitcast %struct.sockaddr_storage* %16 to %struct.sockaddr*
%115 = call i32 @accept(i32 %113, %struct.sockaddr* %114, i32* %17)
store i32 %115, i32* %8
%116 = load i32, i32* %8
%117 = icmp eq i32 %116, -1
br i1 %117, label %118, label %122
118: ; preds = %112
%119 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%120 = load i32, i32* @EXIT_FAILURE
%121 = call i32 @exit(i32 %120)
unreachable
122: ; preds = %112
%123 = bitcast %struct.sockaddr_storage* %16 to %struct.sockaddr*
%124 = load i32, i32* %17
%125 = load i32, i32* @NI_MAXHOST
%126 = load i32, i32* @NI_NUMERICHOST
%127 = call i32 @getnameinfo(%struct.sockaddr* %123, i32 %124, i8* %24, i32 %125, i32* null, i32 0, i32 %126)
store i32 %127, i32* %7
%128 = load i32, i32* %7
%129 = icmp eq i32 %128, 0
br i1 %129, label %130, label %132
130: ; preds = %122
%131 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %24)
br label %137
132: ; preds = %122
%133 = load i32, i32* @stderr
%134 = load i32, i32* %7
%135 = call i8* @gai_strerror(i32 %134)
%136 = call i32 @fprintf(i32 %133, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %135)
br label %137
137: ; preds = %132, %130
br label %138
138: ; preds = %168, %137
%139 = load i32, i32* %8
%140 = load i8*, i8** %20
%141 = load i8*, i8** %20
%142 = call i32 @strlen(i8* %141)
%143 = call i64 @write(i32 %139, i8* %140, i32 %142)
store i64 %143, i64* %15
%144 = load i64, i64* %15
%145 = icmp slt i64 %144, 0
br i1 %145, label %146, label %150
146: ; preds = %138
%147 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%148 = load i32, i32* %8
%149 = call i32 @close(i32 %148)
br label %173
150: ; preds = %138
%151 = load i32, i32* %8
%152 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%153 = call i64 @read(i32 %151, i8* %152, i32 512)
store i64 %153, i64* %14
%154 = load i64, i64* %14
%155 = icmp eq i64 %154, 0
br i1 %155, label %156, label %160
156: ; preds = %150
%157 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %24)
%158 = load i32, i32* %8
%159 = call i32 @close(i32 %158)
br label %173
160: ; preds = %150
%161 = load i64, i64* %14
%162 = icmp slt i64 %161, 0
br i1 %162, label %163, label %167
163: ; preds = %160
%164 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%165 = load i32, i32* %8
%166 = call i32 @close(i32 %165)
br label %173
167: ; preds = %160
br label %168
168: ; preds = %167
%169 = load i64, i64* %14
%170 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 %169
store i8 0, i8* %170
%171 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%172 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i8* %171)
br label %138
173: ; preds = %163, %156, %146
br label %112
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i64, i32, i32, %struct.addrinfo* }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@.str = [20 x i8] c"Message a envoyer: \00"
@.str.1 = [25 x i8] c"Usage: %s port_serveur\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET6 = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@AI_V4MAPPED = global i32 0
@AI_ALL = global i32 0
@stderr = global i32 0
@.str.2 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"accept\00"
@NI_NUMERICHOST = global i32 0
@.str.5 = [24 x i8] c"Debut avec client '%s'\0A\00"
@.str.6 = [17 x i8] c"getnameinfo: %s\0A\00"
@.str.7 = [6 x i8] c"write\00"
@.str.8 = [22 x i8] c"Fin avec client '%s'\0A\00"
@.str.9 = [5 x i8] c"read\00"
@.str.10 = [19 x i8] c"Message recu '%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca [512 x i8]
%6 = alloca %struct.sockaddr_storage
%7 = alloca i32
%8 = bitcast %struct.addrinfo* %3 to i8*
%9 = bitcast %struct.addrinfo** %4 to i8*
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%11 = bitcast %struct.sockaddr_storage* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = load i32, i32* @NI_MAXHOST
%14 = zext i32 %13 to i64
%15 = alloca i8, i64 %14
%16 = icmp eq i32 %0, 2
br i1 %16, label %22, label %17
17: ; preds = %2
%18 = load i8*, i8** %1
%19 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 40)
%24 = load i32, i32* @AF_INET6
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store i32 %24, i32* %25
%26 = load i32, i32* @SOCK_STREAM
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %26, i32* %27
%28 = load i32, i32* @AI_PASSIVE
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 0
%30 = load i32, i32* @AI_V4MAPPED
%31 = load i32, i32* @AI_ALL
%32 = or i32 %30, %28
%33 = or i32 %32, %31
store i32 %33, i32* %29
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i64 0, i64* %34
%35 = getelementptr inbounds i8*, i8** %1, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @getaddrinfo(i32* null, i8* %36, %struct.addrinfo* %3, %struct.addrinfo** %4)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %22
%40 = load %struct.addrinfo*, %struct.addrinfo** %4
%41 = icmp eq %struct.addrinfo* %40, null
br i1 %41, label %71, label %48
42: ; preds = %22
%43 = load i32, i32* @stderr
%44 = call i8* @gai_strerror(i32 %37)
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %39, %67
%49 = phi %struct.addrinfo* [ %69, %67 ], [ %40, %39 ]
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i64 0, i32 5
%51 = load i32, i32* %50
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i64 0, i32 4
%53 = load i32, i32* %52
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i64 0, i32 3
%55 = load i64, i64* %54
%56 = call i32 @socket(i32 %51, i32 %53, i64 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %67, label %58
58: ; preds = %48
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i64 0, i32 2
%60 = load i32, i32* %59
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i64 0, i32 1
%62 = load i32, i32* %61
%63 = call i32 @bind(i32 %56, i32 %60, i32 %62)
%64 = icmp eq i32 %63, 0
br i1 %64, label %75, label %65
65: ; preds = %58
%66 = call i32 @close(i32 %56)
br label %67
67: ; preds = %48, %65
%68 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i64 0, i32 6
%69 = load %struct.addrinfo*, %struct.addrinfo** %68
%70 = icmp eq %struct.addrinfo* %69, null
br i1 %70, label %71, label %48
71: ; preds = %67, %39
%72 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %58
%76 = load %struct.addrinfo*, %struct.addrinfo** %4
%77 = call i32 @freeaddrinfo(%struct.addrinfo* %76)
%78 = call i32 @listen(i32 %56, i32 1)
%79 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
store i32 4, i32* %7
%80 = call i32 @accept(i32 %56, %struct.sockaddr* %79, i32* %7)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %86
82: ; preds = %120, %75
%83 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%84 = load i32, i32* @EXIT_FAILURE
%85 = call i32 @exit(i32 %84)
unreachable
86: ; preds = %75, %120
%87 = phi i32 [ %122, %120 ], [ %80, %75 ]
%88 = load i32, i32* %7
%89 = load i32, i32* @NI_MAXHOST
%90 = load i32, i32* @NI_NUMERICHOST
%91 = call i32 @getnameinfo(%struct.sockaddr* %79, i32 %88, i8* %15, i32 %89, i32* null, i32 0, i32 %90)
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %86
%94 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %15)
br label %99
95: ; preds = %86
%96 = load i32, i32* @stderr
%97 = call i8* @gai_strerror(i32 %91)
%98 = call i32 @fprintf(i32 %96, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %97)
br label %99
99: ; preds = %95, %93
%100 = call i32 @strlen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%101 = call i64 @write(i32 %87, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %100)
%102 = icmp slt i64 %101, 0
br i1 %102, label %103, label %105
103: ; preds = %114, %99
%104 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %120
105: ; preds = %99, %114
%106 = call i64 @read(i32 %87, i8* %10, i32 512)
%107 = icmp eq i64 %106, 0
br i1 %107, label %108, label %110
108: ; preds = %105
%109 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %15)
br label %120
110: ; preds = %105
%111 = icmp slt i64 %106, 0
br i1 %111, label %112, label %114
112: ; preds = %110
%113 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %120
114: ; preds = %110
%115 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %106
store i8 0, i8* %115
%116 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i8* %10)
%117 = call i32 @strlen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%118 = call i64 @write(i32 %87, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %117)
%119 = icmp slt i64 %118, 0
br i1 %119, label %103, label %105
120: ; preds = %112, %108, %103
%121 = call i32 @close(i32 %87)
store i32 4, i32* %7
%122 = call i32 @accept(i32 %56, %struct.sockaddr* %79, i32* %7)
%123 = icmp eq i32 %122, -1
br i1 %123, label %82, label %86
}