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

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int EXIT_FAILURE;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  struct addrinfo hints, *res, *ptr;
  int rc, fd, nread;
  char buf[1024], nombre[80];
  memset(&hints, 0, sizeof(hints));
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_family = AF_UNSPEC;
  rc = getaddrinfo(argv[1], "www", &hints, &res);
  if (rc) {
    fprintf(stderr, "%s: %s\n", argv[0], gai_strerror(rc));
    return EXIT_FAILURE;
  }
  for (ptr = res; ptr != NULL; ptr = ptr->ai_next) {
    fd = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);
    if (fd < 0)
      continue;
    if (connect(fd, ptr->ai_addr, ptr->ai_addrlen) == 0)
      break;
  }
  write(fd, "GET / \r\n", 8);
  while ((nread = read(fd, buf, sizeof(buf)))) {
    write(1, buf, nread);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe30(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1090 <getaddrinfo@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     123c <main+0xbc>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4ac(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x4a8(%rbp)
mov    -0x44(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x4ac(%rbp),%edi
mov    -0x4a8(%rbp),%rdx
mov    %rax,%rcx
lea    0xdde(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1309 <main+0x189>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12b5 <main+0x135>
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    127b <main+0xfb>
jmp    12a4 <main+0x124>
mov    -0x48(%rbp),%edi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   1080 <connect@plt>
cmp    $0x0,%rax
jne    129f <main+0x11f>
jmp    12b5 <main+0x135>
jmp    12a4 <main+0x124>
mov    -0x40(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    1244 <main+0xc4>
mov    -0x48(%rbp),%edi
lea    0xd4d(%rip),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0x48(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
je     1302 <main+0x182>
lea    -0x450(%rbp),%rsi
mov    -0x4c(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    12c9 <main+0x149>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x430,%rsp
mov    %rsi,%rbx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x8(%rbx),%rdi
lea    0xe39(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    %rbp,%rdx
call   1090 <getaddrinfo@plt>
test   %eax,%eax
je     120e <main+0x8e>
mov    0x2df9(%rip),%rcx
mov    (%rcx),%ebp
mov    (%rbx),%rbx
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xe12(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%r14d
jmp    12a2 <main+0x122>
mov    0x8(%rsp),%rbp
test   %rbp,%rbp
jne    1229 <main+0xa9>
jmp    124f <main+0xcf>
nopw   0x0(%rax,%rax,1)
mov    0x18(%rbp),%rbp
test   %rbp,%rbp
je     124f <main+0xcf>
mov    0x10(%rbp),%edi
mov    0x8(%rbp),%edx
mov    0xc(%rbp),%esi
call   10a0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1220 <main+0xa0>
mov    0x0(%rbp),%edx
mov    0x4(%rbp),%esi
mov    %ebx,%edi
call   1080 <connect@plt>
test   %rax,%rax
jne    1220 <main+0xa0>
lea    0xdb6(%rip),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1030 <write@plt>
lea    0x30(%rsp),%rsi
mov    %ebx,%edi
mov    $0x400,%edx
call   1060 <read@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     12a2 <main+0x122>
lea    0x30(%rsp),%rbp
nop
mov    $0x1,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
test   %eax,%eax
jne    1280 <main+0x100>
mov    %r14d,%eax
add    $0x430,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo* }
@SOCK_STREAM = global i32 0
@AF_UNSPEC = global i32 0
@.str = [4 x i8] c"www\00"
@stderr = global i32 0
@.str.1 = [8 x i8] c"%s: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [9 x i8] c"GET / \0D\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
%8 = alloca %struct.addrinfo*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [1024 x i8]
%13 = alloca [80 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 32)
%15 = load i32, i32* @SOCK_STREAM
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i32 %15, i32* %16
%17 = load i32, i32* @AF_UNSPEC
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i32 %17, i32* %18
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @getaddrinfo(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = load i32, i32* %9
%31 = call i8* @gai_strerror(i32 %30)
%32 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
store i32 %33, i32* %3
br label %82
34: ; preds = %2
%35 = load %struct.addrinfo*, %struct.addrinfo** %7
store %struct.addrinfo* %35, %struct.addrinfo** %8
br label %36
36: ; preds = %65, %34
%37 = load %struct.addrinfo*, %struct.addrinfo** %8
%38 = icmp ne %struct.addrinfo* %37, null
br i1 %38, label %39, label %69
39: ; preds = %36
%40 = load %struct.addrinfo*, %struct.addrinfo** %8
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i32 0, i32 4
%42 = load i32, i32* %41
%43 = load %struct.addrinfo*, %struct.addrinfo** %8
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i32 0, i32 3
%45 = load i32, i32* %44
%46 = load %struct.addrinfo*, %struct.addrinfo** %8
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i32 0, i32 2
%48 = load i32, i32* %47
%49 = call i32 @socket(i32 %42, i32 %45, i32 %48)
store i32 %49, i32* %10
%50 = load i32, i32* %10
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %39
br label %65
53: ; preds = %39
%54 = load i32, i32* %10
%55 = load %struct.addrinfo*, %struct.addrinfo** %8
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i32 0, i32 1
%57 = load i32, i32* %56
%58 = load %struct.addrinfo*, %struct.addrinfo** %8
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %58, i32 0, i32 0
%60 = load i32, i32* %59
%61 = call i64 @connect(i32 %54, i32 %57, i32 %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %53
br label %69
64: ; preds = %53
br label %65
65: ; preds = %64, %52
%66 = load %struct.addrinfo*, %struct.addrinfo** %8
%67 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %66, i32 0, i32 5
%68 = load %struct.addrinfo*, %struct.addrinfo** %67
store %struct.addrinfo* %68, %struct.addrinfo** %8
br label %36
69: ; preds = %63, %36
%70 = load i32, i32* %10
%71 = call i32 @write(i32 %70, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
br label %72
72: ; preds = %77, %69
%73 = load i32, i32* %10
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%75 = call i32 @read(i32 %73, i8* %74, i32 1024)
store i32 %75, i32* %11
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %81
77: ; preds = %72
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%79 = load i32, i32* %11
%80 = call i32 @write(i32 1, i8* %78, i32 %79)
br label %72
81: ; preds = %72
store i32 0, i32* %3
br label %82
82: ; preds = %81, %25
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo* }
@SOCK_STREAM = global i32 0
@AF_UNSPEC = global i32 0
@.str = [4 x i8] c"www\00"
@stderr = global i32 0
@.str.1 = [8 x i8] c"%s: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [9 x i8] c"GET / \0D\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca [1024 x i8]
%6 = bitcast %struct.addrinfo* %3 to i8*
%7 = bitcast %struct.addrinfo** %4 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 32)
%10 = load i32, i32* @SOCK_STREAM
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %10, i32* %11
%12 = load i32, i32* @AF_UNSPEC
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %12, i32* %13
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @getaddrinfo(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %3, %struct.addrinfo** %4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load %struct.addrinfo*, %struct.addrinfo** %4
%20 = icmp eq %struct.addrinfo* %19, null
br i1 %20, label %48, label %27
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %1
%24 = call i8* @gai_strerror(i32 %16)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
br label %58
27: ; preds = %18, %44
%28 = phi %struct.addrinfo* [ %46, %44 ], [ %19, %18 ]
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i64 0, i32 4
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i64 0, i32 3
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i64 0, i32 2
%34 = load i32, i32* %33
%35 = call i32 @socket(i32 %30, i32 %32, i32 %34)
%36 = icmp slt i32 %35, 0
br i1 %36, label %44, label %37
37: ; preds = %27
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i64 0, i32 1
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i64 0, i32 0
%41 = load i32, i32* %40
%42 = call i64 @connect(i32 %35, i32 %39, i32 %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %37, %27
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i64 0, i32 5
%46 = load %struct.addrinfo*, %struct.addrinfo** %45
%47 = icmp eq %struct.addrinfo* %46, null
br i1 %47, label %48, label %27
48: ; preds = %44, %37, %18
%49 = phi i32 [ undef, %18 ], [ %35, %37 ], [ %35, %44 ]
%50 = call i32 @write(i32 %49, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%51 = call i32 @read(i32 %49, i8* %8, i32 1024)
%52 = icmp eq i32 %51, 0
br i1 %52, label %58, label %53
53: ; preds = %48, %53
%54 = phi i32 [ %56, %53 ], [ %51, %48 ]
%55 = call i32 @write(i32 1, i8* %8, i32 %54)
%56 = call i32 @read(i32 %49, i8* %8, i32 1024)
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %53
58: ; preds = %53, %48, %21
%59 = phi i32 [ %26, %21 ], [ 0, %48 ], [ 0, %53 ]
ret i32 %59
}