#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct in6_addr {
  int /*<<< orphan*/ *s6_addr16;
};
struct TYPE_2__ {
  int retry;
};

/* Variables and functions */
int AF_INET;
int AF_INET6;
int /*<<< orphan*/ T_PTR;
TYPE_1__ _res;
int asprintf(char **, char *, char *, char *, char *, char *, ...);
int doQuery(char *, int /*<<< orphan*/, char **, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ inet_pton(int, char *, struct in6_addr *);
char *malloc(int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *strdup(char *);
char *strtok(char *, char *);
char *mygethostbyaddr(char *ipnum, int family) {
  int i, j, ret;
  char *buf = NULL;
  char sbuf[5];
  char *result = NULL;
  char *octets[4];
  char *octet = NULL;
  char *parts[8];
  char *partptr = NULL;
  struct in6_addr addr6;
  _res.retry = 1;
  if (ipnum == NULL || (family != AF_INET && family != AF_INET6))
    return NULL;
  if (family == AF_INET) {
    buf = strdup(ipnum);
    octet = strtok(buf, ".");
    i = 0;
    while (octet != NULL) {
      octets[i] = octet;
      i++;
      octet = strtok(NULL, ".");
    }
    if (i == 4) {
      if (asprintf(&ipnum, "%s.%s.%s.%s.in-addr.arpa", octets[3], octets[2],
                   octets[1], octets[0]) == -1)
        return NULL;
    } else {
      return NULL;
    }
    free(buf);
    buf = NULL;
  } else if (family == AF_INET6) {
    if (!inet_pton(AF_INET6, ipnum, &addr6))
      return NULL;
    i = 7;
    while (i >= 0) {
      sprintf(sbuf, "%4x", ntohs(addr6.s6_addr16[i]));
      sbuf[4] = '\0';
      if ((parts[i] = malloc(8)) == NULL)
        return NULL;
      partptr = parts[i];
      for (j = 3; j >= 0; j--) {
        if (sbuf[j] == ' ')
          *partptr = '0';
        else
          *partptr = sbuf[j];
        partptr++;
        if (j != 0) {
          *partptr = '.';
          partptr++;
        }
      }
      i--;
    }
    if (asprintf(&ipnum, "%s.%s.%s.%s.%s.%s.%s.%s.ip6.arpa", parts[7], parts[6],
                 parts[5], parts[4], parts[3], parts[2], parts[1],
                 parts[0]) == -1)
      return NULL;
    for (j = 0; j < 8; j++) {
      free(parts[j]);
      parts[j] = NULL;
    }
  }
  ret = doQuery(ipnum, T_PTR, &result, NULL, family);
  if (ret)
    ret = doQuery(ipnum, T_PTR, &result, NULL, family);
  if (ret)
    return NULL;
  else
    return result;
}


x86 assembly (clang, -O0):
<mygethostbyaddr>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0xe8,%rsp
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0xb8(%rbp)
mov    0x2e1b(%rip),%rax
movl   $0x1,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     1202 <mygethostbyaddr+0x72>
mov    -0x1c(%rbp),%eax
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%eax
je     120f <mygethostbyaddr+0x7f>
mov    -0x1c(%rbp),%eax
mov    0x2dd6(%rip),%rcx
cmp    (%rcx),%eax
je     120f <mygethostbyaddr+0x7f>
movq   $0x0,-0x10(%rbp)
jmp    1574 <mygethostbyaddr+0x3e4>
mov    -0x1c(%rbp),%eax
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%eax
jne    12ed <mygethostbyaddr+0x15d>
mov    -0x18(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xdc7(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x68(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     1283 <mygethostbyaddr+0xf3>
mov    -0x68(%rbp),%rcx
movslq -0x20(%rbp),%rax
mov    %rcx,-0x60(%rbp,%rax,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd8b(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x68(%rbp)
jmp    1249 <mygethostbyaddr+0xb9>
cmpl   $0x4,-0x20(%rbp)
jne    12ca <mygethostbyaddr+0x13a>
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    -0x58(%rbp),%r8
mov    -0x60(%rbp),%r9
lea    -0x18(%rbp),%rdi
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   1070 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    12c5 <mygethostbyaddr+0x135>
movq   $0x0,-0x10(%rbp)
jmp    1574 <mygethostbyaddr+0x3e4>
jmp    12d7 <mygethostbyaddr+0x147>
movq   $0x0,-0x10(%rbp)
jmp    1574 <mygethostbyaddr+0x3e4>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
jmp    1509 <mygethostbyaddr+0x379>
mov    -0x1c(%rbp),%eax
mov    0x2cd9(%rip),%rcx
cmp    (%rcx),%eax
jne    1504 <mygethostbyaddr+0x374>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0xc0(%rbp),%rdx
call   1050 <inet_pton@plt>
cmp    $0x0,%eax
jne    132e <mygethostbyaddr+0x19e>
movq   $0x0,-0x10(%rbp)
jmp    1574 <mygethostbyaddr+0x3e4>
movl   $0x7,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     1452 <mygethostbyaddr+0x2c2>
lea    -0x35(%rbp),%rax
mov    %rax,-0xc8(%rbp)
mov    -0xc0(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1080 <ntohs@plt>
mov    -0xc8(%rbp),%rdi
mov    %eax,%edx
lea    0xcae(%rip),%rsi
call   10a0 <sprintf@plt>
movb   $0x0,-0x31(%rbp)
mov    $0x8,%edi
call   1060 <malloc@plt>
movslq -0x20(%rbp),%rcx
mov    %rax,-0xb0(%rbp,%rcx,8)
ff
cmp    $0x0,%rax
jne    13a3 <mygethostbyaddr+0x213>
movq   $0x0,-0x10(%rbp)
jmp    1574 <mygethostbyaddr+0x3e4>
movslq -0x20(%rbp),%rax
mov    -0xb0(%rbp,%rax,8),%rax
ff
mov    %rax,-0xb8(%rbp)
movl   $0x3,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1444 <mygethostbyaddr+0x2b4>
movslq -0x24(%rbp),%rax
movsbl -0x35(%rbp,%rax,1),%eax
cmp    $0x20,%eax
jne    13e8 <mygethostbyaddr+0x258>
mov    -0xb8(%rbp),%rax
movb   $0x30,(%rax)
jmp    13f9 <mygethostbyaddr+0x269>
movslq -0x24(%rbp),%rax
mov    -0x35(%rbp,%rax,1),%cl
mov    -0xb8(%rbp),%rax
mov    %cl,(%rax)
mov    -0xb8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xb8(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1431 <mygethostbyaddr+0x2a1>
mov    -0xb8(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0xb8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xb8(%rbp)
jmp    1436 <mygethostbyaddr+0x2a6>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    13bd <mygethostbyaddr+0x22d>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1335 <mygethostbyaddr+0x1a5>
mov    -0x78(%rbp),%rdx
mov    -0x80(%rbp),%rcx
mov    -0x88(%rbp),%r8
mov    -0x90(%rbp),%r9
mov    -0x98(%rbp),%rbx
mov    -0xa0(%rbp),%r11
mov    -0xa8(%rbp),%r10
mov    -0xb0(%rbp),%rax
lea    -0x18(%rbp),%rdi
lea    0xb90(%rip),%rsi
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
mov    $0x0,%al
call   1070 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    14bf <mygethostbyaddr+0x32f>
movq   $0x0,-0x10(%rbp)
jmp    1574 <mygethostbyaddr+0x3e4>
movl   $0x0,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jge    14ff <mygethostbyaddr+0x36f>
movslq -0x24(%rbp),%rax
mov    -0xb0(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
movslq -0x24(%rbp),%rax
movq   $0x0,-0xb0(%rbp,%rax,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    14c6 <mygethostbyaddr+0x336>
jmp    1504 <mygethostbyaddr+0x374>
jmp    1509 <mygethostbyaddr+0x379>
mov    -0x18(%rbp),%rdi
mov    0x2ac4(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%r8d
lea    -0x40(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <doQuery@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1555 <mygethostbyaddr+0x3c5>
mov    -0x18(%rbp),%rdi
mov    0x2a99(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%r8d
lea    -0x40(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <doQuery@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     156c <mygethostbyaddr+0x3dc>
movq   $0x0,-0x10(%rbp)
jmp    1574 <mygethostbyaddr+0x3e4>
mov    -0x40(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0xe8,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<mygethostbyaddr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdi,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x2e32(%rip),%rax
movl   $0x1,(%rax)
test   %rdi,%rdi
je     11e3 <mygethostbyaddr+0x53>
mov    %esi,%r12d
mov    %rdi,%rsi
mov    0x2e12(%rip),%rax
mov    (%rax),%ecx
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
cmp    %r12d,%ecx
je     11fb <mygethostbyaddr+0x6b>
cmp    %r12d,%eax
je     11fb <mygethostbyaddr+0x6b>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    %r12d,%ecx
jne    128d <mygethostbyaddr+0xfd>
mov    %rsi,%rdi
call   10b0 <strdup@plt>
mov    %rax,%r14
lea    0xdfa(%rip),%rsi
mov    %rax,%rdi
call   1090 <strtok@plt>
test   %rax,%rax
je     11e3 <mygethostbyaddr+0x53>
xor    %ebp,%ebp
lea    0xde4(%rip),%rbx
nopl   0x0(%rax)
mov    %rax,0x20(%rsp,%rbp,8)
add    $0x1,%rbp
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
jne    1230 <mygethostbyaddr+0xa0>
cmp    $0x4,%ebp
jne    11e3 <mygethostbyaddr+0x53>
mov    0x38(%rsp),%rdx
mov    0x30(%rsp),%rcx
mov    0x20(%rsp),%r9
mov    0x28(%rsp),%r8
lea    0xdaa(%rip),%rsi
xor    %r13d,%r13d
lea    0x10(%rsp),%rdi
xor    %eax,%eax
call   1070 <asprintf@plt>
cmp    $0xffffffff,%eax
je     11e6 <mygethostbyaddr+0x56>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1424 <mygethostbyaddr+0x294>
cmp    %r12d,%eax
jne    1424 <mygethostbyaddr+0x294>
lea    0x80(%rsp),%rdx
mov    %r12d,%edi
call   1050 <inet_pton@plt>
test   %eax,%eax
je     11e3 <mygethostbyaddr+0x53>
mov    $0x7,%ebp
lea    0xd71(%rip),%r14
lea    0xb(%rsp),%r15
xor    %r13d,%r13d
mov    $0x30,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x80(%rsp),%rax
mov    (%rax,%rbp,4),%edi
call   1080 <ntohs@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   10a0 <sprintf@plt>
movb   $0x0,0xf(%rsp)
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,0x20(%rsp,%rbp,8)
test   %rax,%rax
je     11e6 <mygethostbyaddr+0x56>
movzbl 0xe(%rsp),%ecx
cmp    $0x20,%cl
cmove  %ebx,%ecx
mov    %cl,(%rax)
movb   $0x2e,0x1(%rax)
movzbl 0xd(%rsp),%ecx
cmp    $0x20,%cl
cmove  %ebx,%ecx
mov    %cl,0x2(%rax)
movb   $0x2e,0x3(%rax)
movzbl 0xc(%rsp),%ecx
cmp    $0x20,%cl
cmove  %ebx,%ecx
mov    %cl,0x4(%rax)
movb   $0x2e,0x5(%rax)
movzbl 0xb(%rsp),%ecx
cmp    $0x20,%cl
cmove  %ebx,%ecx
mov    %cl,0x6(%rax)
add    $0xffffffffffffffff,%rbp
jb     12d0 <mygethostbyaddr+0x140>
mov    0x58(%rsp),%rdx
mov    0x50(%rsp),%rcx
mov    0x48(%rsp),%r8
mov    0x40(%rsp),%r9
mov    0x38(%rsp),%r14
mov    0x30(%rsp),%r15
mov    0x20(%rsp),%rbx
mov    0x28(%rsp),%rbp
lea    0xca9(%rip),%rsi
xor    %r13d,%r13d
lea    0x10(%rsp),%rdi
mov    %rdx,0x78(%rsp)
mov    %rcx,0x70(%rsp)
mov    %r8,0x68(%rsp)
mov    %r9,0x60(%rsp)
xor    %eax,%eax
push   %rbx
push   %rbp
push   %r15
push   %r14
call   1070 <asprintf@plt>
add    $0x20,%rsp
cmp    $0xffffffff,%eax
je     11e6 <mygethostbyaddr+0x56>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
mov    0x60(%rsp),%rdi
call   1030 <free@plt>
mov    0x68(%rsp),%rdi
call   1030 <free@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
mov    0x70(%rsp),%rdi
call   1030 <free@plt>
mov    0x78(%rsp),%rdi
call   1030 <free@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
mov    0x10(%rsp),%rdi
mov    0x2ba8(%rip),%rbx
mov    (%rbx),%esi
lea    0x18(%rsp),%rdx
xor    %ecx,%ecx
mov    %r12d,%r8d
call   1040 <doQuery@plt>
test   %eax,%eax
je     1466 <mygethostbyaddr+0x2d6>
mov    0x10(%rsp),%rdi
mov    (%rbx),%esi
xor    %r13d,%r13d
lea    0x18(%rsp),%rdx
xor    %ecx,%ecx
mov    %r12d,%r8d
call   1040 <doQuery@plt>
test   %eax,%eax
jne    11e6 <mygethostbyaddr+0x56>
mov    0x18(%rsp),%r13
jmp    11e6 <mygethostbyaddr+0x56>

LLVM IR (-O0):
%struct.TYPE_2__ = type { i32 }
%struct.in6_addr = type { i32* }
@_res = global %struct.TYPE_2__ zeroinitializer
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@.str = [2 x i8] c".\00"
@.str.1 = [25 x i8] c"%s.%s.%s.%s.in-addr.arpa\00"
@.str.2 = [4 x i8] c"%4x\00"
@.str.3 = [33 x i8] c"%s.%s.%s.%s.%s.%s.%s.%s.ip6.arpa\00"
@T_PTR = global i32 0
define i8* @mygethostbyaddr(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [5 x i8]
%11 = alloca i8*
%12 = alloca [4 x i8*]
%13 = alloca i8*
%14 = alloca [8 x i8*]
%15 = alloca i8*
%16 = alloca %struct.in6_addr
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* null, i8** %9
store i8* null, i8** %11
store i8* null, i8** %13
store i8* null, i8** %15
store i32 1, i32* getelementptr inbounds (%struct.TYPE_2__, %struct.TYPE_2__* @_res, i32 0, i32 0)
%17 = load i8*, i8** %4
%18 = icmp eq i8* %17, null
br i1 %18, label %27, label %19
19: ; preds = %2
%20 = load i32, i32* %5
%21 = load i32, i32* @AF_INET
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i32, i32* %5
%25 = load i32, i32* @AF_INET6
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23, %2
store i8* null, i8** %3
br label %194
28: ; preds = %23, %19
%29 = load i32, i32* %5
%30 = load i32, i32* @AF_INET
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %68
32: ; preds = %28
%33 = load i8*, i8** %4
%34 = call i8* @strdup(i8* %33)
store i8* %34, i8** %9
%35 = load i8*, i8** %9
%36 = call i8* @strtok(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %36, i8** %13
store i32 0, i32* %6
br label %37
37: ; preds = %40, %32
%38 = load i8*, i8** %13
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %48
40: ; preds = %37
%41 = load i8*, i8** %13
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [4 x i8*], [4 x i8*]* %12, i64 0, i64 %43
store i8* %41, i8** %44
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
%47 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %47, i8** %13
br label %37
48: ; preds = %37
%49 = load i32, i32* %6
%50 = icmp eq i32 %49, 4
br i1 %50, label %51, label %64
51: ; preds = %48
%52 = getelementptr inbounds [4 x i8*], [4 x i8*]* %12, i64 0, i64 3
%53 = load i8*, i8** %52
%54 = getelementptr inbounds [4 x i8*], [4 x i8*]* %12, i64 0, i64 2
%55 = load i8*, i8** %54
%56 = getelementptr inbounds [4 x i8*], [4 x i8*]* %12, i64 0, i64 1
%57 = load i8*, i8** %56
%58 = getelementptr inbounds [4 x i8*], [4 x i8*]* %12, i64 0, i64 0
%59 = load i8*, i8** %58
%60 = call i32 (i8**, i8*, i8*, i8*, i8*, i8*, ...) @asprintf(i8** %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %53, i8* %55, i8* %57, i8* %59)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %63
62: ; preds = %51
store i8* null, i8** %3
br label %194
63: ; preds = %51
br label %65
64: ; preds = %48
store i8* null, i8** %3
br label %194
65: ; preds = %63
%66 = load i8*, i8** %9
%67 = call i32 @free(i8* %66)
store i8* null, i8** %9
br label %176
68: ; preds = %28
%69 = load i32, i32* %5
%70 = load i32, i32* @AF_INET6
%71 = icmp eq i32 %69, %70
br i1 %71, label %72, label %175
72: ; preds = %68
%73 = load i32, i32* @AF_INET6
%74 = load i8*, i8** %4
%75 = call i32 @inet_pton(i32 %73, i8* %74, %struct.in6_addr* %16)
%76 = icmp ne i32 %75, 0
br i1 %76, label %78, label %77
77: ; preds = %72
store i8* null, i8** %3
br label %194
78: ; preds = %72
store i32 7, i32* %6
br label %79
79: ; preds = %135, %78
%80 = load i32, i32* %6
%81 = icmp sge i32 %80, 0
br i1 %81, label %82, label %138
82: ; preds = %79
%83 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
%84 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %16, i32 0, i32 0
%85 = load i32*, i32** %84
%86 = load i32, i32* %6
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i32, i32* %85, i64 %87
%89 = load i32, i32* %88
%90 = call i32 @ntohs(i32 %89)
%91 = call i32 @sprintf(i8* %83, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %90)
%92 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 4
store i8 0, i8* %92
%93 = call i8* @malloc(i32 8)
%94 = load i32, i32* %6
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds [8 x i8*], [8 x i8*]* %14, i64 0, i64 %95
store i8* %93, i8** %96
%97 = icmp eq i8* %93, null
br i1 %97, label %98, label %99
98: ; preds = %82
store i8* null, i8** %3
br label %194
99: ; preds = %82
%100 = load i32, i32* %6
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds [8 x i8*], [8 x i8*]* %14, i64 0, i64 %101
%103 = load i8*, i8** %102
store i8* %103, i8** %15
store i32 3, i32* %7
br label %104
104: ; preds = %132, %99
%105 = load i32, i32* %7
%106 = icmp sge i32 %105, 0
br i1 %106, label %107, label %135
107: ; preds = %104
%108 = load i32, i32* %7
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 %109
%111 = load i8, i8* %110
%112 = sext i8 %111 to i32
%113 = icmp eq i32 %112, 32
br i1 %113, label %114, label %116
114: ; preds = %107
%115 = load i8*, i8** %15
store i8 48, i8* %115
br label %122
116: ; preds = %107
%117 = load i32, i32* %7
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 %118
%120 = load i8, i8* %119
%121 = load i8*, i8** %15
store i8 %120, i8* %121
br label %122
122: ; preds = %116, %114
%123 = load i8*, i8** %15
%124 = getelementptr inbounds i8, i8* %123, i32 1
store i8* %124, i8** %15
%125 = load i32, i32* %7
%126 = icmp ne i32 %125, 0
br i1 %126, label %127, label %131
127: ; preds = %122
%128 = load i8*, i8** %15
store i8 46, i8* %128
%129 = load i8*, i8** %15
%130 = getelementptr inbounds i8, i8* %129, i32 1
store i8* %130, i8** %15
br label %131
131: ; preds = %127, %122
br label %132
132: ; preds = %131
%133 = load i32, i32* %7
%134 = add nsw i32 %133, -1
store i32 %134, i32* %7
br label %104
135: ; preds = %104
%136 = load i32, i32* %6
%137 = add nsw i32 %136, -1
store i32 %137, i32* %6
br label %79
138: ; preds = %79
%139 = getelementptr inbounds [8 x i8*], [8 x i8*]* %14, i64 0, i64 7
%140 = load i8*, i8** %139
%141 = getelementptr inbounds [8 x i8*], [8 x i8*]* %14, i64 0, i64 6
%142 = load i8*, i8** %141
%143 = getelementptr inbounds [8 x i8*], [8 x i8*]* %14, i64 0, i64 5
%144 = load i8*, i8** %143
%145 = getelementptr inbounds [8 x i8*], [8 x i8*]* %14, i64 0, i64 4
%146 = load i8*, i8** %145
%147 = getelementptr inbounds [8 x i8*], [8 x i8*]* %14, i64 0, i64 3
%148 = load i8*, i8** %147
%149 = getelementptr inbounds [8 x i8*], [8 x i8*]* %14, i64 0, i64 2
%150 = load i8*, i8** %149
%151 = getelementptr inbounds [8 x i8*], [8 x i8*]* %14, i64 0, i64 1
%152 = load i8*, i8** %151
%153 = getelementptr inbounds [8 x i8*], [8 x i8*]* %14, i64 0, i64 0
%154 = load i8*, i8** %153
%155 = call i32 (i8**, i8*, i8*, i8*, i8*, i8*, ...) @asprintf(i8** %4, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %140, i8* %142, i8* %144, i8* %146, i8* %148, i8* %150, i8* %152, i8* %154)
%156 = icmp eq i32 %155, -1
br i1 %156, label %157, label %158
157: ; preds = %138
store i8* null, i8** %3
br label %194
158: ; preds = %138
store i32 0, i32* %7
br label %159
159: ; preds = %171, %158
%160 = load i32, i32* %7
%161 = icmp slt i32 %160, 8
br i1 %161, label %162, label %174
162: ; preds = %159
%163 = load i32, i32* %7
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds [8 x i8*], [8 x i8*]* %14, i64 0, i64 %164
%166 = load i8*, i8** %165
%167 = call i32 @free(i8* %166)
%168 = load i32, i32* %7
%169 = sext i32 %168 to i64
%170 = getelementptr inbounds [8 x i8*], [8 x i8*]* %14, i64 0, i64 %169
store i8* null, i8** %170
br label %171
171: ; preds = %162
%172 = load i32, i32* %7
%173 = add nsw i32 %172, 1
store i32 %173, i32* %7
br label %159
174: ; preds = %159
br label %175
175: ; preds = %174, %68
br label %176
176: ; preds = %175, %65
%177 = load i8*, i8** %4
%178 = load i32, i32* @T_PTR
%179 = load i32, i32* %5
%180 = call i32 @doQuery(i8* %177, i32 %178, i8** %11, i32* null, i32 %179)
store i32 %180, i32* %8
%181 = load i32, i32* %8
%182 = icmp ne i32 %181, 0
br i1 %182, label %183, label %188
183: ; preds = %176
%184 = load i8*, i8** %4
%185 = load i32, i32* @T_PTR
%186 = load i32, i32* %5
%187 = call i32 @doQuery(i8* %184, i32 %185, i8** %11, i32* null, i32 %186)
store i32 %187, i32* %8
br label %188
188: ; preds = %183, %176
%189 = load i32, i32* %8
%190 = icmp ne i32 %189, 0
br i1 %190, label %191, label %192
191: ; preds = %188
store i8* null, i8** %3
br label %194
192: ; preds = %188
%193 = load i8*, i8** %11
store i8* %193, i8** %3
br label %194
194: ; preds = %192, %191, %157, %98, %77, %64, %62, %27
%195 = load i8*, i8** %3
ret i8* %195
}

LLVM IR (-O2):
%struct.TYPE_2__ = type { i32 }
%struct.in6_addr = type { i32* }
@_res = global %struct.TYPE_2__ zeroinitializer
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@.str = [2 x i8] c".\00"
@.str.1 = [25 x i8] c"%s.%s.%s.%s.in-addr.arpa\00"
@.str.2 = [4 x i8] c"%4x\00"
@.str.3 = [33 x i8] c"%s.%s.%s.%s.%s.%s.%s.%s.ip6.arpa\00"
@T_PTR = global i32 0
define i8* @mygethostbyaddr(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca [5 x i8]
%5 = alloca i8*
%6 = alloca [4 x i8*]
%7 = alloca [8 x i8*]
%8 = alloca %struct.in6_addr
store i8* %0, i8** %3
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%10 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%11 = bitcast [4 x i8*]* %6 to i8*
%12 = bitcast [8 x i8*]* %7 to i8*
%13 = bitcast %struct.in6_addr* %8 to i8*
store i32 1, i32* getelementptr inbounds (%struct.TYPE_2__, %struct.TYPE_2__* @_res, i64 0, i32 0)
%14 = icmp eq i8* %0, null
br i1 %14, label %134, label %15
15: ; preds = %2
%16 = load i32, i32* @AF_INET
%17 = icmp eq i32 %16, %1
%18 = load i32, i32* @AF_INET6
%19 = icmp eq i32 %18, %1
%20 = select i1 %17, i1 true, i1 %19
br i1 %20, label %21, label %134
21: ; preds = %15
br i1 %17, label %22, label %49
22: ; preds = %21
%23 = tail call i8* @strdup(i8* %0)
%24 = tail call i8* @strtok(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %134, label %26
26: ; preds = %22, %26
%27 = phi i64 [ %30, %26 ], [ 0, %22 ]
%28 = phi i8* [ %31, %26 ], [ %24, %22 ]
%29 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 %27
store i8* %28, i8** %29
%30 = add nuw i64 %27, 1
%31 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %26
33: ; preds = %26
%34 = trunc i64 %30 to i32
%35 = icmp eq i32 %34, 4
br i1 %35, label %36, label %134
36: ; preds = %33
%37 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 3
%38 = load i8*, i8** %37
%39 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 2
%40 = load i8*, i8** %39
%41 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 1
%42 = load i8*, i8** %41
%43 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
%44 = load i8*, i8** %43
%45 = call i32 (i8**, i8*, i8*, i8*, i8*, i8*, ...) @asprintf(i8** %3, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %38, i8* %40, i8* %42, i8* %44)
%46 = icmp eq i32 %45, -1
br i1 %46, label %134, label %47
47: ; preds = %36
%48 = call i32 @free(i8* %23)
br label %122
49: ; preds = %21
br i1 %19, label %50, label %122
50: ; preds = %49
%51 = call i32 @inet_pton(i32 %1, i8* %0, %struct.in6_addr* %8)
%52 = icmp eq i32 %51, 0
br i1 %52, label %134, label %53
53: ; preds = %50
%54 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %8, i64 0, i32 0
%55 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 4
%56 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 3
%57 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 2
%58 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 1
br label %59
59: ; preds = %53, %69
%60 = phi i64 [ 7, %53 ], [ %88, %69 ]
%61 = load i32*, i32** %54
%62 = getelementptr inbounds i32, i32* %61, i64 %60
%63 = load i32, i32* %62
%64 = call i32 @ntohs(i32 %63)
%65 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %64)
store i8 0, i8* %55
%66 = call dereferenceable_or_null(8) i8* @malloc(i32 8)
%67 = getelementptr inbounds [8 x i8*], [8 x i8*]* %7, i64 0, i64 %60
store i8* %66, i8** %67
%68 = icmp eq i8* %66, null
br i1 %68, label %134, label %69
69: ; preds = %59
%70 = load i8, i8* %56
%71 = icmp eq i8 %70, 32
%72 = select i1 %71, i8 48, i8 %70
store i8 %72, i8* %66
%73 = getelementptr inbounds i8, i8* %66, i64 1
store i8 46, i8* %73
%74 = getelementptr inbounds i8, i8* %66, i64 2
%75 = load i8, i8* %57
%76 = icmp eq i8 %75, 32
%77 = select i1 %76, i8 48, i8 %75
store i8 %77, i8* %74
%78 = getelementptr inbounds i8, i8* %66, i64 3
store i8 46, i8* %78
%79 = getelementptr inbounds i8, i8* %66, i64 4
%80 = load i8, i8* %58
%81 = icmp eq i8 %80, 32
%82 = select i1 %81, i8 48, i8 %80
store i8 %82, i8* %79
%83 = getelementptr inbounds i8, i8* %66, i64 5
store i8 46, i8* %83
%84 = getelementptr inbounds i8, i8* %66, i64 6
%85 = load i8, i8* %9
%86 = icmp eq i8 %85, 32
%87 = select i1 %86, i8 48, i8 %85
store i8 %87, i8* %84
%88 = add nsw i64 %60, -1
%89 = icmp eq i64 %60, 0
br i1 %89, label %90, label %59
90: ; preds = %69
%91 = getelementptr inbounds [8 x i8*], [8 x i8*]* %7, i64 0, i64 7
%92 = load i8*, i8** %91
%93 = getelementptr inbounds [8 x i8*], [8 x i8*]* %7, i64 0, i64 6
%94 = load i8*, i8** %93
%95 = getelementptr inbounds [8 x i8*], [8 x i8*]* %7, i64 0, i64 5
%96 = load i8*, i8** %95
%97 = getelementptr inbounds [8 x i8*], [8 x i8*]* %7, i64 0, i64 4
%98 = load i8*, i8** %97
%99 = getelementptr inbounds [8 x i8*], [8 x i8*]* %7, i64 0, i64 3
%100 = load i8*, i8** %99
%101 = getelementptr inbounds [8 x i8*], [8 x i8*]* %7, i64 0, i64 2
%102 = load i8*, i8** %101
%103 = getelementptr inbounds [8 x i8*], [8 x i8*]* %7, i64 0, i64 1
%104 = load i8*, i8** %103
%105 = getelementptr inbounds [8 x i8*], [8 x i8*]* %7, i64 0, i64 0
%106 = load i8*, i8** %105
%107 = call i32 (i8**, i8*, i8*, i8*, i8*, i8*, ...) @asprintf(i8** %3, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %92, i8* %94, i8* %96, i8* %98, i8* %100, i8* %102, i8* %104, i8* %106)
%108 = icmp eq i32 %107, -1
br i1 %108, label %134, label %109
109: ; preds = %90
%110 = call i32 @free(i8* %106)
%111 = call i32 @free(i8* %104)
%112 = bitcast [8 x i8*]* %7 to <2 x i8*>*
store <2 x i8*> zeroinitializer, <2 x i8*>* %112
%113 = call i32 @free(i8* %102)
%114 = call i32 @free(i8* %100)
%115 = bitcast i8** %101 to <2 x i8*>*
store <2 x i8*> zeroinitializer, <2 x i8*>* %115
%116 = call i32 @free(i8* %98)
%117 = call i32 @free(i8* %96)
%118 = bitcast i8** %97 to <2 x i8*>*
store <2 x i8*> zeroinitializer, <2 x i8*>* %118
%119 = call i32 @free(i8* %94)
%120 = call i32 @free(i8* %92)
%121 = bitcast i8** %93 to <2 x i8*>*
store <2 x i8*> zeroinitializer, <2 x i8*>* %121
br label %122
122: ; preds = %109, %49, %47
%123 = load i8*, i8** %3
%124 = load i32, i32* @T_PTR
%125 = call i32 @doQuery(i8* %123, i32 %124, i8** %5, i32* null, i32 %1)
%126 = icmp eq i32 %125, 0
br i1 %126, label %132, label %127
127: ; preds = %122
%128 = load i8*, i8** %3
%129 = load i32, i32* @T_PTR
%130 = call i32 @doQuery(i8* %128, i32 %129, i8** %5, i32* null, i32 %1)
%131 = icmp eq i32 %130, 0
br i1 %131, label %132, label %134
132: ; preds = %122, %127
%133 = load i8*, i8** %5
br label %134
134: ; preds = %59, %22, %127, %90, %50, %33, %36, %2, %15, %132
%135 = phi i8* [ %133, %132 ], [ null, %15 ], [ null, %2 ], [ null, %36 ], [ null, %33 ], [ null, %50 ], [ null, %90 ], [ null, %127 ], [ null, %22 ], [ null, %59 ]
ret i8* %135
}