// File: /workspace/github_c_makefile_star2_O3/sasairc[P]yasuna/src/libbenly/src/string.c
// Function: str_to_args
char** str_to_args(char* str)
{
    /*
     * # note
     *
     *  sx   : current strings array pointer
     *  xt   : temporary string array pointer
     *  ax   : args array pointer (X)
     *  ay   : args array pointer (Y)
     *  elmc : elements counter
     *  dspf : double space flag
     *  sqtf : single quote flag
     *  dqtf : double quote flag
     */
    int     i,
            ax, ay,
            elmc,
            dspf,
            sqtf,
            dqtf;

    size_t  sx, xt;

    char**  args    = NULL;
    
    /* count elements */
    for (i = dspf = sqtf = dqtf = 0, elmc = 1; str[i] != '\0'; i++) {
        if (str[i] == '\'') {
            if (sqtf == 0)
                sqtf = 1;
            else
                sqtf = 0;
        }
        if (str[i] == '\"') {
            if (dqtf == 0)
                dqtf = 1;
            else
                dqtf = 0;
        }
        if (sqtf == 1 || dqtf == 1)
            continue;

        if (str[i] == ' ' || str[i] == '\t') {
            if (dspf == 1)
                continue;
            elmc++;
        } else {
            dspf = 0;
        }
    }
    if (elmc > 0) {
        if ((args = (char**)
                    malloc(sizeof(char*) * (elmc + 1))) == NULL)
            return NULL;
    } else {
        return NULL;
    }

    /* string to args */
    for (dspf = sqtf = dqtf = sx = ay = ax = xt = 0; sx <= strlen(str); sx++) {
        if (str[sx] == ' ' || str[sx] == '\t' || str[sx] == '\0' || str[sx] == '\'' || str[sx] == '\"') {
            if (str[sx] == '\'') {
                if (sqtf == 0) {
                    xt++;
                    sqtf = 1;
                } else {
                    sqtf = 0;
                }
            }
            if (str[sx] == '\"') {
                if (dqtf == 0) {
                    xt++;
                    dqtf = 1;
                } else {
                    dqtf = 0;
                }
            }
            if (sqtf == 1 || dqtf == 1)
                continue;

            if (dspf == 1) {
                xt++;
                continue;
            }
            if ((args[ay] = (char*)
                        malloc(sizeof(char) * (sx - xt + 1))) == NULL)
                goto ERR;

            for (ax = 0; xt < sx; xt++, ax++)
                    args[ay][ax] = str[xt];

            args[ay][ax] = '\0';
            xt++;
            ay++;
            dspf = 1;
        } else {
            dspf = 0;
        }
    }
    /* null-terminated */
    args[elmc] = NULL;

#ifdef  DEBUG
    fprintf(stderr, "DEBUG: str_to_args(): args(%p)\n", args);
    for (i = 0; i <= elmc; i++)
        fprintf(stderr, "DEBUG: str_to_args(): args[%d](%p) = %s\n", i, args[i], args[i]);
/* DEBUG */
#endif

    return args;


ERR:
    for (i = 0; i < elmc; i++) {
        if (args[i] != NULL) {
            free(args[i]);
            args[i] = NULL;
        }
    }
    free(args);

    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
xorl %edx, %edx
movl $0x1, %eax
movq %rdi, %rcx
xorl %esi, %esi
movl %esi, %r8d
movzbl (%rcx), %r9d
cmpl $0x27, %r9d
je 0x1694
testl %r9d, %r9d
jne 0x169e
jmp 0x16cc
xorl %esi, %esi
testl %edx, %edx
sete %sil
movl %esi, %edx
xorl %esi, %esi
testl %r8d, %r8d
sete %sil
cmpl $0x22, %r9d
cmovnel %r8d, %esi
cmpl $0x1, %edx
je 0x16c7
cmpl $0x1, %esi
je 0x16c7
cmpl $0x20, %r9d
je 0x16c5
cmpl $0x9, %r9d
jne 0x16c7
incl %eax
incq %rcx
jmp 0x1680
testl %eax, %eax
jle 0x195c
movq %rdi, 0x10(%rsp)
movl %eax, %r14d
leaq 0x8(,%r14,8), %rdi
callq 0x1090
xorl %ebx, %ebx
testq %rax, %rax
je 0x195c
movq %r14, 0x20(%rsp)
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x1070
movq %r14, %r8
movl $0x1, %r10d
movabsq $0x8500000201, %r11     # imm = 0x8500000201
xorl %r12d, %r12d
xorl %ebp, %ebp
xorl %r9d, %r9d
xorl %ecx, %ecx
movl $0x0, 0xc(%rsp)
movq %rax, 0x28(%rsp)
movzbl (%r8,%rbp), %esi
xorl %edx, %edx
cmpq $0x27, %rsi
ja 0x1905
btq %rsi, %r11
jae 0x1905
xorl %edx, %edx
testl %r9d, %r9d
sete %dl
cmpb $0x27, %sil
sete %dil
cmovel %edx, %r9d
andb %dil, %dl
movzbl %dl, %r13d
movq %r12, 0x40(%rsp)
leaq (%r12,%r13), %r15
xorl %edx, %edx
testl %ebx, %ebx
sete %dl
cmpb $0x22, %sil
sete %sil
cmovel %edx, %ebx
andb %sil, %dl
movzbl %dl, %r14d
leaq (%r15,%r14), %r12
cmpl $0x1, %r9d
je 0x17a9
cmpl $0x1, %ebx
je 0x17a9
cmpl $0x1, %ecx
jne 0x17b0
incq %r12
jmp 0x18fb
movl %ecx, %edx
jmp 0x1905
movq %r10, 0x30(%rsp)
leaq 0x1(%rbp), %rdi
movq %rdi, 0x38(%rsp)
subq %r12, %rdi
callq 0x1090
movq %rax, %rdx
movslq 0xc(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rdx, (%rcx,%rax,8)
testq %rdx, %rdx
je 0x192a
cmpq %rbp, %r12
jae 0x18d5
movq 0x40(%rsp), %rsi
addq 0x10(%rsp), %rsi
addq %r14, %rsi
addq %r13, %rsi
addq %r14, %r15
movq %rbp, %rbx
subq %r15, %rbx
movq %rdx, %r14
movq %rdx, %rdi
movq %rbx, %rdx
callq 0x1080
decq %rbx
movq %rbx, %xmm0
pshufd $0x44, %xmm0, %xmm2     # xmm2 = xmm0[0,1,0,1]
movq 0x30(%rsp), %r10
movq %r10, %rax
subq %r15, %rax
andq $-0x2, %rax
pxor %xmm0, %xmm0
movl $0x2, %ecx
pcmpeqd %xmm3, %xmm3
movdqa %xmm0, %xmm1
psubq %xmm3, %xmm0
leaq (%rax,%rcx), %rdx
addq $-0x2, %rdx
addq $-0x2, %rcx
cmpq $0x2, %rdx
jne 0x1839
negq %rcx
movq %rcx, %xmm3
pshufd $0x44, %xmm3, %xmm3     # xmm3 = xmm3[0,1,0,1]
por 0x798(%rip), %xmm3      # 0x2000
movdqa 0x7a0(%rip), %xmm4      # 0x2010
pxor %xmm4, %xmm2
pxor %xmm4, %xmm3
movdqa %xmm3, %xmm4
pcmpgtd %xmm2, %xmm4
pshufd $0xa0, %xmm4, %xmm5     # xmm5 = xmm4[0,0,2,2]
pcmpeqd %xmm2, %xmm3
pshufd $0xf5, %xmm3, %xmm2     # xmm2 = xmm3[1,1,3,3]
pand %xmm5, %xmm2
pshufd $0xf5, %xmm4, %xmm3     # xmm3 = xmm4[1,1,3,3]
por %xmm2, %xmm3
pand %xmm3, %xmm1
pandn %xmm0, %xmm3
por %xmm1, %xmm3
pshufd $0xee, %xmm3, %xmm0     # xmm0 = xmm3[2,3,2,3]
paddq %xmm3, %xmm0
movq %xmm0, %rax
movl %eax, %ecx
movq 0x10(%rsp), %r8
movq 0x28(%rsp), %rax
movabsq $0x8500000201, %r11     # imm = 0x8500000201
movq 0x38(%rsp), %r12
movq %r14, %rdx
jmp 0x18f3
incq %r12
xorl %ecx, %ecx
movq 0x10(%rsp), %r8
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %r10
movabsq $0x8500000201, %r11     # imm = 0x8500000201
movb $0x0, (%rdx,%rcx)
incl 0xc(%rsp)
xorl %r9d, %r9d
movl $0x1, %edx
xorl %ebx, %ebx
incq %rbp
incq %r10
movl %edx, %ecx
cmpq %rax, %rbp
jbe 0x1735
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x195e
xorl %ebx, %ebx
movq 0x18(%rsp), %r14
movq 0x20(%rsp), %r15
movq (%r14,%rbx,8), %rdi
testq %rdi, %rdi
je 0x194c
callq 0x1030
movq $0x0, (%r14,%rbx,8)
incq %rbx
cmpq %rbx, %r15
jne 0x1936
movq %r14, %rdi
callq 0x1030
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq