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

/* Variables and functions */
int EAI_SYSTEM;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ msg(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void xgetaddrinfo(const char *node, const char *service, struct addrinfo *hints,
                  struct addrinfo **res) {
  int ret;
  ret = getaddrinfo(node, service, hints, res);
  if (ret != 0) {
    msg("call to getaddrinfo() failed: %s!",
        (ret == EAI_SYSTEM) ? strerror(errno) : gai_strerror(ret));
    exit(EXIT_FAILURE);
  }
  return;
}


x86 assembly (clang, -O0):
<xgetaddrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <getaddrinfo@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11da <xgetaddrinfo+0x8a>
mov    -0x24(%rbp),%eax
mov    0x2e54(%rip),%rcx
cmp    (%rcx),%eax
jne    11b2 <xgetaddrinfo+0x62>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,-0x28(%rbp)
jmp    11bd <xgetaddrinfo+0x6d>
mov    -0x24(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xe39(%rip),%rdi
call   1070 <msg@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xgetaddrinfo>:
push   %rax
call   1050 <getaddrinfo@plt>
test   %eax,%eax
jne    115c <xgetaddrinfo+0xc>
pop    %rax
ret
mov    0x2e85(%rip),%rcx
cmp    (%rcx),%eax
jne    1177 <xgetaddrinfo+0x27>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
jmp    117e <xgetaddrinfo+0x2e>
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xe7b(%rip),%rdi
mov    %eax,%esi
call   1070 <msg@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32 }
@.str = [34 x i8] c"call to getaddrinfo() failed: %s!\00"
@EAI_SYSTEM = global i32 0
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @xgetaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %2, %struct.addrinfo** %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.addrinfo*
%8 = alloca %struct.addrinfo**
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store %struct.addrinfo* %2, %struct.addrinfo** %7
store %struct.addrinfo** %3, %struct.addrinfo*** %8
%10 = load i8*, i8** %5
%11 = load i8*, i8** %6
%12 = load %struct.addrinfo*, %struct.addrinfo** %7
%13 = load %struct.addrinfo**, %struct.addrinfo*** %8
%14 = call i32 @getaddrinfo(i8* %10, i8* %11, %struct.addrinfo* %12, %struct.addrinfo** %13)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %32
17: ; preds = %4
%18 = load i32, i32* %9
%19 = load i32, i32* @EAI_SYSTEM
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* @errno
%23 = call i32 @strerror(i32 %22)
br label %27
24: ; preds = %17
%25 = load i32, i32* %9
%26 = call i32 @gai_strerror(i32 %25)
br label %27
27: ; preds = %24, %21
%28 = phi i32 [ %23, %21 ], [ %26, %24 ]
%29 = call i32 @msg(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %4
ret void
}

LLVM IR (-O2):
%struct.addrinfo = type { i32 }
@.str = [34 x i8] c"call to getaddrinfo() failed: %s!\00"
@EAI_SYSTEM = global i32 0
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @xgetaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %2, %struct.addrinfo** %3) {
%5 = tail call i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %2, %struct.addrinfo** %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %4
%8 = load i32, i32* @EAI_SYSTEM
%9 = icmp eq i32 %5, %8
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* @errno
%12 = tail call i32 @strerror(i32 %11)
br label %15
13: ; preds = %7
%14 = tail call i32 @gai_strerror(i32 %5)
br label %15
15: ; preds = %13, %10
%16 = phi i32 [ %12, %10 ], [ %14, %13 ]
%17 = tail call i32 @msg(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %4
ret void
}