// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x37b8
jmp 0x39aa
movq -0x8(%rbp), %rax
cmpl $0x1, 0x20(%rax)
jne 0x37c7
jmp 0x39aa
movq -0x8(%rbp), %rax
cmpl $0x2, 0x20(%rax)
jne 0x3800
movq -0x8(%rbp), %rax
movl 0x10(%rax), %edi
callq 0xb780
movl %eax, %edi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0xb7c0
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %edi
callq 0xb780
movl %eax, -0x10(%rbp)
jmp 0x3814
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x10(%rbp)
callq 0x22b0
movq -0x8(%rbp), %rax
cmpl $0x1, 0x24(%rax)
jne 0x3843
leaq 0xecee(%rip), %rax      # 0x12518
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x8da3(%rip), %rsi      # 0xc5df
movb $0x0, %al
callq 0x20e0
leaq 0xecce(%rip), %rax      # 0x12518
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x8d8f(%rip), %rsi      # 0xc5eb
movb $0x0, %al
callq 0x20e0
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jge 0x39aa
movl $0x0, -0x14(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x389e
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x1c(%rbp)
subl $0x1, %eax
je 0x38c2
jmp 0x38ab
movl -0x1c(%rbp), %eax
subl $0x4, %eax
je 0x38e2
jmp 0x38b5
movl -0x1c(%rbp), %eax
subl $0x8, %eax
je 0x3902
jmp 0x3966
leaq 0xec4f(%rip), %rax      # 0x12518
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x8d1a(%rip), %rsi      # 0xc5f0
movb $0x0, %al
callq 0x20e0
jmp 0x399a
leaq 0xec2f(%rip), %rax      # 0x12518
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x8d05(%rip), %rsi      # 0xc5fb
movb $0x0, %al
callq 0x20e0
jmp 0x399a
movq -0x8(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x3949
movl -0x10(%rbp), %eax
movl %eax, -0x20(%rbp)
movl $0x20, %edi
callq 0xb740
movl %eax, %ecx
movl -0x20(%rbp), %eax
cmpl %ecx, %eax
jne 0x3949
cmpl $0x0, -0x14(%rbp)
je 0x3949
leaq 0xebe5(%rip), %rax      # 0x12518
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x8cc6(%rip), %rsi      # 0xc606
movb $0x0, %al
callq 0x20e0
jmp 0x3964
leaq 0xebc8(%rip), %rax      # 0x12518
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x8cb5(%rip), %rsi      # 0xc612
movb $0x0, %al
callq 0x20e0
jmp 0x399a
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x3998
leaq 0xeb9c(%rip), %rax      # 0x12518
movq (%rax), %rdi
leaq 0x8c97(%rip), %rsi      # 0xc61d
movb $0x0, %al
callq 0x20e0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x396d
jmp 0x399a
jmp 0x399c
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x386a
addq $0x20, %rsp
popq %rbp
retq