// File: /workspace/github_c_makefile_star2_O2/Gaurang18[P]Compiler-Project-BITS-Pilani/./tokensymboltable.h
// Function: hashinsert
int hashinsert(char* key,char* type,char* functionname,char* ifnumvalue)
{
    int j = get_func_hash_value(functionname);
    int h = hash(key);
    struct tokNode* it = create_node(key,type,functionname,ifnumvalue);
    if (it == NULL){
        return 0;
    }
    while(ht->functable[j]->table[h]->next != NULL){
        h++;
    }
    ht->functable[j]->table[h]->next = it;
    int width =0;
       if(strcmp(ht->functable[j]->table[h]->next->type,"INTEGER") ==0){
        width = 2;
       }
       if(strcmp(ht->functable[j]->table[h]->next->type,"REAL") ==0){
        width = 4;
       }
       if(strcmp(ht->functable[j]->table[h]->next->type,"STRING") ==0){
        width = strlen(ht->functable[j]->table[h]->next->name);
       }
       if(strcmp(ht->functable[j]->table[h]->next->type,"BOOLEAN") ==0){
           width = 1;
       }
       if(strncmp(ht->functable[j]->table[h]->next->type,"ARRAY",5) ==0){
        char type[50];
        memset(type, '\0', sizeof(type));
        strcpy(type, ht->functable[j]->table[h]->next->type);
        int range = 0;
        
                char *token = NULL;
                    token = strtok(type, "(");
                    if(token!=NULL){
                        token = strtok(NULL, ",");

                        if(strcmp(token, "INTEGER")==0)
                            width = 2;
                        if(strcmp(token, "REAL")==0)
                            width = 4;
                        if(strcmp(token, "BOOLEAN")==0)
                            width = 1;


                        token = strtok(NULL, ")");
                        if(token!=NULL){
                            range = atoi(token);

                        }}

                
                // assert(0);

        width = width*range;
       }
        ht->functable[j]->table[h]->next->width = width;
        
        ht->functable[j]->table[h]->next->offset = offset; 
        offset += width;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
movq %rdx, %rdi
callq 0x4409
movl %eax, -0x30(%rbp)
movq %rbx, %rdi
callq 0x4343
movl %eax, %r14d
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x4280
testq %rax, %rax
je 0x49cd
movq 0x1a664(%rip), %rcx     # 0x1eec8
movslq -0x30(%rbp), %rdi
movq (%rcx,%rdi,8), %rdx
movslq %r14d, %r13
shlq $0x3, %r13
movq (%rdx,%r13), %rsi
addq $0x8, %r13
cmpq $0x0, 0x50(%rsi)
jne 0x4873
movq %rax, 0x50(%rsi)
movq %rdi, -0x30(%rbp)
movq (%rcx,%rdi,8), %rax
movq -0x8(%rax,%r13), %rax
movq 0x50(%rax), %r15
leaq 0x37(%r15), %r12
leaq 0x421a(%rip), %rsi      # 0x8abc
movq %r12, %rdi
callq 0x2120
xorl %ebx, %ebx
testl %eax, %eax
sete %bl
addl %ebx, %ebx
leaq 0x420c(%rip), %rsi      # 0x8ac6
movq %r12, %rdi
callq 0x2120
testl %eax, %eax
pushq $0x4
popq %rax
cmovel %eax, %ebx
leaq 0x3e2d(%rip), %rsi      # 0x86fe
movq %r12, %rdi
callq 0x2120
testl %eax, %eax
jne 0x48e8
movq %r15, %rdi
callq 0x20a0
movq %rax, %rbx
leaq 0x41de(%rip), %rsi      # 0x8acd
movq %r12, %rdi
callq 0x2120
testl %eax, %eax
pushq $0x1
popq %r14
cmovel %r14d, %ebx
leaq 0x39ff(%rip), %rsi      # 0x8307
pushq $0x5
popq %rdx
movq %r12, %rdi
callq 0x2050
testl %eax, %eax
jne 0x49ef
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %r15
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
andw $0x0, 0x30(%r15)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2060
leaq 0x3a85(%rip), %rsi      # 0x83cd
movq %r15, %rdi
callq 0x2190
testq %rax, %rax
je 0x49d2
leaq 0x3a65(%rip), %rsi      # 0x83c1
xorl %edi, %edi
callq 0x2190
movq %rax, %r12
leaq 0x414f(%rip), %rsi      # 0x8abc
movq %rax, %rdi
callq 0x2120
testl %eax, %eax
pushq $0x2
popq %rax
cmovel %eax, %ebx
leaq 0x4142(%rip), %rsi      # 0x8ac6
movq %r12, %rdi
callq 0x2120
testl %eax, %eax
movl %ebx, %r15d
pushq $0x4
popq %rax
cmovel %eax, %r15d
leaq 0x412e(%rip), %rsi      # 0x8acd
movq %r12, %rdi
callq 0x2120
testl %eax, %eax
pushq $0x1
popq %rbx
cmovnel %r15d, %ebx
leaq 0x4787(%rip), %rsi      # 0x913e
xorl %edi, %edi
callq 0x2190
testq %rax, %rax
je 0x49d2
movq %rax, %rdi
callq 0x21a0
jmp 0x49d4
xorl %r14d, %r14d
jmp 0x4a05
xorl %eax, %eax
imull %eax, %ebx
movq 0x1a4ea(%rip), %rax     # 0x1eec8
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rax,%r13), %rax
movq 0x50(%rax), %r15
movl %ebx, 0x4c(%r15)
movl 0x1a4cb(%rip), %eax     # 0x1eec4
movl %eax, 0x48(%r15)
addl %ebx, %eax
movl %eax, 0x1a4bf(%rip)     # 0x1eec4
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq