// File: /workspace/github_c_makefile_star2_O3/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
movl $0x3d, %esi
callq 0x10b0
testq %rax, %rax
je 0x1a1e
movq %rax, %r12
subq %r13, %r12
leaq 0x1(%r12), %rdi
movl $0x1, %esi
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
movl $0x1, %esi
callq 0x10e0
movq %rax, %r15
leaq (%r12,%r13), %rsi
incq %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0x1060
jmp 0x1a29
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %r12d, %r12d
leaq 0x62a(%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 0x1a79
leaq 0x1(%r14), %rcx
movq %rcx, -0x30(%rbp)
movl $0x1, %esi
cmpb $0x27, %al
jne 0x1aa5
movq %r15, %rdi
callq 0x10e0
movq %rax, %r13
movq %rax, %rdi
movq -0x30(%rbp), %rsi
movq %r12, %rdx
jmp 0x1a96
cmpb $0x27, %al
jne 0x1ac3
movl $0x1, %esi
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 0x1ac8
movq %r12, %rdi
callq 0x10e0
movq %rax, %r13
movq %rax, %rdi
movq -0x30(%rbp), %rsi
movq %r12, %rdx
callq 0x1060
xorl %eax, %eax
jmp 0x1ac8
xorl %eax, %eax
xorl %r13d, %r13d
movq -0x38(%rbp), %r15
cmpb $0x27, (%r15)
jne 0x1b05
cmpb $0x27, -0x1(%r14,%rbx)
jne 0x1b01
leaq -0x1(%rbx), %rdi
movl $0x1, %esi
callq 0x10e0
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1060
movb $0x0, -0x1(%r12,%rbx)
jmp 0x1b08
testb %al, %al
je 0x1b3f
xorl %r12d, %r12d
leaq 0x56d(%rip), %rdi       # 0x207c
movq %r13, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x10c0
movq 0x25bd(%rip), %rdi      # 0x40e0
movq %r13, %rsi
movq %r12, %rdx
callq 0x1542
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %esi
movq %rbx, %rdi
callq 0x10e0
movq %rax, %r12
incq %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1060
jmp 0x1b08