#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_quit(char *, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
struct addrinfo *Host_serv(const char *host, const 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;
  if ((n = getaddrinfo(host, serv, &hints, &res)) != 0)
    err_quit("host_serv error for %s, %s: %s",
             (host == NULL) ? "(no hostname)" : host,
             (serv == NULL) ? "(no service name)" : serv, gai_strerror(n));
  return (res);
}


x86 assembly (clang, -O0):
<Host_serv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   1050 <bzero@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1060 <getaddrinfo@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1211 <Host_serv+0xd1>
cmpq   $0x0,-0x8(%rbp)
jne    11b8 <Host_serv+0x78>
lea    0xe70(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    11c0 <Host_serv+0x80>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e3 <Host_serv+0xa3>
lea    0xe53(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    11eb <Host_serv+0xab>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x40(%rbp),%rsi
mov    -0x50(%rbp),%rdx
mov    %eax,%ecx
lea    0xdf4(%rip),%rdi
call   1040 <err_quit@plt>
mov    -0x30(%rbp),%rax
add    $0x50,%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,%r15d
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x8(%rsp),%r12
mov    %r12,%rdi
mov    $0xc,%esi
call   1050 <bzero@plt>
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %ebp,0x8(%rsp)
mov    %r15d,0xc(%rsp)
lea    0x18(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1060 <getaddrinfo@plt>
test   %eax,%eax
je     11cd <Host_serv+0x8d>
test   %rbx,%rbx
lea    0xe7f(%rip),%rbp
cmovne %rbx,%rbp
test   %r14,%r14
lea    0xe7f(%rip),%rbx
cmovne %r14,%rbx
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xe40(%rip),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1040 <err_quit@plt>
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 = [31 x i8] c"host_serv error for %s, %s: %s\00"
@.str.1 = [14 x i8] c"(no hostname)\00"
@.str.2 = [18 x i8] c"(no service name)\00"
define %struct.addrinfo* @Host_serv(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.addrinfo
%11 = alloca %struct.addrinfo*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = call i32 @bzero(%struct.addrinfo* %10, i32 12)
%13 = load i32, i32* @AI_CANONNAME
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* %7
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* %8
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 1
store i32 %17, i32* %18
%19 = load i8*, i8** %5
%20 = load i8*, i8** %6
%21 = call i32 @getaddrinfo(i8* %19, i8* %20, %struct.addrinfo* %10, %struct.addrinfo** %11)
store i32 %21, i32* %9
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %41
23: ; preds = %4
%24 = load i8*, i8** %5
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %23
br label %29
27: ; preds = %23
%28 = load i8*, i8** %5
br label %29
29: ; preds = %27, %26
%30 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), %26 ], [ %28, %27 ]
%31 = load i8*, i8** %6
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %34
33: ; preds = %29
br label %36
34: ; preds = %29
%35 = load i8*, i8** %6
br label %36
36: ; preds = %34, %33
%37 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), %33 ], [ %35, %34 ]
%38 = load i32, i32* %9
%39 = call i32 @gai_strerror(i32 %38)
%40 = call i32 @err_quit(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %30, i8* %37, i32 %39)
br label %41
41: ; preds = %36, %4
%42 = load %struct.addrinfo*, %struct.addrinfo** %11
ret %struct.addrinfo* %42
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32 }
@AI_CANONNAME = global i32 0
@.str = [31 x i8] c"host_serv error for %s, %s: %s\00"
@.str.1 = [14 x i8] c"(no hostname)\00"
@.str.2 = [18 x i8] c"(no service name)\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 @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 %23, label %16
16: ; preds = %4
%17 = icmp eq i8* %0, null
%18 = select i1 %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %0
%19 = icmp eq i8* %1, null
%20 = select i1 %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %1
%21 = call i32 @gai_strerror(i32 %14)
%22 = call i32 @err_quit(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %20, i32 %21)
br label %23
23: ; preds = %16, %4
%24 = load %struct.addrinfo*, %struct.addrinfo** %6
ret %struct.addrinfo* %24
}