#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 in_addr {
  int dummy;
};
struct sockaddr_in {
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_socktype;
  void *ai_family;
};

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(struct addrinfo *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ htons(int);
int inet_aton(char *, struct in_addr *);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char const *argv[]) {
  int retour = 0;
  struct sockaddr_in adress_sock;
  struct in_addr addrIPV4;
  retour = inet_aton("173.194.66.106", &addrIPV4);
  if (retour == 0) {
    printf("Adresse IP non valide\n");
    exit(1);
  }
  adress_sock.sin_family = AF_INET;
  adress_sock.sin_port = htons(4242);
  adress_sock.sin_addr = addrIPV4;
  struct addrinfo *first_info;
  struct addrinfo hints;
  bzero(&hints, sizeof(struct addrinfo));
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  retour = getaddrinfo("lucien", "4242", &hints, &first_info);
  if (retour != 0) {
    printf("%s\n", gai_strerror(retour));
    exit(1);
  }
  if (first_info != NULL) {
    adress_sock = *(struct sockaddr_in *)first_info->ai_addr;
  }
  int desc_sock = socket(PF_INET, SOCK_STREAM, 0);
  retour = connect(desc_sock, (struct sockaddr *)&adress_sock,
                   sizeof(struct sockaddr_in));
  if (retour == -1) {
    perror(strerror(errno));
    exit(1);
  }
  char buff[1024];
  int size_rec = recv(desc_sock, buff, 1023 * sizeof(char), 0);
  buff[size_rec] = '\0';
  char *mess = "SALUT!\n";
  retour = send(desc_sock, mess, strlen(mess), 0);
  if (retour == -1) {
    perror(strerror(errno));
    exit(1);
  }
  close(desc_sock);
  freeaddrinfo(first_info);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xdd9(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   10a0 <inet_aton@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1255 <main+0x55>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    $0x1092,%edi
call   1050 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x18,%esi
call   10c0 <bzero@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
lea    0xd81(%rip),%rdi
lea    0xd81(%rip),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   10f0 <getaddrinfo@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12e9 <main+0xe9>
mov    -0x14(%rbp),%edi
call   1080 <gai_strerror@plt>
mov    %rax,%rsi
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
cmpq   $0x0,-0x38(%rbp)
je     130a <main+0x10a>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rcx
mov    %rcx,-0x28(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
mov    0x2cbe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   10e0 <connect@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1363 <main+0x163>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %eax,%edi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x54(%rbp),%edi
lea    -0x460(%rbp),%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x464(%rbp)
movslq -0x464(%rbp),%rax
movb   $0x0,-0x460(%rbp,%rax,1)
lea    0xca1(%rip),%rax
mov    %rax,-0x470(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x47c(%rbp)
mov    -0x470(%rbp),%rax
mov    %rax,-0x478(%rbp)
mov    -0x470(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x47c(%rbp),%edi
mov    -0x478(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1401 <main+0x201>
mov    0x2be7(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %eax,%edi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x54(%rbp),%edi
call   1090 <close@plt>
mov    -0x38(%rbp),%rdi
call   1110 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x480,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x448,%rsp
lea    0xdef(%rip),%rdi
mov    %rsp,%rsi
call   10a0 <inet_aton@plt>
test   %eax,%eax
je     1349 <main+0x149>
mov    0x2dc0(%rip),%r14
mov    (%r14),%rax
mov    %rax,0x18(%rsp)
mov    $0x1092,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%rsp),%eax
mov    %eax,0x10(%rsp)
lea    0x28(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x18,%esi
call   10c0 <bzero@plt>
mov    (%r14),%rax
mov    %rax,0x38(%rsp)
mov    0x2d72(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x30(%rsp)
lea    0xd9b(%rip),%rdi
lea    0xd9b(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    %rbx,%rdx
call   10f0 <getaddrinfo@plt>
test   %eax,%eax
jne    1352 <main+0x152>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     12a5 <main+0xa5>
mov    (%rax),%rax
movups (%rax),%xmm0
movaps %xmm0,0x10(%rsp)
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
je     132a <main+0x12a>
lea    0x40(%rsp),%rsi
mov    %ebx,%edi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,0x40(%rsp,%rax,1)
lea    0xd2a(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0xffffffff,%eax
je     132a <main+0x12a>
mov    %ebx,%edi
call   1090 <close@plt>
mov    0x8(%rsp),%rdi
call   1110 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x448,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %eax,%edi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xcd3(%rip),%rdi
jmp    135c <main+0x15c>
mov    %eax,%edi
call   1080 <gai_strerror@plt>
mov    %rax,%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.in_addr, i32, i8* }
%struct.in_addr = type { i32 }
%struct.addrinfo = type { i64, i32, i8* }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"173.194.66.106\00"
@.str.1 = [23 x i8] c"Adresse IP non valide\0A\00"
@AF_INET = global i8* null
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"lucien\00"
@.str.3 = [5 x i8] c"4242\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@PF_INET = global i32 0
@errno = global i32 0
@.str.5 = [8 x i8] c"SALUT!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.in_addr
%9 = alloca %struct.addrinfo*
%10 = alloca %struct.addrinfo
%11 = alloca i32
%12 = alloca [1024 x i8]
%13 = alloca i32
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%15 = call i32 @inet_aton(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %struct.in_addr* %8)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8*, i8** @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i8* %22, i8** %23
%24 = call i32 @htons(i32 4242)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %24, i32* %25
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%27 = bitcast %struct.in_addr* %26 to i8*
%28 = bitcast %struct.in_addr* %8 to i8*
%29 = call i32 @bzero(%struct.addrinfo* %10, i32 24)
%30 = load i8*, i8** @AF_INET
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 2
store i8* %30, i8** %31
%32 = load i32, i32* @SOCK_STREAM
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 1
store i32 %32, i32* %33
%34 = call i32 @getaddrinfo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %struct.addrinfo* %10, %struct.addrinfo** %9)
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %21
%38 = load i32, i32* %6
%39 = call i8* @gai_strerror(i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %21
%43 = load %struct.addrinfo*, %struct.addrinfo** %9
%44 = icmp ne %struct.addrinfo* %43, null
br i1 %44, label %45, label %52
45: ; preds = %42
%46 = load %struct.addrinfo*, %struct.addrinfo** %9
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i32 0, i32 0
%48 = load i64, i64* %47
%49 = inttoptr i64 %48 to %struct.sockaddr_in*
%50 = bitcast %struct.sockaddr_in* %7 to i8*
%51 = bitcast %struct.sockaddr_in* %49 to i8*
br label %52
52: ; preds = %45, %42
%53 = load i32, i32* @PF_INET
%54 = load i32, i32* @SOCK_STREAM
%55 = call i32 @socket(i32 %53, i32 %54, i32 0)
store i32 %55, i32* %11
%56 = load i32, i32* %11
%57 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%58 = call i32 @connect(i32 %56, %struct.sockaddr* %57, i32 16)
store i32 %58, i32* %6
%59 = load i32, i32* %6
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %66
61: ; preds = %52
%62 = load i32, i32* @errno
%63 = call i32 @strerror(i32 %62)
%64 = call i32 @perror(i32 %63)
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %52
%67 = load i32, i32* %11
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%69 = call i32 @recv(i32 %67, i8* %68, i32 1023, i32 0)
store i32 %69, i32* %13
%70 = load i32, i32* %13
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 %71
store i8 0, i8* %72
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %14
%73 = load i32, i32* %11
%74 = load i8*, i8** %14
%75 = load i8*, i8** %14
%76 = call i32 @strlen(i8* %75)
%77 = call i32 @send(i32 %73, i8* %74, i32 %76, i32 0)
store i32 %77, i32* %6
%78 = load i32, i32* %6
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %85
80: ; preds = %66
%81 = load i32, i32* @errno
%82 = call i32 @strerror(i32 %81)
%83 = call i32 @perror(i32 %82)
%84 = call i32 @exit(i32 1)
unreachable
85: ; preds = %66
%86 = load i32, i32* %11
%87 = call i32 @close(i32 %86)
%88 = load %struct.addrinfo*, %struct.addrinfo** %9
%89 = call i32 @freeaddrinfo(%struct.addrinfo* %88)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.in_addr, i32, i8* }
%struct.in_addr = type { i32 }
%struct.addrinfo = type { i64, i32, i8* }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"173.194.66.106\00"
@AF_INET = global i8* null
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"lucien\00"
@.str.3 = [5 x i8] c"4242\00"
@PF_INET = global i32 0
@errno = global i32 0
@.str.5 = [8 x i8] c"SALUT!\0A\00"
@str = [22 x i8] c"Adresse IP non valide\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.in_addr
%5 = alloca %struct.addrinfo*
%6 = alloca %struct.addrinfo
%7 = alloca [1024 x i8]
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast %struct.in_addr* %4 to i8*
%10 = call i32 @inet_aton(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %struct.in_addr* %4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8*, i8** @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i8* %16, i8** %17
%18 = call i32 @htons(i32 4242)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i64 0, i32 0
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
%22 = load i32, i32* %20
store i32 %22, i32* %21
%23 = bitcast %struct.addrinfo** %5 to i8*
%24 = bitcast %struct.addrinfo* %6 to i8*
%25 = call i32 @bzero(%struct.addrinfo* %6, i32 24)
%26 = load i8*, i8** @AF_INET
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 2
store i8* %26, i8** %27
%28 = load i32, i32* @SOCK_STREAM
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 1
store i32 %28, i32* %29
%30 = call i32 @getaddrinfo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %struct.addrinfo* %6, %struct.addrinfo** %5)
%31 = icmp eq i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %15
%33 = call i8* @gai_strerror(i32 %30)
%34 = call i32 @puts(i8* dereferenceable(1) %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %15
%37 = load %struct.addrinfo*, %struct.addrinfo** %5
%38 = icmp eq %struct.addrinfo* %37, null
br i1 %38, label %43, label %39
39: ; preds = %36
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 0
%41 = load i64, i64* %40
%42 = inttoptr i64 %41 to i8*
br label %43
43: ; preds = %39, %36
%44 = load i32, i32* @PF_INET
%45 = load i32, i32* @SOCK_STREAM
%46 = call i32 @socket(i32 %44, i32 %45, i32 0)
%47 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%48 = call i32 @connect(i32 %46, %struct.sockaddr* %47, i32 16)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %55
50: ; preds = %43
%51 = load i32, i32* @errno
%52 = call i32 @strerror(i32 %51)
%53 = call i32 @perror(i32 %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %43
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%57 = call i32 @recv(i32 %46, i8* %56, i32 1023, i32 0)
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %58
store i8 0, i8* %59
%60 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%61 = call i32 @send(i32 %46, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %60, i32 0)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %68
63: ; preds = %55
%64 = load i32, i32* @errno
%65 = call i32 @strerror(i32 %64)
%66 = call i32 @perror(i32 %65)
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %55
%69 = call i32 @close(i32 %46)
%70 = load %struct.addrinfo*, %struct.addrinfo** %5
%71 = call i32 @freeaddrinfo(%struct.addrinfo* %70)
ret i32 0
}