// File: /workspace/github_c_makefile_star2_O0/koendv[P]stm32duino-raspberrypi/Arduino_Tools/src/stm32flash/init.c
// Function: gpio_sequence
static int gpio_sequence(struct port_interface *port, const char *seq, size_t len_seq)
{
	struct gpio_list *gpio_to_release = NULL;
#if defined(__linux__)
	struct gpio_list *to_free;
#endif
	int ret = 0, level, gpio;
	int sleep_time = 0;
	int delimiter = 0;
	const char *sig_str = NULL;
	const char *s = seq;
	size_t l = len_seq;

	fprintf(diag, "\nGPIO sequence start\n");
	while (ret == 0 && *s && l > 0) {
		sig_str = NULL;
		sleep_time = 0;
		delimiter = 0;

		if (*s == '-') {
			level = 0;
			s++;
			l--;
		} else
			level = 1;

		if (isdigit(*s)) {
			gpio = atoi(s);
			while (isdigit(*s)) {
				s++;
				l--;
			}
		} else if (l >= 3 && !strncmp(s, "rts", 3)) {
			sig_str = s;
			gpio = -GPIO_RTS;
			s += 3;
			l -= 3;
		} else if (l >= 3 && !strncmp(s, "dtr", 3)) {
			sig_str = s;
			gpio = -GPIO_DTR;
			s += 3;
			l -= 3;
		} else if (l >= 3 && !strncmp(s, "brk", 3)) {
			sig_str = s;
			gpio = -GPIO_BRK;
			s += 3;
			l -= 3;
		} else if (*s && (l > 0)) {
			delimiter = 1;
			/* The ',' delimiter adds a 100 ms delay between signal toggles.
			 * i.e -rts,dtr will reset rts, wait 100 ms, set dtr.
			 *
			 * The '&' delimiter adds no delay between signal toggles.
			 * i.e -rts&dtr will reset rts and immediately set dtr.
			 *
			 * Example: -rts&dtr,,,rts,-dtr will reset rts and set dtr
			 * without delay, then wait 300 ms, set rts, wait 100 ms, reset dtr.
			 */
			if (*s == ',') {
				s++;
				l--;
				sleep_time = 100000;
			} else if (*s == '&') {
				s++;
				l--;
			} else {
				fprintf(stderr, "Character \'%c\' is not a valid signal or separator\n", *s);
				ret = 1;
				break;
			}
		} else {
			/* E.g. modifier without signal */
			fprintf(stderr, "Invalid sequence %.*s\n", (int) len_seq, seq);
			ret = 1;
			break;
		}

		if (!delimiter) { /* actual gpio/port signal driving */
			if (gpio < 0) {
				gpio = -gpio;
				fprintf(diag, " setting port signal %.3s to %i... ", sig_str, level);
				ret = (port->gpio(port, gpio, level) != PORT_ERR_OK);
				printStatus(diag, ret);
			} else {
				fprintf(diag, " setting gpio %i to %i... ", gpio, level);
				ret = (drive_gpio(gpio, level, &gpio_to_release) != 1);
				printStatus(diag, ret);
			}
		}

		if (sleep_time) {
			fprintf(diag, " delay %i us\n", sleep_time);
			usleep(sleep_time);
		}
	}
#if defined(__linux__)
	while (gpio_to_release) {
		release_gpio(gpio_to_release->gpio, gpio_to_release->input, gpio_to_release->exported);
		to_free = gpio_to_release;
		gpio_to_release = gpio_to_release->next;
		free(to_free);
	}
#endif
	fprintf(diag, "GPIO sequence end\n\n");
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq 0xdb40(%rip), %rax      # 0x103f0
movq (%rax), %rdi
leaq 0x7bc1(%rip), %rsi      # 0xa47b
movb $0x0, %al
callq 0x2160
xorl %eax, %eax
cmpl $0x0, -0x2c(%rbp)
movb %al, -0x59(%rbp)
jne 0x28e8
movq -0x50(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x59(%rbp)
je 0x28e8
cmpq $0x0, -0x58(%rbp)
seta %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x28f4
jmp 0x2c54
movq $0x0, -0x48(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x2937
movl $0x0, -0x30(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x293e
movl $0x1, -0x30(%rbp)
callq 0x22a0
movq (%rax), %rax
movq -0x50(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x29a9
movq -0x50(%rbp), %rdi
callq 0x2270
movl %eax, -0x34(%rbp)
callq 0x22a0
movq (%rax), %rax
movq -0x50(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x29a4
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x296a
jmp 0x2b6a
cmpq $0x3, -0x58(%rbp)
jb 0x29f6
movq -0x50(%rbp), %rdi
leaq 0x7ad6(%rip), %rsi      # 0xa491
movl $0x3, %edx
callq 0x2050
cmpl $0x0, %eax
jne 0x29f6
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movq -0x50(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
subq $0x3, %rax
movq %rax, -0x58(%rbp)
jmp 0x2b68
cmpq $0x3, -0x58(%rbp)
jb 0x2a43
movq -0x50(%rbp), %rdi
leaq 0x7a8d(%rip), %rsi      # 0xa495
movl $0x3, %edx
callq 0x2050
cmpl $0x0, %eax
jne 0x2a43
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0xfffffffe, -0x34(%rbp) # imm = 0xFFFFFFFE
movq -0x50(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
subq $0x3, %rax
movq %rax, -0x58(%rbp)
jmp 0x2b66
cmpq $0x3, -0x58(%rbp)
jb 0x2a90
movq -0x50(%rbp), %rdi
leaq 0x7a44(%rip), %rsi      # 0xa499
movl $0x3, %edx
callq 0x2050
cmpl $0x0, %eax
jne 0x2a90
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0xfffffffd, -0x34(%rbp) # imm = 0xFFFFFFFD
movq -0x50(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
subq $0x3, %rax
movq %rax, -0x58(%rbp)
jmp 0x2b64
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x2b34
cmpq $0x0, -0x58(%rbp)
jbe 0x2b34
movl $0x1, -0x3c(%rbp)
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2c, %eax
jne 0x2adf
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x58(%rbp)
movl $0x186a0, -0x38(%rbp)   # imm = 0x186A0
jmp 0x2b32
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x26, %eax
jne 0x2b05
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x2b30
movq 0xd4e4(%rip), %rax      # 0xfff0
movq (%rax), %rdi
movq -0x50(%rbp), %rax
movsbl (%rax), %edx
leaq 0x7980(%rip), %rsi      # 0xa49d
movb $0x0, %al
callq 0x2160
movl $0x1, -0x2c(%rbp)
jmp 0x2c54
jmp 0x2b32
jmp 0x2b62
movq 0xd4b5(%rip), %rax      # 0xfff0
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rcx
leaq 0x7981(%rip), %rsi      # 0xa4d0
movb $0x0, %al
callq 0x2160
movl $0x1, -0x2c(%rbp)
jmp 0x2c54
jmp 0x2b64
jmp 0x2b66
jmp 0x2b68
jmp 0x2b6a
cmpl $0x0, -0x3c(%rbp)
jne 0x2c26
cmpl $0x0, -0x34(%rbp)
jge 0x2bd7
xorl %eax, %eax
subl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
leaq 0xd867(%rip), %rax      # 0x103f0
movq (%rax), %rdi
movq -0x48(%rbp), %rdx
movl -0x30(%rbp), %ecx
leaq 0x794d(%rip), %rsi      # 0xa4e7
movb $0x0, %al
callq 0x2160
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x30(%rbp), %edx
callq *%rax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x2c(%rbp)
leaq 0xd826(%rip), %rax      # 0x103f0
movq (%rax), %rdi
movl -0x2c(%rbp), %esi
callq 0x9020
jmp 0x2c24
leaq 0xd812(%rip), %rax      # 0x103f0
movq (%rax), %rdi
movl -0x34(%rbp), %edx
movl -0x30(%rbp), %ecx
leaq 0x791d(%rip), %rsi      # 0xa50b
movb $0x0, %al
callq 0x2160
movl -0x34(%rbp), %edi
movl -0x30(%rbp), %esi
leaq -0x20(%rbp), %rdx
callq 0x2e00
cmpl $0x1, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x2c(%rbp)
leaq 0xd7d7(%rip), %rax      # 0x103f0
movq (%rax), %rdi
movl -0x2c(%rbp), %esi
callq 0x9020
jmp 0x2c26
cmpl $0x0, -0x38(%rbp)
je 0x2c4f
leaq 0xd7bd(%rip), %rax      # 0x103f0
movq (%rax), %rdi
movl -0x38(%rbp), %edx
leaq 0x78e6(%rip), %rsi      # 0xa526
movb $0x0, %al
callq 0x2160
movl -0x38(%rbp), %edi
callq 0x22b0
jmp 0x28c1
jmp 0x2c56
cmpq $0x0, -0x20(%rbp)
je 0x2c95
movq -0x20(%rbp), %rax
movl 0x8(%rax), %edi
movq -0x20(%rbp), %rax
movl 0xc(%rax), %esi
movq -0x20(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x3030
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rdi
callq 0x2030
jmp 0x2c56
leaq 0xd754(%rip), %rax      # 0x103f0
movq (%rax), %rdi
leaq 0x788e(%rip), %rsi      # 0xa534
movb $0x0, %al
callq 0x2160
movl -0x2c(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)