// File: /workspace/github_c_makefile_star2_O3/jech[P]dht/dht.c
// Function: dht_init
int
dht_init(int s, int s6, const unsigned char *id, const unsigned char *v)
{
    int rc;

    if(dht_socket >= 0 || dht_socket6 >= 0 || buckets || buckets6) {
        errno = EBUSY;
        return -1;
    }

    searches = NULL;
    numsearches = 0;

    storage = NULL;
    numstorage = 0;

    if(s >= 0) {
        buckets = calloc(1, sizeof(struct bucket));
        if(buckets == NULL)
            return -1;
        buckets->max_count = 128;
        buckets->af = AF_INET;
    }

    if(s6 >= 0) {
        buckets6 = calloc(1, sizeof(struct bucket));
        if(buckets6 == NULL)
            return -1;
        buckets6->max_count = 128;
        buckets6->af = AF_INET6;
    }

    memcpy(myid, id, 20);
    if(v) {
        memcpy(my_v, "1:v4:", 5);
        memcpy(my_v + 5, v, 4);
        have_v = 1;
    } else {
        have_v = 0;
    }

    dht_gettimeofday(&now, NULL);

    mybucket_grow_time = now.tv_sec;
    mybucket6_grow_time = now.tv_sec;
    confirm_nodes_time = now.tv_sec + random() % 3;

    search_id = random() & 0xFFFF;
    search_time = 0;

    next_blacklisted = 0;

    token_bucket_time = now.tv_sec;
    token_bucket_tokens = MAX_TOKEN_BUCKET_TOKENS;

    memset(secret, 0, sizeof(secret));
    rc = rotate_secrets();
    if(rc < 0)
        goto fail;

    dht_socket = s;
    dht_socket6 = s6;

    expire_buckets(buckets);
    expire_buckets(buckets6);

    return 1;

 fail:
    free(buckets);
    buckets = NULL;
    free(buckets6);
    buckets6 = NULL;
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
cmpl $0x0, 0x7e75(%rip)      # 0xc1c8
jns 0x450c
cmpl $0x0, 0x7e6c(%rip)      # 0xc1cc
jns 0x450c
cmpq $0x0, 0x98e2(%rip)      # 0xdc50
jne 0x450c
cmpq $0x0, 0x98dc(%rip)      # 0xdc58
jne 0x450c
movq %rcx, %r14
movq %rdx, %r15
movl %esi, %ebx
movl %edi, %ebp
xorl %eax, %eax
movq %rax, 0x9873(%rip)      # 0xdc08
movl %eax, 0x98cd(%rip)      # 0xdc68
movq %rax, 0x98be(%rip)      # 0xdc60
movl %eax, 0x98c4(%rip)      # 0xdc6c
testl %edi, %edi
js 0x43d8
movl $0x1, %edi
movl $0xc0, %esi
callq 0x21a0
movq %rax, 0x988e(%rip)      # 0xdc50
testq %rax, %rax
je 0x4517
movl $0x80, 0x1c(%rax)
movl $0x2, (%rax)
testl %ebx, %ebx
js 0x4408
movl $0x1, %edi
movl $0xc0, %esi
callq 0x21a0
movq %rax, 0x9866(%rip)      # 0xdc58
testq %rax, %rax
je 0x4517
movl $0x80, 0x1c(%rax)
movl $0xa, (%rax)
movl 0x10(%r15), %eax
movl %eax, 0x982e(%rip)      # 0xdc40
movups (%r15), %xmm0
movaps %xmm0, 0x9813(%rip)     # 0xdc30
testq %r14, %r14
je 0x443c
movb $0x3a, 0x984b(%rip)     # 0xdc74
movl $0x34763a31, 0x983d(%rip) # imm = 0x34763A31
movl (%r14), %eax
movl %eax, 0x9839(%rip)      # 0xdc75
testq %r14, %r14
setne 0x9836(%rip)            # 0xdc7c
leaq 0x97c3(%rip), %rdi      # 0xdc10
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x2130
movq 0x97b2(%rip), %r15      # 0xdc10
movq %r15, 0x981b(%rip)      # 0xdc80
movq %r15, 0x981c(%rip)      # 0xdc88
callq 0x2230
movq %rax, %rcx
movabsq $0x5555555555555556, %rdx # imm = 0x5555555555555556
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
addq %rdx, %rax
leaq (%rax,%rax,2), %rax
subq %rax, %rcx
addq %r15, %rcx
movq %rcx, 0x97f4(%rip)      # 0xdc90
callq 0x2230
movw %ax, 0x9778(%rip)       # 0xdc20
movq %r14, 0x9799(%rip)      # 0xdc48
movl $0x0, 0x97df(%rip)      # 0xdc98
movq 0x9750(%rip), %rax      # 0xdc10
movq %rax, 0x97d9(%rip)      # 0xdca0
movl $0x190, 0x97d7(%rip)    # imm = 0x190
movq %r14, 0x97d8(%rip)      # 0xdcb0
callq 0x4551
testl %eax, %eax
js 0x4527
movl %ebp, 0x7ce1(%rip)      # 0xc1c8
movl %ebx, 0x7cdf(%rip)      # 0xc1cc
movq 0x975c(%rip), %rdi      # 0xdc50
callq 0x45be
movq 0x9758(%rip), %rdi      # 0xdc58
callq 0x45be
movl $0x1, %eax
jmp 0x451c
callq 0x2060
movl $0x10, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x9722(%rip), %rdi      # 0xdc50
callq 0x2040
xorl %ebx, %ebx
movq %rbx, 0x9714(%rip)      # 0xdc50
movq 0x9715(%rip), %rdi      # 0xdc58
callq 0x2040
movq %rbx, 0x9709(%rip)      # 0xdc58
jmp 0x4517