// File: /workspace/github_c_makefile_star2_O2/ikbenlike[P]nngutils/src/sh.c
// Function: sh_add_alias
int sh_add_alias(char *arg){
    size_t n_len = 0;
    size_t c_len = 0;
    char *name = NULL;
    char *command = NULL;
    
    char *split = strchr(arg, '=');

    if(split){
        n_len = split - arg;
        name = calloc(n_len + 1, sizeof(char));
        strncpy(name, arg, n_len);
        name[n_len] = '\0';

        c_len = strlen(arg) - n_len;
        command = calloc(c_len + 1, sizeof(char));
        strncpy(command, arg + n_len + 1, c_len);
    }


    printf("alias invoked with '%s' and '%s'\n", name, command);

    char *p_name = NULL;

    if(name[0] == '\'' && name[n_len - 1] == '\''){
        p_name = calloc(n_len - 1, sizeof(char));
        strncpy(p_name, name + 1, n_len);
        p_name[n_len - 1] = '\0';
    }
    else if(name[0] == '\'' && name[n_len - 1] != '\''){
        p_name = calloc(n_len, sizeof(char));
        strncpy(p_name, name + 1, n_len);
    }
    else if(name[0] != '\'' && name[n_len - 1] == '\''){
        p_name = calloc(n_len, sizeof(char));
        strncpy(p_name, name, n_len - 1);
        p_name[n_len - 1] = '\0';
    }

    char *p_command = NULL;

    if(command[0] == '\'' && name[c_len - 1] == '\''){
        p_command = calloc(c_len - 1, sizeof(char));
        strncpy(p_command, command, c_len);
        p_command[c_len - 1] = '\0';
    }
    else if(command[0] == '\'' && name[n_len - 1] != '\''){
        p_command = calloc(c_len, sizeof(char));
        strncpy(p_command, name + 1, c_len);
    }

    printf("aliased '%s' to '%s'\n", p_name, p_command);

    return hashmap_set(alias_hashmap, p_name, p_command);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r13
pushq $0x3d
popq %rsi
callq 0x10b0
testq %rax, %rax
je 0x1856
movq %rax, %r12
subq %r13, %r12
leaq 0x1(%r12), %rdi
pushq $0x1
popq %r15
movq %r15, %rsi
callq 0x10e0
movq %rax, %r14
movq %rax, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x1060
movb $0x0, (%r14,%r12)
movq %r13, %rdi
callq 0x1090
movq %rax, %rbx
subq %r12, %rbx
leaq 0x1(%rbx), %rdi
movq %r15, %rsi
callq 0x10e0
movq %rax, %r15
leaq (%r12,%r13), %rsi
incq %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0x1060
jmp 0x1861
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %r12d, %r12d
leaq 0x7f2(%rip), %rdi       # 0x205a
movq %r14, %rsi
movq %r15, -0x38(%rbp)
movq %r15, %rdx
xorl %eax, %eax
callq 0x10c0
leaq -0x1(%r12), %r15
cmpb $0x27, (%r14)
movb -0x1(%r14,%r12), %al
jne 0x18af
leaq 0x1(%r14), %rcx
movq %rcx, -0x30(%rbp)
pushq $0x1
popq %rsi
cmpb $0x27, %al
jne 0x18d9
movq %r15, %rdi
callq 0x10e0
movq %rax, %r13
movq %rax, %rdi
movq -0x30(%rbp), %rsi
movq %r12, %rdx
jmp 0x18ca
cmpb $0x27, %al
jne 0x18f7
pushq $0x1
popq %rsi
movq %r12, %rdi
callq 0x10e0
movq %rax, %r13
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1060
movb $0x0, -0x1(%r13,%r12)
movb $0x1, %al
jmp 0x18fc
movq %r12, %rdi
callq 0x10e0
movq %rax, %r13
movq %rax, %rdi
movq -0x30(%rbp), %rsi
movq %r12, %rdx
callq 0x1060
xorl %eax, %eax
jmp 0x18fc
xorl %eax, %eax
xorl %r13d, %r13d
movq -0x38(%rbp), %r15
cmpb $0x27, (%r15)
jne 0x1937
cmpb $0x27, -0x1(%r14,%rbx)
jne 0x1933
leaq -0x1(%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x10e0
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1060
movb $0x0, -0x1(%r12,%rbx)
jmp 0x193a
testb %al, %al
je 0x1971
xorl %r12d, %r12d
leaq 0x73b(%rip), %rdi       # 0x207c
movq %r13, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x10c0
movq 0x278b(%rip), %rdi      # 0x40e0
movq %r13, %rsi
movq %r12, %rdx
callq 0x13c0
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x10e0
movq %rax, %r12
incq %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1060
jmp 0x193a