#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 in_addr {
  int dummy;
};
struct sockaddr_in {
  struct in_addr sin_addr;
};
struct addrinfo {
  scalar_t__ ai_addr;
};

/* Variables and functions */
int getaddrinfo(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                struct addrinfo **);
struct in_addr *is_val_host(char *hostname) {
  int error;
  struct addrinfo *addressInfo;
  error = getaddrinfo(hostname, NULL, NULL, &addressInfo);
  if (error) {
    return NULL;
  }
  return &(((struct sockaddr_in *)(addressInfo->ai_addr))->sin_addr);
}


x86 assembly (clang, -O0):
<is_val_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x20(%rbp),%rcx
mov    %rdx,%rsi
call   1030 <getaddrinfo@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     114a <is_val_host+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    1155 <is_val_host+0x45>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_val_host>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
lea    0x8(%rsp),%rcx
xor    %esi,%esi
xor    %edx,%edx
call   1030 <getaddrinfo@plt>
test   %eax,%eax
jne    1131 <is_val_host+0x21>
mov    0x8(%rsp),%rax
mov    (%rax),%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.addrinfo = type { i64 }
%struct.sockaddr_in = type { %struct.in_addr }
define %struct.in_addr* @is_val_host(i8* %0) {
%2 = alloca %struct.addrinfo*
%3 = bitcast %struct.addrinfo** %2 to i8*
%4 = call i32 @getaddrinfo(i8* %0, i32* null, i32* null, %struct.addrinfo** %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %1
%7 = load %struct.addrinfo*, %struct.addrinfo** %2
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 0
%9 = load i64, i64* %8
%10 = inttoptr i64 %9 to %struct.sockaddr_in*
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i64 0, i32 0
br label %12
12: ; preds = %1, %6
%13 = phi %struct.in_addr* [ %11, %6 ], [ null, %1 ]
ret %struct.in_addr* %13
}