// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x28, %edi
callq 0x20e0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x30aa
movq 0x13f5b(%rip), %rax     # 0x16fe8
movq (%rax), %rdi
leaq 0xef6d(%rip), %rsi      # 0x12004
movb $0x0, %al
callq 0x23f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x348a
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3b, %eax
je 0x3151
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7c, %eax
je 0x3151
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x26, %eax
je 0x3151
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3c, %eax
je 0x3151
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3e, %eax
je 0x3151
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x3151
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x3438
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x3c(%rbp)
testl %eax, %eax
je 0x33dd
jmp 0x316a
movl -0x3c(%rbp), %eax
subl $0xa, %eax
je 0x33dd
jmp 0x3178
movl -0x3c(%rbp), %eax
subl $0x26, %eax
je 0x31dc
jmp 0x3182
movl -0x3c(%rbp), %eax
subl $0x3b, %eax
je 0x31b5
jmp 0x318c
movl -0x3c(%rbp), %eax
subl $0x3c, %eax
je 0x327a
jmp 0x319a
movl -0x3c(%rbp), %eax
subl $0x3e, %eax
je 0x332d
jmp 0x31a8
movl -0x3c(%rbp), %eax
subl $0x7c, %eax
je 0x3219
jmp 0x33f6
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movl $0x2, %esi
leaq -0x30(%rbp), %rdx
callq 0x2a50
jmp 0x33f6
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x26, %eax
jne 0x3214
movl -0x24(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movl $0x4, %esi
leaq -0x30(%rbp), %rdx
callq 0x2a50
jmp 0x33f6
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7c, %eax
jne 0x3253
movl -0x24(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movl $0x5, %esi
leaq -0x30(%rbp), %rdx
callq 0x2a50
jmp 0x3275
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movl $0x3, %esi
leaq -0x30(%rbp), %rdx
callq 0x2a50
jmp 0x33f6
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3c, %eax
jne 0x32dd
movl -0x24(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movl $0x1, %esi
leaq -0x30(%rbp), %rdx
callq 0x2a50
movl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movl -0x28(%rbp), %eax
subl $0x3, %eax
cltq
addq %rax, %rdi
movl $0x2, %esi
leaq -0x30(%rbp), %rdx
callq 0x2550
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x3328
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movl $0x1, %esi
leaq -0x30(%rbp), %rdx
callq 0x2a50
movl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movl -0x28(%rbp), %eax
subl $0x2, %eax
cltq
addq %rax, %rdi
movl $0x1, %esi
leaq -0x30(%rbp), %rdx
callq 0x2550
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x33f6
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3e, %eax
jne 0x3390
movl -0x24(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movl $0x1, %esi
leaq -0x30(%rbp), %rdx
callq 0x2a50
movl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movl -0x28(%rbp), %eax
subl $0x3, %eax
cltq
addq %rax, %rdi
movl $0x4, %esi
leaq -0x30(%rbp), %rdx
callq 0x2550
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x33db
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movl $0x1, %esi
leaq -0x30(%rbp), %rdx
callq 0x2a50
movl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movl -0x28(%rbp), %eax
subl $0x2, %eax
cltq
addq %rax, %rdi
movl $0x3, %esi
leaq -0x30(%rbp), %rdx
callq 0x2550
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x33f6
movq -0x10(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movl $0x1, %esi
leaq -0x30(%rbp), %rdx
callq 0x2a50
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
je 0x3418
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x341a
jmp 0x3446
leaq -0x30(%rbp), %rdi
callq 0x2fb0
movq %rax, -0x30(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3441
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x30d6
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x345b
jmp 0x347a
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x348a
movq -0x38(%rbp), %rdi
callq 0x34a0
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)