// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movw %dx, %ax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movw %ax, -0x1a(%rbp)
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x2, %eax
jne 0x8860
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movl $0x4, -0x24(%rbp)
jmp 0x8897
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
cmpl $0xa, %eax
jne 0x8889
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movl $0x10, -0x24(%rbp)
jmp 0x8895
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8b05
jmp 0x8897
movq -0x10(%rbp), %rdi
callq 0x3a50
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x8932
cmpl $0x4000, 0x83b3(%rip)   # imm = 0x4000
jl 0x88c7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8b05
movl $0x1, %edi
movl $0x30, %esi
callq 0x21a0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x88ed
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8b05
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movl 0x10(%rcx), %ecx
movl %ecx, 0x10(%rax)
movq 0x8350(%rip), %rcx      # 0x10c60
movq -0x30(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x30(%rbp), %rax
movq %rax, 0x833d(%rip)      # 0x10c60
movl 0x8343(%rip), %eax      # 0x10c6c
addl $0x1, %eax
movl %eax, 0x833a(%rip)      # 0x10c6c
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x89b8
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movzwl 0x1a(%rax), %eax
movzwl -0x1a(%rbp), %ecx
cmpl %ecx, %eax
jne 0x89ab
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movzwl 0x18(%rax), %eax
cmpl -0x24(%rbp), %eax
jne 0x89ab
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdi
movslq -0x20(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
addq $0x8, %rdi
movq -0x38(%rbp), %rsi
movslq -0x24(%rbp), %rdx
callq 0x2190
cmpl $0x0, %eax
jne 0x89ab
jmp 0x89b8
jmp 0x89ad
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x8939
movl -0x20(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x89ed
movq 0x8245(%rip), %rcx      # 0x10c10
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x20(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x8b05
movl -0x20(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jl 0x8a9c
movq -0x30(%rbp), %rax
cmpl $0x800, 0x18(%rax)      # imm = 0x800
jl 0x8a16
movl $0x0, -0x4(%rbp)
jmp 0x8b05
movq -0x30(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x8a2a
movl $0x2, %eax
movl %eax, -0x60(%rbp)
jmp 0x8a36
movq -0x30(%rbp), %rax
movl 0x18(%rax), %eax
shll %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x5c(%rbp)
cmpl $0x800, -0x5c(%rbp)     # imm = 0x800
jg 0x8a4d
movl -0x5c(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x8a57
movl $0x800, %eax            # imm = 0x800
movl %eax, -0x64(%rbp)
jmp 0x8a57
movl -0x64(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdi
movslq -0x5c(%rbp), %rsi
shlq $0x5, %rsi
callq 0x2260
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x8a86
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8b05
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
movl -0x5c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x30(%rbp), %rdx
movl 0x14(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x14(%rdx)
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq 0x8148(%rip), %rcx      # 0x10c10
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movl -0x24(%rbp), %eax
movw %ax, %cx
movq -0x50(%rbp), %rax
movw %cx, 0x18(%rax)
movq -0x50(%rbp), %rdi
addq $0x8, %rdi
movq -0x38(%rbp), %rsi
movslq -0x24(%rbp), %rdx
callq 0x2200
movw -0x1a(%rbp), %cx
movq -0x50(%rbp), %rax
movw %cx, 0x1a(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nop