// File: /workspace/github_c_makefile_star2_O0/koendv[P]stm32duino-raspberrypi/Arduino_Tools/src/stm32flash/stm32.c
// Function: stm32_crc_memory
stm32_err_t stm32_crc_memory(const stm32_t *stm, uint32_t address,
			     uint32_t length, uint32_t *crc)
{
	struct port_interface *port = stm->port;
	uint8_t buf[5];

	if ((address & 0x3) || (length & 0x3)) {
		fprintf(stderr, "Start and end addresses must be 4 byte aligned\n");
		return STM32_ERR_UNKNOWN;
	}

	if (stm->cmd->crc == STM32_CMD_ERR) {
		fprintf(stderr, "Error: CRC command not implemented in bootloader.\n");
		return STM32_ERR_NO_CMD;
	}

	if (stm32_send_command(stm, stm->cmd->crc) != STM32_ERR_OK)
		return STM32_ERR_UNKNOWN;

	buf[0] = address >> 24;
	buf[1] = (address >> 16) & 0xFF;
	buf[2] = (address >> 8) & 0xFF;
	buf[3] = address & 0xFF;
	buf[4] = buf[0] ^ buf[1] ^ buf[2] ^ buf[3];
	if (port->write(port, buf, 5) != PORT_ERR_OK)
		return STM32_ERR_UNKNOWN;

	if (stm32_get_ack(stm) != STM32_ERR_OK)
		return STM32_ERR_UNKNOWN;

	buf[0] = length >> 24;
	buf[1] = (length >> 16) & 0xFF;
	buf[2] = (length >> 8) & 0xFF;
	buf[3] = length & 0xFF;
	buf[4] = buf[0] ^ buf[1] ^ buf[2] ^ buf[3];
	if (port->write(port, buf, 5) != PORT_ERR_OK)
		return STM32_ERR_UNKNOWN;

	if (stm32_get_ack(stm) != STM32_ERR_OK)
		return STM32_ERR_UNKNOWN;

	if (stm32_get_ack(stm) != STM32_ERR_OK)
		return STM32_ERR_UNKNOWN;

	if (port->read(port, buf, 5) != PORT_ERR_OK)
		return STM32_ERR_UNKNOWN;

	if (buf[4] != (buf[0] ^ buf[1] ^ buf[2] ^ buf[3]))
		return STM32_ERR_UNKNOWN;

	*crc = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
	return STM32_ERR_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x8828
movl -0x18(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x884c
movq 0x77c1(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x3954(%rip), %rsi      # 0xc18d
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x8a4e
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movzbl 0xb(%rax), %eax
cmpl $0xff, %eax
jne 0x8883
movq 0x778a(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x394d(%rip), %rsi      # 0xc1bd
movb $0x0, %al
callq 0x2160
movl $0x3, -0x4(%rbp)
jmp 0x8a4e
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movzbl 0xb(%rax), %esi
callq 0x7190
cmpl $0x0, %eax
je 0x88a9
movl $0x1, -0x4(%rbp)
jmp 0x8a4e
movl -0x14(%rbp), %eax
shrl $0x18, %eax
movb %al, -0x2d(%rbp)
movl -0x14(%rbp), %eax
shrl $0x10, %eax
andl $0xff, %eax
movb %al, -0x2c(%rbp)
movl -0x14(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, -0x2b(%rbp)
movl -0x14(%rbp), %eax
andl $0xff, %eax
movb %al, -0x2a(%rbp)
movzbl -0x2d(%rbp), %eax
movzbl -0x2c(%rbp), %ecx
xorl %ecx, %eax
movzbl -0x2b(%rbp), %ecx
xorl %ecx, %eax
movzbl -0x2a(%rbp), %ecx
xorl %ecx, %eax
movb %al, -0x29(%rbp)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x28(%rbp), %rdi
leaq -0x2d(%rbp), %rsi
movl $0x5, %edx
callq *%rax
cmpl $0x0, %eax
je 0x891a
movl $0x1, -0x4(%rbp)
jmp 0x8a4e
movq -0x10(%rbp), %rdi
callq 0x71f0
cmpl $0x0, %eax
je 0x8934
movl $0x1, -0x4(%rbp)
jmp 0x8a4e
movl -0x18(%rbp), %eax
shrl $0x18, %eax
movb %al, -0x2d(%rbp)
movl -0x18(%rbp), %eax
shrl $0x10, %eax
andl $0xff, %eax
movb %al, -0x2c(%rbp)
movl -0x18(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, -0x2b(%rbp)
movl -0x18(%rbp), %eax
andl $0xff, %eax
movb %al, -0x2a(%rbp)
movzbl -0x2d(%rbp), %eax
movzbl -0x2c(%rbp), %ecx
xorl %ecx, %eax
movzbl -0x2b(%rbp), %ecx
xorl %ecx, %eax
movzbl -0x2a(%rbp), %ecx
xorl %ecx, %eax
movb %al, -0x29(%rbp)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x28(%rbp), %rdi
leaq -0x2d(%rbp), %rsi
movl $0x5, %edx
callq *%rax
cmpl $0x0, %eax
je 0x89a5
movl $0x1, -0x4(%rbp)
jmp 0x8a4e
movq -0x10(%rbp), %rdi
callq 0x71f0
cmpl $0x0, %eax
je 0x89bf
movl $0x1, -0x4(%rbp)
jmp 0x8a4e
movq -0x10(%rbp), %rdi
callq 0x71f0
cmpl $0x0, %eax
je 0x89d6
movl $0x1, -0x4(%rbp)
jmp 0x8a4e
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x28(%rbp), %rdi
leaq -0x2d(%rbp), %rsi
movl $0x5, %edx
callq *%rax
cmpl $0x0, %eax
je 0x89fb
movl $0x1, -0x4(%rbp)
jmp 0x8a4e
movzbl -0x29(%rbp), %eax
movzbl -0x2d(%rbp), %ecx
movzbl -0x2c(%rbp), %edx
xorl %edx, %ecx
movzbl -0x2b(%rbp), %edx
xorl %edx, %ecx
movzbl -0x2a(%rbp), %edx
xorl %edx, %ecx
cmpl %ecx, %eax
je 0x8a22
movl $0x1, -0x4(%rbp)
jmp 0x8a4e
movzbl -0x2d(%rbp), %ecx
shll $0x18, %ecx
movzbl -0x2c(%rbp), %eax
shll $0x10, %eax
orl %eax, %ecx
movzbl -0x2b(%rbp), %eax
shll $0x8, %eax
orl %eax, %ecx
movzbl -0x2a(%rbp), %eax
orl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)