// File: /workspace/github_c_makefile_star2_O3/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 0xfee3
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rax
testq %rax, %rax
je 0xfe28
movq %rax, %r12
movq 0x10(%rax), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x22d0
testl %eax, %eax
je 0xfe85
movq (%r12), %rax
testq %rax, %rax
jne 0xfda4
movl $0x1, %edi
movl $0x20, %esi
callq 0x2110
movq %rax, (%r12)
testq %rax, %rax
je 0xfef6
movq %rax, %r15
movq %r14, %rdi
callq 0x20c0
leaq 0x1(%rax), %rdi
callq 0x22b0
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0xfefb
movq %rax, %rdi
movq %r14, %rsi
callq 0x21c0
movq %r12, 0x8(%r15)
movl $0x1, 0x18(%r15)
movl %ebp, 0x1c(%r15)
incq 0x8(%rbx)
jmp 0xfedf
movl $0x1, %edi
movl $0x20, %esi
callq 0x2110
movq %rax, (%rbx)
testq %rax, %rax
je 0xfeec
movq %rax, %r15
movq %r14, %rdi
callq 0x20c0
leaq 0x1(%rax), %rdi
callq 0x22b0
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0xfef1
movq %rax, %rdi
movq %r14, %rsi
callq 0x21c0
movl $0x1, 0x18(%r15)
movl %ebp, 0x1c(%r15)
movq $0x1, 0x8(%rbx)
jmp 0xfedf
movl 0x18(%r12), %ecx
incl %ecx
movl %ecx, 0x18(%r12)
orl 0x1c(%r12), %ebp
movq 0x8(%r12), %rax
movl %ebp, 0x1c(%r12)
testq %rax, %rax
je 0xfedf
movl 0x18(%rax), %edx
cmpl %ecx, %edx
jae 0xfedf
movq 0x10(%rax), %rsi
movl 0x1c(%rax), %edi
movq %r15, 0x10(%rax)
movl %ecx, 0x18(%rax)
movl %edx, %r8d
movl %ebp, 0x1c(%rax)
movq %rsi, 0x10(%r12)
movl %edx, 0x18(%r12)
movl %edi, 0x1c(%r12)
movl 0x18(%rax), %edx
movl %r8d, %ecx
movq %rsi, %r15
movl %edi, %ebp
cmpl %r8d, %edx
jb 0xfeac
incq 0x10(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x3058
callq 0x3043
callq 0x302e
callq 0x3019