// File: /workspace/github_c_makefile_star2_O0/sasairc[P]yasuna/src/libbenly/src/env.c
// Function: split_env
int split_env(char* env, env_t **dest)
{
    if (env == NULL)
        return -1;

    int     x       = 0,
            y       = 0;

    size_t  i       = 0,
            head    = 0,
            tail    = 0;

    env_t*  buf     = NULL;

    if ((buf = (env_t*)
                malloc(sizeof(env_t))) == NULL)
        return -1;

    i = 0;
    buf->envc = 1;
    while (i < strlen(env)) {
        if (*(env + i) == ':')
            buf->envc++;
        i++;
    }
    if ((buf->envs = (char**)
                malloc(sizeof(char*) * buf->envc)) == NULL)
        goto ERR;

    i = x = y = head = tail = 0;
    do {
        if (*(env + tail) == ':' || *(env + tail) == '\0') {
            if ((*(buf->envs + y) = (char*)
                        malloc(sizeof(char) * (tail - head + 1))) == NULL)
                goto ERR;

            while (head < tail) {
                *(*(buf->envs + y) + x) = *(env + head);
                head++;
                x++;
            }
            *(*(buf->envs + y) + x) = '\0';
            x = 0;
            head++;
            y++;
        }
        tail++;
    } while (y < buf->envc);

    *dest = buf;

    return 0;

ERR:
    release_env_t(buf);

    return -2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x1163
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1361
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x10, %edi
callq 0x1050
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x11b1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1361
movq $0x0, -0x28(%rbp)
movq -0x40(%rbp), %rax
movl $0x1, (%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1040
movq %rax, %rcx
movq -0x48(%rbp), %rax
cmpq %rcx, %rax
jae 0x120a
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
jne 0x11fc
movq -0x40(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x11c3
movq -0x40(%rbp), %rax
movslq (%rax), %rdi
shlq $0x3, %rdi
callq 0x1050
movq -0x40(%rbp), %rcx
movq %rax, 0x8(%rcx)
cmpq $0x0, %rax
jne 0x122d
jmp 0x1351
movq $0x0, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
je 0x1279
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1322
movq -0x38(%rbp), %rdi
subq -0x30(%rbp), %rdi
addq $0x1, %rdi
shlq $0x0, %rdi
callq 0x1050
movq -0x40(%rbp), %rcx
movq 0x8(%rcx), %rcx
movslq -0x20(%rbp), %rdx
movq %rax, (%rcx,%rdx,8)
cmpq $0x0, %rax
jne 0x12a9
jmp 0x1351
jmp 0x12ab
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x12ee
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x12ab
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl $0x0, -0x1c(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movl -0x20(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl (%rcx), %eax
jl 0x1253
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x1361
movq -0x40(%rbp), %rdi
callq 0x1060
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)