// File: /workspace/github_c_makefile_star2_O0/kyz[P]amostools/./amoslib.c
// Function: add_token
static int add_token(uint32_t key, uint8_t *name, char type,
                     struct AMOS_token *table[AMOS_TOKEN_TABLE_SIZE],
                     uint8_t **last_name)
{
    int len, tidx;
    struct AMOS_token *e;
    uint8_t *s;

    /* if name begins with '!', it can be recalled with blank name */
    if (*name == 0x80) {
        if (!(name = *last_name)) return 0; /* skip this token */
    }
    else if (*name == '!') {
        *last_name = ++name; /* skip '!', save name */
    }

    /* allocate token table entry and link it into table */
    for (len = 0; name[len] < 0x80; len++);
    e = malloc(sizeof(struct AMOS_token) + len + 2);
    if (!e) return 1; /* failure, out of memory */
    tidx = (key >> 1) % AMOS_TOKEN_TABLE_SIZE;
    e->key = key;
    e->next = table[tidx];
    table[tidx] = e;

    /* keep type as first character */
    e->text[0] = type;

    /* copy text, capitalise words */
    s = (uint8_t *) &e->text[1];
    for (;;) {
        /* copy and capitalise first letter of word */
        uint8_t c = *name++, c2 = c & 0x7F;
        *s++ = (c2 >= 'a' && c2 <= 'z') ? c2 - ('a'-'A') : c2;
        /* copy rest of word */
        do {
            if (c & 0x80) goto done; /* loop exit condition */
        } while ((c = *s++ = *name++) != ' ');
    }
 done:
    /* remove terminating high bit from name */
    s[-1] &= 0x7F;
    /* replace any trailing space with virtual one by changing type to I */
    if (s[-1] == ' ') {
        s--;
        e->text[0] = 'I';
    }
    /* add null terminator */
    *s++ = '\0';

    //printf("$%06x: %s\n", e->key, e->text);
    return 0; /* success */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %dl, %al
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x80, %eax
jne 0x2a19
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
jne 0x2a17
movl $0x0, -0x4(%rbp)
jmp 0x2bc6
jmp 0x2a3a
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x21, %eax
jne 0x2a38
movq -0x10(%rbp), %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2a3a
movl $0x0, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x80, %eax
jge 0x2a61
jmp 0x2a56
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2a41
movslq -0x2c(%rbp), %rdi
addq $0x10, %rdi
addq $0x2, %rdi
callq 0x1180
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x2a89
movl $0x1, -0x4(%rbp)
jmp 0x2bc6
movl -0x8(%rbp), %eax
shrl %eax
movl $0x2069, %ecx           # imm = 0x2069
xorl %edx, %edx
divl %ecx
movl %edx, -0x30(%rbp)
movl -0x8(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rdx
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movb -0x11(%rbp), %cl
movq -0x38(%rbp), %rax
movb %cl, 0xc(%rax)
movq -0x38(%rbp), %rax
addq $0xc, %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movb (%rax), %al
movb %al, -0x41(%rbp)
movzbl -0x41(%rbp), %eax
andl $0x7f, %eax
movb %al, -0x42(%rbp)
movzbl -0x42(%rbp), %eax
cmpl $0x61, %eax
jl 0x2b1d
movzbl -0x42(%rbp), %eax
cmpl $0x7a, %eax
jg 0x2b1d
movzbl -0x42(%rbp), %eax
subl $0x20, %eax
movl %eax, -0x48(%rbp)
jmp 0x2b24
movzbl -0x42(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movzbl -0x41(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x2b4a
jmp 0x2b7e
jmp 0x2b4c
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movb (%rax), %al
movq -0x40(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %al, (%rcx)
movb %al, -0x41(%rbp)
movzbl %al, %eax
cmpl $0x20, %eax
jne 0x2b3a
jmp 0x2ae1
movq -0x40(%rbp), %rax
movzbl -0x1(%rax), %ecx
andl $0x7f, %ecx
movb %cl, -0x1(%rax)
movq -0x40(%rbp), %rax
movzbl -0x1(%rax), %eax
cmpl $0x20, %eax
jne 0x2bad
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movb $0x49, 0xc(%rax)
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movb $0x0, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop