// File: /workspace/github_cpp_makefile_star2_O2/rofl0r[P]ascc/cs_prepro.cpp
// Function: pre_process_directive(char*, FMEM*)
void pre_process_directive(char*dirpt,FMEM*outfl) {
	char *p, *shal=dirpt+1;
	while(is_whitespace(*shal)) ++shal;
	p = shal;
	// seek to the end of the first word (eg. #define)
	while ((!is_whitespace(shal[0])) && (shal[0]!=0)) shal++;
	// extract the directive name
	int shalwas = shal[0];
	shal[0] = 0;
	char dname[150];
	snprintf(dname, sizeof dname, "%s", p);
	ags_strlwr(dname);
	shal[0] = shalwas;

	// skip to the next word on the line
	skip_whitespace(&shal);

	// write a blank line to the output so that line numbers are correct
	fmem_puts("",outfl);

	size_t l = strlen(dname);
	while(l && strchr(" \t\r\n", dname[l-1])) dname[--l] = 0;

	int did = directive_to_id(dname);
	if(skip_conditional_block) switch(did) {
	case di_include: case di_error: case di_warning:
	case di_define: case di_undef:
	case di_line: case di_pragma:
		return;
	default: break;
	}
	switch(did) {
	case di_error:
		cc_error("User error: %s", shal);
		return;
	case di_define: {
		char nambit[100];
		int nin=0;
		while ((!isspace(shal[0])) && (shal[0]!=0)) {
			nambit[nin]=shal[0];
			nin++;
			shal++;
		}
		nambit[nin]=0;
		skip_whitespace(&shal);
		macros.add(nambit,shal);
		} break;
	case di_undef: {
		char macroToCheck[100];
		get_next_word(shal, macroToCheck);
		if (macroToCheck[0] == 0) {
			cc_error("Expected: macro");
			return;
		}

		int idx = macros.find_name(macroToCheck);
		if (idx < 0) {
			cc_error("'%s' not defined", macroToCheck);
			return;
		}

		macros.remove(idx);
		} break;
	case di_if:
		if(all_levels_active()) {
			int wantDefined = evaluate_if_statement(shal);
			set_level(if_level + 1, wantDefined);
		} else
			set_level(if_level + 1, 0);
		break;
	case di_elif:
		if(prev_level_active() && if_level_satisfied < if_level) {
			int wantDefined = evaluate_if_statement(shal);
			if(wantDefined) {
				if_level_active = if_level;
				if_level_satisfied = if_level;
			}
		} else if(if_level_active == if_level) {
			--if_level_active;
		}
		break;
	case di_else:
		if(prev_level_active() && if_level_satisfied < if_level) {
			if(1) {
				if_level_active = if_level;
				if_level_satisfied = if_level;
			}
		} else if(if_level_active == if_level) {
			--if_level_active;
		}
		break;
	case di_ifdef:
	case di_ifndef:
	case di_ifver:
	case di_ifnver: {
		int isVersionCheck = (did == di_ifver || did == di_ifnver);
		int wantDefined, neg = (did == di_ifndef || did == di_ifnver);

		char macroToCheck[100];
		get_next_word(shal, macroToCheck, true);

		if (macroToCheck[0] == 0) {
			cc_error("Expected token after space");
			return;
		}

		if ((isVersionCheck) && (!is_digit(macroToCheck[0]))) {
			cc_error("Expected version number");
			return;
		}

		if (isVersionCheck)
			wantDefined = (strcmp(ccSoftwareVersion, macroToCheck) >= 0);
		else
			wantDefined = macros.find_name(macroToCheck) >= 0;

		if (neg) wantDefined = !wantDefined;

		if(all_levels_active()) {
			set_level(if_level + 1, wantDefined);
		} else {
			set_level(if_level + 1, 0);
		}
		} break;
	case di_endif:
		if (if_level < 1) {
			cc_error("#endif without #if");
			return;
		}
		set_level(if_level-1, -1);
		break;
	case di_sectionstart:
	case di_sectionend:
		// do nothing - markers for the editor, just remove them
		break;
	default:
		cc_error("unknown/unimplemented preprocessor directive '%s'",dname);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x120, %rsp            # imm = 0x120
movq %rsi, %rbx
movq %rdi, %r14
movsbl 0x1(%r14), %edi
incq %r14
callq 0x126b4
testl %eax, %eax
jne 0x154b5
movq %r14, %rcx
movq %rcx, %r15
movq %rcx, 0x8(%rsp)
movsbl (%rcx), %edi
callq 0x126b4
leaq 0x1(%r15), %rcx
movb (%r15), %bpl
testl %eax, %eax
jne 0x154e9
testb %bpl, %bpl
jne 0x154c9
movb $0x0, -0x1(%rcx)
leaq 0x5220(%rip), %rdx      # 0x1a714
leaq 0x80(%rsp), %r15
movl $0x96, %esi
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x3500
movq %r15, %rdi
callq 0x132cc
leaq 0x8(%rsp), %rdi
movq (%rdi), %rax
movb %bpl, (%rax)
callq 0x126d2
leaq 0x5ccb(%rip), %rdi      # 0x1b1f8
movq %rbx, %rsi
callq 0x11cb6
movq %r15, %rdi
callq 0x3190
movq %rax, %rbx
leaq 0x5cad(%rip), %r14      # 0x1b1f4
pushq $0x5
popq %r15
movq %rax, %r12
subq $0x1, %r12
jb 0x15573
movsbl 0x7f(%rsp,%rbx), %esi
movq %r14, %rdi
movq %r15, %rdx
callq 0x3380
testq %rax, %rax
je 0x15573
movb $0x0, 0x7f(%rsp,%rbx)
movq %r12, %rbx
jmp 0x1554e
leaq 0xf786(%rip), %r12      # 0x24d00
xorl %r15d, %r15d
pushq $-0x1
popq %r14
leaq 0x80(%rsp), %rbx
cmpq $0x11, %r15
je 0x155ab
movq (%r12), %rsi
movq %rbx, %rdi
callq 0x1332e
testl %eax, %eax
je 0x155a8
incq %r15
addq $0x8, %r12
jmp 0x15589
movl %r15d, %r14d
movl 0x1bee7(%rip), %eax     # 0x31498
movl 0x1bee5(%rip), %ecx     # 0x3149c
cmpl %ecx, %eax
jle 0x155e5
cmpl $0x10, %r14d
ja 0x157ad
movl %r14d, %edx
leaq 0x5be1(%rip), %rsi      # 0x1b1b0
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
testl %eax, %eax
jg 0x15832
jmp 0x158d5
leal -0x1(%r14), %edx
cmpl $0xf, %edx
ja 0x157ad
leaq 0x5b77(%rip), %rsi      # 0x1b170
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rbx
pushq $0x1
popq %rdx
movq %rbx, %rsi
callq 0x15388
movsbl (%rbx), %edi
testl %edi, %edi
je 0x1564a
leal -0xf(%r14), %eax
cmpl $0x1, %eax
ja 0x15656
callq 0x126f7
testl %eax, %eax
je 0x158cc
leaq 0xfd3d(%rip), %rax      # 0x25378
movq (%rax), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3450
jmp 0x15667
leaq 0x5bd8(%rip), %rdi      # 0x1b229
jmp 0x158e5
leaq 0x16073(%rip), %rdi     # 0x2b6d0
leaq 0x10(%rsp), %rsi
callq 0x15314
testl %eax, %eax
setns %dl
cmpl $0x10, %r14d
je 0x15678
cmpl $0x9, %r14d
jne 0x1567d
shrl $0x1f, %eax
movl %eax, %edx
movl 0x1be19(%rip), %ecx     # 0x3149c
movl 0x1be0f(%rip), %eax     # 0x31498
cmpl %eax, %ecx
jne 0x156af
incl %ecx
cmpl %ecx, 0x1be0b(%rip)     # 0x314a0
jle 0x1569d
movl %ecx, 0x1be03(%rip)     # 0x314a0
testb %dl, %dl
je 0x156d6
movl %ecx, 0x1bdf5(%rip)     # 0x3149c
movl %ecx, 0x1bdf3(%rip)     # 0x314a0
jmp 0x156d6
leal 0x1(%rax), %edx
cmpl %edx, %ecx
jle 0x156be
movl %edx, 0x1bde0(%rip)     # 0x3149c
movl %edx, %ecx
cmpl %edx, 0x1bddc(%rip)     # 0x314a0
jle 0x156cc
movl %edx, 0x1bdd4(%rip)     # 0x314a0
cmpl %edx, %ecx
jne 0x156d6
movl %eax, 0x1bdc6(%rip)     # 0x3149c
incl %eax
movl %eax, 0x1bdba(%rip)     # 0x31498
jmp 0x15900
leal -0x1(%rax), %edx
cmpl %edx, %ecx
jne 0x1573b
cmpl %eax, 0x1bdb0(%rip)     # 0x314a0
jge 0x1573b
movq 0x8(%rsp), %rdi
callq 0x16cc5
testl %eax, %eax
je 0x15900
movl 0x1bd8e(%rip), %eax     # 0x31498
movl %eax, 0x1bd8c(%rip)     # 0x3149c
movl %eax, 0x1bd8a(%rip)     # 0x314a0
jmp 0x15900
leal -0x1(%rax), %edx
cmpl %edx, %ecx
jne 0x1573b
cmpl %eax, 0x1bd78(%rip)     # 0x314a0
jge 0x1573b
movl %eax, 0x1bd6c(%rip)     # 0x3149c
movl %eax, 0x1bd6a(%rip)     # 0x314a0
jmp 0x15900
cmpl %eax, %ecx
jne 0x15900
movl %edx, 0x1bd53(%rip)     # 0x3149c
jmp 0x15900
cmpl %eax, %ecx
jne 0x1589d
movq 0x8(%rsp), %rdi
callq 0x16cc5
movl 0x1bd36(%rip), %esi     # 0x3149c
movl 0x1bd2c(%rip), %edx     # 0x31498
leal 0x1(%rdx), %ecx
cmpl %ecx, %esi
jle 0x1577b
movl %ecx, 0x1bd23(%rip)     # 0x3149c
movl %ecx, %esi
cmpl %ecx, 0x1bd1f(%rip)     # 0x314a0
jle 0x15789
movl %ecx, 0x1bd17(%rip)     # 0x314a0
cmpl $-0x1, %eax
je 0x158fa
testl %eax, %eax
jne 0x158ee
cmpl %ecx, %esi
jne 0x158fa
movl %edx, 0x1bcf4(%rip)     # 0x3149c
jmp 0x158fa
leaq 0x5abb(%rip), %rdi      # 0x1b26f
leaq 0x80(%rsp), %rsi
jmp 0x15894
movq 0x8(%rsp), %r15
xorl %r14d, %r14d
movsbl (%r15,%r14), %ebx
movl %ebx, %edi
callq 0x3080
testl %ebx, %ebx
je 0x157f3
testl %eax, %eax
jne 0x157f3
movb %bl, 0x10(%rsp,%r14)
leaq (%r15,%r14), %rax
incq %rax
incq %r14
movq %rax, 0x8(%rsp)
jmp 0x157c9
movl %r14d, %eax
movb $0x0, 0x10(%rsp,%rax)
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x126d2
movq (%rbx), %rdx
leaq 0x15ebe(%rip), %rdi     # 0x2b6d0
leaq 0x10(%rsp), %rsi
callq 0x1522a
jmp 0x15900
testl %eax, %eax
jle 0x158d5
leal -0x1(%rax), %ecx
movl %ecx, 0x1bc6a(%rip)     # 0x3149c
leal -0x1(%rax), %ecx
cmpl %eax, 0x1bc65(%rip)     # 0x314a0
jge 0x158f4
jmp 0x158fa
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
xorl %edx, %edx
callq 0x15388
cmpb $0x0, (%rbx)
je 0x158de
leaq 0x15e6a(%rip), %rdi     # 0x2b6d0
leaq 0x10(%rsp), %rsi
callq 0x15314
testl %eax, %eax
js 0x15910
leaq 0x15e51(%rip), %rdi     # 0x2b6d0
movl %eax, %esi
callq 0x1535c
jmp 0x15900
movq 0x8(%rsp), %rsi
leaq 0x5965(%rip), %rdi      # 0x1b1f9
xorl %eax, %eax
callq 0xf258
jmp 0x15900
leal 0x1(%rax), %edx
cmpl %edx, %ecx
jle 0x158ac
movl %edx, 0x1bbf2(%rip)     # 0x3149c
movl %edx, %ecx
cmpl %edx, 0x1bbee(%rip)     # 0x314a0
jle 0x158ba
movl %edx, 0x1bbe6(%rip)     # 0x314a0
cmpl %edx, %ecx
jne 0x158c4
movl %eax, 0x1bbd8(%rip)     # 0x3149c
movl %edx, 0x1bbce(%rip)     # 0x31498
jmp 0x15900
leaq 0x5971(%rip), %rdi      # 0x1b244
jmp 0x158e5
leaq 0x5980(%rip), %rdi      # 0x1b25c
jmp 0x158e5
leaq 0x5923(%rip), %rdi      # 0x1b208
xorl %eax, %eax
callq 0xf258
jmp 0x15900
movl %ecx, 0x1bba8(%rip)     # 0x3149c
movl %ecx, 0x1bba6(%rip)     # 0x314a0
movl %ecx, 0x1bb98(%rip)     # 0x31498
addq $0x120, %rsp            # imm = 0x120
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5901(%rip), %rdi      # 0x1b218
leaq 0x10(%rsp), %rsi
jmp 0x15894