// File: /workspace/github_c_makefile_star2_O1/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 0xc1ac
movq %rax, (%rsp)
cmpb $0x0, (%rax)
je 0xd3b9
movq (%r13), %rdx
movq %rsp, %rsi
movq %rax, %rdi
callq 0xcf99
cmpl $0x1, %eax
je 0xd3b9
testl %eax, %eax
jne 0xd245
movq $0x0, (%r13)
movq (%rsp), %rdi
callq 0xc1ac
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 0xd29b
testb %cl, %cl
je 0xd3b9
movl $0x1, %esi
movq %r13, %rdi
callq 0x58a8
movq (%rbx), %rcx
movq %rax, (%rcx)
jmp 0xd2cd
xorl %ebp, %ebp
movsbq 0x1(%r13,%rbp), %rcx
incq %rbp
testb $0x4, 0x1(%rax,%rcx,2)
jne 0xd29d
movq %r13, %rdi
movq %rbp, %rsi
callq 0x58a8
movq (%rbx), %rcx
movq %rax, (%rcx)
leaq -0x1(,%rbp), %rax
addq %r13, %rax
movq %rax, (%rsp)
movq %r15, 0x8(%rsp)
movq (%rsp), %rax
movq %rax, 0x10(%rsp)
incq %rax
movq %rax, 0x18(%rsp)
movq %rax, (%rsp)
movq $0x0, (%r12)
movq (%rbx), %rax
movq (%rax), %r13
leaq 0x268a(%rip), %rdi      # 0xf986
movq %r13, %rsi
callq 0x42d0
testl %eax, %eax
je 0xd33d
movq %r12, %rbp
xorl %ecx, %ecx
leaq 0x978c(%rip), %r15      # 0x16aa0
leaq 0x18(%rcx), %r12
cmpq $0x2d0, %r12            # imm = 0x2D0
je 0xd34b
movq 0x18(%rcx,%r15), %rdi
movq %r13, %rsi
callq 0x42d0
movq %r12, %rcx
testl %eax, %eax
jne 0xd314
addq %r12, %r15
movq %rbp, %r12
jmp 0xd344
leaq 0x975c(%rip), %r15      # 0x16aa0
movq %r12, %rbp
movq %r15, (%r12)
cmpq $0x0, (%rbp)
je 0xd3b9
movq 0x8(%rsp), %rax
movb $0x0, (%rax)
movq 0x18(%rsp), %rcx
cmpb $0x21, (%rcx)
jne 0xd374
movb $0x1, (%rax)
movq 0x10(%rsp), %rax
addq $0x2, %rax
movq %rax, (%rsp)
movq (%rsp), %rdi
callq 0xc1ac
movq %rax, (%rsp)
movq (%rbp), %rcx
cmpb $0x1, 0x10(%rcx)
jne 0xd3c0
movq (%rbx), %rdi
movslq (%r14), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%r14)
leaq 0x10(,%rax,8), %rsi
callq 0x5851
movq %rax, (%rbx)
movq (%rsp), %rdi
callq 0x5863
movq (%rbx), %rcx
movq %rax, 0x8(%rcx)
jmp 0xd3d5
xorl %eax, %eax
jmp 0xd496
movzbl 0x12(%rcx), %ecx
xorl $0x1, %ecx
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xd028
movq (%rbx), %rax
movslq (%r14), %r14
movq $0x0, (%rax,%r14,8)
movq (%rbx), %rbp
callq 0xde6c
movq (%rax), %rdi
callq 0x9348
movq %r14, 0x8(%rsp)
testq %r14, %r14
jle 0xd494
movq %rax, %rbx
xorl %r13d, %r13d
leaq 0x20(%rsp), %r15
movq (%rbp,%r13,8), %rax
movzbl (%rax), %ecx
cmpl $0x5c, %ecx
je 0xd481
testl %ecx, %ecx
je 0xd486
testq %rbx, %rbx
setne %dl
cmpb $0x25, %cl
sete %cl
andb %dl, %cl
cmpb $0x1, %cl
jne 0xd481
movl (%rbp,%r13,8), %ecx
movl %eax, %r14d
subl %ecx, %r14d
movb $0x0, (%rax)
movq (%rbp,%r13,8), %rcx
movq %rcx, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
incq %rax
movq %rax, 0x30(%rsp)
leaq 0x22fc(%rip), %rdi      # 0xf758
movq %r15, %rsi
movl $0x3, %edx
callq 0x58fe
movq %rax, %r12
movq (%rbp,%r13,8), %rdi
callq 0x4080
movq %r12, (%rbp,%r13,8)
movslq %r14d, %rax
addq %r12, %rax
incq %rax
jmp 0xd411
incq %r13
cmpq 0x8(%rsp), %r13
jne 0xd40c
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq