// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/backend/asmgen_gas32.c
// Function: asm_stat_fptoui
static void _asm_stat_fptoui(
	ASMGeneratorGas32Context *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_EAX,
			_ASM_REG_NAME_XMM0
		);
	} else if (type_source == BE_TYPE_DOUBLE) {
		_asm_inst_cvttsd2si_x_x(
			ctx,
			ctx->body,
			_ASM_REG_NAME_EAX,
			_ASM_REG_NAME_XMM0
		);
	} else {
		assert(0);
	}

	if (type_target == BE_TYPE_UINT64) {
		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,
			_ASM_REG_NAME_EAX
		);

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

		_free_varsym(ctx, symbol_target_l);
		_free_varsym(ctx, symbol_target_h);
	} else {
		ParserSymbol *symbol_target_l = _instantiate_varsym(ctx, symbol_target, 0);

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

		_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 0x158f9
jmp 0x15918
leaq 0x6a861(%rip), %rdi     # 0x80161
leaq 0x5fff1(%rip), %rsi     # 0x758f8
movl $0x16a0, %edx           # imm = 0x16A0
leaq 0x62bc4(%rip), %rcx     # 0x784d7
callq 0x30a0
cmpq $0x0, -0x10(%rbp)
je 0x15921
jmp 0x15940
leaq 0x60c34(%rip), %rdi     # 0x7655c
leaq 0x5ffc9(%rip), %rsi     # 0x758f8
movl $0x16a1, %edx           # imm = 0x16A1
leaq 0x62b9c(%rip), %rcx     # 0x784d7
callq 0x30a0
movq -0x10(%rbp), %rax
cmpl $0xbc7, (%rax)          # imm = 0xBC7
jne 0x1594e
jmp 0x1596d
leaq 0x62bc5(%rip), %rdi     # 0x7851a
leaq 0x5ff9c(%rip), %rsi     # 0x758f8
movl $0x16a2, %edx           # imm = 0x16A2
leaq 0x62b6f(%rip), %rcx     # 0x784d7
callq 0x30a0
movq -0x10(%rbp), %rax
cmpl $0x2, 0x44(%rax)
jne 0x15979
jmp 0x15998
leaq 0x6d3c4(%rip), %rdi     # 0x82d44
leaq 0x5ff71(%rip), %rsi     # 0x758f8
movl $0x16a3, %edx           # imm = 0x16A3
leaq 0x62b44(%rip), %rcx     # 0x784d7
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 0x159b5
jmp 0x159d4
leaq 0x60a01(%rip), %rdi     # 0x763bd
leaq 0x5ff35(%rip), %rsi     # 0x758f8
movl $0x16aa, %edx           # imm = 0x16AA
leaq 0x62b08(%rip), %rcx     # 0x784d7
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), %rdx
leaq 0x61ef8(%rip), %rsi     # 0x77906
callq 0x24300
movb %al, -0x31(%rbp)
movzbl -0x31(%rbp), %eax
cmpl $0xa, %eax
jne 0x15a40
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
leaq 0x609b3(%rip), %rdx     # 0x763e5
leaq 0x61ecd(%rip), %rcx     # 0x77906
callq 0x248b0
jmp 0x15a8b
movzbl -0x31(%rbp), %eax
cmpl $0xb, %eax
jne 0x15a6a
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
leaq 0x60989(%rip), %rdx     # 0x763e5
leaq 0x61ea3(%rip), %rcx     # 0x77906
callq 0x249a0
jmp 0x15a89
leaq 0x5d9e9(%rip), %rdi     # 0x7345a
leaq 0x5fe80(%rip), %rsi     # 0x758f8
movl $0x16c4, %edx           # imm = 0x16C4
leaq 0x62a53(%rip), %rcx     # 0x784d7
callq 0x30a0
jmp 0x15a8b
movzbl -0x21(%rbp), %eax
cmpl $0x9, %eax
jne 0x15b11
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0x1f8e0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x4, %edx
callq 0x1f8e0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x40(%rbp), %rdx
leaq 0x60911(%rip), %rcx     # 0x763e5
callq 0x20080
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x48(%rbp), %rdx
leaq 0x60f7b(%rip), %rcx     # 0x76a6b
callq 0x20080
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x1fd10
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x1fd10
jmp 0x15b7d
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0x1f8e0
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
xorl %edx, %edx
leaq 0x5fdab(%rip), %rcx     # 0x758f8
movl $0x16e2, %r8d           # imm = 0x16E2
movzbl -0x21(%rbp), %esi
callq 0x20d10
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %rax, %rcx
callq 0x20080
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x1fd10
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)