// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/backend/asmgen_gas64.c
// Function: asm_stat_fptoui
static void _asm_stat_fptoui(
	ASMGeneratorGas64Context *ctx,
	ParserASTNode *node
) {
	assert(ctx);
	assert(node);
	assert(node->type == BE_NODE_STAT_FPTOUI);
	assert(node->nchilds == 2);
	/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		TODO: 	float/double -> 64位无符号整数不能简单地使用cvttss2si。
				至少clang会生成一堆指令。
	!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/

	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_xmm_reg(
		ctx,
		_ASM_REG_NAME_XMM0,
		node_source
	);

	if (type_source == BE_TYPE_FLOAT) {
		_asm_inst_cvttss2si_x_x(
			ctx,
			ctx->body,
			_ASM_REG_NAME_RAX,
			_ASM_REG_NAME_XMM0
		);
	} else if (type_source == BE_TYPE_DOUBLE) {
		_asm_inst_cvttsd2si_x_x(
			ctx,
			ctx->body,
			_ASM_REG_NAME_RAX,
			_ASM_REG_NAME_XMM0
		);
	} else {
		assert(0);
	}

	_asm_inst_mov_sym_x(
		ctx,
		ctx->body,
		symbol_target,
		_asm_inst_reg(ctx, type_target, _ASM_REG_AX)
	);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x2ccc9
jmp 0x2cce8
leaq 0x53491(%rip), %rdi     # 0x80161
leaq 0x4de2d(%rip), %rsi     # 0x7ab04
movl $0x116f, %edx           # imm = 0x116F
leaq 0x4faf7(%rip), %rcx     # 0x7c7da
callq 0x30a0
cmpq $0x0, -0x10(%rbp)
je 0x2ccf1
jmp 0x2cd10
leaq 0x49864(%rip), %rdi     # 0x7655c
leaq 0x4de05(%rip), %rsi     # 0x7ab04
movl $0x1170, %edx           # imm = 0x1170
leaq 0x4facf(%rip), %rcx     # 0x7c7da
callq 0x30a0
movq -0x10(%rbp), %rax
cmpl $0xbc7, (%rax)          # imm = 0xBC7
jne 0x2cd1e
jmp 0x2cd3d
leaq 0x4b7f5(%rip), %rdi     # 0x7851a
leaq 0x4ddd8(%rip), %rsi     # 0x7ab04
movl $0x1171, %edx           # imm = 0x1171
leaq 0x4faa2(%rip), %rcx     # 0x7c7da
callq 0x30a0
movq -0x10(%rbp), %rax
cmpl $0x2, 0x44(%rax)
jne 0x2cd49
jmp 0x2cd68
leaq 0x55ff4(%rip), %rdi     # 0x82d44
leaq 0x4ddad(%rip), %rsi     # 0x7ab04
movl $0x1172, %edx           # imm = 0x1172
leaq 0x4fa77(%rip), %rcx     # 0x7c7da
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 0x2cd85
jmp 0x2cda4
leaq 0x49631(%rip), %rdi     # 0x763bd
leaq 0x4dd71(%rip), %rsi     # 0x7ab04
movl $0x1179, %edx           # imm = 0x1179
leaq 0x4fa3b(%rip), %rcx     # 0x7c7da
callq 0x30a0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x32820
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), %rdx
leaq 0x4ab28(%rip), %rsi     # 0x77906
callq 0x36060
movb %al, -0x31(%rbp)
movzbl -0x31(%rbp), %eax
cmpl $0xa, %eax
jne 0x2ce10
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
leaq 0x4e2b8(%rip), %rdx     # 0x7b0ba
leaq 0x4aafd(%rip), %rcx     # 0x77906
callq 0x36430
jmp 0x2ce5b
movzbl -0x31(%rbp), %eax
cmpl $0xb, %eax
jne 0x2ce3a
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
leaq 0x4e28e(%rip), %rdx     # 0x7b0ba
leaq 0x4aad3(%rip), %rcx     # 0x77906
callq 0x36520
jmp 0x2ce59
leaq 0x46619(%rip), %rdi     # 0x7345a
leaq 0x4dcbc(%rip), %rsi     # 0x7ab04
movl $0x1193, %edx           # imm = 0x1193
leaq 0x4f986(%rip), %rcx     # 0x7c7da
callq 0x30a0
jmp 0x2ce5b
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
xorl %edx, %edx
movzbl -0x21(%rbp), %esi
callq 0x334d0
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %rax, %rcx
callq 0x32d40
addq $0x50, %rsp
popq %rbp
retq