// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/preprocessor/gen.c
// Function: gen_if
static void _gen_if(
	PPGeneratorContext *ctx,
	ParserASTNode *node
) {
	assert(ctx);
	assert(node);
	assert(node->type == PP_NODE_DIRECTIVE_IF);
	assert(node->nchilds >= 1);

	const char *content = node->token->content;
	int len = node->token->len;

	char cmd[] = "#if";
	ResizableString temp;
	rstr_init(&temp);
	int idx = sizeof(cmd);

	#define	_GET_CHAR(i) ((i) >= len ? -1 : content[(i)])

	while (isspace(_GET_CHAR(idx))) {
		idx++;
	}

	while (_GET_CHAR(idx) != -1) {
		rstr_append_with_char(&temp, _GET_CHAR(idx));
		idx++;
	}

	ResizableString expr;
	rstr_init(&expr);

	rstr_rtrim_ex(&expr, &temp, RSTR_SPACE_CHAR_COMPARER);

	if (RSTR_LEN(&expr) == 0) {
		_SYNERR_NODE(ctx, node, "expect constant expression.");
	}

	int result = pp_eval(ctx, RSTR_CSTR(&expr), RSTR_LEN(&expr));
	
	if (result) {
		ParserASTNode *node_block = node->childs[0];
		assert(node_block->type == PP_NODE_BLOCK);

		_gen_if_block(ctx, node_block);
	} else {
		for (int i = 1; i < node->nchilds; i++) {
			ParserASTNode *child = node->childs[i];
			if (_gen_elifxxx_and_else(ctx, child)) {
				break;
			}
		}
	}

	LexerToken *token_endif = PP_IFXXX_AST_NODE_GET_TOKEN_ENDIF(node);
	assert(token_endif);
	_OUT_FMT(ctx, "#line %d \"%s\"", token_endif->line + 1, token_endif->file);

	rstr_free(&expr);

	rstr_free(&temp);

	#undef	_GET_CHAR
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x8b0, %rsp            # imm = 0x8B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x3e7cc
jmp 0x3e7eb
leaq 0xf38e(%rip), %rdi      # 0x4db61
leaq 0x1071b(%rip), %rsi     # 0x4eef5
movl $0x26c, %edx            # imm = 0x26C
leaq 0x10d2f(%rip), %rcx     # 0x4f515
callq 0xa0b0
cmpq $0x0, -0x10(%rbp)
je 0x3e7f4
jmp 0x3e813
leaq 0xc88c(%rip), %rdi      # 0x4b087
leaq 0x106f3(%rip), %rsi     # 0x4eef5
movl $0x26d, %edx            # imm = 0x26D
leaq 0x10d07(%rip), %rcx     # 0x4f515
callq 0xa0b0
movq -0x10(%rbp), %rax
cmpl $0x203, (%rax)          # imm = 0x203
jne 0x3e821
jmp 0x3e840
leaq 0x10d21(%rip), %rdi     # 0x4f549
leaq 0x106c6(%rip), %rsi     # 0x4eef5
movl $0x26e, %edx            # imm = 0x26E
leaq 0x10cda(%rip), %rcx     # 0x4f515
callq 0xa0b0
movq -0x10(%rbp), %rax
cmpl $0x1, 0x44(%rax)
jl 0x3e84c
jmp 0x3e86b
leaq 0x10d19(%rip), %rdi     # 0x4f56c
leaq 0x1069b(%rip), %rsi     # 0x4eef5
movl $0x26f, %edx            # imm = 0x26F
leaq 0x10caf(%rip), %rcx     # 0x4f515
callq 0xa0b0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x4(%rax), %eax
movl %eax, -0x1c(%rbp)
movl 0x10cf0(%rip), %eax     # 0x4f57f
movl %eax, -0x20(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xfca0
movl $0x4, -0x34(%rbp)
callq 0xa1a0
movq (%rax), %rax
movq %rax, -0x888(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jl 0x3e8c6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x88c(%rbp)
jmp 0x3e8d8
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x88c(%rbp)
movq -0x888(%rbp), %rax
movl -0x88c(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x3e901
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3e8a2
jmp 0x3e903
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jl 0x3e918
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x890(%rbp)
jmp 0x3e92a
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x890(%rbp)
movl -0x890(%rbp), %eax
cmpl $-0x1, %eax
je 0x3e979
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jl 0x3e94a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x894(%rbp)
jmp 0x3e95c
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x894(%rbp)
movl -0x894(%rbp), %eax
leaq -0x30(%rbp), %rdi
movsbl %al, %esi
callq 0xfeb0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3e903
leaq -0x48(%rbp), %rdi
callq 0xfca0
leaq -0x48(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x2d581(%rip), %rdx    # 0x11410
callq 0x115c0
cmpl $0x0, -0x44(%rbp)
jne 0x3e9d0
leaq -0x450(%rbp), %rdi
leaq 0x10bd9(%rip), %rsi     # 0x4f583
movb $0x0, %al
callq 0xa170
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x58(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rdi
movq -0x10(%rbp), %rsi
leaq -0x450(%rbp), %rdx
callq *%rax
movq -0x8(%rbp), %rax
movq %rax, -0x8a0(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x3e9f2
leaq 0x8e9e(%rip), %rax      # 0x47887
movq %rax, -0x8a8(%rbp)
jmp 0x3e9fd
movq -0x40(%rbp), %rax
movq %rax, -0x8a8(%rbp)
movq -0x8a0(%rbp), %rdi
movq -0x8a8(%rbp), %rsi
movl -0x44(%rbp), %edx
callq 0x36380
movl %eax, -0x454(%rbp)
cmpl $0x0, -0x454(%rbp)
je 0x3ea76
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x460(%rbp)
movq -0x460(%rbp), %rax
cmpl $0x300, (%rax)          # imm = 0x300
jne 0x3ea45
jmp 0x3ea64
leaq 0x10b53(%rip), %rdi     # 0x4f59f
leaq 0x104a2(%rip), %rsi     # 0x4eef5
movl $0x291, %edx            # imm = 0x291
leaq 0x10ab6(%rip), %rcx     # 0x4f515
callq 0xa0b0
movq -0x8(%rbp), %rdi
movq -0x460(%rbp), %rsi
callq 0x3fd40
jmp 0x3ead6
movl $0x1, -0x464(%rbp)
movl -0x464(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x44(%rcx), %eax
jge 0x3ead4
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x464(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x470(%rbp)
movq -0x8(%rbp), %rdi
movq -0x470(%rbp), %rsi
callq 0x3fe80
testb $0x1, %al
jne 0x3eabf
jmp 0x3eac1
jmp 0x3ead4
jmp 0x3eac3
movl -0x464(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x464(%rbp)
jmp 0x3ea80
jmp 0x3ead6
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x478(%rbp)
cmpq $0x0, -0x478(%rbp)
je 0x3eaf1
jmp 0x3eb10
leaq 0x10ac9(%rip), %rdi     # 0x4f5c1
leaq 0x103f6(%rip), %rsi     # 0x4eef5
movl $0x29e, %edx            # imm = 0x29E
leaq 0x10a0a(%rip), %rcx     # 0x4f515
callq 0xa0b0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3eb4b
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x478(%rbp), %rax
movl 0x18(%rax), %edx
addl $0x1, %edx
movq -0x478(%rbp), %rax
movq 0x10(%rax), %rcx
leaq 0x10761(%rip), %rsi     # 0x4f2a3
movb $0x0, %al
callq 0xa100
jmp 0x3eb91
leaq -0x880(%rbp), %rdi
movq -0x478(%rbp), %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movq -0x478(%rbp), %rax
movq 0x10(%rax), %r8
movl $0x400, %esi            # imm = 0x400
leaq 0x1072d(%rip), %rdx     # 0x4f2a3
movb $0x0, %al
callq 0xa0a0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x880(%rbp), %rsi
callq 0xfd80
leaq -0x48(%rbp), %rdi
callq 0x10320
leaq -0x30(%rbp), %rdi
callq 0x10320
addq $0x8b0, %rsp            # imm = 0x8B0
popq %rbp
retq
nopl (%rax)