// File: /workspace/github_c_makefile_star2_O3/taeguk[P]Compiler-Proj-Cminus/src/analyze.c
// Function: setSymbolInfo
static SymbolInfo * setSymbolInfo (TreeNode *t)
{
  SymbolInfo * symbolInfo;

  if (t == NULL) return NULL;
  MALLOC(symbolInfo, sizeof(*symbolInfo));

  switch (t->nodeKind)
    {
      case VariableDeclarationK:
        if (tokenToExpType(t->attr.varDecl.type_spec->attr.TOK) != IntT)
          {
            printError(t, "Type", "Variable '%s' cannot be void type.", t->attr.varDecl._var->attr.ID);
            return NULL;
          }
        symbolInfo->nodeType = IntT;
        symbolInfo->attr.intInfo.isParam = 0;
        break;


      case ArrayDeclarationK:
        if (tokenToExpType(t->attr.funcDecl.type_spec->attr.TOK) != IntT)
          {
            printError(t, "Type", "Array '%s' cannot be void type.", t->attr.varDecl._var->attr.ID);
            return NULL;
          }
        symbolInfo->nodeType = IntArrayT;
        symbolInfo->attr.arrInfo.arrLen = t->attr.arrDecl._num->attr.NUM;
        symbolInfo->attr.intInfo.isParam = 0;
        break;


      case FunctionDeclarationK:
        if (tokenToExpType(t->attr.funcDecl.type_spec->attr.TOK) == ErrorT)
          {
            DONT_OCCUR_PRINT;
            return NULL;
          }
        symbolInfo->nodeType = FuncT;
        symbolInfo->attr.funcInfo.retType =
          tokenToExpType(t->attr.funcDecl.type_spec->attr.TOK);

        TreeNode * param_node;
        ExpType * newParamList;
        int n_param;
        int i;

        n_param = 0;
        param_node = t->attr.funcDecl.params;

        while (param_node)
          {
            ++ n_param;
            param_node = param_node->sibling;
          }

        MALLOC(newParamList, n_param * sizeof(ExpType));

        param_node = t->attr.funcDecl.params;
        i = 0;
        while (param_node)
          {
            if (param_node->nodeKind == VariableParameterK)
              newParamList[i] =
                tokenToExpType(param_node->attr.varParam.type_spec->attr.TOK); // Is it need type check?
            else if (param_node->nodeKind == ArrayParameterK)
              {
                newParamList[i] =
                  tokenToExpType(param_node->attr.arrParam.type_spec->attr.TOK);
                if (newParamList[i] != IntT)
                  {
                    DONT_OCCUR_PRINT;
                    return NULL;
                  }
                newParamList[i] = IntArrayT;
              }
            else
              {
                DONT_OCCUR_PRINT;
                return NULL;
              }

            ++i;
            param_node = param_node->sibling;
          }

        symbolInfo->attr.funcInfo.paramTypeList = newParamList;
        symbolInfo->attr.funcInfo.paramLen = n_param;
        break;


      case VariableParameterK:
        if (tokenToExpType(t->attr.varParam.type_spec->attr.TOK) != IntT)
          {
            printError(t, "Type", "Variable parameter '%s' cannot be void type.", t->attr.varDecl._var->attr.ID);
            return NULL;
          }
        symbolInfo->nodeType = IntT;
        symbolInfo->attr.intInfo.isParam = TRUE;
        break;


      case ArrayParameterK:
        if (tokenToExpType(t->attr.arrParam.type_spec->attr.TOK) != IntT)
          {
            printError(t, "Type", "Array parameter '%s' cannot be void type.", t->attr.varDecl._var->attr.ID);
            return NULL;
          }
        symbolInfo->nodeType = IntArrayT;
        symbolInfo->attr.intInfo.isParam = TRUE;
        break;

      default:
        DONT_OCCUR_PRINT;
        free(symbolInfo);
        //symbolInfo = NULL;
        break;
    }

  return symbolInfo;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x1c81
movq %rdi, %r14
movl $0x18, %edi
callq 0x1160
testq %rax, %rax
je 0x1e35
movq %rax, %rbx
movl 0xc(%r14), %eax
decl %eax
cmpl $0x4, %eax
ja 0x1cd8
leaq 0x447b(%rip), %rcx      # 0x6094
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x20(%r14), %rax
cmpl $0x107, 0x20(%rax)      # imm = 0x107
jne 0x1ded
movl $0x4, (%rbx)
jmp 0x1ccc
movq 0x20(%r14), %rax
cmpl $0x107, 0x20(%rax)      # imm = 0x107
jne 0x1ce5
movl $0x5, (%rbx)
jmp 0x1c9f
movq 0x20(%r14), %rax
movl 0x20(%rax), %eax
xorl %ecx, %ecx
cmpl $0x109, %eax            # imm = 0x109
sete %cl
leal 0x1(,%rcx,2), %ecx
cmpl $0x107, %eax            # imm = 0x107
movl $0x4, %eax
cmovnel %ecx, %eax
cmpl $0x1, %eax
jne 0x1d00
xorl %ebx, %ebx
jmp 0x1e27
movq 0x20(%r14), %rax
cmpl $0x107, 0x20(%rax)      # imm = 0x107
jne 0x1dd5
movl $0x4, (%rbx)
movl $0x1, 0x8(%rbx)
jmp 0x1e27
movq 0x20(%r14), %rax
cmpl $0x107, 0x20(%rax)      # imm = 0x107
jne 0x1e05
movl $0x5, (%rbx)
movq 0x30(%r14), %rax
movl 0x20(%rax), %eax
movl %eax, 0x14(%rbx)
movl $0x0, 0x8(%rbx)
jmp 0x1e27
movq %rbx, %rdi
callq 0x1030
jmp 0x1e27
movq 0x28(%r14), %rax
movq 0x20(%rax), %rcx
leaq 0x43b4(%rip), %rsi      # 0x60a8
leaq 0x4792(%rip), %rdx      # 0x648d
jmp 0x1e1b
movl $0x6, (%rbx)
movl %eax, 0x8(%rbx)
addq $0x30, %r14
movq $-0x4, %rdi
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq %r14, %rax
movq (%rax), %rax
addq $0x4, %rdi
incl %r15d
testq %rax, %rax
jne 0x1d1d
callq 0x1160
testq %rax, %rax
je 0x1e7e
movq (%r14), %rcx
testq %rcx, %rcx
je 0x1dcb
movl $0x4, %edx
movq %rax, %rsi
movl 0xc(%rcx), %edi
cmpl $0x5, %edi
je 0x1d8a
cmpl $0x4, %edi
jne 0x1c81
movq 0x20(%rcx), %rdi
movl 0x20(%rdi), %edi
xorl %r8d, %r8d
cmpl $0x109, %edi            # imm = 0x109
sete %r8b
leal 0x1(,%r8,2), %r8d
cmpl $0x107, %edi            # imm = 0x107
cmovel %edx, %r8d
movl %r8d, (%rsi)
jmp 0x1dbf
movq 0x20(%rcx), %rdi
movl 0x20(%rdi), %edi
xorl %r8d, %r8d
cmpl $0x109, %edi            # imm = 0x109
sete %r8b
leal 0x1(,%r8,2), %r8d
cmpl $0x107, %edi            # imm = 0x107
cmovel %edx, %r8d
movl %r8d, (%rsi)
jne 0x1c81
movl $0x5, (%rsi)
movq (%rcx), %rcx
addq $0x4, %rsi
testq %rcx, %rcx
jne 0x1d4e
movq %rax, 0x10(%rbx)
movl %r15d, 0xc(%rbx)
jmp 0x1e27
movq 0x28(%r14), %rax
movq 0x20(%rax), %rcx
leaq 0x42c4(%rip), %rsi      # 0x60a8
leaq 0x4675(%rip), %rdx      # 0x6460
jmp 0x1e1b
movq 0x28(%r14), %rax
movq 0x20(%rax), %rcx
leaq 0x42ac(%rip), %rsi      # 0x60a8
leaq 0x461a(%rip), %rdx      # 0x641d
jmp 0x1e1b
movq 0x28(%r14), %rax
movq 0x20(%rax), %rcx
leaq 0x4294(%rip), %rsi      # 0x60a8
leaq 0x4625(%rip), %rdx      # 0x6440
xorl %ebx, %ebx
movq %r14, %rdi
xorl %eax, %eax
callq 0x1b13
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x93c4(%rip), %rax      # 0xb200
movq (%rax), %rdi
leaq 0x456b(%rip), %rsi      # 0x63b1
leaq 0x4589(%rip), %rbx      # 0x63d6
leaq 0x4595(%rip), %r8       # 0x63e9
movq %rbx, %rdx
movl $0x34, %ecx
xorl %eax, %eax
callq 0x1120
leaq 0x4576(%rip), %rdi      # 0x63e0
leaq 0x4586(%rip), %rcx      # 0x63f7
movq %rbx, %rsi
movl $0x34, %edx
callq 0x10e0
leaq 0x937b(%rip), %rax      # 0xb200
movq (%rax), %rdi
leaq 0x4522(%rip), %rsi      # 0x63b1
leaq 0x4540(%rip), %rbx      # 0x63d6
leaq 0x454c(%rip), %r8       # 0x63e9
movq %rbx, %rdx
movl $0x67, %ecx
xorl %eax, %eax
callq 0x1120
leaq 0x452d(%rip), %rdi      # 0x63e0
leaq 0x453d(%rip), %rcx      # 0x63f7
movq %rbx, %rsi
movl $0x67, %edx
callq 0x10e0