// File: /workspace/github_c_makefile_star2_O1/adamjedlicka[P]blu/src/vm/compiler/compiler.c
// Function: ifStatement
static void ifStatement(bluCompiler* compiler) {
	beginScope(compiler);

	expression(compiler);
	int32_t ifJump = emitJump(compiler, OP_JUMP_IF_FALSE);
	emitByte(compiler, OP_POP); // Condition

	// One-line if notation
	if (match(compiler, TOKEN_COLON)) {
		statement(compiler);

		int32_t elseJump = emitJump(compiler, OP_JUMP);
		patchJump(compiler, ifJump);
		emitByte(compiler, OP_POP); // Condition
		patchJump(compiler, elseJump);
		endScope(compiler);
		return;
	}

	consume(compiler, TOKEN_LEFT_BRACE, "Expect '{' after if condition.");
	beginScope(compiler);
	block(compiler);
	endScope(compiler);

	int32_t elseJump = emitJump(compiler, OP_JUMP);
	patchJump(compiler, ifJump);
	emitByte(compiler, OP_POP); // Condition

	if (match(compiler, TOKEN_ELSE)) {
		if (match(compiler, TOKEN_LEFT_BRACE)) {
			beginScope(compiler);
			block(compiler);
			endScope(compiler);
		} else if (match(compiler, TOKEN_IF)) {
			ifStatement(compiler);
		} else {
			error(compiler, "Expect 'if' or '{' after 'else.'");
		}
	}

	patchJump(compiler, elseJump);

	endScope(compiler);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
incb 0x58(%rdi)
callq 0x5e4c
movq %rbx, %rdi
movl $0x16, %esi
callq 0x652f
movl %eax, %r14d
movq 0x8(%rbx), %rax
movq 0x28(%rbx), %rdi
addq $0x28, %rdi
movl 0x54(%rax), %edx
movl 0x58(%rax), %ecx
movl $0x5, %esi
callq 0x4b23
movq 0x8(%rbx), %rax
cmpl $0x2, 0x40(%rax)
jne 0x6a7c
movq %rbx, %rdi
callq 0x553e
movq %rbx, %rdi
callq 0x65ca
movq %rbx, %rdi
movl $0x15, %esi
callq 0x652f
movl %eax, %ebp
movq 0x28(%rbx), %rcx
movl 0x40(%rcx), %eax
subl %r14d, %eax
addl $-0x2, %eax
movq 0x38(%rcx), %rdx
movslq %r14d, %rsi
movb %ah, (%rdx,%rsi)
movq 0x38(%rcx), %rcx
movb %al, 0x1(%rcx,%rsi)
movq 0x8(%rbx), %rax
movq 0x28(%rbx), %rdi
addq $0x28, %rdi
movl 0x54(%rax), %edx
movl 0x58(%rax), %ecx
movl $0x5, %esi
callq 0x4b23
jmp 0x6b59
leaq 0x3e4f(%rip), %rdx      # 0xa8d2
movq %rbx, %rdi
movl $0x5, %esi
callq 0x5d2c
incb 0x58(%rbx)
movq %rbx, %rdi
callq 0x63ab
movq %rbx, %rdi
callq 0x63df
movq %rbx, %rdi
movl $0x15, %esi
callq 0x652f
movl %eax, %ebp
movq 0x28(%rbx), %rcx
movl 0x40(%rcx), %eax
subl %r14d, %eax
addl $-0x2, %eax
movq 0x38(%rcx), %rdx
movslq %r14d, %rsi
movb %ah, (%rdx,%rsi)
movq 0x38(%rcx), %rcx
movb %al, 0x1(%rcx,%rsi)
movq 0x8(%rbx), %rax
movq 0x28(%rbx), %rdi
addq $0x28, %rdi
movl 0x54(%rax), %edx
movl 0x58(%rax), %ecx
movl $0x5, %esi
callq 0x4b23
movq 0x8(%rbx), %rax
cmpl $0x21, 0x40(%rax)
jne 0x6b59
movq %rbx, %rdi
callq 0x553e
movq 0x8(%rbx), %rax
cmpl $0x5, 0x40(%rax)
jne 0x6b26
movq %rbx, %rdi
callq 0x553e
incb 0x58(%rbx)
movq %rbx, %rdi
callq 0x63ab
movq %rbx, %rdi
callq 0x63df
jmp 0x6b59
movq 0x8(%rbx), %rax
cmpl $0x26, 0x40(%rax)
jne 0x6b42
movq %rbx, %rdi
callq 0x553e
movq %rbx, %rdi
callq 0x69d8
jmp 0x6b59
movq 0x8(%rbx), %rsi
addq $0x20, %rsi
leaq 0x3da0(%rip), %rdx      # 0xa8f1
movq %rbx, %rdi
callq 0x5b1c
movq 0x28(%rbx), %rcx
movl 0x40(%rcx), %eax
subl %ebp, %eax
addl $-0x2, %eax
movq 0x38(%rcx), %rdx
movslq %ebp, %rsi
movb %ah, (%rdx,%rsi)
movq 0x38(%rcx), %rcx
movb %al, 0x1(%rcx,%rsi)
movq %rbx, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x63df