#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_addr;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int /*<<< orphan*/ addrCriteria;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printAddrInfo(int /*<<< orphan*/);
int /*<<< orphan*/ sysError(char *, int /*<<< orphan*/);
int /*<<< orphan*/ userError(char *);
int main(int argc, char **argv) {
  if (argc != 3)
    userError("Usage: GetAddrInfo <address/domain> <port/service>\n");
  char *addrString = argv[1];
  char *portString = argv[2];
  struct addrinfo addrCriteria;
  memset(&addrCriteria, 0, sizeof(addrCriteria));
  addrCriteria.ai_family = AF_UNSPEC;
  addrCriteria.ai_socktype = SOCK_STREAM;
  addrCriteria.ai_protocol = IPPROTO_TCP;
  struct addrinfo *addrList;
  int ret = getaddrinfo(addrString, portString, &addrCriteria, &addrList);
  if (ret != 0)
    sysError("failed to get address list", gai_strerror(ret));
  for (struct addrinfo *addr = addrList; addr != NULL; addr = addr->ai_next)
    printAddrInfo(addr->ai_addr);
  freeaddrinfo(addrList);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119c <main+0x2c>
lea    0xe69(%rip),%rdi
call   1070 <userError@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1080 <getaddrinfo@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     1220 <main+0xb0>
mov    -0x4c(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    %eax,%esi
lea    0xe19(%rip),%rdi
call   1030 <sysError@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     124f <main+0xdf>
mov    -0x58(%rbp),%rax
mov    (%rax),%edi
call   1060 <printAddrInfo@plt>
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    1228 <main+0xb8>
mov    -0x48(%rbp),%rdi
call   1090 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
je     118d <main+0x1d>
lea    0xe78(%rip),%rdi
call   1070 <userError@plt>
mov    0x8(%rbx),%r14
mov    0x10(%rbx),%rbx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
lea    0x8(%rsp),%rcx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1080 <getaddrinfo@plt>
test   %eax,%eax
je     11fc <main+0x8c>
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xe3f(%rip),%rdi
mov    %eax,%esi
call   1030 <sysError@plt>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     1227 <main+0xb7>
cs nopw 0x0(%rax,%rax,1)
mov    (%rbx),%edi
call   1060 <printAddrInfo@plt>
mov    0x8(%rbx),%rbx
test   %rbx,%rbx
jne    1210 <main+0xa0>
mov    0x8(%rsp),%rdi
jmp    1229 <main+0xb9>
xor    %edi,%edi
call   1090 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, %struct.addrinfo*, i32, i32, i32 }
@.str = [52 x i8] c"Usage: GetAddrInfo <address/domain> <port/service>\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [27 x i8] c"failed to get address list\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.addrinfo
%9 = alloca %struct.addrinfo*
%10 = alloca i32
%11 = alloca %struct.addrinfo*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @userError(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
store i8* %22, i8** %7
%23 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 32)
%24 = load i32, i32* @AF_UNSPEC
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 4
store i32 %24, i32* %25
%26 = load i32, i32* @SOCK_STREAM
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 3
store i32 %26, i32* %27
%28 = load i32, i32* @IPPROTO_TCP
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 2
store i32 %28, i32* %29
%30 = load i8*, i8** %6
%31 = load i8*, i8** %7
%32 = call i32 @getaddrinfo(i8* %30, i8* %31, %struct.addrinfo* %8, %struct.addrinfo** %9)
store i32 %32, i32* %10
%33 = load i32, i32* %10
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %16
%36 = load i32, i32* %10
%37 = call i32 @gai_strerror(i32 %36)
%38 = call i32 @sysError(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %35, %16
%40 = load %struct.addrinfo*, %struct.addrinfo** %9
store %struct.addrinfo* %40, %struct.addrinfo** %11
br label %41
41: ; preds = %49, %39
%42 = load %struct.addrinfo*, %struct.addrinfo** %11
%43 = icmp ne %struct.addrinfo* %42, null
br i1 %43, label %44, label %53
44: ; preds = %41
%45 = load %struct.addrinfo*, %struct.addrinfo** %11
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 @printAddrInfo(i32 %47)
br label %49
49: ; preds = %44
%50 = load %struct.addrinfo*, %struct.addrinfo** %11
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 1
%52 = load %struct.addrinfo*, %struct.addrinfo** %51
store %struct.addrinfo* %52, %struct.addrinfo** %11
br label %41
53: ; preds = %41
%54 = load %struct.addrinfo*, %struct.addrinfo** %9
%55 = call i32 @freeaddrinfo(%struct.addrinfo* %54)
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, %struct.addrinfo*, i32, i32, i32 }
@.str = [52 x i8] c"Usage: GetAddrInfo <address/domain> <port/service>\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [27 x i8] c"failed to get address list\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @userError(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = bitcast %struct.addrinfo* %3 to i8*
%14 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 32)
%15 = load i32, i32* @AF_UNSPEC
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %15, i32* %16
%17 = load i32, i32* @SOCK_STREAM
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %17, i32* %18
%19 = load i32, i32* @IPPROTO_TCP
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i32 %19, i32* %20
%21 = bitcast %struct.addrinfo** %4 to i8*
%22 = call i32 @getaddrinfo(i8* %10, i8* %12, %struct.addrinfo* %3, %struct.addrinfo** %4)
%23 = icmp eq i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %8
%25 = call i32 @gai_strerror(i32 %22)
%26 = call i32 @sysError(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %24, %8
%28 = load %struct.addrinfo*, %struct.addrinfo** %4
%29 = icmp eq %struct.addrinfo* %28, null
br i1 %29, label %32, label %35
30: ; preds = %35
%31 = load %struct.addrinfo*, %struct.addrinfo** %4
br label %32
32: ; preds = %30, %27
%33 = phi %struct.addrinfo* [ %31, %30 ], [ null, %27 ]
%34 = call i32 @freeaddrinfo(%struct.addrinfo* %33)
ret i32 0
35: ; preds = %27, %35
%36 = phi %struct.addrinfo* [ %41, %35 ], [ %28, %27 ]
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 @printAddrInfo(i32 %38)
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 1
%41 = load %struct.addrinfo*, %struct.addrinfo** %40
%42 = icmp eq %struct.addrinfo* %41, null
br i1 %42, label %30, label %35
}