#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 /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
struct addrinfo *get_addr_info(const char *host, const char *port) {
  struct addrinfo hints, *res;
  int status;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  if ((status = getaddrinfo(host, port, &hints, &res)) != 0) {
    fprintf(stderr, "[net] getaddrinfo failed: %s\n", gai_strerror(status));
    return NULL;
  }
  return res;
}


x86 assembly (clang, -O0):
<get_addr_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1060 <getaddrinfo@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
je     11cc <get_addr_info+0x8c>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rdx
lea    0xe46(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d4 <get_addr_info+0x94>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_addr_info>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <getaddrinfo@plt>
test   %eax,%eax
je     11b6 <get_addr_info+0x76>
mov    0x2e40(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xe58(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
xor    %eax,%eax
jmp    11bb <get_addr_info+0x7b>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"[net] getaddrinfo failed: %s\0A\00"
define %struct.addrinfo* @get_addr_info(i8* %0, i8* %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo* %3 to i8*
%6 = bitcast %struct.addrinfo** %4 to i8*
%7 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 8)
%8 = load i32, i32* @AF_UNSPEC
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
store i32 %8, i32* %9
%10 = load i32, i32* @SOCK_STREAM
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 0
store i32 %10, i32* %11
%12 = call i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %3, %struct.addrinfo** %4)
%13 = icmp eq i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i8* @gai_strerror(i32 %12)
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %20
18: ; preds = %2
%19 = load %struct.addrinfo*, %struct.addrinfo** %4
br label %20
20: ; preds = %18, %14
%21 = phi %struct.addrinfo* [ null, %14 ], [ %19, %18 ]
ret %struct.addrinfo* %21
}