// File: /workspace/github_c_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r13
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 0x192a7
movq %rcx, %r15
movabsq $0xffffffffffff, %rax   # imm = 0xFFFFFFFFFFFF
andq %rax, %r14
movl (%r14), %ecx
cmpq $0x8, %rcx
ja 0x1949c
movq %rdx, %r12
leaq 0x565a(%rip), %rdx      # 0x1e8d0
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq 0x5f0(%rbx), %rax
cmpq $0x0, 0x58(%rax)
jne 0x19497
leaq 0x5d6f(%rip), %rsi      # 0x1f007
movq %rbx, %rdi
movl $0x1d, %edx
callq 0x7fc8
jmp 0x192d5
movq 0x5f0(%rbx), %rax
cmpq $0x0, 0x58(%rax)
jne 0x19492
movq %r14, %rdi
callq 0xaa1a
leaq 0x5c52(%rip), %rsi      # 0x1ef1a
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x95d0
movq 0x5f0(%rbx), %rcx
movq %rax, 0x58(%rcx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movabsq $-0x4000000000001, %rcx # imm = 0xFFFBFFFFFFFFFFFF
cmpq %rcx, %r12
jbe 0x1930c
andq %r12, %rax
movl (%rax), %edi
callq 0xab7d
testb %al, %al
je 0x1937e
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa060
movq %r12, %rax
notq %rax
movabsq $0x7ffc000000000000, %rcx # imm = 0x7FFC000000000000
testq %rcx, %rax
jne 0x19371
movq %r12, %rax
shrq %rax
movabsq $0x3ffe800000000001, %rcx # imm = 0x3FFE800000000001
cmpq %rcx, %rax
jne 0x193a4
movabsq $0x7ffd000000000002, %rax # imm = 0x7FFD000000000002
incq %rax
cmpq %rax, %r12
je 0x19480
xorpd %xmm0, %xmm0
jmp 0x19379
movq %r12, %rdi
callq 0x9060
movb $0x1, %r12b
jmp 0x193a7
movq 0x5f0(%rbx), %rax
cmpq $0x0, 0x58(%rax)
jne 0x194ab
movq %r12, %rdi
callq 0xaa1a
leaq 0x44a5(%rip), %rsi      # 0x1d844
jmp 0x192c8
xorl %r12d, %r12d
movapd %xmm0, (%rsp)
callq 0x2330
movapd (%rsp), %xmm2
ucomisd %xmm2, %xmm0
setnp %al
sete %bpl
andb %al, %bpl
andb %r12b, %bpl
cmpb $0x1, %bpl
jne 0x193f2
movapd 0x545b(%rip), %xmm0     # 0x1e830
andpd %xmm2, %xmm0
movsd 0x5437(%rip), %xmm1     # 0x1e818
ucomisd %xmm0, %xmm1
jb 0x194a1
cvttsd2si %xmm2, %r12
jmp 0x19427
movq 0x5f0(%rbx), %rax
cmpq $0x0, 0x58(%rax)
jne 0x194a6
leaq 0x6ffc(%rip), %rsi      # 0x20407
leaq 0x5bb6(%rip), %rdx      # 0x1efc8
movq %rbx, %rdi
xorl %eax, %eax
callq 0x95d0
movq 0x5f0(%rbx), %rcx
movq %rax, 0x58(%rcx)
testb %bpl, %bpl
je 0x192e0
movl 0x18(%r14), %r13d
cmpq %r13, %r12
jb 0x19473
movq 0x5f0(%rbx), %rax
cmpq $0x0, 0x58(%rax)
jne 0x194b0
leaq 0x6fe1(%rip), %rsi      # 0x2042f
leaq 0x64c8(%rip), %rdx      # 0x1f91d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x95d0
movq 0x5f0(%rbx), %rcx
movq %rax, 0x58(%rcx)
cmpq %r13, %r12
jae 0x192e0
movq 0x10(%r14), %rax
movq %r15, (%rax,%r12,8)
jmp 0x192e0
movsd 0x3c38(%rip), %xmm0     # 0x1d0c0
jmp 0x19379
callq 0x794f
callq 0x7919
callq 0x7a5d
callq 0x7a93
callq 0x7a27
callq 0x79bb
callq 0x7985
callq 0x79f1