// File: /workspace/github_c_makefile_star2_O2/bobrippling[P]tim/parse_cmd.c
// Function: parse_ranged_cmd
bool parse_ranged_cmd(
		char *cmd,
		const cmd_t **pcmd_f,
		char ***pargv, int *pargc,
		bool *pforce,
		struct range **prange)
{
#define cmd_f (*pcmd_f)
#define argv (*pargv)
#define argc (*pargc)
#define force (*pforce)
#define range (*prange)
	argv = NULL;
	argc = 0;

	char *cmd_i = skipspace(cmd);

	if(!*cmd_i)
		return false;

	switch(parse_range(cmd_i, &cmd_i, range)){
		case RANGE_PARSE_FAIL:
			return false;
		case RANGE_PARSE_NONE:
			range = NULL;
		case RANGE_PARSE_PASS:
			break;
	}

	cmd_i = skipspace(cmd_i);

	/* alpha or single non-ascii for command */
	argc = 1;
	argv = umalloc((argc + 1) * sizeof *argv);

	if(isalpha(*cmd_i)){
		char *p;
		for(p = cmd_i + 1; isalpha(*p); p++);
		argv[0] = ustrdup_len(cmd_i, p - cmd_i);
		cmd_i = p - 1;
	}else if(*cmd_i){
		argv[0] = ustrdup_len(cmd_i, 1);
	}else{
		return false;
	}
	cmd_i++;

	/* look for command */
	cmd_f = NULL;
	for(int i = 0; cmds[i].arg0; i++)
		if(!strcmp(cmds[i].arg0, argv[0])){
			cmd_f = &cmds[i];
			break;
		}

	if(!cmd_f)
		return false;

	force = false;
	/* no whitespace - force must be directly after */
	if(*cmd_i == '!')
		force = true, cmd_i++;

	cmd_i = skipspace(cmd_i);

	if(cmd_f->single_arg){
		argv = urealloc(argv, (++argc + 1) * sizeof *argv);
		argv[1] = ustrdup(cmd_i);

	}else{
		parse_cmd(cmd_i, &argc, &argv, !cmd_f->skipglob);
	}
	argv[argc] = NULL;

	filter_argv(&argc, &argv);

	return true;
#undef cmd_f
#undef argv
#undef argc
#undef force
#undef range
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r13
movq %r8, %r12
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r15
andq $0x0, (%rdx)
andl $0x0, (%rcx)
callq 0xb627
movq %rax, (%rsp)
cmpb $0x0, (%rax)
je 0xc76e
movq (%r13), %rdx
movq %rsp, %rsi
movq %rax, %rdi
callq 0xc37c
cmpl $0x1, %eax
je 0xc76e
testl %eax, %eax
jne 0xc61c
andq $0x0, (%r13)
movq (%rsp), %rdi
callq 0xb627
movq %rax, (%rsp)
movl $0x1, (%r14)
pushq $0x10
popq %rdi
callq 0x5648
movq %rax, (%rbx)
callq 0x4540
movq (%rax), %rax
movq (%rsp), %r13
movsbq (%r13), %rcx
testb $0x4, 0x1(%rax,%rcx,2)
jne 0xc67c
testb %cl, %cl
je 0xc76e
movq %r12, 0x10(%rsp)
movq %r14, 0x8(%rsp)
pushq $0x1
popq %rsi
movq %r13, %rdi
callq 0x5690
movq (%rbx), %rcx
movq %rax, (%rcx)
movq (%rsp), %r12
jmp 0xc6b4
movq %r12, 0x10(%rsp)
xorl %ebp, %ebp
movsbq 0x1(%r13,%rbp), %rcx
incq %rbp
testb $0x4, 0x1(%rax,%rcx,2)
jne 0xc683
movq %r14, 0x8(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x5690
movq (%rbx), %rcx
movq %rax, (%rcx)
leaq -0x1(,%rbp), %r12
addq %r13, %r12
leaq 0x1(%r12), %r13
movq %r13, (%rsp)
movq %r15, 0x18(%rsp)
andq $0x0, (%r15)
movq (%rbx), %rax
movq (%rax), %rbp
xorl %ecx, %ecx
leaq 0x93cb(%rip), %r15      # 0x15aa0
leaq 0x18(%rcx), %r14
cmpq $0x2e8, %r14            # imm = 0x2E8
je 0xc76e
movq (%rcx,%r15), %rdi
movq %rbp, %rsi
callq 0x42e0
movq %r14, %rcx
testl %eax, %eax
jne 0xc6d5
leaq (%r14,%r15), %rax
addq $-0x18, %rax
movq 0x18(%rsp), %r14
movq %rax, (%r14)
movq 0x10(%rsp), %rax
movb $0x0, (%rax)
cmpb $0x21, (%r13)
jne 0xc726
movb $0x1, (%rax)
addq $0x2, %r12
movq %r12, (%rsp)
movq %r12, %r13
movq %r13, %rdi
callq 0xb627
movq %rax, (%rsp)
movq (%r14), %rcx
cmpb $0x1, 0x10(%rcx)
movq 0x8(%rsp), %r14
jne 0xc77f
movq (%rbx), %rdi
movslq (%r14), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r14)
leaq 0x10(,%rax,8), %rsi
callq 0x5660
movq %rax, (%rbx)
movq (%rsp), %rdi
callq 0x5672
movq (%rbx), %rcx
movq %rax, 0x8(%rcx)
jmp 0xc794
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl 0x12(%rcx), %ecx
xorl $0x1, %ecx
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xc404
movq (%rbx), %rax
movslq (%r14), %r15
andq $0x0, (%rax,%r15,8)
movq (%rbx), %r13
callq 0xd170
movq (%rax), %rdi
callq 0x8cc6
xorl %r14d, %r14d
testl %r15d, %r15d
movl $0x0, %ecx
cmovgl %r15d, %ecx
movq %rcx, 0x8(%rsp)
movq %rax, %rbx
pushq $0x3
popq %rbp
cmpq 0x8(%rsp), %r14
je 0xc84f
movq (%r13,%r14,8), %r12
movq %r12, %rax
movzbl (%rax), %ecx
cmpl $0x5c, %ecx
je 0xc842
testl %ecx, %ecx
je 0xc847
testq %rbx, %rbx
setne %dl
cmpb $0x25, %cl
sete %cl
andb %dl, %cl
cmpb $0x1, %cl
jne 0xc842
movl %eax, %r15d
subl %r12d, %r15d
movb $0x0, (%rax)
movq (%r13,%r14,8), %rcx
movq %rcx, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
incq %rax
movq %rax, 0x30(%rsp)
leaq 0x1f2b(%rip), %rdi      # 0xe749
leaq 0x20(%rsp), %rsi
movl %ebp, %edx
callq 0x56c3
movq %rax, %r12
movq (%r13,%r14,8), %rdi
callq 0x4080
movq %r12, (%r13,%r14,8)
movslq %r15d, %rax
addq %r12, %rax
incq %rax
jmp 0xc7d8
incq %r14
jmp 0xc7c9
movb $0x1, %al
jmp 0xc770