// File: eatonphil[P]cpp-json/json.cpp
// Function: json::format_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
std::string format_error(std::string base, std::string source, int index) {
  std::ostringstream s;
  int counter = 0;
  int line = 1;
  int column = 0;
  std::string lastline = "";
  std::string whitespace = "";
  for (auto c : source) {
    if (counter == index) {
      break;
    }

    if (c == '\n') {
      line++;
      column = 0;
      lastline = "";
      whitespace = "";
    } else if (c == '\t') {
      column++;
      lastline += "  ";
      whitespace += "  ";
    } else {
      column++;
      lastline += c;
      whitespace += " ";
    }

    counter++;
  }

  // Continue accumulating the lastline for debugging
  while (counter < source.size()) {
    auto c = source[counter];
    if (c == '\n') {
      break;
    }
    lastline += c;
    counter++;
  }

  s << base << " at line " << line << ", column " << column << std::endl;
  s << lastline << std::endl;
  s << whitespace << "^";

  return s.str();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2a0, %rsp            # imm = 0x2A0
movq %rdx, -0x250(%rbp)
movq %rsi, -0x248(%rbp)
movq %rdi, -0x240(%rbp)
movq %rdi, %rax
movq %rax, -0x238(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x41e0
movl $0x0, -0x19c(%rbp)
movl $0x1, -0x1a0(%rbp)
movl $0x0, -0x1a4(%rbp)
leaq -0x1c9(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0x42b0
movq -0x230(%rbp), %rdx
leaq 0x10b97(%rip), %rsi     # 0x151eb
leaq -0x1c8(%rbp), %rdi
callq 0x8560
jmp 0x4662
leaq -0x1c9(%rbp), %rdi
callq 0x41d0
leaq -0x201(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x42b0
movq -0x258(%rbp), %rdx
leaq 0x10b5c(%rip), %rsi     # 0x151eb
leaq -0x200(%rbp), %rdi
callq 0x8560
jmp 0x469d
leaq -0x201(%rbp), %rdi
callq 0x41d0
movq -0x250(%rbp), %rax
movq %rax, -0x210(%rbp)
movq -0x210(%rbp), %rdi
callq 0x8610
movq %rax, -0x218(%rbp)
movq -0x210(%rbp), %rdi
callq 0x8640
movq %rax, -0x220(%rbp)
leaq -0x218(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x8690
xorb $-0x1, %al
testb $0x1, %al
jne 0x46fb
jmp 0x487d
leaq -0x218(%rbp), %rdi
callq 0x86d0
movb (%rax), %al
movb %al, -0x221(%rbp)
movl -0x19c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x4765
jmp 0x487d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1d8(%rbp)
movl %eax, -0x1dc(%rbp)
leaq -0x1c9(%rbp), %rdi
callq 0x41d0
jmp 0x4a60
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1d8(%rbp)
movl %eax, -0x1dc(%rbp)
leaq -0x201(%rbp), %rdi
callq 0x41d0
jmp 0x4a54
movsbl -0x221(%rbp), %eax
cmpl $0xa, %eax
jne 0x47db
movl -0x1a0(%rbp), %eax
incl %eax
movl %eax, -0x1a0(%rbp)
movl $0x0, -0x1a4(%rbp)
leaq 0x10a5b(%rip), %rsi     # 0x151eb
leaq -0x1c8(%rbp), %rdi
callq 0x86f0
jmp 0x479e
leaq 0x10a46(%rip), %rsi     # 0x151eb
leaq -0x200(%rbp), %rdi
callq 0x86f0
jmp 0x47b3
jmp 0x485d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1d8(%rbp)
movl %eax, -0x1dc(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x87f0
jmp 0x4a54
movsbl -0x221(%rbp), %eax
cmpl $0x9, %eax
jne 0x4821
movl -0x1a4(%rbp), %eax
incl %eax
movl %eax, -0x1a4(%rbp)
leaq 0x1086a(%rip), %rsi     # 0x15066
leaq -0x1c8(%rbp), %rdi
callq 0x8720
jmp 0x480a
leaq 0x10855(%rip), %rsi     # 0x15066
leaq -0x200(%rbp), %rdi
callq 0x8720
jmp 0x481f
jmp 0x485b
movl -0x1a4(%rbp), %eax
incl %eax
movl %eax, -0x1a4(%rbp)
movsbl -0x221(%rbp), %esi
leaq -0x1c8(%rbp), %rdi
callq 0x8750
jmp 0x4844
leaq 0x1081c(%rip), %rsi     # 0x15067
leaq -0x200(%rbp), %rdi
callq 0x8720
jmp 0x4859
jmp 0x485b
jmp 0x485d
movl -0x19c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x19c(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x8780
jmp 0x46dd
jmp 0x487f
movq -0x250(%rbp), %rdi
movslq -0x19c(%rbp), %rax
movq %rax, -0x260(%rbp)
callq 0x87a0
movq %rax, %rcx
movq -0x260(%rbp), %rax
cmpq %rcx, %rax
jae 0x490a
movq -0x250(%rbp), %rdi
movslq -0x19c(%rbp), %rsi
callq 0x87c0
movq %rax, -0x268(%rbp)
jmp 0x48c4
movq -0x268(%rbp), %rax
movb (%rax), %al
movb %al, -0x222(%rbp)
movsbl -0x222(%rbp), %eax
cmpl $0xa, %eax
jne 0x48e1
jmp 0x490a
movsbl -0x222(%rbp), %esi
leaq -0x1c8(%rbp), %rdi
callq 0x8750
jmp 0x48f6
movl -0x19c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x19c(%rbp)
jmp 0x487f
movq -0x248(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0x4170
movq %rax, -0x270(%rbp)
jmp 0x4926
movq -0x270(%rbp), %rdi
leaq 0x10735(%rip), %rsi     # 0x15069
callq 0x4180
movq %rax, -0x278(%rbp)
jmp 0x4942
movq -0x278(%rbp), %rdi
movl -0x1a0(%rbp), %esi
callq 0x4290
movq %rax, -0x280(%rbp)
jmp 0x495d
movq -0x280(%rbp), %rdi
leaq 0x10708(%rip), %rsi     # 0x15073
callq 0x4180
movq %rax, -0x288(%rbp)
jmp 0x4979
movq -0x288(%rbp), %rdi
movl -0x1a4(%rbp), %esi
callq 0x4290
movq %rax, -0x290(%rbp)
jmp 0x4994
movq -0x290(%rbp), %rdi
movq 0x1b5fe(%rip), %rsi     # 0x1ffa0
callq 0x41c0
jmp 0x49a9
leaq -0x198(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0x4170
movq %rax, -0x298(%rbp)
jmp 0x49c5
movq -0x298(%rbp), %rdi
movq 0x1b5cd(%rip), %rsi     # 0x1ffa0
callq 0x41c0
jmp 0x49da
leaq -0x198(%rbp), %rdi
leaq -0x200(%rbp), %rsi
callq 0x4170
movq %rax, -0x2a0(%rbp)
jmp 0x49f6
movq -0x2a0(%rbp), %rdi
leaq 0x10679(%rip), %rsi     # 0x1507d
callq 0x4180
jmp 0x4a0b
movq -0x240(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x4280
jmp 0x4a20
leaq -0x200(%rbp), %rdi
callq 0x87f0
leaq -0x1c8(%rbp), %rdi
callq 0x87f0
leaq -0x198(%rbp), %rdi
callq 0x4070
movq -0x238(%rbp), %rax
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbp
retq
leaq -0x1c8(%rbp), %rdi
callq 0x87f0
leaq -0x198(%rbp), %rdi
callq 0x4070
movq -0x1d8(%rbp), %rdi
callq 0x42a0
nopl (%rax,%rax)