// File: /workspace/github_c_makefile_star2_O0/koendv[P]stm32duino-raspberrypi/Arduino_Tools/src/stm32flash/main.c
// Function: parse_options
int parse_options(int argc, char *argv[])
{
	int c;
	char *pLen;

	while ((c = getopt(argc, argv, "a:b:m:r:w:e:vn:g:jkfcChuos:S:F:i:R")) != -1) {
		switch(c) {
			case 'a':
				port_opts.bus_addr = strtoul(optarg, NULL, 0);
				break;

			case 'b':
				port_opts.baudRate = serial_get_baud(strtoul(optarg, NULL, 0));
				if (port_opts.baudRate == SERIAL_BAUD_INVALID) {
					serial_baud_t baudrate;
					fprintf(stderr,	"Invalid baud rate, valid options are:\n");
					for (baudrate = SERIAL_BAUD_1200; baudrate != SERIAL_BAUD_INVALID; ++baudrate)
						fprintf(stderr, " %d\n", serial_get_baud_int(baudrate));
					return 1;
				}
				break;

			case 'm':
				if (strlen(optarg) != 3
					|| serial_get_bits(optarg) == SERIAL_BITS_INVALID
					|| serial_get_parity(optarg) == SERIAL_PARITY_INVALID
					|| serial_get_stopbit(optarg) == SERIAL_STOPBIT_INVALID) {
					fprintf(stderr, "Invalid serial mode\n");
					return 1;
				}
				port_opts.serial_mode = optarg;
				break;

			case 'r':
			case 'w':
				if (action != ACT_NONE) {
					err_multi_action((c == 'r') ? ACT_READ : ACT_WRITE);
					return 1;
				}
				action = (c == 'r') ? ACT_READ : ACT_WRITE;
				filename = optarg;
				if (filename[0] == '-' && filename[1] == '\0') {
					use_stdinout = 1;
					force_binary = 1;
				}
				break;
			case 'e':
				if (readwrite_len || start_addr) {
					fprintf(stderr, "ERROR: Invalid options, can't specify start page / num pages and start address/length\n");
					return 1;
				}
				npages = strtoul(optarg, NULL, 0);
				if (npages > STM32_MAX_PAGES || npages < 0) {
					fprintf(stderr, "ERROR: You need to specify a page count between 0 and 255");
					return 1;
				}
				if (!npages)
					no_erase = 1;
				break;
			case 'u':
				if (action != ACT_NONE) {
					err_multi_action(ACT_WRITE_UNPROTECT);
					return 1;
				}
				action = ACT_WRITE_UNPROTECT;
				break;

			case 'j':
				if (action != ACT_NONE) {
					err_multi_action(ACT_READ_PROTECT);
					return 1;
				}
				action = ACT_READ_PROTECT;
				break;

			case 'k':
				if (action != ACT_NONE) {
					err_multi_action(ACT_READ_UNPROTECT);
					return 1;
				}
				action = ACT_READ_UNPROTECT;
				break;

			case 'o':
				if (action != ACT_NONE) {
					err_multi_action(ACT_ERASE_ONLY);
					return 1;
				}
				action = ACT_ERASE_ONLY;
				break;

			case 'v':
				verify = 1;
				break;

			case 'n':
				retry = strtoul(optarg, NULL, 0);
				break;

			case 'g':
				exec_flag = 1;
				execute   = strtoul(optarg, NULL, 0);
				if (execute % 4 != 0) {
					fprintf(stderr, "ERROR: Execution address must be word-aligned\n");
					return 1;
				}
				break;
			case 's':
				if (readwrite_len || start_addr) {
					fprintf(stderr, "ERROR: Invalid options, can't specify start page / num pages and start address/length\n");
					return 1;
				}
				spage    = strtoul(optarg, NULL, 0);
				break;
			case 'S':
				if (spage || npages) {
					fprintf(stderr, "ERROR: Invalid options, can't specify start page / num pages and start address/length\n");
					return 1;
				} else {
					start_addr = strtoul(optarg, &pLen, 0);
					if (*pLen == ':') {
						pLen++;
						readwrite_len = strtoul(pLen, NULL, 0);
						if (readwrite_len == 0) {
							fprintf(stderr, "ERROR: Invalid options, can't specify zero length\n");
							return 1;
						}
					}
				}
				break;
			case 'F':
				port_opts.rx_frame_max = strtoul(optarg, &pLen, 0);
				if (*pLen == ':') {
					pLen++;
					port_opts.tx_frame_max = strtoul(pLen, NULL, 0);
				}
				if (port_opts.rx_frame_max < 0
				    || port_opts.tx_frame_max < 0) {
					fprintf(stderr, "ERROR: Invalid negative value for option -F\n");
					return 1;
				}
				if (port_opts.rx_frame_max == 0)
					port_opts.rx_frame_max = STM32_MAX_RX_FRAME;
				if (port_opts.tx_frame_max == 0)
					port_opts.tx_frame_max = STM32_MAX_TX_FRAME;
				if (port_opts.rx_frame_max < 20
				    || port_opts.tx_frame_max < 6) {
					fprintf(stderr, "ERROR: current code cannot work with small frames.\n");
					fprintf(stderr, "min(RX) = 20, min(TX) = 6\n");
					return 1;
				}
				if (port_opts.rx_frame_max > STM32_MAX_RX_FRAME) {
					fprintf(stderr, "WARNING: Ignore RX length in option -F\n");
					port_opts.rx_frame_max = STM32_MAX_RX_FRAME;
				}
				if (port_opts.tx_frame_max > STM32_MAX_TX_FRAME) {
					fprintf(stderr, "WARNING: Ignore TX length in option -F\n");
					port_opts.tx_frame_max = STM32_MAX_TX_FRAME;
				}
				break;
			case 'f':
				force_binary = 1;
				break;

			case 'c':
				init_flag = 0;
				break;

			case 'h':
				show_help(argv[0]);
				exit(0);

			case 'i':
				gpio_seq = optarg;
				break;

			case 'R':
				reset_flag = 1;
				break;

			case 'C':
				if (action != ACT_NONE) {
					err_multi_action(ACT_CRC);
					return 1;
				}
				action = ACT_CRC;
				break;
		}
	}

	for (c = optind; c < argc; ++c) {
		if (port_opts.device) {
			fprintf(stderr, "ERROR: Invalid parameter specified\n");
			show_help(argv[0]);
			return 1;
		}
		port_opts.device = argv[c];
	}

	if (port_opts.device == NULL) {
		fprintf(stderr, "ERROR: Device not specified\n");
		show_help(argv[0]);
		return 1;
	}

	if ((action != ACT_WRITE) && verify) {
		fprintf(stderr, "ERROR: Invalid usage, -v is only valid when writing\n");
		show_help(argv[0]);
		return 1;
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x62a3(%rip), %rdx      # 0xac80
callq 0x2250
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0x508c
movl -0x14(%rbp), %eax
addl $-0x43, %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0x34, %eax
ja 0x5087
movq -0x30(%rbp), %rax
leaq 0x5c2e(%rip), %rcx      # 0xa63c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0xb5b2(%rip), %rax      # 0xffd0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2260
movl %eax, 0xb85e(%rip)      # 0x10290
jmp 0x5087
movq 0xb592(%rip), %rax      # 0xffd0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2260
movl %eax, %edi
callq 0x5670
movl %eax, 0xb827(%rip)      # 0x10280
cmpl $0x13, 0xb820(%rip)     # 0x10280
jne 0x4ac8
movq 0xb587(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x6230(%rip), %rsi      # 0xaca3
movb $0x0, %al
callq 0x2160
movl $0x0, -0x24(%rbp)
cmpl $0x13, -0x24(%rbp)
je 0x4abc
movq 0xb562(%rip), %rax      # 0xfff0
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movl -0x24(%rbp), %edi
callq 0x5880
movq -0x38(%rbp), %rdi
movl %eax, %edx
leaq 0x5ca8(%rip), %rsi      # 0xa752
movb $0x0, %al
callq 0x2160
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4a81
movl $0x1, -0x4(%rbp)
jmp 0x5178
jmp 0x5087
movq 0xb4fc(%rip), %rax      # 0xffd0
movq (%rax), %rdi
callq 0x20b0
cmpq $0x3, %rax
jne 0x4b1e
movq 0xb4e7(%rip), %rax      # 0xffd0
movq (%rax), %rdi
callq 0x5980
cmpl $0x4, %eax
je 0x4b1e
movq 0xb4d3(%rip), %rax      # 0xffd0
movq (%rax), %rdi
callq 0x5a60
cmpl $0x3, %eax
je 0x4b1e
movq 0xb4bf(%rip), %rax      # 0xffd0
movq (%rax), %rdi
callq 0x5b40
cmpl $0x2, %eax
jne 0x4b42
movq 0xb4cb(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x619b(%rip), %rsi      # 0xacca
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x5178
movq 0xb487(%rip), %rax      # 0xffd0
movq (%rax), %rax
movq %rax, 0xb735(%rip)      # 0x10288
jmp 0x5087
cmpl $0x0, 0xb861(%rip)      # 0x103c0
je 0x4b85
movl -0x14(%rbp), %ecx
movl $0x2, %edi
movl $0x1, %eax
cmpl $0x72, %ecx
cmovel %eax, %edi
callq 0x5420
movl $0x1, -0x4(%rbp)
jmp 0x5178
movl -0x14(%rbp), %edx
movl $0x2, %eax
movl $0x1, %ecx
cmpl $0x72, %edx
cmovel %ecx, %eax
movl %eax, 0xb822(%rip)      # 0x103c0
movq 0xb42b(%rip), %rax      # 0xffd0
movq (%rax), %rax
movq %rax, 0xb849(%rip)      # 0x103f8
movq 0xb842(%rip), %rax      # 0x103f8
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x4bdf
movq 0xb833(%rip), %rax      # 0x103f8
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x4bdf
movl $0x1, 0xb800(%rip)      # 0x103d8
movb $0x1, 0xb7fd(%rip)      # 0x103dc
jmp 0x5087
cmpl $0x0, 0xb801(%rip)      # 0x103ec
jne 0x4bf6
cmpl $0x0, 0xb7f4(%rip)      # 0x103e8
je 0x4c1a
movq 0xb3f3(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x60d8(%rip), %rsi      # 0xacdf
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x5178
movq 0xb3af(%rip), %rax      # 0xffd0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2260
movl %eax, 0xb78f(%rip)      # 0x103c4
cmpl $0xffff, 0xb785(%rip)   # imm = 0xFFFF
jg 0x4c4a
cmpl $0x0, 0xb77c(%rip)      # 0x103c4
jge 0x4c6e
movq 0xb39f(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x60db(%rip), %rsi      # 0xad36
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x5178
cmpl $0x0, 0xb74f(%rip)      # 0x103c4
jne 0x4c81
movl $0x1, 0xb74b(%rip)      # 0x103cc
jmp 0x5087
cmpl $0x0, 0xb733(%rip)      # 0x103c0
je 0x4ca5
movl $0x3, %edi
callq 0x5420
movl $0x1, -0x4(%rbp)
jmp 0x5178
movl $0x3, 0xb711(%rip)      # 0x103c0
jmp 0x5087
cmpl $0x0, 0xb705(%rip)      # 0x103c0
je 0x4cd3
movl $0x4, %edi
callq 0x5420
movl $0x1, -0x4(%rbp)
jmp 0x5178
movl $0x4, 0xb6e3(%rip)      # 0x103c0
jmp 0x5087
cmpl $0x0, 0xb6d7(%rip)      # 0x103c0
je 0x4d01
movl $0x5, %edi
callq 0x5420
movl $0x1, -0x4(%rbp)
jmp 0x5178
movl $0x5, 0xb6b5(%rip)      # 0x103c0
jmp 0x5087
cmpl $0x0, 0xb6a9(%rip)      # 0x103c0
je 0x4d2f
movl $0x6, %edi
callq 0x5420
movl $0x1, -0x4(%rbp)
jmp 0x5178
movl $0x6, 0xb687(%rip)      # 0x103c0
jmp 0x5087
movb $0x1, 0xb68b(%rip)      # 0x103d0
jmp 0x5087
movq 0xb27f(%rip), %rax      # 0xffd0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2260
movl %eax, 0xb53b(%rip)      # 0x102a0
jmp 0x5087
movb $0x1, 0xb660(%rip)      # 0x103d1
movq 0xb258(%rip), %rax      # 0xffd0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2260
movl %eax, 0xb648(%rip)      # 0x103d4
movl 0xb642(%rip), %eax      # 0x103d4
andl $0x3, %eax
cmpl $0x0, %eax
je 0x4dbe
movq 0xb24f(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x5fc5(%rip), %rsi      # 0xad70
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x5178
jmp 0x5087
cmpl $0x0, 0xb622(%rip)      # 0x103ec
jne 0x4dd5
cmpl $0x0, 0xb615(%rip)      # 0x103e8
je 0x4df9
movq 0xb214(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x5ef9(%rip), %rsi      # 0xacdf
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x5178
movq 0xb1d0(%rip), %rax      # 0xffd0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2260
movl %eax, 0xb5b4(%rip)      # 0x103c8
jmp 0x5087
cmpl $0x0, 0xb5a8(%rip)      # 0x103c8
jne 0x4e2b
cmpl $0x0, 0xb59b(%rip)      # 0x103c4
je 0x4e4f
movq 0xb1be(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x5ea3(%rip), %rsi      # 0xacdf
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x5178
movq 0xb17a(%rip), %rax      # 0xffd0
movq (%rax), %rdi
leaq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0x2260
movl %eax, 0xb57e(%rip)      # 0x103e8
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
jne 0x4ec6
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2260
movl %eax, 0xb555(%rip)      # 0x103ec
cmpl $0x0, 0xb54e(%rip)      # 0x103ec
jne 0x4ec4
movq 0xb149(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x5eee(%rip), %rsi      # 0xad9f
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x5178
jmp 0x4ec6
jmp 0x4ec8
jmp 0x5087
movq 0xb0fc(%rip), %rax      # 0xffd0
movq (%rax), %rdi
leaq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0x2260
movl %eax, 0xb3ac(%rip)      # 0x10294
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
jne 0x4f15
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2260
movl %eax, 0xb383(%rip)      # 0x10298
cmpl $0x0, 0xb378(%rip)      # 0x10294
jl 0x4f27
cmpl $0x0, 0xb373(%rip)      # 0x10298
jge 0x4f4b
movq 0xb0c2(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x5e9a(%rip), %rsi      # 0xadd2
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x5178
cmpl $0x0, 0xb342(%rip)      # 0x10294
jne 0x4f5e
movl $0x100, 0xb336(%rip)    # imm = 0x100
cmpl $0x0, 0xb333(%rip)      # 0x10298
jne 0x4f71
movl $0x102, 0xb327(%rip)    # imm = 0x102
cmpl $0x14, 0xb31c(%rip)     # 0x10294
jl 0x4f83
cmpl $0x6, 0xb317(%rip)      # 0x10298
jge 0x4fbf
movq 0xb066(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x5e6b(%rip), %rsi      # 0xadff
movb $0x0, %al
callq 0x2160
movq 0xb04e(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x5e87(%rip), %rsi      # 0xae33
movb $0x0, %al
callq 0x2160
movl $0x1, -0x4(%rbp)
jmp 0x5178
cmpl $0x100, 0xb2cb(%rip)    # imm = 0x100
jle 0x4fed
movq 0xb01e(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x5e72(%rip), %rsi      # 0xae4e
movb $0x0, %al
callq 0x2160
movl $0x100, 0xb2a7(%rip)    # imm = 0x100
cmpl $0x102, 0xb2a1(%rip)    # imm = 0x102
jle 0x501b
movq 0xaff0(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x5e6c(%rip), %rsi      # 0xae76
movb $0x0, %al
callq 0x2160
movl $0x102, 0xb27d(%rip)    # imm = 0x102
jmp 0x5087
movb $0x1, 0xb3b8(%rip)      # 0x103dc
jmp 0x5087
movb $0x0, 0xb277(%rip)      # 0x102a4
jmp 0x5087
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x5470
xorl %edi, %edi
callq 0x2290
movq 0xaf87(%rip), %rax      # 0xffd0
movq (%rax), %rax
movq %rax, 0xb38d(%rip)      # 0x103e0
jmp 0x5087
movb $0x1, 0xb381(%rip)      # 0x103dd
jmp 0x5087
cmpl $0x0, 0xb35b(%rip)      # 0x103c0
je 0x507d
movl $0x7, %edi
callq 0x5420
movl $0x1, -0x4(%rbp)
jmp 0x5178
movl $0x7, 0xb339(%rip)      # 0x103c0
jmp 0x49cf
movq 0xaf35(%rip), %rax      # 0xffc8
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x50f8
cmpq $0x0, 0xb1d0(%rip)      # 0x10278
je 0x50da
movq 0xaf3f(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x5de3(%rip), %rsi      # 0xae9e
movb $0x0, %al
callq 0x2160
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x5470
movl $0x1, -0x4(%rbp)
jmp 0x5178
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0xb18b(%rip)      # 0x10278
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x5098
cmpq $0x0, 0xb178(%rip)      # 0x10278
jne 0x512f
movq 0xaee7(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x5daf(%rip), %rsi      # 0xaec2
movb $0x0, %al
callq 0x2160
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x5470
movl $0x1, -0x4(%rbp)
jmp 0x5178
cmpl $0x2, 0xb28a(%rip)      # 0x103c0
je 0x5171
movsbl 0xb291(%rip), %eax      # 0x103d0
cmpl $0x0, %eax
je 0x5171
movq 0xaea5(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x5d8a(%rip), %rsi      # 0xaedf
movb $0x0, %al
callq 0x2160
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x5470
movl $0x1, -0x4(%rbp)
jmp 0x5178
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)