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

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_CANONNAME;
int /*<<< orphan*/ SOCK_STREAM;
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 checkhostname(const char *hostname) {
  struct addrinfo *res, hints;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags |= AI_CANONNAME;
  if (getaddrinfo(hostname, NULL, &hints, &res)) {
    return 1;
  }
  freeaddrinfo(res);
  return 0;
}


x86 assembly (clang, -O0):
<checkhostname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1030 <memset@plt>
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x28(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1040 <getaddrinfo@plt>
cmp    $0x0,%rax
je     119e <checkhostname+0x6e>
movl   $0x1,-0x4(%rbp)
jmp    11ae <checkhostname+0x7e>
mov    -0x18(%rbp),%rdi
call   1050 <freeaddrinfo@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkhostname>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1030 <memset@plt>
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e70(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
or     %eax,(%rsp)
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1040 <getaddrinfo@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    119d <checkhostname+0x6d>
mov    0x10(%rsp),%rdi
call   1050 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_CANONNAME = global i32 0
define i32 @checkhostname(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* %5, i32 0, i32 12)
%7 = load i32, i32* @AF_UNSPEC
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 2
store i32 %7, i32* %8
%9 = load i32, i32* @SOCK_STREAM
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 1
store i32 %9, i32* %10
%11 = load i32, i32* @AI_CANONNAME
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 0
%13 = load i32, i32* %12
%14 = or i32 %13, %11
store i32 %14, i32* %12
%15 = load i8*, i8** %3
%16 = call i64 @getaddrinfo(i8* %15, i32* null, %struct.addrinfo* %5, %struct.addrinfo** %4)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %1
store i32 1, i32* %2
br label %22
19: ; preds = %1
%20 = load %struct.addrinfo*, %struct.addrinfo** %4
%21 = call i32 @freeaddrinfo(%struct.addrinfo* %20)
store i32 0, i32* %2
br label %22
22: ; preds = %19, %18
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_CANONNAME = global i32 0
define i32 @checkhostname(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* %3, i32 0, i32 12)
%7 = load i32, i32* @AF_UNSPEC
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i32 %7, i32* %8
%9 = load i32, i32* @SOCK_STREAM
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
store i32 %9, i32* %10
%11 = load i32, i32* @AI_CANONNAME
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = or i32 %13, %11
store i32 %14, i32* %12
%15 = call i64 @getaddrinfo(i8* %0, i32* null, %struct.addrinfo* %3, %struct.addrinfo** %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = load %struct.addrinfo*, %struct.addrinfo** %2
%19 = call i32 @freeaddrinfo(%struct.addrinfo* %18)
br label %20
20: ; preds = %1, %17
%21 = phi i32 [ 0, %17 ], [ 1, %1 ]
ret i32 %21
}