// File: /workspace/github_c_makefile_star2_O2/atomlang[P]atomlang/src/pk_core.c
// Function: varsetSubscript
void varsetSubscript(PKVM* vm, Var on, Var key, Var value) {
  if (!IS_OBJ(on)) {
    VM_SET_ERROR(vm, stringFormat(vm, "$ type is not subscriptable.",
                                  varTypeName(on)));
    return;
  }

  Object* obj = AS_OBJ(on);
  switch (obj->type) {
    case OBJ_STRING:
      VM_SET_ERROR(vm, newString(vm, "String objects are immutable."));
      return;

    case OBJ_LIST:
    {
      int64_t index;
      pkVarBuffer* elems = &((List*)obj)->elements;
      if (!validateInteger(vm, key, &index, "List index")) return;
      if (!validateIndex(vm, index, elems->count, "List")) return;
      elems->data[index] = value;
      return;
    }

    case OBJ_MAP:
    {
      if (IS_OBJ(key) && !isObjectHashable(AS_OBJ(key)->type)) {
        VM_SET_ERROR(vm, stringFormat(vm, "$ type is not hashable.",
                                      varTypeName(key)));
      } else {
        mapSet(vm, (Map*)obj, key, value);
      }
      return;
    }

    case OBJ_RANGE:
    case OBJ_SCRIPT:
    case OBJ_FUNC:
    case OBJ_FIBER:
    case OBJ_CLASS:
    case OBJ_INST:
      TODO;
      UNREACHABLE();

    default:
      UNREACHABLE();
  }

  UNREACHABLE();
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rax
shrq $0x32, %rax
cmpl $0x3ffe, %eax           # imm = 0x3FFE
jbe 0x13ed1
movq %rcx, %r15
movabsq $0xffffffffffff, %rax   # imm = 0xFFFFFFFFFFFF
andq %rax, %r14
movl (%r14), %ecx
cmpq $0x8, %rcx
ja 0x1404a
movq %rdx, %r12
leaq 0x5a4e(%rip), %rdx      # 0x198f0
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq 0x5f0(%rbx), %rax
cmpq $0x0, 0x58(%rax)
jne 0x14015
leaq 0x6163(%rip), %rsi      # 0x1a027
pushq $0x1d
popq %rdx
movq %rbx, %rdi
callq 0x261f
jmp 0x13eff
movq 0x5f0(%rbx), %rax
cmpq $0x0, 0x58(%rax)
jne 0x13fe7
movq %r14, %rdi
callq 0x4e61
leaq 0x6048(%rip), %rsi      # 0x19f3a
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3a8d
movq 0x5f0(%rbx), %rcx
movq %rax, 0x58(%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movabsq $-0x4000000000001, %rcx # imm = 0xFFFBFFFFFFFFFFFF
cmpq %rcx, %r12
jbe 0x13f33
andq %r12, %rax
movl (%rax), %edi
callq 0x4ff0
testb %al, %al
je 0x13f93
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x447b
leaq 0x6092(%rip), %rcx      # 0x19fe8
movq %rsp, %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x122a2
testb %al, %al
je 0x13f0a
movq (%rsp), %r12
movl 0x18(%r14), %edx
leaq 0x69c6(%rip), %rcx      # 0x1a93d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x13dde
testb %al, %al
je 0x13f0a
movq 0x10(%r14), %rax
movq %r15, (%rax,%r12,8)
jmp 0x13f0a
movq 0x5f0(%rbx), %rax
cmpq $0x0, 0x58(%rax)
jne 0x14078
movq %r12, %rdi
callq 0x4e61
leaq 0x48a0(%rip), %rsi      # 0x18854
jmp 0x13ef2
movq 0xf038(%rip), %rax      # 0x22ff8
movq (%rax), %rdi
leaq 0x4126(%rip), %rsi      # 0x180f0
leaq 0x437e(%rip), %rdx      # 0x1834f
leaq 0x603f(%rip), %rcx      # 0x1a017
leaq 0x5947(%rip), %r8       # 0x19926
movl $0x76c, %r9d            # imm = 0x76C
jmp 0x14041
movq 0xf00a(%rip), %rax      # 0x22ff8
movq (%rax), %rdi
leaq 0x40f8(%rip), %rsi      # 0x180f0
leaq 0x4205(%rip), %rdx      # 0x18204
leaq 0x6011(%rip), %rcx      # 0x1a017
leaq 0x5919(%rip), %r8       # 0x19926
movl $0x747, %r9d            # imm = 0x747
jmp 0x14041
movq 0xefdc(%rip), %rax      # 0x22ff8
movq (%rax), %rdi
leaq 0x40ca(%rip), %rsi      # 0x180f0
leaq 0x41d7(%rip), %rdx      # 0x18204
leaq 0x5fe3(%rip), %rcx      # 0x1a017
leaq 0x58eb(%rip), %r8       # 0x19926
movl $0x74e, %r9d            # imm = 0x74E
xorl %eax, %eax
callq 0x2250
ud2
movq 0xefa7(%rip), %rax      # 0x22ff8
movq (%rax), %rdi
leaq 0x411f(%rip), %rsi      # 0x1817a
leaq 0x5fb5(%rip), %rdx      # 0x1a017
leaq 0x58bd(%rip), %rcx      # 0x19926
movl $0x770, %r8d            # imm = 0x770
xorl %eax, %eax
callq 0x2250
ud2
movq 0xef79(%rip), %rax      # 0x22ff8
movq (%rax), %rdi
leaq 0x4067(%rip), %rsi      # 0x180f0
leaq 0x4174(%rip), %rdx      # 0x18204
leaq 0x5f80(%rip), %rcx      # 0x1a017
leaq 0x5888(%rip), %r8       # 0x19926
movl $0x75f, %r9d            # imm = 0x75F
jmp 0x14041