// File: /workspace/github_c_makefile_star2_O1/jech[P]dht/dht.c
// Function: storage_store
static int
storage_store(const unsigned char *id,
              const struct sockaddr *sa, unsigned short port)
{
    int i, len;
    struct storage *st;
    unsigned char *ip;

    if(sa->sa_family == AF_INET) {
        struct sockaddr_in *sin = (struct sockaddr_in*)sa;
        ip = (unsigned char*)&sin->sin_addr;
        len = 4;
    } else if(sa->sa_family == AF_INET6) {
        struct sockaddr_in6 *sin6 = (struct sockaddr_in6*)sa;
        ip = (unsigned char*)&sin6->sin6_addr;
        len = 16;
    } else {
        return -1;
    }

    st = find_storage(id);

    if(st == NULL) {
        if(numstorage >= DHT_MAX_HASHES)
            return -1;
        st = calloc(1, sizeof(struct storage));
        if(st == NULL) return -1;
        memcpy(st->id, id, 20);
        st->next = storage;
        storage = st;
        numstorage++;
    }

    for(i = 0; i < st->numpeers; i++) {
        if(st->peers[i].port == port && st->peers[i].len == len &&
           memcmp(st->peers[i].ip, ip, len) == 0)
            break;
    }

    if(i < st->numpeers) {
        /* Already there, only need to refresh */
        st->peers[i].time = now.tv_sec;
        return 0;
    } else {
        struct peer *p;
        if(i >= st->maxpeers) {
            /* Need to expand the array. */
            struct peer *new_peers;
            int n;
            if(st->maxpeers >= DHT_MAX_PEERS)
                return 0;
            n = st->maxpeers == 0 ? 2 : 2 * st->maxpeers;
            n = MIN(n, DHT_MAX_PEERS);
            new_peers = realloc(st->peers, n * sizeof(struct peer));
            if(new_peers == NULL)
                return -1;
            st->peers = new_peers;
            st->maxpeers = n;
        }
        p = &st->peers[st->numpeers++];
        p->time = now.tv_sec;
        p->len = len;
        memcpy(p->ip, ip, len);
        p->port = port;
        return 1;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %ebx
movq %rdi, %r12
movq %rsi, 0x18(%rsp)
movzwl (%rsi), %eax
cmpl $0x2, %eax
je 0x7457
cmpl $0xa, %eax
jne 0x75e5
movl $0x10, 0xc(%rsp)
movl $0x8, %r13d
jmp 0x7465
movl $0x4, 0xc(%rsp)
movl $0x4, %r13d
movq %r12, %rdi
callq 0x362b
movq %rax, %r14
testq %rax, %rax
je 0x74fa
addq %r13, 0x18(%rsp)
movl 0x14(%r14), %r12d
movl 0xc(%rsp), %eax
movq %rax, 0x20(%rsp)
testl %r12d, %r12d
setg %r15b
jle 0x7558
movq %r14, 0x10(%rsp)
movq 0x20(%r14), %rbp
movl $0x1a, %r14d
xorl %r13d, %r13d
cmpw %bx, (%rbp,%r14)
jne 0x74dd
movzwl -0x2(%rbp,%r14), %eax
cmpl %eax, 0xc(%rsp)
jne 0x74dd
leaq (%r14,%rbp), %rdi
addq $-0x12, %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
callq 0x2260
testl %eax, %eax
je 0x75f4
incq %r13
cmpq %r12, %r13
setb %r15b
addq $0x20, %r14
cmpq %r13, %r12
jne 0x74aa
movl %r12d, %r13d
movq 0x10(%rsp), %r14
jmp 0x755b
movl 0x676c(%rip), %ebp      # 0xdc6c
cmpl $0x3fff, %ebp           # imm = 0x3FFF
jg 0x75e5
movl $0x1, %edi
movl $0x30, %esi
callq 0x21a0
testq %rax, %rax
je 0x75e5
movq %rax, %r14
movl 0x10(%r12), %eax
movl %eax, 0x10(%r14)
movups (%r12), %xmm0
movups %xmm0, (%r14)
movq 0x6720(%rip), %rax      # 0xdc60
movq %rax, 0x28(%r14)
movq %r14, 0x6715(%rip)      # 0xdc60
incl %ebp
movl %ebp, 0x6719(%rip)      # 0xdc6c
jmp 0x7479
xorl %r13d, %r13d
movl 0x18(%r14), %eax
cmpl %eax, %r13d
jl 0x759f
cmpl $0x7ff, %eax            # imm = 0x7FF
jg 0x75e5
leal (%rax,%rax), %ecx
movl $0x800, %edx            # imm = 0x800
cmpl %edx, %ecx
cmovll %ecx, %edx
testl %eax, %eax
movl $0x2, %ebp
cmovnel %edx, %ebp
movq 0x20(%r14), %rdi
movslq %ebp, %rsi
shlq $0x5, %rsi
callq 0x2270
testq %rax, %rax
je 0x75e5
movq %rax, 0x20(%r14)
movl %ebp, 0x18(%r14)
movq 0x20(%r14), %rax
movslq 0x14(%r14), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x14(%r14)
shlq $0x5, %rcx
movq 0x6657(%rip), %rdx      # 0xdc10
leaq (%rax,%rcx), %r15
addq $0x8, %r15
movq %rdx, -0x8(%r15)
movl 0xc(%rsp), %eax
movw %ax, 0x10(%r15)
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
callq 0x2200
movw %bx, 0x12(%r15)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x1, %r15b
je 0x74f3
movq 0x660b(%rip), %rax      # 0xdc10
movq 0x10(%rsp), %rcx
movq 0x20(%rcx), %rcx
movq %rax, -0x1a(%rcx,%r14)
jmp 0x75e5