// File: /workspace/github_c_makefile_star2_O1/sasairc[P]clangsay/src/libbenly/src/proc.c
// Function: set_cmd_proc
static
int set_cmd_proc(PROC** proc, const char* cmd)
{
    int     status  = 0;

    size_t  len     = 0;

    char*   tok     = NULL,
        *   cmd2    = NULL;

    if ((*proc)->argv != NULL) {
        release_argv_proc(*proc);
        (*proc)->argc = 0;
        (*proc)->argv = NULL;
    }
    if ((len = strlen(cmd)) == 0) {
        status = -1; goto ERR;
    }
    if ((cmd2 = (char*)
                malloc(sizeof(char) * (len + 1))) == NULL) {
        status = -2; goto ERR;
    } else {
        memcpy(cmd2, cmd, len);
        *(cmd2 + len) = '\0';
    }
    if (((*proc)->argv = (char**)
                malloc(sizeof(char*) * sysconf(_SC_ARG_MAX))) == NULL) {
        status = -2; goto ERR;
    }

    tok = mbstrtok(cmd2, SP);
    while (tok != NULL) {
        if ((len = strlen(tok)) > 0) {
            if ((*((*proc)->argv + (*proc)->argc) = (char*)
                        malloc(sizeof(char) * (len + 1))) == NULL) {
                status = -3; goto ERR;
            }
            memcpy(*((*proc)->argv + (*proc)->argc), tok, len);
            *(*((*proc)->argv + (*proc)->argc) + len) = '\0';
            (*proc)->argc++;
        }
        tok = mbstrtok(NULL, SP);
    }
    *((*proc)->argv + (*proc)->argc) = NULL;

    return 0;

ERR:
    switch (status) {
        case    -1:
        case    -2:
            break;
        case    -3:
            release_argv_proc(*proc);
            (*proc)->argc = 0;
            (*proc)->argv = NULL;
            break;
    }

    return status;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rdi
cmpq $0x0, 0x8(%rdi)
je 0x4f6e
callq 0x5797
movq (%rbx), %rax
movl $0x0, 0x4(%rax)
movq $0x0, 0x8(%rax)
movq %r14, %rdi
callq 0x21b0
testq %rax, %rax
je 0x4fe7
movq %rax, %r12
leaq 0x1(%rax), %rdi
callq 0x20e0
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
testq %rax, %rax
je 0x4fec
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2460
movb $0x0, (%r15,%r12)
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x2120
leaq (,%rax,8), %rdi
callq 0x20e0
movq (%rbx), %rcx
movq %rax, 0x8(%rcx)
testq %rax, %rax
je 0x4fef
movq %r15, %rdi
movl $0x20, %esi
callq 0x2350
testq %rax, %rax
je 0x5013
movq %rax, %r14
movb $0x0, (%rax)
incq %r14
jmp 0x5016
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r14d, %r14d
testb %r14b, %r14b
je 0x50d9
movq (%rbx), %rdi
callq 0x5797
movq (%rbx), %rax
movl $0x0, 0x4(%rax)
addq $0x8, %rax
jmp 0x50d2
xorl %r14d, %r14d
movq %r14, 0xc243(%rip)      # 0x11260
movq %r15, %rdi
callq 0x21b0
testq %rax, %rax
je 0x5082
movq %rax, %r12
leaq 0x1(%rax), %rdi
callq 0x20e0
movq (%rbx), %rcx
movq 0x8(%rcx), %rdx
movslq 0x4(%rcx), %rcx
movq %rax, (%rdx,%rcx,8)
testq %rax, %rax
je 0x50e4
movq (%rbx), %rax
movq 0x8(%rax), %rcx
movslq 0x4(%rax), %rax
movq (%rcx,%rax,8), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2460
movq (%rbx), %rax
movq 0x8(%rax), %rcx
movslq 0x4(%rax), %rax
movq (%rcx,%rax,8), %rax
movb $0x0, (%rax,%r12)
movq (%rbx), %rax
incl 0x4(%rax)
testq %r14, %r14
jne 0x508f
movq %r14, %rax
xorl %r14d, %r14d
jmp 0x50b2
movq %r14, %rdi
movl $0x20, %esi
callq 0x2350
testq %rax, %rax
je 0x50a9
movb $0x0, (%rax)
incq %rax
jmp 0x50ab
xorl %eax, %eax
movq %rax, 0xc1ae(%rip)      # 0x11260
movq %r14, %r15
testq %r14, %r14
movq %rax, %r14
jne 0x501d
movq (%rbx), %rcx
movslq 0x4(%rcx), %rax
shlq $0x3, %rax
addq 0x8(%rcx), %rax
xorl %ebp, %ebp
movq $0x0, (%rax)
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
movb $0x1, %r14b
jmp 0x4fef