// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r12
movq $0x0, (%rdx)
movl $0x0, (%rcx)
callq 0xbe3b
movq %rax, (%rsp)
cmpb $0x0, (%rax)
je 0xcfcc
movq (%r13), %rdx
movq %rsp, %rsi
movq %rax, %rdi
callq 0xcc1f
cmpl $0x1, %eax
je 0xcfcc
testl %eax, %eax
jne 0xced8
movq $0x0, (%r13)
movq (%rsp), %rdi
callq 0xbe3b
movq %rax, (%rsp)
movl $0x1, (%r14)
movl $0x10, %edi
callq 0x5830
movq %rax, (%rbx)
callq 0x4540
movq (%rax), %rax
movq (%rsp), %r13
movsbq (%r13), %rcx
testb $0x4, 0x1(%rax,%rcx,2)
jne 0xcf32
testb %cl, %cl
je 0xcfcc
movl $0x1, %esi
movq %r13, %rdi
callq 0x5889
movq (%rbx), %rcx
movq %rax, (%rcx)
movq (%rsp), %rax
jmp 0xcf60
xorl %ebp, %ebp
movsbq 0x1(%r13,%rbp), %rcx
incq %rbp
testb $0x4, 0x1(%rax,%rcx,2)
jne 0xcf34
movq %r13, %rdi
movq %rbp, %rsi
callq 0x5889
movq (%rbx), %rcx
movq %rax, (%rcx)
leaq -0x1(,%rbp), %rax
addq %r13, %rax
movq %r15, 0x8(%rsp)
movq %rax, 0x18(%rsp)
leaq 0x1(%rax), %r13
movq %r13, (%rsp)
movq $0x0, (%r12)
movq (%rbx), %rax
movq (%rax), %rbp
leaq 0x19ef(%rip), %rdi      # 0xe976
movq %rbp, %rsi
callq 0x42e0
testl %eax, %eax
je 0xcfd3
movq %r12, 0x10(%rsp)
xorl %ecx, %ecx
leaq 0x8aff(%rip), %r15      # 0x15aa0
leaq 0x18(%rcx), %r12
cmpq $0x2d0, %r12            # imm = 0x2D0
je 0xcfcc
movq 0x18(%rcx,%r15), %rdi
movq %rbp, %rsi
callq 0x42e0
movq %r12, %rcx
testl %eax, %eax
jne 0xcfa1
addq %r12, %r15
movq 0x10(%rsp), %r12
jmp 0xcfda
xorl %eax, %eax
jmp 0xd115
leaq 0x8ac6(%rip), %r15      # 0x15aa0
movq %r15, (%r12)
movq 0x8(%rsp), %rax
movb $0x0, (%rax)
cmpb $0x21, (%r13)
jne 0xcffd
movb $0x1, (%rax)
movq 0x18(%rsp), %r13
addq $0x2, %r13
movq %r13, (%rsp)
movq %r13, %rdi
callq 0xbe3b
movq %rax, (%rsp)
movq (%r12), %rcx
cmpb $0x1, 0x10(%rcx)
jne 0xd041
movq (%rbx), %rdi
movslq (%r14), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r14)
leaq 0x10(,%rax,8), %rsi
callq 0x584a
movq %rax, (%rbx)
movq (%rsp), %rdi
callq 0x585c
movq (%rbx), %rcx
movq %rax, 0x8(%rcx)
jmp 0xd056
movzbl 0x12(%rcx), %ecx
xorl $0x1, %ecx
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xccac
movq (%rbx), %rax
movslq (%r14), %r14
movq $0x0, (%rax,%r14,8)
movq (%rbx), %rbp
callq 0xdaf0
movq (%rax), %rdi
callq 0x9216
movq %r14, 0x8(%rsp)
testq %r14, %r14
jle 0xd113
movq %rax, %rbx
xorl %r13d, %r13d
leaq 0x20(%rsp), %r15
movq (%rbp,%r13,8), %r12
movq %r12, %rax
movzbl (%rax), %ecx
cmpl $0x5c, %ecx
je 0xd100
testl %ecx, %ecx
je 0xd105
testq %rbx, %rbx
setne %dl
cmpb $0x25, %cl
sete %cl
andb %dl, %cl
cmpb $0x1, %cl
jne 0xd100
movl %eax, %r14d
subl %r12d, %r14d
movb $0x0, (%rax)
movq (%rbp,%r13,8), %rcx
movq %rcx, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
incq %rax
movq %rax, 0x30(%rsp)
leaq 0x166e(%rip), %rdi      # 0xe749
movq %r15, %rsi
movl $0x3, %edx
callq 0x58ca
movq %rax, %r12
movq (%rbp,%r13,8), %rdi
callq 0x4080
movq %r12, (%rbp,%r13,8)
movslq %r14d, %rax
addq %r12, %rax
incq %rax
jmp 0xd095
incq %r13
cmpq 0x8(%rsp), %r13
jne 0xd08d
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq