#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;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ PF_UNSPEC;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fail(int, char *, ...);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ gai_strerror(int);
int /*<<< orphan*/ get_page(int, char const *, char *);
int getaddrinfo(char const *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  struct addrinfo hints, *res, *res0;
  int error;
  int sockfd;
  const char *host = "www.gnu.org";
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = PF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  error = getaddrinfo(host, "http", &hints, &res0);
  fail(error, gai_strerror(error));
  sockfd = -1;
  for (res = res0; res; res = res->ai_next) {
    sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    fail(sockfd < 0, "socket: %s\n", strerror(errno));
    if (connect(sockfd, res->ai_addr, res->ai_addrlen) < 0) {
      fprintf(stderr, "connect: %s\n", strerror(errno));
      close(sockfd);
      exit(EXIT_SUCCESS);
    }
    break;
  }
  if (sockfd != -1) {
    get_page(sockfd, host, "/");
  }
  freeaddrinfo(res0);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe23(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x50(%rbp),%rdi
lea    0xdf8(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   10b0 <getaddrinfo@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x44(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x54(%rbp),%edi
movslq %eax,%rsi
mov    $0x0,%al
call   1030 <fail@plt>
movl   $0xffffffff,-0x48(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     130d <main+0x14d>
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x38(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x58(%rbp)
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
lea    0xd71(%rip),%rsi
mov    $0x0,%al
call   1030 <fail@plt>
mov    -0x48(%rbp),%edi
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    1308 <main+0x148>
mov    0x2d0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2cef(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    %rax,%rdx
lea    0xd30(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x48(%rbp),%edi
call   1070 <close@plt>
mov    0x2cbf(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    130d <main+0x14d>
cmpl   $0xffffffff,-0x48(%rbp)
je     132a <main+0x16a>
mov    -0x48(%rbp),%edi
mov    -0x50(%rbp),%rsi
lea    0xd05(%rip),%rdx
call   1040 <get_page@plt>
mov    -0x40(%rbp),%rdi
call   10d0 <freeaddrinfo@plt>
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
lea    0xe01(%rip),%rdi
lea    0xe06(%rip),%rsi
mov    %rsp,%rcx
mov    %rbx,%rdx
call   10b0 <getaddrinfo@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
movslq %eax,%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fail@plt>
mov    (%rsp),%rbx
test   %rbx,%rbx
je     12c5 <main+0x105>
mov    0x10(%rbx),%edi
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%esi
call   10e0 <socket@plt>
mov    %eax,%r14d
mov    %eax,%ebp
shr    $0x1f,%ebp
mov    0x2d78(%rip),%r15
mov    (%r15),%edi
call   10c0 <strerror@plt>
lea    0xdb2(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fail@plt>
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %r14d,%edi
call   10a0 <connect@plt>
test   %rax,%rax
jns    12a9 <main+0xe9>
mov    0x2d54(%rip),%rax
mov    (%rax),%ebp
mov    (%r15),%edi
call   10c0 <strerror@plt>
lea    0xd88(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    %r14d,%edi
call   1070 <close@plt>
jmp    12ce <main+0x10e>
cmp    $0xffffffff,%r14d
je     12c5 <main+0x105>
lea    0xd4a(%rip),%rsi
lea    0xd6d(%rip),%rdx
mov    %r14d,%edi
call   1040 <get_page@plt>
mov    (%rsp),%rdi
call   10d0 <freeaddrinfo@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo* }
@.str = [12 x i8] c"www.gnu.org\00"
@PF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [5 x i8] c"http\00"
@.str.2 = [12 x i8] c"socket: %s\0A\00"
@errno = global i32 0
@stderr = global i32 0
@.str.3 = [13 x i8] c"connect: %s\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.4 = [2 x i8] c"/\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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %11
%12 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 32)
%13 = load i32, i32* @PF_UNSPEC
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i32 %13, i32* %14
%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 i8*, i8** %11
%18 = call i32 @getaddrinfo(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %6, %struct.addrinfo** %8)
store i32 %18, i32* %9
%19 = load i32, i32* %9
%20 = load i32, i32* %9
%21 = call i32 @gai_strerror(i32 %20)
%22 = sext i32 %21 to i64
%23 = inttoptr i64 %22 to i8*
%24 = call i32 (i32, i8*, ...) @fail(i32 %19, i8* %23)
store i32 -1, i32* %10
%25 = load %struct.addrinfo*, %struct.addrinfo** %8
store %struct.addrinfo* %25, %struct.addrinfo** %7
br label %26
26: ; preds = %65, %2
%27 = load %struct.addrinfo*, %struct.addrinfo** %7
%28 = icmp ne %struct.addrinfo* %27, null
br i1 %28, label %29, label %69
29: ; preds = %26
%30 = load %struct.addrinfo*, %struct.addrinfo** %7
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i32 0, i32 4
%32 = load i32, i32* %31
%33 = load %struct.addrinfo*, %struct.addrinfo** %7
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i32 0, i32 3
%35 = load i32, i32* %34
%36 = load %struct.addrinfo*, %struct.addrinfo** %7
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i32 0, i32 2
%38 = load i32, i32* %37
%39 = call i32 @socket(i32 %32, i32 %35, i32 %38)
store i32 %39, i32* %10
%40 = load i32, i32* %10
%41 = icmp slt i32 %40, 0
%42 = zext i1 %41 to i32
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 (i32, i8*, ...) @fail(i32 %42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = load i32, i32* %10
%47 = load %struct.addrinfo*, %struct.addrinfo** %7
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i32 0, i32 1
%49 = load i32, i32* %48
%50 = load %struct.addrinfo*, %struct.addrinfo** %7
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i64 @connect(i32 %46, i32 %49, i32 %52)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %64
55: ; preds = %29
%56 = load i32, i32* @stderr
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %58)
%60 = load i32, i32* %10
%61 = call i32 @close(i32 %60)
%62 = load i32, i32* @EXIT_SUCCESS
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %29
br label %69
65: ; No predecessors!
%66 = load %struct.addrinfo*, %struct.addrinfo** %7
%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** %7
br label %26
69: ; preds = %64, %26
%70 = load i32, i32* %10
%71 = icmp ne i32 %70, -1
br i1 %71, label %72, label %76
72: ; preds = %69
%73 = load i32, i32* %10
%74 = load i8*, i8** %11
%75 = call i32 @get_page(i32 %73, i8* %74, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %76
76: ; preds = %72, %69
%77 = load %struct.addrinfo*, %struct.addrinfo** %8
%78 = call i32 @freeaddrinfo(%struct.addrinfo* %77)
%79 = load i32, i32* @EXIT_SUCCESS
%80 = call i32 @exit(i32 %79)
unreachable
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo* }
@.str = [12 x i8] c"www.gnu.org\00"
@PF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [5 x i8] c"http\00"
@.str.2 = [12 x i8] c"socket: %s\0A\00"
@errno = global i32 0
@stderr = global i32 0
@.str.3 = [13 x i8] c"connect: %s\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.4 = [2 x i8] c"/\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo* %3 to i8*
%6 = bitcast %struct.addrinfo** %4 to i8*
%7 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 32)
%8 = load i32, i32* @PF_UNSPEC
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %8, i32* %9
%10 = load i32, i32* @SOCK_STREAM
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %10, i32* %11
%12 = call i32 @getaddrinfo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %3, %struct.addrinfo** %4)
%13 = call i32 @gai_strerror(i32 %12)
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i8*
%16 = call i32 (i32, i8*, ...) @fail(i32 %12, i8* %15)
%17 = load %struct.addrinfo*, %struct.addrinfo** %4
%18 = icmp eq %struct.addrinfo* %17, null
br i1 %18, label %49, label %19
19: ; preds = %2
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 4
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 3
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 2
%25 = load i32, i32* %24
%26 = call i32 @socket(i32 %21, i32 %23, i32 %25)
%27 = lshr i32 %26, 31
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 (i32, i8*, ...) @fail(i32 %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 1
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 0
%34 = load i32, i32* %33
%35 = call i64 @connect(i32 %26, i32 %32, i32 %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %19
%38 = load i32, i32* @stderr
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = call i32 @close(i32 %26)
%43 = load i32, i32* @EXIT_SUCCESS
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %19
%46 = icmp eq i32 %26, -1
br i1 %46, label %49, label %47
47: ; preds = %45
%48 = call i32 @get_page(i32 %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %49
49: ; preds = %2, %47, %45
%50 = load %struct.addrinfo*, %struct.addrinfo** %4
%51 = call i32 @freeaddrinfo(%struct.addrinfo* %50)
%52 = load i32, i32* @EXIT_SUCCESS
%53 = call i32 @exit(i32 %52)
unreachable
}