// File: /workspace/github_c_makefile_star2_O0/sasairc[P]clangsay/src/libbenly/src/uri.c
// Function: decode_uri
int decode_uri(char* const src, char** dest)
{
    int     status  = 0;

    size_t  bufsiz  = DEFAULT_BUFSIZE,
            current = 0;

    char*   p       = src;

    if ((*dest = (char*)
                malloc(sizeof(char) * bufsiz)) == NULL) {
        status = -1; goto ERR;
    } else {
        memset(*dest, '\0', bufsiz);
    }

    while (*p != '\0') {
        if ((current + 2) >= bufsiz) {
            bufsiz += DEFAULT_BUFSIZE;
            if ((*dest = (char*)
                        realloc(*dest, sizeof(char) * bufsiz)) == NULL) {
                status = -2; goto ERR;
            } else {
                memset(*dest + current, '\0', DEFAULT_BUFSIZE);
            }
        }
        if (*p == '%') {
            p++;
            sscanf(p, "%2X", *(dest) + current);
            p += 2;
        } else {
            *(*(dest) + current) = *p;
            p++;
        }
        current++;
    }

    return 0;

ERR:
    switch (status) {
        case    -1:
        case    -2:
            fprintf(stderr, "%s\n",
                    strerror(errno));
            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 $0x400, -0x28(%rbp)     # imm = 0x400
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
shlq $0x0, %rdi
callq 0x20e0
movq -0x18(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0xf735
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
jmp 0xf838
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
xorl %esi, %esi
callq 0x2050
jmp 0xf749
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xf82f
movq -0x30(%rbp), %rax
addq $0x2, %rax
cmpq -0x28(%rbp), %rax
jb 0xf7bb
movq -0x28(%rbp), %rax
addq $0x400, %rax            # imm = 0x400
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
shlq $0x0, %rsi
callq 0x23c0
movq -0x18(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0xf7a2
movl $0xfffffffe, -0x1c(%rbp) # imm = 0xFFFFFFFE
jmp 0xf838
movq -0x18(%rbp), %rax
movq (%rax), %rdi
addq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x2050
jmp 0xf7bb
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
jne 0xf7fe
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
addq -0x30(%rbp), %rdx
leaq 0x2926(%rip), %rsi      # 0x1210f
movb $0x0, %al
callq 0x2090
movq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
jmp 0xf81e
movq -0x38(%rbp), %rax
movb (%rax), %dl
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xf749
movl $0x0, -0x4(%rbp)
jmp 0xf87a
movl -0x1c(%rbp), %eax
addl $0x2, %eax
subl $0x1, %eax
ja 0xf874
jmp 0xf845
movq 0x779c(%rip), %rax      # 0x16fe8
movq (%rax), %rax
movq %rax, -0x40(%rbp)
callq 0x2350
movl (%rax), %edi
callq 0x2260
movq -0x40(%rbp), %rdi
movq %rax, %rdx
leaq 0x31ba(%rip), %rsi      # 0x12a27
movb $0x0, %al
callq 0x23f0
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)