// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x54(%rbp)
cmpl $0x7, -0x54(%rbp)
jge 0x3413
leaq 0xbece(%rip), %rdi      # 0xf2ce
movb $0x0, %al
callq 0x3b40
movl $0x1, -0x4(%rbp)
jmp 0x360c
jmp 0x3415
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jne 0x3497
cmpl $0x0, -0x4c(%rbp)
jne 0x344d
leaq 0xbeb3(%rip), %rdi      # 0xf2ed
movb $0x0, %al
callq 0x3b40
movl $0x1, -0x4(%rbp)
jmp 0x360c
movq -0x20(%rbp), %rax
movl -0x4c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2e, %eax
jne 0x347d
movq -0x20(%rbp), %rax
movl -0x4c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x3576
movl -0x50(%rbp), %eax
addl $0x1, %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
cmpl $0xff, -0x4c(%rbp)
jle 0x34c6
leaq 0xbe53(%rip), %rdi      # 0xf306
movb $0x0, %al
callq 0x3b40
movl $0x1, -0x4(%rbp)
jmp 0x360c
movl -0x50(%rbp), %eax
addl $0x1, %eax
cmpl -0x54(%rbp), %eax
jle 0x34eb
leaq 0xbe4d(%rip), %rdi      # 0xf325
movb $0x0, %al
callq 0x3b40
movl $0x1, -0x4(%rbp)
jmp 0x360c
movq -0x40(%rbp), %rdi
addq $0x1, %rdi
movl -0x50(%rbp), %esi
callq 0x37f0
cmpl $0x0, %eax
je 0x351a
leaq 0xbe43(%rip), %rdi      # 0xf34a
movb $0x0, %al
callq 0x3b40
movl $0x1, -0x4(%rbp)
jmp 0x360c
movq -0x60(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x1, %rsi
movslq -0x50(%rbp), %rdx
callq 0x21e0
movq -0x60(%rbp), %rax
movslq -0x50(%rbp), %rcx
movb $0x2e, (%rax,%rcx)
movl -0x50(%rbp), %ecx
addl $0x1, %ecx
movq -0x60(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movl -0x50(%rbp), %ecx
addl $0x1, %ecx
movl -0x54(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %ecx
addl $0x1, %ecx
movq -0x40(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
jmp 0x3415
cmpl $0x0, -0x4c(%rbp)
jne 0x358a
leaq 0xbde2(%rip), %rdi      # 0xf365
movb $0x0, %al
callq 0x3b40
movslq -0x54(%rbp), %rax
cmpq $0x4, %rax
jae 0x35ab
leaq 0xbdec(%rip), %rdi      # 0xf387
movb $0x0, %al
callq 0x3b40
movl $0x1, -0x4(%rbp)
jmp 0x360c
movq -0x40(%rbp), %rax
movw (%rax), %ax
movw %ax, -0x62(%rbp)
movzwl -0x62(%rbp), %edi
callq 0x2250
movw %ax, -0x62(%rbp)
movzwl -0x62(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
movw 0x2(%rax), %ax
movw %ax, -0x62(%rbp)
movzwl -0x62(%rbp), %edi
callq 0x2250
movw %ax, -0x62(%rbp)
movzwl -0x62(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movl -0x54(%rbp), %eax
subl $0x4, %eax
movl %eax, -0x54(%rbp)
movl -0x14(%rbp), %ecx
subl -0x54(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)