// File: /workspace/github_c_makefile_star2_O0/koendv[P]stm32duino-raspberrypi/Arduino_Tools/src/stm32flash/stm32.c
// Function: stm32_guess_len_cmd
static stm32_err_t stm32_guess_len_cmd(const stm32_t *stm, uint8_t cmd,
				       uint8_t *data, unsigned int len)
{
	struct port_interface *port = stm->port;
	port_err_t p_err;

	if (stm32_send_command(stm, cmd) != STM32_ERR_OK)
		return STM32_ERR_UNKNOWN;
	if (port->flags & PORT_BYTE) {
		/* interface is UART-like */
		p_err = port->read(port, data, 1);
		if (p_err != PORT_ERR_OK)
			return STM32_ERR_UNKNOWN;
		len = data[0];
		p_err = port->read(port, data + 1, len + 1);
		if (p_err != PORT_ERR_OK)
			return STM32_ERR_UNKNOWN;
		return STM32_ERR_OK;
	}

	p_err = port->read(port, data, len + 2);
	if (p_err == PORT_ERR_OK && len == data[0])
		return STM32_ERR_OK;
	if (p_err != PORT_ERR_OK) {
		/* restart with only one byte */
		if (stm32_resync(stm) != STM32_ERR_OK)
			return STM32_ERR_UNKNOWN;
		if (stm32_send_command(stm, cmd) != STM32_ERR_OK)
			return STM32_ERR_UNKNOWN;
		p_err = port->read(port, data, 1);
		if (p_err != PORT_ERR_OK)
			return STM32_ERR_UNKNOWN;
	}

	fprintf(stderr, "Re sync (len = %d)\n", data[0]);
	if (stm32_resync(stm) != STM32_ERR_OK)
		return STM32_ERR_UNKNOWN;

	len = data[0];
	if (stm32_send_command(stm, cmd) != STM32_ERR_OK)
		return STM32_ERR_UNKNOWN;
	p_err = port->read(port, data, len + 2);
	if (p_err != PORT_ERR_OK)
		return STM32_ERR_UNKNOWN;
	return STM32_ERR_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movzbl -0x11(%rbp), %esi
callq 0x7190
cmpl $0x0, %eax
je 0x7253
movl $0x1, -0x4(%rbp)
jmp 0x7414
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x72d9
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x1, %edx
callq *%rax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x728e
movl $0x1, -0x4(%rbp)
jmp 0x7414
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movl %ecx, %edx
callq *%rax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x72cd
movl $0x1, -0x4(%rbp)
jmp 0x7414
movl $0x0, -0x4(%rbp)
jmp 0x7414
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movl %ecx, %edx
callq *%rax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x7318
movl -0x24(%rbp), %eax
movq -0x20(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x7318
movl $0x0, -0x4(%rbp)
jmp 0x7414
cmpl $0x0, -0x34(%rbp)
je 0x7384
movq -0x10(%rbp), %rdi
callq 0x8e60
cmpl $0x0, %eax
je 0x7338
movl $0x1, -0x4(%rbp)
jmp 0x7414
movq -0x10(%rbp), %rdi
movzbl -0x11(%rbp), %esi
callq 0x7190
cmpl $0x0, %eax
je 0x7356
movl $0x1, -0x4(%rbp)
jmp 0x7414
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x1, %edx
callq *%rax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x7382
movl $0x1, -0x4(%rbp)
jmp 0x7414
jmp 0x7384
movq 0x8c65(%rip), %rax      # 0xfff0
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movzbl (%rax), %edx
leaq 0x4f75(%rip), %rsi      # 0xc311
movb $0x0, %al
callq 0x2160
movq -0x10(%rbp), %rdi
callq 0x8e60
cmpl $0x0, %eax
je 0x73ba
movl $0x1, -0x4(%rbp)
jmp 0x7414
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movzbl -0x11(%rbp), %esi
callq 0x7190
cmpl $0x0, %eax
je 0x73df
movl $0x1, -0x4(%rbp)
jmp 0x7414
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movl %ecx, %edx
callq *%rax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x740d
movl $0x1, -0x4(%rbp)
jmp 0x7414
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)