// File: /workspace/github_c_makefile_star2_O0/koendv[P]stm32duino-raspberrypi/Arduino_Tools/src/stm32flash/stm32.c
// Function: stm32_erase_memory
stm32_err_t stm32_erase_memory(const stm32_t *stm, uint32_t spage, uint32_t pages)
{
	uint32_t n;
	stm32_err_t s_err;

	if (!pages || spage > STM32_MAX_PAGES ||
	    ((pages != STM32_MASS_ERASE) && ((spage + pages) > STM32_MAX_PAGES)))
		return STM32_ERR_OK;

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

	if (pages == STM32_MASS_ERASE) {
		/*
		 * Not all chips support mass erase.
		 * Mass erase can be obtained executing a "readout protect"
		 * followed by "readout un-protect". This method is not
		 * suggested because can hang the target if a debug SWD/JTAG
		 * is connected. When the target enters in "readout
		 * protection" mode it will consider the debug connection as
		 * a tentative of intrusion and will hang.
		 * Erasing the flash page-by-page is the safer way to go.
		 */
		if (!(stm->dev->flags & F_NO_ME))
			return stm32_mass_erase(stm);

		pages = flash_addr_to_page_ceil(stm->dev->fl_end);
	}

	/*
	 * Some device, like STM32L152, cannot erase more than 512 pages in
	 * one command. Split the call.
	 */
	while (pages) {
		n = (pages <= 512) ? pages : 512;
		s_err = stm32_pages_erase(stm, spage, n);
		if (s_err != STM32_ERR_OK)
			return s_err;
		spage += n;
		pages -= n;
	}
	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)
cmpl $0x0, -0x18(%rbp)
je 0x7eb7
cmpl $0xffff, -0x14(%rbp)    # imm = 0xFFFF
ja 0x7eb7
cmpl $0x100000, -0x18(%rbp)  # imm = 0x100000
je 0x7ec3
movl -0x14(%rbp), %eax
addl -0x18(%rbp), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jbe 0x7ec3
movl $0x0, -0x4(%rbp)
jmp 0x7f9d
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movzbl 0x6(%rax), %eax
cmpl $0xff, %eax
jne 0x7efa
movq 0x8113(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x423f(%rip), %rsi      # 0xc126
movb $0x0, %al
callq 0x2160
movl $0x3, -0x4(%rbp)
jmp 0x7f9d
cmpl $0x100000, -0x18(%rbp)  # imm = 0x100000
jne 0x7f37
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl 0x40(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x7f24
movq -0x10(%rbp), %rdi
callq 0x7fb0
movl %eax, -0x4(%rbp)
jmp 0x7f9d
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl 0x1c(%rax), %edi
callq 0x32a0
movl %eax, -0x18(%rbp)
jmp 0x7f39
cmpl $0x0, -0x18(%rbp)
je 0x7f96
cmpl $0x200, -0x18(%rbp)     # imm = 0x200
ja 0x7f50
movl -0x18(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x7f5a
movl $0x200, %eax            # imm = 0x200
movl %eax, -0x24(%rbp)
jmp 0x7f5a
movl -0x24(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x1c(%rbp), %edx
callq 0x8130
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x7f80
movl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x7f9d
movl -0x1c(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x1c(%rbp), %ecx
movl -0x18(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x18(%rbp)
jmp 0x7f39
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)