// File: /workspace/github_cpp_makefile_star2_O1/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
leaq 0x1(%rdi), %rax
movq %rax, 0x8(%rsp)
movsbl 0x1(%rdi), %edi
callq 0x13f40
testl %eax, %eax
je 0x171c1
movq 0x8(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rsp)
movsbl 0x1(%rax), %edi
jmp 0x171a4
movq 0x8(%rsp), %r14
movsbl (%r14), %edi
callq 0x13f40
testl %eax, %eax
jne 0x171ec
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
je 0x171ec
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rsp)
movsbl 0x1(%rax), %edi
jmp 0x171ca
leaq 0x8(%rsp), %r15
movq (%r15), %rax
movb (%rax), %bpl
movb $0x0, (%rax)
leaq 0x5533(%rip), %rdx      # 0x1c734
leaq 0x80(%rsp), %r12
movl $0x96, %esi
movq %r12, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x34f0
movq %r12, %rdi
callq 0x14ce4
movq (%r15), %rax
movb %bpl, (%rax)
movq %r15, %rdi
callq 0x13f60
leaq 0x5fb0(%rip), %rdi      # 0x1d1e8
movq %rbx, %rsi
callq 0x13473
movq %r12, %rdi
callq 0x31a0
testq %rax, %rax
je 0x17278
movq %rax, %rbx
leaq 0x5f8d(%rip), %r14      # 0x1d1e4
movsbl 0x7f(%rsp,%rbx), %esi
movl $0x5, %edx
movq %r14, %rdi
callq 0x3380
testq %rax, %rax
je 0x17278
movb $0x0, 0x7f(%rsp,%rbx)
decq %rbx
jne 0x17257
leaq 0xda81(%rip), %r15      # 0x24d00
xorl %r14d, %r14d
leaq 0x80(%rsp), %rbx
movq (%r15), %rsi
movq %rbx, %rdi
callq 0x14d56
testl %eax, %eax
je 0x172ac
incq %r14
addq $0x8, %r15
cmpq $0x11, %r14
jne 0x1728a
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl 0x1a1d6(%rip), %eax     # 0x31488
movl 0x1a1d4(%rip), %ecx     # 0x3148c
cmpl %ecx, %eax
jle 0x172d9
cmpl $0x10, %r14d
ja 0x1750a
movl %r14d, %edx
leaq 0x5ed0(%rip), %rsi      # 0x1d1a0
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
leal -0x1(%r14), %edx
cmpl $0xf, %edx
ja 0x1750a
leaq 0x5e73(%rip), %rsi      # 0x1d160
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
movl $0x1, %edx
callq 0x17080
movsbl (%rbx), %edi
testl %edi, %edi
je 0x17340
leal -0xf(%r14), %eax
cmpl $0x1, %eax
ja 0x1734c
callq 0x13f85
testl %eax, %eax
je 0x1761d
leaq 0xe047(%rip), %rax      # 0x25378
movq (%rax), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3450
jmp 0x1735d
leaq 0x5ed2(%rip), %rdi      # 0x1d219
jmp 0x17636
leaq 0x1436d(%rip), %rdi     # 0x2b6c0
leaq 0x10(%rsp), %rsi
callq 0x17008
testl %eax, %eax
setns %dl
cmpl $0x10, %r14d
je 0x1736e
cmpl $0x9, %r14d
jne 0x17373
shrl $0x1f, %eax
movl %eax, %edx
movl 0x1a113(%rip), %esi     # 0x3148c
movl 0x1a109(%rip), %eax     # 0x31488
leal 0x1(%rax), %ecx
cmpl %eax, %esi
jne 0x173ce
cmpl %ecx, %esi
jle 0x17390
movl %ecx, 0x1a0fc(%rip)     # 0x3148c
cmpl %ecx, 0x1a0fa(%rip)     # 0x31490
jle 0x1739e
movl %ecx, 0x1a0f2(%rip)     # 0x31490
movl %ecx, %esi
testb %dl, %dl
jne 0x173ae
movl %eax, %esi
cmpl %ecx, 0x1a0e0(%rip)     # 0x3148c
jne 0x173b4
movl %esi, 0x1a0d8(%rip)     # 0x3148c
cmpl %ecx, 0x1a0d2(%rip)     # 0x3148c
sete %sil
andb %sil, %dl
cmpb $0x1, %dl
jne 0x173f4
movl %ecx, 0x1a0c4(%rip)     # 0x31490
jmp 0x173f4
cmpl %ecx, %esi
jle 0x173d8
movl %ecx, 0x1a0b4(%rip)     # 0x3148c
cmpl %ecx, 0x1a0b2(%rip)     # 0x31490
jle 0x173e6
movl %ecx, 0x1a0aa(%rip)     # 0x31490
cmpl %ecx, 0x1a0a0(%rip)     # 0x3148c
jne 0x173f4
movl %eax, 0x1a098(%rip)     # 0x3148c
incl %eax
jmp 0x17490
leal -0x1(%rax), %edx
cmpl %edx, %ecx
jne 0x17453
cmpl %eax, 0x1a088(%rip)     # 0x31490
jge 0x17453
movq 0x8(%rsp), %rdi
callq 0x18d25
testl %eax, %eax
je 0x1763d
movl 0x1a066(%rip), %eax     # 0x31488
movl %eax, 0x1a064(%rip)     # 0x3148c
movl %eax, 0x1a062(%rip)     # 0x31490
jmp 0x1763d
leal -0x1(%rax), %edx
cmpl %edx, %ecx
jne 0x17453
cmpl %eax, 0x1a050(%rip)     # 0x31490
jge 0x17453
movl %eax, 0x1a044(%rip)     # 0x3148c
movl %eax, 0x1a042(%rip)     # 0x31490
jmp 0x1763d
cmpl %eax, %ecx
jne 0x1763d
decl %ecx
movl %ecx, 0x1a029(%rip)     # 0x3148c
jmp 0x1763d
testl %eax, %eax
jle 0x17626
cmpl %ecx, %eax
jg 0x1747d
leal -0x1(%rax), %ecx
movl %ecx, 0x1a00f(%rip)     # 0x3148c
cmpl %eax, 0x1a00d(%rip)     # 0x31490
jl 0x1748e
leal -0x1(%rax), %ecx
movl %ecx, 0x1a002(%rip)     # 0x31490
decl %eax
movl %eax, 0x19ff2(%rip)     # 0x31488
jmp 0x1763d
cmpl %eax, %ecx
jne 0x175ec
movq 0x8(%rsp), %rdi
callq 0x18d25
movl 0x19fd5(%rip), %edx     # 0x31488
leal 0x1(%rdx), %ecx
cmpl %ecx, 0x19fd0(%rip)     # 0x3148c
jle 0x174c4
movl %ecx, 0x19fc8(%rip)     # 0x3148c
cmpl %ecx, 0x19fc6(%rip)     # 0x31490
jle 0x174d2
movl %ecx, 0x19fbe(%rip)     # 0x31490
cmpl $-0x1, %eax
je 0x174ff
movl %ecx, %esi
testl %eax, %eax
jne 0x174e7
movl %edx, %esi
cmpl %ecx, 0x19fa7(%rip)     # 0x3148c
jne 0x174ed
movl %esi, 0x19f9f(%rip)     # 0x3148c
testl %eax, %eax
je 0x174ff
cmpl %ecx, 0x19f95(%rip)     # 0x3148c
jne 0x174ff
movl %ecx, 0x19f91(%rip)     # 0x31490
movl %ecx, 0x19f83(%rip)     # 0x31488
jmp 0x1763d
leaq 0x5d4e(%rip), %rdi      # 0x1d25f
leaq 0x80(%rsp), %rsi
jmp 0x17527
movq 0x8(%rsp), %rsi
leaq 0x5cc2(%rip), %rdi      # 0x1d1e9
xorl %eax, %eax
callq 0x10418
jmp 0x1763d
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
xorl %edx, %edx
callq 0x17080
cmpb $0x0, (%rbx)
je 0x1762f
leaq 0x14169(%rip), %rdi     # 0x2b6c0
leaq 0x10(%rsp), %rsi
callq 0x17008
testl %eax, %eax
js 0x1764d
leaq 0x14150(%rip), %rdi     # 0x2b6c0
movl %eax, %esi
callq 0x17052
jmp 0x1763d
movq 0x8(%rsp), %r14
movsbl (%r14), %ebx
movl %ebx, %edi
callq 0x3090
xorl %ecx, %ecx
testl %ebx, %ebx
je 0x175c4
testl %eax, %eax
jne 0x175c4
incq %r14
xorl %r15d, %r15d
movb %bl, 0x10(%rsp,%r15)
leaq (%r14,%r15), %rax
movq %rax, 0x8(%rsp)
movsbl (%r14,%r15), %ebx
incq %r15
movl %ebx, %edi
callq 0x3090
testl %ebx, %ebx
je 0x175c1
testl %eax, %eax
je 0x1759c
movl %r15d, %ecx
movb $0x0, 0x10(%rsp,%rcx)
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x13f60
movq (%rbx), %rdx
leaq 0x140e0(%rip), %rdi     # 0x2b6c0
leaq 0x10(%rsp), %rsi
callq 0x16f0e
jmp 0x1763d
leal 0x1(%rax), %edx
cmpl %edx, %ecx
jle 0x175f9
movl %edx, 0x19e93(%rip)     # 0x3148c
cmpl %edx, 0x19e91(%rip)     # 0x31490
jle 0x17607
movl %edx, 0x19e89(%rip)     # 0x31490
cmpl %edx, 0x19e7f(%rip)     # 0x3148c
jne 0x17615
movl %eax, 0x19e77(%rip)     # 0x3148c
movl %edx, 0x19e6d(%rip)     # 0x31488
jmp 0x1763d
leaq 0x5c10(%rip), %rdi      # 0x1d234
jmp 0x17636
leaq 0x5c1f(%rip), %rdi      # 0x1d24c
jmp 0x17636
leaq 0x5bc2(%rip), %rdi      # 0x1d1f8
xorl %eax, %eax
callq 0x10418
addq $0x120, %rsp            # imm = 0x120
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5bb4(%rip), %rdi      # 0x1d208
leaq 0x10(%rsp), %rsi
jmp 0x17527