#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 */
typedef int uint8_t;
typedef scalar_t__ uint16_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  scalar_t__ sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int ai_addrlen;
  char *ai_canonname;
  struct addrinfo *ai_next;
  struct sockaddr *ai_addr;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  void *ai_family;
  scalar_t__ ai_flags;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ dns_response;

/* Variables and functions */
void *AF_INET;
int EAI_FAIL;
int EAI_NONAME;
int EAI_SYSTEM;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ dns_response_get16(int const *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
void *malloc(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int const *, int);
char *new_name(int *, int const *, scalar_t__ *);
int recv(int, int *, int, int /*<<< orphan*/);
int *skip_labels(int const *);
int *skip_questions(int *);
int recv_dns_response(int sock, uint16_t id, struct addrinfo **res) {
  int ret;
  uint8_t dns_response[512];
  ssize_t dns_response_len;
  do {
    uint8_t rcode;
    uint16_t ancount;
    uint16_t ientry;
    const uint8_t *presp;
    struct addrinfo *ai_head;
    struct addrinfo *ai_tail;
    dns_response_len = recv(sock, dns_response, sizeof(dns_response), 0);
    if (dns_response_len < 0) {
      ret = EAI_SYSTEM;
      break;
    }
    if (dns_response_len < 12) {
      continue;
    }
    if (dns_response_get16(&dns_response[0]) != id) {
      continue;
    }
    rcode = dns_response[3] & 0x0F;
    if (rcode == 3) {
      ret = EAI_NONAME;
      break;
    } else if (rcode != 0) {
      ret = EAI_FAIL;
      break;
    }
    presp = skip_questions(dns_response);
    if (presp == NULL) {
      ret = EAI_FAIL;
      break;
    }
    ancount = dns_response_get16(&dns_response[6]);
    ai_head = NULL;
    ai_tail = NULL;
    for (ientry = 0; ientry < ancount; ientry++) {
      uint16_t len;
      uint16_t type;
      uint16_t class;
      uint16_t rdlength;
      char *name;
      name = new_name(dns_response, presp, &len);
      if (name == NULL) {
        ret = EAI_FAIL;
        break;
      }
      presp = skip_labels(presp);
      type = dns_response_get16(&presp[0]);
      class = dns_response_get16(&presp[2]);
      rdlength = dns_response_get16(&presp[8]);
      if ((type == 1) && (class == 1)) {
        struct addrinfo *ai_new;
        struct sockaddr_in *addr;
        ai_new = malloc(sizeof(struct addrinfo));
        ai_new->ai_flags = 0;
        ai_new->ai_family = AF_INET;
        ai_new->ai_socktype = SOCK_DGRAM;
        ai_new->ai_protocol = 0;
        addr = malloc(sizeof(struct sockaddr_in));
        addr->sin_family = AF_INET;
        addr->sin_port = 0;
        memcpy(&addr->sin_addr.s_addr, &presp[10], 4);
        ai_new->ai_addrlen = sizeof(struct sockaddr_in);
        ai_new->ai_addr = (struct sockaddr *)addr;
        ai_new->ai_canonname = name;
        ai_new->ai_next = NULL;
        if (ai_head == NULL) {
          ai_head = ai_new;
          ai_tail = ai_new;
        } else {
          ai_tail->ai_next = ai_new;
          ai_tail = ai_new;
        }
      } else {
        free(name);
      }
      presp += (10 + rdlength);
    }
    if (ientry != ancount) {
      ret = EAI_FAIL;
      freeaddrinfo(ai_head);
      break;
    }
    *res = ai_head;
    ret = 0;
    break;
  } while (1);
  return ret;
}


x86 assembly (clang, -O0):
<recv_dns_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x890,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x824(%rbp)
cmpl   $0x0,-0x824(%rbp)
jge    11e0 <recv_dns_response+0x50>
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1561 <recv_dns_response+0x3d1>
cmpl   $0xc,-0x824(%rbp)
jge    11f2 <recv_dns_response+0x62>
jmp    1552 <recv_dns_response+0x3c2>
lea    -0x820(%rbp),%rdi
call   1070 <dns_response_get16@plt>
cmp    -0x10(%rbp),%rax
je     120d <recv_dns_response+0x7d>
jmp    1552 <recv_dns_response+0x3c2>
mov    -0x814(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x828(%rbp)
cmpl   $0x3,-0x828(%rbp)
jne    123a <recv_dns_response+0xaa>
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1561 <recv_dns_response+0x3d1>
cmpl   $0x0,-0x828(%rbp)
je     1258 <recv_dns_response+0xc8>
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1561 <recv_dns_response+0x3d1>
jmp    125d <recv_dns_response+0xcd>
lea    -0x820(%rbp),%rdi
call   1050 <skip_questions@plt>
mov    %rax,-0x840(%rbp)
cmpq   $0x0,-0x840(%rbp)
jne    128f <recv_dns_response+0xff>
mov    0x2d3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1561 <recv_dns_response+0x3d1>
lea    -0x820(%rbp),%rdi
add    $0x18,%rdi
call   1070 <dns_response_get16@plt>
mov    %rax,-0x830(%rbp)
movq   $0x0,-0x848(%rbp)
movq   $0x0,-0x850(%rbp)
movq   $0x0,-0x838(%rbp)
mov    -0x838(%rbp),%rax
cmp    -0x830(%rbp),%rax
jge    1507 <recv_dns_response+0x377>
lea    -0x820(%rbp),%rdi
mov    -0x840(%rbp),%rsi
lea    -0x858(%rbp),%rdx
call   1080 <new_name@plt>
mov    %rax,-0x878(%rbp)
cmpq   $0x0,-0x878(%rbp)
jne    131b <recv_dns_response+0x18b>
mov    0x2caf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1507 <recv_dns_response+0x377>
mov    -0x840(%rbp),%rdi
call   1060 <skip_labels@plt>
mov    %rax,-0x840(%rbp)
mov    -0x840(%rbp),%rdi
call   1070 <dns_response_get16@plt>
mov    %rax,-0x860(%rbp)
mov    -0x840(%rbp),%rdi
add    $0x8,%rdi
call   1070 <dns_response_get16@plt>
mov    %rax,-0x868(%rbp)
mov    -0x840(%rbp),%rdi
add    $0x20,%rdi
call   1070 <dns_response_get16@plt>
mov    %rax,-0x870(%rbp)
cmpq   $0x1,-0x860(%rbp)
01
jne    14c7 <recv_dns_response+0x337>
cmpq   $0x1,-0x868(%rbp)
01
jne    14c7 <recv_dns_response+0x337>
mov    $0x40,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x880(%rbp)
mov    -0x880(%rbp),%rax
movq   $0x0,0x38(%rax)
mov    0x2c36(%rip),%rax
mov    (%rax),%rcx
mov    -0x880(%rbp),%rax
mov    %rcx,0x30(%rax)
mov    0x2c09(%rip),%rax
mov    (%rax),%ecx
mov    -0x880(%rbp),%rax
mov    %ecx,0x28(%rax)
mov    -0x880(%rbp),%rax
movq   $0x0,0x20(%rax)
mov    $0x18,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x888(%rbp)
mov    0x2bee(%rip),%rax
mov    (%rax),%rcx
mov    -0x888(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x888(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x888(%rbp),%rdi
mov    -0x840(%rbp),%rsi
add    $0x28,%rsi
mov    $0x4,%edx
call   1090 <memcpy@plt>
mov    -0x880(%rbp),%rax
movl   $0x18,(%rax)
mov    -0x888(%rbp),%rcx
mov    -0x880(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x878(%rbp),%rcx
mov    -0x880(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x880(%rbp),%rax
movq   $0x0,0x10(%rax)
cmpq   $0x0,-0x848(%rbp)
jne    14a2 <recv_dns_response+0x312>
mov    -0x880(%rbp),%rax
mov    %rax,-0x848(%rbp)
mov    -0x880(%rbp),%rax
mov    %rax,-0x850(%rbp)
jmp    14c2 <recv_dns_response+0x332>
mov    -0x880(%rbp),%rcx
mov    -0x850(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x880(%rbp),%rax
mov    %rax,-0x850(%rbp)
jmp    14d3 <recv_dns_response+0x343>
mov    -0x878(%rbp),%rdi
call   1030 <free@plt>
mov    -0x870(%rbp),%rax
add    $0xa,%rax
shl    $0x2,%rax
add    -0x840(%rbp),%rax
mov    %rax,-0x840(%rbp)
mov    -0x838(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x838(%rbp)
jmp    12c7 <recv_dns_response+0x137>
mov    -0x838(%rbp),%rax
cmp    -0x830(%rbp),%rax
je     1538 <recv_dns_response+0x3a8>
mov    0x2a9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x848(%rbp),%rdi
call   10b0 <freeaddrinfo@plt>
jmp    1561 <recv_dns_response+0x3d1>
mov    -0x848(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x1c(%rbp)
jmp    1561 <recv_dns_response+0x3d1>
mov    $0x1,%al
test   $0x1,%al
jne    11a6 <recv_dns_response+0x16>
jmp    1561 <recv_dns_response+0x3d1>
mov    -0x1c(%rbp),%eax
add    $0x890,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_dns_response>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x30(%rsp),%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %eax,%eax
js     1212 <recv_dns_response+0x82>
lea    0x30(%rsp),%rbp
jmp    11e5 <recv_dns_response+0x55>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %eax,%eax
js     1212 <recv_dns_response+0x82>
cmp    $0xc,%eax
jb     11d0 <recv_dns_response+0x40>
mov    %rbp,%rdi
call   1070 <dns_response_get16@plt>
cmp    %r14,%rax
jne    11d0 <recv_dns_response+0x40>
mov    0x3c(%rsp),%eax
and    $0xf,%eax
je     122f <recv_dns_response+0x9f>
cmp    $0x3,%eax
jne    13a0 <recv_dns_response+0x210>
mov    0x2dd0(%rip),%rax
jmp    1219 <recv_dns_response+0x89>
mov    0x2dbf(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x838,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x30(%rsp),%rdi
call   1050 <skip_questions@plt>
test   %rax,%rax
je     13a0 <recv_dns_response+0x210>
mov    %rax,%rbp
lea    0x48(%rsp),%rdi
call   1070 <dns_response_get16@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
mov    %r15,0x20(%rsp)
jle    13ac <recv_dns_response+0x21c>
xor    %r13d,%r13d
xor    %eax,%eax
mov    %rax,(%rsp)
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    129f <recv_dns_response+0x10f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
call   1030 <free@plt>
lea    (%r15,%rbp,4),%rbp
add    $0x28,%rbp
add    $0x1,%r13
cmp    %r13,0x18(%rsp)
je     13bc <recv_dns_response+0x22c>
lea    0x30(%rsp),%rdi
mov    %rbp,%rsi
lea    0x28(%rsp),%rdx
call   1080 <new_name@plt>
test   %rax,%rax
je     13b5 <recv_dns_response+0x225>
mov    %rax,%r12
mov    %rbp,%rdi
call   1060 <skip_labels@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <dns_response_get16@plt>
mov    %rax,%r14
lea    0x8(%r15),%rdi
call   1070 <dns_response_get16@plt>
mov    %rax,%rbx
lea    0x20(%r15),%rdi
call   1070 <dns_response_get16@plt>
mov    %rax,%rbp
cmp    $0x1,%r14
jne    1280 <recv_dns_response+0xf0>
cmp    $0x1,%rbx
jne    1280 <recv_dns_response+0xf0>
mov    %rbp,0x10(%rsp)
mov    $0x40,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
movq   $0x0,0x38(%rax)
mov    0x2cd0(%rip),%rax
mov    (%rax),%r14
mov    %r14,0x30(%rbx)
mov    0x2caa(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rbx)
movq   $0x0,0x20(%rbx)
mov    $0x18,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
mov    %r14,0x10(%rax)
movq   $0x0,0x8(%rax)
lea    0x28(%r15),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1090 <memcpy@plt>
movl   $0x18,(%rbx)
mov    %rbp,0x18(%rbx)
mov    %r12,0x8(%rbx)
movq   $0x0,0x10(%rbx)
cmpq   $0x0,(%rsp)
je     138a <recv_dns_response+0x1fa>
mov    0x8(%rsp),%rax
mov    %rbx,0x10(%rax)
mov    %rbx,0x8(%rsp)
jmp    1396 <recv_dns_response+0x206>
mov    %rbx,%rax
mov    %rbx,0x8(%rsp)
mov    %rbx,(%rsp)
mov    0x10(%rsp),%rbp
jmp    1288 <recv_dns_response+0xf8>
mov    0x2c19(%rip),%rax
jmp    1219 <recv_dns_response+0x89>
xor    %eax,%eax
mov    %rax,(%rsp)
xor    %r13d,%r13d
cmp    0x18(%rsp),%r13
jne    13cf <recv_dns_response+0x23f>
mov    0x20(%rsp),%rax
mov    (%rsp),%rcx
mov    %rcx,(%rax)
xor    %ebx,%ebx
jmp    121b <recv_dns_response+0x8b>
mov    0x2bea(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   10b0 <freeaddrinfo@plt>
jmp    121b <recv_dns_response+0x8b>

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

LLVM IR (-O2):
%struct.addrinfo = type { i32, i8*, %struct.addrinfo*, %struct.sockaddr*, i64, i32, i8*, i64 }
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i8* }
%struct.TYPE_2__ = type { i32 }
@EAI_SYSTEM = global i32 0
@EAI_NONAME = global i32 0
@EAI_FAIL = global i32 0
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
define i32 @recv_dns_response(i32 %0, i64 %1, %struct.addrinfo** nocapture writeonly %2) {
%4 = alloca [512 x i32]
%5 = alloca i64
%6 = bitcast [512 x i32]* %4 to i8*
%7 = getelementptr inbounds [512 x i32], [512 x i32]* %4, i64 0, i64 0
%8 = call i32 @recv(i32 %0, i32* %7, i32 2048, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %98, %3
%11 = load i32, i32* @EAI_SYSTEM
br label %101
12: ; preds = %3, %98
%13 = phi i32 [ %99, %98 ], [ %8, %3 ]
%14 = icmp ult i32 %13, 12
br i1 %14, label %98, label %15
15: ; preds = %12
%16 = call i64 @dns_response_get16(i32* %7)
%17 = icmp eq i64 %16, %1
br i1 %17, label %18, label %98
18: ; preds = %15
%19 = getelementptr inbounds [512 x i32], [512 x i32]* %4, i64 0, i64 3
%20 = load i32, i32* %19
%21 = and i32 %20, 15
switch i32 %21, label %24 [
i32 3, label %22
i32 0, label %26
]
22: ; preds = %18
%23 = load i32, i32* @EAI_NONAME
br label %101
24: ; preds = %18
%25 = load i32, i32* @EAI_FAIL
br label %101
26: ; preds = %18
%27 = call i32* @skip_questions(i32* %7)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = load i32, i32* @EAI_FAIL
br label %101
31: ; preds = %26
%32 = getelementptr inbounds [512 x i32], [512 x i32]* %4, i64 0, i64 6
%33 = call i64 @dns_response_get16(i32* %32)
%34 = icmp sgt i64 %33, 0
br i1 %34, label %35, label %89
35: ; preds = %31
%36 = bitcast i64* %5 to i8*
br label %37
37: ; preds = %35, %82
%38 = phi i64 [ 0, %35 ], [ %87, %82 ]
%39 = phi i32* [ %27, %35 ], [ %86, %82 ]
%40 = phi %struct.addrinfo* [ null, %35 ], [ %84, %82 ]
%41 = phi %struct.addrinfo* [ null, %35 ], [ %83, %82 ]
%42 = call i8* @new_name(i32* %7, i32* %39, i64* %5)
%43 = icmp eq i8* %42, null
br i1 %43, label %81, label %44
44: ; preds = %37
%45 = call i32* @skip_labels(i32* %39)
%46 = call i64 @dns_response_get16(i32* %45)
%47 = getelementptr inbounds i32, i32* %45, i64 2
%48 = call i64 @dns_response_get16(i32* %47)
%49 = getelementptr inbounds i32, i32* %45, i64 8
%50 = call i64 @dns_response_get16(i32* %49)
%51 = icmp eq i64 %46, 1
%52 = icmp eq i64 %48, 1
%53 = select i1 %51, i1 %52, i1 false
br i1 %53, label %54, label %79
54: ; preds = %44
%55 = call dereferenceable_or_null(64) i8* @malloc(i32 64)
%56 = bitcast i8* %55 to %struct.addrinfo*
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i64 0, i32 7
store i64 0, i64* %57
%58 = load i8*, i8** @AF_INET
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i64 0, i32 6
store i8* %58, i8** %59
%60 = load i32, i32* @SOCK_DGRAM
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i64 0, i32 5
store i32 %60, i32* %61
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i64 0, i32 4
store i64 0, i64* %62
%63 = call dereferenceable_or_null(24) i8* @malloc(i32 24)
%64 = bitcast i8* %63 to %struct.sockaddr_in*
%65 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %64, i64 0, i32 2
store i8* %58, i8** %65
%66 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %64, i64 0, i32 1
store i64 0, i64* %66
%67 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %64, i64 0, i32 0, i32 0
%68 = getelementptr inbounds i32, i32* %45, i64 10
%69 = call i32 @memcpy(i32* %67, i32* %68, i32 4)
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i64 0, i32 0
store i32 24, i32* %70
%71 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i64 0, i32 3
%72 = bitcast %struct.sockaddr** %71 to i8**
store i8* %63, i8** %72
%73 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i64 0, i32 1
store i8* %42, i8** %73
%74 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i64 0, i32 2
store %struct.addrinfo* null, %struct.addrinfo** %74
%75 = icmp eq %struct.addrinfo* %40, null
br i1 %75, label %82, label %76
76: ; preds = %54
%77 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i64 0, i32 2
%78 = bitcast %struct.addrinfo** %77 to i8**
store i8* %55, i8** %78
br label %82
79: ; preds = %44
%80 = call i32 @free(i8* %42)
br label %82
81: ; preds = %37
br label %89
82: ; preds = %79, %54, %76
%83 = phi %struct.addrinfo* [ %41, %79 ], [ %56, %54 ], [ %56, %76 ]
%84 = phi %struct.addrinfo* [ %40, %79 ], [ %56, %54 ], [ %40, %76 ]
%85 = add nsw i64 %50, 10
%86 = getelementptr inbounds i32, i32* %45, i64 %85
%87 = add nuw nsw i64 %38, 1
%88 = icmp eq i64 %87, %33
br i1 %88, label %96, label %37
89: ; preds = %31, %81
%90 = phi %struct.addrinfo* [ %40, %81 ], [ null, %31 ]
%91 = phi i64 [ %38, %81 ], [ 0, %31 ]
%92 = icmp eq i64 %91, %33
br i1 %92, label %96, label %93
93: ; preds = %89
%94 = load i32, i32* @EAI_FAIL
%95 = call i32 @freeaddrinfo(%struct.addrinfo* %90)
br label %101
96: ; preds = %82, %89
%97 = phi %struct.addrinfo* [ %90, %89 ], [ %84, %82 ]
store %struct.addrinfo* %97, %struct.addrinfo** %2
br label %101
98: ; preds = %15, %12
%99 = call i32 @recv(i32 %0, i32* %7, i32 2048, i32 0)
%100 = icmp slt i32 %99, 0
br i1 %100, label %10, label %12
101: ; preds = %10, %22, %24, %29, %93, %96
%102 = phi i32 [ 0, %96 ], [ %94, %93 ], [ %30, %29 ], [ %25, %24 ], [ %23, %22 ], [ %11, %10 ]
ret i32 %102
}