// File: /workspace/github_c_makefile_star2_O1/mikeakohn[P]print_pe/build/../src/demangle.c
// Function: demangle_name
static int demangle_name(
  const char *name,
  char *demangled,
  char *params,
  char *return_type,
  int offset,
  int length)
{
  const char *s = name;
  int ptr = 0;

  while (s[ptr] != 0)
  {
    if (s[ptr] == '@')
    {
      if (s[ptr + 1] == '@')
      {
        offset = demangle_insert_name(name, demangled, offset, length);
        demangle_params(s + ptr + 2, params, return_type, 0, length);
        return offset;
      }
        else
      {
        offset = demangle_name(s + ptr + 1, demangled, params, return_type, offset, length);
        if (offset < length) { demangled[offset++] = ':'; }
        if (offset < length) { demangled[offset++] = ':'; }
        offset = demangle_insert_name(name, demangled, offset, length);
        return offset;
      }
    }

    ptr++;
  }

  if (offset < length) { demangled[offset] = 0; }

  return offset;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %ebx
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, %r15
leaq 0x4(%rdi), %r13
movzbl -0x4(%r13), %eax
testl %eax, %eax
je 0x22b9
cmpl $0x40, %eax
je 0x20bb
incq %r13
jmp 0x20a4
cmpb $0x40, -0x3(%r13)
jne 0x22c9
movq %rcx, 0x10(%rsp)
xorl %r12d, %r12d
movq %r15, %rdi
movq %rbp, %rsi
xorl %edx, %edx
movl %ebx, %ecx
callq 0x2354
movl %eax, 0x4(%rsp)
testl %ebx, %ebx
jle 0x20ef
movb $0x28, (%r14)
movl $0x1, %r12d
cmpb $0x59, -0x2(%r13)
jne 0x2314
cmpb $0x41, -0x1(%r13)
jne 0x2314
xorl %esi, %esi
movq %r14, 0x8(%rsp)
cmpl %ebx, %r12d
jge 0x2324
movzbl (%r13), %ecx
testb $-0x41, %cl
je 0x2324
xorl %eax, %eax
cmpb $0x5f, %cl
sete %al
leaq (%rax,%r13), %r15
movb 0x1(%r13,%rax), %dl
cmpb $0x40, %dl
sete %bpl
cmpb $0x5a, %dl
jne 0x2152
cmpb $0x40, %dl
sete %dl
cmpb $0x0, 0x2(%r15)
sete %bpl
orb %dl, %bpl
subl $0x1, %esi
jb 0x2167
testb %bpl, %bpl
jne 0x2167
movslq %r12d, %rdx
incl %r12d
movb $0x2c, (%r14,%rdx)
movzbl (%r15), %edx
cmpb $0x5f, %cl
jne 0x2195
leal -0x44(%rdx), %ecx
cmpl $0x16, %ecx
ja 0x2208
leaq 0x349d(%rip), %rdx      # 0x5620
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
leaq 0x35b3(%rip), %rdi      # 0x5746
jmp 0x21b5
addb $-0x43, %dl
leaq 0x35a7(%rip), %rdi      # 0x5746
cmpb $0x18, %dl
jae 0x21b5
movzbl %dl, %ecx
leaq 0x34ce(%rip), %rdx      # 0x567c
movslq (%rdx,%rcx,4), %rdi
addq %rdx, %rdi
movl %esi, %r14d
testb %bpl, %bpl
je 0x21cd
movq 0x10(%rsp), %rsi
xorl %edx, %edx
movl %ebx, %ecx
callq 0x2354
jmp 0x21e6
leaq (%rax,%r13), %r15
incq %r15
movq 0x8(%rsp), %rsi
movl %r12d, %edx
movl %ebx, %ecx
callq 0x2354
movl %eax, %r12d
movq %r15, %r13
testb %bpl, %bpl
movl %r14d, %esi
movq 0x8(%rsp), %r14
je 0x210c
jmp 0x2324
leaq 0x3549(%rip), %rdi      # 0x574f
jmp 0x21b5
leaq 0x3544(%rip), %rdi      # 0x5753
cmpl $0x24, %edx
jne 0x218c
jmp 0x21b5
leaq 0x358a(%rip), %rdi      # 0x57ab
jmp 0x21b5
leaq 0x34e6(%rip), %rdi      # 0x5710
jmp 0x21b5
leaq 0x352d(%rip), %rdi      # 0x5760
jmp 0x21b5
leaq 0x355c(%rip), %rdi      # 0x5798
jmp 0x21b5
leaq 0x34c0(%rip), %rdi      # 0x5708
jmp 0x21b5
leaq 0x354e(%rip), %rdi      # 0x57a2
jmp 0x21b5
leaq 0x3533(%rip), %rdi      # 0x5793
jmp 0x21b5
leaq 0x351e(%rip), %rdi      # 0x578a
jmp 0x21b5
leaq 0x34e1(%rip), %rdi      # 0x5759
jmp 0x21b5
leaq 0x34f4(%rip), %rdi      # 0x5778
jmp 0x21b5
leaq 0x34d8(%rip), %rdi      # 0x5768
jmp 0x21b5
leaq 0x3481(%rip), %rdi      # 0x571d
jmp 0x21b5
leaq 0x34d9(%rip), %rdi      # 0x5781
jmp 0x21b5
leaq 0x34bc(%rip), %rdi      # 0x5770
jmp 0x21b5
xorl %eax, %eax
testl %ebx, %ebx
jle 0x2345
movb $0x0, (%rbp)
jmp 0x2345
addq $-0x3, %r13
movq %r13, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movl %ebx, %r8d
callq 0x2086
cmpl %ebx, %eax
jge 0x22ec
movslq %eax, %rcx
incl %eax
movb $0x3a, (%rbp,%rcx)
cmpl %ebx, %eax
jge 0x22fa
movslq %eax, %rcx
incl %eax
movb $0x3a, (%rbp,%rcx)
movq %r15, %rdi
movq %rbp, %rsi
movl %eax, %edx
movl %ebx, %ecx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2354
cmpl %ebx, %r12d
jge 0x2324
movl %r12d, %eax
incl %r12d
movb $0x3f, (%r14,%rax)
cmpl %ebx, %r12d
jge 0x2334
movslq %r12d, %rax
incl %r12d
movb $0x29, (%r14,%rax)
cmpl %ebx, %r12d
jge 0x2341
movslq %r12d, %rax
movb $0x0, (%r14,%rax)
movl 0x4(%rsp), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq