// File: /workspace/github_c_makefile_star2_O2/jech[P]shncpd/prefix.c
// Function: prefix_assignment_1
int
prefix_assignment_1(struct interface *interface,
                    struct assigned_prefix *ap,
                    int backoff_triggered,
                    const struct prefix_list *all_assigned,
                    const struct prefix_list *link_assigned)
{
    struct prefix best;
    int have_best, have_assigned, rc;
    int republish = 0;

 again:

    have_assigned = ap->assigned.plen > 0;
    have_best =
        best_prefix(&ap->delegated, interface->ifindex,
                    have_assigned && ap->published ? &ap->assigned : NULL,
                    link_assigned, &best);

    if(backoff_triggered && have_assigned) {
        if(!ap->published) {
            ap->published = 1;
            republish = 1;
        }
        if(!ap->applied)
            ts_add_msec(&ap->apply_timer, &now, 2 * FLOODING_DELAY);
    } else if(!have_best && !have_assigned) {
        if(ap->backoff_timer.tv_sec == 0) {
            if(!backoff_triggered) {
                ts_add_random(&ap->backoff_timer, &now, BACKOFF_MAX_DELAY);
            } else {
                rc = random_prefix(&ap->assigned,
                                   select_plen(&ap->delegated,
                                               interface->type),
                                   0, 1,
                                   &ap->delegated, all_assigned);
                if(rc > 0) {
                    ap->assigned.prio = 2;
                    memcpy(ap->assigned.id, myid, 4);
                    ap->assigned.eid = interface->ifindex;
                    ts_add_msec(&ap->apply_timer, &now, 2 * FLOODING_DELAY);
                    rc = publish_prefix(interface, ap, 1);
                    if(rc < 0) {
                        fprintf(stderr, "Couldn't publish prefix.\n");
                        memset(&ap->assigned, 0, sizeof(ap->assigned));
                    }
                    republish = 1;
                } else {
                    fprintf(stderr, "Couldn't draw random prefix.\n");
                }
                ap->applied = 0;
            }
        }
    } else if(have_best && !have_assigned) {
        ts_zero(&ap->backoff_timer);
        ap->assigned = best;
        publish_prefix(interface, ap, 0);
        ts_add_msec(&ap->apply_timer, &now, 2 * FLOODING_DELAY);
    } else if(!have_best && have_assigned) {
        if(!prefix_valid(&ap->assigned, all_assigned, link_assigned)) {
            destroy_assigned(interface, ap);
            backoff_triggered = 0;
            goto again;
        }

        if(!ap->published) {
            /* Adopt. */
            ts_zero(&ap->apply_timer);
            ap->assigned.prio = 2;
            backoff_triggered = 1;
            goto again;
        }
    } else {
        ts_zero(&ap->backoff_timer);
        if(prefix_eq(&best, &ap->assigned)) {
            publish_prefix(interface, ap, 0);
            if(!ap->applied && ap->apply_timer.tv_sec == 0) {
                ts_add_msec(&ap->apply_timer, &now, 2 * FLOODING_DELAY);
            }
        } else {
            destroy_assigned(interface, ap);
            goto again;
        }
    }

    return republish;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %r12
movq %rcx, 0x20(%rsp)
movq %rsi, %rbx
movq %rdi, 0x10(%rsp)
leaq 0x1c(%rsi), %r13
leaq 0x40(%rsi), %rax
movq %rax, 0x18(%rsp)
leaq 0x50(%rsi), %rax
movq %rax, 0x8(%rsp)
testl %edx, %edx
setne %r15b
movb %r15b, 0x7(%rsp)
notb %r15b
movb 0x2c(%rbx), %bpl
testb %bpl, %bpl
je 0x97ba
cmpl $0x0, 0x38(%rbx)
movq %r13, %rdx
movl $0x0, %eax
cmoveq %rax, %rdx
jmp 0x97bc
xorl %edx, %edx
testb %bpl, %bpl
sete %r14b
movq %rbx, %rdi
movq %r12, %rcx
leaq 0x2c(%rsp), %r8
callq 0x91f7
orb %r15b, %r14b
testb $0x1, %r14b
je 0x987d
testb %bpl, %bpl
jne 0x97ed
testl %eax, %eax
je 0x98ac
testb %bpl, %bpl
jne 0x97fa
testl %eax, %eax
jne 0x990e
testb %bpl, %bpl
je 0x9803
testl %eax, %eax
je 0x9834
movq 0x18(%rsp), %rdi
callq 0xa866
leaq 0x2c(%rsp), %rdi
movq %r13, %rsi
callq 0x87b6
testl %eax, %eax
jne 0x994e
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x94f8
jmp 0x979f
movq %r13, %rdi
movq 0x20(%rsp), %rsi
movq %r12, %rdx
callq 0x8b58
testl %eax, %eax
setne %r15b
je 0x986b
cmpl $0x0, 0x38(%rbx)
jne 0x9946
movq 0x8(%rsp), %rdi
callq 0xa866
movw $0x2, 0x2e(%rbx)
jmp 0x9797
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x94f8
jmp 0x9797
xorl %r14d, %r14d
cmpl $0x0, 0x38(%rbx)
jne 0x9891
movl $0x1, 0x38(%rbx)
pushq $0x1
popq %r14
cmpl $0x0, 0x3c(%rbx)
jne 0x9a08
leaq 0x79ce(%rip), %rsi      # 0x11270
movq 0x8(%rsp), %rdi
jmp 0x9975
xorl %r14d, %r14d
movq 0x18(%rsp), %rdi
cmpq $0x0, (%rdi)
jne 0x9a08
testb $0x1, 0x7(%rsp)
je 0x9984
movl $0x80, %esi
movq 0x10(%rsp), %rax
cmpl $0x3, 0xc(%rax)
je 0x99a6
movq %rbx, %rdi
callq 0x8d1b
movb 0x10(%rbx), %cl
testl %eax, %eax
je 0x9997
movzbl %cl, %eax
cmpb $0x75, %al
pushq $0x74
popq %rcx
cmovael %eax, %ecx
cmpb $0x7a, %cl
pushq $0x7a
popq %rax
cmovbl %ecx, %eax
addb $0x4, %al
movzbl %al, %esi
jmp 0x99a6
movq 0x18(%rsp), %rdi
callq 0xa866
movups 0x2c(%rsp), %xmm0
movups 0x38(%rsp), %xmm1
movups %xmm1, 0xc(%r13)
movups %xmm0, (%r13)
andl $0x0, 0x38(%rbx)
leaq 0x7939(%rip), %rsi      # 0x11270
movq 0x8(%rsp), %rdi
movl $0x2710, %edx           # imm = 0x2710
callq 0xa7e7
xorl %r14d, %r14d
jmp 0x9a08
andl $0x0, 0x38(%rbx)
xorl %r14d, %r14d
cmpl $0x0, 0x3c(%rbx)
jne 0x9a08
movq 0x8(%rsp), %rdi
cmpq $0x0, (%rdi)
jne 0x9a08
leaq 0x78fb(%rip), %rsi      # 0x11270
movl $0x2710, %edx           # imm = 0x2710
callq 0xa7e7
jmp 0x9a08
leaq 0x78e5(%rip), %rsi      # 0x11270
movl $0xfa0, %edx            # imm = 0xFA0
callq 0xa826
jmp 0x9a08
xorl %esi, %esi
cmpb $0x3f, %cl
setae %sil
shll $0x4, %esi
orl $0x40, %esi
pushq $0x1
popq %r14
movq %r13, %rdi
xorl %edx, %edx
movl %r14d, %ecx
movq %rbx, %r8
movq 0x20(%rsp), %r9
callq 0x8c5b
testl %eax, %eax
je 0x9a1a
movw $0x2, 0x2e(%rbx)
leaq 0x78b0(%rip), %r15      # 0x11280
movl (%r15), %eax
movl %eax, 0x30(%rbx)
movq 0x10(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x34(%rbx)
leaq 0x7888(%rip), %rsi      # 0x11270
movq 0x8(%rsp), %rdi
movl $0x2710, %edx           # imm = 0x2710
callq 0xa7e7
movl (%r15), %eax
movl %eax, 0x30(%rbx)
movl $0x1, 0x38(%rbx)
andl $0x0, 0x3c(%rbx)
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x75d7(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x36ab(%rip), %rdi      # 0xd0d6
pushq $0x1d
popq %rsi
pushq $0x1
popq %rdx
callq 0x2340
xorl %r14d, %r14d
jmp 0x9a04