// File: /workspace/github_c_makefile_star2_O1/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 0x3571
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r13
movl 0x20(%rdi), %eax
cmpl $0x1, %eax
je 0x3563
cmpl $0x2, %eax
jne 0x3425
movl 0x10(%r13), %edi
callq 0x8e03
movq 0x18(%r13), %rsi
movl %eax, %edi
callq 0x8e29
movl %eax, -0x2c(%rbp)
movl 0x10(%r13), %edi
callq 0x8e03
movl %eax, -0x30(%rbp)
jmp 0x3433
movl 0x10(%r13), %eax
movl %eax, -0x30(%rbp)
movl 0x28(%r13), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x2, 0xbee6(%rip)      # 0xf320
je 0x345c
leaq 0xbf45(%rip), %rax      # 0xf388
movq (%rax), %rsi
leaq 0x6bbf(%rip), %rdi      # 0xa00c
callq 0x20c0
movl $0x2, 0xbec4(%rip)      # 0xf320
cmpl $0x1, 0x24(%r13)
jne 0x347f
leaq 0xbf1e(%rip), %rax      # 0xf388
movq (%rax), %rdi
movq 0x8(%r13), %rdx
leaq 0x7167(%rip), %rsi      # 0xa5df
xorl %eax, %eax
callq 0x2100
leaq 0xbf02(%rip), %r15      # 0xf388
movq (%r15), %rdi
movq 0x8(%r13), %rdx
leaq 0x7157(%rip), %rsi      # 0xa5eb
xorl %eax, %eax
callq 0x2100
cmpl $0x0, 0x2c(%r13)
movl -0x2c(%rbp), %edx
jle 0x3563
leaq 0x716d(%rip), %r12      # 0xa61d
xorl %r14d, %r14d
movq %r13, %rbx
movq 0x30(%r13), %rax
testq %rax, %rax
je 0x34c8
movslq %r14d, %rcx
movl (%rax,%rcx,4), %r13d
jmp 0x34cb
xorl %r13d, %r13d
leaq 0x711e(%rip), %rsi      # 0xa5f0
cmpl $0x1, %edx
je 0x3511
cmpl $0x4, %edx
je 0x350a
cmpl $0x8, %edx
jne 0x352f
testq %rax, %rax
je 0x3501
movl $0x20, %edi
callq 0x8dda
cmpl %eax, -0x30(%rbp)
jne 0x3501
leaq 0x710a(%rip), %rsi      # 0xa606
testl %r13d, %r13d
jne 0x3511
leaq 0x710a(%rip), %rsi      # 0xa612
jmp 0x3511
leaq 0x70ea(%rip), %rsi      # 0xa5fb
movq (%r15), %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x2100
movl -0x2c(%rbp), %edx
movq %rbx, %r13
incl %r14d
cmpl 0x2c(%r13), %r14d
jl 0x34b3
jmp 0x3563
movl %edx, %r14d
testl %edx, %edx
jle 0x3558
movq (%r15), %rcx
movl $0x9, %esi
movl $0x1, %edx
movq %r12, %rdi
callq 0x2170
decl %r14d
jne 0x3536
movl -0x2c(%rbp), %edx
movl %edx, %r14d
jmp 0x3521
xorl %r14d, %r14d
movq %rbx, %r13
movl -0x2c(%rbp), %edx
jmp 0x3524
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq