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

/* Variables and functions */
int /*<<< orphan*/ AI_CANONNAME;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
struct addrinfo *host_serv(const char *hostname, const char *service,
                           int family, int socktype) {
  int n;
  struct addrinfo hints, *res;
  memset(&hints, 0, sizeof(hints));
  hints.ai_flags = AI_CANONNAME;
  hints.ai_family = family;
  hints.ai_socktype = socktype;
  if ((n = getaddrinfo(hostname, service, &hints, &res)) != 0) {
    fprintf(stderr, "host_serv - getaddrinfo() failed: %s\n", gai_strerror(n));
    return NULL;
  }
  return res;
}


x86 assembly (clang, -O0):
<host_serv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1060 <getaddrinfo@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     11d2 <host_serv+0x92>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xe40(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11da <host_serv+0x9a>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<host_serv>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x8(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %ebp,0x8(%rsp)
mov    %ebx,0xc(%rsp)
lea    0x18(%rsp),%rcx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1060 <getaddrinfo@plt>
test   %eax,%eax
je     11bb <host_serv+0x7b>
mov    0x2e3b(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xe53(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
xor    %eax,%eax
jmp    11c0 <host_serv+0x80>
mov    0x18(%rsp),%rax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32 }
@AI_CANONNAME = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"host_serv - getaddrinfo() failed: %s\0A\00"
define %struct.addrinfo* @host_serv(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca %struct.addrinfo*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.addrinfo
%12 = alloca %struct.addrinfo*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = call i32 @memset(%struct.addrinfo* %11, i32 0, i32 12)
%14 = load i32, i32* @AI_CANONNAME
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* %8
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* %9
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 1
store i32 %18, i32* %19
%20 = load i8*, i8** %6
%21 = load i8*, i8** %7
%22 = call i32 @getaddrinfo(i8* %20, i8* %21, %struct.addrinfo* %11, %struct.addrinfo** %12)
store i32 %22, i32* %10
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %4
%25 = load i32, i32* @stderr
%26 = load i32, i32* %10
%27 = call i8* @gai_strerror(i32 %26)
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %27)
store %struct.addrinfo* null, %struct.addrinfo** %5
br label %31
29: ; preds = %4
%30 = load %struct.addrinfo*, %struct.addrinfo** %12
store %struct.addrinfo* %30, %struct.addrinfo** %5
br label %31
31: ; preds = %29, %24
%32 = load %struct.addrinfo*, %struct.addrinfo** %5
ret %struct.addrinfo* %32
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32 }
@AI_CANONNAME = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"host_serv - getaddrinfo() failed: %s\0A\00"
define %struct.addrinfo* @host_serv(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = bitcast %struct.addrinfo* %5 to i8*
%8 = bitcast %struct.addrinfo** %6 to i8*
%9 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 12)
%10 = load i32, i32* @AI_CANONNAME
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 2
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 0
store i32 %2, i32* %12
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 1
store i32 %3, i32* %13
%14 = call i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %5, %struct.addrinfo** %6)
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %4
%17 = load i32, i32* @stderr
%18 = call i8* @gai_strerror(i32 %14)
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %22
20: ; preds = %4
%21 = load %struct.addrinfo*, %struct.addrinfo** %6
br label %22
22: ; preds = %20, %16
%23 = phi %struct.addrinfo* [ null, %16 ], [ %21, %20 ]
ret %struct.addrinfo* %23
}