// File: ctSkennerton[P]fxtract/util/acstr.c
// Function: acstr
char *acstr(char const *buf, int len)
{
    int        i, wid = 3;
    //  Trailing NULs are ignored.
    while (len > 0 && !buf[len-1]) --len;

    for (i = 0; i < len; ++i)
        wid += esc[(unsigned char)buf[i]] ? 2 : isgraph(buf[i]) ? 1 : 4;
    char        *ret = (char *) malloc(wid + 1), *cp = ret, ec;
    *cp++ = '"';
    for (i = 0; i < len; i++) {
        if ((ec = esc[(unsigned char)buf[i]]))
            *cp++ = '\\', *cp++ = ec;
        else if (buf[i] == ' ' || isgraph(buf[i]))
            *cp++ = buf[i];
        else
            cp += sprintf(cp, "\\x%2.2X", (unsigned char)buf[i]);
    }

    *cp++ = '"';
    *cp = 0;
    return      ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x3, -0x14(%rbp)
xorl %eax, %eax
cmpl $0x0, -0xc(%rbp)
movb %al, -0x2a(%rbp)
jle 0x556a
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpb $0x0, (%rax,%rcx)
setne %al
xorb $-0x1, %al
movb %al, -0x2a(%rbp)
movb -0x2a(%rbp), %al
testb $0x1, %al
jne 0x5573
jmp 0x557e
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x5546
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x55fd
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x6c2e(%rip), %rax      # 0xc1d0
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x55b5
movl $0x2, %eax
movl %eax, -0x30(%rbp)
jmp 0x55e9
callq 0x31c0
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movslq -0x10(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %edx
andl $0x8000, %edx           # imm = 0x8000
movl $0x4, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x5585
movl -0x14(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x3250
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movb $0x22, (%rax)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x571a
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x6b7f(%rip), %rax      # 0xc1d0
movb (%rax,%rcx), %al
movb %al, -0x29(%rbp)
cmpb $0x0, %al
je 0x5686
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movb $0x5c, (%rax)
movb -0x29(%rbp), %cl
movq -0x28(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rbp)
movb %cl, (%rax)
jmp 0x570a
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
je 0x56bc
callq 0x31c0
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movslq -0x10(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x56da
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movb (%rax,%rcx), %cl
movq -0x28(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rbp)
movb %cl, (%rax)
jmp 0x5708
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movzbl (%rax,%rcx), %edx
leaq 0x3ab0(%rip), %rsi      # 0x91a1
movb $0x0, %al
callq 0x3060
movl %eax, %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
jmp 0x570a
jmp 0x570c
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x5630
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movb $0x22, (%rax)
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
movq -0x20(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)