#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 in_addr {
  int /*<<< orphan*/ s_addr;
};
struct hostent {
  scalar_t__ *h_name;
  scalar_t__ *h_addr_list;
};
struct addrinfo {
  int ai_socktype;
  int ai_flags;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_canonname;
};

/* Variables and functions */
int SOCK_STREAM;
scalar_t__ atoi(char const *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
struct hostent *gethostbyname(char const *);
int /*<<< orphan*/ htonl(int);
int htons(short);
scalar_t__ inet_aton(char const *, struct in_addr *);
struct addrinfo *malloc_ai(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ strdup(scalar_t__ *);
int getaddrinfo(const char *hostname, const char *servname,
                const struct addrinfo *hints, struct addrinfo **res) {
  struct addrinfo *cur, *prev = NULL;
  struct hostent *hp;
  struct in_addr in;
  int i, port, type;
  if (servname)
    port = htons((short)atoi(servname));
  else
    port = 0;
  if (hints && hints->ai_socktype)
    type = hints->ai_socktype;
  else
    type = SOCK_STREAM;
  if (hints && hints->ai_flags & 1) {
    if (NULL != (*res = malloc_ai(port, type, htonl(0x00000000))))
      return 0;
    else
      return 2;
  }
  if (!hostname) {
    if (NULL != (*res = malloc_ai(port, type, htonl(0x7f000001))))
      return 0;
    else
      return 2;
  }
  if (inet_aton(hostname, &in)) {
    if (NULL != (*res = malloc_ai(port, type, in.s_addr)))
      return 0;
    else
      return 2;
  }
  hp = gethostbyname(hostname);
  if (hp && hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) {
    for (i = 0; hp->h_addr_list[i]; i++) {
      cur =
          malloc_ai(port, type, ((struct in_addr *)hp->h_addr_list[i])->s_addr);
      if (cur == NULL) {
        if (*res)
          freeaddrinfo(*res);
        return 2;
      }
      if (hints && hints->ai_flags & 2)
        cur->ai_canonname = strdup(hp->h_name);
      if (prev)
        prev->ai_next = cur;
      else
        *res = cur;
      prev = cur;
    }
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<getaddrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c4 <getaddrinfo+0x44>
mov    -0x18(%rbp),%rdi
call   1070 <atoi@plt>
movswl %ax,%edi
call   1030 <htons@plt>
mov    %eax,-0x50(%rbp)
jmp    11cb <getaddrinfo+0x4b>
movl   $0x0,-0x50(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f1 <getaddrinfo+0x71>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
je     11f1 <getaddrinfo+0x71>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
jmp    11fd <getaddrinfo+0x7d>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1268 <getaddrinfo+0xe8>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1268 <getaddrinfo+0xe8>
mov    -0x50(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x58(%rbp)
xor    %edi,%edi
call   1040 <htonl@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%esi
mov    %eax,%edx
call   1090 <malloc_ai@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
cmp    %rcx,%rax
je     125c <getaddrinfo+0xdc>
movl   $0x0,-0x4(%rbp)
jmp    1451 <getaddrinfo+0x2d1>
movl   $0x2,-0x4(%rbp)
jmp    1451 <getaddrinfo+0x2d1>
cmpq   $0x0,-0x10(%rbp)
jne    12c3 <getaddrinfo+0x143>
mov    -0x50(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    $0x7f000001,%edi
call   1040 <htonl@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%esi
mov    %eax,%edx
call   1090 <malloc_ai@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
cmp    %rcx,%rax
je     12b7 <getaddrinfo+0x137>
movl   $0x0,-0x4(%rbp)
jmp    1451 <getaddrinfo+0x2d1>
movl   $0x2,-0x4(%rbp)
jmp    1451 <getaddrinfo+0x2d1>
mov    -0x10(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1060 <inet_aton@plt>
cmp    $0x0,%rax
je     1315 <getaddrinfo+0x195>
mov    -0x50(%rbp),%edi
mov    -0x54(%rbp),%esi
mov    -0x48(%rbp),%edx
call   1090 <malloc_ai@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
cmp    %rcx,%rax
je     1309 <getaddrinfo+0x189>
movl   $0x0,-0x4(%rbp)
jmp    1451 <getaddrinfo+0x2d1>
movl   $0x2,-0x4(%rbp)
jmp    1451 <getaddrinfo+0x2d1>
mov    -0x10(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     144a <getaddrinfo+0x2ca>
mov    -0x40(%rbp),%rax
cmpq   $0x0,(%rax)
je     144a <getaddrinfo+0x2ca>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
cmpq   $0x0,(%rax)
je     144a <getaddrinfo+0x2ca>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rax
cmpq   $0x0,(%rax)
je     144a <getaddrinfo+0x2ca>
movl   $0x0,-0x4c(%rbp)
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x4c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     143e <getaddrinfo+0x2be>
mov    -0x50(%rbp),%edi
mov    -0x54(%rbp),%esi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edx
call   1090 <malloc_ai@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    13ce <getaddrinfo+0x24e>
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
je     13c2 <getaddrinfo+0x242>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <freeaddrinfo@plt>
movl   $0x2,-0x4(%rbp)
jmp    1451 <getaddrinfo+0x2d1>
cmpq   $0x0,-0x20(%rbp)
je     1401 <getaddrinfo+0x281>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1401 <getaddrinfo+0x281>
mov    -0x40(%rbp),%rax
mov    (%rax),%rdi
call   1080 <strdup@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x10(%rax)
cmpq   $0x0,-0x38(%rbp)
je     141d <getaddrinfo+0x29d>
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x8(%rax)
jmp    1428 <getaddrinfo+0x2a8>
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1365 <getaddrinfo+0x1e5>
movl   $0x0,-0x4(%rbp)
jmp    1451 <getaddrinfo+0x2d1>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getaddrinfo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rdi,%rbp
test   %rsi,%rsi
je     11d0 <getaddrinfo+0x50>
mov    %rsi,%rdi
call   1070 <atoi@plt>
movswl %ax,%edi
call   1030 <htons@plt>
mov    %eax,%r15d
test   %rbx,%rbx
je     11d8 <getaddrinfo+0x58>
mov    (%rbx),%r12d
test   %r12d,%r12d
jne    11c6 <getaddrinfo+0x46>
mov    0x2e1d(%rip),%rax
mov    (%rax),%r12d
testb  $0x1,0x4(%rbx)
je     11e2 <getaddrinfo+0x62>
xor    %edi,%edi
jmp    120a <getaddrinfo+0x8a>
xor    %r15d,%r15d
test   %rbx,%rbx
jne    11b4 <getaddrinfo+0x34>
mov    0x2e01(%rip),%rax
mov    (%rax),%r12d
test   %rbp,%rbp
je     1205 <getaddrinfo+0x85>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   1060 <inet_aton@plt>
test   %rax,%rax
je     123b <getaddrinfo+0xbb>
mov    0x8(%rsp),%edx
mov    %r15d,%edi
mov    %r12d,%esi
jmp    1217 <getaddrinfo+0x97>
mov    $0x7f000001,%edi
call   1040 <htonl@plt>
mov    %r15d,%edi
mov    %r12d,%esi
mov    %eax,%edx
call   1090 <malloc_ai@plt>
mov    %rax,(%r14)
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
add    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
call   1050 <gethostbyname@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     122a <getaddrinfo+0xaa>
mov    (%rax),%rcx
test   %rcx,%rcx
je     122a <getaddrinfo+0xaa>
cmpq   $0x0,(%rcx)
je     122a <getaddrinfo+0xaa>
mov    %r15d,0xc(%rsp)
mov    %r14,0x10(%rsp)
mov    0x8(%rax),%rcx
mov    (%rcx),%rcx
test   %rcx,%rcx
je     122a <getaddrinfo+0xaa>
mov    $0x8,%r14d
xor    %r13d,%r13d
jmp    12a6 <getaddrinfo+0x126>
nopl   0x0(%rax)
lea    0x8(%rbp),%rax
test   %rbp,%rbp
cmove  0x10(%rsp),%rax
mov    %r13,(%rax)
mov    %r15,%rax
mov    0x8(%r15),%rcx
mov    (%rcx,%r14,1),%rcx
add    $0x8,%r14
xor    %ebp,%ebp
test   %rcx,%rcx
je     122a <getaddrinfo+0xaa>
mov    %rax,%r15
mov    %r13,%rbp
mov    (%rcx),%edx
mov    0xc(%rsp),%edi
mov    %r12d,%esi
call   1090 <malloc_ai@plt>
test   %rax,%rax
je     12db <getaddrinfo+0x15b>
mov    %rax,%r13
test   %rbx,%rbx
je     1280 <getaddrinfo+0x100>
testb  $0x2,0x4(%rbx)
je     1280 <getaddrinfo+0x100>
mov    (%r15),%rdi
call   1080 <strdup@plt>
mov    %eax,0x10(%r13)
jmp    1280 <getaddrinfo+0x100>
mov    0x10(%rsp),%rax
mov    (%rax),%rdi
mov    $0x2,%ebp
test   %rdi,%rdi
je     122a <getaddrinfo+0xaa>
call   10a0 <freeaddrinfo@plt>
jmp    122a <getaddrinfo+0xaa>

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

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, %struct.addrinfo*, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64*, i64* }
@SOCK_STREAM = global i32 0
define i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %2, %struct.addrinfo** nocapture %3) {
%5 = alloca %struct.in_addr
%6 = bitcast %struct.in_addr* %5 to i8*
%7 = icmp eq i8* %1, null
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = tail call i64 @atoi(i8* %1)
%10 = trunc i64 %9 to i16
%11 = tail call i32 @htons(i16 signext %10)
br label %12
12: ; preds = %4, %8
%13 = phi i32 [ %11, %8 ], [ 0, %4 ]
%14 = icmp eq %struct.addrinfo* %2, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = load i32, i32* @SOCK_STREAM
br label %32
17: ; preds = %12
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 0
%19 = load i32, i32* %18
%20 = icmp eq i32 %19, 0
%21 = load i32, i32* @SOCK_STREAM
%22 = select i1 %20, i32 %21, i32 %19
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 1
%24 = load i32, i32* %23
%25 = and i32 %24, 1
%26 = icmp eq i32 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %17
%28 = tail call i32 @htonl(i32 0)
%29 = tail call %struct.addrinfo* @malloc_ai(i32 %13, i32 %22, i32 %28)
store %struct.addrinfo* %29, %struct.addrinfo** %3
%30 = icmp eq %struct.addrinfo* %29, null
%31 = select i1 %30, i32 2, i32 0
br label %98
32: ; preds = %15, %17
%33 = phi i32 [ %22, %17 ], [ %16, %15 ]
%34 = icmp eq i8* %0, null
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = tail call i32 @htonl(i32 2130706433)
%37 = tail call %struct.addrinfo* @malloc_ai(i32 %13, i32 %33, i32 %36)
store %struct.addrinfo* %37, %struct.addrinfo** %3
%38 = icmp eq %struct.addrinfo* %37, null
%39 = select i1 %38, i32 2, i32 0
br label %98
40: ; preds = %32
%41 = call i64 @inet_aton(i8* %0, %struct.in_addr* %5)
%42 = icmp eq i64 %41, 0
br i1 %42, label %49, label %43
43: ; preds = %40
%44 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i64 0, i32 0
%45 = load i32, i32* %44
%46 = call %struct.addrinfo* @malloc_ai(i32 %13, i32 %33, i32 %45)
store %struct.addrinfo* %46, %struct.addrinfo** %3
%47 = icmp eq %struct.addrinfo* %46, null
%48 = select i1 %47, i32 2, i32 0
br label %98
49: ; preds = %40
%50 = call %struct.hostent* @gethostbyname(i8* %0)
%51 = icmp eq %struct.hostent* %50, null
br i1 %51, label %98, label %52
52: ; preds = %49
%53 = getelementptr inbounds %struct.hostent, %struct.hostent* %50, i64 0, i32 0
%54 = load i64*, i64** %53
%55 = icmp eq i64* %54, null
br i1 %55, label %98, label %56
56: ; preds = %52
%57 = load i64, i64* %54
%58 = icmp eq i64 %57, 0
br i1 %58, label %98, label %59
59: ; preds = %56
%60 = getelementptr inbounds %struct.hostent, %struct.hostent* %50, i64 0, i32 1
%61 = load i64*, i64** %60
%62 = load i64, i64* %61
%63 = icmp eq i64 %62, 0
br i1 %63, label %98, label %64
64: ; preds = %59
%65 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 1
br label %66
66: ; preds = %64, %89
%67 = phi i64 [ 0, %64 ], [ %93, %89 ]
%68 = phi i64 [ %62, %64 ], [ %96, %89 ]
%69 = phi %struct.addrinfo* [ null, %64 ], [ %73, %89 ]
%70 = inttoptr i64 %68 to %struct.in_addr*
%71 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %70, i64 0, i32 0
%72 = load i32, i32* %71
%73 = call %struct.addrinfo* @malloc_ai(i32 %13, i32 %33, i32 %72)
%74 = icmp eq %struct.addrinfo* %73, null
br i1 %74, label %75, label %80
75: ; preds = %66
%76 = load %struct.addrinfo*, %struct.addrinfo** %3
%77 = icmp eq %struct.addrinfo* %76, null
br i1 %77, label %98, label %78
78: ; preds = %75
%79 = call i32 @freeaddrinfo(%struct.addrinfo* %76)
br label %98
80: ; preds = %66
br i1 %14, label %89, label %81
81: ; preds = %80
%82 = load i32, i32* %65
%83 = and i32 %82, 2
%84 = icmp eq i32 %83, 0
br i1 %84, label %89, label %85
85: ; preds = %81
%86 = load i64*, i64** %53
%87 = call i32 @strdup(i64* %86)
%88 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %73, i64 0, i32 3
store i32 %87, i32* %88
br label %89
89: ; preds = %85, %81, %80
%90 = icmp eq %struct.addrinfo* %69, null
%91 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i64 0, i32 2
%92 = select i1 %90, %struct.addrinfo** %3, %struct.addrinfo** %91
store %struct.addrinfo* %73, %struct.addrinfo** %92
%93 = add nuw i64 %67, 1
%94 = load i64*, i64** %60
%95 = getelementptr inbounds i64, i64* %94, i64 %93
%96 = load i64, i64* %95
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %66
98: ; preds = %89, %49, %52, %56, %59, %75, %78, %43, %35, %27
%99 = phi i32 [ %31, %27 ], [ %39, %35 ], [ %48, %43 ], [ 2, %78 ], [ 2, %75 ], [ 1, %59 ], [ 1, %56 ], [ 1, %52 ], [ 1, %49 ], [ 0, %89 ]
ret i32 %99
}