// File: /workspace/github_c_makefile_star2_O2/ejunjsh[P]mycc/cg.c
// Function: cgglobsym
void cgglobsym(struct symtable *node) {
  int size, type;
  int initvalue;
  int i;

  if (node == NULL)
    return;
  if (node->stype == S_FUNCTION)
    return;

  // 获取变量（数组元素）的大小
  // 和变量的类型
  if (node->stype == S_ARRAY) {
    size = typesize(value_at(node->type), node->ctype);
    type = value_at(node->type);
  } else {
    size = node->size;
    type = node->type;
  }

  // 生成全局标识和标签
  cgdataseg();
  if (node->class == C_GLOBAL)
    fprintf(Outfile, "\t.globl\t%s\n", node->name);
  fprintf(Outfile, "%s:\n", node->name);

  // 输出一个或者更多元素的空间
  for (i = 0; i < node->nelems; i++) {

    // 初始值
    initvalue = 0;
    if (node->initlist != NULL)
      initvalue = node->initlist[i];

    // 生成这个类型的空间
    switch (size) {
    case 1:
      fprintf(Outfile, "\t.byte\t%d\n", initvalue);
      break;
    case 4:
      fprintf(Outfile, "\t.long\t%d\n", initvalue);
      break;
    case 8:
      // 生成指向字符串字面量的指针，对于0值，就是真的0，而不是标签L0
      if (node->initlist != NULL && type == pointer_to(P_CHAR) && initvalue != 0)
	      fprintf(Outfile, "\t.quad\tL%d\n", initvalue);
      else
      	fprintf(Outfile, "\t.quad\t%d\n", initvalue);
      break;
    default:
      for (i = 0; i < size; i++)
	      fprintf(Outfile, "\t.byte\t0\n");
    }
  }
}

// Assembly:
testq %rdi, %rdi
je 0x333b
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movl 0x20(%rdi), %eax
cmpl $0x1, %eax
je 0x332d
cmpl $0x2, %eax
jne 0x3207
movl 0x10(%r14), %edi
callq 0x877b
movq 0x18(%r14), %rsi
movl %eax, %edi
callq 0x87a1
movl %eax, %ebx
movl 0x10(%r14), %edi
callq 0x877b
movl %eax, -0x2c(%rbp)
jmp 0x3212
movl 0x10(%r14), %eax
movl %eax, -0x2c(%rbp)
movl 0x28(%r14), %ebx
callq 0x22eb
cmpl $0x1, 0x24(%r14)
jne 0x323a
leaq 0xb163(%rip), %rax      # 0xe388
movq (%rax), %rdi
movq 0x8(%r14), %rdx
leaq 0x63ac(%rip), %rsi      # 0x95df
xorl %eax, %eax
callq 0x2100
leaq 0xb147(%rip), %rax      # 0xe388
movq (%rax), %rdi
movq 0x8(%r14), %rdx
leaq 0x639c(%rip), %rsi      # 0x95eb
xorl %eax, %eax
callq 0x2100
testl %ebx, %ebx
movl $0x0, %eax
movl %ebx, -0x34(%rbp)
cmovgl %ebx, %eax
movl %eax, -0x30(%rbp)
leaq 0x63b0(%rip), %r13      # 0x961d
pushq $0x9
popq %r12
pushq $0x1
popq %r15
xorl %ebx, %ebx
movq %r14, -0x40(%rbp)
cmpl 0x2c(%r14), %ebx
jge 0x332d
movq 0x30(%r14), %rax
testq %rax, %rax
je 0x3295
movl %ebx, %ecx
movl (%rax,%rcx,4), %edx
jmp 0x3297
xorl %edx, %edx
leaq 0x6352(%rip), %rsi      # 0x95f0
cmpl $0x1, -0x34(%rbp)
je 0x330c
movl -0x34(%rbp), %ecx
cmpl $0x4, %ecx
je 0x3305
movl -0x30(%rbp), %r14d
cmpl $0x8, %ecx
jne 0x32e5
testq %rax, %rax
movq -0x40(%rbp), %r14
je 0x32dc
pushq $0x20
popq %rdi
movl %edx, -0x38(%rbp)
callq 0x8752
movl -0x38(%rbp), %edx
cmpl %eax, -0x2c(%rbp)
jne 0x32dc
leaq 0x632e(%rip), %rsi      # 0x9606
testl %edx, %edx
jne 0x330c
leaq 0x632f(%rip), %rsi      # 0x9612
jmp 0x330c
subl $0x1, %r14d
jb 0x331f
leaq 0xb096(%rip), %rax      # 0xe388
movq (%rax), %rcx
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x2180
jmp 0x32e5
leaq 0x62ef(%rip), %rsi      # 0x95fb
leaq 0xb075(%rip), %rax      # 0xe388
movq (%rax), %rdi
xorl %eax, %eax
callq 0x2100
jmp 0x3326
movl -0x30(%rbp), %ebx
movq -0x40(%rbp), %r14
incl %ebx
jmp 0x327b
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq