// File: /workspace/github_c_makefile_star2_O3/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
movl $0x28, %edi
callq 0x20e0
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x32fd
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movq $0x0, 0x20(%rax)
xorl %r14d, %r14d
leaq 0x10(%rsp), %r13
movq %rax, 0x8(%rsp)
movq %rax, %r15
xorl %ecx, %ecx
movslq %r14d, %rbp
leaq (%r12,%rbp), %rbx
movzbl (%r12,%rbp), %eax
cmpl $0x3a, %eax
jle 0x314c
cmpl $0x3d, %eax
jg 0x3171
cmpl $0x3b, %eax
je 0x31ae
cmpl $0x3c, %eax
jne 0x31a9
cmpb $0x3c, 0x1(%r12,%rbp)
jne 0x326b
movslq %ecx, %rdi
addq %r12, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x2d23
decq %rbx
movq %rbx, %rdi
movl $0x2, %esi
jmp 0x3234
testl %eax, %eax
je 0x319c
cmpl $0xa, %eax
je 0x319c
cmpl $0x26, %eax
jne 0x31a9
cmpb $0x26, 0x1(%rbx)
jne 0x31c4
addl $0x2, %r14d
movslq %ecx, %rdi
addq %r12, %rdi
movl $0x4, %esi
jmp 0x31bc
cmpl $0x3e, %eax
je 0x320e
cmpl $0x7c, %eax
jne 0x31a9
cmpb $0x7c, 0x1(%r12,%rbp)
movslq %ecx, %rdi
jne 0x329f
addl $0x2, %r14d
addq %r12, %rdi
movl $0x5, %esi
jmp 0x31bc
movslq %ecx, %rdi
addq %r12, %rdi
movl $0x1, %esi
jmp 0x31bc
movq %r15, %rax
jmp 0x3203
incl %r14d
movslq %ecx, %rdi
addq %r12, %rdi
movl $0x2, %esi
movq %r13, %rdx
callq 0x2d23
movslq %r14d, %rax
movzbl (%r12,%rax), %eax
testl %eax, %eax
je 0x32ba
cmpl $0xa, %eax
je 0x32ba
movl $0x28, %edi
callq 0x20e0
movq %rax, 0x18(%r15)
testq %rax, %rax
je 0x31fb
movq %r15, 0x20(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movq %rax, 0x10(%rsp)
movl %r14d, %ecx
incl %r14d
movq %rax, %r15
jmp 0x30f5
cmpb $0x3e, 0x1(%r12,%rbp)
jne 0x3248
movslq %ecx, %rdi
addq %r12, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x2d23
decq %rbx
movq %rbx, %rdi
movl $0x4, %esi
movq %r13, %rdx
callq 0x2adc
addl %eax, %r14d
addl $0x2, %r14d
jmp 0x31c4
incq %rbp
movslq %ecx, %rdi
addq %r12, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x2d23
decq %rbx
movq %rbx, %rdi
movl $0x3, %esi
jmp 0x328c
incq %rbp
movslq %ecx, %rdi
addq %r12, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x2d23
decq %rbx
movq %rbx, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x2adc
movl %eax, %r14d
addl %ebp, %r14d
jmp 0x31c4
incq %rbp
addq %r12, %rdi
movl $0x3, %esi
movq %r13, %rdx
callq 0x2d23
movl %ebp, %r14d
jmp 0x31c4
movq 0x8(%r15), %rax
movq (%rax), %rax
cmpb $0x0, (%rax)
je 0x32df
movq 0x18(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
movq %rcx, (%rax)
xorl %eax, %eax
jmp 0x32ee
movq 0x8(%rsp), %rdi
callq 0x3309
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x24b0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x32ee