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

	p_err = port->write(port, &cmd, 1);
	if (p_err != PORT_ERR_OK) {
		fprintf(stderr, "Failed to send init to device\n");
		return STM32_ERR_UNKNOWN;
	}
	p_err = port->read(port, &byte, 1);
	if (p_err == PORT_ERR_OK && byte == STM32_ACK)
		return STM32_ERR_OK;
	if (p_err == PORT_ERR_OK && byte == STM32_NACK) {
		/* We could get error later, but let's continue, for now. */
		fprintf(stderr,
			"Warning: the interface was not closed properly.\n");
		return STM32_ERR_OK;
	}
	if (p_err != PORT_ERR_TIMEDOUT) {
		fprintf(stderr, "Failed to init device.\n");
		return STM32_ERR_UNKNOWN;
	}

	/*
	 * Check if previous STM32_CMD_INIT was taken as first byte
	 * of a command. Send a new byte, we should get back a NACK.
	 */
	p_err = port->write(port, &cmd, 1);
	if (p_err != PORT_ERR_OK) {
		fprintf(stderr, "Failed to send init to device\n");
		return STM32_ERR_UNKNOWN;
	}
	p_err = port->read(port, &byte, 1);
	if (p_err == PORT_ERR_OK && byte == STM32_NACK)
		return STM32_ERR_OK;
	fprintf(stderr, "Failed to init device.\n");
	return STM32_ERR_UNKNOWN;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movb $0x7f, -0x1e(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rdi
leaq -0x1e(%rbp), %rsi
movl $0x1, %edx
callq *%rax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x7060
movq 0x8fad(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x51ec(%rip), %rsi      # 0xc239
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x7184
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rdi
leaq -0x1d(%rbp), %rsi
movl $0x1, %edx
callq *%rax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x7095
movzbl -0x1d(%rbp), %eax
cmpl $0x79, %eax
jne 0x7095
movl $0x0, -0x4(%rbp)
jmp 0x7184
cmpl $0x0, -0x1c(%rbp)
jne 0x70c8
movzbl -0x1d(%rbp), %eax
cmpl $0x1f, %eax
jne 0x70c8
movq 0x8f45(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x51a3(%rip), %rsi      # 0xc258
movb $0x0, %al
callq 0x2160
movl $0x0, -0x4(%rbp)
jmp 0x7184
cmpl $0x2, -0x1c(%rbp)
je 0x70f2
movq 0x8f1b(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x51aa(%rip), %rsi      # 0xc289
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x7184
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rdi
leaq -0x1e(%rbp), %rsi
movl $0x1, %edx
callq *%rax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x7133
movq 0x8ed7(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x5116(%rip), %rsi      # 0xc239
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x7184
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rdi
leaq -0x1d(%rbp), %rsi
movl $0x1, %edx
callq *%rax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x7165
movzbl -0x1d(%rbp), %eax
cmpl $0x1f, %eax
jne 0x7165
movl $0x0, -0x4(%rbp)
jmp 0x7184
movq 0x8e84(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x5113(%rip), %rsi      # 0xc289
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)