// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movq %r8, %r14
movq %rcx, 0x10(%rsp)
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x1c(%rsi), %r13
leaq 0x40(%rsi), %r12
leaq 0x50(%rsi), %rax
movq %rax, 0x8(%rsp)
testl %edx, %edx
sete %bpl
cmpb $0x0, 0x2c(%rsi)
je 0xa55f
cmpl $0x0, 0x38(%rbx)
je 0xa4c8
movq %r13, %rdx
jmp 0xa4ca
xorl %edx, %edx
movq %rbx, %rdi
movq %r14, %rcx
leaq 0x1c(%rsp), %r8
callq 0x9f3b
testb $0x1, %bpl
je 0xa5b4
testl %eax, %eax
je 0xa52b
movq %r12, %rdi
callq 0xb650
movb 0x2c(%rsp), %al
cmpb 0x2c(%rbx), %al
jne 0xa518
movdqu 0x1c(%rsp), %xmm0
movdqu (%r13), %xmm1
pcmpeqb %xmm0, %xmm1
pmovmskb %xmm1, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0xa61e
movq %r15, %rdi
movq %rbx, %rsi
callq 0xa21f
cmpb $0x0, 0x2c(%rbx)
jne 0xa4bd
jmp 0xa55f
movq %r13, %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x9806
testl %eax, %eax
sete %bpl
je 0xa518
cmpl $0x0, 0x38(%rbx)
jne 0xa609
movq 0x8(%rsp), %rdi
callq 0xb650
movw $0x2, 0x2e(%rbx)
jmp 0xa523
leaq 0x1c(%rsp), %r8
movq %rbx, %rdi
xorl %edx, %edx
movq %r14, %rcx
callq 0x9f3b
testl %eax, %eax
je 0xa5e8
movq %r12, %rdi
callq 0xb650
movdqu 0x1c(%rsp), %xmm0
movdqu 0x28(%rsp), %xmm1
movdqu %xmm1, 0xc(%r13)
movdqu %xmm0, (%r13)
movl $0x0, 0x38(%rbx)
leaq 0x8ccd(%rip), %rsi      # 0x13270
movq 0x8(%rsp), %rdi
movl $0x2710, %edx           # imm = 0x2710
callq 0xb514
jmp 0xa609
xorl %r12d, %r12d
cmpl $0x0, 0x38(%rbx)
jne 0xa5ca
movl $0x1, 0x38(%rbx)
movl $0x1, %r12d
cmpl $0x0, 0x3c(%rbx)
jne 0xa60c
leaq 0x8c99(%rip), %rsi      # 0x13270
movq 0x8(%rsp), %rdi
movl $0x2710, %edx           # imm = 0x2710
callq 0xb514
jmp 0xa60c
cmpq $0x0, (%r12)
jne 0xa609
testb $0x1, %bpl
je 0xa642
leaq 0x8c74(%rip), %rsi      # 0x13270
movq %r12, %rdi
movl $0xfa0, %edx            # imm = 0xFA0
callq 0xb5e5
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x0, 0x38(%rbx)
xorl %r12d, %r12d
cmpl $0x0, 0x3c(%rbx)
jne 0xa60c
movq 0x8(%rsp), %rdi
cmpq $0x0, (%rdi)
jne 0xa60c
leaq 0x8c30(%rip), %rsi      # 0x13270
jmp 0xa5dc
movl $0x80, %esi
cmpl $0x3, 0xc(%r15)
je 0xa696
movb 0x10(%rbx), %al
cmpb $0x60, %al
jb 0xa688
cmpl $0x0, (%rbx)
jne 0xa688
cmpl $0x0, 0x4(%rbx)
jne 0xa688
cmpl $0xffff0000, 0x8(%rbx)  # imm = 0xFFFF0000
jne 0xa688
movzbl %al, %ecx
cmpb $0x75, %al
movl $0x74, %eax
cmovael %ecx, %eax
cmpb $0x7a, %al
movl $0x7a, %ecx
cmovbl %eax, %ecx
addb $0x4, %cl
movzbl %cl, %esi
jmp 0xa696
xorl %esi, %esi
cmpb $0x3f, %al
setae %sil
shll $0x4, %esi
orl $0x40, %esi
movl $0x1, %r12d
movq %r13, %rdi
xorl %edx, %edx
movl $0x1, %ecx
movq %rbx, %r8
movq 0x10(%rsp), %r9
callq 0x9938
testl %eax, %eax
je 0xa700
movw $0x2, 0x2e(%rbx)
leaq 0x8bbc(%rip), %r14      # 0x13280
movl (%r14), %eax
movl %eax, 0x30(%rbx)
movl 0x8(%r15), %eax
movl %eax, 0x34(%rbx)
leaq 0x8b98(%rip), %rsi      # 0x13270
movq 0x8(%rsp), %rdi
movl $0x2710, %edx           # imm = 0x2710
callq 0xb514
movl (%r14), %eax
movl %eax, 0x30(%rbx)
movl $0x1, 0x38(%rbx)
movl $0x0, 0x3c(%rbx)
jmp 0xa60c
callq 0x2f14
xorl %r12d, %r12d
jmp 0xa6f4