// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0x8(%rax)
je 0x6646
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x75e0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl $0x0, 0x4(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq $0x0, 0x8(%rax)
movq -0x18(%rbp), %rdi
callq 0x2190
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x6665
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
jmp 0x67e5
movq -0x28(%rbp), %rdi
addq $0x1, %rdi
shlq $0x0, %rdi
callq 0x20e0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x668c
movl $0xfffffffe, -0x1c(%rbp) # imm = 0xFFFFFFFE
jmp 0x67e5
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x2410
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
movb $0x0, (%rax,%rcx)
xorl %edi, %edi
callq 0x2120
movq %rax, %rdi
shlq $0x3, %rdi
callq 0x20e0
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq %rax, 0x8(%rcx)
cmpq $0x0, %rax
jne 0x66d9
movl $0xfffffffe, -0x1c(%rbp) # imm = 0xFFFFFFFE
jmp 0x67e5
movq -0x38(%rbp), %rdi
leaq 0xc2fb(%rip), %rsi      # 0x129df
callq 0x7680
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x67be
movq -0x30(%rbp), %rdi
callq 0x2190
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jbe 0x67a5
movq -0x28(%rbp), %rdi
addq $0x1, %rdi
shlq $0x0, %rdi
callq 0x20e0
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq 0x8(%rcx), %rcx
movq -0x10(%rbp), %rdx
movq (%rdx), %rdx
movslq 0x4(%rdx), %rdx
movq %rax, (%rcx,%rdx,8)
cmpq $0x0, %rax
jne 0x674c
movl $0xfffffffd, -0x1c(%rbp) # imm = 0xFFFFFFFD
jmp 0x67e5
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movslq 0x4(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x2410
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movslq 0x4(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq -0x28(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
xorl %eax, %eax
movl %eax, %edi
leaq 0xc22f(%rip), %rsi      # 0x129df
callq 0x7680
movq %rax, -0x30(%rbp)
jmp 0x66ed
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movslq 0x4(%rcx), %rcx
movq $0x0, (%rax,%rcx,8)
movl $0x0, -0x4(%rbp)
jmp 0x6830
movl -0x1c(%rbp), %eax
movl %eax, -0x3c(%rbp)
subl $-0x3, %eax
je 0x6801
jmp 0x67f2
movl -0x3c(%rbp), %eax
addl $0x2, %eax
subl $0x1, %eax
ja 0x682a
jmp 0x67ff
jmp 0x682a
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x75e0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl $0x0, 0x4(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq $0x0, 0x8(%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)