// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movabsq $-0x4000000000000, %rax # imm = 0xFFFC000000000000
andq 0x48(%rsp), %rax
movabsq $-0x4000000000000, %rcx # imm = 0xFFFC000000000000
cmpq %rcx, %rax
je 0x2373f
jmp 0x236ac
jmp 0x236ae
movq 0x50(%rsp), %rax
movq 0x5f0(%rax), %rax
cmpq $0x0, 0x58(%rax)
je 0x236fb
movq 0xf930(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x6a7e(%rip), %rsi      # 0x2a150
leaq 0x6b8b(%rip), %rdx      # 0x2a264
leaq 0x8aa7(%rip), %rcx      # 0x2c187
leaq 0x83af(%rip), %r8       # 0x2ba96
movl $0x747, %r9d            # imm = 0x747
movb $0x0, %al
callq 0x2240
ud2
callq 0x2040
jmp 0x236fd
movq 0x50(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rdi
callq 0x7590
movq 0x18(%rsp), %rdi
movq %rax, %rdx
leaq 0x898a(%rip), %rsi      # 0x2c0aa
movb $0x0, %al
callq 0x4ed0
movq %rax, %rcx
movq 0x50(%rsp), %rax
movq 0x5f0(%rax), %rax
movq %rcx, 0x58(%rax)
jmp 0x239d4
movq 0x48(%rsp), %rax
movabsq $0xffffffffffff, %rcx   # imm = 0xFFFFFFFFFFFF
andq %rcx, %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
movl (%rax), %eax
movq %rax, 0x10(%rsp)
subq $0x8, %rax
ja 0x2399f
movq 0x10(%rsp), %rax
leaq 0x82e8(%rip), %rcx      # 0x2ba60
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x23783
jmp 0x23785
movq 0x50(%rsp), %rax
movq 0x5f0(%rax), %rax
cmpq $0x0, 0x58(%rax)
je 0x237d2
movq 0xf859(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x69a7(%rip), %rsi      # 0x2a150
leaq 0x6ab4(%rip), %rdx      # 0x2a264
leaq 0x89d0(%rip), %rcx      # 0x2c187
leaq 0x82d8(%rip), %r8       # 0x2ba96
movl $0x74e, %r9d            # imm = 0x74E
movb $0x0, %al
callq 0x2240
ud2
callq 0x2040
jmp 0x237d4
movq 0x50(%rsp), %rdi
leaq 0x89b7(%rip), %rsi      # 0x2c197
movl $0x1d, %edx
callq 0x2760
movq %rax, %rcx
movq 0x50(%rsp), %rax
movq 0x5f0(%rax), %rax
movq %rcx, 0x58(%rax)
jmp 0x239d4
movq 0x30(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x20(%rsp)
movq 0x50(%rsp), %rdi
movq 0x40(%rsp), %rsi
leaq 0x28(%rsp), %rdx
leaq 0x8932(%rip), %rcx      # 0x2c158
callq 0x20580
testb $0x1, %al
jne 0x23834
jmp 0x239d4
movq 0x50(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rax
movl 0x8(%rax), %edx
leaq 0x9260(%rip), %rcx      # 0x2caad
callq 0x235a0
testb $0x1, %al
jne 0x2385b
jmp 0x239d4
movq 0x38(%rsp), %rdx
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x28(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x239d4
movabsq $-0x4000000000000, %rax # imm = 0xFFFC000000000000
andq 0x40(%rsp), %rax
movabsq $-0x4000000000000, %rcx # imm = 0xFFFC000000000000
cmpq %rcx, %rax
jne 0x23948
movabsq $0xffffffffffff, %rax   # imm = 0xFFFFFFFFFFFF
andq 0x40(%rsp), %rax
movl (%rax), %edi
callq 0x7950
testb $0x1, %al
jne 0x23948
jmp 0x238b8
jmp 0x238ba
movq 0x50(%rsp), %rax
movq 0x5f0(%rax), %rax
cmpq $0x0, 0x58(%rax)
je 0x23907
movq 0xf724(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x6872(%rip), %rsi      # 0x2a150
leaq 0x697f(%rip), %rdx      # 0x2a264
leaq 0x889b(%rip), %rcx      # 0x2c187
leaq 0x81a3(%rip), %r8       # 0x2ba96
movl $0x75f, %r9d            # imm = 0x75F
movb $0x0, %al
callq 0x2240
ud2
callq 0x2040
jmp 0x23909
movq 0x50(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x40(%rsp), %rdi
callq 0x7590
movq 0x8(%rsp), %rdi
movq %rax, %rdx
leaq 0x6f84(%rip), %rsi      # 0x2a8b0
movb $0x0, %al
callq 0x4ed0
movq %rax, %rcx
movq 0x50(%rsp), %rax
movq 0x5f0(%rax), %rax
movq %rcx, 0x58(%rax)
jmp 0x23961
movq 0x50(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rcx
callq 0x61a0
jmp 0x239d4
jmp 0x23965
movq 0xf68c(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x67da(%rip), %rsi      # 0x2a150
leaq 0x6a32(%rip), %rdx      # 0x2a3af
leaq 0x8803(%rip), %rcx      # 0x2c187
leaq 0x810b(%rip), %r8       # 0x2ba96
movl $0x76c, %r9d            # imm = 0x76C
movb $0x0, %al
callq 0x2240
ud2
callq 0x2040
jmp 0x239a1
movq 0xf650(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x6828(%rip), %rsi      # 0x2a1da
leaq 0x87ce(%rip), %rdx      # 0x2c187
leaq 0x80d6(%rip), %rcx      # 0x2ba96
movl $0x770, %r8d            # imm = 0x770
movb $0x0, %al
callq 0x2240
ud2
callq 0x2040
addq $0x58, %rsp
retq
nopl (%rax)