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

/* Variables and functions */
int INET6_ADDRSTRLEN;
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;
int setup_addrinfo(struct addrinfo **servinfo, const char *node,
                   const char *service, int ai_flags, int ai_family,
                   int ai_socktype) {
  struct addrinfo hints;
  struct addrinfo *p;
  int rv;
  char ipstr[INET6_ADDRSTRLEN];
  memset(&hints, 0, sizeof hints);
  hints.ai_flags = ai_flags;
  hints.ai_family = ai_family;
  hints.ai_socktype = ai_socktype;
  if ((rv = getaddrinfo(node, service, &hints, servinfo)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<setup_addrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,-0x58(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rcx
lea    -0x38(%rbp),%rdx
call   1060 <getaddrinfo@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
je     11ef <setup_addrinfo+0xaf>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x44(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x60(%rbp),%edi
mov    %rax,%rdx
lea    0xe29(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    11fd <setup_addrinfo+0xbd>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_addrinfo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r14d
mov    %r8d,%ebp
mov    %ecx,%ebx
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
mov    %rsp,0x10(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    %ebx,(%rsp)
mov    %ebp,0x4(%rsp)
mov    %r14d,0x8(%rsp)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rsp,%rdx
mov    %r13,%rcx
call   1060 <getaddrinfo@plt>
test   %eax,%eax
je     11b5 <setup_addrinfo+0x75>
mov    0x2e45(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xe55(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    0x10(%rsp),%rsp
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32 }
@INET6_ADDRSTRLEN = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"getaddrinfo: %s\0A\00"
define i32 @setup_addrinfo(%struct.addrinfo** %0, i8* %1, i8* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca %struct.addrinfo**
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.addrinfo
%15 = alloca %struct.addrinfo*
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i64
%19 = alloca i32
store %struct.addrinfo** %0, %struct.addrinfo*** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%20 = load i32, i32* @INET6_ADDRSTRLEN
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %17
%23 = alloca i8, i64 %21
store i64 %21, i64* %18
%24 = call i32 @memset(%struct.addrinfo* %14, i32 0, i32 12)
%25 = load i32, i32* %11
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %14, i32 0, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* %12
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %14, i32 0, i32 1
store i32 %27, i32* %28
%29 = load i32, i32* %13
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %14, i32 0, i32 2
store i32 %29, i32* %30
%31 = load i8*, i8** %9
%32 = load i8*, i8** %10
%33 = load %struct.addrinfo**, %struct.addrinfo*** %8
%34 = call i32 @getaddrinfo(i8* %31, i8* %32, %struct.addrinfo* %14, %struct.addrinfo** %33)
store i32 %34, i32* %16
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %6
%37 = load i32, i32* @stderr
%38 = load i32, i32* %16
%39 = call i8* @gai_strerror(i32 %38)
%40 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %39)
store i32 0, i32* %7
store i32 1, i32* %19
br label %42
41: ; preds = %6
store i32 0, i32* %7
store i32 1, i32* %19
br label %42
42: ; preds = %41, %36
%43 = load i8*, i8** %17
%44 = load i32, i32* %7
ret i32 %44
}

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