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

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, char *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ stderr;
struct addrinfo *default_addrinfo(char *host, char *port) {
  struct addrinfo hints = {0};
  struct addrinfo *res = NULL;
  int status;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_family = AF_UNSPEC;
  hints.ai_flags = (host) ? 0 : AI_PASSIVE;
  if (!(status = getaddrinfo(host, port, &hints, &res)))
    return res;
  fprintf(stderr, "[Error] Couldn't open %s:%s!  (Err: %s)\n", host, port,
          gai_strerror(status));
  exit(1);
}


x86 assembly (clang, -O0):
<default_addrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
movq   $0x0,-0x28(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11a5 <default_addrinfo+0x55>
xor    %eax,%eax
mov    %eax,-0x30(%rbp)
jmp    11b1 <default_addrinfo+0x61>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1070 <getaddrinfo@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jne    11e2 <default_addrinfo+0x92>
mov    -0x28(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    %rax,%r8
lea    0xde5(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<default_addrinfo>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,0x1c(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
xor    %eax,%eax
test   %rdi,%rdi
jne    1189 <default_addrinfo+0x49>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <getaddrinfo@plt>
test   %eax,%eax
jne    11b4 <default_addrinfo+0x74>
mov    0x8(%rsp),%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e15(%rip),%rcx
mov    (%rcx),%ebp
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xe35(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %rax,%r8
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32 }
@SOCK_STREAM = global i32 0
@AF_UNSPEC = global i32 0
@AI_PASSIVE = global i32 0
@stderr = global i32 0
@.str = [41 x i8] c"[Error] Couldn't open %s:%s! (Err: %s)\0A\00"
define %struct.addrinfo* @default_addrinfo(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = bitcast %struct.addrinfo* %5 to i8*
store %struct.addrinfo* null, %struct.addrinfo** %6
%9 = load i32, i32* @SOCK_STREAM
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 2
store i32 %9, i32* %10
%11 = load i32, i32* @AF_UNSPEC
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 1
store i32 %11, i32* %12
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
br label %18
16: ; preds = %2
%17 = load i32, i32* @AI_PASSIVE
br label %18
18: ; preds = %16, %15
%19 = phi i32 [ 0, %15 ], [ %17, %16 ]
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i8*, i8** %3
%22 = load i8*, i8** %4
%23 = call i32 @getaddrinfo(i8* %21, i8* %22, %struct.addrinfo* %5, %struct.addrinfo** %6)
store i32 %23, i32* %7
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %18
%26 = load %struct.addrinfo*, %struct.addrinfo** %6
ret %struct.addrinfo* %26
27: ; preds = %18
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %3
%30 = load i8*, i8** %4
%31 = load i32, i32* %7
%32 = call i8* @gai_strerror(i32 %31)
%33 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %29, i8* %30, i8* %32)
%34 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32 }
@SOCK_STREAM = global i32 0
@AF_UNSPEC = global i32 0
@AI_PASSIVE = global i32 0
@stderr = global i32 0
@.str = [41 x i8] c"[Error] Couldn't open %s:%s! (Err: %s)\0A\00"
define %struct.addrinfo* @default_addrinfo(i8* %0, i8* %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo* %3 to i8*
%6 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 0, i32* %6
%7 = bitcast %struct.addrinfo** %4 to i8*
store %struct.addrinfo* null, %struct.addrinfo** %4
%8 = load i32, i32* @SOCK_STREAM
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i32 %8, i32* %9
%10 = load i32, i32* @AF_UNSPEC
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
store i32 %10, i32* %11
%12 = icmp eq i8* %0, null
%13 = load i32, i32* @AI_PASSIVE
%14 = select i1 %12, i32 %13, i32 0
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 0
store i32 %14, i32* %15
%16 = call i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %3, %struct.addrinfo** %4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = load %struct.addrinfo*, %struct.addrinfo** %4
ret %struct.addrinfo* %19
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i8* @gai_strerror(i32 %16)
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
}