#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_socktype;
  int /*<<< orphan*/ *ai_next;
  int /*<<< orphan*/ *ai_addr;
  int /*<<< orphan*/ *ai_canonname;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_flags;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AI_PASSIVE;
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
struct addrinfo *getAddrInfo(const char *nom, const char *service, int type) {
  struct addrinfo hints;
  struct addrinfo *result;
  int s;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_INET;
  hints.ai_socktype = type;
  hints.ai_flags = AI_PASSIVE;
  hints.ai_protocol = 0;
  hints.ai_canonname = NULL;
  hints.ai_addr = NULL;
  hints.ai_next = NULL;
  s = getaddrinfo(nom, service, &hints, &result);
  if (s != 0) {
    perror("getaddrinfo");
    return NULL;
  }
  return result;
}


x86 assembly (clang, -O0):
<getAddrInfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   1050 <getaddrinfo@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     11cc <getAddrInfo+0x9c>
lea    0xe46(%rip),%rdi
call   1040 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d4 <getAddrInfo+0xa4>
mov    -0x58(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAddrInfo>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x8(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
mov    %ebx,0x8(%rsp)
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
movups %xmm0,0x20(%rsp)
mov    %rsp,%rcx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <getaddrinfo@plt>
test   %eax,%eax
jne    11a7 <getAddrInfo+0x77>
mov    (%rsp),%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe52(%rip),%rdi
call   1040 <perror@plt>
xor    %eax,%eax
jmp    119b <getAddrInfo+0x6b>

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

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