#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;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ 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*/ perror(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int main(int argc, char const *argv[]) {
  int retour = 0;
  struct sockaddr_in adress_sock;
  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", "daytime", &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';
  printf("%s", buff);
  close(desc_sock);
  freeaddrinfo(first_info);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x10,%esi
call   1080 <bzero@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
lea    0xdf3(%rip),%rdi
lea    0xdf3(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   10b0 <getaddrinfo@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     124f <main+0x8f>
mov    -0x14(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    %rax,%rsi
lea    0xdcf(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
je     1266 <main+0xa6>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
mov    0x2d62(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   10a0 <connect@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12bf <main+0xff>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %eax,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x34(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x444(%rbp)
movslq -0x444(%rbp),%rax
movb   $0x0,-0x440(%rbp,%rax,1)
lea    -0x440(%rbp),%rsi
lea    0xd1b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
mov    -0x20(%rbp),%rdi
call   10d0 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x428,%rsp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x10,%esi
call   1080 <bzero@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x2de8(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
lea    0xe02(%rip),%rdi
lea    0xe02(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    %rbx,%rdx
call   10b0 <getaddrinfo@plt>
test   %eax,%eax
jne    129f <main+0xdf>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     122c <main+0x6c>
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   10a0 <connect@plt>
cmp    $0xffffffff,%eax
je     12bf <main+0xff>
lea    0x20(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xd9a(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x8(%rsp),%rdi
call   10d0 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r14
ret
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xd62(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %eax,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.addrinfo = type { i64, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"lucien\00"
@.str.1 = [8 x i8] c"daytime\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@PF_INET = global i32 0
@errno = global i32 0
@.str.3 = [3 x i8] c"%s\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.addrinfo*
%9 = alloca %struct.addrinfo
%10 = alloca i32
%11 = alloca [1024 x i8]
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%13 = call i32 @bzero(%struct.addrinfo* %9, i32 16)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* @SOCK_STREAM
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 1
store i32 %16, i32* %17
%18 = call i32 @getaddrinfo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %9, %struct.addrinfo** %8)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %2
%22 = load i32, i32* %6
%23 = call i8* @gai_strerror(i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = load %struct.addrinfo*, %struct.addrinfo** %8
%28 = icmp ne %struct.addrinfo* %27, null
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load %struct.addrinfo*, %struct.addrinfo** %8
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i32 0, i32 0
%32 = load i64, i64* %31
%33 = inttoptr i64 %32 to %struct.sockaddr_in*
%34 = bitcast %struct.sockaddr_in* %7 to i8*
%35 = bitcast %struct.sockaddr_in* %33 to i8*
br label %36
36: ; preds = %29, %26
%37 = load i32, i32* @PF_INET
%38 = load i32, i32* @SOCK_STREAM
%39 = call i32 @socket(i32 %37, i32 %38, i32 0)
store i32 %39, i32* %10
%40 = load i32, i32* %10
%41 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%42 = call i32 @connect(i32 %40, %struct.sockaddr* %41, i32 4)
store i32 %42, i32* %6
%43 = load i32, i32* %6
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %50
45: ; preds = %36
%46 = load i32, i32* @errno
%47 = call i32 @strerror(i32 %46)
%48 = call i32 @perror(i32 %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %36
%51 = load i32, i32* %10
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%53 = call i32 @recv(i32 %51, i8* %52, i32 1023, i32 0)
store i32 %53, i32* %12
%54 = load i32, i32* %12
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %55
store i8 0, i8* %56
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%58 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %57)
%59 = load i32, i32* %10
%60 = call i32 @close(i32 %59)
%61 = load %struct.addrinfo*, %struct.addrinfo** %8
%62 = call i32 @freeaddrinfo(%struct.addrinfo* %61)
ret i32 0
}

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