// File: /workspace/github_c_makefile_star2_O2/sasairc[P]clangsay/src/libbenly/src/cmd.c
// Function: set_io_val
int set_io_val(char* str, int flag, cmd_t** cmd)
{
    int     msc = 0,
            off = 0,
            len = 0;

    short   unt = 0;

    char*   tmp = NULL,
        *   bak = NULL;

    io_t*   io  = NULL;

    /*
     * # io_unit
     * 1. N> file or N>> (N = STDIN, STDOUT, STDERR)
     * 2. > or >>
     * 3. < or <<
     */
    if (isdigit(*str) && *(str + 1) == '>') {
        unt = atoi(&*str);
        if (*(str + 1) == '>' && *(str + 2) == '>')
            str += 3;
        else
            str += 2;
    } else if (*(str + 1) == '>') {
        unt = 1;
        if (*(str + 2) == '>')
            str += 3;
        else
            str += 2;
    } else {
        unt = 0;
        if (*(str + 2) == '<')
            str += 3;
        else
            str += 2;
    }

    bak = str;
    while ( *str != ';'     &&
            *str != '|'     &&
            *str != '&'     &&
            *str != '<'     &&
            *str != '>'     &&
            *str != '\0'    &&
            *str != '\n') {
        str++;
        len++;
    }
    while (*str != '\0' || *str != '\n') {
        if (*str == '&' && *(str + 1) == '&') {
            (*cmd)->type = TAND;
            off++;
            break;
        } else if (*str == '|' && *(str + 1) == '|') {
            (*cmd)->type = TOR;
            off++;
            break;
        } else if (*str == '|') {
            (*cmd)->type = TPIPE;
            off++;
            break;
        } else if (!isspace(*str)) {
            break;
        }
        str++;
    }

    str = bak;
    if ((tmp = (char*)
                malloc(sizeof(char) * (len + 1))) == NULL)
        return -2;

    memcpy(tmp, str, len);
    tmp[len] = '\0';

    if ((msc = trim(tmp)) > 0)
        msc--;

    if ((io = (io_t*)
                malloc(sizeof(io_t))) == NULL)
        return -2;

    if ((io->io_name = (char*)
                malloc(sizeof(char) * (len + 1))) == NULL)
        return -3;

    memcpy(io->io_name, tmp, strlen(tmp) + 1);
    io->io_unit = unt;
    io->io_flag = flag;
    free(tmp);

    (*cmd)->io = io;

    return len + off + 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
callq 0x21e0
movq (%rax), %r13
movsbq (%r15), %rax
testb $0x8, 0x1(%r13,%rax,2)
movb 0x1(%r15), %al
jne 0x25d4
cmpb $0x3e, %al
jne 0x25e6
movw $0x1, %bx
jmp 0x25e2
cmpb $0x3e, %al
jne 0x25e6
movq %r15, %rdi
callq 0x22f0
movl %eax, %ebx
movb $0x3e, %dl
jmp 0x25ea
movb $0x3c, %dl
xorl %ebx, %ebx
leaq 0x2(%r15), %r12
leaq 0x3(%r15), %rcx
cmpb %dl, 0x2(%r15)
cmoveq %rcx, %r12
leaq 0x1(%r12), %rsi
pushq $0x1
popq %r15
movabsq $0x5800004000000401, %rdx # imm = 0x5800004000000401
movq %r14, 0x10(%rsp)
movl %ebp, 0xc(%rsp)
movzbl -0x1(%rsi), %ecx
cmpq $0x3e, %rcx
ja 0x2626
btq %rcx, %rdx
jb 0x2638
cmpl $0x7c, %ecx
je 0x2638
incq %rsi
incq %r15
jmp 0x2616
movb (%rsi), %cl
incq %rsi
cmpb $0x26, %cl
je 0x2647
movzbl %cl, %edx
cmpl $0x7c, %edx
jne 0x264c
jmp 0x265d
cmpb $0x26, (%rsi)
je 0x266d
movsbq %cl, %rcx
testb $0x20, 0x1(%r13,%rcx,2)
jne 0x2633
xorl %r14d, %r14d
jmp 0x2682
cmpb $0x7c, (%rsi)
movq (%r14), %rcx
jne 0x2678
movl $0x5, (%rcx)
jmp 0x267e
movq (%r14), %rax
movl $0x4, (%rax)
jmp 0x267e
movl $0x3, (%rcx)
pushq $0x1
popq %r14
movq %r15, %rdi
callq 0x20e0
pushq $-0x2
popq %rbp
testq %rax, %rax
je 0x2720
movq %rax, %r13
leaq -0x1(%r15), %rdx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2470
movb $0x0, -0x1(%r13,%r15)
movq %r13, %rdi
callq 0x2731
pushq $0x10
popq %rdi
callq 0x20e0
testq %rax, %rax
je 0x2720
movq %rax, %r12
movq %r15, %rdi
callq 0x20e0
movq %rax, 0x8(%r12)
testq %rax, %rax
je 0x271d
movq %rax, %rbp
movq %r13, %rdi
callq 0x21b0
leaq 0x1(%rax), %rdx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2470
movw %bx, (%r12)
movl 0xc(%rsp), %eax
movw %ax, 0x2(%r12)
movq %r13, %rdi
callq 0x21a0
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %r12, 0x10(%rax)
addl %r15d, %r14d
movl %r14d, %ebp
jmp 0x2720
pushq $-0x3
popq %rbp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq