// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x28
popq %rdi
callq 0x20e0
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x2cc4
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
andq $0x0, 0x20(%rax)
xorl %r14d, %r14d
leaq 0x10(%rsp), %r13
movq %rax, 0x8(%rsp)
movq %rax, %r15
xorl %eax, %eax
movslq %r14d, %rbx
movzbl (%r12,%rbx), %ecx
movslq %eax, %rdi
testl %ecx, %ecx
je 0x2b62
cmpl $0xa, %ecx
je 0x2b62
leaq (%r12,%rbx), %rbp
cmpl $0x26, %ecx
je 0x2bd8
cmpl $0x7c, %ecx
je 0x2b69
cmpl $0x3c, %ecx
je 0x2ba4
cmpl $0x3e, %ecx
je 0x2b80
cmpl $0x3b, %ecx
jne 0x2c18
incl %r14d
addq %r12, %rdi
pushq $0x2
jmp 0x2be7
addq %r12, %rdi
pushq $0x1
jmp 0x2be7
cmpb $0x7c, 0x1(%r12,%rbx)
jne 0x2c20
addl $0x2, %r14d
addq %r12, %rdi
pushq $0x5
jmp 0x2be7
cmpb $0x3e, 0x1(%r12,%rbx)
jne 0x2c36
addq %r12, %rdi
pushq $0x1
popq %rsi
movq %r13, %rdx
callq 0x27d1
decq %rbp
movq %rbp, %rdi
pushq $0x4
jmp 0x2bc6
cmpb $0x3c, 0x1(%r12,%rbx)
jne 0x2c52
addq %r12, %rdi
pushq $0x1
popq %rsi
movq %r13, %rdx
callq 0x27d1
decq %rbp
movq %rbp, %rdi
pushq $0x2
popq %rsi
movq %r13, %rdx
callq 0x259c
addl %eax, %r14d
addl $0x2, %r14d
jmp 0x2bf0
cmpb $0x26, 0x1(%rbp)
jne 0x2bf0
addl $0x2, %r14d
addq %r12, %rdi
pushq $0x4
popq %rsi
movq %r13, %rdx
callq 0x27d1
movslq %r14d, %rax
movzbl (%r12,%rax), %eax
testl %eax, %eax
je 0x2c83
cmpl $0xa, %eax
je 0x2c83
movq %r13, %rdi
callq 0x2a8b
movq %rax, %r15
movq %rax, 0x10(%rsp)
movl %r14d, %eax
incl %r14d
jmp 0x2b1c
incq %rbx
addq %r12, %rdi
pushq $0x3
popq %rsi
movq %r13, %rdx
callq 0x27d1
movl %ebx, %r14d
jmp 0x2bf0
incq %rbx
addq %r12, %rdi
pushq $0x1
popq %rsi
movq %r13, %rdx
callq 0x27d1
decq %rbp
movq %rbp, %rdi
pushq $0x3
popq %rsi
jmp 0x2c70
incq %rbx
addq %r12, %rdi
pushq $0x1
popq %r14
movl %r14d, %esi
movq %r13, %rdx
callq 0x27d1
decq %rbp
movq %rbp, %rdi
movl %r14d, %esi
movq %r13, %rdx
callq 0x259c
movl %eax, %r14d
addl %ebx, %r14d
jmp 0x2bf0
movq 0x8(%r15), %rax
movq (%rax), %rax
cmpb $0x0, (%rax)
je 0x2ca8
movq 0x18(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
movq %rcx, (%rax)
xorl %eax, %eax
jmp 0x2cb5
movq 0x8(%rsp), %rdi
callq 0x2ce4
pushq $-0x2
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xe315(%rip), %rax      # 0x10fe0
movq (%rax), %rcx
leaq 0x832f(%rip), %rdi      # 0xb004
pushq $0x11
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
pushq $-0x1
jmp 0x2cb4