// File: /workspace/github_cpp_makefile_star2_O3/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 %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %rbx
movq %rdi, %r14
incq %r14
movsbl (%r14), %edi
callq 0x13dc8
incq %r14
testl %eax, %eax
jne 0x16f5f
leaq -0x1(%r14), %r15
movq %r15, 0x8(%rsp)
movsbl -0x1(%r14), %edi
callq 0x13dc8
movq %r15, %rcx
testl %eax, %eax
jne 0x16fad
jmp 0x16fa0
movq %r14, 0x8(%rsp)
movsbl (%r14), %edi
callq 0x13dc8
incq %r14
testl %eax, %eax
jne 0x16fa7
cmpb $0x0, -0x1(%r14)
jne 0x16f8b
decq %r14
movq %r14, %rcx
movb (%rcx), %bpl
movb $0x0, (%rcx)
leaq 0x577a(%rip), %rdx      # 0x1c734
leaq 0x80(%rsp), %r14
movl $0x96, %esi
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x34f0
movq %r14, %rdi
callq 0x14b58
leaq 0x8(%rsp), %rdi
movq (%rdi), %rax
movb %bpl, (%rax)
callq 0x13de8
leaq 0x61f5(%rip), %rdi      # 0x1d1e8
movq %rbx, %rsi
callq 0x132db
movq %r14, %rdi
callq 0x31a0
testq %rax, %rax
je 0x17033
movq %rax, %rbx
leaq 0x61d2(%rip), %r14      # 0x1d1e4
movsbl 0x7f(%rsp,%rbx), %esi
movl $0x5, %edx
movq %r14, %rdi
callq 0x3380
testq %rax, %rax
je 0x17033
movb $0x0, 0x7f(%rsp,%rbx)
decq %rbx
jne 0x17012
leaq 0xdcc6(%rip), %r15      # 0x24d00
xorl %r14d, %r14d
leaq 0x80(%rsp), %rbx
movq (%r15), %rsi
movq %rbx, %rdi
callq 0x14bca
testl %eax, %eax
je 0x17067
incq %r14
addq $0x8, %r15
cmpq $0x11, %r14
jne 0x17045
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl 0x1a41b(%rip), %eax     # 0x31488
movl 0x1a419(%rip), %ecx     # 0x3148c
cmpl %ecx, %eax
jle 0x170a1
cmpl $0x10, %r14d
ja 0x1726b
movl %r14d, %edx
leaq 0x6115(%rip), %rsi      # 0x1d1a0
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
testl %eax, %eax
jg 0x17303
jmp 0x173a6
leal -0x1(%r14), %edx
cmpl $0xf, %edx
ja 0x1726b
leaq 0x60ab(%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 0x16e3c
movsbl (%rbx), %edi
testl %edi, %edi
je 0x17108
leal -0xf(%r14), %eax
cmpl $0x1, %eax
ja 0x17114
callq 0x13e0d
testl %eax, %eax
je 0x1739d
leaq 0xe27f(%rip), %rax      # 0x25378
movq (%rax), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3450
jmp 0x17125
leaq 0x610a(%rip), %rdi      # 0x1d219
jmp 0x173b6
leaq 0x145a5(%rip), %rdi     # 0x2b6c0
leaq 0x10(%rsp), %rsi
callq 0x16dc4
testl %eax, %eax
setns %dl
cmpl $0x10, %r14d
je 0x17136
cmpl $0x9, %r14d
jne 0x1713b
shrl $0x1f, %eax
movl %eax, %edx
movl 0x1a34b(%rip), %ecx     # 0x3148c
movl 0x1a341(%rip), %eax     # 0x31488
cmpl %eax, %ecx
jne 0x1716d
incl %ecx
cmpl %ecx, 0x1a33d(%rip)     # 0x31490
jle 0x1715b
movl %ecx, 0x1a335(%rip)     # 0x31490
testb %dl, %dl
je 0x17194
movl %ecx, 0x1a327(%rip)     # 0x3148c
movl %ecx, 0x1a325(%rip)     # 0x31490
jmp 0x17194
leal 0x1(%rax), %edx
cmpl %edx, %ecx
jle 0x1717c
movl %edx, 0x1a312(%rip)     # 0x3148c
movl %edx, %ecx
cmpl %edx, 0x1a30e(%rip)     # 0x31490
jle 0x1718a
movl %edx, 0x1a306(%rip)     # 0x31490
cmpl %edx, %ecx
jne 0x17194
movl %eax, 0x1a2f8(%rip)     # 0x3148c
incl %eax
movl %eax, 0x1a2ec(%rip)     # 0x31488
jmp 0x173d1
leal -0x1(%rax), %edx
cmpl %edx, %ecx
jne 0x171f9
cmpl %eax, 0x1a2e2(%rip)     # 0x31490
jge 0x171f9
movq 0x8(%rsp), %rdi
callq 0x189b1
testl %eax, %eax
je 0x173d1
movl 0x1a2c0(%rip), %eax     # 0x31488
movl %eax, 0x1a2be(%rip)     # 0x3148c
movl %eax, 0x1a2bc(%rip)     # 0x31490
jmp 0x173d1
leal -0x1(%rax), %edx
cmpl %edx, %ecx
jne 0x171f9
cmpl %eax, 0x1a2aa(%rip)     # 0x31490
jge 0x171f9
movl %eax, 0x1a29e(%rip)     # 0x3148c
movl %eax, 0x1a29c(%rip)     # 0x31490
jmp 0x173d1
cmpl %eax, %ecx
jne 0x173d1
movl %edx, 0x1a285(%rip)     # 0x3148c
jmp 0x173d1
cmpl %eax, %ecx
jne 0x1736e
movq 0x8(%rsp), %rdi
callq 0x189b1
movl 0x1a268(%rip), %esi     # 0x3148c
movl 0x1a25e(%rip), %edx     # 0x31488
leal 0x1(%rdx), %ecx
cmpl %ecx, %esi
jle 0x17239
movl %ecx, 0x1a255(%rip)     # 0x3148c
movl %ecx, %esi
cmpl %ecx, 0x1a251(%rip)     # 0x31490
jle 0x17247
movl %ecx, 0x1a249(%rip)     # 0x31490
cmpl $-0x1, %eax
je 0x173cb
testl %eax, %eax
jne 0x173bf
cmpl %ecx, %esi
jne 0x173cb
movl %edx, 0x1a226(%rip)     # 0x3148c
jmp 0x173cb
leaq 0x5fed(%rip), %rdi      # 0x1d25f
leaq 0x80(%rsp), %rsi
jmp 0x17365
movq 0x8(%rsp), %r14
movsbl (%r14), %ebx
movl %ebx, %edi
callq 0x3090
xorl %ecx, %ecx
testl %ebx, %ebx
je 0x172c7
testl %eax, %eax
jne 0x172c7
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 0x172c4
testl %eax, %eax
je 0x1729f
movl %r15d, %ecx
movb $0x0, 0x10(%rsp,%rcx)
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x13de8
movq (%rbx), %rdx
leaq 0x143dd(%rip), %rdi     # 0x2b6c0
leaq 0x10(%rsp), %rsi
callq 0x16cc2
jmp 0x173d1
testl %eax, %eax
jle 0x173a6
leal -0x1(%rax), %ecx
movl %ecx, 0x1a189(%rip)     # 0x3148c
leal -0x1(%rax), %ecx
cmpl %eax, 0x1a184(%rip)     # 0x31490
jge 0x173c5
jmp 0x173cb
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
xorl %edx, %edx
callq 0x16e3c
cmpb $0x0, (%rbx)
je 0x173af
leaq 0x14389(%rip), %rdi     # 0x2b6c0
leaq 0x10(%rsp), %rsi
callq 0x16dc4
testl %eax, %eax
js 0x173df
leaq 0x14370(%rip), %rdi     # 0x2b6c0
movl %eax, %esi
callq 0x16e0e
jmp 0x173d1
movq 0x8(%rsp), %rsi
leaq 0x5e84(%rip), %rdi      # 0x1d1e9
xorl %eax, %eax
callq 0x102f4
jmp 0x173d1
leal 0x1(%rax), %edx
cmpl %edx, %ecx
jle 0x1737d
movl %edx, 0x1a111(%rip)     # 0x3148c
movl %edx, %ecx
cmpl %edx, 0x1a10d(%rip)     # 0x31490
jle 0x1738b
movl %edx, 0x1a105(%rip)     # 0x31490
cmpl %edx, %ecx
jne 0x17395
movl %eax, 0x1a0f7(%rip)     # 0x3148c
movl %edx, 0x1a0ed(%rip)     # 0x31488
jmp 0x173d1
leaq 0x5e90(%rip), %rdi      # 0x1d234
jmp 0x173b6
leaq 0x5e9f(%rip), %rdi      # 0x1d24c
jmp 0x173b6
leaq 0x5e42(%rip), %rdi      # 0x1d1f8
xorl %eax, %eax
callq 0x102f4
jmp 0x173d1
movl %ecx, 0x1a0c7(%rip)     # 0x3148c
movl %ecx, 0x1a0c5(%rip)     # 0x31490
movl %ecx, 0x1a0b7(%rip)     # 0x31488
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5e22(%rip), %rdi      # 0x1d208
leaq 0x10(%rsp), %rsi
jmp 0x17365