#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ stderr;
struct addrinfo *resolve_dns(struct addrinfo *hints, const char *host,
                             const char *port) {
  struct addrinfo *servinfo;
  int err = getaddrinfo(host, port, hints, &servinfo);
  if (err) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(err));
    exit(1);
  }
  return servinfo;
}


x86 assembly (clang, -O0):
<resolve_dns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1060 <getaddrinfo@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11a6 <resolve_dns+0x66>
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xe69(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve_dns>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rax
lea    0x8(%rsp),%rcx
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
call   1060 <getaddrinfo@plt>
test   %eax,%eax
jne    116a <resolve_dns+0x2a>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e6f(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xe7f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
%struct.addrinfo = type { i32 }
@stderr = global i32 0
@.str = [17 x i8] c"getaddrinfo: %s\0A\00"
define %struct.addrinfo* @resolve_dns(%struct.addrinfo* %0, i8* %1, i8* %2) {
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo** %4 to i8*
%6 = call i32 @getaddrinfo(i8* %1, i8* %2, %struct.addrinfo* %0, %struct.addrinfo** %4)
%7 = icmp eq i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = call i8* @gai_strerror(i32 %6)
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %3
%14 = load %struct.addrinfo*, %struct.addrinfo** %4
ret %struct.addrinfo* %14
}