#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_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct addrinfo {
  scalar_t__ ai_family;
  int /*<<< orphan*/ ai_addrlen;
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  struct addrinfo *ai_next;
};

/* Variables and functions */
scalar_t__ AF_INET;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ close(int);
int connect(int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ gai_strerror(int);
int getaddrinfo(char *, char *, int /*<<< orphan*/ *, struct addrinfo **);
int /*<<< orphan*/ inet_ntop(scalar_t__, void *, char *, int);
int /*<<< orphan*/ log_write(char *, int /*<<< orphan*/, int /*<<< orphan*/ *);
int socket(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
bool isconnected() {
  struct addrinfo *res, *p;
  int ret, sockfd;
  char ipstr[INET6_ADDRSTRLEN];
  if ((ret = getaddrinfo("www.google.com", "80", NULL, &res)) < 0) {
    log_write("Internet Connector", gai_strerror(ret), NULL);
    return false;
  }
  for (p = res; p != NULL; p = p->ai_next) {
    void *addr;
    if (p->ai_family == AF_INET) {
      struct sockaddr_in *ipv4 = (struct sockaddr_in *)(p->ai_addr);
      addr = &(ipv4->sin_addr);
    } else {
      struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)(p->ai_addr);
      addr = &(ipv6->sin6_addr);
    }
    inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
  }
  if ((sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) <
      0) {
    log_write("Internet Connector", strerror(errno), NULL);
    return false;
  }
  if (connect(sockfd, res->ai_addr, res->ai_addrlen) < -1) {
    log_write("Internet Connector", strerror(errno), NULL);
    freeaddrinfo(res);
    close(sockfd);
    return false;
  }
  close(sockfd);
  freeaddrinfo(res);
  return true;
}


x86 assembly (clang, -O0):
<isconnected>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x60(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
lea    0xe31(%rip),%rdi
lea    0xe39(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x10(%rbp),%rcx
call   1080 <getaddrinfo@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    121c <isconnected+0x8c>
mov    -0x1c(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    %eax,%esi
lea    0xe12(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <log_write@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    137a <isconnected+0x1ea>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     129e <isconnected+0x10e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2da3(%rip),%rcx
cmp    (%rcx),%rax
jne    125f <isconnected+0xcf>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1273 <isconnected+0xe3>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x58(%rbp),%rdx
mov    -0x60(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%rdi
mov    -0x40(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1224 <isconnected+0x94>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x1c(%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%edx
call   10b0 <socket@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    12f7 <isconnected+0x167>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xd37(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <log_write@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    137a <isconnected+0x1ea>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edx
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
jge    135b <isconnected+0x1cb>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xce4(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <log_write@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    137a <isconnected+0x1ea>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isconnected>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsp,%r12
mov    0x2e40(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%r13
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    0xe3d(%rip),%rdi
lea    0xe45(%rip),%rsi
xor    %r14d,%r14d
lea    -0x30(%rbp),%rcx
xor    %edx,%edx
call   1080 <getaddrinfo@plt>
test   %eax,%eax
js     126d <isconnected+0xdd>
mov    -0x30(%rbp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rbx),%rdi
mov    0x10(%rbx),%rsi
mov    %r13,%rdx
mov    %r15d,%ecx
call   1030 <inet_ntop@plt>
mov    0x20(%rbx),%rbx
test   %rbx,%rbx
jne    11f0 <isconnected+0x60>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
mov    0x1c(%rax),%esi
mov    0x18(%rax),%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     127d <isconnected+0xed>
mov    %eax,%ebx
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%rsi
mov    0x8(%rax),%edx
mov    %ebx,%edi
call   1070 <connect@plt>
cmp    $0xfffffffe,%eax
jg     12a0 <isconnected+0x110>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdc3(%rip),%rdi
xor    %r14d,%r14d
mov    %eax,%esi
xor    %edx,%edx
call   1060 <log_write@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
mov    %ebx,%edi
call   1050 <close@plt>
jmp    12b6 <isconnected+0x126>
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xd97(%rip),%rdi
jmp    1295 <isconnected+0x105>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd80(%rip),%rdi
xor    %r14d,%r14d
mov    %eax,%esi
xor    %edx,%edx
call   1060 <log_write@plt>
jmp    12b6 <isconnected+0x126>
mov    %ebx,%edi
call   1050 <close@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
mov    $0x1,%r14d
mov    %r12,%rsp
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32, i64, i32, i32, %struct.addrinfo* }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [15 x i8] c"www.google.com\00"
@.str.1 = [3 x i8] c"80\00"
@.str.2 = [19 x i8] c"Internet Connector\00"
@AF_INET = global i64 0
@errno = global i32 0
define i32 @isconnected() {
%1 = alloca i32
%2 = alloca %struct.addrinfo*
%3 = alloca %struct.addrinfo*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca %struct.sockaddr_in*
%11 = alloca %struct.sockaddr_in6*
%12 = load i32, i32* @INET6_ADDRSTRLEN
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = call i32 @getaddrinfo(i8* getelementptr inbounds ([15 x i8], [15 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** %2)
store i32 %16, i32* %4
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %0
%19 = load i32, i32* %4
%20 = call i32 @gai_strerror(i32 %19)
%21 = call i32 @log_write(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32* null)
store i32 0, i32* %1
store i32 1, i32* %8
br label %99
22: ; preds = %0
%23 = load %struct.addrinfo*, %struct.addrinfo** %2
store %struct.addrinfo* %23, %struct.addrinfo** %3
br label %24
24: ; preds = %56, %22
%25 = load %struct.addrinfo*, %struct.addrinfo** %3
%26 = icmp ne %struct.addrinfo* %25, null
br i1 %26, label %27, label %60
27: ; preds = %24
%28 = load %struct.addrinfo*, %struct.addrinfo** %3
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i32 0, i32 0
%30 = load i64, i64* %29
%31 = load i64, i64* @AF_INET
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %41
33: ; preds = %27
%34 = load %struct.addrinfo*, %struct.addrinfo** %3
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i32 0, i32 2
%36 = load i64, i64* %35
%37 = inttoptr i64 %36 to %struct.sockaddr_in*
store %struct.sockaddr_in* %37, %struct.sockaddr_in** %10
%38 = load %struct.sockaddr_in*, %struct.sockaddr_in** %10
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %38, i32 0, i32 0
%40 = bitcast i32* %39 to i8*
store i8* %40, i8** %9
br label %49
41: ; preds = %27
%42 = load %struct.addrinfo*, %struct.addrinfo** %3
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %42, i32 0, i32 2
%44 = load i64, i64* %43
%45 = inttoptr i64 %44 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %45, %struct.sockaddr_in6** %11
%46 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %11
%47 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %46, i32 0, i32 0
%48 = bitcast i32* %47 to i8*
store i8* %48, i8** %9
br label %49
49: ; preds = %41, %33
%50 = load %struct.addrinfo*, %struct.addrinfo** %3
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 0
%52 = load i64, i64* %51
%53 = load i8*, i8** %9
%54 = trunc i64 %13 to i32
%55 = call i32 @inet_ntop(i64 %52, i8* %53, i8* %15, i32 %54)
br label %56
56: ; preds = %49
%57 = load %struct.addrinfo*, %struct.addrinfo** %3
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i32 0, i32 5
%59 = load %struct.addrinfo*, %struct.addrinfo** %58
store %struct.addrinfo* %59, %struct.addrinfo** %3
br label %24
60: ; preds = %24
%61 = load %struct.addrinfo*, %struct.addrinfo** %2
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %61, i32 0, i32 0
%63 = load i64, i64* %62
%64 = load %struct.addrinfo*, %struct.addrinfo** %2
%65 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %64, i32 0, i32 4
%66 = load i32, i32* %65
%67 = load %struct.addrinfo*, %struct.addrinfo** %2
%68 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %67, i32 0, i32 3
%69 = load i32, i32* %68
%70 = call i32 @socket(i64 %63, i32 %66, i32 %69)
store i32 %70, i32* %5
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %60
%73 = load i32, i32* @errno
%74 = call i32 @strerror(i32 %73)
%75 = call i32 @log_write(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %74, i32* null)
store i32 0, i32* %1
store i32 1, i32* %8
br label %99
76: ; preds = %60
%77 = load i32, i32* %5
%78 = load %struct.addrinfo*, %struct.addrinfo** %2
%79 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %78, i32 0, i32 2
%80 = load i64, i64* %79
%81 = load %struct.addrinfo*, %struct.addrinfo** %2
%82 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %81, i32 0, i32 1
%83 = load i32, i32* %82
%84 = call i32 @connect(i32 %77, i64 %80, i32 %83)
%85 = icmp slt i32 %84, -1
br i1 %85, label %86, label %94
86: ; preds = %76
%87 = load i32, i32* @errno
%88 = call i32 @strerror(i32 %87)
%89 = call i32 @log_write(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %88, i32* null)
%90 = load %struct.addrinfo*, %struct.addrinfo** %2
%91 = call i32 @freeaddrinfo(%struct.addrinfo* %90)
%92 = load i32, i32* %5
%93 = call i32 @close(i32 %92)
store i32 0, i32* %1
store i32 1, i32* %8
br label %99
94: ; preds = %76
%95 = load i32, i32* %5
%96 = call i32 @close(i32 %95)
%97 = load %struct.addrinfo*, %struct.addrinfo** %2
%98 = call i32 @freeaddrinfo(%struct.addrinfo* %97)
store i32 1, i32* %1
store i32 1, i32* %8
br label %99
99: ; preds = %94, %86, %72, %18
%100 = load i8*, i8** %6
%101 = load i32, i32* %1
ret i32 %101
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i32, i64, i32, i32, %struct.addrinfo* }
@INET6_ADDRSTRLEN = global i32 0
@.str = [15 x i8] c"www.google.com\00"
@.str.1 = [3 x i8] c"80\00"
@.str.2 = [19 x i8] c"Internet Connector\00"
@AF_INET = global i64 0
@errno = global i32 0
define i32 @isconnected() {
%1 = alloca %struct.addrinfo*
%2 = bitcast %struct.addrinfo** %1 to i8*
%3 = load i32, i32* @INET6_ADDRSTRLEN
%4 = zext i32 %3 to i64
%5 = tail call i8* @llvm.stacksave()
%6 = alloca i8, i64 %4
%7 = call i32 @getaddrinfo(i8* getelementptr inbounds ([15 x i8], [15 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** %1)
%8 = icmp slt i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = load %struct.addrinfo*, %struct.addrinfo** %1
br label %14
11: ; preds = %0
%12 = call i32 @gai_strerror(i32 %7)
%13 = call i32 @log_write(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32* null)
br label %58
14: ; preds = %9, %14
%15 = phi %struct.addrinfo* [ %23, %14 ], [ %10, %9 ]
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %15, i64 0, i32 0
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %15, i64 0, i32 2
%18 = load i64, i64* %17
%19 = inttoptr i64 %18 to i8*
%20 = load i64, i64* %16
%21 = call i32 @inet_ntop(i64 %20, i8* %19, i8* %6, i32 %3)
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %15, i64 0, i32 5
%23 = load %struct.addrinfo*, %struct.addrinfo** %22
%24 = icmp eq %struct.addrinfo* %23, null
br i1 %24, label %25, label %14
25: ; preds = %14
%26 = load %struct.addrinfo*, %struct.addrinfo** %1
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 0
%28 = load i64, i64* %27
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 4
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 3
%32 = load i32, i32* %31
%33 = call i32 @socket(i64 %28, i32 %30, i32 %32)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %25
%36 = load i32, i32* @errno
%37 = call i32 @strerror(i32 %36)
%38 = call i32 @log_write(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %37, i32* null)
br label %58
39: ; preds = %25
%40 = load %struct.addrinfo*, %struct.addrinfo** %1
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 2
%42 = load i64, i64* %41
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 1
%44 = load i32, i32* %43
%45 = call i32 @connect(i32 %33, i64 %42, i32 %44)
%46 = icmp slt i32 %45, -1
br i1 %46, label %47, label %54
47: ; preds = %39
%48 = load i32, i32* @errno
%49 = call i32 @strerror(i32 %48)
%50 = call i32 @log_write(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %49, i32* null)
%51 = load %struct.addrinfo*, %struct.addrinfo** %1
%52 = call i32 @freeaddrinfo(%struct.addrinfo* %51)
%53 = call i32 @close(i32 %33)
br label %58
54: ; preds = %39
%55 = call i32 @close(i32 %33)
%56 = load %struct.addrinfo*, %struct.addrinfo** %1
%57 = call i32 @freeaddrinfo(%struct.addrinfo* %56)
br label %58
58: ; preds = %54, %47, %35, %11
%59 = phi i32 [ 0, %11 ], [ 0, %35 ], [ 0, %47 ], [ 1, %54 ]
ret i32 %59
}