// File: davidgfnet[P]tadns/tadns.cc
// Function: DNSResolver::queue(unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Query*, dns_record_type, sockaddr*)
void DNSResolver::queue(unsigned niter, std::string name, Query *dep, enum dns_record_type qtype, struct sockaddr * dnss) {
    struct cache_entry * centry;
    struct dns_cb_data cbd;

    std::transform(name.begin(), name.end(), name.begin(), ::tolower);

    /* Search the cache first */
    if ((centry = find_cached_query(qtype, name)) != NULL) {
        assert(dep == NULL);
        return;
    }

    /* Check ongoing requests */
    // Dependants get merged and will be waken all together
    // if there is no callback to the user, safe to ignore it
    auto lookup = std::make_pair(name, qtype);
    auto existingq = ongoing.find(lookup);
    if (existingq != ongoing.end()) {
        if (dep) {
            existingq->second->deps.insert(dep);
            dep->deps_on = existingq->second;
        }
        return;
    }

    /* Allocate new query */
    Query * query = createQuery(niter, NULL, name, qtype, NULL);
    if (dep) {
        query->deps.insert(dep);
        dep->deps_on = query;
    }

    send_dns_packet(query, dnss);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdx, -0x190(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x198(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xb070
movq -0x190(%rbp), %rdi
callq 0x32f0
movq -0x190(%rbp), %rdi
movq %rax, -0x88(%rbp)
callq 0x31d0
movq -0x190(%rbp), %rdi
movq %rax, -0x90(%rbp)
callq 0x32f0
movq %rax, -0x98(%rbp)
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq 0x1d646(%rip), %rcx     # 0x25fd8
callq 0xadb0
movq %rax, -0x188(%rbp)
jmp 0x89a0
movq -0x190(%rbp), %rsi
movq -0x188(%rbp), %rax
movq %rax, -0xb0(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x19c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3160
jmp 0x89cc
movl -0x19c(%rbp), %esi
movq -0x198(%rbp), %rdi
leaq -0xd0(%rbp), %rdx
callq 0x62a0
movq %rax, -0x1a8(%rbp)
jmp 0x89ee
movq -0x1a8(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3200
movq -0x1a8(%rbp), %rax
cmpq $0x0, %rax
je 0x8a83
cmpq $0x0, -0x20(%rbp)
jne 0x8a1b
jmp 0x8a74
leaq 0x10795(%rip), %rdi     # 0x191b7
leaq 0x1067f(%rip), %rsi     # 0x190a8
movl $0x29a, %edx            # imm = 0x29A
leaq 0x1078e(%rip), %rcx     # 0x191c3
callq 0x3210
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x8d08
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3200
jmp 0x8d08
movl $0x1, -0xd4(%rbp)
jmp 0x8cea
movq -0x190(%rbp), %rsi
leaq -0x100(%rbp), %rdi
leaq -0x24(%rbp), %rdx
callq 0x99a0
jmp 0x8a9c
movq -0x198(%rbp), %rax
addq $0x70, %rax
movq %rax, -0x1b0(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x9a40
jmp 0x8ac3
movq -0x1b0(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0xb0a0
movq %rax, -0x1b8(%rbp)
jmp 0x8adf
movq -0x1b8(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x9ab0
movq -0x198(%rbp), %rdi
addq $0x70, %rdi
callq 0xb100
movq %rax, -0x138(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0xb0d0
testb $0x1, %al
jne 0x8b2c
jmp 0x8be0
cmpq $0x0, -0x20(%rbp)
je 0x8bd1
leaq -0x108(%rbp), %rdi
callq 0xb130
movq 0x28(%rax), %rdi
addq $0x40, %rdi
leaq -0x20(%rbp), %rsi
callq 0xb150
movb %dl, -0x1c1(%rbp)
movq %rax, -0x1c0(%rbp)
jmp 0x8b63
movb -0x1c1(%rbp), %al
movq -0x1c0(%rbp), %rcx
movq %rcx, -0x148(%rbp)
movb %al, -0x140(%rbp)
leaq -0x108(%rbp), %rdi
callq 0xb130
movq 0x28(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x70(%rax)
jmp 0x8bd1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x8cfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x9ab0
jmp 0x8cfc
movl $0x1, -0xd4(%rbp)
jmp 0x8cde
movq -0x190(%rbp), %rsi
movl -0xc(%rbp), %eax
movl %eax, -0x1c8(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x3160
jmp 0x8bfe
movl -0x1c8(%rbp), %esi
movq -0x198(%rbp), %rdi
movl -0x24(%rbp), %r8d
xorl %eax, %eax
movl %eax, %r9d
leaq -0x170(%rbp), %rcx
movq %r9, %rdx
callq 0x8d20
movq %rax, -0x1d0(%rbp)
jmp 0x8c2c
leaq -0x170(%rbp), %rdi
callq 0x3200
movq -0x1d0(%rbp), %rax
movq %rax, -0x150(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x8cbb
movq -0x150(%rbp), %rdi
addq $0x40, %rdi
leaq -0x20(%rbp), %rsi
callq 0xb150
movb %dl, -0x1d9(%rbp)
movq %rax, -0x1d8(%rbp)
jmp 0x8c70
movb -0x1d9(%rbp), %al
movq -0x1d8(%rbp), %rcx
movq %rcx, -0x180(%rbp)
movb %al, -0x178(%rbp)
movq -0x150(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x70(%rax)
jmp 0x8cbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x3200
jmp 0x8cfc
movq -0x198(%rbp), %rdi
movq -0x150(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x91f0
jmp 0x8cd4
movl $0x0, -0xd4(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x9b70
leaq -0x80(%rbp), %rdi
callq 0xb1a0
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
leaq -0x100(%rbp), %rdi
callq 0x9b70
leaq -0x80(%rbp), %rdi
callq 0xb1a0
movq -0xa0(%rbp), %rdi
callq 0x3530
nopl (%rax)