// File: /workspace/github_c_makefile_star2_O1/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 0x1cfa
movq %rdi, %r14
movl $0x18, %edi
callq 0x1160
testq %rax, %rax
je 0x1eae
movq %rax, %rbx
movl 0xc(%r14), %eax
decl %eax
cmpl $0x4, %eax
ja 0x1d51
leaq 0x4402(%rip), %rcx      # 0x6094
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x20(%r14), %rax
cmpl $0x107, 0x20(%rax)      # imm = 0x107
jne 0x1e66
movl $0x4, (%rbx)
jmp 0x1d45
movq 0x20(%r14), %rax
cmpl $0x107, 0x20(%rax)      # imm = 0x107
jne 0x1d5e
movl $0x5, (%rbx)
jmp 0x1d18
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 0x1d79
xorl %ebx, %ebx
jmp 0x1ea0
movq 0x20(%r14), %rax
cmpl $0x107, 0x20(%rax)      # imm = 0x107
jne 0x1e4e
movl $0x4, (%rbx)
movl $0x1, 0x8(%rbx)
jmp 0x1ea0
movq 0x20(%r14), %rax
cmpl $0x107, 0x20(%rax)      # imm = 0x107
jne 0x1e7e
movl $0x5, (%rbx)
movq 0x30(%r14), %rax
movl 0x20(%rax), %eax
movl %eax, 0x14(%rbx)
movl $0x0, 0x8(%rbx)
jmp 0x1ea0
movq %rbx, %rdi
callq 0x1030
jmp 0x1ea0
movq 0x28(%r14), %rax
movq 0x20(%rax), %rcx
leaq 0x433b(%rip), %rsi      # 0x60a8
leaq 0x4719(%rip), %rdx      # 0x648d
jmp 0x1e94
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 0x1d96
callq 0x1160
testq %rax, %rax
je 0x1ef7
movq (%r14), %rcx
testq %rcx, %rcx
je 0x1e44
movl $0x4, %edx
movq %rax, %rsi
movl 0xc(%rcx), %edi
cmpl $0x5, %edi
je 0x1e03
cmpl $0x4, %edi
jne 0x1cfa
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 0x1e38
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 0x1cfa
movl $0x5, (%rsi)
movq (%rcx), %rcx
addq $0x4, %rsi
testq %rcx, %rcx
jne 0x1dc7
movq %rax, 0x10(%rbx)
movl %r15d, 0xc(%rbx)
jmp 0x1ea0
movq 0x28(%r14), %rax
movq 0x20(%rax), %rcx
leaq 0x424b(%rip), %rsi      # 0x60a8
leaq 0x45fc(%rip), %rdx      # 0x6460
jmp 0x1e94
movq 0x28(%r14), %rax
movq 0x20(%rax), %rcx
leaq 0x4233(%rip), %rsi      # 0x60a8
leaq 0x45a1(%rip), %rdx      # 0x641d
jmp 0x1e94
movq 0x28(%r14), %rax
movq 0x20(%rax), %rcx
leaq 0x421b(%rip), %rsi      # 0x60a8
leaq 0x45ac(%rip), %rdx      # 0x6440
xorl %ebx, %ebx
movq %r14, %rdi
xorl %eax, %eax
callq 0x1b8c
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x934b(%rip), %rax      # 0xb200
movq (%rax), %rdi
leaq 0x44f2(%rip), %rsi      # 0x63b1
leaq 0x4510(%rip), %rbx      # 0x63d6
leaq 0x451c(%rip), %r8       # 0x63e9
movq %rbx, %rdx
movl $0x34, %ecx
xorl %eax, %eax
callq 0x1120
leaq 0x44fd(%rip), %rdi      # 0x63e0
leaq 0x450d(%rip), %rcx      # 0x63f7
movq %rbx, %rsi
movl $0x34, %edx
callq 0x10e0
leaq 0x9302(%rip), %rax      # 0xb200
movq (%rax), %rdi
leaq 0x44a9(%rip), %rsi      # 0x63b1
leaq 0x44c7(%rip), %rbx      # 0x63d6
leaq 0x44d3(%rip), %r8       # 0x63e9
movq %rbx, %rdx
movl $0x67, %ecx
xorl %eax, %eax
callq 0x1120
leaq 0x44b4(%rip), %rdi      # 0x63e0
leaq 0x44c4(%rip), %rcx      # 0x63f7
movq %rbx, %rsi
movl $0x67, %edx
callq 0x10e0