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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AI_NUMERICHOST;
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
scalar_t__ getaddrinfo(char const *, int /*<<< orphan*/ *, struct addrinfo *,
                       struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int is_hostaddr(const char *address) {
  struct addrinfo hints;
  struct addrinfo *res;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_INET;
  hints.ai_flags = AI_NUMERICHOST;
  if (getaddrinfo(address, NULL, &hints, &res) == 0) {
    freeaddrinfo(res);
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<is_hostaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1040 <getaddrinfo@plt>
cmp    $0x0,%rax
jne    1198 <is_hostaddr+0x68>
mov    -0x20(%rbp),%rdi
call   1050 <freeaddrinfo@plt>
movl   $0x1,-0x4(%rbp)
jmp    119f <is_hostaddr+0x6f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_hostaddr>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%r15
xor    %r14d,%r14d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1040 <getaddrinfo@plt>
test   %rax,%rax
jne    1191 <is_hostaddr+0x61>
mov    0x8(%rsp),%rdi
call   1050 <freeaddrinfo@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32 }
@AF_INET = global i32 0
@AI_NUMERICHOST = global i32 0
define i32 @is_hostaddr(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
store i8* %0, i8** %3
%6 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 8)
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 1
store i32 %7, i32* %8
%9 = load i32, i32* @AI_NUMERICHOST
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i8*, i8** %3
%12 = call i64 @getaddrinfo(i8* %11, i32* null, %struct.addrinfo* %4, %struct.addrinfo** %5)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load %struct.addrinfo*, %struct.addrinfo** %5
%16 = call i32 @freeaddrinfo(%struct.addrinfo* %15)
store i32 1, i32* %2
br label %18
17: ; preds = %1
store i32 0, i32* %2
br label %18
18: ; preds = %17, %14
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32 }
@AF_INET = global i32 0
@AI_NUMERICHOST = global i32 0
define i32 @is_hostaddr(i8* %0) {
%2 = alloca %struct.addrinfo
%3 = alloca %struct.addrinfo*
%4 = bitcast %struct.addrinfo* %2 to i8*
%5 = bitcast %struct.addrinfo** %3 to i8*
%6 = call i32 @memset(%struct.addrinfo* %2, i32 0, i32 8)
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 1
store i32 %7, i32* %8
%9 = load i32, i32* @AI_NUMERICHOST
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 0
store i32 %9, i32* %10
%11 = call i64 @getaddrinfo(i8* %0, i32* null, %struct.addrinfo* %2, %struct.addrinfo** %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load %struct.addrinfo*, %struct.addrinfo** %3
%15 = call i32 @freeaddrinfo(%struct.addrinfo* %14)
br label %16
16: ; preds = %1, %13
%17 = phi i32 [ 1, %13 ], [ 0, %1 ]
ret i32 %17
}