#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_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  scalar_t__ ai_addr;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int getaddrinfo(char *, char *, int /*<<< orphan*/ *, struct addrinfo **);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char const *argv[]) {
  int sock = socket(PF_INET, SOCK_STREAM, 0);
  struct addrinfo *info;
  int res = getaddrinfo("lucien", "13", NULL, &info);
  if (res != 0) {
    printf("erreur host\n");
    exit(-2);
  }
  if (info != NULL) {
    struct sockaddr_in *addressin;
    addressin = (struct sockaddr_in *)info->ai_addr;
    int ret = connect(sock, (struct sockaddr *)addressin,
                      (socklen_t)sizeof(struct sockaddr_in));
    if (ret == 0) {
      char buff[100];
      int recu = recv(sock, buff, 99 * sizeof(char), 0);
      buff[recu] = '\0';
      printf("Message recu : %s\n", buff);
    } else {
      printf("Probleme de connexion!\n");
    }
    close(sock);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    0xe54(%rip),%rdi
lea    0xe54(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x20(%rbp),%rcx
call   1080 <getaddrinfo@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11e5 <main+0x75>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xfffffffe,%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
je     1274 <main+0x104>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   1070 <connect@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    125e <main+0xee>
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0xa4(%rbp)
movslq -0xa4(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rsi
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126c <main+0xfc>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebx
lea    0xe57(%rip),%rdi
lea    0xe57(%rip),%rsi
lea    0x8(%rsp),%rcx
xor    %edx,%edx
call   1090 <getaddrinfo@plt>
test   %eax,%eax
jne    122a <main+0xaa>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     1220 <main+0xa0>
mov    (%rax),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1080 <connect@plt>
test   %eax,%eax
je     11eb <main+0x6b>
lea    0xe39(%rip),%rdi
call   1040 <puts@plt>
jmp    1219 <main+0x99>
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xdfb(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe03(%rip),%rdi
call   1040 <puts@plt>
mov    $0xfffffffe,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i64 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"lucien\00"
@.str.1 = [3 x i8] c"13\00"
@.str.2 = [13 x i8] c"erreur host\0A\00"
@.str.3 = [19 x i8] c"Message recu : %s\0A\00"
@.str.4 = [24 x i8] c"Probleme de connexion!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.addrinfo*
%8 = alloca i32
%9 = alloca %struct.sockaddr_in*
%10 = alloca i32
%11 = alloca [100 x i8]
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @PF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %6
%16 = call i32 @getaddrinfo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* null, %struct.addrinfo** %7)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 -2)
unreachable
22: ; preds = %2
%23 = load %struct.addrinfo*, %struct.addrinfo** %7
%24 = icmp ne %struct.addrinfo* %23, null
br i1 %24, label %25, label %50
25: ; preds = %22
%26 = load %struct.addrinfo*, %struct.addrinfo** %7
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i32 0, i32 0
%28 = load i64, i64* %27
%29 = inttoptr i64 %28 to %struct.sockaddr_in*
store %struct.sockaddr_in* %29, %struct.sockaddr_in** %9
%30 = load i32, i32* %6
%31 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%32 = bitcast %struct.sockaddr_in* %31 to %struct.sockaddr*
%33 = call i32 @connect(i32 %30, %struct.sockaddr* %32, i32 4)
store i32 %33, i32* %10
%34 = load i32, i32* %10
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %25
%37 = load i32, i32* %6
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%39 = call i32 @recv(i32 %37, i8* %38, i32 99, i32 0)
store i32 %39, i32* %12
%40 = load i32, i32* %12
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 %41
store i8 0, i8* %42
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %43)
br label %47
45: ; preds = %25
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %47
47: ; preds = %45, %36
%48 = load i32, i32* %6
%49 = call i32 @close(i32 %48)
br label %50
50: ; preds = %47, %22
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i64 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"lucien\00"
@.str.1 = [3 x i8] c"13\00"
@.str.3 = [19 x i8] c"Message recu : %s\0A\00"
@str = [23 x i8] c"Probleme de connexion!\00"
@str.5 = [12 x i8] c"erreur host\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.addrinfo*
%4 = alloca [100 x i8]
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = bitcast %struct.addrinfo** %3 to i8*
%9 = call i32 @getaddrinfo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* null, %struct.addrinfo** %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.5, i64 0, i64 0))
%13 = call i32 @exit(i32 -2)
unreachable
14: ; preds = %2
%15 = load %struct.addrinfo*, %struct.addrinfo** %3
%16 = icmp eq %struct.addrinfo* %15, null
br i1 %16, label %33, label %17
17: ; preds = %14
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %15, i64 0, i32 0
%19 = load i64, i64* %18
%20 = inttoptr i64 %19 to %struct.sockaddr*
%21 = call i32 @connect(i32 %7, %struct.sockaddr* %20, i32 4)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %17
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%25 = call i32 @recv(i32 %7, i8* %24, i32 99, i32 0)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %26
store i8 0, i8* %27
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %24)
br label %31
29: ; preds = %17
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %31
31: ; preds = %29, %23
%32 = call i32 @close(i32 %7)
br label %33
33: ; preds = %31, %14
ret i32 0
}