#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;
};

/* Variables and functions */
int /*<<< orphan*/ AI_CANONNAME;
int /*<<< orphan*/ bzero(struct addrinfo *, int);
int /*<<< orphan*/ err_msg(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
struct addrinfo *host_serv(const char *hostname, const char *service,
                           int family, int sock_type) {
  struct addrinfo hints, *result;
  int error;
  bzero(&hints, sizeof(struct addrinfo));
  hints.ai_flags = AI_CANONNAME;
  hints.ai_family = family;
  hints.ai_socktype = sock_type;
  if ((error = getaddrinfo(hostname, service, &hints, &result)) != 0) {
    err_msg("error getaddrinfo: %s", strerror(errno));
    return NULL;
  }
  return result;
}


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
mov    $0xc,%esi
call   1030 <bzero@plt>
mov    0x2e7d(%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   1050 <getaddrinfo@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
je     11c6 <host_serv+0x86>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%esi
lea    0xe4c(%rip),%rdi
call   1040 <err_msg@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ce <host_serv+0x8e>
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
mov    $0xc,%esi
call   1030 <bzero@plt>
mov    0x2e79(%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   1050 <getaddrinfo@plt>
test   %eax,%eax
je     11b4 <host_serv+0x74>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe57(%rip),%rdi
mov    %eax,%esi
call   1040 <err_msg@plt>
xor    %eax,%eax
jmp    11b9 <host_serv+0x79>
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
@.str = [22 x i8] c"error getaddrinfo: %s\00"
@errno = global i32 0
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 %struct.addrinfo
%11 = alloca %struct.addrinfo*
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = call i32 @bzero(%struct.addrinfo* %10, i32 12)
%14 = load i32, i32* @AI_CANONNAME
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* %8
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* %9
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, 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* %10, %struct.addrinfo** %11)
store i32 %22, i32* %12
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %4
%25 = load i32, i32* @errno
%26 = call i32 @strerror(i32 %25)
%27 = call i32 @err_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %26)
store %struct.addrinfo* null, %struct.addrinfo** %5
br label %30
28: ; preds = %4
%29 = load %struct.addrinfo*, %struct.addrinfo** %11
store %struct.addrinfo* %29, %struct.addrinfo** %5
br label %30
30: ; preds = %28, %24
%31 = load %struct.addrinfo*, %struct.addrinfo** %5
ret %struct.addrinfo* %31
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32 }
@AI_CANONNAME = global i32 0
@.str = [22 x i8] c"error getaddrinfo: %s\00"
@errno = global i32 0
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 @bzero(%struct.addrinfo* %5, 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* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @err_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %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
}