// File: /workspace/github_c_makefile_star2_O0/gregtour[P]minimal-compiler/grammar.c
// Function: AddToken
int AddToken(char*           string,
              int            len,
              GRAMMAR_TABLE* grammar)
{
    int   j;
    char* search = grammar->tokens;
    char* end = grammar->tokens + TOKEN_BUFFER_SIZE;
    int   index = 1;
    while (index <= grammar->numTokens &&
           search < end)
    {
        for (j = 0; j < len; j++)
        {
            if (string[j] == '\\') j++;
            if (string[j] != search[j])
                break;
        }
        if (j == len && search[j] == 0)
        {
            return index | K_TOKEN;
        }
        while (search[0] != 0 && search != end)
            search++;
        search++;
        index++;
    }

    if (search < end)
    {
        for (j = 0; j < len && search < end; j++)
        {
            if (string[j] == '\\') j++;
            search[0] = string[j];
            search++;
        }
        search[0] = 0;
        grammar->numTokens++;
        return index | K_TOKEN;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
addq $0x1000, %rax           # imm = 0x1000
movq %rax, -0x38(%rbp)
movl $0x1, -0x3c(%rbp)
movl -0x3c(%rbp), %ecx
movq -0x20(%rbp), %rdx
xorl %eax, %eax
cmpl 0x10(%rdx), %ecx
movb %al, -0x3d(%rbp)
jg 0x4643
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
setb %al
movb %al, -0x3d(%rbp)
movb -0x3d(%rbp), %al
testb $0x1, %al
jne 0x464f
jmp 0x471e
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x46a3
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5c, %eax
jne 0x4678
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x30(%rbp), %rcx
movslq -0x24(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x4696
jmp 0x46a3
jmp 0x4698
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4656
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x46cc
movq -0x30(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x46cc
movl -0x3c(%rbp), %eax
orl $0x2000, %eax           # imm = 0x2000
movl %eax, -0x4(%rbp)
jmp 0x47c1
jmp 0x46ce
movq -0x30(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x3e(%rbp)
je 0x46ed
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
setne %al
movb %al, -0x3e(%rbp)
movb -0x3e(%rbp), %al
testb $0x1, %al
jne 0x46f6
jmp 0x4704
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x46ce
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x4624
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x47ba
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %ecx
xorl %eax, %eax
cmpl -0x14(%rbp), %ecx
movb %al, -0x3f(%rbp)
jge 0x474e
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
setb %al
movb %al, -0x3f(%rbp)
movb -0x3f(%rbp), %al
testb $0x1, %al
jne 0x4757
jmp 0x4799
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5c, %eax
jne 0x4771
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4733
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
movq -0x20(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movl -0x3c(%rbp), %eax
orl $0x2000, %eax           # imm = 0x2000
movl %eax, -0x4(%rbp)
jmp 0x47c1
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)