// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
testq %rdi, %rdi
je 0x1c22
movq %rdi, %r14
pushq $0x18
popq %rdi
callq 0x1160
testq %rax, %rax
je 0x1dbb
movq %rax, %rbx
movl 0xc(%r14), %eax
decl %eax
cmpl $0x4, %eax
ja 0x1c76
leaq 0x44dc(%rip), %rcx      # 0x6094
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x20(%r14), %rax
cmpl $0x107, 0x20(%rax)      # imm = 0x107
jne 0x1d6b
movl $0x4, (%rbx)
jmp 0x1c6d
movq 0x20(%r14), %rax
cmpl $0x107, 0x20(%rax)      # imm = 0x107
jne 0x1c83
movl $0x5, (%rbx)
jmp 0x1c40
movq 0x20(%r14), %rax
movl 0x20(%rax), %ecx
xorl %eax, %eax
cmpl $0x109, %ecx            # imm = 0x109
sete %al
leal 0x1(,%rax,2), %eax
cmpl $0x107, %ecx            # imm = 0x107
pushq $0x4
popq %r15
cmovel %r15d, %eax
cmpl $0x1, %eax
jne 0x1c9e
xorl %ebx, %ebx
jmp 0x1da5
movq 0x20(%r14), %rax
cmpl $0x107, 0x20(%rax)      # imm = 0x107
jne 0x1d53
movl $0x4, (%rbx)
movl $0x1, 0x8(%rbx)
jmp 0x1da5
movq 0x20(%r14), %rax
cmpl $0x107, 0x20(%rax)      # imm = 0x107
jne 0x1d83
movl $0x5, (%rbx)
movq 0x30(%r14), %rax
movl 0x20(%rax), %eax
movl %eax, 0x14(%rbx)
andl $0x0, 0x8(%rbx)
jmp 0x1da5
movq %rbx, %rdi
callq 0x1030
jmp 0x1da5
movq 0x28(%r14), %rax
movq 0x20(%rax), %rcx
leaq 0x4416(%rip), %rsi      # 0x60a8
leaq 0x47f4(%rip), %rdx      # 0x648d
jmp 0x1d99
movl $0x6, (%rbx)
movl %eax, 0x8(%rbx)
addq $0x30, %r14
pushq $-0x4
popq %rdi
pushq $-0x1
popq %r12
movq %r14, %rax
movq (%rax), %rax
addq $0x4, %rdi
incl %r12d
testq %rax, %rax
jne 0x1cb5
callq 0x1160
testq %rax, %rax
je 0x1e04
movq %rax, %rcx
movq (%r14), %r14
testq %r14, %r14
je 0x1db1
movl 0xc(%r14), %edx
cmpl $0x5, %edx
je 0x1d1b
cmpl $0x4, %edx
jne 0x1c22
movq 0x20(%r14), %rdx
movl 0x20(%rdx), %edx
xorl %esi, %esi
cmpl $0x109, %edx            # imm = 0x109
sete %sil
leal 0x1(,%rsi,2), %esi
cmpl $0x107, %edx            # imm = 0x107
cmovel %r15d, %esi
movl %esi, (%rcx)
jmp 0x1d4d
movq 0x20(%r14), %rdx
movl 0x20(%rdx), %edx
xorl %esi, %esi
cmpl $0x109, %edx            # imm = 0x109
sete %sil
leal 0x1(,%rsi,2), %esi
cmpl $0x107, %edx            # imm = 0x107
cmovel %r15d, %esi
movl %esi, (%rcx)
jne 0x1c22
movl $0x5, (%rcx)
addq $0x4, %rcx
jmp 0x1cd5
movq 0x28(%r14), %rax
movq 0x20(%rax), %rcx
leaq 0x4346(%rip), %rsi      # 0x60a8
leaq 0x46f7(%rip), %rdx      # 0x6460
jmp 0x1d99
movq 0x28(%r14), %rax
movq 0x20(%rax), %rcx
leaq 0x432e(%rip), %rsi      # 0x60a8
leaq 0x469c(%rip), %rdx      # 0x641d
jmp 0x1d99
movq 0x28(%r14), %rax
movq 0x20(%rax), %rcx
leaq 0x4316(%rip), %rsi      # 0x60a8
leaq 0x46a7(%rip), %rdx      # 0x6440
xorl %ebx, %ebx
movq %r14, %rdi
xorl %eax, %eax
callq 0x1ab5
movq %rbx, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, 0x10(%rbx)
movl %r12d, 0xc(%rbx)
jmp 0x1da5
leaq 0x943e(%rip), %rax      # 0xb200
movq (%rax), %rdi
leaq 0x45e5(%rip), %rsi      # 0x63b1
leaq 0x4603(%rip), %rbx      # 0x63d6
leaq 0x460f(%rip), %r8       # 0x63e9
pushq $0x34
popq %r14
movq %rbx, %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x1120
leaq 0x45ee(%rip), %rdi      # 0x63e0
leaq 0x45fe(%rip), %rcx      # 0x63f7
movq %rbx, %rsi
movl %r14d, %edx
callq 0x10e0
leaq 0x93f5(%rip), %rax      # 0xb200
movq (%rax), %rdi
leaq 0x459c(%rip), %rsi      # 0x63b1
leaq 0x45ba(%rip), %rbx      # 0x63d6
leaq 0x45c6(%rip), %r8       # 0x63e9
pushq $0x67
jmp 0x1ddc