// File: /workspace/github_c_makefile_star2_O1/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)
je 0x2b8a
cmpb $0x3e, 0x1(%r15)
jne 0x2b8a
movq %r15, %rdi
callq 0x22f0
movl %eax, %ebx
leaq 0x2(%r15), %r12
leaq 0x3(%r15), %rcx
cmpb $0x3e, 0x2(%r15)
cmoveq %rcx, %r12
jmp 0x2bb3
leaq 0x2(%r15), %r12
movb 0x2(%r15), %cl
leaq 0x3(%r15), %rax
cmpb $0x3e, 0x1(%r15)
jne 0x2baa
cmpb $0x3e, %cl
cmoveq %rax, %r12
movw $0x1, %bx
jmp 0x2bb3
cmpb $0x3c, %cl
cmoveq %rax, %r12
xorl %ebx, %ebx
leaq 0x1(%r12), %rsi
movl $0x1, %r15d
movabsq $0x5800004000000401, %rcx # imm = 0x5800004000000401
movq %r14, 0x10(%rsp)
movl %ebp, 0xc(%rsp)
movzbl -0x1(%rsi), %edx
cmpq $0x3e, %rdx
ja 0x2be1
btq %rdx, %rcx
jb 0x2bee
cmpl $0x7c, %edx
je 0x2bee
incq %rsi
incq %r15
jmp 0x2bd1
movzbl -0x1(%rsi), %ecx
cmpl $0x26, %ecx
je 0x2bfe
cmpl $0x7c, %ecx
jne 0x2c08
jmp 0x2c1c
cmpb $0x26, (%rsi)
je 0x2c2d
cmpb $0x7c, %cl
je 0x2c1c
movsbq %cl, %rcx
incq %rsi
testb $0x20, 0x1(%r13,%rcx,2)
jne 0x2bee
xorl %r14d, %r14d
jmp 0x2c3d
xorl %ecx, %ecx
cmpb $0x7c, (%rsi)
sete %cl
leal 0x3(,%rcx,2), %edx
jmp 0x2c32
movl $0x4, %edx
movq (%r14), %rcx
movl %edx, (%rcx)
movl $0x1, %r14d
movq %r15, %rdi
callq 0x20e0
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
testq %rax, %rax
je 0x2ce1
movq %rax, %r13
leaq -0x1(%r15), %rdx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2460
movb $0x0, -0x1(%r13,%r15)
movq %r13, %rdi
callq 0x2cf2
movl $0x10, %edi
callq 0x20e0
testq %rax, %rax
je 0x2ce1
movq %rax, %r12
movq %r15, %rdi
callq 0x20e0
movq %rax, 0x8(%r12)
testq %rax, %rax
je 0x2cdc
movq %rax, %rbp
movq %r13, %rdi
callq 0x21b0
leaq 0x1(%rax), %rdx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2460
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 0x2ce1
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq