// File: /workspace/github_c_makefile_star2_O0/niuyuling[P]CProxy/httpdns.c
// Function: cache_record
static void cache_record(char *request, uint16_t request_len, char *response, uint16_t response_len)
{
    struct dns_cache *cache_temp;

    cache_temp = (struct dns_cache *)malloc(sizeof(struct dns_cache));
    if (cache_temp == NULL)
        return;
    cache_temp->dns_cache = (char *)malloc(request_len + response_len + 2);
    if (cache_temp->dns_cache == NULL) {
        free(cache_temp);
        return;
    }
    cache_temp->next = cache;
    cache = cache_temp;
    //不缓存dnsid
    request += 2;
    request_len -= 2;
    memcpy(cache_temp->dns_cache, &request_len, 2);
    memcpy(cache_temp->dns_cache + 2, request, request_len);
    memcpy(cache_temp->dns_cache + request_len + 2, &response_len, 2);
    memcpy(cache_temp->dns_cache + request_len + 4, response, response_len);
    if (httpdns.cacheLimit) {
        //到达缓存记录条目限制则释放前一半缓存
        if (cache_using >= httpdns.cacheLimit) {
            struct dns_cache *free_c;
            int i;
            for (i = cache_using = httpdns.cacheLimit >> 1; i--; cache_temp = cache_temp->next) ;
            for (free_c = cache_temp->next, cache_temp->next = NULL; free_c; free_c = cache_temp) {
                cache_temp = free_c->next;
                free(free_c->dns_cache);
                free(free_c);
            }
        }
        cache_using++;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movw %cx, %ax
movw %si, %cx
movq %rdi, -0x8(%rbp)
movw %cx, -0xa(%rbp)
movq %rdx, -0x18(%rbp)
movw %ax, -0x1a(%rbp)
movl $0x10, %edi
callq 0x2350
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x8888
jmp 0x89f9
movzwl -0xa(%rbp), %eax
movzwl -0x1a(%rbp), %ecx
addl %ecx, %eax
addl $0x2, %eax
movslq %eax, %rdi
callq 0x2350
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x88bf
movq -0x28(%rbp), %rdi
callq 0x2030
jmp 0x89f9
movq 0x13e72(%rip), %rcx     # 0x1c738
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq %rax, 0x13e5f(%rip)     # 0x1c738
movq -0x8(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x8(%rbp)
movzwl -0xa(%rbp), %eax
subl $0x2, %eax
movw %ax, -0xa(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movw -0xa(%rbp), %cx
movw %cx, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
addq $0x2, %rdi
movq -0x8(%rbp), %rsi
movzwl -0xa(%rbp), %eax
movl %eax, %edx
callq 0x2300
movq -0x28(%rbp), %rax
movq (%rax), %rax
movzwl -0xa(%rbp), %ecx
movslq %ecx, %rcx
movw -0x1a(%rbp), %dx
movw %dx, 0x2(%rax,%rcx)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movzwl -0xa(%rbp), %eax
cltq
addq %rax, %rdi
addq $0x4, %rdi
movq -0x18(%rbp), %rsi
movzwl -0x1a(%rbp), %eax
movl %eax, %edx
callq 0x2300
cmpl $0x0, 0x13dc7(%rip)     # 0x1c720
je 0x89f9
movl 0x13d67(%rip), %eax     # 0x1c6cc
cmpl 0x13db5(%rip), %eax     # 0x1c720
jl 0x89ea
movl 0x13dad(%rip), %eax     # 0x1c720
sarl %eax
movl %eax, 0x13d51(%rip)     # 0x1c6cc
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x34(%rbp)
cmpl $0x0, %eax
je 0x899e
jmp 0x8990
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x897e
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq $0x0, 0x8(%rax)
cmpq $0x0, -0x30(%rbp)
je 0x89e8
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x2030
movq -0x30(%rbp), %rdi
callq 0x2030
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x89b6
jmp 0x89ea
movl 0x13cdc(%rip), %eax     # 0x1c6cc
addl $0x1, %eax
movl %eax, 0x13cd3(%rip)     # 0x1c6cc
addq $0x40, %rsp
popq %rbp
retq
nop