// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movw $0x0, -0x2e(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
callq 0x21c0
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x2606
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x3e, %eax
jne 0x2606
movq -0x10(%rbp), %rdi
callq 0x22c0
movw %ax, -0x2e(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x3e, %eax
jne 0x25f8
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x3e, %eax
jne 0x25f8
movq -0x10(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x10(%rbp)
jmp 0x2604
movq -0x10(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x10(%rbp)
jmp 0x2673
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x3e, %eax
jne 0x2642
movw $0x1, -0x2e(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x3e, %eax
jne 0x2634
movq -0x10(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x10(%rbp)
jmp 0x2640
movq -0x10(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x10(%rbp)
jmp 0x2671
movw $0x0, -0x2e(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x3c, %eax
jne 0x2663
movq -0x10(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x10(%rbp)
jmp 0x266f
movq -0x10(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x10(%rbp)
jmp 0x2671
jmp 0x2673
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x3b, %ecx
movb %al, -0x49(%rbp)
je 0x26f1
movq -0x10(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x7c, %ecx
movb %al, -0x49(%rbp)
je 0x26f1
movq -0x10(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x26, %ecx
movb %al, -0x49(%rbp)
je 0x26f1
movq -0x10(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x3c, %ecx
movb %al, -0x49(%rbp)
je 0x26f1
movq -0x10(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x3e, %ecx
movb %al, -0x49(%rbp)
je 0x26f1
movq -0x10(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x49(%rbp)
je 0x26f1
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
setne %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x26fa
jmp 0x2714
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x267b
jmp 0x2716
movq -0x10(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x4a(%rbp)
jne 0x2737
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
setne %al
movb %al, -0x4a(%rbp)
movb -0x4a(%rbp), %al
testb $0x1, %al
jne 0x2743
jmp 0x2805
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x26, %eax
jne 0x2777
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x26, %eax
jne 0x2777
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl $0x4, (%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2805
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7c, %eax
jne 0x27a8
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x7c, %eax
jne 0x27a8
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl $0x5, (%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2805
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7c, %eax
jne 0x27cc
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl $0x3, (%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2805
callq 0x21c0
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
jne 0x27ee
jmp 0x2805
jmp 0x27f0
jmp 0x27f2
jmp 0x27f4
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x2716
movq -0x40(%rbp), %rax
movq %rax, -0x10(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x0, %rdi
callq 0x20e0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x2835
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x2923
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
movslq -0x2c(%rbp), %rdx
callq 0x2410
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x38(%rbp), %rdi
callq 0x2930
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
jle 0x286c
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movl $0x10, %edi
callq 0x20e0
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
jne 0x288c
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x2923
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x0, %rdi
callq 0x20e0
movq -0x48(%rbp), %rcx
movq %rax, 0x8(%rcx)
cmpq $0x0, %rax
jne 0x28b5
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x2923
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rdi
callq 0x2190
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x2410
movw -0x2e(%rbp), %cx
movq -0x48(%rbp), %rax
movw %cx, (%rax)
movl -0x14(%rbp), %eax
movw %ax, %cx
movq -0x48(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x38(%rbp), %rdi
callq 0x2180
movq -0x48(%rbp), %rcx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x10(%rax)
movl -0x2c(%rbp), %eax
addl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)