// File: /workspace/github_c_makefile_star2_O1/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 0xfbdb
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rax
testq %rax, %rax
je 0xfb7a
movq %rax, %r12
movq 0x10(%rax), %rdi
movq %r14, %rsi
callq 0x22d0
testl %eax, %eax
je 0xfbe4
movq (%r12), %rax
testq %rax, %rax
jne 0xfaf5
movl $0x1, %edi
movl $0x20, %esi
callq 0x2110
movq %rax, (%r12)
testq %rax, %rax
je 0xfc3a
movq %rax, %r15
movq %r14, %rdi
callq 0x20c0
leaq 0x1(%rax), %rdi
callq 0x22b0
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0xfc3f
movq %rax, %rdi
movq %r14, %rsi
callq 0x21c0
movq $0x0, (%r15)
movq %r12, 0x8(%r15)
movl $0x1, 0x18(%r15)
movl %ebp, 0x1c(%r15)
incq 0x8(%rbx)
jmp 0xfbd7
movl $0x1, %edi
movl $0x20, %esi
callq 0x2110
movq %rax, (%rbx)
testq %rax, %rax
je 0xfc30
movq %rax, %r15
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %r14, %rdi
callq 0x20c0
leaq 0x1(%rax), %rdi
callq 0x22b0
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0xfc35
movq %rax, %rdi
movq %r14, %rsi
callq 0x21c0
movl $0x1, 0x18(%r15)
movl %ebp, 0x1c(%r15)
movq $0x1, 0x8(%rbx)
incq 0x10(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
incl 0x18(%r12)
movq 0x8(%r12), %rax
orl %ebp, 0x1c(%r12)
testq %rax, %rax
je 0xfbd7
movl 0x18(%rax), %ecx
movl 0x18(%r12), %edx
cmpl %edx, %ecx
jae 0xfbd7
movq 0x10(%rax), %rsi
movl 0x1c(%rax), %edi
movq 0x10(%r12), %r8
movq %r8, 0x10(%rax)
movl %edx, 0x18(%rax)
movl 0x1c(%r12), %edx
movl %edx, 0x1c(%rax)
movq %rsi, 0x10(%r12)
movl %ecx, 0x18(%r12)
movl %edi, 0x1c(%r12)
jmp 0xfbf3
callq 0x3058
callq 0x3043
callq 0x302e
callq 0x3019