// File: /workspace/github_c_makefile_star2_O2/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 0x2e65
leaq 0x641f(%rip), %rdi      # 0x927f
jmp 0x2f52
movq %rdi, %r13
movq %rcx, 0x8(%rsp)
movq %r8, 0x10(%rsp)
movq %r9, 0x18(%rsp)
xorl %r8d, %r8d
movl %esi, (%rsp)
movl %esi, %r12d
movq %rdx, 0x20(%rsp)
movq %rdx, %rbx
movzbl (%r13), %r14d
testl %r14d, %r14d
je 0x2eed
leaq 0x1(%r14), %rbp
addl %ebp, %r8d
cmpl $0x100, %r8d            # imm = 0x100
jae 0x2f30
cmpl %r14d, %r12d
jle 0x2f39
movl %r8d, 0x4(%rsp)
leaq 0x1(%r13), %r15
movq %r15, %rdi
movl %r14d, %esi
callq 0x3088
testl %eax, %eax
jne 0x2f42
movl %r14d, %r14d
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x21e0
movb $0x2e, (%rbx,%r14)
addq %rbp, %rbx
subl %ebp, %r12d
addq %rbp, %r13
movl 0x4(%rsp), %r8d
jmp 0x2e88
testl %r8d, %r8d
je 0x2f4b
movl %r8d, %eax
movq 0x20(%rsp), %rcx
cmpb $0x2e, -0x1(%rcx,%rax)
jne 0x2f1a
movb $0x0, -0x1(%rcx,%rax)
cmpl $0x1, %r8d
jne 0x2f1a
leaq 0x6403(%rip), %rdi      # 0x9316
xorl %eax, %eax
callq 0x3281
leal -0x1(%r12), %eax
cmpl $0x3, %eax
movl (%rsp), %ecx
ja 0x2f6b
leaq 0x640a(%rip), %rdi      # 0x9338
jmp 0x2f52
leaq 0x6380(%rip), %rdi      # 0x92b7
jmp 0x2f52
leaq 0x6396(%rip), %rdi      # 0x92d6
jmp 0x2f52
leaq 0x63b2(%rip), %rdi      # 0x92fb
jmp 0x2f52
leaq 0x634c(%rip), %rdi      # 0x929e
xorl %eax, %eax
callq 0x3281
pushq $0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzwl 0x1(%r13), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movq 0x8(%rsp), %rdx
movl %eax, (%rdx)
movzwl 0x3(%r13), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movq 0x10(%rsp), %rdx
movl %eax, (%rdx)
subl %r12d, %ecx
addl $0x5, %ecx
movq 0x18(%rsp), %rax
movl %ecx, (%rax)
xorl %eax, %eax
jmp 0x2f5c