// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/backend/asmgen_gas32.c
// Function: asm_stat_sext
static void _asm_stat_sext(
	ASMGeneratorGas32Context *ctx,
	ParserASTNode *node
) {
	assert(ctx);
	assert(node);
	assert(node->type == BE_NODE_STAT_SEXT);
	assert(node->nchilds == 2);

	ParserASTNode *node_target = node->childs[0];
	assert(node_target->type == BE_NODE_IDENTIFIER);
	ParserSymbol *symbol_target = _get_var_symbol_by_id_node(ctx, node_target);
	uint8_t type_target = BE_VAR_SYMBOL_GET_TYPE(symbol_target);

	ParserASTNode *node_source = node->childs[1];
	uint8_t type_source = _move_id_or_constexpr_to_reg(
		ctx,
		_ASM_REG_AX,
		_ASM_REG_BX,
		node_source
	);

	assert(type_source != BE_TYPE_UINT64 && type_source != BE_TYPE_INT64);

	if (type_target == BE_TYPE_UINT64 || type_target == BE_TYPE_INT64) {
		const char *reg_target = _asm_inst_reg(ctx, BE_TYPE_UINT32, _ASM_REG_CX);
		const char *reg_source = _asm_inst_reg(ctx, type_source, _ASM_REG_AX);

		if (type_source == BE_TYPE_UINT32 || type_source == BE_TYPE_INT32) {
			_asm_inst_mov_x_x(
				ctx,
				ctx->body,
				BE_TYPE_UINT32,
				reg_target,
				reg_source
			);
		} else {
			_asm_inst_movsx_x_x(
				ctx,
				ctx->body,
				BE_TYPE_UINT32,
				reg_target,
				type_source,
				reg_source
			);
		}

		ParserSymbol *symbol_target_l = _instantiate_varsym(ctx, symbol_target, 0);
		ParserSymbol *symbol_target_h = _instantiate_varsym(ctx, symbol_target, 4);

		_asm_inst_mov_sym_x(
			ctx,
			ctx->body,
			symbol_target_l,
			reg_target
		);

		_asm_inst_sar_x_x(
			ctx,
			ctx->body,
			BE_TYPE_UINT32,
			reg_target,
			_ASM_CONST_31
		);

		_asm_inst_mov_sym_x(
			ctx,
			ctx->body,
			symbol_target_h,
			reg_target
		);

		_free_varsym(ctx, symbol_target_l);
		_free_varsym(ctx, symbol_target_h);
	} else {
		const char *reg_target = _asm_inst_reg(ctx, type_target, _ASM_REG_CX);
		const char *reg_source = _asm_inst_reg(ctx, type_source, _ASM_REG_AX);

		_asm_inst_movsx_x_x(
			ctx,
			ctx->body,
			type_target,
			reg_target,
			type_source,
			reg_source
		);

		ParserSymbol *symbol_target_l = _instantiate_varsym(ctx, symbol_target, 0);

		_asm_inst_mov_sym_x(
			ctx,
			ctx->body,
			symbol_target_l,
			reg_target
		);

		_free_varsym(ctx, symbol_target_l);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x13f09
jmp 0x13f28
leaq 0x6c251(%rip), %rdi     # 0x80161
leaq 0x619e1(%rip), %rsi     # 0x758f8
movl $0x135c, %edx           # imm = 0x135C
leaq 0x637ec(%rip), %rcx     # 0x7770f
callq 0x30a0
cmpq $0x0, -0x10(%rbp)
je 0x13f31
jmp 0x13f50
leaq 0x62624(%rip), %rdi     # 0x7655c
leaq 0x619b9(%rip), %rsi     # 0x758f8
movl $0x135d, %edx           # imm = 0x135D
leaq 0x637c4(%rip), %rcx     # 0x7770f
callq 0x30a0
movq -0x10(%rbp), %rax
cmpl $0xbc1, (%rax)          # imm = 0xBC1
jne 0x13f5e
jmp 0x13f7d
leaq 0x637eb(%rip), %rdi     # 0x77750
leaq 0x6198c(%rip), %rsi     # 0x758f8
movl $0x135e, %edx           # imm = 0x135E
leaq 0x63797(%rip), %rcx     # 0x7770f
callq 0x30a0
movq -0x10(%rbp), %rax
cmpl $0x2, 0x44(%rax)
jne 0x13f89
jmp 0x13fa8
leaq 0x6edb4(%rip), %rdi     # 0x82d44
leaq 0x61961(%rip), %rsi     # 0x758f8
movl $0x135f, %edx           # imm = 0x135F
leaq 0x6376c(%rip), %rcx     # 0x7770f
callq 0x30a0
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x200, (%rax)          # imm = 0x200
jne 0x13fc5
jmp 0x13fe4
leaq 0x623f1(%rip), %rdi     # 0x763bd
leaq 0x61925(%rip), %rsi     # 0x758f8
movl $0x1362, %edx           # imm = 0x1362
leaq 0x63730(%rip), %rcx     # 0x7770f
callq 0x30a0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1f720
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movb 0x30(%rax), %al
movb %al, -0x21(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rcx
xorl %esi, %esi
movl $0x1, %edx
callq 0x22a20
movb %al, -0x31(%rbp)
movzbl -0x31(%rbp), %eax
cmpl $0x9, %eax
je 0x1403a
movzbl -0x31(%rbp), %eax
cmpl $0x5, %eax
je 0x1403a
jmp 0x14059
leaq 0x6372f(%rip), %rdi     # 0x77770
leaq 0x618b0(%rip), %rsi     # 0x758f8
movl $0x136e, %edx           # imm = 0x136E
leaq 0x636bb(%rip), %rcx     # 0x7770f
callq 0x30a0
movzbl -0x21(%rbp), %eax
cmpl $0x9, %eax
je 0x1406f
movzbl -0x21(%rbp), %eax
cmpl $0x5, %eax
jne 0x141a5
movq -0x8(%rbp), %rdi
movl $0x8, %esi
movl $0x2, %edx
leaq 0x61874(%rip), %rcx     # 0x758f8
movl $0x1371, %r8d           # imm = 0x1371
callq 0x20d10
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
xorl %edx, %edx
leaq 0x61858(%rip), %rcx     # 0x758f8
movl $0x1372, %r8d           # imm = 0x1372
movzbl -0x31(%rbp), %esi
callq 0x20d10
movq %rax, -0x48(%rbp)
movzbl -0x31(%rbp), %eax
cmpl $0x8, %eax
je 0x140c5
movzbl -0x31(%rbp), %eax
cmpl $0x4, %eax
jne 0x140e5
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movl $0x8, %edx
callq 0x20f30
jmp 0x1410a
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x40(%rbp), %rcx
movb -0x31(%rbp), %al
movq -0x48(%rbp), %r9
movl $0x8, %edx
movzbl %al, %r8d
callq 0x22e20
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0x1f8e0
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x4, %edx
callq 0x1f8e0
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x50(%rbp), %rdx
movq -0x40(%rbp), %rcx
callq 0x20080
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x40(%rbp), %rcx
movl $0x8, %edx
leaq 0x63646(%rip), %r8      # 0x777ae
callq 0x22f80
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x58(%rbp), %rdx
movq -0x40(%rbp), %rcx
callq 0x20080
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x1fd10
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x1fd10
jmp 0x14247
movq -0x8(%rbp), %rdi
movl $0x2, %edx
leaq 0x61743(%rip), %rcx     # 0x758f8
movl $0x13a3, %r8d           # imm = 0x13A3
movzbl -0x21(%rbp), %esi
callq 0x20d10
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
xorl %edx, %edx
leaq 0x61723(%rip), %rcx     # 0x758f8
movl $0x13a4, %r8d           # imm = 0x13A4
movzbl -0x31(%rbp), %esi
callq 0x20d10
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movb -0x21(%rbp), %dl
movq -0x60(%rbp), %rcx
movb -0x31(%rbp), %al
movq -0x68(%rbp), %r9
movzbl %dl, %edx
movzbl %al, %r8d
callq 0x22e20
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0x1f8e0
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x70(%rbp), %rdx
movq -0x60(%rbp), %rcx
callq 0x20080
movq -0x8(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x1fd10
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)