// File: /workspace/github_c_makefile_star2_O3/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 0x3592
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 0x3584
cmpl $0x2, %eax
jne 0x3446
movl 0x10(%r13), %edi
callq 0x8e7b
movq 0x18(%r13), %rsi
movl %eax, %edi
callq 0x8ea1
movl %eax, -0x2c(%rbp)
movl 0x10(%r13), %edi
callq 0x8e7b
movl %eax, -0x30(%rbp)
jmp 0x3454
movl 0x10(%r13), %eax
movl %eax, -0x30(%rbp)
movl 0x28(%r13), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x2, 0xbec5(%rip)      # 0xf320
je 0x347d
leaq 0xbf24(%rip), %rax      # 0xf388
movq (%rax), %rsi
leaq 0x6b9e(%rip), %rdi      # 0xa00c
callq 0x20c0
movl $0x2, 0xbea3(%rip)      # 0xf320
cmpl $0x1, 0x24(%r13)
jne 0x34a0
leaq 0xbefd(%rip), %rax      # 0xf388
movq (%rax), %rdi
movq 0x8(%r13), %rdx
leaq 0x7146(%rip), %rsi      # 0xa5df
xorl %eax, %eax
callq 0x2100
leaq 0xbee1(%rip), %r15      # 0xf388
movq (%r15), %rdi
movq 0x8(%r13), %rdx
leaq 0x7136(%rip), %rsi      # 0xa5eb
xorl %eax, %eax
callq 0x2100
cmpl $0x0, 0x2c(%r13)
movl -0x2c(%rbp), %edx
jle 0x3584
leaq 0x714c(%rip), %r12      # 0xa61d
xorl %r14d, %r14d
movq %r13, %rbx
movq 0x30(%r13), %rax
testq %rax, %rax
je 0x34e9
movslq %r14d, %rcx
movl (%rax,%rcx,4), %r13d
jmp 0x34ec
xorl %r13d, %r13d
leaq 0x70fd(%rip), %rsi      # 0xa5f0
cmpl $0x1, %edx
je 0x3532
cmpl $0x4, %edx
je 0x352b
cmpl $0x8, %edx
jne 0x3550
testq %rax, %rax
je 0x3522
movl $0x20, %edi
callq 0x8e52
cmpl %eax, -0x30(%rbp)
jne 0x3522
leaq 0x70e9(%rip), %rsi      # 0xa606
testl %r13d, %r13d
jne 0x3532
leaq 0x70e9(%rip), %rsi      # 0xa612
jmp 0x3532
leaq 0x70c9(%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 0x34d4
jmp 0x3584
movl %edx, %r14d
testl %edx, %edx
jle 0x3579
movq (%r15), %rcx
movl $0x9, %esi
movl $0x1, %edx
movq %r12, %rdi
callq 0x2170
decl %r14d
jne 0x3557
movl -0x2c(%rbp), %edx
movl %edx, %r14d
jmp 0x3542
xorl %r14d, %r14d
movq %rbx, %r13
movl -0x2c(%rbp), %edx
jmp 0x3545
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq