#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 getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
struct addrinfo *host_serv(char *host, char *serv, int family, int socktype) {
  int n;
  struct addrinfo hints, *res;
  bzero(&hints, sizeof(struct addrinfo));
  hints.ai_flags = AI_CANONNAME;
  hints.ai_family = family;
  hints.ai_socktype = socktype;
  n = getaddrinfo(host, serv, &hints, &res);
  if (n != 0) {
    return NULL;
  } else {
    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
mov    $0xc,%esi
call   1030 <bzero@plt>
mov    0x2e9d(%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   1040 <getaddrinfo@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     118b <host_serv+0x6b>
movq   $0x0,-0x8(%rbp)
jmp    1193 <host_serv+0x73>
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    0x2e99(%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   1040 <getaddrinfo@plt>
test   %eax,%eax
jne    117b <host_serv+0x5b>
mov    0x18(%rsp),%rax
jmp    117d <host_serv+0x5d>
xor    %eax,%eax
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
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 @bzero(%struct.addrinfo* %11, 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 = load i32, i32* %10
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %4
store %struct.addrinfo* null, %struct.addrinfo** %5
br label %28
26: ; preds = %4
%27 = load %struct.addrinfo*, %struct.addrinfo** %12
store %struct.addrinfo* %27, %struct.addrinfo** %5
br label %28
28: ; preds = %26, %25
%29 = load %struct.addrinfo*, %struct.addrinfo** %5
ret %struct.addrinfo* %29
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32 }
@AI_CANONNAME = 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
%16 = load %struct.addrinfo*, %struct.addrinfo** %6
%17 = select i1 %15, %struct.addrinfo* %16, %struct.addrinfo* null
ret %struct.addrinfo* %17
}