// File: /workspace/github_c_makefile_star2_O2/Ziddykins[P]Dawn/src/tokenlist.c
// Function: inc_token
void inc_token(TokenList l, char * c, int end) {
    if(!l) {
        return;
    }
    struct token_list * cl = l;
    struct token_node * tmp = cl->head;
    if(!tmp) { //list is empty
        CALLEXIT(!(cl->head = calloc(1, sizeof *cl->head)))
        cl->head->next = cl->head->prev = 0;
        CALLEXIT(!(cl->head->elem = malloc(strlen(c)+1)))
        strcpy(cl->head->elem, c);
        cl->head->num = 1; //c has one occurrence
        cl->head->end = end;
        cl->len = 1; //and the list is now of length 1
    } else { //list is not empty
        //search for the item
        struct token_node * prev = 0;
        while(tmp && strcmp(tmp->elem, c) != 0) {
            prev = tmp;
            tmp = tmp->next;
        }
        if(!tmp) { //c was not found, we've reached the end of the list
            //insert new element at the end of the list
            CALLEXIT(!(prev->next = calloc(1, sizeof *prev)))

            tmp = prev->next;
            CALLEXIT(!(tmp->elem = malloc(strlen(c)+1)))
            strcpy(tmp->elem, c);
            tmp->next = 0;
            tmp->prev = prev;
            tmp->num = 1;
            tmp->end = end,
            cl->len++; //list is now 1 entry longer
        } else {
            //c has been found, increment its value
            tmp->num++;
            tmp->end |= end;
            //swap with predecessors till sorted
            while(tmp->prev && tmp->prev->num < tmp->num) {
                swap(tmp->prev, tmp);
            }
        }
    }
    cl->num_total++;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
testq %rdi, %rdi
je 0xebdc
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rax
testq %rax, %rax
je 0xeb27
xorl %r12d, %r12d
testq %rax, %rax
je 0xeb80
movq %rax, %r15
movq 0x10(%rax), %rdi
movq %r14, %rsi
callq 0x22e0
testl %eax, %eax
je 0xebe5
movq (%r15), %rax
movq %r15, %r12
jmp 0xeb03
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0x2110
movq %rax, (%rbx)
testq %rax, %rax
je 0xec09
movq %rax, %r15
movq %r14, %rdi
callq 0x20c0
leaq 0x1(%rax), %rdi
callq 0x22c0
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0xec12
movq %rax, %rdi
movq %r14, %rsi
callq 0x21c0
movl $0x1, 0x18(%r15)
movl %ebp, 0x1c(%r15)
movq $0x1, 0x8(%rbx)
jmp 0xebd8
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0x2110
movq %rax, (%r12)
testq %rax, %rax
je 0xec1b
movq %rax, %r15
movq %r14, %rdi
callq 0x20c0
leaq 0x1(%rax), %rdi
callq 0x22c0
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0xec24
movq %rax, %rdi
movq %r14, %rsi
callq 0x21c0
andq $0x0, (%r15)
movq %r12, 0x8(%r15)
movl $0x1, 0x18(%r15)
movl %ebp, 0x1c(%r15)
incq 0x8(%rbx)
incq 0x10(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
incl 0x18(%r15)
orl %ebp, 0x1c(%r15)
movq 0x8(%r15), %rdi
testq %rdi, %rdi
je 0xebd8
movl 0x18(%rdi), %eax
cmpl 0x18(%r15), %eax
jae 0xebd8
movq %r15, %rsi
callq 0xec38
jmp 0xebed
leaq 0x8d60(%rip), %rdi      # 0x17970
jmp 0xec2b
leaq 0x8da8(%rip), %rdi      # 0x179c1
jmp 0xec2b
leaq 0x8dee(%rip), %rdi      # 0x17a10
jmp 0xec2b
leaq 0x8e34(%rip), %rdi      # 0x17a5f
callq 0x2190
pushq $0x1
popq %rdi
callq 0x2270