// File: /workspace/github_c_makefile_star2_O0/bloomsource[P]dns_update/dns.c
// Function: dns_write_domain
int dns_write_domain( char* data, int size, char* domain, int* write_len )
{
    char* pdata;
    char* pdomain, *p;
    unsigned char *blen;
    int seclen;
    int left;
    
    left = size;
    if( strlen( domain ) > MAX_DOMAIN )
    {
        write_log( "[WRN] write domain failed, domain name too large." );
        return -1;
    }
    
    pdata = data;
    pdomain = domain;
    
    while( 1 )
    {
        if( pdomain[0] == 0 )
            break;
        
        p = strchr( pdomain, '.' );
        if( p )
        {
            seclen = p - pdomain;
            if( left <= seclen + 1 )
            {
                write_log( "[WRN] write domain failed, space not enough." );
                return 1;
            }
            
            blen = (unsigned char*)pdata;
            *blen = seclen;
            memcpy( pdata+1, pdomain, seclen );
            left -= ( seclen + 1 );
            pdata += ( seclen + 1 );
            pdomain = p+1;
        }
        else
        {
            seclen = strlen( pdomain );
            if( left < seclen + 2 )
            {
                write_log( "[WRN] write domain failed, space not enough." );
                return 1;
            }
            
            blen = (unsigned char*)pdata;
            *blen = seclen;
            memcpy( pdata+1, pdomain, seclen );
            blen = (unsigned char*)pdata + 1 + seclen;
            *blen = 0;
            left -= ( seclen + 2 );
            pdata += ( seclen + 2 );
            break;
        }
    }
    
    *write_len = size - left;
    
    return 0;
    
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x20(%rbp), %rdi
callq 0x20f0
cmpq $0xff, %rax
jbe 0x3668
leaq 0xbd54(%rip), %rdi      # 0xf3a9
movb $0x0, %al
callq 0x3b40
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x37e4
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x3689
jmp 0x37d1
movq -0x38(%rbp), %rdi
movl $0x2e, %esi
callq 0x2110
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x3736
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x4c(%rbp)
movl -0x50(%rbp), %eax
movl -0x4c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jg 0x36db
leaq 0xbd13(%rip), %rdi      # 0xf3db
movb $0x0, %al
callq 0x3b40
movl $0x1, -0x4(%rbp)
jmp 0x37e4
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x4c(%rbp), %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rdi
addq $0x1, %rdi
movq -0x38(%rbp), %rsi
movslq -0x4c(%rbp), %rdx
callq 0x21e0
movl -0x4c(%rbp), %ecx
addl $0x1, %ecx
movl -0x50(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %ecx
addl $0x1, %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x37cc
movq -0x38(%rbp), %rdi
callq 0x20f0
movl %eax, -0x4c(%rbp)
movl -0x50(%rbp), %eax
movl -0x4c(%rbp), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jge 0x3766
leaq 0xbc85(%rip), %rdi      # 0xf3db
movb $0x0, %al
callq 0x3b40
movl $0x1, -0x4(%rbp)
jmp 0x37e4
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x4c(%rbp), %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rdi
addq $0x1, %rdi
movq -0x38(%rbp), %rsi
movslq -0x4c(%rbp), %rdx
callq 0x21e0
movq -0x30(%rbp), %rax
addq $0x1, %rax
movslq -0x4c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movb $0x0, (%rax)
movl -0x4c(%rbp), %ecx
addl $0x2, %ecx
movl -0x50(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %ecx
addl $0x2, %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0x37d1
jmp 0x3678
movl -0x14(%rbp), %ecx
subl -0x50(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)