// File: /workspace/github_c_makefile_star2_O2/nimble-code[P]Modex/Src/xtract.c
// Function: do_globals
void
do_globals(int setup, scopetab_t *that, int lastcall)
{	Fcts *g;
	char *z;
	FILE *fd;
	NameL *nl;

	if (suppress)
	{	return;
	}

	if (Verbose_cmds)
	{	printf("-- do globals [%d %d %d %s]\n", setup, do_inc_globals, allprocs, globfilename);
	}

	if (setup)
	{	setglobfile();
		if (do_inc_globals && allprocs)
		{	sprintf(tbuf, "#include \"%s\"	/* global header file */\n\n",
				globfilename);
			vis_direct(tbuf);
		}	/*  else created but not #include'd */
		return;
	}
	if (!globfilename)	/* no functions matched, user forgot -x */
	{	setglobfile();
	}

	#ifdef PC
		#define AFLAGS	"ab"
	#else
		#define AFLAGS	"a"
	#endif

	if ((fd = fopen(globfilename, AFLAGS)) == NULL)
	{	fprintf(stderr, "%s: error, cannot create global header file %s\n",
			progname, globfilename);
		return;
	}
if (debug_io) fprintf(stderr, ":: open %s -> %p\n", globfilename, fd);
	add_fnm(globfilename);

	fprintf(fd, "/** globals **/\n\n");

	do_constants(fd);
	fprintf(fd, "/** done with constants... **/\n\n");

	for (g = modex_globals; g; g = g->nxt)
	{
		if (strlen(g->full?g->full:g->nm) == 0)
			continue;

		if (!imported(g->nm, "Global", 1))
			continue;

		if (g->purged)
		{	continue;
		}
		g->purged = 1;

		if (0)
		printf("nm %s, dt %s, full %s\n", g->nm, g->dt, g->full);

		if ((z = spintype(g->dt, g->full?g->full:g->nm)) != NULL)
		{	sprintf(tbuf, "%s %s;\t/* derived <%s> */\n",
				z, g->full?g->full:g->nm, g->nm);
		} else if (strstr(g->dt, "typedef"))
		{	continue;
		} else
		{	z = checkfull(g->dt, g->full, g->lno);
			cleanse(g->dt);

			if (du_mode)
			{	char *yy, *y = g->full?g->full:g->nm;
				while (*y == '*' || *y == ' ' || *y == '\t')
					y++;
				if ((yy = strstr(y, "[]")) != NULL)
				{	*yy = '\0';
				}
				sprintf(tbuf, "int %s;	/* global */\n", y);
			} else
			{	if (z)
				sprintf(tbuf, " c_state \"%s %s\" \"Global\" \"%s\"\n",
					g->dt, g->full?g->full:g->nm, z);
				else
				sprintf(tbuf, " c_state \"%s %s\" \"Global\"\n",
					g->dt, g->full?g->full:g->nm);
		}	}
		fprintf(fd, "%s", tbuf);
	}

	for (nl = globchans; nl; nl = nl->nxt)
	{
		if (nl->purged)
		{	continue;
		}
		nl->purged = 1;

		fprintf(fd, "%s\n", nl->nm);
	}

	add_nomap_locals(fd);
	do_externals(fd);

	do_hidden(fd);			/* hidden vars */
	if (that)
	{	x_scopetab(that, fd, want);	/* extra c_state decls */
	}

	if (i_assert)
	{	ax_doprops(fd, that);
	}

	if (that && !nostructs)	/* import global structure declarations */
	{
		if (lastcall)				/* new 2.8 */
		{	find_typedefs(that, fd);	/* new 2.6 */
			put_structs(that, fd);
	}	}
if (debug_io) fprintf(stderr, "close z %p\n", fd);
	Fclose(fd);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x2a0c0(%rip), %rax     # 0x36cc0
cmpl $0x0, (%rax)
je 0xcc14
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %edx, %ebp
movq %rsi, %rbx
movl %edi, %r14d
leaq 0x29df9(%rip), %rax     # 0x36a1c
cmpl $0x0, (%rax)
je 0xcc52
leaq 0x275c1(%rip), %rax     # 0x341f0
movl (%rax), %edx
leaq 0x29e30(%rip), %rax     # 0x36a68
movl (%rax), %ecx
movq 0x2e9af(%rip), %r8      # 0x3b5f0
leaq 0x15642(%rip), %rdi     # 0x2228a
movl %r14d, %esi
xorl %eax, %eax
callq 0x4140
testl %r14d, %r14d
je 0xccb2
leaq 0x15622(%rip), %rax     # 0x22280
movq %rax, 0x2e98b(%rip)     # 0x3b5f0
leaq 0x27584(%rip), %rax     # 0x341f0
cmpl $0x0, (%rax)
je 0xcc05
leaq 0x29df0(%rip), %rax     # 0x36a68
cmpl $0x0, (%rax)
je 0xcc05
leaq 0x2e97c(%rip), %rbx     # 0x3b600
leaq 0x1561c(%rip), %rsi     # 0x222a7
leaq 0x155ee(%rip), %rdx     # 0x22280
movq %rbx, %rdi
xorl %eax, %eax
callq 0x42a0
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd07c
movq 0x2e937(%rip), %rdi     # 0x3b5f0
testq %rdi, %rdi
jne 0xcccc
leaq 0x155bb(%rip), %rdi     # 0x22280
movq %rdi, 0x2e924(%rip)     # 0x3b5f0
leaq 0x14b8a(%rip), %rsi     # 0x2185d
callq 0x4270
testq %rax, %rax
je 0xcffe
movq %rax, %r14
movl %ebp, 0x4(%rsp)
movq %rbx, 0x10(%rsp)
leaq 0x29d24(%rip), %rax     # 0x36a18
cmpl $0x0, (%rax)
jne 0xd035
movq 0x2e8ec(%rip), %rdi     # 0x3b5f0
callq 0xcb92
leaq 0x15602(%rip), %rdi     # 0x22312
pushq $0x11
popq %rsi
pushq $0x1
popq %r15
movq %r15, %rdx
movq %r14, %rcx
callq 0x42c0
movq %r14, %rdi
callq 0x57b2
leaq 0x155f3(%rip), %rdi     # 0x22324
pushq $0x20
popq %rsi
movq %r15, %rdx
movq %r14, 0x8(%rsp)
movq %r14, %rcx
callq 0x42c0
leaq 0x2c67d(%rip), %rbx     # 0x393c8
leaq 0x13364(%rip), %rbp     # 0x200b6
pushq $0x1
popq %r12
leaq 0x2e8a3(%rip), %r15     # 0x3b600
movq (%rbx), %rbx
testq %rbx, %rbx
je 0xceec
movq 0x18(%rbx), %rax
testq %rax, %rax
jne 0xcd75
movq (%rbx), %rax
cmpb $0x0, (%rax)
je 0xce25
movq (%rbx), %rdi
movq %rbp, %rsi
movl %r12d, %edx
callq 0xcaf8
testl %eax, %eax
je 0xce25
cmpl $0x0, 0x20(%rbx)
jne 0xce25
movl %r12d, %r14d
movq %rbp, %r12
movl $0x1, 0x20(%rbx)
movq 0x18(%rbx), %r13
movq %r13, %rsi
testq %r13, %r13
jne 0xcdba
movq (%rbx), %rsi
movq 0x10(%rbx), %rbp
movq %rbp, %rdi
callq 0xc486
testq %rax, %rax
je 0xce01
testq %r13, %r13
movq (%rbx), %r8
cmoveq %r8, %r13
movq %r15, %rdi
leaq 0x15566(%rip), %rsi     # 0x22345
movq %rax, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x42a0
movq %r12, %rbp
movl %r14d, %r12d
movq %r15, %rdi
movq 0x8(%rsp), %rsi
callq 0x4170
jmp 0xce25
movq %rbp, %rdi
leaq 0x15269(%rip), %rsi     # 0x22074
callq 0x42d0
testq %rax, %rax
movq %r12, %rbp
movl %r14d, %r12d
movabsq $0x40100000200, %r14    # imm = 0x40100000200
je 0xce2e
addq $0x38, %rbx
jmp 0xcd5d
movq %r13, %rsi
callq 0xc786
movq %rax, %r13
movq 0x10(%rbx), %rdi
callq 0xc831
leaq 0x29c0f(%rip), %rax     # 0x36a58
cmpl $0x0, (%rax)
je 0xcea0
movq 0x18(%rbx), %r13
testq %r13, %r13
jne 0xce5a
movq (%rbx), %r13
movzbl (%r13), %eax
cmpq $0x2a, %rax
ja 0xce70
btq %rax, %r14
jae 0xce70
incq %r13
jmp 0xce5a
movq %r13, %rdi
leaq 0x132a5(%rip), %rsi     # 0x2011f
callq 0x42d0
testq %rax, %rax
je 0xce87
movb $0x0, (%rax)
movq %r15, %rdi
leaq 0x154cf(%rip), %rsi     # 0x22360
movq %r13, %rdx
xorl %eax, %eax
callq 0x42a0
jmp 0xcdf2
movq 0x10(%rbx), %rdx
movq 0x18(%rbx), %rcx
testq %r13, %r13
je 0xcece
testq %rcx, %rcx
jne 0xceb5
movq (%rbx), %rcx
movq %r15, %rdi
leaq 0x154b7(%rip), %rsi     # 0x22376
movq %r13, %r8
xorl %eax, %eax
callq 0x42a0
jmp 0xcdf2
testq %rcx, %rcx
jne 0xced6
movq (%rbx), %rcx
movq %r15, %rdi
leaq 0x154b6(%rip), %rsi     # 0x22396
xorl %eax, %eax
callq 0x42a0
jmp 0xcdf2
leaq 0x2f78d(%rip), %rbx     # 0x3c680
leaq 0x15382(%rip), %r15     # 0x2227c
movq 0x8(%rsp), %r14
movq (%rbx), %rbx
testq %rbx, %rbx
je 0xcf2a
cmpl $0x0, 0x8(%rbx)
jne 0xcf24
movl $0x1, 0x8(%rbx)
movq (%rbx), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x41c0
addq $0x10, %rbx
jmp 0xceff
movq %r14, %rdi
callq 0xc872
leaq 0x2fb6f(%rip), %rbx     # 0x3caa8
leaq 0x164ff(%rip), %r15     # 0x2343f
movq (%rbx), %rbx
testq %rbx, %rbx
je 0xcf6f
cmpl $0x0, 0x18(%rbx)
jne 0xcf69
movl $0x1, 0x18(%rbx)
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x41c0
addq $0x20, %rbx
jmp 0xcf40
movq %r14, %rdi
callq 0xc581
movq 0x10(%rsp), %rbx
testq %rbx, %rbx
je 0xcf96
leaq 0x27220(%rip), %rax     # 0x341a8
movq (%rax), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd0f3
leaq 0x2725b(%rip), %rax     # 0x341f8
cmpl $0x0, (%rax)
movl 0x4(%rsp), %ebp
je 0xcfb1
movq %r14, %rdi
movq %rbx, %rsi
callq 0xd181
testl %ebp, %ebp
je 0xcfdc
testq %rbx, %rbx
je 0xcfdc
leaq 0x29a87(%rip), %rax     # 0x36a48
cmpl $0x0, (%rax)
jne 0xcfdc
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5022
movq %rbx, %rdi
movq %r14, %rsi
callq 0x514d
leaq 0x29a35(%rip), %rax     # 0x36a18
cmpl $0x0, (%rax)
jne 0xd05c
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x59e0
movq 0x26ff3(%rip), %rax     # 0x33ff8
movq (%rax), %rdi
leaq 0x27191(%rip), %rax     # 0x341a0
movq (%rax), %rdx
movq 0x2e5d7(%rip), %rcx     # 0x3b5f0
leaq 0x152b0(%rip), %rsi     # 0x222d0
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x41c0
movq 0x26fbc(%rip), %rax     # 0x33ff8
movq (%rax), %rdi
movq 0x2e5aa(%rip), %rdx     # 0x3b5f0
leaq 0x152b3(%rip), %rsi     # 0x22300
movq %r14, %rcx
xorl %eax, %eax
callq 0x41c0
jmp 0xccfd
movq 0x26f95(%rip), %rax     # 0x33ff8
movq (%rax), %rdi
leaq 0x15344(%rip), %rsi     # 0x223b1
movq %r14, %rdx
xorl %eax, %eax
callq 0x41c0
jmp 0xcfe8