// File: /workspace/github_c_makefile_star2_O3/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, %rbx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r13
movq %rdx, %rdi
callq 0x47cd
movl %eax, -0x30(%rbp)
movq %r13, %rdi
callq 0x20a0
xorl %r14d, %r14d
testq %rax, %rax
je 0x4c7c
xorl %ecx, %ecx
movsbl (%r13,%rcx), %edx
addl %edx, %r14d
incq %rcx
cmpq %rcx, %rax
jne 0x4c49
movslq %r14d, %rax
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x23, %rcx
addl %edx, %ecx
shll $0x2, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
movslq %eax, %r14
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x45ef
testq %rax, %rax
je 0x4e16
movq 0x1b22b(%rip), %rcx     # 0x1fec8
movslq -0x30(%rbp), %rdi
movq (%rcx,%rdi,8), %rdx
shlq $0x3, %r14
movq (%rdx,%r14), %rsi
addq $0x8, %r14
cmpq $0x0, 0x50(%rsi)
jne 0x4ca9
movq %rax, 0x50(%rsi)
movq %rdi, -0x30(%rbp)
movq (%rcx,%rdi,8), %rax
movq -0x8(%rax,%r14), %rax
movq 0x50(%rax), %r15
leaq 0x37(%r15), %r12
leaq 0x4de4(%rip), %rsi      # 0x9abc
movq %r12, %rdi
callq 0x2120
xorl %r13d, %r13d
testl %eax, %eax
sete %r13b
addl %r13d, %r13d
leaq 0x4dd3(%rip), %rsi      # 0x9ac6
movq %r12, %rdi
callq 0x2120
testl %eax, %eax
movl $0x4, %ebx
cmovnel %r13d, %ebx
leaq 0x49f1(%rip), %rsi      # 0x96fe
movq %r12, %rdi
callq 0x2120
testl %eax, %eax
jne 0x4d24
movq %r15, %rdi
callq 0x20a0
movq %rax, %rbx
leaq 0x4da2(%rip), %rsi      # 0x9acd
movq %r12, %rdi
callq 0x2120
testl %eax, %eax
movl $0x1, %r13d
cmovel %r13d, %ebx
leaq 0x45c1(%rip), %rsi      # 0x9307
movl $0x5, %edx
movq %r12, %rdi
callq 0x2050
testl %eax, %eax
jne 0x4e38
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %r15
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
movw $0x0, 0x30(%r15)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2060
leaq 0x4644(%rip), %rsi      # 0x93cd
movq %r15, %rdi
callq 0x2180
testq %rax, %rax
je 0x4e1b
leaq 0x4620(%rip), %rsi      # 0x93c1
xorl %edi, %edi
callq 0x2180
movq %rax, %r12
leaq 0x4d0a(%rip), %rsi      # 0x9abc
movq %rax, %rdi
callq 0x2120
testl %eax, %eax
movl $0x2, %eax
cmovel %eax, %ebx
leaq 0x4cfb(%rip), %rsi      # 0x9ac6
movq %r12, %rdi
callq 0x2120
testl %eax, %eax
movl $0x4, %r15d
cmovnel %ebx, %r15d
leaq 0x4ce7(%rip), %rsi      # 0x9acd
movq %r12, %rdi
callq 0x2120
testl %eax, %eax
movl $0x1, %ebx
cmovnel %r15d, %ebx
leaq 0x533e(%rip), %rsi      # 0xa13e
xorl %edi, %edi
callq 0x2180
testq %rax, %rax
je 0x4e1b
movq %rax, %rdi
callq 0x2190
jmp 0x4e1d
xorl %r13d, %r13d
jmp 0x4e4e
xorl %eax, %eax
imull %eax, %ebx
movq 0x1b0a1(%rip), %rax     # 0x1fec8
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rax,%r14), %rax
movq 0x50(%rax), %r15
movl %ebx, 0x4c(%r15)
movl 0x1b082(%rip), %eax     # 0x1fec4
movl %eax, 0x48(%r15)
addl %ebx, %eax
movl %eax, 0x1b076(%rip)     # 0x1fec4
movl %r13d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq