// File: /workspace/github_c_makefile_star2_O1/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 0xa2d0
movq %rax, 0x20(%rsp)
movq %rax, %rdi
callq 0x9c51
callq 0xa3e8
movq %rax, 0x30(%rsp)
testl %r13d, %r13d
movl %r13d, 0x14(%rsp)
je 0xaf7f
leaq 0x83d3(%rip), %rax      # 0x132a0
cmpl $0x0, (%rax)
jle 0xaf7f
xorl %r14d, %r14d
leaq 0x83d0(%rip), %r15      # 0x132b0
imulq $0x98, %r14, %rax
leaq (%r15,%rax), %rbx
cmpl $0x0, 0x68(%r15,%rax)
jle 0xaf2d
xorl %ebp, %ebp
cmpl $0x0, 0x8(%rbx)
movslq %ebp, %r12
je 0xaf18
imulq $0x70, %r12, %rdi
addq 0x60(%rbx), %rdi
movq 0x20(%rsp), %rsi
callq 0x999c
testl %eax, %eax
je 0xaf18
incl %ebp
jmp 0xaf28
imulq $0x70, %r12, %rsi
addq 0x60(%rbx), %rsi
movq %rbx, %rdi
callq 0xa96d
cmpl 0x68(%rbx), %ebp
jl 0xaef5
movq 0x20(%rsp), %rbp
cmpw $0x0, 0x8(%rbp)
jle 0xaf64
xorl %r12d, %r12d
xorl %r13d, %r13d
movq (%rbp), %rsi
addq %r12, %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0xa8a2
incq %r13
movswq 0x8(%rbp), %rax
addq $0x1c, %r12
cmpq %rax, %r13
jl 0xaf3f
incq %r14
leaq 0x8332(%rip), %rax      # 0x132a0
movslq (%rax), %rax
cmpq %rax, %r14
movl 0x14(%rsp), %r13d
jl 0xaee0
leaq 0x82ea(%rip), %rax      # 0x13270
movups (%rax), %xmm0
movaps %xmm0, 0x40(%rsp)
addq $0x78, 0x40(%rsp)
leaq 0x8305(%rip), %rax      # 0x132a0
cmpl $0x0, (%rax)
jle 0xb1c9
xorl %eax, %eax
testl %r13d, %r13d
sete %al
movl %eax, 0x2c(%rsp)
leaq 0x82f9(%rip), %rax      # 0x132b0
xorl %ecx, %ecx
movl $0x0, 0x10(%rsp)
movq %rcx, 0x58(%rsp)
imulq $0x98, %rcx, %r15
cmpl $0x0, 0x68(%rax,%r15)
jle 0xb1a5
addq %rax, %r15
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x60(%r15), %r14
leaq (%r14,%rbp), %rsi
movq %r15, %rdi
movq %rsi, 0x68(%rsp)
callq 0xa0d6
movq %rax, %r12
callq 0xa00d
movq %rax, 0x38(%rsp)
leaq (%r14,%rbp), %rsi
addq $0x40, %rsi
cmpq $0x0, (%rsi)
movq %rsi, 0x18(%rsp)
jle 0xb028
leaq 0x8254(%rip), %rdi      # 0x13270
callq 0xba38
testl %eax, %eax
setg %al
jmp 0xb02a
xorl %eax, %eax
testl %r13d, %r13d
movq %r12, 0x70(%rsp)
jne 0xb038
testb %al, %al
je 0xb06f
testl %r13d, %r13d
jne 0xb047
movq 0x18(%rsp), %rdi
callq 0xbc1e
movq 0x60(%r15), %rsi
addq %rbp, %rsi
movq %r15, %rdi
movl 0x2c(%rsp), %edx
movq 0x38(%rsp), %rcx
movq %r12, %r8
callq 0xaa0a
xorl %ecx, %ecx
orl %eax, 0x10(%rsp)
setne %cl
movl %ecx, 0x10(%rsp)
leaq (%r14,%rbp), %r12
addq $0x50, %r12
cmpq $0x0, (%r12)
jle 0xb132
leaq 0x81e7(%rip), %rdi      # 0x13270
movq %r12, %rsi
callq 0xba38
testl %eax, %eax
jle 0xb132
leaq 0x81b8(%rip), %r13      # 0x13258
cmpl $0x2, (%r13)
jge 0xb179
leaq (%r14,%rbp), %rdi
addq $0x1c, %rdi
movq %rdi, 0x60(%rsp)
callq 0x95d6
cmpl $0x2, (%r13)
jge 0xb183
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 0xb76c
testl %eax, %eax
js 0xb19e
movl $0x1, 0x3c(%r14,%rbp)
movl $0x1, 0x10(%rsp)
xorl %edi, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x781f
movq %r15, %rdi
movq 0x68(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0xad00
movl 0x14(%rsp), %r13d
movq %r12, %rdi
callq 0xbc1e
movq 0x18(%rsp), %rsi
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0xba62
movq %r14, %rdi
movq %r12, %rsi
callq 0xba62
movq 0x38(%rsp), %rdi
callq 0x97c3
movq 0x70(%rsp), %rdi
callq 0x97c3
incq %rbx
movslq 0x68(%r15), %rax
addq $0x70, %rbp
cmpq %rax, %rbx
jl 0xafe0
jmp 0xb1a5
callq 0x3053
jmp 0xb0ab
movq (%r15), %rdx
movl $0x2, %edi
leaq 0x2fed(%rip), %rsi      # 0xe17f
xorl %eax, %eax
callq 0x319e
jmp 0xb0c8
callq 0x306a
jmp 0xb125
movq 0x58(%rsp), %rcx
incq %rcx
leaq 0x80ec(%rip), %rax      # 0x132a0
movslq (%rax), %rax
cmpq %rax, %rcx
leaq 0x80ef(%rip), %rax      # 0x132b0
jl 0xafc1
jmp 0xb1d1
movl $0x0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
callq 0x97c3
movq 0x30(%rsp), %rdi
callq 0x97c3
leaq 0x803c(%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