// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %rdi, %rbx
movq (%rdi), %rdi
cmpq $0x0, 0x8(%rdi)
je 0x4de2
callq 0x55ce
movq (%rbx), %rax
movl $0x0, 0x4(%rax)
movq $0x0, 0x8(%rax)
movq %r15, %rdi
callq 0x21b0
testq %rax, %rax
je 0x4e59
movq %rax, %r12
leaq 0x1(%rax), %rdi
callq 0x20e0
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
testq %rax, %rax
je 0x4f37
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2470
movb $0x0, (%r14,%r12)
xorl %edi, %edi
callq 0x2120
leaq (,%rax,8), %rdi
callq 0x20e0
movq (%rbx), %rcx
movq %rax, 0x8(%rcx)
testq %rax, %rax
je 0x4f37
movq %r14, %rdi
movl $0x20, %esi
callq 0x2350
testq %rax, %rax
jne 0x4e63
xorl %eax, %eax
jmp 0x4e69
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x4f37
movb $0x0, (%rax)
incq %rax
movq %r14, %r15
movq %rax, %r14
movq %rax, 0xc3f2(%rip)      # 0x11268
movq %r15, %rdi
callq 0x21b0
testq %rax, %rax
je 0x4ed7
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)
movq (%rbx), %rdi
testq %rax, %rax
je 0x4f18
movq 0x8(%rdi), %rax
movslq 0x4(%rdi), %rcx
movq (%rax,%rcx,8), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2470
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
je 0x4f05
movq %r14, %rdi
movl $0x20, %esi
callq 0x2350
movq %rax, %rcx
movl $0x0, %eax
movq %r14, %r15
testq %rcx, %rcx
je 0x4e6c
movq %rcx, %rax
jmp 0x4e63
movq (%rbx), %rcx
movslq 0x4(%rcx), %rax
shlq $0x3, %rax
addq 0x8(%rcx), %rax
xorl %ebp, %ebp
jmp 0x4f30
callq 0x55ce
movq (%rbx), %rax
movl $0x0, 0x4(%rax)
addq $0x8, %rax
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
movq $0x0, (%rax)
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq