#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 */
typedef int /*<<< orphan*/ host;
typedef int /*<<< orphan*/ HEADER;

/* Variables and functions */
int /*<<< orphan*/ C_IN;
int /*<<< orphan*/ GETLONG(unsigned int, unsigned char *);
int /*<<< orphan*/ GETSHORT(unsigned int, unsigned char *);
int /*<<< orphan*/ INT16SZ;
int T_ANY;
int T_CNAME;
int T_TXT;
int dn_expand(unsigned char *, unsigned char *, unsigned char *, char *, int);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ memcpy(char *, unsigned char *, unsigned int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ res_init();
int res_query(char const *, int /*<<< orphan*/, int, unsigned char *, int);
char *txtquery(const char *domain, unsigned int *ttl) {
  unsigned char answer[512], *answend, *pt;
  char *txt, host[128];
  int len, type, qtype;
  unsigned int cttl, size, txtlen = 0;
  *ttl = 0;
  if (res_init() < 0) {
    printf("^res_init failed\n");
    return NULL;
  }
  printf("*Querying %s\n", domain);
  memset(answer, 0, 512);
  qtype = T_TXT;
  if ((len = res_query(domain, C_IN, qtype, answer, 512)) < 0 || len > 512) {
    memset(answer, 0, 512);
    qtype = T_ANY;
    if ((len = res_query(domain, C_IN, qtype, answer, 512)) < 0) {
      printf("^Can't query %s\n", domain);
      return NULL;
    }
  }
  answend = answer + len;
  pt = answer + sizeof(HEADER);
  if ((len = dn_expand(answer, answend, pt, host, sizeof(host))) < 0) {
    printf("^dn_expand failed\n");
    return NULL;
  }
  pt += len;
  if (pt > answend - 4) {
    printf("^Bad (too short) DNS reply\n");
    return NULL;
  }
  GETSHORT(type, pt);
  if (type != qtype) {
    printf("^Broken DNS reply.\n");
    return NULL;
  }
  pt += INT16SZ;
  size = 0;
  do {
    pt += size;
    if ((len = dn_expand(answer, answend, pt, host, sizeof(host))) < 0) {
      printf("^second dn_expand failed\n");
      return NULL;
    }
    printf("^Host: %s\n", host);
    pt += len;
    if (pt > answend - 10) {
      printf("^Bad (too short) DNS reply\n");
      return NULL;
    }
    GETSHORT(type, pt);
    pt += INT16SZ;
    GETLONG(cttl, pt);
    GETSHORT(size, pt);
    if (pt + size < answer || pt + size > answend) {
      printf("^DNS rr overflow\n");
      return NULL;
    }
  } while (type == T_CNAME);
  if (type != T_TXT) {
    printf("^Not a TXT record\n");
    return NULL;
  }
  if (!size || (txtlen = *pt) >= size || !txtlen) {
    printf("^Broken TXT record (txtlen = %d, size = %d)\n", txtlen, size);
    return NULL;
  }
  if (!(txt = (char *)malloc(txtlen + 1)))
    return NULL;
  memcpy(txt, pt + 1, txtlen);
  txt[txtlen] = 0;
  *ttl = cttl;
  return txt;
}


x86 assembly (clang, -O0):
<txtquery>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2e0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x2d8(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    $0x0,%al
call   1060 <res_init@plt>
cmp    $0x0,%rax
jge    11e3 <txtquery+0x53>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1698 <txtquery+0x508>
mov    -0x10(%rbp),%rsi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2cc(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
mov    -0x2cc(%rbp),%edx
lea    -0x220(%rbp),%rcx
mov    $0x200,%r8d
call   10b0 <res_query@plt>
mov    %eax,-0x2c4(%rbp)
cmp    $0x0,%eax
jl     125b <txtquery+0xcb>
cmpl   $0x200,-0x2c4(%rbp)
jle    12d5 <txtquery+0x145>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2cc(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2d60(%rip),%rax
mov    (%rax),%esi
mov    -0x2cc(%rbp),%edx
lea    -0x220(%rbp),%rcx
mov    $0x200,%r8d
call   10b0 <res_query@plt>
mov    %eax,-0x2c4(%rbp)
cmp    $0x0,%eax
jge    12d0 <txtquery+0x140>
mov    -0x10(%rbp),%rsi
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1698 <txtquery+0x508>
jmp    12d5 <txtquery+0x145>
lea    -0x220(%rbp),%rax
movslq -0x2c4(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x228(%rbp)
lea    -0x220(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x230(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x228(%rbp),%rsi
mov    -0x230(%rbp),%rdx
lea    -0x2c0(%rbp),%rcx
mov    $0x80,%r8d
call   10a0 <dn_expand@plt>
mov    %eax,-0x2c4(%rbp)
cmp    $0x0,%eax
jge    1350 <txtquery+0x1c0>
lea    0xcf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1698 <txtquery+0x508>
mov    -0x2c4(%rbp),%ecx
mov    -0x230(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x230(%rbp)
mov    -0x230(%rbp),%rax
mov    -0x228(%rbp),%rcx
add    $0xfffffffffffffffc,%rcx
cmp    %rcx,%rax
jbe    13a0 <txtquery+0x210>
lea    0xcb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1698 <txtquery+0x508>
mov    -0x2c8(%rbp),%edi
mov    -0x230(%rbp),%rsi
call   1070 <GETSHORT@plt>
mov    -0x2c8(%rbp),%eax
cmp    -0x2cc(%rbp),%eax
je     13df <txtquery+0x24f>
lea    0xc95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1698 <txtquery+0x508>
mov    0x2bea(%rip),%rax
mov    (%rax),%ecx
mov    -0x230(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x230(%rbp)
movl   $0x0,-0x2d4(%rbp)
mov    -0x2d4(%rbp),%ecx
mov    -0x230(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x230(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x228(%rbp),%rsi
mov    -0x230(%rbp),%rdx
lea    -0x2c0(%rbp),%rcx
mov    $0x80,%r8d
call   10a0 <dn_expand@plt>
mov    %eax,-0x2c4(%rbp)
cmp    $0x0,%eax
jge    1470 <txtquery+0x2e0>
lea    0xc18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1698 <txtquery+0x508>
lea    -0x2c0(%rbp),%rsi
lea    0xc10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c4(%rbp),%ecx
mov    -0x230(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x230(%rbp)
mov    -0x230(%rbp),%rax
mov    -0x228(%rbp),%rcx
add    $0xfffffffffffffff6,%rcx
cmp    %rcx,%rax
jbe    14d5 <txtquery+0x345>
lea    0xb83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1698 <txtquery+0x508>
mov    -0x2c8(%rbp),%edi
mov    -0x230(%rbp),%rsi
call   1070 <GETSHORT@plt>
mov    0x2ae2(%rip),%rax
mov    (%rax),%ecx
mov    -0x230(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x230(%rbp)
mov    -0x2d0(%rbp),%edi
mov    -0x230(%rbp),%rsi
call   1030 <GETLONG@plt>
mov    -0x2d4(%rbp),%edi
mov    -0x230(%rbp),%rsi
call   1070 <GETSHORT@plt>
mov    -0x230(%rbp),%rax
mov    -0x2d4(%rbp),%ecx
add    %rcx,%rax
lea    -0x220(%rbp),%rcx
cmp    %rcx,%rax
jb     1565 <txtquery+0x3d5>
mov    -0x230(%rbp),%rax
mov    -0x2d4(%rbp),%ecx
add    %rcx,%rax
cmp    -0x228(%rbp),%rax
jbe    1580 <txtquery+0x3f0>
lea    0xb2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1698 <txtquery+0x508>
jmp    1585 <txtquery+0x3f5>
mov    -0x2c8(%rbp),%eax
mov    0x2a26(%rip),%rcx
cmp    (%rcx),%eax
je     1406 <txtquery+0x276>
mov    -0x2c8(%rbp),%eax
mov    0x2a31(%rip),%rcx
cmp    (%rcx),%eax
je     15ca <txtquery+0x43a>
lea    0xaf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1698 <txtquery+0x508>
cmpl   $0x0,-0x2d4(%rbp)
je     1600 <txtquery+0x470>
mov    -0x230(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x2d8(%rbp)
cmp    -0x2d4(%rbp),%eax
jae    1600 <txtquery+0x470>
cmpl   $0x0,-0x2d8(%rbp)
jne    1627 <txtquery+0x497>
mov    -0x2d8(%rbp),%esi
mov    -0x2d4(%rbp),%edx
lea    0xaab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1698 <txtquery+0x508>
mov    -0x2d8(%rbp),%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x238(%rbp)
cmp    $0x0,%rax
jne    1653 <txtquery+0x4c3>
movq   $0x0,-0x8(%rbp)
jmp    1698 <txtquery+0x508>
mov    -0x238(%rbp),%rdi
mov    -0x230(%rbp),%rsi
add    $0x1,%rsi
mov    -0x2d8(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x238(%rbp),%rax
mov    -0x2d8(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x2d0(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x238(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x2e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<txtquery>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x280,%rsp
mov    %rdi,%rbx
movl   $0x0,(%rsi)
xor    %eax,%eax
call   1070 <res_init@plt>
test   %rax,%rax
js     12de <txtquery+0x15e>
lea    0xe50(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x80(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
mov    0x2e07(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
mov    %r14,%rcx
mov    $0x200,%r8d
call   10a0 <res_query@plt>
cmp    $0x201,%eax
jb     1238 <txtquery+0xb8>
lea    0x80(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%edx
mov    (%r15),%esi
mov    %rbx,%rdi
mov    %r14,%rcx
mov    $0x200,%r8d
call   10a0 <res_query@plt>
test   %eax,%eax
js     12f0 <txtquery+0x170>
mov    %eax,%eax
lea    (%rsp,%rax,1),%r15
add    $0x80,%r15
lea    0x84(%rsp),%rbx
lea    0x80(%rsp),%rdi
mov    %rsp,%rcx
mov    %r15,%rsi
mov    %rbx,%rdx
mov    $0x80,%r8d
call   1090 <dn_expand@plt>
test   %eax,%eax
js     12e7 <txtquery+0x167>
mov    %eax,%eax
add    %rax,%rbx
lea    -0x4(%r15),%rax
cmp    %rax,%rbx
ja     12d5 <txtquery+0x155>
mov    %rbx,%rsi
call   1080 <GETSHORT@plt>
mov    0x2d46(%rip),%r13
movslq 0x0(%r13),%r12
add    %rbx,%r12
lea    0x80(%rsp),%r14
mov    %rsp,%rcx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    $0x80,%r8d
call   1090 <dn_expand@plt>
test   %eax,%eax
js     1303 <txtquery+0x183>
mov    %eax,%ebx
lea    0xd62(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    %rax,%r12
lea    -0xa(%r15),%rax
cmp    %rax,%r12
jbe    130c <txtquery+0x18c>
lea    0xda5(%rip),%rdi
jmp    1352 <txtquery+0x1d2>
lea    0xdc9(%rip),%rdi
jmp    1352 <txtquery+0x1d2>
lea    0xdae(%rip),%rdi
jmp    1352 <txtquery+0x1d2>
lea    0xd17(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1357 <txtquery+0x1d7>
lea    0xd5e(%rip),%rdi
jmp    1352 <txtquery+0x1d2>
mov    %r12,%rsi
call   1080 <GETSHORT@plt>
movslq 0x0(%r13),%rbx
add    %r12,%rbx
mov    %rbx,%rsi
call   1040 <GETLONG@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1080 <GETSHORT@plt>
cmp    %r14,%rbx
jb     134b <txtquery+0x1cb>
cmp    %r15,%rbx
ja     134b <txtquery+0x1cb>
lea    0xcec(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1357 <txtquery+0x1d7>
lea    0xd05(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x280,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"^res_init failed\0A\00"
@.str.1 = [14 x i8] c"*Querying %s\0A\00"
@T_TXT = global i32 0
@C_IN = global i32 0
@T_ANY = global i32 0
@.str.2 = [17 x i8] c"^Can't query %s\0A\00"
@.str.3 = [19 x i8] c"^dn_expand failed\0A\00"
@.str.4 = [28 x i8] c"^Bad (too short) DNS reply\0A\00"
@.str.5 = [20 x i8] c"^Broken DNS reply.\0A\00"
@INT16SZ = global i32 0
@.str.6 = [26 x i8] c"^second dn_expand failed\0A\00"
@.str.7 = [11 x i8] c"^Host: %s\0A\00"
@.str.8 = [18 x i8] c"^DNS rr overflow\0A\00"
@T_CNAME = global i32 0
@.str.9 = [19 x i8] c"^Not a TXT record\0A\00"
@.str.10 = [45 x i8] c"^Broken TXT record (txtlen = %d, size = %d)\0A\00"
define i8* @txtquery(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [512 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [128 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 0, i32* %16
%17 = load i32*, i32** %5
store i32 0, i32* %17
%18 = call i64 (...) @res_init()
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %193
22: ; preds = %2
%23 = load i8*, i8** %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%26 = call i32 @memset(i8* %25, i32 0, i32 512)
%27 = load i32, i32* @T_TXT
store i32 %27, i32* %13
%28 = load i8*, i8** %4
%29 = load i32, i32* @C_IN
%30 = load i32, i32* %13
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%32 = call i32 @res_query(i8* %28, i32 %29, i32 %30, i8* %31, i32 512)
store i32 %32, i32* %11
%33 = icmp slt i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %22
%35 = load i32, i32* %11
%36 = icmp sgt i32 %35, 512
br i1 %36, label %37, label %51
37: ; preds = %34, %22
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%39 = call i32 @memset(i8* %38, i32 0, i32 512)
%40 = load i32, i32* @T_ANY
store i32 %40, i32* %13
%41 = load i8*, i8** %4
%42 = load i32, i32* @C_IN
%43 = load i32, i32* %13
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%45 = call i32 @res_query(i8* %41, i32 %42, i32 %43, i8* %44, i32 512)
store i32 %45, i32* %11
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %37
%48 = load i8*, i8** %4
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %48)
store i8* null, i8** %3
br label %193
50: ; preds = %37
br label %51
51: ; preds = %50, %34
%52 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%53 = load i32, i32* %11
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
store i8* %55, i8** %7
%56 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%57 = getelementptr inbounds i8, i8* %56, i64 4
store i8* %57, i8** %8
%58 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%59 = load i8*, i8** %7
%60 = load i8*, i8** %8
%61 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%62 = call i32 @dn_expand(i8* %58, i8* %59, i8* %60, i8* %61, i32 128)
store i32 %62, i32* %11
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %51
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %3
br label %193
66: ; preds = %51
%67 = load i32, i32* %11
%68 = load i8*, i8** %8
%69 = sext i32 %67 to i64
%70 = getelementptr inbounds i8, i8* %68, i64 %69
store i8* %70, i8** %8
%71 = load i8*, i8** %8
%72 = load i8*, i8** %7
%73 = getelementptr inbounds i8, i8* %72, i64 -4
%74 = icmp ugt i8* %71, %73
br i1 %74, label %75, label %77
75: ; preds = %66
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i8* null, i8** %3
br label %193
77: ; preds = %66
%78 = load i32, i32* %12
%79 = load i8*, i8** %8
%80 = call i32 @GETSHORT(i32 %78, i8* %79)
%81 = load i32, i32* %12
%82 = load i32, i32* %13
%83 = icmp ne i32 %81, %82
br i1 %83, label %84, label %86
84: ; preds = %77
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
store i8* null, i8** %3
br label %193
86: ; preds = %77
%87 = load i32, i32* @INT16SZ
%88 = load i8*, i8** %8
%89 = sext i32 %87 to i64
%90 = getelementptr inbounds i8, i8* %88, i64 %89
store i8* %90, i8** %8
store i32 0, i32* %15
br label %91
91: ; preds = %147, %86
%92 = load i32, i32* %15
%93 = load i8*, i8** %8
%94 = zext i32 %92 to i64
%95 = getelementptr inbounds i8, i8* %93, i64 %94
store i8* %95, i8** %8
%96 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%97 = load i8*, i8** %7
%98 = load i8*, i8** %8
%99 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%100 = call i32 @dn_expand(i8* %96, i8* %97, i8* %98, i8* %99, i32 128)
store i32 %100, i32* %11
%101 = icmp slt i32 %100, 0
br i1 %101, label %102, label %104
102: ; preds = %91
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
store i8* null, i8** %3
br label %193
104: ; preds = %91
%105 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %105)
%107 = load i32, i32* %11
%108 = load i8*, i8** %8
%109 = sext i32 %107 to i64
%110 = getelementptr inbounds i8, i8* %108, i64 %109
store i8* %110, i8** %8
%111 = load i8*, i8** %8
%112 = load i8*, i8** %7
%113 = getelementptr inbounds i8, i8* %112, i64 -10
%114 = icmp ugt i8* %111, %113
br i1 %114, label %115, label %117
115: ; preds = %104
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i8* null, i8** %3
br label %193
117: ; preds = %104
%118 = load i32, i32* %12
%119 = load i8*, i8** %8
%120 = call i32 @GETSHORT(i32 %118, i8* %119)
%121 = load i32, i32* @INT16SZ
%122 = load i8*, i8** %8
%123 = sext i32 %121 to i64
%124 = getelementptr inbounds i8, i8* %122, i64 %123
store i8* %124, i8** %8
%125 = load i32, i32* %14
%126 = load i8*, i8** %8
%127 = call i32 @GETLONG(i32 %125, i8* %126)
%128 = load i32, i32* %15
%129 = load i8*, i8** %8
%130 = call i32 @GETSHORT(i32 %128, i8* %129)
%131 = load i8*, i8** %8
%132 = load i32, i32* %15
%133 = zext i32 %132 to i64
%134 = getelementptr inbounds i8, i8* %131, i64 %133
%135 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%136 = icmp ult i8* %134, %135
br i1 %136, label %144, label %137
137: ; preds = %117
%138 = load i8*, i8** %8
%139 = load i32, i32* %15
%140 = zext i32 %139 to i64
%141 = getelementptr inbounds i8, i8* %138, i64 %140
%142 = load i8*, i8** %7
%143 = icmp ugt i8* %141, %142
br i1 %143, label %144, label %146
144: ; preds = %137, %117
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
store i8* null, i8** %3
br label %193
146: ; preds = %137
br label %147
147: ; preds = %146
%148 = load i32, i32* %12
%149 = load i32, i32* @T_CNAME
%150 = icmp eq i32 %148, %149
br i1 %150, label %91, label %151
151: ; preds = %147
%152 = load i32, i32* %12
%153 = load i32, i32* @T_TXT
%154 = icmp ne i32 %152, %153
br i1 %154, label %155, label %157
155: ; preds = %151
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
store i8* null, i8** %3
br label %193
157: ; preds = %151
%158 = load i32, i32* %15
%159 = icmp ne i32 %158, 0
br i1 %159, label %160, label %169
160: ; preds = %157
%161 = load i8*, i8** %8
%162 = load i8, i8* %161
%163 = zext i8 %162 to i32
store i32 %163, i32* %16
%164 = load i32, i32* %15
%165 = icmp uge i32 %163, %164
br i1 %165, label %169, label %166
166: ; preds = %160
%167 = load i32, i32* %16
%168 = icmp ne i32 %167, 0
br i1 %168, label %173, label %169
169: ; preds = %166, %160, %157
%170 = load i32, i32* %16
%171 = load i32, i32* %15
%172 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.10, i64 0, i64 0), i32 %170, i32 %171)
store i8* null, i8** %3
br label %193
173: ; preds = %166
%174 = load i32, i32* %16
%175 = add i32 %174, 1
%176 = call i64 @malloc(i32 %175)
%177 = inttoptr i64 %176 to i8*
store i8* %177, i8** %9
%178 = icmp ne i8* %177, null
br i1 %178, label %180, label %179
179: ; preds = %173
store i8* null, i8** %3
br label %193
180: ; preds = %173
%181 = load i8*, i8** %9
%182 = load i8*, i8** %8
%183 = getelementptr inbounds i8, i8* %182, i64 1
%184 = load i32, i32* %16
%185 = call i32 @memcpy(i8* %181, i8* %183, i32 %184)
%186 = load i8*, i8** %9
%187 = load i32, i32* %16
%188 = zext i32 %187 to i64
%189 = getelementptr inbounds i8, i8* %186, i64 %188
store i8 0, i8* %189
%190 = load i32, i32* %14
%191 = load i32*, i32** %5
store i32 %190, i32* %191
%192 = load i8*, i8** %9
store i8* %192, i8** %3
br label %193
193: ; preds = %180, %179, %169, %155, %144, %115, %102, %84, %75, %64, %47, %20
%194 = load i8*, i8** %3
ret i8* %194
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"*Querying %s\0A\00"
@T_TXT = global i32 0
@C_IN = global i32 0
@T_ANY = global i32 0
@.str.2 = [17 x i8] c"^Can't query %s\0A\00"
@INT16SZ = global i32 0
@.str.7 = [11 x i8] c"^Host: %s\0A\00"
@T_CNAME = global i32 0
@.str.10 = [45 x i8] c"^Broken TXT record (txtlen = %d, size = %d)\0A\00"
@str = [17 x i8] c"^DNS rr overflow\00"
@str.12 = [25 x i8] c"^second dn_expand failed\00"
@str.13 = [27 x i8] c"^Bad (too short) DNS reply\00"
@str.14 = [18 x i8] c"^dn_expand failed\00"
@str.15 = [17 x i8] c"^res_init failed\00"
define noalias i8* @txtquery(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [512 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
store i32 0, i32* %1
%7 = tail call i64 (...) @res_init()
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.15, i64 0, i64 0))
br label %73
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%13 = call i32 @memset(i8* %5, i32 0, i32 512)
%14 = load i32, i32* @T_TXT
%15 = load i32, i32* @C_IN
%16 = call i32 @res_query(i8* %0, i32 %15, i32 %14, i8* %5, i32 512)
%17 = icmp ugt i32 %16, 512
br i1 %17, label %18, label %26
18: ; preds = %11
%19 = call i32 @memset(i8* %5, i32 0, i32 512)
%20 = load i32, i32* @T_ANY
%21 = load i32, i32* @C_IN
%22 = call i32 @res_query(i8* %0, i32 %21, i32 %20, i8* %5, i32 512)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %73
26: ; preds = %18, %11
%27 = phi i32 [ %22, %18 ], [ %16, %11 ]
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %28
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 4
%31 = call i32 @dn_expand(i8* %5, i8* %29, i8* %30, i8* %6, i32 128)
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.14, i64 0, i64 0))
br label %73
35: ; preds = %26
%36 = zext i32 %31 to i64
%37 = getelementptr inbounds i8, i8* %30, i64 %36
%38 = getelementptr inbounds i8, i8* %29, i64 -4
%39 = icmp ugt i8* %37, %38
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.13, i64 0, i64 0))
br label %73
42: ; preds = %35
%43 = call i32 @GETSHORT(i32 undef, i8* %37)
%44 = load i32, i32* @INT16SZ
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %37, i64 %45
%47 = call i32 @dn_expand(i8* %5, i8* %29, i8* %46, i8* %6, i32 128)
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %42
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.12, i64 0, i64 0))
br label %73
51: ; preds = %42
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %6)
%53 = zext i32 %47 to i64
%54 = getelementptr inbounds i8, i8* %46, i64 %53
%55 = getelementptr inbounds i8, i8* %29, i64 -10
%56 = icmp ugt i8* %54, %55
br i1 %56, label %57, label %59
57: ; preds = %51
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.13, i64 0, i64 0))
br label %73
59: ; preds = %51
%60 = call i32 @GETSHORT(i32 undef, i8* %54)
%61 = load i32, i32* @INT16SZ
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %54, i64 %62
%64 = call i32 @GETLONG(i32 undef, i8* %63)
%65 = call i32 @GETSHORT(i32 0, i8* %63)
%66 = icmp ult i8* %63, %5
%67 = icmp ugt i8* %63, %29
%68 = or i1 %66, %67
br i1 %68, label %69, label %71
69: ; preds = %59
%70 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %73
71: ; preds = %59
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.10, i64 0, i64 0), i32 0, i32 0)
br label %73
73: ; preds = %71, %69, %57, %49, %40, %33, %24, %9
ret i8* null
}