// File: /workspace/github_c_makefile_star2_O3/jech[P]shncpd/prefix.c
// Function: prefix_assignment
int
prefix_assignment(int changed)
{
    struct prefix_list *delegated =
        filter_included(all_delegated_prefixes());
    struct prefix_list *addresses = all_node_addresses();
    int i, j;
    int republish = 0;
    struct timespec again;

    if(changed) {
        for(i = 0; i < numinterfaces; i++) {
            /* Flush any delegated prefixes that have disappeared. */
            j = 0;
            while(j < interfaces[i].numassigned) {
                if(interfaces[i].ifindex == 0 ||
                   !prefix_list_member(&interfaces[i].assigned[j].delegated,
                                       delegated))
                    flush_assigned(&interfaces[i], &interfaces[i].assigned[j]);
                else
                    j++;
            }
            /* Add any delegated prefixes that have appeared. */
            for(j = 0; j < delegated->numprefixes; j++) {
                struct assigned_prefix *ap =
                    find_assigned(&interfaces[i],
                                  &delegated->prefixes[j], 1);
                if(ap == NULL)
                    continue;
            }
        }
    }

    again = now;
    again.tv_sec += 120;

    for(i = 0; i < numinterfaces; i++) {
        for(j = 0; j < interfaces[i].numassigned; j++) {
            struct assigned_prefix *ap = &interfaces[i].assigned[j];
            struct prefix_list *link_assigned =
                link_assigned_prefixes(&interfaces[i], &ap->delegated);
            struct prefix_list *all_assigned = all_assigned_prefixes();
            int bt =
                ap->backoff_timer.tv_sec > 0 &&
                ts_compare(&now, &ap->backoff_timer) > 0;
            int rc;
            if(changed || bt) {
                if(!changed)
                    ts_zero(&ap->backoff_timer);
                rc = prefix_assignment_1(&interfaces[i],
                                         &interfaces[i].assigned[j],
                                         !changed,
                                         all_assigned, link_assigned);
                republish = republish || rc;
            }

            if(ap->apply_timer.tv_sec > 0 &&
               ts_compare(&now, &ap->apply_timer) > 0) {
                debugf("Adding prefix ");
                debug_prefix(&ap->assigned);
                debugf(" to interface %s.\n", interfaces[i].ifname);
                rc = kernel_route(interfaces[i].ifindex, interfaces[i].ifname,
                                  &ap->assigned.p, ap->assigned.plen,
                                  NULL, 0, 1);
                if(rc >= 0) {
                    ap->applied = 1;
                    republish = 1;
                    schedule_ra(NULL, 1, 0);
                    rc = address_assignment_1(&interfaces[i], ap, addresses);
                    republish = republish || rc;
                } else {
                    fprintf(stderr, "Couldn't apply prefix.\n");
                }
                ts_zero(&ap->apply_timer);
            }

            ts_min(&again, &ap->backoff_timer);
            ts_min(&again, &ap->apply_timer);

            destroy_prefix_list(all_assigned);
            destroy_prefix_list(link_assigned);
        }
    }

    destroy_prefix_list(delegated);
    destroy_prefix_list(addresses);

    prefix_assignment_time = again;
    return republish;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edi, %r13d
callq 0x9d6a
movq %rax, %r12
movq %rax, %rdi
callq 0x9754
callq 0x9e60
movq %rax, 0x30(%rsp)
testl %r13d, %r13d
setne %cl
leaq 0x89c2(%rip), %rax      # 0x132a0
movl (%rax), %eax
testl %eax, %eax
setg %dl
andb %cl, %dl
cmpb $0x1, %dl
movq %r12, 0x20(%rsp)
movl %r13d, 0x14(%rsp)
jne 0xa9b1
xorl %r15d, %r15d
imulq $0x98, %r15, %rax
leaq 0x89a5(%rip), %rcx      # 0x132b0
leaq (%rcx,%rax), %rbx
movl 0x68(%rcx,%rax), %r13d
testl %r13d, %r13d
jle 0xa95c
xorl %ebp, %ebp
cmpl $0x0, 0x8(%rbx)
movq 0x60(%rbx), %r14
movslq %ebp, %r12
je 0xa941
imulq $0x70, %r12, %rdi
addq %r14, %rdi
movq 0x20(%rsp), %rsi
callq 0x94b7
testl %eax, %eax
je 0xa941
incl %ebp
jmp 0xa957
imulq $0x70, %r12, %rax
addq %rax, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa3dd
movl 0x68(%rbx), %r13d
cmpl %r13d, %ebp
jl 0xa91b
movq 0x20(%rsp), %r12
cmpw $0x0, 0x8(%r12)
jle 0xa996
xorl %r14d, %r14d
xorl %r13d, %r13d
movq (%r12), %rsi
addq %r14, %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0xa312
incq %r13
movswq 0x8(%r12), %rax
addq $0x1c, %r14
cmpq %rax, %r13
jl 0xa970
incq %r15
leaq 0x8900(%rip), %rax      # 0x132a0
movslq (%rax), %rax
cmpq %rax, %r15
jl 0xa8fd
movl 0x14(%rsp), %r13d
leaq 0x88b8(%rip), %rcx      # 0x13270
movups (%rcx), %xmm0
movaps %xmm0, 0x40(%rsp)
addq $0x78, 0x40(%rsp)
testl %eax, %eax
jle 0xabfa
xorl %ecx, %ecx
testl %r13d, %r13d
sete %cl
movl %ecx, 0x2c(%rsp)
leaq 0x88cf(%rip), %rdx      # 0x132b0
xorl %esi, %esi
movl $0x0, 0x10(%rsp)
imulq $0x98, %rsi, %r15
cmpl $0x0, 0x68(%rdx,%r15)
jle 0xabe9
movq %rsi, 0x58(%rsp)
addq %rdx, %r15
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x60(%r15), %r14
leaq (%r14,%rbp), %rsi
movq %r15, %rdi
movq %rsi, 0x68(%rsp)
callq 0x9bcd
movq %rax, %r12
callq 0x9b03
movq %rax, 0x38(%rsp)
leaq (%r14,%rbp), %rsi
addq $0x40, %rsi
cmpq $0x0, (%rsi)
movq %rsi, 0x18(%rsp)
jle 0xaa52
leaq 0x882a(%rip), %rdi      # 0x13270
callq 0xb464
testl %eax, %eax
setg %al
jmp 0xaa54
xorl %eax, %eax
testl %r13d, %r13d
movq %r12, 0x70(%rsp)
jne 0xaa62
testb %al, %al
je 0xaa99
testl %r13d, %r13d
jne 0xaa71
movq 0x18(%rsp), %rdi
callq 0xb650
movq 0x60(%r15), %rsi
addq %rbp, %rsi
movq %r15, %rdi
movl 0x2c(%rsp), %edx
movq 0x38(%rsp), %rcx
movq %r12, %r8
callq 0xa480
xorl %ecx, %ecx
orl %eax, 0x10(%rsp)
setne %cl
movl %ecx, 0x10(%rsp)
leaq (%r14,%rbp), %r12
addq $0x50, %r12
cmpq $0x0, (%r12)
jle 0xab5c
leaq 0x87bd(%rip), %rdi      # 0x13270
movq %r12, %rsi
callq 0xb464
testl %eax, %eax
jle 0xab5c
leaq 0x878e(%rip), %r13      # 0x13258
cmpl $0x2, (%r13)
jge 0xaba3
leaq (%r14,%rbp), %rdi
addq $0x1c, %rdi
movq %rdi, 0x60(%rsp)
callq 0x90d1
cmpl $0x2, (%r13)
jge 0xabad
movl 0x8(%r15), %edi
movq (%r15), %rsi
movzbl 0x2c(%r14,%rbp), %ecx
movl $0x1, (%rsp)
movq 0x60(%rsp), %rdx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xb198
testl %eax, %eax
js 0xabc8
movl $0x1, 0x3c(%r14,%rbp)
movl $0x1, 0x10(%rsp)
xorl %edi, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x74b8
movq %r15, %rdi
movq 0x68(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0xa70a
movl 0x14(%rsp), %r13d
movq %r12, %rdi
callq 0xb650
movq 0x18(%rsp), %rsi
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0xb48e
movq %r14, %rdi
movq %r12, %rsi
callq 0xb48e
movq 0x38(%rsp), %rdi
callq 0x92d1
movq 0x70(%rsp), %rdi
callq 0x92d1
incq %rbx
movslq 0x68(%r15), %rax
addq $0x70, %rbp
cmpq %rax, %rbx
jl 0xaa0a
jmp 0xabcf
callq 0x2f5d
jmp 0xaad5
movq (%r15), %rdx
movl $0x2, %edi
leaq 0x358b(%rip), %rsi      # 0xe147
xorl %eax, %eax
callq 0x30a8
jmp 0xaaf2
callq 0x2f74
jmp 0xab4f
leaq 0x86ca(%rip), %rax      # 0x132a0
movl (%rax), %eax
movq 0x20(%rsp), %r12
leaq 0x86cc(%rip), %rdx      # 0x132b0
movq 0x58(%rsp), %rsi
incq %rsi
movslq %eax, %rcx
cmpq %rcx, %rsi
jl 0xa9eb
jmp 0xac02
movl $0x0, 0x10(%rsp)
movq %r12, %rdi
callq 0x92d1
movq 0x30(%rsp), %rdi
callq 0x92d1
leaq 0x860d(%rip), %rax      # 0x13228
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rax)
movl 0x10(%rsp), %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq