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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
void setup_addrinfo(struct addrinfo **servinfo, char *hostname, char *port,
                    int flags) {
  struct addrinfo hints;
  int rv;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = flags;
  if ((rv = getaddrinfo(hostname, port, &hints, servinfo)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
    freeaddrinfo(*servinfo);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<setup_addrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rcx
lea    -0x28(%rbp),%rdx
call   1070 <getaddrinfo@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
je     1202 <setup_addrinfo+0xa2>
mov    0x2e0b(%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    0xe19(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1080 <freeaddrinfo@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_addrinfo>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %ebp,(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
call   1070 <getaddrinfo@plt>
test   %eax,%eax
jne    11c8 <setup_addrinfo+0x68>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e09(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xe21(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    (%r14),%rdi
call   1080 <freeaddrinfo@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

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