// File: /workspace/github_c_makefile_star2_O0/gregtour[P]minimal-compiler/grammar.c
// Function: AddSymbol
int AddSymbol(char*          string,
              int            len,
              GRAMMAR_TABLE* grammar)
{
    int   j;
    char* search = grammar->symbols;
    char* end = grammar->symbols + SYMBOL_BUFFER_SIZE;
    int   index = 1;
    while (index <= grammar->numSymbols &&
           search < end)
    {
        for (j = 0; j < len; j++)
        {
            if (string[j] != search[j])
                break;
        }
        if (j == len && search[j] == 0)
        {
            return index | K_SYMBOL;
        }
        while (search[0] != 0 && search != end)
            search++;
        search++;
        index++;
    }

    if (search < end)
    {
        for (j = 0; j < len && search < end; j++)
        {
            search[0] = string[j];
            search++;
        }
        search[0] = 0;
        grammar->numSymbols++;
        return index | K_SYMBOL;
    }

    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 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%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 (%rdx), %ecx
movb %al, -0x3d(%rbp)
jg 0x44a2
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
setb %al
movb %al, -0x3d(%rbp)
movb -0x3d(%rbp), %al
testb $0x1, %al
jne 0x44ae
jmp 0x4563
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x44e8
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 0x44db
jmp 0x44e8
jmp 0x44dd
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x44b5
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x4511
movq -0x30(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x4511
movl -0x3c(%rbp), %eax
orl $0x1000, %eax           # imm = 0x1000
movl %eax, -0x4(%rbp)
jmp 0x45e6
jmp 0x4513
movq -0x30(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x3e(%rbp)
je 0x4532
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
setne %al
movb %al, -0x3e(%rbp)
movb -0x3e(%rbp), %al
testb $0x1, %al
jne 0x453b
jmp 0x4549
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x4513
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x4484
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x45df
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %ecx
xorl %eax, %eax
cmpl -0x14(%rbp), %ecx
movb %al, -0x3f(%rbp)
jge 0x458f
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
setb %al
movb %al, -0x3f(%rbp)
movb -0x3f(%rbp), %al
testb $0x1, %al
jne 0x4598
jmp 0x45c0
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 0x4574
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl -0x3c(%rbp), %eax
orl $0x1000, %eax           # imm = 0x1000
movl %eax, -0x4(%rbp)
jmp 0x45e6
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax,%rax)