#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_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ hint;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_NUMERICHOST;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ getaddrinfo(char const *, int /*<<< orphan*/ *, struct addrinfo *,
                       struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
struct addrinfo *sxi_gethostai(const char *host) {
  struct addrinfo hint, *res;
  if (!host)
    return NULL;
  memset(&hint, 0, sizeof(hint));
  hint.ai_flags = AI_NUMERICHOST;
  hint.ai_family = AF_UNSPEC;
  hint.ai_socktype = SOCK_STREAM;
  hint.ai_protocol = IPPROTO_TCP;
  if (getaddrinfo(host, NULL, &hint, &res))
    return NULL;
  return res;
}


x86 assembly (clang, -O0):
<sxi_gethostai>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <sxi_gethostai+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11b8 <sxi_gethostai+0x98>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1040 <getaddrinfo@plt>
cmp    $0x0,%rax
je     11b0 <sxi_gethostai+0x90>
movq   $0x0,-0x8(%rbp)
jmp    11b8 <sxi_gethostai+0x98>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sxi_gethostai>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
test   %rdi,%rdi
je     119a <sxi_gethostai+0x7a>
mov    %rdi,%rbx
lea    0x8(%rsp),%r15
xor    %r14d,%r14d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0x18(%rsp),%rcx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1040 <getaddrinfo@plt>
test   %rax,%rax
jne    119d <sxi_gethostai+0x7d>
mov    0x18(%rsp),%r14
jmp    119d <sxi_gethostai+0x7d>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32 }
@AI_NUMERICHOST = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
define %struct.addrinfo* @sxi_gethostai(i8* %0) {
%2 = alloca %struct.addrinfo*
%3 = alloca i8*
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store %struct.addrinfo* null, %struct.addrinfo** %2
br label %25
9: ; preds = %1
%10 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 16)
%11 = load i32, i32* @AI_NUMERICHOST
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 3
store i32 %11, i32* %12
%13 = load i32, i32* @AF_UNSPEC
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @SOCK_STREAM
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* @IPPROTO_TCP
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 0
store i32 %17, i32* %18
%19 = load i8*, i8** %3
%20 = call i64 @getaddrinfo(i8* %19, i32* null, %struct.addrinfo* %4, %struct.addrinfo** %5)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %9
store %struct.addrinfo* null, %struct.addrinfo** %2
br label %25
23: ; preds = %9
%24 = load %struct.addrinfo*, %struct.addrinfo** %5
store %struct.addrinfo* %24, %struct.addrinfo** %2
br label %25
25: ; preds = %23, %22, %8
%26 = load %struct.addrinfo*, %struct.addrinfo** %2
ret %struct.addrinfo* %26
}

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