#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 addrinfo {
  struct addrinfo *ai_next;
  scalar_t__ ai_addrlen;
  int /*<<< orphan*/ *ai_addr;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  scalar_t__ ai_flags;
  int /*<<< orphan*/ *ai_canonname;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int NI_MAXHOST;
int NI_MAXSERV;
int NI_NUMERICHOST;
int NI_NUMERICSERV;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ applog(int, char *, char const *, ...);
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/ *, scalar_t__);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int getnameinfo(int /*<<< orphan*/ *, scalar_t__, char *, int, char *, int,
                int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int connect_to(const char *ip, const char *port, int *sock) {
  struct addrinfo hints;
  struct addrinfo *result;
  char host_name[NI_MAXHOST], numeric_port[NI_MAXSERV];
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_addr = NULL;
  hints.ai_addrlen = 0;
  hints.ai_canonname = NULL;
  hints.ai_flags = 0;
  hints.ai_next = NULL;
  hints.ai_protocol = 0;
  int res = getaddrinfo(ip, port, &hints, &result);
  if (res != 0) {
    applog(2,
           "[Network] Erreur lors de la recherche sur %s:%s."
           " Erreur : %s.\n",
           gai_strerror(res));
    return -2;
  }
  int has_valid_socket = 0;
  struct addrinfo *addr_info = result;
  while (addr_info != NULL && has_valid_socket != 1) {
    res = getnameinfo(addr_info->ai_addr, addr_info->ai_addrlen, host_name,
                      NI_MAXHOST, numeric_port, NI_MAXSERV,
                      NI_NUMERICHOST | NI_NUMERICSERV);
    if (res != 0) {
      applog(2,
             "[Network] Erreur lors de la récupération "
             "des informations. Erreur : %s.\n",
             gai_strerror(res));
      return -3;
    }
    int attempted_socket = socket(addr_info->ai_family, addr_info->ai_socktype,
                                  addr_info->ai_protocol);
    if (attempted_socket == -1) {
      applog(2,
             "[Network] Erreur lors de la création de la "
             "socket. Erreur : %s.\n",
             strerror(errno));
      continue;
    }
    res = connect(attempted_socket, addr_info->ai_addr, addr_info->ai_addrlen);
    if (res == 0) {
      has_valid_socket = 1;
      *sock = attempted_socket;
      applog(0,
             "[Network] Connexion en attente sur le serveur "
             "%s:%s.\n",
             host_name, numeric_port);
    } else {
      applog(2,
             "[Network] Echec de la connexion. Erreur: %s."
             "\n",
             strerror(errno));
      close(attempted_socket);
      addr_info = addr_info->ai_next;
    }
  }
  freeaddrinfo(result);
  if (has_valid_socket == 0) {
    applog(2,
           "[Network] Impossible de se connecter au serveur "
           "%s:%s.\n",
           ip, port);
    return -4;
  }
  return -1;
}


x86 assembly (clang, -O0):
<connect_to>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xa8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x70(%rbp)
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xa0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x78(%rbp)
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x58(%rbp),%rdx
lea    -0x60(%rbp),%rcx
call   1090 <getaddrinfo@plt>
mov    %eax,-0x7c(%rbp)
cmpl   $0x0,-0x7c(%rbp)
je     12b9 <connect_to+0x119>
mov    -0x7c(%rbp),%edi
call   1030 <gai_strerror@plt>
movslq %eax,%rdx
mov    $0x2,%edi
lea    0xd61(%rip),%rsi
mov    $0x0,%al
call   1070 <applog@plt>
movl   $0xfffffffe,-0x4(%rbp)
movl   $0x1,-0x80(%rbp)
jmp    14fd <connect_to+0x35d>
movl   $0x0,-0x84(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x90(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x90(%rbp)
mov    %al,-0xa9(%rbp)
je     12f4 <connect_to+0x154>
cmpl   $0x1,-0x84(%rbp)
setne  %al
mov    %al,-0xa9(%rbp)
mov    -0xa9(%rbp),%al
test   $0x1,%al
jne    1307 <connect_to+0x167>
jmp    14ab <connect_to+0x30b>
mov    -0xa0(%rbp),%r8
mov    -0xa8(%rbp),%rdx
mov    -0x90(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x90(%rbp),%rax
mov    0x8(%rax),%rsi
mov    0x2c7e(%rip),%rax
mov    (%rax),%ecx
mov    0x2c9d(%rip),%rax
mov    (%rax),%r9d
mov    0x2c7b(%rip),%rax
mov    (%rax),%eax
mov    0x2c9a(%rip),%r10
or     (%r10),%eax
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1060 <getnameinfo@plt>
add    $0x10,%rsp
mov    %eax,-0x7c(%rbp)
cmpl   $0x0,-0x7c(%rbp)
je     139f <connect_to+0x1ff>
mov    -0x7c(%rbp),%edi
call   1030 <gai_strerror@plt>
movslq %eax,%rdx
mov    $0x2,%edi
lea    0xcba(%rip),%rsi
mov    $0x0,%al
call   1070 <applog@plt>
movl   $0xfffffffd,-0x4(%rbp)
movl   $0x1,-0x80(%rbp)
jmp    14fd <connect_to+0x35d>
mov    -0x90(%rbp),%rax
mov    0x24(%rax),%edi
mov    -0x90(%rbp),%rax
mov    0x20(%rax),%esi
mov    -0x90(%rbp),%rax
mov    0x18(%rax),%rdx
call   10c0 <socket@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0xffffffff,-0x94(%rbp)
jne    13ff <connect_to+0x25f>
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
movslq %eax,%rdx
mov    $0x2,%edi
lea    0xc97(%rip),%rsi
mov    $0x0,%al
call   1070 <applog@plt>
jmp    12ce <connect_to+0x12e>
mov    -0x94(%rbp),%edi
mov    -0x90(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x90(%rbp),%rax
mov    0x8(%rax),%rdx
call   1080 <connect@plt>
mov    %eax,-0x7c(%rbp)
cmpl   $0x0,-0x7c(%rbp)
jne    1466 <connect_to+0x2c6>
mov    -0xa0(%rbp),%rcx
mov    -0xa8(%rbp),%rdx
movl   $0x1,-0x84(%rbp)
mov    -0x94(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    %esi,(%rax)
xor    %edi,%edi
lea    0xc72(%rip),%rsi
mov    $0x0,%al
call   1070 <applog@plt>
jmp    14a6 <connect_to+0x306>
mov    0x2b4b(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
movslq %eax,%rdx
mov    $0x2,%edi
lea    0xc7f(%rip),%rsi
mov    $0x0,%al
call   1070 <applog@plt>
mov    -0x94(%rbp),%edi
call   1050 <close@plt>
mov    -0x90(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x90(%rbp)
jmp    12ce <connect_to+0x12e>
mov    -0x60(%rbp),%rdi
call   10b0 <freeaddrinfo@plt>
cmpl   $0x0,-0x84(%rbp)
jne    14ef <connect_to+0x34f>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x2,%edi
lea    0xc5b(%rip),%rsi
mov    $0x0,%al
call   1070 <applog@plt>
movl   $0xfffffffc,-0x4(%rbp)
movl   $0x1,-0x80(%rbp)
jmp    14fd <connect_to+0x35d>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x80(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect_to>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdx,-0x50(%rbp)
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,-0x30(%rbp)
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x90(%rbp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
xorps  %xmm0,%xmm0
movaps %xmm0,-0x90(%rbp)
movaps %xmm0,-0x80(%rbp)
movups %xmm0,-0x68(%rbp)
lea    -0x48(%rbp),%rcx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <getaddrinfo@plt>
test   %eax,%eax
je     1274 <connect_to+0xd4>
mov    %eax,%edi
call   1030 <gai_strerror@plt>
movslq %eax,%rdx
lea    0xda6(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1070 <applog@plt>
mov    $0xfffffffe,%eax
mov    -0x30(%rbp),%r14
jmp    13d4 <connect_to+0x234>
mov    %r14,-0x38(%rbp)
mov    %rbx,-0x40(%rbp)
mov    -0x48(%rbp),%r14
test   %r14,%r14
jne    12d5 <connect_to+0x135>
xor    %edi,%edi
mov    -0x30(%rbp),%r14
mov    -0x40(%rbp),%r15
mov    -0x38(%rbp),%rbx
jmp    13b1 <connect_to+0x211>
nopl   0x0(%rax,%rax,1)
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
movslq %eax,%rdx
mov    $0x2,%edi
lea    0xdcd(%rip),%rsi
xor    %eax,%eax
call   1070 <applog@plt>
mov    -0x40(%rbp),%r15
mov    -0x38(%rbp),%rbx
test   %r14,%r14
je     13a9 <connect_to+0x209>
mov    0x8(%r14),%rsi
mov    0x10(%r14),%rdi
mov    0x2ccc(%rip),%rax
mov    (%rax),%ecx
mov    0x2ceb(%rip),%rax
mov    (%rax),%r9d
mov    0x2cf1(%rip),%rax
mov    (%rax),%eax
mov    0x2cc0(%rip),%rdx
or     (%rdx),%eax
sub    $0x8,%rsp
mov    %r13,%rdx
mov    %r12,%r8
push   %rax
call   1060 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    1382 <connect_to+0x1e2>
mov    0x24(%r14),%edi
mov    0x20(%r14),%esi
mov    0x18(%r14),%rdx
call   10c0 <socket@plt>
cmp    $0xffffffff,%eax
je     12a0 <connect_to+0x100>
mov    %eax,%r15d
mov    0x8(%r14),%rdx
mov    0x10(%r14),%rsi
mov    %eax,%edi
call   1080 <connect@plt>
test   %eax,%eax
je     13e6 <connect_to+0x246>
mov    0x2c63(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
movslq %eax,%rdx
mov    $0x2,%edi
lea    0xd97(%rip),%rsi
xor    %eax,%eax
call   1070 <applog@plt>
mov    %r15d,%edi
call   1050 <close@plt>
mov    (%r14),%r14
jmp    12c4 <connect_to+0x124>
mov    %eax,%edi
call   1030 <gai_strerror@plt>
movslq %eax,%rdx
lea    0xcac(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1070 <applog@plt>
mov    $0xfffffffd,%eax
jmp    126b <connect_to+0xcb>
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%r14
call   10b0 <freeaddrinfo@plt>
lea    0xd73(%rip),%rsi
mov    $0x2,%edi
mov    %rbx,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <applog@plt>
mov    $0xfffffffc,%eax
mov    %r14,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    -0x50(%rbp),%rax
mov    %r15d,(%rax)
lea    0xcd8(%rip),%rsi
xor    %edi,%edi
mov    %r13,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1070 <applog@plt>
mov    -0x48(%rbp),%rdi
call   10b0 <freeaddrinfo@plt>
mov    $0xffffffff,%eax
jmp    126b <connect_to+0xcb>

LLVM IR (-O0):
%struct.addrinfo = type { %struct.addrinfo*, i64, i32*, i64, i32, i32, i64, i32* }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [63 x i8] c"[Network] Erreur lors de la recherche sur %s:%s. Erreur : %s.\0A\00"
@NI_NUMERICHOST = global i32 0
@NI_NUMERICSERV = global i32 0
@.str.1 = [75 x i8] c"[Network] Erreur lors de la r\C3\A9cup\C3\A9ration des informations. Erreur : %s.\0A\00"
@.str.2 = [66 x i8] c"[Network] Erreur lors de la cr\C3\A9ation de la socket. Erreur : %s.\0A\00"
@errno = global i32 0
@.str.3 = [54 x i8] c"[Network] Connexion en attente sur le serveur %s:%s.\0A\00"
@.str.4 = [46 x i8] c"[Network] Echec de la connexion. Erreur: %s.\0A\00"
@.str.5 = [56 x i8] c"[Network] Impossible de se connecter au serveur %s:%s.\0A\00"
define i32 @connect_to(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca %struct.addrinfo
%9 = alloca %struct.addrinfo*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.addrinfo*
%17 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%18 = load i32, i32* @NI_MAXHOST
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %10
%21 = alloca i8, i64 %19
store i64 %19, i64* %11
%22 = load i32, i32* @NI_MAXSERV
%23 = zext i32 %22 to i64
%24 = alloca i8, i64 %23
store i64 %23, i64* %12
%25 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 56)
%26 = load i32, i32* @AF_UNSPEC
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 5
store i32 %26, i32* %27
%28 = load i32, i32* @SOCK_STREAM
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 4
store i32 %28, i32* %29
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 2
store i32* null, i32** %30
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 1
store i64 0, i64* %31
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 7
store i32* null, i32** %32
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 6
store i64 0, i64* %33
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 0
store %struct.addrinfo* null, %struct.addrinfo** %34
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 3
store i64 0, i64* %35
%36 = load i8*, i8** %5
%37 = load i8*, i8** %6
%38 = call i32 @getaddrinfo(i8* %36, i8* %37, %struct.addrinfo* %8, %struct.addrinfo** %9)
store i32 %38, i32* %13
%39 = load i32, i32* %13
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %3
%42 = load i32, i32* %13
%43 = call i32 @gai_strerror(i32 %42)
%44 = sext i32 %43 to i64
%45 = inttoptr i64 %44 to i8*
%46 = call i32 (i32, i8*, i8*, ...) @applog(i32 2, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %45)
store i32 -2, i32* %4
store i32 1, i32* %14
br label %134
47: ; preds = %3
store i32 0, i32* %15
%48 = load %struct.addrinfo*, %struct.addrinfo** %9
store %struct.addrinfo* %48, %struct.addrinfo** %16
br label %49
49: ; preds = %123, %91, %47
%50 = load %struct.addrinfo*, %struct.addrinfo** %16
%51 = icmp ne %struct.addrinfo* %50, null
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i32, i32* %15
%54 = icmp ne i32 %53, 1
br label %55
55: ; preds = %52, %49
%56 = phi i1 [ false, %49 ], [ %54, %52 ]
br i1 %56, label %57, label %124
57: ; preds = %55
%58 = load %struct.addrinfo*, %struct.addrinfo** %16
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %58, i32 0, i32 2
%60 = load i32*, i32** %59
%61 = load %struct.addrinfo*, %struct.addrinfo** %16
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %61, i32 0, i32 1
%63 = load i64, i64* %62
%64 = load i32, i32* @NI_MAXHOST
%65 = load i32, i32* @NI_MAXSERV
%66 = load i32, i32* @NI_NUMERICHOST
%67 = load i32, i32* @NI_NUMERICSERV
%68 = or i32 %66, %67
%69 = call i32 @getnameinfo(i32* %60, i64 %63, i8* %21, i32 %64, i8* %24, i32 %65, i32 %68)
store i32 %69, i32* %13
%70 = load i32, i32* %13
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %78
72: ; preds = %57
%73 = load i32, i32* %13
%74 = call i32 @gai_strerror(i32 %73)
%75 = sext i32 %74 to i64
%76 = inttoptr i64 %75 to i8*
%77 = call i32 (i32, i8*, i8*, ...) @applog(i32 2, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0), i8* %76)
store i32 -3, i32* %4
store i32 1, i32* %14
br label %134
78: ; preds = %57
%79 = load %struct.addrinfo*, %struct.addrinfo** %16
%80 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %79, i32 0, i32 5
%81 = load i32, i32* %80
%82 = load %struct.addrinfo*, %struct.addrinfo** %16
%83 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %82, i32 0, i32 4
%84 = load i32, i32* %83
%85 = load %struct.addrinfo*, %struct.addrinfo** %16
%86 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %85, i32 0, i32 3
%87 = load i64, i64* %86
%88 = call i32 @socket(i32 %81, i32 %84, i64 %87)
store i32 %88, i32* %17
%89 = load i32, i32* %17
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %97
91: ; preds = %78
%92 = load i32, i32* @errno
%93 = call i32 @strerror(i32 %92)
%94 = sext i32 %93 to i64
%95 = inttoptr i64 %94 to i8*
%96 = call i32 (i32, i8*, i8*, ...) @applog(i32 2, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* %95)
br label %49
97: ; preds = %78
%98 = load i32, i32* %17
%99 = load %struct.addrinfo*, %struct.addrinfo** %16
%100 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %99, i32 0, i32 2
%101 = load i32*, i32** %100
%102 = load %struct.addrinfo*, %struct.addrinfo** %16
%103 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %102, i32 0, i32 1
%104 = load i64, i64* %103
%105 = call i32 @connect(i32 %98, i32* %101, i64 %104)
store i32 %105, i32* %13
%106 = load i32, i32* %13
%107 = icmp eq i32 %106, 0
br i1 %107, label %108, label %112
108: ; preds = %97
store i32 1, i32* %15
%109 = load i32, i32* %17
%110 = load i32*, i32** %7
store i32 %109, i32* %110
%111 = call i32 (i32, i8*, i8*, ...) @applog(i32 0, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i8* %21, i8* %24)
br label %123
112: ; preds = %97
%113 = load i32, i32* @errno
%114 = call i32 @strerror(i32 %113)
%115 = sext i32 %114 to i64
%116 = inttoptr i64 %115 to i8*
%117 = call i32 (i32, i8*, i8*, ...) @applog(i32 2, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %116)
%118 = load i32, i32* %17
%119 = call i32 @close(i32 %118)
%120 = load %struct.addrinfo*, %struct.addrinfo** %16
%121 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %120, i32 0, i32 0
%122 = load %struct.addrinfo*, %struct.addrinfo** %121
store %struct.addrinfo* %122, %struct.addrinfo** %16
br label %123
123: ; preds = %112, %108
br label %49
124: ; preds = %55
%125 = load %struct.addrinfo*, %struct.addrinfo** %9
%126 = call i32 @freeaddrinfo(%struct.addrinfo* %125)
%127 = load i32, i32* %15
%128 = icmp eq i32 %127, 0
br i1 %128, label %129, label %133
129: ; preds = %124
%130 = load i8*, i8** %5
%131 = load i8*, i8** %6
%132 = call i32 (i32, i8*, i8*, ...) @applog(i32 2, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i8* %130, i8* %131)
store i32 -4, i32* %4
store i32 1, i32* %14
br label %134
133: ; preds = %124
store i32 -1, i32* %4
store i32 1, i32* %14
br label %134
134: ; preds = %133, %129, %72, %41
%135 = load i8*, i8** %10
%136 = load i32, i32* %4
ret i32 %136
}

LLVM IR (-O2):
%struct.addrinfo = type { %struct.addrinfo*, i64, i32*, i64, i32, i32, i64, i32* }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [63 x i8] c"[Network] Erreur lors de la recherche sur %s:%s. Erreur : %s.\0A\00"
@NI_NUMERICHOST = global i32 0
@NI_NUMERICSERV = global i32 0
@.str.1 = [75 x i8] c"[Network] Erreur lors de la r\C3\A9cup\C3\A9ration des informations. Erreur : %s.\0A\00"
@.str.2 = [66 x i8] c"[Network] Erreur lors de la cr\C3\A9ation de la socket. Erreur : %s.\0A\00"
@errno = global i32 0
@.str.3 = [54 x i8] c"[Network] Connexion en attente sur le serveur %s:%s.\0A\00"
@.str.4 = [46 x i8] c"[Network] Echec de la connexion. Erreur: %s.\0A\00"
@.str.5 = [56 x i8] c"[Network] Impossible de se connecter au serveur %s:%s.\0A\00"
define i32 @connect_to(i8* %0, i8* %1, i32* nocapture writeonly %2) {
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = bitcast %struct.addrinfo* %4 to i8*
%7 = bitcast %struct.addrinfo** %5 to i8*
%8 = load i32, i32* @NI_MAXHOST
%9 = zext i32 %8 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = load i32, i32* @NI_MAXSERV
%13 = zext i32 %12 to i64
%14 = alloca i8, i64 %13
%15 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 56)
%16 = load i32, i32* @AF_UNSPEC
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 5
store i32 %16, i32* %17
%18 = load i32, i32* @SOCK_STREAM
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 4
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 6
%21 = bitcast %struct.addrinfo* %4 to i8*
%22 = bitcast i64* %20 to i8*
%23 = call i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %4, %struct.addrinfo** %5)
%24 = icmp eq i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %3
%26 = call i32 @gai_strerror(i32 %23)
%27 = sext i32 %26 to i64
%28 = inttoptr i64 %27 to i8*
%29 = call i32 (i32, i8*, i8*, ...) @applog(i32 2, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %93
30: ; preds = %3
%31 = load %struct.addrinfo*, %struct.addrinfo** %5
%32 = icmp eq %struct.addrinfo* %31, null
br i1 %32, label %89, label %33
33: ; preds = %30, %80
%34 = phi %struct.addrinfo* [ %81, %80 ], [ %31, %30 ]
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 2
%36 = load i32*, i32** %35
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 1
%38 = load i64, i64* %37
%39 = load i32, i32* @NI_MAXHOST
%40 = load i32, i32* @NI_MAXSERV
%41 = load i32, i32* @NI_NUMERICHOST
%42 = load i32, i32* @NI_NUMERICSERV
%43 = or i32 %42, %41
%44 = call i32 @getnameinfo(i32* %36, i64 %38, i8* %11, i32 %39, i8* %14, i32 %40, i32 %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %51, label %46
46: ; preds = %33
%47 = call i32 @gai_strerror(i32 %44)
%48 = sext i32 %47 to i64
%49 = inttoptr i64 %48 to i8*
%50 = call i32 (i32, i8*, i8*, ...) @applog(i32 2, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0), i8* %49)
br label %93
51: ; preds = %33
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 5
%53 = load i32, i32* %52
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 4
%55 = load i32, i32* %54
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 3
%57 = load i64, i64* %56
%58 = call i32 @socket(i32 %53, i32 %55, i64 %57)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %66
60: ; preds = %51
%61 = load i32, i32* @errno
%62 = call i32 @strerror(i32 %61)
%63 = sext i32 %62 to i64
%64 = inttoptr i64 %63 to i8*
%65 = call i32 (i32, i8*, i8*, ...) @applog(i32 2, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* %64)
br label %80
66: ; preds = %51
%67 = load i32*, i32** %35
%68 = load i64, i64* %37
%69 = call i32 @connect(i32 %58, i32* %67, i64 %68)
%70 = icmp eq i32 %69, 0
br i1 %70, label %85, label %71
71: ; preds = %66
%72 = load i32, i32* @errno
%73 = call i32 @strerror(i32 %72)
%74 = sext i32 %73 to i64
%75 = inttoptr i64 %74 to i8*
%76 = call i32 (i32, i8*, i8*, ...) @applog(i32 2, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %75)
%77 = call i32 @close(i32 %58)
%78 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 0
%79 = load %struct.addrinfo*, %struct.addrinfo** %78
br label %80
80: ; preds = %71, %60
%81 = phi %struct.addrinfo* [ %79, %71 ], [ %34, %60 ]
%82 = icmp eq %struct.addrinfo* %81, null
br i1 %82, label %83, label %33
83: ; preds = %80
%84 = load %struct.addrinfo*, %struct.addrinfo** %5
br label %89
85: ; preds = %66
store i32 %58, i32* %2
%86 = call i32 (i32, i8*, i8*, ...) @applog(i32 0, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i8* %11, i8* %14)
%87 = load %struct.addrinfo*, %struct.addrinfo** %5
%88 = call i32 @freeaddrinfo(%struct.addrinfo* %87)
br label %93
89: ; preds = %30, %83
%90 = phi %struct.addrinfo* [ %84, %83 ], [ null, %30 ]
%91 = call i32 @freeaddrinfo(%struct.addrinfo* %90)
%92 = call i32 (i32, i8*, i8*, ...) @applog(i32 2, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %1)
br label %93
93: ; preds = %85, %46, %89, %25
%94 = phi i32 [ -2, %25 ], [ -3, %46 ], [ -4, %89 ], [ -1, %85 ]
ret i32 %94
}