// File: /workspace/github_c_makefile_star2_O0/koendv[P]stm32duino-raspberrypi/Arduino_Tools/src/stm32flash/stm32.c
// Function: stm32_crc_wrapper
stm32_err_t stm32_crc_wrapper(const stm32_t *stm, uint32_t address,
			      uint32_t length, uint32_t *crc)
{
	uint8_t buf[256];
	uint32_t start, total_len, len, current_crc;

	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)
		return stm32_crc_memory(stm, address, length, crc);

	start = address;
	total_len = length;
	current_crc = CRC_INIT_VALUE;
	while (length) {
		len = length > 256 ? 256 : length;
		if (stm32_read_memory(stm, address, buf, len) != STM32_ERR_OK) {
			fprintf(stderr,
				"Failed to read memory at address 0x%08x, target write-protected?\n",
				address);
			return STM32_ERR_UNKNOWN;
		}
		current_crc = stm32_sw_crc(current_crc, buf, len);
		length -= len;
		address += len;

		fprintf(stderr,
			"\rCRC address 0x%08x (%.2f%%) ",
			address,
			(100.0f / (float)total_len) * (float)(address - start)
		);
		fflush(stderr);
	}
	fprintf(stderr, "Done.\n");
	*crc = current_crc;
	return STM32_ERR_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl -0x14(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x8baf
movl -0x18(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x8bd3
movq 0x743a(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x35cd(%rip), %rsi      # 0xc18d
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x8d59
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movzbl 0xb(%rax), %eax
cmpl $0xff, %eax
je 0x8c01
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
movq -0x20(%rbp), %rcx
callq 0x87f0
movl %eax, -0x4(%rbp)
jmp 0x8d59
movl -0x14(%rbp), %eax
movl %eax, -0x124(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x128(%rbp)
movl $0xffffffff, -0x130(%rbp) # imm = 0xFFFFFFFF
cmpl $0x0, -0x18(%rbp)
je 0x8d2e
cmpl $0x100, -0x18(%rbp)     # imm = 0x100
jbe 0x8c3d
movl $0x100, %eax            # imm = 0x100
movl %eax, -0x134(%rbp)
jmp 0x8c46
movl -0x18(%rbp), %eax
movl %eax, -0x134(%rbp)
movl -0x134(%rbp), %eax
movl %eax, -0x12c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq -0x120(%rbp), %rdx
movl -0x12c(%rbp), %ecx
callq 0x7420
cmpl $0x0, %eax
je 0x8c97
movq 0x7379(%rip), %rax      # 0xfff0
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x1cc5(%rip), %rsi      # 0xa949
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x8d59
movl -0x130(%rbp), %edi
movl -0x12c(%rbp), %edx
leaq -0x120(%rbp), %rsi
callq 0x8a60
movl %eax, -0x130(%rbp)
movl -0x12c(%rbp), %ecx
movl -0x18(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x12c(%rbp), %ecx
movl -0x14(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x14(%rbp)
movq 0x7318(%rip), %rax      # 0xfff0
movq (%rax), %rdi
movl -0x14(%rbp), %edx
movl -0x128(%rbp), %eax
cvtsi2ss %rax, %xmm1
movss 0x1947(%rip), %xmm0     # 0xa638
divss %xmm1, %xmm0
movl -0x124(%rbp), %ecx
movl %edx, %eax
subl %ecx, %eax
cvtsi2ss %rax, %xmm1
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x3508(%rip), %rsi      # 0xc21b
movb $0x1, %al
callq 0x2160
movq 0x72cf(%rip), %rax      # 0xfff0
movq (%rax), %rdi
callq 0x21c0
jmp 0x8c1d
movq 0x72bb(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x1c89(%rip), %rsi      # 0xa9c8
movb $0x0, %al
callq 0x2160
movl -0x130(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw %cs:(%rax,%rax)