// File: exrd[P]neteruhsp/neteruhsp/neteruhsp.cc
// Function: neteruhsp::prepro_do(char const*)
char* prepro_do( const char* src )
{
	auto* pctx = create_prepro_context();
	prepro_register_default_macros( pctx );
	pctx->out_buffer_ = create_string_buffer();

	const char* p = src;
	for ( ; ; )
	{
		const char* const s = p;

		string_buffer_t line;
		initialize_string_buffer( &line );

		{
			bool is_in_multi_line_comment = false;
			for ( ; ; )
			{
				if ( p[0] == '/' && p[1] == '*' )
				{
					is_in_multi_line_comment = true;
					p += 2;
					continue;
				}
				else if ( p[0] == '*' && p[1] == '/' )
				{
					is_in_multi_line_comment = false;
					p += 2;
					continue;
				}
				else if ( p[0] == '\\' && p[1] == '\n' )
				{
					p += 2;
					++pctx->line_;
					continue;
				}
				else if ( p[0] == '\n' )
				{
					if ( !is_in_multi_line_comment )
					{
						break;
					}
					++pctx->line_;
				}
				else if ( p[0] == '\0' )
				{
					break;
				}
				if ( !is_in_multi_line_comment )
				{
					string_buffer_append( &line, p, 1 );
				}
				++p;
			}
		}

		const char* const e = p;

		if ( e > s )
		{
			auto* out_line = prepro_line( pctx, line.buffer_, true );

			if ( out_line != nullptr )
			{
				string_buffer_append( pctx->out_buffer_, out_line );
				destroy_string( out_line );
			}
		}

		uninitialize_string_buffer( &line );

		if ( p[0] == '\0' )
		{
			break;
		}

		string_buffer_append( pctx->out_buffer_, "\n" );

		++p;
		++pctx->line_;
	}

	if ( pctx->pp_region_idx_ > 0 )
	{
		raise_error( "プリプロセス：#if-#endifリージョンが正しく閉じられていません：閉じられていないリージョンの始まり（%d行目）", pctx->pp_region_[0].line_ + 1 );
		return nullptr;
	}

	// 抜き取り
	auto* const res = pctx->out_buffer_->buffer_;
	pctx->out_buffer_->buffer_ = nullptr;
	destroy_prepro_context( pctx );

	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
callq 0x5630
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x5770
movl $0x400, %edi            # imm = 0x400
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x39c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq -0x40(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
movl $0x400, %edx            # imm = 0x400
callq 0x3a20
movb $0x0, -0x41(%rbp)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x590a
movq -0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2a, %eax
jne 0x590a
movb $0x1, -0x41(%rbp)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
jmp 0x58df
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2a, %eax
jne 0x5935
movq -0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2f, %eax
jne 0x5935
movb $0x0, -0x41(%rbp)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
jmp 0x58df
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5c, %eax
jne 0x596c
movq -0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0xa, %eax
jne 0x596c
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
jmp 0x58df
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x598f
testb $0x1, -0x41(%rbp)
jne 0x5980
jmp 0x59ce
movq -0x18(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
jmp 0x599f
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x599d
jmp 0x59ce
jmp 0x599f
jmp 0x59a1
jmp 0x59a3
jmp 0x59a5
testb $0x1, -0x41(%rbp)
jne 0x59bd
movq -0x20(%rbp), %rsi
leaq -0x40(%rbp), %rdi
movl $0x1, %edx
callq 0x3b50
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x58df
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x28(%rbp), %rax
jbe 0x5a1e
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl $0x1, %edx
callq 0x5ae0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x5a1c
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x58(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x3b50
movq -0x58(%rbp), %rdi
callq 0x5030
jmp 0x5a1e
leaq -0x40(%rbp), %rdi
callq 0x3ab0
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x5a35
jmp 0x5a6c
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x104e7(%rip), %rsi     # 0x15f2b
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x3b50
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
jmp 0x58c0
movq -0x18(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jle 0x5a98
movq -0x18(%rbp), %rax
movl 0x20(%rax), %esi
addl $0x1, %esi
leaq 0xd4b2(%rip), %rdi      # 0x12f39
movb $0x0, %al
callq 0x4cd0
movq $0x0, -0x8(%rbp)
jmp 0x5ac7
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rdi
callq 0x56b0
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)