// File: /workspace/github_c_makefile_star2_O1/bloomsource[P]dns_update/dns.c
// Function: dns_resove_query
int dns_resove_query( char* data, int len, char* domain, int* query_type, int* query_class, int* query_len )
{
    char* pdata;
    unsigned char *blen;
    int namelen= 0;
    int seclen;
    int left;
    char *pname;
    unsigned short shortlen;
    
    domain[0] = 0;
    pdata = data;
    pname = domain;
    left = len;
    
    if( left < 3+ 4 )
    {
        write_log( "[WRN] query length not enough." );
        return 1;
    }
    
    while( 1 )
    {
        blen = (unsigned char*)pdata;
        seclen = *blen;
        if( seclen == 0 )
        {
            if( namelen == 0 )
            {
                write_log( "[WRN] domain length is 0" );
                return 1;
            }
            
            if( domain[namelen-1] == '.' )
            {
                domain[namelen-1] = 0;
                namelen--;
            }
            pdata++;
            left --;
            break;
        }
        
        namelen += ( seclen + 1 );
        if( namelen > 255 )
        {
            write_log( "[WRN] domain name over length." );
            return 1;
        }
        
        if( seclen + 1 > left )
        {
            write_log( "[WRN] domain name not enough length." );
            return 1;
        }
        
        if( check_domain_char( pdata+1, seclen ) )
        {
            write_log( "[WRN] invalid domain char." );
            return 1;
        }
        
        memcpy( pname, pdata+1, seclen );
        pname[ seclen ] = '.';
        pname += ( seclen + 1 );
        left -= ( seclen+1 );
        pdata += ( seclen + 1 );
    }
    
    if( namelen == 0 )
    {
        write_log( "[WRN] domain name length is zero." );
    }
    
    if( left < sizeof(short)* 2 )
    {
        write_log( "[WRN] query length is not enough." );
        return 1;
    }
    
    memcpy( &shortlen, pdata, 2 );
    shortlen = ntohs( shortlen );
    *query_type = shortlen;
    
    memcpy( &shortlen, pdata+2, 2 );
    shortlen = ntohs( shortlen );
    *query_class = shortlen;
    
    left -= 4;
    
    *query_len = len - left;
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movb $0x0, (%rdx)
cmpl $0x7, %esi
jge 0x2e99
leaq 0x6401(%rip), %rdi      # 0x927f
xorl %eax, %eax
callq 0x32e8
movl $0x1, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %r13
movq %rcx, 0x8(%rsp)
movq %r8, 0x10(%rsp)
movq %r9, 0x18(%rsp)
movb (%rdi), %al
testb %al, %al
movl %esi, (%rsp)
movq %rdx, 0x20(%rsp)
je 0x2f2f
xorl %edi, %edi
movq %rdx, %r12
movl %esi, %ebp
movq %r13, %rbx
movzbl %al, %r13d
leaq 0x1(%r13), %r15
addl %r15d, %edi
cmpl $0x100, %edi            # imm = 0x100
jae 0x2f5e
cmpl %r13d, %ebp
jle 0x2fce
movl %edi, 0x4(%rsp)
leaq 0x1(%rbx), %r14
movq %r14, %rdi
movl %r13d, %esi
callq 0x30da
testl %eax, %eax
jne 0x2fda
movl %r13d, %r13d
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x21e0
movb $0x2e, (%r12,%r13)
addq %r15, %r12
subl %r15d, %ebp
leaq (%rbx,%r15), %r13
movb (%rbx,%r15), %al
movq %r13, %rbx
testb %al, %al
movl 0x4(%rsp), %edi
jne 0x2ec3
jmp 0x2f33
xorl %edi, %edi
movl %esi, %ebp
testl %edi, %edi
je 0x2f52
movl %edi, %eax
movq 0x20(%rsp), %rcx
cmpb $0x2e, -0x1(%rcx,%rax)
jne 0x2f6a
movb $0x0, -0x1(%rcx,%rax)
cmpl $0x1, %edi
sete %al
jmp 0x2f6c
leaq 0x6345(%rip), %rdi      # 0x929e
jmp 0x2e7e
leaq 0x6352(%rip), %rdi      # 0x92b7
jmp 0x2e7e
xorl %eax, %eax
leal -0x1(%rbp), %ebx
testb %al, %al
je 0x2f81
leaq 0x639c(%rip), %rdi      # 0x9316
xorl %eax, %eax
callq 0x32e8
cmpl $0x3, %ebx
ja 0x2f92
leaq 0x63ab(%rip), %rdi      # 0x9338
jmp 0x2e7e
movzwl 0x1(%r13), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
movzwl 0x3(%r13), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
movl (%rsp), %ecx
subl %ebp, %ecx
addl $0x5, %ecx
movq 0x18(%rsp), %rax
movl %ecx, (%rax)
xorl %eax, %eax
jmp 0x2e8a
leaq 0x6301(%rip), %rdi      # 0x92d6
jmp 0x2e7e
leaq 0x631a(%rip), %rdi      # 0x92fb
jmp 0x2e7e