#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 sockaddr_in {
  unsigned short sin_port;
  int /*<<< orphan*/ sin_addr;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int ai_socktype;
  int ai_protocol;
  int ai_addrlen;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_canonname;
  struct sockaddr *ai_addr;
  void *ai_family;
};

/* Variables and functions */
void *AF_INET;
int AI_CANONNAME;
int EAI_MEMORY;
int EAI_NONAME;
int SOCK_DGRAM;
int SOCK_STREAM;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo_parse_hints(struct addrinfo const *, int *, int *, int *);
int getaddrinfo_resolve_hostname(char const *, int, char ***, char const **);
int getaddrinfo_resolve_servname(char const *, int, int, unsigned short *,
                                 int *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ strdup(char const *);
int getaddrinfo(const char *nodename, const char *servname,
                const struct addrinfo *hints, struct addrinfo **res) {
  struct addrinfo *addrinfo, **addrinfo_p;
  char **addr_list;
  const char *canonname;
  int flags, i, protocol, protocol_spec, r, result;
  unsigned short port;
  struct sockaddr_in *sockaddr;
  int socktype, socktype_spec;
  if ((!nodename && !servname) || !res)
    return EAI_NONAME;
  if ((r = getaddrinfo_parse_hints(hints, &flags, &socktype_spec,
                                   &protocol_spec)))
    return r;
  if ((r = getaddrinfo_resolve_hostname(nodename, flags, &addr_list,
                                        &canonname)))
    return r;
  addrinfo_p = res;
  *addrinfo_p = NULL;
  result = EAI_NONAME;
  while (*addr_list) {
    for (i = 0; i < 2; i++) {
      socktype = (i == 0) ? SOCK_STREAM : SOCK_DGRAM;
      if (socktype_spec != 0 && socktype_spec != socktype)
        continue;
      if ((r = getaddrinfo_resolve_servname(servname, flags, socktype, &port,
                                            &protocol))) {
        freeaddrinfo(*res);
        return r;
      }
      if (!protocol)
        protocol = protocol_spec;
      else if (protocol_spec && protocol != protocol_spec)
        continue;
      *addrinfo_p = addrinfo =
          (struct addrinfo *)calloc(1, sizeof(struct addrinfo));
      if (!addrinfo) {
        freeaddrinfo(*res);
        return EAI_MEMORY;
      }
      sockaddr = (struct sockaddr_in *)calloc(1, sizeof(struct sockaddr_in));
      if (!sockaddr) {
        freeaddrinfo(*res);
        return EAI_MEMORY;
      }
      addrinfo->ai_family = AF_INET;
      addrinfo->ai_socktype = socktype;
      addrinfo->ai_protocol = protocol;
      addrinfo->ai_addrlen = sizeof(*sockaddr);
      addrinfo->ai_addr = (struct sockaddr *)sockaddr;
      sockaddr->sin_family = AF_INET;
      sockaddr->sin_port = port;
      memcpy(&sockaddr->sin_addr, *addr_list, sizeof(sockaddr->sin_addr));
      if (((flags & AI_CANONNAME) == AI_CANONNAME) && canonname) {
        addrinfo->ai_canonname = strdup(canonname);
        if (!addrinfo->ai_canonname) {
          freeaddrinfo(*res);
          return EAI_MEMORY;
        }
      }
      result = 0;
      addrinfo_p = &addrinfo->ai_next;
    }
    addr_list++;
  }
  return result;
}


x86 assembly (clang, -O0):
<getaddrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a1 <getaddrinfo+0x31>
cmpq   $0x0,-0x18(%rbp)
je     11ac <getaddrinfo+0x3c>
cmpq   $0x0,-0x28(%rbp)
jne    11bd <getaddrinfo+0x4d>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    149b <getaddrinfo+0x32b>
mov    -0x20(%rbp),%rdi
lea    -0x4c(%rbp),%rsi
lea    -0x78(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   1070 <getaddrinfo_parse_hints@plt>
mov    %eax,-0x5c(%rbp)
cmp    $0x0,%eax
je     11e9 <getaddrinfo+0x79>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    149b <getaddrinfo+0x32b>
mov    -0x10(%rbp),%rdi
mov    -0x4c(%rbp),%esi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1060 <getaddrinfo_resolve_hostname@plt>
mov    %eax,-0x5c(%rbp)
cmp    $0x0,%eax
je     1214 <getaddrinfo+0xa4>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    149b <getaddrinfo+0x32b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movq   $0x0,(%rax)
mov    0x2db2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x40(%rbp),%rax
cmpq   $0x0,(%rax)
je     1495 <getaddrinfo+0x325>
movl   $0x0,-0x50(%rbp)
cmpl   $0x2,-0x50(%rbp)
jge    1484 <getaddrinfo+0x314>
cmpl   $0x0,-0x50(%rbp)
jne    126d <getaddrinfo+0xfd>
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
jmp    1279 <getaddrinfo+0x109>
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x78(%rbp)
je     129a <getaddrinfo+0x12a>
mov    -0x78(%rbp),%eax
cmp    -0x74(%rbp),%eax
je     129a <getaddrinfo+0x12a>
jmp    1476 <getaddrinfo+0x306>
mov    -0x18(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    -0x74(%rbp),%edx
lea    -0x62(%rbp),%rcx
lea    -0x54(%rbp),%r8
call   1030 <getaddrinfo_resolve_servname@plt>
mov    %eax,-0x5c(%rbp)
cmp    $0x0,%eax
je     12d4 <getaddrinfo+0x164>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1090 <freeaddrinfo@plt>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    149b <getaddrinfo+0x32b>
cmpl   $0x0,-0x54(%rbp)
jne    12e9 <getaddrinfo+0x179>
mov    -0x58(%rbp),%eax
mov    %eax,-0x54(%rbp)
jmp    1309 <getaddrinfo+0x199>
cmpl   $0x0,-0x58(%rbp)
je     1304 <getaddrinfo+0x194>
mov    -0x54(%rbp),%eax
cmp    -0x58(%rbp),%eax
je     1304 <getaddrinfo+0x194>
jmp    1476 <getaddrinfo+0x306>
jmp    1309 <getaddrinfo+0x199>
mov    $0x1,%edi
mov    $0x30,%esi
call   1040 <calloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x30(%rbp)
jne    134e <getaddrinfo+0x1de>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1090 <freeaddrinfo@plt>
mov    0x2c74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    149b <getaddrinfo+0x32b>
mov    $0x1,%edi
mov    $0x10,%esi
call   1040 <calloc@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    1389 <getaddrinfo+0x219>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1090 <freeaddrinfo@plt>
mov    0x2c39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    149b <getaddrinfo+0x32b>
mov    0x2c58(%rip),%rax
mov    (%rax),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    -0x74(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x54(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x30(%rbp),%rax
movl   $0x10,0x8(%rax)
mov    -0x70(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    0x2c1c(%rip),%rax
mov    (%rax),%rcx
mov    -0x70(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x62(%rbp),%cx
mov    -0x70(%rbp),%rax
mov    %cx,(%rax)
mov    -0x70(%rbp),%rdi
add    $0x4,%rdi
mov    -0x40(%rbp),%rax
mov    (%rax),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    -0x4c(%rbp),%eax
mov    0x2bd3(%rip),%rcx
and    (%rcx),%eax
mov    0x2bca(%rip),%rcx
cmp    (%rcx),%eax
jne    1463 <getaddrinfo+0x2f3>
cmpq   $0x0,-0x48(%rbp)
je     1463 <getaddrinfo+0x2f3>
mov    -0x48(%rbp),%rdi
call   1080 <strdup@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x30(%rbp),%rax
cmpl   $0x0,0x18(%rax)
jne    145e <getaddrinfo+0x2ee>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1090 <freeaddrinfo@plt>
mov    0x2b64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    149b <getaddrinfo+0x32b>
jmp    1463 <getaddrinfo+0x2f3>
movl   $0x0,-0x60(%rbp)
mov    -0x30(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x38(%rbp)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1248 <getaddrinfo+0xd8>
mov    -0x40(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x40(%rbp)
jmp    1233 <getaddrinfo+0xc3>
mov    -0x60(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getaddrinfo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rax
or     %rsi,%rax
je     11f0 <getaddrinfo+0x80>
mov    %rcx,%r14
test   %rcx,%rcx
je     11f0 <getaddrinfo+0x80>
mov    %rsi,%r13
mov    %rdi,%rbx
lea    0xc(%rsp),%rsi
lea    0x18(%rsp),%rax
lea    0x1c(%rsp),%rcx
mov    %rdx,%rdi
mov    %rax,%rdx
call   1070 <getaddrinfo_parse_hints@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11f9 <getaddrinfo+0x89>
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rdx
lea    0x20(%rsp),%rcx
mov    %rbx,%rdi
call   1060 <getaddrinfo_resolve_hostname@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11f9 <getaddrinfo+0x89>
movq   $0x0,(%r14)
mov    0x2e02(%rip),%rax
mov    (%rax),%ebp
mov    0x10(%rsp),%rax
cmpq   $0x0,(%rax)
je     11f9 <getaddrinfo+0x89>
mov    %r14,%r12
jmp    1228 <getaddrinfo+0xb8>
mov    0x2de9(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x10,%rbx
xor    %ebp,%ebp
mov    %rbx,%r12
mov    0x10(%rsp),%rax
lea    0x8(%rax),%rcx
mov    %rcx,0x10(%rsp)
cmpq   $0x0,0x8(%rax)
je     11f9 <getaddrinfo+0x89>
mov    0x2d91(%rip),%rax
mov    (%rax),%r15d
mov    0x18(%rsp),%eax
test   %eax,%eax
je     1243 <getaddrinfo+0xd3>
cmp    %r15d,%eax
jne    1335 <getaddrinfo+0x1c5>
mov    0xc(%rsp),%esi
mov    %r13,%rdi
mov    %r15d,%edx
lea    0xa(%rsp),%rcx
lea    0x4(%rsp),%r8
call   1030 <getaddrinfo_resolve_servname@plt>
test   %eax,%eax
jne    1451 <getaddrinfo+0x2e1>
mov    0x4(%rsp),%eax
mov    0x1c(%rsp),%ecx
test   %eax,%eax
je     127e <getaddrinfo+0x10e>
test   %ecx,%ecx
je     1282 <getaddrinfo+0x112>
cmp    %ecx,%eax
jne    1335 <getaddrinfo+0x1c5>
jmp    1282 <getaddrinfo+0x112>
mov    %ecx,0x4(%rsp)
mov    $0x1,%edi
mov    $0x30,%esi
call   1040 <calloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     143d <getaddrinfo+0x2cd>
mov    %rax,%rbx
mov    $0x1,%edi
mov    $0x10,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     143d <getaddrinfo+0x2cd>
mov    0x2d28(%rip),%rcx
mov    (%rcx),%rcx
mov    %rcx,0x28(%rbx)
mov    %r15d,(%rbx)
mov    0x4(%rsp),%edx
mov    %edx,0x4(%rbx)
movl   $0x10,0x8(%rbx)
mov    %rax,0x20(%rbx)
mov    %rcx,0x8(%rax)
movzwl 0xa(%rsp),%ecx
mov    %cx,(%rax)
add    $0x4,%rax
mov    0x10(%rsp),%rcx
mov    (%rcx),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    0xc(%rsp),%eax
not    %eax
mov    0x2cca(%rip),%rcx
test   %eax,(%rcx)
jne    132c <getaddrinfo+0x1bc>
mov    0x20(%rsp),%rdi
test   %rdi,%rdi
je     132c <getaddrinfo+0x1bc>
call   1080 <strdup@plt>
mov    %eax,0x18(%rbx)
test   %eax,%eax
je     143d <getaddrinfo+0x2cd>
add    $0x10,%rbx
xor    %ebp,%ebp
mov    %rbx,%r12
mov    0x2c94(%rip),%rax
mov    (%rax),%r15d
mov    0x18(%rsp),%eax
test   %eax,%eax
je     1350 <getaddrinfo+0x1e0>
cmp    %r15d,%eax
jne    1213 <getaddrinfo+0xa3>
mov    0xc(%rsp),%esi
mov    %r13,%rdi
mov    %r15d,%edx
lea    0xa(%rsp),%rcx
lea    0x4(%rsp),%r8
call   1030 <getaddrinfo_resolve_servname@plt>
test   %eax,%eax
jne    1451 <getaddrinfo+0x2e1>
mov    0x4(%rsp),%eax
mov    0x1c(%rsp),%ecx
test   %eax,%eax
je     138b <getaddrinfo+0x21b>
test   %ecx,%ecx
je     138f <getaddrinfo+0x21f>
cmp    %ecx,%eax
jne    1213 <getaddrinfo+0xa3>
jmp    138f <getaddrinfo+0x21f>
mov    %ecx,0x4(%rsp)
mov    $0x1,%edi
mov    $0x30,%esi
call   1040 <calloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     143d <getaddrinfo+0x2cd>
mov    %rax,%rbx
mov    $0x1,%edi
mov    $0x10,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     143d <getaddrinfo+0x2cd>
mov    0x2c1f(%rip),%rcx
mov    (%rcx),%rcx
mov    %rcx,0x28(%rbx)
mov    %r15d,(%rbx)
mov    0x4(%rsp),%edx
mov    %edx,0x4(%rbx)
movl   $0x10,0x8(%rbx)
mov    %rax,0x20(%rbx)
mov    %rcx,0x8(%rax)
movzwl 0xa(%rsp),%ecx
mov    %cx,(%rax)
add    $0x4,%rax
mov    0x10(%rsp),%rcx
mov    (%rcx),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    0xc(%rsp),%eax
not    %eax
mov    0x2bc1(%rip),%rcx
test   %eax,(%rcx)
jne    120a <getaddrinfo+0x9a>
mov    0x20(%rsp),%rdi
test   %rdi,%rdi
je     120a <getaddrinfo+0x9a>
call   1080 <strdup@plt>
mov    %eax,0x18(%rbx)
test   %eax,%eax
jne    120a <getaddrinfo+0x9a>
mov    (%r14),%rdi
call   1090 <freeaddrinfo@plt>
mov    0x2b6c(%rip),%rax
jmp    11f7 <getaddrinfo+0x87>
mov    %eax,%ebp
mov    (%r14),%rdi
call   1090 <freeaddrinfo@plt>
jmp    11f9 <getaddrinfo+0x89>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, %struct.addrinfo*, i32, %struct.sockaddr*, i8* }
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i16, i32, i8* }
@EAI_NONAME = global i32 0
@SOCK_STREAM = global i32 0
@SOCK_DGRAM = global i32 0
@EAI_MEMORY = global i32 0
@AF_INET = global i8* null
@AI_CANONNAME = global i32 0
define i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %2, %struct.addrinfo** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.addrinfo*
%9 = alloca %struct.addrinfo**
%10 = alloca %struct.addrinfo*
%11 = alloca %struct.addrinfo**
%12 = alloca i8**
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i16
%21 = alloca %struct.sockaddr_in*
%22 = alloca i32
%23 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store %struct.addrinfo* %2, %struct.addrinfo** %8
store %struct.addrinfo** %3, %struct.addrinfo*** %9
%24 = load i8*, i8** %6
%25 = icmp ne i8* %24, null
br i1 %25, label %29, label %26
26: ; preds = %4
%27 = load i8*, i8** %7
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %26, %4
%30 = load %struct.addrinfo**, %struct.addrinfo*** %9
%31 = icmp ne %struct.addrinfo** %30, null
br i1 %31, label %34, label %32
32: ; preds = %29, %26
%33 = load i32, i32* @EAI_NONAME
store i32 %33, i32* %5
br label %182
34: ; preds = %29
%35 = load %struct.addrinfo*, %struct.addrinfo** %8
%36 = call i32 @getaddrinfo_parse_hints(%struct.addrinfo* %35, i32* %14, i32* %23, i32* %17)
store i32 %36, i32* %18
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = load i32, i32* %18
store i32 %39, i32* %5
br label %182
40: ; preds = %34
%41 = load i8*, i8** %6
%42 = load i32, i32* %14
%43 = call i32 @getaddrinfo_resolve_hostname(i8* %41, i32 %42, i8*** %12, i8** %13)
store i32 %43, i32* %18
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %40
%46 = load i32, i32* %18
store i32 %46, i32* %5
br label %182
47: ; preds = %40
%48 = load %struct.addrinfo**, %struct.addrinfo*** %9
store %struct.addrinfo** %48, %struct.addrinfo*** %11
%49 = load %struct.addrinfo**, %struct.addrinfo*** %11
store %struct.addrinfo* null, %struct.addrinfo** %49
%50 = load i32, i32* @EAI_NONAME
store i32 %50, i32* %19
br label %51
51: ; preds = %177, %47
%52 = load i8**, i8*** %12
%53 = load i8*, i8** %52
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %180
55: ; preds = %51
store i32 0, i32* %15
br label %56
56: ; preds = %174, %55
%57 = load i32, i32* %15
%58 = icmp slt i32 %57, 2
br i1 %58, label %59, label %177
59: ; preds = %56
%60 = load i32, i32* %15
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = load i32, i32* @SOCK_STREAM
br label %66
64: ; preds = %59
%65 = load i32, i32* @SOCK_DGRAM
br label %66
66: ; preds = %64, %62
%67 = phi i32 [ %63, %62 ], [ %65, %64 ]
store i32 %67, i32* %22
%68 = load i32, i32* %23
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %75
70: ; preds = %66
%71 = load i32, i32* %23
%72 = load i32, i32* %22
%73 = icmp ne i32 %71, %72
br i1 %73, label %74, label %75
74: ; preds = %70
br label %174
75: ; preds = %70, %66
%76 = load i8*, i8** %7
%77 = load i32, i32* %14
%78 = load i32, i32* %22
%79 = call i32 @getaddrinfo_resolve_servname(i8* %76, i32 %77, i32 %78, i16* %20, i32* %16)
store i32 %79, i32* %18
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %86
81: ; preds = %75
%82 = load %struct.addrinfo**, %struct.addrinfo*** %9
%83 = load %struct.addrinfo*, %struct.addrinfo** %82
%84 = call i32 @freeaddrinfo(%struct.addrinfo* %83)
%85 = load i32, i32* %18
store i32 %85, i32* %5
br label %182
86: ; preds = %75
%87 = load i32, i32* %16
%88 = icmp ne i32 %87, 0
br i1 %88, label %91, label %89
89: ; preds = %86
%90 = load i32, i32* %17
store i32 %90, i32* %16
br label %100
91: ; preds = %86
%92 = load i32, i32* %17
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %99
94: ; preds = %91
%95 = load i32, i32* %16
%96 = load i32, i32* %17
%97 = icmp ne i32 %95, %96
br i1 %97, label %98, label %99
98: ; preds = %94
br label %174
99: ; preds = %94, %91
br label %100
100: ; preds = %99, %89
%101 = call i64 @calloc(i32 1, i32 48)
%102 = inttoptr i64 %101 to %struct.addrinfo*
store %struct.addrinfo* %102, %struct.addrinfo** %10
%103 = load %struct.addrinfo**, %struct.addrinfo*** %11
store %struct.addrinfo* %102, %struct.addrinfo** %103
%104 = load %struct.addrinfo*, %struct.addrinfo** %10
%105 = icmp ne %struct.addrinfo* %104, null
br i1 %105, label %111, label %106
106: ; preds = %100
%107 = load %struct.addrinfo**, %struct.addrinfo*** %9
%108 = load %struct.addrinfo*, %struct.addrinfo** %107
%109 = call i32 @freeaddrinfo(%struct.addrinfo* %108)
%110 = load i32, i32* @EAI_MEMORY
store i32 %110, i32* %5
br label %182
111: ; preds = %100
%112 = call i64 @calloc(i32 1, i32 16)
%113 = inttoptr i64 %112 to %struct.sockaddr_in*
store %struct.sockaddr_in* %113, %struct.sockaddr_in** %21
%114 = load %struct.sockaddr_in*, %struct.sockaddr_in** %21
%115 = icmp ne %struct.sockaddr_in* %114, null
br i1 %115, label %121, label %116
116: ; preds = %111
%117 = load %struct.addrinfo**, %struct.addrinfo*** %9
%118 = load %struct.addrinfo*, %struct.addrinfo** %117
%119 = call i32 @freeaddrinfo(%struct.addrinfo* %118)
%120 = load i32, i32* @EAI_MEMORY
store i32 %120, i32* %5
br label %182
121: ; preds = %111
%122 = load i8*, i8** @AF_INET
%123 = load %struct.addrinfo*, %struct.addrinfo** %10
%124 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %123, i32 0, i32 6
store i8* %122, i8** %124
%125 = load i32, i32* %22
%126 = load %struct.addrinfo*, %struct.addrinfo** %10
%127 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %126, i32 0, i32 0
store i32 %125, i32* %127
%128 = load i32, i32* %16
%129 = load %struct.addrinfo*, %struct.addrinfo** %10
%130 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %129, i32 0, i32 1
store i32 %128, i32* %130
%131 = load %struct.addrinfo*, %struct.addrinfo** %10
%132 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %131, i32 0, i32 2
store i32 16, i32* %132
%133 = load %struct.sockaddr_in*, %struct.sockaddr_in** %21
%134 = bitcast %struct.sockaddr_in* %133 to %struct.sockaddr*
%135 = load %struct.addrinfo*, %struct.addrinfo** %10
%136 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %135, i32 0, i32 5
store %struct.sockaddr* %134, %struct.sockaddr** %136
%137 = load i8*, i8** @AF_INET
%138 = load %struct.sockaddr_in*, %struct.sockaddr_in** %21
%139 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %138, i32 0, i32 2
store i8* %137, i8** %139
%140 = load i16, i16* %20
%141 = load %struct.sockaddr_in*, %struct.sockaddr_in** %21
%142 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %141, i32 0, i32 0
store i16 %140, i16* %142
%143 = load %struct.sockaddr_in*, %struct.sockaddr_in** %21
%144 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %143, i32 0, i32 1
%145 = load i8**, i8*** %12
%146 = load i8*, i8** %145
%147 = call i32 @memcpy(i32* %144, i8* %146, i32 4)
%148 = load i32, i32* %14
%149 = load i32, i32* @AI_CANONNAME
%150 = and i32 %148, %149
%151 = load i32, i32* @AI_CANONNAME
%152 = icmp eq i32 %150, %151
br i1 %152, label %153, label %171
153: ; preds = %121
%154 = load i8*, i8** %13
%155 = icmp ne i8* %154, null
br i1 %155, label %156, label %171
156: ; preds = %153
%157 = load i8*, i8** %13
%158 = call i32 @strdup(i8* %157)
%159 = load %struct.addrinfo*, %struct.addrinfo** %10
%160 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %159, i32 0, i32 4
store i32 %158, i32* %160
%161 = load %struct.addrinfo*, %struct.addrinfo** %10
%162 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %161, i32 0, i32 4
%163 = load i32, i32* %162
%164 = icmp ne i32 %163, 0
br i1 %164, label %170, label %165
165: ; preds = %156
%166 = load %struct.addrinfo**, %struct.addrinfo*** %9
%167 = load %struct.addrinfo*, %struct.addrinfo** %166
%168 = call i32 @freeaddrinfo(%struct.addrinfo* %167)
%169 = load i32, i32* @EAI_MEMORY
store i32 %169, i32* %5
br label %182
170: ; preds = %156
br label %171
171: ; preds = %170, %153, %121
store i32 0, i32* %19
%172 = load %struct.addrinfo*, %struct.addrinfo** %10
%173 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %172, i32 0, i32 3
store %struct.addrinfo** %173, %struct.addrinfo*** %11
br label %174
174: ; preds = %171, %98, %74
%175 = load i32, i32* %15
%176 = add nsw i32 %175, 1
store i32 %176, i32* %15
br label %56
177: ; preds = %56
%178 = load i8**, i8*** %12
%179 = getelementptr inbounds i8*, i8** %178, i32 1
store i8** %179, i8*** %12
br label %51
180: ; preds = %51
%181 = load i32, i32* %19
store i32 %181, i32* %5
br label %182
182: ; preds = %180, %165, %116, %106, %81, %45, %38, %32
%183 = load i32, i32* %5
ret i32 %183
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, %struct.addrinfo*, i32, %struct.sockaddr*, i8* }
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i16, i32, i8* }
@EAI_NONAME = global i32 0
@SOCK_STREAM = global i32 0
@SOCK_DGRAM = global i32 0
@EAI_MEMORY = global i32 0
@AF_INET = global i8* null
@AI_CANONNAME = global i32 0
define i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %2, %struct.addrinfo** %3) {
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i16
%11 = alloca i32
%12 = bitcast i8*** %5 to i8*
%13 = bitcast i8** %6 to i8*
%14 = bitcast i32* %7 to i8*
%15 = bitcast i32* %8 to i8*
%16 = bitcast i32* %9 to i8*
%17 = bitcast i16* %10 to i8*
%18 = bitcast i32* %11 to i8*
%19 = icmp ne i8* %0, null
%20 = icmp ne i8* %1, null
%21 = or i1 %19, %20
%22 = icmp ne %struct.addrinfo** %3, null
%23 = and i1 %21, %22
br i1 %23, label %26, label %24
24: ; preds = %4
%25 = load i32, i32* @EAI_NONAME
br label %177
26: ; preds = %4
%27 = call i32 @getaddrinfo_parse_hints(%struct.addrinfo* %2, i32* %7, i32* %11, i32* %9)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %177
29: ; preds = %26
%30 = load i32, i32* %7
%31 = call i32 @getaddrinfo_resolve_hostname(i8* %0, i32 %30, i8*** %5, i8** %6)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %177
33: ; preds = %29
store %struct.addrinfo* null, %struct.addrinfo** %3
%34 = load i32, i32* @EAI_NONAME
%35 = load i8**, i8*** %5
%36 = load i8*, i8** %35
%37 = icmp eq i8* %36, null
br i1 %37, label %177, label %38
38: ; preds = %33, %170
%39 = phi %struct.addrinfo** [ %172, %170 ], [ %3, %33 ]
%40 = phi i32 [ %171, %170 ], [ %34, %33 ]
%41 = load i32, i32* @SOCK_STREAM
%42 = load i32, i32* %11
%43 = icmp eq i32 %42, 0
%44 = icmp eq i32 %42, %41
%45 = select i1 %43, i1 true, i1 %44
br i1 %45, label %46, label %112
46: ; preds = %38
%47 = load i32, i32* %7
%48 = call i32 @getaddrinfo_resolve_servname(i8* %1, i32 %47, i32 %41, i16* %10, i32* %8)
%49 = icmp eq i32 %48, 0
br i1 %49, label %54, label %50
50: ; preds = %120, %46
%51 = phi i32 [ %48, %46 ], [ %122, %120 ]
%52 = load %struct.addrinfo*, %struct.addrinfo** %3
%53 = call i32 @freeaddrinfo(%struct.addrinfo* %52)
br label %177
54: ; preds = %46
%55 = load i32, i32* %8
%56 = icmp eq i32 %55, 0
%57 = load i32, i32* %9
br i1 %56, label %58, label %59
58: ; preds = %54
store i32 %57, i32* %8
br label %63
59: ; preds = %54
%60 = icmp eq i32 %57, 0
%61 = icmp eq i32 %55, %57
%62 = select i1 %60, i1 true, i1 %61
br i1 %62, label %63, label %112
63: ; preds = %59, %58
%64 = call i64 @calloc(i32 1, i32 48)
%65 = inttoptr i64 %64 to %struct.addrinfo*
store %struct.addrinfo* %65, %struct.addrinfo** %39
%66 = icmp eq i64 %64, 0
br i1 %66, label %67, label %71
67: ; preds = %133, %63
%68 = load %struct.addrinfo*, %struct.addrinfo** %3
%69 = call i32 @freeaddrinfo(%struct.addrinfo* %68)
%70 = load i32, i32* @EAI_MEMORY
br label %177
71: ; preds = %63
%72 = call i64 @calloc(i32 1, i32 16)
%73 = inttoptr i64 %72 to %struct.sockaddr_in*
%74 = icmp eq i64 %72, 0
br i1 %74, label %75, label %79
75: ; preds = %137, %71
%76 = load %struct.addrinfo*, %struct.addrinfo** %3
%77 = call i32 @freeaddrinfo(%struct.addrinfo* %76)
%78 = load i32, i32* @EAI_MEMORY
br label %177
79: ; preds = %71
%80 = load i8*, i8** @AF_INET
%81 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i64 0, i32 6
store i8* %80, i8** %81
%82 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i64 0, i32 0
store i32 %41, i32* %82
%83 = load i32, i32* %8
%84 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i64 0, i32 1
store i32 %83, i32* %84
%85 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i64 0, i32 2
store i32 16, i32* %85
%86 = inttoptr i64 %72 to %struct.sockaddr*
%87 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i64 0, i32 5
store %struct.sockaddr* %86, %struct.sockaddr** %87
%88 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %73, i64 0, i32 2
store i8* %80, i8** %88
%89 = load i16, i16* %10
%90 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %73, i64 0, i32 0
store i16 %89, i16* %90
%91 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %73, i64 0, i32 1
%92 = load i8**, i8*** %5
%93 = load i8*, i8** %92
%94 = call i32 @memcpy(i32* %91, i8* %93, i32 4)
%95 = load i32, i32* %7
%96 = load i32, i32* @AI_CANONNAME
%97 = and i32 %96, %95
%98 = icmp eq i32 %97, %96
%99 = load i8*, i8** %6
%100 = icmp ne i8* %99, null
%101 = select i1 %98, i1 %100, i1 false
br i1 %101, label %102, label %110
102: ; preds = %79
%103 = call i32 @strdup(i8* %99)
%104 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i64 0, i32 4
store i32 %103, i32* %104
%105 = icmp eq i32 %103, 0
br i1 %105, label %106, label %110
106: ; preds = %164, %102
%107 = load %struct.addrinfo*, %struct.addrinfo** %3
%108 = call i32 @freeaddrinfo(%struct.addrinfo* %107)
%109 = load i32, i32* @EAI_MEMORY
br label %177
110: ; preds = %102, %79
%111 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i64 0, i32 3
br label %112
112: ; preds = %59, %38, %110
%113 = phi i32 [ 0, %110 ], [ %40, %38 ], [ %40, %59 ]
%114 = phi %struct.addrinfo** [ %111, %110 ], [ %39, %38 ], [ %39, %59 ]
%115 = load i32, i32* @SOCK_DGRAM
%116 = load i32, i32* %11
%117 = icmp eq i32 %116, 0
%118 = icmp eq i32 %116, %115
%119 = select i1 %117, i1 true, i1 %118
br i1 %119, label %120, label %170
120: ; preds = %112
%121 = load i32, i32* %7
%122 = call i32 @getaddrinfo_resolve_servname(i8* %1, i32 %121, i32 %115, i16* %10, i32* %8)
%123 = icmp eq i32 %122, 0
br i1 %123, label %124, label %50
124: ; preds = %120
%125 = load i32, i32* %8
%126 = icmp eq i32 %125, 0
%127 = load i32, i32* %9
br i1 %126, label %132, label %128
128: ; preds = %124
%129 = icmp eq i32 %127, 0
%130 = icmp eq i32 %125, %127
%131 = select i1 %129, i1 true, i1 %130
br i1 %131, label %133, label %170
132: ; preds = %124
store i32 %127, i32* %8
br label %133
133: ; preds = %132, %128
%134 = call i64 @calloc(i32 1, i32 48)
%135 = inttoptr i64 %134 to %struct.addrinfo*
store %struct.addrinfo* %135, %struct.addrinfo** %114
%136 = icmp eq i64 %134, 0
br i1 %136, label %67, label %137
137: ; preds = %133
%138 = call i64 @calloc(i32 1, i32 16)
%139 = inttoptr i64 %138 to %struct.sockaddr_in*
%140 = icmp eq i64 %138, 0
br i1 %140, label %75, label %141
141: ; preds = %137
%142 = load i8*, i8** @AF_INET
%143 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %135, i64 0, i32 6
store i8* %142, i8** %143
%144 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %135, i64 0, i32 0
store i32 %115, i32* %144
%145 = load i32, i32* %8
%146 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %135, i64 0, i32 1
store i32 %145, i32* %146
%147 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %135, i64 0, i32 2
store i32 16, i32* %147
%148 = inttoptr i64 %138 to %struct.sockaddr*
%149 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %135, i64 0, i32 5
store %struct.sockaddr* %148, %struct.sockaddr** %149
%150 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %139, i64 0, i32 2
store i8* %142, i8** %150
%151 = load i16, i16* %10
%152 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %139, i64 0, i32 0
store i16 %151, i16* %152
%153 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %139, i64 0, i32 1
%154 = load i8**, i8*** %5
%155 = load i8*, i8** %154
%156 = call i32 @memcpy(i32* %153, i8* %155, i32 4)
%157 = load i32, i32* %7
%158 = load i32, i32* @AI_CANONNAME
%159 = and i32 %158, %157
%160 = icmp eq i32 %159, %158
%161 = load i8*, i8** %6
%162 = icmp ne i8* %161, null
%163 = select i1 %160, i1 %162, i1 false
br i1 %163, label %164, label %168
164: ; preds = %141
%165 = call i32 @strdup(i8* %161)
%166 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %135, i64 0, i32 4
store i32 %165, i32* %166
%167 = icmp eq i32 %165, 0
br i1 %167, label %106, label %168
168: ; preds = %164, %141
%169 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %135, i64 0, i32 3
br label %170
170: ; preds = %168, %128, %112
%171 = phi i32 [ 0, %168 ], [ %113, %112 ], [ %113, %128 ]
%172 = phi %struct.addrinfo** [ %169, %168 ], [ %114, %112 ], [ %114, %128 ]
%173 = load i8**, i8*** %5
%174 = getelementptr inbounds i8*, i8** %173, i64 1
store i8** %174, i8*** %5
%175 = load i8*, i8** %174
%176 = icmp eq i8* %175, null
br i1 %176, label %177, label %38
177: ; preds = %170, %33, %29, %26, %106, %75, %67, %50, %24
%178 = phi i32 [ %51, %50 ], [ %109, %106 ], [ %78, %75 ], [ %70, %67 ], [ %25, %24 ], [ %27, %26 ], [ %31, %29 ], [ %34, %33 ], [ %171, %170 ]
ret i32 %178
}