// File: /workspace/github_c_makefile_star2_O3/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
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rax
shrq $0x32, %rax
cmpl $0x3ffe, %eax           # imm = 0x3FFE
jbe 0x18644
movq %rcx, %r15
movabsq $0xffffffffffff, %rax   # imm = 0xFFFFFFFFFFFF
andq %rax, %r14
movl (%r14), %ecx
cmpq $0x8, %rcx
ja 0x187e4
movq %rdx, %r12
leaq 0x52fd(%rip), %rdx      # 0x1d910
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq 0x5f0(%rbx), %rax
cmpq $0x0, 0x58(%rax)
jne 0x187df
leaq 0x5a12(%rip), %rsi      # 0x1e047
movq %rbx, %rdi
movl $0x1d, %edx
callq 0x7f0c
jmp 0x18672
movq 0x5f0(%rbx), %rax
cmpq $0x0, 0x58(%rax)
jne 0x187da
movq %r14, %rdi
callq 0xa89c
leaq 0x58f5(%rip), %rsi      # 0x1df5a
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x94f4
movq 0x5f0(%rbx), %rcx
movq %rax, 0x58(%rcx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movabsq $-0x4000000000001, %rcx # imm = 0xFFFBFFFFFFFFFFFF
cmpq %rcx, %r12
jbe 0x186aa
andq %r12, %rax
movl (%rax), %edi
callq 0xaa01
testb %al, %al
je 0x18782
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x9f38
movq %r12, %rax
notq %rax
movabsq $0x7ffc000000000000, %rcx # imm = 0x7FFC000000000000
testq %rcx, %rax
jne 0x1870c
movq %r12, %rax
shrq %rax
movabsq $0x3ffe800000000001, %rcx # imm = 0x3FFE800000000001
cmpq %rcx, %rax
jne 0x18764
movabsq $0x7ffd000000000002, %rax # imm = 0x7FFD000000000002
incq %rax
cmpq %rax, %r12
je 0x187c8
xorpd %xmm0, %xmm0
jmp 0x18714
movq %r12, %rdi
callq 0x8fa4
movapd %xmm0, (%rsp)
callq 0x2330
movapd (%rsp), %xmm2
ucomisd %xmm2, %xmm0
jne 0x18764
jp 0x18764
movapd 0x513d(%rip), %xmm0     # 0x1d870
andpd %xmm2, %xmm0
movsd 0x5119(%rip), %xmm1     # 0x1d858
ucomisd %xmm0, %xmm1
jb 0x187ee
cvttsd2si %xmm2, %rax
movl 0x18(%r14), %ecx
cmpq %rax, %rcx
jbe 0x187a4
movq 0x10(%r14), %rcx
movq %r15, (%rcx,%rax,8)
jmp 0x1867d
movq 0x5f0(%rbx), %rax
cmpq $0x0, 0x58(%rax)
jne 0x187e9
leaq 0x6cce(%rip), %rsi      # 0x1f447
leaq 0x5888(%rip), %rdx      # 0x1e008
jmp 0x187c0
movq 0x5f0(%rbx), %rax
cmpq $0x0, 0x58(%rax)
jne 0x187f3
movq %r12, %rdi
callq 0xa89c
leaq 0x40a5(%rip), %rsi      # 0x1c844
jmp 0x18665
movq 0x5f0(%rbx), %rax
cmpq $0x0, 0x58(%rax)
jne 0x187f8
leaq 0x6cb6(%rip), %rsi      # 0x1f46f
leaq 0x619d(%rip), %rdx      # 0x1e95d
movq %rbx, %rdi
jmp 0x1866b
movsd 0x38f0(%rip), %xmm0     # 0x1c0c0
jmp 0x18714
callq 0x7919
callq 0x78e3
callq 0x7a27
callq 0x7a5d
callq 0x7985
callq 0x79f1
callq 0x794f
callq 0x79bb