// File: /workspace/github_c_makefile_star2_O1/sasairc[P]clangsay/src/libbenly/src/cmd.c
// Function: parse_cmdline
int parse_cmdline(char* str, cmd_t** dest_cmd, cmd_t** dest_start)
{
    int     head    = 0,
            tail    = 0;

    cmd_t*  cmd     = NULL,
         *  start   = NULL;

    if ((cmd = (cmd_t*)
                malloc(sizeof(cmd_t))) == NULL) {
        fprintf(stderr, "malloc() failure\n");

        return -1;
    }

    start = cmd;
    cmd->io = NULL;
    cmd->next = NULL;
    cmd->prev = NULL;

    while (1) {
        if (str[head] == ';'        ||
                str[head] == '|'    ||
                str[head] == '&'    ||
                str[head] == '<'    ||
                str[head] == '>'    ||
                str[head] == '\0'   ||
                str[head] == '\n') {
            switch (str[head]) {
                case    ';':
                    head++;
                    set_cmd_val(&str[tail], TPAREN, &cmd);
                    break;
                case    '&':
                    if (str[head + 1] == '&') {
                        head += 2;
                        set_cmd_val(&str[tail], TAND, &cmd);
                    }
                    break;
                case    '|':
                    if (str[head + 1] == '|') {
                        head += 2;
                        set_cmd_val(&str[tail], TOR, &cmd);
                    } else {
                        head++;
                        set_cmd_val(&str[tail], TPIPE, &cmd);
                    }
                    break;
                case    '<':
                    if (str[head + 1] == '<') {
                        head += 2;
                        set_cmd_val(&str[tail], TCOM, &cmd);
                        tail = head;
                        head += set_io_val(&str[tail - 3], IOHERE, &cmd);
                    } else {
                        head++;
                        set_cmd_val(&str[tail], TCOM, &cmd);
                        tail = head;
                        head += set_io_val(&str[tail - 2], IOREAD, &cmd);
                    }
                    break;
                case    '>':
                    if (str[head + 1] == '>') {
                        head += 2;
                        set_cmd_val(&str[tail], TCOM, &cmd);
                        tail = head;
                        head += set_io_val(&str[tail - 3], IOCAT, &cmd);
                    } else {
                        head++;
                        set_cmd_val(&str[tail], TCOM, &cmd);
                        tail = head;
                        head += set_io_val(&str[tail - 2], IOWRITE, &cmd);
                    }
                    break;
                case    '\0':
                case    '\n':
                    set_cmd_val(&str[tail], TCOM, &cmd);
                    break;
            }
            if (str[head] == '\n' || str[head] == '\0')
                break;

            cmd = add_cmdline_t(&cmd);
            tail = head;
            head++;
        } else {
            head++;
        }
    }
    if (cmd->args[0][0] == '\0')
        goto NOCMD;

    *dest_cmd = start;
    *dest_start = start;

    return 0;

NOCMD:

    release_cmd_t(start);

    return -2;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r12
movq $0x0, 0x8(%rsp)
movl $0x28, %edi
callq 0x20e0
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x335d
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movq %rax, 0x10(%rsp)
movq $0x0, 0x20(%rax)
xorl %r15d, %r15d
leaq 0x8(%rsp), %r13
movq (%r13), %r14
xorl %eax, %eax
movslq %r15d, %rbp
leaq (%r12,%rbp), %rbx
movzbl (%r12,%rbp), %ecx
cmpl $0x3a, %ecx
jle 0x319a
cmpl $0x3d, %ecx
jg 0x31c3
cmpl $0x3b, %ecx
je 0x31ff
cmpl $0x3c, %ecx
jne 0x3261
cmpb $0x3c, 0x1(%r12,%rbp)
jne 0x32c6
movslq %eax, %rdi
addq %r12, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x2d8e
decq %rbx
movq %rbx, %rdi
movl $0x2, %esi
jmp 0x328f
testl %ecx, %ecx
je 0x31f2
cmpl $0xa, %ecx
je 0x31f2
cmpl $0x26, %ecx
jne 0x3261
cmpb $0x26, 0x1(%rbx)
jne 0x3215
addl $0x2, %r15d
movslq %eax, %rdi
addq %r12, %rdi
movl $0x4, %esi
jmp 0x320d
cmpl $0x3e, %ecx
je 0x3269
cmpl $0x7c, %ecx
jne 0x3261
cmpb $0x7c, 0x1(%r12,%rbp)
movslq %eax, %rdi
jne 0x32fa
addl $0x2, %r15d
addq %r12, %rdi
movl $0x5, %esi
jmp 0x320d
movslq %eax, %rdi
addq %r12, %rdi
movl $0x1, %esi
jmp 0x320d
incl %r15d
movslq %eax, %rdi
addq %r12, %rdi
movl $0x2, %esi
movq %r13, %rdx
callq 0x2d8e
movslq %r15d, %rax
movzbl (%r12,%rax), %eax
testl %eax, %eax
je 0x3315
cmpl $0xa, %eax
je 0x3315
movl $0x28, %edi
callq 0x20e0
movq %rax, 0x18(%r14)
testq %rax, %rax
je 0x3256
movq %r14, 0x20(%rax)
movq %rax, 0x8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movq %rax, %r14
jmp 0x3259
xorl %r14d, %r14d
movq %r14, 0x8(%rsp)
movl %r15d, %eax
incl %r15d
jmp 0x3143
cmpb $0x3e, 0x1(%r12,%rbp)
jne 0x32a3
movslq %eax, %rdi
addq %r12, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x2d8e
decq %rbx
movq %rbx, %rdi
movl $0x4, %esi
movq %r13, %rdx
callq 0x2b3c
addl %eax, %r15d
addl $0x2, %r15d
jmp 0x3215
incq %rbp
movslq %eax, %rdi
addq %r12, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x2d8e
decq %rbx
movq %rbx, %rdi
movl $0x3, %esi
jmp 0x32e7
incq %rbp
movslq %eax, %rdi
addq %r12, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x2d8e
decq %rbx
movq %rbx, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x2b3c
movl %eax, %r15d
addl %ebp, %r15d
jmp 0x3215
incq %rbp
addq %r12, %rdi
movl $0x3, %esi
movq %r13, %rdx
callq 0x2d8e
movl %ebp, %r15d
jmp 0x3215
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
cmpb $0x0, (%rax)
je 0x333f
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
movq %rcx, (%rax)
xorl %eax, %eax
jmp 0x334e
movq 0x10(%rsp), %rdi
callq 0x3369
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x24a0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x334e