#include "mw4_funcs.h"
#include "mw4_globals.h"
#include "mw4_types.h"

void Reset(void)

{
  undefined4 uVar1;
  int iVar2;
  word wVar3;
  byte bVar4;
  undefined4 *puVar5;
  short sVar6;
  uint uVar7;
  union2_t uVar8;
  short sVar9;
  undefined1 *puVar10;
  undefined4 *puVar11;
  byte *pbVar12;
  undefined4 *puVar13;
  bool bVar14;

  uVar1 = Ram00a10008;
  iVar2 = Ram00a10008;
  bVar14 = iVar2 == 0;
  if (bVar14) {
    wVar3 = IO_EXT_CTRL;
    wVar3 = IO_EXT_CTRL;
    bVar14 = wVar3 == 0;
  }
  if (bVar14) {
    uVar7 = 0xffff8000;
    sVar9 = 0x3fff;
    bVar4 = IO_PCBVER._1_1_;
    if ((bVar4 & 0xf) != 0) {
      IO_TMSS = 0x53454741;
    }
    puVar13 = (undefined4 *)0x0;
    sVar6 = 0x17;
    puVar5 = (undefined4 *)&DAT_000002a8;
    do {
      puVar11 = puVar5;
      uVar8.w = (word)CONCAT31((int3)(uVar7 >> 8), *(undefined1 *)puVar11);
      VDP_CTRL = (union2_t)uVar8.w;
      uVar7 = (uint)(ushort)(uVar8.w + 0x100);
      sVar6 = sVar6 + -1;
      puVar5 = (undefined4 *)((int)puVar11 + 1);
    } while (sVar6 != -1);
    Ram00c00004 = *(undefined4 *)((int)puVar11 + 1);
    VDP_DATA = 0;
    IO_Z80BUS = IO_Z80BUS_LOCK;
    IO_Z80RES = IO_Z80RES_THAW;
    do {
      bVar4 = IO_Z80BUS._0_1_;
    } while ((bVar4 & 1) != 0);
    sVar6 = 0x25;
    puVar10 = &z80_ram;
    puVar5 = (undefined4 *)((int)puVar11 + 5);
    do {
      puVar11 = puVar5;
      *puVar10 = *(undefined1 *)puVar11;
      sVar6 = sVar6 + -1;
      puVar10 = puVar10 + 1;
      puVar5 = (undefined4 *)((int)puVar11 + 1);
    } while (sVar6 != -1);
    IO_Z80RES = IO_Z80RES_FREEZE;
    IO_Z80BUS = IO_Z80BUS_UNLOCK;
    IO_Z80RES = IO_Z80RES_THAW;
    do {
      puVar13 = puVar13 + -1;
      *puVar13 = 0;
      sVar9 = sVar9 + -1;
    } while (sVar9 != -1);
    Ram00c00004 = *(undefined4 *)((int)puVar11 + 1);
    Ram00c00004 = *(undefined4 *)((int)puVar11 + 5);
    sVar9 = 0x1f;
    do {
      Ram00c00000 = 0;
      sVar9 = sVar9 + -1;
    } while (sVar9 != -1);
    Ram00c00004 = *(undefined4 *)((int)puVar11 + 9);
    sVar9 = 0x13;
    do {
      Ram00c00000 = 0;
      sVar9 = sVar9 + -1;
    } while (sVar9 != -1);
    sVar9 = 3;
    pbVar12 = (byte *)((int)puVar11 + 0xd);
    do {
      VDP_PSG = *pbVar12;
      sVar9 = sVar9 + -1;
      pbVar12 = pbVar12 + 1;
    } while (sVar9 != -1);
    IO_Z80RES = IO_Z80RES_FREEZE;
  }
  uVar8 = VDP_CTRL;
  uVar8 = VDP_CTRL;
  init();
  return;
}

void BusErr(void)

{
  do {
    // WARNING: Do nothing block with infinite loop
  } while (true);
}

void FUN_0000030a(void)

{
  return;
}

undefined8 init_something(ulong param_1, ulong param_2, ulong param_3,
                          ulong param_4, long param_5, short param_6,
                          long param_7, long param_8, long param_9,
                          long param_10, long param_11)

{
  uint uVar1;
  short i;
  long extraout_D0;
  undefined2 *puVar2;
  undefined **ppuVar3;
  undefined4 unaff_A2;
  undefined8 uVar4;
  register_t a[5];
  register_t d[8];
  undefined2 extraout_D1u;

  DAT_ffff96ba = 0;
  related_to_palette_maybe_1 = 0;
  DAT_ffff968b = 0;
  related_to_palette_maybe_2 = 0;
  DAT_ffff968d = 0;
  DAT_ffffe230 = 0;
  vdp_related_to_display_1 = 0;
  DAT_ffff96b0 = 0;
  DAT_ffffc714 = 0xf;
  DAT_ffff9101 = 0xff;
  vdp_init_and_clear_gamepad();
  ecs_clear_some_component_all();
  vdp_clear_palettes_and_more();
  vdp_clear_something();
  sram_unk_3();
  clear_unk_1();
  clear_unk_2();
  DAT_ffffcb2c = DAT_ffffcbb0 == '\x02';
  gamepad_pressed_prev = GAMEPAD_NONE;
  gamepad_held_prev = GAMEPAD_NONE;
  gamepad_pressed = GAMEPAD_NONE;
  gamepad_held_3 = GAMEPAD_NONE;
  DAT_ffff9101 = 0;
  DAT_ffff9102 = 0;
  DAT_ffff9100 = 0;
  i = 4;
  puVar2 = &DAT_ffff9104;
  ppuVar3 = &PTR_SSP_00000454;
  do {
    a[0] = ppuVar3 + 1;
    *(undefined **)(puVar2 + 4) = *ppuVar3;
    *puVar2 = 0;
    puVar2 = puVar2 + 8;
    i = i + -1;
    ppuVar3 = a[0];
  } while (i != -1);
  a[3] = param_2;
  a[4] = param_3;
  a[2] = param_1;
  a[1] = unaff_A2;
  d[6] = param_10;
  d[7] = param_11;
  d[4] = param_8;
  d[5] = param_9;
  d[2] = 0x10;
  d[3] = param_7;
  d[0] = 1;
  d[1] = 0;
  main_save_registers_into_stack(sega_and_title_screen, d, a);
  uVar1 = CONCAT22(extraout_D1u, vdp_ctrl_mode_set_2_state);
  VDP_CTRL = (union2_t)(vdp_ctrl_mode_set_2_state | 0x60);
  vdp_ctrl_mode_set_2_state = vdp_ctrl_mode_set_2_state | 0x60;
  uVar4 = exception_unk_0((script_ctx_t *)param_1,
                          param_2,
                          (void *)param_4,
                          extraout_D0,
                          uVar1 | 0x60,
                          0x10,
                          param_7,
                          param_8,
                          param_9,
                          param_10,
                          param_11);
  return uVar4;
}

// This likely doesn't need all these params, it just loads registers from the
// stack.

longlong exception_load_registers_from_stack(longlong param_1, register_t d[8],
                                             register_t a[6])

{
  short sVar1;
  short sVar3;
  undefined4 uVar2;
  undefined2 uVar4;
  undefined4 uVar5;
  undefined4 extraout_A0;
  undefined2 *puVar6;
  ushort uVar7;
  register_t *prVar8;
  undefined8 uVar9;
  register_t *regs;

  if (DAT_ffff9101 != '\0') {
    return param_1;
  }
  DAT_ffff9101 = 0xff;
  if (DAT_ffff9102 != 0) {
    // Restore registers
    DAT_ffff9101 = 0;
    return param_1;
  }
  if (DAT_ffff9104 == -1) {
    DAT_ffff9104 = 1;
    DAT_ffff910c = (undefined1 *)register0x0000003c;
  }
  DAT_ffff9100 = 0;
  uVar9 = exception_unk_0(
      a[2], a[3], a[5], d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7]);
  sVar3 = (short)((ulonglong)uVar9 >> 0x20);
  uVar4 = (undefined2)((ulonglong)uVar9 >> 0x10);
  uVar5 = CONCAT22(uVar4, sVar3 * 2);
  puVar6 = (undefined2 *)(int)*(short *)((short)(sVar3 * 2) + 0x468);
  sVar1 = sVar3 << 2;
  uVar2 = CONCAT22((short)((ulonglong)uVar9 >> 0x30), sVar1);
  regs = *(register_t **)(sVar1 + 0x454);
  *puVar6 = 1;
  prVar8 = regs + -1;
  regs[-1] = extraout_A0;
  if (sVar1 == 0) {
    uVar7 = (ushort)(byte)(CARRY2(sVar3 * 2, sVar3 * 2) << 4 |
                           (sVar1 < 0) << 3 | (sVar1 == 0) << 2);
    uVar5 = CONCAT22(uVar4, uVar7);
    *(ushort *)((int)regs + -6) = uVar7;
    *(short **)((int)regs + -10) = &DAT_ffff9104;
    *(entity_id_t *)((int)regs + -0xe) = a[3];
    *(script_ctx_t **)((int)regs + -0x12) = a[2];
    *(BADSPACEBASE **)((int)regs + -0x16) = register0x0000003c;
    *(undefined2 **)((int)regs + -0x1a) = puVar6;
    *(undefined4 *)((int)regs + -0x1e) = extraout_A0;
    *(long *)((int)regs + -0x22) = d[7];
    *(long *)((int)regs + -0x26) = d[6];
    *(long *)((int)regs + -0x2a) = d[5];
    *(long *)((int)regs + -0x2e) = d[4];
    *(long *)((int)regs + -0x32) = d[3];
    *(long *)((int)regs + -0x36) = d[2];
    *(undefined4 *)((int)regs + -0x3a) = uVar5;
    prVar8 = (register_t *)((int)regs + -0x3e);
    *prVar8 = uVar2;
  }
  prVar8[-1] = (register_t)a[5];
  *(register_t **)(puVar6 + 4) = prVar8 + -1;
  DAT_ffff9101 = 0;
  return CONCAT44(uVar2, uVar5);
}

// This likely doesn't need all these params, it just stores registers on the
// stack.

void main_save_registers_into_stack(func *callback, register_t d[8],
                                    register_t a[5])

{
  short index_w;
  word *dunno_p;
  undefined4 unaff_A6;
  ushort uVar1;
  undefined4 *puVar2;
  void *stack_p;
  short stack_offset;

  index_w = d[0]._2_2_;
  dunno_p = (word *)(int)*(short *)((short)(index_w * 2) + 0x468);
  stack_offset = index_w << 2;
  stack_p = *(void **)(stack_offset + 0x454);
  *dunno_p = 1;
  puVar2 = (undefined4 *)((int)stack_p + -4);
  *(func **)((int)stack_p + -4) = callback;
  if (stack_offset == 0) {
    uVar1 = (ushort)(byte)(CARRY2(index_w * 2, index_w * 2) << 4 |
                           (stack_offset < 0) << 3 | (stack_offset == 0) << 2);
    *(ushort *)((int)stack_p + -6) = uVar1;
    *(register_t *)((int)stack_p + -10) = a[4];
    *(register_t *)((int)stack_p + -0xe) = a[3];
    *(register_t *)((int)stack_p + -0x12) = a[2];
    *(BADSPACEBASE **)((int)stack_p + -0x16) = register0x0000003c;
    *(word **)((int)stack_p + -0x1a) = dunno_p;
    *(func **)((int)stack_p + -0x1e) = callback;
    *(register_t *)((int)stack_p + -0x22) = d[7];
    *(register_t *)((int)stack_p + -0x26) = d[6];
    *(register_t *)((int)stack_p + -0x2a) = d[5];
    *(register_t *)((int)stack_p + -0x2e) = d[4];
    *(register_t *)((int)stack_p + -0x32) = d[3];
    *(register_t *)((int)stack_p + -0x36) = d[2];
    *(uint *)((int)stack_p + -0x3a) = CONCAT22(d[1]._0_2_, uVar1);
    puVar2 = (undefined4 *)((int)stack_p + -0x3e);
    *puVar2 = CONCAT22(d[0]._0_2_, stack_offset);
  }
  puVar2[-1] = unaff_A6;
  *(undefined4 **)(dunno_p + 4) = puVar2 + -1;
  DAT_ffff9101 = 0;
  return;
}

undefined8 FUN_00000472(ulong param_1, long param_2, long param_3)

{
  short sVar2;
  long lVar1;
  long lVar3;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  undefined8 uVar4;

  sVar2 = (short)param_2;
  lVar3 = CONCAT22((short)((uint)param_3 >> 0x10), sVar2);
  lVar1 = CONCAT22((short)((uint)param_2 >> 0x10), sVar2 * 2);
  *(undefined2 *)(int)*(short *)((short)(sVar2 * 2) + 0x468) = 0;
  DAT_ffff9101 = 0;
  if (sVar2 == DAT_ffff9102) {
    uVar4 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            (void *)param_1,
                            lVar1,
                            lVar3,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    return uVar4;
  }
  return CONCAT44(lVar1, lVar3);
}

// WARNING: This function may have set the stack pointer
// This function seems quite central and is called from many places.

undefined8 exception_unk_0(script_ctx_t *ctx, entity_id_t self, void *param_3,
                           long param_4, long param_5, long param_6,
                           long param_7, long param_8, long param_9,
                           long param_10, long param_11)

{
  undefined2 uVar1;
  undefined4 in_A1;
  undefined4 unaff_A2;
  short *psVar2;
  char in_XF;
  ushort uVar3;
  register_t a[5];
  register_t d[8];
  undefined4 uStack_3e;
  long lStack_3a;
  undefined4 local_4;

  psVar2 = &DAT_ffff9104;
  local_4 = (void *)CONCAT22(local_4._0_2_, local_4._2_2_);
  if (DAT_ffff9100 != '\0') {
    uVar1 = (undefined2)((uint)param_4 >> 0x10);
    local_4._0_2_ = SUB42(param_3, 0);
    if (DAT_ffff9102 == 0) {
      uVar3 = (ushort)(byte)(in_XF << 4 | 4);
      uStack_3e = CONCAT22(uVar1, uVar3);
      lStack_3a = param_5;
      local_4 = (void *)CONCAT22(local_4._0_2_, uVar3);
      if (DAT_ffff9104 == -1) {
        DAT_ffff9104 = 1;
        DAT_ffff910c = (undefined8 *)&uStack_3e;
        local_4 = (void *)CONCAT22(local_4._0_2_, uVar3);
      }
      goto LAB_00000546;
    }
    param_4 = CONCAT22(uVar1, DAT_ffff9102 * 2);
    psVar2 = (short *)(int)*(short *)((short)(DAT_ffff9102 * 2) + 0x468);
    if (*psVar2 == -1) {
      *psVar2 = 1;
    }
    *(undefined4 **)(psVar2 + 4) = &local_4;
    local_4 = param_3;
  }
  while (true) {
    DAT_ffff9100 = -1;
    DAT_ffff9102 = DAT_ffff9102 + 1;
    if (DAT_ffff9102 == 5)
      break;
    psVar2 = psVar2 + 8;
    if (*psVar2 == 1) {
      *psVar2 = -1;
      DAT_ffff9101 = 0;
      return CONCAT44(param_4, param_5);
    }
  }
  DAT_ffff9102 = 0;
  if (DAT_ffff9104 == 1) {
    DAT_ffff9104 = 0xffff;
    DAT_ffff9101 = 0;
    return *DAT_ffff910c;
  }
LAB_00000546:
  DAT_ffff9102 = 0;
  DAT_ffff9101 = 0;
  if (DAT_ffff96b0 != '\0') {
    DAT_ffff90fc = 0x564;
    a[3] = self;
    a[4] = (register_t)&DAT_ffff9104;
    a[2] = (register_t)ctx;
    a[0] = in_A1;
    a[1] = unaff_A2;
    d[6] = param_10;
    d[7] = param_11;
    d[4] = param_8;
    d[5] = param_9;
    d[2] = param_6;
    d[3] = param_7;
    d[1] = param_5;
    d[0] = 0;
    main_save_registers_into_stack(FUN_00000568, d, a);
  }
  do {
    // WARNING: Do nothing block with infinite loop
  } while (true);
}

undefined8 FUN_00000568(void)

{
  long in_D1;
  long extraout_D1;
  ulong unaff_A6;
  undefined8 uVar1;

  while (DAT_ffff96b0 != '\0') {
    (*PTR_ffff96b2)();
    in_D1 = extraout_D1;
  }
  uVar1 = FUN_00000472(unaff_A6, 0, in_D1);
  return uVar1;
}

void vdp_copy(vdp_mem_t mem, void *src, void *dst, uint16_t length,
              uint8_t stride)

{
  ushort addr_2;
  uint dma_src;
  ushort addr_1;
  byte dma_src_high;
  byte dma_src_mid;
  byte dma_src_low;
  byte z80_is_busy;

  io_z80bus_tmp = IO_Z80BUS;
  IO_Z80BUS = IO_Z80BUS_LOCK;
  do {
    z80_is_busy = IO_Z80BUS._0_1_;
  } while ((z80_is_busy & 1) != 0);
  if (stride != '\0') {
    // Set the VDP auto-increment register.
    VDP_CTRL = (union2_t)(word)CONCAT31(0x8f, stride);
  }
  // Maybe set scroll size register #10?
  // Or horizontal position #11?
  // Or vertical position #12?
  // Or something completely different.
  VDP_CTRL = (union2_t)(vdp_ctrl_mode_set_2_state | 0x10);
  // Set the low byte of the VDP DMA counter.
  VDP_CTRL = (union2_t)(word)CONCAT31(0x93, (char)length);
  // Set the hight byte of the VDP DMA counter.
  VDP_CTRL = (union2_t)(length >> 8 | 0x9400);
  dma_src = (uint)src >> 1;
  dma_src_low = (byte)dma_src;
  // Set the low byte of the VDP DMA source address.
  VDP_CTRL = (union2_t)(word)CONCAT31(0x95, dma_src_low);
  dma_src_mid = (byte)(dma_src >> 8);
  // Set the mid byte of the VDP DMA source address.
  VDP_CTRL = (union2_t)(word)CONCAT31(0x96, dma_src_mid);
  dma_src_high = (byte)(dma_src >> 0x10);
  // Set the ghigh byte of the VDP DMA source address.
  // Also set it to VRAM.
  VDP_CTRL = (union2_t)((ushort)CONCAT31(0x97, dma_src_high) & 0xff7f);
  addr_1 = (ushort)dst & 0x3fff;
  if (mem == VDP_MEM_COLOR_RAM) {
    addr_1 = addr_1 | 0xc000;
  }
  addr_2 = (ushort)dst >> 0xe;
  if (mem == VDP_MEM_VSCROLL_RAM) {
    addr_2 = addr_2 | 0x90;
  }
  // Write
  VDP_CTRL = (union2_t)(addr_1 | 0x4000);
  VDP_CTRL = (union2_t)(addr_2 | 0x80);
  VDP_CTRL = (union2_t)vdp_ctrl_mode_set_2_state;
  VDP_CTRL = (union2_t)(addr_1 | 0x4000);
  VDP_CTRL = (union2_t)(addr_2 & 0xff7f);
  // WARNING: Load size is inaccurate
  VDP_DATA = *src;
  IO_Z80BUS = ~io_z80bus_tmp;
  VDP_CTRL = VDP_REG_MODE_AUTO_INCREMENT_02;
  return;
}

// Fills the VRAM with the given value.

void vdp_vram_fill(uint16_t value, void *dst, uint16_t length, uint16_t stride)

{
  vdp_ctrl_read_lower_byte_t vdp_ctrl;

  // Can be called with the variable set as the mode set 2 register, in which
  // case the `| #10` enables DMA access.
  VDP_CTRL = (union2_t)(vdp_ctrl_mode_set_2_state | 0x10);
  if (stride != 0) {
    VDP_CTRL = (union2_t)(word)CONCAT31(0x8f, (char)stride);
  }
  VDP_CTRL = (union2_t)(word)CONCAT31(0x93, (char)length);
  VDP_CTRL = (union2_t)(length >> 8 | VDP_REG_MODE_DMA_COUNTER_HIGH);
  // DMA source address high register #17, value #80: VRAM fill
  VDP_CTRL = VDP_REG_MODE_DMA_SOURCE_VRAM_FILL;
  // & #3fff: RAM address lower part
  // | #4000: VRAM or VSRAM write
  VDP_CTRL = (union2_t)((ushort)dst & 0x3fff | 0x4000);
  // RAM address upper part and either RAM to VRAM or VRAM fill.
  // Unclear from the documentation, there may be a typo.
  // https://wiki.megadrive.org/index.php?title=VDP_Ports#Write_2_-_Setting_RAM_address
  //
  // According to this other documentation, it just triggers the operation.
  // https://www.neperos.com/article/picoxo1fc33c8979#:~:text=Setting%20CD5%20will%20trigger%20a%20DMA%20operation%2E
  VDP_CTRL = (union2_t)((ushort)((uint)((int)dst << 2) >> 0x10) & 3 | 0x80);
  // Wait for the copy to be done.
  VDP_DATA = value;
  do {
    vdp_ctrl = VDP_CTRL._1_1_;
  } while ((vdp_ctrl & VDP_CTRL_READ_DMA_BUSY) != VDP_CTRL_READ_NONE);
  VDP_CTRL = (union2_t)vdp_ctrl_mode_set_2_state;
  // Set stride (auto-increment) to 2.
  VDP_CTRL = VDP_REG_MODE_AUTO_INCREMENT_02;
  return;
}

void vdp_vram_copy(void *src, void *dst, uint16_t length, uint16_t stride)

{
  // Enable DMA access
  VDP_CTRL = (union2_t)(vdp_ctrl_mode_set_2_state | 0x10);
  if (stride != 0) {
    VDP_CTRL = (union2_t)(word)CONCAT31(0x8f, (char)stride);
  }
  VDP_CTRL = (union2_t)(word)CONCAT31(0x93, (char)length);
  // This seems buggy, it looks like it should do a shift right.
  VDP_CTRL = (union2_t)(length << 8 | 0x9400);
  VDP_CTRL = 0x9500;
  VDP_CTRL = (union2_t)((short)src << 8 | 0x9600);
  VDP_CTRL = 0x97c0;
  VDP_CTRL = (union2_t)((ushort)dst & 0x3fff);
  VDP_CTRL = (union2_t)((ushort)((uint)dst >> 0x12) & 3 | 0xc0);
  do {
    // WTF is happening here?
    // Is it because of the auto-increment, and we are waiting for the copy to
    // be done as src gets incremented by the stride?
  } while ((*(byte *)((int)src + 1) & 2) != 0);
  // Revert DMA access
  VDP_CTRL = (union2_t)vdp_ctrl_mode_set_2_state;
  VDP_CTRL = 0x8f02;
  return;
}

// D0 isn't used, it's stored on the stack and restored at the end.

undefined2 exception_mode1_set_color_use_all_bits(void)

{
  undefined2 in_D0w;
  vdp_ctrl_read_t vdp_state;
  vdp_draw_pos_t pos;

  VDP_CTRL = VDP_REG_MODE_SET_1_COLOR_USE_ALL_BITS;
  // Why are these read?
  pos = VDP_DRAW_POS;
  vdp_state = (vdp_ctrl_read_t)VDP_CTRL;
  return in_D0w;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined2 exception_something(void)

{
  ushort uVar1;
  vdp_draw_pos_t vVar2;
  undefined2 in_D0w;

  vVar2 = VDP_DRAW_POS;
  if ((ushort)vVar2 < 0xde00) {
    VDP_CTRL = 0x8a00;
    VDP_CTRL = 0x8014;
    if (vdp_related_to_hblank_effects_2 <= (ushort)vVar2) {
      if ((ushort)vVar2 < 0xdc00) {
        _DAT_ffff91cc = _DAT_ffff91cc + 1;
        VDP_CTRL = 0x4000;
        VDP_CTRL = 0x10;
        VDP_DATA = -_DAT_ffff91cc;
      } else {
        if (DAT_ffff9628 == '\0') {
          uVar1 = vdp_related_to_hblank_effects_2 + 0x100;
          if (0xdbff < (ushort)(vdp_related_to_hblank_effects_2 + 0x100)) {
            VDP_CTRL = 0x8004;
            vdp_gfx_ptr_5._0_2_ = 0;
            vdp_related_to_display_asha = 4;
            vdp_related_to_display_1 = 0xff;
            DAT_ffff9628 = 0xff;
            return in_D0w;
          }
        } else {
          uVar1 = vdp_related_to_hblank_effects_2 - 0x100;
          if (uVar1 < 0x1000) {
            VDP_CTRL = 0x8004;
            vdp_gfx_ptr_5._0_2_ = 0;
            vdp_related_to_display_asha = 4;
            vdp_related_to_display_1 = 0xff;
            vdp_related_to_hblank_effects_2 = uVar1;
            DAT_ffff9628 = 0;
            return in_D0w;
          }
        }
        vdp_related_to_hblank_effects_2 = uVar1;
        DAT_ffff9630 = 0x8a00;
        VDP_CTRL = 0x8a00;
        VDP_CTRL = 0x8004;
        vdp_related_to_display_1 = 0xff;
      }
    }
  }
  vdp_gfx_ptr_5._0_2_ = 0;
  vdp_related_to_display_asha = 4;
  return in_D0w;
}

undefined2 FUN_000007a4(void)

{
  ushort uVar1;
  undefined2 in_stack_00000000;

  if (DAT_ffff9628 == '\0') {
    uVar1 = vdp_related_to_hblank_effects_2 + 0x100;
    if (0xdbff < (ushort)(vdp_related_to_hblank_effects_2 + 0x100)) {
      VDP_CTRL = 0x8004;
      vdp_gfx_ptr_5._0_2_ = 0;
      vdp_related_to_display_asha = 4;
      vdp_related_to_display_1 = 0xff;
      DAT_ffff9628 = 0xff;
      return in_stack_00000000;
    }
  } else {
    uVar1 = vdp_related_to_hblank_effects_2 - 0x100;
    if (uVar1 < 0x1000) {
      VDP_CTRL = 0x8004;
      vdp_gfx_ptr_5._0_2_ = 0;
      vdp_related_to_display_asha = 4;
      vdp_related_to_display_1 = 0xff;
      vdp_related_to_hblank_effects_2 = uVar1;
      DAT_ffff9628 = 0;
      return in_stack_00000000;
    }
  }
  vdp_related_to_hblank_effects_2 = uVar1;
  VDP_CTRL = 0x8a00;
  VDP_CTRL = 0x8004;
  DAT_ffff9630 = 0x8a00;
  vdp_related_to_display_1 = 0xff;
  vdp_gfx_ptr_5._0_2_ = 0;
  vdp_related_to_display_asha = 4;
  return in_stack_00000000;
}

undefined2 exception_vdp_hblank_effect_maybe(void)

{
  undefined2 in_D0w;
  vdp_draw_pos_t vdp_hv_counter;

  vdp_hv_counter = VDP_DRAW_POS;
  // If writing line 223 (#df).
  if (((ushort)vdp_hv_counter & 0xff00) == 0xdf00) {
    VDP_CTRL = VDP_REG_MODE_SET_1_COLOR_USE_ALL_BITS;
    if (vdp_related_to_hblank_effects_2 == 0) {
      VDP_CTRL = VDP_REG_MODE_SET_1_COLOR_USE_ALL_BITS;
      vdp_related_to_display_1 = 0;
      // Disable display
      vdp_ctrl_mode_set_2_state = vdp_ctrl_mode_set_2_state & 0xffbf;
      VDP_CTRL = (union2_t)vdp_ctrl_mode_set_2_state;
    } else {
      vdp_related_to_display_1 = 0xff;
      vdp_related_to_hblank_effects_2 = vdp_related_to_hblank_effects_2 - 1;
    }
  } else if (((ushort)vdp_hv_counter & 0xff00) < 0xdf00) {
    vdp_related_to_hblank_y_pos_pepelogoo.w =
        vdp_related_to_hblank_y_pos_pepelogoo.w + 1;
    if (vdp_related_to_hblank_y_pos_pepelogoo.w <
        vdp_related_to_hblank_effects_2) {
      // Enable display
      vdp_ctrl_mode_set_2_state = vdp_ctrl_mode_set_2_state | 0x40;
      VDP_CTRL = (union2_t)vdp_ctrl_mode_set_2_state;
    } else {
      // Disable display
      vdp_ctrl_mode_set_2_state = vdp_ctrl_mode_set_2_state & 0xffbf;
      VDP_CTRL = (union2_t)vdp_ctrl_mode_set_2_state;
    }
    if (vdp_related_to_hblank_y_pos_pepelogoo.w == 8) {
      vdp_related_to_hblank_y_pos_pepelogoo.w = 0;
    }
  }
  return in_D0w;
}

// Likely some hblank effect

void exception_some_hblank_effect(void)

{
  short i;
  word *data;
  vdp_draw_pos_t vdp_draw_pos;

  vdp_draw_pos = VDP_DRAW_POS;
  // if (drawing row 222)
  if (((ushort)vdp_draw_pos & 0xff00) == 0xde00) {
    related_to_palettes = 0xff;
  } else if (((ushort)vdp_draw_pos & 0xff00) < 0xde00) {
    VDP_CTRL = VDP_REG_HBLANK_INTERRUPT_RATE;
    VDP_CTRL = VDP_REG_MODE_SET_1_COLOR_HBLANK_INTERRUPT_AND_USE_ALL_BITS;
    if ((ushort)vdp_draw_pos >> 8 == vdp_related_to_hblank_y_pos_pepelogoo.w) {
      i = 10;
      // FIXME What is this for?
      // Does it write #c004 and #0000, aka "write at Color RAM #4"?
      Ram00c00004 = 0xc0040000;
      data = vdp_data_92e;
      do {
        VDP_DATA = *data;
        i = i + -1;
        data = data + 1;
      } while (i != -1);
    } else if ((ushort)vdp_draw_pos >> 8 <
               vdp_related_to_hblank_y_pos_pepelogoo.w) {
      vdp_related_to_hblank_effects_2 = 0;
      return;
    }
    i = vdp_related_to_hblank_effects_2 * 2;
    vdp_related_to_hblank_effects_2 = vdp_related_to_hblank_effects_2 + 1;
    // Write to Vertical Scrolling RAM at address 0.
    VDP_CTRL = 0x4000;
    VDP_CTRL = 0x10;
    VDP_DATA = -(i + 1);
    return;
  }
  vdp_related_to_hblank_effects_2 = 0;
  return;
}

void palette_set_fade_black_ease_out_all(void)

{
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_OUT,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  return;
}

void palette_set_fade_black_ease_in_all(void)

{
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  return;
}

void FUN_00000966(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  do {
    do {
      uVar1 = exception_unk_0(unaff_A3,
                              unaff_A4,
                              unaff_A6,
                              (long)((ulonglong)uVar1 >> 0x20),
                              (long)uVar1,
                              unaff_D2,
                              unaff_D3,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
    } while (palette_fade_done_0 == 0);
  } while (((palette_fade_done_1 == 0) || (palette_fade_done_2 == 0)) ||
           (palette_fade_done_3 == 0));
  return;
}

void FUN_00000986(void)

{
  FUN_00000994();
  prepare_sprites_maybe();
  DAT_ffffc708 = 0xff;
  return;
}

void FUN_00000994(void)

{
  short i;
  undefined2 *puVar1;
  int iVar2;
  entity_id_t self;
  undefined2 uVar3;
  anim_item_t *unaff_A5;

  puVar1 = &some_word_array;
  i = DAT_ffffc714;
  do {
    *puVar1 = 0xffff;
    i = i + -1;
    puVar1 = puVar1 + 1;
  } while (i != -1);
  self = ENTITY_ID_ASHA;
  i = 0x3f;
  do {
    if ((((&comp_has_func_maybe)[self] & COMPONENT_STATE_B_C0) ==
         COMPONENT_STATE_B_C0) &&
        (ecs_anim_update(self, unaff_A5),
         ((&comp_has_func_maybe)[self] & 8) == 0)) {
      *(undefined2 *)((int)&comp_unk_6 + self) = 0xffff;
      iVar2 = (int)*(short *)((int)&comp_unk_3 + self);
      uVar3 = (undefined2)self;
      if (*(short *)((int)&some_word_array + iVar2) < 0) {
        *(undefined2 *)((int)&some_word_array + iVar2) = uVar3;
      } else {
        *(undefined2 *)((int)&comp_unk_6 +
                        (int)*(short *)(&DAT_ffffc6b6 + iVar2)) = uVar3;
      }
      *(undefined2 *)(&DAT_ffffc6b6 + iVar2) = uVar3;
    }
    self = self + ENTITY_ID_PEPELOGOO;
    i = i + -1;
  } while (i != -1);
  return;
}

void prepare_sprites_maybe(void)

{
  short sVar1;
  short sVar2;
  byte bVar3;
  ushort uVar4;
  ushort uVar5;
  short extraout_D0w;
  short i;
  short sVar6;
  ushort uVar7;
  uint some_word_array_offset;
  uint extraout_A0;
  undefined **vdp_sprites_p;
  undefined **ppuVar8;
  undefined **extraout_A1;
  byte *some_byte_p;
  entity_id_t self;
  bool bVar9;
  bool bVar10;
  short pos_y;
  short pos_x;
  short some_word;
  entity_state_a_t state_a;

  some_word_array_offset = 0;
  vdp_sprites_p = &vdp_sprites_ptr;
  vdp_sprites_ptr = (undefined *)0x0;
  DAT_ffffc6f6 = 1;
  i = DAT_ffffc714;
  do {
    some_word = *(short *)((int)&some_word_array + some_word_array_offset);
    while (-1 < some_word) {
      self = (entity_id_t)some_word;
      pos_y = *(short *)((int)&comp_pos_y + self);
      some_word = *(short *)((int)&related_to_comp_unk_4_ffffa32a_1 +
                             (int)*(short *)((int)&comp_unk_4 + self));
      pos_x = *(short *)((int)&comp_pos_x + self);
      sVar1 = *(short *)(&related_to_comp_unk_4_ffffa32a_2 +
                         *(short *)((int)&comp_unk_4 + self));
      state_a = (&comp_state_a)[self];
      for (some_byte_p = *(byte **)((int)&comp_anim_frame_p + self);
           bVar3 = *some_byte_p, -1 < (char)bVar3;
           some_byte_p = some_byte_p + 5) {
        sVar6 = (short)(char)some_byte_p[4];
        sVar2 = *(short *)((short)((ushort)bVar3 * 2) + 0xb18);
        if ((state_a & ENTITY_STATE_A_H_FLIP) != 0) {
          sVar6 = -sVar2 - sVar6;
        }
        uVar4 = (pos_y - some_word) + sVar6;
        if (uVar4 < 0x160) {
          uVar7 = uVar4 + sVar2;
          if (some_word_array_offset < 4) {
            bVar10 = uVar7 < 0x80;
            bVar9 = uVar7 == 0x80;
          } else {
            bVar10 = uVar7 < DAT_ffffd2e2;
            bVar9 = uVar7 == DAT_ffffd2e2;
          }
          if (!bVar10 && !bVar9) {
            uVar7 =
                CONCAT11(state_a & (ENTITY_STATE_A_H_FLIP | ENTITY_STATE_A_08) ^
                             some_byte_p[1],
                         some_byte_p[2]);
            if (((&comp_has_func_maybe)[self] & 0x20) != 0) {
              uVar7 = *(short *)((int)&comp_unk_7 + self) + uVar7;
            }
            if ((state_a & 0x80) != 0) {
              uVar7 = uVar7 | 0x8000;
            }
            sVar6 = (short)(char)some_byte_p[3];
            sVar2 = *(short *)((short)((ushort)bVar3 * 2) + 0xb38);
            if ((state_a & ENTITY_STATE_A_08) != 0) {
              sVar6 = -sVar2 - sVar6;
            }
            uVar5 = (pos_x - sVar1) + sVar6;
            if ((uVar5 < 0x180) && (0x80 < (ushort)(uVar5 + sVar2))) {
              ppuVar8 = vdp_sprites_p + 1;
              *vdp_sprites_p =
                  (undefined *)(CONCAT22(CONCAT11(bVar3, DAT_ffffc6f6), uVar4)
                                    << 0x10 |
                                (uint)CONCAT11(bVar3, DAT_ffffc6f6));
              vdp_sprites_p = vdp_sprites_p + 2;
              *ppuVar8 = (undefined *)CONCAT22(uVar7, uVar5);
              DAT_ffffc6f6 = DAT_ffffc6f6 + 1;
              if (0x40 < DAT_ffffc6f6)
                goto LAB_00000b08;
            }
          }
        }
      }
      some_word = *(short *)((int)&comp_unk_6 + self);
    }
    some_word_array_offset = some_word_array_offset + 2;
    if ((some_word_array_offset == 4) && (DAT_ffffd2de != '\0')) {
      if (0x3c < DAT_ffffc6f6)
        break;
      FUN_00000b58(vdp_sprites_p);
      some_word_array_offset = extraout_A0;
      vdp_sprites_p = extraout_A1;
      i = extraout_D0w;
    }
    i = i + -1;
  } while (i != -1);
LAB_00000b08:
  DAT_ffffc6f6 = DAT_ffffc6f6 - 1;
  if (DAT_ffffc6f6 != '\0') {
    *(undefined1 *)((int)vdp_sprites_p + -5) = 0;
  }
  DAT_ffffc708 = 0xff;
  return;
}

void FUN_00000b58(void *vdp_sprites_p)

{
  *(undefined2 *)vdp_sprites_p = DAT_ffffd2e0;
  *(ushort *)((int)vdp_sprites_p + 2) = DAT_ffffc6f6 | 0x300;
  *(undefined4 *)((int)vdp_sprites_p + 4) = 10;
  DAT_ffffc6f6 = DAT_ffffc6f6 + 1;
  *(undefined2 *)((int)vdp_sprites_p + 8) = DAT_ffffd2e0;
  *(ushort *)((int)vdp_sprites_p + 10) = DAT_ffffc6f6 | 0x300;
  *(undefined4 *)((int)vdp_sprites_p + 0xc) = 0;
  DAT_ffffc6f6 = DAT_ffffc6f6 + 1;
  return;
}

void ecs_clear_some_component_all(void)

{
  short i;
  entity_id_t self;

  self = ENTITY_ID_ASHA;
  i = 0x3f;
  do {
    (&comp_has_func_maybe)[self] = 0;
    self = self + ENTITY_ID_PEPELOGOO;
    i = i + -1;
  } while (i != -1);
  return;
}

void copy_sprites_to_vram_maybe(void)

{
  void *dst;

  if (DAT_ffffc708 != '\0') {
    dst = (void *)0xffffde00;
    if (DAT_ffff96ba != '\0') {
      dst = (void *)0xffffdc00;
    }
    DAT_ffffc708 = '\0';
    vdp_copy(VDP_MEM_VIDEO_RAM, &vdp_sprites_ptr, dst, 0x100, '\x02');
  }
  return;
}

void ecs_anim_unk_1(entity_id_t self, anim_item_t *anim)

{
  (&comp_state_1_a)[self] = (&comp_state_1_a)[self] | 0x40;
  if (((&comp_state_1_a)[self] & ECS_STATE_1_A_NORMAL) == 0) {
    (&comp_anim[0].frame)[self] = 0;
    *(undefined2 *)((int)&comp_anim_tick + self) = 0;
    (&comp_state_1_a)[self] = (&comp_state_1_a)[self] | ECS_STATE_1_A_NORMAL;
    ecs_set_anim_for_state(self, &anim_base);
    ecs_anim_next_frame(self, anim, &anim_base);
  }
  return;
}

void FUN_00000bfe(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_update(unaff_A4, unaff_A5);
  (&comp_state_1_a)[unaff_A4] = (&comp_state_1_a)[unaff_A4] | 0x40;
  return;
}

void ecs_anim_update(entity_id_t self, anim_item_t *anim)

{
  component_state_b_t extraout_D0b;
  component_state_b_t cVar1;
  ushort ani_tick_new;
  ushort anim_tick_old;

  cVar1 = (&comp_has_func_maybe)[self];
  if (((&comp_state_a)[self] & 4) != 0) {
    FUN_00000e14(self);
    cVar1 = extraout_D0b;
  }
  if ((cVar1 & (COMPONENT_STATE_B_C0 | COMPONENT_STATE_B_ACTIVE)) ==
      COMPONENT_STATE_B_C0) {
    if (((&comp_state_1_a)[self] & 0x40) == 0) {
      if (((&comp_state_1_a)[self] & ECS_STATE_1_A_NORMAL) == 0) {
        *(undefined2 *)((int)&comp_anim_tick + self) = 0;
        (&comp_state_1_a)[self] =
            (&comp_state_1_a)[self] | ECS_STATE_1_A_NORMAL;
        ecs_set_anim_for_state(self, &anim_base);
        ecs_anim_next_frame(self, anim, &anim_base);
      }
      if ((*(short *)((int)&comp_anim_tick + self) != 0) &&
          (anim_tick_old = *(ushort *)((int)&comp_anim_tick + self),
           ani_tick_new =
               anim_tick_old - *(ushort *)((int)&comp_anim_speed + self),
           *(ushort *)((int)&comp_anim_tick + self) = ani_tick_new,
           anim_tick_old < *(ushort *)((int)&comp_anim_speed + self) ||
               ani_tick_new == 0)) {
        // The animation frame has been completed and the next frame needs to be
        // loaded.
        ecs_anim_next_frame(self,
                            *(anim_item_t **)((int)comp_anim_current_p + self),
                            &anim_base);
      }
    }
    (&comp_state_1_a)[self] = (&comp_state_1_a)[self] & 0xbf;
  }
  return;
}

// Called when an animation frame has been completed to set the next one.
// Param 2 can be (comp_anim_frame_related_p + self) aka #ffffa73a
// Param 3 can be #68000

void ecs_anim_next_frame(entity_id_t self, anim_item_t *anim,
                         word *anim_related)

{
  anim_item_t anim_item;

  while (true) {
    anim_item = *anim;
    if (anim_item < ANIM_INVALID_COMMAND_F0)
      break;
    // Valid values are in the [#5, #f] range.
    // Calls anim_command_f5() to anim_command_ff().
    (*(code *)((short)((ushort)(anim_item & ~ANIM_INVALID_COMMAND_F0) << 2) +
               0xc86))();
    anim = anim + 1;
  }
  (&comp_anim[0].frame)[self] = (&comp_anim[0].frame)[self] + 1;
  if (anim_item == ANIM_RESET_TICK) {
    *(undefined2 *)((int)&comp_anim_tick + self) = 0;
  }
  *(char *)((int)&comp_anim_tick + self) =
      anim_item + *(char *)((int)&comp_anim_tick + self);
  *(int *)((int)&comp_anim_frame_p + self) =
      (int)anim_related + (int)(short)*(undefined2 *)(anim + 1);
  *(anim_item_t **)((int)comp_anim_current_p + self) = anim + 3;
  return;
}

// WARNING: Unknown calling convention

void ecs_anim_command_f5(anim_item_t *anim)

{
  anim_item_t aVar1;
  undefined4 extraout_A0;
  int iVar2;

  FUN_00018c8e();
  aVar1 = anim[2];
  if ((aVar1 & 0x10) == ANIM_RESET_TICK) {
    if ((aVar1 & ~ANIM_INVALID_COMMAND_F0) == ANIM_RESET_TICK) {
      DAT_ffff9694 = 0;
      iVar2 = 0;
    } else {
      iVar2 = 4;
    }
  } else if ((aVar1 & ~ANIM_INVALID_COMMAND_F0) == ANIM_RESET_TICK) {
    DAT_ffff969c = 0;
    iVar2 = 8;
  } else {
    iVar2 = 0xc;
  }
  (&DAT_ffff9690)[iVar2] = 0xff;
  *(undefined4 *)(&comp_vdp_gfx_ptr + iVar2) = extraout_A0;
  *(ushort *)(&DAT_ffff9692 + iVar2) = (aVar1 + 0x100) * 0x20;
  (&DAT_ffff9691)[iVar2] = anim[3];
  DAT_ffff968e = DAT_ffff968e + '\x01';
  return;
}

void ecs_anim_command_f6(entity_id_t self, anim_item_t *anim)

{
  (&comp_anim[0].unk1)[self] = *anim;
  *(anim_item_t **)((int)comp_anim_command_f6_arg + self) = anim + 1;
  (&comp_anim[0].unk2)[self] = (&comp_anim[0].frame)[self];
  return;
}

void ecs_anim_command_f7(entity_id_t self)

{
  byte bVar1;

  bVar1 = (&comp_anim[0].unk1)[self] - 1;
  (&comp_anim[0].unk1)[self] = bVar1;
  if (bVar1 != 0) {
    (&comp_anim[0].frame)[self] = (&comp_anim[0].unk2)[self];
  }
  return;
}

// WARNING: Unknown calling convention

void ecs_anim_command_f8(entity_id_t self)

{
  (&comp_state_1_a)[self] = (&comp_state_1_a)[self] | 0x20;
  return;
}

// WARNING: Unknown calling convention

void ecs_anim_command_f9(entity_id_t self)

{
  (&comp_state_1_a)[self] = (&comp_state_1_a)[self] | 0x10;
  return;
}

// WARNING: Unknown calling convention

void ecs_anim_command_fa(entity_id_t self, anim_item_t *anim)

{
  *(short *)((int)&comp_pos_x + self) =
      (short)(char)*anim + *(short *)((int)&comp_pos_x + self);
  *(short *)((int)&comp_pos_y + self) =
      (short)(char)anim[1] + *(short *)((int)&comp_pos_y + self);
  return;
}

// WARNING: Unknown calling convention

void ecs_anim_command_fb(entity_id_t self, anim_item_t *anim)

{
  (&comp_collision[0].set_by_anim_command_fb)[self] = *anim;
  (&comp_collision[0].unk2)[self] = anim[1];
  return;
}

// WARNING: Unknown calling convention

void ecs_anim_command_fc(entity_id_t self, anim_item_t *anim)

{
  if (((char)(&comp_anim[0].unk4)[self] < '\0') &&
      (((&comp_has_func_maybe)[self] & 0x40) != 0)) {
    *(short *)((int)&comp_pos_y + self) =
        *(short *)((int)&comp_pos_y + self) -
        ((ushort)anim[1] - *(short *)((int)&comp_collision_sensor[0].y + self));
  }
  *(ushort *)((int)&comp_collision_sensor[0].x + self) = (ushort)*anim;
  *(ushort *)((int)&comp_collision_sensor[0].y + self) = (ushort)anim[1];
  return;
}

void ecs_anim_command_fd(entity_id_t self, anim_item_t *anim)

{
  *(undefined2 *)((int)&comp_anim_tick + self) = 0;
  *(anim_item_t **)((int)comp_anim_current_p + self) = anim;
  return;
}

// WARNING: Unknown calling convention

void ecs_anim_command_fe(entity_id_t self, anim_item_t *anim)

{
  *(anim_item_t **)((int)comp_anim_start_p + self) = anim;
  return;
}

// WARNING: Unknown calling convention

void ecs_anim_command_ff_loop(entity_id_t self)

{
  (&comp_anim[0].frame)[self] = 0;
  return;
}

void ecs_set_anim_for_state(entity_id_t self, word *anim_base)

{
  anim_item_t *anim;
  int anim_base_offset;

  anim_base_offset =
      (uint)(&comp_anim_b)[self] +
      (uint) * (ushort *)((int)anim_base +
                          (int)(short)(ushort)(&comp_anim_base_offset)[self]);
  anim_base_offset =
      (uint)(&comp_anim_c)[self] +
      CONCAT22((short)((uint)anim_base_offset >> 0x10),
               *(undefined2 *)((int)anim_base + anim_base_offset));
  anim = (anim_item_t *)((int)anim_base +
                         CONCAT22((short)((uint)anim_base_offset >> 0x10),
                                  *(undefined2 *)((int)anim_base +
                                                  anim_base_offset)));
  *(anim_item_t **)((int)comp_anim_start_p + self) = anim;
  *(anim_item_t **)((int)comp_anim_current_p + self) = anim;
  return;
}

void ecs_anim_command_f6(entity_id_t self, anim_item_t *anim)

{
  // Store #f6?
  (&comp_anim[0].unk1)[self] = *anim;
  *(anim_item_t **)((int)comp_anim_command_f6_arg + self) = anim + 1;
  (&comp_anim[0].unk2)[self] = (&comp_anim[0].frame)[self];
  return;
}

void ecs_anim_command_f7(entity_id_t self)

{
  byte i;

  i = (&comp_anim[0].unk1)[self] - 1;
  (&comp_anim[0].unk1)[self] = i;
  if (i != 0) {
    (&comp_anim[0].frame)[self] = (&comp_anim[0].unk2)[self];
  }
  return;
}

// WARNING: Unknown calling convention

void ecs_anim_command_f8(entity_id_t self)

{
  (&comp_state_1_a)[self] = (&comp_state_1_a)[self] | 0x20;
  return;
}

// WARNING: Unknown calling convention

void ecs_anim_command_f9(entity_id_t self)

{
  (&comp_state_1_a)[self] = (&comp_state_1_a)[self] | 0x10;
  return;
}

// WARNING: Unknown calling convention

void ecs_anim_command_fa(entity_id_t self, anim_item_t *anim)

{
  *(short *)((int)&comp_pos_x + self) =
      (short)(char)*anim + *(short *)((int)&comp_pos_x + self);
  *(short *)((int)&comp_pos_y + self) =
      (short)(char)anim[1] + *(short *)((int)&comp_pos_y + self);
  return;
}

// WARNING: Unknown calling convention

void ecs_anim_command_fb(entity_id_t self, anim_item_t *anim)

{
  (&comp_collision[0].set_by_anim_command_fb)[self] = *anim;
  (&comp_collision[0].unk2)[self] = anim[1];
  return;
}

// WARNING: Unknown calling convention

void ecs_anim_command_fc(entity_id_t self, anim_item_t *anim)

{
  if (((char)(&comp_anim[0].unk4)[self] < '\0') &&
      (((&comp_has_func_maybe)[self] & 0x40) != 0)) {
    *(short *)((int)&comp_pos_y + self) =
        *(short *)((int)&comp_pos_y + self) -
        ((ushort)anim[1] - *(short *)((int)&comp_collision_sensor[0].y + self));
  }
  *(ushort *)((int)&comp_collision_sensor[0].x + self) = (ushort)*anim;
  *(ushort *)((int)&comp_collision_sensor[0].y + self) = (ushort)anim[1];
  return;
}

void ecs_anim_command_fd(entity_id_t self, anim_item_t *anim)

{
  *(undefined2 *)((int)&comp_anim_tick + self) = 0;
  *(anim_item_t **)((int)comp_anim_current_p + self) = anim;
  return;
}

// WARNING: Unknown calling convention

void ecs_anim_command_fe(entity_id_t self, anim_item_t *anim)

{
  *(anim_item_t **)((int)comp_anim_start_p + self) = anim;
  return;
}

// WARNING: Unknown calling convention
// FIXME This updates the current animation (sotred in A5), which isn't shown in
// C.

void ecs_anim_command_ff_loop(entity_id_t self)

{
  (&comp_anim[0].frame)[self] = 0;
  return;
}

// WARNING: Unknown calling convention

void ecs_anim_command_f5(anim_item_t *anim)

{
  anim_item_t aVar1;
  undefined4 extraout_A0;
  int iVar2;

  FUN_00018c8e();
  aVar1 = anim[2];
  if ((aVar1 & 0x10) == ANIM_RESET_TICK) {
    if ((aVar1 & ~ANIM_INVALID_COMMAND_F0) == ANIM_RESET_TICK) {
      DAT_ffff9694 = 0;
      iVar2 = 0;
    } else {
      iVar2 = 4;
    }
  } else if ((aVar1 & ~ANIM_INVALID_COMMAND_F0) == ANIM_RESET_TICK) {
    DAT_ffff969c = 0;
    iVar2 = 8;
  } else {
    iVar2 = 0xc;
  }
  (&DAT_ffff9690)[iVar2] = 0xff;
  *(undefined4 *)(&comp_vdp_gfx_ptr + iVar2) = extraout_A0;
  *(ushort *)(&DAT_ffff9692 + iVar2) = (aVar1 + 0x100) * 0x20;
  (&DAT_ffff9691)[iVar2] = anim[3];
  DAT_ffff968e = DAT_ffff968e + '\x01';
  return;
}

void FUN_00000e14(ulong ctx)

{
  char cVar1;
  byte bVar2;

  if ((&DAT_ffffab43)[ctx] != '\0') {
    cVar1 = (&DAT_ffffab43)[ctx] + -1;
    (&DAT_ffffab43)[ctx] = cVar1;
    if (cVar1 != '\0') {
      return;
    }
    if (((&comp_has_func_maybe)[ctx] & 8) == 0) {
      bVar2 = (&DAT_ffffab42)[ctx] & 0xf;
      (&comp_has_func_maybe)[ctx] = (&comp_has_func_maybe)[ctx] | 8;
      goto LAB_00000e44;
    }
  }
  bVar2 = (byte)(&DAT_ffffab42)[ctx] >> 4;
  (&comp_has_func_maybe)[ctx] = (&comp_has_func_maybe)[ctx] & 0xf7;
LAB_00000e44:
  (&DAT_ffffab43)[ctx] = *(undefined1 *)((short)(ushort)bVar2 + 0xe4c);
  return;
}

void FUN_00000e5c(entity_id_t self)

{
  *(undefined2 *)((int)&comp_anim_tick + self) = 0;
  ecs_anim_next_frame(
      self, *(anim_item_t **)((int)comp_anim_current_p + self), &anim_base);
  return;
}

void player_update_pos_x(ulong ctx)

{
  *(int *)((int)&comp_pos_x + ctx) =
      *(short *)((int)&comp_vel[0].x + ctx) * 0x100 +
      *(int *)((int)&comp_pos_x + ctx);
  return;
}

void ecs_update_pos_y(entity_id_t self)

{
  *(int *)((int)&comp_pos_y + self) =
      *(short *)((int)&comp_vel[0].y + self) * 0x100 +
      *(int *)((int)&comp_pos_y + self);
  return;
}

void player_update_pos(ulong ctx)

{
  *(int *)((int)&comp_pos_x + ctx) =
      *(short *)((int)&comp_vel[0].x + ctx) * 0x100 +
      *(int *)((int)&comp_pos_x + ctx);
  *(int *)((int)&comp_pos_y + ctx) =
      *(short *)((int)&comp_vel[0].y + ctx) * 0x100 +
      *(int *)((int)&comp_pos_y + ctx);
  return;
}

bool FUN_00000eae(entity_id_t self)

{
  bool bVar1;

  bVar1 = *(ushort *)((int)&comp_pos_x + self) < DAT_ffffc73a;
  if ((!bVar1) && (bVar1 = (ushort)(DAT_ffffc73a + 0x100) <
                           *(ushort *)((int)&comp_pos_x + self),
                   !bVar1)) {
    bVar1 = *(ushort *)((int)&comp_pos_y + self) < DAT_ffffc746;
    if (!bVar1) {
      bVar1 =
          (ushort)(DAT_ffffc746 + 0x100) < *(ushort *)((int)&comp_pos_y + self);
    }
  }
  return bVar1;
}

undefined6 FUN_00000ed6(entity_id_t self, entity_id_t other)

{
  byte bVar1;
  ushort delta_pos_x_abs;

  delta_pos_x_abs = *(ushort *)((int)&comp_pos_x + other) -
                    *(ushort *)((int)&comp_pos_x + self);
  if (*(ushort *)((int)&comp_pos_x + other) <
      *(ushort *)((int)&comp_pos_x + self)) {
    delta_pos_x_abs = -delta_pos_x_abs;
  }
  bVar1 = (&comp_collision[0].set_by_anim_command_fb)[self] +
          (&comp_collision[0].set_by_anim_command_fb)[other];
  if (delta_pos_x_abs <= bVar1) {
    delta_pos_x_abs = *(ushort *)((int)&comp_pos_y + other) -
                      *(ushort *)((int)&comp_pos_y + self);
    if (*(ushort *)((int)&comp_pos_y + other) <
        *(ushort *)((int)&comp_pos_y + self)) {
      delta_pos_x_abs = -delta_pos_x_abs;
    }
    bVar1 = (&comp_collision[0].unk2)[self] + (&comp_collision[0].unk2)[other];
  }
  return CONCAT24(delta_pos_x_abs, (uint)bVar1);
}

undefined4 ecs_check_collides_x(int entity, int other_entity)

{
  ushort pos_x_int_delta_abs;
  ushort collision_sensor_x_diff;

  pos_x_int_delta_abs = *(ushort *)((int)&comp_pos_x + other_entity) -
                        *(ushort *)((int)&comp_pos_x + entity);
  if (*(ushort *)((int)&comp_pos_x + other_entity) <
      *(ushort *)((int)&comp_pos_x + entity)) {
    pos_x_int_delta_abs = -pos_x_int_delta_abs;
  }
  collision_sensor_x_diff =
      *(short *)((int)&comp_collision_sensor[0].x + entity) +
      *(short *)((int)&comp_collision_sensor[0].x + other_entity);
  if (pos_x_int_delta_abs <= collision_sensor_x_diff) {
    pos_x_int_delta_abs = *(ushort *)((int)&comp_pos_y + other_entity) -
                          *(ushort *)((int)&comp_pos_y + entity);
    if (*(ushort *)((int)&comp_pos_y + other_entity) <
        *(ushort *)((int)&comp_pos_y + entity)) {
      pos_x_int_delta_abs = -pos_x_int_delta_abs;
    }
    collision_sensor_x_diff =
        *(short *)((int)&comp_collision_sensor[0].y + entity) +
        *(short *)((int)&comp_collision_sensor[0].y + other_entity);
  }
  return CONCAT22(pos_x_int_delta_abs, collision_sensor_x_diff);
}

void FUN_00000f3a(void)

{
  return;
}

int FUN_0000107a(void)

{
  short sVar1;
  int iVar2;

  iVar2 = 8;
  sVar1 = 10;
  do {
    if (-1 < (char)(&comp_has_func_maybe)[iVar2]) {
      return iVar2;
    }
    iVar2 = iVar2 + 4;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return 0xffff;
}

int FUN_0000109c(void)

{
  short sVar1;
  int iVar2;

  iVar2 = 8;
  sVar1 = 10;
  while (((char)(&comp_has_func_maybe)[iVar2] < '\0' ||
          ((&component_state_b_pepelogoo)[iVar2] != '\0'))) {
    iVar2 = iVar2 + 4;
    sVar1 = sVar1 + -1;
    if (sVar1 == -1) {
      return 0xffff;
    }
  }
  return iVar2;
}

entity_id_t ecs_find_some_entity_with_func(void)

{
  short i;
  entity_id_t self;

  self = 0x34;
  i = 0x13;
  do {
    if (-1 < (char)(&comp_has_func_maybe)[self]) {
      return self;
    }
    self = self + ENTITY_ID_PEPELOGOO;
    i = i + -1;
  } while (i != -1);
  return 0xffff;
}

int FUN_000010e6(void)

{
  short sVar1;
  int iVar2;

  iVar2 = 0xcc;
  sVar1 = 2;
  do {
    if (-1 < (char)(&comp_has_func_maybe)[iVar2]) {
      return iVar2;
    }
    iVar2 = iVar2 + 4;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return 0xffff;
}

void ecs_anim_unk_2(entity_id_t self, anim_item_t *anim, byte state_1_b)

{
  if (self == ENTITY_ID_PEPELOGOO) {
    BYTE_ffffc709 = 0;
  }
  if (self == ENTITY_ID_ASHA) {
    BYTE_ffffc70a = 0;
  }
  (&comp_state_1_a)[self] = 0;
  (&comp_anim_c)[self] = state_1_b;
  ecs_anim_unk_1(self, anim);
  (&comp_has_func_maybe)[self] =
      (&comp_has_func_maybe)[self] | COMPONENT_STATE_B_C0;
  return;
}

void entity_reset(entity_id_t e)

{
  (&comp_has_func_maybe)[e] = 0;
  (&comp_state_a)[e] = 0;
  *(undefined2 *)((int)&comp_unk_3 + e) = 0;
  *(undefined2 *)((int)&comp_unk_4 + e) = 0;
  (&component_collision_flags)[e] = 0;
  (&component_unknown_5)[e] = 0;
  (&component_unknown_6)[e] = 0;
  (&comp_state_1_a)[e] = 0;
  *(undefined2 *)((int)&comp_unk_7 + e) = 0;
  *(undefined2 *)((int)&comp_vel[0].x + e) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + e) = 0;
  *(undefined2 *)((int)&comp_collision_sensor[0].x + e) = 0;
  *(undefined2 *)((int)&comp_collision_sensor[0].y + e) = 0;
  *(undefined2 *)((int)&comp_unk_8 + e) = 0;
  *(undefined2 *)((int)&component_unknown_9 + e) = 0;
  *(undefined2 *)((int)&comp_pos_x + e + 2) = 0;
  *(undefined2 *)((int)&comp_pos_y + e + 2) = 0;
  (&comp_anim[0].unk4)[e] = 0;
  *(undefined2 *)((int)&comp_anim_speed + e) = 0x100;
  (&component_unknown_12)[e] = 0;
  return;
}

char FUN_00001184(void)

{
  char cVar1;
  ushort uVar2;
  ushort uVar3;
  int unaff_A4;

  uVar2 = *(ushort *)((int)&comp_vel[0].x + unaff_A4);
  uVar3 = *(ushort *)((int)&comp_vel[0].y + unaff_A4);
  if (uVar3 == 0) {
    if ((short)uVar2 < 0) {
      cVar1 = -0x80;
    } else {
      cVar1 = '\0';
    }
  } else {
    if (uVar2 != 0) {
      if ((short)uVar2 < 0) {
        uVar2 = -uVar2;
      }
      if ((short)uVar3 < 0) {
        uVar3 = -uVar3;
      }
      if (uVar2 < uVar3) {
        cVar1 = FUN_00001230();
        if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
          if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
            cVar1 = -0x40 - cVar1;
          } else {
            cVar1 = cVar1 + '@';
          }
        } else if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
          cVar1 = cVar1 + -0x40;
        } else {
          cVar1 = '@' - cVar1;
        }
        return cVar1;
      }
      cVar1 = FUN_00001230();
      if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
        if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
          cVar1 = cVar1 + -0x80;
        } else {
          cVar1 = -cVar1;
        }
      } else if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
        cVar1 = -0x80 - cVar1;
      }
      return cVar1;
    }
    if ((short)uVar3 < 0) {
      cVar1 = -0x40;
    } else {
      cVar1 = '@';
    }
  }
  return cVar1;
}

undefined2 FUN_000011ae(void)

{
  return 0x80;
}

undefined2 FUN_000011b4(void)

{
  undefined2 uVar1;
  short unaff_D2w;

  if (unaff_D2w < 0) {
    uVar1 = 0xffc0;
  } else {
    uVar1 = 0x40;
  }
  return uVar1;
}

char FUN_000011c4(void)

{
  char cVar1;
  int unaff_A4;

  cVar1 = FUN_00001230();
  if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
    if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
      cVar1 = cVar1 + -0x80;
    } else {
      cVar1 = -cVar1;
    }
  } else if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
    cVar1 = -0x80 - cVar1;
  }
  return cVar1;
}

char FUN_000011f6(void)

{
  char cVar1;
  int unaff_A4;

  cVar1 = FUN_00001230();
  if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
    if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
      cVar1 = -0x40 - cVar1;
    } else {
      cVar1 = cVar1 + '@';
    }
  } else if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
    cVar1 = cVar1 + -0x40;
  } else {
    cVar1 = '@' - cVar1;
  }
  return cVar1;
}

char FUN_0000121c(void)

{
  char in_D0b;
  char cVar1;
  int unaff_A4;

  if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
    cVar1 = -0x40 - in_D0b;
  } else {
    cVar1 = in_D0b + '@';
  }
  return cVar1;
}

ushort FUN_00001230(void)

{
  ushort uVar1;
  ushort in_D1w;
  ushort uVar2;

  uVar2 = 0x10;
  uVar1 = 0x20;
  do {
    while (true) {
      if (in_D1w == *(ushort *)((int)WORD_ARRAY_00001266 + (int)(short)uVar1))
        goto LAB_00001262;
      if (*(ushort *)((int)WORD_ARRAY_00001266 + (int)(short)uVar1) <= in_D1w)
        break;
      if (*(ushort *)((short)uVar1 + 0x1264) < in_D1w)
        goto LAB_00001262;
      uVar1 = uVar1 - uVar2;
      uVar2 = uVar2 >> 1;
      if (uVar2 == 0)
        goto LAB_00001262;
    }
    if (in_D1w < *(ushort *)((int)WORD_ARRAY_00001266 + (short)uVar1 + 2))
      break;
    uVar1 = uVar2 + uVar1;
    uVar2 = uVar2 >> 1;
  } while (uVar2 != 0);
LAB_00001262:
  return uVar1 >> 1;
}

ushort FUN_000012a8(void)

{
  ushort in_D0w;
  ushort in_D1w;
  ushort uVar1;
  ushort uVar2;
  ushort uVar3;

  uVar3 = in_D1w;
  if (in_D0w != 0) {
    if (in_D0w == 0x40) {
      uVar3 = 0;
    } else if (in_D0w == 0x80) {
      uVar3 = -in_D1w;
    } else {
      uVar1 = in_D0w;
      if (in_D0w == 0xc0) {
        uVar3 = 0;
      } else {
        for (; 0x3f < uVar1; uVar1 = uVar1 - 0x40) {
        }
        uVar2 = (ushort)((uint) *
                             (ushort *)((int)WORD_ARRAY_00001334 +
                                        (int)(short)((0x40 - uVar1) * 2)) *
                             (uint)in_D1w >>
                         0x10);
        uVar3 = uVar2;
        if (0x3f < in_D0w) {
          uVar3 = (ushort)((uint) *
                               (ushort *)((int)WORD_ARRAY_00001334 +
                                          (int)(short)(uVar1 * 2)) *
                               (uint)in_D1w >>
                           0x10);
          if (in_D0w < 0x80) {
            uVar3 = -uVar3;
          } else if (in_D0w < 0xc0) {
            uVar3 = -uVar2;
          }
        }
      }
    }
  }
  return uVar3;
}

bool ecs_get_cannot_jump(entity_id_t self)

{
  bool in_air;

  in_air = ((&component_collision_flags)[self] & 4) == 0;
  if (in_air) {
    in_air = ((&component_unknown_5)[self] & 4) == 0;
  }
  return in_air;
}

void game_lock_entities(void)

{
  component_state_b_t cVar1;
  short sVar2;
  int iVar3;

  // This takes 64 bytes each with a 4 bytes offset, and copies their 2nd bit
  // into their 1st one.
  //
  // It seems to put all objects in their "frozen" mode.
  iVar3 = 0;
  sVar2 = 0x3f;
  do {
    cVar1 = (&comp_has_func_maybe)[iVar3];
    (&comp_has_func_maybe)[iVar3] = (&comp_has_func_maybe)[iVar3] & 0xfc;
    (&comp_has_func_maybe)[iVar3] =
        (cVar1 & COMPONENT_STATE_B_ACTIVE) * '\x02' | COMPONENT_STATE_B_ACTIVE |
        (&comp_has_func_maybe)[iVar3];
    iVar3 = iVar3 + 4;
    sVar2 = sVar2 + -1;
  } while (sVar2 != -1);
  return;
}

void game_unlock_entities(void)

{
  component_state_b_t cVar1;
  short sVar2;
  int iVar3;

  // This takes 64 bytes each with a 4 bytes offset, copies their 1st bit into
  // their 2nd one, and sets their 1st bit to 1.
  //
  // It seems to move all objects out of their "frozen" mode.
  iVar3 = 0;
  sVar2 = 0x3f;
  do {
    cVar1 = (&comp_has_func_maybe)[iVar3];
    (&comp_has_func_maybe)[iVar3] = (&comp_has_func_maybe)[iVar3] & 0xfc;
    (&comp_has_func_maybe)[iVar3] =
        (cVar1 & 2) >> 1 | (&comp_has_func_maybe)[iVar3];
    iVar3 = iVar3 + 4;
    sVar2 = sVar2 + -1;
  } while (sVar2 != -1);
  return;
}

void FUN_0000140c(void)

{
  short sVar1;
  int iVar2;

  sVar1 = 0x3f;
  iVar2 = 0;
  do {
    (&comp_has_func_maybe)[iVar2] = 0;
    iVar2 = iVar2 + 4;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return;
}

void text_unk_1(void *param_1, void *param_2)

{
  byte bVar1;
  short i;
  ushort j;
  short sVar2;
  byte *pbVar3;
  byte *pbVar4;

  while (true) {
    while (true) {
      while (true) {
        while (true) {
          // WARNING: Load size is inaccurate
          pbVar3 = (byte *)((int)param_1 + 1);
          bVar1 = *param_1;
          if ((char)bVar1 < '\0')
            break;
          pbVar4 = (byte *)((int)param_2 + 1);
          *(byte *)param_2 = bVar1;
          param_2 = (void *)((int)param_2 + 2);
          *pbVar4 = *pbVar3;
          param_1 = (byte *)((int)param_1 + 2);
        }
        if (0xbf < bVar1)
          break;
        param_2 = (void *)((int)compressed_data_indices +
                           (int)(short)((bVar1 & 0x3f) * 2));
        param_1 = pbVar3;
      }
      if (bVar1 != 0xc0)
        break;
      param_2 = (void *)((int)param_2 + 2);
      param_1 = pbVar3;
    }
    if (bVar1 == 0xff)
      break;
    if (bVar1 < 0xf8) {
      i = (bVar1 & 0x3f) - 1;
      param_1 = (void *)((int)param_1 + 3);
      sVar2 = *(short *)pbVar3;
      pbVar3 = (byte *)param_2;
      do {
        param_2 = pbVar3 + 2;
        *(short *)pbVar3 = sVar2;
        sVar2 = sVar2 + 1;
        i = i + -1;
        pbVar3 = (byte *)param_2;
      } while (i != -1);
    } else {
      j = bVar1 & 7;
      pbVar4 = (byte *)param_2;
      do {
        pbVar4[0x80] = 0xff;
        pbVar4[0x81] = 0xfe;
        param_2 = pbVar4 + 2;
        pbVar4[0] = 0xff;
        pbVar4[1] = 0xfe;
        j = j - 1;
        param_1 = pbVar3;
        pbVar4 = (byte *)param_2;
      } while (j != 0xffff);
    }
  }
  return;
}

void FUN_0000147a(func *f, short param_2, ushort param_3)

{
  short i;
  uint uVar1;
  short sVar2;
  entity_id_t self;

  self = 0x84;
  i = 0x11;
  uVar1 = 0;
  sVar2 = 0x84;
  do {
    if (-1 < (char)(&comp_has_func_maybe)[self])
      goto LAB_000014b0;
    if (uVar1 <= *(uint *)(&comp_unk_2 + self)) {
      uVar1 = *(uint *)(&comp_unk_2 + self);
      sVar2 = (short)self;
    }
    self = self + ENTITY_ID_PEPELOGOO;
    i = i + -1;
  } while (i != -1);
  if ((ushort)(uVar1 >> 0x10) < param_3) {
    return;
  }
  self = (entity_id_t)sVar2;
LAB_000014b0:
  *(short *)(&comp_unk_1 + self) = param_2;
  *(ushort *)(&comp_unk_2 + self) = param_3;
  *(undefined2 *)(&comp_unk_5 + self) = 0;
  if (param_2 == 1) {
    *(func **)((int)&comp_some_function + self) = f;
  }
  return;
}

// This loads a sized string to the VDP data port.
//
// It does so by adding #780 to the characters to set the corresponding glyph.

void vdp_load_sized_string(sized_string_t *string)

{
  uint16_t i;
  char *c;

  i = string->length;
  c = string->string;
  do {
    VDP_DATA = (byte)*c + 0x780;
    i = i - 1;
    c = c + 1;
  } while (i != 0xffff);
  return;
}

// Set the VDP to read the VRAM at the given address.
// Cf. https://wiki.megadrive.org/index.php?title=VDP_Ports

void vdp_set_vram_write_addr(void *vram_dst)

{
  VDP_CTRL = (union2_t)((ushort)vram_dst & 0x3fff | 0x4000);
  VDP_CTRL = (union2_t)((ushort)vram_dst >> 0xe);
  return;
}

void FUN_00001502(void)

{
  ushort unaff_D2w;

  VDP_CTRL = (union2_t)(unaff_D2w & 0x3fff);
  VDP_CTRL = (union2_t)(unaff_D2w >> 0xe);
  return;
}

void FUN_0000151e(void)

{
  VDP_CTRL = 0x4000;
  VDP_CTRL = 0x10;
  return;
}

void FUN_00001530(void)

{
  short in_D0w;
  undefined1 in_D1b;

  *(undefined1 *)(in_D0w + -0x34e4) = in_D1b;
  return;
}

undefined1 FUN_0000153a(void)

{
  short in_D0w;

  return *(undefined1 *)(in_D0w + -0x34e4);
}

void FUN_00001544(void)

{
  char cVar1;
  short sVar2;
  char *pcVar3;

  pcVar3 = (char *)&DAT_ffffcb26;
  cVar1 = '\x12';
  sVar2 = 9;
  do {
    pcVar3 = pcVar3 + -1;
    *pcVar3 = cVar1;
    cVar1 = cVar1 + -2;
    sVar2 = sVar2 + -1;
  } while (sVar2 != -1);
  return;
}

word rand(void)

{
  ushort uVar1;
  uint uVar2;

  // Sets the initial seed.
  if (DAT_ffffcb26 == 0) {
    DAT_ffffcb26 = 0x2a6d365a;
  }
  uVar2 = DAT_ffffcb26 * 0x29;
  uVar1 = (short)(uVar2 >> 0x10) + (short)uVar2;
  DAT_ffffcb26 = (uint)uVar1 << 0x10 | uVar2 & 0xffff;
  return uVar1;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00001580(void)

{
  ushort uVar1;
  ushort extraout_D0u;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  palette_effect_t *in_A1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar2;

  DAT_ffffc782 = 0;
  DAT_ffffc784 = 0;
  _DAT_ffffc786 = 0;
  _DAT_ffffc788 = 0;
  DAT_ffff91c6 = 0;
  DAT_ffffc716 = 0;
  DAT_ffffc71a = 0;
  VDP_CTRL = 0x8b00;
  palette_set_effect(~PALETTE_ID_FLAG_NONE, false, in_A1);
  uVar1 = DAT_ffff91ce;
  DAT_ffff91ce = DAT_ffff91ce & 0xff;
  uVar2 = FUN_00001646();
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar2 >> 0x20),
                  (long)uVar2,
                  -1,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  DAT_ffff91ce = CONCAT11(0xff, (char)uVar1);
  DAT_ffff96ba = 0;
  VDP_CTRL = 0x856f;
  VDP_CTRL = 0x8c00;
  FUN_0000ba1a();
  clear_unk_1();
  vdp_write_something_to_vram();
  palette_set_fade(0xffff000f,
                   (uint)extraout_D0u << 0x10,
                   '\0',
                   (palette_color_iter_t)0xffffffff);
  FUN_0000140c();
  vdp_set_window_position(0);
  DAT_ffff9690 = 0;
  DAT_ffff9694 = 0;
  DAT_ffff9698 = 0;
  DAT_ffff969c = 0;
  DAT_ffff91ce = uVar1;
  return;
}

void FUN_00001630(void)

{
  long in_D0;
  long in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;

  if (((undefined1)vdp_ctrl_mode_set_2_state & 0x40) == 0) {
    related_to_palette_maybe_2 = 0xff;
    related_to_palette_maybe_1 = 0;
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    in_D0,
                    in_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  return;
}

void FUN_00001646(void)

{
  long in_D0;
  long in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;

  if (((undefined1)vdp_ctrl_mode_set_2_state & 0x40) != 0) {
    related_to_palette_maybe_1 = 0xff;
    related_to_palette_maybe_2 = 0;
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    in_D0,
                    in_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  return;
}

void FUN_0000165c(ushort *param_1, byte *param_2, entity_id_w_t other,
                  short pos_x, short pos_y, byte param_6)

{
  entity_id_t self;

  FUN_0000147a(FUN_000016a6, 1, *param_1);
  if (-1 < (short)other) {
    self = (entity_id_t)(short)other;
    entity_reset(self);
    (&comp_state_a)[self] = param_6 | (&comp_state_a)[self];
    *(short *)((int)&comp_pos_x + self) = pos_x;
    *(short *)((int)&comp_pos_y + self) = pos_y;
    *(ushort *)((int)&comp_unk_3 + self) = (ushort) * (byte *)(param_1 + 1);
    (&comp_anim_base_offset)[self] = *(byte *)((int)param_1 + 3);
    (&comp_anim_b)[self] = *(byte *)(param_1 + 2);
    ecs_anim_unk_2(self, param_2, *(byte *)((int)param_1 + 5));
  }
  return;
}

void FUN_000016a6(void)

{
  int unaff_A4;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

void FUN_000016b2(void)

{
  byte state_1_b;
  short unaff_D2w;
  undefined2 unaff_D3w;
  undefined2 unaff_D4w;
  entity_state_a_t unaff_D5b;
  undefined4 unaff_D6;
  ushort *unaff_A2;
  entity_id_t e;
  anim_item_t *unaff_A5;

  FUN_0000147a(FUN_00001706, 1, *unaff_A2);
  if (-1 < unaff_D2w) {
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    (&comp_state_a)[e] = unaff_D5b | (&comp_state_a)[e];
    *(undefined2 *)((int)&comp_pos_x + e) = unaff_D3w;
    *(undefined2 *)((int)&comp_pos_y + e) = unaff_D4w;
    *(ushort *)((int)&comp_unk_3 + e) = (ushort) * (byte *)(unaff_A2 + 1);
    (&comp_anim_base_offset)[e] = *(byte *)((int)unaff_A2 + 3);
    (&comp_anim_b)[e] = *(byte *)(unaff_A2 + 2);
    state_1_b = *(byte *)((int)unaff_A2 + 5);
    *(short *)((int)&comp_vel[0].y + e) = (short)unaff_D6;
    *(short *)((int)&comp_vel[0].x + e) = (short)((uint)unaff_D6 >> 0x10);
    ecs_anim_unk_2(e, unaff_A5, state_1_b);
  }
  return;
}

void FUN_00001706(void)

{
  ulong unaff_A4;

  player_update_pos(unaff_A4);
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

ushort FUN_00001770(void)

{
  ushort uVar1;

  uVar1 = 0;
  if ((ecs_holding_a_rope & 0x80) != 0) {
    uVar1 = 0x10;
  }
  if ((pepelogoo_state_b & 0x80) != 0) {
    uVar1 = uVar1 | 4;
  }
  if ((0xb < comp_state) && (comp_state < 0x19)) {
    uVar1 = uVar1 | 2;
  }
  if ((pepelogoo_state_b & 0x20) != 0) {
    uVar1 = uVar1 | 0x20;
  }
  if ((uVar1 == 0) && (((component_collision_flags & 4) != 0 ||
                        ((component_unknown_5 & 4) != 0)))) {
    uVar1 = 1;
  }
  if (comp_state == (COMP_STATE_ROPE_JUMP | COMP_STATE_ROPE_HOLD)) {
    uVar1 = uVar1 | 0x40;
  }
  if (DAT_ffffd2eb != '\0') {
    uVar1 = uVar1 & 0xfffe;
  }
  return uVar1;
}

void FUN_000017da(ulong ctx, byte *param_2, short new_ctx)

{
  FUN_0000165c((ushort *)FUN_00001800,
               param_2,
               new_ctx,
               *(short *)((int)&comp_pos_x + ctx),
               DAT_ffffcbf6,
               0x80);
  audio_play(SOUND_ID_SPLASH);
  return;
}

void FUN_00001800(void)

{
  entity_id_w_t unaff_D2w;
  int unaff_A4;
  byte *unaff_A5;

  FUN_0000165c(WORD_ARRAY_0000182c,
               unaff_A5,
               unaff_D2w,
               *(short *)((int)&comp_pos_x + unaff_A4),
               *(short *)((int)&comp_pos_y + unaff_A4),
               0x80);
  audio_play(SOUND_ID_SPLASH);
  return;
}

void FUN_00001832(void)

{
  entity_id_w_t unaff_D2w;
  int unaff_A4;
  byte *unaff_A5;

  FUN_0000165c(WORD_ARRAY_00001858,
               unaff_A5,
               unaff_D2w,
               *(short *)((int)&comp_pos_x + unaff_A4),
               *(short *)((int)&comp_pos_y + unaff_A4),
               0);
  audio_play(SOUND_ID_SPLASH);
  return;
}

void FUN_0000185e(void)

{
  entity_id_w_t unaff_D2w;
  int unaff_A4;
  byte *unaff_A5;

  FUN_0000165c((ushort *)&LAB_0000187a,
               unaff_A5,
               unaff_D2w,
               *(short *)((int)&comp_pos_x + unaff_A4),
               *(short *)((int)&comp_pos_y + unaff_A4),
               0x80);
  return;
}

void FUN_00001880(void)

{
  entity_id_w_t unaff_D2w;
  short unaff_D3w;
  short unaff_D4w;
  byte *unaff_A5;

  FUN_0000165c(
      (ushort *)&LAB_00001892, unaff_A5, unaff_D2w, unaff_D3w, unaff_D4w, 0x80);
  return;
}

void FUN_00001896(void)

{
  entity_id_w_t unaff_D2w;
  short unaff_D3w;
  short unaff_D4w;
  byte *unaff_A5;

  FUN_0000165c(
      (ushort *)&LAB_000018ac, unaff_A5, unaff_D2w, unaff_D3w, unaff_D4w, 0x80);
  return;
}

void FUN_000018b2(byte *param_1, entity_id_w_t other, short pos_x, short pos_y)

{
  audio_play(SOUND_ID_CRITIC);
  FUN_0000165c(WORD_ARRAY_000018cc, param_1, other, pos_x, pos_y, 0x80);
  return;
}

void FUN_000018d2(void)

{
  entity_id_w_t unaff_D2w;
  int unaff_A4;
  byte *unaff_A5;

  FUN_0000165c(WORD_ARRAY_000018ea,
               unaff_A5,
               unaff_D2w,
               *(short *)((int)&comp_pos_x + unaff_A4),
               *(short *)((int)&comp_pos_y + unaff_A4),
               0x80);
  return;
}

// WARNING: Unknown calling convention -- yet parameter storage is locked

void audio_pause(void)

{
  AUDIO_PAUSE_COUNT = AUDIO_PAUSE_COUNT + 1;
  audio_play(SOUND_ID_PAUSE);
  return;
}

// WARNING: Unknown calling convention

void audio_resume(void)

{
  AUDIO_PAUSE_COUNT = AUDIO_PAUSE_COUNT - 1;
  if ((AUDIO_PAUSE_COUNT == 0) || ((short)AUDIO_PAUSE_COUNT < 0)) {
    audio_play(SOUND_ID_RESUME);
  }
  return;
}

void audio_play_sound_asha_dies(void)

{
  AUDIO_PAUSE_COUNT = 0;
  UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
  audio_play(SOUND_ID_F9);
  return;
}

void FUN_0000192a(sound_id_word_t sound_id)

{
  sound_id_word_t sound_id3;

  if (sound_id !=
      (sound_id_word_t)UNION_sound_id_word_union_t_ffff97e6.as_word) {
    UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
    audio_stop_all();
    UNION_sound_id_word_union_t_ffff97e6 = (sound_id_word_union_t)sound_id;
    audio_play(sound_id.as_word);
  }
  return;
}

undefined4 FUN_00001948(void)

{
  int unaff_A4;

  if (((((ushort)(comp_pos_x.fixed.i - 0xa0U) <=
         *(ushort *)((int)&comp_pos_x + unaff_A4)) &&
        (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
         (ushort)(comp_pos_x.fixed.i + 0xa0U))) &&
       ((ushort)(comp_pos_y.fixed.i - 0x80U) <=
        *(ushort *)((int)&comp_pos_y + unaff_A4))) &&
      (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
       (ushort)(comp_pos_y.fixed.i + 0x80U))) {
    return 0;
  }
  return 0xffffffff;
}

void FUN_00001980(void)

{
  DAT_ffffcc85 = 0xff;
  DAT_ffffcc86 = 0;
  pepelogoo_state_b = pepelogoo_state_b & 0x7f;
  return;
}

void FUN_00001990(void)

{
  DAT_ffffcc85 = 0xff;
  DAT_ffffcc86 = 1;
  return;
}

void FUN_0000199c(void)

{
  DAT_ffffcc85 = 0xff;
  DAT_ffffcc86 = 2;
  pepelogoo_state_b = pepelogoo_state_b & 0x7f;
  return;
}

void FUN_000019ae(void)

{
  short sVar1;
  undefined2 *puVar2;
  int unaff_A4;

  *(undefined2 *)(&DAT_ffffbc76 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  *(undefined2 *)(&DAT_ffffbc78 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  sVar1 = (ushort)(&comp_func_offset[0].unk1)[unaff_A4] << 3;
  (&comp_func_offset[0].func_offset_from_15ede)[unaff_A4] =
      (&DAT_0007d63c)[sVar1];
  (&comp_func_offset[0].unk3)[unaff_A4] = (&DAT_0007d63d)[sVar1];
  *(undefined2 *)(&comp_anim_base_offset + unaff_A4) =
      *(undefined2 *)(&DAT_0007d63e + sVar1);
  if (((&DAT_0007d640)[sVar1] & 4) != 0) {
    (&comp_anim[0].unk4)[unaff_A4] = (&comp_anim[0].unk4)[unaff_A4] | 0x80;
  }
  *(undefined2 *)((int)&comp_unk_7 + unaff_A4) = 0;
  if (*(short *)(&DAT_0007d642 + sVar1) != 0) {
    puVar2 = (undefined2 *)&DAT_ffffd126;
    sVar1 = DAT_ffffcf9a;
    while ((&comp_func_offset[0].unk1)[unaff_A4] != *(byte *)(puVar2 + 1)) {
      puVar2 = puVar2 + 2;
      sVar1 = sVar1 + -1;
      if (sVar1 == 0) {
        do {
          // WARNING: Do nothing block with infinite loop
        } while (true);
      }
    }
    *(undefined2 *)((int)&comp_unk_7 + unaff_A4) = *puVar2;
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x20;
  }
  return;
}

longlong FUN_00001a22(void)

{
  char *pcVar1;
  short sVar2;
  ushort uVar3;
  ushort uVar4;
  short sVar5;
  uint uVar6;
  uint uVar7;
  int unaff_A3;
  entity_id_t eVar8;

  uVar6 = 0x34;
  uVar3 = (ushort)(byte)(&DAT_0007d641)[(
      short)((ushort)(byte)(&DAT_ffffd05c)[unaff_A3] << 3)];
  sVar2 = 0x13 - uVar3;
  if (-1 < sVar2) {
    do {
      if (-1 < (char)(&comp_has_func_maybe)[uVar6]) {
        sVar2 = (short)uVar6;
        uVar4 = uVar3;
        uVar7 = uVar6;
        do {
          uVar4 = uVar4 - 1;
          if ((short)uVar4 < 0) {
            eVar8 = (entity_id_t)sVar2;
            (&comp_has_func_maybe)[eVar8] = 0x80;
            (&comp_unk_10)[eVar8] = 0;
            sVar5 = sVar2 + 4;
            *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + eVar8) =
                sVar5;
            *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + eVar8) =
                sVar2;
            while (uVar3 = uVar3 - 1, -1 < (short)uVar3) {
              sVar5 = sVar5 + 4;
              entity_reset(eVar8 + ENTITY_ID_PEPELOGOO);
              (&component_state_b_pepelogoo)[eVar8] = 0x80;
              *(undefined1 *)(eVar8 - 0x4887) = 0xff;
              *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[1].unk2 + eVar8) =
                  sVar5;
              *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[1].unk1 + eVar8) =
                  sVar2;
              eVar8 = eVar8 + ENTITY_ID_PEPELOGOO;
            }
            *(ushort *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + eVar8) =
                uVar3;
            return (ulonglong)(uVar6 & 0xffff) << 0x20;
          }
          pcVar1 = &component_state_b_pepelogoo + uVar7;
          uVar7 = uVar7 + 4;
        } while (-1 < *pcVar1);
        uVar6 = (uint)sVar2;
      }
      uVar6 = uVar6 + 4;
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
  }
  return CONCAT44(0xffffffff,
                  (uint)(byte)(&DAT_0007d641)[(
                      short)((ushort)(byte)(&DAT_ffffd05c)[unaff_A3] << 3)]);
}

// Initializes the Z80 by copying the content of #38000 into the Z80's RAM.

undefined8 init_z80(long param_1, long param_2)

{
  undefined2 uVar1;
  long length;
  short i;
  byte *src;
  byte *pbVar2;
  undefined8 uVar3;
  byte is_bus_busy;

  IO_Z80BUS = IO_Z80BUS_LOCK;
  uVar3 = context_swap(param_1, param_2);
  do {
    is_bus_busy = IO_Z80BUS._0_1_;
  } while ((is_bus_busy & 1) != 0);
  uVar1 = (undefined2)((ulonglong)uVar3 >> 0x30);
  // The length is a little endian 16-bits number (the Z80 is little endian). It
  // reads #1809.
  length = CONCAT22(
      uVar1, (short)CONCAT31((int3)(CONCAT22(uVar1, 0x1800) >> 8), 9) + -1);
  src = z80_program;
  pbVar2 = &z80_ram;
  do {
    src = src + 1;
    *pbVar2 = *src;
    i = (short)length + -1;
    length = CONCAT22((short)((uint)length >> 0x10), i);
    src = src;
    pbVar2 = pbVar2 + 1;
  } while (i != -1);
  uVar3 = context_swap(length, (long)uVar3);
  IO_Z80BUS = IO_Z80BUS_UNLOCK;
  return uVar3;
}

// This halts the Z80, stores the 68K's context into the stack, loads the 68K's
// context from the stack, and resumes the Z80.

undefined8 context_swap(long param_1, long param_2)

{
  IO_Z80RES = IO_Z80RES_FREEZE;
  IO_Z80RES = IO_Z80RES_THAW;
  return CONCAT44(param_1, param_2);
}

// This plays audio #fd and #ff in succession, which likely are special codes to
// stop the sound effects and music.

void audio_stop_all(void)

{
  byte bVar1;
  short sVar2;

  audio_play(SOUND_ID_RESUME);
  while (true) {
    IO_Z80BUS = 0x100;
    do {
      bVar1 = IO_Z80BUS._0_1_;
    } while ((bVar1 & 1) != 0);
    if (z80_ram_something_1 == '\0')
      break;
    IO_Z80BUS = 0;
    sVar2 = 0x1f;
    do {
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
  }
  (&z80_ram)[(short)(((byte)(z80_ram_something_3 + z80_ram_something_2) & 0xf) +
                     0x1c30)] = 0xff;
  z80_ram_something_3 = z80_ram_something_3 + '\x01';
  IO_Z80BUS = 0;
  return;
}

// Called when some sounds start to play, possibly when some are stopped too.

void audio_play(sound_id_t sound_id)

{
  short i;
  byte is_busy;

  while (true) {
    IO_Z80BUS = IO_Z80BUS_LOCK;
    do {
      is_busy = IO_Z80BUS._0_1_;
    } while ((is_busy & 1) != 0);
    if (z80_ram_something_1 == '\0')
      break;
    IO_Z80BUS = IO_Z80BUS_UNLOCK;
    // Busy wait?
    i = 0x1f;
    do {
      i = i + -1;
    } while (i != -1);
  }
  (&z80_ram)[(short)(((byte)(z80_ram_something_3 + z80_ram_something_2) & 0xf) +
                     0x1c30)] = sound_id;
  z80_ram_something_3 = z80_ram_something_3 + '\x01';
  IO_Z80BUS = IO_Z80BUS_UNLOCK;
  return;
}

undefined1 ecs_unk_3(entity_id_t self, short param_2)

{
  int iVar1;

  iVar1 = *(int *)((int)WORD_ARRAY_00001b78 +
                   (int)(short)(ushort)(&comp_func_offset[0]
                                             .func_offset_from_15ede)[self]);
  return *(undefined1 *)(*(short *)(iVar1 + (short)(ushort)(&comp_func_offset[0]
                                                                 .unk3)[self]) +
                         iVar1 + (int)param_2);
}

// This function takes a 7 words array, located right after its call point.
//
// If the value is 6 or greater, it is an offset to jump to from the jump
// table's address. Otherwise, it is used the second index for a local 2-deep
// jump table, following this function.

void ecs_jump_table(entity_id_t self)

{
  ushort state_as_offset;
  word *remote_jump_table;
  word remote_jump_table_value;
  short local_jump_table_value;

  // The state value is multiplied by 2 as a byte, it can overflow, so it's more
  // like: `offset = (self.comp_state * 2) & #7f;`.
  state_as_offset = (ushort)(byte)(*(char *)((int)&comp_state + self) * '\x02');
  remote_jump_table_value =
      *(word *)((int)remote_jump_table + (int)(short)state_as_offset);
  if (5 < remote_jump_table_value) {
    // WARNING: Could not recover jumptable at 0x00001d5c. Too many branches
    // WARNING: Treating indirect jump as call
    (*(code *)((int)remote_jump_table + (int)(short)remote_jump_table_value))();
    return;
  }
  local_jump_table_value =
      *(short *)((int)&WORD_00001d72 + (int)(short)state_as_offset);
  // WARNING: Could not recover jumptable at 0x00001d6e. Too many branches
  // WARNING: Treating indirect jump as call
  // local_jump_table[state_as_offset][remote_jump_table_value]();
  (*(code *)((int)&WORD_00001d72 +
             (int)*(short *)((int)&WORD_00001d72 +
                             (int)(short)(remote_jump_table_value * 2) +
                             (int)local_jump_table_value) +
             (int)local_jump_table_value))();
  return;
}

void FUN_00001d8a(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_state_a)[unaff_A4] = 0x80;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 6;
  ecs_clear_x_vel_round_up_pos(unaff_A4);
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_pos_y + unaff_A4) -
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  ecs_sprite_face_asha(unaff_A4);
  return;
}

void FUN_00001d98(entity_id_t self, entity_id_t other)

{
  (&comp_state_a)[self] = 0;
  *(undefined2 *)((int)&comp_unk_3 + self) = 0x18;
  ecs_clear_x_vel_round_up_pos(self);
  ecs_anim_unk_2(self, (anim_item_t *)other, 0);
  *(short *)((int)&comp_pos_y + self) =
      *(short *)((int)&comp_pos_y + self) -
      *(short *)((int)&comp_collision_sensor[0].y + self);
  *(undefined1 *)((int)&comp_state + self) = 3;
  ecs_sprite_face_asha(self);
  return;
}

void ecs_clear_x_vel_round_up_pos(entity_id_t self)

{
  *(undefined4 *)((int)&comp_vel[0].x + self) = 0;
  *(undefined2 *)((int)&comp_pos_x + self + 2) = 0;
  *(undefined2 *)((int)&comp_pos_y + self + 2) = 0;
  return;
}

void FUN_00001dcc(void)

{
  byte bVar1;
  component_state_b_t cVar2;
  short sVar3;
  entity_state_a_t eVar4;
  char unaff_D5b;
  int iVar5;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    audio_play(SOUND_ID_EN_DEAD);
    FUN_0000231c();
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
    FUN_00001eac();
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
  if (sVar3 == 0) {
    FUN_00015e86();
    iVar5 = (int)(short)unaff_A4;
    while (sVar3 =
               *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar5),
           -1 < sVar3) {
      iVar5 = (int)sVar3;
      (&comp_has_func_maybe)[iVar5] = 0;
    }
    ecs_unk_1(unaff_A4);
    if (unaff_D5b != -1) {
      FUN_00024d78();
      cVar2 = (&comp_has_func_maybe)[unaff_A4];
      (&comp_has_func_maybe)[unaff_A4] = cVar2 | 0x40;
      if ((cVar2 & 0x40) == 0) {
        FUN_000019ae();
        *(undefined2 *)((int)&comp_anim_speed + unaff_A4) = 0x100;
        eVar4 = 0;
        if (DAT_ffffcc28 != '\0') {
          eVar4 = 0x80;
        }
        (&comp_state_a)[unaff_A4] = eVar4;
        *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 4;
        *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
      }
      // WARNING: Could not recover jumptable at 0x00024e1e. Too many branches
      // WARNING: Treating indirect jump as call
      (*(code *)((int)&WORD_00024e22 +
                 (int)*(
                     short *)((int)&WORD_00024e22 +
                              (int)(short)(ushort)(&comp_func_offset[0]
                                                        .unk3)[unaff_A4])))();
      return;
    }
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

void FUN_00001e2c(void)

{
  byte bVar1;
  component_state_b_t cVar2;
  short sVar3;
  entity_state_a_t eVar4;
  char unaff_D5b;
  int iVar5;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    audio_play(SOUND_ID_EN_DEAD);
    FUN_0000231c();
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
    FUN_00001eac();
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
  if (sVar3 == 0) {
    FUN_00015e86();
    iVar5 = (int)(short)unaff_A4;
    while (sVar3 =
               *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar5),
           -1 < sVar3) {
      iVar5 = (int)sVar3;
      (&comp_has_func_maybe)[iVar5] = 0;
    }
    ecs_unk_1(unaff_A4);
    if (unaff_D5b != -1) {
      *(short *)((int)&comp_pos_x + unaff_A4) =
          ((short)(room_boundary_x - 0x1000) >> 1) + 0x1000;
      *(short *)((int)&comp_pos_y + unaff_A4) =
          ((short)(camera_pos_x_int - 0x1000) >> 1) + 0x1000;
      FUN_00024d78();
      cVar2 = (&comp_has_func_maybe)[unaff_A4];
      (&comp_has_func_maybe)[unaff_A4] = cVar2 | 0x40;
      if ((cVar2 & 0x40) == 0) {
        FUN_000019ae();
        *(undefined2 *)((int)&comp_anim_speed + unaff_A4) = 0x100;
        eVar4 = 0;
        if (DAT_ffffcc28 != '\0') {
          eVar4 = 0x80;
        }
        (&comp_state_a)[unaff_A4] = eVar4;
        *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 4;
        *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
      }
      // WARNING: Could not recover jumptable at 0x00024e1e. Too many branches
      // WARNING: Treating indirect jump as call
      (*(code *)((int)&WORD_00024e22 +
                 (int)*(
                     short *)((int)&WORD_00024e22 +
                              (int)(short)(ushort)(&comp_func_offset[0]
                                                        .unk3)[unaff_A4])))();
      return;
    }
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

void FUN_00001eac(void)

{
  ushort uVar1;

  if ((DAT_ffffde29 != 'd') &&
      (DAT_ffffde29 = DAT_ffffde29 + '\x01', DAT_ffffde29 == 'd')) {
    uVar1 = (ushort)OWNED_SWORD;
    DAT_ffffde0e = (&DAT_000297d4)[(short)uVar1];
    DAT_ffffde0f = (&DAT_000297dc)[(short)uVar1];
    DAT_ffffde12 = (ushort)(byte)(&DAT_000297e4)[(short)uVar1];
    if ((&DAT_000297e4)[(short)uVar1] != 0) {
      DAT_ffffde12 = 3;
    }
    DAT_ffffde10 = (&DAT_000297f4)[(short)(ushort)(OWNED_SHIELD & 7)];
    DAT_ffffde14 =
        (ushort)(byte)(&DAT_000297ec)[(short)(ushort)(OWNED_SHIELD & 7)];
    red_hearts = get_red_hearts((ushort)OWNED_ARMOR);
    total_hearts_max = blue_hearts + red_hearts;
    if (total_hearts_max < total_hearts) {
      total_hearts = total_hearts_max;
    }
    return;
  }
  return;
}

void FUN_00001ec8(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  audio_play(SOUND_ID_DAMAGE_2);
  FUN_0000231c();
  ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
  FUN_000022a0();
  return;
}

void FUN_00001ee2(void)

{
  byte bVar1;
  undefined1 uVar2;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  bool bVar3;
  undefined1 in_CF;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    FUN_00001ec8();
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff00;
    in_CF = false;
  }
  FUN_000021c2(unaff_A4, false, (bool)in_CF);
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  bVar3 = *(short *)((int)&comp_anim_tick + unaff_A4) == 0;
  if (bVar3) {
    FUN_00002248();
    if (!bVar3) {
      *(undefined2 *)(&comp_has_func_maybe + unaff_A4) =
          *(undefined2 *)(&comp_has_func_maybe + unaff_A4) & 0xf7fb;
      uVar2 = ecs_unk_3(unaff_A4, 1);
      *(undefined1 *)((int)&comp_state + unaff_A4) = uVar2;
    }
  }
  return;
}

void FUN_00001f1c(void)

{
  byte bVar1;
  byte bVar2;
  undefined1 uVar3;
  entity_id_t unaff_A4;
  undefined1 in_CF;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  bVar2 = bVar1 & 0x80;
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if (bVar2 == 0) {
    FUN_00001ec8();
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    in_CF = false;
  }
  FUN_000021c2(unaff_A4, bVar2 == 0, (bool)in_CF);
  player_update_pos_x(unaff_A4);
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined2 *)(&comp_has_func_maybe + unaff_A4) =
        *(undefined2 *)(&comp_has_func_maybe + unaff_A4) & 0xf7fb;
    uVar3 = ecs_unk_3(unaff_A4, 1);
    *(undefined1 *)((int)&comp_state + unaff_A4) = uVar3;
  }
  return;
}

void FUN_00001f4a(void)

{
  byte bVar1;
  byte bVar2;
  undefined1 uVar3;
  entity_id_t unaff_A4;
  undefined1 in_CF;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  bVar2 = bVar1 & 0x80;
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if (bVar2 == 0) {
    FUN_00001ec8();
    *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    in_CF = false;
  }
  FUN_000021c2(unaff_A4, bVar2 == 0, (bool)in_CF);
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined2 *)(&comp_has_func_maybe + unaff_A4) =
        *(undefined2 *)(&comp_has_func_maybe + unaff_A4) & 0xf7fb;
    uVar3 = ecs_unk_3(unaff_A4, 1);
    *(undefined1 *)((int)&comp_state + unaff_A4) = uVar3;
  }
  return;
}

void FUN_00001f76(void)

{
  byte bVar1;
  byte bVar2;
  undefined1 uVar3;
  entity_id_t unaff_A4;
  undefined1 in_CF;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    FUN_00001ec8();
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfe00;
    in_CF = 0;
  }
  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  bVar2 = bVar1 & 0x80;
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if (bVar2 == 0) {
    FUN_00001ec8();
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    in_CF = false;
  }
  FUN_000021c2(unaff_A4, bVar2 == 0, (bool)in_CF);
  player_update_pos_x(unaff_A4);
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined2 *)(&comp_has_func_maybe + unaff_A4) =
        *(undefined2 *)(&comp_has_func_maybe + unaff_A4) & 0xf7fb;
    uVar3 = ecs_unk_3(unaff_A4, 1);
    *(undefined1 *)((int)&comp_state + unaff_A4) = uVar3;
  }
  return;
}

void FUN_00001f92(void)

{
  short *psVar1;
  byte bVar2;
  undefined1 uVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  bool bVar4;
  undefined1 in_CF;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    FUN_00001ec8();
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = *psVar1 >> 1;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff00;
    in_CF = false;
  }
  FUN_000021c2(unaff_A4, false, (bool)in_CF);
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  bVar4 = *(short *)((int)&comp_anim_tick + unaff_A4) == 0;
  if (bVar4) {
    FUN_00002248();
    if (!bVar4) {
      (&comp_unk_11)[unaff_A4] = 0x1e;
      uVar3 = ecs_unk_3(unaff_A4, 1);
      *(undefined1 *)((int)&comp_state + unaff_A4) = uVar3;
    }
  }
  return;
}

void FUN_00001fd2(void)

{
  entity_id_t unaff_A4;
  undefined1 in_ZF;
  undefined1 in_CF;

  FUN_000189d0();
  FUN_000021c2(unaff_A4, (bool)in_ZF, (bool)in_CF);
  return;
}

undefined4 FUN_00001fdc(entity_id_t self, entity_id_t other, byte *param_3)

{
  byte bVar1;
  short sVar2;
  ushort uVar3;
  byte *pbVar4;

  if (*param_3 == 0) {
    pbVar4 = param_3 + 2;
  } else {
    bVar1 = (&comp_anim[0].frame)[other];
    if (param_3[1] < bVar1) {
      return 0xffffffff;
    }
    if (bVar1 < *param_3) {
      return 0xffffffff;
    }
    pbVar4 = param_3 + (short)((ushort)(byte)(bVar1 - *param_3) << 2) + 2;
  }
  sVar2 = (short)(char)*pbVar4;
  if (((&comp_state_a)[other] & ENTITY_STATE_A_08) != 0) {
    sVar2 = -sVar2;
  }
  uVar3 = (*(short *)((int)&comp_pos_x + other) + sVar2) -
          *(short *)((int)&comp_pos_x + self);
  if ((short)uVar3 < 0) {
    uVar3 = -uVar3;
  }
  if (uVar3 < 0x100) {
    if ((pbVar4[1] != 0) &&
        ((byte)uVar3 <
         (byte)((&comp_collision[0].set_by_anim_command_fb)[self] +
                pbVar4[1]))) {
      sVar2 = (short)(char)pbVar4[2];
      if (((&comp_state_a)[other] & ENTITY_STATE_A_H_FLIP) != 0) {
        sVar2 = -sVar2;
      }
      uVar3 = (*(short *)((int)&comp_pos_y + other) + sVar2) -
              *(short *)((int)&comp_pos_y + self);
      if ((short)uVar3 < 0) {
        uVar3 = -uVar3;
      }
      if ((uVar3 < 0x100) &&
          ((byte)uVar3 < (byte)((&comp_collision[0].unk2)[self] + pbVar4[3]))) {
        return 0;
      }
    }
  }
  return 0xffffffff;
}

undefined4 FUN_0000205a(entity_id_t self, entity_id_t other, byte *param_3,
                        byte *param_4)

{
  byte bVar1;
  short sVar2;
  ushort uVar3;
  short sVar4;
  byte *pbVar5;
  byte *pbVar6;

  if (*param_3 == 0) {
    pbVar5 = param_3 + 2;
  } else {
    bVar1 = (&comp_anim[0].frame)[other];
    if (param_3[1] < bVar1) {
      return 0xffffffff;
    }
    if (bVar1 < *param_3) {
      return 0xffffffff;
    }
    pbVar5 = param_3 + (short)((ushort)(byte)(bVar1 - *param_3) << 2) + 2;
  }
  if (*param_4 == 0) {
    pbVar6 = param_4 + 2;
  } else {
    bVar1 = (&comp_anim[0].frame)[self];
    if (param_4[1] < bVar1) {
      return 0xffffffff;
    }
    if (bVar1 < *param_4) {
      return 0xffffffff;
    }
    pbVar6 = param_4 + (short)((ushort)(byte)(bVar1 - *param_4) << 2) + 2;
  }
  sVar2 = (short)(char)*pbVar5;
  if (((&comp_state_a)[other] & ENTITY_STATE_A_08) != 0) {
    sVar2 = -sVar2;
  }
  sVar4 = (short)(char)*pbVar6;
  if (((&comp_state_a)[self] & ENTITY_STATE_A_08) != 0) {
    sVar4 = -sVar4;
  }
  uVar3 = (*(short *)((int)&comp_pos_x + other) + sVar2) -
          (*(short *)((int)&comp_pos_x + self) + sVar4);
  if ((short)uVar3 < 0) {
    uVar3 = -uVar3;
  }
  if (uVar3 < 0x100) {
    if (((pbVar5[1] != 0) && (pbVar6[1] != 0)) &&
        ((byte)uVar3 < (byte)(pbVar6[1] + pbVar5[1]))) {
      sVar2 = (short)(char)pbVar5[2];
      if (((&comp_state_a)[other] & ENTITY_STATE_A_H_FLIP) != 0) {
        sVar2 = -sVar2;
      }
      sVar4 = (short)(char)pbVar6[2];
      if (((&comp_state_a)[self] & ENTITY_STATE_A_H_FLIP) != 0) {
        sVar4 = -sVar4;
      }
      uVar3 = (*(short *)((int)&comp_pos_y + other) + sVar2) -
              (*(short *)((int)&comp_pos_y + self) + sVar4);
      if ((short)uVar3 < 0) {
        uVar3 = -uVar3;
      }
      if ((uVar3 < 0x100) && ((byte)uVar3 < (byte)(pbVar6[3] + pbVar5[3]))) {
        return 0;
      }
    }
  }
  return 0xffffffff;
}

void FUN_00002120(entity_id_t self, short param_2)

{
  byte bVar1;

  bVar1 = ecs_unk_3(self, param_2);
  uint8_t_ffffcc70 = (uint8_t_ffffcc70 | bVar1) & 0x7f;
  if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + self)) {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x80;
  }
  return;
}

void FUN_00002124(entity_id_t self, byte param_2)

{
  uint8_t_ffffcc70 = (uint8_t_ffffcc70 | param_2) & 0x7f;
  if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + self)) {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x80;
  }
  return;
}

undefined4 FUN_00002140(void)

{
  undefined4 uVar1;
  int unaff_A4;

  FUN_000021a2();
  if ((((&comp_func_offset[0].unk4)[unaff_A4] & 2) == 0) &&
      (uVar1 = FUN_000189d0(),
       ((&comp_func_offset[0].unk4)[unaff_A4] & 1) == 0)) {
    return uVar1;
  }
  if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    if ((-0x180 < comp_vel[0].x.raw) || (-0x300 < comp_vel[0].x.raw)) {
      comp_vel[0].x.raw = -0x200;
    }
  } else if (comp_vel[0].x.raw < 0x180) {
    comp_vel[0].x.raw = 0x200;
  } else if (comp_vel[0].x.raw < 0x300) {
    comp_vel[0].x.raw = comp_vel[0].x.raw + 0x100;
  }
  return 0xffffffff;
}

uint FUN_000021a2(void)

{
  uint extraout_D0;
  entity_id_t unaff_A4;
  undefined1 in_ZF;
  undefined1 in_CF;
  undefined6 uVar1;

  uVar1 = FUN_00000ed6(unaff_A4, ENTITY_ID_ASHA);
  if ((bool)in_CF || (bool)in_ZF) {
    FUN_00002120(unaff_A4, 3);
    (&comp_func_offset[0].unk4)[unaff_A4] =
        (&comp_func_offset[0].unk4)[unaff_A4] | 2;
    return extraout_D0;
  }
  (&comp_func_offset[0].unk4)[unaff_A4] =
      (&comp_func_offset[0].unk4)[unaff_A4] & 0xfd;
  return (uint)(ushort)((uint6)uVar1 >> 0x20);
}

uint FUN_000021c2(entity_id_t self, bool param_2, bool param_3)

{
  undefined2 extraout_D0u;
  uint extraout_D0;
  undefined6 uVar1;

  uVar1 = FUN_00000ed6(self, ENTITY_ID_ASHA);
  if (param_3 || param_2) {
    FUN_00002120(self, 0);
    (&comp_func_offset[0].unk4)[self] = (&comp_func_offset[0].unk4)[self] | 2;
    return extraout_D0;
  }
  (&comp_func_offset[0].unk4)[self] = (&comp_func_offset[0].unk4)[self] & 0xfd;
  return CONCAT22(extraout_D0u, (short)((uint6)uVar1 >> 0x20));
}

void FUN_000021e2(entity_id_t self)

{
  byte bVar1;
  byte bVar2;
  char cVar3;
  byte item_id_likely;

  if (((&comp_unk_11)[self] == '\0') &&
      (((&comp_func_offset[0].unk4)[self] & 1) != 0)) {
    bVar2 = DAT_ffffde0e;
    if (((&comp_func_offset[0].unk4)[self] & 4) != 0) {
      bVar2 = DAT_ffffde0f;
    }
    item_id_likely = (&comp_collected_item_id_maybe)[self];
    bVar1 = item_id_likely - bVar2;
    (&comp_collected_item_id_maybe)[self] = bVar1;
    if (item_id_likely < bVar2 || bVar1 == 0) {
      *(undefined1 *)((int)&comp_state + self) = 1;
    } else {
      cVar3 = ecs_unk_3(self, 1);
      if (cVar3 == -1) {
        audio_play(SOUND_ID_DAMAGE_2);
        (&comp_unk_11)[self] = 0x40;
        FUN_0000231c();
        return;
      }
      *(undefined1 *)((int)&comp_state + self) = 2;
    }
  }
  return;
}

void FUN_00002238(void)

{
  byte bVar1;
  entity_id_t unaff_A4;

  if (((&comp_func_offset[0].unk4)[unaff_A4] & 0x10) != 0) {
    bVar1 = ecs_unk_3(unaff_A4, 3);
    uint8_t_ffffcc70 = (uint8_t_ffffcc70 | bVar1) & 0x7f;
    if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x80;
    }
    return;
  }
  return;
}

byte FUN_00002248(void)

{
  int unaff_A4;

  return ((&component_unknown_5)[unaff_A4] |
          (&component_collision_flags)[unaff_A4]) &
         4;
}

void FUN_00002256(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = *(short *)((int)&comp_vel[0].x + unaff_A4);
  if (sVar1 == 0) {
    return;
  }
  if (sVar1 < 0) {
    sVar1 = sVar1 + 0x20;
    if (sVar1 < 0)
      goto LAB_0000226c;
  } else {
    sVar1 = sVar1 + -0x20;
    if (-1 < sVar1)
      goto LAB_0000226c;
  }
  sVar1 = 0;
LAB_0000226c:
  *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar1;
  return;
}

void FUN_00002258(void)

{
  short in_D0w;
  short sVar1;
  int unaff_A4;

  sVar1 = *(short *)((int)&comp_vel[0].x + unaff_A4);
  if (sVar1 == 0) {
    return;
  }
  if (sVar1 < 0) {
    sVar1 = in_D0w + sVar1;
    if (sVar1 < 0)
      goto LAB_0000226c;
  } else {
    sVar1 = sVar1 - in_D0w;
    if (-1 < sVar1)
      goto LAB_0000226c;
  }
  sVar1 = 0;
LAB_0000226c:
  *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar1;
  return;
}

void FUN_00002272(void)

{
  short *psVar1;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x40;
  if (0x500 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x500;
  }
  return;
}

void FUN_00002288(ulong entity, short param_2, word param_3, word param_4)

{
  short unaff_D2w;

  entity_update_pos(entity);
  interact_with_all_other_entities(entity, unaff_D2w, (char)param_2);
  ecs_update_collision(entity, param_2, param_3, param_4);
  ecs_apply_collision(entity);
  return;
}

void FUN_000022a0(void)

{
  short extraout_D0w;
  short sVar1;
  entity_id_t unaff_A4;

  ecs_sprite_face_asha(unaff_A4);
  sVar1 = extraout_D0w;
  if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
    sVar1 = -extraout_D0w;
  }
  *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar1;
  return;
}

void FUN_000022a2(void)

{
  short in_D0w;
  int unaff_A4;

  if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
    in_D0w = -in_D0w;
  }
  *(short *)((int)&comp_vel[0].x + unaff_A4) = in_D0w;
  return;
}

// This (likely) toggles the sprite's h-flip bit on when it is (strictly) right
// from Asha, making it face her.
//
// Cf. https://segaretro.org/Sega_Mega_Drive/Sprites

void ecs_sprite_face_asha(entity_id_t self)

{
  if (*(ushort *)((int)&comp_pos_x + self) <= (ushort)comp_pos_x.fixed.i) {
    (&comp_state_a)[self] = (&comp_state_a)[self] & ~ENTITY_STATE_A_08;
    return;
  }
  (&comp_state_a)[self] = (&comp_state_a)[self] | ENTITY_STATE_A_08;
  return;
}

short FUN_000022cc(void)

{
  int unaff_A4;

  return ((*(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
           *(short *)((int)&comp_pos_y + unaff_A4)) -
          comp_pos_y._0_2_) -
         comp_collision_sensor[0].y;
}

byte FUN_000022de(void)

{
  return (component_unknown_5 | component_collision_flags) & 4;
}

short FUN_000022ec(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  if (sVar1 < 0) {
    sVar1 = -sVar1;
  }
  return sVar1;
}

short FUN_000022fa(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = *(short *)((int)&comp_pos_x + unaff_A4) - comp_pos_x._0_2_;
  if (sVar1 < 0) {
    sVar1 = -sVar1;
  }
  return sVar1;
}

void FUN_0000231c(void)

{
  undefined1 in_D0b;
  int unaff_A4;

  (&DAT_ffffab42)[unaff_A4] = in_D0b;
  (&DAT_ffffab43)[unaff_A4] = 0;
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | 4;
  return;
}

undefined4 FUN_0000232c(void)

{
  short sVar1;
  short sVar2;
  char *in_A0;
  int unaff_A4;

  sVar1 = (short)*in_A0;
  sVar2 = (short)in_A0[1];
  if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
    sVar2 = -sVar1;
    sVar1 = -(short)in_A0[1];
  }
  if (((short)(*(short *)((int)&comp_pos_x + unaff_A4) + sVar1) <=
       comp_pos_x.fixed.i) &&
      (comp_pos_x.fixed.i <=
       (short)(*(short *)((int)&comp_pos_x + unaff_A4) + sVar2))) {
    if (((short)(*(short *)((int)&comp_pos_y + unaff_A4) + (short)in_A0[2]) <=
         comp_pos_y.fixed.i) &&
        (comp_pos_y.fixed.i <=
         (short)(*(short *)((int)&comp_pos_y + unaff_A4) + (short)in_A0[3]))) {
      return 0;
    }
  }
  return 0xffffffff;
}

void FUN_0000237a(void)

{
  short *psVar1;
  short in_D0w;
  short in_D1w;
  int unaff_A4;

  if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) == 0) {
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = in_D0w + *psVar1;
    if (*(short *)((int)&comp_vel[0].x + unaff_A4) < in_D1w) {
      return;
    }
  } else {
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = *psVar1 - in_D0w;
    in_D1w = -in_D1w;
    if (in_D1w < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
      return;
    }
  }
  *(short *)((int)&comp_vel[0].x + unaff_A4) = in_D1w;
  return;
}

short FUN_000023a0(void)

{
  short sVar1;
  short sVar2;
  char *extraout_A1;
  entity_id_t e;
  int unaff_A4;

  sVar1 = ecs_find_some_entity_with_func();
  if (-1 < sVar1) {
    e = (entity_id_t)sVar1;
    (&comp_unk_10)[e] = 0;
    entity_reset(e);
    (&comp_has_func_maybe)[e] = 0x80;
    sVar2 = (short)*extraout_A1;
    if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
      sVar2 = -sVar2;
    }
    *(short *)((int)&comp_pos_x + e) =
        *(short *)((int)&comp_pos_x + unaff_A4) + sVar2;
    *(short *)((int)&comp_pos_y + e) =
        *(short *)((int)&comp_pos_y + unaff_A4) + (short)extraout_A1[1];
    (&comp_func_offset[0].unk1)[e] = extraout_A1[2];
    (&comp_collision_related)[e] = extraout_A1[3];
    FUN_000019ae();
    (&comp_state_a)[e] =
        (&comp_state_a)[unaff_A4] & (ENTITY_STATE_A_H_FLIP | ENTITY_STATE_A_08);
    *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + e) =
        (short)unaff_A4;
    *(undefined2 *)((int)&comp_unk_8 + e) =
        *(undefined2 *)((int)&comp_unk_8 + unaff_A4);
  }
  return sVar1;
}

void FUN_00002408(void)

{
  short unaff_D3w;

  FUN_000183ce(unaff_D3w);
  return;
}

void FUN_00002420(void)

{
  int unaff_A4;

  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_pos_y + unaff_A4) -
      (*(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
           *(short *)((int)&comp_pos_y + unaff_A4) &
       0xfU);
  return;
}

void FUN_00002432(void)

{
  short unaff_D3w;

  FUN_000183ce(unaff_D3w);
  return;
}

short FUN_00002456(void)

{
  int unaff_A4;

  return ((*(short *)((int)&comp_pos_y + unaff_A4) -
           *(short *)((int)&comp_collision_sensor[0].y + unaff_A4)) +
          -0xd8) -
         DAT_ffffc746;
}

short FUN_0000246a(void)

{
  int unaff_A4;

  if (-1 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
    return (*(short *)((int)&comp_pos_x + unaff_A4) -
            *(short *)((int)&comp_collision_sensor[0].x + unaff_A4)) +
           -0x108;
  }
  return *(short *)((int)&comp_collision_sensor[0].x + unaff_A4) +
         *(short *)((int)&comp_pos_x + unaff_A4) + 8;
}

void FUN_0000248e(entity_id_t self)

{
  word wVar1;

  wVar1 = rand();
  *(word *)(&comp_unk_4 + self) = (wVar1 & 0x1f) + 0x10;
  return;
}

void FUN_00002492(void)

{
  ushort in_D0w;
  int unaff_A4;

  *(ushort *)(&comp_unk_4 + unaff_A4) = (in_D0w & 0x1f) + 0x10;
  return;
}

short FUN_000024a0(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  if (sVar1 < 0) {
    sVar1 = -sVar1;
  }
  return sVar1;
}

void FUN_000024ae(void)

{
  return;
}

void FUN_000024d2(void)

{
  ushort uVar1;
  ushort uVar2;
  int unaff_A4;

  uVar1 = *(short *)(&DAT_ffffbc76 + unaff_A4) -
          *(short *)((int)&comp_pos_x + unaff_A4);
  uVar2 = uVar1;
  if ((short)uVar1 < 0) {
    uVar2 = -uVar1;
  }
  if (uVar2 < 0xc0) {
    uVar1 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  }
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  if ((short)uVar1 < 0) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  }
  return;
}

undefined2 FUN_00002500(void)

{
  ushort uVar1;
  undefined2 uVar2;
  short unaff_D3w;

  uVar1 = FUN_000183ce(unaff_D3w);
  if ((uVar1 & 1) != 0) {
    uVar2 = FUN_000183ce(unaff_D3w);
    return uVar2;
  }
  return 0xffff;
}

void FUN_00002538(void)

{
  short *psVar1;
  int unaff_A4;
  undefined1 in_ZF;

  FUN_00002500();
  if (!(bool)in_ZF) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] ^ 3;
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = -*psVar1;
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
        *(undefined2 *)((int)component_pos_old_x + unaff_A4);
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)((int)component_pos_old_y + unaff_A4);
  }
  return;
}

void FUN_00002554(void)

{
  return;
}

void FUN_00002566(void)

{
  short sVar1;
  short in_D0w;
  int unaff_A4;

  sVar1 = *(short *)((int)&comp_pos_x + unaff_A4) -
          *(short *)(&DAT_ffffbc76 + unaff_A4);
  if ((in_D0w <= sVar1) ||
      (((&comp_state_a)[unaff_A4] =
            (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08,
        -sVar1 < in_D0w && ((ushort)comp_pos_x.fixed.i <
                            *(ushort *)((int)&comp_pos_x + unaff_A4))))) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  }
  return;
}

void FUN_00002590(void)

{
  ushort in_D0w;
  int unaff_A4;

  if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
    if (*(ushort *)((int)&comp_vel[0].x + unaff_A4) <= (ushort)-in_D0w) {
      *(ushort *)((int)&comp_vel[0].x + unaff_A4) = -in_D0w;
    }
  } else if (in_D0w < *(ushort *)((int)&comp_vel[0].x + unaff_A4)) {
    *(ushort *)((int)&comp_vel[0].x + unaff_A4) = in_D0w;
    return;
  }
  return;
}

void FUN_000025b0(void)

{
  ushort in_D0w;
  int unaff_A4;

  if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
    if (*(ushort *)((int)&comp_vel[0].y + unaff_A4) <= (ushort)-in_D0w) {
      *(ushort *)((int)&comp_vel[0].y + unaff_A4) = -in_D0w;
    }
  } else if (in_D0w < *(ushort *)((int)&comp_vel[0].y + unaff_A4)) {
    *(ushort *)((int)&comp_vel[0].y + unaff_A4) = in_D0w;
    return;
  }
  return;
}

void FUN_000025d0(void)

{
  short *psVar1;
  short sVar2;
  short in_D0w;
  short in_D1w;
  short unaff_D2w;
  short unaff_D3w;
  short sVar3;
  int unaff_A4;

  if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
    in_D0w = -in_D0w;
  }
  if ((ushort)(unaff_D2w + in_D0w) < *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    sVar3 = -unaff_D3w;
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 - in_D1w;
    sVar2 = *(short *)((int)&comp_vel[0].y + unaff_A4);
    if (-sVar2 == unaff_D3w || sVar3 < sVar2) {
      return;
    }
  } else {
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = in_D1w + *psVar1;
    sVar3 = unaff_D3w;
    if (*(short *)((int)&comp_vel[0].y + unaff_A4) <= unaff_D3w) {
      return;
    }
  }
  *(short *)((int)&comp_vel[0].y + unaff_A4) = sVar3;
  return;
}

void FUN_000025fe(void)

{
  ushort uVar1;
  ushort uVar2;
  ushort uVar3;
  ushort uVar4;
  ushort in_D0w;
  ushort uVar5;
  short sVar6;
  ushort uVar7;
  int unaff_A4;

  uVar1 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  uVar3 = uVar1;
  if ((short)uVar1 < 0) {
    uVar3 = -uVar1;
  }
  uVar2 = comp_pos_y.fixed.i - *(short *)((int)&comp_pos_y + unaff_A4);
  uVar4 = uVar2;
  if ((short)uVar2 < 0) {
    uVar4 = -uVar2;
  }
  uVar5 = uVar3;
  uVar7 = uVar4;
  if (uVar3 < uVar4) {
    uVar5 = uVar4;
    uVar7 = uVar3;
  }
  if (uVar5 == 0) {
    *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 1;
    return;
  }
  uVar7 = (ushort)(((uint)((int)(short)uVar7 << 8) / (uint)uVar5 & 0xffff) *
                       (uint)in_D0w * 0x100 >>
                   0x10);
  sVar6 = (short)((uint)((int)(short)uVar5 << 8) / (uint)in_D0w);
  if (sVar6 == 0) {
    sVar6 = 1;
  }
  *(short *)(&comp_unk_4 + unaff_A4) = sVar6;
  uVar5 = in_D0w;
  if (uVar3 < uVar4) {
    uVar5 = uVar7;
    uVar7 = in_D0w;
  }
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  if ((short)uVar1 < 0) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    uVar5 = -uVar5;
  }
  *(ushort *)((int)&comp_vel[0].x + unaff_A4) = uVar5;
  if ((short)uVar2 < 0) {
    uVar7 = -uVar7;
  }
  *(ushort *)((int)&comp_vel[0].y + unaff_A4) = uVar7;
  return;
}

void FUN_00002606(void)

{
  ushort uVar1;
  ushort uVar2;
  ushort uVar3;
  ushort uVar4;
  ushort in_D0w;
  short unaff_D2w;
  ushort uVar5;
  short sVar6;
  short unaff_D4w;
  ushort uVar7;
  int unaff_A4;

  uVar1 = unaff_D2w - *(short *)((int)&comp_pos_x + unaff_A4);
  uVar3 = uVar1;
  if ((short)uVar1 < 0) {
    uVar3 = -uVar1;
  }
  uVar2 = unaff_D4w - *(short *)((int)&comp_pos_y + unaff_A4);
  uVar4 = uVar2;
  if ((short)uVar2 < 0) {
    uVar4 = -uVar2;
  }
  uVar5 = uVar3;
  uVar7 = uVar4;
  if (uVar3 < uVar4) {
    uVar5 = uVar4;
    uVar7 = uVar3;
  }
  if (uVar5 == 0) {
    *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 1;
    return;
  }
  uVar7 = (ushort)(((uint)((int)(short)uVar7 << 8) / (uint)uVar5 & 0xffff) *
                       (uint)in_D0w * 0x100 >>
                   0x10);
  sVar6 = (short)((uint)((int)(short)uVar5 << 8) / (uint)in_D0w);
  if (sVar6 == 0) {
    sVar6 = 1;
  }
  *(short *)(&comp_unk_4 + unaff_A4) = sVar6;
  uVar5 = in_D0w;
  if (uVar3 < uVar4) {
    uVar5 = uVar7;
    uVar7 = in_D0w;
  }
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  if ((short)uVar1 < 0) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    uVar5 = -uVar5;
  }
  *(ushort *)((int)&comp_vel[0].x + unaff_A4) = uVar5;
  if ((short)uVar2 < 0) {
    uVar7 = -uVar7;
  }
  *(ushort *)((int)&comp_vel[0].y + unaff_A4) = uVar7;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00002678(void)

{
  int unaff_A4;

  DAT_ffffdb16 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  _DAT_ffffdb12 = DAT_ffffdb16;
  if (DAT_ffffdb16 < 0) {
    DAT_ffffdb16 = -DAT_ffffdb16;
  }
  DAT_ffffdb18 = ((comp_collision_sensor[0].y + comp_pos_y.fixed.i) -
                  *(short *)((int)&comp_pos_y + unaff_A4)) -
                 *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  _DAT_ffffdb14 = DAT_ffffdb18;
  if (DAT_ffffdb18 < 0) {
    DAT_ffffdb18 = -DAT_ffffdb18;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000026aa(void)

{
  int unaff_A4;

  if (-1 < _DAT_ffffdb12) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    return;
  }
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  return;
}

void FUN_000026c0(void)

{
  FUN_000026c8();
  return;
}

void FUN_000026c8(void)

{
  return;
}

void FUN_000026e4(void)

{
  return;
}

// Return a value in the [#bfff, #4000] range, mapping it to the ]-1, 1] range.

word angle_sin(angle_t angle)

{
  ushort sin;
  byte i;

  i = angle * '\x02';
  if ((char)i < '\0') {
    i = angle * -2;
  }
  sin = *(ushort *)((int)angle_sin_table + (int)(short)(ushort)i) >> 1;
  if ((char)angle < '\0') {
    sin = -sin;
  }
  return sin;
}

void FUN_00002782(void)

{
  ushort uVar1;
  ushort in_D0w;
  ushort in_D1w;
  ushort uVar2;
  ushort uVar3;
  ushort uVar4;

  if ((short)in_D0w < 0) {
    in_D0w = -in_D0w;
  }
  if ((short)in_D1w < 0) {
    in_D1w = -in_D1w;
  }
  if (in_D1w != in_D0w) {
    uVar2 = in_D0w;
    if (in_D0w <= in_D1w) {
      uVar2 = in_D1w;
      in_D1w = in_D0w;
    }
    uVar4 = 0;
    uVar3 = 0x40;
    do {
      uVar1 = ((ushort)(uVar3 + uVar4 + 2) >> 2) * 2;
      if ((ushort)(((uint)in_D1w << 0x10) / (uint)uVar2) <
          *(ushort *)((short)uVar1 + 0x27dc)) {
        uVar3 = uVar1 - 2;
        uVar1 = uVar4;
      }
      uVar4 = uVar1;
    } while (uVar4 < uVar3);
  }
  return;
}

void FUN_0000281e(void)

{
  short sVar1;
  byte bVar2;
  int unaff_A4;

  bVar2 = (&comp_func_offset[0].unk1)[unaff_A4];
  while (sVar1 =
             *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4),
         -1 < sVar1) {
    unaff_A4 = (int)sVar1;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
    (&comp_unk_11)[unaff_A4] = 0;
    (&comp_func_offset[0].unk1)[unaff_A4] = bVar2;
    FUN_000019ae();
  }
  return;
}

short FUN_00002848(void)

{
  int unaff_A4;

  return DAT_ffffce0a - *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
}

undefined4 FUN_00002856(void)

{
  undefined2 uVar1;
  int unaff_A4;
  undefined1 in_ZF;
  undefined1 in_CF;

  uVar1 = FUN_00002848();
  if ((bool)in_CF || (bool)in_ZF) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) = uVar1;
    return 0xffffffff;
  }
  return 0;
}

undefined4 FUN_00002866(void)

{
  undefined2 uVar1;
  int unaff_A4;
  undefined1 in_ZF;
  undefined1 in_CF;

  uVar1 = FUN_00002848();
  if ((bool)in_CF || (bool)in_ZF) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) = uVar1;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    return 0xffffffff;
  }
  return 0;
}

undefined4 FUN_0000287a(void)

{
  short sVar1;
  int unaff_A4;

  if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
    sVar1 =
        *(short *)((int)&comp_collision_sensor[0].x + unaff_A4) + DAT_ffffce04;
    if (sVar1 < *(short *)((int)&comp_pos_x + unaff_A4)) {
      return 0;
    }
  } else {
    sVar1 =
        DAT_ffffce08 - *(short *)((int)&comp_collision_sensor[0].x + unaff_A4);
    if (*(short *)((int)&comp_pos_x + unaff_A4) < sVar1) {
      return 0;
    }
  }
  *(short *)((int)&comp_pos_x + unaff_A4) = sVar1;
  return 0xffffffff;
}

void FUN_000028aa(void)

{
  short unaff_D3w;
  short unaff_D4w;
  int unaff_A4;

  FUN_000026c0();
  *(short *)((int)&comp_pos_x + unaff_A4) =
      *(short *)((int)&comp_pos_x + (int)*(short *)(&DAT_ffffbc76 + unaff_A4)) +
      unaff_D3w;
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_pos_y + (int)*(short *)(&DAT_ffffbc76 + unaff_A4)) +
      unaff_D4w;
  return;
}

void FUN_000028ce(void)

{
  long in_D0;
  long in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;

  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  in_D0,
                  in_D1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  FUN_0001a388();
  return;
}

void FUN_000028d8(void)

{
  short in_D0w;
  undefined2 local_2;

  local_2 = in_D0w;
  do {
    FUN_000028ce();
    local_2 = local_2 + -1;
  } while (local_2 != 0);
  return;
}

// Iterates over some value for each palette, and return when it's not 0,
// whatever it means.

short palette_iterate_for_unknown_reasons(void)

{
  short i;
  byte *src;
  byte value;

  src = &palette_fade_done_0;
  i = 3;
  do {
    value = *src;
    src = src + 4;
    if (value != 0) {
      return i;
    }
    i = i + -1;
  } while (i != -1);
  return -1;
}

undefined8 init(void)

{
  undefined1 uVar1;
  long in_D0;
  long in_D1;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  ulong unaff_A3;
  ulong unaff_A4;
  ulong unaff_A5;
  ulong unaff_A6;
  undefined8 uVar2;

  do {
    uVar1 = VDP_CTRL.b[1];
  } while ((uVar1 & 2) != 0);
  uVar2 = init_z80(in_D0, in_D1);
  uVar2 = init_something(unaff_A3,
                         unaff_A4,
                         unaff_A5,
                         unaff_A6,
                         (long)((ulonglong)uVar2 >> 0x20),
                         (short)uVar2,
                         unaff_D3,
                         unaff_D4,
                         unaff_D5,
                         unaff_D6,
                         unaff_D7);
  return uVar2;
}

void sega_and_title_screen(palette_id_flag_t palettes)

{
  int iVar1;
  undefined4 uVar2;
  short sVar3;
  long extraout_D1;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  undefined8 uVar4;
  undefined8 uVar5;
  ushort uStack_6;

  DAT_ffff96ce = 0;
  DAT_ffff91ce._0_1_ = 0;
  uStack_6 = 0;
  uVar4 = main_unk_4();
  do {
    if (DAT_ffff9156 != '\0') {
      if ((((uStack_6 == 6) || (uStack_6 == 4)) || (uStack_6 == 10)) ||
          ((gamepad_pressed & GAMEPAD_START) == GAMEPAD_NONE)) {
        if (DAT_ffff9154 == -1) {
          uVar4 = FUN_00000472((ulong)&stack0xfffffffc, 3, (long)uVar4);
          uVar4 = FUN_00000472((ulong)&stack0xfffffffc, 4, (long)uVar4);
          FUN_00000472((ulong)&stack0xfffffffc, 0, (long)uVar4);
          DAT_ffffc714 = 0xf;
          iVar1 = (int)(short)uStack_6;
          uStack_6 = *(ushort *)((int)&WORD_000029ce + iVar1) >> 1;
          uVar4 = (**(
              code **)((int)&PTR_main_unk_4_000029da +
                       (int)(short)*(ushort *)((int)&WORD_000029ce + iVar1)))();
        }
      } else {
        unaff_D3 = -1;
        palette_set_fade(palettes,
                         PALETTE_FADE_NONE,
                         '\0',
                         (palette_color_iter_t)0xffffffff);
        uVar4 = FUN_00000472((ulong)&stack0xfffffffc, 4, extraout_D1);
        FUN_00000472((ulong)&stack0xfffffffc, 0, (long)uVar4);
        iVar1 = (int)(short)uStack_6;
        uStack_6 = *(ushort *)((int)&WORD_000029c2 + iVar1) >> 1;
        uVar4 = (**(
            code **)((int)&PTR_main_unk_4_000029da +
                     (int)(short)*(ushort *)((int)&WORD_000029c2 + iVar1)))();
      }
    }
    uVar5 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            &stack0xfffffffc,
                            (long)((ulonglong)uVar4 >> 0x20),
                            (long)uVar4,
                            palettes,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    uVar2 = CONCAT22((short)((ulonglong)uVar5 >> 0x30), 0x300);
    do {
      sVar3 = (short)uVar2 + -1;
      uVar2 = CONCAT22((short)((uint)uVar2 >> 0x10), sVar3);
      uVar4 = CONCAT44(uVar2, (int)uVar5);
    } while (sVar3 != -1);
  } while (true);
}

void main_unk_4(void)

{
  undefined4 extraout_D1;
  undefined4 unaff_D2;
  undefined4 unaff_D3;
  undefined4 unaff_D4;
  undefined4 unaff_D5;
  undefined4 unaff_D6;
  undefined4 unaff_D7;
  undefined4 extraout_A1;
  undefined4 extraout_A1_00;
  undefined4 extraout_A1_01;
  undefined4 unaff_A2;
  undefined4 unaff_A3;
  undefined4 unaff_A4;
  undefined4 unaff_A5;
  register_t a[5];
  register_t a_00[5];
  register_t a_01[5];
  register_t d[8];
  register_t d_00[8];
  register_t d_01[8];
  undefined4 extraout_D1_00;
  undefined4 extraout_D1_01;

  DAT_ffff96b0 = 0;
  vdp_set_window_position(0);
  vdp_write_something_to_vram();
  DAT_ffff9154 = 0;
  DAT_ffff9156 = 0;
  a[3] = unaff_A4;
  a[4] = unaff_A5;
  a[2] = unaff_A3;
  a[0] = extraout_A1;
  a[1] = unaff_A2;
  d[6] = unaff_D6;
  d[7] = unaff_D7;
  d[4] = unaff_D4;
  d[5] = unaff_D5;
  d[2] = unaff_D2;
  d[3] = unaff_D3;
  d[0] = 3;
  d[1] = extraout_D1;
  main_save_registers_into_stack(main_unk_11, d, a);
  a_00[3] = unaff_A4;
  a_00[4] = unaff_A5;
  a_00[2] = unaff_A3;
  a_00[0] = extraout_A1_00;
  a_00[1] = unaff_A2;
  d_00[6] = unaff_D6;
  d_00[7] = unaff_D7;
  d_00[4] = unaff_D4;
  d_00[5] = unaff_D5;
  d_00[2] = unaff_D2;
  d_00[3] = unaff_D3;
  d_00[0] = 2;
  d_00[1] = extraout_D1_00;
  main_save_registers_into_stack(main_unk_2, d_00, a_00);
  a_01[3] = unaff_A4;
  a_01[4] = unaff_A5;
  a_01[2] = unaff_A3;
  a_01[0] = extraout_A1_01;
  a_01[1] = unaff_A2;
  d_01[6] = unaff_D6;
  d_01[7] = unaff_D7;
  d_01[4] = unaff_D4;
  d_01[5] = unaff_D5;
  d_01[2] = unaff_D2;
  d_01[3] = unaff_D3;
  d_01[0] = 4;
  d_01[1] = extraout_D1_01;
  main_save_registers_into_stack(main_unk_3, d_01, a_01);
  return;
}

void main_unk_5(void)

{
  undefined4 extraout_D1;
  undefined4 unaff_D2;
  undefined4 unaff_D3;
  undefined4 unaff_D4;
  undefined4 unaff_D5;
  undefined4 unaff_D6;
  undefined4 unaff_D7;
  undefined4 extraout_A1;
  undefined4 extraout_A1_00;
  undefined4 extraout_A1_01;
  undefined4 unaff_A2;
  undefined4 unaff_A3;
  undefined4 unaff_A4;
  undefined4 unaff_A5;
  register_t a[5];
  register_t a_00[5];
  register_t a_01[5];
  register_t d[8];
  register_t d_00[8];
  register_t d_01[8];
  undefined4 extraout_D1_00;
  undefined4 extraout_D1_01;

  DAT_ffff96b0 = 0;
  vdp_set_window_position(0);
  DAT_ffff9154 = 1;
  DAT_ffff9156 = 0;
  a[3] = unaff_A4;
  a[4] = unaff_A5;
  a[2] = unaff_A3;
  a[0] = extraout_A1;
  a[1] = unaff_A2;
  d[6] = unaff_D6;
  d[7] = unaff_D7;
  d[4] = unaff_D4;
  d[5] = unaff_D5;
  d[2] = unaff_D2;
  d[3] = unaff_D3;
  d[0] = 3;
  d[1] = extraout_D1;
  main_save_registers_into_stack(main_unk_12, d, a);
  a_00[3] = unaff_A4;
  a_00[4] = unaff_A5;
  a_00[2] = unaff_A3;
  a_00[0] = extraout_A1_00;
  a_00[1] = unaff_A2;
  d_00[6] = unaff_D6;
  d_00[7] = unaff_D7;
  d_00[4] = unaff_D4;
  d_00[5] = unaff_D5;
  d_00[2] = unaff_D2;
  d_00[3] = unaff_D3;
  d_00[0] = 2;
  d_00[1] = extraout_D1_00;
  main_save_registers_into_stack(main_unk_2, d_00, a_00);
  a_01[3] = unaff_A4;
  a_01[4] = unaff_A5;
  a_01[2] = unaff_A3;
  a_01[0] = extraout_A1_01;
  a_01[1] = unaff_A2;
  d_01[6] = unaff_D6;
  d_01[7] = unaff_D7;
  d_01[4] = unaff_D4;
  d_01[5] = unaff_D5;
  d_01[2] = unaff_D2;
  d_01[3] = unaff_D3;
  d_01[0] = 4;
  d_01[1] = extraout_D1_01;
  main_save_registers_into_stack(main_unk_3, d_01, a_01);
  return;
}

void main_unk_1(void)

{
  undefined4 extraout_D1;
  undefined4 unaff_D2;
  undefined4 unaff_D3;
  undefined4 unaff_D4;
  undefined4 unaff_D5;
  undefined4 unaff_D6;
  undefined4 unaff_D7;
  undefined4 extraout_A1;
  undefined4 extraout_A1_00;
  undefined4 extraout_A1_01;
  undefined4 unaff_A2;
  undefined4 unaff_A3;
  undefined4 unaff_A4;
  undefined4 unaff_A5;
  register_t a[5];
  register_t a_00[5];
  register_t a_01[5];
  register_t d[8];
  register_t d_00[8];
  register_t d_01[8];
  undefined4 extraout_D1_00;
  undefined4 extraout_D1_01;

  DAT_ffff96b0 = 0;
  audio_stop_all();
  audio_play(SOUND_ID_RES_BTTN);
  DAT_ffff9154 = 2;
  DAT_ffff9156 = 0;
  a[3] = unaff_A4;
  a[4] = unaff_A5;
  a[2] = unaff_A3;
  a[0] = extraout_A1;
  a[1] = unaff_A2;
  d[6] = unaff_D6;
  d[7] = unaff_D7;
  d[4] = unaff_D4;
  d[5] = unaff_D5;
  d[2] = unaff_D2;
  d[3] = unaff_D3;
  d[0] = 3;
  d[1] = extraout_D1;
  main_save_registers_into_stack(menu_title, d, a);
  a_00[3] = unaff_A4;
  a_00[4] = unaff_A5;
  a_00[2] = unaff_A3;
  a_00[0] = extraout_A1_00;
  a_00[1] = unaff_A2;
  d_00[6] = unaff_D6;
  d_00[7] = unaff_D7;
  d_00[4] = unaff_D4;
  d_00[5] = unaff_D5;
  d_00[2] = unaff_D2;
  d_00[3] = unaff_D3;
  d_00[0] = 2;
  d_00[1] = extraout_D1_00;
  main_save_registers_into_stack(main_unk_2, d_00, a_00);
  a_01[3] = unaff_A4;
  a_01[4] = unaff_A5;
  a_01[2] = unaff_A3;
  a_01[0] = extraout_A1_01;
  a_01[1] = unaff_A2;
  d_01[6] = unaff_D6;
  d_01[7] = unaff_D7;
  d_01[4] = unaff_D4;
  d_01[5] = unaff_D5;
  d_01[2] = unaff_D2;
  d_01[3] = unaff_D3;
  d_01[0] = 4;
  d_01[1] = extraout_D1_01;
  main_save_registers_into_stack(main_unk_3, d_01, a_01);
  return;
}

undefined4 main_unk_6(void)

{
  undefined4 extraout_D0;
  undefined4 uVar1;
  undefined4 extraout_D1;
  undefined4 extraout_D1_00;
  long lVar2;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  undefined4 extraout_A1;
  undefined4 extraout_A1_00;
  undefined4 extraout_A1_01;
  undefined4 unaff_A2;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  undefined4 unaff_A5;
  void *unaff_A6;
  undefined8 uVar3;
  register_t a[5];
  register_t a_00[5];
  register_t a_01[5];
  register_t d[8];
  register_t d_00[8];
  register_t d_01[8];
  undefined4 extraout_D1_01;
  undefined4 extraout_D1_02;

  DAT_ffff96b0 = 0;
  vdp_set_window_position(0);
  FUN_0000bce8();
  a[3] = unaff_A4;
  a[4] = unaff_A5;
  a[2] = (register_t)unaff_A3;
  a[0] = extraout_A1;
  a[1] = unaff_A2;
  d[6] = unaff_D6;
  d[7] = unaff_D7;
  d[4] = unaff_D4;
  d[5] = unaff_D5;
  d[2] = unaff_D2;
  d[3] = unaff_D3;
  d[0] = 4;
  d[1] = extraout_D1;
  main_save_registers_into_stack(main_unk_3, d, a);
  if ((DAT_ffff96bc & 4) == 0) {
    FUN_0000bd48();
  } else {
    FUN_0000bd26();
  }
  vdp_write_something_to_vram();
  DAT_ffff9154 = 4;
  DAT_ffff9156 = 0xff;
  a_00[3] = unaff_A4;
  a_00[4] = unaff_A5;
  a_00[2] = (register_t)unaff_A3;
  a_00[0] = extraout_A1_00;
  a_00[1] = unaff_A2;
  d_00[6] = unaff_D6;
  d_00[7] = unaff_D7;
  d_00[4] = unaff_D4;
  d_00[5] = unaff_D5;
  d_00[2] = unaff_D2;
  d_00[3] = unaff_D3;
  d_00[0] = 3;
  d_00[1] = extraout_D1_00;
  main_save_registers_into_stack(main_unk_13, d_00, a_00);
  a_01[3] = unaff_A4;
  a_01[4] = unaff_A5;
  a_01[2] = (register_t)unaff_A3;
  a_01[0] = extraout_A1_01;
  a_01[1] = unaff_A2;
  d_01[6] = unaff_D6;
  d_01[7] = unaff_D7;
  d_01[4] = unaff_D4;
  d_01[5] = unaff_D5;
  d_01[2] = unaff_D2;
  d_01[3] = unaff_D3;
  d_01[0] = 2;
  d_01[1] = extraout_D1_01;
  main_save_registers_into_stack(main_unk_2, d_01, a_01);
  uVar3 = CONCAT44(extraout_D0, extraout_D1_02);
  while (true) {
    lVar2 = (long)uVar3;
    if (DAT_ffff9154 == -1) {
      uVar3 = FUN_00000472((ulong)unaff_A6, 3, lVar2);
      return (int)((ulonglong)uVar3 >> 0x20);
    }
    if (DAT_ffff9154 == 0)
      break;
    gamepad_held = gamepad_held_4;
    uVar3 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar3 >> 0x20),
                            lVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  }
  FUN_00000472((ulong)unaff_A6, 3, lVar2);
  *(undefined2 *)((int)unaff_A6 + -2) = 0;
  uVar1 = main_unk_4();
  return uVar1;
}

undefined4 main_unk_7(void)

{
  undefined4 extraout_D0;
  undefined4 uVar1;
  undefined4 extraout_D1;
  long lVar2;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  undefined4 extraout_A1;
  undefined4 extraout_A1_00;
  undefined4 unaff_A2;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  undefined4 unaff_A5;
  void *unaff_A6;
  undefined8 uVar3;
  register_t a[5];
  register_t a_00[5];
  register_t d[8];
  register_t d_00[8];
  undefined4 extraout_D1_00;
  undefined4 extraout_D1_01;

  vdp_write_something_to_vram();
  DAT_ffff9154 = 4;
  DAT_ffff9156 = 0xff;
  a[3] = unaff_A4;
  a[4] = unaff_A5;
  a[2] = (register_t)unaff_A3;
  a[0] = extraout_A1;
  a[1] = unaff_A2;
  d[6] = unaff_D6;
  d[7] = unaff_D7;
  d[4] = unaff_D4;
  d[5] = unaff_D5;
  d[2] = unaff_D2;
  d[3] = unaff_D3;
  d[0] = 3;
  d[1] = extraout_D1;
  main_save_registers_into_stack(main_unk_13, d, a);
  a_00[3] = unaff_A4;
  a_00[4] = unaff_A5;
  a_00[2] = (register_t)unaff_A3;
  a_00[0] = extraout_A1_00;
  a_00[1] = unaff_A2;
  d_00[6] = unaff_D6;
  d_00[7] = unaff_D7;
  d_00[4] = unaff_D4;
  d_00[5] = unaff_D5;
  d_00[2] = unaff_D2;
  d_00[3] = unaff_D3;
  d_00[0] = 2;
  d_00[1] = extraout_D1_00;
  main_save_registers_into_stack(main_unk_2, d_00, a_00);
  uVar3 = CONCAT44(extraout_D0, extraout_D1_01);
  while (true) {
    lVar2 = (long)uVar3;
    if (DAT_ffff9154 == -1) {
      uVar3 = FUN_00000472((ulong)unaff_A6, 3, lVar2);
      return (int)((ulonglong)uVar3 >> 0x20);
    }
    if (DAT_ffff9154 == 0)
      break;
    gamepad_held = gamepad_held_4;
    uVar3 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar3 >> 0x20),
                            lVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  }
  FUN_00000472((ulong)unaff_A6, 3, lVar2);
  *(undefined2 *)((int)unaff_A6 + -2) = 0;
  uVar1 = main_unk_4();
  return uVar1;
}

undefined8 main_unk_8(void)

{
  undefined4 extraout_D1;
  long extraout_D1_02;
  long extraout_D1_05;
  undefined4 unaff_D2;
  undefined4 unaff_D3;
  undefined4 unaff_D4;
  undefined4 unaff_D5;
  undefined4 unaff_D6;
  undefined4 unaff_D7;
  undefined4 extraout_A1;
  undefined4 extraout_A1_00;
  undefined4 extraout_A1_01;
  undefined4 extraout_A1_02;
  undefined4 extraout_A1_03;
  undefined4 unaff_A2;
  undefined4 unaff_A3;
  undefined4 unaff_A4;
  undefined4 unaff_A5;
  ulong unaff_A6;
  undefined8 uVar1;
  register_t a[5];
  register_t a_00[5];
  register_t a_01[5];
  register_t a_02[5];
  register_t a_03[5];
  register_t a_04[5];
  register_t d[8];
  register_t d_00[8];
  register_t d_01[8];
  register_t d_02[8];
  register_t d_03[8];
  register_t d_04[8];
  undefined4 extraout_D1_00;
  undefined4 extraout_D1_01;
  undefined4 extraout_D1_03;
  undefined4 extraout_D1_04;

  DAT_ffff96b0 = 0;
  FUN_00001580();
  vdp_set_window_position(0);
  DAT_ffff9154 = 3;
  if ((DAT_ffff96ce != '\x01') && (DAT_ffff96ce != '\x03')) {
    DAT_ffff96bc = 2;
    DAT_ffff9156 = 0xff;
    a[3] = unaff_A4;
    a[4] = unaff_A5;
    a[2] = unaff_A3;
    a[0] = extraout_A1;
    a[1] = unaff_A2;
    d[6] = unaff_D6;
    d[7] = unaff_D7;
    d[4] = unaff_D4;
    d[5] = unaff_D5;
    d[2] = unaff_D2;
    d[3] = unaff_D3;
    d[0] = 3;
    d[1] = extraout_D1;
    main_save_registers_into_stack(main_unk_13, d, a);
    a_00[3] = unaff_A4;
    a_00[4] = unaff_A5;
    a_00[2] = unaff_A3;
    a_00[0] = extraout_A1_00;
    a_00[1] = unaff_A2;
    d_00[6] = unaff_D6;
    d_00[7] = unaff_D7;
    d_00[4] = unaff_D4;
    d_00[5] = unaff_D5;
    d_00[2] = unaff_D2;
    d_00[3] = unaff_D3;
    d_00[0] = 2;
    d_00[1] = extraout_D1_00;
    main_save_registers_into_stack(main_unk_2, d_00, a_00);
    a_01[3] = unaff_A4;
    a_01[4] = unaff_A5;
    a_01[2] = unaff_A3;
    a_01[0] = extraout_A1_01;
    a_01[1] = unaff_A2;
    d_01[6] = unaff_D6;
    d_01[7] = unaff_D7;
    d_01[4] = unaff_D4;
    d_01[5] = unaff_D5;
    d_01[2] = unaff_D2;
    d_01[3] = unaff_D3;
    d_01[0] = 4;
    d_01[1] = extraout_D1_01;
    main_save_registers_into_stack(main_unk_3, d_01, a_01);
    FUN_00005f38();
    DAT_ffff96ce = DAT_ffff96ce + 1;
    if (3 < DAT_ffff96ce) {
      DAT_ffff96ce = 0;
    }
    uVar1 = FUN_00000472(unaff_A6, 3, extraout_D1_02);
    return uVar1;
  }
  DAT_ffff9156 = 0xff;
  a_02[3] = unaff_A4;
  a_02[4] = unaff_A5;
  a_02[2] = unaff_A3;
  a_02[0] = extraout_A1;
  a_02[1] = unaff_A2;
  d_02[6] = unaff_D6;
  d_02[7] = unaff_D7;
  d_02[4] = unaff_D4;
  d_02[5] = unaff_D5;
  d_02[2] = unaff_D2;
  d_02[3] = unaff_D3;
  d_02[0] = 3;
  d_02[1] = extraout_D1;
  main_save_registers_into_stack(main_unk_14, d_02, a_02);
  a_03[3] = unaff_A4;
  a_03[4] = unaff_A5;
  a_03[2] = unaff_A3;
  a_03[0] = extraout_A1_02;
  a_03[1] = unaff_A2;
  d_03[6] = unaff_D6;
  d_03[7] = unaff_D7;
  d_03[4] = unaff_D4;
  d_03[5] = unaff_D5;
  d_03[2] = unaff_D2;
  d_03[3] = unaff_D3;
  d_03[0] = 2;
  d_03[1] = extraout_D1_03;
  main_save_registers_into_stack(main_unk_2, d_03, a_03);
  a_04[3] = unaff_A4;
  a_04[4] = unaff_A5;
  a_04[2] = unaff_A3;
  a_04[0] = extraout_A1_03;
  a_04[1] = unaff_A2;
  d_04[6] = unaff_D6;
  d_04[7] = unaff_D7;
  d_04[4] = unaff_D4;
  d_04[5] = unaff_D5;
  d_04[2] = unaff_D2;
  d_04[3] = unaff_D3;
  d_04[0] = 4;
  d_04[1] = extraout_D1_04;
  main_save_registers_into_stack(main_unk_3, d_04, a_04);
  FUN_0000609e();
  DAT_ffff96ce = DAT_ffff96ce + 1;
  if (3 < DAT_ffff96ce) {
    DAT_ffff96ce = 0;
  }
  uVar1 = FUN_00000472(unaff_A6, 3, extraout_D1_05);
  return uVar1;
}

void main_unk_9(void)

{
  undefined4 extraout_D1;
  undefined4 unaff_D3;
  undefined4 unaff_D4;
  undefined4 unaff_D5;
  undefined4 unaff_D6;
  undefined4 unaff_D7;
  undefined4 extraout_A1;
  undefined4 extraout_A1_00;
  undefined4 extraout_A1_01;
  undefined4 unaff_A2;
  undefined4 unaff_A3;
  undefined4 unaff_A4;
  undefined4 unaff_A5;
  register_t a[5];
  register_t a_00[5];
  register_t a_01[5];
  register_t d[8];
  register_t d_00[8];
  register_t d_01[8];
  undefined4 extraout_D1_00;
  undefined4 extraout_D1_01;

  DAT_ffff96b0 = 0;
  vdp_set_window_position(0);
  FUN_0000bba2();
  vdp_write_something_to_vram();
  DAT_ffff9154 = 5;
  DAT_ffff9156 = 0;
  a[3] = unaff_A4;
  a[4] = unaff_A5;
  a[2] = unaff_A3;
  a[0] = extraout_A1;
  a[1] = unaff_A2;
  d[6] = unaff_D6;
  d[7] = unaff_D7;
  d[4] = unaff_D4;
  d[5] = unaff_D5;
  d[2] = 3;
  d[3] = unaff_D3;
  d[0] = 3;
  d[1] = extraout_D1;
  main_save_registers_into_stack(main_unk_15, d, a);
  a_00[3] = unaff_A4;
  a_00[4] = unaff_A5;
  a_00[2] = unaff_A3;
  a_00[0] = extraout_A1_00;
  a_00[1] = unaff_A2;
  d_00[6] = unaff_D6;
  d_00[7] = unaff_D7;
  d_00[4] = unaff_D4;
  d_00[5] = unaff_D5;
  d_00[2] = 3;
  d_00[3] = unaff_D3;
  d_00[0] = 2;
  d_00[1] = extraout_D1_00;
  main_save_registers_into_stack(main_unk_2, d_00, a_00);
  a_01[3] = unaff_A4;
  a_01[4] = unaff_A5;
  a_01[2] = unaff_A3;
  a_01[0] = extraout_A1_01;
  a_01[1] = unaff_A2;
  d_01[6] = unaff_D6;
  d_01[7] = unaff_D7;
  d_01[4] = unaff_D4;
  d_01[5] = unaff_D5;
  d_01[2] = 3;
  d_01[3] = unaff_D3;
  d_01[0] = 4;
  d_01[1] = extraout_D1_01;
  main_save_registers_into_stack(main_unk_3, d_01, a_01);
  return;
}

undefined4 FUN_00002c4c(void)

{
  undefined4 extraout_D0;
  undefined4 extraout_D0_00;
  undefined4 uVar1;
  undefined4 extraout_D1;
  undefined4 extraout_D1_02;
  long lVar2;
  undefined4 extraout_D1_05;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  undefined4 extraout_A1;
  undefined4 extraout_A1_00;
  undefined4 extraout_A1_01;
  undefined4 extraout_A1_02;
  undefined4 extraout_A1_03;
  undefined4 extraout_A1_04;
  undefined4 unaff_A2;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  undefined4 unaff_A5;
  void *unaff_A6;
  undefined8 uVar3;
  register_t d[8];
  register_t d_00[8];
  register_t d_01[8];
  register_t d_02[8];
  register_t d_03[8];
  register_t d_04[8];
  register_t a[5];
  register_t a_00[5];
  register_t a_01[5];
  register_t a_02[5];
  register_t a_03[5];
  register_t a_04[5];
  undefined4 extraout_D1_00;
  undefined4 extraout_D1_01;
  undefined4 extraout_D1_03;
  undefined4 extraout_D1_04;

  if (DAT_ffff980c == '\0') {
    *(undefined2 *)((int)unaff_A6 + -2) = 0;
    DAT_ffff96b0 = 0;
    vdp_set_window_position(0);
    vdp_write_something_to_vram();
    DAT_ffff9154 = 0;
    DAT_ffff9156 = 0;
    d[6] = unaff_D6;
    d[7] = unaff_D7;
    d[4] = unaff_D4;
    d[5] = unaff_D5;
    d[2] = unaff_D2;
    d[3] = unaff_D3;
    d[0] = 3;
    d[1] = extraout_D1;
    a[3] = unaff_A4;
    a[4] = unaff_A5;
    a[2] = (register_t)unaff_A3;
    a[0] = extraout_A1;
    a[1] = unaff_A2;
    main_save_registers_into_stack(main_unk_11, d, a);
    d_00[6] = unaff_D6;
    d_00[7] = unaff_D7;
    d_00[4] = unaff_D4;
    d_00[5] = unaff_D5;
    d_00[2] = unaff_D2;
    d_00[3] = unaff_D3;
    d_00[0] = 2;
    d_00[1] = extraout_D1_00;
    a_00[3] = unaff_A4;
    a_00[4] = unaff_A5;
    a_00[2] = (register_t)unaff_A3;
    a_00[0] = extraout_A1_00;
    a_00[1] = unaff_A2;
    main_save_registers_into_stack(main_unk_2, d_00, a_00);
    d_01[6] = unaff_D6;
    d_01[7] = unaff_D7;
    d_01[4] = unaff_D4;
    d_01[5] = unaff_D5;
    d_01[2] = unaff_D2;
    d_01[3] = unaff_D3;
    d_01[0] = 4;
    d_01[1] = extraout_D1_01;
    a_01[3] = unaff_A4;
    a_01[4] = unaff_A5;
    a_01[2] = (register_t)unaff_A3;
    a_01[0] = extraout_A1_01;
    a_01[1] = unaff_A2;
    main_save_registers_into_stack(main_unk_3, d_01, a_01);
    return extraout_D0;
  }
  *(undefined2 *)((int)unaff_A6 + -2) = 6;
  DAT_ffff96bc = 0xff;
  DAT_ffff96b0 = 0;
  vdp_set_window_position(0);
  FUN_0000bce8();
  d_04[6] = unaff_D6;
  d_04[7] = unaff_D7;
  d_04[4] = unaff_D4;
  d_04[5] = unaff_D5;
  d_04[2] = unaff_D2;
  d_04[3] = unaff_D3;
  d_04[0] = 4;
  d_04[1] = extraout_D1_05;
  a_04[3] = unaff_A4;
  a_04[4] = unaff_A5;
  a_04[2] = (register_t)unaff_A3;
  a_04[0] = extraout_A1_04;
  a_04[1] = unaff_A2;
  main_save_registers_into_stack(main_unk_3, d_04, a_04);
  if ((DAT_ffff96bc & 4) == 0) {
    FUN_0000bd48();
  } else {
    FUN_00156068();
    DAT_ffffcc93 = 0;
  }
  vdp_write_something_to_vram();
  DAT_ffff9154 = 4;
  DAT_ffff9156 = 0xff;
  d_02[0] = 3;
  d_02[1] = extraout_D1_02;
  d_02[4] = unaff_D4;
  d_02[5] = unaff_D5;
  d_02[6] = unaff_D6;
  d_02[7] = unaff_D7;
  d_02[2] = unaff_D2;
  d_02[3] = unaff_D3;
  a_02[2] = (register_t)unaff_A3;
  a_02[3] = unaff_A4;
  a_02[4] = unaff_A5;
  a_02[0] = extraout_A1_02;
  a_02[1] = unaff_A2;
  main_save_registers_into_stack(main_unk_13, d_02, a_02);
  d_03[0] = 2;
  d_03[1] = extraout_D1_03;
  d_03[4] = unaff_D4;
  d_03[5] = unaff_D5;
  d_03[6] = unaff_D6;
  d_03[7] = unaff_D7;
  d_03[2] = unaff_D2;
  d_03[3] = unaff_D3;
  a_03[2] = (register_t)unaff_A3;
  a_03[3] = unaff_A4;
  a_03[4] = unaff_A5;
  a_03[0] = extraout_A1_03;
  a_03[1] = unaff_A2;
  main_save_registers_into_stack(main_unk_2, d_03, a_03);
  uVar3 = CONCAT44(extraout_D0_00, extraout_D1_04);
  while (true) {
    lVar2 = (long)uVar3;
    if (DAT_ffff9154 == -1) {
      uVar3 = FUN_00000472((ulong)unaff_A6, 3, lVar2);
      return (int)((ulonglong)uVar3 >> 0x20);
    }
    if (DAT_ffff9154 == 0)
      break;
    gamepad_held = gamepad_held_4;
    uVar3 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar3 >> 0x20),
                            lVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  }
  FUN_00000472((ulong)unaff_A6, 3, lVar2);
  *(undefined2 *)((int)unaff_A6 + -2) = 0;
  uVar1 = main_unk_4();
  return uVar1;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined8 main_unk_11(void)

{
  short sVar1;
  undefined2 extraout_D0u;
  long lVar2;
  undefined4 extraout_D0;
  long extraout_D1;
  long lVar3;
  undefined4 extraout_D1_00;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  void *extraout_A1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  byte *unaff_A5;
  void *unaff_A6;
  undefined8 uVar4;

  DAT_ffff91ce._0_1_ = 0xff;
  text_unk_3();
  FUN_00001580();
  FUN_00001646();
  DAT_ffff91ce._0_1_ = 0;
  vdp_hblank_effect_asha_p = 0;
  vdp_gfx_ptr_5._0_2_ = 0;
  vdp_hblank_effect_pepelogoo_p = 0;
  vdp_gfx_ptr_6 = 0;
  vdp_related_to_display_asha = 0xf;
  text_unk_2(extraout_A1);
  FUN_00002dc4();
  get_io_pcbver_with_z80_locked();
  _DAT_ffffc6fc = 0xff80;
  _DAT_ffffc6fe = 0xff80;
  FUN_00002de4(unaff_A5);
  FUN_00002e4a();
  FUN_00002f5a();
  DAT_ffff9156 = 0xff;
  DAT_ffff91a0 = 0;
  FUN_0000333a();
  FUN_0000355a();
  FUN_00002f9a();
  lVar2 = CONCAT22(extraout_D0u, 0x3c);
  lVar3 = extraout_D1;
  do {
    uVar4 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            lVar2,
                            lVar3,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    lVar3 = (long)uVar4;
    sVar1 = (short)lVar2 + -1;
    lVar2 = CONCAT22((short)((ulonglong)uVar4 >> 0x30), sVar1);
  } while (sVar1 != 0);
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar4 = CONCAT44(extraout_D0, extraout_D1_00);
  do {
    uVar4 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar4 >> 0x20),
                            (long)uVar4,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (palette_fade_done_0 == 0);
  DAT_ffff9154 = 0xffff;
  uVar4 = FUN_0000140c();
  uVar4 = exception_unk_0(unaff_A3,
                          unaff_A4,
                          unaff_A6,
                          (long)((ulonglong)uVar4 >> 0x20),
                          (long)uVar4,
                          0xf,
                          -1,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar4;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00002dc4(void)

{
  compressed_data_indices[0] = 0x1be;
  _DAT_ffff9a0c = 0x1bf;
  DAT_ffff9a0e._0_2_ = 0x3a0;
  DAT_ffff9a0e._2_2_ = 0x3a1;
  uncompress_and_copy_to_vram();
  return;
}

void FUN_00002de4(byte *param_1)

{
  entity_reset(ENTITY_ID_08);
  DAT_ffffa332 = 4;
  DAT_ffff9f24 = 0xc;
  DAT_ffffa12a = 0x80;
  DAT_ffffa22e = 0x80;
  DAT_ffffa63e = 0x18;
  DAT_ffffa63f = 0x10;
  ecs_anim_unk_2(ENTITY_ID_08, param_1, 0);
  entity_reset(ENTITY_ID_0C);
  DAT_ffffa336 = 4;
  DAT_ffff9f28 = 0xc;
  DAT_ffffa12e = 0x80;
  DAT_ffffa232 = 0x80;
  DAT_ffffa642 = 0x18;
  DAT_ffffa643 = 0x10;
  ecs_anim_unk_2(ENTITY_ID_0C, param_1, 2);
  return;
}

void FUN_00002e4a(void)

{
  anim_item_t *unaff_A5;

  entity_reset(ENTITY_ID_PEPELOGOO);
  component_unknown_3_pepelogoo = 10;
  DAT_ffffa32e = 4;
  component_pos_x_pepelogoo.fixed.i = 0;
  component_pos_y_pepelogoo.fixed.i = 0x100;
  DAT_ffffa63a = 0x18;
  DAT_ffffa63b = 0x10;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 6);
  entity_reset(0x10);
  DAT_ffff9f2c = 10;
  DAT_ffffa33a = 4;
  DAT_ffffa132 = 0;
  DAT_ffffa236 = 0x100;
  DAT_ffffa646 = 0x18;
  DAT_ffffa647 = 0x10;
  DAT_ffff9f2b = DAT_ffff9f2b | 4;
  DAT_ffffab52 = 0;
  DAT_ffffab53 = 0;
  ecs_anim_unk_2(0x10, unaff_A5, 6);
  entity_reset(0x14);
  DAT_ffff9f30 = 10;
  DAT_ffffa33e = 4;
  DAT_ffffa136 = 0;
  DAT_ffffa23a = 0x100;
  DAT_ffffa64a = 0x18;
  DAT_ffffa64b = 0x10;
  DAT_ffff9f2f = DAT_ffff9f2f | 4;
  DAT_ffffab56 = 1;
  DAT_ffffab57 = 0;
  ecs_anim_unk_2(0x14, unaff_A5, 6);
  DAT_ffff91ba = 10;
  DAT_ffff91bc = 10;
  DAT_ffff91be = 10;
  DAT_ffff91c0 = 10;
  DAT_ffff91c2 = 10;
  DAT_ffff91c4 = 10;
  DAT_ffff91a2 = 0;
  DAT_ffff91a4 = 0;
  DAT_ffff91a6 = 0;
  DAT_ffff91a8 = 0;
  DAT_ffff91aa = 0;
  DAT_ffff91ac = 0;
  DAT_ffff91ae = 0x100;
  DAT_ffff91b0 = 0x100;
  DAT_ffff91b2 = 0x100;
  DAT_ffff91b4 = 0x100;
  DAT_ffff91b6 = 0x100;
  DAT_ffff91b8 = 0x100;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00002f5a(void)

{
  undefined2 extraout_D0u;
  long extraout_D0;
  undefined4 extraout_D0_00;
  long extraout_D1;
  undefined4 extraout_D1_00;
  undefined4 unaff_D2;
  palette_id_flag_t palettes;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  _DAT_ffff9812 = 0x5f0200;
  vdp_palettes_something();
  palettes = CONCAT22((short)((uint)unaff_D2 >> 0x10), 0xf);
  palette_set_fade(palettes,
                   CONCAT22(extraout_D0u, 3),
                   '\0',
                   (palette_color_iter_t)0xffffffff);
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  extraout_D0,
                  extraout_D1,
                  palettes,
                  -1,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_OUT,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar1 = CONCAT44(extraout_D0_00, extraout_D1_00);
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (palette_fade_done_0 == 0);
  return;
}

undefined4 FUN_00002f9a(void)

{
  undefined4 in_D0;
  long extraout_D0;
  undefined4 in_D1;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  undefined8 uVar1;
  short palette_offset;
  short local_6;

  uVar1 = CONCAT44(in_D0, in_D1);
  palette_offset = 0x26;
  do {
    local_6 = 2;
    do {
      uVar1 = exception_unk_0(unaff_A3,
                              unaff_A4,
                              &stack0xfffffffc,
                              (long)((ulonglong)uVar1 >> 0x20),
                              (long)uVar1,
                              unaff_D2,
                              unaff_D3,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
      local_6 = local_6 + -1;
    } while (local_6 != 0);
    vdp_load_some_colors_to_palettes(palette_offset);
    palette_offset = palette_offset + -2;
    related_to_palettes = 0xff;
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            &stack0xfffffffc,
                            extraout_D0,
                            extraout_D1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (palette_offset != 0);
  local_6 = 2;
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            &stack0xfffffffc,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    local_6 = local_6 + -1;
  } while (local_6 != 0);
  return 0x280;
}

// Sets the the first palette.
// The first 2 colors are set to 0.
// Then, colors 2 to 11 (10 colors) are copied from the table starting at the
// given positive offset. If the offset is large enough, it can write to later
// palettes (there are 4 palettes of 16 colors), so the max offset shoud be
// something like 64 colors - 10 colors - 2 colors * 2 bytes per color = 104 (or
// #68).

void vdp_load_some_colors_to_palettes(short palette_offset)

{
  short i;
  vdp_color_t *dst;
  vdp_color_t *src;

  vdp_palettes[0][0] = 0;
  vdp_palettes[0][1] = 0;
  if (palette_offset < 0) {
    palette_offset = 0;
  }
  // dst is &vdp_palettes[0][2] IIUC.
  i = 10;
  dst = vdp_palettes[0] + 2;
  src = (vdp_color_t *)((int)vdp_color_t_ARRAY_0000301e + (int)palette_offset);
  do {
    *dst = *src;
    i = i + -1;
    dst = dst + 1;
    src = src + 1;
  } while (i != -1);
  return;
}

undefined8 FUN_0000305c(void)

{
  undefined2 in_D0w;
  undefined2 in_D1w;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  uint uVar1;
  long unaff_D7;
  short sVar2;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar3;

  DAT_ffff9168 = 0;
  DAT_ffff9164 = in_D0w;
  DAT_ffff9166 = in_D1w;
  do {
    unaff_D7 = CONCAT22((short)((uint)unaff_D7 >> 0x10), DAT_ffff9166);
    uVar1 = 0;
    do {
      FUN_0000308e();
      uVar3 = FUN_0000309c();
      uVar1 = (uint)(ushort)((short)uVar1 + 1);
      sVar2 = (short)unaff_D7 + -1;
      unaff_D7 = CONCAT22((short)((uint)unaff_D7 >> 0x10), sVar2);
    } while (sVar2 != -1);
    uVar3 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar3 >> 0x20),
                            (long)uVar3,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            uVar1,
                            unaff_D7);
    DAT_ffff9168 = DAT_ffff9168 + 1;
  } while (DAT_ffff9168 != 0x40);
  return uVar3;
}

short FUN_0000308e(void)

{
  return DAT_ffff9164 << 8;
}

void FUN_0000309c(void)

{
  ushort uVar1;
  word wVar2;
  word extraout_D1w;
  short unaff_D2w;

  uVar1 =
      *(ushort *)((int)WORD_ARRAY_000030ee + (int)(short)(DAT_ffff9168 * 2));
  FUN_00001502();
  wVar2 = VDP_DATA;
  vdp_set_vram_write_addr((void *)(((uVar1 & 0xfffc) >> 1) + unaff_D2w));
  VDP_DATA = extraout_D1w;
  return;
}

undefined1 get_io_pcbver_with_z80_locked(void)

{
  undefined1 uVar1;
  byte is_busy;
  word old_state;

  old_state = IO_Z80BUS;
  IO_Z80BUS = IO_Z80BUS_LOCK;
  do {
    is_busy = IO_Z80BUS._0_1_;
  } while ((is_busy & 1) != 0);
  uVar1 = IO_PCBVER._1_1_;
  IO_Z80BUS = ~old_state;
  return uVar1;
}

void FUN_00003196(void)

{
  undefined2 extraout_D0u;
  uint in_D0;
  long extraout_D0;
  long extraout_D1;
  long unaff_D2;
  palette_id_flag_t palettes;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  uint unaff_D7;
  uint uVar1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar2;

  uVar1 = unaff_D7 | 6;
  if ((in_D0 & 0x40) != 0) {
    return;
  }
  clear_unk_1();
  FUN_0000ba1a();
  uVar2 = vdp_write_something_to_vram();
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar2 >> 0x20),
                  (long)uVar2,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  uVar1);
  VDP_CTRL = 0x8c81;
  DAT_ffff9812 = 1;
  DAT_ffff9813 = 1;
  DAT_ffff9814 = 1;
  DAT_ffff9815 = 1;
  vdp_palettes_something();
  palettes = CONCAT22((short)((uint)unaff_D2 >> 0x10), 0xf);
  palette_set_fade(palettes,
                   CONCAT22(extraout_D0u, 1),
                   '\0',
                   (palette_color_iter_t)0xffffffff);
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  extraout_D0,
                  extraout_D1,
                  palettes,
                  -1,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  uVar1);
  uVar2 = FUN_00003208();
  related_to_palette_maybe_2 = 0xff;
  related_to_palette_maybe_1 = 0;
  do {
    uVar2 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar2 >> 0x20),
                            (long)uVar2,
                            palettes,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            uVar1);
  } while (true);
}

void FUN_000031de(void)

{
  undefined4 in_D0;
  long extraout_D0;
  long extraout_D1;
  undefined4 unaff_D2;
  palette_id_flag_t palettes;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  palettes = CONCAT22((short)((uint)unaff_D2 >> 0x10), 0xf);
  palette_set_fade(palettes,
                   CONCAT22((short)((uint)in_D0 >> 0x10), 1),
                   '\0',
                   (palette_color_iter_t)0xffffffff);
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  extraout_D0,
                  extraout_D1,
                  palettes,
                  -1,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  uVar1 = FUN_00003208();
  related_to_palette_maybe_2 = 0xff;
  related_to_palette_maybe_1 = 0;
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            palettes,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (true);
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00003208(void)

{
  sized_string_t *string;
  sized_string_t *string_00;
  sized_string_t *string_01;
  sized_string_t *string_02;
  sized_string_t *string_03;

  _DAT_ffff9a82 = 0x40;
  _DAT_ffff9a84 = 0x41;
  _DAT_ffff9a86 = 0x42;
  _DAT_ffff9a88 = 0x43;
  uncompress_and_copy_to_vram();
  vdp_set_vram_write_addr((void *)0xc408);
  vdp_load_sized_string(string);
  vdp_set_vram_write_addr((void *)0xc508);
  vdp_load_sized_string(string_00);
  vdp_set_vram_write_addr((void *)0xc608);
  vdp_load_sized_string(string_01);
  vdp_set_vram_write_addr((void *)0xc708);
  vdp_load_sized_string(string_02);
  vdp_set_vram_write_addr((void *)0xc808);
  vdp_load_sized_string(string_03);
  return;
}

void FUN_0000333a(void)

{
  short sVar1;
  int iVar2;
  int unaff_A4;

  while (true) {
    iVar2 = (int)(short)(DAT_ffff91a0 << 2);
    DAT_ffff917e = (uint) * (ushort *)((int)&WORD_000033ca + iVar2) << 0x10;
    DAT_ffff918e = (uint) * (ushort *)((int)&WORD_000033cc + iVar2) << 0x10;
    DAT_ffff9182 = (uint) * (ushort *)((int)&WORD_000033ce + iVar2) << 0x10;
    DAT_ffff9192 = (uint) * (ushort *)((int)&WORD_000033d0 + iVar2) << 0x10;
    DAT_ffff9186 = (uint) * (ushort *)((int)&WORD_000033d2 + iVar2) << 0x10;
    DAT_ffff9196 = (uint) * (ushort *)((int)&WORD_000033d4 + iVar2) << 0x10;
    DAT_ffff918a = (uint) * (ushort *)((int)&WORD_000033d6 + iVar2) << 0x10;
    DAT_ffff919a = (uint) * (ushort *)((int)&WORD_000033d8 + iVar2) << 0x10;
    sVar1 =
        *(short *)((int)WORD_ARRAY_00003416 + (int)(short)(DAT_ffff91a0 * 2));
    if (sVar1 < 0)
      break;
    DAT_ffff919e = sVar1;
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) =
        *(undefined2 *)((int)WORD_ARRAY_00003438 +
                        (int)(short)(DAT_ffff91a0 * 2));
    FUN_000035f0();
    DAT_ffff91a0 = DAT_ffff91a0 + 1;
  }
  return;
}

void FUN_0000345c(void)

{
  short sVar1;
  int iVar2;
  int unaff_A4;

  DAT_ffff91a0 = 0;
  while (true) {
    iVar2 = (int)(short)(DAT_ffff91a0 << 2);
    DAT_ffff917e = (uint) * (ushort *)((int)&WORD_000034f0 + iVar2) << 0x10;
    DAT_ffff918e = (uint) * (ushort *)((int)&WORD_000034f2 + iVar2) << 0x10;
    DAT_ffff9182 = (uint) * (ushort *)((int)&WORD_000034f4 + iVar2) << 0x10;
    DAT_ffff9192 = (uint) * (ushort *)((int)&WORD_000034f6 + iVar2) << 0x10;
    DAT_ffff9186 = (uint) * (ushort *)((int)&WORD_000034f8 + iVar2) << 0x10;
    DAT_ffff9196 = (uint) * (ushort *)((int)&WORD_000034fa + iVar2) << 0x10;
    DAT_ffff918a = (uint) * (ushort *)((int)&WORD_000034fc + iVar2) << 0x10;
    DAT_ffff919a = (uint) * (ushort *)((int)WORD_ARRAY_000034fe + iVar2)
                   << 0x10;
    sVar1 =
        *(short *)((int)WORD_ARRAY_00003528 + (int)(short)(DAT_ffff91a0 * 2));
    if (sVar1 < 0)
      break;
    DAT_ffff919e = sVar1;
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) =
        *(undefined2 *)((int)WORD_ARRAY_0000353e +
                        (int)(short)(DAT_ffff91a0 * 2));
    FUN_00003612();
    DAT_ffff91a0 = DAT_ffff91a0 + 1;
  }
  return;
}

void FUN_0000355a(void)

{
  short sVar1;
  undefined2 extraout_D0u;
  undefined4 uVar2;
  long lVar3;
  long extraout_D1;
  long lVar4;
  long extraout_D1_00;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;
  void *unaff_A6;
  undefined8 uVar5;

  uVar5 = FUN_0000358a();
  comp_vel[1].y.raw = -0x668;
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar5 >> 0x20),
                    (long)uVar5,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_000035a2();
    uVar2 = FUN_000035b6(unaff_A5);
    uVar5 = CONCAT44(uVar2, extraout_D1);
  } while ((short)uVar2 != 0);
  lVar3 = CONCAT22((short)((uint)uVar2 >> 0x10), 0x1e);
  lVar4 = extraout_D1;
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    lVar3,
                    lVar4,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_000035a2();
    sVar1 = (short)lVar3 + -1;
    lVar3 = CONCAT22(extraout_D0u, sVar1);
    lVar4 = extraout_D1_00;
  } while (sVar1 != 0);
  return;
}

void FUN_0000358a(void)

{
  comp_vel[3].y.raw = 0x668;
  DAT_ffffbd84 = DAT_ffffa232;
  DAT_ffffbd82 = DAT_ffffa12e;
  return;
}

void FUN_000035a2(void)

{
  FUN_00003686();
  ecs_update_pos_y(ENTITY_ID_PEPELOGOO);
  comp_vel[1].y.raw = comp_vel[1].y.raw + -0x40;
  return;
}

undefined4 FUN_000035b6(entity_id_t self)

{
  ecs_update_pos_y(ENTITY_ID_0C);
  if ((comp_vel[3].y.raw == 0) ||
      ((comp_vel[3].y.raw < 0 && (DAT_ffffa644 != '\x04')))) {
    ecs_anim_unk_2(ENTITY_ID_0C, (anim_item_t *)self, 4);
  }
  if (-0x668 < comp_vel[3].y.raw) {
    comp_vel[3].y.raw = comp_vel[3].y.raw + -0xa4;
    return 0xffffffff;
  }
  audio_play(SOUND_ID_ITEM_GET);
  return 0;
}

void FUN_000035f0(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  DAT_ffff916a = 0;
  do {
    uVar1 = FUN_0000366e();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    DAT_ffff916a = DAT_ffff919e + DAT_ffff916a;
  } while (DAT_ffff916a < 0x10000);
  return;
}

void FUN_00003612(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  DAT_ffff916a = 0;
  do {
    uVar1 = FUN_0000364e();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_00014722();
    unaff_A4 = ENTITY_ID_PEPELOGOO;
    DAT_ffffb97b = DAT_ffffb97b + -1;
    if (DAT_ffffb97b == '\0') {
      DAT_ffffb97b = '\n';
      FUN_0000185e();
    }
    DAT_ffff916a = DAT_ffff919e + DAT_ffff916a;
  } while (DAT_ffff916a < 0x10000);
  return;
}

void FUN_0000364e(void)

{
  int unaff_D4;
  int unaff_D5;

  FUN_00003720();
  component_pos_x_pepelogoo.raw = unaff_D4 + 0x11800000;
  component_pos_y_pepelogoo.raw = 0x10400000 - unaff_D5;
  return;
}

void FUN_0000366e(void)

{
  fixed_t unaff_D4;
  int unaff_D5;

  FUN_00003686();
  FUN_00003720();
  component_pos_x_pepelogoo = unaff_D4;
  component_pos_y_pepelogoo.raw = -unaff_D5;
  return;
}

void FUN_00003686(void)

{
  DAT_ffff9f30 = DAT_ffff91c2;
  DAT_ffff9f2c = DAT_ffff91bc;
  DAT_ffffa23a = DAT_ffff91b6;
  DAT_ffffa236 = DAT_ffff91b0;
  DAT_ffffa136 = DAT_ffff91aa;
  DAT_ffffa132 = DAT_ffff91a4;
  DAT_ffff91c4 = DAT_ffff91c2;
  DAT_ffff91c2 = DAT_ffff91c0;
  DAT_ffff91c0 = DAT_ffff91be;
  DAT_ffff91be = DAT_ffff91bc;
  DAT_ffff91bc = DAT_ffff91ba;
  DAT_ffff91ba = component_unknown_3_pepelogoo;
  DAT_ffff91ac = DAT_ffff91aa;
  DAT_ffff91aa = DAT_ffff91a8;
  DAT_ffff91a8 = DAT_ffff91a6;
  DAT_ffff91a6 = DAT_ffff91a4;
  DAT_ffff91a4 = DAT_ffff91a2;
  DAT_ffff91a2 = component_pos_x_pepelogoo.fixed.i;
  DAT_ffff91b8 = DAT_ffff91b6;
  DAT_ffff91b6 = DAT_ffff91b4;
  DAT_ffff91b4 = DAT_ffff91b2;
  DAT_ffff91b2 = DAT_ffff91b0;
  DAT_ffff91b0 = DAT_ffff91ae;
  DAT_ffff91ae = component_pos_y_pepelogoo.fixed.i;
  return;
}

void FUN_00003720(void)

{
  int iVar1;
  int iVar2;
  int iVar3;
  int iVar4;

  FUN_000037a8();
  FUN_000037d8();
  FUN_00003804();
  FUN_0000382c();
  iVar1 = DAT_ffff917e;
  FUN_0000385a();
  iVar2 = DAT_ffff9182;
  FUN_0000385a();
  iVar3 = DAT_ffff9186;
  FUN_0000385a();
  iVar4 = DAT_ffff918a;
  FUN_0000385a();
  FUN_0000385a(iVar4 + iVar3 + iVar2 + iVar1);
  FUN_0000385a();
  FUN_0000385a();
  FUN_0000385a();
  return;
}

void FUN_000037a8(void)

{
  int iVar1;

  iVar1 = DAT_ffff916a + -0x20000;
  FUN_0000385a();
  FUN_0000385a();
  FUN_0000385a();
  DAT_ffff916e = iVar1;
  return;
}

void FUN_000037d8(void)

{
  int iVar1;

  iVar1 = DAT_ffff916a + -0x10000;
  FUN_0000385a();
  FUN_0000385a();
  DAT_ffff9172 = iVar1 >> 1;
  return;
}

void FUN_00003804(void)

{
  int iVar1;

  iVar1 = DAT_ffff916a;
  FUN_0000385a();
  FUN_0000385a();
  DAT_ffff9176 = iVar1 >> 1;
  return;
}

void FUN_0000382c(void)

{
  undefined4 uVar1;

  uVar1 = DAT_ffff916a;
  FUN_0000385a();
  FUN_0000385a();
  FUN_0000385a();
  DAT_ffff917a = uVar1;
  return;
}

void FUN_0000385a(void)

{
  return;
}

void main_unk_3(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  do {
    FUN_000038d8();
    FUN_000038e2();
    FUN_000038ea();
    FUN_000038d2();
    uVar1 = FUN_000038f8();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  } while (true);
}

void FUN_000038ce(void)

{
  return;
}

void FUN_000038d0(void)

{
  return;
}

void FUN_000038d2(void)

{
  FUN_00000986();
  return;
}

void FUN_000038d8(void)

{
  palette_update_effect_all();
  palette_update();
  return;
}

void FUN_000038e2(void)

{
  FUN_0000aca6();
  return;
}

void FUN_000038ea(void)

{
  if (DAT_ffff91c6 == '\0') {
    FUN_0000ae60();
  }
  return;
}

void FUN_000038f8(void)

{
  if (related_to_palette_maybe_2 != '\0') {
    related_to_palette_maybe_2 = '\0';
    related_to_palette_maybe_1 = '\0';
    DAT_ffff968d = 0xff;
  }
  if (related_to_palette_maybe_1 != '\0') {
    related_to_palette_maybe_1 = '\0';
    DAT_ffff968b = 0xff;
  }
  return;
}

void vdp_init_and_clear_gamepad(void)

{
  word i;
  union2_t *vdp_reg;

  vdp_ctrl_mode_set_2_state = VDP_REG_MODE_SET_2;
  // Clear the VRAM.
  vdp_vram_fill(0, (void *)0x0, 0xffff, 1);
  i = 0xe;
  vdp_reg = (union2_t *)&vdp_init_table;
  do {
    VDP_CTRL = (union2_t)vdp_reg->w;
    i = i - 1;
    vdp_reg = vdp_reg + 1;
  } while (i != 0xffff);
  gamepad_pressed_prev = GAMEPAD_NONE;
  gamepad_held_prev = GAMEPAD_NONE;
  gamepad_pressed = GAMEPAD_NONE;
  gamepad_held_3 = GAMEPAD_NONE;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined8 VBLANK(void)

{
  byte bVar1;
  char cVar2;
  word wVar3;
  union2_t uVar4;
  ulong in_D0;
  undefined4 uVar5;
  undefined4 extraout_D0;
  undefined4 extraout_D0_00;
  undefined4 extraout_D0_01;
  undefined4 extraout_D0_02;
  undefined4 extraout_D0_03;
  undefined4 extraout_D0_04;
  undefined4 in_D1;
  undefined4 extraout_D1;
  undefined4 extraout_D1_00;
  undefined4 extraout_D1_01;
  undefined4 uVar6;
  undefined4 extraout_D1_02;
  undefined4 extraout_D1_03;
  undefined4 extraout_D1_04;
  undefined4 extraout_D1_05;
  undefined4 extraout_D1_06;
  undefined4 extraout_D1_07;
  undefined4 unaff_D2;
  undefined4 unaff_D3;
  undefined4 unaff_D4;
  undefined4 unaff_D5;
  undefined4 unaff_D6;
  undefined4 unaff_D7;
  undefined4 in_A1;
  undefined4 extraout_A1;
  undefined4 extraout_A1_00;
  undefined4 extraout_A1_01;
  undefined4 extraout_A1_02;
  undefined4 extraout_A1_03;
  undefined4 extraout_A1_04;
  undefined4 extraout_A1_05;
  undefined4 extraout_A1_06;
  undefined4 extraout_A1_07;
  undefined4 extraout_A1_08;
  undefined4 extraout_A1_09;
  undefined4 unaff_A2;
  undefined4 unaff_A3;
  undefined4 unaff_A4;
  undefined4 unaff_A5;
  undefined4 unaff_A6;
  undefined8 uVar7;
  register_t d[8];
  register_t a[6];
  ulong uVar8;
  undefined4 uVar9;

  DAT_ffff91ca = DAT_ffff91ca + 1;
  _DAT_ffff91cc = 0;
  uVar8 = in_D0;
  uVar9 = in_D1;
  if (DAT_ffff91ce._0_1_ != '\0')
    goto LAB_00003b8c;
  if (DAT_ffff968d == '\0') {
    if (DAT_ffff968b != '\0') {
      vdp_ctrl_mode_set_2_state = vdp_ctrl_mode_set_2_state & 0xffbf;
      goto LAB_000039ba;
    }
  } else {
    DAT_ffff968d = '\0';
    vdp_ctrl_mode_set_2_state = vdp_ctrl_mode_set_2_state | 0x40;
  LAB_000039ba:
    DAT_ffff968b = '\0';
    VDP_CTRL = (union2_t)vdp_ctrl_mode_set_2_state;
  }
  wVar3 = IO_Z80BUS;
  IO_Z80BUS = IO_Z80BUS_LOCK;
  do {
    bVar1 = IO_Z80BUS._0_1_;
  } while ((bVar1 & 1) != 0);
  IO_CT1_CTRL._1_1_ = 0x40;
  IO_CT1_DATA._1_1_ = 0;
  cVar2 = IO_CT1_DATA._1_1_;
  IO_CT1_DATA._1_1_ = 0x40;
  bVar1 = IO_CT1_DATA._1_1_;
  gamepad_held_4 = ~(bVar1 & 0x3f | cVar2 * '\x04' & 0xc0U);
  gamepad_pressed = gamepad_held_4 & (gamepad_held_4 ^ gamepad_held_3);
  IO_CT2_CTRL._1_1_ = 0x40;
  IO_CT2_DATA._1_1_ = 0;
  cVar2 = IO_CT2_DATA._1_1_;
  IO_CT2_DATA._1_1_ = 0x40;
  bVar1 = IO_CT2_DATA._1_1_;
  DAT_ffff915f = ~(bVar1 & 0x3f | cVar2 * '\x04' & 0xc0U);
  DAT_ffff915d = DAT_ffff915f & (DAT_ffff915f ^ DAT_ffff915e);
  unaff_D3 = CONCAT22((short)((uint)unaff_D3 >> 0x10), ~wVar3);
  IO_Z80BUS = ~wVar3;
  gamepad_held_3 = gamepad_held_4;
  DAT_ffff915e = DAT_ffff915f;
  copy_first_few_entities_sprites_to_vram_maybe();
  copy_sprites_to_vram_maybe();
  uVar6 = extraout_D1;
  in_A1 = extraout_A1;
  uVar8 = in_D0;
  uVar9 = in_D1;
  if (related_to_palettes != '\0') {
    related_to_palettes = '\0';
    unaff_D2 = 3;
    vdp_copy(VDP_MEM_COLOR_RAM, vdp_palettes, (void *)0x0, 0x40, '\x02');
    uVar6 = extraout_D1_00;
    in_A1 = extraout_A1_00;
    uVar8 = in_D0;
    uVar9 = in_D1;
  }
  uVar5 = 0;
  if (DAT_ffffc719 != '\0') {
    entity_load_gfx_likely(ENTITY_ID_ASHA);
    DAT_ffffc719 = '\0';
    uVar5 = extraout_D0;
    uVar6 = extraout_D1_01;
    in_A1 = extraout_A1_01;
  }
  uVar7 = CONCAT44(uVar5, uVar6);
  if (DAT_ffffc718 != '\0') {
    uVar7 = FUN_0000b0e8();
    DAT_ffffc718 = '\0';
    in_A1 = extraout_A1_02;
  }
  unaff_A4 = 4;
  if (DAT_ffffc71d != '\0') {
    entity_load_gfx_likely(ENTITY_ID_PEPELOGOO);
    uVar7 = CONCAT44(extraout_D0_00, extraout_D1_02);
    DAT_ffffc71d = '\0';
    in_A1 = extraout_A1_03;
  }
  if (DAT_ffffc71c != '\0') {
    uVar7 = FUN_0000b0e8();
    DAT_ffffc71c = '\0';
    in_A1 = extraout_A1_04;
  }
  bVar1 = vdp_related_to_display_asha & 1;
  vdp_related_to_display_asha = vdp_related_to_display_asha & 0xfe;
  if (bVar1 != 0) {
    unaff_D2 = 1;
    vdp_copy(VDP_MEM_VIDEO_RAM,
             &vdp_hblank_effect_asha_p,
             (void *)0xffffd800,
             0x100,
             '\x04');
    uVar7 = CONCAT44(extraout_D0_01, extraout_D1_03);
    in_A1 = extraout_A1_05;
  }
  bVar1 = vdp_related_to_display_asha & 2;
  vdp_related_to_display_asha = vdp_related_to_display_asha & 0xfd;
  if (bVar1 != 0) {
    unaff_D2 = 1;
    vdp_copy(VDP_MEM_VIDEO_RAM,
             &vdp_hblank_effect_pepelogoo_p,
             (void *)0xffffd802,
             0x100,
             '\x04');
    uVar7 = CONCAT44(extraout_D0_02, extraout_D1_04);
    in_A1 = extraout_A1_06;
  }
  bVar1 = vdp_related_to_display_asha & 4;
  vdp_related_to_display_asha = vdp_related_to_display_asha & 0xfb;
  if (bVar1 != 0) {
    unaff_D2 = 5;
    vdp_copy(VDP_MEM_VSCROLL_RAM, &vdp_gfx_ptr_5, (void *)0x0, 0x14, '\x04');
    uVar7 = CONCAT44(extraout_D0_03, extraout_D1_05);
    in_A1 = extraout_A1_07;
  }
  bVar1 = vdp_related_to_display_asha & 8;
  vdp_related_to_display_asha = vdp_related_to_display_asha & 0xf7;
  if (bVar1 != 0) {
    unaff_D2 = 5;
    vdp_copy(VDP_MEM_VSCROLL_RAM,
             &vdp_gfx_ptr_6,
             BYTE_ARRAY_00000000 + 2,
             0x14,
             '\x04');
    uVar7 = CONCAT44(extraout_D0_04, extraout_D1_06);
    in_A1 = extraout_A1_08;
  }
  in_D0 = (ulong)((ulonglong)uVar7 >> 0x20);
  in_D1 = (undefined4)uVar7;
  if (vdp_related_to_display_1 != '\0') {
    uVar4 = VDP_CTRL;
    in_D0 = CONCAT22((short)((ulonglong)uVar7 >> 0x30), uVar4.w);
    VDP_CTRL = (union2_t)DAT_ffff9630.w;
    VDP_CTRL = 0x8014;
    vdp_related_to_display_1 = '\0';
  }
  if (DAT_ffff96b0 != '\0') {
    in_D0 = (*PTR_ffff96b6)();
    in_D1 = extraout_D1_07;
    in_A1 = extraout_A1_09;
  }
LAB_00003b8c:
  DAT_ffff968e = 0;
  d[6] = unaff_D6;
  d[7] = unaff_D7;
  d[4] = unaff_D4;
  d[5] = unaff_D5;
  d[2] = unaff_D2;
  d[3] = unaff_D3;
  d[0] = in_D0;
  d[1] = in_D1;
  a[4] = unaff_A5;
  a[5] = unaff_A6;
  a[1] = unaff_A2;
  a[2] = unaff_A3;
  a[3] = unaff_A4;
  a[0] = in_A1;
  uVar7 = exception_load_registers_from_stack(CONCAT44(uVar8, uVar9), d, a);
  return uVar7;
}

void copy_first_few_entities_sprites_to_vram_maybe(void)

{
  entity_id_t self;

  self = ENTITY_ID_ASHA;
  do {
    if ((&DAT_ffff9690)[self] != '\0') {
      (&DAT_ffff9690)[self] = 0;
      copy_sprites_to_vram_likely(self);
      self = (entity_id_t)(short)self;
    }
    self = self + ENTITY_ID_PEPELOGOO;
  } while (self < 0x10);
  return;
}

void copy_sprites_to_vram_likely(entity_id_t self)

{
  vdp_copy(VDP_MEM_VIDEO_RAM,
           *(void **)(&comp_vdp_gfx_ptr + self),
           (void *)(int)*(short *)(&DAT_ffff9692 + self),
           (ushort)(byte)(&DAT_ffff9691)[self] << 4,
           '\0');
  return;
}

void clear_unk_2(void)

{
  DAT_ffff9690 = 0;
  DAT_ffff9694 = 0;
  DAT_ffff9698 = 0;
  DAT_ffff969c = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 hblank_cb_something_1(void)

{
  int iVar1;
  vdp_draw_pos_t vVar2;
  undefined4 in_D0;

  vVar2 = VDP_DRAW_POS;
  if ((union2_t)((ushort)vVar2 >> 8) != (union2_t)_DAT_ffff962e) {
    return in_D0;
  }
  iVar1 = (int)(short)vdp_related_to_hblank_effects_2;
  if (-1 < DAT_ffff9629) {
    vdp_related_to_hblank_effects_2 = vdp_related_to_hblank_effects_2 + 2;
  }
  VDP_CTRL = 0x4000;
  VDP_CTRL = 0x10;
  VDP_DATA = vdp_gfx_ptr_5._0_2_ + *(short *)(iVar1 + -0x69ce);
  _DAT_ffff962e = _DAT_ffff962e + 1;
  if ((word)(vdp_related_to_hblank_y_pos_pepelogoo.w + 0x28) == _DAT_ffff962e) {
    DAT_ffff9629 = -1;
  }
  if ((word)(vdp_related_to_hblank_y_pos_pepelogoo.w + 0x50) == _DAT_ffff962e) {
    VDP_CTRL = 0x4000;
    VDP_CTRL = 0x10;
    VDP_DATA = vdp_gfx_ptr_5._0_2_;
    if (_DAT_ffff962c == 0x28) {
      DAT_ffff9628 = 0;
      _DAT_ffff962e = vdp_related_to_hblank_y_pos_pepelogoo;
      DAT_ffff9629 = 0;
      _DAT_ffff962a = 0xffff;
      _DAT_ffff962c = 0;
      return in_D0;
    }
    *(short *)(_DAT_ffff962c + -0x69ce) = _DAT_ffff962a;
    _DAT_ffff962e = vdp_related_to_hblank_y_pos_pepelogoo;
    vdp_related_to_hblank_effects_2 = 0;
    DAT_ffff9629 = '\0';
    _DAT_ffff962a = _DAT_ffff962a + -1;
    _DAT_ffff962c = _DAT_ffff962c + -1;
  }
  return in_D0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_00003c0a(undefined4 param_1)

{
  int iVar1;

  iVar1 = (int)(short)vdp_related_to_hblank_effects_2;
  if (-1 < DAT_ffff9629) {
    vdp_related_to_hblank_effects_2 = vdp_related_to_hblank_effects_2 + 2;
  }
  VDP_CTRL = 0x4000;
  VDP_CTRL = 0x10;
  VDP_DATA = vdp_gfx_ptr_5._0_2_ + *(short *)(iVar1 + -0x69ce);
  _DAT_ffff962e = _DAT_ffff962e + 1;
  if ((word)(vdp_related_to_hblank_y_pos_pepelogoo.w + 0x28) == _DAT_ffff962e) {
    DAT_ffff9629 = -1;
  }
  if ((word)(vdp_related_to_hblank_y_pos_pepelogoo.w + 0x50) == _DAT_ffff962e) {
    VDP_CTRL = 0x4000;
    VDP_CTRL = 0x10;
    VDP_DATA = vdp_gfx_ptr_5._0_2_;
    if (_DAT_ffff962c == 0x28) {
      DAT_ffff9628 = 0;
      _DAT_ffff962e = vdp_related_to_hblank_y_pos_pepelogoo;
      DAT_ffff9629 = 0;
      _DAT_ffff962a = 0xffff;
      _DAT_ffff962c = 0;
      return param_1;
    }
    *(short *)(_DAT_ffff962c + -0x69ce) = _DAT_ffff962a;
    _DAT_ffff962e = vdp_related_to_hblank_y_pos_pepelogoo;
    vdp_related_to_hblank_effects_2 = 0;
    DAT_ffff9629 = '\0';
    _DAT_ffff962a = _DAT_ffff962a + -1;
    _DAT_ffff962c = _DAT_ffff962c + -1;
  }
  return param_1;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 exception_something_2(undefined4 param_1)

{
  short in_D0w;

  vdp_related_to_hblank_effects_2 = vdp_related_to_hblank_effects_2 - 2;
  VDP_CTRL = 0x4000;
  VDP_CTRL = 0x10;
  VDP_DATA = vdp_gfx_ptr_5._0_2_ - in_D0w;
  _DAT_ffff962e = _DAT_ffff962e + 1;
  if ((word)(vdp_related_to_hblank_y_pos_pepelogoo.w + 0x28) == _DAT_ffff962e) {
    DAT_ffff9629 = 0xff;
  }
  if ((word)(vdp_related_to_hblank_y_pos_pepelogoo.w + 0x50) == _DAT_ffff962e) {
    VDP_CTRL = 0x4000;
    VDP_CTRL = 0x10;
    VDP_DATA = vdp_gfx_ptr_5._0_2_;
    if (_DAT_ffff962c == 0x28) {
      DAT_ffff9628 = 0;
      _DAT_ffff962e = vdp_related_to_hblank_y_pos_pepelogoo;
      DAT_ffff9629 = 0;
      _DAT_ffff962a = 0xffff;
      _DAT_ffff962c = 0;
      return param_1;
    }
    *(short *)(_DAT_ffff962c + -0x69ce) = _DAT_ffff962a;
    _DAT_ffff962e = vdp_related_to_hblank_y_pos_pepelogoo;
    vdp_related_to_hblank_effects_2 = 0;
    DAT_ffff9629 = 0;
    _DAT_ffff962a = _DAT_ffff962a + -1;
    _DAT_ffff962c = _DAT_ffff962c + -1;
  }
  return param_1;
}

undefined4 hblank_cb_something_3(void)

{
  vdp_draw_pos_t vVar1;
  undefined4 in_D0;

  vVar1 = VDP_DRAW_POS;
  if ((ushort)vVar1 >> 8 == vdp_related_to_hblank_y_pos_pepelogoo.w) {
    if ((ushort)vVar1 >> 8 == 0x80) {
      VDP_CTRL = 0x4000;
      VDP_CTRL = 0x10;
      VDP_DATA = 0;
      vdp_related_to_hblank_y_pos_pepelogoo.w = 0x20;
      if ((DAT_ffff9628 & 2) != 0) {
        DAT_ffff9628 = DAT_ffff9628 & 0xfd;
        DAT_ffff9628 = DAT_ffff9628 ^ 1;
      }
    } else {
      FUN_00003d2a();
    }
  }
  return in_D0;
}

word FUN_00003d2a(void)

{
  short sVar1;
  undefined *puVar2;

  sVar1 = vdp_related_to_hblank_y_pos_pepelogoo.w * 2;
  if ((DAT_ffff9628 & 1) == 0) {
    puVar2 = &DAT_ffffe252;
  } else {
    puVar2 = &DAT_ffffe392;
  }
  VDP_CTRL = 0x4000;
  VDP_CTRL = 0x10;
  VDP_DATA = *(word *)(puVar2 + sVar1);
  vdp_related_to_hblank_y_pos_pepelogoo.w =
      vdp_related_to_hblank_y_pos_pepelogoo.w + 1;
  return *(word *)(puVar2 + sVar1);
}

undefined4 hblank_cb_something_4(void)

{
  vdp_draw_pos_t vVar1;
  undefined4 in_D0;

  vVar1 = VDP_DRAW_POS;
  if ((ushort)vVar1 >> 8 == vdp_related_to_hblank_y_pos_pepelogoo.w) {
    if ((ushort)vVar1 >> 8 == 0x80) {
      VDP_CTRL = 0x4000;
      VDP_CTRL = 0x10;
      VDP_DATA = 0;
      vdp_related_to_hblank_y_pos_pepelogoo.w = 0x47;
      if ((DAT_ffff9628 & 2) != 0) {
        DAT_ffff9628 = DAT_ffff9628 & 0xfd;
        DAT_ffff9628 = DAT_ffff9628 ^ 1;
      }
    } else {
      FUN_00003dc0();
    }
  }
  return in_D0;
}

word FUN_00003dc0(void)

{
  short sVar1;
  undefined *puVar2;

  sVar1 = vdp_related_to_hblank_y_pos_pepelogoo.w - 0x47;
  if ((DAT_ffff9628 & 1) == 0) {
    puVar2 = &DAT_ffffe252;
  } else {
    puVar2 = &DAT_ffffe392;
  }
  VDP_CTRL = 0x4000;
  VDP_CTRL = 0x10;
  VDP_DATA = *(word *)(puVar2 + (short)(sVar1 * 2));
  vdp_related_to_hblank_y_pos_pepelogoo.w =
      vdp_related_to_hblank_y_pos_pepelogoo.w + 1;
  return *(word *)(puVar2 + (short)(sVar1 * 2));
}

void FUN_00003dfc(void)

{
  do {
    // WARNING: Do nothing block with infinite loop
  } while (true);
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined8 main_unk_12(void)

{
  undefined2 extraout_D0u;
  long extraout_D0;
  undefined4 extraout_D0_00;
  long extraout_D1;
  undefined4 extraout_D1_00;
  long unaff_D2;
  palette_id_flag_t palettes;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;
  ushort uStack_8;

  FUN_00001646();
  FUN_00001580();
  FUN_00001646();
  DAT_ffff96ba = 0xff;
  DAT_ffff91ce._0_1_ = 0;
  VDP_CTRL = 0x856e;
  VDP_CTRL = 0x8c81;
  vdp_hblank_effect_asha_p = 0;
  vdp_gfx_ptr_5._0_2_ = 0;
  vdp_hblank_effect_pepelogoo_p = 0;
  vdp_gfx_ptr_6 = 0;
  vdp_related_to_display_asha = 0xf;
  clear_unk_1();
  FUN_0000ba1a();
  uVar1 = vdp_write_something_to_vram();
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  &stack0xfffffffc,
                  (long)((ulonglong)uVar1 >> 0x20),
                  (long)uVar1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  _DAT_ffff9812 = 0x6f707172;
  vdp_palettes_something();
  audio_play(SOUND_ID_OVERTURE);
  palettes = CONCAT22((short)((uint)unaff_D2 >> 0x10), 0xf);
  palette_set_fade(palettes,
                   CONCAT22(extraout_D0u, 1),
                   '\0',
                   (palette_color_iter_t)0xffffffff);
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  &stack0xfffffffc,
                  extraout_D0,
                  extraout_D1,
                  palettes,
                  -1,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  FUN_00003ed0();
  FUN_00003f1c();
  uVar1 = FUN_00001630();
  DAT_ffff9156 = 0xff;
  for (uStack_8 = 0; uStack_8 < 0x1c2; uStack_8 = uStack_8 + 1) {
    if (uStack_8 == 0x1a4) {
      audio_play(SOUND_ID_FE);
      uVar1 = CONCAT44(extraout_D0_00, extraout_D1_00);
    }
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            &stack0xfffffffc,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            palettes,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  }
  audio_stop_all();
  uVar1 = FUN_00001646();
  DAT_ffff9154 = 0xffff;
  uVar1 = exception_unk_0(unaff_A3,
                          unaff_A4,
                          unaff_A6,
                          (long)((ulonglong)uVar1 >> 0x20),
                          (long)uVar1,
                          palettes,
                          -1,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar1;
}

void FUN_00003ed0(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  void *in_A1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  text_unk_1(BYTE_ARRAY_00003f08, in_A1);
  uVar1 = uncompress_and_copy_to_vram();
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar1 >> 0x20),
                  (long)uVar1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  DAT_ffff91ce._0_1_ = 0xff;
  something(BYTE_ARRAY_0000402c);
  something(BYTE_ARRAY_000044f2);
  DAT_ffff91ce._0_1_ = 0;
  return;
}

void FUN_00003f1c(void)

{
  anim_item_t *unaff_A5;

  entity_reset(ENTITY_ID_08);
  DAT_ffff9f23 = 0x80;
  DAT_ffffa63e = 0x18;
  DAT_ffffa63f = 0x2a;
  ecs_anim_unk_2(ENTITY_ID_08, unaff_A5, 0);
  DAT_ffffa12a = 0x80;
  DAT_ffffa22e = 0x80;
  DAT_ffffa332 = 4;
  entity_reset(ENTITY_ID_0C);
  DAT_ffff9f27 = 0x80;
  DAT_ffffa642 = 0x18;
  DAT_ffffa643 = 0x2a;
  ecs_anim_unk_2(ENTITY_ID_0C, unaff_A5, 10);
  DAT_ffffa12e = 0x80;
  DAT_ffffa232 = 0x80;
  DAT_ffffa336 = 4;
  entity_reset(0x10);
  DAT_ffffa646 = 0x18;
  DAT_ffffa647 = 0x2a;
  DAT_ffff9f2b = 0x84;
  DAT_ffffab52 = 0x76;
  DAT_ffffab53 = 0;
  ecs_anim_unk_2(0x10, unaff_A5, 2);
  DAT_ffffa132 = 0x80;
  DAT_ffffa236 = 0x80;
  DAT_ffffa33a = 4;
  return;
}

vdp_reg_t FUN_00003fc6(void)

{
  word wVar1;
  undefined1 uVar2;
  byte bVar3;
  byte *pbVar4;

  VDP_CTRL = (union2_t)(vdp_ctrl_mode_set_2_state | 0x20);
  wVar1 = IO_Z80BUS;
  IO_Z80BUS = IO_Z80BUS_LOCK;
  do {
    bVar3 = IO_Z80BUS._0_1_;
  } while ((bVar3 & 1) != 0);
  pbVar4 = BYTE_ARRAY_00004024;
  IO_CT1_CTRL._1_1_ = 0x40;
  bVar3 = 8;
  do {
    IO_CT1_DATA._1_1_ = *pbVar4;
    uVar2 = IO_CT1_DATA._1_1_;
    pbVar4 = pbVar4 + 2;
    bVar3 = bVar3 >> 1;
  } while (bVar3 != 0);
  IO_Z80BUS = ~wVar1;
  VDP_CTRL = (union2_t)vdp_ctrl_mode_set_2_state;
  return vdp_ctrl_mode_set_2_state;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined8 menu_title(void)

{
  byte bVar1;
  uint uVar2;
  uint uVar3;
  undefined2 extraout_D0u;
  undefined2 extraout_D0u_00;
  undefined2 extraout_D0u_01;
  long useless_d0;
  long extraout_D0;
  long extraout_D1;
  long lVar4;
  long extraout_D1_00;
  long extraout_D1_01;
  undefined2 uVar5;
  palette_id_flag_t unaff_D2;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  void *extraout_A1;
  void *extraout_A1_00;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  bool bVar6;
  undefined8 uVar7;
  undefined6 uVar8;
  palette_id_flag_t palettes;

  do {
    audio_play(SOUND_ID_F9);
    _DAT_ffff9812 = 0x73708182;
    vdp_palettes_something();
    uVar5 = (undefined2)(unaff_D2 >> 0x10);
    palettes = CONCAT22(uVar5, 0xf);
    palette_set_fade(palettes,
                     CONCAT22(extraout_D0u, 1),
                     '\0',
                     (palette_color_iter_t)0xffffffff);
    FUN_000048de();
    DAT_ffff9156 = 0xff;
    PTR_ffff96c4 = BYTE_ARRAY_000048d4;
    FUN_000049a6();
    audio_play(SOUND_ID_RES_BTTN);
    DAT_ffff96c1 = 0;
    if ((char)(_DAT_ffff96bc >> 0x10) == '\x01') {
      _DAT_ffff96bc = 0;
      menu_sound_test_sound_id = SOUND_ID_OVERTURE;
      DAT_ffff96c3 = 0;
      FUN_00001646();
      vdp_hblank_effect_asha_p = 0;
      vdp_gfx_ptr_5._0_2_ = 0;
      vdp_hblank_effect_pepelogoo_p = 0;
      vdp_gfx_ptr_6 = 0;
      vdp_related_to_display_asha = 0xf;
      DAT_ffff91ce._0_1_ = 0xff;
      text_unk_3();
      FUN_00001580();
      text_unk_2(extraout_A1);
      FUN_00005858(extraout_A1_00, unaff_A6);
      menu_sound_test_print_title(useless_d0, palettes);
      DAT_ffff91ce._0_1_ = 0;
      menu_sound_test_update();
      FUN_00001630();
      while (true) {
        uVar7 = menu_sound_test_update();
        // Quit the sound test when A, B or C is pressed.
        if ((((gamepad_pressed & GAMEPAD_A) != GAMEPAD_NONE) ||
             ((gamepad_pressed & GAMEPAD_B) != GAMEPAD_NONE)) ||
            ((gamepad_pressed & GAMEPAD_C) != GAMEPAD_NONE))
          break;
        exception_unk_0(unaff_A3,
                        unaff_A4,
                        unaff_A6,
                        (long)((ulonglong)uVar7 >> 0x20),
                        (long)uVar7,
                        palettes,
                        -1,
                        unaff_D4,
                        unaff_D5,
                        unaff_D6,
                        unaff_D7);
      }
    } else {
      uVar2 = _DAT_ffff96bc >> 8 & 0xffff;
      _DAT_ffff96bc = uVar2 << 8;
      uVar3 = _DAT_ffff96bc;
      DAT_ffff96bd = (char)(uVar2 >> 8);
      bVar6 = DAT_ffff96bd == '\0';
      lVar4 = extraout_D1;
      _DAT_ffff96bc = uVar3;
      if (bVar6)
        goto LAB_000048be;
      sram_unk_6();
      if (DAT_ffffcbb0 == '\0') {
        _DAT_ffff96bc = 0;
        lVar4 = extraout_D1_01;
      LAB_000048be:
        bVar1 = DAT_ffff96be & 3;
        _DAT_ffff96bc = CONCAT13(bVar1 | DAT_ffff96bc, _DAT_ffff96bd);
        DAT_ffff9154 = 0xffff;
        uVar7 = exception_unk_0(unaff_A3,
                                unaff_A4,
                                unaff_A6,
                                (uint)bVar1,
                                lVar4,
                                palettes,
                                -1,
                                unaff_D4,
                                unaff_D5,
                                unaff_D6,
                                unaff_D7);
        return uVar7;
      }
      _DAT_ffff96bc = CONCAT13(4, _DAT_ffff96bd);
      _DAT_ffff96bc = CONCAT31(_DAT_ffff96bc, 0xff);
      uVar8 = FUN_00028e9e();
      lVar4 = (long)uVar8;
      if ((short)((uint6)uVar8 >> 0x20) == 0)
        goto LAB_000048be;
    }
    DAT_ffff9156 = 0;
    audio_stop_all();
    FUN_00001646();
    FUN_00001580();
    vdp_set_window_position(0);
    DAT_ffff96ba = 0xff;
    DAT_ffff91ce._0_1_ = 0;
    VDP_CTRL = VDP_REG_SPRITES_TABLE_ADDR_DC00;
    VDP_CTRL = VDP_REG_MODE_SET_4_H40_AND_SHADOW;
    vdp_hblank_effect_asha_p = 0;
    vdp_gfx_ptr_5._0_2_ = 0;
    vdp_hblank_effect_pepelogoo_p = 0;
    vdp_gfx_ptr_6 = 0;
    vdp_related_to_display_asha = 0xf;
    clear_unk_1();
    FUN_0000ba1a();
    uVar7 = vdp_write_something_to_vram();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar7 >> 0x20),
                    (long)uVar7,
                    palettes,
                    -1,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    _DAT_ffff9812 = 0x73708182;
    vdp_palettes_something();
    palette_set_fade(CONCAT22(uVar5, 0xf),
                     CONCAT22(extraout_D0u_00, 1),
                     '\0',
                     (palette_color_iter_t)0xffffffff);
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    extraout_D0,
                    extraout_D1_00,
                    CONCAT22(uVar5, 0xf),
                    -1,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_00003ed0();
    FUN_00003f1c();
    _DAT_ffff9813 = CONCAT12(0x73, _DAT_ffff9814);
    vdp_palettes_something();
    unaff_D2 = CONCAT22(uVar5, 0xf);
    palette_set_fade(unaff_D2,
                     CONCAT22(extraout_D0u_01, 1),
                     '\0',
                     (palette_color_iter_t)0xffffffff);
    uVar7 = FUN_000048de();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar7 >> 0x20),
                    (long)uVar7,
                    unaff_D2,
                    -1,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_00001630();
  } while (true);
}

byte FUN_000048de(void)

{
  anim_item_t *unaff_A5;
  bool bVar1;

  entity_reset(0x10);
  DAT_ffff9f2b = 0x80;
  DAT_ffffa646 = 0x18;
  DAT_ffffa647 = 0x2a;
  ecs_anim_unk_2(0x10, unaff_A5, 6);
  DAT_ffffa132 = 0x80;
  DAT_ffffa236 = 0x90;
  DAT_ffffa33a = 4;
  bVar1 = false;
  FUN_001560b4();
  if (!bVar1) {
    entity_reset(0x18);
    uRamffff9f33 = 0x80;
    uRamffffa64e = 0x18;
    uRamffffa64f = 0x2a;
    ecs_anim_unk_2(0x18, unaff_A5, 4);
    uRamffffa13a = 0x80;
    uRamffffa23e = 0x90;
    uRamffffa342 = 4;
  }
  entity_reset(0x1c);
  uRamffff9f37 = 0x80;
  uRamffffa652 = 0x18;
  uRamffffa653 = 0x2a;
  uRamffffa346 = 4;
  uRamffffa13e = 0x80;
  ecs_anim_unk_2(0x1c, unaff_A5, 0xc);
  if ((DAT_ffffcbb0 & 3) == 0) {
    DAT_ffff96bd = 0;
    DAT_ffff96be = 0;
    DAT_ffff96bf = 0;
    uRamffffa242 = 0xa0;
  } else {
    DAT_ffff96bd = 0xff;
    DAT_ffff96be = 0xff;
    DAT_ffff96bf = 0xff;
    uRamffffa242 = 0x90;
  }
  return DAT_ffffcbb0 & 3;
}

uint FUN_000049a6(void)

{
  undefined3 uVar1;
  undefined4 in_D0;
  undefined4 extraout_D0;
  undefined4 extraout_D0_00;
  undefined4 uVar2;
  undefined4 in_D1;
  undefined4 extraout_D1;
  undefined4 extraout_D1_00;
  undefined4 uVar3;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar4;
  ulonglong uVar5;

  uVar5 = CONCAT44(in_D0, in_D1);
code_r0x000049a6:
  do {
    do {
      uVar4 = exception_unk_0(unaff_A3,
                              unaff_A4,
                              unaff_A6,
                              (long)(uVar5 >> 0x20),
                              (long)uVar5,
                              unaff_D2,
                              unaff_D3,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
      uVar1 = (undefined3)((ulonglong)uVar4 >> 0x28);
      unaff_A4 = 0x1c;
      if ((gamepad_pressed & GAMEPAD_BUTTON_ANY) != GAMEPAD_NONE) {
        return CONCAT31(uVar1, gamepad_pressed) & 0xfffffff0;
      }
      uVar5 = CONCAT44(CONCAT31(uVar1, gamepad_pressed), (int)uVar4) &
              0xffffff0fffffffff;
      if ((gamepad_pressed & GAMEPAD_DPAD_ANY) != GAMEPAD_NONE) {
        uVar5 = FUN_00004a3a();
        if ((char)uVar5 < '\0') {
          DAT_ffff96bd = 1;
          return (uint)(uVar5 >> 0x20);
        }
      }
    } while (DAT_ffff96bf == '\0');
    if ((gamepad_pressed & GAMEPAD_UP) != GAMEPAD_NONE)
      goto LAB_000049f8;
  } while (((gamepad_pressed & GAMEPAD_DOWN) == GAMEPAD_NONE) ||
           (sRamffffa242 == 0xa0));
  sRamffffa242 = sRamffffa242 + 0x10;
  audio_play(SOUND_ID_RES_KEY);
  uVar2 = extraout_D0;
  uVar3 = extraout_D1;
  goto LAB_00004a0e;
LAB_000049f8:
  if (sRamffffa242 != 0x90) {
    sRamffffa242 = sRamffffa242 + -0x10;
    audio_play(SOUND_ID_RES_KEY);
    uVar2 = extraout_D0_00;
    uVar3 = extraout_D1_00;
  LAB_00004a0e:
    uVar5 = CONCAT44(uVar2, uVar3);
    if (sRamffffa242 == 0x90) {
      DAT_ffff96bd = 0xff;
      DAT_ffff96be = 0xff;
      uVar5 = CONCAT44(uVar2, uVar3);
    } else {
      DAT_ffff96bd = 0;
      DAT_ffff96be = 0;
    }
  }
  goto code_r0x000049a6;
}

void FUN_00004a3a(void)

{
  byte bVar1;
  uint in_D0;

  bVar1 = *PTR_ffff96c4;
  if ((-1 < (char)bVar1) &&
      (PTR_ffff96c4 = PTR_ffff96c4 + 1, (in_D0 & 1 << (bVar1 & 0x1f)) == 0)) {
    PTR_ffff96c4 = BYTE_ARRAY_000048d4;
  }
  return;
}

void FUN_00004ae6(void)

{
  return;
}

// `useless_d2` is there only to fix some "unaf" because the code doesn't clear
// the upper half of D2 before using it. We likely should clear it.

void menu_sound_test_print_title(long useless_d0, long useless_d2)

{
  sized_string_t *string;

  palette_set_fade(CONCAT22((short)((uint)useless_d2 >> 0x10), 0xf),
                   CONCAT22((short)((uint)useless_d0 >> 0x10), 1),
                   '\0',
                   (palette_color_iter_t)0xffffffff);
  // The upper word should be 0, the VRAM address should just be #c408.
  vdp_set_vram_write_addr((void *)0xc408);
  // C is wrong, the param should be menu_sound_test_title.
  vdp_load_sized_string(string);
  return;
}

// This handles:
// - selecting a sound
// - printing the sound's name
// - stops any sound and playing the new one

void menu_sound_test_update(void)

{
  sized_string_t *string;

  if ((gamepad_pressed & GAMEPAD_UP) != GAMEPAD_NONE) {
    if (menu_sound_test_sound_id == SOUND_ID_OVERTURE) {
      menu_sound_test_sound_id = SOUND_ID_LAST;
    }
    menu_sound_test_sound_id =
        menu_sound_test_sound_id - SOUND_ID_OVER_THE_CLOUDS;
  }
  if ((gamepad_pressed & GAMEPAD_DOWN) != GAMEPAD_NONE) {
    if (SOUND_ID_SONG_OFF < menu_sound_test_sound_id) {
      menu_sound_test_sound_id = SOUND_ID_FF;
    }
    menu_sound_test_sound_id =
        menu_sound_test_sound_id + SOUND_ID_OVER_THE_CLOUDS;
  }
  vdp_set_vram_write_addr((void *)0xc700);
  // C is wrong, `string` should be:
  //
  // (&menu_sound_test_music_name_jump_table +
  // menu_sound_test_music_name_jump_table[menu_sound_test_sound_id])
  vdp_load_sized_string(string);
  if ((gamepad_pressed & GAMEPAD_START) != GAMEPAD_NONE) {
    audio_stop_all();
    audio_play(menu_sound_test_sound_id);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00005858(void *param_1, void *param_2)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  undefined8 uVar1;

  text_unk_1(BYTE_ARRAY_0000588e, param_1);
  uVar1 = uncompress_and_copy_to_vram();
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  param_2,
                  (long)((ulonglong)uVar1 >> 0x20),
                  (long)uVar1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  DAT_ffff91ce._0_1_ = 0xff;
  something(BYTE_ARRAY_00005893);
  DAT_ffff91ce._0_1_ = 0;
  _DAT_ffff9812 = 0x2007172;
  vdp_palettes_something();
  return;
}

void main_unk_2(entity_id_t self, ulong param_2, ulong param_3)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  undefined8 uVar1;
  gamepad_t gamepad_changed;

  uVar1 = CONCAT44(param_2, param_3);
  do {
    unaff_D2 = CONCAT31((int3)((uint)unaff_D2 >> 8), gamepad_pressed_prev);
    gamepad_changed = gamepad_held ^ gamepad_held_prev;
    gamepad_held_prev = gamepad_held;
    gamepad_pressed_prev = gamepad_held & gamepad_changed;
    uVar1 = exception_unk_0(
        unaff_A3,
        unaff_A4,
        (void *)self,
        CONCAT31((int3)((ulonglong)uVar1 >> 0x28), gamepad_held),
        CONCAT31((int3)((ulonglong)uVar1 >> 8), gamepad_pressed_prev),
        unaff_D2,
        unaff_D3,
        unaff_D4,
        unaff_D5,
        unaff_D6,
        unaff_D7);
  } while (true);
}

void FUN_00005f38(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  (*(code *)((int)&JMP_00005fea +
             (int)*(short *)((int)&JMP_00005fea +
                             (int)(short)((ushort)DAT_ffff96ce * 2))))();
  DAT_ffffcb26 = 0xc213898b;
  DAT_ffff96ca = *(undefined4 *)((int)&WORD_00005fda +
                                 (int)(short)((ushort)DAT_ffff96ce << 2));
  DAT_ffff96c8 = gamepad_pressed;
  DAT_ffff96c9 = '\0';
  while ((gamepad_pressed & GAMEPAD_START) == GAMEPAD_NONE) {
    FUN_00005ff2();
    uVar1 = FUN_0000603e();
    if (DAT_ffff96c9 == -1)
      break;
    if (DAT_ffff9154 == -1) {
      return;
    }
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  FUN_0000140c();
  audio_play(SOUND_ID_FF);
  DAT_ffff9154 = 0xffff;
  audio_stop_all();
  return;
}

void FUN_00005f76(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  while ((gamepad_pressed & GAMEPAD_START) == GAMEPAD_NONE) {
    FUN_00005ff2();
    uVar1 = FUN_0000603e();
    if (DAT_ffff96c9 == -1)
      break;
    if (DAT_ffff9154 == -1) {
      return;
    }
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  FUN_0000140c();
  audio_play(SOUND_ID_FF);
  DAT_ffff9154 = 0xffff;
  audio_stop_all();
  return;
}

void FUN_00005fc4(void)

{
  FUN_0000140c();
  audio_play(SOUND_ID_FF);
  DAT_ffff9154 = 0xffff;
  audio_stop_all();
  return;
}

void FUN_00005ff2(void)

{
  return;
}

void FUN_00005ff4(void)

{
  gamepad_t gVar1;
  gamepad_t *pgVar2;

  gVar1 = gamepad_held_4;
  gamepad_held = gamepad_held_4;
  if (DAT_ffff9154 != -1) {
    if (gamepad_held_4 != DAT_ffff96c8) {
      pgVar2 = (gamepad_t *)(DAT_ffff96ca + 1);
      *DAT_ffff96ca = DAT_ffff96c9;
      DAT_ffff96ca = DAT_ffff96ca + 2;
      *pgVar2 = DAT_ffff96c8;
      DAT_ffff96c8 = gVar1;
      DAT_ffff96c9 = '\0';
      goto LAB_00006034;
    }
    if (DAT_ffff96c9 != -1)
      goto LAB_00006034;
  }
  pgVar2 = (gamepad_t *)(DAT_ffff96ca + 1);
  *DAT_ffff96ca = DAT_ffff96c9;
  DAT_ffff96ca = DAT_ffff96ca + 2;
  *pgVar2 = DAT_ffff96c8;
  DAT_ffff96c9 = '\0';
LAB_00006034:
  DAT_ffff96c9 = DAT_ffff96c9 + '\x01';
  return;
}

void FUN_0000603e(void)

{
  gamepad_t *pgVar1;

  if (DAT_ffff96c9 == '\0') {
    pgVar1 = (gamepad_t *)(DAT_ffff96ca + 1);
    DAT_ffff96c9 = *DAT_ffff96ca;
    DAT_ffff96ca = DAT_ffff96ca + 2;
    DAT_ffff96c8 = *pgVar1;
  }
  gamepad_held = DAT_ffff96c8;
  DAT_ffff96c9 = DAT_ffff96c9 + -1;
  return;
}

void FUN_00006062(void)

{
  DAT_ffff97e5 = 0;
  DAT_ffff96c1 = 0xff;
  DAT_ffff96c0 = 2;
  FUN_0000bce8();
  FUN_0000bd48();
  return;
}

void FUN_00006080(void)

{
  DAT_ffff97e5 = 0;
  DAT_ffff96c1 = 0xff;
  DAT_ffff96c0 = 3;
  FUN_0000bce8();
  FUN_0000bd48();
  return;
}

void FUN_0000609e(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  while (true) {
    if (((gamepad_pressed & GAMEPAD_START) != GAMEPAD_NONE) ||
        (DAT_ffff9154 == -1))
      break;
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  }
  FUN_0000140c();
  audio_play(SOUND_ID_FF);
  DAT_ffff9154 = 0xffff;
  audio_stop_all();
  return;
}

undefined8 main_unk_14(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  FUN_0002c0e0();
  FUN_0000140c();
  audio_play(SOUND_ID_FF);
  DAT_ffff9154 = 0xffff;
  uVar1 = audio_stop_all();
  uVar1 = exception_unk_0(unaff_A3,
                          unaff_A4,
                          unaff_A6,
                          (long)((ulonglong)uVar1 >> 0x20),
                          (long)uVar1,
                          unaff_D2,
                          unaff_D3,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar1;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void main_unk_13(void)

{
  short sVar1;
  undefined2 extraout_D0u;
  long lVar2;
  char extraout_D0b;
  undefined4 extraout_D0;
  long extraout_D1;
  long extraout_D1_00;
  long extraout_D1_01;
  long extraout_D1_02;
  long lVar3;
  undefined4 extraout_D1_03;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t self;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined1 in_NF;
  undefined8 uVar4;
  int6 iVar5;

  FUN_00001580();
  FUN_00001646();
  entity_reset(ENTITY_ID_ASHA);
  self = ENTITY_ID_PEPELOGOO;
  entity_reset(ENTITY_ID_PEPELOGOO);
  FUN_0000c1b6();
  do {
  } while ((bool)in_NF);
  audio_play(SOUND_ID_FF);
  FUN_00029778();
  DAT_ffff97ea = SAVE_POINT;
  DAT_ffff97ec = SAVE_POINT;
  DAT_ffffcc93 = 7;
  DAT_ffff97ee = 0xff;
  pepelogoo_state_b = '\0';
  UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
  DAT_ffffcc73 = 0;
  DAT_ffff97e8 = 0;
  DAT_ffffcc92 = 0;
  comp_state = COMP_STATE_STAND;
  DAT_ffff97e9 = 0;
  ecs_holding_a_rope = 0;
  DAT_ffffd2f0 = 0;
  DAT_ffffd2ee = 0;
  FUN_00009b6e();
  vdp_set_window_position(4);
  _DAT_ffffc6fc = 0xff80;
  _DAT_ffffc6fe = 0xff80;
  FUN_00012f4e();
  FUN_0002b9f6();
  DAT_ffffcc85 = '\0';
  related_to_entering_a_room_7 = 0;
  DAT_ffffcc92 = 0;
  (*(code *)((int)&WORD_00006270 +
             (int)*(short *)((int)&WORD_00006270 +
                             (int)(short)((ushort)DAT_ffffcc93 * 2))))();
  FUN_00009de4();
  DAT_ffffd180 = 8;
  DAT_ffffd181 = 8;
  DAT_ffffd17e = 1;
  DAT_ffffd17f = 1;
  FUN_000145b4();
  FUN_0002ad72();
  clear_unk_1();
  FUN_0000ae18();
  FUN_0000e738();
  FUN_00012f46();
  FUN_0000c70c();
  FUN_0001408e();
  FUN_00029a2c();
  FUN_0000ff44((entity_id_t)unaff_A5);
  clear_data_and_uncompress_and_copy_to_vram();
  FUN_0002e3ee();
  game_locked = '\0';
  AUDIO_PAUSE_COUNT = 0;
  (*(code *)((int)&jmp_00006256 +
             (int)*(short *)((int)&jmp_00006256 +
                             (int)(short)((ushort)DAT_ffffcc93 * 2))))();
  game_unlock();
  if ((char)pepelogoo_state_b < '\0') {
    FUN_0002a6da();
  } else {
    related_to_entering_a_room();
  }
  FUN_0002e5d0();
  DAT_ffffe230 = 0xff;
  DAT_ffff97e9 = 0xff;
  DAT_ffffcbf5 = 0xff;
FUN_00006354:
  do {
    DAT_ffff9807 = '\0';
    FUN_00009a74();
    DAT_ffff97e4 = '\0';
    FUN_0002afb0();
    if (((DAT_ffffcc85 == '\0') && (DAT_ffff9808 == '\0')) &&
        ((gamepad_pressed_prev & GAMEPAD_START) != GAMEPAD_NONE)) {
      game_lock();
      menu_in_game_handle_input();
      game_unlock();
      lVar3 = extraout_D1;
      if (DAT_ffffcc92 == 0)
        goto LAB_00006396;
      goto LAB_00006c6c;
    }
  LAB_00006396:
    ecs_do_somthing_for_entity_id_8_to_48();
    FUN_00029aee();
    FUN_0001008a(unaff_A5, (short)unaff_D2);
    if (DAT_ffff97e4 == '\0') {
      lVar3 = extraout_D1_00;
      if (DAT_ffffcc92 == 0) {
        FUN_0001859e();
        FUN_0002e48a();
        FUN_00012f8a();
        lVar3 = extraout_D1_01;
        if (DAT_ffffcc92 != 0)
          goto LAB_00006c6c;
      } else {
      LAB_00006c6c:
        if (DAT_ffffcc8e != '\0') {
          (&comp_has_func_maybe)[(short)entity_id_w_t_ffffcc90] = 0;
          DAT_ffffcc8e = '\0';
        }
        if (DAT_ffffcc93 != 0) {
        LAB_00006c86:
          DAT_ffffe230 = 0;
          FUN_00000472((ulong)unaff_A6, 0, lVar3);
          DAT_ffff97e9 = 0;
          (*(code *)((int)&JMP_00006cb2 +
                     (int)*(
                         short *)((int)&JMP_00006cb2 +
                                  (int)(short)((ushort)DAT_ffffcc93 * 2))))();
          FUN_0002a720();
          FUN_00006184();
          return;
        }
        comp_has_func_maybe = comp_has_func_maybe & 0xf7;
        comp_state_a = comp_state_a & 0xfb;
        uint8_t_ffffcc70 = '\0';
        ecs_holding_a_rope = ecs_holding_a_rope & 0x7f;
        iVar5 = (*(
            code *)((int)&WORD_00007762 +
                    (int)*(short *)((int)&WORD_00007762 +
                                    (int)(short)((ushort)DAT_ffffcc92 * 2))))();
        lVar3 = (long)iVar5;
        if (iVar5 < 0)
          goto LAB_00006c86;
        DAT_ffffcc92 = 0;
      }
      self = ENTITY_ID_ASHA;
      ecs_called_before_run_entity_func_all();
      ecs_run_entity_func_all();
      ecs_called_after_run_entity_func_all();
      FUN_00016904();
      goto FUN_00006354;
    }
    audio_pause();
    if (OWNED_HEALING_MEDICINE_COUNT == '\0') {
      audio_play_sound_asha_dies();
    }
    game_lock();
    lVar2 = CONCAT22(extraout_D0u, 0x3c);
    lVar3 = extraout_D1_02;
    do {
      uVar4 = exception_unk_0(unaff_A3,
                              self,
                              unaff_A6,
                              lVar2,
                              lVar3,
                              unaff_D2,
                              unaff_D3,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
      lVar3 = (long)uVar4;
      sVar1 = (short)lVar2 + -1;
      lVar2 = CONCAT22((short)((ulonglong)uVar4 >> 0x30), sVar1);
    } while (sVar1 != 0);
    comp_state_a = comp_state_a | 4;
    DAT_ffffab42 = 0;
    DAT_ffffab43 = 0;
    DAT_ffff97fa = comp_pos_x.fixed.i;
    DAT_ffff97fc = comp_pos_y.fixed.i;
    comp_anim_b = 0;
    comp_has_func_maybe = 0;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x1a);
    comp_state_a = comp_state_a | 0x80;
    do {
      FUN_00009a74();
      comp_pos_y.fixed.i = comp_pos_y.fixed.i - 1;
    } while ((ushort)(DAT_ffffc746 - 0x10U) < (ushort)comp_pos_y.fixed.i);
    FUN_00001646();
    if (OWNED_HEALING_MEDICINE_COUNT == '\0') {
    LAB_000064f4:
      palette_set_fade(~PALETTE_ID_FLAG_NONE,
                       PALETTE_FADE_BLACK_EASE_IN,
                       '\0',
                       (palette_color_iter_t)0xffffffff);
      uVar4 = CONCAT44(extraout_D0, extraout_D1_03);
      do {
        uVar4 = exception_unk_0(unaff_A3,
                                ENTITY_ID_ASHA,
                                unaff_A6,
                                (long)((ulonglong)uVar4 >> 0x20),
                                (long)uVar4,
                                -1,
                                -1,
                                unaff_D4,
                                unaff_D5,
                                unaff_D6,
                                unaff_D7);
      } while (palette_fade_done_0 == 0);
      FUN_0000140c();
      audio_play(SOUND_ID_FF);
      DAT_ffff9154 = 0xffff;
      audio_stop_all();
      FUN_00009a74();
      return;
    }
    FUN_0000655a(unaff_A3);
    if (extraout_D0b == '\0')
      goto LAB_000064f4;
    DAT_ffffcc92 = 0;
    if (DAT_ffff9807 != '\0') {
      FUN_00006632();
      comp_state = COMP_STATE_STAND;
      comp_anim_b = 0;
      ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
      vdp_set_window_position(4);
      FUN_00006526();
      UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
      FUN_00006184();
      return;
    }
    comp_pos_x.fixed.i = DAT_ffff97fa;
    comp_pos_y.fixed.i = DAT_ffff97fc;
    FUN_0002861a();
    self = ENTITY_ID_ASHA;
    comp_has_func_maybe = 0;
    comp_state = COMP_STATE_STAND;
    comp_anim_b = 0;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
    game_unlock();
    audio_resume();
  } while (true);
}

void FUN_00006184(void)

{
  short sVar1;
  undefined2 extraout_D0u;
  long lVar2;
  char extraout_D0b;
  undefined4 extraout_D0;
  long extraout_D1;
  long extraout_D1_00;
  long extraout_D1_01;
  long extraout_D1_02;
  long lVar3;
  undefined4 extraout_D1_03;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar4;
  int6 iVar5;

  DAT_ffffcc85 = '\0';
  related_to_entering_a_room_7 = 0;
  DAT_ffffcc92 = 0;
  (*(code *)((int)&WORD_00006270 +
             (int)*(short *)((int)&WORD_00006270 +
                             (int)(short)((ushort)DAT_ffffcc93 * 2))))();
  FUN_00009de4();
  DAT_ffffd180 = 8;
  DAT_ffffd181 = 8;
  DAT_ffffd17e = 1;
  DAT_ffffd17f = 1;
  FUN_000145b4();
  FUN_0002ad72();
  clear_unk_1();
  FUN_0000ae18();
  FUN_0000e738();
  FUN_00012f46();
  FUN_0000c70c();
  FUN_0001408e();
  FUN_00029a2c();
  FUN_0000ff44((entity_id_t)unaff_A5);
  clear_data_and_uncompress_and_copy_to_vram();
  FUN_0002e3ee();
  game_locked = '\0';
  AUDIO_PAUSE_COUNT = 0;
  (*(code *)((int)&jmp_00006256 +
             (int)*(short *)((int)&jmp_00006256 +
                             (int)(short)((ushort)DAT_ffffcc93 * 2))))();
  game_unlock();
  if ((char)pepelogoo_state_b < '\0') {
    FUN_0002a6da();
  } else {
    related_to_entering_a_room();
  }
  FUN_0002e5d0();
  DAT_ffffe230 = 0xff;
  DAT_ffff97e9 = 0xff;
  DAT_ffffcbf5 = 0xff;
FUN_00006354:
  do {
    DAT_ffff9807 = '\0';
    FUN_00009a74();
    DAT_ffff97e4 = '\0';
    FUN_0002afb0();
    if (((DAT_ffffcc85 == '\0') && (DAT_ffff9808 == '\0')) &&
        ((gamepad_pressed_prev & GAMEPAD_START) != GAMEPAD_NONE)) {
      game_lock();
      menu_in_game_handle_input();
      game_unlock();
      lVar3 = extraout_D1;
      if (DAT_ffffcc92 == 0)
        goto LAB_00006396;
      goto LAB_00006c6c;
    }
  LAB_00006396:
    ecs_do_somthing_for_entity_id_8_to_48();
    FUN_00029aee();
    FUN_0001008a(unaff_A5, (short)unaff_D2);
    if (DAT_ffff97e4 == '\0') {
      lVar3 = extraout_D1_00;
      if (DAT_ffffcc92 == 0) {
        FUN_0001859e();
        FUN_0002e48a();
        FUN_00012f8a();
        lVar3 = extraout_D1_01;
        if (DAT_ffffcc92 != 0)
          goto LAB_00006c6c;
      } else {
      LAB_00006c6c:
        if (DAT_ffffcc8e != '\0') {
          (&comp_has_func_maybe)[(short)entity_id_w_t_ffffcc90] = 0;
          DAT_ffffcc8e = '\0';
        }
        if (DAT_ffffcc93 != 0) {
        LAB_00006c86:
          DAT_ffffe230 = 0;
          FUN_00000472((ulong)unaff_A6, 0, lVar3);
          DAT_ffff97e9 = 0;
          (*(code *)((int)&JMP_00006cb2 +
                     (int)*(
                         short *)((int)&JMP_00006cb2 +
                                  (int)(short)((ushort)DAT_ffffcc93 * 2))))();
          FUN_0002a720();
          FUN_00006184();
          return;
        }
        comp_has_func_maybe = comp_has_func_maybe & 0xf7;
        comp_state_a = comp_state_a & 0xfb;
        uint8_t_ffffcc70 = '\0';
        ecs_holding_a_rope = ecs_holding_a_rope & 0x7f;
        iVar5 = (*(
            code *)((int)&WORD_00007762 +
                    (int)*(short *)((int)&WORD_00007762 +
                                    (int)(short)((ushort)DAT_ffffcc92 * 2))))();
        lVar3 = (long)iVar5;
        if (iVar5 < 0)
          goto LAB_00006c86;
        DAT_ffffcc92 = 0;
      }
      unaff_A4 = ENTITY_ID_ASHA;
      ecs_called_before_run_entity_func_all();
      ecs_run_entity_func_all();
      ecs_called_after_run_entity_func_all();
      FUN_00016904();
      goto FUN_00006354;
    }
    audio_pause();
    if (OWNED_HEALING_MEDICINE_COUNT == '\0') {
      audio_play_sound_asha_dies();
    }
    game_lock();
    lVar2 = CONCAT22(extraout_D0u, 0x3c);
    lVar3 = extraout_D1_02;
    do {
      uVar4 = exception_unk_0(unaff_A3,
                              unaff_A4,
                              unaff_A6,
                              lVar2,
                              lVar3,
                              unaff_D2,
                              unaff_D3,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
      lVar3 = (long)uVar4;
      sVar1 = (short)lVar2 + -1;
      lVar2 = CONCAT22((short)((ulonglong)uVar4 >> 0x30), sVar1);
    } while (sVar1 != 0);
    comp_state_a = comp_state_a | 4;
    DAT_ffffab42 = 0;
    DAT_ffffab43 = 0;
    DAT_ffff97fa = comp_pos_x.fixed.i;
    DAT_ffff97fc = comp_pos_y.fixed.i;
    comp_anim_b = 0;
    comp_has_func_maybe = 0;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x1a);
    comp_state_a = comp_state_a | 0x80;
    do {
      FUN_00009a74();
      comp_pos_y.fixed.i = comp_pos_y.fixed.i - 1;
    } while ((ushort)(DAT_ffffc746 - 0x10U) < (ushort)comp_pos_y.fixed.i);
    FUN_00001646();
    if (OWNED_HEALING_MEDICINE_COUNT == '\0') {
    LAB_000064f4:
      palette_set_fade(~PALETTE_ID_FLAG_NONE,
                       PALETTE_FADE_BLACK_EASE_IN,
                       '\0',
                       (palette_color_iter_t)0xffffffff);
      uVar4 = CONCAT44(extraout_D0, extraout_D1_03);
      do {
        uVar4 = exception_unk_0(unaff_A3,
                                ENTITY_ID_ASHA,
                                unaff_A6,
                                (long)((ulonglong)uVar4 >> 0x20),
                                (long)uVar4,
                                -1,
                                -1,
                                unaff_D4,
                                unaff_D5,
                                unaff_D6,
                                unaff_D7);
      } while (palette_fade_done_0 == 0);
      FUN_0000140c();
      audio_play(SOUND_ID_FF);
      DAT_ffff9154 = 0xffff;
      audio_stop_all();
      FUN_00009a74();
      return;
    }
    FUN_0000655a(unaff_A3);
    if (extraout_D0b == '\0')
      goto LAB_000064f4;
    DAT_ffffcc92 = 0;
    if (DAT_ffff9807 != '\0') {
      FUN_00006632();
      comp_state = COMP_STATE_STAND;
      comp_anim_b = 0;
      ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
      vdp_set_window_position(4);
      FUN_00006526();
      UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
      FUN_00006184();
      return;
    }
    comp_pos_x.fixed.i = DAT_ffff97fa;
    comp_pos_y.fixed.i = DAT_ffff97fc;
    FUN_0002861a();
    unaff_A4 = ENTITY_ID_ASHA;
    comp_has_func_maybe = 0;
    comp_state = COMP_STATE_STAND;
    comp_anim_b = 0;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
    game_unlock();
    audio_resume();
  } while (true);
}

void FUN_0000623e(void)

{
  short sVar1;
  undefined2 extraout_D0u;
  long lVar2;
  char extraout_D0b;
  undefined4 extraout_D0;
  long extraout_D1;
  long extraout_D1_00;
  long extraout_D1_01;
  long extraout_D1_02;
  long lVar3;
  undefined4 extraout_D1_03;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar4;
  int6 iVar5;

  FUN_0002e5d0();
  DAT_ffffe230 = 0xff;
  DAT_ffff97e9 = 0xff;
  DAT_ffffcbf5 = 0xff;
FUN_00006354:
  do {
    DAT_ffff9807 = '\0';
    FUN_00009a74();
    DAT_ffff97e4 = '\0';
    FUN_0002afb0();
    if (((DAT_ffffcc85 == '\0') && (DAT_ffff9808 == '\0')) &&
        ((gamepad_pressed_prev & GAMEPAD_START) != GAMEPAD_NONE)) {
      game_lock();
      menu_in_game_handle_input();
      game_unlock();
      lVar3 = extraout_D1;
      if (DAT_ffffcc92 == 0)
        goto LAB_00006396;
      goto LAB_00006c6c;
    }
  LAB_00006396:
    ecs_do_somthing_for_entity_id_8_to_48();
    FUN_00029aee();
    FUN_0001008a(unaff_A5, (short)unaff_D2);
    if (DAT_ffff97e4 == '\0') {
      lVar3 = extraout_D1_00;
      if (DAT_ffffcc92 == 0) {
        FUN_0001859e();
        FUN_0002e48a();
        FUN_00012f8a();
        lVar3 = extraout_D1_01;
        if (DAT_ffffcc92 != 0)
          goto LAB_00006c6c;
      } else {
      LAB_00006c6c:
        if (DAT_ffffcc8e != '\0') {
          (&comp_has_func_maybe)[(short)entity_id_w_t_ffffcc90] = 0;
          DAT_ffffcc8e = '\0';
        }
        if (DAT_ffffcc93 != 0) {
        LAB_00006c86:
          DAT_ffffe230 = 0;
          FUN_00000472((ulong)unaff_A6, 0, lVar3);
          DAT_ffff97e9 = 0;
          (*(code *)((int)&JMP_00006cb2 +
                     (int)*(
                         short *)((int)&JMP_00006cb2 +
                                  (int)(short)((ushort)DAT_ffffcc93 * 2))))();
          FUN_0002a720();
          FUN_00006184();
          return;
        }
        comp_has_func_maybe = comp_has_func_maybe & 0xf7;
        comp_state_a = comp_state_a & 0xfb;
        uint8_t_ffffcc70 = '\0';
        ecs_holding_a_rope = ecs_holding_a_rope & 0x7f;
        iVar5 = (*(
            code *)((int)&WORD_00007762 +
                    (int)*(short *)((int)&WORD_00007762 +
                                    (int)(short)((ushort)DAT_ffffcc92 * 2))))();
        lVar3 = (long)iVar5;
        if (iVar5 < 0)
          goto LAB_00006c86;
        DAT_ffffcc92 = 0;
      }
      unaff_A4 = ENTITY_ID_ASHA;
      ecs_called_before_run_entity_func_all();
      ecs_run_entity_func_all();
      ecs_called_after_run_entity_func_all();
      FUN_00016904();
      goto FUN_00006354;
    }
    audio_pause();
    if (OWNED_HEALING_MEDICINE_COUNT == '\0') {
      audio_play_sound_asha_dies();
    }
    game_lock();
    lVar2 = CONCAT22(extraout_D0u, 0x3c);
    lVar3 = extraout_D1_02;
    do {
      uVar4 = exception_unk_0(unaff_A3,
                              unaff_A4,
                              unaff_A6,
                              lVar2,
                              lVar3,
                              unaff_D2,
                              unaff_D3,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
      lVar3 = (long)uVar4;
      sVar1 = (short)lVar2 + -1;
      lVar2 = CONCAT22((short)((ulonglong)uVar4 >> 0x30), sVar1);
    } while (sVar1 != 0);
    comp_state_a = comp_state_a | 4;
    DAT_ffffab42 = 0;
    DAT_ffffab43 = 0;
    DAT_ffff97fa = comp_pos_x.fixed.i;
    DAT_ffff97fc = comp_pos_y.fixed.i;
    comp_anim_b = 0;
    comp_has_func_maybe = 0;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x1a);
    comp_state_a = comp_state_a | 0x80;
    do {
      FUN_00009a74();
      comp_pos_y.fixed.i = comp_pos_y.fixed.i - 1;
    } while ((ushort)(DAT_ffffc746 - 0x10U) < (ushort)comp_pos_y.fixed.i);
    FUN_00001646();
    if (OWNED_HEALING_MEDICINE_COUNT == '\0') {
    LAB_000064f4:
      palette_set_fade(~PALETTE_ID_FLAG_NONE,
                       PALETTE_FADE_BLACK_EASE_IN,
                       '\0',
                       (palette_color_iter_t)0xffffffff);
      uVar4 = CONCAT44(extraout_D0, extraout_D1_03);
      do {
        uVar4 = exception_unk_0(unaff_A3,
                                ENTITY_ID_ASHA,
                                unaff_A6,
                                (long)((ulonglong)uVar4 >> 0x20),
                                (long)uVar4,
                                -1,
                                -1,
                                unaff_D4,
                                unaff_D5,
                                unaff_D6,
                                unaff_D7);
      } while (palette_fade_done_0 == 0);
      FUN_0000140c();
      audio_play(SOUND_ID_FF);
      DAT_ffff9154 = 0xffff;
      audio_stop_all();
      FUN_00009a74();
      return;
    }
    FUN_0000655a(unaff_A3);
    if (extraout_D0b == '\0')
      goto LAB_000064f4;
    DAT_ffffcc92 = 0;
    if (DAT_ffff9807 != '\0') {
      FUN_00006632();
      comp_state = COMP_STATE_STAND;
      comp_anim_b = 0;
      ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
      vdp_set_window_position(4);
      FUN_00006526();
      UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
      FUN_00006184();
      return;
    }
    comp_pos_x.fixed.i = DAT_ffff97fa;
    comp_pos_y.fixed.i = DAT_ffff97fc;
    FUN_0002861a();
    unaff_A4 = ENTITY_ID_ASHA;
    comp_has_func_maybe = 0;
    comp_state = COMP_STATE_STAND;
    comp_anim_b = 0;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
    game_unlock();
    audio_resume();
  } while (true);
}

void ecs_update_hflip_asha_0(void)

{
  if ((&DAT_0007c8fe)[(short)(DAT_ffff97ea << 3)] != '\0') {
    if ((&DAT_0007c8fe)[(short)(DAT_ffff97ea << 3)] == '\x01') {
      comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
    } else {
      comp_state_a = comp_state_a | ENTITY_STATE_A_08;
    }
  }
  return;
}

void FUN_000062b4(void)

{
  return;
}

void FUN_000062b6(void)

{
  return;
}

void FUN_000062b8(void)

{
  return;
}

void FUN_000062ba(void)

{
  return;
}

void FUN_000062bc(void)

{
  FUN_00013d2e();
  ecs_update_hflip_asha_0();
  return;
}

void FUN_000062c6(void)

{
  anim_item_t *unaff_A5;

  FUN_00013e52();
  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  comp_unk_3 = 0x10;
  comp_anim_base_offset = 0;
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  comp_state = COMP_STATE_STAND;
  ecs_update_hflip_asha_0();
  return;
}

void FUN_000062fa(void)

{
  anim_item_t *unaff_A5;

  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  comp_state = COMP_STATE_STAND;
  return;
}

void FUN_0000631a(void)

{
  anim_item_t *unaff_A5;

  FUN_00013e52();
  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  comp_unk_3 = 0x10;
  comp_anim_base_offset = 0;
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  comp_state = COMP_STATE_STAND;
  ecs_update_hflip_asha_0();
  return;
}

void FUN_00006350(void)

{
  return;
}

void FUN_00006352(void)

{
  return;
}

void FUN_00006354(void)

{
  short sVar1;
  undefined2 extraout_D0u;
  long lVar2;
  char extraout_D0b;
  undefined4 extraout_D0;
  long extraout_D1;
  long extraout_D1_00;
  long extraout_D1_01;
  long extraout_D1_02;
  long lVar3;
  undefined4 extraout_D1_03;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar4;
  int6 iVar5;

code_r0x00006354:
  do {
    DAT_ffff9807 = '\0';
    FUN_00009a74();
    DAT_ffff97e4 = '\0';
    FUN_0002afb0();
    if (((DAT_ffffcc85 == '\0') && (DAT_ffff9808 == '\0')) &&
        ((gamepad_pressed_prev & GAMEPAD_START) != GAMEPAD_NONE)) {
      game_lock();
      menu_in_game_handle_input();
      game_unlock();
      lVar3 = extraout_D1;
      if (DAT_ffffcc92 == 0)
        goto LAB_00006396;
      goto LAB_00006c6c;
    }
  LAB_00006396:
    ecs_do_somthing_for_entity_id_8_to_48();
    FUN_00029aee();
    FUN_0001008a(unaff_A5, (short)unaff_D2);
    if (DAT_ffff97e4 == '\0') {
      lVar3 = extraout_D1_00;
      if (DAT_ffffcc92 == 0) {
        FUN_0001859e();
        FUN_0002e48a();
        FUN_00012f8a();
        lVar3 = extraout_D1_01;
        if (DAT_ffffcc92 != 0)
          goto LAB_00006c6c;
      } else {
      LAB_00006c6c:
        if (DAT_ffffcc8e != '\0') {
          (&comp_has_func_maybe)[(short)entity_id_w_t_ffffcc90] = 0;
          DAT_ffffcc8e = '\0';
        }
        if (DAT_ffffcc93 != 0) {
        LAB_00006c86:
          DAT_ffffe230 = 0;
          FUN_00000472((ulong)unaff_A6, 0, lVar3);
          DAT_ffff97e9 = 0;
          (*(code *)((int)&JMP_00006cb2 +
                     (int)*(
                         short *)((int)&JMP_00006cb2 +
                                  (int)(short)((ushort)DAT_ffffcc93 * 2))))();
          FUN_0002a720();
          FUN_00006184();
          return;
        }
        comp_has_func_maybe = comp_has_func_maybe & 0xf7;
        comp_state_a = comp_state_a & 0xfb;
        uint8_t_ffffcc70 = '\0';
        ecs_holding_a_rope = ecs_holding_a_rope & 0x7f;
        iVar5 = (*(
            code *)((int)&WORD_00007762 +
                    (int)*(short *)((int)&WORD_00007762 +
                                    (int)(short)((ushort)DAT_ffffcc92 * 2))))();
        lVar3 = (long)iVar5;
        if (iVar5 < 0)
          goto LAB_00006c86;
        DAT_ffffcc92 = 0;
      }
      unaff_A4 = ENTITY_ID_ASHA;
      ecs_called_before_run_entity_func_all();
      ecs_run_entity_func_all();
      ecs_called_after_run_entity_func_all();
      FUN_00016904();
      goto code_r0x00006354;
    }
    audio_pause();
    if (OWNED_HEALING_MEDICINE_COUNT == '\0') {
      audio_play_sound_asha_dies();
    }
    game_lock();
    lVar2 = CONCAT22(extraout_D0u, 0x3c);
    lVar3 = extraout_D1_02;
    do {
      uVar4 = exception_unk_0(unaff_A3,
                              unaff_A4,
                              unaff_A6,
                              lVar2,
                              lVar3,
                              unaff_D2,
                              unaff_D3,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
      lVar3 = (long)uVar4;
      sVar1 = (short)lVar2 + -1;
      lVar2 = CONCAT22((short)((ulonglong)uVar4 >> 0x30), sVar1);
    } while (sVar1 != 0);
    comp_state_a = comp_state_a | 4;
    DAT_ffffab42 = 0;
    DAT_ffffab43 = 0;
    DAT_ffff97fa = comp_pos_x.fixed.i;
    DAT_ffff97fc = comp_pos_y.fixed.i;
    comp_anim_b = 0;
    comp_has_func_maybe = 0;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x1a);
    comp_state_a = comp_state_a | 0x80;
    do {
      FUN_00009a74();
      comp_pos_y.fixed.i = comp_pos_y.fixed.i - 1;
    } while ((ushort)(DAT_ffffc746 - 0x10U) < (ushort)comp_pos_y.fixed.i);
    FUN_00001646();
    if (OWNED_HEALING_MEDICINE_COUNT == '\0') {
    LAB_000064f4:
      palette_set_fade(~PALETTE_ID_FLAG_NONE,
                       PALETTE_FADE_BLACK_EASE_IN,
                       '\0',
                       (palette_color_iter_t)0xffffffff);
      uVar4 = CONCAT44(extraout_D0, extraout_D1_03);
      do {
        uVar4 = exception_unk_0(unaff_A3,
                                ENTITY_ID_ASHA,
                                unaff_A6,
                                (long)((ulonglong)uVar4 >> 0x20),
                                (long)uVar4,
                                -1,
                                -1,
                                unaff_D4,
                                unaff_D5,
                                unaff_D6,
                                unaff_D7);
      } while (palette_fade_done_0 == 0);
      FUN_0000140c();
      audio_play(SOUND_ID_FF);
      DAT_ffff9154 = 0xffff;
      audio_stop_all();
      FUN_00009a74();
      return;
    }
    FUN_0000655a(unaff_A3);
    if (extraout_D0b == '\0')
      goto LAB_000064f4;
    DAT_ffffcc92 = 0;
    if (DAT_ffff9807 != '\0') {
      FUN_00006632();
      comp_state = COMP_STATE_STAND;
      comp_anim_b = 0;
      ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
      vdp_set_window_position(4);
      FUN_00006526();
      UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
      FUN_00006184();
      return;
    }
    comp_pos_x.fixed.i = DAT_ffff97fa;
    comp_pos_y.fixed.i = DAT_ffff97fc;
    FUN_0002861a();
    unaff_A4 = ENTITY_ID_ASHA;
    comp_has_func_maybe = 0;
    comp_state = COMP_STATE_STAND;
    comp_anim_b = 0;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
    game_unlock();
    audio_resume();
  } while (true);
}

void FUN_00006526(void)

{
  if (DAT_ffff97ec < 0) {
    comp_pos_x.fixed.i = DAT_ffff97f4;
    comp_pos_y.fixed.i = DAT_ffff97f6;
    DAT_ffffcbb2 = DAT_ffff97f0;
    DAT_ffffcbb4 = DAT_ffff97f2;
    DAT_ffffcc93 = 0xc;
  } else {
    DAT_ffffcc93 = 0xb;
    DAT_ffff97ea = DAT_ffff97ec;
  }
  return;
}

void FUN_0000655a(script_ctx_t *ctx)

{
  undefined1 uVar1;
  word wVar2;
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;
  void *unaff_A6;

  if ((-1 < (char)script_ctx_bf_0e_arg) && (script_ctx_bf_0e_arg < 3)) {
    game_lock();
    FUN_00006632();
    FUN_00028010();
    uVar1 = DAT_ffff91ce._0_1_;
    DAT_ffff91ce._0_1_ = 0;
    FUN_00027ec8();
    DAT_ffff91ce._0_1_ = uVar1;
    wVar2 = FUN_0000664c();
    FUN_0000669e(wVar2);
    FUN_00006928();
    FUN_00006932(unaff_A5);
    FUN_0000694e();
    audio_play(SOUND_ID_REBIRTH);
    FUN_0000699c();
    FUN_000069d6(ctx, unaff_A6);
    FUN_000069b6();
    ecs_does_something_on_entity_f8();
    FUN_00006a7e();
    FUN_00006a9e();
    FUN_00006ae4();
    FUN_00006b46();
    FUN_00006b68(unaff_A5);
    FUN_00006b98();
    FUN_00006bc4(unaff_A5);
    FUN_00006c0c();
    animate_menu_cursor_maybe(unaff_A4, ctx);
    FUN_000069b6();
    related_to_entering_and_exiting_menu();
    game_unlock();
    audio_play(SOUND_ID_FX_OFF);
    if (DAT_ffff9807 != '\0') {
      if (DAT_ffff97ec < 0) {
        comp_pos_x.fixed.i = DAT_ffff97f4;
        comp_pos_y.fixed.i = DAT_ffff97f6;
        DAT_ffffcbb2 = DAT_ffff97f0;
        DAT_ffffcbb4 = DAT_ffff97f2;
        DAT_ffffcc93 = 0xc;
      } else {
        DAT_ffffcc93 = 0xb;
        DAT_ffff97ea = DAT_ffff97ec;
      }
    }
  }
  return;
}

void FUN_00006632(void)

{
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar1 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (palette_fade_done_0 == 0);
  return;
}

void FUN_0000664c(void)

{
  byte *pbVar1;
  void *in_A1;

  if (script_ctx_bf_0e_arg == '\0') {
    pbVar1 = BYTE_ARRAY_0000667a;
  } else if (script_ctx_bf_0e_arg == '\x01') {
    pbVar1 = BYTE_ARRAY_00006686;
  } else {
    pbVar1 = BYTE_ARRAY_00006692;
  }
  text_unk_1(pbVar1, in_A1);
  uncompress_and_copy_to_vram();
  return;
}

void FUN_0000669e(word param_1)

{
  FUN_00027f20((uint3 *)BYTE_ARRAY_000066aa, param_1);
  return;
}

void FUN_00006928(void)

{
  FUN_00027ff6();
  return;
}

void FUN_00006932(entity_id_t self)

{
  ecs_init_entity_state(ENTITY_ID_F4, self, &component_mixed_1_t_00006944);
  return;
}

void FUN_0000694e(void)

{
  component_mixed_1_t *state;
  entity_id_t unaff_A5;

  if (script_ctx_bf_0e_arg == '\0') {
    state = &component_mixed_1_t_0000697e;
  } else if (script_ctx_bf_0e_arg == '\x01') {
    state = &component_mixed_1_t_00006988;
  } else {
    state = &component_mixed_1_t_00006992;
  }
  ecs_init_entity_state(ENTITY_ID_F8, unaff_A5, state);
  return;
}

void FUN_0000699c(void)

{
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_OUT,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar1 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (palette_fade_done_0 == 0);
  return;
}

void FUN_000069b6(void)

{
  long lVar1;
  short sVar2;
  long in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar3;

  lVar1 = 0x1e;
  do {
    uVar3 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            lVar1,
                            in_D1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    in_D1 = (long)uVar3;
    sVar2 = (short)lVar1 + -1;
    lVar1 = CONCAT22((short)((ulonglong)uVar3 >> 0x30), sVar2);
  } while (sVar2 != -1);
  return;
}

void FUN_000069c6(void)

{
  long lVar1;
  short sVar2;
  long in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar3;

  lVar1 = 0x3c;
  do {
    uVar3 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            lVar1,
                            in_D1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    in_D1 = (long)uVar3;
    sVar2 = (short)lVar1 + -1;
    lVar1 = CONCAT22((short)((ulonglong)uVar3 >> 0x30), sVar2);
  } while (sVar2 != -1);
  return;
}

void FUN_000069d6(script_ctx_t *ctx, void *param_2)

{
  ushort uVar1;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;

  DAT_ffffa526 = 0xff00;
  DAT_ffffa528 = 0x100;
  do {
    entity_update_pos(ENTITY_ID_F8);
    uVar1 = *(ushort *)((int)&WORD_00006a22 +
                        (int)(short)((ushort)script_ctx_bf_0e_arg << 2));
    if (uVar1 == DAT_ffffa21a) {
      DAT_ffffa526 = 0;
      uVar1 = *(ushort *)((int)WORD_ARRAY_00006a24 +
                          (int)(short)((ushort)script_ctx_bf_0e_arg << 2));
      if (uVar1 == DAT_ffffa31e) {
        DAT_ffffa528 = 0;
        return;
      }
    }
    exception_unk_0(ctx,
                    ENTITY_ID_F8,
                    param_2,
                    (uint)uVar1,
                    extraout_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  } while (true);
}

void ecs_does_something_on_entity_f8(void)

{
  ushort uVar1;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;

  related_to_entering_and_exiting_menu_2 = 0;
  ecs_anim_unk_2(ENTITY_ID_F8, unaff_A5, 2);
  DAT_ffffa528 = 0xff00;
  while (true) {
    entity_update_pos(ENTITY_ID_F8);
    uVar1 = *(ushort *)((int)WORD_ARRAY_00006a74 +
                        (int)(short)((ushort)script_ctx_bf_0e_arg << 2));
    if (uVar1 == DAT_ffffa31e)
      break;
    exception_unk_0(unaff_A3,
                    ENTITY_ID_F8,
                    unaff_A6,
                    (uint)uVar1,
                    extraout_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  DAT_ffffa528 = 0;
  return;
}

undefined8 FUN_00006a7e(void)

{
  long extraout_D0;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  ecs_init_entity_state(ENTITY_ID_FC, unaff_A5, &component_mixed_1_t_00006a94);
  uVar1 = exception_unk_0(unaff_A3,
                          ENTITY_ID_FC,
                          unaff_A6,
                          extraout_D0,
                          extraout_D1,
                          unaff_D2,
                          unaff_D3,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar1;
}

void FUN_00006a9e(void)

{
  ushort uVar1;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  void *unaff_A6;

  DAT_ffffa528 = 0xff00;
  while (true) {
    entity_update_pos(ENTITY_ID_F8);
    uVar1 = *(ushort *)((int)WORD_ARRAY_00006ada +
                        (int)(short)((ushort)script_ctx_bf_0e_arg << 2));
    if (uVar1 == DAT_ffffa31e)
      break;
    exception_unk_0(unaff_A3,
                    ENTITY_ID_F8,
                    unaff_A6,
                    (uint)uVar1,
                    extraout_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  DAT_ffffa528 = 0;
  return;
}

void FUN_00006ae4(void)

{
  ushort uVar1;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;

  related_to_entering_and_exiting_menu_2 = 0;
  ecs_anim_unk_2(ENTITY_ID_F8, unaff_A5, 0);
  DAT_ffffa528 = 0x100;
  DAT_ffffa526 = 0x100;
  do {
    entity_update_pos(ENTITY_ID_F8);
    uVar1 = *(ushort *)((int)WORD_ARRAY_00006b3c +
                        (int)(short)((ushort)script_ctx_bf_0e_arg << 2));
    if (uVar1 == DAT_ffffa31e) {
      DAT_ffffa528 = 0;
      uVar1 = *(ushort *)((int)&WORD_00006b3a +
                          (int)(short)((ushort)script_ctx_bf_0e_arg << 2));
      if (uVar1 == DAT_ffffa21a) {
        DAT_ffffa526 = 0;
        return;
      }
    }
    exception_unk_0(unaff_A3,
                    ENTITY_ID_F8,
                    unaff_A6,
                    (uint)uVar1,
                    extraout_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  } while (true);
}

void FUN_00006b46(void)

{
  byte bVar1;
  undefined4 in_D0;
  undefined4 extraout_D0;
  undefined4 in_D1;
  undefined4 extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  void *unaff_A6;
  undefined8 uVar2;

  uVar2 = CONCAT44(in_D0, in_D1);
  while (true) {
    bVar1 = DAT_ffffa735 & 0x20;
    DAT_ffffa735 = DAT_ffffa735 & 0xdf;
    if (bVar1 != 0) {
      audio_play(SOUND_ID_CRYS_FLASH);
      uVar2 = CONCAT44(extraout_D0, extraout_D1);
    }
    if (DAT_ffffa630 == 0)
      break;
    uVar2 = exception_unk_0(unaff_A3,
                            ENTITY_ID_FC,
                            unaff_A6,
                            (long)((ulonglong)uVar2 >> 0x20),
                            (long)uVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  }
  return;
}

undefined8 FUN_00006b68(entity_id_t self)

{
  long extraout_D0;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  void *unaff_A6;
  undefined8 uVar1;

  ecs_init_entity_state(ENTITY_ID_FC, self, &component_mixed_1_t_00006b8e);
  DAT_ffffa017 = DAT_ffffa017 | 4;
  DAT_ffffac3e = 0;
  DAT_ffffac3f = 0;
  uVar1 = exception_unk_0(unaff_A3,
                          ENTITY_ID_FC,
                          unaff_A6,
                          extraout_D0,
                          extraout_D1,
                          unaff_D2,
                          unaff_D3,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar1;
}

void FUN_00006b98(void)

{
  long extraout_D0;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  void *unaff_A6;

  DAT_ffffa52a = 0;
  DAT_ffffa52c = 0x200;
  while (true) {
    entity_update_pos(ENTITY_ID_FC);
    if (0x93 < DAT_ffffa322)
      break;
    exception_unk_0(unaff_A3,
                    ENTITY_ID_FC,
                    unaff_A6,
                    extraout_D0,
                    extraout_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  related_to_entering_and_exiting_menu_2 = 0;
  return;
}

void FUN_00006bc4(entity_id_t self)

{
  related_to_entering_and_exiting_menu_1 = 0;
  ecs_anim_unk_2(ENTITY_ID_F4, (anim_item_t *)self, 2);
  related_to_entering_and_exiting_menu_2 = 0;
  ecs_anim_unk_2(ENTITY_ID_F8, (anim_item_t *)self, 4);
  return;
}

void animate_menu_cursor_maybe(entity_id_t self, script_ctx_t *ctx)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  do {
    uVar1 = exception_unk_0(ctx,
                            self,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    self = ENTITY_ID_F4;
  } while (menu_cursor_animation_tick_2 != 0);
  return;
}

ulong related_to_entering_and_exiting_menu(void)

{
  related_to_entering_and_exiting_menu_1 = 0;
  related_to_entering_and_exiting_menu_2 = 0;
  related_to_entering_and_exiting_menu_2 = 0;
  return 0x100;
}

void FUN_00006c0c(void)

{
  undefined2 extraout_D0u;
  undefined4 extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined1 uVar1;
  undefined8 uVar2;

  OWNED_HEALING_MEDICINE_COUNT = 0;
  audio_play(SOUND_ID_LIFE);
  uVar2 = CONCAT44(CONCAT22(extraout_D0u, total_hearts_max), extraout_D1);
  total_hearts = total_hearts_max;
  uVar1 = total_hearts_max == 0;
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar2 >> 0x20),
                    (long)uVar2,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_0001a388();
    uVar2 = FUN_0001a582();
  } while (!(bool)uVar1);
  return;
}

void FUN_00006c34(void)

{
  FUN_000156b2();
  ecs_called_before_run_entity_func_all();
  ecs_run_entity_func_all();
  ecs_called_after_run_entity_func_all();
  return;
}

void FUN_00006c4e(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  FUN_000156b2();
  ecs_called_before_run_entity_func_all();
  uVar1 = ecs_run_entity_func_all();
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar1 >> 0x20),
                  (long)uVar1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  uncompress_and_copy_to_vram();
  return;
}

void FUN_00006ccc(void)

{
  return;
}

void FUN_00006cce(void)

{
  game_lock();
  audio_play(SOUND_ID_SCN_CHG);
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  do {
    FUN_00009a74();
  } while (palette_fade_done_0 == 0);
  comp_pos_x.fixed.i = DAT_ffff97f4;
  comp_pos_y.fixed.i = DAT_ffff97f6;
  component_pos_old_x[0].fixed.i = DAT_ffff97f4;
  component_pos_old_y[0].fixed.i = DAT_ffff97f6;
  return;
}

void FUN_00006d0c(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  DAT_ffff91c6 = 0xff;
  uVar1 = game_lock();
  comp_state_a = comp_state_a | 0x80;
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar1 >> 0x20),
                  (long)uVar1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  FUN_0000b338();
  return;
}

void FUN_00006d28(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  DAT_ffff91c6 = 0xff;
  uVar1 = game_lock();
  comp_state_a = comp_state_a | 0x80;
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar1 >> 0x20),
                  (long)uVar1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  FUN_0000b338();
  return;
}

void FUN_00006d44(void)

{
  long in_D0;
  long in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  in_D0,
                  in_D1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  game_lock();
  FUN_00006d7a();
  uVar1 = FUN_00007646();
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar1 >> 0x20),
                  (long)uVar1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  do {
    FUN_00009a74();
  } while (palette_fade_done_0 == 0);
  (&comp_has_func_maybe)[DAT_ffffcc56] = 0;
  return;
}

void FUN_00006d7a(void)

{
  anim_item_t *unaff_A5;

  comp_has_func_maybe = 0;
  FUN_00009d60();
  comp_has_func_maybe = 0;
  comp_anim_b = DAT_ffffcd42;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, DAT_ffffcd43);
  return;
}

void FUN_00006da4(void)

{
  long in_D0;
  long extraout_D0;
  long in_D1;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;

  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  in_D0,
                  in_D1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  game_lock();
  audio_play(SOUND_ID_SCN_CHG);
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  extraout_D0,
                  extraout_D1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  do {
    FUN_00009a74();
  } while (palette_fade_done_0 == 0);
  FUN_0002e7c4();
  DAT_ffff97ee = 0xff;
  DAT_ffffcc93 = 5;
  return;
}

// WARNING: Removing unreachable block (ram,0x00006414)
// WARNING: Removing unreachable block (ram,0x0000644c)
// WARNING: Removing unreachable block (ram,0x00006468)
// WARNING: Removing unreachable block (ram,0x00006474)
// WARNING: Removing unreachable block (ram,0x0000647e)
// WARNING: Removing unreachable block (ram,0x000064c2)
// WARNING: Removing unreachable block (ram,0x0000648a)
// WARNING: Removing unreachable block (ram,0x00006354)
// WARNING: Removing unreachable block (ram,0x0000636e)
// WARNING: Removing unreachable block (ram,0x00006374)
// WARNING: Removing unreachable block (ram,0x0000637c)
// WARNING: Removing unreachable block (ram,0x00006396)
// WARNING: Removing unreachable block (ram,0x000063ae)
// WARNING: Removing unreachable block (ram,0x000063b6)
// WARNING: Removing unreachable block (ram,0x00006c6c)
// WARNING: Removing unreachable block (ram,0x00006c72)
// WARNING: Removing unreachable block (ram,0x00006c7e)
// WARNING: Removing unreachable block (ram,0x00007724)
// WARNING: Removing unreachable block (ram,0x00006c86)
// WARNING: Removing unreachable block (ram,0x0000775a)
// WARNING: Removing unreachable block (ram,0x000063d4)
// WARNING: Removing unreachable block (ram,0x000064f4)
// WARNING: Removing unreachable block (ram,0x00006502)
// WARNING: Removing unreachable block (ram,0x0000650c)

void FUN_00006de2(void)

{
  undefined2 extraout_D0u;
  long lVar1;
  long extraout_D1;
  long lVar2;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  void *unaff_A6;
  undefined8 uVar3;

  game_lock();
  audio_play_sound_asha_dies();
  DAT_ffff9807 = 0xff;
  comp_func_offset[0].unk1 = 3;
  total_hearts = total_hearts - 1;
  (*(code *)((int)&WORD_00006e52 +
             (int)*(short *)((int)&WORD_00006e52 +
                             (int)(short)(DAT_ffffcbb2 * 2))))();
  if (total_hearts == 0) {
    ecs_holding_a_rope = 0x80;
    comp_state_a = comp_state_a | 4;
    DAT_ffffab42 = 0;
    DAT_ffffab43 = 0;
    DAT_ffff97e4 = 0xff;
    audio_pause();
    if (OWNED_HEALING_MEDICINE_COUNT == '\0') {
      audio_play_sound_asha_dies();
    }
    game_lock();
    lVar1 = CONCAT22(extraout_D0u, 0x3c);
    lVar2 = extraout_D1;
    do {
      uVar3 = exception_unk_0(unaff_A3,
                              ENTITY_ID_ASHA,
                              unaff_A6,
                              lVar1,
                              lVar2,
                              unaff_D2,
                              unaff_D3,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
      lVar2 = (long)uVar3;
      lVar1 = CONCAT22((short)((ulonglong)uVar3 >> 0x30), 0x640d);
    } while (true);
  }
  // WARNING: Could not recover jumptable at 0x00006e50. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00006e78 +
             (int)*(short *)((int)&WORD_00006e78 +
                             (int)(short)(DAT_ffffcbb2 * 2))))();
  return;
}

void FUN_00006e9e(void)

{
  short sVar1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar2;

  (&comp_has_func_maybe)[unaff_A4] = 0;
  (&comp_anim_b)[unaff_A4] = 0xc;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined2 *)((int)component_pos_old_x + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  *(undefined2 *)((int)component_pos_old_y + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  audio_play(SOUND_ID_DAMAGE_1);
  FUN_00006f42();
  uVar2 = FUN_0001a388();
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar2 >> 0x20),
                  (long)uVar2,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  sVar1 = 0x20;
  do {
    uVar2 = FUN_0000707a();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar2 >> 0x20),
                    (long)uVar2,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    sVar1 = sVar1 + -1;
  } while (sVar1 != 0);
  return;
}

void FUN_00006eee(void)

{
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  do {
    FUN_0001a388();
    FUN_0000707a();
    FUN_00009a74();
  } while (palette_fade_done_0 == 0);
  if (-1 < DAT_ffff97ec) {
    DAT_ffffcc93 = 0xb;
    DAT_ffff97ea = DAT_ffff97ec;
    return;
  }
  comp_pos_x.fixed.i = DAT_ffff97f4;
  comp_pos_y.fixed.i = DAT_ffff97f6;
  DAT_ffffcbb2 = DAT_ffff97f0;
  DAT_ffffcbb4 = DAT_ffff97f2;
  DAT_ffffcc93 = 0xc;
  return;
}

void FUN_00006f42(void)

{
  comp_vel[0].y.raw = -0x800;
  comp_state_a = comp_state_a | 0x80;
  FUN_00006f60();
  FUN_00006fcc();
  FUN_00006fa2();
  return;
}

void FUN_00006f60(void)

{
  long extraout_D0;
  long extraout_D0_00;
  long extraout_D1;
  long extraout_D1_00;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;

  player_update_pos(unaff_A4);
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  extraout_D0,
                  extraout_D1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  FUN_0001a388();
  while (true) {
    comp_vel[0].y.raw = comp_vel[0].y.raw + 0x60;
    player_update_pos(0);
    if (-1 < comp_vel[0].y.raw)
      break;
    exception_unk_0(unaff_A3,
                    ENTITY_ID_ASHA,
                    unaff_A6,
                    extraout_D0_00,
                    extraout_D1_00,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_0001a388();
  }
  comp_vel[0].y.raw = 0;
  comp_func_offset[0].func_offset_from_15ede = 0x19;
  return;
}

void FUN_00006f94(void)

{
  int unaff_A4;

  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x400;
  (&comp_func_offset[0].func_offset_from_15ede)[unaff_A4] = 0x19;
  return;
}

void FUN_00006fa2(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  func *f;
  script_ctx_t *unaff_A3;
  void *unaff_A6;
  bool bVar1;
  undefined8 uVar2;

  while (true) {
    comp_vel[0].y.raw = comp_vel[0].y.raw + 0x60;
    player_update_pos(0);
    bVar1 = FUN_00000eae(ENTITY_ID_ASHA);
    if (bVar1)
      break;
    FUN_00006fe4(f);
    uVar2 = FUN_0000707a();
    exception_unk_0(unaff_A3,
                    ENTITY_ID_ASHA,
                    unaff_A6,
                    (long)((ulonglong)uVar2 >> 0x20),
                    (long)uVar2,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_0001a388();
  }
  return;
}

void FUN_00006fcc(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  while (comp_func_offset[0].func_offset_from_15ede =
             comp_func_offset[0].func_offset_from_15ede - 1,
         -1 < (char)comp_func_offset[0].func_offset_from_15ede) {
    exception_unk_0(unaff_A3,
                    ENTITY_ID_ASHA,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar1 = FUN_0001a388();
  }
  return;
}

void FUN_00006fe4(func *f)

{
  short sVar1;
  word wVar2;
  short unaff_D2w;
  int unaff_A4;
  entity_id_t self;
  anim_item_t *unaff_A5;

  (&comp_func_offset[0].unk1)[unaff_A4] =
      (&comp_func_offset[0].unk1)[unaff_A4] - 1;
  if ((char)(&comp_func_offset[0].unk1)[unaff_A4] < '\0') {
    (&comp_func_offset[0].unk1)[unaff_A4] = 3;
    FUN_0000147a(f, 2, 2);
    if (-1 < unaff_D2w) {
      self = (entity_id_t)unaff_D2w;
      entity_reset(self);
      *(undefined2 *)((int)&comp_unk_3 + self) = 6;
      (&comp_state_a)[self] = 0x80;
      *(int16_t *)((int)&comp_pos_x + self) = comp_pos_x.fixed.i;
      *(int16_t *)((int)&comp_pos_y + self) = comp_pos_y.fixed.i;
      wVar2 = rand();
      sVar1 = (wVar2 & 7) * 4;
      *(short *)((int)&comp_pos_x + self) =
          *(short *)((int)&int16_vec2_t_ARRAY_0000705a[0].x + (int)sVar1) +
          *(short *)((int)&comp_pos_x + self);
      *(short *)((int)&comp_pos_y + self) =
          *(short *)((int)&int16_vec2_t_ARRAY_0000705a[0].y + (int)sVar1) +
          *(short *)((int)&comp_pos_y + self);
      (&comp_anim_base_offset)[self] = 0;
      (&comp_anim_b)[self] = 10;
      ecs_anim_unk_2(self, unaff_A5, 0);
      *(code **)((int)&comp_some_function + self) = FUN_0000709c;
    }
  }
  return;
}

void FUN_0000707a(void)

{
  uint uVar1;

  uVar1 = 0x84;
  do {
    if (((char)(&comp_has_func_maybe)[uVar1] < '\0') &&
        (*(short *)(&comp_unk_1 + uVar1) == 2)) {
      (**(code **)((int)&comp_some_function + uVar1))();
    }
    uVar1 = uVar1 + 4;
  } while (uVar1 < 0xcc);
  return;
}

void FUN_0000709c(void)

{
  int unaff_A4;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

undefined8 FUN_000070a8(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  (&comp_has_func_maybe)[unaff_A4] = 0;
  (&comp_anim_b)[unaff_A4] = 0xe;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined2 *)((int)component_pos_old_x + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  *(undefined2 *)((int)component_pos_old_y + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0x12);
  audio_play(SOUND_ID_DAMAGE_1);
  FUN_000070e4();
  uVar1 = FUN_0001a388();
  uVar1 = exception_unk_0(unaff_A3,
                          unaff_A4,
                          unaff_A6,
                          (long)((ulonglong)uVar1 >> 0x20),
                          (long)uVar1,
                          unaff_D2,
                          unaff_D3,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar1;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000070e4(void)

{
  _comp_unk_1 = 0x60;
  do {
    FUN_0001a388();
    FUN_00009a74();
    _comp_unk_1 = _comp_unk_1 + -1;
  } while (-1 < _comp_unk_1);
  return;
}

void FUN_00007108(void)

{
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  do {
    FUN_0001a388();
    FUN_00009a74();
  } while (palette_fade_done_0 == 0);
  if (-1 < DAT_ffff97ec) {
    DAT_ffffcc93 = 0xb;
    DAT_ffff97ea = DAT_ffff97ec;
    return;
  }
  comp_pos_x.fixed.i = DAT_ffff97f4;
  comp_pos_y.fixed.i = DAT_ffff97f6;
  DAT_ffffcbb2 = DAT_ffff97f0;
  DAT_ffffcbb4 = DAT_ffff97f2;
  DAT_ffffcc93 = 0xc;
  return;
}

undefined8 FUN_00007158(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  (&comp_has_func_maybe)[unaff_A4] = 0;
  (&comp_anim_b)[unaff_A4] = 0x12;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined2 *)((int)component_pos_old_x + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  *(undefined2 *)((int)component_pos_old_y + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  ecs_anim_unk_2(unaff_A4, unaff_A5, 10);
  audio_play(SOUND_ID_DAMAGE_1);
  FUN_000071e4();
  uVar1 = FUN_0001a388();
  uVar1 = exception_unk_0(unaff_A3,
                          unaff_A4,
                          unaff_A6,
                          (long)((ulonglong)uVar1 >> 0x20),
                          (long)uVar1,
                          unaff_D2,
                          unaff_D3,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar1;
}

void FUN_00007194(void)

{
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  do {
    FUN_0001a388();
    FUN_00009a74();
  } while (palette_fade_done_0 == 0);
  if (-1 < DAT_ffff97ec) {
    DAT_ffffcc93 = 0xb;
    DAT_ffff97ea = DAT_ffff97ec;
    return;
  }
  comp_pos_x.fixed.i = DAT_ffff97f4;
  comp_pos_y.fixed.i = DAT_ffff97f6;
  DAT_ffffcbb2 = DAT_ffff97f0;
  DAT_ffffcbb4 = DAT_ffff97f2;
  DAT_ffffcc93 = 0xc;
  return;
}

void FUN_000071e4(void)

{
  comp_vel[0].y.raw = -0x800;
  comp_state_a = comp_state_a | 0x80;
  FUN_00007202();
  FUN_00007266();
  FUN_00007244();
  return;
}

void FUN_00007202(void)

{
  long extraout_D0;
  long extraout_D0_00;
  long extraout_D1;
  long extraout_D1_00;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;

  player_update_pos(unaff_A4);
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  extraout_D0,
                  extraout_D1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  FUN_0001a388();
  while (true) {
    comp_vel[0].y.raw = comp_vel[0].y.raw + 0x60;
    player_update_pos(0);
    if (-1 < comp_vel[0].y.raw)
      break;
    exception_unk_0(unaff_A3,
                    ENTITY_ID_ASHA,
                    unaff_A6,
                    extraout_D0_00,
                    extraout_D1_00,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_0001a388();
  }
  comp_vel[0].y.raw = 0;
  comp_func_offset[0].func_offset_from_15ede = 0x19;
  return;
}

void FUN_00007236(void)

{
  int unaff_A4;

  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x400;
  (&comp_func_offset[0].func_offset_from_15ede)[unaff_A4] = 0x19;
  return;
}

void FUN_00007244(void)

{
  long extraout_D0;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  void *unaff_A6;
  bool bVar1;

  while (true) {
    comp_vel[0].y.raw = comp_vel[0].y.raw + 0x60;
    player_update_pos(0);
    bVar1 = FUN_00000eae(ENTITY_ID_ASHA);
    if (bVar1)
      break;
    exception_unk_0(unaff_A3,
                    ENTITY_ID_ASHA,
                    unaff_A6,
                    extraout_D0,
                    extraout_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_0001a388();
  }
  return;
}

void FUN_00007266(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  while (comp_func_offset[0].func_offset_from_15ede =
             comp_func_offset[0].func_offset_from_15ede - 1,
         -1 < (char)comp_func_offset[0].func_offset_from_15ede) {
    exception_unk_0(unaff_A3,
                    ENTITY_ID_ASHA,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar1 = FUN_0001a388();
  }
  return;
}

void FUN_0000727e(void)

{
  return;
}

void FUN_00007280(void)

{
  game_lock();
  audio_play(SOUND_ID_SCN_CHG);
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  do {
    FUN_00009a74();
  } while (palette_fade_done_0 == 0);
  return;
}

void FUN_000072a6(void)

{
  game_lock();
  audio_play(SOUND_ID_SCN_CHG);
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  do {
    FUN_00009a74();
  } while (palette_fade_done_0 == 0);
  return;
}

void FUN_000072cc(void)

{
  long extraout_D0;
  long lVar1;
  long extraout_D0_00;
  long extraout_D1;
  long lVar2;
  long extraout_D1_00;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  func *f;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  entity_id_t e;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar3;

  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined2 *)((int)component_pos_old_x + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  *(undefined2 *)((int)component_pos_old_y + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  (&comp_anim_b)[unaff_A4] = 0;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  audio_play(SOUND_ID_DAMAGE_1);
  uVar3 = FUN_0001a388();
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar3 >> 0x20),
                  (long)uVar3,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  FUN_0000147a(f, 0, 0);
  e = (entity_id_t)(short)unaff_D2;
  entity_reset(e);
  *(int16_t *)((int)&comp_pos_x + e) = comp_pos_x.fixed.i;
  *(undefined2 *)((int)&comp_pos_y + e) = 0x10c0;
  (&comp_anim_base_offset)[e] = 0x14;
  (&comp_anim_b)[e] = 0x32;
  ecs_anim_unk_2(e, unaff_A5, 2);
  *(undefined2 *)((int)&comp_vel[0].y + e) = 0xff00;
  lVar1 = extraout_D0;
  lVar2 = extraout_D1;
  do {
    exception_unk_0(unaff_A3,
                    e,
                    unaff_A6,
                    lVar1,
                    lVar2,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    e = (entity_id_t)(short)e;
    ecs_update_pos_y(e);
    lVar1 = extraout_D0_00;
    lVar2 = extraout_D1_00;
  } while (*(short *)((int)&comp_anim_tick + e) != 0);
  return;
}

void FUN_00007344(void)

{
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  do {
    FUN_0001a388();
    FUN_00009a74();
  } while (palette_fade_done_0 == 0);
  if (-1 < DAT_ffff97ec) {
    DAT_ffffcc93 = 0xb;
    DAT_ffff97ea = DAT_ffff97ec;
    return;
  }
  comp_pos_x.fixed.i = DAT_ffff97f4;
  comp_pos_y.fixed.i = DAT_ffff97f6;
  DAT_ffffcbb2 = DAT_ffff97f0;
  DAT_ffffcbb4 = DAT_ffff97f2;
  DAT_ffffcc93 = 0xc;
  return;
}

void FUN_00007394(void)

{
  long in_D0;
  long extraout_D0;
  long extraout_D0_00;
  long lVar1;
  long extraout_D0_01;
  long in_D1;
  long extraout_D1;
  long extraout_D1_00;
  long lVar2;
  long extraout_D1_01;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  func *f;
  script_ctx_t *unaff_A3;
  entity_id_t e;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  bool bVar3;
  undefined8 uVar4;

  comp_state_a = comp_state_a & 0xfb;
  comp_has_func_maybe = comp_has_func_maybe & 0xf7;
  do {
    exception_unk_0(unaff_A3,
                    ENTITY_ID_ASHA,
                    unaff_A6,
                    in_D0,
                    in_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    comp_vel[0].y.raw = comp_vel[0].y.raw + 0x40;
    player_update_pos(0);
    bVar3 = FUN_00000eae(ENTITY_ID_ASHA);
    in_D0 = extraout_D0;
    in_D1 = extraout_D1;
  } while (!bVar3);
  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  component_pos_old_x[0].fixed.i = comp_pos_x.fixed.i;
  component_pos_old_y[0].fixed.i = comp_pos_y.fixed.i;
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 6);
  audio_play(SOUND_ID_DAMAGE_1);
  uVar4 = FUN_0001a388();
  exception_unk_0(unaff_A3,
                  ENTITY_ID_ASHA,
                  unaff_A6,
                  (long)((ulonglong)uVar4 >> 0x20),
                  (long)uVar4,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  FUN_0000147a(f, 0, 0);
  e = (entity_id_t)(short)unaff_D2;
  entity_reset(e);
  *(int16_t *)((int)&comp_pos_x + e) = comp_pos_x.fixed.i;
  *(int16_t *)((int)&comp_pos_y + e) = comp_pos_y.fixed.i;
  *(short *)((int)&comp_pos_y + e) = *(short *)((int)&comp_pos_y + e) + -0x30;
  (&comp_anim_base_offset)[e] = 0x14;
  (&comp_anim_b)[e] = 0x32;
  ecs_anim_unk_2(e, unaff_A5, 2);
  *(undefined2 *)((int)&comp_vel[0].y + e) = 0xff00;
  lVar1 = extraout_D0_00;
  lVar2 = extraout_D1_00;
  do {
    exception_unk_0(unaff_A3,
                    e,
                    unaff_A6,
                    lVar1,
                    lVar2,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    e = (entity_id_t)(short)e;
    ecs_update_pos_y(e);
    lVar1 = extraout_D0_01;
    lVar2 = extraout_D1_01;
  } while (*(short *)((int)&comp_anim_tick + e) != 0);
  return;
}

void FUN_0000743a(void)

{
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  do {
    FUN_0001a388();
    FUN_00009a74();
  } while (palette_fade_done_0 == 0);
  if (-1 < DAT_ffff97ec) {
    DAT_ffffcc93 = 0xb;
    DAT_ffff97ea = DAT_ffff97ec;
    return;
  }
  comp_pos_x.fixed.i = DAT_ffff97f4;
  comp_pos_y.fixed.i = DAT_ffff97f6;
  DAT_ffffcbb2 = DAT_ffff97f0;
  DAT_ffffcbb4 = DAT_ffff97f2;
  DAT_ffffcc93 = 0xc;
  return;
}

undefined8 FUN_0000748a(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  game_lock();
  FUN_000074a4();
  uVar1 = FUN_000074dc();
  uVar1 = exception_unk_0(unaff_A3,
                          unaff_A4,
                          unaff_A6,
                          (long)((ulonglong)uVar1 >> 0x20),
                          (long)uVar1,
                          unaff_D2,
                          unaff_D3,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  DAT_ffffcc93 = 6;
  return uVar1;
}

void FUN_000074a4(void)

{
  anim_item_t *unaff_A5;

  FUN_00009d60();
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0xe);
  return;
}

void FUN_000074c2(void)

{
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  palette_set_fade(PALETTE_ID_FLAG_2,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar1 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            4,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (palette_fade_done_2 == 0);
  return;
}

void FUN_000074dc(void)

{
  short sVar1;
  entity_state_1_a_t eVar2;
  long extraout_D0;
  undefined4 extraout_D0_00;
  undefined4 extraout_D0_01;
  undefined4 extraout_D0_02;
  long extraout_D1;
  undefined4 extraout_D1_00;
  undefined4 extraout_D1_01;
  undefined4 extraout_D1_02;
  long unaff_D2;
  short sVar3;
  undefined4 unaff_D3;
  long lVar4;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  void *in_A1;
  func *f;
  func *f_00;
  script_ctx_t *ctx;
  entity_id_t eVar5;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar6;

  if (DAT_ffffcd3e != (void *)0x0) {
    text_unk_1(DAT_ffffcd3e, in_A1);
    uncompress_and_copy_to_vram();
    DAT_ffffcd3e = (void *)0x0;
  }
  FUN_000074c2();
  FUN_0000147a(f, 0, 0);
  sVar3 = (short)unaff_D2;
  do {
  } while (sVar3 < 0);
  eVar5 = (entity_id_t)sVar3;
  DAT_ffffcc56 = sVar3;
  entity_reset(eVar5);
  *(undefined2 *)((int)&comp_anim_tick + eVar5) = 0;
  *(undefined2 *)((int)&comp_pos_x + eVar5) = DAT_ffffcd32;
  *(undefined2 *)((int)&comp_pos_y + eVar5) = DAT_ffffcd34;
  *(undefined2 *)((int)&comp_unk_3 + eVar5) = 0x12;
  (&comp_anim_base_offset)[eVar5] = DAT_ffffcd3b;
  (&comp_anim_b)[eVar5] = DAT_ffffcd3c;
  (&comp_has_func_maybe)[eVar5] = 0;
  ecs_anim_unk_2(eVar5, unaff_A5, 0);
  sVar1 = *(short *)((int)&comp_collision_sensor[0].y + eVar5);
  lVar4 = CONCAT22((short)((uint)unaff_D3 >> 0x10), sVar1);
  *(short *)((int)&comp_pos_y + eVar5) =
      *(short *)((int)&comp_pos_y + eVar5) - sVar1;
  FUN_0000147a(f_00, 0, 0);
  do {
  } while (sVar3 < 0);
  eVar5 = (entity_id_t)sVar3;
  entity_reset(eVar5);
  ctx = (script_ctx_t *)(int)DAT_ffffcc56;
  *(undefined2 *)((int)&comp_anim_tick + eVar5) = 0;
  *(undefined2 *)((int)&comp_pos_x + eVar5) = *(undefined2 *)&ctx[-0x2a3].h;
  *(uint16_t *)((int)&comp_pos_y + eVar5) =
      ctx[-0x29c].bf_05_arg2_vram_address_related;
  *(undefined2 *)((int)&comp_unk_3 + eVar5) = 0x1e;
  (&comp_anim_base_offset)[eVar5] = 0x14;
  (&comp_anim_b)[eVar5] = 0x28;
  ecs_anim_unk_2(eVar5, unaff_A5, 0);
  exception_unk_0(ctx,
                  eVar5,
                  unaff_A6,
                  extraout_D0,
                  extraout_D1,
                  unaff_D2,
                  lVar4,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  FUN_0000d73a();
  eVar5 = (entity_id_t)DAT_ffffcc56;
  (&comp_has_func_maybe)[eVar5] = 0;
  ecs_anim_unk_2(eVar5, unaff_A5, 2);
  uVar6 = CONCAT44(extraout_D0_00, extraout_D1_00);
  do {
    uVar6 = exception_unk_0(ctx,
                            eVar5,
                            unaff_A6,
                            (long)((ulonglong)uVar6 >> 0x20),
                            (long)uVar6,
                            unaff_D2,
                            lVar4,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    eVar5 = (entity_id_t)DAT_ffffcc56;
  } while (*(short *)((int)&comp_anim_tick + eVar5) != 0);
  comp_anim_b = DAT_ffffcd42;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, DAT_ffffcd43);
  uVar6 = CONCAT44(extraout_D0_01, extraout_D1_01);
  do {
    uVar6 = exception_unk_0(ctx,
                            ENTITY_ID_ASHA,
                            unaff_A6,
                            (long)((ulonglong)uVar6 >> 0x20),
                            (long)uVar6,
                            unaff_D2,
                            lVar4,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    eVar2 = comp_state_1_a & 0x20;
    comp_state_1_a = comp_state_1_a & 0xdf;
  } while (eVar2 == 0);
  audio_play(SOUND_ID_WARP);
  DAT_ffff9814 = 0xb;
  vdp_palettes_something();
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_WHITE_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar6 = CONCAT44(extraout_D0_02, extraout_D1_02);
  do {
    uVar6 = exception_unk_0(ctx,
                            ENTITY_ID_ASHA,
                            unaff_A6,
                            (long)((ulonglong)uVar6 >> 0x20),
                            (long)uVar6,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (palette_fade_done_0 == 0);
  (&comp_has_func_maybe)[DAT_ffffcc56] = 0;
  DAT_ffffcc56 = 0xffff;
  DAT_ffff97ec = DAT_ffffcc9c;
  DAT_ffff97ea = DAT_ffffcc9c;
  return;
}

void FUN_0000760c(void)

{
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  game_lock();
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar1 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (palette_fade_done_0 == 0);
  FUN_0002f306();
  DAT_ffff97ee = 0xff;
  DAT_ffff97ec = 0xd9;
  DAT_ffff97ea = 0xd9;
  DAT_ffffcc93 = 6;
  return;
}

void FUN_00007646(void)

{
  long extraout_D0;
  undefined4 extraout_D0_00;
  undefined4 extraout_D0_01;
  long extraout_D1;
  undefined4 extraout_D1_00;
  undefined4 extraout_D1_01;
  long unaff_D2;
  short sVar1;
  undefined4 unaff_D3;
  long lVar2;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  func *in_A1;
  func *extraout_A1;
  func *extraout_A1_00;
  script_ctx_t *unaff_A3;
  entity_id_t eVar3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar4;

  do {
    if (DAT_ffffcd3a == '\x04') {
      FUN_00007718();
      DAT_ffff97ea = DAT_ffffcc9c;
      DAT_ffff97ec = DAT_ffffcc9c;
      return;
    }
    if (DAT_ffffcd3e != (void *)0x0) {
      text_unk_1(DAT_ffffcd3e, in_A1);
      uncompress_and_copy_to_vram();
      DAT_ffffcd3e = (void *)0x0;
      in_A1 = extraout_A1;
    }
    FUN_0000147a(in_A1, 0, 0);
    sVar1 = (short)unaff_D2;
    in_A1 = extraout_A1_00;
  } while (sVar1 < 0);
  eVar3 = (entity_id_t)sVar1;
  DAT_ffffcc56 = sVar1;
  if (-1 < DAT_ffffcd3d) {
    entity_reset(eVar3);
    *(undefined2 *)((int)&comp_anim_tick + eVar3) = 0;
    *(undefined2 *)((int)&comp_pos_x + eVar3) = DAT_ffffcd32;
    *(undefined2 *)((int)&comp_pos_y + eVar3) = DAT_ffffcd34;
    *(undefined2 *)((int)&comp_unk_3 + eVar3) = 0x12;
    (&comp_anim_base_offset)[eVar3] = DAT_ffffcd3b;
    (&comp_anim_b)[eVar3] = DAT_ffffcd3c;
    (&comp_has_func_maybe)[eVar3] = 0;
    ecs_anim_unk_2(eVar3, unaff_A5, 0);
    sVar1 = *(short *)((int)&comp_collision_sensor[0].y + eVar3);
    lVar2 = CONCAT22((short)((uint)unaff_D3 >> 0x10), sVar1);
    *(short *)((int)&comp_pos_y + eVar3) =
        *(short *)((int)&comp_pos_y + eVar3) - sVar1;
    exception_unk_0(unaff_A3,
                    eVar3,
                    unaff_A6,
                    extraout_D0,
                    extraout_D1,
                    unaff_D2,
                    lVar2,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_0000d6f6();
    eVar3 = (entity_id_t)DAT_ffffcc56;
    (&comp_has_func_maybe)[eVar3] = 0;
    ecs_anim_unk_2(eVar3, unaff_A5, 2);
    audio_play(SOUND_ID_DOOR);
    uVar4 = CONCAT44(extraout_D0_00, extraout_D1_00);
    do {
      uVar4 = exception_unk_0(unaff_A3,
                              eVar3,
                              unaff_A6,
                              (long)((ulonglong)uVar4 >> 0x20),
                              (long)uVar4,
                              unaff_D2,
                              lVar2,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
      eVar3 = (entity_id_t)DAT_ffffcc56;
    } while (*(short *)((int)&comp_anim_tick + eVar3) != 0);
    *(undefined2 *)((int)&comp_unk_3 + eVar3) = 8;
    (&comp_has_func_maybe)[eVar3] = 0;
    ecs_anim_unk_2(eVar3, unaff_A5, 4);
    uVar4 = CONCAT44(extraout_D0_01, extraout_D1_01);
    do {
      uVar4 = exception_unk_0(unaff_A3,
                              eVar3,
                              unaff_A6,
                              (long)((ulonglong)uVar4 >> 0x20),
                              (long)uVar4,
                              unaff_D2,
                              lVar2,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
      eVar3 = (entity_id_t)DAT_ffffcc56;
    } while (*(short *)((int)&comp_anim_tick + eVar3) != 0);
  }
  DAT_ffff97ec = DAT_ffffcc9c;
  DAT_ffff97ea = DAT_ffffcc9c;
  return;
}

void FUN_00007718(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (comp_anim_tick != 0);
  return;
}

undefined4 FUN_00007794(void)

{
  return 0;
}

// FIXME Where is it called?

undefined4 FUN_00007798(void)

{
  return 0;
}

// FIXME Where is it called?

undefined4 FUN_0000779c(void)

{
  short sVar1;

  game_lock();
  sVar1 = FUN_0001937a();
  if (sVar1 != 0) {
    FUN_000077ce();
    game_unlock();
    return 0xffffffff;
  }
  if (set_to_13a62_when_facing_a_door != (code *)0x0) {
    (*set_to_13a62_when_facing_a_door)();
  }
  game_unlock();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address D1 and D2 can be values extracted from text command 18.

void FUN_000077ce(void)

{
  short in_D1w;
  undefined2 unaff_D2w;

  _DAT_ffffcc9e = &DAT_0007c8f8 + (short)(in_D1w << 3);
  DAT_ffffcc9c = unaff_D2w;
  (**(code **)((int)&value_dst_t_ARRAY_000138e0[0].value +
               (int)(short)((ushort)(byte)(&DAT_0007c8fc)[(short)(in_D1w << 3)]
                            << 3)))();
  return;
}

undefined4 FUN_000077f8(void)

{
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_000077fc(void)

{
  ushort *puVar1;
  undefined2 extraout_D0u;
  long lVar2;
  char extraout_D0b;
  undefined4 extraout_D0;
  undefined4 uVar3;
  short sVar4;
  ushort uVar5;
  long extraout_D1;
  long extraout_D1_00;
  long extraout_D1_01;
  long extraout_D1_02;
  long lVar6;
  undefined4 extraout_D1_03;
  ushort extraout_D1w;
  byte extraout_D1b;
  byte extraout_D1b_00;
  long extraout_D1_04;
  long unaff_D2;
  short new_ctx;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  func *f;
  func *extraout_A1;
  func *extraout_A1_00;
  func *f_00;
  script_ctx_t *unaff_A3;
  entity_id_t eVar7;
  int iVar8;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar9;
  int6 iVar10;

  game_lock();
  audio_pause();
  comp_has_func_maybe = 0;
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x26);
  FUN_00007a8c();
  eVar7 = (entity_id_t)_DAT_ffffcf86;
  (&comp_has_func_maybe)[eVar7] = 0;
  (&comp_anim_base_offset)[eVar7] = 0x14;
  (&comp_anim_b)[eVar7] = 10;
  ecs_anim_unk_2(eVar7, unaff_A5, 2);
  audio_play(SOUND_ID_BOX_OPEN);
  FUN_00007a9e();
  iVar8 = (int)_DAT_ffffcf86;
  if ((**(byte **)(&comp_unk_9 + iVar8) & 0x80) != 0) {
    audio_resume();
    DAT_ffffcc92 = 0;
    *(undefined1 *)((int)&comp_state + iVar8) = 2;
    game_unlock();
    return 0;
  }
  sVar4 = FUN_00007ad4();
  new_ctx = (short)unaff_D2;
  if (sVar4 != 0) {
    FUN_0000147a(f, 2, 0);
    do {
    } while (new_ctx < 0);
    eVar7 = (entity_id_t)new_ctx;
    entity_reset(eVar7);
    FUN_00024da0();
    (&comp_func_offset[0].unk1)[eVar7] = extraout_D1b_00;
    FUN_000019ae();
    (&comp_state_a)[eVar7] = (&comp_state_a)[eVar7] | 0x80;
    iVar8 = (int)_DAT_ffffcf86;
    *(int16_t *)((int)&comp_pos_x + eVar7) = comp_pos_x.fixed.i;
    *(undefined2 *)((int)&comp_pos_y + eVar7) =
        *(undefined2 *)((int)&comp_pos_y + iVar8);
    *(short *)((int)&comp_pos_y + eVar7) =
        *(short *)((int)&comp_pos_y + eVar7) + -0x18;
    *(undefined2 *)((int)&comp_unk_3 + eVar7) = 4;
    ecs_anim_unk_2(eVar7, unaff_A5, 0);
    *(undefined2 *)((int)&comp_vel[0].x + eVar7) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + eVar7) = 0xfc00;
    comp_anim_b = 0;
    _DAT_ffff97f8 = new_ctx;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x2a);
    FUN_00007bda();
    puVar1 = *(ushort **)(&comp_unk_9 + _DAT_ffffcf86);
    audio_play(SOUND_ID_JINGLE_1);
    script_ctx_bf_0c_arg_item_name_index = 0x37;
    DAT_ffffd916 = 6;
    FUN_0001937a();
    FUN_00029824();
    script_state_set_true((script_state_bit_t)(*puVar1 & 0x7fff));
    *(undefined1 *)((int)&comp_state + (int)_DAT_ffffcf86) = 1;
    DAT_ffffcc92 = 0;
    (&comp_has_func_maybe)[_DAT_ffff97f8] = 0;
    audio_resume();
    game_unlock();
    return 0;
  }
  if ((short)unaff_D5 == 0x37) {
    script_ctx_bf_0c_arg_item_name_index =
        *(undefined1 *)(*(int *)(&comp_unk_9 + _DAT_ffffcf86) + 3);
    DAT_ffffd916 = 0x72;
    FUN_0001937a();
    ecs_anim_unk_2((int)_DAT_ffffcf86, unaff_A5, 4);
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x28);
    FUN_00007a9e();
    DAT_ffffcc92 = 0;
    *(undefined1 *)((int)&comp_state + (int)_DAT_ffffcf86) = 0;
    game_unlock();
    audio_resume();
    return 0;
  }
  if ((short)unaff_D5 == 0x1c) {
    if (OWNED_HEALING_MEDICINE_COUNT != '\0') {
      script_ctx_bf_0c_arg_item_name_index =
          *(undefined1 *)(*(int *)(&comp_unk_9 + _DAT_ffffcf86) + 3);
      DAT_ffffd916 = 0x73;
      FUN_0001937a();
      ecs_anim_unk_2((int)_DAT_ffffcf86, unaff_A5, 4);
      ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x28);
      FUN_00007a9e();
      DAT_ffffcc92 = 0;
      *(undefined1 *)((int)&comp_state + (int)_DAT_ffffcf86) = 0;
      game_unlock();
      audio_resume();
      return 0;
    }
    FUN_00007d36();
    f_00 = extraout_A1;
  } else {
    uVar5 = FUN_00007d36();
    if (0x6f < uVar5) {
      FUN_00007c2e();
      FUN_00007c56();
      FUN_00007cb0();
      audio_play(SOUND_ID_JINGLE_1);
      FUN_00007cfe();
      FUN_00007d16();
      script_ctx_bf_0c_arg_item_name_index = FUN_00007d36();
      FUN_000271ec();
      lVar6 = extraout_D1_04;
    LAB_00006c6c:
      do {
        if (DAT_ffffcc8e != '\0') {
          (&comp_has_func_maybe)[(short)entity_id_w_t_ffffcc90] = 0;
          DAT_ffffcc8e = '\0';
        }
        if (DAT_ffffcc93 != 0) {
        LAB_00006c86:
          DAT_ffffe230 = 0;
          FUN_00000472((ulong)unaff_A6, 0, lVar6);
          DAT_ffff97e9 = 0;
          (*(code *)((int)&JMP_00006cb2 +
                     (int)*(
                         short *)((int)&JMP_00006cb2 +
                                  (int)(short)((ushort)DAT_ffffcc93 * 2))))();
          FUN_0002a720();
          uVar3 = FUN_00006184();
          return uVar3;
        }
        comp_has_func_maybe = comp_has_func_maybe & 0xf7;
        comp_state_a = comp_state_a & 0xfb;
        uint8_t_ffffcc70 = '\0';
        ecs_holding_a_rope = ecs_holding_a_rope & 0x7f;
        iVar10 = (*(
            code *)((int)&WORD_00007762 +
                    (int)*(short *)((int)&WORD_00007762 +
                                    (int)(short)((ushort)DAT_ffffcc92 * 2))))();
        lVar6 = (long)iVar10;
        if (iVar10 < 0)
          goto LAB_00006c86;
        DAT_ffffcc92 = 0;
        do {
          ecs_called_before_run_entity_func_all();
          ecs_run_entity_func_all();
          ecs_called_after_run_entity_func_all();
          FUN_00016904();
          while (true) {
            DAT_ffff9807 = '\0';
            FUN_00009a74();
            DAT_ffff97e4 = '\0';
            FUN_0002afb0();
            if (((DAT_ffffcc85 == '\0') && (DAT_ffff9808 == '\0')) &&
                ((gamepad_pressed_prev & GAMEPAD_START) != GAMEPAD_NONE)) {
              game_lock();
              menu_in_game_handle_input();
              game_unlock();
              lVar6 = extraout_D1;
              if (DAT_ffffcc92 != 0)
                goto LAB_00006c6c;
            }
            ecs_do_somthing_for_entity_id_8_to_48();
            FUN_00029aee();
            FUN_0001008a(unaff_A5, new_ctx);
            if (DAT_ffff97e4 == '\0')
              break;
            audio_pause();
            if (OWNED_HEALING_MEDICINE_COUNT == '\0') {
              audio_play_sound_asha_dies();
            }
            game_lock();
            lVar2 = CONCAT22(extraout_D0u, 0x3c);
            lVar6 = extraout_D1_02;
            do {
              uVar9 = exception_unk_0(unaff_A3,
                                      ENTITY_ID_ASHA,
                                      unaff_A6,
                                      lVar2,
                                      lVar6,
                                      unaff_D2,
                                      unaff_D3,
                                      unaff_D4,
                                      unaff_D5,
                                      unaff_D6,
                                      unaff_D7);
              lVar6 = (long)uVar9;
              sVar4 = (short)lVar2 + -1;
              lVar2 = CONCAT22((short)((ulonglong)uVar9 >> 0x30), sVar4);
            } while (sVar4 != 0);
            comp_state_a = comp_state_a | 4;
            DAT_ffffab42 = 0;
            DAT_ffffab43 = 0;
            DAT_ffff97fa = comp_pos_x.fixed.i;
            DAT_ffff97fc = comp_pos_y.fixed.i;
            comp_anim_b = 0;
            comp_has_func_maybe = 0;
            ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x1a);
            comp_state_a = comp_state_a | 0x80;
            do {
              FUN_00009a74();
              comp_pos_y.fixed.i = comp_pos_y.fixed.i - 1;
            } while ((ushort)(DAT_ffffc746 - 0x10U) <
                     (ushort)comp_pos_y.fixed.i);
            FUN_00001646();
            if ((OWNED_HEALING_MEDICINE_COUNT == '\0') ||
                (FUN_0000655a(unaff_A3), extraout_D0b == '\0')) {
              palette_set_fade(~PALETTE_ID_FLAG_NONE,
                               PALETTE_FADE_BLACK_EASE_IN,
                               '\0',
                               (palette_color_iter_t)0xffffffff);
              uVar9 = CONCAT44(extraout_D0, extraout_D1_03);
              do {
                uVar9 = exception_unk_0(unaff_A3,
                                        ENTITY_ID_ASHA,
                                        unaff_A6,
                                        (long)((ulonglong)uVar9 >> 0x20),
                                        (long)uVar9,
                                        -1,
                                        -1,
                                        unaff_D4,
                                        unaff_D5,
                                        unaff_D6,
                                        unaff_D7);
              } while (palette_fade_done_0 == 0);
              FUN_0000140c();
              audio_play(SOUND_ID_FF);
              DAT_ffff9154 = 0xffff;
              audio_stop_all();
              uVar3 = FUN_00009a74();
              return uVar3;
            }
            DAT_ffffcc92 = 0;
            if (DAT_ffff9807 != '\0') {
              FUN_00006632();
              comp_state = COMP_STATE_STAND;
              comp_anim_b = 0;
              ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
              vdp_set_window_position(4);
              FUN_00006526();
              UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
              uVar3 = FUN_00006184();
              return uVar3;
            }
            comp_pos_x.fixed.i = DAT_ffff97fa;
            comp_pos_y.fixed.i = DAT_ffff97fc;
            FUN_0002861a();
            comp_has_func_maybe = 0;
            comp_state = COMP_STATE_STAND;
            comp_anim_b = 0;
            ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
            game_unlock();
            audio_resume();
          }
          lVar6 = extraout_D1_00;
          if (DAT_ffffcc92 != 0)
            break;
          FUN_0001859e();
          FUN_0002e48a();
          FUN_00012f8a();
          lVar6 = extraout_D1_01;
        } while (DAT_ffffcc92 == 0);
      } while (true);
    }
    FUN_0002980e();
    f_00 = extraout_A1_00;
    if (9 < extraout_D1w) {
      script_ctx_bf_0c_arg_item_name_index =
          *(undefined1 *)(*(int *)(&comp_unk_9 + _DAT_ffffcf86) + 3);
      DAT_ffffd916 = 7;
      FUN_0001937a();
      ecs_anim_unk_2((int)_DAT_ffffcf86, unaff_A5, 4);
      ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x28);
      FUN_00007a9e();
      DAT_ffffcc92 = 0;
      *(undefined1 *)((int)&comp_state + (int)_DAT_ffffcf86) = 0;
      game_unlock();
      audio_resume();
      return 0;
    }
  }
  FUN_0000147a(f_00, 2, 0);
  do {
  } while (new_ctx < 0);
  eVar7 = (entity_id_t)new_ctx;
  entity_reset(eVar7);
  FUN_00024da0();
  (&comp_func_offset[0].unk1)[eVar7] = extraout_D1b;
  FUN_000019ae();
  (&comp_state_a)[eVar7] = (&comp_state_a)[eVar7] | 0x80;
  iVar8 = (int)_DAT_ffffcf86;
  *(int16_t *)((int)&comp_pos_x + eVar7) = comp_pos_x.fixed.i;
  *(undefined2 *)((int)&comp_pos_y + eVar7) =
      *(undefined2 *)((int)&comp_pos_y + iVar8);
  *(short *)((int)&comp_pos_y + eVar7) =
      *(short *)((int)&comp_pos_y + eVar7) + -0x18;
  *(undefined2 *)((int)&comp_unk_3 + eVar7) = 4;
  ecs_anim_unk_2(eVar7, unaff_A5, 0);
  *(undefined2 *)((int)&comp_vel[0].x + eVar7) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + eVar7) = 0xfc00;
  comp_anim_b = 0;
  _DAT_ffff97f8 = new_ctx;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x2a);
  FUN_00007aae();
  puVar1 = *(ushort **)(&comp_unk_9 + _DAT_ffffcf86);
  audio_play(SOUND_ID_JINGLE_1);
  script_ctx_bf_0c_arg_item_name_index = *(undefined1 *)((int)puVar1 + 3);
  DAT_ffffd916 = 6;
  FUN_0001937a();
  FUN_00029824();
  script_state_set_true((script_state_bit_t)(*puVar1 & 0x7fff));
  *(undefined1 *)((int)&comp_state + (int)_DAT_ffffcf86) = 1;
  DAT_ffffcc92 = 0;
  (&comp_has_func_maybe)[_DAT_ffff97f8] = 0;
  audio_resume();
  game_unlock();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_00007992(void)

{
  anim_item_t *unaff_A5;

  script_ctx_bf_0c_arg_item_name_index =
      *(undefined1 *)(*(int *)(&comp_unk_9 + _DAT_ffffcf86) + 3);
  DAT_ffffd916 = 7;
  FUN_0001937a();
  ecs_anim_unk_2((int)_DAT_ffffcf86, unaff_A5, 4);
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x28);
  FUN_00007a9e();
  DAT_ffffcc92 = 0;
  *(undefined1 *)((int)&comp_state + (int)_DAT_ffffcf86) = 0;
  game_unlock();
  audio_resume();
  return 0;
}

undefined4 FUN_000079de(void)

{
  int unaff_A4;

  audio_resume();
  DAT_ffffcc92 = 0;
  *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  game_unlock();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_000079f4(void)

{
  anim_item_t *unaff_A5;

  script_ctx_bf_0c_arg_item_name_index =
      *(undefined1 *)(*(int *)(&comp_unk_9 + _DAT_ffffcf86) + 3);
  DAT_ffffd916 = 0x72;
  FUN_0001937a();
  ecs_anim_unk_2((int)_DAT_ffffcf86, unaff_A5, 4);
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x28);
  FUN_00007a9e();
  DAT_ffffcc92 = 0;
  *(undefined1 *)((int)&comp_state + (int)_DAT_ffffcf86) = 0;
  game_unlock();
  audio_resume();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_00007a40(void)

{
  anim_item_t *unaff_A5;

  script_ctx_bf_0c_arg_item_name_index =
      *(undefined1 *)(*(int *)(&comp_unk_9 + _DAT_ffffcf86) + 3);
  DAT_ffffd916 = 0x73;
  FUN_0001937a();
  ecs_anim_unk_2((int)_DAT_ffffcf86, unaff_A5, 4);
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x28);
  FUN_00007a9e();
  DAT_ffffcc92 = 0;
  *(undefined1 *)((int)&comp_state + (int)_DAT_ffffcf86) = 0;
  game_unlock();
  audio_resume();
  return 0;
}

void FUN_00007a8c(void)

{
  entity_state_1_a_t eVar1;
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar2;

  uVar2 = CONCAT44(in_D0, in_D1);
  do {
    uVar2 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar2 >> 0x20),
                            (long)uVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    unaff_A4 = ENTITY_ID_ASHA;
    eVar1 = comp_state_1_a & 0x20;
    comp_state_1_a = comp_state_1_a & 0xdf;
  } while (eVar1 == 0);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00007a9e(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    unaff_A4 = (entity_id_t)_DAT_ffffcf86;
  } while (*(short *)((int)&comp_anim_tick + unaff_A4) != 0);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00007aae(void)

{
  short *psVar1;
  undefined2 extraout_D0u;
  long in_D0;
  long extraout_D0;
  undefined2 extraout_D1u;
  long in_D1;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  bool bVar2;
  undefined4 uVar3;

  do {
    do {
      exception_unk_0(unaff_A3,
                      unaff_A4,
                      unaff_A6,
                      in_D0,
                      in_D1,
                      unaff_D2,
                      unaff_D3,
                      unaff_D4,
                      unaff_D5,
                      unaff_D6,
                      unaff_D7);
      unaff_A4 = (entity_id_t)_DAT_ffff97f8;
      player_update_pos(unaff_A4);
      psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
      *psVar1 = *psVar1 + 0x40;
      bVar2 = false;
      in_D0 = extraout_D0;
      in_D1 = extraout_D1;
    } while (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0);
    unaff_A3 = (script_ctx_t *)0x0;
    uVar3 = ecs_check_collides_x(unaff_A4, 0);
    in_D0 = CONCAT22(extraout_D0u, (short)((uint)uVar3 >> 0x10));
    in_D1 = CONCAT22(extraout_D1u, (short)uVar3);
  } while (!bVar2);
  return;
}

undefined4 FUN_00007ad4(void)

{
  int unaff_A4;

  if ((*(short *)(*(int *)(&comp_unk_9 + unaff_A4) + 2) == 0x37) &&
      (total_hearts != total_hearts_max)) {
    return 1;
  }
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_00007afa(void)

{
  ushort *puVar1;
  byte extraout_D1b;
  short unaff_D2w;
  func *in_A1;
  entity_id_t e;
  int iVar2;
  anim_item_t *unaff_A5;

  FUN_0000147a(in_A1, 2, 0);
  do {
  } while (unaff_D2w < 0);
  e = (entity_id_t)unaff_D2w;
  entity_reset(e);
  FUN_00024da0();
  (&comp_func_offset[0].unk1)[e] = extraout_D1b;
  FUN_000019ae();
  (&comp_state_a)[e] = (&comp_state_a)[e] | 0x80;
  iVar2 = (int)_DAT_ffffcf86;
  *(int16_t *)((int)&comp_pos_x + e) = comp_pos_x.fixed.i;
  *(undefined2 *)((int)&comp_pos_y + e) =
      *(undefined2 *)((int)&comp_pos_y + iVar2);
  *(short *)((int)&comp_pos_y + e) = *(short *)((int)&comp_pos_y + e) + -0x18;
  *(undefined2 *)((int)&comp_unk_3 + e) = 4;
  ecs_anim_unk_2(e, unaff_A5, 0);
  *(undefined2 *)((int)&comp_vel[0].x + e) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + e) = 0xfc00;
  comp_anim_b = 0;
  _DAT_ffff97f8 = unaff_D2w;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x2a);
  FUN_00007bda();
  puVar1 = *(ushort **)(&comp_unk_9 + _DAT_ffffcf86);
  audio_play(SOUND_ID_JINGLE_1);
  script_ctx_bf_0c_arg_item_name_index = 0x37;
  DAT_ffffd916 = 6;
  FUN_0001937a();
  FUN_00029824();
  script_state_set_true((script_state_bit_t)(*puVar1 & 0x7fff));
  *(undefined1 *)((int)&comp_state + (int)_DAT_ffffcf86) = 1;
  DAT_ffffcc92 = 0;
  (&comp_has_func_maybe)[_DAT_ffff97f8] = 0;
  audio_resume();
  game_unlock();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00007bda(void)

{
  short *psVar1;
  undefined2 extraout_D0u;
  long in_D0;
  long extraout_D0;
  undefined2 extraout_D1u;
  long in_D1;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  bool bVar2;
  undefined4 uVar3;

  do {
    do {
      exception_unk_0(unaff_A3,
                      unaff_A4,
                      unaff_A6,
                      in_D0,
                      in_D1,
                      unaff_D2,
                      unaff_D3,
                      unaff_D4,
                      unaff_D5,
                      unaff_D6,
                      unaff_D7);
      unaff_A4 = (entity_id_t)_DAT_ffff97f8;
      player_update_pos(unaff_A4);
      psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
      *psVar1 = *psVar1 + 0x40;
      bVar2 = false;
      in_D0 = extraout_D0;
      in_D1 = extraout_D1;
    } while (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0);
    unaff_A3 = (script_ctx_t *)0x0;
    uVar3 = ecs_check_collides_x(unaff_A4, 0);
    in_D0 = CONCAT22(extraout_D0u, (short)((uint)uVar3 >> 0x10));
    in_D1 = CONCAT22(extraout_D1u, (short)uVar3);
  } while (!bVar2);
  return;
}

void FUN_00007c00(void)

{
  short sVar1;
  undefined2 extraout_D0u;
  long lVar2;
  char extraout_D0b;
  undefined4 extraout_D0;
  long extraout_D1;
  long extraout_D1_00;
  long extraout_D1_01;
  long extraout_D1_02;
  long lVar3;
  undefined4 extraout_D1_03;
  long extraout_D1_04;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar4;
  int6 iVar5;

  FUN_00007c2e();
  FUN_00007c56();
  FUN_00007cb0();
  audio_play(SOUND_ID_JINGLE_1);
  FUN_00007cfe();
  FUN_00007d16();
  script_ctx_bf_0c_arg_item_name_index = FUN_00007d36();
  FUN_000271ec();
  lVar3 = extraout_D1_04;
LAB_00006c6c:
  do {
    if (DAT_ffffcc8e != '\0') {
      (&comp_has_func_maybe)[(short)entity_id_w_t_ffffcc90] = 0;
      DAT_ffffcc8e = '\0';
    }
    if (DAT_ffffcc93 != 0) {
    LAB_00006c86:
      DAT_ffffe230 = 0;
      FUN_00000472((ulong)unaff_A6, 0, lVar3);
      DAT_ffff97e9 = 0;
      (*(code *)((int)&JMP_00006cb2 +
                 (int)*(short *)((int)&JMP_00006cb2 +
                                 (int)(short)((ushort)DAT_ffffcc93 * 2))))();
      FUN_0002a720();
      FUN_00006184();
      return;
    }
    comp_has_func_maybe = comp_has_func_maybe & 0xf7;
    comp_state_a = comp_state_a & 0xfb;
    uint8_t_ffffcc70 = '\0';
    ecs_holding_a_rope = ecs_holding_a_rope & 0x7f;
    iVar5 =
        (*(code *)((int)&WORD_00007762 +
                   (int)*(short *)((int)&WORD_00007762 +
                                   (int)(short)((ushort)DAT_ffffcc92 * 2))))();
    lVar3 = (long)iVar5;
    if (iVar5 < 0)
      goto LAB_00006c86;
    DAT_ffffcc92 = 0;
    do {
      ecs_called_before_run_entity_func_all();
      ecs_run_entity_func_all();
      ecs_called_after_run_entity_func_all();
      FUN_00016904();
      while (true) {
        DAT_ffff9807 = '\0';
        FUN_00009a74();
        DAT_ffff97e4 = '\0';
        FUN_0002afb0();
        if (((DAT_ffffcc85 == '\0') && (DAT_ffff9808 == '\0')) &&
            ((gamepad_pressed_prev & GAMEPAD_START) != GAMEPAD_NONE)) {
          game_lock();
          menu_in_game_handle_input();
          game_unlock();
          lVar3 = extraout_D1;
          if (DAT_ffffcc92 != 0)
            goto LAB_00006c6c;
        }
        ecs_do_somthing_for_entity_id_8_to_48();
        FUN_00029aee();
        FUN_0001008a(unaff_A5, (short)unaff_D2);
        if (DAT_ffff97e4 == '\0')
          break;
        audio_pause();
        if (OWNED_HEALING_MEDICINE_COUNT == '\0') {
          audio_play_sound_asha_dies();
        }
        game_lock();
        lVar2 = CONCAT22(extraout_D0u, 0x3c);
        lVar3 = extraout_D1_02;
        do {
          uVar4 = exception_unk_0(unaff_A3,
                                  ENTITY_ID_ASHA,
                                  unaff_A6,
                                  lVar2,
                                  lVar3,
                                  unaff_D2,
                                  unaff_D3,
                                  unaff_D4,
                                  unaff_D5,
                                  unaff_D6,
                                  unaff_D7);
          lVar3 = (long)uVar4;
          sVar1 = (short)lVar2 + -1;
          lVar2 = CONCAT22((short)((ulonglong)uVar4 >> 0x30), sVar1);
        } while (sVar1 != 0);
        comp_state_a = comp_state_a | 4;
        DAT_ffffab42 = 0;
        DAT_ffffab43 = 0;
        DAT_ffff97fa = comp_pos_x.fixed.i;
        DAT_ffff97fc = comp_pos_y.fixed.i;
        comp_anim_b = 0;
        comp_has_func_maybe = 0;
        ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x1a);
        comp_state_a = comp_state_a | 0x80;
        do {
          FUN_00009a74();
          comp_pos_y.fixed.i = comp_pos_y.fixed.i - 1;
        } while ((ushort)(DAT_ffffc746 - 0x10U) < (ushort)comp_pos_y.fixed.i);
        FUN_00001646();
        if (OWNED_HEALING_MEDICINE_COUNT == '\0') {
        LAB_000064f4:
          palette_set_fade(~PALETTE_ID_FLAG_NONE,
                           PALETTE_FADE_BLACK_EASE_IN,
                           '\0',
                           (palette_color_iter_t)0xffffffff);
          uVar4 = CONCAT44(extraout_D0, extraout_D1_03);
          do {
            uVar4 = exception_unk_0(unaff_A3,
                                    ENTITY_ID_ASHA,
                                    unaff_A6,
                                    (long)((ulonglong)uVar4 >> 0x20),
                                    (long)uVar4,
                                    -1,
                                    -1,
                                    unaff_D4,
                                    unaff_D5,
                                    unaff_D6,
                                    unaff_D7);
          } while (palette_fade_done_0 == 0);
          FUN_0000140c();
          audio_play(SOUND_ID_FF);
          DAT_ffff9154 = 0xffff;
          audio_stop_all();
          FUN_00009a74();
          return;
        }
        FUN_0000655a(unaff_A3);
        if (extraout_D0b == '\0')
          goto LAB_000064f4;
        DAT_ffffcc92 = 0;
        if (DAT_ffff9807 != '\0') {
          FUN_00006632();
          comp_state = COMP_STATE_STAND;
          comp_anim_b = 0;
          ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
          vdp_set_window_position(4);
          FUN_00006526();
          UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
          FUN_00006184();
          return;
        }
        comp_pos_x.fixed.i = DAT_ffff97fa;
        comp_pos_y.fixed.i = DAT_ffff97fc;
        FUN_0002861a();
        comp_has_func_maybe = 0;
        comp_state = COMP_STATE_STAND;
        comp_anim_b = 0;
        ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
        game_unlock();
        audio_resume();
      }
      lVar3 = extraout_D1_00;
      if (DAT_ffffcc92 != 0)
        break;
      FUN_0001859e();
      FUN_0002e48a();
      FUN_00012f8a();
      lVar3 = extraout_D1_01;
    } while (DAT_ffffcc92 == 0);
  } while (true);
}

undefined8 FUN_00007c2e(void)

{
  long extraout_D0;
  char duration;
  long extraout_D1;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  FUN_00007d36();
  FUN_0000aba0(palettes[1]);
  palette_set_fade(PALETTE_ID_FLAG_1,
                   PALETTE_FADE_1,
                   duration,
                   (palette_color_iter_t)0xffffffff);
  uVar1 = exception_unk_0(unaff_A3,
                          unaff_A4,
                          unaff_A6,
                          extraout_D0,
                          extraout_D1,
                          2,
                          -1,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar1;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00007c56(void)

{
  byte state_1_b;
  char cVar1;
  short unaff_D2w;
  int iVar2;
  func *in_A1;
  entity_id_t self;
  anim_item_t *unaff_A5;

  FUN_0000147a(in_A1, 0, 0);
  self = (entity_id_t)unaff_D2w;
  ecs_anim_unk_2(self, unaff_A5, state_1_b);
  (&comp_anim_base_offset)[self] = 0xc;
  (&comp_anim_b)[self] = 0x2e;
  cVar1 = FUN_00007d36();
  ecs_anim_unk_2(self, unaff_A5, (cVar1 + -0x70) * '\x02');
  *(undefined2 *)((int)&comp_unk_3 + self) = 0x16;
  (&comp_state_a)[self] = (&comp_state_a)[self] | 0x80;
  iVar2 = (int)_DAT_ffffcf86;
  *(undefined2 *)((int)&comp_pos_x + self) =
      *(undefined2 *)((int)&comp_pos_x + iVar2);
  *(undefined2 *)((int)&comp_pos_y + self) =
      *(undefined2 *)((int)&comp_pos_y + iVar2);
  *(short *)((int)&comp_pos_y + self) =
      *(short *)((int)&comp_pos_y + self) + -0x20;
  *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + self) = 0;
  (&DAT_ffffb976)[self] = 4;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00007cb0(void)

{
  short *psVar1;
  char cVar2;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar3;

  do {
    uVar3 = FUN_00014722();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar3 >> 0x20),
                    (long)uVar3,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    unaff_A4 = (entity_id_t)(short)unaff_A4;
    ecs_update_pos_y(unaff_A4);
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + -0x40;
    if (*(short *)((int)&comp_vel[0].y + unaff_A4) < -0x2ff) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfd00;
    }
    cVar2 = (&DAT_ffffb976)[unaff_A4] + -1;
    (&DAT_ffffb976)[unaff_A4] = cVar2;
    if (cVar2 == '\0') {
      (&DAT_ffffb976)[unaff_A4] = 4;
      FUN_0000185e();
    }
  } while ((ushort)(*(short *)((int)&comp_pos_y + (int)_DAT_ffffcf86) - 0x60U) <
           *(ushort *)((int)&comp_pos_y + unaff_A4));
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  return;
}

void FUN_00007cfe(void)

{
  short sVar1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar2;

  sVar1 = 0x96;
  do {
    uVar2 = FUN_00014722();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar2 >> 0x20),
                    (long)uVar2,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    sVar1 = sVar1 + -1;
  } while (sVar1 != 0);
  return;
}

undefined8 FUN_00007d16(void)

{
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  do {
    uVar1 = FUN_00014722();
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (palette_fade_done_0 == 0);
  return uVar1;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined1 FUN_00007d36(void)

{
  return *(undefined1 *)(*(int *)(&comp_unk_9 + _DAT_ffffcf86) + 3);
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_00007d4a(void)

{
  entity_id_w_t unaff_D2w;
  anim_item_t *unaff_A5;

  game_lock();
  audio_pause();
  FUN_00009d60();
  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  comp_has_func_maybe = 0;
  comp_anim_b = 0xc;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  FUN_00007dfe();
  FUN_0000165c(&WORD_00007df8,
               unaff_A5,
               unaff_D2w,
               comp_pos_x.fixed.i,
               comp_pos_y.fixed.i + 6,
               comp_state_a);
  _DAT_ffffcf86 = 0;
  _comp_unk_1 = 2;
  comp_some_function = FUN_00009d14;
  comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 2);
  comp_anim_speed = 0x200;
  FUN_00007e12();
  audio_play(SOUND_ID_BOMB_USE);
  comp_anim_speed = 0x100;
  FUN_00007e2c();
  FUN_00007e5e();
  FUN_00007e9a();
  audio_play(SOUND_ID_JUNGLE_5);
  audio_resume();
  game_unlock();
  return 0;
}

void FUN_00007dfe(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar1 = FUN_00009cf2();
    unaff_A4 = ENTITY_ID_ASHA;
  } while (comp_anim_tick != 0);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00007e12(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  _DAT_ffff9804 = 0x1e;
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar1 = FUN_00009cf2();
    _DAT_ffff9804 = _DAT_ffff9804 + -1;
  } while (-1 < _DAT_ffff9804);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00007e2c(void)

{
  long in_D0;
  long extraout_D0;
  long in_D1;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  void *unaff_A6;

  _DAT_ffff9804 = 0x10;
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    in_D0,
                    in_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_00009cf2();
    unaff_A4 = ENTITY_ID_ASHA;
    comp_vel[0].x.raw = 0x300;
    player_update_pos(0);
    _DAT_ffff9804 = _DAT_ffff9804 + -1;
    in_D0 = extraout_D0;
    in_D1 = extraout_D1;
  } while (-1 < _DAT_ffff9804);
  comp_vel[0].x.raw = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 4);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00007e5e(void)

{
  entity_state_1_a_t eVar1;
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar2;

  uVar2 = CONCAT44(in_D0, in_D1);
  _DAT_ffff9804 = 5;
  do {
    uVar2 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar2 >> 0x20),
                            (long)uVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    _DAT_ffff9804 = _DAT_ffff9804 + -1;
  } while (_DAT_ffff9804 != 0);
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar2 >> 0x20),
                    (long)uVar2,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar2 = FUN_00009cf2();
    unaff_A4 = (entity_id_t)_DAT_ffffcf86;
    eVar1 = (&comp_state_1_a)[unaff_A4];
    (&comp_state_1_a)[unaff_A4] = eVar1 & 0xdf;
  } while ((eVar1 & 0x20) == 0);
  WORD_ffff97fe = 0x5a;
  UNION_sound_id_word_union_t_ffff9800.as_word = 0;
  _DAT_ffff9802 = 0;
  FUN_0001689e();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00007e9a(void)

{
  undefined2 uVar1;
  byte bVar2;
  undefined2 extraout_D0u;
  undefined2 extraout_D0u_00;
  undefined4 in_D0;
  short sVar3;
  undefined4 in_D1;
  undefined4 extraout_D1;
  undefined4 extraout_D1_00;
  undefined4 uVar4;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  func *f;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  int iVar5;
  entity_id_t unaff_A5;
  void *unaff_A6;
  undefined8 uVar6;

  uVar6 = CONCAT44(in_D0, in_D1);
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar6 >> 0x20),
                    (long)uVar6,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_00016904();
    FUN_00009cf2();
    bVar2 = BYTE_ARRAY_00007f22[_DAT_ffff9802];
    uVar6 = CONCAT44(CONCAT22(extraout_D0u, _DAT_ffff9802),
                     CONCAT31((int3)((uint)extraout_D1 >> 8), bVar2));
    if (bVar2 != 0) {
      if (bVar2 == 1) {
        uVar6 = FUN_00007fa8();
      } else {
        FUN_00007f52(unaff_A5, (entity_id_w_t)unaff_D2, f);
        uVar6 = CONCAT44(CONCAT22(extraout_D0u_00,
                                  UNION_sound_id_word_union_t_ffff9800.as_word),
                         extraout_D1_00);
        if (-1 < (short)(entity_id_w_t)unaff_D2) {
          sVar3 = UNION_sound_id_word_union_t_ffff9800.as_word << 2;
          *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) =
              *(undefined2 *)((int)&vel_7f32[0].x + (int)sVar3);
          uVar1 = *(undefined2 *)((int)&vel_7f32[0].y + (int)sVar3);
          uVar4 = CONCAT22((short)((uint)extraout_D1_00 >> 0x10), uVar1);
          *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = uVar1;
          UNION_sound_id_word_union_t_ffff9800.as_word =
              UNION_sound_id_word_union_t_ffff9800.as_word + 1;
          uVar6 = CONCAT44(CONCAT22(extraout_D0u_00, sVar3), uVar4);
          if (UNION_sound_id_word_union_t_ffff9800.as_word == 8) {
            UNION_sound_id_word_union_t_ffff9800.as_word = 0;
            uVar6 = CONCAT44(CONCAT22(extraout_D0u_00, sVar3), uVar4);
          }
        }
      }
    }
    _DAT_ffff9802 = _DAT_ffff9802 + 1;
    if (_DAT_ffff9802 == 0x10) {
      _DAT_ffff9802 = 0;
    }
    WORD_ffff97fe = WORD_ffff97fe - 1;
  } while (WORD_ffff97fe != 0);
  FUN_0001689e();
  iVar5 = (int)_DAT_ffffda72;
  script_state_set_true(*(script_state_bit_t *)(&DAT_ffffba76 + iVar5));
  (&comp_has_func_maybe)[iVar5] = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00007f52(entity_id_t self, entity_id_w_t other, func *f)

{
  int iVar1;
  entity_id_t loc_other;

  FUN_0000147a(f, 2, 2);
  if (-1 < (short)other) {
    loc_other = (entity_id_t)(short)other;
    entity_reset(loc_other);
    *(code **)((int)&comp_some_function + loc_other) = FUN_00009d20;
    iVar1 = (int)_DAT_ffffda72;
    *(undefined2 *)((int)&comp_pos_x + loc_other) =
        *(undefined2 *)((int)&comp_pos_x + iVar1);
    *(undefined2 *)((int)&comp_pos_y + loc_other) =
        *(undefined2 *)((int)&comp_pos_y + iVar1);
    *(short *)((int)&comp_pos_y + loc_other) =
        *(short *)((int)&comp_pos_y + loc_other) + -0x10;
    *(undefined2 *)((int)&comp_unk_3 + loc_other) = 4;
    (&comp_anim_base_offset)[loc_other] = 0x14;
    (&comp_anim_b)[loc_other] = 8;
    ecs_anim_unk_2(loc_other, (anim_item_t *)self, 2);
    (&comp_state_a)[loc_other] = (&comp_state_a)[loc_other] | 0x80;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00007fa8(void)

{
  word wVar1;
  short sVar2;
  short unaff_D2w;
  func *in_A1;
  int iVar3;
  entity_id_t e;
  anim_item_t *unaff_A5;

  FUN_0000147a(in_A1, 2, 2);
  if (-1 < unaff_D2w) {
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    *(code **)((int)&comp_some_function + e) = FUN_00009d14;
    iVar3 = (int)_DAT_ffffda72;
    *(undefined2 *)((int)&comp_pos_x + e) =
        *(undefined2 *)((int)&comp_pos_x + iVar3);
    *(undefined2 *)((int)&comp_pos_y + e) =
        *(undefined2 *)((int)&comp_pos_y + iVar3);
    *(short *)((int)&comp_pos_y + e) = *(short *)((int)&comp_pos_y + e) + -0x10;
    *(undefined2 *)((int)&comp_vel[0].y + e) = 0;
    *(undefined2 *)((int)&comp_vel[0].x + e) = 0;
    *(undefined2 *)((int)&comp_unk_3 + e) = 4;
    (&comp_anim_base_offset)[e] = 0x14;
    (&comp_anim_b)[e] = 0;
    ecs_anim_unk_2(e, unaff_A5, 0);
    (&comp_state_a)[e] = (&comp_state_a)[e] | 0x80;
    wVar1 = rand();
    sVar2 = (wVar1 & 7) << 2;
    *(short *)((int)&comp_pos_x + e) =
        *(short *)((int)&int16_vec2_t_ARRAY_0000801e[0].x + (int)sVar2) +
        *(short *)((int)&comp_pos_x + e);
    *(short *)((int)&comp_pos_y + e) =
        *(short *)((int)&int16_vec2_t_ARRAY_0000801e[0].y + (int)sVar2) +
        *(short *)((int)&comp_pos_y + e);
  }
  return;
}

undefined4 FUN_0000803a(void)

{
  game_lock();
  FUN_00008056();
  FUN_0000807a();
  FUN_0000809a();
  DAT_ffffcc92 = 0;
  game_unlock();
  return 0;
}

void FUN_00008056(void)

{
  int unaff_A4;
  anim_item_t *unaff_A5;

  *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
  comp_has_func_maybe = 0;
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x24);
  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000807a(void)

{
  entity_state_1_a_t eVar1;
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  entity_id_t self;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar2;

  uVar2 = CONCAT44(in_D0, in_D1);
  do {
    uVar2 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar2 >> 0x20),
                            (long)uVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    unaff_A4 = ENTITY_ID_ASHA;
    eVar1 = comp_state_1_a & 0x20;
    comp_state_1_a = comp_state_1_a & 0xdf;
  } while (eVar1 == 0);
  self = (entity_id_t)_DAT_ffffcc6e;
  (&comp_has_func_maybe)[self] = 0;
  ecs_anim_unk_2(self, unaff_A5, 4);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000809a(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  entity_id_t self;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    unaff_A4 = ENTITY_ID_ASHA;
  } while (comp_anim_tick != 0);
  self = (entity_id_t)_DAT_ffffcc6e;
  script_state_set_true(*(script_state_bit_t *)(&DAT_ffffba76 + self));
  ecs_anim_unk_2(self, unaff_A5, 2);
  comp_state = COMP_STATE_STAND;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000080e4(void)

{
  ushort uVar1;
  int iVar2;
  anim_item_t *unaff_A5;

  iVar2 = (int)_DAT_ffffde38;
  *(undefined1 *)((int)&comp_state + iVar2) = 1;
  comp_vel[1].x.raw = 0;
  comp_vel[1].y.raw = 0;
  related_to_entering_a_room_2 = related_to_entering_a_room_2 | 0x20;
  pepelogoo_state_b = pepelogoo_state_b & 0xbf;
  component_state_b_pepelogoo = 0;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 0x18);
  component_pos_y_pepelogoo.fixed.i = *(short *)((int)&comp_pos_y + iVar2) + -5;
  uVar1 = *(ushort *)((int)&comp_pos_x + iVar2);
  if (uVar1 < (ushort)component_pos_x_pepelogoo._0_2_) {
    component_pos_x_pepelogoo.fixed.i = uVar1 + 0xb;
    DAT_ffff9f1f = DAT_ffff9f1f | 8;
  } else {
    component_pos_x_pepelogoo.fixed.i = uVar1 - 0xb;
    DAT_ffff9f1f = DAT_ffff9f1f & 0xf7;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00008140(void)

{
  byte bVar1;
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  entity_id_t self;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar2;

  uVar2 = CONCAT44(in_D0, in_D1);
  do {
    uVar2 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar2 >> 0x20),
                            (long)uVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    unaff_A4 = ENTITY_ID_PEPELOGOO;
    bVar1 = DAT_ffffa63d & 0x20;
    DAT_ffffa63d = DAT_ffffa63d & 0xdf;
  } while (bVar1 == 0);
  self = (entity_id_t)_DAT_ffffde38;
  (&comp_has_func_maybe)[self] = 0;
  ecs_anim_unk_2(self, unaff_A5, 4);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00008160(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  entity_id_t self;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    unaff_A4 = ENTITY_ID_PEPELOGOO;
  } while (sRamffffa538 != 0);
  self = (entity_id_t)_DAT_ffffde38;
  script_state_set_true(*(script_state_bit_t *)(&DAT_ffffba76 + self));
  ecs_anim_unk_2(self, unaff_A5, 2);
  FUN_00029d0c();
  related_to_entering_a_room_2 = related_to_entering_a_room_2 & 0xdf;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_00008194(void)

{
  game_lock();
  (&comp_has_func_maybe)[_DAT_ffffde38] =
      (&comp_has_func_maybe)[_DAT_ffffde38] & 0xfc;
  FUN_000081ba();
  FUN_00008216();
  FUN_0000824c();
  DAT_ffffcc92 = 0;
  game_unlock();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000081ba(void)

{
  ushort uVar1;
  int iVar2;
  anim_item_t *unaff_A5;

  iVar2 = (int)_DAT_ffffde38;
  *(undefined1 *)((int)&comp_state + iVar2) = 1;
  comp_vel[1].x.raw = 0;
  comp_vel[1].y.raw = 0;
  related_to_entering_a_room_2 = related_to_entering_a_room_2 | 0x20;
  pepelogoo_state_b = pepelogoo_state_b & 0xbf;
  component_state_b_pepelogoo = 0;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 0x20);
  component_pos_y_pepelogoo.fixed.i = *(short *)((int)&comp_pos_y + iVar2) + -5;
  uVar1 = *(ushort *)((int)&comp_pos_x + iVar2);
  if (uVar1 < (ushort)component_pos_x_pepelogoo._0_2_) {
    component_pos_x_pepelogoo.fixed.i = uVar1 + 0xb;
    DAT_ffff9f1f = DAT_ffff9f1f | 8;
  } else {
    component_pos_x_pepelogoo.fixed.i = uVar1 - 0xb;
    DAT_ffff9f1f = DAT_ffff9f1f & 0xf7;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00008216(void)

{
  undefined4 in_D0;
  byte bVar1;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  entity_id_t self;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar2;

  uVar2 = CONCAT44(in_D0, in_D1);
  do {
    uVar2 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar2 >> 0x20),
                            (long)uVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    unaff_A4 = ENTITY_ID_PEPELOGOO;
    bVar1 = DAT_ffffa63d & 0x20;
    DAT_ffffa63d = DAT_ffffa63d & 0xdf;
  } while (bVar1 == 0);
  audio_play(SOUND_ID_EXT_BREATH);
  self = (entity_id_t)_DAT_ffffde38;
  (&comp_has_func_maybe)[self] = 0;
  if ((DAT_ffff9f1f & 8) == 0) {
    bVar1 = 0;
  } else {
    bVar1 = 2;
  }
  ecs_anim_unk_2(self, unaff_A5, bVar1);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000824c(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    unaff_A4 = (entity_id_t)_DAT_ffffde38;
  } while (*(short *)((int)&comp_anim_tick + unaff_A4) != 0);
  (&comp_has_func_maybe)[unaff_A4] = 0;
  script_state_set_true(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  FUN_00029d0c();
  related_to_entering_a_room_2 = related_to_entering_a_room_2 & 0xdf;
  return;
}

undefined4 FUN_0000827a(void)

{
  game_lock();
  audio_pause();
  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  FUN_000082a6();
  FUN_00008312();
  FUN_000083b6();
  DAT_ffffcc92 = 0;
  audio_resume();
  game_unlock();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000082a6(void)

{
  long extraout_D0;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;

  comp_anim_b = 0;
  comp_has_func_maybe = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 2);
  while (true) {
    if (comp_pos_x.fixed.i == _DAT_ffffcf80)
      break;
    if ((ushort)comp_pos_x._0_2_ < _DAT_ffffcf80 ||
        comp_pos_x.fixed.i == _DAT_ffffcf80) {
      comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
      comp_vel[0].x.raw = 0x100;
    } else {
      comp_state_a = comp_state_a | ENTITY_STATE_A_08;
      comp_vel[0].x.raw = -0x100;
    }
    entity_update_pos(ENTITY_ID_ASHA);
    exception_unk_0(unaff_A3,
                    ENTITY_ID_ASHA,
                    unaff_A6,
                    extraout_D0,
                    extraout_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  comp_state_a = comp_state_a | ENTITY_STATE_A_08;
  comp_anim_b = 0xe;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0xc);
  audio_play(SOUND_ID_SCOOP_UP);
  return;
}

void FUN_00008312(void)

{
  short *psVar1;
  entity_state_1_a_t eVar2;
  undefined2 extraout_D0u;
  undefined4 in_D0;
  long extraout_D0;
  long extraout_D0_00;
  undefined2 extraout_D1u;
  undefined4 in_D1;
  byte extraout_D1b;
  long extraout_D1;
  long extraout_D1_00;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  uint uVar5;
  long unaff_D6;
  long unaff_D7;
  func *f;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  entity_id_t e;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  bool bVar6;
  undefined8 uVar7;
  undefined4 uVar8;
  long lVar3;
  long lVar4;

  uVar7 = CONCAT44(in_D0, in_D1);
  do {
    uVar7 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar7 >> 0x20),
                            (long)uVar7,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    unaff_A4 = ENTITY_ID_ASHA;
    eVar2 = comp_state_1_a & 0x20;
    comp_state_1_a = comp_state_1_a & 0xdf;
  } while (eVar2 == 0);
  FUN_0000147a(f, 0, 0);
  do {
  } while ((short)unaff_D2 < 0);
  e = (entity_id_t)(short)unaff_D2;
  entity_reset(e);
  uVar5 = (uint)DAT_ffffcf7e;
  FUN_00024da0();
  (&comp_func_offset[0].unk1)[e] = extraout_D1b;
  FUN_000019ae();
  *(int16_t *)((int)&comp_pos_x + e) = comp_pos_x.fixed.i;
  *(int16_t *)((int)&comp_pos_y + e) = comp_pos_y.fixed.i;
  *(short *)((int)&comp_pos_x + e) = *(short *)((int)&comp_pos_x + e) + -0xb;
  *(short *)((int)&comp_pos_y + e) = *(short *)((int)&comp_pos_y + e) + -0x10;
  *(undefined2 *)((int)&comp_unk_3 + e) = 4;
  ecs_anim_unk_2(e, unaff_A5, 2);
  *(undefined2 *)((int)&comp_vel[0].x + e) = 0x80;
  *(undefined2 *)((int)&comp_vel[0].y + e) = 0xfc00;
  lVar3 = extraout_D0;
  lVar4 = extraout_D1;
  do {
    do {
      exception_unk_0(unaff_A3,
                      e,
                      unaff_A6,
                      lVar3,
                      lVar4,
                      unaff_D2,
                      unaff_D3,
                      unaff_D4,
                      uVar5,
                      unaff_D6,
                      unaff_D7);
      e = (entity_id_t)(short)e;
      player_update_pos(e);
      psVar1 = (short *)((int)&comp_vel[0].y + e);
      *psVar1 = *psVar1 + 0x40;
      bVar6 = false;
      lVar3 = extraout_D0_00;
      lVar4 = extraout_D1_00;
    } while (*(short *)((int)&comp_vel[0].y + e) < 0);
    unaff_A3 = (script_ctx_t *)0x0;
    uVar8 = ecs_check_collides_x(e, 0);
    lVar3 = CONCAT22(extraout_D0u, (short)((uint)uVar8 >> 0x10));
    lVar4 = CONCAT22(extraout_D1u, (short)uVar8);
  } while (!bVar6);
  *(undefined2 *)((int)&comp_vel[0].x + e) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + e) = 0;
  audio_play(SOUND_ID_JUNGLE_5);
  return;
}

void FUN_000083b6(void)

{
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0xe);
  uVar1 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar1 = exception_unk_0((script_ctx_t *)0x0,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    unaff_A4 = (entity_id_t)(short)unaff_A4;
  } while (comp_anim_tick != 0);
  (&comp_has_func_maybe)[unaff_A4] = 0;
  FUN_00029d0c();
  comp_vel[0].x.raw = 0;
  comp_state = COMP_STATE_STAND;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_000083f0(void)

{
  anim_item_t *unaff_A5;

  game_lock();
  (&comp_has_func_maybe)[_DAT_ffffda72] =
      (&comp_has_func_maybe)[_DAT_ffffda72] & 0xfc;
  FUN_0000844c();
  comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
  if (*(ushort *)((int)&comp_pos_x + (int)_DAT_ffffda72) <=
      (ushort)comp_pos_x.fixed.i) {
    comp_state_a = comp_state_a | ENTITY_STATE_A_08;
  }
  comp_has_func_maybe = 0;
  comp_anim_b = 0xe;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x10);
  FUN_00008472();
  FUN_00008484();
  FUN_000084f6();
  FUN_00008532();
  DAT_ffffcc92 = 0;
  game_unlock();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000844c(void)

{
  FUN_00009d60();
  return;
}

void FUN_00008472(void)

{
  entity_state_1_a_t eVar1;
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar2;

  uVar2 = CONCAT44(in_D0, in_D1);
  do {
    uVar2 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar2 >> 0x20),
                            (long)uVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    unaff_A4 = ENTITY_ID_ASHA;
    eVar1 = comp_state_1_a & 0x20;
    comp_state_1_a = comp_state_1_a & 0xdf;
  } while (eVar1 == 0);
  return;
}

void FUN_00008484(void)

{
  short sVar1;
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  func *in_A1;
  script_ctx_t *unaff_A3;
  entity_id_t e;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar2;

  FUN_0000147a(in_A1, 0, 0);
  do {
  } while ((short)unaff_D2 < 0);
  e = (entity_id_t)(short)unaff_D2;
  entity_reset(e);
  *(undefined2 *)((int)&comp_unk_3 + e) = 0x10;
  (&comp_anim_base_offset)[e] = 0x14;
  (&comp_anim_b)[e] = 0x18;
  *(int16_t *)((int)&comp_pos_x + e) = comp_pos_x.fixed.i;
  *(int16_t *)((int)&comp_pos_y + e) = comp_pos_y.fixed.i;
  *(short *)((int)&comp_pos_y + e) = *(short *)((int)&comp_pos_y + e) + 2;
  sVar1 = 0x1c;
  (&comp_state_a)[e] = (&comp_state_a)[e] & ~ENTITY_STATE_A_08;
  if ((comp_state_a & ENTITY_STATE_A_08) != 0) {
    (&comp_state_a)[e] = (&comp_state_a)[e] | ENTITY_STATE_A_08;
    sVar1 = -0x1c;
  }
  *(short *)((int)&comp_pos_x + e) = sVar1 + *(short *)((int)&comp_pos_x + e);
  ecs_anim_unk_2(e, unaff_A5, 0);
  audio_play(SOUND_ID_EXT_BUCKET);
  uVar2 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar2 = exception_unk_0(unaff_A3,
                            e,
                            unaff_A6,
                            (long)((ulonglong)uVar2 >> 0x20),
                            (long)uVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    e = (entity_id_t)(short)e;
  } while (*(short *)((int)&comp_anim_tick + e) != 0);
  (&comp_has_func_maybe)[e] = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000084f6(void)

{
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *ctx;
  entity_id_t self;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  self = (entity_id_t)_DAT_ffffda72;
  *(undefined2 *)(&comp_unk_1 + self) = 0;
  ecs_anim_unk_2(self, unaff_A5, 2);
  script_state_set_true(*(script_state_bit_t *)(&DAT_ffffba76 + self));
  ctx = (script_ctx_t *)(int)*(short *)((int)&comp_unk_8 + self);
  *(undefined1 *)&ctx[-0x14a].bf_03_and_bf_06_arg_fed_to_vdp_data = 0;
  ctx[-0x213].bf_05_arg2_vram_address_related = 0xffff;
  audio_play(SOUND_ID_JUNGLE_5);
  uVar1 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar1 = exception_unk_0(ctx,
                            self,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (comp_anim_tick != 0);
  return;
}

void FUN_00008532(void)

{
  FUN_00029d0c();
  comp_state = COMP_STATE_STAND;
  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_00008550(void)

{
  game_lock();
  (&comp_has_func_maybe)[_DAT_ffffde38] =
      (&comp_has_func_maybe)[_DAT_ffffde38] & 0xfc;
  FUN_00008572();
  FUN_000085ce();
  DAT_ffffcc92 = 0;
  game_unlock();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00008572(void)

{
  ushort uVar1;
  int iVar2;
  anim_item_t *unaff_A5;

  iVar2 = (int)_DAT_ffffde38;
  *(undefined1 *)((int)&comp_state + iVar2) = 1;
  comp_vel[1].x.raw = 0;
  comp_vel[1].y.raw = 0;
  related_to_entering_a_room_2 = related_to_entering_a_room_2 | 0x20;
  pepelogoo_state_b = pepelogoo_state_b & 0xbf;
  component_state_b_pepelogoo = 0;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 0x26);
  component_pos_y_pepelogoo.fixed.i = *(short *)((int)&comp_pos_y + iVar2) + -5;
  uVar1 = *(ushort *)((int)&comp_pos_x + iVar2);
  if (uVar1 < (ushort)component_pos_x_pepelogoo._0_2_) {
    component_pos_x_pepelogoo.fixed.i = uVar1 + 0xb;
    DAT_ffff9f1f = DAT_ffff9f1f | 8;
  } else {
    component_pos_x_pepelogoo.fixed.i = uVar1 - 0xb;
    DAT_ffff9f1f = DAT_ffff9f1f & 0xf7;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000085ce(void)

{
  byte bVar1;
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar2;

  uVar2 = CONCAT44(in_D0, in_D1);
  do {
    uVar2 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar2 >> 0x20),
                            (long)uVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    unaff_A4 = ENTITY_ID_PEPELOGOO;
    unaff_A3 = (script_ctx_t *)(int)_DAT_ffffde38;
    bVar1 = DAT_ffffa63d & 0x20;
    DAT_ffffa63d = DAT_ffffa63d & 0xdf;
    if (bVar1 != 0) {
      unaff_A3[-0xffffffff00000286].d = 2;
      unaff_A3[-0xffffffff00000286].e = 0;
    }
    bVar1 = DAT_ffffa63d & 0x10;
    DAT_ffffa63d = DAT_ffffa63d & 0xef;
    if (bVar1 != 0) {
      unaff_A3[-0xffffffff00000286].d = 1;
      unaff_A3[-0xffffffff00000286].e = 0;
    }
  } while (sRamffffa538 != 0);
  unaff_A3[-0xffffffff00000286].d = 1;
  unaff_A3[-0xffffffff00000286].e = 0;
  FUN_00029d0c();
  related_to_entering_a_room_2 = related_to_entering_a_room_2 & 0xdf;
  return;
}

undefined4 FUN_00008610(void)

{
  game_lock();
  FUN_0000863c();
  FUN_00008652();
  FUN_000086ce();
  FUN_00008718();
  FUN_000087bc();
  FUN_000087ca();
  FUN_000087d4();
  DAT_ffffcc92 = 0;
  game_unlock();
  return 0;
}

void FUN_0000863c(void)

{
  int unaff_A4;

  FUN_00009d60();
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00008652(void)

{
  short *psVar1;
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D2;
  short sVar2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  func *in_A1;
  script_ctx_t *unaff_A3;
  entity_id_t e;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar3;

  FUN_0000147a(in_A1, 0, 0);
  sVar2 = (short)unaff_D2;
  do {
  } while (sVar2 < 0);
  e = (entity_id_t)sVar2;
  entity_reset(e);
  *(undefined2 *)((int)&comp_unk_3 + e) = 8;
  (&comp_anim_base_offset)[e] = 0xc;
  (&comp_anim_b)[e] = 0x10;
  ecs_anim_unk_2(e, unaff_A5, 0);
  *(int16_t *)((int)&comp_pos_x + e) = comp_pos_x.fixed.i;
  *(int16_t *)((int)&comp_pos_y + e) = comp_pos_y.fixed.i;
  *(short *)((int)&comp_pos_y + e) =
      *(short *)((int)&comp_pos_y + e) - comp_collision_sensor[0].y;
  psVar1 = (short *)((int)&comp_collision_sensor[0].y + e);
  *psVar1 = *psVar1 - *(short *)((int)&comp_collision_sensor[0].y + e);
  comp_has_func_maybe = 0;
  comp_state_a = comp_state_a | ENTITY_STATE_A_08;
  comp_anim_b = 6;
  _DAT_ffffda72 = sVar2;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 8);
  uVar3 = CONCAT44(extraout_D0, extraout_D1);
  do {
    exception_unk_0(unaff_A3,
                    ENTITY_ID_ASHA,
                    unaff_A6,
                    (long)((ulonglong)uVar3 >> 0x20),
                    (long)uVar3,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar3 = FUN_00014722();
  } while ((comp_state_1_a & 0x20) == 0);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000086ce(void)

{
  short *psVar1;
  ushort uVar2;
  undefined2 extraout_D0u;
  long in_D0;
  long in_D1;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t self;
  void *unaff_A6;

  self = (entity_id_t)_DAT_ffffda72;
  *(undefined2 *)((int)&comp_vel[0].y + self) = 0xfb00;
  *(undefined2 *)((int)&comp_vel[0].x + self) = 0xfd80;
  do {
    exception_unk_0(unaff_A3,
                    self,
                    unaff_A6,
                    in_D0,
                    in_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_00014722();
    self = (entity_id_t)_DAT_ffffda72;
    entity_update_pos(self);
    psVar1 = (short *)((int)&comp_vel[0].y + self);
    *psVar1 = *psVar1 + 0x60;
    uVar2 = (comp_collision_sensor[0].y + comp_pos_y.fixed.i) - 0x20;
    in_D0 = CONCAT22(extraout_D0u, uVar2);
    in_D1 = extraout_D1;
  } while (*(ushort *)((int)&comp_pos_y + self) < uVar2);
  (&comp_has_func_maybe)[self] = 0;
  FUN_00001832();
  *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00008718(void)

{
  undefined2 extraout_D0u;
  undefined4 in_D0;
  long lVar1;
  undefined4 in_D1;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  int in_A0;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  entity_id_t self;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar2;

  uVar2 = CONCAT44(in_D0, in_D1);
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar2 >> 0x20),
                    (long)uVar2,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar2 = FUN_00014722();
    in_A0 = (int)(short)in_A0;
  } while (*(short *)((int)&comp_anim_tick + in_A0) != 0);
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar2 >> 0x20),
                  (long)uVar2,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  FUN_00014722();
  self = (entity_id_t)_DAT_ffffda72;
  entity_update_pos(self);
  entity_reset(self);
  *(undefined2 *)((int)&comp_unk_7 + self) = 800;
  (&comp_has_func_maybe)[self] = (&comp_has_func_maybe)[self] | 0x20;
  (&comp_anim_base_offset)[self] = 8;
  (&comp_anim_b)[self] = 0x16;
  ecs_anim_unk_2(self, unaff_A5, 0);
  *(int16_t *)((int)&comp_pos_x + self) = comp_pos_x.fixed.i;
  *(int16_t *)((int)&comp_pos_y + self) = comp_pos_y.fixed.i;
  lVar1 = CONCAT22(extraout_D0u, comp_collision_sensor[0].y);
  *(short *)((int)&comp_pos_y + self) =
      comp_collision_sensor[0].y + *(short *)((int)&comp_pos_y + self);
  *(short *)((int)&comp_pos_x + self) =
      *(short *)((int)&comp_pos_x + self) + -0x40;
  *(short *)((int)&comp_pos_y + self) =
      *(short *)((int)&comp_pos_y + self) + -0x20;
  *(short *)((int)&comp_pos_y + self) =
      *(short *)((int)&comp_pos_y + self) + -0x10;
  exception_unk_0(unaff_A3,
                  self,
                  unaff_A6,
                  lVar1,
                  extraout_D1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  uVar2 = FUN_00014722();
  exception_unk_0(unaff_A3,
                  self,
                  unaff_A6,
                  (long)((ulonglong)uVar2 >> 0x20),
                  (long)uVar2,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  uVar2 = FUN_00014722();
  exception_unk_0(unaff_A3,
                  self,
                  unaff_A6,
                  (long)((ulonglong)uVar2 >> 0x20),
                  (long)uVar2,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  uVar2 = FUN_00014722();
  exception_unk_0(unaff_A3,
                  self,
                  unaff_A6,
                  (long)((ulonglong)uVar2 >> 0x20),
                  (long)uVar2,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  uVar2 = FUN_00014722();
  exception_unk_0(unaff_A3,
                  self,
                  unaff_A6,
                  (long)((ulonglong)uVar2 >> 0x20),
                  (long)uVar2,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  FUN_00014722();
  return;
}

void FUN_000087bc(void)

{
  DAT_ffffd916 = 0x2d;
  FUN_0001937a();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000087ca(void)

{
  (&comp_has_func_maybe)[_DAT_ffffda72] = 0;
  return;
}

void FUN_000087d4(void)

{
  comp_vel[0].y.raw = 0;
  comp_vel[0].x.raw = 0;
  comp_state = COMP_STATE_STAND;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_000087e8(void)

{
  anim_item_t *unaff_A5;

  game_lock();
  (&comp_has_func_maybe)[_DAT_ffffda72] =
      (&comp_has_func_maybe)[_DAT_ffffda72] & 0xfc;
  FUN_00008844();
  comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
  if (*(ushort *)((int)&comp_pos_x + (int)_DAT_ffffda72) <=
      (ushort)comp_pos_x.fixed.i) {
    comp_state_a = comp_state_a | ENTITY_STATE_A_08;
  }
  comp_has_func_maybe = 0;
  comp_anim_b = 0xe;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x10);
  FUN_00008894();
  FUN_000088a6();
  FUN_00008912();
  FUN_0000893e();
  DAT_ffffcc92 = 0;
  game_unlock();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00008844(void)

{
  ushort uVar1;
  undefined2 extraout_D0u;
  long extraout_D0;
  long lVar2;
  long extraout_D1;
  long lVar3;
  long extraout_D1_00;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *ctx;
  anim_item_t *unaff_A5;
  void *unaff_A6;

  comp_vel[0].y.raw = 0;
  comp_has_func_maybe = 0;
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 2);
  ctx = (script_ctx_t *)(int)_DAT_ffffda72;
  comp_vel[0].x.raw = -0x200;
  comp_state_a = comp_state_a | ENTITY_STATE_A_08;
  lVar2 = extraout_D0;
  lVar3 = extraout_D1;
  do {
    exception_unk_0(ctx,
                    ENTITY_ID_ASHA,
                    unaff_A6,
                    lVar2,
                    lVar3,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    ctx = (script_ctx_t *)(int)_DAT_ffffda72;
    player_update_pos(0);
    uVar1 = *(short *)&ctx[-0x2a3].h - 0x30;
    lVar2 = CONCAT22(extraout_D0u, uVar1);
    lVar3 = extraout_D1_00;
  } while (uVar1 < (ushort)comp_pos_x.fixed.i);
  comp_vel[0].x.raw = 0;
  comp_pos_x.fixed.i = uVar1;
  return;
}

void FUN_00008894(void)

{
  entity_state_1_a_t eVar1;
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar2;

  uVar2 = CONCAT44(in_D0, in_D1);
  do {
    uVar2 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar2 >> 0x20),
                            (long)uVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    unaff_A4 = ENTITY_ID_ASHA;
    eVar1 = comp_state_1_a & 0x20;
    comp_state_1_a = comp_state_1_a & 0xdf;
  } while (eVar1 == 0);
  return;
}

void FUN_000088a6(void)

{
  short sVar1;
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  func *in_A1;
  script_ctx_t *unaff_A3;
  entity_id_t e;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar2;

  FUN_0000147a(in_A1, 0, 0);
  do {
  } while ((short)unaff_D2 < 0);
  e = (entity_id_t)(short)unaff_D2;
  entity_reset(e);
  *(undefined2 *)((int)&comp_unk_3 + e) = 0x10;
  (&comp_anim_base_offset)[e] = 0x14;
  (&comp_anim_b)[e] = 0x18;
  *(int16_t *)((int)&comp_pos_x + e) = comp_pos_x.fixed.i;
  *(int16_t *)((int)&comp_pos_y + e) = comp_pos_y.fixed.i;
  *(short *)((int)&comp_pos_y + e) = *(short *)((int)&comp_pos_y + e) + 2;
  sVar1 = 0x1c;
  (&comp_state_a)[e] = (&comp_state_a)[e] & ~ENTITY_STATE_A_08;
  if ((comp_state_a & ENTITY_STATE_A_08) != 0) {
    (&comp_state_a)[e] = (&comp_state_a)[e] | ENTITY_STATE_A_08;
    sVar1 = -0x1c;
  }
  *(short *)((int)&comp_pos_x + e) = sVar1 + *(short *)((int)&comp_pos_x + e);
  ecs_anim_unk_2(e, unaff_A5, 0);
  uVar2 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar2 = exception_unk_0(unaff_A3,
                            e,
                            unaff_A6,
                            (long)((ulonglong)uVar2 >> 0x20),
                            (long)uVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    e = (entity_id_t)(short)e;
  } while (*(short *)((int)&comp_anim_tick + e) != 0);
  (&comp_has_func_maybe)[e] = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00008912(void)

{
  short sVar1;
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  entity_id_t self;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar2;

  self = (entity_id_t)_DAT_ffffda72;
  ecs_anim_unk_2(self, unaff_A5, 4);
  sVar1 = *(short *)((int)&comp_unk_8 + self);
  script_state_set_true(
      (script_state_bit_t)((script_ctx_t *)(int)sVar1)[-0x155].i);
  audio_play(SOUND_ID_JUNGLE_5);
  uVar2 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar2 = exception_unk_0((script_ctx_t *)(int)sVar1,
                            self,
                            unaff_A6,
                            (long)((ulonglong)uVar2 >> 0x20),
                            (long)uVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (comp_anim_tick != 0);
  return;
}

void FUN_0000893e(void)

{
  FUN_00029d0c();
  comp_state = COMP_STATE_STAND;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_00008954(void)

{
  undefined4 uVar1;
  undefined4 extraout_D0;
  byte extraout_D1b;
  undefined4 extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  uint uVar2;
  long unaff_D6;
  long unaff_D7;
  short sVar3;
  char *pcVar4;
  func *f;
  int iVar5;
  script_ctx_t *unaff_A3;
  entity_id_t e;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar6;

  game_lock();
  FUN_00009d60();
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0xe);
  FUN_0000147a(f, 8, 0);
  _DAT_ffffda72 = (short)unaff_D2;
  e = (entity_id_t)_DAT_ffffda72;
  entity_reset(e);
  uVar2 = (uint)DAT_ffffcf7e;
  FUN_00024da0();
  (&comp_func_offset[0].unk1)[e] = extraout_D1b;
  uVar1 = FUN_000019ae();
  *(undefined2 *)((int)&comp_pos_x + e) = _DAT_ffffcf80;
  *(undefined2 *)((int)&comp_pos_y + e) = _DAT_ffffcf82;
  *(undefined2 *)((int)&comp_unk_3 + e) = 0x1a;
  (&DAT_ffffde46)[(short)CONCAT31((int3)((uint)uVar1 >> 8), DAT_ffffde4b)] =
      DAT_ffffcf7e;
  ecs_anim_unk_2(e, unaff_A5, 0);
  *(short *)((int)&comp_pos_y + e) =
      *(short *)((int)&comp_pos_y + e) -
      *(short *)((int)&comp_collision_sensor[0].y + e);
  FUN_000018d2();
  audio_play(SOUND_ID_BOX_OPEN);
  uVar6 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar6 = exception_unk_0(unaff_A3,
                            e,
                            unaff_A6,
                            (long)((ulonglong)uVar6 >> 0x20),
                            (long)uVar6,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            uVar2,
                            unaff_D6,
                            unaff_D7);
    e = (entity_id_t)(short)e;
  } while (*(short *)((int)&comp_anim_tick + e) != 0);
  (&comp_has_func_maybe)[e] = 0;
  exception_unk_0(unaff_A3,
                  e,
                  unaff_A6,
                  (long)((ulonglong)uVar6 >> 0x20),
                  (long)uVar6,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  uVar2,
                  unaff_D6,
                  unaff_D7);
  sVar3 = 4;
  pcVar4 = &DAT_ffffde46;
  do {
    if (*pcVar4 < '\0')
      goto LAB_00008a26;
    sVar3 = sVar3 + -1;
    pcVar4 = pcVar4 + 1;
  } while (sVar3 != -1);
  sVar3 = 4;
  pcVar4 = &DAT_ffffde46;
  iVar5 = _DAT_ffffde4c;
  do {
    if ((char)*(undefined2 *)(iVar5 + 4) != *pcVar4) {
      audio_pause();
      FUN_0002b708();
      goto LAB_00008a26;
    }
    iVar5 = iVar5 + 6;
    sVar3 = sVar3 + -1;
    pcVar4 = pcVar4 + 1;
  } while (sVar3 != -1);
  audio_play_sound_asha_dies();
  FUN_0002b62c();
LAB_00008a26:
  audio_resume();
  DAT_ffffcc92 = 0;
  game_unlock();
  return 0;
}

undefined4 FUN_00008a36(void)

{
  anim_item_t *unaff_A5;

  game_lock();
  FUN_00009d60();
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0xe);
  purchase_regen_item();
  DAT_ffffcc92 = 0;
  game_unlock();
  return 0;
}

void FUN_00008a8e(void)

{
  FUN_00009d60();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00008aa0(void)

{
  undefined4 uVar1;
  byte extraout_D1b;
  short unaff_D2w;
  func *in_A1;
  entity_id_t e;
  anim_item_t *unaff_A5;

  FUN_0000147a(in_A1, 0, 0);
  do {
  } while (unaff_D2w < 0);
  e = (entity_id_t)unaff_D2w;
  entity_reset(e);
  FUN_00024da0();
  (&comp_func_offset[0].unk1)[e] = extraout_D1b;
  uVar1 = FUN_000019ae();
  *(undefined2 *)((int)&comp_pos_x + e) = _DAT_ffffcf80;
  *(int16_t *)((int)&comp_pos_y + e) = comp_pos_y.fixed.i;
  *(undefined2 *)((int)&comp_unk_3 + e) = 0x1a;
  (&DAT_ffffde46)[(short)CONCAT31((int3)((uint)uVar1 >> 8), DAT_ffffde4b)] =
      DAT_ffffcf7e;
  ecs_anim_unk_2(e, unaff_A5, 0);
  *(short *)((int)&comp_pos_y + e) =
      *(short *)((int)&comp_pos_y + e) -
      *(short *)((int)&comp_collision_sensor[0].y + e);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00008af6(void)

{
  script_state_set_true(_DAT_ffffcf82);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address
// FIXME Where is it called?

undefined4 FUN_00008b02(void)

{
  undefined4 uVar1;
  short unaff_A4w;

  game_lock();
  FUN_00008b74();
  if (script_ctx_bf_0e_arg == (&DAT_ffffb976)[_DAT_ffffda72]) {
    FUN_00008baa();
    uVar1 = FUN_00008bfc();
    if ((short)uVar1 != 0) {
      FUN_000077ce();
    }
    (&comp_has_func_maybe)[unaff_A4w] = 0;
    (&comp_has_func_maybe)[_DAT_ffffda72] = 0;
    DAT_ffffcc92 = 0;
    game_unlock();
    if ((short)uVar1 != 0) {
      uVar1 = 0xffffffff;
    }
    return uVar1;
  }
  FUN_00029824();
  DAT_ffffd916 = 0xbf;
  FUN_0001937a();
  DAT_ffffcc92 = 0;
  game_unlock();
  return 0;
}

void FUN_00008b74(void)

{
  short sVar1;
  undefined2 extraout_D0u;
  long lVar2;
  long extraout_D1;
  long lVar3;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar4;

  FUN_00009d60();
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0xe);
  lVar2 = CONCAT22(extraout_D0u, 0x3c);
  lVar3 = extraout_D1;
  do {
    uVar4 = exception_unk_0(unaff_A3,
                            ENTITY_ID_ASHA,
                            unaff_A6,
                            lVar2,
                            lVar3,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    lVar3 = (long)uVar4;
    sVar1 = (short)lVar2 + -1;
    lVar2 = CONCAT22((short)((ulonglong)uVar4 >> 0x30), sVar1);
  } while (sVar1 != 0);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00008baa(void)

{
  byte extraout_D1b;
  short unaff_D2w;
  func *in_A1;
  int iVar1;
  entity_id_t e;
  anim_item_t *unaff_A5;

  FUN_0000147a(in_A1, 0, 0);
  do {
  } while (unaff_D2w < 0);
  iVar1 = (int)_DAT_ffffda72;
  e = (entity_id_t)unaff_D2w;
  entity_reset(e);
  *(undefined2 *)((int)&comp_pos_x + e) =
      *(undefined2 *)((int)&comp_pos_x + iVar1);
  *(undefined2 *)((int)&comp_pos_y + e) =
      *(undefined2 *)((int)&comp_pos_y + iVar1);
  FUN_00024da0();
  (&comp_func_offset[0].unk1)[e] = extraout_D1b;
  FUN_000019ae();
  *(undefined2 *)((int)&comp_unk_3 + e) = 0x1a;
  ecs_anim_unk_2(e, unaff_A5, 0);
  script_state_set_true(*(script_state_bit_t *)(&DAT_ffffba76 + _DAT_ffffda72));
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00008bfc(void)

{
  DAT_ffffd916 = *(undefined2 *)((int)&comp_unk_8 + (int)_DAT_ffffda72);
  FUN_0001937a();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_00008c0e(void)

{
  game_lock();
  FUN_00009d60();
  comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
  FUN_00008c48();
  FUN_00008cb6();
  FUN_00008d28();
  (&comp_has_func_maybe)[_DAT_ffffda72] = 0;
  DAT_ffffcc92 = 0;
  game_unlock();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00008c48(void)

{
  short *psVar1;
  short sVar2;
  long extraout_D0;
  long lVar3;
  long extraout_D0_00;
  byte extraout_D1b;
  long extraout_D1;
  long lVar4;
  long extraout_D1_00;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  uint uVar5;
  long unaff_D6;
  undefined4 unaff_D7;
  long lVar6;
  short sVar7;
  func *in_A1;
  script_ctx_t *unaff_A3;
  entity_id_t e;
  anim_item_t *unaff_A5;
  void *unaff_A6;

  FUN_0000147a(in_A1, 0, 0);
  do {
  } while ((short)unaff_D2 < 0);
  e = (entity_id_t)(short)unaff_D2;
  entity_reset(e);
  uVar5 = (uint)DAT_ffffcf7e;
  FUN_00024da0();
  (&comp_func_offset[0].unk1)[e] = extraout_D1b;
  FUN_000019ae();
  *(undefined2 *)((int)&comp_pos_x + e) = 0x11e0;
  *(undefined2 *)((int)&comp_pos_y + e) = 0x1080;
  *(undefined2 *)((int)&comp_unk_3 + e) = 0x1a;
  ecs_anim_unk_2(e, unaff_A5, 0);
  *(undefined2 *)((int)&comp_vel[0].x + e) = 0x100;
  *(undefined2 *)((int)&comp_vel[0].y + e) = 0xfc00;
  lVar6 = CONCAT22((short)((uint)unaff_D7 >> 0x10), 0x1f);
  lVar3 = extraout_D0;
  lVar4 = extraout_D1;
  do {
    sVar2 = (short)e;
    exception_unk_0(unaff_A3,
                    e,
                    unaff_A6,
                    lVar3,
                    lVar4,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    uVar5,
                    unaff_D6,
                    lVar6);
    e = (entity_id_t)sVar2;
    player_update_pos(e);
    psVar1 = (short *)((int)&comp_vel[0].y + e);
    *psVar1 = *psVar1 + 0x40;
    sVar7 = (short)lVar6 + -1;
    lVar6 = CONCAT22((short)((uint)lVar6 >> 0x10), sVar7);
    lVar3 = extraout_D0_00;
    lVar4 = extraout_D1_00;
  } while (sVar7 != -1);
  _DAT_ffffda72 = sVar2;
  return;
}

void FUN_00008cb6(void)

{
  short sVar1;
  long unaff_D2;
  undefined2 uVar2;
  undefined4 unaff_D3;
  undefined2 uVar3;
  undefined4 unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar4;

  uVar2 = (undefined2)((uint)unaff_D3 >> 0x10);
  uVar3 = (undefined2)((uint)unaff_D4 >> 0x10);
  FUN_00008d12();
  sVar1 = 4;
  do {
    uVar4 = FUN_00009cd0();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar4 >> 0x20),
                    (long)uVar4,
                    unaff_D2,
                    CONCAT22(uVar2, 0x11f8),
                    CONCAT22(uVar3, 0x1080),
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  FUN_00008d12();
  sVar1 = 4;
  do {
    uVar4 = FUN_00009cd0();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar4 >> 0x20),
                    (long)uVar4,
                    unaff_D2,
                    CONCAT22(uVar2, 0x1208),
                    CONCAT22(uVar3, 0x1080),
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  FUN_00008d12();
  sVar1 = 4;
  do {
    uVar4 = FUN_00009cd0();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar4 >> 0x20),
                    (long)uVar4,
                    unaff_D2,
                    CONCAT22(uVar2, 0x1200),
                    CONCAT22(uVar3, 0x1080),
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return;
}

void FUN_00008d12(void)

{
  entity_id_w_t unaff_D2w;
  short unaff_D3w;
  short unaff_D4w;
  byte *unaff_A5;

  FUN_0000165c(&WORD_00008d22, unaff_A5, unaff_D2w, unaff_D3w, unaff_D4w, 0x80);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00008d28(void)

{
  long extraout_D0;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t self;
  anim_item_t *unaff_A5;
  void *unaff_A6;

  self = (entity_id_t)_DAT_ffffda72;
  (&comp_anim_base_offset)[self] = 6;
  (&comp_anim_b)[self] = 0x16;
  ecs_anim_unk_2(self, unaff_A5, 0);
  audio_play(SOUND_ID_JUNGLE_5);
  exception_unk_0(unaff_A3,
                  self,
                  unaff_A6,
                  extraout_D0,
                  extraout_D1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  script_state_set_true((script_state_bit_t)0x7f);
  return;
}

// FIXME Where is it called?

undefined4 FUN_00008d56(void)

{
  anim_item_t *unaff_A5;

  game_lock();
  FUN_00008d8e();
  FUN_00008daa();
  DAT_ffffd916 = 4;
  FUN_0001937a();
  FUN_0001a5fa();
  FUN_00008dca();
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  DAT_ffffcc92 = 0;
  game_unlock();
  return 0;
}

void FUN_00008d8e(void)

{
  FUN_00009d60();
  return;
}

void FUN_00008daa(void)

{
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x38);
  uVar1 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            ENTITY_ID_ASHA,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (comp_anim_tick != 0);
  return;
}

void FUN_00008dca(void)

{
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x3a);
  uVar1 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            ENTITY_ID_ASHA,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (comp_anim_tick != 0);
  return;
}

undefined4 FUN_00008de6(void)

{
  long extraout_D0;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  entity_id_t self;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  game_lock();
  if ((&DAT_ffffb976)[(short)entity_id_w_t_ffffcf94] != '\0') {
    (&comp_has_func_maybe)[*(
        short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                 (int)(short)entity_id_w_t_ffffcf94)] =
        (&comp_has_func_maybe)[*(
            short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                     (int)(short)entity_id_w_t_ffffcf94)] &
        ~COMPONENT_STATE_B_ACTIVE;
  }
  FUN_00008ea2();
  FUN_00008eb8();
  uVar1 = FUN_00008ed2();
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar1 >> 0x20),
                  (long)uVar1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  uVar1 = FUN_00014722();
  self = (entity_id_t)(short)entity_id_w_t_ffffcf94;
  if ((&DAT_ffffb976)[self] == '\0') {
    DAT_ffffcc92 = 0;
    game_unlock();
    return 0;
  }
  do {
    exception_unk_0(unaff_A3,
                    self,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar1 = FUN_00014722();
    self = (entity_id_t)(short)entity_id_w_t_ffffcf94;
  } while ((&DAT_ffffb976)[self] != '\0');
  exception_unk_0(unaff_A3,
                  self,
                  unaff_A6,
                  (long)((ulonglong)uVar1 >> 0x20),
                  (long)uVar1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  FUN_00014722();
  DAT_ffffb97b = 3;
  FUN_00009016(unaff_A5);
  comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  exception_unk_0(unaff_A3,
                  ENTITY_ID_ASHA,
                  unaff_A6,
                  extraout_D0,
                  extraout_D1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  comp_has_func_maybe = comp_has_func_maybe | COMPONENT_STATE_B_ACTIVE;
  DAT_ffffd916 = 5;
  FUN_0001937a();
  audio_play_sound_asha_dies();
  UNION_sound_id_word_union_t_ffff97e6 = UNION_sound_id_word_union_t_ffff9800;
  audio_play((sound_id_t)UNION_sound_id_word_union_t_ffff9800.as_word);
  DAT_ffffcc92 = 0;
  drop_pepelogoo();
  game_unlock();
  return 0;
}

void FUN_00008ea2(void)

{
  FUN_00009d60();
  return;
}

void FUN_00008eb8(void)

{
  entity_id_t self;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x2e);
  self = (entity_id_t)(short)entity_id_w_t_ffffcf94;
  (&comp_has_func_maybe)[self] = 0;
  ecs_anim_unk_2(self, unaff_A5, 2);
  return;
}

void FUN_00008ed2(void)

{
  entity_state_1_a_t eVar1;
  short sVar2;
  undefined2 extraout_D0u;
  undefined2 extraout_D0u_00;
  undefined2 uVar3;
  long in_D0;
  undefined4 extraout_D0;
  long in_D1;
  long extraout_D1;
  long extraout_D1_00;
  undefined4 extraout_D1_01;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  int iVar4;
  void *unaff_A6;
  undefined8 uVar5;

  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    in_D0,
                    in_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_00014722();
    in_D1 = extraout_D1;
    uVar3 = extraout_D0u;
    if ((short)in_D0 == 8) {
      audio_play(SOUND_ID_TREE);
      in_D1 = extraout_D1_00;
      uVar3 = extraout_D0u_00;
    }
    sVar2 = (short)in_D0 + -1;
    in_D0 = CONCAT22(uVar3, sVar2);
  } while (sVar2 != 0);
  uVar5 = FUN_00008f48();
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar5 >> 0x20),
                    (long)uVar5,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar5 = FUN_00014722();
    iVar4 = (int)(short)entity_id_w_t_ffffcf94;
    eVar1 = (&comp_state_1_a)[iVar4];
    (&comp_state_1_a)[iVar4] = eVar1 & 0xdf;
    if (((eVar1 & 0x20) != 0) && ((&DAT_ffffb976)[iVar4] != '\0')) {
      script_state_set_false(*(script_state_bit_t *)(&DAT_ffffba76 + iVar4));
      iVar4 =
          (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar4);
      *(undefined2 *)((int)&comp_vel[0].x + iVar4) = 0;
      *(undefined1 **)((int)&comp_some_function + iVar4) = &LAB_000098a2;
      *(undefined2 *)(&comp_unk_1 + iVar4) = 1;
      audio_pause();
      uVar5 = CONCAT44(extraout_D0, extraout_D1_01);
    }
    unaff_A4 = ENTITY_ID_ASHA;
  } while (comp_anim_tick != 0);
  return;
}

void FUN_00008f48(void)

{
  entity_id_w_t unaff_D2w;

  WORD_ffff97fe = 0;
  FUN_00008f86(unaff_D2w);
  WORD_ffff97fe = 1;
  FUN_00008f86(unaff_D2w);
  WORD_ffff97fe = 2;
  FUN_00008f86(unaff_D2w);
  WORD_ffff97fe = 3;
  FUN_00008f86(unaff_D2w);
  WORD_ffff97fe = 4;
  FUN_00008f86(unaff_D2w);
  WORD_ffff97fe = 5;
  FUN_00008f86(unaff_D2w);
  return;
}

void FUN_00008f86(entity_id_w_t self_w)

{
  short pos_table_offset;
  entity_id_t other;
  entity_id_t self;
  anim_item_t *unaff_A5;

  FUN_0000147a(FUN_00008ffe, 1, 4);
  if (-1 < (short)self_w) {
    self = (entity_id_t)(short)self_w;
    entity_reset(self);
    other = (entity_id_t)(short)entity_id_w_t_ffffcf94;
    *(undefined2 *)((int)&comp_pos_x + self) =
        *(undefined2 *)((int)&comp_pos_x + other);
    *(undefined2 *)((int)&comp_pos_y + self) =
        *(undefined2 *)((int)&comp_pos_y + other);
    (&comp_anim_base_offset)[self] = 0x14;
    (&comp_anim_b)[self] = 0x38;
    pos_table_offset = WORD_ffff97fe << 2;
    *(short *)((int)&comp_pos_x + self) =
        *(short *)((int)&pos_table_8fe6[0].x + (int)pos_table_offset) +
        *(short *)((int)&comp_pos_x + self);
    *(short *)((int)&comp_pos_y + self) =
        *(short *)((int)&pos_table_8fe6[0].y + (int)pos_table_offset) +
        *(short *)((int)&comp_pos_y + self);
    *(undefined2 *)((int)&comp_vel[0].y + self) = 0x100;
    *(undefined2 *)((int)&comp_unk_3 + self) = 0x1a;
    ecs_anim_unk_2(self, unaff_A5, 0);
  }
  return;
}

// FIXME Where is this used?

void FUN_00008ffe(void)

{
  entity_id_t unaff_A4;

  ecs_update_pos_y(unaff_A4);
  if (*(ushort *)((int)&comp_pos_y + (int)(short)entity_id_w_t_ffffcf94) <=
      *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

void FUN_00009016(anim_item_t *anim)

{
  short sVar1;
  ushort uVar2;
  byte bVar3;
  undefined2 extraout_D0u;
  undefined2 extraout_D0u_00;
  undefined2 extraout_D0u_01;
  undefined4 in_D0;
  long extraout_D0;
  long lVar4;
  long lVar5;
  long extraout_D0_00;
  undefined4 in_D1;
  long extraout_D1;
  long extraout_D1_00;
  long extraout_D1_01;
  long extraout_D1_02;
  long extraout_D1_03;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar6;

  uVar6 = CONCAT44(in_D0, in_D1);
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar6 >> 0x20),
                    (long)uVar6,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar6 = FUN_00014722();
    unaff_A4 = ENTITY_ID_PEPELOGOO;
    bVar3 = DAT_ffffa63d & 0x20;
    DAT_ffffa63d = DAT_ffffa63d & 0xdf;
  } while (bVar3 == 0);
  audio_play(SOUND_ID_PEPE_VOICE_3);
  comp_vel[1].y.raw = 0;
  lVar4 = extraout_D0;
  lVar5 = extraout_D1;
  do {
    exception_unk_0(unaff_A3,
                    ENTITY_ID_PEPELOGOO,
                    unaff_A6,
                    lVar4,
                    lVar5,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_000090e8();
    FUN_00014722();
    comp_vel[1].y.raw = comp_vel[1].y.raw + -0x40;
    ecs_update_pos_y(ENTITY_ID_PEPELOGOO);
    lVar4 = CONCAT22(extraout_D0u, DAT_ffffc746 - 0x20U);
    lVar5 = extraout_D1_00;
  } while ((ushort)(DAT_ffffc746 - 0x20U) <
           (ushort)component_pos_y_pepelogoo.fixed.i);
  lVar5 = 0x3c;
  lVar4 = extraout_D1_00;
  do {
    exception_unk_0(unaff_A3,
                    ENTITY_ID_PEPELOGOO,
                    unaff_A6,
                    lVar5,
                    lVar4,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_00014722();
    sVar1 = (short)lVar5 + -1;
    lVar5 = CONCAT22(extraout_D0u_00, sVar1);
    lVar4 = extraout_D1_01;
  } while (sVar1 != 0);
  script_ctx_bf_0e_arg = script_ctx_bf_0e_arg + 1;
  DAT_ffffa63b = (undefined1)((ushort)script_ctx_bf_0e_arg * 2);
  ecs_anim_unk_2(
      ENTITY_ID_PEPELOGOO,
      anim,
      (byte) * (undefined2 *)((int)WORD_ARRAY_000090e2 +
                              (int)(short)((ushort)script_ctx_bf_0e_arg * 2)));
  comp_vel[1].y.raw = 0x200;
  UNION_sound_id_word_union_t_ffff9800 = UNION_sound_id_word_union_t_ffff97e6;
  audio_play_sound_asha_dies();
  audio_play(SOUND_ID_BIRTH_OF_PEPELOGOO);
  lVar4 = extraout_D0_00;
  lVar5 = extraout_D1_02;
  do {
    exception_unk_0(unaff_A3,
                    ENTITY_ID_PEPELOGOO,
                    unaff_A6,
                    lVar4,
                    lVar5,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_00014722();
    ecs_update_pos_y(ENTITY_ID_PEPELOGOO);
    uVar2 = *(short *)((int)&comp_pos_y + (int)(short)entity_id_w_t_ffffcf94) -
            0x30;
    lVar4 = CONCAT22(extraout_D0u_01, uVar2);
    lVar5 = extraout_D1_03;
  } while ((ushort)component_pos_y_pepelogoo.fixed.i <= uVar2);
  component_pos_y_pepelogoo.fixed.i = uVar2;
  comp_vel[1].x.raw = 0;
  comp_vel[1].y.raw = 0;
  return;
}

void FUN_000090e8(void)

{
  char cVar1;
  int unaff_A4;

  cVar1 = *(char *)(unaff_A4 + -0x4689) + -1;
  *(char *)(unaff_A4 + -0x4689) = cVar1;
  if (cVar1 == '\0') {
    *(undefined1 *)(unaff_A4 + -0x4689) = 3;
    FUN_0000185e();
  }
  return;
}

undefined4 FUN_000090fa(void)

{
  short sVar1;
  undefined2 extraout_D0u;
  long lVar2;
  long extraout_D1;
  long lVar3;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar4;

  game_lock();
  FUN_00009162();
  audio_pause();
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0xe);
  lVar2 = CONCAT22(extraout_D0u, 0x3c);
  lVar3 = extraout_D1;
  do {
    uVar4 = exception_unk_0(unaff_A3,
                            ENTITY_ID_ASHA,
                            unaff_A6,
                            lVar2,
                            lVar3,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    lVar3 = (long)uVar4;
    sVar1 = (short)lVar2 + -1;
    lVar2 = CONCAT22((short)((ulonglong)uVar4 >> 0x30), sVar1);
  } while (sVar1 != 0);
  FUN_00009174();
  FUN_000091d6();
  FUN_0000927c();
  FUN_000092b6();
  FUN_000092e2();
  FUN_00009392();
  ecs_holding_a_rope = 0;
  drop_pepelogoo();
  FUN_000077ce();
  game_unlock();
  audio_resume();
  DAT_ffffcc92 = 0;
  return 0xffffffff;
}

void FUN_00009162(void)

{
  FUN_00009d60();
  return;
}

void FUN_00009174(void)

{
  ushort in_D1w;
  word unaff_D2w;
  func *in_A1;
  entity_id_t e;
  anim_item_t *unaff_A5;

  FUN_0000147a(in_A1, 0, in_D1w);
  do {
  } while ((short)unaff_D2w < 0);
  e = (entity_id_t)(short)unaff_D2w;
  WORD_ffff97fe = unaff_D2w;
  entity_reset(e);
  (&comp_state_a)[e] = 0x88;
  *(undefined2 *)((int)&comp_unk_3 + e) = 0x12;
  *(int16_t *)((int)&comp_pos_x + e) = comp_pos_x.fixed.i;
  *(int16_t *)((int)&comp_pos_y + e) = comp_pos_y.fixed.i;
  *(short *)((int)&comp_pos_y + e) =
      *(short *)((int)&comp_pos_y + e) - comp_collision_sensor[0].y;
  (&comp_anim_base_offset)[e] = 0xc;
  (&comp_anim_b)[e] = 0x2a;
  ecs_anim_unk_2(e, unaff_A5, 2);
  *(undefined2 *)((int)&comp_vel[0].y + e) = 0xff00;
  *(undefined2 *)((int)&comp_vel[0].x + e) = 0;
  (&DAT_ffffb976)[e] = 0x10;
  audio_play(SOUND_ID_FLOW);
  return;
}

void FUN_000091d6(void)

{
  char cVar1;
  short sVar2;
  undefined2 extraout_D0u;
  undefined4 in_D0;
  undefined4 extraout_D0;
  long lVar3;
  long extraout_D0_00;
  undefined4 extraout_D0_01;
  undefined4 extraout_D0_02;
  undefined4 in_D1;
  undefined4 extraout_D1;
  long extraout_D1_00;
  long extraout_D1_01;
  undefined4 extraout_D1_02;
  long lVar4;
  undefined4 extraout_D1_03;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  entity_id_t self;
  void *unaff_A6;
  undefined8 uVar5;

  uVar5 = CONCAT44(in_D0, in_D1);
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar5 >> 0x20),
                    (long)uVar5,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_00014722();
    unaff_A4 = (entity_id_t)(short)WORD_ffff97fe;
    ecs_update_pos_y(unaff_A4);
    uVar5 = CONCAT44(extraout_D0, extraout_D1);
    cVar1 = (&DAT_ffffb976)[unaff_A4] + -1;
    (&DAT_ffffb976)[unaff_A4] = cVar1;
    if (cVar1 == '\0') {
      (&DAT_ffffb976)[unaff_A4] = 0x10;
      uVar5 = FUN_0000185e();
    }
    lVar4 = (long)uVar5;
  } while (0x1020 < *(ushort *)((int)&comp_pos_y + unaff_A4));
  lVar3 = 0x1e;
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    lVar3,
                    lVar4,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_00014722();
    sVar2 = (short)lVar3 + -1;
    lVar3 = CONCAT22(extraout_D0u, sVar2);
    lVar4 = extraout_D1_00;
  } while (sVar2 != 0);
  audio_play(SOUND_ID_FX_OFF);
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  extraout_D0_00,
                  extraout_D1_01,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  audio_play(SOUND_ID_CRYS_FLASH);
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_WHITE_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar5 = CONCAT44(extraout_D0_01, extraout_D1_02);
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar5 >> 0x20),
                    (long)uVar5,
                    0xf,
                    -1,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar5 = FUN_00014722();
    lVar4 = (long)uVar5;
    unaff_A4 = (entity_id_t)(short)WORD_ffff97fe;
  } while (palette_fade_done_0 == 0);
  lVar3 = CONCAT22((short)((ulonglong)uVar5 >> 0x30), 0x1e);
  do {
    uVar5 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            lVar3,
                            lVar4,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    lVar4 = (long)uVar5;
    sVar2 = (short)lVar3 + -1;
    lVar3 = CONCAT22((short)((ulonglong)uVar5 >> 0x30), sVar2);
  } while (sVar2 != 0);
  self = (entity_id_t)(short)WORD_ffff97fe;
  (&comp_has_func_maybe)[self] = 0;
  FUN_00001630();
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_WHITE_EASE_OUT,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar5 = CONCAT44(extraout_D0_02, extraout_D1_03);
  do {
    uVar5 = exception_unk_0(unaff_A3,
                            self,
                            unaff_A6,
                            (long)((ulonglong)uVar5 >> 0x20),
                            (long)uVar5,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (palette_fade_done_0 == 0);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000927c(void)

{
  short sVar1;
  long lVar2;
  long in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar3;

  lVar2 = 0x3c;
  do {
    uVar3 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            lVar2,
                            in_D1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    in_D1 = (long)uVar3;
    sVar1 = (short)lVar2 + -1;
    lVar2 = CONCAT22((short)((ulonglong)uVar3 >> 0x30), sVar1);
  } while (sVar1 != 0);
  UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
  audio_play(SOUND_ID_SONG_OFF);
  audio_play(SOUND_ID_TOW_APPEAR);
  WORD_ffff97fe = 0x80;
  _UNION_sound_id_word_union_t_ffff9800 = 0x80000;
  FUN_0001689e();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000092b6(void)

{
  int iVar1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  bool bVar2;
  undefined8 uVar3;

  do {
    ecs_called_after_run_entity_func_all();
    uVar3 = FUN_00016904();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar3 >> 0x20),
                    (long)uVar3,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    iVar1 = (uint)WORD_ffff97fe * 0x100 + _UNION_sound_id_word_union_t_ffff9800;
    _UNION_sound_id_word_union_t_ffff9800 = iVar1;
    iVar1 = _UNION_sound_id_word_union_t_ffff9800;
    UNION_sound_id_word_union_t_ffff9800.as_word = (word)((uint)iVar1 >> 0x10);
    _DAT_ffffd17c = UNION_sound_id_word_union_t_ffff9800;
    bVar2 = UNION_sound_id_word_union_t_ffff9800.as_word != 0x44;
  } while (bVar2);
  _UNION_sound_id_word_union_t_ffff9800 = iVar1;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000092e2(void)

{
  int iVar1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  bool bVar2;
  undefined8 uVar3;

  while (true) {
    WORD_ffff97fe = WORD_ffff97fe + 0x10;
    if (0x44f < WORD_ffff97fe) {
      WORD_ffff97fe = 0x450;
    }
    iVar1 = (uint)WORD_ffff97fe * 0x100 + _UNION_sound_id_word_union_t_ffff9800;
    UNION_sound_id_word_union_t_ffff9800.as_word = (word)((uint)iVar1 >> 0x10);
    _DAT_ffffd17c = UNION_sound_id_word_union_t_ffff9800;
    bVar2 = 0x45f < UNION_sound_id_word_union_t_ffff9800.as_word;
    _UNION_sound_id_word_union_t_ffff9800 = iVar1;
    if (bVar2)
      break;
    ecs_called_after_run_entity_func_all();
    uVar3 = FUN_00016904();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar3 >> 0x20),
                    (long)uVar3,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  while (true) {
    WORD_ffff97fe = WORD_ffff97fe - 0x10;
    if (WORD_ffff97fe < 0x80) {
      WORD_ffff97fe = 0x80;
    }
    iVar1 = (uint)WORD_ffff97fe * 0x100 + _UNION_sound_id_word_union_t_ffff9800;
    UNION_sound_id_word_union_t_ffff9800.as_word = (word)((uint)iVar1 >> 0x10);
    _DAT_ffffd17c = UNION_sound_id_word_union_t_ffff9800;
    _UNION_sound_id_word_union_t_ffff9800 = iVar1;
    if (0x55f < UNION_sound_id_word_union_t_ffff9800.as_word)
      break;
    ecs_called_after_run_entity_func_all();
    uVar3 = FUN_00016904();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar3 >> 0x20),
                    (long)uVar3,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  _DAT_ffffd17c = (sound_id_word_union_t)0x560;
  ecs_called_after_run_entity_func_all();
  uVar3 = FUN_00016904();
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar3 >> 0x20),
                  (long)uVar3,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  FUN_0001689e();
  audio_play(SOUND_ID_TOW_STOP);
  audio_play(SOUND_ID_JUNGLE_5);
  return;
}

void FUN_00009392(void)

{
  short sVar1;
  long lVar2;
  long extraout_D1;
  long lVar3;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar4;

  script_state_set_true((script_state_bit_t)0x3ec);
  lVar2 = 0x3c;
  lVar3 = extraout_D1;
  do {
    uVar4 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            lVar2,
                            lVar3,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    lVar3 = (long)uVar4;
    sVar1 = (short)lVar2 + -1;
    lVar2 = CONCAT22((short)((ulonglong)uVar4 >> 0x30), sVar1);
  } while (sVar1 != 0);
  return;
}

void FUN_00009412(void)

{
  FUN_00009d60();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined8 FUN_00009424(void)

{
  long extraout_D0;
  ushort in_D1w;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  func *in_A1;
  script_ctx_t *unaff_A3;
  entity_id_t e;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  FUN_0000147a(in_A1, 0, in_D1w);
  e = (entity_id_t)(short)unaff_D2;
  entity_reset(e);
  *(undefined2 *)((int)&comp_unk_3 + e) = 0x14;
  (&comp_anim_base_offset)[e] = 0x14;
  (&comp_anim_b)[e] = 0xe;
  *(undefined2 *)((int)&comp_pos_x + e) = 0x1200;
  *(undefined2 *)((int)&comp_pos_y + e) = 0x10a7;
  *(undefined2 *)(&DAT_ffffbd78 + e) = 0x10a7;
  *(undefined1 *)(e - 0x4689) = 0x10;
  *(short *)(&DAT_ffffbd78 + e) = *(short *)(&DAT_ffffbd78 + e) + -0x40;
  ecs_anim_unk_2(e, unaff_A5, 0);
  *(undefined2 *)((int)&comp_vel[0].y + e) = 0xff00;
  _DAT_ffffda72 = (short)unaff_D2;
  uVar1 = exception_unk_0(unaff_A3,
                          e,
                          unaff_A6,
                          extraout_D0,
                          extraout_D1,
                          unaff_D2,
                          unaff_D3,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar1;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00009478(void)

{
  char cVar1;
  short sVar2;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t self;
  int iVar3;
  void *unaff_A6;
  undefined8 uVar4;

  while (true) {
    self = (entity_id_t)_DAT_ffffda72;
    ecs_update_pos_y(self);
    cVar1 = *(char *)(self - 0x4689) + -1;
    *(char *)(self - 0x4689) = cVar1;
    if (cVar1 == '\0') {
      *(undefined1 *)(self - 0x4689) = 0x14;
      FUN_0000185e();
    }
    if (*(ushort *)((int)&comp_pos_y + self) <=
        *(ushort *)(&DAT_ffffbd78 + self))
      break;
    uVar4 = FUN_00014722();
    exception_unk_0(unaff_A3,
                    self,
                    unaff_A6,
                    (long)((ulonglong)uVar4 >> 0x20),
                    (long)uVar4,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  *(ushort *)((int)&comp_pos_y + self) = *(ushort *)(&DAT_ffffbd78 + self);
  *(undefined2 *)((int)&comp_vel[0].y + self) = 0;
  sVar2 = 0x1e;
  do {
    uVar4 = FUN_00014722();
    exception_unk_0(unaff_A3,
                    self,
                    unaff_A6,
                    (long)((ulonglong)uVar4 >> 0x20),
                    (long)uVar4,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    sVar2 = sVar2 + -1;
  } while (sVar2 != 0);
  iVar3 = (int)_DAT_ffffda72;
  *(undefined2 *)((int)&comp_vel[0].y + iVar3) = 0;
  *(undefined2 *)(&DAT_ffffbd78 + iVar3) = 0x10a7;
  *(short *)(&DAT_ffffbd78 + iVar3) = *(short *)(&DAT_ffffbd78 + iVar3) + -0x20;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined8 FUN_000094da(void)

{
  short *psVar1;
  short sVar2;
  undefined4 extraout_D0;
  long lVar3;
  undefined4 extraout_D0_00;
  long extraout_D0_01;
  undefined4 extraout_D1;
  long extraout_D1_00;
  long lVar4;
  undefined4 extraout_D1_01;
  long extraout_D1_02;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t eVar5;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar6;

  while (true) {
    eVar5 = (entity_id_t)_DAT_ffffda72;
    psVar1 = (short *)((int)&comp_vel[0].y + eVar5);
    *psVar1 = *psVar1 + 0x20;
    ecs_update_pos_y(eVar5);
    if (*(ushort *)(&DAT_ffffbd78 + eVar5) <=
        *(ushort *)((int)&comp_pos_y + eVar5))
      break;
    uVar6 = FUN_00014722();
    exception_unk_0(unaff_A3,
                    eVar5,
                    unaff_A6,
                    (long)((ulonglong)uVar6 >> 0x20),
                    (long)uVar6,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  *(ushort *)((int)&comp_pos_y + eVar5) = *(ushort *)(&DAT_ffffbd78 + eVar5);
  *(undefined2 *)((int)&comp_vel[0].y + eVar5) = 0;
  ecs_anim_unk_2(eVar5, unaff_A5, 2);
  audio_play(SOUND_ID_EGG_FALL);
  uVar6 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar6 = exception_unk_0(unaff_A3,
                            eVar5,
                            unaff_A6,
                            (long)((ulonglong)uVar6 >> 0x20),
                            (long)uVar6,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    eVar5 = (entity_id_t)_DAT_ffffda72;
  } while (*(short *)((int)&comp_anim_tick + eVar5) != 0);
  ecs_anim_unk_2(eVar5, unaff_A5, 0);
  lVar3 = 0x78;
  lVar4 = extraout_D1_00;
  do {
    uVar6 = exception_unk_0(unaff_A3,
                            eVar5,
                            unaff_A6,
                            lVar3,
                            lVar4,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    lVar4 = (long)uVar6;
    sVar2 = (short)lVar3 + -1;
    lVar3 = CONCAT22((short)((ulonglong)uVar6 >> 0x30), sVar2);
  } while (sVar2 != 0);
  eVar5 = (entity_id_t)_DAT_ffffda72;
  ecs_anim_unk_2(eVar5, unaff_A5, 8);
  uVar6 = CONCAT44(extraout_D0_00, extraout_D1_01);
  do {
    uVar6 = exception_unk_0(unaff_A3,
                            eVar5,
                            unaff_A6,
                            (long)((ulonglong)uVar6 >> 0x20),
                            (long)uVar6,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    eVar5 = (entity_id_t)_DAT_ffffda72;
  } while (*(short *)((int)&comp_anim_tick + eVar5) != 0);
  ecs_anim_unk_2(eVar5, unaff_A5, 0);
  *(undefined2 *)(&DAT_ffffbd76 + eVar5) =
      *(undefined2 *)((int)&comp_pos_x + eVar5);
  *(undefined2 *)(&DAT_ffffbd78 + eVar5) =
      *(undefined2 *)((int)&comp_pos_y + eVar5);
  *(short *)(&DAT_ffffbd76 + eVar5) = *(short *)(&DAT_ffffbd76 + eVar5) + 0x30;
  *(short *)(&DAT_ffffbd78 + eVar5) = *(short *)(&DAT_ffffbd78 + eVar5) + 0x20;
  *(undefined2 *)((int)&comp_vel[0].x + eVar5) = 0x100;
  *(undefined2 *)((int)&comp_vel[0].y + eVar5) = 0xfe00;
  uVar6 = exception_unk_0(unaff_A3,
                          eVar5,
                          unaff_A6,
                          extraout_D0_01,
                          extraout_D1_02,
                          unaff_D2,
                          unaff_D3,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar6;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined8 FUN_0000957e(void)

{
  ushort uVar1;
  short *psVar2;
  undefined2 extraout_D0u;
  undefined4 extraout_D0;
  long extraout_D0_00;
  long extraout_D1;
  undefined4 extraout_D1_00;
  long extraout_D1_01;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t self;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar3;

  while (true) {
    self = (entity_id_t)_DAT_ffffda72;
    player_update_pos(self);
    psVar2 = (short *)((int)&comp_vel[0].y + self);
    *psVar2 = *psVar2 + 0x1c;
    uVar1 = *(ushort *)(&DAT_ffffbd76 + self);
    if (uVar1 <= *(ushort *)((int)&comp_pos_x + self))
      break;
    exception_unk_0(unaff_A3,
                    self,
                    unaff_A6,
                    CONCAT22(extraout_D0u, uVar1),
                    extraout_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  *(ushort *)((int)&comp_pos_x + self) = uVar1;
  *(undefined2 *)((int)&comp_pos_y + self) =
      *(undefined2 *)(&DAT_ffffbd78 + self);
  ecs_anim_unk_2(self, unaff_A5, 2);
  audio_play(SOUND_ID_EGG_FALL);
  uVar3 = CONCAT44(extraout_D0, extraout_D1_00);
  do {
    uVar3 = exception_unk_0(unaff_A3,
                            self,
                            unaff_A6,
                            (long)((ulonglong)uVar3 >> 0x20),
                            (long)uVar3,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    self = (entity_id_t)_DAT_ffffda72;
  } while (*(short *)((int)&comp_anim_tick + self) != 0);
  ecs_anim_unk_2(self, unaff_A5, 0);
  *(undefined2 *)(&DAT_ffffbd76 + self) =
      *(undefined2 *)((int)&comp_pos_x + self);
  *(undefined2 *)(&DAT_ffffbd78 + self) =
      *(undefined2 *)((int)&comp_pos_y + self);
  *(short *)(&DAT_ffffbd76 + self) = *(short *)(&DAT_ffffbd76 + self) + 0x30;
  *(short *)(&DAT_ffffbd78 + self) = *(short *)(&DAT_ffffbd78 + self) + 0x30;
  *(undefined2 *)((int)&comp_vel[0].x + self) = 0x100;
  *(undefined2 *)((int)&comp_vel[0].y + self) = 0xfe00;
  uVar3 = exception_unk_0(unaff_A3,
                          self,
                          unaff_A6,
                          extraout_D0_00,
                          extraout_D1_01,
                          unaff_D2,
                          unaff_D3,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar3;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000095f4(void)

{
  ushort uVar1;
  short *psVar2;
  undefined2 extraout_D0u;
  undefined4 extraout_D0;
  long extraout_D1;
  undefined4 extraout_D1_00;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t self;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar3;

  while (true) {
    self = (entity_id_t)_DAT_ffffda72;
    player_update_pos(self);
    psVar2 = (short *)((int)&comp_vel[0].y + self);
    *psVar2 = *psVar2 + 0x20;
    uVar1 = *(ushort *)(&DAT_ffffbd76 + self);
    if (uVar1 <= *(ushort *)((int)&comp_pos_x + self))
      break;
    exception_unk_0(unaff_A3,
                    self,
                    unaff_A6,
                    CONCAT22(extraout_D0u, uVar1),
                    extraout_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  *(ushort *)((int)&comp_pos_x + self) = uVar1;
  *(undefined2 *)((int)&comp_pos_y + self) =
      *(undefined2 *)(&DAT_ffffbd78 + self);
  ecs_anim_unk_2(self, unaff_A5, 2);
  audio_play(SOUND_ID_EGG_FALL);
  uVar3 = CONCAT44(extraout_D0, extraout_D1_00);
  do {
    uVar3 = exception_unk_0(unaff_A3,
                            self,
                            unaff_A6,
                            (long)((ulonglong)uVar3 >> 0x20),
                            (long)uVar3,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    self = (entity_id_t)_DAT_ffffda72;
  } while (*(short *)((int)&comp_anim_tick + self) != 0);
  ecs_anim_unk_2(self, unaff_A5, 4);
  *(undefined2 *)((int)&comp_vel[0].y + self) = 0;
  *(undefined2 *)((int)&comp_vel[0].x + self) = 0xfe00;
  *(undefined2 *)(&DAT_ffffbd76 + self) =
      *(undefined2 *)((int)&comp_pos_x + self);
  *(short *)(&DAT_ffffbd76 + self) = *(short *)(&DAT_ffffbd76 + self) + -0x60;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00009658(void)

{
  ushort uVar1;
  char cVar2;
  undefined2 extraout_D0u;
  undefined4 extraout_D0;
  long extraout_D1;
  undefined4 extraout_D1_00;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t eVar3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar4;

  while (true) {
    eVar3 = (entity_id_t)_DAT_ffffda72;
    player_update_pos_x(eVar3);
    uVar1 = *(ushort *)(&DAT_ffffbd76 + eVar3);
    if (*(ushort *)((int)&comp_pos_x + eVar3) <= uVar1)
      break;
    exception_unk_0(unaff_A3,
                    eVar3,
                    unaff_A6,
                    CONCAT22(extraout_D0u, uVar1),
                    extraout_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  *(ushort *)((int)&comp_pos_x + eVar3) = uVar1;
  *(undefined2 *)((int)&comp_vel[0].x + eVar3) = 0;
  ecs_anim_unk_2(eVar3, unaff_A5, 6);
  (&DAT_ffffb976)[eVar3] = 0x90;
  eVar3 = ENTITY_ID_ASHA;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x22);
  uVar4 = CONCAT44(extraout_D0, extraout_D1_00);
  do {
    uVar4 = exception_unk_0(unaff_A3,
                            eVar3,
                            unaff_A6,
                            (long)((ulonglong)uVar4 >> 0x20),
                            (long)uVar4,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    eVar3 = (entity_id_t)_DAT_ffffda72;
    cVar2 = (&DAT_ffffb976)[eVar3] + -1;
    (&DAT_ffffb976)[eVar3] = cVar2;
  } while (cVar2 != '\0');
  audio_play(SOUND_ID_EGG_CRACK);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000096aa(void)

{
  entity_state_1_a_t eVar1;
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  int iVar2;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar3;

  uVar3 = CONCAT44(in_D0, in_D1);
  do {
    uVar3 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar3 >> 0x20),
                            (long)uVar3,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    unaff_A4 = (entity_id_t)_DAT_ffffda72;
    eVar1 = (&comp_state_1_a)[unaff_A4];
    (&comp_state_1_a)[unaff_A4] = eVar1 & 0xdf;
  } while ((eVar1 & 0x20) == 0);
  audio_play(SOUND_ID_EGG_HATCH);
  entity_reset(ENTITY_ID_PEPELOGOO);
  script_ctx_bf_0e_arg = 0;
  related_to_entering_a_room();
  component_pos_x_pepelogoo.fixed.i =
      *(int16_t *)((int)&comp_pos_x + (int)_DAT_ffffda72);
  component_pos_y_pepelogoo.fixed.i =
      *(short *)((int)&comp_pos_y + (int)_DAT_ffffda72) + -6;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 4);
  component_state_a_pepelogoo = 2;
  iVar2 = (int)_DAT_ffffda72;
  (&comp_state_a)[iVar2] = (&comp_state_a)[iVar2] | 4;
  (&DAT_ffffab42)[iVar2] = 0;
  (&DAT_ffffab43)[iVar2] = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00009714(void)

{
  short sVar1;
  long lVar2;
  long in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar3;

  lVar2 = 0x10;
  do {
    uVar3 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            lVar2,
                            in_D1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    in_D1 = (long)uVar3;
    sVar1 = (short)lVar2 + -1;
    lVar2 = CONCAT22((short)((ulonglong)uVar3 >> 0x30), sVar1);
  } while (sVar1 != 0);
  (&comp_has_func_maybe)[_DAT_ffffda72] = 0;
  audio_play(SOUND_ID_PEPE_VOICE_3);
  return;
}

void FUN_00009734(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  void *unaff_A6;
  undefined8 uVar1;

  comp_vel[1].y.raw = -0x300;
  DAT_ffffb97b = '\x10';
  while (true) {
    uVar1 = FUN_00014722();
    exception_unk_0(unaff_A3,
                    ENTITY_ID_PEPELOGOO,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    player_update_pos(4);
    if ((ushort)component_pos_y_pepelogoo.fixed.i < 0x1050)
      break;
    DAT_ffffb97b = DAT_ffffb97b + -1;
    if (DAT_ffffb97b == '\0') {
      DAT_ffffb97b = '\n';
      FUN_0000185e();
    }
  }
  component_pos_y_pepelogoo.fixed.i = 0x1050;
  return;
}

void FUN_00009778(void)

{
  sound_id_word_union_t sVar1;

  sVar1.as_word = UNION_sound_id_word_union_t_ffff97e6.as_word;
  audio_play_sound_asha_dies();
  audio_play(SOUND_ID_BIRTH_OF_PEPELOGOO);
  FUN_0000345c();
  audio_play_sound_asha_dies();
  UNION_sound_id_word_union_t_ffff97e6 = sVar1;
  audio_play((sound_id_t)sVar1.as_word);
  return;
}

undefined4 FUN_0000979c(void)

{
  game_lock();
  FUN_000097bc();
  audio_pause();
  FUN_000097ce();
  game_unlock();
  audio_resume();
  FUN_0000982c();
  return 0xffffffff;
}

void FUN_000097bc(void)

{
  FUN_00009d60();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000097ce(void)

{
  short sVar1;
  undefined2 extraout_D0u;
  long lVar2;
  long extraout_D1;
  long lVar3;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  int iVar4;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar5;

  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x10);
  comp_state = COMP_STATE_STAND;
  audio_play(SOUND_ID_JUNGLE_5);
  for (iVar4 = 0x84;
       ((*(short *)(&comp_unk_1 + iVar4) != 10 ||
         (_DAT_ffffcf80 != *(short *)((int)&comp_pos_x + iVar4))) ||
        (_DAT_ffffcf82 != *(short *)((int)&comp_pos_y + iVar4)));
       iVar4 = iVar4 + 4) {
  }
  (&comp_has_func_maybe)[iVar4] = 0;
  script_state_set_true(*(script_state_bit_t *)(&DAT_ffffba76 + iVar4));
  lVar2 = CONCAT22(extraout_D0u, 0x5a);
  lVar3 = extraout_D1;
  do {
    uVar5 = exception_unk_0(unaff_A3,
                            ENTITY_ID_ASHA,
                            unaff_A6,
                            lVar2,
                            lVar3,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    lVar3 = (long)uVar5;
    sVar1 = (short)lVar2 + -1;
    lVar2 = CONCAT22((short)((ulonglong)uVar5 >> 0x30), sVar1);
  } while (sVar1 != 0);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000982c(void)

{
  short sVar1;

  if (DAT_ffffcbb4 == 1) {
    sVar1 = 0x10;
    DAT_ffffcd39 = 5;
  } else {
    sVar1 = 0x22;
    DAT_ffffcd39 = 0x11;
  }
  DAT_ffffcd38 = 0xd;
  _DAT_ffffcd2e = &DAT_0007c8f8 + (short)(sVar1 << 3);
  FUN_000136e8();
  return;
}

void FUN_0000986c(void)

{
  short sVar1;
  undefined2 extraout_D0u;
  long lVar2;
  long extraout_D1;
  long lVar3;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar4;

  // FIXME Where is this called?
  game_lock();
  audio_pause();
  lVar2 = CONCAT22(extraout_D0u, 0xb4);
  lVar3 = extraout_D1;
  do {
    uVar4 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            lVar2,
                            lVar3,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    lVar3 = (long)uVar4;
    sVar1 = (short)lVar2 + -1;
    lVar2 = CONCAT22((short)((ulonglong)uVar4 >> 0x30), sVar1);
  } while (sVar1 != 0);
  FUN_000320a0();
  DAT_ffffcc92 = 0;
  game_unlock();
  DAT_ffff9154 = 0;
  audio_stop_all();
  FUN_00009a74();
  return;
}

void ecs_anim_unk_3(entity_id_t self, anim_item_t *anim)

{
  undefined2 uVar1;
  short sVar2;

  FUN_000099f6();
  if ((ushort)(component_pos_y_pepelogoo.fixed.i + 8U) ==
      *(ushort *)((int)&comp_pos_y + self)) {
    comp_vel[1].y.raw = 0;
  } else if ((ushort)(component_pos_y_pepelogoo.fixed.i + 8U) <
             *(ushort *)((int)&comp_pos_y + self)) {
    comp_vel[1].y.raw = 0x300;
  } else {
    comp_vel[1].y.raw = -0x300;
  }
  if ((ushort)(component_pos_x_pepelogoo.fixed.i + 0x14U) ==
      *(ushort *)((int)&comp_pos_x + self)) {
    comp_vel[1].x.raw = 0;
  } else if ((ushort)(component_pos_x_pepelogoo.fixed.i + 0x14U) <
             *(ushort *)((int)&comp_pos_x + self)) {
    DAT_ffff9f1f = DAT_ffff9f1f & 0xf7;
    comp_vel[1].x.raw = 0x300;
  } else {
    comp_vel[1].x.raw = -0x300;
    DAT_ffff9f1f = DAT_ffff9f1f | 8;
  }
  player_update_pos(4);
  sVar2 = -1;
  uVar1 = component_pos_y_pepelogoo.fixed.i;
  if (comp_vel[1].y.raw != 0) {
    if (comp_vel[1].y.raw < 0) {
      uVar1 = *(short *)((int)&comp_pos_y + self) - 8;
      if ((ushort)uVar1 < (ushort)component_pos_y_pepelogoo.fixed.i)
        goto LAB_0000997e;
    } else {
      uVar1 = *(short *)((int)&comp_pos_y + self) - 8;
      if ((ushort)component_pos_y_pepelogoo.fixed.i < (ushort)uVar1) {
      LAB_0000997e:
        sVar2 = 0;
        uVar1 = component_pos_y_pepelogoo.fixed.i;
      }
    }
  }
  component_pos_y_pepelogoo.fixed.i = uVar1;
  uVar1 = component_pos_x_pepelogoo.fixed.i;
  if (comp_vel[1].x.raw != 0) {
    if (comp_vel[1].x.raw < 0) {
      uVar1 = *(short *)((int)&comp_pos_x + self) - 0x14;
      if ((ushort)component_pos_x_pepelogoo.fixed.i <= (ushort)uVar1)
        goto LAB_000099c6;
    } else {
      uVar1 = *(short *)((int)&comp_pos_x + self) - 0x14;
      if ((ushort)uVar1 <= (ushort)component_pos_x_pepelogoo.fixed.i)
        goto LAB_000099c6;
    }
    sVar2 = 0;
    uVar1 = component_pos_x_pepelogoo.fixed.i;
  }
LAB_000099c6:
  component_pos_x_pepelogoo.fixed.i = uVar1;
  if (sVar2 != 0) {
    DAT_ffff9f1f = DAT_ffff9f1f & 0xf7;
    DAT_ffffa63d = DAT_ffffa63d & 0xdf;
    ecs_anim_unk_2(
        ENTITY_ID_PEPELOGOO,
        anim,
        (byte) *
            (undefined2 *)((int)WORD_ARRAY_00009a10 +
                           (int)(short)((ushort)script_ctx_bf_0e_arg * 2)));
    *(code **)((int)&comp_some_function + self) = FUN_00009a14;
  }
  return;
}

void FUN_000099f6(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_has_func_maybe)[unaff_A4] =
      (&comp_has_func_maybe)[unaff_A4] & ~COMPONENT_STATE_B_ACTIVE;
  if ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_JUMPING_OR_UNSHIELDING) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
  }
  return;
}

void FUN_00009a14(void)

{
  byte bVar1;
  int iVar2;
  int unaff_A4;

  bVar1 = DAT_ffffa63d & 0x20;
  DAT_ffffa63d = DAT_ffffa63d & 0xdf;
  if (bVar1 != 0) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
    iVar2 = (int)(short)entity_id_w_t_ffffcf94;
    (&DAT_ffffb976)[iVar2] = 0;
    script_state_set_false(*(script_state_bit_t *)(&DAT_ffffba76 + iVar2));
    audio_play(SOUND_ID_EAT_A_NUT);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00009a3e(void)

{
  _related_to_comp_unk_4_ffffa32a_2 = 0xf80;
  related_to_comp_unk_4_ffffa32a_1 = 0xf80;
  return;
}

void game_lock(void)

{
  if ((game_locked == '\0') || (game_locked < '\0')) {
    game_lock_entities();
  }
  game_locked = game_locked + '\x01';
  return;
}

void game_unlock(void)

{
  game_locked = game_locked + -1;
  if ((game_locked == '\0') || (game_locked < '\0')) {
    game_locked = '\0';
    game_unlock_entities();
  }
  return;
}

undefined8 FUN_00009a74(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = FUN_0001a388();
  uVar1 = exception_unk_0(unaff_A3,
                          unaff_A4,
                          unaff_A6,
                          (long)((ulonglong)uVar1 >> 0x20),
                          (long)uVar1,
                          unaff_D2,
                          unaff_D3,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar1;
}

void FUN_00009a80(void)

{
  game_unlock();
  FUN_00012f8a();
  game_lock();
  FUN_00009a3e();
  FUN_000165ec();
  FUN_0002ad92();
  FUN_00006c34();
  FUN_0000c472();
  return;
}

void FUN_00009aa4(void)

{
  FUN_00006c34();
  FUN_00012f8a();
  FUN_0002ad92();
  FUN_0000c4fc();
  comp_state_a = comp_state_a & 0x7f;
  DAT_ffff91c6 = 0;
  return;
}

void FUN_00009ac6(void)

{
  FUN_0000c566();
  FUN_00006c4e();
  FUN_00012f8a();
  FUN_0002ad92();
  comp_state_a = comp_state_a & 0x7f;
  DAT_ffff91c6 = 0;
  return;
}

void FUN_00009aea(void)

{
  FUN_00012f8a();
  FUN_0002ad92();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00009af8(void)

{
  short in_D0w;
  undefined1 in_D1b;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  DAT_ffffcd39 = (undefined1)unaff_D2;
  _DAT_ffffcd2e = &DAT_0007c8f8 + (short)(in_D0w << 3);
  set_to_13a62_when_facing_a_door = FUN_000136e8;
  DAT_ffffcd38 = in_D1b;
  uVar1 = FUN_000136e8();
  comp_state_a = comp_state_a | 0x80;
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar1 >> 0x20),
                  (long)uVar1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  FUN_0000b338();
  DAT_ffffd180 = 8;
  DAT_ffffd181 = 8;
  DAT_ffffd17e = 1;
  DAT_ffffd17f = 1;
  FUN_0000ae18();
  FUN_0000e738();
  FUN_0000c70c();
  FUN_00012f46();
  FUN_00006c34();
  FUN_0000c4fc();
  comp_state_a = comp_state_a & 0x7f;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined8 FUN_00009b6e(void)

{
  long extraout_D0;
  long extraout_D1;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  _DAT_ffff9812 = 0xb0b0b0b;
  comp_has_func_maybe = 0;
  vdp_palettes_something();
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_1,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar1 = exception_unk_0(unaff_A3,
                          unaff_A4,
                          unaff_A6,
                          extraout_D0,
                          extraout_D1,
                          0xf,
                          -1,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar1;
}

void FUN_00009b96(void)

{
  game_unlock();
  FUN_00012f8a();
  game_lock();
  FUN_00009a3e();
  FUN_000165ec();
  FUN_0002ad92();
  FUN_00006c34();
  FUN_0000c5c2();
  FUN_0000d210();
  return;
}

void FUN_00009bc6(void)

{
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  comp_pos_y.fixed.i = comp_pos_y.fixed.i - comp_collision_sensor[0].y;
  game_unlock();
  FUN_00012f8a();
  game_lock();
  FUN_00009a3e();
  FUN_000165ec();
  FUN_0002ad92();
  FUN_00006c34();
  FUN_0000c5c2();
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_OUT,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar1 = FUN_0000c60a();
  if (DAT_ffffcbf4 != '\0') {
    uVar1 = FUN_0000ac92();
  }
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    if (DAT_ffffcd3a == '\x05') {
      return;
    }
  } while (palette_fade_done_0 == 0);
  return;
}

void FUN_00009bfc(void)

{
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  comp_pos_y.fixed.i = comp_pos_y.fixed.i - comp_collision_sensor[0].y;
  game_unlock();
  FUN_00012f8a();
  game_lock();
  FUN_00009a3e();
  FUN_000165ec();
  FUN_0002ad92();
  FUN_00006c34();
  FUN_0000c5c2();
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_OUT,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar1 = FUN_0000c60a();
  if (DAT_ffffcbf4 != '\0') {
    uVar1 = FUN_0000ac92();
  }
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    if (DAT_ffffcd3a == '\x05') {
      return;
    }
  } while (palette_fade_done_0 == 0);
  return;
}

void FUN_00009c32(void)

{
  return;
}

void FUN_00009c34(void)

{
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  comp_pos_y.fixed.i = comp_pos_y.fixed.i - comp_collision_sensor[0].y;
  game_unlock();
  FUN_00012f8a();
  game_lock();
  FUN_00009a3e();
  FUN_000165ec();
  FUN_0002ad92();
  FUN_00006c34();
  FUN_0000c5c2();
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_OUT,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar1 = FUN_0000c60a();
  if (DAT_ffffcbf4 != '\0') {
    uVar1 = FUN_0000ac92();
  }
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    if (DAT_ffffcd3a == '\x05') {
      return;
    }
  } while (palette_fade_done_0 == 0);
  return;
}

void FUN_00009c6a(void)

{
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  comp_pos_y.fixed.i = comp_pos_y.fixed.i - comp_collision_sensor[0].y;
  game_unlock();
  FUN_00012f8a();
  game_lock();
  FUN_00009a3e();
  FUN_000165ec();
  FUN_0002ad92();
  FUN_00006c34();
  FUN_0000c5c2();
  component_collision_flags = component_collision_flags | 4;
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_OUT,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar1 = FUN_0000c60a();
  if (DAT_ffffcbf4 != '\0') {
    uVar1 = FUN_0000ac92();
  }
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    if (DAT_ffffcd3a == '\x05') {
      return;
    }
  } while (palette_fade_done_0 == 0);
  return;
}

void FUN_00009ca6(void)

{
  game_unlock();
  FUN_00012f8a();
  game_lock();
  FUN_00009a3e();
  FUN_000165ec();
  FUN_0002ad92();
  FUN_00006c34();
  FUN_0000c472();
  return;
}

void FUN_00009cd0(void)

{
  uint uVar1;

  uVar1 = 0x84;
  do {
    if (((char)(&comp_has_func_maybe)[uVar1] < '\0') &&
        (*(short *)(&comp_unk_1 + uVar1) == 1)) {
      (**(code **)((int)&comp_some_function + uVar1))();
    }
    uVar1 = uVar1 + 4;
  } while (uVar1 < 0xcc);
  return;
}

void FUN_00009cf2(void)

{
  uint uVar1;

  uVar1 = 0x84;
  do {
    if (((char)(&comp_has_func_maybe)[uVar1] < '\0') &&
        (*(short *)(&comp_unk_1 + uVar1) == 2)) {
      (**(code **)((int)&comp_some_function + uVar1))();
    }
    uVar1 = uVar1 + 4;
  } while (uVar1 < 0xcc);
  return;
}

void FUN_00009d14(void)

{
  int unaff_A4;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

void FUN_00009d20(entity_id_t self)

{
  short *psVar1;
  bool bVar2;

  player_update_pos(self);
  psVar1 = (short *)((int)&comp_vel[0].y + self);
  *psVar1 = *psVar1 + 0x40;
  psVar1 = (short *)((int)&comp_vel[0].x + self);
  if (*psVar1 != 0) {
    if (*psVar1 < 0) {
      psVar1 = (short *)((int)&comp_vel[0].x + self);
      *psVar1 = *psVar1 + 0x10;
      if (-1 < *(short *)((int)&comp_vel[0].x + self)) {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
      }
    } else {
      psVar1 = (short *)((int)&comp_vel[0].x + self);
      *psVar1 = *psVar1 + -0x10;
      if (*(short *)((int)&comp_vel[0].x + self) < 0) {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
      }
    }
  }
  bVar2 = FUN_00000eae(self);
  if (bVar2) {
    (&comp_has_func_maybe)[self] = 0;
  }
  return;
}

void FUN_00009d60(void)

{
  ushort in_D0w;
  fixed_w_t in_D1w;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  comp_has_func_maybe = 0;
  comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
  if (in_D0w != comp_pos_x.fixed.i) {
    if (in_D0w < (ushort)comp_pos_x.fixed.i) {
      comp_state_a = comp_state_a | ENTITY_STATE_A_08;
      in_D1w.raw = -in_D1w.raw;
    }
    comp_anim_b = 0;
    comp_vel[0].x = in_D1w;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 2);
    do {
      while (true) {
        uVar1 = ecs_called_after_run_entity_func_all();
        exception_unk_0(unaff_A3,
                        ENTITY_ID_ASHA,
                        unaff_A6,
                        (long)((ulonglong)uVar1 >> 0x20),
                        (long)uVar1,
                        0,
                        unaff_D3,
                        unaff_D4,
                        unaff_D5,
                        unaff_D6,
                        unaff_D7);
        entity_update_pos(ENTITY_ID_ASHA);
        if (-1 < comp_vel[0].x.raw)
          break;
        if ((ushort)comp_pos_x.fixed.i <= in_D0w)
          goto LAB_00009dc8;
      }
    } while (comp_pos_x.fixed.i < (short)in_D0w);
  }
LAB_00009dc8:
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  ecs_called_after_run_entity_func_all();
  return;
}

void FUN_00009de4(void)

{
  byte *pbVar1;
  bool bVar2;

  pbVar1 = &DAT_0007d254;
  while (true) {
    if ((char)*pbVar1 < '\0') {
      return;
    }
    if ((*pbVar1 == DAT_ffffcbb2) && (pbVar1[1] == DAT_ffffcbb4))
      break;
    pbVar1 = pbVar1 + 6;
  }
  bVar2 = script_state_get(*(script_state_bit_t *)(pbVar1 + 2));
  if (!bVar2) {
    return;
  }
  audio_play_sound_asha_dies();
  script_state_set_true(*(script_state_bit_t *)(pbVar1 + 2));
  FUN_0002d37e();
  FUN_0001a638();
  return;
}

undefined8 main_unk_15(void)

{
  undefined2 extraout_D0u;
  long lVar1;
  short sVar2;
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  uint uVar3;
  undefined4 extraout_D1_00;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  ulonglong uVar4;
  undefined8 uVar5;

  FUN_00001580();
  vdp_hblank_effect_asha_p = 0;
  vdp_gfx_ptr_5._0_2_ = 0;
  vdp_hblank_effect_pepelogoo_p = 0;
  vdp_gfx_ptr_6 = 0;
  vdp_related_to_display_asha = 0xf;
  text_unk_4();
  audio_play(SOUND_ID_ASCENSION_TO_HEAVEN);
  FUN_00009f54();
  FUN_0000a06e();
  uVar4 = FUN_0000a03c();
  uVar3 = (uint)uVar4;
  DAT_ffff9156 = 0xff;
  if (DAT_ffff96bf == '\0') {
    lVar1 = CONCAT22((short)(uVar4 >> 0x30), 0xb4);
    do {
      sVar2 = (short)lVar1;
      exception_unk_0(unaff_A3,
                      unaff_A4,
                      unaff_A6,
                      lVar1,
                      uVar3,
                      unaff_D2,
                      unaff_D3,
                      unaff_D4,
                      unaff_D5,
                      unaff_D6,
                      unaff_D7);
      DAT_ffff980c = 0;
      FUN_0000a0c8();
      lVar1 = CONCAT22(extraout_D0u, sVar2);
      if (sVar2 == 0)
        break;
      uVar3 = CONCAT31((int3)((uint)extraout_D1 >> 8), gamepad_pressed) &
              0xfffffff0;
    } while ((gamepad_pressed & GAMEPAD_BUTTON_ANY) == GAMEPAD_NONE);
  } else {
    do {
      exception_unk_0(unaff_A3,
                      unaff_A4,
                      unaff_A6,
                      (long)(uVar4 >> 0x20),
                      (long)uVar4,
                      unaff_D2,
                      unaff_D3,
                      unaff_D4,
                      unaff_D5,
                      unaff_D6,
                      unaff_D7);
      uVar5 = FUN_0000a0c8();
      uVar4 =
          CONCAT44(CONCAT31((int3)((ulonglong)uVar5 >> 0x28), gamepad_pressed),
                   (int)uVar5) &
          0xfffffff0ffffffff;
    } while ((gamepad_pressed & GAMEPAD_BUTTON_ANY) == GAMEPAD_NONE);
    FUN_0000a16c();
    uVar4 = FUN_00009fc6();
    do {
      exception_unk_0(unaff_A3,
                      unaff_A4,
                      unaff_A6,
                      (long)(uVar4 >> 0x20),
                      (long)uVar4,
                      unaff_D2,
                      unaff_D3,
                      unaff_D4,
                      unaff_D5,
                      unaff_D6,
                      unaff_D7);
      uVar4 = FUN_0000a0c8();
    } while (palette_fade_done_0 == 0);
    do {
      exception_unk_0(unaff_A3,
                      unaff_A4,
                      unaff_A6,
                      (long)(uVar4 >> 0x20),
                      (long)uVar4,
                      unaff_D2,
                      unaff_D3,
                      unaff_D4,
                      unaff_D5,
                      unaff_D6,
                      unaff_D7);
      FUN_0000a0c8();
      uVar5 = FUN_0000a126();
      uVar4 =
          CONCAT44(CONCAT31((int3)((ulonglong)uVar5 >> 0x28), gamepad_pressed),
                   (int)uVar5) &
          0xfffffff0ffffffff;
    } while ((gamepad_pressed & GAMEPAD_BUTTON_ANY) == GAMEPAD_NONE);
    palette_set_effect(PALETTE_ID_FLAG_0, false, &palette_effect_t_0000a532);
    palette_set_effect(PALETTE_ID_FLAG_1, false, &palette_effect_t_0000a5b6);
    audio_play(SOUND_ID_RES_BTTN);
  }
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_IN,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar5 = CONCAT44(extraout_D0, extraout_D1_00);
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar5 >> 0x20),
                    (long)uVar5,
                    0xf,
                    -1,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar5 = FUN_0000a0c8();
  } while (palette_fade_done_0 == 0);
  DAT_ffff9154 = 0xffff;
  uVar5 = exception_unk_0(unaff_A3,
                          unaff_A4,
                          unaff_A6,
                          (long)((ulonglong)uVar5 >> 0x20),
                          (long)uVar5,
                          0xf,
                          -1,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar5;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_00009f24(void)

{
  undefined4 uVar1;

  uVar1 = 0xffffffff;
  _DAT_ffff980e = _DAT_ffff980e + -1;
  if (_DAT_ffff980e == 0) {
    uVar1 = 0;
  }
  return uVar1;
}

void text_unk_4(void)

{
  word compressed_data_index;
  void *extraout_A1;
  void *extraout_A1_00;
  word *pwVar1;
  undefined *dst;

  text_unk_3();
  text_unk_2(extraout_A1);
  text_unk_1(BYTE_ARRAY_00009f48, extraout_A1_00);
  pwVar1 = compressed_data_indices;
  dst = (undefined *)0x0;
  compressed_data_indices_size = 0x40;
  do {
    compressed_data_index = *pwVar1;
    if ((-1 < (short)compressed_data_index) &&
        (compressed_data_index != pwVar1[0x40])) {
      pwVar1[0x40] = compressed_data_index;
      uncompress_data(compressed_data_index, (uint8_t *)&vdp_gfx_ptr_1);
      vdp_copy_1kb_from_gfx_ptr_1_to_vram(dst);
    }
    pwVar1 = pwVar1 + 1;
    dst = dst + 0x400;
    compressed_data_indices_size = compressed_data_indices_size - 1;
  } while (compressed_data_indices_size != 0);
  return;
}

void FUN_00009f54(void)

{
  sized_string_t *string;
  sized_string_t *string_00;

  DAT_ffff91ce._0_1_ = 0xff;
  game_over_maybe(&fed_to_vdp_data_2);
  something(&fed_to_vdp_data_1);
  DAT_ffff91ce._0_1_ = 0;
  FUN_0001a638();
  vdp_set_vram_write_addr((void *)0xeb98);
  vdp_load_sized_string(string);
  vdp_set_vram_write_addr((void *)0xec98);
  vdp_load_sized_string(string_00);
  return;
}

void FUN_00009fc6(void)

{
  sized_string_t *string;
  sized_string_t *string_00;

  DAT_ffff980c = 0;
  if (DAT_ffff96bf != '\0') {
    vdp_set_vram_write_addr((void *)0xeb98);
    vdp_load_sized_string(string);
    DAT_ffff980c = 0xff;
    FUN_0000a002();
    vdp_set_vram_write_addr((void *)0xec98);
    vdp_load_sized_string(string_00);
  }
  return;
}

void FUN_0000a002(void)

{
  anim_item_t *unaff_A5;

  entity_reset(ENTITY_ID_08);
  DAT_ffff9f24 = 4;
  DAT_ffff9f23 = 0x88;
  DAT_ffffa332 = 4;
  DAT_ffffa12a = 0x80;
  DAT_ffffa22e = 0xbb;
  DAT_ffffa63e = 0x18;
  DAT_ffffa63f = 0x14;
  ecs_anim_unk_2(ENTITY_ID_08, unaff_A5, 0);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000a03c(void)

{
  long extraout_D0;
  long extraout_D1;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  _DAT_ffff9812 = 0x2510002;
  vdp_palettes_something();
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_OUT,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  extraout_D0,
                  extraout_D1,
                  0xf,
                  -1,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  uVar1 = FUN_0002f8d4();
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (palette_fade_done_0 == 0);
  return;
}

void FUN_0000a06e(void)

{
  anim_item_t *unaff_A5;

  if ((-1 < (char)script_ctx_bf_0e_arg) && (script_ctx_bf_0e_arg < 3)) {
    entity_reset(ENTITY_ID_PEPELOGOO);
    component_unknown_3_pepelogoo = 10;
    DAT_ffffa32e = 4;
    component_pos_x_pepelogoo.fixed.i = 0xc0;
    component_pos_y_pepelogoo.fixed.i = 0x6c;
    DAT_ffffa63a = 0x18;
    DAT_ffff9f1f = 0x88;
    DAT_ffffa63b = script_ctx_bf_0e_arg * '\x02' + '\n';
    ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 0);
    uRamffffb97a = 0;
    DAT_ffffb97b = 0;
  }
  return;
}

void FUN_0000a0c8(void)

{
  ulong unaff_A4;

  if ((-1 < (char)script_ctx_bf_0e_arg) && (script_ctx_bf_0e_arg < 3)) {
    player_update_pos(unaff_A4);
    if (bRamffffb97a == 0) {
      comp_vel[1].y.raw = comp_vel[1].y.raw + -0x20;
      if (comp_vel[1].y.raw < -0x100) {
        comp_vel[1].y.raw = -0x100;
      }
    } else {
      comp_vel[1].y.raw = comp_vel[1].y.raw + 0x20;
      if (0x100 < comp_vel[1].y.raw) {
        comp_vel[1].y.raw = 0x100;
      }
    }
    if (DAT_ffffb97b == '\0') {
      DAT_ffffb97b = ' ';
      bRamffffb97a = bRamffffb97a ^ 1;
    }
    DAT_ffffb97b = DAT_ffffb97b + -1;
  }
  return;
}

void FUN_0000a126(void)

{
  if (DAT_ffff980c == '\0') {
    if ((gamepad_pressed & GAMEPAD_UP) != GAMEPAD_NONE) {
      DAT_ffffa22e = 0xbb;
      DAT_ffff980c = -1;
      audio_play(SOUND_ID_RES_KEY);
    }
  } else if ((gamepad_pressed & GAMEPAD_DOWN) != GAMEPAD_NONE) {
    DAT_ffffa22e = 0xcb;
    DAT_ffff980c = '\0';
    audio_play(SOUND_ID_RES_KEY);
  }
  return;
}

void FUN_0000a16c(void)

{
  palette_set_effect(PALETTE_ID_FLAG_0, true, &palette_effect_t_0000a532);
  palette_set_effect(PALETTE_ID_FLAG_1, true, &palette_effect_t_0000a5b6);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address This sets all colors to full black.

void vdp_clear_palettes_and_more(void)

{
  short i;
  vdp_color_t *palette;

  DAT_ffff9810 = 0;
  _related_to_palettes = 0;
  i = 0x1f;
  palette = vdp_palettes[0];
  do {
    palette[0] = 0;
    palette[1] = 0;
    i = i + -1;
    palette = palette + 2;
  } while (i != -1);
  palette_fade[0].ongoing = false;
  palette_fade[1].ongoing = false;
  palette_fade[2].ongoing = false;
  palette_fade[3].ongoing = false;
  palette_effect[0].state = PALETTE_EFFECT_STATE_DISABLED;
  palette_effect[1].state = PALETTE_EFFECT_STATE_DISABLED;
  palette_effect[2].state = PALETTE_EFFECT_STATE_DISABLED;
  palette_effect[3].state = PALETTE_EFFECT_STATE_DISABLED;
  return;
}

// The extraout variables likely are wrong, unneeded.

void palette_set_fade(palette_id_flag_t palettes,
                      palette_fade_type_long_t fade_type, char duration,
                      palette_color_iter_t color_iter)

{
  palette_fade_type_long_t extraout_D0;
  palette_fade_type_long_t extraout_D0_00;
  palette_fade_type_long_t extraout_D0_01;
  char extraout_D1b;
  char extraout_D1b_00;
  char extraout_D1b_01;

  if ((palettes & PALETTE_ID_FLAG_0) != PALETTE_ID_FLAG_NONE) {
    palette_set_fade_inner(
        PALETTE_ID_OFFSET_0, fade_type, duration, color_iter);
    fade_type = extraout_D0;
    duration = extraout_D1b;
  }
  if ((palettes & PALETTE_ID_FLAG_1) != PALETTE_ID_FLAG_NONE) {
    palette_set_fade_inner(
        PALETTE_ID_OFFSET_1, fade_type, duration, color_iter);
    fade_type = extraout_D0_00;
    duration = extraout_D1b_00;
  }
  if ((palettes & PALETTE_ID_FLAG_2) != PALETTE_ID_FLAG_NONE) {
    palette_set_fade_inner(
        PALETTE_ID_OFFSET_2, fade_type, duration, color_iter);
    fade_type = extraout_D0_01;
    duration = extraout_D1b_01;
  }
  if ((palettes & PALETTE_ID_FLAG_3) != PALETTE_ID_FLAG_NONE) {
    palette_set_fade_inner(
        PALETTE_ID_OFFSET_3, fade_type, duration, color_iter);
  }
  return;
}

void palette_set_fade_inner(palette_id_offset_t palette,
                            palette_fade_type_long_t fade_type, char duration,
                            palette_color_iter_t color_iter)

{
  palette_fade_type_t loc_fade_type;

  (&palette_fade_done_0)[palette] = 0;
  loc_fade_type = (palette_fade_type_t)fade_type;
  (&palette_fade[0].type)[palette] = loc_fade_type;
  if (loc_fade_type == PALETTE_FADE_NONE) {
    (&palette_fade[0].ongoing)[palette] = false;
  } else {
    (&palette_fade[0].frames_n)[palette] = duration;
    (&palette_fade[0].frames_i)[palette] = duration;
    if (loc_fade_type == PALETTE_FADE_1) {
      (&palette_fade[0].ongoing)[palette] = true;
      (&palette_fade[0].type)[palette] = 1;
    }
    // if (color_iter.index < 0) {
    //   // Apply to all colors
    // }
    if ((int)color_iter < 0) {
      (&palette_iter[0].start)[palette] = 0;
      (&palette_iter[0].length)[palette] = 0xf;
    } else {
      (&palette_iter[0].length)[palette] = (byte)color_iter.length;
      (&palette_iter[0].start)[palette] = (byte)color_iter.start;
    }
    if (loc_fade_type == PALETTE_FADE_BLACK_EASE_IN) {
      (&palette_fade[0].ongoing)[palette] = true;
      (&palette_fade_color_channel_0)[palette] = 0;
      (&palette_fade_color[0].r)[palette] = '\0';
      (&palette_fade_color[0].g)[palette] = '\0';
      (&palette_fade_color[0].b)[palette] = '\0';
      (&palette_fade[0].frames_i)[palette] = 0;
      return;
    }
    if (loc_fade_type == PALETTE_FADE_BLACK_EASE_OUT) {
      related_to_palette_maybe_2 = 0xff;
      related_to_palette_maybe_1 = 0;
      (&palette_fade[0].ongoing)[palette] = true;
      (&palette_fade_color_channel_0)[palette] = 0xf1;
      (&palette_fade_color[0].r)[palette] = -0xf;
      (&palette_fade_color[0].g)[palette] = -0xf;
      (&palette_fade_color[0].b)[palette] = -0xf;
      (&palette_fade[0].frames_i)[palette] = 0;
      return;
    }
    if (loc_fade_type == PALETTE_FADE_WHITE_EASE_IN) {
      (&palette_fade[0].ongoing)[palette] = true;
      (&palette_fade_color_channel_0)[palette] = 0;
      (&palette_fade_color[0].r)[palette] = '\0';
      (&palette_fade_color[0].g)[palette] = '\0';
      (&palette_fade_color[0].b)[palette] = '\0';
      (&palette_fade[0].frames_i)[palette] = 0;
      return;
    }
    if (loc_fade_type == PALETTE_FADE_WHITE_EASE_OUT) {
      (&palette_fade[0].ongoing)[palette] = true;
      (&palette_fade_color_channel_0)[palette] = 0xf;
      (&palette_fade_color[0].r)[palette] = '\x0f';
      (&palette_fade_color[0].g)[palette] = '\x0f';
      (&palette_fade_color[0].b)[palette] = '\x0f';
      (&palette_fade[0].frames_i)[palette] = 0;
      return;
    }
  }
  return;
}

void palette_update(void)

{
  if (palette_fade[0].ongoing) {
    palette_update_fade(PALETTE_ID_OFFSET_0);
  } else if (palette_effect[0].state != PALETTE_EFFECT_STATE_DISABLED) {
    palette_commit(PALETTE_ID_OFFSET_0);
  }
  if (palette_fade[1].ongoing == false) {
    if (palette_effect[1].state != PALETTE_EFFECT_STATE_DISABLED) {
      palette_commit(PALETTE_ID_OFFSET_1);
    }
  } else {
    palette_update_fade(PALETTE_ID_OFFSET_1);
  }
  if (palette_fade[2].ongoing == false) {
    if (palette_effect[2].state != PALETTE_EFFECT_STATE_DISABLED) {
      palette_commit(PALETTE_ID_OFFSET_2);
    }
  } else {
    palette_update_fade(PALETTE_ID_OFFSET_2);
  }
  if (palette_fade[3].ongoing == false) {
    if (palette_effect[3].state != PALETTE_EFFECT_STATE_DISABLED) {
      palette_commit(PALETTE_ID_OFFSET_3);
    }
  } else {
    palette_update_fade(PALETTE_ID_OFFSET_3);
  }
  return;
}

// This applies an iteration of the palette's effect, if any. It updates the
// effect's frame counter and apply it if it reached its threshold.

void palette_update_fade(palette_id_offset_t palette)

{
  short i;
  short palette_offset;
  vdp_color_t *src;
  vdp_color_t *dst;
  palette_fade_type_t fade_type;

  fade_type = (&palette_fade[0].type)[palette];
  if (fade_type == PALETTE_FADE_NONE) {
    return;
  }
  // if (fx_type == PALETTE_FX_TYPE_1) {
  //   palette_commit();
  //   return;
  // }
  if (fade_type == PALETTE_FADE_1) {
    i = 0xf;
    palette_offset = (short)palette << 3;
    src = (vdp_color_t *)((int)palettes[0] + (int)palette_offset);
    dst = (vdp_color_t *)((int)vdp_palettes[0] + (int)palette_offset);
    do {
      src = src + 1;
      *dst = *src;
      i = i + -1;
      src = src;
      dst = dst + 1;
    } while (i != -1);
    related_to_palettes = 0xff;
    (&palette_fade[0].ongoing)[palette] = false;
    return;
  }
  // Only apply the effect every n frames.
  if ((&palette_fade[0].frames_i)[palette] != 0) {
    (&palette_fade[0].frames_i)[palette] =
        (&palette_fade[0].frames_i)[palette] - 1;
    return;
  }
  // The effect's counter reached 0, reset the counter and apply the effect.
  (&palette_fade[0].frames_i)[palette] = (&palette_fade[0].frames_n)[palette];
  if (fade_type != PALETTE_FADE_BLACK_EASE_IN) {
    if (fade_type == PALETTE_FADE_BLACK_EASE_OUT) {
      palette_update_fade_black_ease_out(palette);
      palette_apply_fade(palette);
      return;
    }
    if (fade_type != PALETTE_FADE_WHITE_EASE_IN) {
      if (fade_type != PALETTE_FADE_WHITE_EASE_OUT) {
        return;
      }
      palette_update_fade_white_ease_out(palette);
      palette_apply_fade(palette);
      return;
    }
    palette_update_fade_white_ease_in(palette);
    palette_apply_fade(palette);
    return;
  }
  palette_update_fade_black_ease_in(palette);
  palette_apply_fade(palette);
  return;
}

// Updates the effect and clears it once done.

void palette_update_fade_black_ease_in(palette_id_offset_t palette)

{
  (&palette_fade_color[0].r)[palette] =
      (&palette_fade_color_channel_0)[palette];
  (&palette_fade_color[0].g)[palette] =
      (&palette_fade_color_channel_0)[palette];
  (&palette_fade_color[0].b)[palette] =
      (&palette_fade_color_channel_0)[palette];
  (&palette_fade_color_channel_0)[palette] =
      (&palette_fade_color_channel_0)[palette] - 1;
  if ((&palette_fade_color_channel_0)[palette] == 0xf0) {
    (&palette_fade_done_0)[palette] = 0xff;
    (&palette_fade[0].type)[palette] = 0;
    (&palette_fade[0].ongoing)[palette] = false;
  }
  return;
}

// Updates the effect and clears it once done.

void palette_update_fade_black_ease_out(palette_id_offset_t palette)

{
  (&palette_fade_color[0].r)[palette] =
      (&palette_fade_color_channel_0)[palette];
  (&palette_fade_color[0].g)[palette] =
      (&palette_fade_color_channel_0)[palette];
  (&palette_fade_color[0].b)[palette] =
      (&palette_fade_color_channel_0)[palette];
  (&palette_fade_color_channel_0)[palette] =
      (&palette_fade_color_channel_0)[palette] + 1;
  if ((&palette_fade_color_channel_0)[palette] == 1) {
    (&palette_fade_done_0)[palette] = 0xff;
    (&palette_fade[0].type)[palette] = 0;
    (&palette_fade[0].ongoing)[palette] = false;
  }
  return;
}

// Updates the effect and clears it once done.

void palette_update_fade_white_ease_in(palette_id_offset_t palette)

{
  (&palette_fade_color[0].r)[palette] =
      (&palette_fade_color_channel_0)[palette];
  (&palette_fade_color[0].g)[palette] =
      (&palette_fade_color_channel_0)[palette];
  (&palette_fade_color[0].b)[palette] =
      (&palette_fade_color_channel_0)[palette];
  (&palette_fade_color_channel_0)[palette] =
      (&palette_fade_color_channel_0)[palette] + 1;
  if ((&palette_fade_color_channel_0)[palette] == 0x10) {
    (&palette_fade_done_0)[palette] = 0xff;
    (&palette_fade[0].type)[palette] = 0;
    (&palette_fade[0].ongoing)[palette] = false;
    // If mode 2 display enabled
    if (((undefined1)vdp_ctrl_mode_set_2_state & 0x40) != 0) {
      related_to_palette_maybe_1 = 0xff;
      related_to_palette_maybe_2 = 0;
    }
  }
  return;
}

// Updates the effect and clears it once done.

void palette_update_fade_white_ease_out(palette_id_flag_t palette)

{
  byte next;

  (&palette_fade_color[0].r)[palette] =
      (&palette_fade_color_channel_0)[palette];
  (&palette_fade_color[0].g)[palette] =
      (&palette_fade_color_channel_0)[palette];
  (&palette_fade_color[0].b)[palette] =
      (&palette_fade_color_channel_0)[palette];
  next = (&palette_fade_color_channel_0)[palette] - 1;
  (&palette_fade_color_channel_0)[palette] = next;
  if (next == 0) {
    (&palette_fade_done_0)[palette] = 0xff;
    (&palette_fade[0].type)[palette] = 0;
    (&palette_fade[0].ongoing)[palette] = false;
  }
  return;
}

void vdp_palettes_something(void)

{
  byte bVar1;
  short j;
  short k;
  short i;
  ushort uVar2;
  byte *pbVar3;
  vdp_palette_t *palettes_local;
  vdp_color_t *pvVar4;
  byte *pbVar5;
  vdp_color_t *pvVar6;
  bool bVar7;

  palettes_local = palettes;
  i = 3;
  pbVar3 = &DAT_ffff9812;
  do {
    (*palettes_local)[0] = DAT_ffff9810;
    bVar1 = *pbVar3;
    if (bVar1 < 0xfc) {
      k = (ushort)bVar1 + (ushort)bVar1 * 0x10;
      uVar2 = *(ushort *)(&DAT_0007c034 + k);
      j = 0xe;
      pvVar4 = (vdp_color_t *)((int)palettes_local + 2);
      pbVar5 = &DAT_0007c036 + k;
      do {
        bVar1 = *pbVar5;
        k = (ushort)(bVar1 & 0xe0) * 2;
        k = CONCAT11((char)((ushort)k >> 8), bVar1 & 0x1c | (byte)k) * 2;
        bVar7 = CARRY2(uVar2, uVar2);
        uVar2 = uVar2 * 2;
        palettes_local = (vdp_palette_t *)(pvVar4 + 1);
        *pvVar4 = (CONCAT11((char)((ushort)k >> 8), bVar1 & 3 | (byte)k) * 2 +
                   (ushort)bVar7) *
                  2;
        j = j + -1;
        pvVar4 = (vdp_color_t *)palettes_local;
        pbVar5 = pbVar5 + 1;
      } while (j != -1);
    } else {
      k = 0xf;
      pvVar4 = *palettes_local;
      pvVar6 = (vdp_color_t *)((int)palettes_2 +
                               (int)(short)((bVar1 - 0xfc) * 0x20));
      do {
        palettes_local = (vdp_palette_t *)(pvVar4 + 1);
        *pvVar4 = *pvVar6;
        k = k + -1;
        pvVar4 = (vdp_color_t *)palettes_local;
        pvVar6 = pvVar6 + 1;
      } while (k != -1);
    }
    i = i + -1;
    pbVar3 = pbVar3 + 1;
  } while (i != -1);
  return;
}

// Copies the source palette for the given entity to the final palette, which
// will be fed to the VDP.
//
// Called with entity #4, #8 or #c, for palettes 1, 2 and 3.
// Entity #0 for palette 0 should be possible but I didn't see it ingame yet.

void palette_commit(palette_id_offset_t palette)

{
  short i;
  short palette_offset;
  vdp_color_t *src;
  vdp_color_t *dst;

  i = 0xf;
  // Palette ID offsets are multiple of 4, this makes them multiples of 32,
  // which is the offset of a palette.
  palette_offset = (short)palette << 3;
  src = (vdp_color_t *)((int)palettes[0] + (int)palette_offset);
  dst = (vdp_color_t *)((int)vdp_palettes[0] + (int)palette_offset);
  do {
    src = src + 1;
    *dst = *src;
    i = i + -1;
    src = src;
    dst = dst + 1;
  } while (i != -1);
  related_to_palettes = 0xff;
  (&palette_fade[0].ongoing)[palette] = false;
  return;
}

// The applies the palette's effect, assuming it reached its frame count.
//
// It does so by adding the effect's color modifications to the palette's
// colors, saturating each channel on overflow or underflow.

void palette_apply_fade(palette_id_offset_t palette)

{
  ushort i;
  short palette_offset;
  ushort red;
  ushort green;
  byte blue;
  byte *color_green_red_p;
  char *color_p;
  ushort *vdp_color_p;
  char color_blue;
  byte color_element;
  short color_offset;

  i = (ushort)(&palette_iter[0].length)[palette];
  palette_offset = (short)palette << 3;
  color_offset = (ushort)(&palette_iter[0].start)[palette] * 2;
  color_p =
      (char *)((int)palettes[0] + (int)color_offset + (int)palette_offset);
  vdp_color_p = (ushort *)((int)vdp_palettes[0] + (int)color_offset +
                           (int)palette_offset);
  do {
    color_green_red_p = (byte *)(color_p + 1);
    color_blue = *color_p;
    color_p = color_p + 2;
    color_element =
        (&palette_fade_color[0].r)[palette] + (*color_green_red_p & 0xf);
    red = (ushort)color_element;
    // Saturate at 0 on subtraction
    if ((short)((ushort)color_element << 8) < 0) {
      red = 0;
    }
    // Saturate on overflow
    if ((red & 0xfff0) != 0) {
      red = 0xf;
    }
    color_element =
        (&palette_fade_color[0].g)[palette] + (*color_green_red_p >> 4);
    green = (ushort)color_element;
    // Saturate at 0 on subtraction
    if ((short)((ushort)color_element << 8) < 0) {
      green = 0;
    }
    // Saturate on overflow
    if ((green & 0xfff0) != 0) {
      green = 0xf;
    }
    // Saturate at 0 on subtraction
    blue = (&palette_fade_color[0].b)[palette] + color_blue;
    if ((short)((ushort)blue << 8) < 0) {
      blue = 0;
    }
    // Saturate on overflow
    if ((blue & 0xf0) != 0) {
      blue = 0xf;
    }
    *vdp_color_p = (ushort)blue << 8 | green << 4 | red;
    i = i - 1;
    vdp_color_p = vdp_color_p + 1;
  } while (i != 0xffff);
  related_to_palettes = 0xff;
  return;
}

void palette_set_effect(palette_id_flag_t palettes, bool enabled,
                        palette_effect_t *effect)

{
  if (enabled) {
    if ((palettes & PALETTE_ID_FLAG_0) != PALETTE_ID_FLAG_NONE) {
      palette_effect[0].state = PALETTE_EFFECT_STATE_ENABLED;
      palette_effect[0].duration = 0;
      palette_effect[0].remaining = 0;
      palette_effect_start[0] = effect;
      palette_effect_next[0] = effect;
    }
    if ((palettes & PALETTE_ID_FLAG_1) != PALETTE_ID_FLAG_NONE) {
      palette_effect[1].state = PALETTE_EFFECT_STATE_ENABLED;
      palette_effect[1].duration = 0;
      palette_effect[1].remaining = 0;
      palette_effect_start[1] = effect;
      palette_effect_next[1] = effect;
    }
    if ((palettes & PALETTE_ID_FLAG_2) != PALETTE_ID_FLAG_NONE) {
      palette_effect[2].state = PALETTE_EFFECT_STATE_ENABLED;
      palette_effect[2].duration = 0;
      palette_effect[2].remaining = 0;
      palette_effect_start[2] = effect;
      palette_effect_next[2] = effect;
    }
    if ((palettes & PALETTE_ID_FLAG_3) != PALETTE_ID_FLAG_NONE) {
      palette_effect[3].state = PALETTE_EFFECT_STATE_ENABLED;
      palette_effect[3].duration = 0;
      palette_effect[3].remaining = 0;
      palette_effect_start[3] = effect;
      palette_effect_next[3] = effect;
    }
    return;
  }
  if ((palettes & PALETTE_ID_FLAG_0) != PALETTE_ID_FLAG_NONE) {
    palette_effect[0].state = PALETTE_EFFECT_STATE_DISABLED;
  }
  if ((palettes & PALETTE_ID_FLAG_1) != PALETTE_ID_FLAG_NONE) {
    palette_effect[1].state = PALETTE_EFFECT_STATE_DISABLED;
  }
  if ((palettes & PALETTE_ID_FLAG_2) != PALETTE_ID_FLAG_NONE) {
    palette_effect[2].state = PALETTE_EFFECT_STATE_DISABLED;
  }
  if ((palettes & PALETTE_ID_FLAG_3) != PALETTE_ID_FLAG_NONE) {
    palette_effect[3].state = PALETTE_EFFECT_STATE_DISABLED;
  }
  return;
}

// Update a palette effect by decreasing its iteration count or loading the next
// effect instruction.

void palette_update_effect_all(void)

{
  short extraout_D0w;
  short i;
  vdp_palette_t *palettes_p;
  vdp_palette_t *extraout_A0;
  palette_id_offset_t palette;

  palette = PALETTE_ID_OFFSET_0;
  palettes_p = palettes;
  i = 3;
  do {
    if ((&palette_effect[0].state)[palette] != PALETTE_EFFECT_STATE_DISABLED) {
      if ((&palette_effect[0].remaining)[palette] == 0) {
        palette_update_effect(
            palette,
            palettes_p,
            *(palette_effect_t **)((int)palette_effect_next + palette));
        palettes_p = extraout_A0;
        i = extraout_D0w;
      } else {
        (&palette_effect[0].remaining)[palette] =
            (&palette_effect[0].remaining)[palette] - 1;
      }
    }
    palettes_p = palettes_p + 1;
    palette = palette + PALETTE_ID_OFFSET_1;
    i = i + -1;
  } while (i != -1);
  return;
}

// This applies a palette effect to the given palette.
//
// Can be called with:
// palette_fx_volcano_2
// palette_fx_volcano_3

void palette_update_effect(palette_id_offset_t palette, vdp_palette_t *dst,
                           palette_effect_t *effect_p)

{
  palette_effect_t effect;
  palette_effect_value_t value;
  vdp_palette_t *extraout_A0;
  palette_effect_t *ppVar1;
  palette_effect_t *extraout_A1;

  while (true) {
    while (true) {
      while (true) {
        ppVar1 = effect_p + 1;
        effect = *effect_p;
        value = (ushort)effect >> 1;
        if (value < PALETTE_EFFECT_VALUE_RESTART)
          break;
        effect_p = *(palette_effect_t **)((int)palette_effect_start + palette);
      }
      if (value < PALETTE_EFFECT_VALUE_SET_START)
        break;
      *(palette_effect_t **)((int)palette_effect_start + palette) = ppVar1;
      effect_p = ppVar1;
    }
    if (PALETTE_EFFECT_VALUE_STOP < value)
      break;
    if (PALETTE_EFFECT_VALUE_SET_DURATION < value) {
      (&palette_effect[0].duration)[palette] = effect._1_1_;
    LAB_0000ab6c:
      *(palette_effect_t **)((int)palette_effect_next + palette) = ppVar1;
      (&palette_effect[0].remaining)[palette] =
          (&palette_effect[0].duration)[palette];
      return;
    }
    palette_apply_effect_color(dst, effect, value);
    dst = extraout_A0;
    effect_p = extraout_A1;
  }
  (&palette_effect[0].state)[palette] = PALETTE_EFFECT_STATE_DISABLED;
  (&palette_fade_done_0)[palette] = 0xff;
  palette_commit(palette);
  goto LAB_0000ab6c;
}

// There is no need for the second parameter as everything is in the first one,
// it is an artifact of the fact the code was written in assembly.

void palette_apply_effect_color(vdp_palette_t *dst, palette_effect_t effect,
                                palette_effect_value_t color_index)

{
  ushort uVar1;

  // This extracts the index and the color channels from the effect and write
  // the color at the given index.
  uVar1 = (short)effect << 1;
  *(ushort *)((int)*dst + (int)(short)((color_index >> 8) * 2)) =
      (uVar1 & 0x380) << 2 | (uVar1 & 0x70) << 1 | uVar1 & 0xe;
  related_to_palettes = 0xff;
  return;
}

void FUN_0000aba0(word *dst_2)

{
  byte bVar1;
  short sVar2;
  ushort in_D0w;
  ushort uVar3;
  short i;
  word *dst_1;
  byte *src_1;
  bool bVar4;

  *dst_2 = DAT_ffff9810;
  if (in_D0w < 0xfc) {
    uVar3 = *(ushort *)(&DAT_0007c034 + (short)(in_D0w * 0x11));
    i = 0xe;
    dst_1 = dst_2 + 1;
    src_1 = &DAT_0007c036 + (short)(in_D0w * 0x11);
    do {
      bVar1 = *src_1;
      sVar2 = (ushort)(bVar1 & 0xe0) * 2;
      sVar2 =
          CONCAT11((char)((ushort)sVar2 >> 8), bVar1 & 0x1c | (byte)sVar2) * 2;
      bVar4 = CARRY2(uVar3, uVar3);
      uVar3 = uVar3 * 2;
      *dst_1 =
          (CONCAT11((char)((ushort)sVar2 >> 8), bVar1 & 3 | (byte)sVar2) * 2 +
           (ushort)bVar4) *
          2;
      i = i + -1;
      dst_1 = dst_1 + 1;
      src_1 = src_1 + 1;
    } while (i != -1);
    return;
  }
  i = 0xf;
  dst_1 = (word *)((int)palettes_2 + (int)(short)((in_D0w - 0xfc) * 0x20));
  do {
    *dst_2 = *dst_1;
    i = i + -1;
    dst_2 = dst_2 + 1;
    dst_1 = dst_1 + 1;
  } while (i != -1);
  return;
}

void text_unk_3(void)

{
  short i;
  uint uVar1;
  ushort j;
  word *pwVar2;
  uint *puVar3;

  i = 0x3f;
  pwVar2 = compressed_data_indices;
  do {
    pwVar2[0] = 0xffff;
    pwVar2[1] = 0xffff;
    i = i + -1;
    pwVar2 = pwVar2 + 2;
  } while (i != -1);
  uVar1 = 0xff;
  puVar3 = &vdp_gfx_ptr_1;
  do {
    *puVar3 = uVar1;
    j = (short)uVar1 - 1;
    uVar1 = (uint)j;
    puVar3 = puVar3 + 1;
  } while (j != 0xffff);
  return;
}

void FUN_0000ac2a(void)

{
  short sVar1;
  word *pwVar2;

  sVar1 = 0x1f;
  pwVar2 = compressed_data_indices;
  do {
    pwVar2[0] = 0xffff;
    pwVar2[1] = 0xffff;
    sVar1 = sVar1 + -1;
    pwVar2 = pwVar2 + 2;
  } while (sVar1 != -1);
  return;
}

void uncompress_and_copy_to_vram(void)

{
  word *indices;
  undefined *dst;
  word index;

  indices = compressed_data_indices;
  dst = (undefined *)0x0;
  compressed_data_indices_size = 0x40;
  do {
    index = *indices;
    if ((-1 < (short)index) && (index != indices[0x40])) {
      indices[0x40] = index;
      uncompress_data(index, (uint8_t *)&vdp_gfx_ptr_1);
      vdp_copy_1kb_from_gfx_ptr_1_to_vram(dst);
    }
    indices = indices + 1;
    dst = dst + 0x400;
    compressed_data_indices_size = compressed_data_indices_size - 1;
  } while (compressed_data_indices_size != 0);
  return;
}

void FUN_0000ac74(void)

{
  do {
    // WARNING: Do nothing block with infinite loop
  } while (true);
}

// The upper half of dst isn't set somehow.

void vdp_copy_1kb_from_gfx_ptr_1_to_vram(undefined *dst)

{
  vdp_copy(VDP_MEM_VIDEO_RAM,
           &vdp_gfx_ptr_1,
           (void *)(int)(short)dst,
           0x200,
           '\x02');
  return;
}

void clear_unk_1(void)

{
  DAT_ffff9f0a = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000ac92(void)

{
  undefined4 in_A0;

  DAT_ffff9f0a = 0x80;
  DAT_ffff9f0c = in_A0;
  _DAT_ffff9f10 = in_A0;
  anim_related_maybe();
  return;
}

void FUN_0000aca6(void)

{
  if (DAT_ffff9f0a < '\0') {
    FUN_0000acb2();
  }
  return;
}

void FUN_0000acb2(void)

{
  byte bVar1;
  byte *unaff_D2;
  byte *pbVar2;
  byte *extraout_A1;

  DAT_ffff9f0b = DAT_ffff9f0b + -1;
  if (DAT_ffff9f0b != '\0') {
    return;
  }
  DAT_ffff9f0b = 0;
  pbVar2 = DAT_ffff9f0c;
  while (true) {
    bVar1 = *pbVar2;
    if (bVar1 < 0xf8)
      break;
    (*(code *)((int)&WORD_0000ad16 +
               (int)*(short *)((int)&WORD_0000ad16 +
                               (int)(short)((bVar1 - 0xf8) * 2))))();
    pbVar2 = extraout_A1;
  }
  DAT_ffff9f0b = bVar1;
  copy_uncompressed_data_to_vdp_ram((word *)(pbVar2 + 1), unaff_D2);
  return;
}

// Are tile arrays #ffff-terminated?

byte copy_uncompressed_data_to_vdp_ram(word *id_p, byte *param_2)

{
  void *vram_dst;
  ushort uVar1;
  undefined4 *extraout_A0;
  undefined4 *data_p;
  word *extraout_A1;

  do {
    uVar1 = (ushort) * (byte *)id_p;
    vram_dst = *(void **)((int)id_p + 1);
    // This returns A0, for some reason Ghidra doesn't get it.
    get_uncompressed_data_address(*(word *)((int)id_p + 3));
    vdp_set_vram_write_addr(vram_dst);
    data_p = extraout_A0;
    do {
      Ram00c00000 = *data_p;
      uVar1 = uVar1 - 1;
      data_p = data_p + 1;
    } while (uVar1 != 0xffff);
    id_p = extraout_A1;
  } while (-1 < (char)*(byte *)extraout_A1);
  DAT_ffff9f0c = (byte *)((int)extraout_A1 + 1);
  return *(byte *)extraout_A1;
}

void anim_related_maybe(void)

{
  byte *unaff_D2;
  byte *anim;
  byte *extraout_A1;
  byte anim_item;

  anim = DAT_ffff9f0c;
  while (true) {
    anim_item = *anim;
    // Is this related to anim_item_t?
    // Is it just similar to it?
    // #c6e has extremely similar code.
    if (anim_item < 0xf8)
      break;
    (*(code *)((int)&WORD_0000ad16 +
               (int)*(short *)((int)&WORD_0000ad16 +
                               (int)(short)((anim_item - 0xf8) * 2))))();
    anim = extraout_A1;
  }
  DAT_ffff9f0b = anim_item;
  copy_uncompressed_data_to_vdp_ram((word *)(anim + 1), unaff_D2);
  return;
}

void FUN_0000ad26(void)

{
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000ad28(void)

{
  undefined1 *in_A1;

  DAT_ffff9f18 = *in_A1;
  _DAT_ffff9f14 = in_A1 + 1;
  return;
}

void FUN_0000ad32(void)

{
  DAT_ffff9f18 = DAT_ffff9f18 + -1;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000ad3e(void)

{
  undefined4 in_A1;

  _DAT_ffff9f10 = in_A1;
  return;
}

void FUN_0000ad44(void)

{
  return;
}

void FUN_0000ad4a(void)

{
  DAT_ffff9f0a = 0;
  return;
}

void something(byte *param_1)

{
  byte *extraout_A0;
  byte data;

  do {
    while (true) {
      data = *param_1;
      if (0xf7 < data)
        break;
      VDP_DATA = (ushort)data;
      param_1 = param_1 + 1;
    }
    // Data is in the [#f8, #ff] range, so adding 8 moves it to the [0, 8]
    // range, turning it into the "jump table" index.
    //
    // It's not a jump table actually but branching instructions, but it works
    // the same.
    (*(something_command_f8 + (short)((ushort)(byte)(data + 8) << 2)))();
    param_1 = extraout_A0;
  } while (true);
}

void something_command_f8(void)

{
  undefined2 unaff_D6w;
  undefined1 *in_A0;
  undefined2 *unaff_A4;

  *unaff_A4 = CONCAT11((char)((ushort)unaff_D6w >> 8), *in_A0);
  return;
}

void something_command_f9(void)

{
  FUN_0000adfc();
  return;
}

void something_command_fa(void)

{
  FUN_0000adfc();
  return;
}

void something_command_fb(void)

{
  undefined2 *in_A0;
  undefined2 *unaff_A4;

  *unaff_A4 = *in_A0;
  return;
}

void something_command_fc(void)

{
  return;
}

void something_command_fd(void)

{
  ushort uVar1;
  undefined2 unaff_D6w;
  short sVar2;
  byte *in_A0;
  short *unaff_A4;

  uVar1 = (ushort)*in_A0;
  sVar2 = CONCAT11((char)((ushort)unaff_D6w >> 8), in_A0[1]) + -1;
  do {
    sVar2 = sVar2 + 1;
    *unaff_A4 = sVar2;
    uVar1 = uVar1 - 1;
  } while (uVar1 != 0xffff);
  return;
}

void something_command_fe(void)

{
  byte bVar1;
  ushort uVar2;
  undefined2 unaff_D6w;
  byte *in_A0;
  undefined2 *unaff_A4;

  uVar2 = (ushort)*in_A0;
  bVar1 = in_A0[1];
  do {
    *unaff_A4 = CONCAT11((char)((ushort)unaff_D6w >> 8), bVar1);
    uVar2 = uVar2 - 1;
  } while (uVar2 != 0xffff);
  return;
}

void something_command_ff(void)

{
  return;
}

void something_command_ff(void)

{
  return;
}

void something_command_fe(void)

{
  byte bVar1;
  ushort uVar2;
  undefined2 unaff_D6w;
  byte *in_A0;
  undefined2 *unaff_A4;

  uVar2 = (ushort)*in_A0;
  bVar1 = in_A0[1];
  do {
    *unaff_A4 = CONCAT11((char)((ushort)unaff_D6w >> 8), bVar1);
    uVar2 = uVar2 - 1;
  } while (uVar2 != 0xffff);
  return;
}

void something_command_fd(void)

{
  ushort uVar1;
  undefined2 unaff_D6w;
  short sVar2;
  byte *in_A0;
  short *unaff_A4;

  uVar1 = (ushort)*in_A0;
  sVar2 = CONCAT11((char)((ushort)unaff_D6w >> 8), in_A0[1]) + -1;
  do {
    sVar2 = sVar2 + 1;
    *unaff_A4 = sVar2;
    uVar1 = uVar1 - 1;
  } while (uVar1 != 0xffff);
  return;
}

void something_command_fc(void)

{
  return;
}

void something_command_fb(void)

{
  undefined2 *in_A0;
  undefined2 *unaff_A4;

  *unaff_A4 = *in_A0;
  return;
}

void something_command_fa(void)

{
  FUN_0000adfc();
  return;
}

void something_command_f9(void)

{
  FUN_0000adfc();
  return;
}

void something_command_f8(void)

{
  undefined2 unaff_D6w;
  undefined1 *in_A0;
  undefined2 *unaff_A4;

  *unaff_A4 = CONCAT11((char)((ushort)unaff_D6w >> 8), *in_A0);
  return;
}

void FUN_0000adfc(void)

{
  undefined4 in_D0;
  ushort unaff_D7w;
  ushort *unaff_A5;

  *unaff_A5 = unaff_D7w & 0x3fff | 0x4000;
  *unaff_A5 = (ushort)((CONCAT22((short)((uint)in_D0 >> 0x10), unaff_D7w) &
                        0xffffc000) *
                           4 >>
                       0x10);
  return;
}

void FUN_0000ae18(void)

{
  short sVar1;
  int iVar2;

  FUN_0000b52e();
  iVar2 = 0;
  sVar1 = 0;
  do {
    (&DAT_ffffc716)[iVar2] = 0;
    (&DAT_ffffc717)[iVar2] = 0;
    *(undefined4 *)((int)&DAT_ffffc722 + iVar2) = 0;
    *(undefined2 *)((int)&room_boundary_x + iVar2) = 0;
    *(undefined2 *)((int)&camera_pos_x_int + iVar2) = 0;
    *(undefined2 *)((int)&room_boundary_x + iVar2) = 0;
    *(undefined2 *)((int)&camera_pos_x_int + iVar2) = 0;
    (&DAT_ffffc718)[iVar2] = 0;
    (&DAT_ffffc719)[iVar2] = 0;
    iVar2 = iVar2 + 4;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  sVar1 = 9;
  iVar2 = 0;
  do {
    (&DAT_ffffc8f0)[iVar2] = 0;
    iVar2 = iVar2 + 4;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000ae60(void)

{
  undefined2 uVar1;
  int iVar2;

  _related_to_comp_unk_4_ffffa32a_2 = DAT_ffffc73a + DAT_ffffc782 + -0x80;
  related_to_comp_unk_4_ffffa32a_1 = DAT_ffffc746 + DAT_ffffc784 + -0x80;
  iVar2 = 0;
  do {
    uVar1 = DAT_ffff91ce;
    if (((&DAT_ffffc716)[iVar2] & 0xc0) != 0) {
      if (((&DAT_ffffc716)[iVar2] & 0xc0) == 0xc0) {
        FUN_0000b13c();
      } else {
        DAT_ffff91ce = CONCAT11(0xff, (undefined1)DAT_ffff91ce);
        FUN_0000aeba();
        DAT_ffff91ce = uVar1;
        (&DAT_ffffc716)[iVar2] = (&DAT_ffffc716)[iVar2] | 0x40;
      }
    }
    iVar2 = iVar2 + 4;
  } while (iVar2 != 8);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000aeba(void)

{
  short sVar1;
  undefined2 unaff_D2w;
  short sVar2;
  int unaff_A4;

  if ((unaff_A4 == 4) &&
      (((DAT_ffffc71a & 1) != 0 || ((DAT_ffffc71a & 2) != 0)))) {
    VDP_CTRL = 0x8b03;
    sRamffffc758 = _DAT_ffffc788 + DAT_ffffc74a;
    uRamffffc756 = 0x1000;
    uRamffffc762 = 0x1000;
    sRamffffc764 = sRamffffc758;
    if ((DAT_ffffc71a & 1) == 0) {
      FUN_0000b776();
    } else {
      FUN_0000b3d2();
    }
    sVar2 = 0x1c;
    do {
      FUN_0000af7c();
      FUN_0000b36e();
      FUN_0000b306();
      uRamffffc77c = unaff_D2w;
      FUN_0000b3b4();
      sRamffffc764 = sRamffffc764 + 8;
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
    return;
  }
  VDP_CTRL = 0x8b03;
  sVar2 = *(short *)((int)&DAT_ffffc782 + unaff_A4) +
          *(short *)((int)&DAT_ffffc73a + unaff_A4);
  sVar1 = *(short *)((int)&DAT_ffffc784 + unaff_A4) +
          *(short *)((int)&DAT_ffffc746 + unaff_A4);
  *(short *)(&DAT_ffffc752 + unaff_A4) = sVar2;
  *(short *)(&DAT_ffffc754 + unaff_A4) = sVar1;
  *(short *)(&DAT_ffffc75e + unaff_A4) = sVar2;
  *(short *)(&DAT_ffffc760 + unaff_A4) = sVar1;
  FUN_0000afac();
  sVar2 = 0x1c;
  do {
    FUN_0000affa();
    FUN_0000b04e();
    FUN_0000b306();
    *(undefined2 *)(&DAT_ffffc778 + unaff_A4) = unaff_D2w;
    FUN_0000b0e8();
    *(short *)(&DAT_ffffc760 + unaff_A4) =
        *(short *)(&DAT_ffffc760 + unaff_A4) + 8;
    sVar2 = sVar2 + -1;
  } while (sVar2 != -1);
  return;
}

void FUN_0000af7c(void)

{
  return;
}

void FUN_0000afac(void)

{
  ushort uVar1;
  word wVar2;
  ushort in_D0w;
  ushort in_D1w;
  short sVar3;
  int unaff_A4;
  word *pwVar4;

  uVar1 = in_D1w & 0xff;
  wVar2 = -(in_D0w & 0x1ff);
  if ((short)unaff_A4 == 0) {
    sVar3 = 0xe7;
    pwVar4 = &vdp_hblank_effect_asha_p;
    do {
      *pwVar4 = wVar2;
      sVar3 = sVar3 + -1;
      pwVar4 = pwVar4 + 1;
    } while (sVar3 != -1);
    vdp_related_to_display_asha = vdp_related_to_display_asha | 5;
    vdp_gfx_ptr_5._0_2_ = uVar1;
  } else {
    sVar3 = 0xe7;
    pwVar4 = &vdp_hblank_effect_pepelogoo_p;
    do {
      *pwVar4 = wVar2;
      sVar3 = sVar3 + -1;
      pwVar4 = pwVar4 + 1;
    } while (sVar3 != -1);
    vdp_related_to_display_asha = vdp_related_to_display_asha | 10;
    vdp_gfx_ptr_6 = uVar1;
  }
  *(word *)(&DAT_ffffc76a + unaff_A4) = wVar2;
  *(ushort *)(&DAT_ffffc76c + unaff_A4) = uVar1;
  return;
}

void FUN_0000affa(void)

{
  return;
}

void FUN_0000b04e(void)

{
  ushort uVar1;
  ushort uVar2;
  ushort unaff_D2w;
  ushort uVar3;
  ushort *extraout_A0;
  ushort *puVar4;
  ushort *extraout_A1;
  ushort *puVar5;
  ushort *puVar6;

  uVar3 = 0;
  FUN_0000b0c6();
  puVar4 = extraout_A0;
  puVar5 = extraout_A1;
  if ((unaff_D2w & 1) != 0) {
    uVar3 = *extraout_A0;
    *extraout_A1 = *(ushort *)(&DAT_ffff4000 +
                               (ushort)(unaff_D2w * 2 + (uVar3 & 0x3ff) * 8));
    puVar5 = extraout_A1 + 1;
    *extraout_A1 = uVar3 & 0x8000 | *extraout_A1;
    uVar3 = 1;
    unaff_D2w = unaff_D2w & 0xfffe;
    puVar4 = extraout_A0 + 1;
  }
  do {
    uVar2 = *puVar4 & 0x8000;
    uVar1 = unaff_D2w * 2 + (*puVar4 & 0x3ff) * 8;
    *puVar5 = *(ushort *)(&DAT_ffff4000 + uVar1);
    puVar6 = puVar5 + 1;
    *puVar5 = uVar2 | *puVar5;
    *puVar6 = *(ushort *)(&DAT_ffff4002 + uVar1);
    puVar5 = puVar5 + 2;
    *puVar6 = uVar2 | *puVar6;
    uVar3 = uVar3 + 2;
    puVar4 = puVar4 + 1;
  } while (uVar3 < 0x21);
  return;
}

void FUN_0000b0c6(void)

{
  return;
}

void FUN_0000b0e8(void)

{
  void *vram_dst;
  short sVar1;
  ushort uVar3;
  short sVar4;
  uint extraout_D1;
  uint uVar2;
  void *pvVar5;
  word *extraout_A0;
  word *pwVar6;
  undefined2 *extraout_A0_00;
  undefined2 *puVar7;
  undefined2 *extraout_A1;
  int unaff_A4;

  vram_dst = *(void **)(&DAT_ffffc778 + unaff_A4);
  vdp_set_vram_write_addr(vram_dst);
  uVar3 = ((ushort)vram_dst & 0x7f) >> 1;
  if (uVar3 < 0x1f) {
    sVar1 = 0x20;
    sVar4 = 0;
    pwVar6 = extraout_A0;
  } else {
    sVar4 = uVar3 - 0x1f;
    sVar1 = 0x20 - sVar4;
    pwVar6 = extraout_A0;
  }
  do {
    pvVar5 = vram_dst;
    VDP_DATA = *pwVar6;
    sVar1 = sVar1 + -1;
    vram_dst = (void *)((short)pvVar5 + 2);
    pwVar6 = pwVar6 + 1;
  } while (sVar1 != -1);
  if (sVar4 != 0) {
    vdp_set_vram_write_addr((void *)((short)pvVar5 + -0x7e));
    uVar2 = extraout_D1;
    puVar7 = extraout_A0_00;
    do {
      *extraout_A1 = *puVar7;
      uVar3 = (short)uVar2 - 1;
      uVar2 = (uint)uVar3;
      puVar7 = puVar7 + 1;
    } while (uVar3 != 0xffff);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined *FUN_0000b13c(void)

{
  ushort uVar1;
  undefined *puVar2;
  word wVar3;
  undefined2 extraout_D1w;
  ushort unaff_D2w;
  short sVar4;
  undefined **ppuVar5;
  word *pwVar6;
  int iVar7;
  int unaff_A4;

  if (unaff_A4 != 4) {
  LAB_0000b156:
    uVar1 = *(short *)((int)&DAT_ffffc782 + unaff_A4) +
            *(short *)((int)&DAT_ffffc73a + unaff_A4);
    if (uVar1 != *(ushort *)(&DAT_ffffc752 + unaff_A4)) {
      if (uVar1 < *(ushort *)(&DAT_ffffc752 + unaff_A4)) {
        *(ushort *)(&DAT_ffffc75e + unaff_A4) = uVar1;
        *(short *)(&DAT_ffffc760 + unaff_A4) =
            *(short *)((int)&DAT_ffffc784 + unaff_A4) +
            *(short *)((int)&DAT_ffffc746 + unaff_A4);
      } else {
        unaff_D2w = uVar1 + 0x100;
        *(ushort *)(&DAT_ffffc75e + unaff_A4) = unaff_D2w;
        *(short *)(&DAT_ffffc760 + unaff_A4) =
            *(short *)((int)&DAT_ffffc784 + unaff_A4) +
            *(short *)((int)&DAT_ffffc746 + unaff_A4);
      }
      FUN_0000b208();
      (&DAT_ffffc719)[unaff_A4] = 0xff;
      FUN_0000b306();
      *(ushort *)(&entity_something + unaff_A4) = unaff_D2w;
    }
    uVar1 = *(short *)((int)&DAT_ffffc784 + unaff_A4) +
            *(short *)((int)&DAT_ffffc746 + unaff_A4);
    if (uVar1 != *(ushort *)(&DAT_ffffc754 + unaff_A4)) {
      if (uVar1 < *(ushort *)(&DAT_ffffc754 + unaff_A4)) {
        *(ushort *)(&DAT_ffffc760 + unaff_A4) = uVar1;
        *(short *)(&DAT_ffffc75e + unaff_A4) =
            *(short *)((int)&DAT_ffffc782 + unaff_A4) +
            *(short *)((int)&DAT_ffffc73a + unaff_A4);
      } else {
        unaff_D2w = uVar1 + 0xe0;
        *(ushort *)(&DAT_ffffc760 + unaff_A4) = unaff_D2w;
        *(short *)(&DAT_ffffc75e + unaff_A4) =
            *(short *)((int)&DAT_ffffc782 + unaff_A4) +
            *(short *)((int)&DAT_ffffc73a + unaff_A4);
      }
      FUN_0000affa();
      FUN_0000b04e();
      (&DAT_ffffc718)[unaff_A4] = 0xff;
      FUN_0000b306();
      *(ushort *)(&DAT_ffffc778 + unaff_A4) = unaff_D2w;
    }
    puVar2 = (undefined *)FUN_0000afac();
    *(short *)(&DAT_ffffc752 + unaff_A4) = (short)puVar2;
    *(undefined2 *)(&DAT_ffffc754 + unaff_A4) = extraout_D1w;
    return puVar2;
  }
  if ((DAT_ffffc71a & 2) != 0) {
    uVar1 = _DAT_ffffc788 + DAT_ffffc74a;
    if (uVar1 != uRamffffc758) {
      uRamffffc764 = uVar1;
      if (uRamffffc758 <= uVar1) {
        unaff_D2w = uVar1 + 0xe0;
        uRamffffc764 = unaff_D2w;
      }
      uRamffffc762 = 0x1000;
      FUN_0000b80e();
      FUN_0000b36e();
      FUN_0000b306();
      uRamffffc77c = unaff_D2w;
      FUN_0000b3b4();
    }
    if ((DAT_ffffc71a & 1) == 0) {
      puVar2 = (undefined *)FUN_0000afac();
      if ((DAT_ffffc71a & 4) != 0) {
        puVar2 = (undefined *)FUN_0000b54a();
      }
      if ((DAT_ffffc71a & 8) != 0) {
        puVar2 = (undefined *)FUN_0000b640();
      }
    } else {
      puVar2 = (undefined *)FUN_0000b3d2();
    }
    sRamffffc756 = _DAT_ffffc786 + _DAT_ffffc73e;
    uRamffffc758 = _DAT_ffffc788 + DAT_ffffc74a;
    return puVar2;
  }
  if ((DAT_ffffc71a & 1) == 0)
    goto LAB_0000b156;
  vdp_related_to_display_asha = vdp_related_to_display_asha | 10;
  vdp_gfx_ptr_6 = (ushort)(byte)(DAT_ffffc788_1 + (char)DAT_ffffc74a);
  sVar4 = DAT_ffffc8ee + -1;
  iVar7 = 0;
  do {
    if (((&DAT_ffffc8f0)[iVar7] & 1) == 0) {
      puVar2 = (undefined *)FUN_0000b4b0();
    } else {
      puVar2 = (undefined *)FUN_0000b444();
    }
    iVar7 = iVar7 + 4;
    sVar4 = sVar4 + -1;
  } while (sVar4 != -1);
  if ((DAT_ffffc71a & 4) != 0) {
    puVar2 = (undefined *)FUN_0000b5f8();
    BYTE_ffffc8e5 = BYTE_ffffc8e5 - 1;
    if ((char)BYTE_ffffc8e5 < '\0') {
      ppuVar5 = (undefined **)(PTR_ffffc8e6 + 1);
      wVar3 = *PTR_ffffc8e6;
      if ((short)wVar3 < 0) {
        ppuVar5 = &PTR_WORD_ARRAY_0000b57a;
        wVar3 = 100;
      }
      BYTE_ffffc8e5 = (byte)wVar3;
      PTR_ffffc8e6 = (word *)(ppuVar5 + 1);
      puVar2 = *ppuVar5;
      DAT_ffffc8ea = puVar2;
    }
    return puVar2;
  }
  if ((DAT_ffffc71a & 8) == 0) {
    return puVar2;
  }
  uVar1 = _DAT_ffffc792 - DAT_ffffc74a;
  puVar2 = (undefined *)(uint)uVar1;
  if ((short)uVar1 < 0) {
    puVar2 = (undefined *)(uint)(ushort)(_DAT_ffffc794 + uVar1);
    if ((short)(_DAT_ffffc794 + uVar1) < 0)
      goto LAB_0000b65e;
  } else if (0xdf < uVar1)
    goto LAB_0000b65e;
  puVar2 = (undefined *)FUN_0000b708();
LAB_0000b65e:
  BYTE_ffffc8e5 = BYTE_ffffc8e5 - 1;
  if ((char)BYTE_ffffc8e5 < '\0') {
    pwVar6 = PTR_ffffc8e6 + 1;
    wVar3 = *PTR_ffffc8e6;
    if ((short)wVar3 < 0) {
      pwVar6 = WORD_ARRAY_0000b68a;
      wVar3 = 100;
    }
    BYTE_ffffc8e5 = (byte)wVar3;
    PTR_ffffc8e6 = (word *)((int)pwVar6 + 4);
    puVar2 = *(undefined **)pwVar6;
    DAT_ffffc8ea = puVar2;
  }
  return puVar2;
}

void FUN_0000b208(void)

{
  ushort uVar1;
  ushort uVar2;
  ushort unaff_D2w;
  ushort uVar3;
  short sVar4;
  ushort uVar5;
  ushort *extraout_A0;
  ushort *puVar6;
  ushort *extraout_A1;
  ushort *puVar7;
  ushort *puVar8;
  int unaff_A4;

  uVar5 = 0;
  FUN_0000affa();
  FUN_0000b0c6();
  uVar3 = *(ushort *)(&DAT_ffffc760 + unaff_A4);
  sVar4 = 0x10 << ((&DAT_ffffc717)[unaff_A4] & 0x3f);
  puVar6 = extraout_A0;
  puVar7 = extraout_A1;
  if ((unaff_D2w & 2) != 0) {
    uVar5 = *extraout_A0;
    *extraout_A1 = *(ushort *)(&DAT_ffff4000 +
                               (ushort)(unaff_D2w * 2 + (uVar5 & 0x3ff) * 8));
    puVar7 = extraout_A1 + 1;
    *extraout_A1 = uVar5 & 0x8000 | *extraout_A1;
    uVar3 = uVar3 + 8;
    uVar5 = 1;
    unaff_D2w = unaff_D2w & 0xfffd;
    if (0x100f < uVar3) {
      puVar6 = (ushort *)((int)sVar4 + (int)extraout_A0);
    }
  }
  while (true) {
    uVar2 = *puVar6 & 0x8000;
    uVar1 = unaff_D2w * 2 + (*puVar6 & 0x3ff) * 8;
    *puVar7 = *(ushort *)(&DAT_ffff4000 + uVar1);
    puVar8 = puVar7 + 1;
    *puVar7 = uVar2 | *puVar7;
    *puVar8 = *(ushort *)(&DAT_ffff4004 + uVar1);
    puVar7 = puVar7 + 2;
    *puVar8 = uVar2 | *puVar8;
    uVar3 = uVar3 + 0x10;
    uVar5 = uVar5 + 2;
    if (0x1c < uVar5)
      break;
    if (0x100f < uVar3) {
      puVar6 = (ushort *)((int)sVar4 + (int)puVar6);
    }
  }
  return;
}

// This function is improperly decompiled, data loaded to A0 should be reused in
// the whole function as the functions called between the load and the usage
// don't use A0, but it's not detected as such.

void entity_load_gfx_likely(entity_id_t self)

{
  uint extraout_D0;
  uint uVar1;
  short extraout_D1w;
  short sVar3;
  void *pvVar4;
  void *vram_dst;
  undefined2 *extraout_A0;
  undefined2 *extraout_A0_00;
  undefined2 *puVar5;
  undefined2 *vdp_data;
  undefined2 *vdp_data2;
  ushort uVar2;

  // Set auto increment to #80
  VDP_CTRL = 0x8f80;
  vram_dst = *(void **)(&entity_something + self);
  if (2 < ((ushort)vram_dst & 0xf80) >> 7) {
    vdp_set_vram_write_addr(vram_dst);
    sVar3 = extraout_D1w;
    puVar5 = extraout_A0;
    do {
      pvVar4 = vram_dst;
      *vdp_data = *puVar5;
      sVar3 = sVar3 + -1;
      puVar5 = puVar5 + 1;
      vram_dst = (void *)((short)pvVar4 + 0x80);
    } while (sVar3 != -1);
    vram_dst = (void *)((short)pvVar4 + -0xf80);
  }
  vdp_set_vram_write_addr(vram_dst);
  uVar1 = extraout_D0;
  puVar5 = extraout_A0_00;
  do {
    *vdp_data2 = *puVar5;
    uVar2 = (short)uVar1 - 1;
    uVar1 = (uint)uVar2;
    puVar5 = puVar5 + 1;
  } while (uVar2 != 0xffff);
  // Set auto increment to 2
  VDP_CTRL = 0x8f02;
  return;
}

ushort FUN_0000b306(void)

{
  int unaff_A4;

  return (*(short *)(&DAT_ffffc75e + unaff_A4) - 0x1000U & 0x1f8) >> 2;
}

void FUN_0000b338(void)

{
  undefined2 uVar1;
  undefined2 extraout_D0w;
  void *vram_dst;
  short sVar2;
  undefined2 *extraout_A0;

  uVar1 = DAT_ffff91ce;
  DAT_ffff91ce = CONCAT11(0xff, (undefined1)DAT_ffff91ce);
  vram_dst = (void *)0xc000;
  sVar2 = 0x7ff;
  do {
    FUN_00001502();
    vdp_set_vram_write_addr(vram_dst);
    *extraout_A0 = extraout_D0w;
    vram_dst = (void *)((short)vram_dst + 2);
    sVar2 = sVar2 + -1;
  } while (sVar2 != -1);
  DAT_ffff91ce = uVar1;
  return;
}

void FUN_0000b36e(void)

{
  ushort uVar1;
  ushort uVar2;
  short sVar3;
  ushort uVar4;
  ushort *in_A0;
  ushort *puVar5;
  ushort *puVar6;
  int unaff_A4;

  puVar5 = &DAT_ffffc81e;
  uVar4 = 0;
  sVar3 = 0;
  if (((&DAT_ffffc761)[unaff_A4] & 8) != 0) {
    sVar3 = 4;
  }
  do {
    uVar2 = *in_A0 & 0x8000;
    uVar1 = sVar3 + (*in_A0 & 0x3ff) * 8;
    *puVar5 = *(ushort *)(&DAT_ffff4000 + uVar1);
    puVar6 = puVar5 + 1;
    *puVar5 = uVar2 | *puVar5;
    *puVar6 = *(ushort *)(&DAT_ffff4002 + uVar1);
    puVar5 = puVar5 + 2;
    *puVar6 = uVar2 | *puVar6;
    uVar4 = uVar4 + 2;
    in_A0 = in_A0 + 1;
  } while (uVar4 < 0x40);
  return;
}

void FUN_0000b3b4(void)

{
  short sVar1;
  word *extraout_A0;
  word *pwVar2;
  int unaff_A4;

  vdp_set_vram_write_addr(*(void **)(&DAT_ffffc778 + unaff_A4));
  sVar1 = 0x3f;
  pwVar2 = extraout_A0;
  do {
    VDP_DATA = *pwVar2;
    sVar1 = sVar1 + -1;
    pwVar2 = pwVar2 + 1;
  } while (sVar1 != -1);
  return;
}

undefined *FUN_0000b3d2(void)

{
  ushort uVar1;
  undefined *puVar2;
  word wVar3;
  short sVar4;
  undefined **ppuVar5;
  word *pwVar6;
  int iVar7;
  int unaff_A4;

  vdp_related_to_display_asha = vdp_related_to_display_asha | 10;
  vdp_gfx_ptr_6 = (ushort)(byte)(*(char *)((int)&DAT_ffffc784 + unaff_A4 + 1) +
                                 *(char *)((int)&DAT_ffffc746 + unaff_A4 + 1));
  sVar4 = DAT_ffffc8ee + -1;
  iVar7 = 0;
  do {
    if (((&DAT_ffffc8f0)[iVar7] & 1) == 0) {
      puVar2 = (undefined *)FUN_0000b4b0();
    } else {
      puVar2 = (undefined *)FUN_0000b444();
    }
    iVar7 = iVar7 + 4;
    sVar4 = sVar4 + -1;
  } while (sVar4 != -1);
  if (((&DAT_ffffc716)[unaff_A4] & 4) != 0) {
    puVar2 = (undefined *)FUN_0000b5f8();
    BYTE_ffffc8e5 = BYTE_ffffc8e5 - 1;
    if ((char)BYTE_ffffc8e5 < '\0') {
      ppuVar5 = (undefined **)(PTR_ffffc8e6 + 1);
      wVar3 = *PTR_ffffc8e6;
      if ((short)wVar3 < 0) {
        ppuVar5 = &PTR_WORD_ARRAY_0000b57a;
        wVar3 = 100;
      }
      BYTE_ffffc8e5 = (byte)wVar3;
      PTR_ffffc8e6 = (word *)(ppuVar5 + 1);
      puVar2 = *ppuVar5;
      DAT_ffffc8ea = puVar2;
    }
    return puVar2;
  }
  if (((&DAT_ffffc716)[unaff_A4] & 8) == 0) {
    return puVar2;
  }
  uVar1 = *(short *)(&DAT_ffffc78e + unaff_A4) -
          *(short *)((int)&DAT_ffffc746 + unaff_A4);
  puVar2 = (undefined *)(uint)uVar1;
  if ((short)uVar1 < 0) {
    puVar2 = (undefined *)(uint)(ushort)(*(short *)(&DAT_ffffc790 + unaff_A4) +
                                         uVar1);
    if ((short)(*(short *)(&DAT_ffffc790 + unaff_A4) + uVar1) < 0)
      goto LAB_0000b65e;
  } else if (0xdf < uVar1)
    goto LAB_0000b65e;
  puVar2 = (undefined *)FUN_0000b708();
LAB_0000b65e:
  BYTE_ffffc8e5 = BYTE_ffffc8e5 - 1;
  if ((char)BYTE_ffffc8e5 < '\0') {
    pwVar6 = PTR_ffffc8e6 + 1;
    wVar3 = *PTR_ffffc8e6;
    if ((short)wVar3 < 0) {
      pwVar6 = WORD_ARRAY_0000b68a;
      wVar3 = 100;
    }
    BYTE_ffffc8e5 = (byte)wVar3;
    PTR_ffffc8e6 = (word *)((int)pwVar6 + 4);
    puVar2 = *(undefined **)pwVar6;
    DAT_ffffc8ea = puVar2;
  }
  return puVar2;
}

uint FUN_0000b444(void)

{
  uint uVar1;
  ushort unaff_D4w;
  ushort unaff_D5w;
  ushort unaff_D6w;
  int unaff_A3;

  if (unaff_D4w < unaff_D5w) {
    if (unaff_D5w <= (ushort)(unaff_D4w + (byte)(&DAT_ffffc8f1)[unaff_A3])) {
      uVar1 = FUN_0000b47e();
      return uVar1;
    }
  } else if (unaff_D4w <= unaff_D6w) {
    FUN_0000b47e();
  }
  return (uint)(byte)(&DAT_ffffc8f1)[unaff_A3];
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000b47e(void)

{
  ushort uVar1;
  short sVar2;
  uint uVar3;
  short in_D0w;
  ushort unaff_D4w;
  ushort unaff_D6w;
  short *unaff_A2;
  int unaff_A3;

  sVar2 = DAT_ffffc782 + (short)_DAT_ffffc73a;
  uVar3 = (uint)_DAT_ffffc73a >> 0x10;
  uVar1 = *(ushort *)(&DAT_ffffc8f2 + unaff_A3);
  do {
    *unaff_A2 =
        -((ushort)((uint)(uVar1 >> 4) *
                       (CONCAT22((short)uVar3, sVar2) + 0xf0000000U >> 0xc &
                        0xffff) *
                       0x100 >>
                   0x10) &
          0x1ff);
    unaff_D4w = unaff_D4w + 1;
    if (unaff_D6w < unaff_D4w) {
      return;
    }
    in_D0w = in_D0w + -1;
    unaff_A2 = unaff_A2 + 1;
  } while (in_D0w != -1);
  return;
}

uint FUN_0000b4b0(void)

{
  uint uVar1;
  ushort unaff_D4w;
  ushort unaff_D5w;
  ushort unaff_D6w;
  int unaff_A3;

  FUN_0000b4ee();
  if (unaff_D4w < unaff_D5w) {
    if (unaff_D5w <= (ushort)(unaff_D4w + (byte)(&DAT_ffffc8f1)[unaff_A3])) {
      uVar1 = FUN_0000b51c();
      return uVar1;
    }
  } else {
    if (unaff_D6w < unaff_D4w) {
      return (uint)(byte)(&DAT_ffffc8f1)[unaff_A3];
    }
    FUN_0000b51c();
  }
  return (uint)(byte)(&DAT_ffffc8f1)[unaff_A3];
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000b4ee(void)

{
  int unaff_A3;

  *(int *)(&DAT_ffffc974 + unaff_A3) =
      *(short *)(&DAT_ffffc8f2 + unaff_A3) * 0x100 +
      *(int *)(&DAT_ffffc974 + unaff_A3);
  *(ushort *)(&DAT_ffffca7c + unaff_A3) =
      *(short *)(&DAT_ffffc974 + unaff_A3) -
          (short)((uint)(CONCAT22((short)((uint)_DAT_ffffc73a >> 0x10),
                                  DAT_ffffc782 + (short)_DAT_ffffc73a) +
                         -0x10000000) >>
                  0x10) &
      0x1ff;
  return;
}

void FUN_0000b51c(void)

{
  undefined2 uVar1;
  short in_D0w;
  ushort unaff_D4w;
  ushort unaff_D6w;
  undefined2 *unaff_A2;
  int unaff_A3;

  uVar1 = *(undefined2 *)(&DAT_ffffca7c + unaff_A3);
  do {
    *unaff_A2 = uVar1;
    unaff_D4w = unaff_D4w + 1;
    if (unaff_D6w < unaff_D4w) {
      return;
    }
    in_D0w = in_D0w + -1;
    unaff_A2 = unaff_A2 + 1;
  } while (in_D0w != -1);
  return;
}

void FUN_0000b52e(void)

{
  DAT_ffffc8e4 = 0;
  BYTE_ffffc8e5 = 100;
  DAT_ffffc8ea = WORD_ARRAY_0000b592;
  PTR_ffffc8e6 = &WORD_0000b57e;
  return;
}

void FUN_0000b54a(void)

{
  word wVar1;
  undefined **ppuVar2;

  FUN_0000b5f8();
  BYTE_ffffc8e5 = BYTE_ffffc8e5 - 1;
  if ((char)BYTE_ffffc8e5 < '\0') {
    ppuVar2 = (undefined **)(PTR_ffffc8e6 + 1);
    wVar1 = *PTR_ffffc8e6;
    if ((short)wVar1 < 0) {
      ppuVar2 = &PTR_WORD_ARRAY_0000b57a;
      wVar1 = 100;
    }
    BYTE_ffffc8e5 = (byte)wVar1;
    PTR_ffffc8e6 = (word *)(ppuVar2 + 1);
    DAT_ffffc8ea = *ppuVar2;
  }
  return;
}

void FUN_0000b5f8(void)

{
  FUN_0000b62c();
  if (0xe < DAT_ffffc8e4) {
    DAT_ffffc8e4 = 0xff;
  }
  DAT_ffffc8e4 = DAT_ffffc8e4 + 1;
  return;
}

void FUN_0000b62c(void)

{
  short in_D0w;
  short sVar1;
  short *in_A0;
  short *unaff_A2;

  do {
    sVar1 = *in_A0;
    if (sVar1 < 0) {
      sVar1 = *DAT_ffffc8ea;
      in_A0 = DAT_ffffc8ea;
    }
    in_A0 = in_A0 + 1;
    *unaff_A2 = sVar1 + *unaff_A2;
    in_D0w = in_D0w + -1;
    unaff_A2 = unaff_A2 + 1;
  } while (in_D0w != -1);
  return;
}

uint FUN_0000b640(void)

{
  ushort uVar1;
  uint uVar2;
  word wVar3;
  word *pwVar4;
  int unaff_A4;

  uVar1 = *(short *)(&DAT_ffffc78e + unaff_A4) -
          *(short *)((int)&DAT_ffffc746 + unaff_A4);
  uVar2 = (uint)uVar1;
  if ((short)uVar1 < 0) {
    uVar2 = (uint)(ushort)(*(short *)(&DAT_ffffc790 + unaff_A4) + uVar1);
    if ((short)(*(short *)(&DAT_ffffc790 + unaff_A4) + uVar1) < 0)
      goto LAB_0000b65e;
  } else if (0xdf < uVar1)
    goto LAB_0000b65e;
  uVar2 = FUN_0000b708();
LAB_0000b65e:
  BYTE_ffffc8e5 = BYTE_ffffc8e5 - 1;
  if ((char)BYTE_ffffc8e5 < '\0') {
    pwVar4 = PTR_ffffc8e6 + 1;
    wVar3 = *PTR_ffffc8e6;
    if ((short)wVar3 < 0) {
      pwVar4 = WORD_ARRAY_0000b68a;
      wVar3 = 100;
    }
    BYTE_ffffc8e5 = (byte)wVar3;
    PTR_ffffc8e6 = (word *)((int)pwVar4 + 4);
    uVar2 = *(uint *)pwVar4;
    DAT_ffffc8ea = uVar2;
  }
  return uVar2;
}

void FUN_0000b708(void)

{
  FUN_0000b762();
  if (0xe < DAT_ffffc8e4) {
    DAT_ffffc8e4 = 0xff;
  }
  DAT_ffffc8e4 = DAT_ffffc8e4 + 1;
  return;
}

void FUN_0000b762(void)

{
  short in_D0w;
  short sVar1;
  short *in_A0;
  short *unaff_A2;

  do {
    sVar1 = *in_A0;
    if (sVar1 < 0) {
      sVar1 = *DAT_ffffc8ea;
      in_A0 = DAT_ffffc8ea;
    }
    in_A0 = in_A0 + 1;
    *unaff_A2 = sVar1 + *unaff_A2;
    in_D0w = in_D0w + -1;
    unaff_A2 = unaff_A2 + 1;
  } while (in_D0w != -1);
  return;
}

void FUN_0000b776(void)

{
  ushort uVar1;
  short unaff_D2w;
  int unaff_A4;

  uVar1 = *(short *)((int)&DAT_ffffc784 + unaff_A4) +
          *(short *)((int)&DAT_ffffc746 + unaff_A4);
  if (uVar1 != *(ushort *)(&DAT_ffffc754 + unaff_A4)) {
    if (uVar1 < *(ushort *)(&DAT_ffffc754 + unaff_A4)) {
      *(ushort *)(&DAT_ffffc760 + unaff_A4) = uVar1;
      *(undefined2 *)(&DAT_ffffc75e + unaff_A4) = 0x1000;
    } else {
      unaff_D2w = uVar1 + 0xe0;
      *(short *)(&DAT_ffffc760 + unaff_A4) = unaff_D2w;
      *(undefined2 *)(&DAT_ffffc75e + unaff_A4) = 0x1000;
    }
    FUN_0000b80e();
    FUN_0000b36e();
    FUN_0000b306();
    *(short *)(&DAT_ffffc778 + unaff_A4) = unaff_D2w;
    FUN_0000b3b4();
  }
  if (((&DAT_ffffc716)[unaff_A4] & 1) == 0) {
    FUN_0000afac();
    if (((&DAT_ffffc716)[unaff_A4] & 4) != 0) {
      FUN_0000b54a();
    }
    if (((&DAT_ffffc716)[unaff_A4] & 8) != 0) {
      FUN_0000b640();
    }
  } else {
    FUN_0000b3d2();
  }
  *(short *)(&DAT_ffffc752 + unaff_A4) =
      *(short *)((int)&DAT_ffffc782 + unaff_A4) +
      *(short *)((int)&DAT_ffffc73a + unaff_A4);
  *(short *)(&DAT_ffffc754 + unaff_A4) =
      *(short *)((int)&DAT_ffffc784 + unaff_A4) +
      *(short *)((int)&DAT_ffffc746 + unaff_A4);
  return;
}

void FUN_0000b80e(void)

{
  return;
}

void FUN_0000b83e(void)

{
  short sVar1;
  int iVar2;

  iVar2 = 0;
  sVar1 = 9;
  do {
    if (((char)(&DAT_ffffc8f0)[iVar2] < '\0') &&
        (((&DAT_ffffc8f0)[iVar2] & 2) != 0)) {
      *(undefined4 *)(&DAT_ffffc974 + iVar2) = 0;
    }
    iVar2 = iVar2 + 4;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return;
}

void FUN_0000b85e(undefined2 *param_1)

{
  ushort uVar1;
  ushort uVar2;
  short sVar3;
  short sVar4;
  undefined2 *puVar5;
  undefined2 *puVar6;
  int unaff_A3;

  uVar1 = DAT_ffffc8de;
  sVar4 = DAT_ffffc8e0 + -1;
  uVar2 = DAT_ffffc8dc;
  do {
    sVar3 = DAT_ffffc8e2 + -1;
    puVar5 = param_1;
    puVar6 =
        (undefined2 *)((int)(short)((uVar1 & 0xff0) >> 3) +
                       (int)(short)((uVar2 & 0xff0)
                                    << ((&DAT_ffffc717)[unaff_A3] & 0x3f)) +
                       *(int *)((int)&DAT_ffffc722 + unaff_A3));
    do {
      param_1 = puVar5 + 1;
      *puVar6 = *puVar5;
      sVar3 = sVar3 + -1;
      puVar5 = param_1;
      puVar6 = puVar6 + 1;
    } while (sVar3 != -1);
    uVar2 = uVar2 + 0x10;
    sVar4 = sVar4 + -1;
  } while (sVar4 != -1);
  if (DAT_ffffcbf5 != '\0') {
    FUN_0000b8aa();
  }
  return;
}

void FUN_0000b8aa(void)

{
  short sVar1;
  short sVar2;
  short sVar3;

  sVar3 = DAT_ffffc8e0 + -1;
  do {
    sVar2 = DAT_ffffc8e2 + -1;
    do {
      sVar1 = FUN_0000b8e4();
      if (sVar1 != 0) {
        FUN_0000b922();
      }
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
    sVar3 = sVar3 + -1;
  } while (sVar3 != -1);
  return;
}

undefined4 FUN_0000b8e4(void)

{
  short sVar1;
  undefined4 uVar2;
  ushort unaff_D4w;
  ushort unaff_D5w;
  int unaff_A3;

  uVar2 = 0;
  sVar1 = *(short *)((int)&DAT_ffffc782 + unaff_A3) +
          *(short *)((int)&DAT_ffffc73a + unaff_A3);
  if (((((ushort)(sVar1 - 0x10U) <= unaff_D4w) &&
        (unaff_D4w <= (ushort)(sVar1 + 0x110U))) &&
       (sVar1 = *(short *)((int)&DAT_ffffc784 + unaff_A3) +
                *(short *)((int)&DAT_ffffc746 + unaff_A3),
        (ushort)(sVar1 - 0x10U) <= unaff_D5w)) &&
      (unaff_D5w <= (ushort)(sVar1 + 0xf0U))) {
    uVar2 = 1;
  }
  return uVar2;
}

void FUN_0000b922(void)

{
  void *vram_dst;
  short sVar1;
  ushort extraout_D0w;
  ushort extraout_D0w_00;
  short sVar2;
  ushort unaff_D4w;
  ushort unaff_D5w;
  int unaff_A3;

  sVar1 = (*(ushort *)((int)(short)(((unaff_D5w & 0xff0)
                                     << ((&DAT_ffffc717)[unaff_A3] & 0x3f)) +
                                    ((unaff_D4w & 0xff0) >> 3)) +
                       *(int *)((int)&DAT_ffffc722 + unaff_A3)) &
           0x3ff)
          << 3;
  if ((short)unaff_A3 == 0) {
    sVar2 = -0x4000;
  } else {
    sVar2 = -0x2000;
  }
  vram_dst = (void *)((unaff_D5w - 0x1000 & 0xf8) * 0x10 +
                      ((unaff_D4w - 0x1000 & 0x1f8) >> 2) + sVar2);
  vdp_set_vram_write_addr(vram_dst);
  VDP_DATA = extraout_D0w | *(ushort *)(&DAT_ffff4000 + sVar1);
  VDP_DATA = extraout_D0w | *(ushort *)(&DAT_ffff4002 + sVar1);
  vdp_set_vram_write_addr((void *)((short)vram_dst + 0x80));
  VDP_DATA = extraout_D0w_00 | *(ushort *)(&DAT_ffff4004 + sVar1);
  VDP_DATA = extraout_D0w_00 | *(ushort *)(&DAT_ffff4006 + sVar1);
  return;
}

// #8bxx writes xx to the Mode Set 3 register, but only the 4 lower bits are
// valid yet here only the 4 upper ones are used.
//
// It seems it's only called with the param being 0, which loads the first and
// only valid value of the table, setting full scroll and no interrupt.
//
// https://wiki.megadrive.org/index.php?title=VDP_Ports#Write_1_-_Setting_Register
// https://wiki.megadrive.org/index.php?title=VDP_Registers#0xB_-_Mode_set_3
//
// This function likely shouldn't return anything.

word vdp_set_mode_set_3(word must_be_zero)

{
  vdp_reg_t vdp_reg;

  vdp_reg =
      *(vdp_reg_t *)((int)&vdp_reg_t_0000b9cc + (int)(short)(must_be_zero * 2));
  VDP_CTRL = (union2_t)vdp_reg;
  return vdp_reg;
}

void FUN_0000b9d8(void)

{
  short sVar1;
  word *pwVar2;
  undefined4 *puVar3;

  sVar1 = 0x7f;
  pwVar2 = &vdp_hblank_effect_asha_p;
  do {
    pwVar2[0] = 0;
    pwVar2[1] = 0;
    sVar1 = sVar1 + -1;
    pwVar2 = pwVar2 + 2;
  } while (sVar1 != -1);
  sVar1 = 0x7f;
  puVar3 = (undefined4 *)&vdp_hblank_effect_pepelogoo_p;
  do {
    *puVar3 = 0;
    sVar1 = sVar1 + -1;
    puVar3 = puVar3 + 1;
  } while (sVar1 != -1);
  sVar1 = 9;
  puVar3 = &vdp_gfx_ptr_5;
  do {
    *puVar3 = 0;
    sVar1 = sVar1 + -1;
    puVar3 = puVar3 + 1;
  } while (sVar1 != -1);
  sVar1 = 9;
  puVar3 = (undefined4 *)&vdp_gfx_ptr_6;
  do {
    *puVar3 = 0;
    sVar1 = sVar1 + -1;
    puVar3 = puVar3 + 1;
  } while (sVar1 != -1);
  vdp_related_to_display_asha = 0xf;
  return;
}

void FUN_0000ba1a(void)

{
  vdp_set_mode_set_3(0);
  FUN_0000b9d8();
  return;
}

void vdp_write_something_to_vram(void)

{
  short i;

  vdp_set_vram_write_addr((void *)0xc000);
  i = 0x7ff;
  do {
    VDP_DATA = 0x780;
    i = i + -1;
  } while (i != -1);
  vdp_set_vram_write_addr((void *)0xe000);
  i = 0x7ff;
  do {
    VDP_DATA = 0x780;
    i = i + -1;
  } while (i != -1);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000ba58(void)

{
  _WORD_ffffcb00 = 0;
  DAT_ffffcb04 = 0;
  FUN_0000ba1a();
  DAT_ffffcb08 = 0;
  DAT_ffffcb0a = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address
// FIXME Where is it called?

void FUN_0000ba6e(void)

{
  int iVar1;
  ushort uVar2;
  ushort uVar3;

  // #b4? Like the special text parsing command value? Is this related to text
  // parsing?
  _WORD_ffffcb00 = _WORD_ffffcb00 + 0xb400;
  iVar1 = _WORD_ffffcb00;
  uVar3 = DAT_ffffcb0a + 1;
  DAT_ffffcb0a = uVar3;
  if (uVar3 < 0x280) {
    for (uVar2 = uVar3 & 0xfffc; 0xb3 < uVar2; uVar2 = uVar2 - 0xb4) {
    }
    DAT_ffffcb04 = *(uint *)((int)smooth_curve_sine_like + (int)(short)uVar2);
    vdp_gfx_ptr_5._0_2_ =
        (ushort)(*(uint *)((int)smooth_curve_sine_like + (int)(short)uVar2) >>
                 0xb);
    for (; 0x167 < uVar3; uVar3 = uVar3 - 0xb4) {
    }
    if (0xb3 < uVar3) {
      vdp_gfx_ptr_5._0_2_ = ~vdp_gfx_ptr_5._0_2_;
    }
    WORD_ffffcb00 = (word)((uint)_WORD_ffffcb00 >> 0x10);
    vdp_hblank_effect_asha_p = WORD_ffffcb00;
    vdp_related_to_display_asha = 5;
    _WORD_ffffcb00 = iVar1;
    return;
  }
  DAT_ffffcb08 = 0xff;
  return;
}

void vdp_clear_something(void)

{
  vdp_related_to_display_asha_1 = 0;
  vdp_related_to_display_pepelogoo_1 = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000bba2(void)

{
  char in_D0b;
  undefined2 in_D1w;
  uint unaff_D2;

  if (in_D0b != '\0') {
    if ((unaff_D2 & 1) != 0) {
      vdp_related_to_display_asha_1 = 0xff;
      _component_hblank_related = 0;
      _component_unknown_3 = in_D1w;
      _DAT_ffffcb14 = in_D1w;
    }
    if ((unaff_D2 & 2) != 0) {
      vdp_related_to_display_pepelogoo_1 = 0xff;
      _DAT_ffffcb1a = 0;
      _component_unknown_3 = in_D1w;
      _DAT_ffffcb14 = in_D1w;
    }
    return;
  }
  if ((unaff_D2 & 1) != 0) {
    vdp_related_to_display_asha_1 = 0;
    component_unknown_1 = 0;
    _component_hblank_related = 0;
  }
  if ((unaff_D2 & 2) != 0) {
    vdp_related_to_display_pepelogoo_1 = 0;
    DAT_ffffcb11 = 0;
    _DAT_ffffcb1a = 0;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000bbd2(void)

{
  undefined2 in_D1w;
  uint unaff_D2;

  if ((unaff_D2 & 1) != 0) {
    vdp_related_to_display_asha_1 = 0xff;
    _component_hblank_related = 0;
    _component_unknown_3 = in_D1w;
    _DAT_ffffcb14 = in_D1w;
  }
  if ((unaff_D2 & 2) != 0) {
    vdp_related_to_display_pepelogoo_1 = 0xff;
    _DAT_ffffcb1a = 0;
    _component_unknown_3 = in_D1w;
    _DAT_ffffcb14 = in_D1w;
  }
  return;
}

void vdp_set_some_hblank_effect(void)

{
  vdp_prepare_some_hblank_effect_1();
  if (vdp_related_to_display_asha_1 != '\0') {
    vdp_prepare_some_hblank_effect(ENTITY_ID_ASHA, &vdp_hblank_effect_asha_p);
    vdp_related_to_display_asha = vdp_related_to_display_asha | 3;
  }
  if (vdp_related_to_display_pepelogoo_1 != '\0') {
    vdp_prepare_some_hblank_effect(ENTITY_ID_PEPELOGOO,
                                   &vdp_hblank_effect_pepelogoo_p);
    vdp_related_to_hblank_y_pos_pepelogoo.b[0] =
        vdp_related_to_hblank_y_pos_pepelogoo.b[0] | 3;
  }
  return;
}

void vdp_prepare_some_hblank_effect(entity_id_t self, word *dst)

{
  word *dst_2;

  if (*(short *)(&component_unknown_3 + self) == 0) {
    // Doesn't touch A0.
    FUN_0000bc56(self);
    dst = dst_2;
  } else {
    *(short *)(&component_unknown_3 + self) =
        *(short *)(&component_unknown_3 + self) + -1;
  }
  vdp_prepare_some_hblank_effect_inner(self, dst);
  VDP_CTRL = VDP_REG_MODE_SET_3_PER_LINE_H_SCROLL;
  return;
}

void FUN_0000bc56(entity_id_t self)

{
  short sVar1;

  if ((&component_unknown_1)[self] == '\0') {
    *(short *)(&component_hblank_related + self) =
        *(short *)(&component_hblank_related + self) + 1;
    if (0xf < *(ushort *)(&component_hblank_related + self)) {
      (&component_unknown_1)[self] = 0xff;
    }
  } else {
    sVar1 = *(short *)(&component_hblank_related + self) + -1;
    *(short *)(&component_hblank_related + self) = sVar1;
    if (sVar1 == 0) {
      (&component_unknown_1)[self] = 0;
    }
  }
  return;
}

// This copies 256 words from #bca4 (looping through it) to the given
// destination.

void vdp_prepare_some_hblank_effect_inner(entity_id_t self, word *dst)

{
  word value;
  short i;
  word *i_p;

  i = 0xff;
  i_p =
      (word *)((int)vdp_prepare_some_hblank_effect_data +
               (int)(short)(*(short *)(&component_hblank_related + self) << 1));
  do {
    value = *i_p;
    // Loop around the table.
    if (value == 0xffff) {
      i_p = vdp_prepare_some_hblank_effect_data;
      value = 0;
    }
    i_p = i_p + 1;
    *dst = value + *dst;
    i = i + -1;
    dst = dst + 1;
  } while (i != -1);
  return;
}

// Copies the first data from a table onto its 256 words?

void vdp_prepare_some_hblank_effect_1(void)

{
  short i;
  word *hblank_asha_p;
  undefined2 *hblank_pepelogoo_p;
  word hblank_asha;
  undefined2 hblank_pepelogoo;

  hblank_pepelogoo = vdp_hblank_effect_pepelogoo_p;
  hblank_asha = vdp_hblank_effect_asha_p;
  i = 0xff;
  hblank_asha_p = &vdp_hblank_effect_asha_p;
  hblank_pepelogoo_p = &vdp_hblank_effect_pepelogoo_p;
  do {
    *hblank_asha_p = hblank_asha;
    *hblank_pepelogoo_p = hblank_pepelogoo;
    i = i + -1;
    hblank_asha_p = hblank_asha_p + 1;
    hblank_pepelogoo_p = hblank_pepelogoo_p + 1;
  } while (i != -1);
  return;
}

void FUN_0000bce8(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  undefined8 uVar1;

  DAT_ffffcc56 = 0;
  uVar1 = FUN_0000140c();
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  &stack0xfffffffc,
                  (long)((ulonglong)uVar1 >> 0x20),
                  (long)uVar1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  FUN_0000c6fe();
  DAT_ffff97e5 = 0;
  DAT_ffffcbb2 = 0;
  DAT_ffffcbb4 = 0;
  script_ctx_bf_0e_arg = 0;
  return;
}

void FUN_0000bd26(void)

{
  FUN_0000c168();
  DAT_ffffcc93 = 0;
  return;
}

void FUN_0000bd48(void)

{
  if (DAT_ffff96c1 == '\0') {
    DAT_ffff96c1 = 0;
    FUN_0002c10e();
    DAT_ffffcc93 = 0;
    FUN_0000bdd0();
    return;
  }
  DAT_ffffcc93 = 0;
  FUN_0000be24(0);
  return;
}

void sram_unk_3(void)

{
  undefined1 uVar1;

  DAT_ffffcbb0 = '\0';
  uVar1 = 1;
  sram_unk_4();
  sram_unk_5();
  if (!(bool)uVar1) {
    uVar1 = 0;
    sram_unk_4();
    sram_unk_5();
    if (!(bool)uVar1)
      goto LAB_0000bdac;
    sram_unk_2(0);
  }
  DAT_ffffcbb0 = DAT_ffffcbb0 + '\x01';
LAB_0000bdac:
  uVar1 = 0;
  sram_unk_4();
  sram_unk_5();
  if (!(bool)uVar1) {
    uVar1 = 0;
    sram_unk_4();
    sram_unk_5();
    if (!(bool)uVar1) {
      return;
    }
    sram_unk_2(1);
  }
  DAT_ffffcbb0 = DAT_ffffcbb0 + '\x02';
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000bdd0(void)

{
  char cVar1;
  short sVar2;
  char *pcVar3;
  char *pcVar4;
  char *pcVar5;

  DAT_ffffcb30 = 0;
  DAT_ffffcb34 = 0;
  DAT_ffffcb36 = 0;
  DAT_ffffcb37 = 0xff;
  _DAT_ffffcb38 = 0x1010100;
  DAT_ffffcb3c = 0;
  DAT_ffffcb3d = 7;
  sVar2 = 10;
  pcVar3 = (char *)((int)&LONG_0000bde2 + 2);
  pcVar4 = &DAT_ffffcb3e;
  while (true) {
    cVar1 = *pcVar3;
    if (cVar1 < '\0')
      break;
    *pcVar4 = cVar1;
    sVar2 = sVar2 + -1;
    pcVar3 = pcVar3 + 1;
    pcVar4 = pcVar4 + 1;
  }
  while (sVar2 = sVar2 + -1, sVar2 != -1) {
    *pcVar4 = cVar1;
    pcVar4 = pcVar4 + 1;
  }
  sVar2 = 0x5f;
  do {
    pcVar5 = pcVar4;
    *pcVar5 = '\0';
    sVar2 = sVar2 + -1;
    pcVar4 = pcVar5 + 1;
  } while (sVar2 != -1);
  pcVar5[1] = -1;
  pcVar5[2] = -1;
  pcVar5[3] = pcVar3[1];
  pcVar5[4] = '\0';
  pcVar5[5] = -0x1b;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000bde6(word *param_1)

{
  char cVar1;
  short sVar2;
  word *pwVar3;
  char *pcVar4;
  char *pcVar5;

  DAT_ffffcb30 = *(undefined4 *)param_1;
  DAT_ffffcb34 = param_1[2];
  DAT_ffffcb36 = *(undefined1 *)(param_1 + 3);
  DAT_ffffcb37 = *(undefined1 *)((int)param_1 + 7);
  _DAT_ffffcb38 = *(undefined4 *)(param_1 + 4);
  DAT_ffffcb3c = *(undefined1 *)(param_1 + 6);
  DAT_ffffcb3d = *(undefined1 *)((int)param_1 + 0xd);
  sVar2 = 10;
  pwVar3 = param_1 + 7;
  pcVar4 = &DAT_ffffcb3e;
  while (true) {
    cVar1 = *(char *)pwVar3;
    if (cVar1 < '\0')
      break;
    *pcVar4 = cVar1;
    sVar2 = sVar2 + -1;
    pwVar3 = (word *)((int)pwVar3 + 1);
    pcVar4 = pcVar4 + 1;
  }
  while (sVar2 = sVar2 + -1, sVar2 != -1) {
    *pcVar4 = cVar1;
    pcVar4 = pcVar4 + 1;
  }
  sVar2 = 0x5f;
  do {
    pcVar5 = pcVar4;
    *pcVar5 = '\0';
    sVar2 = sVar2 + -1;
    pcVar4 = pcVar5 + 1;
  } while (sVar2 != -1);
  pcVar5[1] = -1;
  pcVar5[2] = -1;
  pcVar5[3] = *(char *)((int)pwVar3 + 1);
  pcVar5[4] = '\0';
  pcVar5[5] = -0x1b;
  return;
}

void FUN_0000be24(word param_1)

{
  short sVar1;
  undefined1 *extraout_A0;
  undefined1 *puVar2;
  undefined1 *puVar3;

  FUN_0000bde6((word *)((int)&WORD_0000be3e +
                        (int)*(short *)((int)&WORD_0000be3e +
                                        (int)(short)(param_1 * 2))));
  sVar1 = 0x5f;
  puVar2 = extraout_A0;
  puVar3 = (undefined1 *)0xffffcb48;
  do {
    *puVar3 = *puVar2;
    sVar1 = sVar1 + -1;
    puVar2 = puVar2 + 1;
    puVar3 = puVar3 + 1;
  } while (sVar1 != -1);
  return;
}

undefined4 FUN_0000c168(void)

{
  byte bVar1;
  ushort in_D0w;
  undefined4 uVar2;
  short sVar4;
  uint uVar3;
  char cVar5;
  short *extraout_A0;
  item_t *piVar6;
  item_t *piVar8;
  char *pcVar9;
  bool bVar10;
  undefined1 uVar11;
  item_t *piVar7;

  uVar11 = (in_D0w & 1) == 0;
  sram_unk_4();
  uVar2 = sram_unk_5();
  if ((bool)uVar11) {
    return uVar2;
  }
  sram_unk_4();
  sVar4 = FUN_0000c3c4((byte *)((int)&DAT_ffffcb30 + 1));
  if (*extraout_A0 != sVar4) {
    return 0xffffffff;
  }
  life_drops = (word)(DAT_ffffcb30._1_1_ >> 4);
  gold = CONCAT12(DAT_ffffcb30._1_1_, DAT_ffffcb30._2_2_) & 0xfffff;
  SAVE_POINT = DAT_ffffcb34;
  blue_hearts = (word)DAT_ffffcb36;
  script_ctx_bf_0e_arg = DAT_ffffcb37;
  OWNED_EQUIPMENT_FLAGS[0] = DAT_ffffcb38;
  OWNED_EQUIPMENT_FLAGS[1] = DAT_ffffcb39;
  OWNED_EQUIPMENT_FLAGS[2] = DAT_ffffcb3a;
  OWNED_EQUIPMENT_FLAGS[3] = DAT_ffffcb3b;
  OWNED_SHIELD = DAT_ffffcb3c & 0xf;
  OWNED_SWORD = DAT_ffffcb3c >> 4;
  OWNED_HEALING_MEDICINE_COUNT = -((DAT_ffffcb3d & 8) != 0);
  DAT_ffffde27 = DAT_ffffcb3d & 7;
  OWNED_ARMOR = DAT_ffffcb3d >> 4;
  if (DAT_ffffde27 == 7) {
    DAT_ffffde27 = 0xff;
  }
  sVar4 = 9;
  piVar7 = &DAT_ffffcb3e;
  piVar8 = OWNED_INVENTORY;
  do {
    piVar6 = piVar7 + 1;
    *piVar8 = *piVar7;
    sVar4 = sVar4 + -1;
    piVar7 = piVar6;
    piVar8 = piVar8 + 1;
  } while (sVar4 != -1);
  sVar4 = 0x5f;
  piVar7 = &DAT_ffffccca;
  do {
    piVar8 = piVar6;
    *piVar7 = *piVar8;
    sVar4 = sVar4 + -1;
    piVar6 = piVar8 + 1;
    piVar7 = piVar7 + 1;
  } while (sVar4 != -1);
  uVar3 = (uint)(ushort) * (undefined2 *)(piVar8 + 1);
  sVar4 = 4;
  pcVar9 = &DAT_ffffde46;
  do {
    cVar5 = -1;
    bVar1 = (byte)uVar3 & 7;
    if (bVar1 != 7) {
      cVar5 = bVar1 + 0x25;
    }
    *pcVar9 = cVar5;
    uVar3 = uVar3 >> 3;
    sVar4 = sVar4 + -1;
    pcVar9 = pcVar9 + 1;
  } while (sVar4 != -1);
  total_hearts = (word)piVar8[3];
  DAT_ffffde29 = piVar8[4];
  if (DAT_ffffde29 == 0xe5) {
    DAT_ffffde29 = ITEM_ASHA_SWORD;
  }
  if ((((((DAT_ffffde29 < 0x65) && (piVar8[5] == 0xe5)) &&
         ((uint)gold < &UNK_000f4240)) &&
        ((blue_hearts < 0x10 && (life_drops < 10)))) &&
       ((OWNED_SWORD < ITEM_PLAIN_SHIELD &&
         (((OWNED_EQUIPMENT_FLAGS[0] & '\x01' << (OWNED_SWORD & 7)) != 0 &&
           (OWNED_SHIELD < ITEM_PLAIN_SHIELD)))))) &&
      ((OWNED_EQUIPMENT_FLAGS[1] & '\x01' << (OWNED_SHIELD & 7)) != 0)) {
    OWNED_SHIELD = OWNED_SHIELD + ITEM_PLAIN_SHIELD;
    if ((OWNED_ARMOR < ITEM_PLAIN_SHIELD) &&
        ((OWNED_EQUIPMENT_FLAGS[2] & '\x01' << (OWNED_ARMOR & 7)) != 0)) {
      OWNED_ARMOR = OWNED_ARMOR + ITEM_TRAVELER_ARMOR;
      if (-1 < (char)DAT_ffffde27) {
        if ((OWNED_EQUIPMENT_FLAGS[3] & '\x01' << (DAT_ffffde27 & 7)) == 0) {
          return 0xffffffff;
        }
        DAT_ffffde27 = DAT_ffffde27 + 0x18;
      }
      bVar10 = SAVE_POINT < 0;
      FUN_00029630(piVar8 + 6);
      if (!bVar10) {
        return 0;
      }
    }
  }
  return 0xffffffff;
}

void FUN_0000c188(void)

{
  uint in_D0;

  DAT_ffffcbb0 = DAT_ffffcbb0 | '\x01' << (in_D0 & 7);
  FUN_0000c308();
  FUN_0000c3ee();
  FUN_0000c3ee();
  return;
}

undefined4 sram_unk_5(void)

{
  byte bVar1;
  short i;
  uint uVar2;
  char cVar3;
  short *extraout_A0;
  item_t *piVar4;
  item_t *piVar6;
  char *pcVar7;
  bool bVar8;
  item_t *piVar5;

  i = FUN_0000c3c4((byte *)((int)&DAT_ffffcb30 + 1));
  if (*extraout_A0 != i) {
    return 0xffffffff;
  }
  life_drops = (word)(DAT_ffffcb30._1_1_ >> 4);
  gold = CONCAT12(DAT_ffffcb30._1_1_, DAT_ffffcb30._2_2_) & 0xfffff;
  SAVE_POINT = DAT_ffffcb34;
  blue_hearts = (word)DAT_ffffcb36;
  script_ctx_bf_0e_arg = DAT_ffffcb37;
  OWNED_EQUIPMENT_FLAGS[0] = DAT_ffffcb38;
  OWNED_EQUIPMENT_FLAGS[1] = DAT_ffffcb39;
  OWNED_EQUIPMENT_FLAGS[2] = DAT_ffffcb3a;
  OWNED_EQUIPMENT_FLAGS[3] = DAT_ffffcb3b;
  OWNED_SHIELD = DAT_ffffcb3c & 0xf;
  OWNED_SWORD = DAT_ffffcb3c >> 4;
  OWNED_HEALING_MEDICINE_COUNT = -((DAT_ffffcb3d & 8) != 0);
  DAT_ffffde27 = DAT_ffffcb3d & 7;
  OWNED_ARMOR = DAT_ffffcb3d >> 4;
  if (DAT_ffffde27 == 7) {
    DAT_ffffde27 = 0xff;
  }
  i = 9;
  piVar5 = &DAT_ffffcb3e;
  piVar6 = OWNED_INVENTORY;
  do {
    piVar4 = piVar5 + 1;
    *piVar6 = *piVar5;
    i = i + -1;
    piVar5 = piVar4;
    piVar6 = piVar6 + 1;
  } while (i != -1);
  i = 0x5f;
  piVar5 = &DAT_ffffccca;
  do {
    piVar6 = piVar4;
    *piVar5 = *piVar6;
    i = i + -1;
    piVar4 = piVar6 + 1;
    piVar5 = piVar5 + 1;
  } while (i != -1);
  uVar2 = (uint)(ushort) * (undefined2 *)(piVar6 + 1);
  i = 4;
  pcVar7 = &DAT_ffffde46;
  do {
    cVar3 = -1;
    bVar1 = (byte)uVar2 & 7;
    if (bVar1 != 7) {
      cVar3 = bVar1 + 0x25;
    }
    *pcVar7 = cVar3;
    uVar2 = uVar2 >> 3;
    i = i + -1;
    pcVar7 = pcVar7 + 1;
  } while (i != -1);
  total_hearts = (word)piVar6[3];
  DAT_ffffde29 = piVar6[4];
  if (DAT_ffffde29 == 0xe5) {
    DAT_ffffde29 = ITEM_ASHA_SWORD;
  }
  if ((((((DAT_ffffde29 < 0x65) && (piVar6[5] == 0xe5)) &&
         ((uint)gold < &UNK_000f4240)) &&
        ((blue_hearts < 0x10 && (life_drops < 10)))) &&
       ((OWNED_SWORD < ITEM_PLAIN_SHIELD &&
         (((OWNED_EQUIPMENT_FLAGS[0] & '\x01' << (OWNED_SWORD & 7)) != 0 &&
           (OWNED_SHIELD < ITEM_PLAIN_SHIELD)))))) &&
      ((OWNED_EQUIPMENT_FLAGS[1] & '\x01' << (OWNED_SHIELD & 7)) != 0)) {
    OWNED_SHIELD = OWNED_SHIELD + ITEM_PLAIN_SHIELD;
    if ((OWNED_ARMOR < ITEM_PLAIN_SHIELD) &&
        ((OWNED_EQUIPMENT_FLAGS[2] & '\x01' << (OWNED_ARMOR & 7)) != 0)) {
      OWNED_ARMOR = OWNED_ARMOR + ITEM_TRAVELER_ARMOR;
      if (-1 < (char)DAT_ffffde27) {
        if ((OWNED_EQUIPMENT_FLAGS[3] & '\x01' << (DAT_ffffde27 & 7)) == 0) {
          return 0xffffffff;
        }
        DAT_ffffde27 = DAT_ffffde27 + 0x18;
      }
      bVar8 = SAVE_POINT < 0;
      FUN_00029630(piVar6 + 6);
      if (!bVar8) {
        return 0;
      }
    }
  }
  return 0xffffffff;
}

undefined4 FUN_0000c1b6(void)

{
  byte bVar1;
  short i;
  uint uVar2;
  char cVar3;
  item_t *piVar4;
  item_t *piVar6;
  char *pcVar7;
  bool bVar8;
  item_t *piVar5;

  life_drops = (word)(DAT_ffffcb30._1_1_ >> 4);
  gold = CONCAT12(DAT_ffffcb30._1_1_, DAT_ffffcb30._2_2_) & 0xfffff;
  SAVE_POINT = DAT_ffffcb34;
  blue_hearts = (word)DAT_ffffcb36;
  script_ctx_bf_0e_arg = DAT_ffffcb37;
  OWNED_EQUIPMENT_FLAGS[0] = DAT_ffffcb38;
  OWNED_EQUIPMENT_FLAGS[1] = DAT_ffffcb39;
  OWNED_EQUIPMENT_FLAGS[2] = DAT_ffffcb3a;
  OWNED_EQUIPMENT_FLAGS[3] = DAT_ffffcb3b;
  OWNED_SHIELD = DAT_ffffcb3c & 0xf;
  OWNED_SWORD = DAT_ffffcb3c >> 4;
  OWNED_HEALING_MEDICINE_COUNT = -((DAT_ffffcb3d & 8) != 0);
  DAT_ffffde27 = DAT_ffffcb3d & 7;
  OWNED_ARMOR = DAT_ffffcb3d >> 4;
  if (DAT_ffffde27 == 7) {
    DAT_ffffde27 = 0xff;
  }
  i = 9;
  piVar5 = &DAT_ffffcb3e;
  piVar6 = OWNED_INVENTORY;
  do {
    piVar4 = piVar5 + 1;
    *piVar6 = *piVar5;
    i = i + -1;
    piVar5 = piVar4;
    piVar6 = piVar6 + 1;
  } while (i != -1);
  i = 0x5f;
  piVar5 = &DAT_ffffccca;
  do {
    piVar6 = piVar4;
    *piVar5 = *piVar6;
    i = i + -1;
    piVar4 = piVar6 + 1;
    piVar5 = piVar5 + 1;
  } while (i != -1);
  uVar2 = (uint)(ushort) * (undefined2 *)(piVar6 + 1);
  i = 4;
  pcVar7 = &DAT_ffffde46;
  do {
    cVar3 = -1;
    bVar1 = (byte)uVar2 & 7;
    if (bVar1 != 7) {
      cVar3 = bVar1 + 0x25;
    }
    *pcVar7 = cVar3;
    uVar2 = uVar2 >> 3;
    i = i + -1;
    pcVar7 = pcVar7 + 1;
  } while (i != -1);
  total_hearts = (word)piVar6[3];
  DAT_ffffde29 = piVar6[4];
  if (DAT_ffffde29 == 0xe5) {
    DAT_ffffde29 = ITEM_ASHA_SWORD;
  }
  if ((((((DAT_ffffde29 < 0x65) && (piVar6[5] == 0xe5)) &&
         ((uint)gold < &UNK_000f4240)) &&
        ((blue_hearts < 0x10 && (life_drops < 10)))) &&
       ((OWNED_SWORD < ITEM_PLAIN_SHIELD &&
         (((OWNED_EQUIPMENT_FLAGS[0] & '\x01' << (OWNED_SWORD & 7)) != 0 &&
           (OWNED_SHIELD < ITEM_PLAIN_SHIELD)))))) &&
      ((OWNED_EQUIPMENT_FLAGS[1] & '\x01' << (OWNED_SHIELD & 7)) != 0)) {
    OWNED_SHIELD = OWNED_SHIELD + ITEM_PLAIN_SHIELD;
    if ((OWNED_ARMOR < ITEM_PLAIN_SHIELD) &&
        ((OWNED_EQUIPMENT_FLAGS[2] & '\x01' << (OWNED_ARMOR & 7)) != 0)) {
      OWNED_ARMOR = OWNED_ARMOR + ITEM_TRAVELER_ARMOR;
      if (-1 < (char)DAT_ffffde27) {
        if ((OWNED_EQUIPMENT_FLAGS[3] & '\x01' << (DAT_ffffde27 & 7)) == 0) {
          return 0xffffffff;
        }
        DAT_ffffde27 = DAT_ffffde27 + 0x18;
      }
      bVar8 = SAVE_POINT < 0;
      FUN_00029630(piVar6 + 6);
      if (!bVar8) {
        return 0;
      }
    }
  }
  return 0xffffffff;
}

void FUN_0000c308(void)

{
  char cVar1;
  uint3 uVar2;
  short i;
  uint uVar3;
  ushort j;
  uint uVar4;
  item_t *piVar5;
  undefined1 *extraout_A0;
  item_t *piVar7;
  char *pcVar8;
  item_t *piVar6;

  DAT_ffffcb30._0_1_ = 0;
  DAT_ffffcb30._1_1_ = gold._1_1_ | (char)life_drops << 4;
  DAT_ffffcb30._2_2_ = gold._2_2_;
  DAT_ffffcb34 = SAVE_POINT;
  DAT_ffffcb36 = (undefined1)blue_hearts;
  DAT_ffffcb37 = script_ctx_bf_0e_arg;
  DAT_ffffcb38 = OWNED_EQUIPMENT_FLAGS[0];
  DAT_ffffcb39 = OWNED_EQUIPMENT_FLAGS[1];
  DAT_ffffcb3a = OWNED_EQUIPMENT_FLAGS[2];
  DAT_ffffcb3b = OWNED_EQUIPMENT_FLAGS[3];
  DAT_ffffcb3c = OWNED_SHIELD - ITEM_PLAIN_SHIELD | OWNED_SWORD << 4;
  DAT_ffffcb3d = DAT_ffffde27 & 7 | OWNED_ARMOR << 4;
  if (OWNED_HEALING_MEDICINE_COUNT != '\0') {
    DAT_ffffcb3d = DAT_ffffcb3d + 8;
  }
  i = 9;
  piVar6 = &DAT_ffffcb3e;
  piVar7 = OWNED_INVENTORY;
  do {
    piVar5 = piVar6 + 1;
    *piVar6 = *piVar7;
    i = i + -1;
    piVar6 = piVar5;
    piVar7 = piVar7 + 1;
  } while (i != -1);
  uVar3 = 0x5f;
  piVar6 = &DAT_ffffccca;
  do {
    piVar7 = piVar5;
    *piVar7 = *piVar6;
    j = (short)uVar3 - 1;
    uVar3 = (uint)j;
    piVar5 = piVar7 + 1;
    piVar6 = piVar6 + 1;
  } while (j != 0xffff);
  i = 4;
  pcVar8 = &DAT_ffffde46;
  do {
    uVar2 = (uint3)((uVar3 << 0x10) >> 8);
    cVar1 = *pcVar8;
    if (-1 < cVar1) {
      cVar1 = cVar1 + -0x25;
    }
    uVar4 = CONCAT31(uVar2, cVar1) << 0x10 | (uint)(uVar2 >> 8);
    uVar3 = uVar4 >> 3;
    i = i + -1;
    pcVar8 = pcVar8 + 1;
  } while (i != -1);
  uVar3 = uVar4 >> 4 & 0x7fff;
  piVar7[2] = (item_t)uVar3;
  piVar7[1] = (item_t)(uVar3 >> 8);
  piVar7[3] = (item_t)total_hearts;
  piVar7[4] = DAT_ffffde29;
  piVar7[5] = 0xe5;
  i = FUN_0000c3c4(piVar7 + -0x76);
  extraout_A0[1] = (char)i;
  *extraout_A0 = (char)((ushort)i >> 8);
  extraout_A0[2] = 0;
  return;
}

short FUN_0000c3c4(byte *param_1)

{
  short sVar1;
  char i;
  byte offset;

  sVar1 = 0;
  i = '|';
  offset = 0;
  do {
    offset = *param_1 + offset;
    sVar1 = (ushort)offset + sVar1;
    i = i + -1;
    param_1 = param_1 + 1;
  } while (i != '\0');
  return sVar1 + 0x1324;
}

void sram_unk_4(void)

{
  undefined4 in_D0;
  short i;
  byte *pbVar1;
  undefined4 *puVar2;
  byte *pbVar3;
  undefined1 *puVar4;

  pbVar3 = sram_get_save_offset_likely(in_D0);
  i = 0x7f;
  pbVar1 = (byte *)&DAT_ffffcb30;
  do {
    *pbVar1 = *pbVar3;
    pbVar3 = pbVar3 + 2;
    i = i + -1;
    pbVar1 = pbVar1 + 1;
  } while (i != -1);
  i = 0x7f;
  puVar2 = &DAT_ffffcb30;
  puVar4 = &DAT_ffffff00;
  do {
    *puVar4 = *(undefined1 *)puVar2;
    i = i + -1;
    puVar2 = (undefined4 *)((int)puVar2 + 1);
    puVar4 = puVar4 + 1;
  } while (i != -1);
  return;
}

void FUN_0000c3ee(void)

{
  undefined4 in_D0;
  short i;
  byte *pbVar1;
  undefined4 *puVar2;
  byte *pbVar3;
  undefined1 *puVar4;

  pbVar3 = sram_get_save_offset_likely(in_D0);
  i = 0x7f;
  pbVar1 = (byte *)&DAT_ffffcb30;
  do {
    *pbVar3 = *pbVar1;
    pbVar3 = pbVar3 + 2;
    i = i + -1;
    pbVar1 = pbVar1 + 1;
  } while (i != -1);
  i = 0x7f;
  puVar2 = &DAT_ffffcb30;
  puVar4 = &DAT_ffffff00;
  do {
    *puVar4 = *(undefined1 *)puVar2;
    i = i + -1;
    puVar2 = (undefined4 *)((int)puVar2 + 1);
    puVar4 = puVar4 + 1;
  } while (i != -1);
  return;
}

void sram_unk_2(uint save_index)

{
  short sVar1;
  byte *pbVar2;

  pbVar2 = sram_get_save_offset_likely(save_index * 2);
  sVar1 = 0x7f;
  do {
    *pbVar2 = pbVar2[0x100];
    pbVar2 = pbVar2 + 2;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return;
}

void sram_load(byte *dst, word save_index)

{
  short i;
  byte *save;

  save = *(byte **)((int)&PTR_SRAM_GAME_1_0000c408 + (int)(short)save_index);
  i = 0x7f;
  do {
    *dst = *save;
    dst = dst + 2;
    save = save + 2;
    i = i + -1;
  } while (i != -1);
  return;
}

void FUN_0000c42c(void)

{
  uint uVar1;
  uint in_D0;
  short sVar2;
  uint *in_A0;
  undefined1 *extraout_A0;

  if ((DAT_ffffcbb0 & '\x01' << (in_D0 & 7)) == 0) {
    *in_A0 = 0;
    in_A0[1] = 0;
    *(undefined1 *)(in_A0 + 2) = 0;
    return;
  }
  sram_unk_4();
  uVar1 = DAT_ffffcb30 & 0xfffff;
  *in_A0 = uVar1;
  *(undefined2 *)(in_A0 + 1) = DAT_ffffcb34;
  *(undefined1 *)((int)in_A0 + 6) = DAT_ffffcb36;
  sVar2 = get_red_hearts(
      (ushort)CONCAT31((int3)(uVar1 >> 8), (DAT_ffffcb3d >> 4) + 0x10));
  *extraout_A0 = (char)sVar2;
  extraout_A0[1] = DAT_ffffcbaa;
  return;
}

void FUN_0000c472(void)

{
  long extraout_D0;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  void *in_A1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  byte *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  text_unk_2(in_A1);
  uncompress_and_copy_to_vram();
  vdp_palettes_something();
  FUN_0000c674();
  FUN_0000b83e();
  FUN_0000ae60();
  if (DAT_ffff97ee != '\0') {
    DAT_ffff97ee = '\0';
    FUN_0001a638();
  }
  uVar1 = FUN_0000c5fe();
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar1 >> 0x20),
                  (long)uVar1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  if ((char)pepelogoo_state_b < '\0') {
    FUN_0002a6da();
    unaff_A4 = ENTITY_ID_PEPELOGOO;
    component_state_b_pepelogoo = component_state_b_pepelogoo | 1;
  }
  FUN_0001008a(unaff_A5, (short)unaff_D2);
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  extraout_D0,
                  extraout_D1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_OUT,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar1 = FUN_0000c60a();
  if (DAT_ffffcbf4 != '\0') {
    uVar1 = FUN_0000ac92();
  }
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (palette_fade_done_0 == 0);
  return;
}

void FUN_0000c4fc(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  void *extraout_A1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  if (DAT_ffff97ee != '\0') {
    DAT_ffff97ee = '\0';
    uVar1 = FUN_0001a638();
  }
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar1 >> 0x20),
                  (long)uVar1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  text_unk_2(extraout_A1);
  uncompress_and_copy_to_vram();
  vdp_palettes_something();
  FUN_0000c674();
  FUN_0000c5fe();
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_1,
                   '\0',
                   (palette_color_iter_t)0xffffffff);
  FUN_0000c60a();
  if (DAT_ffffcbf4 != '\0') {
    FUN_0000ac92();
  }
  FUN_0000cbe6();
  (&comp_has_func_maybe)[DAT_ffffcc56] = 0;
  return;
}

void FUN_0000c566(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  void *extraout_A1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  if (DAT_ffff97ee != '\0') {
    DAT_ffff97ee = '\0';
    uVar1 = FUN_0001a638();
  }
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar1 >> 0x20),
                  (long)uVar1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  text_unk_2(extraout_A1);
  uncompress_and_copy_to_vram();
  vdp_palettes_something();
  FUN_0000c674();
  FUN_0000c5fe();
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_1,
                   '\0',
                   (palette_color_iter_t)0xffffffff);
  FUN_0000c60a();
  if (DAT_ffffcbf4 != '\0') {
    FUN_0000ac92();
  }
  FUN_0000ce0e();
  return;
}

undefined8 FUN_0000c5c2(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  void *in_A1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  text_unk_2(in_A1);
  uncompress_and_copy_to_vram();
  vdp_palettes_something();
  FUN_0000c674();
  FUN_0000b83e();
  FUN_0000ae60();
  if (DAT_ffff97ee != '\0') {
    DAT_ffff97ee = '\0';
    FUN_0001a638();
  }
  uVar1 = FUN_0000c5fe();
  uVar1 = exception_unk_0(unaff_A3,
                          unaff_A4,
                          unaff_A6,
                          (long)((ulonglong)uVar1 >> 0x20),
                          (long)uVar1,
                          unaff_D2,
                          unaff_D3,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar1;
}

void FUN_0000c5fe(void)

{
  palette_effect_t *in_A1;

  palette_set_effect(PALETTE_ID_FLAG_ALL, false, in_A1);
  return;
}

void FUN_0000c60a(void)

{
  if ((DAT_ffffcc29 & 1) != 0) {
    palette_set_effect(PALETTE_ID_FLAG_0, true, DAT_ffffcc2a);
  }
  if ((DAT_ffffcc29 & 2) != 0) {
    palette_set_effect(PALETTE_ID_FLAG_1, true, DAT_ffffcc2e);
  }
  if ((DAT_ffffcc29 & 4) != 0) {
    palette_set_effect(PALETTE_ID_FLAG_2, true, DAT_ffffcc32);
  }
  if ((DAT_ffffcc29 & 8) != 0) {
    palette_set_effect(PALETTE_ID_FLAG_3, true, DAT_ffffcc36);
  }
  return;
}

void FUN_0000c674(void)

{
  if (DAT_ffffcbce != DAT_ffffcbde) {
    FUN_0000ca2c();
  }
  if (DAT_ffffcbd2 != DAT_ffffcbe2) {
    FUN_0000ca2c();
  }
  if (DAT_ffffcbd6 != DAT_ffffcbe6) {
    FUN_0000ca2c();
  }
  if (DAT_ffffcbda != DAT_ffffcbea) {
    FUN_0000ca2c();
  }
  return;
}

void FUN_0000c6e0(void)

{
  DAT_ffffcbde = DAT_ffffcbce;
  DAT_ffffcbce = &DAT_0007d2da;
  DAT_ffffcbe2 = DAT_ffffcbd2;
  DAT_ffffcbd2 = &PTR_DAT_0007d5e2;
  DAT_ffffcbe6 = DAT_ffffcbd6;
  DAT_ffffcbea = DAT_ffffcbda;
  return;
}

void FUN_0000c6fe(void)

{
  DAT_ffffcbce = 0;
  DAT_ffffcbd2 = 0;
  DAT_ffffcbd6 = 0;
  DAT_ffffcbda = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000c70c(void)

{
  byte bVar1;
  sound_id_word_union_t sVar2;
  byte *pbVar3;
  byte *pbVar4;
  bool bVar5;

  DAT_ffffc714 = 0xf;
  FUN_00014ac0();
  FUN_0000d968();
  DAT_ffff9808 = 0;
  DAT_ffffcc28 = 0;
  DAT_ffffcf8a = 0;
  DAT_ffffcbf6 = 0;
  _DAT_ffffde34 = 0;
  DAT_ffffcca2 = 0;
  DAT_ffffcbf5 = 0;
  DAT_ffffcc29 = 0;
  DAT_ffffcbf4 = 0;
  DAT_ffffcbcc = 0;
  FUN_0000c6e0();
  FUN_0000ac2a();
  FUN_00012f5e();
  FUN_0000e8ae();
  FUN_00012f5e();
  DAT_ffff9812 = 2;
  DAT_ffff9813 = 3;
  DAT_ffffc716 = 0x80;
  DAT_ffffc71a = 0x80;
  if (DAT_ffffcbb2 == 1) {
    bVar5 = script_state_get((script_state_bit_t)0x3e9);
    if (bVar5) {
      bVar5 = script_state_get((script_state_bit_t)0x3e8);
      if (!bVar5) {
        sVar2.as_word = 0x23;
        goto LAB_0000c7ba;
      }
    }
  }
  sVar2 = *(sound_id_word_union_t *)((int)WORD_ARRAY_0000c840 +
                                     (int)(short)(DAT_ffffcbb2 * 2));
LAB_0000c7ba:
  if (sVar2.as_word != UNION_sound_id_word_union_t_ffff97e6.as_word) {
    UNION_sound_id_word_union_t_ffff97e6 = sVar2;
    audio_play(SOUND_ID_F9);
    audio_play((sound_id_t)UNION_sound_id_word_union_t_ffff97e6.as_word);
  }
  if (DAT_ffffcbb2 != DAT_ffffcbb6) {
    FUN_00012f4e();
  }
  DAT_ffffcbb6 = DAT_ffffcbb2;
  DAT_ffffcbc0 = (byte *)((int)*(short *)(*(int *)(&DAT_0007d292 +
                                                   (short)(DAT_ffffcbb2 << 2)) +
                                          (int)(short)(DAT_ffffcbb4 * 2)) +
                          *(int *)(&DAT_0007d292 + (short)(DAT_ffffcbb2 << 2)));
  pbVar3 = DAT_ffffcbc0;
  while (true) {
    while (true) {
      pbVar4 = pbVar3 + 1;
      bVar1 = *pbVar3;
      pbVar3 = pbVar4;
      if (0xbf < bVar1)
        break;
      (*(code *)((int)&WORD_0000c86a +
                 (int)*(short *)((int)&WORD_0000c86a +
                                 (int)(short)((ushort)bVar1 * 2))))();
    }
    if (bVar1 == 0xff)
      break;
    (*(code *)((int)&jmp_text_command_ff_to_e1 +
               (int)*(short *)((int)&jmp_text_command_ff_to_e1 +
                               (int)(short)((ushort)(byte)~bVar1 * 2))))();
  }
  DAT_ffffcbc0 = pbVar4;
  return;
}

void FUN_0000c8ac(void)

{
  do {
    // WARNING: Do nothing block with infinite loop
  } while (true);
}

void text_unk_2(void *param_1)

{
  text_unk_1(BYTE_ARRAY_0000c8bc, param_1);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined2 FUN_0000c8ce(void)

{
  undefined2 *unaff_A5;

  _DAT_ffffcbc8 = unaff_A5 + 1;
  return *unaff_A5;
}

void FUN_0000c8e0(void)

{
  return;
}

void FUN_0000c8e6(void)

{
  short *unaff_A5;

  DAT_ffffcbc4 = (int)unaff_A5 + (int)*unaff_A5;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000c8f6(void)

{
  FUN_00019146();
  DAT_ffffd18c = room_boundary_x;
  _DAT_ffffd184 = room_boundary_x;
  DAT_ffffd190 = camera_pos_x_int;
  _DAT_ffffd188 = camera_pos_x_int;
  DAT_ffffd18a = 0x1000;
  _DAT_ffffd182 = 0x1000;
  DAT_ffffd18e = 0x1000;
  _DAT_ffffd186 = 0x1000;
  if ((DAT_ffffcbcc & 8) == 0) {
    if (0x10e < (ushort)(room_boundary_x - 0x1000)) {
      DAT_ffffd18a = 0x1008;
      DAT_ffffd18c = room_boundary_x - 8;
    }
    if (0xce < (ushort)(camera_pos_x_int - 0x1000)) {
      DAT_ffffd18e = 0x1008;
      DAT_ffffd190 = camera_pos_x_int - 8;
    }
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000c962(void)

{
  FUN_00019132();
  DAT_ffffd18c = room_boundary_x;
  _DAT_ffffd184 = room_boundary_x;
  DAT_ffffd190 = camera_pos_x_int;
  _DAT_ffffd188 = camera_pos_x_int;
  DAT_ffffd18a = 0x1000;
  _DAT_ffffd182 = 0x1000;
  DAT_ffffd18e = 0x1000;
  _DAT_ffffd186 = 0x1000;
  if ((DAT_ffffcbcc & 8) == 0) {
    if (0x10e < (ushort)(room_boundary_x - 0x1000)) {
      DAT_ffffd18a = 0x1008;
      DAT_ffffd18c = room_boundary_x - 8;
    }
    if (0xce < (ushort)(camera_pos_x_int - 0x1000)) {
      DAT_ffffd18e = 0x1008;
      DAT_ffffd190 = camera_pos_x_int - 8;
    }
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000c96a(void)

{
  FUN_000190a2();
  DAT_ffffd18c = room_boundary_x;
  _DAT_ffffd184 = room_boundary_x;
  DAT_ffffd190 = camera_pos_x_int;
  _DAT_ffffd188 = camera_pos_x_int;
  DAT_ffffd18a = 0x1000;
  _DAT_ffffd182 = 0x1000;
  DAT_ffffd18e = 0x1000;
  _DAT_ffffd186 = 0x1000;
  if ((DAT_ffffcbcc & 8) == 0) {
    if (0x10e < (ushort)(room_boundary_x - 0x1000)) {
      DAT_ffffd18a = 0x1008;
      DAT_ffffd18c = room_boundary_x - 8;
    }
    if (0xce < (ushort)(camera_pos_x_int - 0x1000)) {
      DAT_ffffd18e = 0x1008;
      DAT_ffffd190 = camera_pos_x_int - 8;
    }
  }
  return;
}

void FUN_0000c972(void)

{
  undefined4 in_D1;
  byte *unaff_A5;

  *(uint *)((int)&DAT_ffffcbce + (int)(short)(ushort)*unaff_A5) =
      CONCAT31(CONCAT21((short)CONCAT31((int3)((uint)in_D1 >> 8), unaff_A5[1]),
                        unaff_A5[2]),
               unaff_A5[3]);
  return;
}

void FUN_0000c98a(void)

{
  short *unaff_A5;

  DAT_ffffcbce = (int)unaff_A5 + (int)*unaff_A5;
  return;
}

void FUN_0000c99a(void)

{
  short *unaff_A5;

  DAT_ffffcbd2 = (int)unaff_A5 + (int)*unaff_A5;
  return;
}

void FUN_0000c9aa(void)

{
  short *unaff_A5;

  DAT_ffffcbd6 = (int)unaff_A5 + (int)*unaff_A5;
  return;
}

void FUN_0000c9ba(void)

{
  short *unaff_A5;

  DAT_ffffcbda = (int)unaff_A5 + (int)*unaff_A5;
  return;
}

void FUN_0000c9ca(void)

{
  byte *unaff_A5;

  DAT_ffffcc29 = DAT_ffffcc29 | '\x01' << (*unaff_A5 & 7);
  *(byte **)((int)&DAT_ffffcc2a + (int)(short)((ushort)*unaff_A5 << 2)) =
      unaff_A5 + *(short *)(unaff_A5 + 1) + 1;
  return;
}

void FUN_0000c9e6(void)

{
  undefined1 *unaff_A5;

  DAT_ffff9812 = *unaff_A5;
  return;
}

void FUN_0000c9ec(void)

{
  undefined1 *unaff_A5;

  DAT_ffff9813 = *unaff_A5;
  return;
}

void FUN_0000c9f2(void)

{
  undefined1 *unaff_A5;

  DAT_ffff9814 = *unaff_A5;
  DAT_ffff9815 = unaff_A5[1];
  return;
}

void FUN_0000c9fc(void)

{
  void *in_A1;
  short *unaff_A5;

  text_unk_1((void *)((int)unaff_A5 + (int)*unaff_A5), in_A1);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000ca0c(void)

{
  short *unaff_A5;

  _DAT_ffffd11c = (int)unaff_A5 + (int)*unaff_A5;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000ca1c(void)

{
  short *unaff_A5;

  _DAT_ffffde34 = (int)unaff_A5 + (int)*unaff_A5;
  return;
}

void FUN_0000ca2c(void)

{
  byte bVar1;
  ushort uVar2;
  bool bVar3;
  byte bVar4;
  short sVar5;
  undefined1 *in_A0;
  ushort *in_A1;
  ushort *puVar6;
  ushort *puVar7;
  ushort *puVar8;
  short *unaff_A3;
  byte *pbVar9;
  byte *pbVar10;

  sVar5 = *unaff_A3;
  if (sVar5 != 0) {
    puVar8 = (ushort *)((int)(unaff_A3 + 1) +
                        (int)(short)((ushort)(sVar5 + 1U) >> 1));
    bVar3 = false;
    sVar5 = sVar5 + -1;
    pbVar9 = (byte *)(unaff_A3 + 1);
    do {
      bVar3 = (bool)(bVar3 ^ 1);
      if (bVar3) {
        bVar4 = *pbVar9 >> 4;
        pbVar10 = pbVar9;
      } else {
        pbVar10 = pbVar9 + 1;
        bVar4 = *pbVar9;
      }
      if ((bVar4 & 0xf) != 0) {
        puVar7 = puVar8;
        if (((bVar4 & 0xf ^ 0xf) & 8) == 0) {
          puVar7 = (ushort *)((int)puVar8 + 1);
        }
        *in_A0 = 0;
        bVar1 = *(byte *)puVar7;
        puVar8 = puVar7 + 1;
        uVar2 = *puVar7;
        puVar6 = in_A1 + 1;
        *in_A1 = uVar2;
        bVar4 = (bVar4 & 0xf ^ 0xf) & 7;
        if (bVar4 == 0) {
          *(byte *)puVar6 = *(byte *)puVar8;
          *(byte *)((int)in_A1 + 3) = *(byte *)((int)puVar7 + 3);
          *(byte *)(in_A1 + 2) = *(byte *)(puVar7 + 2);
          *(byte *)((int)in_A1 + 5) = *(byte *)((int)puVar7 + 5);
          *(byte *)(in_A1 + 3) = *(byte *)(puVar7 + 3);
          puVar8 = puVar7 + 4;
          *(byte *)((int)in_A1 + 7) = *(byte *)((int)puVar7 + 7);
        } else if (bVar4 == 2) {
          uVar2 = uVar2 & 0xffe0;
          *puVar6 = uVar2 | *(byte *)puVar8 & 0x1f;
          in_A1[2] = uVar2 | *(byte *)((int)puVar7 + 3) & 0x1f;
          puVar8 = puVar7 + 2;
          in_A1[3] =
              CONCAT11((char)(uVar2 >> 8),
                       *(byte *)(puVar7 + 1) >> 5 |
                           (byte)((*(byte *)((int)puVar7 + 3) & 0x60) >> 2) |
                           (byte)uVar2);
        } else if (bVar4 < 2) {
          *puVar6 = uVar2 + 1;
          in_A1[2] = uVar2 + 0x10;
          in_A1[3] = uVar2 + 0x11;
        } else if (bVar4 == 3) {
          *puVar6 = CONCAT11(bVar1, *(byte *)puVar8);
          in_A1[2] = CONCAT11(bVar1, *(byte *)((int)puVar7 + 3));
          puVar8 = (ushort *)((int)puVar7 + 5);
          in_A1[3] = CONCAT11(bVar1, *(byte *)(puVar7 + 2));
        } else {
          uVar2 = uVar2 & 0xe7e0;
          *puVar6 =
              uVar2 | *(byte *)puVar8 & 0x1f | (*(byte *)puVar8 & 0xc0) << 5;
          in_A1[2] = uVar2 | *(byte *)((int)puVar7 + 3) & 0x1f |
                     (*(byte *)((int)puVar7 + 3) & 0xc0) << 5;
          puVar8 = (ushort *)((int)puVar7 + 5);
          in_A1[3] = uVar2 | *(byte *)(puVar7 + 2) & 0x1f |
                     (*(byte *)(puVar7 + 2) & 0xc0) << 5;
        }
      }
      in_A1 = in_A1 + 4;
      in_A0 = in_A0 + 1;
      sVar5 = sVar5 + -1;
      pbVar9 = pbVar10;
    } while (sVar5 != -1);
  }
  return;
}

void FUN_0000cb38(void)

{
  byte bVar1;
  short sVar2;
  byte *pbVar3;
  byte *pbVar4;
  int iVar5;
  short *unaff_A5;

  pbVar4 = (byte *)((int)unaff_A5 + (int)*unaff_A5);
  iVar5 = 0;
  DAT_ffffc71a = DAT_ffffc71a | 1;
  DAT_ffffc8ee = (ushort)*pbVar4;
  sVar2 = DAT_ffffc8ee - 1;
  do {
    pbVar3 = pbVar4 + 2;
    bVar1 = pbVar4[1];
    (&DAT_ffffc8f0)[iVar5] = bVar1;
    *(ushort *)(iVar5 + -0x3608) = (ushort)(bVar1 >> 2);
    (&DAT_ffffc8f0)[iVar5] = (&DAT_ffffc8f0)[iVar5] | 0x80;
    pbVar4 = pbVar4 + 3;
    (&DAT_ffffc8f1)[iVar5] = *pbVar3;
    (&DAT_ffffc8f1)[iVar5] = (&DAT_ffffc8f1)[iVar5] + -1;
    *(short *)(&DAT_ffffc8f2 + iVar5) = (short)(char)*pbVar4 << 4;
    iVar5 = iVar5 + 4;
    sVar2 = sVar2 + -1;
  } while (sVar2 != -1);
  return;
}

void FUN_0000cb84(void)

{
  DAT_ffffcbcc = 1;
  return;
}

void FUN_0000cb8c(void)

{
  DAT_ffffcbcc = DAT_ffffcbcc | 2;
  return;
}

void FUN_0000cb94(void)

{
  undefined1 *unaff_A5;

  DAT_ffffde42 = *unaff_A5;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000cb9a(void)

{
  undefined2 *unaff_A5;

  DAT_ffffde42 = 7;
  DAT_ffffcc85 = 0xff;
  DAT_ffffcc86 = 1;
  DAT_ffffde72 = 0x80;
  _DAT_ffffdea2 = 0x7e;
  _DAT_ffffde74 = *unaff_A5;
  _DAT_ffffde82 = unaff_A5[1];
  _DAT_ffffde92 = unaff_A5[2];
  return;
}

void FUN_0000cbd6(void)

{
  DAT_ffffcbcc = DAT_ffffcbcc | 4;
  return;
}

void FUN_0000cbde(void)

{
  DAT_ffffcbcc = DAT_ffffcbcc | 8;
  return;
}

undefined8 FUN_0000cbe6(void)

{
  ushort uVar1;
  short sVar2;
  undefined2 extraout_D0u;
  undefined4 in_D0;
  undefined2 extraout_D1u;
  undefined4 in_D1;
  long unaff_D2;
  long lVar3;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  entity_id_t self;
  void *unaff_A6;
  bool bVar4;
  undefined8 uVar5;

  vdp_gfx_ptr_5._0_2_ = DAT_ffffc746 & 0xff;
  vdp_hblank_effect_asha_p = -(DAT_ffffc73a & 0x1ff);
  vdp_related_to_display_asha = vdp_related_to_display_asha | 5;
  exception_unk_0(
      unaff_A3,
      unaff_A4,
      unaff_A6,
      CONCAT22((short)((uint)in_D0 >> 0x10), vdp_hblank_effect_asha_p),
      CONCAT22((short)((uint)in_D1 >> 0x10), DAT_ffffc746) & 0xffff00ff,
      unaff_D2,
      unaff_D3,
      unaff_D4,
      unaff_D5,
      unaff_D6,
      unaff_D7);
  FUN_0000d442();
  self = (entity_id_t)DAT_ffffcc56;
  (&comp_has_func_maybe)[self] = 0;
  DAT_ffffcc50 = DAT_ffffc73a + 0x108;
  DAT_ffffcc52 = DAT_ffffc746 + 0xe8;
  lVar3 =
      CONCAT22((short)((uint)unaff_D2 >> 0x10), DAT_ffffcc4a - DAT_ffffc73a);
  sVar2 = DAT_ffffcc4c - DAT_ffffc746;
  DAT_ffffcc3a = (DAT_ffffcc4a - DAT_ffffc73a) + DAT_ffffc73a & 0xfff8;
  DAT_ffffcc3c = sVar2 + DAT_ffffc746 & 0xfff8;
  DAT_ffffcc44 = 8;
  do {
    unaff_D7 = CONCAT22((short)((uint)unaff_D7 >> 0x10), DAT_ffffcc44);
    DAT_ffffcc4e = '\0';
    DAT_ffffcc3e = 0;
    DAT_ffffcc40 = DAT_ffffcc44;
    DAT_ffffcc42 = DAT_ffffcc44 * 2 - 1;
    lVar3 = CONCAT22((short)((uint)lVar3 >> 0x10), DAT_ffffcc42);
    while (true) {
      FUN_0000ccc6();
      if (DAT_ffffcc40 < DAT_ffffcc3e)
        break;
      DAT_ffffcc3e = DAT_ffffcc3e + 4;
      uVar1 = DAT_ffffcc3e * 2 + 1;
      bVar4 = DAT_ffffcc42 < uVar1;
      DAT_ffffcc42 = DAT_ffffcc42 - uVar1;
      if (bVar4 || DAT_ffffcc42 == 0) {
        DAT_ffffcc40 = DAT_ffffcc40 - 4;
        DAT_ffffcc42 = DAT_ffffcc40 * 2 + -1 + DAT_ffffcc42;
      }
    }
    uVar5 = exception_unk_0((script_ctx_t *)&DAT_ffff4000,
                            self,
                            unaff_A6,
                            CONCAT22(extraout_D0u, DAT_ffffcc3e),
                            CONCAT22(extraout_D1u, DAT_ffffcc40),
                            lVar3,
                            CONCAT22((short)((uint)unaff_D3 >> 0x10), sVar2),
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    DAT_ffffcc44 = DAT_ffffcc44 + 8;
  } while (DAT_ffffcc4e != '\0');
  return uVar5;
}

void FUN_0000ccc6(void)

{
  ushort uVar1;
  ushort uVar2;
  ushort uVar3;
  short sVar4;
  int unaff_A2;
  int unaff_A3;

  FUN_0000cd32(unaff_A2, unaff_A3, DAT_ffffcc3e, DAT_ffffcc40);
  FUN_0000cd32(unaff_A2, unaff_A3, DAT_ffffcc40, DAT_ffffcc3e);
  FUN_0000cd32(unaff_A2, unaff_A3, -DAT_ffffcc3e, DAT_ffffcc40);
  FUN_0000cd32(unaff_A2, unaff_A3, DAT_ffffcc40, -DAT_ffffcc3e);
  FUN_0000cd32(unaff_A2, unaff_A3, DAT_ffffcc3e, -DAT_ffffcc40);
  FUN_0000cd32(unaff_A2, unaff_A3, -DAT_ffffcc40, DAT_ffffcc3e);
  FUN_0000cd32(unaff_A2, unaff_A3, -DAT_ffffcc3e, -DAT_ffffcc40);
  uVar1 = DAT_ffffcc3a + -DAT_ffffcc40;
  uVar2 = DAT_ffffcc3c + -DAT_ffffcc3e;
  if (((((uVar1 < room_boundary_x) && (uVar2 < camera_pos_x_int)) &&
        (uVar1 <= DAT_ffffcc50)) &&
       ((uVar2 <= DAT_ffffcc52 && ((ushort)(DAT_ffffc73a - 8U) <= uVar1)))) &&
      ((DAT_ffffc746 <= uVar2 &&
        ((uVar1 = uVar1 - 0x1000,
          -1 < (short)uVar1 &&
              (uVar2 = uVar2 - 0x1000, -1 < (short)uVar2)))))) {
    sVar4 = 0;
    if ((uVar1 & 8) != 0) {
      sVar4 = 2;
    }
    if ((uVar2 & 8) != 0) {
      sVar4 = sVar4 + 4;
    }
    uVar3 = ((DAT_ffffcc3c + -DAT_ffffcc3e) - 0x1000U & 0xf8) * 0x10 +
            (((DAT_ffffcc3a + -DAT_ffffcc40) - 0x1000U & 0x1f8) >> 2) + 0xc000;
    VDP_CTRL = (union2_t)(uVar3 & 0x3fff | 0x4000);
    VDP_CTRL = (union2_t)(uVar3 >> 0xe);
    VDP_DATA =
        *(word *)((short)(sVar4 +
                          (*(ushort *)(unaff_A2 +
                                       (short)((uVar1 >> 4) * 2 +
                                               ((uVar2 & 0xfff0)
                                                << (DAT_ffffc717 & 0x3f)))) &
                           0x3ff) *
                              8) +
                  unaff_A3);
    DAT_ffffcc4e = 0xff;
  }
  return;
}

void FUN_0000cd32(int param_1, int param_2, short param_3, short param_4)

{
  ushort uVar1;
  ushort uVar2;
  ushort uVar3;
  short sVar4;

  uVar1 = DAT_ffffcc3a + param_3;
  uVar2 = DAT_ffffcc3c + param_4;
  if (((((uVar1 < room_boundary_x) && (uVar2 < camera_pos_x_int)) &&
        (uVar1 <= DAT_ffffcc50)) &&
       ((uVar2 <= DAT_ffffcc52 && ((ushort)(DAT_ffffc73a - 8U) <= uVar1)))) &&
      ((DAT_ffffc746 <= uVar2 &&
        ((uVar1 = uVar1 - 0x1000,
          -1 < (short)uVar1 &&
              (uVar2 = uVar2 - 0x1000, -1 < (short)uVar2)))))) {
    sVar4 = 0;
    if ((uVar1 & 8) != 0) {
      sVar4 = 2;
    }
    if ((uVar2 & 8) != 0) {
      sVar4 = sVar4 + 4;
    }
    uVar3 = ((DAT_ffffcc3c + param_4) - 0x1000U & 0xf8) * 0x10 +
            (((DAT_ffffcc3a + param_3) - 0x1000U & 0x1f8) >> 2) + 0xc000;
    VDP_CTRL = (union2_t)(uVar3 & 0x3fff | 0x4000);
    VDP_CTRL = (union2_t)(uVar3 >> 0xe);
    VDP_DATA =
        *(word *)((short)(sVar4 +
                          (*(ushort *)(param_1 +
                                       (short)((uVar1 >> 4) * 2 +
                                               ((uVar2 & 0xfff0)
                                                << (DAT_ffffc717 & 0x3f)))) &
                           0x3ff) *
                              8) +
                  param_2);
    DAT_ffffcc4e = 0xff;
  }
  return;
}

void FUN_0000ce0e(void)

{
  undefined2 extraout_D0u;
  undefined2 extraout_D1u;
  undefined4 in_D1;
  long unaff_D2;
  long lVar1;
  ushort uVar2;
  long unaff_D3;
  ushort uVar4;
  long lVar3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  short sVar5;
  long unaff_D7;
  short sVar6;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  int iVar7;
  void *unaff_A6;
  bool bVar8;

  DAT_ffffcc4a = DAT_ffffcd32;
  DAT_ffffcc4c = DAT_ffffcd34 + (ushort)DAT_ffffcd37 * -4;
  vdp_gfx_ptr_5._0_2_ = DAT_ffffc746 & 0xff;
  vdp_hblank_effect_asha_p = -(DAT_ffffc73a & 0x1ff);
  vdp_related_to_display_asha = vdp_related_to_display_asha | 5;
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (uint)vdp_hblank_effect_asha_p,
                  CONCAT22((short)((uint)in_D1 >> 0x10), DAT_ffffc746) &
                      0xffff00ff,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  DAT_ffffcc50 = DAT_ffffc73a + 0x108;
  DAT_ffffcc52 = DAT_ffffc746 + 0xe8;
  uVar2 = DAT_ffffcc4a - DAT_ffffc73a;
  uVar4 = DAT_ffffcc4c - DAT_ffffc746;
  DAT_ffffcc3a = uVar2 + DAT_ffffc73a & 0xfff8;
  DAT_ffffcc3c = uVar4 + DAT_ffffc746 & 0xfff8;
  if (uVar2 < 0x80) {
    unaff_D4 = CONCAT22((short)((uint)unaff_D4 >> 0x10), uVar2);
    uVar2 = 0x100 - uVar2;
  }
  if (uVar4 < 0x70) {
    unaff_D4 = CONCAT22((short)((uint)unaff_D4 >> 0x10), uVar4);
    uVar4 = 0xe0 - uVar4;
  }
  if (uVar4 < uVar2) {
    uVar4 = uVar4 >> 1;
  } else {
    uVar2 = uVar2 >> 1;
  }
  lVar1 = CONCAT22((short)((uint)unaff_D2 >> 0x10), uVar2);
  DAT_ffffcc44 = uVar2 + uVar4;
  lVar3 = CONCAT22((short)((uint)unaff_D3 >> 0x10), DAT_ffffcc44);
  while (true) {
    unaff_D7 = CONCAT22((short)((uint)unaff_D7 >> 0x10), DAT_ffffcc44);
    DAT_ffffcc3e = 0;
    DAT_ffffcc40 = DAT_ffffcc44;
    DAT_ffffcc42 = DAT_ffffcc44 * 2 - 1;
    lVar1 = CONCAT22((short)((uint)lVar1 >> 0x10), DAT_ffffcc42);
    while (true) {
      FUN_0000cfb4();
      if (DAT_ffffcc40 < DAT_ffffcc3e)
        break;
      DAT_ffffcc3e = DAT_ffffcc3e + 4;
      uVar2 = DAT_ffffcc3e * 2 + 1;
      bVar8 = DAT_ffffcc42 < uVar2;
      DAT_ffffcc42 = DAT_ffffcc42 - uVar2;
      if (bVar8 || DAT_ffffcc42 == 0) {
        DAT_ffffcc40 = DAT_ffffcc40 - 4;
        DAT_ffffcc42 = DAT_ffffcc40 * 2 + -1 + DAT_ffffcc42;
      }
    }
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    CONCAT22(extraout_D0u, DAT_ffffcc3e),
                    CONCAT22(extraout_D1u, DAT_ffffcc40),
                    lVar1,
                    lVar3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    if (DAT_ffffcc44 < 0xf)
      break;
    DAT_ffffcc44 = DAT_ffffcc44 - 8;
  }
  FUN_0000d5ca();
  DAT_ffffcc3e = DAT_ffffcd32 + (ushort)DAT_ffffcd36 * -4;
  DAT_ffffcc40 = DAT_ffffcd34 + (ushort)DAT_ffffcd37 * -0x10;
  sVar5 = DAT_ffffcd37 - 1;
  do {
    sVar6 = DAT_ffffcd36 - 1;
    DAT_ffffcc3a = DAT_ffffcc3e;
    do {
      FUN_0000d57a();
      DAT_ffffcc3e = DAT_ffffcc3e + 0x10;
      sVar6 = sVar6 + -1;
    } while (sVar6 != -1);
    DAT_ffffcc40 = DAT_ffffcc40 + 0x10;
    DAT_ffffcc3e = DAT_ffffcc3a;
    sVar5 = sVar5 + -1;
  } while (sVar5 != -1);
  iVar7 = (int)DAT_ffffcc56;
  (&comp_has_func_maybe + iVar7)[0] = 0;
  (&comp_has_func_maybe + iVar7)[1] = 0;
  return;
}

ushort FUN_0000cfb4(void)

{
  ushort uVar1;
  ushort uVar2;
  ushort uVar3;
  ushort uVar4;
  short sVar5;

  FUN_0000d020();
  FUN_0000d020();
  FUN_0000d020();
  FUN_0000d020();
  FUN_0000d020();
  FUN_0000d020();
  uVar4 = FUN_0000d020();
  uVar1 = DAT_ffffcc3a + -DAT_ffffcc40;
  uVar2 = DAT_ffffcc3c + -DAT_ffffcc3e;
  if ((((uVar1 <= room_boundary_x) && (uVar2 <= camera_pos_x_int)) &&
       (uVar1 <= DAT_ffffcc50)) &&
      (uVar2 <= DAT_ffffcc52)) {
    uVar4 = DAT_ffffc73a & 0xfff8;
    if (((DAT_ffffc73a & 0xfff8) <= uVar1) &&
        (uVar4 = DAT_ffffc746 & 0xfff8, (DAT_ffffc746 & 0xfff8) <= uVar2)) {
      uVar4 = (DAT_ffffcd32 + (ushort)DAT_ffffcd36 * -4) - 8;
      if (((uVar4 <= uVar1) &&
           ((uVar4 = (ushort)DAT_ffffcd36 * 0x10 + uVar4,
             uVar1 < uVar4 && (uVar4 = DAT_ffffcd34, uVar2 < DAT_ffffcd34)))) &&
          (uVar4 = DAT_ffffcd34 + (ushort)DAT_ffffcd37 * -0x10,
           uVar4 <= uVar2)) {
        return uVar4;
      }
      uVar1 = uVar1 - 0x1000;
      if ((-1 < (short)uVar1) && (uVar2 = uVar2 - 0x1000, -1 < (short)uVar2)) {
        sVar5 = 0;
        if ((uVar1 & 8) != 0) {
          sVar5 = 2;
        }
        if ((uVar2 & 8) != 0) {
          sVar5 = sVar5 + 4;
        }
        uVar4 = ((DAT_ffffcc3a + -DAT_ffffcc40) - 0x1000U & 0x1f8) >> 2;
        uVar3 = ((DAT_ffffcc3c + -DAT_ffffcc3e) - 0x1000U & 0xf8) * 0x10 +
                uVar4 + 0xc000;
        VDP_CTRL = (union2_t)(uVar3 & 0x3fff | 0x4000);
        VDP_CTRL = (union2_t)(uVar3 >> 0xe);
        VDP_DATA =
            *(ushort *)(&DAT_ffff4000 +
                        (short)(sVar5 + (*(ushort *)(DAT_ffffc722 +
                                                     (short)((uVar1 >> 4) * 2 +
                                                             ((uVar2 & 0xfff0)
                                                              << (DAT_ffffc717 &
                                                                  0x3f)))) &
                                         0x3ff) *
                                            8)) |
            0x8000;
        DAT_ffffcc4e = 0xff;
      }
    }
  }
  return uVar4;
}

void FUN_0000d020(void)

{
  ushort uVar1;
  ushort uVar2;
  ushort uVar3;
  short sVar4;
  short unaff_D5w;
  short unaff_D6w;

  uVar1 = DAT_ffffcc3a + unaff_D5w;
  uVar2 = DAT_ffffcc3c + unaff_D6w;
  if (((((uVar1 <= room_boundary_x) && (uVar2 <= camera_pos_x_int)) &&
        (uVar1 <= DAT_ffffcc50)) &&
       ((uVar2 <= DAT_ffffcc52 && ((DAT_ffffc73a & 0xfff8) <= uVar1)))) &&
      ((DAT_ffffc746 & 0xfff8) <= uVar2)) {
    uVar3 = (DAT_ffffcd32 + (ushort)DAT_ffffcd36 * -4) - 8;
    if ((((uVar1 < uVar3) ||
          ((ushort)((ushort)DAT_ffffcd36 * 0x10 + uVar3) <= uVar1)) ||
         ((DAT_ffffcd34 <= uVar2 ||
           (uVar2 < (ushort)(DAT_ffffcd34 + (ushort)DAT_ffffcd37 * -0x10))))) &&
        ((uVar1 = uVar1 - 0x1000,
          -1 < (short)uVar1 && (uVar2 = uVar2 - 0x1000, -1 < (short)uVar2)))) {
      sVar4 = 0;
      if ((uVar1 & 8) != 0) {
        sVar4 = 2;
      }
      if ((uVar2 & 8) != 0) {
        sVar4 = sVar4 + 4;
      }
      uVar3 = ((DAT_ffffcc3c + unaff_D6w) - 0x1000U & 0xf8) * 0x10 +
              (((DAT_ffffcc3a + unaff_D5w) - 0x1000U & 0x1f8) >> 2) + 0xc000;
      VDP_CTRL = (union2_t)(uVar3 & 0x3fff | 0x4000);
      VDP_CTRL = (union2_t)(uVar3 >> 0xe);
      VDP_DATA =
          *(ushort *)(&DAT_ffff4000 +
                      (short)(sVar4 + (*(ushort *)(DAT_ffffc722 +
                                                   (short)((uVar1 >> 4) * 2 +
                                                           ((uVar2 & 0xfff0)
                                                            << (DAT_ffffc717 &
                                                                0x3f)))) &
                                       0x3ff) *
                                          8)) |
          0x8000;
      DAT_ffffcc4e = 0xff;
    }
  }
  return;
}

void FUN_0000d140(void)

{
  short unaff_D5w;
  short unaff_D6w;
  ushort *extraout_A0;

  vdp_set_vram_write_addr(
      (void *)(((DAT_ffffcc3c + unaff_D6w) - 0x1000U & 0xf8) * 0x10 +
               (((DAT_ffffcc3a + unaff_D5w) - 0x1000U & 0x1f8) >> 2) + 0xc000));
  VDP_DATA = *extraout_A0 | 0x8000;
  DAT_ffffcc4e = 0xff;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000d17e(void)

{
  long unaff_D2;
  long unaff_D3;
  undefined4 unaff_D4;
  undefined4 unaff_D5;
  undefined4 unaff_D6;
  undefined4 unaff_D7;
  script_ctx_t *unaff_A3;
  void *unaff_A6;
  undefined8 uVar1;

  FUN_0000d1b8();
  FUN_0000d1ec();
  _DAT_ffffcc54 = 0;
  do {
    _DAT_ffffcc54 = _DAT_ffffcc54 + 1;
    uVar1 = FUN_0000d1fe();
    exception_unk_0(unaff_A3,
                    ENTITY_ID_PEPELOGOO,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    CONCAT22((short)((uint)unaff_D4 >> 0x10), 0x1000),
                    CONCAT22((short)((uint)unaff_D5 >> 0x10), 0x1070),
                    CONCAT22((short)((uint)unaff_D6 >> 0x10), 0x10),
                    CONCAT22((short)((uint)unaff_D7 >> 0x10), 0x10));
  } while (_DAT_ffffcc54 != 0xe0);
  FUN_0000d20e();
  return;
}

void FUN_0000d1b8(void)

{
  short sVar1;
  ushort unaff_D4w;
  ushort unaff_D5w;
  short unaff_D6w;
  short unaff_D7w;
  ushort *puVar2;
  int unaff_A4;

  do {
    sVar1 = unaff_D6w;
    puVar2 = (ushort *)((int)(short)(((unaff_D5w & 0xfff0)
                                      << ((&DAT_ffffc717)[unaff_A4] & 0x3f)) +
                                     ((unaff_D4w & 0xfff0) >> 3)) +
                        *(int *)((int)&DAT_ffffc722 + unaff_A4));
    do {
      *puVar2 = *puVar2 | 0x8000;
      sVar1 = sVar1 + -1;
      puVar2 = puVar2 + 1;
    } while (sVar1 != -1);
    unaff_D5w = unaff_D5w + 0x10;
    unaff_D7w = unaff_D7w + -1;
  } while (unaff_D7w != -1);
  return;
}

void FUN_0000d1ec(void)

{
  DAT_ffffc746 = 0xf30;
  FUN_0000ae60();
  return;
}

void FUN_0000d1fe(void)

{
  DAT_ffffc746 = DAT_ffffc746 + 1;
  FUN_0000ae60();
  return;
}

void FUN_0000d20e(void)

{
  return;
}

void FUN_0000d210(void)

{
  // WARNING: Could not recover jumptable at 0x0000d222. Too many branches
  // WARNING: Treating indirect jump as call
  (*(FUN_0000d224 +
     *(short *)(FUN_0000d224 + (short)((ushort)DAT_ffffcd3a * 2))))();
  return;
}

void FUN_0000d224(void)

{
  short sVar1;
  uint in_D0;
  undefined4 extraout_D0;
  undefined4 extraout_D0_00;
  undefined4 extraout_D1;
  undefined4 extraout_D1_00;
  long unaff_D2;
  undefined4 unaff_D3;
  long lVar2;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  byte *in_A0;
  func *in_A1;
  func *extraout_A1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  entity_id_t eVar3;
  anim_item_t *unaff_A5;
  int unaff_A6;
  byte *pbVar4;
  undefined8 uVar5;

  *in_A0 = *in_A0 | 0x10;
  *in_A0 = *in_A0 | 0x10;
  *(byte *)(unaff_A6 + 0x16e) =
      *(byte *)(unaff_A6 + 0x16e) ^ '\x01' << (in_D0 & 7);
  pbVar4 = (byte *)(unaff_A6 + -1);
  *pbVar4 = *pbVar4 & ~('\x01' << (in_D0 & 7));
  *in_A0 = *in_A0 | '\x01' << (in_D0 & 7);
  if (DAT_ffffcd3e != (void *)0x0) {
    text_unk_1(DAT_ffffcd3e, in_A1);
    uncompress_and_copy_to_vram();
    DAT_ffffcd3e = (void *)0x0;
    in_A1 = extraout_A1;
  }
  if (DAT_ffffcd3d < '\0') {
    DAT_ffffcc56 = 0;
    palette_set_fade(PALETTE_ID_FLAG_ALL,
                     PALETTE_FADE_BLACK_EASE_OUT,
                     '\x01',
                     (palette_color_iter_t)0xffffffff);
    uVar5 = FUN_0000c60a();
    if (DAT_ffffcbf4 != '\0') {
      uVar5 = FUN_0000ac92();
    }
    do {
      uVar5 = exception_unk_0(unaff_A3,
                              unaff_A4,
                              pbVar4,
                              (long)((ulonglong)uVar5 >> 0x20),
                              (long)uVar5,
                              0xf,
                              -1,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
      if (DAT_ffffcd3a == '\x05') {
        return;
      }
    } while (palette_fade_done_0 == 0);
    return;
  }
  FUN_0000147a(in_A1, 0, 0);
  do {
    DAT_ffffcc56 = (short)unaff_D2;
  } while (DAT_ffffcc56 < 0);
  eVar3 = (entity_id_t)DAT_ffffcc56;
  entity_reset(eVar3);
  *(undefined2 *)((int)&comp_anim_tick + eVar3) = 0;
  *(undefined2 *)((int)&comp_anim_speed + eVar3) = 0x100;
  *(undefined2 *)((int)&comp_unk_3 + eVar3) = 8;
  (&comp_anim_base_offset)[eVar3] = DAT_ffffcd3b;
  (&comp_anim_b)[eVar3] = DAT_ffffcd3c;
  *(undefined2 *)((int)&comp_pos_x + eVar3) = DAT_ffffcd32;
  *(undefined2 *)((int)&comp_pos_y + eVar3) = DAT_ffffcd34;
  (&comp_has_func_maybe)[eVar3] = 0;
  ecs_anim_unk_2(eVar3, unaff_A5, 0);
  sVar1 = *(short *)((int)&comp_collision_sensor[0].y + eVar3);
  lVar2 = CONCAT22((short)((uint)unaff_D3 >> 0x10), sVar1);
  *(short *)((int)&comp_pos_y + eVar3) =
      *(short *)((int)&comp_pos_y + eVar3) - sVar1;
  FUN_0000d30a();
  FUN_0000d6f6();
  eVar3 = (entity_id_t)DAT_ffffcc56;
  (&comp_has_func_maybe)[eVar3] = 0;
  ecs_anim_unk_2(eVar3, unaff_A5, 2);
  uVar5 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar5 = exception_unk_0(unaff_A3,
                            eVar3,
                            pbVar4,
                            (long)((ulonglong)uVar5 >> 0x20),
                            (long)uVar5,
                            unaff_D2,
                            lVar2,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    eVar3 = (entity_id_t)DAT_ffffcc56;
  } while (*(short *)((int)&comp_anim_tick + eVar3) != 0);
  *(undefined2 *)((int)&comp_unk_3 + eVar3) = 0x12;
  (&comp_has_func_maybe)[eVar3] = 0;
  ecs_anim_unk_2(eVar3, unaff_A5, 4);
  uVar5 = CONCAT44(extraout_D0_00, extraout_D1_00);
  do {
    uVar5 = exception_unk_0(unaff_A3,
                            eVar3,
                            pbVar4,
                            (long)((ulonglong)uVar5 >> 0x20),
                            (long)uVar5,
                            unaff_D2,
                            lVar2,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    eVar3 = (entity_id_t)DAT_ffffcc56;
  } while (*(short *)((int)&comp_anim_tick + eVar3) != 0);
  FUN_0000d6b2();
  entity_reset((int)DAT_ffffcc56);
  DAT_ffffcc56 = 0;
  return;
}

void FUN_0000d30a(void)

{
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_BLACK_EASE_OUT,
                   '\x01',
                   (palette_color_iter_t)0xffffffff);
  uVar1 = FUN_0000c60a();
  if (DAT_ffffcbf4 != '\0') {
    uVar1 = FUN_0000ac92();
  }
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    if (DAT_ffffcd3a == '\x05') {
      return;
    }
  } while (palette_fade_done_0 == 0);
  return;
}

void FUN_0000d342(void)

{
  short sVar1;
  long lVar2;
  long extraout_D1;
  long lVar3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar4;

  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_WHITE_EASE_OUT,
                   '\x03',
                   (palette_color_iter_t)0xffffffff);
  FUN_00001630();
  uVar4 = FUN_0000c60a();
  if (DAT_ffffcbf4 != '\0') {
    FUN_0000ac92();
    lVar2 = 0xf;
    lVar3 = extraout_D1;
    do {
      uVar4 = exception_unk_0(unaff_A3,
                              unaff_A4,
                              unaff_A6,
                              lVar2,
                              lVar3,
                              0xf,
                              -1,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
      lVar3 = (long)uVar4;
      sVar1 = (short)lVar2 + -1;
      lVar2 = CONCAT22((short)((ulonglong)uVar4 >> 0x30), sVar1);
      uVar4 = CONCAT44(lVar2, lVar3);
    } while (-1 < sVar1);
  }
  comp_has_func_maybe = comp_has_func_maybe & 0xfc;
  do {
    uVar4 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar4 >> 0x20),
                            (long)uVar4,
                            0xf,
                            -1,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    if (DAT_ffffcd3a == '\x05') {
      return;
    }
  } while (palette_fade_done_0 == 0);
  return;
}

void FUN_0000d392(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  comp_has_func_maybe = 0;
  comp_anim_b = DAT_ffffcd3b;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, DAT_ffffcd3c);
  comp_has_func_maybe = comp_has_func_maybe | COMPONENT_STATE_B_ACTIVE;
  uVar1 = FUN_0000d30a();
  comp_has_func_maybe = comp_has_func_maybe & 0xfc;
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            ENTITY_ID_ASHA,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (comp_anim_tick != 0);
  return;
}

void FUN_0000d3ca(void)

{
  long extraout_D0;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  comp_has_func_maybe = 0;
  comp_anim_b = DAT_ffffcd3b;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, DAT_ffffcd3c);
  exception_unk_0(unaff_A3,
                  ENTITY_ID_ASHA,
                  unaff_A6,
                  extraout_D0,
                  extraout_D1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  comp_has_func_maybe = comp_has_func_maybe | COMPONENT_STATE_B_ACTIVE;
  uVar1 = FUN_0000d342();
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            ENTITY_ID_ASHA,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (comp_anim_tick != 0);
  return;
}

undefined8 FUN_0000d3fc(void)

{
  long extraout_D0;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  comp_has_func_maybe = 0;
  comp_state_a = comp_state_a & 0x88;
  ecs_holding_a_rope = 0;
  uint8_t_ffffcc70 = '\0';
  comp_anim_speed = 0x100;
  comp_anim_b = DAT_ffffcd3b;
  comp_state = COMP_STATE_STAND;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, DAT_ffffcd3c);
  exception_unk_0(unaff_A3,
                  ENTITY_ID_ASHA,
                  unaff_A6,
                  extraout_D0,
                  extraout_D1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  comp_has_func_maybe = comp_has_func_maybe | COMPONENT_STATE_B_ACTIVE;
  uVar1 = FUN_0000d30a();
  uVar1 = exception_unk_0(unaff_A3,
                          ENTITY_ID_ASHA,
                          unaff_A6,
                          (long)((ulonglong)uVar1 >> 0x20),
                          (long)uVar1,
                          unaff_D2,
                          unaff_D3,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar1;
}

void FUN_0000d442(void)

{
  byte state_1_b;
  long extraout_D0;
  undefined4 extraout_D0_00;
  undefined4 extraout_D0_01;
  long extraout_D1;
  undefined4 extraout_D1_00;
  undefined4 extraout_D1_01;
  long unaff_D2;
  short sVar2;
  uint uVar1;
  undefined4 unaff_D3;
  uint uVar3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  uint uVar4;
  long unaff_D7;
  uint uVar5;
  ushort uVar6;
  func *in_A1;
  func *extraout_A1;
  script_ctx_t *unaff_A3;
  entity_id_t e;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar7;

  if (DAT_ffffcd3e != (void *)0x0) {
    text_unk_1(DAT_ffffcd3e, in_A1);
    uncompress_and_copy_to_vram();
    in_A1 = extraout_A1;
  }
  FUN_0000147a(in_A1, 0, 0);
  sVar2 = (short)unaff_D2;
  if (-1 < sVar2) {
    e = (entity_id_t)sVar2;
    DAT_ffffcc56 = sVar2;
    entity_reset(e);
    *(short *)((int)&comp_pos_x + e) = DAT_ffffcd32;
    *(short *)((int)&comp_pos_y + e) = DAT_ffffcd34;
    (&comp_anim_base_offset)[e] = DAT_ffffcd3b;
    (&comp_anim_b)[e] = DAT_ffffcd3c;
    state_1_b = DAT_ffffcd3d;
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x12;
    ecs_anim_unk_2(e, unaff_A5, state_1_b);
    audio_play(SOUND_ID_DOOR);
    sVar2 = *(short *)((int)&comp_collision_sensor[0].y + e);
    *(short *)((int)&comp_pos_y + e) = *(short *)((int)&comp_pos_y + e) - sVar2;
    DAT_ffffcc4c = *(undefined2 *)((int)&comp_pos_y + e);
    DAT_ffffcc4a = *(undefined2 *)((int)&comp_pos_x + e);
    exception_unk_0(unaff_A3,
                    e,
                    unaff_A6,
                    extraout_D0,
                    extraout_D1,
                    unaff_D2,
                    CONCAT22((short)((uint)unaff_D3 >> 0x10), sVar2),
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar3 = (uint)(ushort)((ushort)DAT_ffffcd37 * 0x10);
    DAT_ffffcc3e = DAT_ffffcd32 + (ushort)DAT_ffffcd36 * -4;
    DAT_ffffcc40 = DAT_ffffcd34 + (ushort)DAT_ffffcd37 * -0x10;
    uVar4 = (uint)(ushort)(DAT_ffffcd37 - 1);
    do {
      uVar1 = (uint)DAT_ffffc717;
      uVar5 = (uint)(ushort)(DAT_ffffcd36 - 1);
      DAT_ffffcc3a = DAT_ffffcc3e;
      do {
        FUN_0000d57a();
        DAT_ffffcc3e = DAT_ffffcc3e + 0x10;
        uVar6 = (short)uVar5 - 1;
        uVar5 = (uint)uVar6;
      } while (uVar6 != 0xffff);
      DAT_ffffcc40 = DAT_ffffcc40 + 0x10;
      DAT_ffffcc3e = DAT_ffffcc3a;
      uVar6 = (short)uVar4 - 1;
      uVar4 = (uint)uVar6;
    } while (uVar6 != 0xffff);
    ecs_anim_unk_2(e, unaff_A5, 2);
    uVar7 = CONCAT44(extraout_D0_00, extraout_D1_00);
    do {
      uVar7 = exception_unk_0(unaff_A3,
                              e,
                              unaff_A6,
                              (long)((ulonglong)uVar7 >> 0x20),
                              (long)uVar7,
                              uVar1,
                              uVar3,
                              unaff_D4,
                              unaff_D5,
                              uVar4,
                              uVar5);
    } while (*(short *)((int)&comp_anim_tick + e) != 0);
    *(undefined2 *)((int)&comp_unk_3 + e) = 8;
    ecs_anim_unk_2(e, unaff_A5, 4);
    uVar7 = CONCAT44(extraout_D0_01, extraout_D1_01);
    do {
      uVar7 = exception_unk_0(unaff_A3,
                              e,
                              unaff_A6,
                              (long)((ulonglong)uVar7 >> 0x20),
                              (long)uVar7,
                              uVar1,
                              uVar3,
                              unaff_D4,
                              unaff_D5,
                              uVar4,
                              uVar5);
    } while (*(short *)((int)&comp_anim_tick + e) != 0);
  }
  return;
}

void FUN_0000d57a(void)

{
  void *vram_dst;
  word *extraout_A1;
  int extraout_A1_00;

  vram_dst = (void *)((DAT_ffffcc40 - 0x1000U & 0xf0) * 0x10 +
                      ((DAT_ffffcc3e - 0x1000U & 0x1f0) >> 2) + 0xc000);
  vdp_set_vram_write_addr(vram_dst);
  VDP_DATA = *extraout_A1;
  VDP_DATA = extraout_A1[1];
  vdp_set_vram_write_addr((void *)((short)vram_dst + 0x80));
  VDP_DATA = *(word *)(extraout_A1_00 + 4);
  VDP_DATA = *(word *)(extraout_A1_00 + 6);
  return;
}

void FUN_0000d5ca(void)

{
  undefined4 extraout_D0;
  undefined4 extraout_D0_00;
  undefined4 extraout_D1;
  undefined4 extraout_D1_00;
  long unaff_D2;
  short sVar1;
  undefined4 unaff_D3;
  long lVar2;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  func *in_A1;
  func *extraout_A1;
  script_ctx_t *unaff_A3;
  entity_id_t e;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar3;

  if (DAT_ffffcd3e != (void *)0x0) {
    text_unk_1(DAT_ffffcd3e, in_A1);
    uncompress_and_copy_to_vram();
    in_A1 = extraout_A1;
  }
  FUN_0000147a(in_A1, 0, 0);
  sVar1 = (short)unaff_D2;
  if (-1 < sVar1) {
    e = (entity_id_t)sVar1;
    DAT_ffffcc56 = sVar1;
    entity_reset(e);
    *(undefined2 *)((int)&comp_pos_x + e) = DAT_ffffcd32;
    *(undefined2 *)((int)&comp_pos_y + e) = DAT_ffffcd34;
    (&comp_anim_base_offset)[e] = DAT_ffffcd3b;
    (&comp_anim_b)[e] = DAT_ffffcd3c;
    *(undefined2 *)((int)&comp_unk_3 + e) = 8;
    (&comp_state_a)[e] = 0x80;
    ecs_anim_unk_2(e, unaff_A5, 2);
    audio_play(SOUND_ID_DOOR);
    uVar3 = CONCAT44(extraout_D0, extraout_D1);
    sVar1 = *(short *)((int)&comp_collision_sensor[0].y + e);
    lVar2 = CONCAT22((short)((uint)unaff_D3 >> 0x10), sVar1);
    *(short *)((int)&comp_pos_y + e) = *(short *)((int)&comp_pos_y + e) - sVar1;
    DAT_ffffcc4c = *(undefined2 *)((int)&comp_pos_y + e);
    DAT_ffffcc4a = *(undefined2 *)((int)&comp_pos_x + e);
    do {
      uVar3 = exception_unk_0(unaff_A3,
                              e,
                              unaff_A6,
                              (long)((ulonglong)uVar3 >> 0x20),
                              (long)uVar3,
                              unaff_D2,
                              lVar2,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
    } while (*(short *)((int)&comp_anim_tick + e) != 0);
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x12;
    ecs_anim_unk_2(e, unaff_A5, 4);
    uVar3 = CONCAT44(extraout_D0_00, extraout_D1_00);
    do {
      uVar3 = exception_unk_0(unaff_A3,
                              e,
                              unaff_A6,
                              (long)((ulonglong)uVar3 >> 0x20),
                              (long)uVar3,
                              unaff_D2,
                              lVar2,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
    } while (*(short *)((int)&comp_anim_tick + e) != 0);
  }
  return;
}

void FUN_0000d664(void)

{
  undefined1 *unaff_A5;

  DAT_ffffd17e = *unaff_A5;
  DAT_ffffd180 = unaff_A5[1];
  DAT_ffffd17f = unaff_A5[2];
  DAT_ffffd181 = unaff_A5[3];
  return;
}

void FUN_0000d676(void)

{
  byte *unaff_A5;

  DAT_ffffc71a = *unaff_A5 | 0x80;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000d682(void)

{
  undefined2 *unaff_A5;

  _DAT_ffffc792 = *unaff_A5;
  _DAT_ffffc794 = unaff_A5[1];
  DAT_ffffc71a = DAT_ffffc71a | 8;
  return;
}

void FUN_0000d69e(void)

{
  short *unaff_A5;

  DAT_ffffcbf0 = (int)unaff_A5 + (int)*unaff_A5;
  DAT_ffffcbf4 = 0xff;
  return;
}

void FUN_0000d6b2(void)

{
  short sVar1;
  short sVar2;
  short sVar3;

  sVar3 = DAT_ffffcd37 - 1;
  do {
    sVar2 = DAT_ffffcd36 - 1;
    do {
      sVar1 = FUN_0000d77e();
      if (sVar1 != 0) {
        FUN_0000d7a4();
      }
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
    sVar3 = sVar3 + -1;
  } while (sVar3 != -1);
  return;
}

void FUN_0000d6f6(void)

{
  short sVar1;
  short sVar2;
  short sVar3;

  sVar3 = DAT_ffffcd37 - 1;
  do {
    sVar2 = DAT_ffffcd36 - 1;
    do {
      sVar1 = FUN_0000d77e();
      if (sVar1 != 0) {
        FUN_0000d834();
      }
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
    sVar3 = sVar3 + -1;
  } while (sVar3 != -1);
  return;
}

void FUN_0000d73a(void)

{
  short sVar1;
  short sVar2;
  short sVar3;

  sVar3 = DAT_ffffcd37 - 1;
  do {
    sVar2 = DAT_ffffcd36 - 1;
    do {
      sVar1 = FUN_0000d77e();
      if (sVar1 != 0) {
        FUN_0000d8a4();
      }
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
    sVar3 = sVar3 + -1;
  } while (sVar3 != -1);
  return;
}

undefined4 FUN_0000d77e(void)

{
  undefined4 uVar1;
  ushort unaff_D4w;
  ushort unaff_D5w;

  uVar1 = 0;
  if ((((DAT_ffffc73a <= unaff_D4w) &&
        (unaff_D4w <= (ushort)(DAT_ffffc73a + 0x100))) &&
       (DAT_ffffc746 <= unaff_D5w)) &&
      (unaff_D5w <= (ushort)(DAT_ffffc746 + 0xe0))) {
    uVar1 = 1;
  }
  return uVar1;
}

void FUN_0000d7a4(void)

{
  void *vram_dst;
  short sVar1;
  ushort extraout_D0w;
  ushort extraout_D0w_00;
  ushort unaff_D4w;
  ushort unaff_D5w;

  sVar1 = (*(ushort *)((short)(((unaff_D5w & 0xff0) << (DAT_ffffc717 & 0x3f)) +
                               ((unaff_D4w & 0xff0) >> 3)) +
                       DAT_ffffc722) &
           0x3ff)
          << 3;
  vram_dst = (void *)((unaff_D5w - 0x1000 & 0xf8) * 0x10 +
                      ((unaff_D4w - 0x1000 & 0x1f8) >> 2) + 0xc000);
  vdp_set_vram_write_addr(vram_dst);
  VDP_DATA = extraout_D0w | *(ushort *)(&DAT_ffff4000 + sVar1);
  VDP_DATA = extraout_D0w | *(ushort *)(&DAT_ffff4002 + sVar1);
  vdp_set_vram_write_addr((void *)((short)vram_dst + 0x80));
  VDP_DATA = extraout_D0w_00 | *(ushort *)(&DAT_ffff4004 + sVar1);
  VDP_DATA = extraout_D0w_00 | *(ushort *)(&DAT_ffff4006 + sVar1);
  return;
}

void FUN_0000d834(void)

{
  void *vram_dst;
  ushort extraout_D0w;
  ushort extraout_D0w_00;
  short unaff_D4w;
  short unaff_D5w;

  vram_dst = (void *)((unaff_D5w - 0x1000U & 0xf8) * 0x10 +
                      ((unaff_D4w - 0x1000U & 0x1f8) >> 2) + 0xc000);
  vdp_set_vram_write_addr(vram_dst);
  VDP_DATA = extraout_D0w | uRamffff4010;
  VDP_DATA = extraout_D0w | uRamffff4012;
  vdp_set_vram_write_addr((void *)((short)vram_dst + 0x80));
  VDP_DATA = extraout_D0w_00 | uRamffff4014;
  VDP_DATA = extraout_D0w_00 | uRamffff4016;
  return;
}

void FUN_0000d8a4(void)

{
  void *vram_dst;
  ushort extraout_D0w;
  ushort extraout_D0w_00;
  short unaff_D4w;
  short unaff_D5w;

  vram_dst = (void *)((unaff_D5w - 0x1000U & 0xf8) * 0x10 +
                      ((unaff_D4w - 0x1000U & 0x1f8) >> 2) + 0xc000);
  vdp_set_vram_write_addr(vram_dst);
  VDP_DATA = extraout_D0w | uRamffff51b8;
  VDP_DATA = extraout_D0w | uRamffff51ba;
  vdp_set_vram_write_addr((void *)((short)vram_dst + 0x80));
  VDP_DATA = extraout_D0w_00 | uRamffff51bc;
  VDP_DATA = extraout_D0w_00 | uRamffff51be;
  return;
}

void FUN_0000d914(void)

{
  short *unaff_A5;

  DAT_ffffc714 = *unaff_A5 + -1;
  return;
}

void FUN_0000d922(void)

{
  int iVar1;
  byte *unaff_A5;

  iVar1 = (int)(short)((ushort)*unaff_A5 << 2);
  (&DAT_ffffcbf8)[iVar1] = 0x80;
  *(byte *)(iVar1 + -0x33e5) = *unaff_A5;
  *(undefined2 *)(&DAT_ffffcbfa + iVar1) = *(undefined2 *)(unaff_A5 + 1);
  *(byte *)(iVar1 + -0x3407) = unaff_A5[3];
  *(undefined2 *)(iVar1 + -0x33f8) = *(undefined2 *)(unaff_A5 + 4);
  *(undefined2 *)(iVar1 + -0x33f6) = *(undefined2 *)(unaff_A5 + 6);
  *(undefined2 *)(iVar1 + -0x33e8) = *(undefined2 *)(unaff_A5 + 8);
  *(undefined1 *)(iVar1 + -0x33e6) = 0;
  return;
}

void FUN_0000d968(void)

{
  uint uVar1;

  uVar1 = 0;
  do {
    (&DAT_ffffcbf8)[uVar1] = 0;
    uVar1 = uVar1 + 4;
  } while (uVar1 < 0x10);
  return;
}

void FUN_0000d97a(void)

{
  DAT_ffffcc28 = 0xff;
  return;
}

script_t audio_play_sound_ref_3(script_t script)

{
  audio_play_sound_asha_dies();
  UNION_sound_id_word_union_t_ffff97e6.as_byte = 0;
  UNION_sound_id_word_union_t_ffff97e6.as_word._1_1_ = *script;
  audio_play(*script);
  return script + 1;
}

void FUN_0000d992(void)

{
  FUN_0000d99c();
  FUN_0000d9e8();
  return;
}

void FUN_0000d99c(void)

{
  short sVar1;
  char unaff_D4b;
  short unaff_D5w;
  int unaff_A4;

  sVar1 = unaff_D5w * 4;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x1c;
  *(undefined2 *)((int)&comp_unk_8 + unaff_A4) = 0xffff;
  (&comp_anim_base_offset)[unaff_A4] = (&DAT_0007d1dc)[sVar1];
  (&comp_anim_b)[unaff_A4] = (&UNK_0007d1dd)[sVar1];
  (&comp_anim_c)[unaff_A4] = (&UNK_0007d1de)[sVar1];
  (&comp_collision_related)[unaff_A4] = (&UNK_0007d1df)[sVar1];
  (&comp_func_offset[0].func_offset_from_15ede)[unaff_A4] = unaff_D4b * '\x02';
  if (DAT_ffffcc28 != '\0') {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | 0x80;
    return;
  }
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & 0x7f;
  return;
}

void FUN_0000d9e8(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_1(unaff_A4, unaff_A5);
  (&comp_has_func_maybe)[unaff_A4] =
      (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
  (*(code *)((int)&WORD_0000da02 +
             (int)*(short *)((int)&WORD_0000da02 +
                             (int)(short)(ushort)(&comp_func_offset[0]
                                                       .func_offset_from_15ede)
                                 [unaff_A4])))();
  return;
}

void FUN_0000da3a(void)

{
  int unaff_A4;

  *(ushort *)((int)&comp_pos_x + unaff_A4) =
      *(short *)((int)&comp_collision_sensor[0].x + unaff_A4) +
          *(short *)((int)&comp_pos_x + unaff_A4) + 7 &
      0xfff8;
  *(ushort *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
          *(short *)((int)&comp_pos_y + unaff_A4) + 7 &
      0xfff8;
  return;
}

void ecs_do_somthing_for_entity_id_8_to_48(void)

{
  short i;
  entity_id_t self;

  self = ENTITY_ID_08;
  i = 10;
  do {
    if ((((&comp_has_func_maybe)[self] & 0x80) != 0) &&
        (-1 < *(char *)((int)&comp_state + self))) {
      (*(code *)((int)&WORD_0000da8c +
                 (int)*(
                     short *)((int)&WORD_0000da8c +
                              (int)(short)(ushort)(&comp_func_offset[0]
                                                        .func_offset_from_15ede)
                                  [self])))();
    }
    self = self + ENTITY_ID_PEPELOGOO;
    i = i + -1;
  } while (i != -1);
  return;
}

void FUN_0000dac4(void)

{
  ulong unaff_A4;

  *(undefined4 *)((int)component_pos_old_x + unaff_A4) =
      *(undefined4 *)((int)&comp_pos_x + unaff_A4);
  *(undefined4 *)((int)component_pos_old_y + unaff_A4) =
      *(undefined4 *)((int)&comp_pos_y + unaff_A4);
  player_update_pos(unaff_A4);
  return;
}

void FUN_0000dad6(void)

{
  int unaff_A4;

  (&comp_unk_10)[unaff_A4] = 0;
  *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  FUN_0000da3a();
  *(ushort *)(&comp_unk_1 + unaff_A4) =
      (ushort)((byte) * (undefined2 *)(&DAT_ffffb66e + unaff_A4) & 0xf0) << 2;
  return;
}

void FUN_0000dafe(void)

{
  short sVar1;
  uint uVar2;
  short extraout_D1w;
  int unaff_A4;

  uVar2 = FUN_0000dad6();
  sVar1 = *(short *)((int)&comp_pos_y + unaff_A4);
  if ((uVar2 & 8) == 0) {
    *(short *)(unaff_A4 + -0x4788) = sVar1;
    *(short *)(&DAT_ffffb876 + unaff_A4) = extraout_D1w + sVar1;
  } else {
    *(short *)(&DAT_ffffb876 + unaff_A4) = sVar1;
    *(short *)(unaff_A4 + -0x4788) = sVar1 - extraout_D1w;
  }
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  return;
}

void FUN_0000db2a(void)

{
  short sVar1;
  uint uVar2;
  short extraout_D1w;
  int unaff_A4;

  uVar2 = FUN_0000dad6();
  sVar1 = *(short *)((int)&comp_pos_x + unaff_A4);
  if ((uVar2 & 8) == 0) {
    *(short *)(unaff_A4 + -0x4788) = sVar1;
    *(short *)(&DAT_ffffb876 + unaff_A4) = extraout_D1w + sVar1;
  } else {
    *(short *)(&DAT_ffffb876 + unaff_A4) = sVar1;
    *(short *)(unaff_A4 + -0x4788) = sVar1 - extraout_D1w;
  }
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  return;
}

void FUN_0000db56(void)

{
  short sVar1;
  int unaff_A4;

  FUN_0000db2a();
  sVar1 = *(short *)(&comp_unk_1 + unaff_A4);
  if (((&DAT_ffffb66f)[unaff_A4] & 8) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  } else {
    sVar1 = -sVar1;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  }
  *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar1;
  return;
}

void FUN_0000db7a(entity_id_t self)

{
  FUN_0000dac4();
  (*(code *)((int)&WORD_0000db96 +
             (int)*(short *)((int)&WORD_0000db96 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + self))))();
  FUN_0000e75a();
  return;
}

void FUN_0000db9e(void)

{
  int unaff_A4;

  if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
      *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    *(undefined2 *)((int)&comp_pos_x + unaff_A4 + 2) = 0;
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 10;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

void FUN_0000dbc4(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
      *(ushort *)(unaff_A4 + -0x4788)) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
        *(undefined2 *)(unaff_A4 + -0x4788);
    *(undefined2 *)((int)&comp_pos_x + unaff_A4 + 2) = 0;
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 10;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  }
  return;
}

void FUN_0000dbea(void)

{
  int unaff_A4;

  *(short *)(&comp_unk_2 + unaff_A4) = *(short *)(&comp_unk_2 + unaff_A4) + -1;
  if (*(short *)(&comp_unk_2 + unaff_A4) < 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    *(short *)((int)&comp_vel[0].x + unaff_A4) =
        -*(short *)(&comp_unk_1 + unaff_A4);
  }
  return;
}

void FUN_0000dc06(void)

{
  int unaff_A4;

  *(short *)(&comp_unk_2 + unaff_A4) = *(short *)(&comp_unk_2 + unaff_A4) + -1;
  if (*(short *)(&comp_unk_2 + unaff_A4) < 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) =
        *(undefined2 *)(&comp_unk_1 + unaff_A4);
  }
  return;
}

void FUN_0000dc20(void)

{
  short sVar1;
  int unaff_A4;

  FUN_0000dafe();
  sVar1 = *(short *)(&comp_unk_1 + unaff_A4);
  if (((&DAT_ffffb66f)[unaff_A4] & 8) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  } else {
    sVar1 = -sVar1;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  }
  *(short *)((int)&comp_vel[0].y + unaff_A4) = sVar1;
  return;
}

void FUN_0000dc46(void)

{
  int unaff_A4;

  FUN_0000dac4();
  (*(code *)((int)&WORD_0000dc62 +
             (int)*(short *)((int)&WORD_0000dc62 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  FUN_0000e75a();
  return;
}

void FUN_0000dc6a(void)

{
  int unaff_A4;

  if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
      *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 10;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

void FUN_0000dc90(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
      *(ushort *)(unaff_A4 + -0x4788)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(unaff_A4 + -0x4788);
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 10;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  }
  return;
}

void FUN_0000dcb6(void)

{
  int unaff_A4;

  *(short *)(&comp_unk_2 + unaff_A4) = *(short *)(&comp_unk_2 + unaff_A4) + -1;
  if (*(short *)(&comp_unk_2 + unaff_A4) < 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    *(short *)((int)&comp_vel[0].y + unaff_A4) =
        -*(short *)(&comp_unk_1 + unaff_A4);
  }
  return;
}

void FUN_0000dcd2(void)

{
  int unaff_A4;

  *(short *)(&comp_unk_2 + unaff_A4) = *(short *)(&comp_unk_2 + unaff_A4) + -1;
  if (*(short *)(&comp_unk_2 + unaff_A4) < 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) =
        *(undefined2 *)(&comp_unk_1 + unaff_A4);
  }
  return;
}

void FUN_0000dcec(void)

{
  int unaff_A4;

  (&comp_unk_10)[unaff_A4] = 0;
  *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  FUN_0000da3a();
  *(ushort *)(&DAT_ffffb876 + unaff_A4) =
      ((*(ushort *)(&DAT_ffffb66e + unaff_A4) & 0xff00) >> 4) + 0xf80;
  *(short *)(&DAT_ffffb876 + unaff_A4) =
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
      *(short *)(&DAT_ffffb876 + unaff_A4);
  *(undefined2 *)(unaff_A4 + -0x4788) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  return;
}

void FUN_0000dd2c(void)

{
  int unaff_A4;

  FUN_0000dac4();
  (*(code *)((int)&WORD_0000dd48 +
             (int)*(short *)((int)&WORD_0000dd48 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  FUN_0000e75a();
  return;
}

void FUN_0000dd4e(void)

{
  char extraout_D1b;
  int unaff_A4;

  FUN_0000dda8();
  if (extraout_D1b != '\0') {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    FUN_0000ddd0();
  }
  return;
}

void FUN_0000dd68(void)

{
  char extraout_D1b;
  int unaff_A4;

  FUN_0000dda8();
  if (extraout_D1b == '\0') {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    FUN_0000de06();
  } else {
    FUN_0000ddd0();
  }
  return;
}

void FUN_0000dd88(void)

{
  char extraout_D1b;
  int unaff_A4;

  FUN_0000dda8();
  if (extraout_D1b == '\0') {
    FUN_0000de06();
  } else {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    FUN_0000ddd0();
  }
  return;
}

void FUN_0000dda8(void)

{
  return;
}

void FUN_0000ddd0(void)

{
  short *psVar1;
  int unaff_A4;

  if (*(ushort *)(unaff_A4 + -0x4788) < *(ushort *)(&DAT_ffffb876 + unaff_A4)) {
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + 0x40;
    if (0x200 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x200;
    }
  } else {
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + -0x40;
    if (*(short *)((int)&comp_vel[0].y + unaff_A4) < -0x200) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfe00;
    }
  }
  return;
}

void FUN_0000de06(void)

{
  short *psVar1;
  int unaff_A4;

  if (*(ushort *)(unaff_A4 + -0x4788) < *(ushort *)(&DAT_ffffb876 + unaff_A4)) {
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + -0x40;
    if (*(short *)((int)&comp_vel[0].y + unaff_A4) < -0x200) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfe00;
    }
  } else {
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + 0x40;
    if (0x200 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x200;
    }
  }
  return;
}

void FUN_0000de3c(void)

{
  FUN_0000db2a();
  return;
}

void FUN_0000de42(void)

{
  int unaff_A4;

  FUN_0000dac4();
  (*(code *)((int)&WORD_0000de5e +
             (int)*(short *)((int)&WORD_0000de5e +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  FUN_0000e75a();
  return;
}

void FUN_0000de68(void)

{
  int unaff_A4;
  bool bVar1;

  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar1) {
    if (*(short *)((int)&comp_pos_x + unaff_A4) ==
        *(short *)(&DAT_ffffb876 + unaff_A4)) {
      *(short *)((int)&comp_vel[0].x + unaff_A4) =
          -*(short *)(&comp_unk_1 + unaff_A4);
      *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    } else {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) =
          *(undefined2 *)(&comp_unk_1 + unaff_A4);
      *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    }
  }
  return;
}

void FUN_0000dea0(void)

{
  int unaff_A4;

  if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
      *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    *(undefined2 *)((int)&comp_pos_x + unaff_A4 + 2) = 0;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 10;
  }
  return;
}

void FUN_0000dec6(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
      *(ushort *)(unaff_A4 + -0x4788)) {
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
        *(undefined2 *)(unaff_A4 + -0x4788);
    *(undefined2 *)((int)&comp_pos_x + unaff_A4 + 2) = 0;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 8;
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 10;
  }
  return;
}

void FUN_0000deec(void)

{
  int unaff_A4;

  *(short *)(&comp_unk_2 + unaff_A4) = *(short *)(&comp_unk_2 + unaff_A4) + -1;
  if (*(short *)(&comp_unk_2 + unaff_A4) < 0) {
    *(short *)((int)&comp_vel[0].x + unaff_A4) =
        -*(short *)(&comp_unk_1 + unaff_A4);
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

void FUN_0000df08(void)

{
  int unaff_A4;

  *(short *)(&comp_unk_2 + unaff_A4) = *(short *)(&comp_unk_2 + unaff_A4) + -1;
  if (*(short *)(&comp_unk_2 + unaff_A4) < 0) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) =
        *(undefined2 *)(&comp_unk_1 + unaff_A4);
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  }
  return;
}

void FUN_0000df22(void)

{
  FUN_0000dafe();
  return;
}

void FUN_0000df28(void)

{
  int unaff_A4;

  FUN_0000dac4();
  (*(code *)((int)&WORD_0000df44 +
             (int)*(short *)((int)&WORD_0000df44 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  FUN_0000e75a();
  return;
}

void FUN_0000df4e(void)

{
  int unaff_A4;
  bool bVar1;

  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar1) {
    if (*(short *)((int)&comp_pos_y + unaff_A4) ==
        *(short *)(&DAT_ffffb876 + unaff_A4)) {
      *(short *)((int)&comp_vel[0].y + unaff_A4) =
          -*(short *)(&comp_unk_1 + unaff_A4);
      *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    } else {
      *(short *)((int)&comp_vel[0].y + unaff_A4) =
          *(short *)(&comp_unk_1 + unaff_A4);
      *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    }
  }
  return;
}

void FUN_0000df82(void)

{
  int unaff_A4;

  if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
      *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 10;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  }
  return;
}

void FUN_0000dfa8(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
      *(ushort *)(unaff_A4 + -0x4788)) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(unaff_A4 + -0x4788);
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 10;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 8;
  }
  return;
}

void FUN_0000dfce(void)

{
  int unaff_A4;

  *(short *)(&comp_unk_2 + unaff_A4) = *(short *)(&comp_unk_2 + unaff_A4) + -1;
  if (*(short *)(&comp_unk_2 + unaff_A4) < 0) {
    *(short *)((int)&comp_vel[0].y + unaff_A4) =
        -*(short *)(&comp_unk_1 + unaff_A4);
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

void FUN_0000dfea(void)

{
  int unaff_A4;

  *(short *)(&comp_unk_2 + unaff_A4) = *(short *)(&comp_unk_2 + unaff_A4) + -1;
  if (*(short *)(&comp_unk_2 + unaff_A4) < 0) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) =
        *(undefined2 *)(&comp_unk_1 + unaff_A4);
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  }
  return;
}

void FUN_0000e002(void)

{
  int unaff_A4;

  FUN_0000db2a();
  if (*(short *)((int)&comp_pos_x + unaff_A4) ==
      *(short *)(&DAT_ffffb876 + unaff_A4)) {
    *(undefined2 *)(&DAT_ffffb876 + unaff_A4) =
        *(undefined2 *)(unaff_A4 + -0x4788);
  }
  return;
}

void FUN_0000e018(void)

{
  int unaff_A4;

  FUN_0000dac4();
  (*(code *)((int)&WORD_0000e034 +
             (int)*(short *)((int)&WORD_0000e034 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  FUN_0000e75a();
  return;
}

void FUN_0000e03c(void)

{
  short sVar1;
  int unaff_A4;
  bool bVar2;

  bVar2 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar2) {
    sVar1 = *(short *)(&comp_unk_1 + unaff_A4);
    if (*(ushort *)((int)&comp_pos_x + unaff_A4) <
        *(ushort *)(&DAT_ffffb876 + unaff_A4)) {
      *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar1;
      *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    } else {
      *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
          *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
      *(undefined2 *)((int)&comp_pos_x + unaff_A4 + 2) = 0;
      *(short *)((int)&comp_vel[0].x + unaff_A4) = -sVar1;
      *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    }
  }
  return;
}

void FUN_0000e07a(void)

{
  int unaff_A4;

  if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
      *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    *(undefined2 *)((int)&comp_pos_x + unaff_A4 + 2) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  }
  return;
}

void FUN_0000e09a(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
      *(ushort *)(&DAT_ffffb876 + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    *(undefined2 *)((int)&comp_pos_x + unaff_A4 + 2) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  }
  return;
}

void FUN_0000e0ba(void)

{
  return;
}

void FUN_0000e0bc(void)

{
  int unaff_A4;

  FUN_0000dafe();
  if (*(short *)((int)&comp_pos_y + unaff_A4) ==
      *(short *)(&DAT_ffffb876 + unaff_A4)) {
    *(undefined2 *)(&DAT_ffffb876 + unaff_A4) =
        *(undefined2 *)(unaff_A4 + -0x4788);
  }
  return;
}

void FUN_0000e0d2(void)

{
  int unaff_A4;

  (*(code *)((int)&WORD_0000e0ea +
             (int)*(short *)((int)&WORD_0000e0ea +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  FUN_0000e74a();
  return;
}

void FUN_0000e0f2(void)

{
  int unaff_A4;
  bool bVar1;

  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar1) {
    if (*(ushort *)((int)&comp_pos_y + unaff_A4) <
        *(ushort *)(&DAT_ffffb876 + unaff_A4)) {
      *(short *)((int)&comp_vel[0].y + unaff_A4) =
          *(short *)(&comp_unk_1 + unaff_A4);
      *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    } else {
      *(short *)((int)&comp_vel[0].y + unaff_A4) =
          -*(short *)(&comp_unk_1 + unaff_A4);
      *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    }
  }
  return;
}

void FUN_0000e126(void)

{
  int unaff_A4;

  if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
      *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  return;
}

void FUN_0000e146(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
      *(ushort *)(&DAT_ffffb876 + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  return;
}

void FUN_0000e166(void)

{
  return;
}

void FUN_0000e168(void)

{
  int unaff_A4;

  (&comp_unk_10)[unaff_A4] = 0;
  FUN_0000da3a();
  *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  *(undefined *)(unaff_A4 + -0x4788) = (&DAT_ffffb66e)[unaff_A4];
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 4;
  return;
}

void FUN_0000e18e(void)

{
  int unaff_A4;

  (*(code *)((int)&WORD_0000e1a2 +
             (int)*(short *)((int)&WORD_0000e1a2 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  return;
}

void FUN_0000e1a6(entity_id_t self, entity_id_t other)

{
  bool bVar1;

  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + self));
  if (bVar1) {
    FUN_0000e74a();
  } else {
    (&comp_has_func_maybe)[self] = 0;
    FUN_0000e898(self, other);
    audio_play(SOUND_ID_JUNGLE_5);
  }
  return;
}

void FUN_0000e1ca(void)

{
  return;
}

void FUN_0000e1cc(void)

{
  ushort uVar1;
  int unaff_A4;

  (&comp_unk_10)[unaff_A4] = 0;
  *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  FUN_0000da3a();
  uVar1 = (*(ushort *)(&DAT_ffffb66e + unaff_A4) & 0xff00) >> 7;
  *(undefined2 *)(&comp_unk_1 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  *(ushort *)(unaff_A4 + -0x4788) = uVar1;
  *(ushort *)(&DAT_ffffb876 + unaff_A4) = uVar1;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  return;
}

void FUN_0000e1fa(void)

{
  int unaff_A4;

  (*(code *)((int)&WORD_0000e212 +
             (int)*(short *)((int)&WORD_0000e212 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  FUN_0000e74a();
  return;
}

void FUN_0000e21c(void)

{
  int unaff_A4;
  bool bVar1;

  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar1) {
    *(undefined2 *)(&DAT_ffffb876 + unaff_A4) =
        *(undefined2 *)(unaff_A4 + -0x4788);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfe00;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  }
  return;
}

void FUN_0000e23c(void)

{
  int unaff_A4;

  *(short *)(&DAT_ffffb876 + unaff_A4) =
      *(short *)(&DAT_ffffb876 + unaff_A4) + -1;
  if (*(short *)(&DAT_ffffb876 + unaff_A4) < 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    *(undefined2 *)(&DAT_ffffb876 + unaff_A4) = 0x1e;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  return;
}

void FUN_0000e258(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = *(short *)(&DAT_ffffb876 + unaff_A4) + -1;
  *(short *)(&DAT_ffffb876 + unaff_A4) = sVar1;
  if (sVar1 < 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  }
  return;
}

void FUN_0000e266(void)

{
  short *psVar1;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x20;
  if (0x5ff < *(ushort *)((int)&comp_vel[0].y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x600;
  }
  if ((uint) * (ushort *)(&comp_unk_1 + unaff_A4) * 0x10000 <=
      (uint)(*(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
             *(int *)((int)&comp_pos_y + unaff_A4))) {
    *(ushort *)((int)&comp_vel[0].y + unaff_A4) =
        (ushort)((uint) * (ushort *)(&comp_unk_1 + unaff_A4) * 0x10000 -
                     *(int *)((int)&comp_pos_y + unaff_A4) >>
                 8) &
        0xff;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 8;
  }
  return;
}

void FUN_0000e2a8(void)

{
  int unaff_A4;

  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  script_state_set_false(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  return;
}

void FUN_0000e2be(void)

{
  int unaff_A4;
  bool bVar1;

  FUN_0000dafe();
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar1) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(unaff_A4 + -0x4788);
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

void FUN_0000e2e4(void)

{
  int unaff_A4;

  (*(code *)((int)&WORD_0000e2fc +
             (int)*(short *)((int)&WORD_0000e2fc +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  FUN_0000e74a();
  return;
}

void FUN_0000e306(void)

{
  int unaff_A4;
  bool bVar1;

  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar1) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff00;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  }
  return;
}

void FUN_0000e324(void)

{
  int unaff_A4;

  if (*(short *)((int)&comp_pos_y + unaff_A4) ==
      *(short *)(unaff_A4 + -0x4788)) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  return;
}

void FUN_0000e33a(void)

{
  int unaff_A4;

  if (((component_unknown_5 & 4) != 0) &&
      (*(word *)((int)&comp_unk_8 + unaff_A4) == component_unknown_9)) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x200;
  }
  return;
}

void FUN_0000e35c(void)

{
  short *psVar1;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + -0x40;
  if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 8;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff00;
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
  }
  return;
}

void FUN_0000e37e(void)

{
  int unaff_A4;

  if ((*(short *)((int)&comp_pos_y + unaff_A4) ==
       *(short *)(unaff_A4 + -0x4788)) &&
      ((*(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0,
        (component_unknown_5 & 4) == 0 ||
            (*(word *)((int)&comp_unk_8 + unaff_A4) != component_unknown_9)))) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

void FUN_0000e3a8(void)

{
  short sVar1;
  int unaff_A4;

  (&comp_unk_10)[unaff_A4] = 0;
  FUN_0000da3a();
  *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  sVar1 = *(short *)((int)&comp_pos_y + unaff_A4);
  *(short *)(unaff_A4 + -0x4788) = sVar1;
  *(ushort *)(&DAT_ffffb876 + unaff_A4) =
      sVar1 + (ushort)(byte)(&DAT_ffffb66e)[unaff_A4] * 0x10;
  return;
}

void FUN_0000e3ce(void)

{
  int unaff_A4;

  (*(code *)((int)&WORD_0000e3e6 +
             (int)*(short *)((int)&WORD_0000e3e6 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  FUN_0000e74a();
  return;
}

void FUN_0000e3ea(void)

{
  int unaff_A4;

  if ((((short)*(word *)((int)&comp_unk_8 + unaff_A4) < 0) ||
       ((component_unknown_5 & 4) == 0)) ||
      (*(word *)((int)&comp_unk_8 + unaff_A4) != component_unknown_9)) {
    if (*(short *)((int)&comp_pos_y + unaff_A4) ==
        *(short *)(unaff_A4 + -0x4788)) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    } else {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff00;
    }
  } else {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x100;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  }
  return;
}

void FUN_0000e426(void)

{
  int unaff_A4;

  if ((((short)*(word *)((int)&comp_unk_8 + unaff_A4) < 0) ||
       ((component_unknown_5 & 4) == 0)) ||
      (*(word *)((int)&comp_unk_8 + unaff_A4) != component_unknown_9)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff00;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  } else if (*(short *)((int)&comp_pos_y + unaff_A4) ==
             *(short *)(&DAT_ffffb876 + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  return;
}

void FUN_0000e45a(void)

{
  undefined2 uVar1;
  int unaff_A4;

  *(ushort *)(unaff_A4 + -0x4788) =
      (*(ushort *)(&DAT_ffffb66e + unaff_A4) & 0xf00) >> 4;
  *(ushort *)(&DAT_ffffb876 + unaff_A4) =
      ((*(ushort *)(&DAT_ffffb66e + unaff_A4) & 0xf000) >> 8) - 1;
  (&comp_unk_10)[unaff_A4] = 0;
  *(short *)((int)&comp_pos_x + unaff_A4) =
      (*(short *)((int)&comp_collision_sensor[0].x + unaff_A4) + 7U & 0xfff8) +
      *(short *)((int)&comp_pos_x + unaff_A4);
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
      *(short *)((int)&comp_pos_y + unaff_A4);
  uVar1 = *(undefined2 *)(unaff_A4 + -0x4788);
  *(undefined2 *)(&comp_unk_1 + unaff_A4) = 0;
  *(undefined2 *)(unaff_A4 + -0x408a) = uVar1;
  *(undefined2 *)(&DAT_ffffbc76 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  *(undefined2 *)(&DAT_ffffbc78 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  (&comp_unk_11)[unaff_A4] = 0;
  (&comp_unk_4)[unaff_A4] = 0;
  *(undefined2 *)(&comp_unk_2 + unaff_A4) = 0;
  *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  return;
}

void FUN_0000e4ca(void)

{
  int unaff_A4;

  (*(code *)((int)&WORD_0000e4da +
             (int)*(short *)((int)&WORD_0000e4da +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  return;
}

void FUN_0000e4e2(void)

{
  short sVar1;
  ushort uVar2;
  short sVar3;
  int unaff_A4;
  int unaff_A5;

  sVar1 = *(short *)(unaff_A4 + -0x408a);
  *(int *)(unaff_A4 + -0x408a) =
      *(short *)(&comp_unk_2 + unaff_A4) * 0x100 + *(int *)(unaff_A4 + -0x408a);
  uVar2 = *(ushort *)(unaff_A4 + -0x4788);
  sVar3 = *(short *)(&comp_unk_2 + unaff_A4) + -0x10;
  if (sVar3 < -0x200) {
    sVar3 = -0x180;
  }
  *(short *)(&comp_unk_2 + unaff_A4) = sVar3;
  if (*(ushort *)(unaff_A4 + -0x408a) <= uVar2) {
    *(undefined2 *)(&comp_unk_1 + unaff_A4) = 0;
    *(ushort *)(unaff_A4 + -0x408a) = uVar2;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    (&DAT_ffffb978)[unaff_A4] = 0x20;
    (&DAT_ffffb979)[unaff_A4] = 0xff;
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 0;
  }
  FUN_0000e6a6();
  FUN_0000e74a();
  *(short *)(&DAT_ffffd21c + unaff_A5) = sVar1 - *(short *)(unaff_A4 + -0x408a);
  return;
}

void FUN_0000e54c(void)

{
  short sVar1;
  short sVar2;
  int unaff_A4;
  int unaff_A5;

  sVar1 = *(short *)(unaff_A4 + -0x408a);
  *(int *)(unaff_A4 + -0x408a) =
      *(short *)(&comp_unk_2 + unaff_A4) * 0x100 + *(int *)(unaff_A4 + -0x408a);
  sVar2 = *(short *)(&comp_unk_2 + unaff_A4) + 0x10;
  if (0x300 < sVar2) {
    sVar2 = 0x300;
  }
  *(short *)(&comp_unk_2 + unaff_A4) = sVar2;
  if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
      *(ushort *)(unaff_A4 + -0x408a)) {
    *(undefined2 *)(&comp_unk_1 + unaff_A4) = 0;
    *(ushort *)(unaff_A4 + -0x408a) = *(ushort *)(&DAT_ffffb876 + unaff_A4);
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 0;
    (&DAT_ffffb978)[unaff_A4] = 0x20;
    (&DAT_ffffb979)[unaff_A4] = 0;
  }
  FUN_0000e6a6();
  FUN_0000e74a();
  *(short *)(&DAT_ffffd21c + unaff_A5) = sVar1 - *(short *)(unaff_A4 + -0x408a);
  return;
}

void FUN_0000e5b6(void)

{
  short sVar1;
  char cVar2;
  int unaff_A4;
  int unaff_A5;

  cVar2 = (&DAT_ffffb978)[unaff_A4] + -1;
  (&DAT_ffffb978)[unaff_A4] = cVar2;
  if (cVar2 == '\0') {
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  } else if ((char)(&DAT_ffffb979)[unaff_A4] < '\0') {
    *(short *)(&comp_unk_2 + unaff_A4) =
        *(short *)(&comp_unk_2 + unaff_A4) + 0x20;
    if (0x80 < *(short *)(&comp_unk_2 + unaff_A4)) {
      (&DAT_ffffb979)[unaff_A4] = 0;
      *(undefined2 *)(&comp_unk_2 + unaff_A4) = 0x80;
    }
  } else {
    *(short *)(&comp_unk_2 + unaff_A4) =
        *(short *)(&comp_unk_2 + unaff_A4) + -0x20;
    if (*(short *)(&comp_unk_2 + unaff_A4) < -0x80) {
      *(undefined2 *)(&comp_unk_2 + unaff_A4) = 0xff80;
      (&DAT_ffffb979)[unaff_A4] = 0xff;
    }
  }
  sVar1 = *(short *)(unaff_A4 + -0x408a);
  *(int *)(unaff_A4 + -0x408a) =
      *(short *)(&comp_unk_2 + unaff_A4) * 0x100 + *(int *)(unaff_A4 + -0x408a);
  FUN_0000e6a6();
  FUN_0000e74a();
  *(short *)(&DAT_ffffd21c + unaff_A5) = sVar1 - *(short *)(unaff_A4 + -0x408a);
  return;
}

void FUN_0000e62e(void)

{
  short sVar1;
  char cVar2;
  int unaff_A4;
  int unaff_A5;

  cVar2 = (&DAT_ffffb978)[unaff_A4] + -1;
  (&DAT_ffffb978)[unaff_A4] = cVar2;
  if (cVar2 == '\0') {
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  } else if ((char)(&DAT_ffffb979)[unaff_A4] < '\0') {
    *(short *)(&comp_unk_2 + unaff_A4) =
        *(short *)(&comp_unk_2 + unaff_A4) + 0x20;
    if (0x80 < *(short *)(&comp_unk_2 + unaff_A4)) {
      (&DAT_ffffb979)[unaff_A4] = 0;
      *(undefined2 *)(&comp_unk_2 + unaff_A4) = 0x80;
    }
  } else {
    *(short *)(&comp_unk_2 + unaff_A4) =
        *(short *)(&comp_unk_2 + unaff_A4) + -0x20;
    if (*(short *)(&comp_unk_2 + unaff_A4) < -0x80) {
      *(undefined2 *)(&comp_unk_2 + unaff_A4) = 0xff80;
      (&DAT_ffffb979)[unaff_A4] = 0xff;
    }
  }
  sVar1 = *(short *)(unaff_A4 + -0x408a);
  *(int *)(unaff_A4 + -0x408a) =
      *(short *)(&comp_unk_2 + unaff_A4) * 0x100 + *(int *)(unaff_A4 + -0x408a);
  FUN_0000e6a6();
  FUN_0000e74a();
  *(short *)(&DAT_ffffd21c + unaff_A5) = sVar1 - *(short *)(unaff_A4 + -0x408a);
  return;
}

void FUN_0000e6a6(void)

{
  byte bVar1;
  ushort uVar2;
  byte bVar3;
  byte bVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  uVar2 = *(ushort *)(unaff_A4 - 0x408a);
  if (uVar2 < *(ushort *)(unaff_A4 - 0x4788)) {
    uVar2 = *(ushort *)(unaff_A4 - 0x4788);
  }
  if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <= uVar2) {
    uVar2 = *(ushort *)(&DAT_ffffb876 + unaff_A4);
  }
  *(ushort *)(unaff_A4 - 0x408a) = uVar2;
  *(ushort *)((int)&comp_pos_y + unaff_A4) =
      *(short *)(&DAT_ffffbc78 + unaff_A4) - (uVar2 + ((uVar2 >> 4) + 1) * -8);
  *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
      *(undefined2 *)(&DAT_ffffbc76 + unaff_A4);
  bVar1 = (&BYTE_0000e72c)[(short)(uVar2 >> 4)];
  (&comp_unk_4)[unaff_A4] = (&comp_unk_4)[unaff_A4] + -1;
  if (((&comp_unk_4)[unaff_A4] == '\0') ||
      ((char)(&comp_unk_4)[unaff_A4] < '\0')) {
    bVar3 = (&comp_unk_11)[unaff_A4] + 1;
    bVar4 = (&BYTE_0000e734)[(short)(ushort)bVar3];
    if (bVar4 == 0) {
      bVar3 = 0;
      bVar4 = 5;
    }
    (&comp_unk_11)[unaff_A4] = bVar3;
    (&comp_unk_4)[unaff_A4] = bVar4;
  }
  ecs_anim_unk_2(unaff_A4, unaff_A5, (&comp_unk_11)[unaff_A4] * '\x02' + bVar1);
  return;
}

void FUN_0000e738(void)

{
  short sVar1;
  int iVar2;

  sVar1 = 0xf;
  iVar2 = 0;
  do {
    (&DAT_ffffd19a)[iVar2] = 0;
    iVar2 = iVar2 + 4;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return;
}

void FUN_0000e74a(void)

{
  short sVar1;
  char unaff_D2b;
  entity_id_t unaff_A4;
  int unaff_A5;

  *(undefined4 *)((int)component_pos_old_x + unaff_A4) =
      *(undefined4 *)((int)&comp_pos_x + unaff_A4);
  *(undefined4 *)((int)component_pos_old_y + unaff_A4) =
      *(undefined4 *)((int)&comp_pos_y + unaff_A4);
  player_update_pos(unaff_A4);
  FUN_0000e858(unaff_A4);
  FUN_0000e80a();
  if (unaff_D2b == '\0') {
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] & 0xf7;
    sVar1 = *(short *)((int)&comp_pos_x + unaff_A4);
    *(short *)(&DAT_ffffd1da + unaff_A5) = sVar1;
    *(short *)(&DAT_ffffd21a + unaff_A5) =
        sVar1 - *(short *)((int)component_pos_old_x + unaff_A4);
    sVar1 = *(short *)((int)&comp_pos_y + unaff_A4);
    *(short *)(&DAT_ffffd1dc + unaff_A5) = sVar1;
    *(short *)(&DAT_ffffd21c + unaff_A5) =
        sVar1 - *(short *)((int)component_pos_old_y + unaff_A4);
    *(undefined2 *)(&DAT_ffffd25a + unaff_A5) =
        *(undefined2 *)((int)&comp_collision_sensor[0].x + unaff_A4);
    *(undefined2 *)(&DAT_ffffd25c + unaff_A5) =
        *(undefined2 *)((int)&comp_collision_sensor[0].y + unaff_A4);
    (&DAT_ffffd29d)[unaff_A5] = (&DAT_ffffd29c)[unaff_A5];
    (&DAT_ffffd29c)[unaff_A5] = 0;
    if ((&comp_collision_related)[unaff_A4] == '\x02') {
      (&DAT_ffffd19b)[unaff_A5] = 0xff;
    } else {
      (&DAT_ffffd19b)[unaff_A5] = 0;
    }
    if ((((&comp_collision_related)[unaff_A4] == '\x0e') ||
         ((&comp_collision_related)[unaff_A4] == '\x10')) ||
        ((&comp_collision_related)[unaff_A4] == '\x04')) {
      (&DAT_ffffd19a)[unaff_A5] = 0x80;
    } else {
      (&DAT_ffffd19a)[unaff_A5] = 0x81;
    }
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      (&DAT_ffffd19a)[unaff_A5] = (&DAT_ffffd19a)[unaff_A5] | 2;
    }
  } else {
    (&DAT_ffffd19a)[unaff_A5] = 0;
    *(undefined2 *)((int)&comp_unk_8 + unaff_A4) = 0xffff;
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 8;
  }
  return;
}

void FUN_0000e75a(void)

{
  short sVar1;
  char unaff_D2b;
  entity_id_t unaff_A4;
  int unaff_A5;

  FUN_0000e858(unaff_A4);
  FUN_0000e80a();
  if (unaff_D2b == '\0') {
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] & 0xf7;
    sVar1 = *(short *)((int)&comp_pos_x + unaff_A4);
    *(short *)(&DAT_ffffd1da + unaff_A5) = sVar1;
    *(short *)(&DAT_ffffd21a + unaff_A5) =
        sVar1 - *(short *)((int)component_pos_old_x + unaff_A4);
    sVar1 = *(short *)((int)&comp_pos_y + unaff_A4);
    *(short *)(&DAT_ffffd1dc + unaff_A5) = sVar1;
    *(short *)(&DAT_ffffd21c + unaff_A5) =
        sVar1 - *(short *)((int)component_pos_old_y + unaff_A4);
    *(undefined2 *)(&DAT_ffffd25a + unaff_A5) =
        *(undefined2 *)((int)&comp_collision_sensor[0].x + unaff_A4);
    *(undefined2 *)(&DAT_ffffd25c + unaff_A5) =
        *(undefined2 *)((int)&comp_collision_sensor[0].y + unaff_A4);
    (&DAT_ffffd29d)[unaff_A5] = (&DAT_ffffd29c)[unaff_A5];
    (&DAT_ffffd29c)[unaff_A5] = 0;
    if ((&comp_collision_related)[unaff_A4] == '\x02') {
      (&DAT_ffffd19b)[unaff_A5] = 0xff;
    } else {
      (&DAT_ffffd19b)[unaff_A5] = 0;
    }
    if ((((&comp_collision_related)[unaff_A4] == '\x0e') ||
         ((&comp_collision_related)[unaff_A4] == '\x10')) ||
        ((&comp_collision_related)[unaff_A4] == '\x04')) {
      (&DAT_ffffd19a)[unaff_A5] = 0x80;
    } else {
      (&DAT_ffffd19a)[unaff_A5] = 0x81;
    }
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      (&DAT_ffffd19a)[unaff_A5] = (&DAT_ffffd19a)[unaff_A5] | 2;
    }
  } else {
    (&DAT_ffffd19a)[unaff_A5] = 0;
    *(undefined2 *)((int)&comp_unk_8 + unaff_A4) = 0xffff;
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 8;
  }
  return;
}

void FUN_0000e7fc(void)

{
  do {
    // WARNING: Do nothing block with infinite loop
  } while (true);
}

// WARNING: Removing unreachable block (ram,0x0000e766)

void FUN_0000e800(void)

{
  short sVar1;
  entity_id_t unaff_A4;
  int unaff_A5;

  FUN_0000e858(unaff_A4);
  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] & 0xf7;
  sVar1 = *(short *)((int)&comp_pos_x + unaff_A4);
  *(short *)(&DAT_ffffd1da + unaff_A5) = sVar1;
  *(short *)(&DAT_ffffd21a + unaff_A5) =
      sVar1 - *(short *)((int)component_pos_old_x + unaff_A4);
  sVar1 = *(short *)((int)&comp_pos_y + unaff_A4);
  *(short *)(&DAT_ffffd1dc + unaff_A5) = sVar1;
  *(short *)(&DAT_ffffd21c + unaff_A5) =
      sVar1 - *(short *)((int)component_pos_old_y + unaff_A4);
  *(undefined2 *)(&DAT_ffffd25a + unaff_A5) =
      *(undefined2 *)((int)&comp_collision_sensor[0].x + unaff_A4);
  *(undefined2 *)(&DAT_ffffd25c + unaff_A5) =
      *(undefined2 *)((int)&comp_collision_sensor[0].y + unaff_A4);
  (&DAT_ffffd29d)[unaff_A5] = (&DAT_ffffd29c)[unaff_A5];
  (&DAT_ffffd29c)[unaff_A5] = 0;
  if ((&comp_collision_related)[unaff_A4] == '\x02') {
    (&DAT_ffffd19b)[unaff_A5] = 0xff;
  } else {
    (&DAT_ffffd19b)[unaff_A5] = 0;
  }
  if ((((&comp_collision_related)[unaff_A4] == '\x0e') ||
       ((&comp_collision_related)[unaff_A4] == '\x10')) ||
      ((&comp_collision_related)[unaff_A4] == '\x04')) {
    (&DAT_ffffd19a)[unaff_A5] = 0x80;
  } else {
    (&DAT_ffffd19a)[unaff_A5] = 0x81;
  }
  if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
    (&DAT_ffffd19a)[unaff_A5] = (&DAT_ffffd19a)[unaff_A5] | 2;
  }
  return;
}

void FUN_0000e80a(void)

{
  return;
}

undefined2 FUN_0000e858(entity_id_t self)

{
  short sVar1;
  int iVar2;

  if (((-1 < *(short *)((int)&comp_unk_8 + self)) &&
       ((char)(&DAT_ffffd19a)[*(short *)((int)&comp_unk_8 + self)] < '\0')) &&
      ((short)self == *(short *)((int)&DAT_ffffd29a +
                                 (int)*(short *)((int)&comp_unk_8 + self)))) {
    return 0;
  }
  iVar2 = 0;
  sVar1 = 0xf;
  do {
    if (-1 < (char)(&DAT_ffffd19a)[iVar2]) {
      *(short *)((int)&DAT_ffffd29a + iVar2) = (short)self;
      *(short *)((int)&comp_unk_8 + self) = (short)iVar2;
      return 0;
    }
    iVar2 = iVar2 + 4;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return 0xffff;
}

void FUN_0000e898(entity_id_t self, entity_id_t other)

{
  short sVar1;

  sVar1 = FUN_0000e858(self);
  if (-1 < sVar1) {
    (&DAT_ffffd19a)[other] = 0;
    *(undefined2 *)((int)&comp_unk_8 + self) = 0xffff;
  }
  return;
}

void FUN_0000e8ae(void)

{
  short sVar1;
  int iVar2;

  iVar2 = 8;
  sVar1 = 10;
  do {
    (&comp_has_func_maybe)[iVar2] = 0;
    iVar2 = iVar2 + 4;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return;
}

void FUN_0000e8c0(void)

{
  int unaff_A4;

  FUN_0000db2a();
  *(undefined2 *)(&DAT_ffffbc78 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  if (((&DAT_ffffb66f)[unaff_A4] & 8) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  } else {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  }
  return;
}

void FUN_0000e8e2(void)

{
  int unaff_A4;

  FUN_0000dac4();
  (*(code *)((int)&WORD_0000e8fa +
             (int)*(short *)((int)&WORD_0000e8fa +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  FUN_0000e75a();
  return;
}

void FUN_0000e902(void)

{
  int unaff_A4;

  FUN_0000e9c4();
  if (((component_unknown_5 & 4) != 0) &&
      (*(word *)((int)&comp_unk_8 + unaff_A4) == component_unknown_9)) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x180;
  }
  return;
}

void FUN_0000e928(void)

{
  short *psVar1;
  int unaff_A4;

  FUN_0000e9c4();
  if (((component_unknown_5 & 4) == 0) ||
      (*(word *)((int)&comp_unk_8 + unaff_A4) != component_unknown_9)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  } else {
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + -0x40;
    if (*(short *)((int)&comp_vel[0].y + unaff_A4) == 0) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff40;
      *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    }
  }
  return;
}

void FUN_0000e966(void)

{
  short *psVar1;
  short sVar2;
  int unaff_A4;

  FUN_0000e9c4();
  if (((component_unknown_5 & 4) != 0) &&
      (*(word *)((int)&comp_unk_8 + unaff_A4) == component_unknown_9)) {
    if ((*(short *)((int)&comp_vel[0].y + unaff_A4) == 0) ||
        (psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4),
         sVar2 = *psVar1 + 0x40,
         *psVar1 = sVar2,
         -1 < sVar2)) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    }
    return;
  }
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  return;
}

void FUN_0000e99e(void)

{
  short *psVar1;
  int unaff_A4;

  FUN_0000e9c4();
  if (*(ushort *)(&DAT_ffffbc78 + unaff_A4) <
      *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + -0x20;
  } else {
    *(ushort *)((int)&comp_pos_y + unaff_A4) =
        *(ushort *)(&DAT_ffffbc78 + unaff_A4);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  }
  return;
}

void FUN_0000e9c4(void)

{
  short *psVar1;
  short sVar2;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  if (*psVar1 != 0) {
    if (*psVar1 < 0) {
      if (*(ushort *)((int)&comp_pos_x + unaff_A4) <
          *(ushort *)(unaff_A4 + -0x4788)) {
        *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
            *(undefined2 *)(unaff_A4 + -0x4788);
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      } else {
        sVar2 = *(short *)((int)&comp_vel[0].x + unaff_A4) >> 4;
        if (sVar2 == 0) {
          sVar2 = 1;
        }
        psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
        sVar2 = *psVar1 - sVar2;
        *psVar1 = sVar2;
        if (-1 < sVar2) {
          *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
        }
      }
    } else if (*(ushort *)((int)&comp_pos_x + unaff_A4) <
               *(ushort *)(&DAT_ffffb876 + unaff_A4)) {
      sVar2 = *(short *)((int)&comp_vel[0].x + unaff_A4) >> 4;
      if (sVar2 == 0) {
        sVar2 = 1;
      }
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      sVar2 = *psVar1 - sVar2;
      *psVar1 = sVar2;
      if (sVar2 < 0) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      }
    } else {
      *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
          *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    }
  }
  return;
}

void FUN_0000ea24(void)

{
  ushort uVar1;
  int unaff_A4;

  uVar1 = *(ushort *)(&DAT_ffffb66e + unaff_A4);
  if ((uVar1 & 8) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  } else {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  }
  *(ushort *)(&comp_unk_1 + unaff_A4) = (uVar1 & 0xf0) << 2;
  *(ushort *)(&DAT_ffffb876 + unaff_A4) = uVar1 >> 8;
  *(short *)(unaff_A4 + -0x4788) = *(short *)(&DAT_ffffba76 + unaff_A4) << 8;
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
      *(short *)((int)&comp_pos_y + unaff_A4);
  *(undefined2 *)(&DAT_ffffbc76 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  *(undefined2 *)(&DAT_ffffbc78 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  FUN_0000ea92();
  *(undefined4 *)((int)component_pos_old_x + unaff_A4) =
      *(undefined4 *)((int)&comp_pos_x + unaff_A4);
  *(undefined4 *)((int)component_pos_old_y + unaff_A4) =
      *(undefined4 *)((int)&comp_pos_y + unaff_A4);
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  return;
}

void FUN_0000ea92(void)

{
  short sVar1;
  short extraout_D1w;
  int unaff_A4;

  sVar1 = FUN_000012a8();
  *(short *)((int)&comp_pos_x + unaff_A4) =
      sVar1 + *(short *)(&DAT_ffffbc76 + unaff_A4);
  *(short *)((int)&comp_pos_y + unaff_A4) =
      extraout_D1w + *(short *)(&DAT_ffffbc78 + unaff_A4);
  return;
}

void FUN_0000eab6(void)

{
  int unaff_A4;

  FUN_0000dac4();
  (*(code *)((int)&WORD_0000eace +
             (int)*(short *)((int)&WORD_0000eace +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  FUN_0000e75a();
  return;
}

void FUN_0000eada(void)

{
  int unaff_A4;

  *(short *)(unaff_A4 + -0x4788) =
      *(short *)(unaff_A4 + -0x4788) - *(short *)(&comp_unk_1 + unaff_A4);
  FUN_0000ea92();
  FUN_0000eb80();
  return;
}

void FUN_0000eaea(void)

{
  int unaff_A4;

  *(short *)(unaff_A4 + -0x4788) =
      *(short *)(&comp_unk_1 + unaff_A4) + *(short *)(unaff_A4 + -0x4788);
  FUN_0000ea92();
  FUN_0000eb80();
  return;
}

void FUN_0000eafa(void)

{
  short *psVar1;
  short sVar2;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar2 = *psVar1 + -0x40;
  *psVar1 = sVar2;
  if (sVar2 < 0) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff00;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  }
  return;
}

void FUN_0000eb10(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
      *(ushort *)(&DAT_ffffbd78 + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffbd78 + unaff_A4);
    *(undefined *)((int)&comp_state + unaff_A4) = (&DAT_ffffb976)[unaff_A4];
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\b';
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  return;
}

void FUN_0000eb30(void)

{
  int unaff_A4;

  if (((component_unknown_5 & 4) == 0) ||
      (*(word *)((int)&comp_unk_8 + unaff_A4) != component_unknown_9)) {
    *(undefined *)((int)&comp_state + unaff_A4) = (&DAT_ffffb976)[unaff_A4];
  }
  *(short *)(unaff_A4 + -0x4788) =
      *(short *)(unaff_A4 + -0x4788) - *(short *)(&comp_unk_1 + unaff_A4);
  FUN_0000ea92();
  return;
}

void FUN_0000eb58(void)

{
  int unaff_A4;

  if (((component_unknown_5 & 4) == 0) ||
      (*(word *)((int)&comp_unk_8 + unaff_A4) != component_unknown_9)) {
    *(undefined *)((int)&comp_state + unaff_A4) = (&DAT_ffffb976)[unaff_A4];
  }
  *(short *)(unaff_A4 + -0x4788) =
      *(short *)(&comp_unk_1 + unaff_A4) + *(short *)(unaff_A4 + -0x4788);
  FUN_0000ea92();
  return;
}

void FUN_0000eb80(void)

{
  int unaff_A4;

  if (((component_unknown_5 & 4) != 0) &&
      (*(word *)((int)&comp_unk_8 + unaff_A4) == component_unknown_9)) {
    *(undefined2 *)(&DAT_ffffbd78 + unaff_A4) =
        *(undefined2 *)((int)&comp_pos_y + unaff_A4);
    (&DAT_ffffb976)[unaff_A4] = *(undefined1 *)((int)&comp_state + unaff_A4);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x200;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

void FUN_0000ebae(void)

{
  int unaff_A4;

  (&comp_unk_10)[unaff_A4] = 0;
  FUN_0000da3a();
  *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  return;
}

void FUN_0000ebc6(void)

{
  FUN_0000e800();
  return;
}

void FUN_0000ebcc(void)

{
  short sVar1;
  undefined2 extraout_D0w;
  undefined2 unaff_D6w;
  entity_id_t e;

  sVar1 = FUN_0000107a();
  e = (entity_id_t)sVar1;
  entity_reset(e);
  (&comp_has_func_maybe)[e] = 0x80;
  *(undefined2 *)(&DAT_ffffba76 + e) = extraout_D0w;
  *(undefined2 *)(&DAT_ffffb66e + e) = unaff_D6w;
  (&comp_func_offset[0].func_offset_from_15ede)[e] = 0x1c;
  *(undefined2 *)((int)&comp_pos_x + e) = DAT_ffffce04;
  *(short *)((int)&comp_pos_x + e) = *(short *)((int)&comp_pos_x + e) + -0x10;
  *(undefined2 *)((int)&comp_pos_y + e) = 0x1080;
  *(undefined2 *)((int)&comp_collision_sensor[0].x + e) = 0x10;
  *(undefined2 *)((int)&comp_collision_sensor[0].y + e) = 0x80;
  (&comp_collision_related)[e] = 1;
  *(undefined2 *)((int)&comp_vel[0].x + e) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + e) = 0;
  *(undefined2 *)((int)component_pos_old_x + e) =
      *(undefined2 *)((int)&comp_pos_x + e);
  *(undefined2 *)((int)component_pos_old_y + e) =
      *(undefined2 *)((int)&comp_pos_y + e);
  return;
}

void FUN_0000ec26(void)

{
  ushort uVar1;
  int unaff_A4;

  (&comp_unk_10)[unaff_A4] = 0;
  *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  FUN_0000da3a();
  uVar1 = *(ushort *)(&DAT_ffffb66e + unaff_A4);
  *(ushort *)(&DAT_ffffb876 + unaff_A4) =
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
      ((uVar1 & 0xff00) >> 4) + 0x1000;
  *(undefined2 *)(unaff_A4 + -0x4788) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(ushort *)(&comp_unk_2 + unaff_A4) = (uVar1 & 0xf0) << 2;
  return;
}

void FUN_0000ec6a(void)

{
  int unaff_A4;

  FUN_0000dac4();
  (*(code *)((int)&WORD_0000ec86 +
             (int)*(short *)((int)&WORD_0000ec86 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  FUN_0000e75a();
  return;
}

void FUN_0000ec8c(void)

{
  char extraout_D1b;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_0000dda8();
  if (extraout_D1b != '\0') {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    *(short *)((int)&comp_vel[0].y + unaff_A4) =
        -*(short *)(&comp_unk_2 + unaff_A4);
    ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  }
  return;
}

void FUN_0000ecae(void)

{
  char extraout_D1b;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_0000dda8();
  if (extraout_D1b == '\0') {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) =
        *(undefined2 *)(&comp_unk_2 + unaff_A4);
    ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
  } else if (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
             *(ushort *)(&DAT_ffffb876 + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    if ((&comp_anim_c)[unaff_A4] != 0) {
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    }
  }
  return;
}

void FUN_0000ecf0(void)

{
  char extraout_D1b;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_0000dda8();
  if (extraout_D1b == '\0') {
    if (*(ushort *)(unaff_A4 - 0x4788) <=
        *(ushort *)((int)&comp_pos_y + unaff_A4)) {
      *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
      *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
          *(undefined2 *)(unaff_A4 - 0x4788);
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
      if ((&comp_anim_c)[unaff_A4] != 0) {
        ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
      }
    }
  } else {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    *(short *)((int)&comp_vel[0].y + unaff_A4) =
        -*(short *)(&comp_unk_2 + unaff_A4);
    ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  }
  return;
}

void FUN_0000ed3c(void)

{
  int unaff_A4;
  bool bVar1;

  FUN_0000dafe();
  if (*(short *)((int)&comp_pos_y + unaff_A4) ==
      *(short *)(&DAT_ffffb876 + unaff_A4)) {
    *(undefined2 *)(&DAT_ffffb876 + unaff_A4) =
        *(undefined2 *)(unaff_A4 + -0x4788);
  }
  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar1) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  }
  return;
}

void FUN_0000ed6a(void)

{
  int unaff_A4;

  FUN_0000dac4();
  (*(code *)((int)&WORD_0000ed86 +
             (int)*(short *)((int)&WORD_0000ed86 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  FUN_0000e75a();
  return;
}

void FUN_0000ed8e(entity_id_t self)

{
  bool bVar1;

  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + self));
  if (!bVar1) {
    FUN_0001689e();
    DAT_ffff9808 = 0xff;
    audio_play(SOUND_ID_TOW_APPEAR);
    if (*(ushort *)((int)&comp_pos_y + self) <
        *(ushort *)(&DAT_ffffb876 + self)) {
      *(short *)((int)&comp_vel[0].y + self) = *(short *)(&comp_unk_1 + self);
      *(undefined1 *)((int)&comp_state + self) = 2;
    } else {
      *(short *)((int)&comp_vel[0].y + self) = -*(short *)(&comp_unk_1 + self);
      *(undefined1 *)((int)&comp_state + self) = 4;
    }
  }
  return;
}

void FUN_0000edd6(void)

{
  int unaff_A4;

  if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
      *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    FUN_0001689e();
    audio_play(SOUND_ID_TOW_STOP);
    DAT_ffff9808 = 0;
  }
  return;
}

void FUN_0000ee0a(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
      *(ushort *)(&DAT_ffffb876 + unaff_A4)) {
    audio_play(SOUND_ID_JUNGLE_5);
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    FUN_0001689e();
  }
  return;
}

void FUN_0000ee3a(void)

{
  return;
}

void FUN_0000ee3c(void)

{
  undefined4 in_D0;
  int unaff_A4;

  *(uint *)(&comp_unk_2 + unaff_A4) =
      CONCAT22((short)(CONCAT22((short)((uint)in_D0 >> 0x10),
                                *(short *)(&DAT_ffffb66e + unaff_A4)) >>
                       8),
               *(ushort *)(&DAT_ffffba76 + unaff_A4) |
                   *(short *)(&DAT_ffffb66e + unaff_A4) << 8);
  (&DAT_ffffb976)[unaff_A4] = 0;
  FUN_0000efe6();
  return;
}

void FUN_0000ee56(void)

{
  char cVar1;
  int unaff_A4;

  FUN_0000ee90();
  (*(code *)((int)&WORD_0000ee84 +
             (int)*(short *)((int)&WORD_0000ee84 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  if (((&DAT_ffffb976)[unaff_A4] != '\0') &&
      (cVar1 = *(char *)(unaff_A4 + -0x4689) + -1,
       *(char *)(unaff_A4 + -0x4689) = cVar1,
       cVar1 == '\0')) {
    FUN_0001689e();
    (&DAT_ffffb976)[unaff_A4] = 0;
  }
  return;
}

void FUN_0000ee90(void)

{
  ushort uVar1;
  ushort uVar2;
  int unaff_A4;

  uVar1 = *(short *)((int)&comp_pos_x + unaff_A4) - comp_pos_x._0_2_;
  if ((short)uVar1 < 0) {
    uVar1 = -uVar1;
  }
  uVar2 = *(short *)((int)&comp_pos_y + unaff_A4) - comp_pos_y._0_2_;
  if ((short)uVar2 < 0) {
    uVar2 = -uVar2;
  }
  if ((uVar1 <
       (ushort)(comp_collision_sensor[0].x +
                *(short *)((int)&comp_collision_sensor[0].x + unaff_A4))) &&
      (uVar2 <
       (ushort)(comp_collision_sensor[0].y +
                *(short *)((int)&comp_collision_sensor[0].y + unaff_A4)))) {
    DAT_ffffcc93 = 8;
    DAT_ffffcc92 = 1;
  }
  return;
}

void FUN_0000eed2(void)

{
  int unaff_A4;

  FUN_0000dac4();
  if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
      *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    FUN_0000efe6();
    if ((&comp_has_func_maybe)[unaff_A4] == 0) {
      return;
    }
  }
  FUN_0000e75a();
  if (-1 < *(short *)((int)&comp_unk_8 + unaff_A4)) {
    *(short *)(&DAT_ffffd21a + *(short *)((int)&comp_unk_8 + unaff_A4)) =
        *(short *)(&DAT_ffffd21a + *(short *)((int)&comp_unk_8 + unaff_A4)) + 1;
  }
  return;
}

void FUN_0000ef02(void)

{
  int unaff_A4;

  FUN_0000dac4();
  if (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
      *(ushort *)(&DAT_ffffb876 + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    FUN_0000efe6();
    if ((&comp_has_func_maybe)[unaff_A4] == 0) {
      return;
    }
  }
  FUN_0000e75a();
  if (-1 < *(short *)((int)&comp_unk_8 + unaff_A4)) {
    *(short *)(&DAT_ffffd21a + *(short *)((int)&comp_unk_8 + unaff_A4)) =
        *(short *)(&DAT_ffffd21a + *(short *)((int)&comp_unk_8 + unaff_A4)) +
        -1;
  }
  return;
}

void FUN_0000ef32(void)

{
  short sVar1;
  int unaff_A4;

  FUN_0000dac4();
  sVar1 = *(short *)(&DAT_ffffb876 + unaff_A4) + -1;
  *(short *)(&DAT_ffffb876 + unaff_A4) = sVar1;
  if ((sVar1 < 0) && (FUN_0000efe6(), (&comp_has_func_maybe)[unaff_A4] == 0)) {
    return;
  }
  FUN_0000e75a();
  return;
}

void FUN_0000ef4c(void)

{
  short sVar1;
  short *psVar2;
  int unaff_A4;

  psVar2 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar2 = *psVar2 + 0x40;
  if (0x600 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x600;
  }
  FUN_0000dac4();
  if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
      *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    FUN_0000efe6();
    if ((&comp_has_func_maybe)[unaff_A4] == 0) {
      return;
    }
  }
  FUN_0000e75a();
  sVar1 = *(short *)((int)&comp_unk_8 + unaff_A4);
  if (-1 < sVar1) {
    if (*(short *)(unaff_A4 + -0x4788) < 0) {
      *(short *)(&DAT_ffffd21a + sVar1) =
          *(short *)(&DAT_ffffd21a + sVar1) + -1;
    } else if (*(short *)(unaff_A4 + -0x4788) != 0) {
      *(short *)(&DAT_ffffd21a + sVar1) = *(short *)(&DAT_ffffd21a + sVar1) + 1;
    }
  }
  return;
}

void FUN_0000ef9e(void)

{
  FUN_0000dac4();
  FUN_0000e75a();
  return;
}

void FUN_0000efa8(void)

{
  short sVar1;
  int unaff_A4;

  FUN_0000dac4();
  if (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
      *(ushort *)(&DAT_ffffb876 + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    FUN_0000efe6();
    if ((&comp_has_func_maybe)[unaff_A4] == 0) {
      return;
    }
  }
  FUN_0000e75a();
  sVar1 = *(short *)((int)&comp_unk_8 + unaff_A4);
  if (-1 < sVar1) {
    if (*(short *)(unaff_A4 + -0x4788) < 0) {
      *(short *)(&DAT_ffffd21a + sVar1) =
          *(short *)(&DAT_ffffd21a + sVar1) + -1;
    } else if (*(short *)(unaff_A4 + -0x4788) != 0) {
      *(short *)(&DAT_ffffd21a + sVar1) = *(short *)(&DAT_ffffd21a + sVar1) + 1;
    }
  }
  return;
}

void FUN_0000efe6(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x0000eff8. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0000effc +
             (int)*(short *)((int)&WORD_0000effc +
                             (int)(short)((ushort) *
                                          *(byte **)(&comp_unk_2 + unaff_A4) *
                                          2))))();
  return;
}

void FUN_0000f010(void)

{
  undefined2 uVar1;
  undefined2 *in_A0;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = *in_A0;
  uVar1 = in_A0[1];
  *(undefined2 **)(&comp_unk_2 + unaff_A4) = in_A0 + 2;
  *(undefined2 *)(&DAT_ffffb876 + unaff_A4) = uVar1;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
  *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  return;
}

void FUN_0000f03e(void)

{
  short sVar1;
  short *in_A0;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(short *)((int)&comp_vel[0].x + unaff_A4) = -*in_A0;
  sVar1 = in_A0[1];
  *(short **)(&comp_unk_2 + unaff_A4) = in_A0 + 2;
  *(short *)(&DAT_ffffb876 + unaff_A4) = sVar1;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  return;
}

void FUN_0000f06e(void)

{
  undefined2 uVar1;
  undefined2 *in_A0;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  uVar1 = *in_A0;
  *(undefined2 **)(&comp_unk_2 + unaff_A4) = in_A0 + 1;
  *(undefined2 *)(&DAT_ffffb876 + unaff_A4) = uVar1;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  return;
}

void FUN_0000f092(void)

{
  undefined2 *in_A0;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  *(undefined2 *)(&DAT_ffffb876 + unaff_A4) = *in_A0;
  *(undefined2 **)(&comp_unk_2 + unaff_A4) = in_A0 + 1;
  *(undefined2 *)(unaff_A4 - 0x4788) =
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4);
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  return;
}

void FUN_0000f0b4(void)

{
  undefined4 *in_A0;

  // WARNING: Could not recover jumptable at 0x0000eff8. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0000effc +
             (int)*(short *)((int)&WORD_0000effc +
                             (int)(short)((ushort) * (byte *)*in_A0 * 2))))();
  return;
}

void FUN_0000f0c8(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
  *(undefined1 *)((int)&comp_state + unaff_A4) = 8;
  return;
}

void FUN_0000f0d6(void)

{
  int unaff_A4;

  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

void FUN_0000f0dc(void)

{
  undefined2 *in_A0;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_pos_x + unaff_A4) = *in_A0;
  *(undefined2 *)((int)&comp_pos_y + unaff_A4) = in_A0[1];
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  // WARNING: Could not recover jumptable at 0x0000eff8. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0000effc +
             (int)*(
                 short *)((int)&WORD_0000effc +
                          (int)(short)((ushort) * (byte *)(in_A0 + 2) * 2))))();
  return;
}

void FUN_0000f106(void)

{
  short unaff_D2w;
  undefined1 *extraout_A0;
  int unaff_A4;

  FUN_0000f12c();
  if (unaff_D2w == 0) {
    (&DAT_ffffb976)[unaff_A4] = 0xff;
    *(undefined1 *)(unaff_A4 + -0x4689) = *extraout_A0;
    FUN_0001689e();
  }
  // WARNING: Could not recover jumptable at 0x0000eff8. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0000effc +
             (int)*(
                 short *)((int)&WORD_0000effc +
                          (int)(short)((ushort)(byte)extraout_A0[1] * 2))))();
  return;
}

void FUN_0000f12c(void)

{
  return;
}

void FUN_0000f16e(void)

{
  char cVar1;
  short *in_A0;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(short *)((int)&comp_vel[0].y + unaff_A4) = -*in_A0;
  *(short *)(&DAT_ffffb876 + unaff_A4) = in_A0[1];
  cVar1 = *(char *)(in_A0 + 2);
  *(int *)(&comp_unk_2 + unaff_A4) = (int)in_A0 + 5;
  if (cVar1 == '\0') {
    *(undefined2 *)(unaff_A4 - 0x4788) = 0xffff;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  } else {
    *(undefined2 *)(unaff_A4 - 0x4788) = 1;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
  }
  *(undefined1 *)((int)&comp_state + unaff_A4) = 10;
  return;
}

void FUN_0000f1b8(void)

{
  short sVar1;
  int unaff_A4;

  FUN_0000da3a();
  *(ushort *)((int)&comp_state + unaff_A4) =
      (*(ushort *)(&DAT_ffffb66e + unaff_A4) & 0xf0) >> 4;
  sVar1 = *(short *)((int)&WORD_0000f1ec +
                     (int)(short)(*(short *)((int)&comp_state + unaff_A4) * 2));
  *(undefined2 *)(&DAT_ffffbd76 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  *(undefined2 *)(&DAT_ffffbd78 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  // WARNING: Could not recover jumptable at 0x0000f1e8. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0000f1ec + (int)sVar1))();
  return;
}

void FUN_0000f1f4(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_H_FLIP;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  return;
}

void FUN_0000f202(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_state_a)[unaff_A4] =
      (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_H_FLIP;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  return;
}

void FUN_0000f210(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  return;
}

void FUN_0000f21e(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  return;
}

void FUN_0000f22c(void)

{
  short *psVar1;
  ushort uVar2;
  ulong unaff_A4;
  short sVar4;
  ulong uVar3;

  sVar4 = (short)unaff_A4;
  // WARNING: Switch is manually overridden
  switch (*(undefined2 *)((int)&comp_state + unaff_A4)) {
  case 1:
    if (*(short *)((int)&comp_pos_y + unaff_A4) ==
        *(short *)(&DAT_ffffbd78 + unaff_A4)) {
      if ((short)(*(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
                  comp_collision_sensor[0].y + comp_pos_y.fixed.i) ==
          *(short *)((int)&comp_pos_y + unaff_A4)) {
        uVar2 = *(short *)((int)&comp_pos_x + unaff_A4) - comp_pos_x._0_2_;
        if ((short)uVar2 < 0) {
          uVar2 = -uVar2;
        }
        if (uVar2 < 0x11) {
          FUN_000123a8();
          FUN_00018c56();
          uVar3 = (ulong)sVar4;
          *(undefined2 *)((int)&comp_vel[0].x + uVar3) = 0;
          *(undefined2 *)((int)&comp_vel[0].y + uVar3) = 64000;
          player_update_pos(uVar3);
        }
      }
      return;
    }
    player_update_pos(unaff_A4);
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    sVar4 = *psVar1 + 0x100;
    *psVar1 = sVar4;
    if ((-1 < sVar4) && (*(ushort *)(&DAT_ffffbd78 + unaff_A4) <=
                         *(ushort *)((int)&comp_pos_y + unaff_A4))) {
      *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
          *(undefined2 *)(&DAT_ffffbd78 + unaff_A4);
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    }
    return;
  case 2:
    if (*(short *)((int)&comp_pos_x + unaff_A4) ==
        *(short *)(&DAT_ffffbd76 + unaff_A4)) {
      if ((int16_t)((comp_pos_x.fixed.i - comp_collision_sensor[0].x) -
                    *(short *)((int)&comp_collision_sensor[0].x + unaff_A4)) ==
          *(short *)((int)&comp_pos_x + unaff_A4)) {
        uVar2 = *(short *)((int)&comp_pos_y + unaff_A4) - comp_pos_y._0_2_;
        if ((short)uVar2 < 0) {
          uVar2 = -uVar2;
        }
        if (uVar2 < 0x11) {
          FUN_000123fe();
          FUN_00018c56();
          uVar3 = (ulong)sVar4;
          *(undefined2 *)((int)&comp_vel[0].y + uVar3) = 0;
          *(undefined2 *)((int)&comp_vel[0].x + uVar3) = 0x600;
          player_update_pos(uVar3);
        }
      }
      return;
    }
    player_update_pos(unaff_A4);
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    sVar4 = *psVar1 + -0x100;
    *psVar1 = sVar4;
    if ((sVar4 < 0) && (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
                        *(ushort *)(&DAT_ffffbd76 + unaff_A4))) {
      *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
          *(undefined2 *)(&DAT_ffffbd76 + unaff_A4);
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    }
    return;
  case 3:
    if (*(short *)((int)&comp_pos_x + unaff_A4) ==
        *(short *)(&DAT_ffffbd76 + unaff_A4)) {
      if ((short)(*(short *)((int)&comp_collision_sensor[0].x + unaff_A4) +
                  comp_collision_sensor[0].x + comp_pos_x.fixed.i) ==
          *(short *)((int)&comp_pos_x + unaff_A4)) {
        uVar2 = *(short *)((int)&comp_pos_y + unaff_A4) - comp_pos_y._0_2_;
        if ((short)uVar2 < 0) {
          uVar2 = -uVar2;
        }
        if (uVar2 < 0x11) {
          FUN_000123d2();
          FUN_00018c56();
          uVar3 = (ulong)sVar4;
          *(undefined2 *)((int)&comp_vel[0].y + uVar3) = 0;
          *(undefined2 *)((int)&comp_vel[0].x + uVar3) = 64000;
          player_update_pos(uVar3);
        }
      }
      return;
    }
    player_update_pos(unaff_A4);
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    sVar4 = *psVar1 + 0x100;
    *psVar1 = sVar4;
    if ((-1 < sVar4) && (*(ushort *)(&DAT_ffffbd76 + unaff_A4) <=
                         *(ushort *)((int)&comp_pos_x + unaff_A4))) {
      *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
          *(undefined2 *)(&DAT_ffffbd76 + unaff_A4);
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    }
    return;
  }
  if (*(short *)((int)&comp_pos_y + unaff_A4) ==
      *(short *)(&DAT_ffffbd78 + unaff_A4)) {
    if ((int16_t)(comp_pos_y.fixed.i + comp_collision_sensor[0].y * -2) ==
        *(short *)((int)&comp_pos_y + unaff_A4)) {
      uVar2 = *(short *)((int)&comp_pos_x + unaff_A4) - comp_pos_x._0_2_;
      if ((short)uVar2 < 0) {
        uVar2 = -uVar2;
      }
      if (uVar2 < 0x11) {
        FUN_0001237e();
        FUN_00018c56();
        uVar3 = (ulong)sVar4;
        *(undefined2 *)((int)&comp_vel[0].x + uVar3) = 0;
        *(undefined2 *)((int)&comp_vel[0].y + uVar3) = 0x600;
        player_update_pos(uVar3);
      }
    }
    return;
  }
  player_update_pos(unaff_A4);
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar4 = *psVar1 + -0x100;
  *psVar1 = sVar4;
  if ((sVar4 < 0) && (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
                      *(ushort *)(&DAT_ffffbd78 + unaff_A4))) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffbd78 + unaff_A4);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000f416(void)

{
  undefined4 in_D0;
  int unaff_A4;

  DAT_ffffcc63 = 0;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x1e;
  *(uint *)(&comp_unk_2 + unaff_A4) =
      CONCAT22((short)(CONCAT22((short)((uint)in_D0 >> 0x10),
                                *(short *)(&DAT_ffffb66e + unaff_A4)) >>
                       8),
               *(ushort *)(&DAT_ffffba76 + unaff_A4) |
                   *(short *)(&DAT_ffffb66e + unaff_A4) << 8);
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  *(undefined2 *)(&DAT_ffffbd76 + unaff_A4) = 0;
  DAT_ffffcc62 = 0;
  _DAT_ffffcc5e = 0;
  return;
}

void FUN_0000f444(void)

{
  int unaff_A4;

  FUN_0000dac4();
  FUN_0000f486();
  (*(code *)((int)&WORD_0000f476 +
             (int)*(
                 short *)((int)&WORD_0000f476 +
                          (int)(short)(*(short *)((int)&comp_state + unaff_A4) *
                                       2))))();
  FUN_0000e75a();
  if (*(short *)(&DAT_ffffbd76 + unaff_A4) != 0) {
    FUN_0000dac4();
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000f486(void)

{
  int unaff_A4;

  *(int *)((int)&comp_pos_y + unaff_A4) =
      _DAT_ffffcc5e + *(int *)((int)&comp_pos_y + unaff_A4);
  if (DAT_ffffcc62 < '\0') {
    _DAT_ffffcc5e = _DAT_ffffcc5e + -0x2000;
    if (_DAT_ffffcc5e < -0x10000) {
      DAT_ffffcc62 = '\0';
    }
  } else {
    _DAT_ffffcc5e = _DAT_ffffcc5e + 0x2000;
    if (0x10000 < _DAT_ffffcc5e) {
      DAT_ffffcc62 = -1;
    }
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000f4c4(void)

{
  char extraout_D1b;
  short unaff_D2w;
  func *f;
  entity_id_t e;
  int unaff_A4;

  FUN_0000dda8();
  if (extraout_D1b != '\0') {
    DAT_ffffcc63 = 0xff;
    FUN_0000f5e2();
    FUN_0000147a(f, 0, 0);
    do {
    } while (unaff_D2w < 0);
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x1e;
    *(undefined2 *)((int)&comp_pos_x + e) =
        *(undefined2 *)((int)&comp_pos_x + unaff_A4);
    *(undefined2 *)((int)&comp_pos_y + e) =
        *(undefined2 *)((int)&comp_pos_y + unaff_A4);
    *(undefined2 *)((int)&comp_vel[0].x + e) = 0x100;
    *(undefined2 *)((int)&comp_vel[0].y + e) = 0;
    (&comp_has_func_maybe)[e] = 0x80;
    _DAT_ffffcc5c = unaff_D2w;
    *(short *)(&DAT_ffffbd76 + unaff_A4) = unaff_D2w;
    DAT_ffffd16c = 4;
  }
  return;
}

void FUN_0000f51e(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = *(short *)(&DAT_ffffb876 + unaff_A4) + -1;
  *(short *)(&DAT_ffffb876 + unaff_A4) = sVar1;
  if (sVar1 < 0) {
    if ((DAT_ffff915f & 0x40) == 0) {
      FUN_0000f5e2();
    } else {
      *(undefined2 *)((int)&comp_state + unaff_A4) = 7;
    }
  }
  return;
}

void FUN_0000f53a(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
      *(ushort *)(&DAT_ffffb876 + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    if ((DAT_ffff915f & 0x40) == 0) {
      FUN_0000f5e2();
    } else {
      *(undefined2 *)((int)&comp_state + unaff_A4) = 7;
    }
  }
  return;
}

void FUN_0000f560(void)

{
  int unaff_A4;

  if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
      *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    if ((DAT_ffff915f & 0x40) == 0) {
      FUN_0000f5e2();
    } else {
      *(undefined2 *)((int)&comp_state + unaff_A4) = 7;
    }
  }
  return;
}

void FUN_0000f586(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
      *(ushort *)(&DAT_ffffb876 + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    if ((DAT_ffff915f & 0x40) == 0) {
      FUN_0000f5e2();
    } else {
      *(undefined2 *)((int)&comp_state + unaff_A4) = 7;
    }
  }
  return;
}

void FUN_0000f5ac(void)

{
  int unaff_A4;

  if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
      *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    if ((DAT_ffff915f & 0x40) == 0) {
      FUN_0000f5e2();
    } else {
      *(undefined2 *)((int)&comp_state + unaff_A4) = 7;
    }
  }
  return;
}

void FUN_0000f5d2(void)

{
  return;
}

void FUN_0000f5d4(void)

{
  if ((DAT_ffff915d & 0x10) != 0) {
    FUN_0000f5e2();
  }
  return;
}

void FUN_0000f5e2(void)

{
  undefined1 *puVar1;
  int unaff_A4;

  puVar1 = *(undefined1 **)(&comp_unk_2 + unaff_A4);
  // WARNING: Switch is manually overridden
  switch (*puVar1) {
  case 0:
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)(&DAT_ffffb876 + unaff_A4) = *(undefined2 *)(puVar1 + 1);
    *(undefined1 **)(&comp_unk_2 + unaff_A4) = puVar1 + 3;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 1;
    return;
  case 1:
    FUN_0000f622();
    *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
    return;
  case 2:
    FUN_0000f622();
    *(undefined2 *)((int)&comp_state + unaff_A4) = 3;
    return;
  case 3:
    FUN_0000f622();
    *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
    return;
  case 4:
    FUN_0000f622();
    *(undefined2 *)((int)&comp_state + unaff_A4) = 5;
    return;
  case 5:
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
    return;
  }
}

void FUN_0000f622(void)

{
  undefined2 *in_A0;
  int unaff_A4;

  *(undefined2 *)(&DAT_ffffb876 + unaff_A4) = *in_A0;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = in_A0[1];
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = in_A0[2];
  *(undefined2 **)(&comp_unk_2 + unaff_A4) = in_A0 + 3;
  return;
}

void FUN_0000f67e(void)

{
  short sVar1;
  int unaff_A4;

  FUN_0000db2a();
  sVar1 = *(short *)(&comp_unk_1 + unaff_A4);
  if (((&DAT_ffffb66f)[unaff_A4] & 8) != 0) {
    sVar1 = -sVar1;
  }
  *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar1;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  return;
}

void FUN_0000f69c(void)

{
  int unaff_A4;
  undefined1 uVar1;

  FUN_0000dac4();
  uVar1 = 0;
  (*(code *)((int)&WORD_0000f6dc +
             (int)*(short *)((int)&WORD_0000f6dc +
                             (int)*(short *)((int)&comp_state + unaff_A4))))();
  FUN_0000e75a();
  FUN_0000f6cc();
  if ((bool)uVar1) {
    if (-1 < *(short *)((int)&comp_unk_8 + unaff_A4)) {
      (&DAT_ffffd19a)[*(short *)((int)&comp_unk_8 + unaff_A4)] = 0;
    }
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

short FUN_0000f6cc(void)

{
  return DAT_ffffc73a + -0x30;
}

void FUN_0000f6e2(void)

{
  char extraout_D1b;
  int unaff_A4;

  FUN_0000dda8();
  if (extraout_D1b != '\0') {
    *(undefined2 *)(&DAT_ffffbd78 + unaff_A4) =
        *(undefined2 *)((int)&comp_pos_y + unaff_A4);
    *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x200;
  }
  return;
}

void FUN_0000f700(void)

{
  short *psVar1;
  int unaff_A4;

  if (*(ushort *)(&DAT_ffffbd78 + unaff_A4) <
      *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + -0x40;
  } else {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffbd78 + unaff_A4);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

void FUN_0000f724(void)

{
  char extraout_D1b;
  int unaff_A4;

  FUN_0000dda8();
  if (extraout_D1b == '\0') {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  }
  return;
}

void FUN_0000f736(void)

{
  int unaff_A4;

  *(undefined2 *)((int)&comp_pos_x + unaff_A4) = DAT_ffffc73a;
  *(short *)((int)&comp_pos_x + unaff_A4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + -0x10;
  *(undefined2 *)((int)&comp_pos_y + unaff_A4) = DAT_ffffc746;
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_pos_y + unaff_A4) + 0x60;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  return;
}

void FUN_0000f75e(void)

{
  int unaff_A4;

  FUN_0000dac4();
  // WARNING: Switch is manually overridden
  switch (*(undefined2 *)((int)&comp_state + unaff_A4)) {
  case 2:
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) = DAT_ffffc73a;
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_pos_x + unaff_A4) + -8;
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) = DAT_ffffc746;
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) + 0x60;
    FUN_0000e800();
    return;
  }
  *(undefined2 *)((int)&comp_pos_x + unaff_A4) = DAT_ffffc73a;
  *(short *)((int)&comp_pos_x + unaff_A4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + -8;
  *(undefined2 *)((int)&comp_pos_y + unaff_A4) = DAT_ffffc746;
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_pos_y + unaff_A4) + 0x60;
  if (DAT_ffffcc63 != '\0') {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
  }
  return;
}

void FUN_0000f7b4(void)

{
  byte state_1_b;
  short sVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_0000db2a();
  sVar1 = *(short *)(&comp_unk_1 + unaff_A4);
  if (((&DAT_ffffb66f)[unaff_A4] & 8) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  } else {
    sVar1 = -sVar1;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  }
  *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar1;
  state_1_b = 0;
  if (((&DAT_ffffb66f)[unaff_A4] & 4) != 0) {
    state_1_b = 2;
  }
  ecs_anim_unk_2(unaff_A4, unaff_A5, state_1_b);
  return;
}

void FUN_0000f7ea(void)

{
  short sVar1;
  short sVar2;
  int unaff_A4;

  FUN_0000dac4();
  (*(code *)((int)&WORD_0000f82c +
             (int)*(short *)((int)&WORD_0000f82c +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  FUN_0000e75a();
  sVar1 = *(short *)((int)&comp_unk_8 + unaff_A4);
  if (-1 < sVar1) {
    sVar2 = 1;
    if (((&DAT_ffffb66f)[unaff_A4] & 2) != 0) {
      sVar2 = 2;
    }
    if (((&DAT_ffffb66f)[unaff_A4] & 4) == 0) {
      *(short *)(&DAT_ffffd21a + sVar1) =
          sVar2 + *(short *)(&DAT_ffffd21a + sVar1);
    } else {
      *(short *)(&DAT_ffffd21a + sVar1) =
          *(short *)(&DAT_ffffd21a + sVar1) - sVar2;
    }
  }
  return;
}

void FUN_0000f834(void)

{
  int unaff_A4;

  if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
      *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    *(undefined2 *)((int)&comp_pos_x + unaff_A4 + 2) = 0;
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 10;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

void FUN_0000f85a(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
      *(ushort *)(unaff_A4 + -0x4788)) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
        *(undefined2 *)(unaff_A4 + -0x4788);
    *(undefined2 *)((int)&comp_pos_x + unaff_A4 + 2) = 0;
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 10;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  }
  return;
}

void FUN_0000f880(void)

{
  int unaff_A4;

  *(short *)(&comp_unk_2 + unaff_A4) = *(short *)(&comp_unk_2 + unaff_A4) + -1;
  if (*(short *)(&comp_unk_2 + unaff_A4) < 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    *(short *)((int)&comp_vel[0].x + unaff_A4) =
        -*(short *)(&comp_unk_1 + unaff_A4);
  }
  return;
}

void FUN_0000f89c(void)

{
  int unaff_A4;

  *(short *)(&comp_unk_2 + unaff_A4) = *(short *)(&comp_unk_2 + unaff_A4) + -1;
  if (*(short *)(&comp_unk_2 + unaff_A4) < 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) =
        *(undefined2 *)(&comp_unk_1 + unaff_A4);
  }
  return;
}

void FUN_0000f8b6(void)

{
  byte state_1_b;
  short sVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_0000dafe();
  sVar1 = *(short *)(&comp_unk_1 + unaff_A4);
  if (((&DAT_ffffb66f)[unaff_A4] & 8) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  } else {
    sVar1 = -sVar1;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  }
  *(short *)((int)&comp_vel[0].y + unaff_A4) = sVar1;
  state_1_b = 0;
  if (((&DAT_ffffb66f)[unaff_A4] & 4) != 0) {
    state_1_b = 2;
  }
  ecs_anim_unk_2(unaff_A4, unaff_A5, state_1_b);
  return;
}

void FUN_0000f8ec(void)

{
  short sVar1;
  short sVar2;
  int unaff_A4;

  FUN_0000dac4();
  (*(code *)((int)&WORD_0000f92e +
             (int)*(short *)((int)&WORD_0000f92e +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  FUN_0000e75a();
  sVar1 = *(short *)((int)&comp_unk_8 + unaff_A4);
  if (-1 < sVar1) {
    sVar2 = 1;
    if (((&DAT_ffffb66f)[unaff_A4] & 2) != 0) {
      sVar2 = 2;
    }
    if (((&DAT_ffffb66f)[unaff_A4] & 4) == 0) {
      *(short *)(&DAT_ffffd21a + sVar1) =
          sVar2 + *(short *)(&DAT_ffffd21a + sVar1);
    } else {
      *(short *)(&DAT_ffffd21a + sVar1) =
          *(short *)(&DAT_ffffd21a + sVar1) - sVar2;
    }
  }
  return;
}

void FUN_0000f936(void)

{
  int unaff_A4;

  if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
      *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 10;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

void FUN_0000f95c(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
      *(ushort *)(unaff_A4 + -0x4788)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(unaff_A4 + -0x4788);
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
    *(undefined2 *)(&comp_unk_2 + unaff_A4) = 10;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  }
  return;
}

void FUN_0000f982(void)

{
  int unaff_A4;

  *(short *)(&comp_unk_2 + unaff_A4) = *(short *)(&comp_unk_2 + unaff_A4) + -1;
  if (*(short *)(&comp_unk_2 + unaff_A4) < 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    *(short *)((int)&comp_vel[0].y + unaff_A4) =
        -*(short *)(&comp_unk_1 + unaff_A4);
  }
  return;
}

void FUN_0000f99e(void)

{
  int unaff_A4;

  *(short *)(&comp_unk_2 + unaff_A4) = *(short *)(&comp_unk_2 + unaff_A4) + -1;
  if (*(short *)(&comp_unk_2 + unaff_A4) < 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) =
        *(undefined2 *)(&comp_unk_1 + unaff_A4);
  }
  return;
}

void FUN_0000f9b8(void)

{
  int unaff_A4;

  FUN_0000da3a();
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0xc;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  *(undefined2 *)(&DAT_ffffbd76 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  *(undefined2 *)(&DAT_ffffbd78 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  return;
}

void FUN_0000f9d8(void)

{
  int unaff_A4;

  FUN_0000dac4();
  (*(code *)((int)&WORD_0000f9f0 +
             (int)*(short *)((int)&WORD_0000f9f0 +
                             (int)*(short *)((int)&comp_state + unaff_A4))))();
  FUN_0000e75a();
  return;
}

void FUN_0000f9fa(void)

{
  char extraout_D1b;
  int unaff_A4;

  if (*(short *)(&DAT_ffffbd78 + unaff_A4) ==
      *(short *)((int)&comp_pos_y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
  } else {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff00;
  }
  FUN_0000dda8();
  if (extraout_D1b != '\0') {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
  }
  return;
}

void FUN_0000fa2a(void)

{
  char extraout_D1b;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_0000dda8();
  if (extraout_D1b != '\0') {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x100;
    if ((ushort)(*(short *)(&DAT_ffffbd78 + unaff_A4) + 10U) <=
        *(ushort *)((int)&comp_pos_y + unaff_A4)) {
      *(ushort *)((int)&comp_pos_y + unaff_A4) =
          *(short *)(&DAT_ffffbd78 + unaff_A4) + 10U;
      *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
      *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
      script_state_set_true(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
      ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
    }
    return;
  }
  *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  return;
}

void FUN_0000fa7c(void)

{
  char extraout_D1b;
  int unaff_A4;

  FUN_0000dda8();
  if (extraout_D1b == '\0') {
    (&DAT_ffffb976)[unaff_A4] = (&DAT_ffffb66e)[unaff_A4];
    *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
  }
  return;
}

void FUN_0000fa94(void)

{
  char cVar1;
  char extraout_D1b;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_0000dda8();
  if (extraout_D1b == '\0') {
    cVar1 = (&DAT_ffffb976)[unaff_A4] + -1;
    (&DAT_ffffb976)[unaff_A4] = cVar1;
    if (cVar1 == '\0') {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff00;
      FUN_0000dac4();
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
      if (*(short *)(&DAT_ffffbd78 + unaff_A4) ==
          *(short *)((int)&comp_pos_y + unaff_A4)) {
        *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
        script_state_set_false(
            *(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
        ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
      }
      (&DAT_ffffb976)[unaff_A4] = (&DAT_ffffb66e)[unaff_A4];
    }
    return;
  }
  *(undefined1 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 8;
  return;
}

void FUN_0000fae6(void)

{
  char extraout_D1b;
  int unaff_A4;

  FUN_0000dda8();
  if (extraout_D1b != '\0') {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x100;
    if ((ushort)(*(short *)(&DAT_ffffbd78 + unaff_A4) + 10U) <=
        *(ushort *)((int)&comp_pos_y + unaff_A4)) {
      *(ushort *)((int)&comp_pos_y + unaff_A4) =
          *(short *)(&DAT_ffffbd78 + unaff_A4) + 10U;
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
      *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
      *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
    }
    return;
  }
  *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  (&DAT_ffffb976)[unaff_A4] = (&DAT_ffffb66e)[unaff_A4];
  *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
  return;
}

void FUN_0000fb30(void)

{
  int unaff_A4;
  bool bVar1;

  FUN_0000dafe();
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar1) {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
    if (((&DAT_ffffb66f)[unaff_A4] & 8) == 0) {
      *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
          *(undefined2 *)(&DAT_ffffb876 + unaff_A4);
    } else {
      *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
          *(undefined2 *)(unaff_A4 + -0x4788);
    }
  }
  return;
}

void FUN_0000fb64(void)

{
  int unaff_A4;

  FUN_0000dac4();
  (*(code *)((int)&WORD_0000fb80 +
             (int)*(short *)((int)&WORD_0000fb80 +
                             (int)*(short *)((int)&comp_state + unaff_A4))))();
  FUN_0000e75a();
  return;
}

void FUN_0000fb88(void)

{
  entity_id_t unaff_A4;
  bool bVar1;

  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar1) {
    FUN_0000fc4c(unaff_A4);
  }
  return;
}

void FUN_0000fb9a(void)

{
  int unaff_A4;
  bool bVar1;

  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (bVar1) {
    FUN_0000fc66();
  }
  return;
}

void FUN_0000fbac(void)

{
  int unaff_A4;
  bool bVar1;

  if (((&DAT_ffffb66f)[unaff_A4] & 8) == 0) {
    if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
        *(ushort *)((int)&comp_pos_y + unaff_A4)) {
      *(ushort *)((int)&comp_pos_y + unaff_A4) =
          *(ushort *)(&DAT_ffffb876 + unaff_A4);
      *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
      *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    }
  } else if (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
             *(ushort *)(unaff_A4 + -0x4788)) {
    *(ushort *)((int)&comp_pos_y + unaff_A4) = *(ushort *)(unaff_A4 + -0x4788);
    *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (bVar1) {
    FUN_0000fc66();
  }
  return;
}

void FUN_0000fbfc(void)

{
  entity_id_t unaff_A4;
  bool bVar1;

  if (((&DAT_ffffb66f)[unaff_A4] & 8) == 0) {
    if (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
        *(ushort *)(unaff_A4 - 0x4788)) {
      *(ushort *)((int)&comp_pos_y + unaff_A4) = *(ushort *)(unaff_A4 - 0x4788);
      *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    }
  } else if (*(ushort *)(&DAT_ffffb876 + unaff_A4) <=
             *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    *(ushort *)((int)&comp_pos_y + unaff_A4) =
        *(ushort *)(&DAT_ffffb876 + unaff_A4);
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar1) {
    FUN_0000fc4c(unaff_A4);
  }
  return;
}

void FUN_0000fc4c(entity_id_t self)

{
  short sVar1;

  sVar1 = *(short *)(&comp_unk_1 + self);
  if (((&DAT_ffffb66f)[self] & 8) != 0) {
    sVar1 = -sVar1;
  }
  *(short *)((int)&comp_vel[0].y + self) = sVar1;
  *(undefined2 *)((int)&comp_state + self) = 4;
  return;
}

void FUN_0000fc66(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = *(short *)(&comp_unk_1 + unaff_A4);
  if (((&DAT_ffffb66f)[unaff_A4] & 8) == 0) {
    sVar1 = -sVar1;
  }
  *(short *)((int)&comp_vel[0].y + unaff_A4) = sVar1;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
  return;
}

void FUN_0000fc80(void)

{
  int unaff_A4;
  bool bVar1;

  FUN_0000da3a();
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0xc;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  *(undefined2 *)(&DAT_ffffbd76 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  *(undefined2 *)(&DAT_ffffbd78 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar1) {
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) + 10;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

void FUN_0000fcb8(void)

{
  int unaff_A4;

  FUN_0000dac4();
  (*(code *)((int)&WORD_0000fcd0 +
             (int)*(short *)((int)&WORD_0000fcd0 +
                             (int)*(short *)((int)&comp_state + unaff_A4))))();
  FUN_0000e75a();
  return;
}

void FUN_0000fcd6(void)

{
  char extraout_D1b;
  int unaff_A4;

  if (*(short *)(&DAT_ffffbd78 + unaff_A4) ==
      *(short *)((int)&comp_pos_y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
  } else {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff00;
  }
  FUN_0000dda8();
  if (extraout_D1b != '\0') {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
  }
  return;
}

void FUN_0000fd06(void)

{
  char extraout_D1b;
  int unaff_A4;

  FUN_0000dda8();
  if (extraout_D1b != '\0') {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x100;
    if ((ushort)(*(short *)(&DAT_ffffbd78 + unaff_A4) + 10U) <=
        *(ushort *)((int)&comp_pos_y + unaff_A4)) {
      *(ushort *)((int)&comp_pos_y + unaff_A4) =
          *(short *)(&DAT_ffffbd78 + unaff_A4) + 10U;
      *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
      *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
      script_state_set_true(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
    }
    return;
  }
  *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  return;
}

void FUN_0000fd52(void)

{
  return;
}

void FUN_0000fd54(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar1;

  FUN_0000da3a();
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0xc;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  *(undefined2 *)(&DAT_ffffbd76 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  *(undefined2 *)(&DAT_ffffbd78 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar1) {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  }
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  (&DAT_ffffb976)[unaff_A4] = 0;
  return;
}

void FUN_0000fd98(void)

{
  int unaff_A4;

  FUN_0000dac4();
  FUN_0000e75a();
  (*(code *)((int)&WORD_0000fdb0 +
             (int)*(short *)((int)&WORD_0000fdb0 +
                             (int)*(short *)((int)&comp_state + unaff_A4))))();
  return;
}

void FUN_0000fdb4(void)

{
  char cVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar2;

  bVar2 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar2) {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  }
  bVar2 = (&DAT_ffffb976)[unaff_A4] == '\0';
  if (!bVar2) {
    cVar1 = (&DAT_ffffb976)[unaff_A4] + -1;
    (&DAT_ffffb976)[unaff_A4] = cVar1;
    bVar2 = cVar1 == '\0';
  }
  FUN_0000feca();
  if (!bVar2) {
    (&DAT_ffffb976)[unaff_A4] = 10;
    audio_play(SOUND_ID_DEFENCE);
  }
  return;
}

void FUN_0000fdea(void)

{
  int unaff_A4;
  undefined1 in_ZF;

  FUN_0000feca();
  if (!(bool)in_ZF) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
    FUN_0000fdfa();
  }
  return;
}

void FUN_0000fdfa(void)

{
  entity_id_w_t unaff_D2w;
  entity_id_t other_a;
  int unaff_A4;
  entity_id_t unaff_A5;
  bool bVar1;

  (&DAT_ffffd19a)[*(short *)((int)&comp_unk_8 + unaff_A4)] = 0;
  other_a = (entity_id_t)(short)unaff_A4;
  bVar1 = FUN_0000fe7e(unaff_A5, other_a, unaff_D2w, 4);
  if (!bVar1) {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
    bVar1 = FUN_0000fe7e(unaff_A5, other_a, unaff_D2w, 6);
    if (!bVar1) {
      *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
      bVar1 = FUN_0000fe7e(unaff_A5, other_a, unaff_D2w, 4);
      if (!bVar1) {
        *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
        bVar1 = FUN_0000fe7e(unaff_A5, other_a, unaff_D2w, 4);
        if (!bVar1) {
          *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
          bVar1 = FUN_0000fe7e(unaff_A5, other_a, unaff_D2w, 4);
          if (!bVar1) {
            *(undefined2 *)((int)&comp_state + unaff_A4) = 8;
            bVar1 = FUN_0000fe7e(unaff_A5, other_a, unaff_D2w, 6);
            if (!bVar1) {
              *(undefined2 *)((int)&comp_state + unaff_A4) = 10;
              bVar1 = FUN_0000fe7e(unaff_A5, other_a, unaff_D2w, 4);
              if (!bVar1) {
                *(undefined2 *)((int)&comp_state + unaff_A4) = 0xc;
                bVar1 = FUN_0000fe7e(unaff_A5, other_a, unaff_D2w, 4);
                if (!bVar1) {
                  *(undefined2 *)((int)&comp_state + unaff_A4) = 0xe;
                  audio_play(SOUND_ID_SLASH);
                }
              }
            }
          }
        }
      }
    }
  }
  return;
}

void FUN_0000fe28(void)

{
  entity_id_w_t unaff_D2w;
  entity_id_t unaff_A3;
  int unaff_A4;
  entity_id_t unaff_A5;
  bool bVar1;

  *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
  bVar1 = FUN_0000fe7e(unaff_A5, unaff_A3, unaff_D2w, 4);
  if (!bVar1) {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
    bVar1 = FUN_0000fe7e(unaff_A5, unaff_A3, unaff_D2w, 4);
    if (!bVar1) {
      *(undefined2 *)((int)&comp_state + unaff_A4) = 8;
      bVar1 = FUN_0000fe7e(unaff_A5, unaff_A3, unaff_D2w, 6);
      if (!bVar1) {
        *(undefined2 *)((int)&comp_state + unaff_A4) = 10;
        bVar1 = FUN_0000fe7e(unaff_A5, unaff_A3, unaff_D2w, 4);
        if (!bVar1) {
          *(undefined2 *)((int)&comp_state + unaff_A4) = 0xc;
          bVar1 = FUN_0000fe7e(unaff_A5, unaff_A3, unaff_D2w, 4);
          if (!bVar1) {
            *(undefined2 *)((int)&comp_state + unaff_A4) = 0xe;
            audio_play(SOUND_ID_SLASH);
          }
        }
      }
    }
  }
  return;
}

bool FUN_0000fe7e(entity_id_t self, entity_id_t other_a, entity_id_w_t other_b,
                  byte param_4)

{
  entity_id_t other_c;

  FUN_0000147a(FUN_0000fed8, 1, 2);
  if ((short)other_b >= 0) {
    other_c = (entity_id_t)(short)other_b;
    entity_reset(other_c);
    (&comp_anim_base_offset)[other_c] = (&comp_anim_base_offset)[other_a];
    (&comp_anim_b)[other_c] = (&comp_anim_b)[other_a];
    *(undefined2 *)((int)&comp_pos_x + other_c) =
        *(undefined2 *)((int)&comp_pos_x + other_a);
    *(undefined2 *)((int)&comp_pos_y + other_c) =
        *(undefined2 *)((int)&comp_pos_y + other_a);
    ecs_anim_unk_2(other_c, (anim_item_t *)self, param_4);
    (&comp_state_a)[other_c] = 0x50;
    *(undefined2 *)((int)&comp_unk_3 + other_c) = 4;
    *(undefined2 *)((int)&comp_vel[0].x + other_c) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + other_c) = 0;
  }
  return (short)other_b < 0;
}

void FUN_0000feca(void)

{
  FUN_000189d0();
  return;
}

void FUN_0000fed8(void)

{
  entity_id_t unaff_A4;
  bool bVar1;

  player_update_pos(unaff_A4);
  bVar1 = FUN_00000eae(unaff_A4);
  if (bVar1) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  // WARNING: Switch is manually overridden
  switch (*(undefined2 *)((int)&comp_state + unaff_A4)) {
  case 0:
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_pos_x + unaff_A4) + 6;
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) + -6;
    return;
  case 2:
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_pos_x + unaff_A4) + 8;
    return;
  case 4:
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_pos_x + unaff_A4) + 6;
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) + 6;
    return;
  case 6:
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) + 8;
    return;
  case 8:
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_pos_x + unaff_A4) + -6;
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) + 6;
    return;
  case 10:
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_pos_x + unaff_A4) + -8;
    return;
  case 0xc:
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_pos_x + unaff_A4) + -6;
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) + -6;
    return;
  case 0xe:
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) + -8;
    return;
  }
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0000ff44(entity_id_t other)

{
  DAT_ffffcc8c = 0;
  DAT_ffffcc8d = 0;
  DAT_ffffcc64 = 0;
  uint8_t_ffffcc70 = '\0';
  DAT_ffffcc8a = 0;
  _DAT_ffffcc74 = 0;
  DAT_ffffcc8e = 0;
  entity_id_w_t_ffffcc90 = 0xffff;
  comp_anim_speed = 0x100;
  ecs_holding_a_rope = ecs_holding_a_rope & 0x80;
  clear_asha_and_uncompress_and_copy_to_vram_scene_transition_related_maybe(
      (anim_item_t *)other);
  FUN_0001002e();
  if (DAT_ffffcc73 == '\0') {
    component_collision_flags = 4;
    FUN_00011dee(ENTITY_ID_ASHA, other);
    comp_state = COMP_STATE_STAND;
    DAT_ffffcc73 = -1;
  }
  if ((DAT_ffffcc93 != '\x02') && (DAT_ffffcc93 != '\x03')) {
    ecs_update_h_flip_asha_1();
  }
  return;
}

void clear_asha_and_uncompress_and_copy_to_vram_scene_transition_related_maybe(
    anim_item_t *anim)

{
  DAT_ffffcc64 = 0;
  FUN_00029778();
  clear_data_and_uncompress_and_copy_to_vram();
  if ((DAT_ffffcc93 != '\x02') && (DAT_ffffcc93 != '\x03')) {
    comp_has_func_maybe = 0;
    comp_unk_4 = 0;
    component_collision_flags = 0;
    component_unknown_5 = 0;
    component_unknown_6 = 0;
    comp_state_1_a = 0;
    comp_unk_7 = 0;
    comp_unk_8 = 0;
    component_unknown_9 = 0;
    comp_pos_x.fixed.f = 0;
    comp_pos_y.fixed.f = 0;
    comp_anim[0].unk4 = 0;
    component_unknown_12 = 0;
    comp_state = COMP_STATE_STAND;
    comp_unk_3 = 0x10;
    comp_anim_base_offset = 0;
    comp_anim_b = 0;
    ecs_anim_unk_2(ENTITY_ID_ASHA, anim, 0);
    comp_has_func_maybe = COMPONENT_STATE_B_C0;
  }
  return;
}

void FUN_0001002e(void)

{
  short sVar1;
  short *psVar2;
  long *plVar3;
  short *psVar5;
  long *plVar4;

  plVar3 = &LONG_0001005c;
  psVar2 = (short *)0xffff9a18;
  while (true) {
    psVar5 = psVar2;
    plVar4 = (long *)((int)plVar3 + 2);
    sVar1 = *(short *)plVar3;
    if (sVar1 == -1)
      break;
    *psVar5 = sVar1;
    plVar3 = plVar4;
    psVar2 = psVar5 + 1;
    if (sVar1 == -2) {
      psVar5[0x40] = -2;
    }
  }
  *psVar5 =
      *(short *)((int)WORD_ARRAY_00010064 + (int)(short)(DAT_ffffcbb2 * 2));
  return;
}

void FUN_0001008a(byte *param_1, short new_ctx)

{
  short sVar1;
  word wVar2;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;

  DAT_ffffcc64 = 0;
  if (DAT_ffffcc85 != '\0') {
    comp_state = COMP_STATE_STAND;
    if (DAT_ffffcc86 != '\x01') {
      FUN_00018c56();
      comp_vel[0].x.raw = 0;
      ecs_cap_fall_speed(ENTITY_ID_ASHA);
      FUN_0002ba00(ENTITY_ID_ASHA, new_ctx, unaff_D3w, unaff_D6w, unaff_D7w);
      if (DAT_ffffcc86 != '\x02') {
        if (((component_unknown_5 | component_collision_flags) & 4) == 0) {
          if ((comp_anim_b != 0) || (comp_anim_c != ECS_STATE_1_B_FALLING)) {
            comp_anim_b = 0;
            ecs_anim_unk_2(ENTITY_ID_ASHA, param_1, 6);
          }
        } else if ((comp_anim_b != 0) || (comp_anim_c != 0)) {
          comp_anim_b = 0;
          ecs_anim_unk_2(ENTITY_ID_ASHA, param_1, 0);
        }
      }
    }
    FUN_000103e0();
    FUN_00012f0e();
    return;
  }
  decrement_something_until_0();
  ecs_update_h_flip_asha_1();
  if (comp_state !=
      (COMP_STATE_THROW_PEPELOGOO_MID_AIR | COMP_STATE_ROPE_HOLD)) {
    // If not holding a rope, flip based on gamepad input.
    if ((ecs_holding_a_rope & 0x40) == 0) {
      ecs_update_h_flip_asha_from_gamepad(ENTITY_ID_ASHA);
    }
    sVar1 = FUN_00011a4e();
    if (sVar1 < 0)
      goto LAB_00010106;
  }
  wVar2 = FUN_0001035a();
  FUN_000102e6(ENTITY_ID_ASHA, wVar2);
  (*(code *)((int)&WORD_00010258 +
             (int)*(short *)((int)&WORD_00010258 + (int)(short)comp_state)))();
  if (comp_state !=
      (COMP_STATE_THROW_PEPELOGOO_MID_AIR | COMP_STATE_ROPE_HOLD)) {
    sVar1 = FUN_00010194();
    if (sVar1 == 0) {
      FUN_0001183c(ENTITY_ID_ASHA, (entity_id_t)param_1);
    }
    FUN_00011caa();
    FUN_00012300();
    FUN_000101e0(0, param_1, new_ctx);
    FUN_00010202();
    FUN_00010fb8(ENTITY_ID_ASHA,
                 (entity_id_t)param_1,
                 new_ctx,
                 unaff_D3w,
                 unaff_D6w,
                 unaff_D7w);
  }
  FUN_00011228();
LAB_00010106:
  FUN_000103e0();
  FUN_00012f0e();
  return;
}

undefined4 FUN_00010194(void)

{
  undefined4 uVar1;
  int unaff_A4;

  uVar1 = 0xffffffff;
  if (comp_state != (COMP_STATE_ROPE_CLIMB_DOWN | COMP_STATE_WALK)) {
    uVar1 = FUN_00011ab6();
    if ((((*(short *)((int)&comp_state + unaff_A4) != 0x46) &&
          (*(short *)((int)&comp_state + unaff_A4) != 0x4c)) &&
         (*(short *)((int)&comp_state + unaff_A4) != 0x54)) &&
        (((*(short *)((int)&comp_state + unaff_A4) != 0x5a &&
           (*(short *)((int)&comp_state + unaff_A4) != 0x5c)) &&
          ((*(short *)((int)&comp_state + unaff_A4) != 0x38 &&
            (*(short *)((int)&comp_state + unaff_A4) != 0x3a)))))) {
      uVar1 = 0;
    }
  }
  return uVar1;
}

void FUN_000101e0(ulong ctx, byte *param_2, short new_ctx)

{
  if (DAT_ffffcbb2 == 0xe) {
    if ((*(ushort *)((int)&comp_state + ctx) < 0x38) ||
        (0x3b < *(ushort *)((int)&comp_state + ctx))) {
      FUN_0001270a();
    }
    FUN_00012912(ctx, param_2, new_ctx);
  }
  return;
}

void FUN_00010202(void)

{
  if (DAT_ffffcbb2 == 0x10) {
    FUN_00012b08();
  }
  return;
}

void FUN_00010210(entity_id_t self)

{
  *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + self) = 0;
  if ((gamepad_held & GAMEPAD_UP) != GAMEPAD_NONE) {
    *(undefined2 *)((int)&comp_vel[0].y + self) = 0xf800;
  }
  if ((gamepad_held & GAMEPAD_DOWN) != GAMEPAD_NONE) {
    *(undefined2 *)((int)&comp_vel[0].y + self) = 0x800;
  }
  if ((gamepad_held & GAMEPAD_LEFT) != GAMEPAD_NONE) {
    *(undefined2 *)((int)&comp_vel[0].x + self) = 0xf800;
  }
  if ((gamepad_held & GAMEPAD_RIGHT) != GAMEPAD_NONE) {
    *(undefined2 *)((int)&comp_vel[0].x + self) = 0x800;
  }
  entity_update_pos(self);
  return;
}

void FUN_000102b6(void)

{
  if ((gamepad_held & (GAMEPAD_ACCEPT | GAMEPAD_B)) ==
      (GAMEPAD_ACCEPT | GAMEPAD_B)) {
    DAT_ffffcc92 = 0x18;
    DAT_ffffcc93 = 0;
  }
  return;
}

void ecs_update_h_flip_asha_1(void)

{
  if (DAT_ffffcc28 == '\0') {
    comp_state_a = comp_state_a & 0x7f;
  } else {
    comp_state_a = comp_state_a | 0x80;
  }
  return;
}

ushort FUN_000102e6(entity_id_t self, word param_2)

{
  short *psVar1;
  byte bVar2;
  undefined1 uVar3;
  ushort uVar4;
  int iVar5;

  uVar3 = (undefined1)(param_2 >> 8);
  if (((&component_collision_flags)[self] & 4) == 0) {
    return CONCAT11(uVar3, (&component_collision_flags)[self]) & 0xff04;
  }
  uVar4 = CONCAT11(uVar3, (&component_unknown_5)[self]);
  if ((&component_unknown_5)[self] == 0) {
    return uVar4;
  }
  iVar5 = (int)*(short *)((int)&DAT_ffffd29a +
                          (int)*(short *)(&DAT_ffffc376 + self));
  if ((&comp_func_offset[0].func_offset_from_15ede)[iVar5] != 0x22) {
    return uVar4;
  }
  psVar1 = (short *)((int)&comp_vel[0].x + iVar5);
  if (*psVar1 != 0) {
    if (*psVar1 < 0) {
      bVar2 = (&component_unknown_5)[self] & 1;
    } else {
      bVar2 = (&component_unknown_5)[self] & 2;
    }
    if (bVar2 != 0) {
      DAT_ffffcc92 = 1;
      DAT_ffffcc93 = 8;
      return uVar4;
    }
  }
  if (((&component_unknown_5)[self] & 8) == 0) {
    return uVar4;
  }
  uVar4 = *(short *)((int)&comp_pos_y + self) -
          *(short *)((int)&comp_collision_sensor[0].y + self);
  if (uVar4 < (ushort)(*(short *)((int)&comp_collision_sensor[0].y + iVar5) +
                       *(short *)((int)&comp_pos_y + iVar5))) {
    DAT_ffffcc93 = 8;
    DAT_ffffcc92 = 1;
    return uVar4;
  }
  return uVar4;
}

void decrement_something_until_0(void)

{
  if (DAT_ffffcc8a != 0) {
    DAT_ffffcc8a = DAT_ffffcc8a + -1;
  }
  return;
}

void FUN_0001035a(void)

{
  ushort unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;

  if ((*(short *)((int)&comp_state + unaff_A4) != 0x3c) &&
      ((ecs_holding_a_rope & 0x40) == 0)) {
    FUN_0002ba00(unaff_A4, unaff_D2w, unaff_D3w, unaff_D6w, unaff_D7w);
  }
  return;
}

void FUN_00010372(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;

  if ((((&comp_anim_b)[unaff_A4] != 4) ||
       ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_JUMPING_OR_UNSHIELDING)) ||
      (*(char *)((int)&comp_anim_tick + unaff_A4) == '\0')) {
    FUN_00011dee(unaff_A4, unaff_A5);
  }
  FUN_0001128a(unaff_A4);
  ecs_cap_fall_speed(unaff_A4);
  FUN_0001168e(unaff_A4, unaff_A5);
  FUN_00011c14();
  ecs_try_jump(unaff_A4, unaff_A5);
  FUN_00011c48();
  FUN_000119d4();
  FUN_000124a6();
  return;
}

void FUN_000103b0(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;

  if ((&comp_collision[0].collision.y)[unaff_A4] == '\r') {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x48;
  }
  FUN_00011f3c();
  ecs_cap_fall_speed(unaff_A4);
  FUN_000118e0(unaff_A4);
  FUN_000119b8();
  FUN_00011c14();
  ecs_try_jump(unaff_A4, unaff_A5);
  FUN_000119d4();
  FUN_000124a6();
  return;
}

void FUN_000103e0(void)

{
  // If Pepelogoo is connected to Asha or Asha walks/runs, *and*
  if ((((pepelogoo_state_b & 0x80) != 0) || (comp_state != COMP_STATE_WALK)) &&
      (DAT_ffffcc8c != '\0')) {
    DAT_ffffcc8a = 0;
    DAT_ffffcc8c = '\0';
  }
  return;
}

void FUN_00010400(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;

  if ((&comp_collision[0].collision.y)[unaff_A4] != '\r') {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
  }
  FUN_0001207c();
  ecs_cap_fall_speed(unaff_A4);
  FUN_000118e0(unaff_A4);
  FUN_000119b8();
  FUN_00011c14();
  ecs_try_jump(unaff_A4, unaff_A5);
  FUN_000119d4();
  FUN_000124a6();
  return;
}

void FUN_00010430(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;

  FUN_00012118(unaff_A4, unaff_A5);
  FUN_00011362(unaff_A4, unaff_A5);
  if (-1 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
    if ((pepelogoo_state_b & 0x80) == 0) {
      FUN_0001215a(unaff_A4, unaff_A5);
    }
    *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
  }
  if (((gamepad_held & GAMEPAD_UP) != GAMEPAD_NONE) &&
      (FUN_00010be4(), ((&comp_func_offset[0].unk4)[unaff_A4] & 1) != 0)) {
    return;
  }
  FUN_000119d4();
  return;
}

void FUN_0001046c(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar1;

  FUN_0001215a(unaff_A4, (entity_id_t)unaff_A5);
  if (DAT_ffffd2eb != '\0') {
    FUN_00018c56();
  }
  if ((pepelogoo_state_b & 0x80) == 0) {
    FUN_00011362(unaff_A4, (entity_id_t)unaff_A5);
    bVar1 = ecs_get_cannot_jump(unaff_A4);
    if (((bVar1) && ((gamepad_held & GAMEPAD_UP) != GAMEPAD_NONE)) &&
        (FUN_00010be4(), ((&comp_func_offset[0].unk4)[unaff_A4] & 1) != 0)) {
      return;
    }
    FUN_000119d4();
  } else if ((gamepad_pressed_prev & GAMEPAD_C) == GAMEPAD_NONE) {
    FUN_00011d2a(unaff_A4, (entity_id_t)unaff_A5);
  } else {
    ecs_holding_a_rope = ecs_holding_a_rope | 8;
    FUN_00029d0c();
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfb40;
    (&comp_anim_b)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x2c);
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x36;
    audio_play(SOUND_ID_JUMP);
  }
  return;
}

void FUN_000104ee(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;

  FUN_00012118(unaff_A4, unaff_A5);
  FUN_00011430(unaff_A4, unaff_A5);
  if (-1 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
    FUN_0001215a(unaff_A4, unaff_A5);
    *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
  }
  if (((gamepad_held & GAMEPAD_UP) != GAMEPAD_NONE) &&
      (FUN_00010be4(), ((&comp_func_offset[0].unk4)[unaff_A4] & 1) != 0)) {
    return;
  }
  FUN_000119d4();
  return;
}

void FUN_00010522(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if ((pepelogoo_state_b & 0x80) == 0) {
    FUN_00011430(unaff_A4, (entity_id_t)unaff_A5);
    if (((gamepad_held & GAMEPAD_UP) != GAMEPAD_NONE) &&
        (FUN_00010be4(), ((&comp_func_offset[0].unk4)[unaff_A4] & 1) != 0)) {
      return;
    }
    FUN_000119d4();
  } else {
    FUN_0001215a(unaff_A4, (entity_id_t)unaff_A5);
    if ((gamepad_pressed_prev & GAMEPAD_C) == GAMEPAD_NONE) {
      FUN_00011d2a(unaff_A4, (entity_id_t)unaff_A5);
    } else {
      FUN_00029d0c();
      ecs_holding_a_rope = ecs_holding_a_rope | 8;
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfb40;
      (&comp_anim_b)[unaff_A4] = 0;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0x2c);
      *(undefined2 *)((int)&comp_state + unaff_A4) = 0x36;
      audio_play(SOUND_ID_JUMP);
    }
  }
  return;
}

void FUN_0001054a(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_0001215a(unaff_A4, (entity_id_t)unaff_A5);
  if ((gamepad_pressed_prev & GAMEPAD_C) == GAMEPAD_NONE) {
    FUN_00011d2a(unaff_A4, (entity_id_t)unaff_A5);
  } else {
    FUN_00029d0c();
    ecs_holding_a_rope = ecs_holding_a_rope | 8;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfb40;
    (&comp_anim_b)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x2c);
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x36;
    audio_play(SOUND_ID_JUMP);
  }
  return;
}

void FUN_00010592(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_0001215a(unaff_A4, (entity_id_t)unaff_A5);
  if ((gamepad_pressed_prev & GAMEPAD_C) == GAMEPAD_NONE) {
    FUN_00011d2a(unaff_A4, (entity_id_t)unaff_A5);
    if (*(short *)((int)&comp_state + unaff_A4) == 0) {
      FUN_0002ab66();
    }
  } else {
    FUN_0002ab66();
    ecs_holding_a_rope = ecs_holding_a_rope | 8;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfb40;
    (&comp_anim_b)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x2c);
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x36;
    audio_play(SOUND_ID_JUMP);
  }
  return;
}

void FUN_000105e0(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if ((pepelogoo_state_b & 0x80) == 0) {
    FUN_000114da(unaff_A4, (entity_id_t)unaff_A5);
    if (((gamepad_held & GAMEPAD_UP) != GAMEPAD_NONE) &&
        (FUN_00010be4(), ((&comp_func_offset[0].unk4)[unaff_A4] & 1) != 0)) {
      return;
    }
    FUN_000119d4();
  } else {
    FUN_0001215a(unaff_A4, (entity_id_t)unaff_A5);
    if ((gamepad_pressed_prev & GAMEPAD_C) == GAMEPAD_NONE) {
      FUN_00011d2a(unaff_A4, (entity_id_t)unaff_A5);
    } else {
      FUN_00029d0c();
      ecs_holding_a_rope = ecs_holding_a_rope | 8;
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfb40;
      (&comp_anim_b)[unaff_A4] = 0;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0x2c);
      *(undefined2 *)((int)&comp_state + unaff_A4) = 0x36;
      audio_play(SOUND_ID_JUMP);
    }
  }
  return;
}

void FUN_00010650(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if ((pepelogoo_state_b & 0x80) == 0) {
    FUN_00011592();
    if ((gamepad_held & GAMEPAD_UP) != GAMEPAD_NONE) {
      FUN_00010be4();
    }
  } else {
    FUN_0001215a(unaff_A4, (entity_id_t)unaff_A5);
    if ((gamepad_pressed_prev & GAMEPAD_C) == GAMEPAD_NONE) {
      FUN_00011d2a(unaff_A4, (entity_id_t)unaff_A5);
    } else {
      FUN_00029d0c();
      ecs_holding_a_rope = ecs_holding_a_rope | 8;
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfb40;
      (&comp_anim_b)[unaff_A4] = 0;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0x2c);
      *(undefined2 *)((int)&comp_state + unaff_A4) = 0x36;
      audio_play(SOUND_ID_JUMP);
    }
  }
  return;
}

void FUN_000106b4(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;

  ecs_update_h_flip_asha_from_gamepad(unaff_A4);
  FUN_0001128a(unaff_A4);
  ecs_cap_fall_speed(unaff_A4);
  if ((ecs_holding_a_rope & 4) == 0) {
    ecs_holding_a_rope = ecs_holding_a_rope & 0xf0;
    FUN_00011dee(unaff_A4, unaff_A5);
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  }
  return;
}

void FUN_000106da(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;
  bool bVar1;

  ecs_update_h_flip_asha_from_gamepad(unaff_A4);
  FUN_00011362(unaff_A4, unaff_A5);
  if ((ecs_holding_a_rope & 4) == 0) {
    bVar1 = ecs_get_cannot_jump(unaff_A4);
    if (bVar1) {
      FUN_0001215a(unaff_A4, unaff_A5);
      *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
      ecs_holding_a_rope = ecs_holding_a_rope & 0xf0;
    } else {
      FUN_00011dee(unaff_A4, unaff_A5);
      *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
      ecs_holding_a_rope = ecs_holding_a_rope & 0xf0;
    }
  } else {
    bVar1 = ecs_get_cannot_jump(unaff_A4);
    if (!bVar1) {
      *(undefined2 *)((int)&comp_state + unaff_A4) = 8;
    }
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00010722(void)

{
  short unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar1;
  undefined1 uVar2;

  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  uVar2 = 0;
  FUN_00017d6a(unaff_A4, (entity_id_t)unaff_A5, (byte)unaff_D3w);
  if ((gamepad_held & GAMEPAD_RIGHT) == GAMEPAD_NONE) {
    if (((gamepad_held & GAMEPAD_LEFT) == GAMEPAD_NONE) ||
        (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) == 0))
      goto LAB_000107c6;
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_pos_x + unaff_A4) + -8;
    FUN_00017f76(unaff_A4);
    if ((&comp_collision[0].collision.x)[unaff_A4] == '\x01') {
      *(short *)((int)&comp_pos_x + unaff_A4) =
          *(short *)((int)&comp_pos_x + unaff_A4) + 8;
      goto LAB_0001085c;
    }
    ecs_held_rope_side = -1;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0xe;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 10);
    audio_play(SOUND_ID_ROPE_RIDE);
  } else if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) == 0) {
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_pos_x + unaff_A4) + 8;
    FUN_00017f90(unaff_A4, unaff_D6w, unaff_D7w);
    if ((&comp_collision[0].collision.x)[unaff_A4] == '\x01') {
      *(short *)((int)&comp_pos_x + unaff_A4) =
          *(short *)((int)&comp_pos_x + unaff_A4) + -8;
      goto LAB_0001085c;
    }
    ecs_held_rope_side = '\x01';
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0xe;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 10);
    audio_play(SOUND_ID_ROPE_RIDE);
  } else {
  LAB_000107c6:
    if ((gamepad_held & GAMEPAD_UP) == GAMEPAD_NONE) {
      uVar1 = (gamepad_held & GAMEPAD_DOWN) == GAMEPAD_NONE;
      if (!(bool)uVar1) {
        DAT_ffffcc65 = 1;
        _DAT_ffffcc68 = 0x10;
        *(undefined2 *)((int)&comp_state + unaff_A4) = 0x12;
        uVar1 = 0;
        uVar2 = 0;
        ecs_anim_unk_2(unaff_A4, unaff_A5, 0x12);
      }
    } else {
      gamepad_held_prev = gamepad_held_prev | GAMEPAD_UP;
      DAT_ffffcc65 = 0xff;
      _DAT_ffffcc68 = 0x10;
      *(undefined2 *)((int)&comp_state + unaff_A4) = 0x10;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0x12);
      DAT_ffffcc6a = 0;
      uVar1 = 1;
      uVar2 = 0;
    }
    FUN_00010eb0();
    if ((bool)uVar2 || (bool)uVar1) {
      (&comp_func_offset[0].unk4)[unaff_A4] = 0;
      FUN_0001215a(unaff_A4, (entity_id_t)unaff_A5);
      DAT_ffffd16c = 0;
      ecs_holding_a_rope = ecs_holding_a_rope & 0xbf;
      *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
    }
  }
  if ((gamepad_pressed_prev & GAMEPAD_B) != GAMEPAD_NONE) {
    audio_play(SOUND_ID_ROPE_FALL);
    _DAT_ffffcc76 = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x14;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x16);
  }
LAB_0001085c:
  ecs_update_jump_from_rope(unaff_A4);
  FUN_0001124a(unaff_A4, unaff_D2w, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00010f8e();
  return;
}

void FUN_0001086e(void)

{
  short unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  FUN_00017d6a(unaff_A4, (entity_id_t)unaff_A5, (byte)unaff_D3w);
  if (*(short *)((int)&comp_anim_tick + unaff_A4) != 0)
    goto LAB_00010920;
  if (ecs_held_rope_side < '\0') {
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_pos_x + unaff_A4) + -8;
    FUN_00017f76(unaff_A4);
    if ((&comp_collision[0].collision.x)[unaff_A4] == '\x01') {
      *(short *)((int)&comp_pos_x + unaff_A4) =
          *(short *)((int)&comp_pos_x + unaff_A4) + 0x10;
      FUN_00017f90(unaff_A4, unaff_D6w, unaff_D7w);
      if ((&comp_collision[0].collision.x)[unaff_A4] == '\x01') {
      LAB_000108c0:
        *(short *)((int)&comp_pos_x + unaff_A4) =
            *(short *)((int)&comp_pos_x + unaff_A4) + -8;
        DAT_ffffd16c = 0;
        FUN_0001215a(unaff_A4, (entity_id_t)unaff_A5);
        *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
        ecs_holding_a_rope = ecs_holding_a_rope & 0xb7;
        goto LAB_00010920;
      }
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    } else {
      (&comp_state_a)[unaff_A4] =
          (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    }
  } else {
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_pos_x + unaff_A4) + 8;
    FUN_00017f90(unaff_A4, unaff_D6w, unaff_D7w);
    if ((&comp_collision[0].collision.x)[unaff_A4] == '\x01') {
      *(short *)((int)&comp_pos_x + unaff_A4) =
          *(short *)((int)&comp_pos_x + unaff_A4) + -0x10;
      FUN_00017f76(unaff_A4);
      if ((&comp_collision[0].collision.x)[unaff_A4] == '\x01')
        goto LAB_000108c0;
      (&comp_state_a)[unaff_A4] =
          (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    } else {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    }
  }
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0xc;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
LAB_00010920:
  FUN_0001124a(unaff_A4, unaff_D2w, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00010f8e();
  return;
}

void FUN_000108de(void)

{
  short unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  *(short *)((int)&comp_pos_x + unaff_A4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + 8;
  FUN_00017f90(unaff_A4, unaff_D6w, unaff_D7w);
  if ((&comp_collision[0].collision.x)[unaff_A4] == '\x01') {
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_pos_x + unaff_A4) + -0x10;
    FUN_00017f76(unaff_A4);
    if ((&comp_collision[0].collision.x)[unaff_A4] == '\x01') {
      *(short *)((int)&comp_pos_x + unaff_A4) =
          *(short *)((int)&comp_pos_x + unaff_A4) + -8;
      DAT_ffffd16c = 0;
      FUN_0001215a(unaff_A4, (entity_id_t)unaff_A5);
      *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
      ecs_holding_a_rope = ecs_holding_a_rope & 0xb7;
      goto LAB_00010920;
    }
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  } else {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  }
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0xc;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
LAB_00010920:
  FUN_0001124a(unaff_A4, unaff_D2w, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00010f8e();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001092e(void)

{
  short unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  FUN_00017d6a(unaff_A4, (entity_id_t)unaff_A5, (byte)unaff_D3w);
  if ((gamepad_pressed_prev & GAMEPAD_UP) != GAMEPAD_NONE) {
    DAT_ffffcc6a = -1;
  }
  _DAT_ffffcc68 = _DAT_ffffcc68 + -1;
  if (_DAT_ffffcc68 == 0) {
    _DAT_ffffcc6c = 0x600;
    DAT_ffffcc6b = 3;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x16;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x14);
    audio_play(SOUND_ID_ROPE_RIDE);
    _DAT_ffffcc68 = 5;
    if (DAT_ffffcc6a != '\0') {
      _DAT_ffffcc6c = 0x700;
      DAT_ffffcc6b = 4;
      _DAT_ffffcc68 = 2;
    }
  }
  FUN_00010f62();
  ecs_update_jump_from_rope(unaff_A4);
  FUN_0001124a(unaff_A4, unaff_D2w, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00010f8e();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001099e(void)

{
  short unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  FUN_00017d6a(unaff_A4, (entity_id_t)unaff_A5, (byte)unaff_D3w);
  _DAT_ffffcc68 = _DAT_ffffcc68 + -1;
  if (_DAT_ffffcc68 == 0) {
    _DAT_ffffcc6c = 0x600;
    DAT_ffffcc6b = 3;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x18;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x14);
    audio_play(SOUND_ID_ROPE_RIDE);
    _DAT_ffffcc68 = 5;
  }
  FUN_00010f62();
  ecs_update_jump_from_rope(unaff_A4);
  FUN_0001124a(unaff_A4, unaff_D2w, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00010f8e();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000109ea(void)

{
  bool bVar1;
  short unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar2;
  undefined1 uVar3;

  FUN_00017d6a(unaff_A4, (entity_id_t)unaff_A5, (byte)unaff_D3w);
  if ((gamepad_held & GAMEPAD_B) == GAMEPAD_NONE) {
    _DAT_ffffcc76 = _DAT_ffffcc76 + -0x40;
    if ((_DAT_ffffcc76 == 0) || (_DAT_ffffcc76 < 0)) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
      *(undefined2 *)((int)&comp_state + unaff_A4) = 0xc;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
    }
  } else if ((0x3ff < _DAT_ffffcc76) || (bVar1 = 0x3ff < _DAT_ffffcc76,
                                         _DAT_ffffcc76 = _DAT_ffffcc76 + 0x40,
                                         bVar1)) {
    _DAT_ffffcc76 = 0x400;
  }
  *(short *)((int)&comp_vel[0].y + unaff_A4) = _DAT_ffffcc76;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  uVar2 = 1;
  uVar3 = 0;
  player_update_pos(unaff_A4);
  FUN_00010eb0();
  if ((bool)uVar3 || (bool)uVar2) {
    (&comp_func_offset[0].unk4)[unaff_A4] = 0;
    FUN_0001215a(unaff_A4, (entity_id_t)unaff_A5);
    DAT_ffffd16c = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
    ecs_holding_a_rope = ecs_holding_a_rope & 0xb7;
  }
  *(int *)((int)&comp_pos_y + unaff_A4) =
      *(int *)((int)&comp_pos_y + unaff_A4) +
      *(short *)((int)&comp_vel[0].y + unaff_A4) * -0x100;
  FUN_0001124a(unaff_A4, unaff_D2w, unaff_D3w, unaff_D6w, unaff_D7w);
  if ((((&component_collision_flags)[unaff_A4] |
        (&component_unknown_5)[unaff_A4]) &
       0xf) != 0) {
    DAT_ffffd16c = 0;
    FUN_0001215a(unaff_A4, (entity_id_t)unaff_A5);
    ecs_holding_a_rope = ecs_holding_a_rope & 0xbf;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
    (&comp_func_offset[0].unk4)[unaff_A4] = 0;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00010a7e(void)

{
  uint uVar1;
  short *psVar2;
  short sVar3;
  byte state_1_b;
  short unaff_D2w;
  uint unaff_D3;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar4;

  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  FUN_00017d6a(unaff_A4, (entity_id_t)unaff_A5, (byte)unaff_D3);
  if (DAT_ffffcc6b == '\0') {
    _DAT_ffffcc68 = _DAT_ffffcc68 + -1;
    if (_DAT_ffffcc68 == 0) {
      _DAT_ffffcc68 = 0x10;
      if (DAT_ffffcc6a == '\0') {
        state_1_b = 0xc;
        *(undefined2 *)((int)&comp_state + unaff_A4) = 0xc;
      } else {
        audio_play(SOUND_ID_ROPE_RIDE);
        _DAT_ffffcc68 = 0xc;
        DAT_ffffcc6a = '\0';
        state_1_b = 0x12;
        *(undefined2 *)((int)&comp_state + unaff_A4) = 0x10;
      }
      ecs_anim_unk_2(unaff_A4, unaff_A5, state_1_b);
    }
  } else {
    sVar3 = -_DAT_ffffcc6c;
    psVar2 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar2 = sVar3 + *psVar2;
    unaff_D3 = sVar3 * 0x100;
    uVar1 = *(uint *)((int)&comp_pos_y + unaff_A4);
    bVar4 = CARRY4(unaff_D3, uVar1);
    *(uint *)((int)&comp_pos_y + unaff_A4) = unaff_D3 + uVar1;
    FUN_00010e68();
    if (bVar4) {
      DAT_ffffcc6b = '\x01';
    }
    *(int *)((int)&comp_pos_y + unaff_A4) =
        *(int *)((int)&comp_pos_y + unaff_A4) + sVar3 * -0x100;
    DAT_ffffcc6b = DAT_ffffcc6b + -1;
  }
  FUN_00010f62();
  ecs_update_jump_from_rope(unaff_A4);
  entity_update_pos(unaff_A4);
  player_vel_unknown_y_1 = 4;
  interact_with_all_other_entities(unaff_A4, unaff_D2w, (char)unaff_D3);
  ecs_update_collision(unaff_A4, (short)unaff_D3, unaff_D6w, unaff_D7w);
  ecs_apply_collision(unaff_A4);
  WORD_ffffd178 = *(word *)((int)&comp_pos_y + unaff_A4);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00010b02(void)

{
  uint uVar1;
  short *psVar2;
  short sVar3;
  short unaff_D2w;
  uint unaff_D3;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar4;
  bool bVar5;

  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  FUN_00017d6a(unaff_A4, (entity_id_t)unaff_A5, (byte)unaff_D3);
  sVar3 = _DAT_ffffcc6c;
  if (DAT_ffffcc6b == '\0') {
    _DAT_ffffcc68 = _DAT_ffffcc68 + -1;
    if (_DAT_ffffcc68 == 0) {
      *(undefined2 *)((int)&comp_state + unaff_A4) = 0xc;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
    }
  } else {
    psVar2 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar2 = _DAT_ffffcc6c + *psVar2;
    unaff_D3 = sVar3 * 0x100;
    uVar1 = *(uint *)((int)&comp_pos_y + unaff_A4);
    bVar5 = CARRY4(unaff_D3, uVar1);
    uVar1 = unaff_D3 + uVar1;
    *(uint *)((int)&comp_pos_y + unaff_A4) = uVar1;
    bVar4 = uVar1 == 0;
    FUN_00010eb0();
    if (bVar5 || bVar4) {
      DAT_ffffcc6b = '\x01';
    }
    *(int *)((int)&comp_pos_y + unaff_A4) =
        *(int *)((int)&comp_pos_y + unaff_A4) + sVar3 * -0x100;
    DAT_ffffcc6b = DAT_ffffcc6b + -1;
  }
  FUN_00010f62();
  ecs_update_jump_from_rope(unaff_A4);
  entity_update_pos(unaff_A4);
  player_vel_unknown_y_1 = 4;
  interact_with_all_other_entities(unaff_A4, unaff_D2w, (char)unaff_D3);
  ecs_update_collision(unaff_A4, (short)unaff_D3, unaff_D6w, unaff_D7w);
  ecs_apply_collision(unaff_A4);
  WORD_ffffd178 = *(word *)((int)&comp_pos_y + unaff_A4);
  return;
}

void FUN_00010b5c(void)

{
  int unaff_A4;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  } else {
    FUN_00011616();
  }
  return;
}

void FUN_00010b70(void)

{
  entity_id_t unaff_A4;

  ecs_update_h_flip_asha_from_gamepad(unaff_A4);
  FUN_0001128a(unaff_A4);
  ecs_cap_fall_speed(unaff_A4);
  if ((ecs_holding_a_rope & 4) == 0) {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
    ecs_holding_a_rope = ecs_holding_a_rope & 0xf7;
  }
  if (*(short *)((int)&comp_state + unaff_A4) != 0x1c) {
    FUN_00018c56();
  }
  FUN_00011c48();
  if (*(short *)((int)&comp_state + unaff_A4) == 0) {
    FUN_00018c56();
    (&component_collision_flags)[unaff_A4] =
        (&component_collision_flags)[unaff_A4] & 0xfb;
    (&component_unknown_5)[unaff_A4] = (&component_unknown_5)[unaff_A4] & 0xfb;
  }
  return;
}

void ecs_update_h_flip_asha_from_gamepad(entity_id_t e)

{
  if ((ecs_holding_a_rope & 2) == 0) {
    // If holding left
    if ((gamepad_held & GAMEPAD_LEFT) != GAMEPAD_NONE) {
      (&comp_state_a)[e] = (&comp_state_a)[e] | ENTITY_STATE_A_08;
    }
    // If holding right
    if ((gamepad_held & GAMEPAD_RIGHT) != GAMEPAD_NONE) {
      (&comp_state_a)[e] = (&comp_state_a)[e] & ~ENTITY_STATE_A_08;
    }
  }
  return;
}

void FUN_00010be4(void)

{
  ushort uVar1;
  short sVar2;
  byte unaff_D3b;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;

  if (((ecs_holding_a_rope & 4) == 0) && ((pepelogoo_state_b & 0x80) == 0)) {
    (&comp_func_offset[0].unk4)[unaff_A4] = 0;
    FUN_00017d6a(unaff_A4, unaff_A5, unaff_D3b);
    uVar1 = *(ushort *)((int)&comp_pos_x + unaff_A4);
    if (*(ushort *)((int)component_pos_old_x + unaff_A4) <= uVar1) {
      uVar1 = *(word *)((int)component_pos_old_x + unaff_A4);
    }
    sVar2 = *(short *)((int)component_pos_old_x + unaff_A4) -
            *(short *)((int)&comp_pos_x + unaff_A4);
    if (sVar2 < 0) {
      sVar2 = -sVar2;
    }
    FUN_00010dba(unaff_A4,
                 unaff_A5,
                 uVar1,
                 *(word *)((int)&comp_pos_y + unaff_A4),
                 sVar2,
                 unaff_D6w,
                 unaff_D7w);
  }
  return;
}

void ecs_hold_rope(entity_id_t self, entity_id_t other, ushort param_3,
                   word param_4, word param_5)

{
  short *psVar1;

  if ((param_3 & 0xf) < 8) {
    param_3 = param_3 + 8;
  }
  DAT_ffffd176 = param_3 & 0xfff8;
  *(ushort *)((int)&comp_pos_x + self) = DAT_ffffd176;
  DAT_ffffd16c = 2;
  WORD_ffffd178 = *(word *)((int)&comp_pos_y + self);
  (&comp_anim_b)[self] = 0;
  *(undefined2 *)((int)&comp_state + self) = 0xe;
  ecs_anim_unk_2(self, (anim_item_t *)other, 10);
  // Hold a rope
  ecs_holding_a_rope = ecs_holding_a_rope | 0x40;
  psVar1 = (short *)((int)&comp_vel[0].x + self);
  if (*psVar1 == 0) {
    if (((&comp_state_a)[self] & ENTITY_STATE_A_08) == 0) {
      ecs_held_rope_side = '\x01';
    } else {
      ecs_held_rope_side = -1;
    }
  } else if (*psVar1 < 0) {
    ecs_held_rope_side = -1;
  } else {
    ecs_held_rope_side = '\x01';
  }
  *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + self) = 0;
  FUN_00017f90(self, param_4, param_5);
  if ((&comp_collision[0].collision.x)[self] == '\x01') {
    *(short *)((int)&comp_pos_x + self) =
        *(short *)((int)&comp_pos_x + self) + -8;
    (&comp_state_a)[self] = (&comp_state_a)[self] & ~ENTITY_STATE_A_08;
  } else {
    FUN_00017f76(self);
    if ((&comp_collision[0].collision.x)[self] != '\x01') {
      return;
    }
    *(short *)((int)&comp_pos_x + self) =
        *(short *)((int)&comp_pos_x + self) + 8;
    (&comp_state_a)[self] = (&comp_state_a)[self] | ENTITY_STATE_A_08;
  }
  *(undefined2 *)((int)&comp_state + self) = 0xc;
  ecs_anim_unk_2(self, (anim_item_t *)other, 0xc);
  return;
}

void FUN_00010cd4(void)

{
  short *psVar1;
  char unaff_D4b;
  entity_id_t unaff_A4;

  FUN_00011d02(unaff_A4);
  if (unaff_D4b == '\x06') {
    ecs_cap_fall_speed(unaff_A4);
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = *psVar1 + -0x40;
    if (*(short *)((int)&comp_vel[0].x + unaff_A4) < -0x400) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfc00;
    }
    return;
  }
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  ecs_holding_a_rope = ecs_holding_a_rope & 0xe7;
  return;
}

void FUN_00010d16(void)

{
  short *psVar1;
  char unaff_D4b;
  entity_id_t unaff_A4;

  FUN_00011d02(unaff_A4);
  if (unaff_D4b == '\x05') {
    ecs_cap_fall_speed(unaff_A4);
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = *psVar1 + 0x40;
    if (0x400 < *(ushort *)((int)&comp_vel[0].x + unaff_A4)) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x400;
    }
    return;
  }
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  ecs_holding_a_rope = ecs_holding_a_rope & 0xe7;
  return;
}

void FUN_00010d56(void)

{
  short *psVar1;
  char unaff_D4b;
  entity_id_t unaff_A4;

  FUN_00011d02(unaff_A4);
  if (unaff_D4b == '\a') {
    FUN_00010d96();
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + 0x40;
    if (0x600 < *(ushort *)((int)&comp_vel[0].y + unaff_A4)) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x600;
    }
    return;
  }
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  ecs_holding_a_rope = ecs_holding_a_rope & 0xe7;
  return;
}

void FUN_00010d96(void)

{
  short *psVar1;
  short sVar2;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  if (*psVar1 != 0) {
    if (*psVar1 < 0) {
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      sVar2 = *psVar1 + 0x20;
      *psVar1 = sVar2;
      if (-1 < sVar2) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      }
    } else {
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      sVar2 = *psVar1 + -0x20;
      *psVar1 = sVar2;
      if (sVar2 < 0) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      }
    }
  }
  return;
}

void FUN_00010dba(entity_id_t self, entity_id_t other, word param_3,
                  word param_4, short param_5, word param_6, word param_7)

{
  ushort extraout_D0w;
  ushort uVar1;
  word extraout_D1w;
  word extraout_D1w_00;
  uint8_t uVar2;

  while (true) {
    uVar2 = FUN_00010e08(self, param_3, param_4);
    param_6 = CONCAT11((char)(param_6 >> 8), uVar2);
    if ((uVar2 == '\x02') && ((extraout_D0w & 0xf) < 0xd)) {
      uVar1 = FUN_00010df0(extraout_D0w, param_5);
      param_4 = extraout_D1w;
      if (1 < (uVar1 & 0xf)) {
        ecs_hold_rope(self, other, uVar1, param_6, param_7);
        return;
      }
    } else {
      uVar1 = FUN_00010df0(extraout_D0w, param_5);
      param_4 = extraout_D1w_00;
    }
    if (param_5 == 0)
      break;
    param_5 = param_5 - 1;
    param_3 = uVar1 + 1;
  }
  return;
}

short FUN_00010df0(ushort param_1, ushort param_2)

{
  ushort uVar1;
  short sVar2;

  uVar1 = 0xf - (param_1 & 0xf);
  if (param_2 < uVar1) {
    sVar2 = param_2 + param_1;
  } else {
    sVar2 = uVar1 + param_1;
  }
  return sVar2;
}

uint8_t FUN_00010e08(entity_id_t self, word param_2, word param_3)

{
  if (param_3 < 0x1000) {
    param_3 = 0x1000;
  } else if (camera_pos_x_int <= param_3) {
    param_3 = camera_pos_x_int;
  }
  if (param_2 < 0x1000) {
    param_2 = 0x1000;
  } else if (room_boundary_x <= param_2) {
    param_2 = room_boundary_x;
  }
  return (&DAT_ffff6000)[(
      short)(*(ushort *)(DAT_ffffc722 +
                         (short)(((ushort)(param_2 - 0x1000) >> 4) * 2 +
                                 ((param_3 - 0x1000 & 0xfff0)
                                  << ((&DAT_ffffc717)[self] & 0x3f)))) &
             0x3ff)];
}

void FUN_00010e68(void)

{
  short sVar1;
  short sVar2;
  int unaff_D3;
  int unaff_A4;

  if ((((&comp_func_offset[0].unk4)[unaff_A4] & 1) != 0) &&
      (sVar1 = *(short *)(&DAT_ffffd1dc +
                          *(short *)((int)&component_unknown_9 + unaff_A4)),
       sVar2 = *(short *)(&DAT_ffffd25c +
                          *(short *)((int)&component_unknown_9 + unaff_A4)),
       (ushort)(*(short *)((int)&comp_pos_y + unaff_A4) -
                *(short *)((int)&comp_collision_sensor[0].y + unaff_A4)) <
           (ushort)(sVar1 - sVar2))) {
    *(int *)((int)&comp_pos_y + unaff_A4) =
        *(int *)((int)&comp_pos_y + unaff_A4) - unaff_D3;
    *(short *)((int)&comp_vel[0].y + unaff_A4) =
        ((sVar1 - sVar2) -
         (*(short *)((int)&comp_pos_y + unaff_A4) -
          *(short *)((int)&comp_collision_sensor[0].y + unaff_A4))) *
        0x100;
    *(int *)((int)&comp_pos_y + unaff_A4) =
        unaff_D3 + *(int *)((int)&comp_pos_y + unaff_A4);
  }
  return;
}

void FUN_00010eb0(void)

{
  short sVar1;
  word wVar2;
  ushort uVar3;
  entity_id_t unaff_A4;

  uVar3 = *(short *)((int)&comp_pos_y + unaff_A4) -
          *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  if (((&comp_func_offset[0].unk4)[unaff_A4] & 1) == 0) {
    sVar1 = *(short *)((int)&comp_collision_sensor[0].x + unaff_A4);
    if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
      sVar1 = -sVar1;
    }
    wVar2 = *(short *)((int)&comp_pos_x + unaff_A4) + sVar1;
    if (wVar2 < 0x1000) {
      wVar2 = 0x1000;
    }
    if (uVar3 < 0x1000) {
      uVar3 = 0x1000;
    }
    FUN_00010e08(unaff_A4, wVar2, uVar3);
  }
  return;
}

void ecs_update_jump_from_rope(entity_id_t e)

{
  entity_id_t unaff_A5;

  if ((gamepad_pressed_prev & GAMEPAD_C) != GAMEPAD_NONE) {
    (&comp_func_offset[0].unk4)[e] = 0;
    FUN_00012118(e, unaff_A5);
    ecs_holding_a_rope = ecs_holding_a_rope & 0xb7;
    *(undefined2 *)((int)&comp_state + e) = 0x20;
    DAT_ffffd16c = 0;
    // Set y speed to -2.
    *(undefined2 *)((int)&comp_vel[0].y + e) = 0xfe00;
    // If facing right.
    if (((&comp_state_a)[e] & ENTITY_STATE_A_08) == 0) {
      // Set x speed to -2 and face left.
      *(undefined2 *)((int)&comp_vel[0].x + e) = 0xfe00;
      (&comp_state_a)[e] = (&comp_state_a)[e] | ENTITY_STATE_A_08;
    } else {
      // Set x speed to 2 and face right.
      *(undefined2 *)((int)&comp_vel[0].x + e) = 0x200;
      (&comp_state_a)[e] = (&comp_state_a)[e] & ~ENTITY_STATE_A_08;
    }
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00010f62(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if ((gamepad_pressed_prev & GAMEPAD_B) != GAMEPAD_NONE) {
    audio_play(SOUND_ID_ROPE_FALL);
    _DAT_ffffcc76 = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x14;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x16);
    gamepad_pressed_prev = gamepad_pressed_prev &
                           (GAMEPAD_START | GAMEPAD_ACCEPT | GAMEPAD_DPAD_ANY);
  }
  return;
}

void FUN_00010f8e(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;

  if ((((&component_collision_flags)[unaff_A4] |
        (&component_unknown_5)[unaff_A4]) &
       0xf) != 0) {
    DAT_ffffd16c = 0;
    FUN_0001215a(unaff_A4, unaff_A5);
    ecs_holding_a_rope = ecs_holding_a_rope & 0xbf;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
    (&comp_func_offset[0].unk4)[unaff_A4] = 0;
  }
  return;
}

void FUN_00010fb8(entity_id_t e, entity_id_t other, short param_3,
                  short param_4, word param_5, word param_6)

{
  undefined4 uVar1;

  if ((DAT_ffffcc8e == '\0') && (-1 < (char)ecs_holding_a_rope)) {
    if ((uint8_t_ffffcc70 & 0x7e) != 0) {
      if ((pepelogoo_state_b & 0x80) != 0) {
        drop_pepelogoo();
      }
      if ((*(short *)((int)&comp_state + e) != 0x5c) &&
          (FUN_00011048(), param_3 < 0)) {
        uint8_t_ffffcc70 = '\0';
        return;
      }
      ecs_holding_a_rope = ecs_holding_a_rope & 0xbf;
      FUN_0001117e(other, param_3, param_4, param_5, param_6);
      FUN_000110fe(e);
      uint8_t_ffffcc70 = '\0';
      return;
    }
  } else {
    if ((comp_anim_b == 0) && (comp_anim_c == 0x1c)) {
      uint8_t_ffffcc70 = '\0';
      return;
    }
    if ((uint8_t_ffffcc70 & 0x7e) != 0) {
      *(undefined2 *)((int)&comp_vel[0].y + e) = 0xfd00;
      goto LAB_0001102a;
    }
  }
  uVar1 = FUN_00011124(e, other);
  if ((short)uVar1 < 0) {
    uint8_t_ffffcc70 = '\0';
    return;
  }
LAB_0001102a:
  if ((uint8_t_ffffcc70 & 0x80) == 0) {
    *(undefined2 *)((int)&comp_vel[0].x + e) = 0x200;
  } else {
    *(undefined2 *)((int)&comp_vel[0].x + e) = 0xfe00;
  }
  uint8_t_ffffcc70 = '\0';
  return;
}

void FUN_00011048(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;

  if ((~DAT_ffffde10 & uint8_t_ffffcc70 & 0x7e) == 0) {
    DAT_ffffd2f0 = DAT_ffffd2f0 + 1;
    if ((((DAT_ffffde14 != 0) && (DAT_ffffde14 <= DAT_ffffd2f0)) &&
         (DAT_ffffd2f0 = 0, (ecs_holding_a_rope & 4) == 0)) &&
        ((ecs_holding_a_rope & 0x40) == 0)) {
      FUN_0001108a(unaff_A4, unaff_A5, 0);
    }
  }
  return;
}

void FUN_0001108a(entity_id_t e, entity_id_t other, entity_id_w_t e_ter_w)

{
  func *f;
  entity_id_t e_ter;

  audio_play(SOUND_ID_DEFENCE);
  *(undefined2 *)((int)&comp_vel[0].x + e) = 0xfe00;
  if ((uint8_t_ffffcc70 & 0x80) == 0) {
    *(undefined2 *)((int)&comp_vel[0].x + e) = 0x200;
  }
  FUN_0000147a(f, 0, 0);
  e_ter = (entity_id_t)(short)e_ter_w;
  entity_reset(e_ter);
  DAT_ffffcc88 = 0x3c;
  *(int16_t *)((int)&comp_pos_x + e_ter) = comp_pos_x.fixed.i;
  *(int16_t *)((int)&comp_pos_y + e_ter) = comp_pos_y.fixed.i;
  (&comp_state_a)[e_ter] = comp_state_a;
  *(word *)((int)&comp_unk_3 + e_ter) = comp_unk_3;
  *(short *)((int)&comp_unk_3 + e_ter) =
      *(short *)((int)&comp_unk_3 + e_ter) + -2;
  (&comp_anim_base_offset)[e_ter] = 0x14;
  (&comp_anim_b)[e_ter] = 0x4c;
  ecs_anim_unk_2(e_ter, (anim_item_t *)other, 0);
  DAT_ffffcc8e = 0xff;
  entity_id_w_t_ffffcc90 = e_ter_w;
  uint8_t_ffffcc70 = '\0';
  return;
}

void FUN_000110fe(entity_id_t e)

{
  *(undefined2 *)((int)&comp_state + e) = 0x1a;
  if (((DAT_ffffd16c != 6) && (DAT_ffffd16c != 8)) && (DAT_ffffd16c != 4)) {
    DAT_ffffd16c = 0;
  }
  return;
}

undefined4 FUN_00011124(entity_id_t e, entity_id_t other)

{
  undefined4 uVar1;

  uVar1 = 0xffffffff;
  if (uint8_t_ffffcc70 != '\0') {
    audio_play(SOUND_ID_EGG_FALL);
    *(undefined2 *)((int)&comp_vel[0].y + e) = 0xfd00;
    if ((ecs_holding_a_rope & 4) == 0) {
      if ((pepelogoo_state_b & 0x80) != 0) {
        drop_pepelogoo();
      }
      FUN_00018c56();
      (&comp_anim_b)[e] = 0;
      ecs_anim_unk_2(e, (anim_item_t *)other, 0x2c);
      *(undefined2 *)((int)&comp_state + e) = 0x36;
      ecs_holding_a_rope = ecs_holding_a_rope & 0xbf;
    } else {
      *(undefined2 *)((int)&comp_state + e) = 10;
    }
    uVar1 = 0;
  }
  return uVar1;
}

void FUN_0001117e(entity_id_t other, short param_2, short param_3, word param_4,
                  word param_5)

{
  FUN_00018c56();
  comp_anim_b = 0;
  ecs_holding_a_rope = 0x80;
  comp_state_a = comp_state_a | 4;
  DAT_ffffab42 = 0;
  DAT_ffffab43 = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, (anim_item_t *)other, 0x1c);
  if (total_hearts != 0) {
    if ((uint8_t_ffffcc70 & 0x20) == 0) {
      total_hearts = total_hearts - 1;
      if (total_hearts == 0)
        goto LAB_0001120e;
    } else if (total_hearts < 6) {
      total_hearts = 1;
    } else {
      total_hearts = total_hearts - 5;
    }
    comp_vel[0].y.raw = -0x300;
    if ((uint8_t_ffffcc70 & 0x80) == 0) {
      comp_vel[0].x.raw = 0x200;
    } else {
      comp_vel[0].x.raw = -0x200;
    }
    audio_play(SOUND_ID_DAMAGE_1);
    DAT_ffffcc71 = 0x7f;
    uint8_t_ffffcc70 = '\0';
    FUN_0001124a(ENTITY_ID_ASHA, param_2, param_3, param_4, param_5);
    return;
  }
LAB_0001120e:
  DAT_ffff97e4 = 0xff;
  // Clears Asha's hflip, likely making her face right.
  comp_state_a = comp_state_a & 0xfb;
  comp_has_func_maybe = comp_has_func_maybe & 0xf7;
  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  return;
}

void FUN_00011228(void)

{
  int unaff_A4;

  if ((ecs_holding_a_rope < '\0') &&
      (DAT_ffffcc71 = DAT_ffffcc71 + -1, DAT_ffffcc71 == '\0')) {
    uint8_t_ffffcc70 = '\0';
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & 0xfb;
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] & 0xf7;
    FUN_00011270();
  }
  return;
}

void FUN_0001124a(entity_id_t e, short param_2, short param_3, word param_4,
                  word param_5)

{
  entity_update_pos(e);
  player_vel_unknown_y_1 = 4;
  interact_with_all_other_entities(e, param_2, (char)param_3);
  ecs_update_collision(e, param_3, param_4, param_5);
  ecs_apply_collision(e);
  WORD_ffffd178 = *(word *)((int)&comp_pos_y + e);
  return;
}

void FUN_00011270(void)

{
  int unaff_A4;

  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] & 0xf7;
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & 0xfb;
  uint8_t_ffffcc70 = '\0';
  ecs_holding_a_rope = ecs_holding_a_rope & 0x7f;
  return;
}

void FUN_0001128a(entity_id_t self)

{
  short sVar1;
  ushort uVar2;
  short *psVar3;

  if (((&component_collision_flags)[self] & COLLISION_FLAGS_FLOOR) != 0) {
    if (((&comp_collision[0].collision.y)[self] == '\f') ||
        ((&comp_collision[0].collision.y)[self] == '\x0e'))
      goto LAB_00011304;
    if ((&comp_collision[0].collision.y)[self] == '\r') {
      if ((pepelogoo_state_b & 0x80) == 0) {
        return;
      }
      goto LAB_00011304;
    }
  }
  if ((((&component_unknown_5)[self] & 4) == 0) ||
      ((sVar1 = *(short *)((int)&DAT_ffffd29a +
                           (int)*(short *)((int)&component_unknown_9 + self)),
        (&comp_collision_related)[sVar1] != '\f' &&
            ((&comp_collision_related)[sVar1] != '\x0e')))) {
    uVar2 = *(ushort *)((int)&comp_vel[0].x + self);
    if (uVar2 != 0) {
      if ((short)uVar2 < 0) {
        if ((short)uVar2 < -0x40) {
          psVar3 = (short *)((int)&comp_vel[0].x + self);
          *psVar3 = *psVar3 + 0x40;
        } else {
          *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
        }
      } else if (uVar2 < 0x41) {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
      } else {
        psVar3 = (short *)((int)&comp_vel[0].x + self);
        *psVar3 = *psVar3 + -0x40;
      }
    }
    return;
  }
LAB_00011304:
  uVar2 = *(ushort *)((int)&comp_vel[0].x + self);
  if (uVar2 != 0) {
    if ((short)uVar2 < 0) {
      if ((short)uVar2 < -10) {
        psVar3 = (short *)((int)&comp_vel[0].x + self);
        *psVar3 = *psVar3 + 10;
      } else {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
      }
    } else if (uVar2 < 0xb) {
      *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
    } else {
      psVar3 = (short *)((int)&comp_vel[0].x + self);
      *psVar3 = *psVar3 + -10;
    }
  }
  return;
}

void ecs_cap_fall_speed(entity_id_t self)

{
  short *psVar1;
  short vel_y;

  vel_y = *(short *)((int)&comp_vel[0].y + self);
  if ((0x5ff < vel_y) || (psVar1 = (short *)((int)&comp_vel[0].y + self),
                          *psVar1 = *psVar1 + 0x40,
                          0x5ff < vel_y)) {
    *(undefined2 *)((int)&comp_vel[0].y + self) = 0x600;
  }
  return;
}

void FUN_00011362(entity_id_t self, entity_id_t other)

{
  short *psVar1;
  byte state_1_b;
  bool bVar2;

  if ((ecs_holding_a_rope & 4) == 0) {
    if ((gamepad_held & GAMEPAD_LEFT) != GAMEPAD_NONE) {
      if (*(short *)((int)&comp_vel[0].x + self) < -0x1ff) {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0xfe00;
      } else {
        psVar1 = (short *)((int)&comp_vel[0].x + self);
        *psVar1 = *psVar1 + -0x20;
      }
      goto LAB_000113d0;
    }
    if ((gamepad_held & GAMEPAD_RIGHT) != GAMEPAD_NONE) {
      if (*(short *)((int)&comp_vel[0].x + self) < 0x200) {
        psVar1 = (short *)((int)&comp_vel[0].x + self);
        *psVar1 = *psVar1 + 0x20;
      } else {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0x200;
      }
      goto LAB_000113d0;
    }
  }
  psVar1 = (short *)((int)&comp_vel[0].x + self);
  if (*psVar1 != 0) {
    if (*psVar1 < 0) {
      psVar1 = (short *)((int)&comp_vel[0].x + self);
      *psVar1 = *psVar1 + 5;
      if (-1 < *(short *)((int)&comp_vel[0].x + self)) {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
      }
    } else {
      psVar1 = (short *)((int)&comp_vel[0].x + self);
      *psVar1 = *psVar1 + -5;
      if (*(short *)((int)&comp_vel[0].x + self) < 0) {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
      }
    }
  }
LAB_000113d0:
  if ((*(short *)((int)&comp_vel[0].y + self) < 0) &&
      ((gamepad_held & GAMEPAD_C) == GAMEPAD_NONE)) {
    psVar1 = (short *)((int)&comp_vel[0].y + self);
    *psVar1 = *psVar1 + 0x80;
    if (-1 < *(short *)((int)&comp_vel[0].y + self)) {
      *(undefined2 *)((int)&comp_vel[0].y + self) = 0;
    }
  } else {
    psVar1 = (short *)((int)&comp_vel[0].y + self);
    *psVar1 = *psVar1 + 0x40;
  }
  if (0x5ff < *(short *)((int)&comp_vel[0].y + self)) {
    *(undefined2 *)((int)&comp_vel[0].y + self) = 0x600;
  }
  if ((ecs_holding_a_rope & 4) == 0) {
    bVar2 = ecs_get_cannot_jump(self);
    if (!bVar2) {
      audio_play(SOUND_ID_LANDING);
      ecs_anim_unk_2(self, (anim_item_t *)other, state_1_b);
      ecs_holding_a_rope = ecs_holding_a_rope & 0xf7;
      FUN_00011dee(self, other);
      *(undefined2 *)((int)&comp_state + self) = 0;
    }
  }
  return;
}

void FUN_00011430(entity_id_t self, entity_id_t other)

{
  short *psVar1;
  bool bVar2;

  // Similar to #114da.
  if ((ecs_holding_a_rope & 4) == 0) {
    if ((gamepad_held & GAMEPAD_LEFT) != GAMEPAD_NONE) {
      if (*(short *)((int)&comp_vel[0].x + self) < -0x1ff) {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0xfe00;
      } else {
        psVar1 = (short *)((int)&comp_vel[0].x + self);
        *psVar1 = *psVar1 + -0x20;
      }
      goto LAB_0001149e;
    }
    if ((gamepad_held & GAMEPAD_RIGHT) != GAMEPAD_NONE) {
      if (*(short *)((int)&comp_vel[0].x + self) < 0x200) {
        psVar1 = (short *)((int)&comp_vel[0].x + self);
        *psVar1 = *psVar1 + 0x20;
      } else {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0x200;
      }
      goto LAB_0001149e;
    }
  }
  psVar1 = (short *)((int)&comp_vel[0].x + self);
  if (*psVar1 != 0) {
    if (*psVar1 < 0) {
      psVar1 = (short *)((int)&comp_vel[0].x + self);
      *psVar1 = *psVar1 + 5;
      if (-1 < *(short *)((int)&comp_vel[0].x + self)) {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
      }
    } else {
      psVar1 = (short *)((int)&comp_vel[0].x + self);
      *psVar1 = *psVar1 + -5;
      if (*(short *)((int)&comp_vel[0].x + self) < 0) {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
      }
    }
  }
LAB_0001149e:
  psVar1 = (short *)((int)&comp_vel[0].y + self);
  *psVar1 = *psVar1 + 0x40;
  if (0x5ff < *(short *)((int)&comp_vel[0].y + self)) {
    *(undefined2 *)((int)&comp_vel[0].y + self) = 0x600;
  }
  if ((ecs_holding_a_rope & 4) == 0) {
    bVar2 = ecs_get_cannot_jump(self);
    if (!bVar2) {
      audio_play(SOUND_ID_LANDING);
      FUN_00011dee(self, other);
      *(undefined2 *)((int)&comp_state + self) = 0;
      ecs_holding_a_rope = ecs_holding_a_rope & 0xf7;
    }
  }
  return;
}

void FUN_000114da(entity_id_t self, entity_id_t other)

{
  short *psVar1;
  bool bVar2;

  // Similar to #11430.
  if ((ecs_holding_a_rope & 4) == 0) {
    if ((gamepad_held & GAMEPAD_LEFT) != GAMEPAD_NONE) {
      if (*(short *)((int)&comp_vel[0].x + self) < -0x1ff) {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0xfe00;
      } else {
        psVar1 = (short *)((int)&comp_vel[0].x + self);
        *psVar1 = *psVar1 + -0x20;
      }
      goto LAB_00011548;
    }
    if ((gamepad_held & GAMEPAD_RIGHT) != GAMEPAD_NONE) {
      if (*(short *)((int)&comp_vel[0].x + self) < 0x200) {
        psVar1 = (short *)((int)&comp_vel[0].x + self);
        *psVar1 = *psVar1 + 0x20;
      } else {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0x200;
      }
      goto LAB_00011548;
    }
  }
  psVar1 = (short *)((int)&comp_vel[0].x + self);
  if (*psVar1 != 0) {
    if (*psVar1 < 0) {
      psVar1 = (short *)((int)&comp_vel[0].x + self);
      *psVar1 = *psVar1 + 5;
      if (-1 < *(short *)((int)&comp_vel[0].x + self)) {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
      }
    } else {
      psVar1 = (short *)((int)&comp_vel[0].x + self);
      *psVar1 = *psVar1 + -5;
      if (*(short *)((int)&comp_vel[0].x + self) < 0) {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
      }
    }
  }
LAB_00011548:
  if (*(short *)((int)&comp_vel[0].y + self) < 0) {
    psVar1 = (short *)((int)&comp_vel[0].y + self);
    *psVar1 = *psVar1 + 0x40;
  } else {
    psVar1 = (short *)((int)&comp_vel[0].y + self);
    *psVar1 = *psVar1 + 0x40;
  }
  if (0x5ff < *(short *)((int)&comp_vel[0].y + self)) {
    *(undefined2 *)((int)&comp_vel[0].y + self) = 0x600;
  }
  if ((ecs_holding_a_rope & 4) == 0) {
    bVar2 = ecs_get_cannot_jump(self);
    if (!bVar2) {
      audio_play(SOUND_ID_LANDING);
      FUN_00011dee(self, other);
      *(undefined2 *)((int)&comp_state + self) = 0;
      ecs_holding_a_rope = ecs_holding_a_rope & 0xf7;
    }
  }
  return;
}

void FUN_00011592(void)

{
  short *psVar1;
  ushort uVar2;
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;
  bool bVar3;

  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  if (*psVar1 != 0) {
    if (*psVar1 < 0) {
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + 0x10;
      if (-1 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      }
    } else {
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + -0x10;
      if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      }
    }
  }
  uVar2 = *(ushort *)((int)&comp_vel[0].x + unaff_A4);
  if ((short)uVar2 < 0) {
    uVar2 = -uVar2;
  }
  if (uVar2 < 0x400) {
    if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
      psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
      *psVar1 = *psVar1 + 0x40;
    } else {
      psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
      *psVar1 = *psVar1 + 0x40;
    }
    if (0x5ff < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x600;
    }
    if ((ecs_holding_a_rope & 4) == 0) {
      bVar3 = ecs_get_cannot_jump(unaff_A4);
      if (!bVar3) {
        audio_play(SOUND_ID_LANDING);
        FUN_00011dee(unaff_A4, unaff_A5);
        *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
        ecs_holding_a_rope = ecs_holding_a_rope & 0xf7;
      }
    }
  }
  return;
}

byte FUN_00011616(void)

{
  short *psVar1;
  byte bVar2;
  int unaff_A4;

  bVar2 = (component_unknown_5 | component_collision_flags) & 4;
  if (bVar2 == 0) {
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    if (*psVar1 != 0) {
      if (*psVar1 < 0) {
        psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
        *psVar1 = *psVar1 + 5;
        if (-1 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
          *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
        }
      } else {
        psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
        *psVar1 = *psVar1 + -5;
        if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
          *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
        }
      }
    }
  } else {
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    if (*psVar1 != 0) {
      if (*psVar1 < 0) {
        psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
        *psVar1 = *psVar1 + 0x40;
        if (-1 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
          *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
        }
      } else {
        psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
        *psVar1 = *psVar1 + -0x40;
        if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
          *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
        }
      }
    }
  }
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x40;
  if (0x5ff < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x600;
  }
  return bVar2;
}

void FUN_0001168e(entity_id_t self, entity_id_t other)

{
  short sVar1;
  short *psVar2;
  gamepad_t gVar3;
  bool bVar4;

  bVar4 = ecs_get_cannot_jump(self);
  if ((!bVar4) && ((gamepad_held & GAMEPAD_DPAD_X) != GAMEPAD_NONE)) {
    if ((&comp_collision[0].collision.y)[self] == '\r') {
      FUN_0001207c();
      *(undefined2 *)((int)&comp_state + self) = 0x48;
      return;
    }
    if ((char)pepelogoo_state_b < '\0') {
      if (script_ctx_bf_0e_arg == '\x02') {
        return;
      }
      (&comp_anim_b)[self] = 6;
    } else {
      (&comp_anim_b)[self] = 0;
    }
    DAT_ffffcc8c = 0;
    if (DAT_ffffcc8a != 0) {
      if ((DAT_ffffcc8d & GAMEPAD_LEFT) == GAMEPAD_NONE) {
        gVar3 = gamepad_pressed_prev & GAMEPAD_RIGHT;
      } else {
        gVar3 = gamepad_pressed_prev & GAMEPAD_LEFT;
      }
      if (((gVar3 != GAMEPAD_NONE) && ((pepelogoo_state_b & 0x80) == 0)) &&
          ((((&component_unknown_5)[self] & 4) == 0 ||
            ((sVar1 =
                  *(short *)((int)&DAT_ffffd29a +
                             (int)*(short *)((int)&component_unknown_9 + self)),
              (&comp_collision_related)[sVar1] != '\x0f' &&
                  ((&comp_collision_related)[sVar1] != '\x10')))))) {
        DAT_ffffcc8c = 1;
      }
    }
    DAT_ffffcc8d = gamepad_held;
    DAT_ffffcc8a = 0xf;
    ecs_anim_unk_2(self, (anim_item_t *)other, 2);
    FUN_00011f3c();
    *(undefined2 *)((int)&comp_state + self) = 2;
    if ((gamepad_held & GAMEPAD_LEFT) == GAMEPAD_NONE) {
      psVar2 = (short *)((int)&comp_vel[0].x + self);
      *psVar2 = *psVar2 + 0x40;
    } else {
      psVar2 = (short *)((int)&comp_vel[0].x + self);
      *psVar2 = *psVar2 + -0x40;
    }
  }
  return;
}

void ecs_try_jump(entity_id_t self, entity_id_t other)

{
  short *psVar1;
  ushort abs_vel_x;
  bool cannot_jump;

  cannot_jump = ecs_get_cannot_jump(self);
  if ((cannot_jump) || ((gamepad_pressed_prev & GAMEPAD_C) == GAMEPAD_NONE)) {
    return;
  }
  // Jump
  if ((&comp_collision[0].collision.y)[self] != '\r') {
    if (((((*(short *)((int)&comp_state + self) == 0) &&
           ((gamepad_held & GAMEPAD_DOWN) != GAMEPAD_NONE)) &&
          ((gamepad_held & GAMEPAD_LEFT) == GAMEPAD_NONE)) &&
         ((gamepad_held & GAMEPAD_RIGHT) == GAMEPAD_NONE)) &&
        ((((&component_collision_flags)[self] & 4) == 0 ||
          (((&comp_collision[0].collision.y)[self] != '\x0e' &&
            ((&comp_collision[0].collision.y)[self] == '\x04')))))) {
      if (((&component_unknown_5)[self] & 4) == 0) {
        return;
      }
      other = (entity_id_t) * (short *)((int)&component_unknown_9 + self);
      if (((&DAT_ffffd19a)[other] & 1) == 0) {
        return;
      }
    }
    *(undefined2 *)((int)&comp_vel[0].y + self) = 0xfb00;
    FUN_00012118(self, other);
    *(undefined2 *)((int)&comp_state + self) = 4;
    audio_play(SOUND_ID_JUMP);
    return;
  }
  abs_vel_x = *(ushort *)((int)&comp_vel[0].x + self);
  if ((short)abs_vel_x < 0) {
    abs_vel_x = -abs_vel_x;
  }
  if (0xff < abs_vel_x)
    goto LAB_0001180e;
  psVar1 = (short *)((int)&comp_vel[0].x + self);
  if (*psVar1 == 0) {
    cannot_jump = ((&comp_state_a)[self] & ENTITY_STATE_A_08) != 0;
    if (cannot_jump) {
      if (!cannot_jump)
        goto LAB_0001180e;
      goto LAB_000117fc;
    }
  } else if (*psVar1 < 0) {
  LAB_000117fc:
    *(undefined2 *)((int)&comp_vel[0].x + self) = 0xff00;
    goto LAB_0001180e;
  }
  *(undefined2 *)((int)&comp_vel[0].x + self) = 0x100;
LAB_0001180e:
  (&comp_anim_b)[self] = 0x10;
  ecs_anim_unk_2(self, (anim_item_t *)other, 2);
  audio_play(SOUND_ID_SLIP);
  ecs_holding_a_rope = ecs_holding_a_rope | 2;
  *(undefined2 *)((int)&comp_state + self) = 0x46;
  if ((pepelogoo_state_b & 0x80) != 0) {
    drop_pepelogoo();
  }
  return;
}

void FUN_0001183c(entity_id_t self, entity_id_t other)

{
  byte bVar1;
  bool bVar2;

  if (((((ecs_holding_a_rope & 0x20) == 0) &&
        ((ecs_holding_a_rope & 0x40) == 0)) &&
       ((ecs_holding_a_rope & 4) == 0)) &&
      ((*(short *)((int)&comp_state + self) != 0x5c &&
        ((((gamepad_held & GAMEPAD_DOWN) != GAMEPAD_NONE &&
           ((((&component_unknown_5)[self] |
              (&component_collision_flags)[self]) &
             4) != 0)) ||
          ((gamepad_pressed_prev & GAMEPAD_B) != GAMEPAD_NONE)))))) {
    if (component_state_a_pepelogoo == 6) {
      pepelogoo_state_b = pepelogoo_state_b | 0x10;
    }
    bVar1 = pepelogoo_state_b & 0x80;
    pepelogoo_state_b = pepelogoo_state_b & 0x5f;
    if (bVar1 != 0) {
      drop_pepelogoo();
    }
    ecs_holding_a_rope = ecs_holding_a_rope | 0xc;
    bVar2 = ecs_get_cannot_jump(self);
    if (bVar2) {
      *(undefined2 *)((int)&comp_state + self) = 10;
    } else {
      *(undefined2 *)((int)&comp_state + self) = 8;
      if (*(short *)((int)&comp_vel[0].y + self) < 0) {
        *(undefined2 *)((int)&comp_vel[0].y + self) = 0;
      }
    }
    bVar2 = false;
    audio_play(SOUND_ID_ATTACK);
    FUN_00018508(self, other, bVar2);
  }
  return;
}

void FUN_000118e0(entity_id_t self)

{
  short sVar1;
  short *psVar2;

  if (((&component_collision_flags)[self] & 4) != 0) {
    if (((&comp_collision[0].collision.y)[self] == '\f') ||
        ((&comp_collision[0].collision.y)[self] == '\x0e'))
      goto LAB_00011942;
    if ((&comp_collision[0].collision.y)[self] == '\r') {
      if ((gamepad_held & GAMEPAD_LEFT) == GAMEPAD_NONE) {
        if ((gamepad_held & GAMEPAD_RIGHT) != GAMEPAD_NONE) {
          if (*(short *)((int)&comp_vel[0].x + self) < 0) {
            if (((pepelogoo_state_b & 0x80) != 0) &&
                (psVar2 = (short *)((int)&comp_vel[0].x + self),
                 *psVar2 = *psVar2 + 4,
                 -1 < *(short *)((int)&comp_vel[0].x + self))) {
              *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
            }
          } else {
            psVar2 = (short *)((int)&comp_vel[0].x + self);
            *psVar2 = *psVar2 + 4;
          }
        }
      } else {
        psVar2 = (short *)((int)&comp_vel[0].x + self);
        if ((*psVar2 == 0) || (*psVar2 < 0)) {
          psVar2 = (short *)((int)&comp_vel[0].x + self);
          *psVar2 = *psVar2 + -4;
        } else if (((pepelogoo_state_b & 0x80) != 0) &&
                   (psVar2 = (short *)((int)&comp_vel[0].x + self),
                    *psVar2 = *psVar2 + -4,
                    *(short *)((int)&comp_vel[0].x + self) < 0)) {
          *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
        }
      }
      return;
    }
  }
  if ((((&component_unknown_5)[self] & 4) == 0) ||
      ((sVar1 = *(short *)((int)&DAT_ffffd29a +
                           (int)*(short *)((int)&component_unknown_9 + self)),
        (&comp_collision_related)[sVar1] != '\f' &&
            ((&comp_collision_related)[sVar1] != '\x0e')))) {
    if ((gamepad_held & GAMEPAD_LEFT) == GAMEPAD_NONE) {
      psVar2 = (short *)((int)&comp_vel[0].x + self);
      *psVar2 = *psVar2 + 0x40;
    } else {
      psVar2 = (short *)((int)&comp_vel[0].x + self);
      *psVar2 = *psVar2 + -0x40;
    }
    return;
  }
LAB_00011942:
  if ((gamepad_held & GAMEPAD_LEFT) == GAMEPAD_NONE) {
    psVar2 = (short *)((int)&comp_vel[0].x + self);
    *psVar2 = *psVar2 + 10;
  } else {
    psVar2 = (short *)((int)&comp_vel[0].x + self);
    *psVar2 = *psVar2 + -10;
  }
  return;
}

void FUN_000119b8(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;
  bool bVar1;

  if (((gamepad_held & GAMEPAD_DPAD_X) != GAMEPAD_NONE) &&
      (bVar1 = ecs_get_cannot_jump(unaff_A4), !bVar1)) {
    return;
  }
  FUN_00011dee(unaff_A4, unaff_A5);
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  return;
}

void FUN_000119d4(void)

{
  if (DAT_ffffcc8c == '\0') {
    FUN_000119ea();
  } else {
    FUN_00011a2c();
  }
  FUN_00011a0c();
  return;
}

void FUN_000119ea(void)

{
  ushort uVar1;
  int unaff_A4;

  uVar1 = *(ushort *)((int)&comp_vel[0].x + unaff_A4);
  if ((short)uVar1 < 0) {
    if ((short)uVar1 < -0x200) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfe00;
    }
  } else if (0x1ff < uVar1) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x200;
  }
  return;
}

ushort FUN_00011a0c(void)

{
  ushort uVar1;
  int unaff_A4;

  uVar1 = *(ushort *)((int)&comp_vel[0].y + unaff_A4);
  if ((short)uVar1 < 0) {
    if ((short)uVar1 < -0x500) {
      uVar1 = 0xfb00;
    }
  } else if (0x5ff < uVar1) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x600;
  }
  return uVar1;
}

void FUN_00011a2c(void)

{
  ushort uVar1;
  int unaff_A4;

  uVar1 = *(ushort *)((int)&comp_vel[0].x + unaff_A4);
  if ((short)uVar1 < 0) {
    if ((short)uVar1 < -0x400) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfc00;
    }
  } else if (0x3ff < uVar1) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x400;
  }
  return;
}

undefined4 FUN_00011a4e(void)

{
  undefined4 uVar1;
  code *pcVar2;
  int unaff_A4;

  uVar1 = 0;
  if (((*(short *)((int)&comp_state + unaff_A4) == 0) &&
       ((pepelogoo_state_b & 0x80) == 0)) &&
      (((set_to_13a62_when_facing_a_door != (code *)0x0 &&
         (pcVar2 = set_to_13a62_when_facing_a_door,
          (gamepad_pressed_prev & GAMEPAD_UP) != GAMEPAD_NONE)) ||
        ((DAT_ffffcc94 != (code *)0x0 &&
          (pcVar2 = DAT_ffffcc94,
           (gamepad_pressed_prev & GAMEPAD_DOWN) != GAMEPAD_NONE)))))) {
    (*pcVar2)();
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    uVar1 = 0xffffffff;
  }
  return uVar1;
}

void FUN_00011ab6(void)

{
  anim_item_t *unaff_A5;
  bool bVar1;

  if (-1 < (char)script_ctx_bf_0e_arg) {
    if (2 < script_ctx_bf_0e_arg) {
      if ((((gamepad_held & GAMEPAD_A) != GAMEPAD_NONE) &&
           (DAT_ffffcf96 != 0)) &&
          (*(short *)((int)&comp_anim_tick + (int)DAT_ffffcf96) == 0)) {
        ecs_anim_unk_2((int)DAT_ffffcf96, unaff_A5, 2);
      }
      return;
    }
    if (((((comp_state < COMP_STATE_ROPE_HOLD) || (0x18 < (short)comp_state)) &&
          ((component_state_a_pepelogoo != 0x28 &&
            ((component_state_a_pepelogoo != 0x22 &&
              (component_state_a_pepelogoo != 0x24)))))) &&
         ((ecs_holding_a_rope & 4) == 0)) &&
        ((((ecs_holding_a_rope & 8) == 0 &&
           ((pepelogoo_state_b & 0x40) == 0)) &&
          ((related_to_entering_a_room_2 & 0x20) == 0)))) {
      if ((gamepad_held & GAMEPAD_A) == GAMEPAD_NONE) {
        if (DAT_ffffcc82 != '\0') {
          DAT_ffffcc82 = 0;
          FUN_00029d0c();
          return;
        }
      } else {
        if ((ecs_holding_a_rope & 0x20) != 0) {
          DAT_ffffcc82 = 0;
          ecs_pepelogoo_something_1((entity_id_t)unaff_A5);
          return;
        }
        if ((pepelogoo_state_b & 0x80) != 0) {
          if ((gamepad_pressed_prev & GAMEPAD_A) != GAMEPAD_NONE) {
            bVar1 = ecs_get_cannot_jump(ENTITY_ID_ASHA);
            if (bVar1) {
              comp_state = COMP_STATE_THROW_PEPELOGOO_MID_AIR;
            } else {
              comp_state = COMP_STATE_THROW_PEPELOGOO;
            }
            ecs_holding_a_rope = ecs_holding_a_rope | 2;
            FUN_0002a504();
            return;
          }
          return;
        }
        DAT_ffffcc82 = -1;
        bVar1 = component_state_a_pepelogoo < 0x26;
        if (component_state_a_pepelogoo == 0x26) {
          ecs_pepelogoo_something_3((entity_id_t)unaff_A5);
        } else {
          FUN_00000ed6(ENTITY_ID_ASHA, ENTITY_ID_PEPELOGOO);
          if (bVar1) {
            DAT_ffffcc82 = '\0';
            FUN_0002a346();
            if (script_ctx_bf_0e_arg == 2) {
              comp_anim_b = 6;
              ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0xe);
            }
          } else {
            if ((ecs_holding_a_rope & 0x20) == 0) {
              ecs_pepelogoo_something_3((entity_id_t)unaff_A5);
              return;
            }
            ecs_pepelogoo_something_2();
          }
        }
      }
    }
  }
  return;
}

void FUN_00011c14(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;
  bool bVar1;

  bVar1 = ecs_get_cannot_jump(unaff_A4);
  if (bVar1) {
    if ((char)pepelogoo_state_b < '\0') {
      (&comp_anim_b)[unaff_A4] = 6;
    } else {
      (&comp_anim_b)[unaff_A4] = 0;
    }
    FUN_0001215a(unaff_A4, unaff_A5);
    *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
    if (DAT_ffff97e9 != '\0') {
      audio_play(SOUND_ID_FALL);
    }
  }
  return;
}

void FUN_00011c48(void)

{
  int unaff_A4;

  if ((((((gamepad_held & GAMEPAD_DOWN) != GAMEPAD_NONE) &&
         ((gamepad_held & GAMEPAD_LEFT) == GAMEPAD_NONE)) &&
        ((gamepad_held & GAMEPAD_RIGHT) == GAMEPAD_NONE)) &&
       ((gamepad_held & GAMEPAD_C) != GAMEPAD_NONE)) &&
      (((((&component_collision_flags)[unaff_A4] & 4) != 0 &&
         (((&comp_collision[0].collision.y)[unaff_A4] == '\x04' ||
           ((&comp_collision[0].collision.y)[unaff_A4] == '\x0e')))) ||
        ((((&component_unknown_5)[unaff_A4] & 4) != 0 &&
          (((&DAT_ffffd19a)[*(short *)((int)&component_unknown_9 + unaff_A4)] &
            1) == 0)))))) {
    comp_pos_y.fixed.i = comp_pos_y.fixed.i + 1;
    audio_play(SOUND_ID_FALL);
    FUN_00011de4();
  }
  return;
}

void FUN_00011caa(void)

{
  char cVar1;
  word wVar2;
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;

  wVar2 =
      FUN_00017330(*(word *)((int)&comp_pos_x + unaff_A4),
                   (*(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
                    *(short *)((int)&comp_pos_y + unaff_A4)) -
                       1);
  cVar1 = (&DAT_ffff6000)[(short)wVar2];
  if (cVar1 == '\x05') {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x22;
  } else if (cVar1 == '\x06') {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x24;
  } else {
    if (cVar1 != '\a') {
      return;
    }
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x26;
  }
  FUN_00011dee(unaff_A4, unaff_A5);
  ecs_holding_a_rope = ecs_holding_a_rope | 0x18;
  return;
}

void FUN_00011d02(entity_id_t self)

{
  FUN_00017330(*(word *)((int)&comp_pos_x + self),
               (*(short *)((int)&comp_collision_sensor[0].y + self) +
                *(short *)((int)&comp_pos_y + self)) -
                   1);
  return;
}

void FUN_00011d22(entity_id_t self, ushort param_2, short param_3, word param_4,
                  word param_5)

{
  FUN_0002ba00(self, param_2, param_3, param_4, param_5);
  return;
}

void FUN_00011d2a(entity_id_t self, entity_id_t other)

{
  short *psVar1;
  ushort uVar2;
  bool bVar3;

  if ((gamepad_held & GAMEPAD_LEFT) == GAMEPAD_NONE) {
    if ((gamepad_held & GAMEPAD_RIGHT) == GAMEPAD_NONE) {
      psVar1 = (short *)((int)&comp_vel[0].x + self);
      if (*psVar1 != 0) {
        if (*psVar1 < 0) {
          psVar1 = (short *)((int)&comp_vel[0].x + self);
          *psVar1 = *psVar1 + 5;
          if (-1 < *(short *)((int)&comp_vel[0].x + self)) {
            *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
          }
        } else {
          psVar1 = (short *)((int)&comp_vel[0].x + self);
          *psVar1 = *psVar1 + -5;
          if (*(short *)((int)&comp_vel[0].x + self) < 0) {
            *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
          }
        }
      }
    } else if (*(short *)((int)&comp_vel[0].x + self) < 0x200) {
      psVar1 = (short *)((int)&comp_vel[0].x + self);
      *psVar1 = *psVar1 + 0x20;
    } else {
      *(undefined2 *)((int)&comp_vel[0].x + self) = 0x200;
    }
  } else if (*(short *)((int)&comp_vel[0].x + self) < -0x1ff) {
    *(undefined2 *)((int)&comp_vel[0].x + self) = 0xfe00;
  } else {
    psVar1 = (short *)((int)&comp_vel[0].x + self);
    *psVar1 = *psVar1 + -0x20;
  }
  if (*(short *)((int)&comp_vel[0].y + self) < 0) {
    psVar1 = (short *)((int)&comp_vel[0].y + self);
    *psVar1 = *psVar1 + 0x40;
  } else {
    uVar2 = *(ushort *)((int)&comp_vel[0].y + self);
    if (uVar2 != 0x100) {
      if (uVar2 < 0x100) {
        psVar1 = (short *)((int)&comp_vel[0].y + self);
        *psVar1 = *psVar1 + 0x40;
        if (0xff < *(ushort *)((int)&comp_vel[0].y + self)) {
          *(undefined2 *)((int)&comp_vel[0].y + self) = 0x100;
        }
      } else {
        psVar1 = (short *)((int)&comp_vel[0].y + self);
        *psVar1 = *psVar1 + -0x40;
        if (*(ushort *)((int)&comp_vel[0].y + self) < 0x100) {
          *(undefined2 *)((int)&comp_vel[0].y + self) = 0x100;
        }
      }
    }
  }
  bVar3 = ecs_get_cannot_jump(self);
  if (!bVar3) {
    FUN_00011dee(self, other);
    *(undefined2 *)((int)&comp_state + self) = 0;
  }
  return;
}

void FUN_00011de4(void)

{
  short *psVar1;
  int iVar2;
  anim_item_t *unaff_A5;

  comp_state = COMP_STATE_STAND;
  if ((char)pepelogoo_state_b < '\0') {
    if (script_ctx_bf_0e_arg != '\x02') {
      if ((comp_anim_b != 6) || (comp_anim_c != 0)) {
        comp_anim_b = 6;
        ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
      }
      return;
    }
    if ((comp_anim_b != 6) ||
        (comp_anim_c != ECS_STATE_1_B_TALKING_OR_ENTERING_BACK_DOOR)) {
      comp_anim_b = 6;
      ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0xe);
    }
    comp_state = 0x4a;
    return;
  }
  if (comp_collision[0].collision.y == '\r') {
    if ((comp_anim_b != 0x10) || (comp_anim_c != 0)) {
      comp_anim_b = 0x10;
      ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
    }
    return;
  }
  if ((component_unknown_5 & 4) != 0) {
    iVar2 =
        (int)*(short *)((int)&DAT_ffffd29a + (int)(short)component_unknown_9);
    if (((&comp_func_offset[0].func_offset_from_15ede)[iVar2] == 0x28) ||
        ((&comp_func_offset[0].func_offset_from_15ede)[iVar2] == 0x26)) {
      comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
      if ((comp_anim_b != 0x12) || (comp_anim_c != 0)) {
        comp_anim_b = 0x12;
        ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
      }
      return;
    }
    if (((&comp_collision_related)[iVar2] == '\x0f') ||
        ((&comp_collision_related)[iVar2] == '\x10')) {
      if ((&comp_func_offset[0].func_offset_from_15ede)[iVar2] == 0x22) {
        psVar1 = (short *)((int)&comp_vel[0].x + iVar2);
        if (*psVar1 != 0) {
          if (*psVar1 < 0) {
            comp_state_a = comp_state_a | ENTITY_STATE_A_08;
          } else {
            comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
          }
        }
      } else {
        comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
        if (((&DAT_ffffb66f)[iVar2] & 4) != 0) {
          comp_state_a = comp_state_a | ENTITY_STATE_A_08;
        }
      }
      if ((comp_anim_b != 0x12) ||
          (comp_anim_c != ECS_STATE_1_B_ATTACKING_MID_AIR)) {
        comp_anim_b = 0x12;
        ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 8);
      }
      return;
    }
  }
  if ((comp_anim_b != 0) || (comp_anim_c != 0)) {
    comp_anim_b = 0;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  }
  return;
}

void FUN_00011dee(entity_id_t self, entity_id_t other)

{
  short *psVar1;
  int iVar2;

  if ((char)pepelogoo_state_b < '\0') {
    if (script_ctx_bf_0e_arg != '\x02') {
      if (((&comp_anim_b)[self] != 6) || ((&comp_anim_c)[self] != 0)) {
        (&comp_anim_b)[self] = 6;
        ecs_anim_unk_2(self, (anim_item_t *)other, 0);
      }
      return;
    }
    if (((&comp_anim_b)[self] != 6) ||
        ((&comp_anim_c)[self] != ECS_STATE_1_B_TALKING_OR_ENTERING_BACK_DOOR)) {
      (&comp_anim_b)[self] = 6;
      ecs_anim_unk_2(self, (anim_item_t *)other, 0xe);
    }
    *(undefined2 *)((int)&comp_state + self) = 0x4a;
    return;
  }
  if ((&comp_collision[0].collision.y)[self] == '\r') {
    if (((&comp_anim_b)[self] != 0x10) || ((&comp_anim_c)[self] != 0)) {
      (&comp_anim_b)[self] = 0x10;
      ecs_anim_unk_2(self, (anim_item_t *)other, 0);
    }
    return;
  }
  if (((&component_unknown_5)[self] & 4) != 0) {
    iVar2 = (int)*(short *)((int)&DAT_ffffd29a +
                            (int)*(short *)((int)&component_unknown_9 + self));
    if (((&comp_func_offset[0].func_offset_from_15ede)[iVar2] == 0x28) ||
        ((&comp_func_offset[0].func_offset_from_15ede)[iVar2] == 0x26)) {
      (&comp_state_a)[self] = (&comp_state_a)[self] & ~ENTITY_STATE_A_08;
      if (((&comp_anim_b)[self] != 0x12) || ((&comp_anim_c)[self] != 0)) {
        (&comp_anim_b)[self] = 0x12;
        ecs_anim_unk_2(self, (anim_item_t *)other, 0);
      }
      return;
    }
    if (((&comp_collision_related)[iVar2] == '\x0f') ||
        ((&comp_collision_related)[iVar2] == '\x10')) {
      if ((&comp_func_offset[0].func_offset_from_15ede)[iVar2] == 0x22) {
        psVar1 = (short *)((int)&comp_vel[0].x + iVar2);
        if (*psVar1 != 0) {
          if (*psVar1 < 0) {
            (&comp_state_a)[self] = (&comp_state_a)[self] | ENTITY_STATE_A_08;
          } else {
            (&comp_state_a)[self] = (&comp_state_a)[self] & ~ENTITY_STATE_A_08;
          }
        }
      } else {
        (&comp_state_a)[self] = (&comp_state_a)[self] & ~ENTITY_STATE_A_08;
        if (((&DAT_ffffb66f)[iVar2] & 4) != 0) {
          (&comp_state_a)[self] = (&comp_state_a)[self] | ENTITY_STATE_A_08;
        }
      }
      if (((&comp_anim_b)[self] != 0x12) ||
          ((&comp_anim_c)[self] != ECS_STATE_1_B_ATTACKING_MID_AIR)) {
        (&comp_anim_b)[self] = 0x12;
        ecs_anim_unk_2(self, (anim_item_t *)other, 8);
      }
      return;
    }
  }
  if (((&comp_anim_b)[self] != 0) || ((&comp_anim_c)[self] != 0)) {
    (&comp_anim_b)[self] = 0;
    ecs_anim_unk_2(self, (anim_item_t *)other, 0);
  }
  return;
}

void FUN_00011f3c(void)

{
  short *psVar1;
  int iVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if ((DAT_ffffcc64 == '\0') && (DAT_ffffcc8c != '\0')) {
    if (((&comp_anim_b)[unaff_A4] == 0) && ((&comp_anim_c)[unaff_A4] == 0x46)) {
      return;
    }
    (&comp_anim_b)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x46);
    return;
  }
  if (DAT_ffffcc64 == '\0') {
  LAB_00011fac:
    if ((char)pepelogoo_state_b < '\0') {
      if (script_ctx_bf_0e_arg == '\x02') {
        (&comp_anim_b)[unaff_A4] = 6;
        ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
        *(undefined2 *)((int)&comp_state + unaff_A4) = 0x4a;
        return;
      }
      if (((&comp_anim_b)[unaff_A4] == 6) &&
          ((&comp_anim_c)[unaff_A4] == ECS_STATE_1_B_WALKING_OR_DOWNSTAB)) {
        return;
      }
      (&comp_anim_b)[unaff_A4] = 6;
    } else {
      if ((((&component_unknown_5)[unaff_A4] & 4) != 0) &&
          ((iVar2 = (int)*(
                short *)((int)&DAT_ffffd29a +
                         (int)*(short *)((int)&component_unknown_9 + unaff_A4)),
            (&comp_collision_related)[iVar2] == '\x0f' ||
                ((&comp_collision_related)[iVar2] == '\x10')))) {
        if ((&comp_func_offset[0].func_offset_from_15ede)[iVar2] == 0x22) {
          psVar1 = (short *)((int)&comp_vel[0].x + iVar2);
          if (*psVar1 != 0) {
            if (*psVar1 < 0) {
              (&comp_state_a)[unaff_A4] =
                  (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
            } else {
              (&comp_state_a)[unaff_A4] =
                  (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
            }
          }
        } else {
          (&comp_state_a)[unaff_A4] =
              (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
          if (((&DAT_ffffb66f)[iVar2] & 4) != 0) {
            (&comp_state_a)[unaff_A4] =
                (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
          }
        }
        if (((&comp_anim_b)[unaff_A4] != 0x12) ||
            ((&comp_anim_c)[unaff_A4] !=
             (ECS_STATE_1_B_ATTACKING_MID_AIR |
              ECS_STATE_1_B_JUMPING_OR_UNSHIELDING))) {
          (&comp_anim_b)[unaff_A4] = 0x12;
          ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
        }
        return;
      }
      if (((&comp_anim_b)[unaff_A4] == 0) &&
          ((&comp_anim_c)[unaff_A4] == ECS_STATE_1_B_WALKING_OR_DOWNSTAB)) {
        return;
      }
      (&comp_anim_b)[unaff_A4] = 0;
    }
    ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  } else {
    if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) == 0) {
      if ((ushort)component_pos_x_pepelogoo.fixed.i <
          *(ushort *)((int)&comp_pos_x + unaff_A4))
        goto LAB_00011fac;
    } else if (*(ushort *)((int)&comp_pos_x + unaff_A4) <
               (ushort)component_pos_x_pepelogoo.fixed.i)
      goto LAB_00011fac;
    if (((&comp_anim_b)[unaff_A4] != 0x10) ||
        ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_JUMPING_OR_UNSHIELDING)) {
      (&comp_anim_b)[unaff_A4] = 0x10;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
    }
  }
  return;
}

void FUN_0001207c(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if (DAT_ffffcc64 == '\0') {
  LAB_000120be:
    if ((char)pepelogoo_state_b < '\0') {
      if (script_ctx_bf_0e_arg == '\x02') {
        (&comp_anim_b)[unaff_A4] = 6;
        ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
        *(undefined2 *)((int)&comp_state + unaff_A4) = 0x4a;
        return;
      }
      if (((&comp_anim_b)[unaff_A4] == 0x10) &&
          ((&comp_anim_c)[unaff_A4] == 0)) {
        return;
      }
      (&comp_anim_b)[unaff_A4] = 0x10;
    } else {
      if (((&comp_anim_b)[unaff_A4] == 0x10) &&
          ((&comp_anim_c)[unaff_A4] == 0)) {
        return;
      }
      (&comp_anim_b)[unaff_A4] = 0x10;
    }
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  } else {
    if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) == 0) {
      if (*(ushort *)((int)&comp_pos_x + unaff_A4) <
          *(ushort *)((int)&comp_pos_x + unaff_A4))
        goto LAB_000120be;
    } else if ((ushort)component_pos_x_pepelogoo.fixed.i <
               *(ushort *)((int)&comp_pos_x + unaff_A4))
      goto LAB_000120be;
    if (((&comp_anim_b)[unaff_A4] != 0x10) ||
        ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_FALLING)) {
      (&comp_anim_b)[unaff_A4] = 0x10;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    }
  }
  return;
}

void FUN_00012118(entity_id_t self, entity_id_t other)

{
  if ((char)pepelogoo_state_b < '\0') {
    if (((&comp_anim_b)[self] != 6) ||
        ((&comp_anim_c)[self] != ECS_STATE_1_B_JUMPING_OR_UNSHIELDING)) {
      (&comp_anim_b)[self] = 6;
      ecs_anim_unk_2(self, (anim_item_t *)other, 4);
    }
  } else if (((&comp_anim_b)[self] != 0) ||
             ((&comp_anim_c)[self] != ECS_STATE_1_B_JUMPING_OR_UNSHIELDING)) {
    (&comp_anim_b)[self] = 0;
    ecs_anim_unk_2(self, (anim_item_t *)other, 4);
  }
  return;
}

void FUN_0001215a(entity_id_t self, entity_id_t other)

{
  if ((char)pepelogoo_state_b < '\0') {
    if (script_ctx_bf_0e_arg == '\x02') {
      if (((&comp_anim_b)[self] != 6) || ((&comp_anim_c)[self] != 0x10)) {
        (&comp_anim_b)[self] = 6;
        ecs_anim_unk_2(self, (anim_item_t *)other, 0x10);
      }
      return;
    }
    if (((&comp_anim_b)[self] != 6) ||
        ((&comp_anim_c)[self] != ECS_STATE_1_B_FALLING)) {
      (&comp_anim_b)[self] = 6;
      ecs_anim_unk_2(self, (anim_item_t *)other, 6);
    }
  } else if (((&comp_anim_b)[self] != 0) ||
             ((&comp_anim_c)[self] != ECS_STATE_1_B_FALLING)) {
    (&comp_anim_b)[self] = 0;
    ecs_anim_unk_2(self, (anim_item_t *)other, 6);
  }
  return;
}

void FUN_000121c2(entity_id_t self, entity_id_t other)

{
  if (((&comp_state_1_a)[self] & 0x20) != 0) {
    pepelogoo_state_b = pepelogoo_state_b | 0x10;
    (&comp_state_1_a)[self] = (&comp_state_1_a)[self] & 0xdf;
  }
  if (*(short *)((int)&comp_anim_tick + self) == 0) {
    FUN_00011dee(self, other);
    ecs_holding_a_rope = ecs_holding_a_rope & 0xfd;
    *(undefined2 *)((int)&comp_state + self) = 0;
  }
  FUN_0001128a(self);
  ecs_cap_fall_speed(self);
  return;
}

void FUN_000121f6(entity_id_t self, entity_id_t other)

{
  if (((&comp_state_1_a)[self] & 0x20) != 0) {
    pepelogoo_state_b = pepelogoo_state_b | 0x10;
    (&comp_state_1_a)[self] = (&comp_state_1_a)[self] & 0xdf;
  }
  if (*(short *)((int)&comp_anim_tick + self) == 0) {
    ecs_holding_a_rope = ecs_holding_a_rope & 0xfd;
    if (*(short *)((int)&comp_vel[0].y + self) < 0) {
      FUN_00012118(self, other);
      *(undefined2 *)((int)&comp_state + self) = 4;
    } else {
      FUN_0001215a(self, other);
      *(undefined2 *)((int)&comp_state + self) = 6;
    }
  }
  FUN_00012238(self);
  return;
}

void FUN_00012238(entity_id_t self)

{
  short *psVar1;
  bool bVar2;

  if ((ecs_holding_a_rope & 4) == 0) {
    if ((gamepad_held & GAMEPAD_LEFT) != GAMEPAD_NONE) {
      if (*(short *)((int)&comp_vel[0].x + self) < -0x1ff) {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0xfe00;
      } else {
        psVar1 = (short *)((int)&comp_vel[0].x + self);
        *psVar1 = *psVar1 + -0x20;
      }
      goto LAB_000122a6;
    }
    if ((gamepad_held & GAMEPAD_RIGHT) != GAMEPAD_NONE) {
      if (*(short *)((int)&comp_vel[0].x + self) < 0x200) {
        psVar1 = (short *)((int)&comp_vel[0].x + self);
        *psVar1 = *psVar1 + 0x20;
      } else {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0x200;
      }
      goto LAB_000122a6;
    }
  }
  psVar1 = (short *)((int)&comp_vel[0].x + self);
  if (*psVar1 != 0) {
    if (*psVar1 < 0) {
      psVar1 = (short *)((int)&comp_vel[0].x + self);
      *psVar1 = *psVar1 + 5;
      if (-1 < *(short *)((int)&comp_vel[0].x + self)) {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
      }
    } else {
      psVar1 = (short *)((int)&comp_vel[0].x + self);
      *psVar1 = *psVar1 + -5;
      if (*(short *)((int)&comp_vel[0].x + self) < 0) {
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
      }
    }
  }
LAB_000122a6:
  if ((*(short *)((int)&comp_vel[0].y + self) < 0) &&
      ((gamepad_held & GAMEPAD_C) == GAMEPAD_NONE)) {
    psVar1 = (short *)((int)&comp_vel[0].y + self);
    *psVar1 = *psVar1 + 0x80;
    if (-1 < *(short *)((int)&comp_vel[0].y + self)) {
      *(undefined2 *)((int)&comp_vel[0].y + self) = 0;
    }
  } else {
    psVar1 = (short *)((int)&comp_vel[0].y + self);
    *psVar1 = *psVar1 + 0x40;
  }
  if (0x5ff < *(short *)((int)&comp_vel[0].y + self)) {
    *(undefined2 *)((int)&comp_vel[0].y + self) = 0x600;
  }
  if ((((ecs_holding_a_rope & 4) == 0) &&
       (*(short *)((int)&comp_state + self) != 4)) &&
      (*(short *)((int)&comp_state + self) != 6)) {
    bVar2 = ecs_get_cannot_jump(self);
    if (!bVar2) {
      *(undefined2 *)((int)&comp_state + self) = 0x2e;
    }
  }
  return;
}

void FUN_000122aa(entity_id_t self, bool param_2)

{
  short *psVar1;
  bool bVar2;

  if ((param_2) && ((gamepad_held & GAMEPAD_C) == GAMEPAD_NONE)) {
    psVar1 = (short *)((int)&comp_vel[0].y + self);
    *psVar1 = *psVar1 + 0x80;
    if (-1 < *(short *)((int)&comp_vel[0].y + self)) {
      *(undefined2 *)((int)&comp_vel[0].y + self) = 0;
    }
  } else {
    psVar1 = (short *)((int)&comp_vel[0].y + self);
    *psVar1 = *psVar1 + 0x40;
  }
  if (0x5ff < *(short *)((int)&comp_vel[0].y + self)) {
    *(undefined2 *)((int)&comp_vel[0].y + self) = 0x600;
  }
  if ((((ecs_holding_a_rope & 4) == 0) &&
       (*(short *)((int)&comp_state + self) != 4)) &&
      (*(short *)((int)&comp_state + self) != 6)) {
    bVar2 = ecs_get_cannot_jump(self);
    if (!bVar2) {
      *(undefined2 *)((int)&comp_state + self) = 0x2e;
    }
  }
  return;
}

void FUN_00012300(void)

{
  ushort uVar1;
  short unaff_D3w;

  uVar1 = FUN_000183ce(unaff_D3w);
  if ((uVar1 & 0x40) != 0) {
    DAT_ffffcc93 = 8;
    DAT_ffffcc92 = 1;
  }
  return;
}

void FUN_00012324(void)

{
  int unaff_A4;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  }
  return;
}

void FUN_00012332(void)

{
  anim_item_t *unaff_A5;

  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x26);
  comp_state = COMP_STATE_THROW_PEPELOGOO_MID_AIR | COMP_STATE_WALK;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00012352(void)

{
  int unaff_A4;
  entity_id_t self;
  anim_item_t *unaff_A5;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    self = (entity_id_t)_DAT_ffffcc6e;
    script_state_set_true(*(script_state_bit_t *)(&DAT_ffffba76 + self));
    ecs_anim_unk_2(self, unaff_A5, 2);
    comp_state = COMP_STATE_STAND;
    ecs_holding_a_rope = ecs_holding_a_rope & 0x7f;
  }
  return;
}

void FUN_0001237e(void)

{
  anim_item_t *unaff_A5;

  audio_play(SOUND_ID_JUMP);
  comp_vel[0].y.raw = 0x600;
  comp_vel[0].x.raw = 0;
  comp_anim_b = 0x12;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 2);
  comp_state = 0x56;
  return;
}

void FUN_000123a8(void)

{
  anim_item_t *unaff_A5;

  audio_play(SOUND_ID_JUMP);
  comp_vel[0].y.raw = -0xa00;
  comp_vel[0].x.raw = 0;
  comp_anim_b = 0x12;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 2);
  comp_state = 0x56;
  return;
}

void FUN_000123d2(void)

{
  anim_item_t *unaff_A5;

  audio_play(SOUND_ID_JUMP);
  comp_vel[0].x.raw = -0x600;
  comp_vel[0].y.raw = -0x200;
  comp_anim_b = 0x12;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 2);
  comp_state = 0x58;
  return;
}

void FUN_000123fe(void)

{
  anim_item_t *unaff_A5;

  audio_play(SOUND_ID_JUMP);
  comp_vel[0].x.raw = 0x600;
  comp_vel[0].y.raw = -0x200;
  comp_anim_b = 0x12;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 2);
  comp_state = 0x58;
  return;
}

void FUN_0001242a(void)

{
  anim_item_t *unaff_A5;

  audio_play(SOUND_ID_JUMP);
  comp_vel[0].y.raw = -0x600;
  if ((comp_state_a & ENTITY_STATE_A_08) == 0) {
    comp_vel[0].x.raw = 0x200;
  } else {
    comp_vel[0].x.raw = -0x200;
  }
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 4);
  comp_state = COMP_STATE_ROPE_JUMP;
  return;
}

void FUN_00012466(void)

{
  anim_item_t *unaff_A5;

  if ((pepelogoo_state_b & 0x80) != 0) {
    FUN_00029d0c();
  }
  comp_state = COMP_STATE_JUMP_FROM_PEPELOGOO;
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x2c);
  return;
}

void FUN_00012490(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;

  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  FUN_00011dee(unaff_A4, unaff_A5);
  ecs_update_h_flip_asha_from_gamepad(unaff_A4);
  FUN_00011c14();
  ecs_try_jump(unaff_A4, unaff_A5);
  return;
}

void FUN_000124a6(void)

{
  int unaff_A4;

  if ((((pepelogoo_state_b & 0x80) != 0) &&
       (((&component_unknown_5)[unaff_A4] & 4) != 0)) &&
      ((&comp_func_offset[0].func_offset_from_15ede)[*(
           short *)((int)&DAT_ffffd29a +
                    (int)*(short *)((int)&component_unknown_9 + unaff_A4))] ==
       0x18)) {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x42;
    FUN_0002aa82();
  }
  return;
}

void FUN_000124d4(void)

{
  short sVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 in_ZF;
  undefined1 in_CF;

  FUN_00012786();
  if ((bool)in_CF || (bool)in_ZF) {
    if ((gamepad_pressed_prev & GAMEPAD_C) == GAMEPAD_NONE) {
      FUN_000124f2();
      return;
    }
  } else {
    sVar1 = FUN_0001270a();
    if (sVar1 == 0) {
      ecs_holding_a_rope = ecs_holding_a_rope & 0xf7;
      (&comp_anim_b)[unaff_A4] = 0;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0x2c);
      *(undefined2 *)((int)&comp_state + unaff_A4) = 0x36;
      ecs_holding_a_rope = ecs_holding_a_rope & 0xfd;
      return;
    }
    if ((gamepad_pressed_prev & GAMEPAD_C) == GAMEPAD_NONE) {
      FUN_000124f2();
      return;
    }
  }
  audio_play(SOUND_ID_JUMP);
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0x3a;
  (&comp_anim_b)[unaff_A4] = 0;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
  FUN_00012604();
  return;
}

void FUN_000124f2(void)

{
  byte bVar1;
  short sVar2;
  int in_A0;
  int unaff_A4;

  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  bVar1 = (&DAT_ffffceff)[in_A0];
  if ((bVar1 & 1) != 0) {
    sVar2 = *(ushort *)(&DAT_ffffcf1e + in_A0) -
            *(ushort *)((int)&comp_pos_y + unaff_A4);
    if (*(ushort *)(&DAT_ffffcf1e + in_A0) <
        *(ushort *)((int)&comp_pos_y + unaff_A4)) {
      if (sVar2 < -1) {
        sVar2 = -2;
      }
    } else if (2 < sVar2) {
      sVar2 = 2;
    }
    *(short *)((int)&comp_vel[0].y + unaff_A4) = sVar2 << 8;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x200;
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  }
  if ((bVar1 & 2) != 0) {
    sVar2 = *(ushort *)(&DAT_ffffcf1e + in_A0) -
            *(ushort *)((int)&comp_pos_y + unaff_A4);
    if (*(ushort *)(&DAT_ffffcf1e + in_A0) <
        *(ushort *)((int)&comp_pos_y + unaff_A4)) {
      if (sVar2 < -1) {
        sVar2 = -2;
      }
    } else if (2 < sVar2) {
      sVar2 = 2;
    }
    *(short *)((int)&comp_vel[0].y + unaff_A4) = sVar2 << 8;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfe00;
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  }
  if ((bVar1 & 4) != 0) {
    sVar2 = *(ushort *)(&DAT_ffffcf00 + in_A0) -
            *(ushort *)((int)&comp_pos_x + unaff_A4);
    if (*(ushort *)(&DAT_ffffcf00 + in_A0) <
        *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      if (sVar2 < -1) {
        sVar2 = -2;
      }
    } else if (2 < sVar2) {
      sVar2 = 2;
    }
    *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar2 << 8;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x200;
  }
  if ((bVar1 & 8) != 0) {
    sVar2 = *(ushort *)(&DAT_ffffcf00 + in_A0) -
            *(ushort *)((int)&comp_pos_x + unaff_A4);
    if (*(ushort *)(&DAT_ffffcf00 + in_A0) <
        *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      if (sVar2 < -1) {
        sVar2 = -2;
      }
    } else if (2 < sVar2) {
      sVar2 = 2;
    }
    *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar2 << 8;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfe00;
  }
  return;
}

void FUN_00012604(void)

{
  byte bVar1;
  int iVar2;
  int unaff_A4;

  iVar2 = (int)DAT_ffffcc78;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfa80;
  bVar1 = (&DAT_ffffceff)[iVar2];
  if ((bVar1 & 1) == 0) {
    if ((bVar1 & 2) == 0) {
      if ((bVar1 & 0x10) != 0) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x200;
      }
      if ((bVar1 & 0x20) != 0) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfe00;
      }
    } else {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfe00;
    }
  } else {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x200;
  }
  return;
}

void FUN_0001265c(void)

{
  short sVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  sVar1 = FUN_0001270a();
  if (sVar1 == 0) {
    ecs_holding_a_rope = ecs_holding_a_rope & 0xf7;
    (&comp_anim_b)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x2c);
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x36;
    ecs_holding_a_rope = ecs_holding_a_rope & 0xfd;
    return;
  }
  if ((gamepad_pressed_prev & GAMEPAD_C) != GAMEPAD_NONE) {
    audio_play(SOUND_ID_JUMP);
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x3a;
    (&comp_anim_b)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
    FUN_00012604();
    return;
  }
  FUN_000124f2();
  return;
}

void FUN_0001267a(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_holding_a_rope = ecs_holding_a_rope & 0xf7;
  (&comp_anim_b)[unaff_A4] = 0;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0x2c);
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0x36;
  ecs_holding_a_rope = ecs_holding_a_rope & 0xfd;
  return;
}

void FUN_0001269a(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 in_ZF;
  undefined1 in_CF;

  FUN_00012786();
  if ((bool)in_CF || (bool)in_ZF) {
    FUN_000126ce();
    return;
  }
  ecs_holding_a_rope = ecs_holding_a_rope & 0xf5;
  (&comp_anim_b)[unaff_A4] = 0;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0x2c);
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0x36;
  FUN_000126ce();
  return;
}

void FUN_000126ce(void)

{
  short *psVar1;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  if (*psVar1 != 0) {
    if (*psVar1 < 0) {
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + 5;
      if (-1 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      }
    } else {
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + -5;
      if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      }
    }
  }
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x40;
  if (0x5ff < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x600;
  }
  return;
}

undefined4 FUN_0001270a(void)

{
  undefined4 uVar1;
  uint uVar2;
  uint extraout_A0;

  uVar2 = 0;
  while ((-1 < (char)(&DAT_ffffcefe)[uVar2] ||
          (uVar1 = FUN_00012728(), uVar2 = extraout_A0, (short)uVar1 == 0))) {
    uVar2 = uVar2 + 4;
    if (0x1f < uVar2) {
      return 0;
    }
  }
  return uVar1;
}

undefined4 FUN_00012728(void)

{
  undefined1 in_ZF;
  undefined1 in_CF;

  FUN_00012786();
  if ((bool)in_CF || (bool)in_ZF) {
    FUN_00012752();
    FUN_00018c56();
    if ((pepelogoo_state_b & 0x80) != 0) {
      drop_pepelogoo();
      pepelogoo_state_b = pepelogoo_state_b & 0x7f;
    }
    return 0xffffffff;
  }
  return 0;
}

void FUN_00012752(void)

{
  undefined2 in_A0w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_holding_a_rope = ecs_holding_a_rope & 0xbf;
  DAT_ffffd16c = 0;
  ecs_holding_a_rope = ecs_holding_a_rope | 8;
  DAT_ffffcc78 = in_A0w;
  FUN_000124f2();
  ecs_holding_a_rope = ecs_holding_a_rope | 2;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0x38;
  (&comp_anim_b)[unaff_A4] = 0xe;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  return;
}

ushort FUN_00012786(void)

{
  ushort uVar1;
  int in_A0;
  int unaff_A4;

  uVar1 = *(ushort *)(&DAT_ffffcf00 + in_A0) -
          *(ushort *)((int)&comp_pos_x + unaff_A4);
  if (*(ushort *)(&DAT_ffffcf00 + in_A0) <
      *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    uVar1 = -uVar1;
  }
  if ((uVar1 <=
       (ushort)(*(short *)((int)&comp_collision_sensor[0].x + unaff_A4) +
                *(short *)(&DAT_ffffcf20 + in_A0))) &&
      (uVar1 = *(ushort *)(&DAT_ffffcf1e + in_A0) -
               *(ushort *)((int)&comp_pos_y + unaff_A4),
       *(ushort *)(&DAT_ffffcf1e + in_A0) <
           *(ushort *)((int)&comp_pos_y + unaff_A4))) {
    uVar1 = -uVar1;
  }
  return uVar1;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000127b6(void)

{
  ushort uVar1;
  ushort uVar2;
  word wVar3;
  short sVar4;
  ushort unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  byte *pbVar5;
  byte *extraout_A1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  uint8_t_ffffcc70 = '\0';
  if (*(ushort *)((int)&comp_pos_x + unaff_A4) == _DAT_ffffcc7e) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  } else if (*(ushort *)((int)&comp_pos_x + unaff_A4) < _DAT_ffffcc7e) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x400;
  } else {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfc00;
  }
  if (*(ushort *)((int)&comp_pos_y + unaff_A4) == _DAT_ffffcc80) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  } else if (*(ushort *)((int)&comp_pos_y + unaff_A4) < _DAT_ffffcc80) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x500;
  } else {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfd00;
  }
  entity_update_pos(unaff_A4);
  uVar1 = _DAT_ffffcc7e;
  if (_DAT_ffffcc7e != *(ushort *)((int)component_pos_old_x + unaff_A4)) {
    if (_DAT_ffffcc7e < *(ushort *)((int)component_pos_old_x + unaff_A4)) {
      if (*(ushort *)((int)&comp_pos_x + unaff_A4) <= _DAT_ffffcc7e) {
        *(ushort *)((int)&comp_pos_x + unaff_A4) = _DAT_ffffcc7e;
      }
    } else if (_DAT_ffffcc7e <= *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      *(ushort *)((int)&comp_pos_x + unaff_A4) = _DAT_ffffcc7e;
    }
  }
  uVar2 = _DAT_ffffcc80;
  if (_DAT_ffffcc80 != *(ushort *)((int)component_pos_old_y + unaff_A4)) {
    if (*(ushort *)((int)component_pos_old_y + unaff_A4) < _DAT_ffffcc80) {
      if (_DAT_ffffcc80 <= *(ushort *)((int)&comp_pos_y + unaff_A4)) {
        *(ushort *)((int)&comp_pos_y + unaff_A4) = _DAT_ffffcc80;
      }
    } else if (*(ushort *)((int)&comp_pos_y + unaff_A4) <= _DAT_ffffcc80) {
      *(ushort *)((int)&comp_pos_y + unaff_A4) = _DAT_ffffcc80;
    }
  }
  if ((uVar1 != *(ushort *)((int)&comp_pos_x + unaff_A4)) ||
      (pbVar5 = _DAT_ffffcc7a,
       uVar2 != *(ushort *)((int)&comp_pos_y + unaff_A4))) {
    return;
  }
  while (-1 < (char)*pbVar5) {
    sVar4 = (*(code *)((int)&WORD_000128a0 +
                       (int)*(short *)((int)&WORD_000128a0 +
                                       (int)(short)((ushort)*pbVar5 * 2))))();
    pbVar5 = extraout_A1;
    if (sVar4 < 0) {
      _DAT_ffffcc7a = extraout_A1;
      return;
    }
  }
  ecs_holding_a_rope = ecs_holding_a_rope & 0xf7;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  *(undefined4 *)((int)component_pos_old_x + unaff_A4) =
      *(undefined4 *)((int)&comp_pos_x + unaff_A4);
  *(undefined4 *)((int)component_pos_old_y + unaff_A4) =
      *(undefined4 *)((int)&comp_pos_y + unaff_A4);
  FUN_00011dee(unaff_A4, (entity_id_t)unaff_A5);
  ecs_holding_a_rope = ecs_holding_a_rope & 0xdf;
  DAT_ffffcc64 = 0;
  if (DAT_ffffcc85 != '\0') {
    comp_state = COMP_STATE_STAND;
    if (DAT_ffffcc86 != '\x01') {
      FUN_00018c56();
      comp_vel[0].x.raw = 0;
      ecs_cap_fall_speed(ENTITY_ID_ASHA);
      FUN_0002ba00(ENTITY_ID_ASHA, unaff_D2w, unaff_D3w, unaff_D6w, unaff_D7w);
      if (DAT_ffffcc86 != '\x02') {
        if (((component_unknown_5 | component_collision_flags) & 4) == 0) {
          if ((comp_anim_b != 0) || (comp_anim_c != ECS_STATE_1_B_FALLING)) {
            comp_anim_b = 0;
            ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 6);
          }
        } else if ((comp_anim_b != 0) || (comp_anim_c != 0)) {
          comp_anim_b = 0;
          ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
        }
      }
    }
    FUN_000103e0();
    FUN_00012f0e();
    return;
  }
  decrement_something_until_0();
  ecs_update_h_flip_asha_1();
  if (comp_state !=
      (COMP_STATE_THROW_PEPELOGOO_MID_AIR | COMP_STATE_ROPE_HOLD)) {
    if ((ecs_holding_a_rope & 0x40) == 0) {
      ecs_update_h_flip_asha_from_gamepad(ENTITY_ID_ASHA);
    }
    sVar4 = FUN_00011a4e();
    if (sVar4 < 0)
      goto LAB_00010106;
  }
  wVar3 = FUN_0001035a();
  FUN_000102e6(ENTITY_ID_ASHA, wVar3);
  (*(code *)((int)&WORD_00010258 +
             (int)*(short *)((int)&WORD_00010258 + (int)(short)comp_state)))();
  if (comp_state !=
      (COMP_STATE_THROW_PEPELOGOO_MID_AIR | COMP_STATE_ROPE_HOLD)) {
    sVar4 = FUN_00010194();
    if (sVar4 == 0) {
      FUN_0001183c(ENTITY_ID_ASHA, (entity_id_t)unaff_A5);
    }
    FUN_00011caa();
    FUN_00012300();
    FUN_000101e0(0, unaff_A5, unaff_D2w);
    FUN_00010202();
    FUN_00010fb8(ENTITY_ID_ASHA,
                 (entity_id_t)unaff_A5,
                 unaff_D2w,
                 unaff_D3w,
                 unaff_D6w,
                 unaff_D7w);
  }
  FUN_00011228();
LAB_00010106:
  FUN_000103e0();
  FUN_00012f0e();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00012854(void)

{
  word wVar1;
  short sVar2;
  ushort unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  byte *pbVar3;
  byte *extraout_A1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  pbVar3 = _DAT_ffffcc7a;
  while (-1 < (char)*pbVar3) {
    sVar2 = (*(code *)((int)&WORD_000128a0 +
                       (int)*(short *)((int)&WORD_000128a0 +
                                       (int)(short)((ushort)*pbVar3 * 2))))();
    pbVar3 = extraout_A1;
    if (sVar2 < 0) {
      _DAT_ffffcc7a = extraout_A1;
      return;
    }
  }
  ecs_holding_a_rope = ecs_holding_a_rope & 0xf7;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  *(undefined4 *)((int)component_pos_old_x + unaff_A4) =
      *(undefined4 *)((int)&comp_pos_x + unaff_A4);
  *(undefined4 *)((int)component_pos_old_y + unaff_A4) =
      *(undefined4 *)((int)&comp_pos_y + unaff_A4);
  FUN_00011dee(unaff_A4, (entity_id_t)unaff_A5);
  ecs_holding_a_rope = ecs_holding_a_rope & 0xdf;
  DAT_ffffcc64 = 0;
  if (DAT_ffffcc85 != '\0') {
    comp_state = COMP_STATE_STAND;
    if (DAT_ffffcc86 != '\x01') {
      FUN_00018c56();
      comp_vel[0].x.raw = 0;
      ecs_cap_fall_speed(ENTITY_ID_ASHA);
      FUN_0002ba00(ENTITY_ID_ASHA, unaff_D2w, unaff_D3w, unaff_D6w, unaff_D7w);
      if (DAT_ffffcc86 != '\x02') {
        if (((component_unknown_5 | component_collision_flags) & 4) == 0) {
          if ((comp_anim_b != 0) || (comp_anim_c != ECS_STATE_1_B_FALLING)) {
            comp_anim_b = 0;
            ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 6);
          }
        } else if ((comp_anim_b != 0) || (comp_anim_c != 0)) {
          comp_anim_b = 0;
          ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
        }
      }
    }
    FUN_000103e0();
    FUN_00012f0e();
    return;
  }
  decrement_something_until_0();
  ecs_update_h_flip_asha_1();
  if (comp_state !=
      (COMP_STATE_THROW_PEPELOGOO_MID_AIR | COMP_STATE_ROPE_HOLD)) {
    if ((ecs_holding_a_rope & 0x40) == 0) {
      ecs_update_h_flip_asha_from_gamepad(ENTITY_ID_ASHA);
    }
    sVar2 = FUN_00011a4e();
    if (sVar2 < 0)
      goto LAB_00010106;
  }
  wVar1 = FUN_0001035a();
  FUN_000102e6(ENTITY_ID_ASHA, wVar1);
  (*(code *)((int)&WORD_00010258 +
             (int)*(short *)((int)&WORD_00010258 + (int)(short)comp_state)))();
  if (comp_state !=
      (COMP_STATE_THROW_PEPELOGOO_MID_AIR | COMP_STATE_ROPE_HOLD)) {
    sVar2 = FUN_00010194();
    if (sVar2 == 0) {
      FUN_0001183c(ENTITY_ID_ASHA, (entity_id_t)unaff_A5);
    }
    FUN_00011caa();
    FUN_00012300();
    FUN_000101e0(0, unaff_A5, unaff_D2w);
    FUN_00010202();
    FUN_00010fb8(ENTITY_ID_ASHA,
                 (entity_id_t)unaff_A5,
                 unaff_D2w,
                 unaff_D3w,
                 unaff_D6w,
                 unaff_D7w);
  }
  FUN_00011228();
LAB_00010106:
  FUN_000103e0();
  FUN_00012f0e();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_000128a8(void)

{
  undefined2 *in_A1;

  _DAT_ffffcc7e = *in_A1;
  _DAT_ffffcc80 = in_A1[1];
  return 0xffffffff;
}

undefined4 FUN_000128c0(void)

{
  byte *in_A1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_anim_b)[unaff_A4] = *in_A1;
  ecs_anim_unk_2(unaff_A4, unaff_A5, in_A1[1]);
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000128d4(void)

{
  undefined4 in_D0;

  if (comp_state !=
      (COMP_STATE_THROW_PEPELOGOO_MID_AIR | COMP_STATE_ROPE_HOLD)) {
    _DAT_ffffcc7a = in_D0;
    FUN_00012854();
    comp_state = COMP_STATE_THROW_PEPELOGOO_MID_AIR | COMP_STATE_ROPE_HOLD;
    FUN_00018c56();
    ecs_holding_a_rope = ecs_holding_a_rope | 8;
    drop_pepelogoo();
  }
  return;
}

void FUN_00012902(void)

{
  int unaff_A4;

  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] & 0xf7;
  return;
}

void FUN_0001290a(void)

{
  int unaff_A4;

  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 8;
  return;
}

void FUN_00012912(ulong ctx, byte *param_2, short new_ctx)

{
  if ((((ecs_holding_a_rope & 0x20) == 0) && (DAT_ffffcbf6 != 0)) &&
      (DAT_ffffcbf6 <=
       (ushort)((*(short *)((int)&comp_collision_sensor[0].y + ctx) +
                 *(short *)((int)&comp_pos_y + ctx)) -
                1U))) {
    ecs_holding_a_rope = ecs_holding_a_rope | 0x20;
    FUN_00018c56();
    *(undefined2 *)((int)&comp_state + ctx) = 0x3e;
    (&comp_anim_b)[ctx] = 0xe;
    ecs_anim_unk_2(ctx, param_2, 0);
    *(undefined2 *)((int)&comp_vel[0].y + ctx) = 0;
    if ((((pepelogoo_state_b & 0x20) != 0) ||
         ((pepelogoo_state_b & 0x40) != 0)) ||
        ((pepelogoo_state_b & 0x80) != 0)) {
      drop_pepelogoo();
    }
    ecs_holding_a_rope = ecs_holding_a_rope | 8;
    if (*(ushort *)((int)component_pos_old_y + ctx) < DAT_ffffcbf6) {
      FUN_000017da(ctx, param_2, new_ctx);
    }
  }
  return;
}

void FUN_00012984(void)

{
  short *psVar1;
  short sVar2;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  if (*psVar1 == 0) {
    if ((DAT_ffffcbf6 <=
         (ushort)(*(short *)((int)&comp_pos_y + unaff_A4) -
                  *(short *)((int)&comp_collision_sensor[0].y + unaff_A4))) &&
        (ecs_holding_a_rope = ecs_holding_a_rope & 0xf7,
         (gamepad_held & GAMEPAD_UP) != GAMEPAD_NONE)) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x80;
      FUN_000129f2();
      return;
    }
  } else if (*psVar1 < 0) {
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    sVar2 = *psVar1 + 0x14;
    *psVar1 = sVar2;
    if (-1 < sVar2) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    }
  } else {
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    sVar2 = *psVar1 + -0x14;
    *psVar1 = sVar2;
    if (sVar2 < 0) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    }
  }
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x100;
  FUN_000129dc();
  return;
}

void FUN_000129dc(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if ((&comp_anim_c)[unaff_A4] != 0) {
    (&comp_anim_b)[unaff_A4] = 0xe;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  }
  return;
}

void FUN_000129f2(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_WALKING_OR_DOWNSTAB) {
    (&comp_anim_b)[unaff_A4] = 0xe;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  }
  return;
}

void FUN_00012a08(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  comp_pos_x.fixed.i = component_pos_x_pepelogoo.fixed.i;
  comp_pos_y.fixed.i = comp_collision_sensor[0].y + comp_collision_sensor[1].y +
                       component_pos_y_pepelogoo.fixed.i;
  if ((ushort)(comp_collision_sensor[0].y + comp_pos_y.fixed.i) <
      DAT_ffffcbf6) {
    if ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_FALLING) {
      ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    }
  } else if ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_JUMPING_OR_UNSHIELDING) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
  }
  return;
}

void FUN_00012a4c(void)

{
  entity_id_t unaff_A5;

  comp_vel[0].y.raw = 0;
  comp_state = COMP_STATE_FALL;
  FUN_0001215a(ENTITY_ID_ASHA, unaff_A5);
  return;
}

void FUN_00012a64(void)

{
  entity_id_t unaff_A5;

  comp_vel[0].y.raw = 0;
  comp_state = 0x44;
  FUN_0001215a(ENTITY_ID_ASHA, unaff_A5);
  return;
}

void FUN_00012a7c(void)

{
  anim_item_t *unaff_A5;

  comp_state = 0x40;
  comp_vel[0].y.raw = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 6);
  return;
}

void FUN_00012a9a(void)

{
  byte bVar1;

  bVar1 = uint8_t_ffffcc70 | 2;
  if ((comp_state_a & ENTITY_STATE_A_08) != 0) {
    bVar1 = uint8_t_ffffcc70 | 0x82;
  }
  uint8_t_ffffcc70 = bVar1;
  return;
}

void FUN_00012ab0(void)

{
  entity_state_1_a_t eVar1;
  entity_id_t unaff_A4;

  eVar1 = (&comp_state_1_a)[unaff_A4];
  (&comp_state_1_a)[unaff_A4] = eVar1 & 0xdf;
  if ((eVar1 & 0x20) != 0) {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x4c;
  }
  FUN_0001128a(unaff_A4);
  ecs_cap_fall_speed(unaff_A4);
  return;
}

void FUN_00012ac8(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;

  if (((&comp_collision[0].collision.y)[unaff_A4] == '\r') &&
      (*(short *)((int)&comp_vel[0].x + unaff_A4) != 0)) {
    ecs_try_jump(unaff_A4, unaff_A5);
    FUN_0001128a(unaff_A4);
    ecs_cap_fall_speed(unaff_A4);
    return;
  }
  FUN_00011dee(unaff_A4, unaff_A5);
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  ecs_holding_a_rope = ecs_holding_a_rope & 0xfd;
  return;
}

void FUN_00012af6(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;

  FUN_0001128a(unaff_A4);
  ecs_cap_fall_speed(unaff_A4);
  ecs_try_jump(unaff_A4, unaff_A5);
  FUN_00011c14();
  return;
}

void FUN_00012b08(void)

{
  uint uVar1;

  uVar1 = 0;
  do {
    if ((char)(&DAT_ffffcefe)[uVar1] < '\0') {
      FUN_00012b24();
      FUN_00012b38();
    }
    uVar1 = uVar1 + 4;
  } while (uVar1 < 0x20);
  return;
}

void FUN_00012b24(void)

{
  short sVar1;
  int unaff_A3;

  if ((((&DAT_ffffcefe)[unaff_A3] & 0x40) == 0) &&
      (sVar1 = *(short *)(&DAT_ffffcf20 + unaff_A3) + -1,
       *(short *)(&DAT_ffffcf20 + unaff_A3) = sVar1,
       sVar1 == 0)) {
    FUN_00012c60();
  }
  return;
}

void FUN_00012b38(void)

{
  short sVar1;
  int unaff_A3;
  anim_item_t *unaff_A5;

  if (((&DAT_ffffcefe)[unaff_A3] & 1) == 0) {
    FUN_00012c32();
    return;
  }
  if ((0x4f < comp_state) && (comp_state < 0x55)) {
    if ((DAT_ffffcc78 == (short)unaff_A3) &&
        (sVar1 = FUN_00012c02(), sVar1 == 0)) {
      comp_state = COMP_STATE_STAND;
      FUN_00011dee(ENTITY_ID_ASHA, (entity_id_t)unaff_A5);
      return;
    }
    return;
  }
  sVar1 = FUN_00012c02();
  if (sVar1 == 0) {
    return;
  }
  DAT_ffffcc78 = (short)unaff_A3;
  FUN_00012cd8();
  if (((component_unknown_5 | component_collision_flags) & 4) != 0) {
    if ((comp_anim_b == 4) && (comp_anim_c == 0)) {
      comp_state = 0x52;
      return;
    }
    if (DAT_ffffd2eb == '\0') {
      FUN_00018c56();
      comp_state = 0x50;
      DAT_ffffcc84 = 0x5a;
      comp_anim_b = 0x12;
      ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 4);
      return;
    }
  }
  DAT_ffffd16c = 0;
  ecs_holding_a_rope = ecs_holding_a_rope & 0xb7;
  FUN_00018c56();
  comp_state = 0x54;
  comp_anim_b = 0x12;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 6);
  return;
}

void FUN_00012b46(void)

{
  return;
}

undefined4 FUN_00012c02(void)

{
  int unaff_A3;
  int unaff_A4;

  if ((*(ushort *)(&DAT_ffffcf3e + unaff_A3) <=
       *(ushort *)((int)&comp_pos_x + unaff_A4)) &&
      (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
       (ushort)(*(short *)(&DAT_ffffcf00 + unaff_A3) +
                *(ushort *)(&DAT_ffffcf3e + unaff_A3)))) {
    if ((*(ushort *)(&DAT_ffffcf40 + unaff_A3) <=
         *(ushort *)((int)&comp_pos_y + unaff_A4)) &&
        (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
         (ushort)(*(ushort *)(&DAT_ffffcf40 + unaff_A3) + 0x40))) {
      return 0xffffffff;
    }
  }
  return 0;
}

void FUN_00012c32(void)

{
  short unaff_A3w;
  entity_id_t unaff_A5;

  if (((0x4f < comp_state) && (comp_state < 0x55)) &&
      (DAT_ffffcc78 == unaff_A3w)) {
    FUN_00018c56();
    comp_state = COMP_STATE_STAND;
    FUN_00011dee(ENTITY_ID_ASHA, unaff_A5);
    return;
  }
  return;
}

void FUN_00012c60(void)

{
  char *pcVar1;
  char *pcVar2;
  int unaff_A3;
  anim_item_t *unaff_A5;

  while (true) {
    pcVar1 = *(char **)(unaff_A3 + -0x30a2);
    pcVar2 = pcVar1 + 1;
    if (*pcVar1 < '\0')
      break;
    // WARNING: Switch is manually overridden
    switch (*pcVar1) {
    case '\0':
      (&DAT_ffffcefe)[unaff_A3] = (&DAT_ffffcefe)[unaff_A3] | 1;
      *(undefined2 *)(&DAT_ffffcf20 + unaff_A3) = *(undefined2 *)pcVar2;
      *(char **)(unaff_A3 + -0x30a2) = pcVar1 + 3;
      ecs_anim_unk_2((int)*(short *)(&DAT_ffffcf1e + unaff_A3), unaff_A5, 2);
      return;
    case '\x01':
      (&DAT_ffffcefe)[unaff_A3] = (&DAT_ffffcefe)[unaff_A3] & 0xfe;
      *(undefined2 *)(&DAT_ffffcf20 + unaff_A3) = *(undefined2 *)pcVar2;
      *(char **)(unaff_A3 + -0x30a2) = pcVar1 + 3;
      ecs_anim_unk_2((int)*(short *)(&DAT_ffffcf1e + unaff_A3), unaff_A5, 4);
      return;
    case '\x02':
      *(undefined4 *)(unaff_A3 + -0x30a2) = *(undefined4 *)pcVar2;
    }
  }
  (&DAT_ffffcefe)[unaff_A3] = (&DAT_ffffcefe)[unaff_A3] | 0x40;
  return;
}

char FUN_00012cd8(void)

{
  if ((&DAT_ffffceff)[DAT_ffffcc78] == '\0') {
    comp_state_a = comp_state_a | ENTITY_STATE_A_08;
  } else {
    comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
  }
  return (&DAT_ffffceff)[DAT_ffffcc78];
}

char FUN_00012cf2(void)

{
  char cVar1;
  short *psVar2;
  int unaff_A4;

  cVar1 = (&DAT_ffffceff)[DAT_ffffcc78];
  if (cVar1 == '\0') {
    psVar2 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar2 = *psVar2 + 0x20;
    if (0x100 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x100;
    }
  } else {
    psVar2 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar2 = *psVar2 + -0x20;
    if (*(short *)((int)&comp_vel[0].x + unaff_A4) < -0x100) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xff00;
    }
  }
  psVar2 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar2 = *psVar2 + 0x40;
  if (0x600 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x600;
  }
  return cVar1;
}

char FUN_00012d3c(void)

{
  char cVar1;
  short *psVar2;
  int unaff_A4;

  cVar1 = (&DAT_ffffceff)[DAT_ffffcc78];
  if (cVar1 == '\0') {
    psVar2 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar2 = *psVar2 + 0x40;
    if (0x300 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x300;
    }
  } else {
    psVar2 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar2 = *psVar2 + -0x40;
    if (*(short *)((int)&comp_vel[0].x + unaff_A4) < -0x300) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfd00;
    }
  }
  psVar2 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar2 = *psVar2 + 0x40;
  if (0x600 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x600;
  }
  return cVar1;
}

void FUN_00012d86(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_00012cd8();
  FUN_00012cf2();
  DAT_ffffcc84 = DAT_ffffcc84 + -1;
  if (DAT_ffffcc84 == '\0') {
    comp_state = 0x54;
    comp_anim_b = 0x12;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  ecs_try_jump(unaff_A4, (entity_id_t)unaff_A5);
  if (*(short *)((int)&comp_state + unaff_A4) == 4) {
    (&component_collision_flags)[unaff_A4] =
        (&component_collision_flags)[unaff_A4] & 0xfb;
    (&component_unknown_5)[unaff_A4] = (&component_unknown_5)[unaff_A4] & 0xfb;
  }
  return;
}

void FUN_00012dc0(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_00012cd8();
  if (((&comp_anim_c)[unaff_A4] == ECS_STATE_1_B_JUMPING_OR_UNSHIELDING) &&
      (*(short *)((int)&comp_anim_tick + unaff_A4) == 0)) {
    comp_state = 0x50;
    DAT_ffffcc84 = 0x5a;
    (&comp_anim_b)[unaff_A4] = 0x12;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
  }
  FUN_00012e08();
  ecs_try_jump(unaff_A4, (entity_id_t)unaff_A5);
  if (*(short *)((int)&comp_state + unaff_A4) == 4) {
    (&component_collision_flags)[unaff_A4] =
        (&component_collision_flags)[unaff_A4] & 0xfb;
    (&component_unknown_5)[unaff_A4] = (&component_unknown_5)[unaff_A4] & 0xfb;
  }
  return;
}

void FUN_00012e08(void)

{
  short *psVar1;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  if (*psVar1 != 0) {
    if (*psVar1 < 0) {
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + 0x40;
      if (-1 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      }
    } else {
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + -0x40;
      if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      }
    }
  }
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x40;
  if (0x600 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x600;
  }
  return;
}

void FUN_00012e48(void)

{
  FUN_00012cd8();
  FUN_00012d3c();
  return;
}

void FUN_00012e56(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;

  ecs_cap_fall_speed(unaff_A4);
  FUN_00012e70();
  DAT_ffffcc88 = DAT_ffffcc88 + -1;
  if (DAT_ffffcc88 == 0) {
    FUN_00011dee(unaff_A4, unaff_A5);
    comp_state = COMP_STATE_STAND;
  }
  return;
}

void FUN_00012e70(void)

{
  ushort uVar1;
  short *psVar2;
  int unaff_A4;

  uVar1 = *(ushort *)((int)&comp_vel[0].x + unaff_A4);
  if (uVar1 != 0) {
    if ((short)uVar1 < 0) {
      if ((short)uVar1 < -0x10) {
        psVar2 = (short *)((int)&comp_vel[0].x + unaff_A4);
        *psVar2 = *psVar2 + 0x10;
      } else {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      }
    } else if (uVar1 < 0x11) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    } else {
      psVar2 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar2 = *psVar2 + -0x10;
    }
  }
  return;
}

void FUN_00012ea4(void)

{
  anim_item_t *unaff_A5;

  uint8_t_ffffcc70 = '\0';
  comp_state_a = comp_state_a & 0xfb;
  comp_has_func_maybe = comp_has_func_maybe & 0xf7;
  FUN_00011270();
  FUN_00018c56();
  comp_state = 0x5c;
  ecs_holding_a_rope = 3;
  comp_anim_b = 8;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0xe);
  return;
}

void FUN_00012ee0(void)

{
  entity_id_t unaff_A4;

  FUN_0001128a(unaff_A4);
  ecs_cap_fall_speed(unaff_A4);
  return;
}

void FUN_00012eea(void)

{
  anim_item_t *unaff_A5;

  comp_anim_c = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0xe);
  comp_state = COMP_STATE_STAND;
  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  return;
}

void FUN_00012f0e(void)

{
  entity_id_t entity;

  if (DAT_ffffcc8e != '\0') {
    entity = (entity_id_t)(short)entity_id_w_t_ffffcc90;
    *(int16_t *)((int)&comp_pos_x + entity) = comp_pos_x.fixed.i;
    *(int16_t *)((int)&comp_pos_y + entity) = comp_pos_y.fixed.i;
    (&comp_state_a)[entity] = comp_state_a;
    DAT_ffffcc88 = DAT_ffffcc88 + -1;
    if (DAT_ffffcc88 == 0) {
      DAT_ffffcc8e = '\0';
      (&comp_has_func_maybe)[entity] = 0;
    }
  }
  return;
}

void FUN_00012f46(void)

{
  short sVar1;
  byte *pbVar2;

  sVar1 = 3;
  pbVar2 = &SCRIPT_STATE;
  do {
    pbVar2[0] = 0;
    pbVar2[1] = 0;
    pbVar2[2] = 0;
    pbVar2[3] = 0;
    sVar1 = sVar1 + -1;
    pbVar2 = pbVar2 + 4;
  } while (sVar1 != -1);
  return;
}

void FUN_00012f4e(void)

{
  short sVar1;
  undefined4 *puVar2;

  sVar1 = 3;
  puVar2 = &DAT_ffffccba;
  do {
    *puVar2 = 0;
    sVar1 = sVar1 + -1;
    puVar2 = puVar2 + 1;
  } while (sVar1 != -1);
  return;
}

void FUN_00012f5e(void)

{
  short sVar1;
  int iVar2;

  DAT_ffffcf96 = 0;
  sVar1 = 0xf;
  iVar2 = 0;
  do {
    (&DAT_ffffcd44)[iVar2] = 0;
    iVar2 = iVar2 + 4;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return;
}

// This reads the command (between c0 and fe), negates it to turn in into a
// value from 3f to 01, and uses it as an index to jump to the matching
// function.
//
// Only commands e1 to fe seem valid though.

script_t text_command_c0_to_fe(script_t script)

{
  (*(code *)((int)&jmp_text_command_ff_to_e1 +
             (int)*(short *)((int)&jmp_text_command_ff_to_e1 +
                             (int)(short)((ushort)(byte) ~*script * 2))))();
  return script + 1;
}

void FUN_00012f8a(void)

{
  set_to_13a62_when_facing_a_door = 0;
  DAT_ffffcc94 = 0;
  FUN_00012fb0();
  FUN_00013f04();
  FUN_00014722();
  FUN_00014610();
  FUN_000134a4();
  return;
}

void FUN_00012fb0(void)

{
  byte bVar1;
  byte *unaff_A5;

  DAT_ffffcf7e = 0;
  DAT_ffffcc92 = '\0';
  DAT_ffffcc93 = 0;
  DAT_ffffcc56 = 0;
  while (true) {
    while (true) {
      bVar1 = *unaff_A5;
      if (0xbf < bVar1)
        break;
      (*(code *)((int)&jmp_00013002 +
                 (int)*(short *)((int)&jmp_00013002 +
                                 (int)(short)((ushort)bVar1 * 2))))();
      unaff_A5 = unaff_A5 + 1 +
                 (short)(ushort)(&BYTE_0001303a)[(short)(ushort)*unaff_A5];
      if (DAT_ffffcc92 != '\0') {
        return;
      }
    }
    if (bVar1 == 0xff)
      break;
    (*(code *)((int)&jmp_text_command_ff_to_e1 +
               (int)*(short *)((int)&jmp_text_command_ff_to_e1 +
                               (int)(short)((ushort)(byte)~bVar1 * 2))))();
    unaff_A5 = unaff_A5 + 1;
  }
  return;
}

void script_ctx_f9_nop(void)

{
  return;
}

void FUN_00013098(void)

{
  undefined2 unaff_D2w;
  undefined2 unaff_D3w;

  DAT_ffff97ec = 0xffff;
  DAT_ffff97f0 = DAT_ffffcbb2;
  DAT_ffff97f2 = DAT_ffffcbb4;
  DAT_ffff97f4 = unaff_D2w;
  DAT_ffff97f6 = unaff_D3w;
  return;
}

void FUN_000130b4(void)

{
  byte bVar1;
  byte bVar2;
  ushort uVar3;
  short sVar4;
  ushort extraout_D1w;
  int unaff_A4;
  byte *unaff_A5;

  bVar1 = *unaff_A5;
  bVar2 = unaff_A5[1];
  FUN_00013144();
  uVar3 = CONCAT11(*unaff_A5, unaff_A5[2]) & 0xfff;
  sVar4 = FUN_00013150();
  if ((((uVar3 < extraout_D1w) &&
        ((ushort)(*(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
                  *(short *)((int)&comp_pos_y + unaff_A4)) <= uVar3)) &&
       (uVar3 =
            sVar4 - CONCAT11((char)((ushort)((ushort)bVar1 << 4) >> 8), bVar2),
        -1 < (short)uVar3)) &&
      (uVar3 <= (ushort)((ushort)unaff_A5[3] << 4))) {
    DAT_ffffcbb2._1_1_ = unaff_A5[4];
    DAT_ffffcbb4._1_1_ = unaff_A5[5];
    FUN_00013144();
    FUN_00013150();
    DAT_ffffcc92 = 1;
    DAT_ffffcc93 = 1;
    FUN_00013098();
  }
  return;
}

void FUN_00013144(void)

{
  return;
}

void FUN_00013150(void)

{
  return;
}

void FUN_0001315c(void)

{
  byte bVar1;
  byte bVar2;
  ushort uVar3;
  short sVar4;
  ushort extraout_D1w;
  int unaff_A4;
  byte *unaff_A5;

  bVar1 = *unaff_A5;
  bVar2 = unaff_A5[1];
  FUN_00013144();
  uVar3 = CONCAT11(*unaff_A5, unaff_A5[2]) & 0xfff;
  sVar4 = FUN_00013150();
  if ((((extraout_D1w < uVar3) &&
        (uVar3 <=
         (ushort)(*(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
                  *(short *)((int)&comp_pos_y + unaff_A4)))) &&
       (uVar3 =
            sVar4 - CONCAT11((char)((ushort)((ushort)bVar1 << 4) >> 8), bVar2),
        -1 < (short)uVar3)) &&
      (uVar3 <= (ushort)((ushort)unaff_A5[3] << 4))) {
    DAT_ffffcbb2._1_1_ = unaff_A5[4];
    DAT_ffffcbb4._1_1_ = unaff_A5[5];
    FUN_00013144();
    FUN_00013150();
    DAT_ffffcc92 = 1;
    DAT_ffffcc93 = 1;
    FUN_00013098();
  }
  return;
}

void FUN_000131ec(void)

{
  byte bVar1;
  byte bVar2;
  ushort uVar3;
  short extraout_D1w;
  ushort uVar4;
  int unaff_A4;
  byte *unaff_A5;

  uVar4 = CONCAT11((char)((ushort)((ushort)*unaff_A5 << 4) >> 8), unaff_A5[1]);
  FUN_00013144();
  bVar1 = *unaff_A5;
  bVar2 = unaff_A5[2];
  uVar3 = FUN_00013150();
  if ((uVar4 < uVar3) && (*(ushort *)((int)&comp_pos_x + unaff_A4) <= uVar4)) {
    uVar4 = extraout_D1w - (CONCAT11(bVar1, bVar2) & 0xfff);
    if (uVar4 != 0) {
      if (-1 < (short)uVar4) {
        return;
      }
      uVar4 = -uVar4;
    }
    if (uVar4 <= (ushort)((ushort)unaff_A5[3] << 4)) {
      DAT_ffffcbb2._1_1_ = unaff_A5[4];
      DAT_ffffcbb4._1_1_ = unaff_A5[5];
      FUN_00013144();
      FUN_00013150();
      DAT_ffffcc92 = 1;
      DAT_ffffcc93 = 1;
      FUN_00013098();
    }
  }
  return;
}

void FUN_0001327c(void)

{
  byte bVar1;
  byte bVar2;
  ushort uVar3;
  short extraout_D1w;
  ushort uVar4;
  int unaff_A4;
  byte *unaff_A5;

  uVar4 = CONCAT11((char)((ushort)((ushort)*unaff_A5 << 4) >> 8), unaff_A5[1]);
  FUN_00013144();
  bVar1 = *unaff_A5;
  bVar2 = unaff_A5[2];
  uVar3 = FUN_00013150();
  if ((uVar3 < uVar4) && (uVar4 <= *(ushort *)((int)&comp_pos_x + unaff_A4))) {
    uVar4 = extraout_D1w - (CONCAT11(bVar1, bVar2) & 0xfff);
    if (uVar4 != 0) {
      if (-1 < (short)uVar4) {
        return;
      }
      uVar4 = -uVar4;
    }
    if (uVar4 <= (ushort)((ushort)unaff_A5[3] << 4)) {
      DAT_ffffcbb2._1_1_ = unaff_A5[4];
      DAT_ffffcbb4._1_1_ = unaff_A5[5];
      FUN_00013144();
      FUN_00013150();
      DAT_ffffcc92 = 1;
      DAT_ffffcc93 = 1;
      FUN_00013098();
    }
  }
  return;
}

void script_state_set_true(script_state_bit_t index)

{
  (&SCRIPT_STATE)[(short)((ushort)index >> 3)] =
      (byte)(1 << (index._1_1_ & 7)) |
      (&SCRIPT_STATE)[(short)((ushort)index >> 3)];
  return;
}

void script_state_set_false(script_state_bit_t index)

{
  (&SCRIPT_STATE)[(short)((ushort)index >> 3)] =
      ~(byte)(1 << (index._1_1_ & 7)) &
      (&SCRIPT_STATE)[(short)((ushort)index >> 3)];
  return;
}

bool script_state_get(script_state_bit_t index)

{
  return ((&SCRIPT_STATE)[(short)((ushort)index >> 3)] &
          '\x01' << (index._1_1_ & 7)) == 0;
}

script_t script_ctx_fc_seek_if_false(script_t script)

{
  script_t script_next;
  bool condition;

  condition = script_state_get(*(script_state_bit_t *)script);
  if (condition) {
    script_next = script + 4;
  } else {
    script_next = script + *(short *)(script + 2) + 2;
  }
  return script_next;
}

script_t script_ctx_fd_seek_if_true(script_t script)

{
  script_t script_next;
  bool condition;

  condition = script_state_get(*(script_state_bit_t *)script);
  if (condition) {
    script_next = script + *(short *)(script + 2) + 2;
  } else {
    script_next = script + 4;
  }
  return script_next;
}

script_t script_seek_if_rand_e4(script_t script)

{
  word r;
  script_t script_next;
  ushort arg_1;

  arg_1 = *(ushort *)script;
  r = rand();
  if (r < arg_1) {
    script_next = script + *(short *)(script + 2) + 2;
  } else {
    script_next = script + 4;
  }
  return script_next;
}

// Reads a word? Not sure what this does, it seems to maybe it doesn't read a
// word but pops the scripts stack of something.

script_t script_ctx_fe_seek(script_t script)

{
  return script + *(short *)script;
}

script_t script_ctx_set_true(script_t script)

{
  script_state_set_true(*(script_state_bit_t *)script);
  return script + 2;
}

script_t script_set_false(script_t script)

{
  script_state_set_false(*(script_state_bit_t *)script);
  return script + 2;
}

// FIXME Where is it called?

void FUN_000133cc(void)

{
  int unaff_A3;

  if (DAT_ffff97e9 != '\0') {
    if ((&DAT_ffffce0c)[unaff_A3] == -0x40) {
      FUN_00013488();
    } else {
      FUN_0001342e();
    }
  }
  return;
}

ushort FUN_000133e6(void)

{
  short sVar1;
  ushort uVar2;
  int unaff_A3;

  sVar1 = *(short *)(unaff_A3 + -0x312c) + *(short *)(unaff_A3 + -0x3154);
  uVar2 = sVar1 + 0x10;
  if ((DAT_ffffc73a <= uVar2) &&
      (uVar2 = ((sVar1 + -0x10) - *(short *)(unaff_A3 + -0x312c)) -
               *(short *)(unaff_A3 + -0x312c),
       uVar2 <= (ushort)(DAT_ffffc73a + 0x100))) {
    uVar2 = *(short *)(unaff_A3 + -0x3152) + 0x10;
    if (DAT_ffffc746 <= uVar2) {
      uVar2 = *(short *)(unaff_A3 + -0x3152) - *(short *)(unaff_A3 + -0x312a);
    }
  }
  return uVar2;
}

void FUN_0001342e(void)

{
  short unaff_D2w;
  func *f;
  int unaff_A3;
  entity_id_t e;
  anim_item_t *unaff_A5;
  undefined1 in_CF;

  FUN_000133e6();
  if (!(bool)in_CF) {
    FUN_0000147a(f, 0, 0);
    if (unaff_D2w < 0) {
      do {
        // WARNING: Do nothing block with infinite loop
      } while (true);
    }
    e = (entity_id_t)unaff_D2w;
    *(short *)(&DAT_ffffce5c + unaff_A3) = unaff_D2w;
    entity_reset(e);
    *(undefined2 *)((int)&comp_unk_3 + e) = 8;
    (&comp_anim_base_offset)[e] = 0xe;
    (&comp_anim_b)[e] = 6;
    *(undefined2 *)((int)&comp_pos_x + e) = *(undefined2 *)(unaff_A3 + -0x3154);
    *(undefined2 *)((int)&comp_pos_y + e) = *(undefined2 *)(unaff_A3 + -0x3152);
    (&comp_state_a)[e] = 0x80;
    ecs_anim_unk_2(e, unaff_A5, 0);
    *(short *)((int)&comp_pos_y + e) =
        *(short *)((int)&comp_pos_y + e) -
        *(short *)((int)&comp_collision_sensor[0].y + e);
    (&DAT_ffffce0c)[unaff_A3] = (&DAT_ffffce0c)[unaff_A3] | 0x40;
    *(short *)(unaff_A3 + -0x327a) = unaff_D2w;
  }
  return;
}

void FUN_00013488(void)

{
  short sVar1;
  int unaff_A3;
  undefined1 in_CF;

  FUN_000133e6();
  if ((bool)in_CF) {
    sVar1 = *(short *)(&DAT_ffffce5c + unaff_A3);
    *(undefined2 *)(&DAT_ffffce5c + unaff_A3) = 0xffff;
    (&comp_has_func_maybe)[sVar1] = 0;
    (&DAT_ffffce0c)[unaff_A3] = (&DAT_ffffce0c)[unaff_A3] & 0xbf;
  }
  return;
}

void FUN_000134a4(void)

{
  return;
}

void FUN_000134a6(void)

{
  ushort uVar1;
  int unaff_A4;
  byte *unaff_A5;

  uVar1 = (*(short *)((int)&comp_pos_x + unaff_A4) -
           *(short *)((int)&comp_collision_sensor[0].x + unaff_A4)) -
          ((*unaff_A5 - 8) * 0x10 + 0x1000);
  if ((((-1 < (short)uVar1) &&
        (uVar1 <= (ushort)((ushort)unaff_A5[3] * 0x10))) &&
       ((ushort)(*(short *)((int)&comp_collision_sensor[0].x + unaff_A4) * 2) <=
        (ushort)((ushort)unaff_A5[3] * 0x10 - uVar1))) &&
      (((uVar1 = (*(short *)((int)&comp_pos_y + unaff_A4) -
                  *(short *)((int)&comp_collision_sensor[0].y + unaff_A4)) -
                 ((unaff_A5[1] - 8) * 0x10 + 0x1000),
         -1 < (short)uVar1 &&
             (uVar1 <= (ushort)((ushort)unaff_A5[2] * 0x10))) &&
        ((ushort)(*(short *)((int)&comp_collision_sensor[0].y + unaff_A4) *
                  2) <= (ushort)((ushort)unaff_A5[2] * 0x10 - uVar1))))) {
    DAT_ffffcbb2._1_1_ = unaff_A5[4];
    DAT_ffffcbb4._1_1_ = unaff_A5[5];
    set_to_13a62_when_facing_a_door = FUN_0001354a;
    DAT_ffffcc4a = (*unaff_A5 - 8) * 0x10 + 0x1000;
    DAT_ffffcc4c = (unaff_A5[1] - 8) * 0x10 + 0x1000;
  }
  return;
}

void FUN_0001354a(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_anim_b)[unaff_A4] = 0;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
  DAT_ffffcc92 = 1;
  DAT_ffffcc93 = 2;
  return;
}

void FUN_00013564(void)

{
  ushort uVar1;
  int unaff_A4;
  byte *unaff_A5;

  uVar1 = (*(short *)((int)&comp_pos_x + unaff_A4) -
           *(short *)((int)&comp_collision_sensor[0].x + unaff_A4)) -
          ((*unaff_A5 - 8) * 0x10 + 0x1000);
  if ((((-1 < (short)uVar1) &&
        (uVar1 <= (ushort)((ushort)unaff_A5[3] * 0x10))) &&
       ((ushort)(*(short *)((int)&comp_collision_sensor[0].x + unaff_A4) * 2) <=
        (ushort)((ushort)unaff_A5[3] * 0x10 - uVar1))) &&
      (((uVar1 = (*(short *)((int)&comp_pos_y + unaff_A4) -
                  *(short *)((int)&comp_collision_sensor[0].y + unaff_A4)) -
                 ((unaff_A5[1] - 8) * 0x10 + 0x1000),
         -1 < (short)uVar1 &&
             (uVar1 <= (ushort)((ushort)unaff_A5[2] * 0x10))) &&
        ((ushort)(*(short *)((int)&comp_collision_sensor[0].y + unaff_A4) *
                  2) <= (ushort)((ushort)unaff_A5[2] * 0x10 - uVar1))))) {
    DAT_ffffcbb2._1_1_ = unaff_A5[4];
    DAT_ffffcbb4._1_1_ = unaff_A5[5];
    DAT_ffffcc94 = FUN_00013608;
    DAT_ffffcc4a = (*unaff_A5 - 8) * 0x10 + 0x1000;
    DAT_ffffcc4c = (unaff_A5[1] - 8) * 0x10 + 0x1000;
  }
  return;
}

void FUN_00013608(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_anim_b)[unaff_A4] = 0;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  DAT_ffffcc92 = 1;
  DAT_ffffcc93 = 3;
  DAT_ffffcc94 = 0;
  set_to_13a62_when_facing_a_door = 0;
  return;
}

script_t text_command_f7(script_t script)

{
  byte bVar1;
  undefined3 uVar2;
  short sVar3;
  entity_id_t self;

  sVar3 = FUN_0000107a();
  if (-1 < sVar3) {
    self = (entity_id_t)sVar3;
    entity_reset(self);
    *(undefined2 *)((int)&comp_pos_x + self + 2) = 0;
    *(undefined2 *)((int)&comp_pos_y + self + 2) = 0;
    bVar1 = *script;
    *(short *)((int)&comp_pos_x + self) =
        CONCAT11((char)((ushort)((ushort)bVar1 << 4) >> 8), script[1]) * 8 +
        0xf80;
    *(ushort *)((int)&comp_pos_y + self) =
        (CONCAT11(bVar1, script[2]) & 0xfff) * 8 + 0xf80;
    uVar2 = *(undefined3 *)(script + 5);
    *(ushort *)(&DAT_ffffba76 + self) = (ushort)uVar2 & 0x7ff;
    *(short *)(&DAT_ffffb66e + self) = (short)((uint3)uVar2 >> 8);
    FUN_0000d992();
    return script + 8;
  }
  do {
    // WARNING: Do nothing block with infinite loop
  } while (true);
}

void FUN_00013696(void)

{
  return;
}

void FUN_000136a4(void)

{
  return;
}

void FUN_000136b0(void)

{
  do {
    // WARNING: Do nothing block with infinite loop
  } while (true);
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000136b4(void)

{
  short unaff_D4w;
  undefined4 extraout_A0;
  int unaff_A5;

  FUN_00014574();
  if (unaff_D4w != 0) {
    set_to_13a62_when_facing_a_door = FUN_000136e8;
    DAT_ffffcd38 = *(undefined1 *)(unaff_A5 + 2);
    DAT_ffffcd39 = *(undefined1 *)(unaff_A5 + 3);
    _DAT_ffffcd2e = extraout_A0;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000136e8(void)

{
  short sVar1;
  short sVar2;
  anim_item_t *unaff_A5;

  DAT_ffffcd32 = (*_DAT_ffffcd2e - 8) * 0x10 + 0x1000;
  DAT_ffffcd34 = (_DAT_ffffcd2e[1] - 8) * 0x10 + 0x1000;
  DAT_ffffcd3a = _DAT_ffffcd2e[4];
  sVar2 = (ushort)_DAT_ffffcd2e[5] * 6;
  DAT_ffffcd3d = 0;
  DAT_ffffcd3b = (&DAT_0007d168)[sVar2];
  DAT_ffffcd3c = (&UNK_0007d169)[sVar2];
  DAT_ffffcd36 = (&UNK_0007d16a)[sVar2];
  DAT_ffffcd37 = (&UNK_0007d16b)[sVar2];
  DAT_ffffcd3e = (undefined *)0x0;
  sVar1 = *(short *)(&UNK_0007d16c + sVar2);
  if (sVar1 != 0) {
    DAT_ffffcd3e = (undefined *)((int)sVar1 + (int)(&UNK_0007d16c + sVar2));
  }
  comp_anim_b = 0;
  comp_state = COMP_STATE_STAND;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0xe);
  DAT_ffffcc92 = 1;
  DAT_ffffcc93 = 2;
  DAT_ffffcc94 = 0;
  set_to_13a62_when_facing_a_door = 0;
  DAT_ffffcbb2._1_1_ = DAT_ffffcd38;
  DAT_ffffcbb4._1_1_ = DAT_ffffcd39;
  FUN_00013098();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00013790(void)

{
  short unaff_D4w;
  undefined4 extraout_A0;

  if (DAT_ffff97e9 == '\0') {
    FUN_00014632();
  }
  FUN_00014574();
  if (unaff_D4w != 0) {
    DAT_ffffcc94 = FUN_000137c2;
    _DAT_ffffcd2a = extraout_A0;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000137c2(void)

{
  short sVar1;
  short sVar2;
  anim_item_t *unaff_A5;

  DAT_ffffcd32 = (*_DAT_ffffcd2a - 8) * 0x10 + 0x1000;
  DAT_ffffcd34 = (_DAT_ffffcd2a[1] - 8) * 0x10 + 0x1000;
  DAT_ffffcbb2._1_1_ = _DAT_ffffcd2a[2];
  DAT_ffffcbb4._1_1_ = _DAT_ffffcd2a[3];
  DAT_ffffcd3d = 0;
  sVar2 = (ushort)_DAT_ffffcd2a[5] * 6;
  DAT_ffffcd3b = (&DAT_0007d168)[sVar2];
  DAT_ffffcd3c = (&UNK_0007d169)[sVar2];
  DAT_ffffcd36 = (&UNK_0007d16a)[sVar2];
  DAT_ffffcd37 = (&UNK_0007d16b)[sVar2];
  DAT_ffffcd3e = (undefined *)0x0;
  sVar1 = *(short *)(&UNK_0007d16c + sVar2);
  if (sVar1 != 0) {
    DAT_ffffcd3e = (undefined *)((int)sVar1 + (int)(&UNK_0007d16c + sVar2));
  }
  comp_anim_b = 0;
  comp_state = COMP_STATE_STAND;
  DAT_ffffcd38 = (byte)DAT_ffffcbb2;
  DAT_ffffcd39 = (byte)DAT_ffffcbb4;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x22);
  DAT_ffffcc92 = 1;
  DAT_ffffcc93 = 3;
  DAT_ffffcc94 = 0;
  set_to_13a62_when_facing_a_door = 0;
  FUN_00013098();
  return;
}

script_t text_command_f6(script_t script)

{
  DAT_ffffce04._0_1_ = *script;
  DAT_ffffce04._1_1_ = script[1];
  DAT_ffffce06._0_1_ = script[2];
  DAT_ffffce06._1_1_ = script[3];
  DAT_ffffce08._0_1_ = script[4];
  DAT_ffffce08._1_1_ = script[5];
  DAT_ffffce0a._0_1_ = script[6];
  DAT_ffffce0a._1_1_ = script[7];
  return script + 8;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001388e(void)

{
  short offset;
  short unaff_D4w;
  int extraout_A0;
  int unaff_A5;

  if (DAT_ffff97e9 == '\0') {
    FUN_000146a4();
  }
  FUN_00014574();
  if (unaff_D4w != 0) {
    offset = (ushort) * (byte *)(extraout_A0 + 4) << 3;
    _DAT_ffffcc9e = extraout_A0;
    **(undefined4 **)((int)&value_dst_t_ARRAY_000138e0[0].dst + (int)offset) =
        *(undefined4 *)((int)&value_dst_t_ARRAY_000138e0[0].value +
                        (int)offset);
    DAT_ffffcc9c = *(undefined2 *)(unaff_A5 + 2);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00013920(void)

{
  short sVar1;
  short sVar2;
  anim_item_t *unaff_A5;

  DAT_ffffcd32 = (*_DAT_ffffcc9e - 8) * 0x10 + 0x1000;
  DAT_ffffcd34 = (_DAT_ffffcc9e[1] - 8) * 0x10 + 0x1000;
  DAT_ffffcd38 = _DAT_ffffcc9e[2];
  DAT_ffffcd39 = _DAT_ffffcc9e[3];
  DAT_ffffcd3a = _DAT_ffffcc9e[4];
  DAT_ffffcd3d = 0;
  sVar2 = (ushort)_DAT_ffffcc9e[5] * 6;
  DAT_ffffcd3b = (&DAT_0007d168)[sVar2];
  DAT_ffffcd3c = (&UNK_0007d169)[sVar2];
  DAT_ffffcd36 = (&UNK_0007d16a)[sVar2];
  DAT_ffffcd37 = (&UNK_0007d16b)[sVar2];
  DAT_ffffcd3e = (undefined *)0x0;
  sVar1 = *(short *)(&UNK_0007d16c + sVar2);
  if (sVar1 != 0) {
    DAT_ffffcd3e = (undefined *)((int)sVar1 + (int)(&UNK_0007d16c + sVar2));
  }
  comp_anim_b = 0;
  comp_state = COMP_STATE_STAND;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  DAT_ffffcc92 = 1;
  DAT_ffffcc93 = 5;
  comp_state = COMP_STATE_STAND;
  DAT_ffffcd42 = 0;
  DAT_ffffcd43 = 0xe;
  comp_has_func_maybe = 0;
  DAT_ffffcc94 = 0;
  set_to_13a62_when_facing_a_door = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000139ce(void)

{
  short sVar1;
  short sVar2;

  DAT_ffffcd32 = (*_DAT_ffffcc9e - 8) * 0x10 + 0x1000;
  DAT_ffffcd34 = (_DAT_ffffcc9e[1] - 8) * 0x10 + 0x1000;
  DAT_ffffcd38 = _DAT_ffffcc9e[2];
  DAT_ffffcd39 = _DAT_ffffcc9e[3];
  DAT_ffffcd3a = _DAT_ffffcc9e[4];
  DAT_ffffcd3d = 0xff;
  sVar2 = (ushort)_DAT_ffffcc9e[5] * 6;
  DAT_ffffcd3b = (&DAT_0007d168)[sVar2];
  DAT_ffffcd3c = (&UNK_0007d169)[sVar2];
  DAT_ffffcd36 = (&UNK_0007d16a)[sVar2];
  DAT_ffffcd37 = (&UNK_0007d16b)[sVar2];
  DAT_ffffcd3e = (undefined *)0x0;
  sVar1 = *(short *)(&UNK_0007d16c + sVar2);
  if (sVar1 != 0) {
    DAT_ffffcd3e = (undefined *)((int)sVar1 + (int)(&UNK_0007d16c + sVar2));
  }
  comp_state = COMP_STATE_STAND;
  DAT_ffffcd42 = 0;
  DAT_ffffcd43 = 0;
  DAT_ffffcc92 = 1;
  DAT_ffffcc93 = 6;
  DAT_ffffcc94 = 0;
  set_to_13a62_when_facing_a_door = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00013a62(void)

{
  DAT_ffffcd32 = (*_DAT_ffffcc9e - 8) * 0x10 + 0x1000;
  DAT_ffffcd34 = (_DAT_ffffcc9e[1] - 8) * 0x10 + 0x1000;
  DAT_ffffcd38 = _DAT_ffffcc9e[2];
  DAT_ffffcd39 = _DAT_ffffcc9e[3];
  DAT_ffffcd3a = _DAT_ffffcc9e[4];
  DAT_ffffcd3d = 0xff;
  DAT_ffffcd42 = FUN_00013aca[(short)((ushort)_DAT_ffffcc9e[5] << 2)];
  DAT_ffffcd43 =
      *(undefined1 *)((short)((ushort)_DAT_ffffcc9e[5] << 2) + 0x13acb);
  DAT_ffffcc92 = 1;
  DAT_ffffcc93 = 6;
  DAT_ffffcc94 = 0;
  set_to_13a62_when_facing_a_door = 0;
  return;
}

void FUN_00013aca(void)

{
  byte *pbVar1;
  short sVar2;
  short sVar3;
  undefined4 in_D0;
  short in_D1w;
  byte *in_A0;
  undefined1 unaff_A2b;
  int unaff_A4;
  anim_item_t *unaff_A5;
  byte *unaff_A6;

  *unaff_A6 = *unaff_A6 | 0x20;
  in_A0[in_D1w + 8] = in_A0[in_D1w + 8] | 0x32;
  pbVar1 = (byte *)(unaff_A4 + 0x3c +
                    (int)(short)CONCAT31((int3)((uint)in_D0 >> 8), unaff_A2b));
  *pbVar1 = *pbVar1 | 0x36;
  DAT_ffffcd32 = (*in_A0 - 8) * 0x10 + 0x1000;
  DAT_ffffcd34 = (in_A0[1] - 8) * 0x10 + 0x1000;
  DAT_ffffcd38 = in_A0[2];
  DAT_ffffcd39 = in_A0[3];
  DAT_ffffcd3a = in_A0[4];
  DAT_ffffcd3d = 0;
  sVar3 = (ushort)in_A0[5] * 6;
  DAT_ffffcd3b = (&DAT_0007d168)[sVar3];
  DAT_ffffcd3c = (&UNK_0007d169)[sVar3];
  DAT_ffffcd36 = (&UNK_0007d16a)[sVar3];
  DAT_ffffcd37 = (&UNK_0007d16b)[sVar3];
  DAT_ffffcd3e = (undefined *)0x0;
  sVar2 = *(short *)(&UNK_0007d16c + sVar3);
  if (sVar2 != 0) {
    DAT_ffffcd3e = (undefined *)((int)sVar2 + (int)(&UNK_0007d16c + sVar3));
  }
  comp_anim_b = 0;
  comp_state = COMP_STATE_STAND;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  comp_state = COMP_STATE_STAND;
  DAT_ffffcd42 = 0;
  DAT_ffffcd43 = 0x34;
  DAT_ffffcc94 = 0;
  set_to_13a62_when_facing_a_door = 0;
  DAT_ffffcc92 = 1;
  DAT_ffffcc93 = 0xb;
  return;
}

script_t text_command_f5(script_t script)

{
  DAT_ffffc8de = FUN_00013bf4();
  DAT_ffffc8dc = FUN_00013bf4();
  DAT_ffffc8e2 = 1;
  DAT_ffffc8e0 = 1;
  uRamffffcca6 = *(undefined2 *)script;
  FUN_0000b85e((undefined2 *)0xffffcca6);
  return script + 2;
}

script_t text_command_f4(script_t script)

{
  byte *pbVar1;

  DAT_ffffc8de = FUN_00013bf4();
  DAT_ffffc8dc = FUN_00013bf4();
  pbVar1 = (byte *)(uint) * (uint3 *)script;
  DAT_ffffc8e2 = (ushort)*pbVar1;
  DAT_ffffc8e0 = (ushort)pbVar1[1];
  FUN_0000b85e((undefined2 *)(pbVar1 + 2));
  return script + 3;
}

short FUN_00013bf4(void)

{
  byte *unaff_A5;

  return (ushort)*unaff_A5 * 0x10 + 0x1000;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

script_t script_f3(script_t script)

{
  byte bVar1;

  bVar1 = *script;
  DAT_ffffd18a = (*(ushort *)script & 0x3ff) << 3;
  _DAT_ffffd182 = DAT_ffffd18a;
  DAT_ffffd18e = CONCAT11((char)((ushort)((bVar1 & 0xc) << 6) >> 8), script[2])
                 << 3;
  _DAT_ffffd186 = DAT_ffffd18e;
  DAT_ffffd18c =
      CONCAT11((char)((ushort)((bVar1 & 0x30) << 4) >> 8), script[3]) * 8 + -1;
  _DAT_ffffd184 = DAT_ffffd18c;
  DAT_ffffd190 =
      CONCAT11((char)((ushort)((bVar1 & 0xc0) << 2) >> 8), script[4]) * 8 + -1;
  _DAT_ffffd188 = DAT_ffffd190;
  return script + 5;
}

script_t script_f2(script_t script)

{
  byte bVar1;
  script_t pcVar2;

  bVar1 = *script;
  if (((((ushort)comp_pos_x.fixed.i <
         (ushort)(CONCAT11((char)((ushort)((bVar1 & 0xc0) << 2) >> 8),
                           script[1])
                  << 3)) ||
        ((ushort)(CONCAT11((char)((ushort)((bVar1 & 0xc) << 6) >> 8), script[3])
                  << 3) < (ushort)comp_pos_x.fixed.i)) ||
       ((ushort)(comp_collision_sensor[0].y + comp_pos_y.fixed.i) <
        (ushort)(CONCAT11((char)((ushort)((bVar1 & 0x30) << 4) >> 8), script[2])
                 << 3))) ||
      ((ushort)(CONCAT11(3, script[4]) << 3) <
       (ushort)(comp_collision_sensor[0].y + comp_pos_y.fixed.i))) {
    pcVar2 = script + 7;
  } else {
    pcVar2 = script + *(short *)(script + 5) + 5;
  }
  return pcVar2;
}

script_t script_f1(script_t script, entity_id_t entity)

{
  if ((((ushort)(*(short *)script - 8U) <=
        *(ushort *)((int)&comp_pos_x + entity)) &&
       (*(ushort *)((int)&comp_pos_x + entity) <=
        (ushort)(*(short *)script + 8U))) &&
      ((ushort)((ushort)(byte)script[2] * 0x10 + 0x1000) ==
       (ushort)(*(short *)((int)&comp_collision_sensor[0].y + entity) +
                *(short *)((int)&comp_pos_y + entity)))) {
    set_to_13a62_when_facing_a_door = FUN_00013cec;
    DAT_ffffd916 = *(undefined2 *)(script + 3);
  }
  return script + 5;
}

void FUN_00013cec(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_anim_b)[unaff_A4] = 0;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
  DAT_ffffcc92 = 2;
  DAT_ffffcc93 = 0;
  set_to_13a62_when_facing_a_door = 0;
  return;
}

script_t script_unused_seek_if_owned_f0(script_t script)

{
  bool isnt_owned;

  isnt_owned = item_check_isnt_owned(*script);
  if (!isnt_owned) {
    return script + *(short *)(script + 1) + 1;
  }
  return script + 3;
}

script_t script_ef(script_t script)

{
  item_remove_from_inventory(*script);
  return script + 1;
}

void FUN_00013d2e(void)

{
  DAT_ffffcd3a = (&DAT_0007c8fc)[(short)(DAT_ffff97ea << 3)];
  // WARNING: Could not recover jumptable at 0x00013d52. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00013d54 +
             (int)*(short *)((int)&WORD_00013d54 +
                             (int)(short)((ushort)DAT_ffffcd3a * 2))))();
  return;
}

void FUN_00013d64(void)

{
  short sVar1;
  short sVar2;
  byte *in_A0;

  DAT_ffffcd3d = 0;
  if (DAT_ffffcd3a != '\x01') {
    DAT_ffffcd3d = 0xff;
  }
  DAT_ffffcd32 = (*in_A0 - 8) * 0x10 + 0x1000;
  DAT_ffffcd34 = (in_A0[1] - 8) * 0x10 + 0x1000;
  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  comp_pos_x.fixed.i = DAT_ffffcd32;
  comp_pos_y.fixed.i = DAT_ffffcd34 - comp_collision_sensor[0].y;
  DAT_ffffcbb2._1_1_ = in_A0[2];
  DAT_ffffcbb4._1_1_ = in_A0[3];
  sVar2 = (ushort)in_A0[5] * 6;
  DAT_ffffcd3b = (&DAT_0007d168)[sVar2];
  DAT_ffffcd3c = (&UNK_0007d169)[sVar2];
  DAT_ffffcd36 = (&UNK_0007d16a)[sVar2];
  DAT_ffffcd37 = (&UNK_0007d16b)[sVar2];
  DAT_ffffcd3e = (undefined *)0x0;
  sVar1 = *(short *)(&UNK_0007d16c + sVar2);
  if (sVar1 != 0) {
    DAT_ffffcd3e = (undefined *)((int)sVar1 + (int)(&UNK_0007d16c + sVar2));
  }
  return;
}

void FUN_00013dec(void)

{
  short sVar1;
  byte *in_A0;

  DAT_ffffcd3d = 0xff;
  DAT_ffffcd32 = (*in_A0 - 8) * 0x10 + 0x1000;
  sVar1 = (in_A0[1] - 8) * 0x10;
  DAT_ffffcd34 = sVar1 + 0x1000;
  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  comp_pos_x.fixed.i = DAT_ffffcd32;
  comp_pos_y.fixed.i = sVar1 + 0xff0;
  DAT_ffffcbb2._1_1_ = in_A0[2];
  DAT_ffffcbb4._1_1_ = in_A0[3];
  DAT_ffffcd3b = FUN_00013aca[(short)((ushort)in_A0[5] << 2) + 2];
  DAT_ffffcd3c = *(undefined1 *)((short)((ushort)in_A0[5] << 2) + 0x13acd);
  DAT_ffffcd3e = 0;
  return;
}

void FUN_00013e52(void)

{
  short sVar1;

  DAT_ffffcc92 = 0;
  entity_reset(ENTITY_ID_ASHA);
  sVar1 = DAT_ffff97ea << 3;
  DAT_ffffcd32 = ((byte)(&DAT_0007c8f8)[sVar1] - 8) * 0x10 + 0x1000;
  comp_pos_x.fixed.i = DAT_ffffcd32;
  DAT_ffffcd34 = ((byte)(&UNK_0007c8f9)[sVar1] - 8) * 0x10 + 0x1000;
  comp_pos_y.fixed.i = DAT_ffffcd34;
  DAT_ffffcd38 = (&UNK_0007c8fa)[sVar1];
  DAT_ffffcd39 = (&UNK_0007c8fb)[sVar1];
  DAT_ffffcd3a = (&DAT_0007c8fc)[sVar1];
  DAT_ffffcbb2 = (ushort)(byte)(&UNK_0007c8fa)[sVar1];
  DAT_ffffcbb4 = (ushort)(byte)(&UNK_0007c8fb)[sVar1];
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

script_t script_ee(script_t script)

{
  DAT_ffffcca2 = script + *(short *)script;
  _DAT_ffffd182 = FUN_00013efa();
  DAT_ffffd18a = _DAT_ffffd182;
  _DAT_ffffd186 = FUN_00013efa();
  DAT_ffffd18e = _DAT_ffffd186;
  _DAT_ffffd184 = FUN_00013efa();
  DAT_ffffd18c = _DAT_ffffd184;
  DAT_ffffd190 = FUN_00013efa();
  _DAT_ffffd188 = DAT_ffffd190;
  return script + 2;
}

undefined2 FUN_00013efa(void)

{
  undefined2 *in_A0;

  return *in_A0;
}

void FUN_00013f04(void)

{
  byte *pbVar1;
  byte *extraout_A0;

  if (DAT_ffffcca2 != 0) {
    pbVar1 = (byte *)(DAT_ffffcca2 + 8);
    while (*pbVar1 != 0xff) {
      (*(code *)((int)&WORD_00013f2c +
                 (int)*(short *)((int)&WORD_00013f2c +
                                 (int)(short)((ushort)*pbVar1 * 2))))();
      pbVar1 = extraout_A0;
    }
  }
  return;
}

void FUN_00013f34(void)

{
  ushort *in_A0;

  if ((((in_A0[1] <= (ushort)(comp_collision_sensor[0].y +
                              component_pos_old_y[0].fixed.i)) &&
        ((ushort)(comp_collision_sensor[0].y + comp_pos_y.fixed.i) <
         in_A0[1])) &&
       (*in_A0 <= (ushort)comp_pos_x.fixed.i)) &&
      ((ushort)comp_pos_x.fixed.i <= (ushort)(*in_A0 + in_A0[2]))) {
    FUN_00014044();
  }
  return;
}

void FUN_00013f7a(void)

{
  ushort *in_A0;

  if (((((ushort)(comp_collision_sensor[0].y +
                  component_pos_old_y[0].fixed.i) <= in_A0[1]) &&
        (in_A0[1] <=
         (ushort)(comp_collision_sensor[0].y + comp_pos_y.fixed.i))) &&
       (*in_A0 <= (ushort)comp_pos_x.fixed.i)) &&
      ((ushort)comp_pos_x.fixed.i <= (ushort)(*in_A0 + in_A0[2]))) {
    FUN_00014044();
  }
  return;
}

void FUN_00013fc0(void)

{
  ushort *in_A0;

  if ((((*in_A0 <= (ushort)component_pos_old_x[0]._0_2_) &&
        ((ushort)comp_pos_x.fixed.i < *in_A0)) &&
       (in_A0[1] <=
        (ushort)(comp_collision_sensor[0].y + comp_pos_y.fixed.i))) &&
      ((ushort)(comp_collision_sensor[0].y + comp_pos_y.fixed.i) <=
       (ushort)(in_A0[1] + in_A0[2]))) {
    FUN_00014044();
  }
  return;
}

void FUN_00014002(void)

{
  ushort *in_A0;

  if (((((ushort)component_pos_old_x[0]._0_2_ <= *in_A0) &&
        (*in_A0 <= (ushort)comp_pos_x.fixed.i)) &&
       (in_A0[1] <=
        (ushort)(comp_collision_sensor[0].y + comp_pos_y.fixed.i))) &&
      ((ushort)(comp_collision_sensor[0].y + comp_pos_y.fixed.i) <=
       (ushort)(in_A0[1] + in_A0[2]))) {
    FUN_00014044();
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00014044(void)

{
  short *in_A0;

  DAT_ffffcf84 = 0xff;
  DAT_ffffcca2 = (int)in_A0 + (int)*in_A0;
  _DAT_ffffd182 = FUN_00014084();
  DAT_ffffd18a = _DAT_ffffd182;
  _DAT_ffffd186 = FUN_00014084();
  DAT_ffffd18e = _DAT_ffffd186;
  _DAT_ffffd184 = FUN_00014084();
  DAT_ffffd18c = _DAT_ffffd184;
  DAT_ffffd190 = FUN_00014084();
  _DAT_ffffd188 = DAT_ffffd190;
  return;
}

undefined2 FUN_00014084(void)

{
  undefined2 *in_A1;

  return *in_A1;
}

void FUN_0001408e(void)

{
  char unaff_D6b;
  short *psVar1;
  int extraout_A0;

  psVar1 = DAT_ffffcca2;
  if (DAT_ffffcca2 != (short *)0x0) {
    while (*psVar1 != 0) {
      FUN_000140d8();
      if (unaff_D6b != '\0') {
        return;
      }
      psVar1 = (short *)(extraout_A0 + 2);
    }
    FUN_000140f0();
  }
  return;
}

void FUN_000140d8(void)

{
  ushort in_D0w;
  ushort in_D1w;
  ushort unaff_D2w;
  ushort unaff_D3w;
  ushort unaff_D4w;
  ushort unaff_D5w;

  if ((((in_D0w <= unaff_D4w) && (unaff_D4w <= unaff_D2w)) &&
       (in_D1w <= unaff_D5w)) &&
      (unaff_D5w <= unaff_D3w)) {
    FUN_000140f0();
  }
  return;
}

void FUN_000140f0(void)

{
  short *in_A0;

  DAT_ffffcca2 = (int)in_A0 + (int)*in_A0;
  FUN_00014106();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00014106(void)

{
  _DAT_ffffd182 = FUN_00014130();
  DAT_ffffd18a = _DAT_ffffd182;
  _DAT_ffffd186 = FUN_00014130();
  DAT_ffffd18e = _DAT_ffffd186;
  _DAT_ffffd184 = FUN_00014130();
  DAT_ffffd18c = _DAT_ffffd184;
  DAT_ffffd190 = FUN_00014130();
  _DAT_ffffd188 = DAT_ffffd190;
  return;
}

undefined2 FUN_00014130(void)

{
  undefined2 *in_A0;

  return *in_A0;
}

void FUN_0001413a(void)

{
  undefined2 *unaff_A5;
  bool bVar1;

  DAT_ffff97ea = *unaff_A5;
  DAT_ffffcd3d = 0xff;
  DAT_ffffcd3e = 0;
  DAT_ffffcc92 = 1;
  DAT_ffffcc93 = 7;
  DAT_ffffe232 = 0;
  bVar1 = script_state_get((script_state_bit_t)0x3e9);
  if (!bVar1) {
    DAT_ffffe232 = 2;
  }
  return;
}

script_t script_ed(script_t script)

{
  undefined2 uVar1;
  undefined2 uVar2;
  byte state_1_b;
  short unaff_D2w;
  entity_id_t self;
  anim_item_t *anim;
  bool bVar3;

  uVar1 = *(undefined2 *)script;
  uVar2 = *(undefined2 *)(script + 2);
  anim = (anim_item_t *)(script + 8);
  bVar3 =
      script_state_get((script_state_bit_t)(*(ushort *)(script + 4) & 0x7fff));
  if (bVar3) {
    FUN_0000147a(FUN_00014784, 1, 0);
    if (unaff_D2w < 0) {
      return (script_t)anim;
    }
    entity_reset((int)unaff_D2w);
    *(undefined1 *)((int)&comp_state + (int)unaff_D2w) = 0;
    state_1_b = 0;
  } else {
    FUN_0000147a(FUN_00014784, 1, 0);
    if (unaff_D2w < 0) {
      return (script_t)anim;
    }
    entity_reset((int)unaff_D2w);
    *(undefined1 *)((int)&comp_state + (int)unaff_D2w) = 1;
    state_1_b = 6;
  }
  self = (entity_id_t)unaff_D2w;
  *(undefined2 *)((int)&comp_unk_3 + self) = 0x1e;
  (&comp_anim_base_offset)[self] = 0x14;
  (&comp_anim_b)[self] = 10;
  *(undefined2 *)((int)&comp_pos_x + self) = uVar1;
  *(undefined2 *)((int)&comp_pos_y + self) = uVar2;
  *(script_t *)(&comp_unk_9 + self) = script + 4;
  *(undefined2 *)((int)&comp_collision_sensor[0].x + self) = 0;
  *(undefined2 *)((int)&comp_collision_sensor[0].y + self) = 0;
  ecs_anim_unk_2(self, anim, state_1_b);
  (&comp_state_a)[self] = (&comp_state_a)[self] & 0x7f;
  if (DAT_ffffcc28 != '\0') {
    (&comp_state_a)[self] = (&comp_state_a)[self] | 0x80;
  }
  if (DAT_ffffcc93 == '\x03') {
    (&comp_has_func_maybe)[self] = (&comp_has_func_maybe)[self] | 8;
  }
  return (script_t)anim;
}

script_t script_ec(script_t script)

{
  short unaff_D2w;
  entity_id_t e;

  FUN_0000147a(FUN_00014288, 1, 0);
  if (-1 < unaff_D2w) {
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    (&comp_state_a)[e] = *script;
    *(undefined2 *)((int)&comp_pos_x + e) = *(undefined2 *)(script + 1);
    *(undefined2 *)((int)&comp_pos_y + e) = *(undefined2 *)(script + 3);
    *(char *)((int)&comp_unk_3 + e + 1) = script[5];
    (&comp_anim_base_offset)[e] = script[6];
    (&comp_anim_b)[e] = script[7];
    ecs_anim_unk_2(e, (anim_item_t *)(script + 9), script[8]);
    return (script_t)(anim_item_t *)(script + 9);
  }
  return script + 9;
}

void FUN_00014282(void)

{
  return;
}

void FUN_00014288(void)

{
  return;
}

void FUN_0001428a(void)

{
  short unaff_D2w;
  func *f;
  entity_id_t e;
  anim_item_t *unaff_A5;
  bool bVar1;

  if (DAT_ffff97e9 == '\0') {
    bVar1 = script_state_get(*(script_state_bit_t *)(unaff_A5 + 4));
    if (bVar1) {
      FUN_0000147a(f, 3, 0);
      if (-1 < unaff_D2w) {
        e = (entity_id_t)unaff_D2w;
        entity_reset(e);
        *(undefined2 *)((int)&comp_pos_x + e) = *(undefined2 *)unaff_A5;
        *(undefined2 *)((int)&comp_pos_y + e) = *(undefined2 *)(unaff_A5 + 2);
        *(undefined2 *)((int)&comp_unk_3 + e) = 0x1e;
        (&comp_anim_base_offset)[e] = 0x14;
        (&comp_anim_b)[e] = 8;
        ecs_anim_unk_2(e, unaff_A5, 0);
        *(undefined2 *)(&DAT_ffffba76 + e) = *(undefined2 *)(unaff_A5 + 4);
      }
    }
  }
  return;
}

void FUN_000142fc(void)

{
  short unaff_D2w;
  func *f;
  entity_id_t e;
  anim_item_t *unaff_A5;
  bool bVar1;

  if (DAT_ffff97e9 == '\0') {
    bVar1 = script_state_get(*(script_state_bit_t *)(unaff_A5 + 4));
    if (bVar1) {
      FUN_0000147a(f, 10, 0);
      if (-1 < unaff_D2w) {
        e = (entity_id_t)unaff_D2w;
        entity_reset(e);
        *(undefined2 *)((int)&comp_pos_x + e) = *(undefined2 *)unaff_A5;
        *(undefined2 *)((int)&comp_pos_y + e) = *(undefined2 *)(unaff_A5 + 2);
        *(undefined2 *)((int)&comp_unk_3 + e) = 0x1e;
        (&comp_anim_base_offset)[e] = 0x14;
        (&comp_anim_b)[e] = 0x2a;
        ecs_anim_unk_2(e, unaff_A5, 0);
        *(undefined2 *)(&DAT_ffffba76 + e) = *(undefined2 *)(unaff_A5 + 4);
        *(undefined2 *)((int)&comp_unk_8 + e) = *(undefined2 *)(unaff_A5 + 6);
        (&comp_collected_item_id_maybe)[e] = unaff_A5[8];
        (&DAT_ffffb976)[e] = unaff_A5[9];
      }
    }
  }
  return;
}

void FUN_0001438a(void)

{
  short unaff_D2w;
  func *in_A1;
  entity_id_t e;
  byte *unaff_A5;

  if (DAT_ffff97e9 == '\0') {
    FUN_0000147a(in_A1, 4, 0);
    if (-1 < unaff_D2w) {
      e = (entity_id_t)unaff_D2w;
      entity_reset(e);
      *(ushort *)((int)&comp_pos_x + e) = (ushort)*unaff_A5 * 0x10 + 0x1000;
      *(ushort *)((int)&comp_pos_y + e) = (ushort)unaff_A5[1] * 0x10 + 0x1000;
      (*(code
             *)((int)&WORD_000143ec +
                (int)*(
                    short
                        *)((int)&WORD_000143ec +
                           (int)(short)((ushort) *
                                        (byte
                                             *)((int)&WORD_000143f0 +
                                                (int)(short)(*(short
                                                                   *)(unaff_A5 +
                                                                      2)
                                                             << 2)) *
                                        2))))();
    }
  }
  return;
}

void FUN_000143f8(void)

{
  script_state_bit_t index;
  byte state_1_b;
  int unaff_A3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar1;

  index = *(script_state_bit_t *)(unaff_A5 + 4);
  *(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4) = index;
  bVar1 = script_state_get(index);
  if (bVar1) {
    state_1_b = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  } else {
    state_1_b = 2;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
  }
  *(undefined1 *)((int)&comp_unk_3 + unaff_A4 + 1) =
      *(undefined1 *)(unaff_A3 + 1);
  (&comp_anim_base_offset)[unaff_A4] = *(byte *)(unaff_A3 + 2);
  (&comp_anim_b)[unaff_A4] = *(byte *)(unaff_A3 + 3);
  ecs_anim_unk_2(unaff_A4, unaff_A5, state_1_b);
  *(short *)((int)&comp_pos_x + unaff_A4) =
      *(short *)((int)&comp_collision_sensor[0].x + unaff_A4) +
      *(short *)((int)&comp_pos_x + unaff_A4);
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
      *(short *)((int)&comp_pos_y + unaff_A4);
  *(code **)((int)&comp_some_function + unaff_A4) = FUN_000144a0;
  return;
}

void FUN_0001444e(void)

{
  script_state_bit_t index;
  int unaff_A3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar1;

  index = *(script_state_bit_t *)(unaff_A5 + 4);
  *(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4) = index;
  bVar1 = script_state_get(index);
  if (bVar1) {
    *(undefined1 *)((int)&comp_unk_3 + unaff_A4 + 1) =
        *(undefined1 *)(unaff_A3 + 1);
    (&comp_anim_base_offset)[unaff_A4] = *(byte *)(unaff_A3 + 2);
    (&comp_anim_b)[unaff_A4] = *(byte *)(unaff_A3 + 3);
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_collision_sensor[0].x + unaff_A4) +
        *(short *)((int)&comp_pos_x + unaff_A4);
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
        *(short *)((int)&comp_pos_y + unaff_A4);
    *(code **)((int)&comp_some_function + unaff_A4) = FUN_00014550;
  } else {
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

void FUN_000144a0(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x000144b2. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&jmp_000144b4 +
             (int)*(
                 short *)((int)&jmp_000144b4 +
                          (int)(short)((ushort) *
                                       (byte *)((int)&comp_state + unaff_A4) *
                                       2))))();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000144b8(void)

{
  ushort uVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar2;
  bool bVar3;

  bVar2 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (bVar2) {
    bVar2 = *(ushort *)((int)&comp_pos_y + unaff_A4) <
            (ushort)(comp_pos_y.fixed.i - 8U);
    if (*(ushort *)((int)&comp_pos_y + unaff_A4) ==
        (ushort)(comp_pos_y.fixed.i - 8U)) {
      bVar2 = (ushort)comp_pos_x.fixed.i <
              (ushort)(*(short *)((int)&comp_pos_x + unaff_A4) - 4U);
      if ((!bVar2) && (uVar1 = *(short *)((int)&comp_pos_x + unaff_A4) + 4,
                       bVar2 = (ushort)comp_pos_x.fixed.i < uVar1,
                       (ushort)comp_pos_x.fixed.i <= uVar1)) {
        _DAT_ffffcc6e = (short)unaff_A4;
        set_to_13a62_when_facing_a_door = FUN_0001452a;
        return;
      }
    }
    bVar3 = (pepelogoo_state_b & 0x40) == 0;
    if ((!bVar3) && (ecs_check_collides_x(unaff_A4, 4), bVar2 || bVar3)) {
      DAT_ffffcc92 = 7;
      _DAT_ffffde38 = (short)unaff_A4;
      *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
    }
  } else {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
    *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
  }
  return;
}

void FUN_0001452a(void)

{
  set_to_13a62_when_facing_a_door = 0;
  DAT_ffffcc92 = 6;
  return;
}

void FUN_00014536(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar1;

  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (bVar1) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00014550(void)

{
  int unaff_A4;
  bool bVar1;
  undefined1 in_CF;

  bVar1 = (pepelogoo_state_b & 0x40) == 0;
  if (!bVar1) {
    ecs_check_collides_x(unaff_A4, 4);
    if ((bool)in_CF || bVar1) {
      DAT_ffffcc92 = 8;
      _DAT_ffffde38 = (undefined2)unaff_A4;
      *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
    }
  }
  return;
}

void FUN_00014574(void)

{
  return;
}

void FUN_000145b4(void)

{
  short sVar1;
  uint uVar2;
  int iVar3;

  uVar2 = 0;
  do {
    (&DAT_ffffce0c)[uVar2] = 0;
    uVar2 = uVar2 + 4;
  } while (uVar2 < 0x28);
  iVar3 = 0x84;
  sVar1 = 0x11;
  do {
    (&comp_has_func_maybe)[iVar3] = 0;
    iVar3 = iVar3 + 4;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return;
}

void FUN_000145d8(void)

{
  undefined1 uVar1;
  undefined2 extraout_D1w;
  short unaff_D2w;
  int unaff_A3;

  uVar1 = FUN_000145f8();
  if (-1 < unaff_D2w) {
    *(undefined1 *)(unaff_A3 + -0x31f2) = uVar1;
    *(undefined2 *)(unaff_A3 + -0x31cc) = extraout_D1w;
    (&DAT_ffffce0c)[unaff_A3] = 0x80;
    *(undefined2 *)(&DAT_ffffce5c + unaff_A3) = 0xffff;
  }
  return;
}

void FUN_000145f8(void)

{
  uint uVar1;

  uVar1 = 0;
  do {
    if (-1 < (char)(&DAT_ffffce0c)[uVar1]) {
      return;
    }
    uVar1 = uVar1 + 4;
  } while (uVar1 < 0x28);
  return;
}

void FUN_00014610(void)

{
  uint uVar1;

  uVar1 = 0;
  do {
    if ((char)(&DAT_ffffce0c)[uVar1] < '\0') {
      *(short *)((int)&DAT_ffffce36 + uVar1) =
          *(short *)((int)&DAT_ffffce36 + uVar1) + -1;
      (**(code **)((int)&DAT_ffffce84 + uVar1))();
    }
    uVar1 = uVar1 + 4;
  } while (uVar1 < 0x28);
  return;
}

void FUN_00014632(void)

{
  byte bVar1;
  short sVar2;
  short unaff_D2w;
  int unaff_A3;
  short *unaff_A5;

  FUN_000145d8();
  do {
  } while (unaff_D2w < 0);
  sVar2 = *unaff_A5 << 3;
  *(ushort *)(unaff_A3 + -0x3154) =
      ((byte)(&DAT_0007c8f8)[sVar2] - 8) * 0x10 + 0x1000;
  *(ushort *)(unaff_A3 + -0x3152) =
      ((byte)(&UNK_0007c8f9)[sVar2] - 8) * 0x10 + 0x1000;
  bVar1 = (&UNK_0007c8fd)[sVar2];
  *(ushort *)(unaff_A3 + -0x312c) =
      (ushort)(byte)(&UNK_0007d16a)[(short)((ushort)bVar1 << 2)] << 2;
  *(ushort *)(unaff_A3 + -0x312a) =
      (ushort)(byte)(&UNK_0007d16b)[(short)((ushort)bVar1 << 2)] << 4;
  *(code **)((int)&DAT_ffffce84 + unaff_A3) = FUN_000133cc;
  return;
}

void FUN_000146a4(void)

{
  byte bVar1;
  byte *in_A1;
  byte *extraout_A1;
  int unaff_A3;
  short *unaff_A5;
  bool in_NF;

  if (!in_NF) {
    if ((&DAT_0007c8fc)[(short)(*unaff_A5 << 3)] != '\x02') {
      return;
    }
    FUN_000145d8();
    in_A1 = extraout_A1;
  }
  *(ushort *)(unaff_A3 + -0x3154) = (*in_A1 - 8) * 0x10 + 0x1000;
  *(ushort *)(unaff_A3 + -0x3152) = (in_A1[1] - 8) * 0x10 + 0x1000;
  bVar1 = in_A1[5];
  *(ushort *)(unaff_A3 + -0x312c) =
      (ushort)(byte)(&UNK_0007d16a)[(short)((ushort)bVar1 << 2)] << 2;
  *(ushort *)(unaff_A3 + -0x312a) =
      (ushort)(byte)(&UNK_0007d16b)[(short)((ushort)bVar1 << 2)] << 4;
  *(code **)((int)&DAT_ffffce84 + unaff_A3) = FUN_000133cc;
  return;
}

void FUN_00014722(void)

{
  uint uVar1;

  if ((DAT_ffffcf8a != '\0') &&
      (DAT_ffffcf8c = DAT_ffffcf8c + -1, DAT_ffffcf8c == 0)) {
    DAT_ffffcf8a = '\0';
    script_state_set_true(DAT_ffffcf8e);
  }
  uVar1 = 0x84;
  do {
    if ((char)(&comp_has_func_maybe)[uVar1] < '\0') {
      (*(code *)((int)&WORD_00014762 +
                 (int)*(short *)((int)&WORD_00014762 +
                                 (int)(short)(*(short *)(&comp_unk_1 + uVar1) *
                                              2))))();
    }
    uVar1 = uVar1 + 4;
  } while (uVar1 < 0xcc);
  return;
}

void FUN_00014778(void)

{
  return;
}

void FUN_0001477a(entity_id_t self)

{
  *(short *)(&comp_unk_5 + self) = *(short *)(&comp_unk_5 + self) + 1;
  // WARNING: Could not recover jumptable at 0x00014782. Too many branches
  // WARNING: Treating indirect jump as call
  (**(code **)((int)&comp_some_function + self))();
  return;
}

// FIXME Where is this used?

void FUN_00014784(entity_id_t self)

{
  if (DAT_ffff97e9 != '\0') {
    (&comp_has_func_maybe)[self] = (&comp_has_func_maybe)[self] & 0xf7;
  }
  // WARNING: Could not recover jumptable at 0x000147a2. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_000147a4 +
             (int)*(short *)((int)&WORD_000147a4 +
                             (int)(short)((ushort) *
                                          (byte *)((int)&comp_state + self) *
                                          2))))();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000147ac(void)

{
  short *psVar1;
  short sVar2;
  entity_id_t unaff_A4;
  undefined1 uVar3;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar2 = *psVar1 + 0x40;
  *psVar1 = sVar2;
  uVar3 = sVar2 == 0;
  entity_update_pos(unaff_A4);
  FUN_00002408();
  if (!(bool)uVar3) {
    FUN_00002420();
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  if (((*(short *)((int)&comp_pos_y + unaff_A4) ==
        (short)(comp_collision_sensor[0].y + comp_pos_y.fixed.i)) &&
       ((ushort)(*(short *)((int)&comp_pos_x + unaff_A4) - 8U) <=
        (ushort)comp_pos_x.fixed.i)) &&
      ((ushort)comp_pos_x.fixed.i <=
       (ushort)(*(short *)((int)&comp_pos_x + unaff_A4) + 8U))) {
    _DAT_ffffcf86 = (undefined2)unaff_A4;
    set_to_13a62_when_facing_a_door = FUN_000148a8;
  }
  return;
}

void FUN_000147fe(void)

{
  return;
}

void FUN_00014800(void)

{
  char *pcVar1;
  char cVar2;
  ushort *puVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    puVar3 = *(ushort **)(&comp_unk_9 + unaff_A4) + 1;
    script_state_set_true(
        (script_state_bit_t)(**(ushort **)(&comp_unk_9 + unaff_A4) & 0x7fff));
    pcVar1 = (char *)((int)puVar3 + (int)(short)*puVar3);
    cVar2 = *pcVar1;
    if (cVar2 == '\0') {
      ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
      *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
      return;
    }
    (&comp_collision_related)[unaff_A4] = cVar2;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    *(char **)(&comp_unk_9 + unaff_A4) = pcVar1 + 1;
  }
  return;
}

void ecs_unk_2(entity_id_t self, anim_item_t *anim)

{
  byte item_id_maybe;
  char cVar1;
  short extraout_D0w;

  (&comp_collision_related)[self] = (&comp_collision_related)[self] + -1;
  if ((&comp_collision_related)[self] == '\0') {
    item_id_maybe = **(byte **)(&comp_unk_9 + self);
    *(byte **)(&comp_unk_9 + self) = *(byte **)(&comp_unk_9 + self) + 1;
    ecs_collect_or_spawn_item_maybe(*(int16_t *)((int)&comp_pos_x + self),
                                    *(short *)((int)&comp_pos_y + self) + -0x18,
                                    item_id_maybe);
    if (extraout_D0w < 0) {
      (&comp_collision_related)[self] = 1;
      *(int *)(&comp_unk_9 + self) = *(int *)(&comp_unk_9 + self) + -1;
    } else {
      cVar1 = **(char **)(&comp_unk_9 + self);
      if (cVar1 == '\0') {
        ecs_anim_unk_2(self, anim, 6);
        *(undefined1 *)((int)&comp_state + self) = 1;
      } else {
        *(char **)(&comp_unk_9 + self) = *(char **)(&comp_unk_9 + self) + 1;
        (&comp_collision_related)[self] = cVar1;
        *(undefined1 *)((int)&comp_state + self) = 3;
      }
    }
  }
  return;
}

// FIXME Where is it called?

void FUN_000148a8(void)

{
  DAT_ffffcc92 = 4;
  set_to_13a62_when_facing_a_door = 0;
  return;
}

// FIXME Where is it called?

void FUN_000148b4(void)

{
  word wVar1;
  short unaff_D2w;
  func *in_A1;
  entity_id_t e;
  anim_item_t *unaff_A5;

  if (DAT_ffff97e9 == '\0') {
    FUN_0000147a(in_A1, 5, 0);
    if (-1 < unaff_D2w) {
      e = (entity_id_t)unaff_D2w;
      entity_reset(e);
      *(ushort *)((int)&comp_pos_x + e) = (ushort)*unaff_A5 * 0x10 + 0x1000;
      *(ushort *)((int)&comp_pos_y + e) = (ushort)unaff_A5[1] * 0x10 + 0x1000;
      *(ushort *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + e) =
          (ushort)unaff_A5[2] << 4;
      *(code **)((int)&comp_some_function + e) = FUN_0001492e;
      (&comp_anim_base_offset)[e] = 0x14;
      (&comp_anim_b)[e] = 6;
      ecs_anim_unk_2(e, unaff_A5, 0);
      *(short *)((int)&comp_pos_y + e) =
          *(short *)((int)&comp_pos_y + e) -
          *(short *)((int)&comp_collision_sensor[0].y + e);
      wVar1 = rand();
      (&DAT_ffffb979)[e] = (byte)wVar1 & 0x3f;
      *(undefined1 *)((int)&comp_state + e) = 0;
    }
  }
  return;
}

void FUN_0001492e(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x0001493a. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&jmp_0001493e +
             (int)*(
                 short *)((int)&jmp_0001493e +
                          (int)(short)((ushort) *
                                       (byte *)((int)&comp_state + unaff_A4) *
                                       2))))();
  return;
}

void FUN_00014942(void)

{
  word wVar1;
  int unaff_A4;

  (&DAT_ffffb979)[unaff_A4] = (&DAT_ffffb979)[unaff_A4] + -1;
  if ((char)(&DAT_ffffb979)[unaff_A4] < '\0') {
    FUN_000149d4();
    wVar1 = rand();
    (&DAT_ffffb979)[unaff_A4] = (byte)wVar1 & 0x3f;
  }
  return;
}

void FUN_0001495e(void)

{
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00014960(void)

{
  int unaff_A3;

  *(undefined1 *)((int)&comp_state + unaff_A3) = 1;
  _DAT_ffffcf88 = (short)unaff_A3;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address
// FIXME Where is it called?

void FUN_0001496c(void)

{
  int iVar1;

  FUN_0001498c();
  iVar1 = (int)_DAT_ffffcf88;
  *(undefined1 *)((int)&comp_state + iVar1) = 0;
  rand();
  (&DAT_ffffb979)[iVar1] = 0x7f;
  return;
}

void FUN_0001498c(void)

{
  short sVar1;
  short unaff_D2w;
  func *in_A1;
  int unaff_A4;
  entity_id_t e;
  anim_item_t *unaff_A5;

  FUN_0000147a(in_A1, 1, 4);
  if (-1 < unaff_D2w) {
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    sVar1 = *(short *)((int)&comp_pos_y + unaff_A4);
    *(undefined2 *)((int)&comp_pos_x + e) =
        *(undefined2 *)((int)&comp_pos_x + unaff_A4);
    *(short *)((int)&comp_pos_y + e) = sVar1 + -8;
    *(code **)((int)&comp_some_function + e) = FUN_00014a58;
    (&comp_anim_base_offset)[e] = 0x14;
    (&comp_anim_b)[e] = 4;
    ecs_anim_unk_2(e, unaff_A5, 0);
    *(undefined2 *)((int)&comp_vel[0].y + e) = 0xffc0;
  }
  return;
}

void FUN_000149d4(void)

{
  word wVar1;
  short sVar2;
  short unaff_D2w;
  func *in_A1;
  int unaff_A4;
  entity_id_t self;
  anim_item_t *unaff_A5;

  FUN_0000147a(in_A1, 1, 4);
  if (-1 < unaff_D2w) {
    self = (entity_id_t)unaff_D2w;
    entity_reset(self);
    sVar2 = *(short *)((int)&comp_pos_y + unaff_A4);
    *(undefined2 *)((int)&comp_pos_x + self) =
        *(undefined2 *)((int)&comp_pos_x + unaff_A4);
    *(short *)((int)&comp_pos_y + self) = sVar2 + -8;
    *(code **)((int)&comp_some_function + self) = FUN_00014a58;
    (&comp_anim_base_offset)[self] = 0;
    (&comp_anim_b)[self] = 10;
    ecs_anim_unk_2(self, unaff_A5, 0);
    wVar1 = rand();
    sVar2 = (wVar1 & 7) << 2;
    *(short *)((int)&comp_pos_x + self) =
        *(short *)((int)&int16_vec2_t_ARRAY_00014a38[0].x + (int)sVar2) +
        *(short *)((int)&comp_pos_x + self);
    *(undefined2 *)((int)&comp_vel[0].y + self) =
        *(undefined2 *)((int)&int16_vec2_t_ARRAY_00014a38[0].y + (int)sVar2);
  }
  return;
}

void FUN_00014a58(void)

{
  ulong unaff_A4;

  player_update_pos(unaff_A4);
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

script_t script_eb(script_t script)

{
  char *pcVar1;
  char *extraout_A0;

  pcVar1 = script + *(short *)script;
  while (-1 < *pcVar1) {
    func_0x00014a7e();
    pcVar1 = extraout_A0;
  }
  return script + 2;
}

void FUN_00014ac0(void)

{
  uint uVar1;

  uVar1 = 0;
  do {
    (&DAT_ffffcefe)[uVar1] = 0;
    uVar1 = uVar1 + 4;
  } while (uVar1 < 0x20);
  return;
}

script_t text_command_ea(script_t script)

{
  ushort uVar1;

  uVar1 = *(ushort *)script - comp_pos_x._0_2_;
  if (*(ushort *)script < (ushort)comp_pos_x.fixed.i) {
    uVar1 = -uVar1;
  }
  if (uVar1 <= (ushort)(comp_collision_sensor[0].x + *(short *)(script + 4))) {
    uVar1 = *(ushort *)(script + 2) - comp_pos_y._0_2_;
    if (*(ushort *)(script + 2) < (ushort)comp_pos_y.fixed.i) {
      uVar1 = -uVar1;
    }
    if (uVar1 <=
        (ushort)(comp_collision_sensor[0].y + *(short *)(script + 6))) {
      FUN_000128d4();
    }
  }
  return script + 10;
}

script_t script_e9(script_t script)

{
  DAT_ffffcbf6 = *(undefined2 *)script;
  return script + 2;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00014b30(void)

{
  int iVar1;
  bool bVar2;

  iVar1 = 0;
  while (-1 < (char)(&DAT_ffffcefe)[iVar1]) {
    iVar1 = iVar1 + 4;
    if (iVar1 == 0x10) {
      return;
    }
  }
  if (*(char *)(iVar1 + -0x33e6) != '\0') {
    bVar2 = script_state_get(_DAT_ffffcbfa);
    if (!bVar2) {
      return;
    }
    bVar2 = script_state_get(*(script_state_bit_t *)(&DAT_ffffcbfa + iVar1));
    if (bVar2) {
      DAT_ffffc8de = *(undefined2 *)(iVar1 + -0x33f8);
      DAT_ffffc8dc = *(undefined2 *)(iVar1 + -0x33f6);
      FUN_00014c6c();
      (&DAT_ffffcefe)[(short)((ushort)(byte)(&DAT_ffffcf40)[iVar1] << 2)] = 0;
    }
    return;
  }
  bVar2 = script_state_get(_DAT_ffffcbfa);
  if (bVar2) {
    return;
  }
  bVar2 = script_state_get(*(script_state_bit_t *)(&DAT_ffffcbfa + iVar1));
  if (!bVar2) {
    DAT_ffffc8de = *(undefined2 *)(iVar1 + -0x33f8);
    DAT_ffffc8dc = *(undefined2 *)(iVar1 + -0x33f6);
    if ((*(byte *)(iVar1 + -0x3407) & 1) == 0) {
      FUN_00014bd4();
    } else {
      FUN_00014c06();
    }
    _DAT_ffffcf1e = *(short *)(iVar1 + -0x33f6) + -0x10;
    _DAT_ffffcf3e = 0x10;
    _DAT_ffffcf20 = *(ushort *)(iVar1 + -0x33e8) >> 1;
    _DAT_ffffcf00 = *(short *)(iVar1 + -0x33f8) + _DAT_ffffcf20;
    DAT_ffffceff = *(undefined1 *)(iVar1 + -0x3407);
    DAT_ffffcf40 = *(undefined1 *)(iVar1 + -0x33e5);
    DAT_ffffcefe = 0x80;
  }
  return;
}

void FUN_00014bd4(void)

{
  int unaff_A4;

  do {
    DAT_ffffc8e0 = 0;
    DAT_ffffc8e2 = 1;
    FUN_0000b85e(WORD_ARRAY_00014c38);
    DAT_ffffc8de = DAT_ffffc8de + 0x10;
  } while (DAT_ffffc8de < (ushort)(*(short *)(unaff_A4 + -0x33e8) +
                                   *(short *)(unaff_A4 + -0x33f8)));
  return;
}

void FUN_00014c06(void)

{
  int unaff_A4;

  do {
    DAT_ffffc8e0 = 0;
    DAT_ffffc8e2 = 1;
    FUN_0000b85e(WORD_ARRAY_00014c38);
    DAT_ffffc8de = DAT_ffffc8de + 0x10;
  } while (DAT_ffffc8de < (ushort)(*(short *)(unaff_A4 + -0x33e8) +
                                   *(short *)(unaff_A4 + -0x33f8)));
  return;
}

void FUN_00014c6c(void)

{
  int unaff_A4;

  do {
    DAT_ffffc8e0 = 0;
    DAT_ffffc8e2 = 1;
    FUN_0000b85e(&WORD_00014c9e);
    DAT_ffffc8de = DAT_ffffc8de + 0x10;
  } while (DAT_ffffc8de < (ushort)(*(short *)(unaff_A4 + -0x33e8) +
                                   *(short *)(unaff_A4 + -0x33f8)));
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00014ca0(void)

{
  ushort *unaff_A5;

  if (unaff_A5[1] ==
      (ushort)(comp_collision_sensor[0].y + comp_pos_y.fixed.i)) {
    if ((*unaff_A5 <=
         (ushort)(comp_pos_x.fixed.i - comp_collision_sensor[0].x)) &&
        ((ushort)(comp_pos_x.fixed.i - comp_collision_sensor[0].x) <=
         (ushort)(*unaff_A5 + (ushort) * (byte *)(unaff_A5 + 2)))) {
      DAT_ffffcf7e = *(undefined1 *)((int)unaff_A5 + 5);
      DAT_ffffcf7f = *(undefined1 *)(unaff_A5 + 3);
      _DAT_ffffcf80 = *(undefined2 *)((int)unaff_A5 + 7);
      _DAT_ffffcf82 = *(undefined2 *)((int)unaff_A5 + 9);
    }
  }
  return;
}

void FUN_00014d00(void)

{
  script_state_bit_t index;
  byte state_1_b;
  short unaff_D2w;
  func *in_A1;
  entity_id_t e;
  anim_item_t *unaff_A5;
  bool bVar1;

  if (DAT_ffff97e9 == '\0') {
    FUN_0000147a(in_A1, 7, 0);
    do {
    } while (unaff_D2w < 0);
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    *(undefined2 *)((int)&comp_pos_x + e) = *(undefined2 *)unaff_A5;
    *(undefined2 *)((int)&comp_pos_y + e) = *(undefined2 *)(unaff_A5 + 2);
    (&comp_anim_base_offset)[e] = unaff_A5[4];
    (&comp_anim_b)[e] = unaff_A5[5];
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x1a;
    index = *(script_state_bit_t *)(unaff_A5 + 6);
    *(script_state_bit_t *)(&DAT_ffffba76 + e) = index;
    bVar1 = script_state_get(index);
    if (bVar1) {
      state_1_b = 0;
    } else {
      *(undefined2 *)(&comp_unk_1 + e) = 0;
      state_1_b = 2;
    }
    ecs_anim_unk_2(e, unaff_A5, state_1_b);
    *(short *)((int)&comp_pos_y + e) =
        *(short *)((int)&comp_pos_y + e) -
        *(short *)((int)&comp_collision_sensor[0].y + e);
    *(code **)((int)&comp_some_function + e) = FUN_00014d82;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00014d82(void)

{
  byte bVar1;
  entity_id_t unaff_A4;
  undefined1 in_ZF;
  bool bVar2;
  undefined1 in_CF;

  FUN_00000ed6(unaff_A4, ENTITY_ID_ASHA);
  if ((bool)in_CF || (bool)in_ZF) {
    bVar1 = uint8_t_ffffcc70 | 2;
    if ((ushort)comp_pos_x.fixed.i <=
        *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      bVar1 = uint8_t_ffffcc70 | 0x82;
    }
  } else {
    bVar2 = (pepelogoo_state_b & 0x40) == 0;
    bVar1 = uint8_t_ffffcc70;
    if ((!bVar2) && (FUN_00000ed6(unaff_A4, ENTITY_ID_PEPELOGOO),
                     bVar1 = uint8_t_ffffcc70,
                     (bool)in_CF || bVar2)) {
      DAT_ffffcc92 = 0xb;
      _DAT_ffffde38 = (undefined2)unaff_A4;
      *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
      bVar1 = uint8_t_ffffcc70;
    }
  }
  uint8_t_ffffcc70 = bVar1;
  entity_update_pos(unaff_A4);
  (&comp_unk_10)[unaff_A4] = 0;
  (&comp_collision_related)[unaff_A4] = 1;
  FUN_0000e75a();
  return;
}

void FUN_00014dde(void)

{
  short sVar1;
  short sVar2;
  undefined2 uVar3;
  script_state_bit_t index;
  short unaff_D2w;
  entity_id_t e;
  anim_item_t *unaff_A5;
  bool bVar4;

  if (DAT_ffff97e9 == '\0') {
    FUN_0000147a(FUN_00014e80, 1, 0);
    do {
    } while (unaff_D2w < 0);
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    uVar3 = *(undefined2 *)(unaff_A5 + 3);
    *(undefined2 *)((int)&comp_pos_x + e) = *(undefined2 *)(unaff_A5 + 1);
    *(undefined2 *)((int)&comp_pos_y + e) = uVar3;
    (&comp_anim_base_offset)[e] = 0x14;
    (&comp_anim_b)[e] = 0x1c;
    ecs_anim_unk_2(e, unaff_A5, 0);
    *(undefined2 *)((int)&comp_state + e) = 0;
    sVar1 = *(short *)((int)&comp_collision_sensor[0].x + e);
    sVar2 = -sVar1;
    if (*unaff_A5 != ANIM_RESET_TICK) {
      (&comp_state_a)[e] = (&comp_state_a)[e] | ENTITY_STATE_A_08;
      sVar2 = sVar1;
    }
    *(short *)((int)&comp_pos_x + e) = sVar2 + *(short *)((int)&comp_pos_x + e);
    index = *(script_state_bit_t *)(unaff_A5 + 5);
    *(script_state_bit_t *)(&DAT_ffffba76 + e) = index;
    bVar4 = script_state_get(index);
    if (!bVar4) {
      *(undefined2 *)((int)&comp_state + e) = 4;
      *(undefined2 *)((int)&comp_anim_tick + e) = 0;
      (&comp_has_func_maybe)[e] = 0;
      ecs_anim_unk_2(e, unaff_A5, 2);
    }
  }
  return;
}

void FUN_00014e80(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x00014e8e. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00014e90 +
             (int)*(short *)((int)&WORD_00014e90 +
                             (int)*(short *)((int)&comp_state + unaff_A4))))();
  return;
}

void FUN_00014e98(void)

{
  int unaff_A4;
  bool bVar1;

  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar1) {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
  }
  return;
}

void FUN_00014eaa(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  *(short *)((int)&comp_anim_tick + unaff_A4) =
      *(short *)((int)&comp_anim_tick + unaff_A4) + -0x10;
  if (*(short *)((int)&comp_anim_tick + unaff_A4) != 0) {
    if (-1 < *(short *)((int)&comp_anim_tick + unaff_A4)) {
      return;
    }
    *(undefined2 *)((int)&comp_anim_tick + unaff_A4) = 0;
  }
  ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
  return;
}

void FUN_00014eca(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar1;

  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (bVar1) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
  }
  return;
}

void FUN_00014ee6(void)

{
  int unaff_A4;

  *(short *)((int)&comp_anim_tick + unaff_A4) =
      *(short *)((int)&comp_anim_tick + unaff_A4) + 0x10;
  if (0xff < *(short *)((int)&comp_anim_tick + unaff_A4)) {
    *(undefined2 *)((int)&comp_anim_tick + unaff_A4) = 0x100;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  }
  return;
}

void FUN_00014f02(void)

{
  short sVar1;
  short sVar2;
  undefined2 uVar3;
  script_state_bit_t index;
  short unaff_D2w;
  entity_id_t e;
  anim_item_t *unaff_A5;
  bool bVar4;

  if (DAT_ffff97e9 == '\0') {
    FUN_0000147a(FUN_00014fa4, 1, 0);
    do {
    } while (unaff_D2w < 0);
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    uVar3 = *(undefined2 *)(unaff_A5 + 3);
    *(undefined2 *)((int)&comp_pos_x + e) = *(undefined2 *)(unaff_A5 + 1);
    *(undefined2 *)((int)&comp_pos_y + e) = uVar3;
    (&comp_anim_base_offset)[e] = 0x14;
    (&comp_anim_b)[e] = 0x1c;
    ecs_anim_unk_2(e, unaff_A5, 0);
    *(undefined2 *)((int)&comp_state + e) = 0;
    sVar1 = *(short *)((int)&comp_collision_sensor[0].x + e);
    sVar2 = -sVar1;
    if (*unaff_A5 != ANIM_RESET_TICK) {
      (&comp_state_a)[e] = (&comp_state_a)[e] | ENTITY_STATE_A_08;
      sVar2 = sVar1;
    }
    *(short *)((int)&comp_pos_x + e) = sVar2 + *(short *)((int)&comp_pos_x + e);
    index = *(script_state_bit_t *)(unaff_A5 + 5);
    *(script_state_bit_t *)(&DAT_ffffba76 + e) = index;
    bVar4 = script_state_get(index);
    if (bVar4) {
      *(undefined2 *)((int)&comp_state + e) = 4;
      *(undefined2 *)((int)&comp_anim_tick + e) = 0;
      (&comp_has_func_maybe)[e] = 0;
      ecs_anim_unk_2(e, unaff_A5, 2);
    }
  }
  return;
}

void FUN_00014fa4(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x00014fb2. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00014fb4 +
             (int)*(short *)((int)&WORD_00014fb4 +
                             (int)*(short *)((int)&comp_state + unaff_A4))))();
  return;
}

void FUN_00014fbc(void)

{
  int unaff_A4;
  bool bVar1;

  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (bVar1) {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
  }
  return;
}

void FUN_00014fce(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  *(short *)((int)&comp_anim_tick + unaff_A4) =
      *(short *)((int)&comp_anim_tick + unaff_A4) + -0x10;
  if (*(short *)((int)&comp_anim_tick + unaff_A4) != 0) {
    if (-1 < *(short *)((int)&comp_anim_tick + unaff_A4)) {
      return;
    }
    *(undefined2 *)((int)&comp_anim_tick + unaff_A4) = 0;
  }
  ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
  return;
}

void FUN_00014fee(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar1;

  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + unaff_A4));
  if (!bVar1) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    *(undefined2 *)((int)&comp_state + unaff_A4) = 6;
  }
  return;
}

void FUN_00015006(void)

{
  int unaff_A4;

  *(short *)((int)&comp_anim_tick + unaff_A4) =
      *(short *)((int)&comp_anim_tick + unaff_A4) + 0x10;
  if (0xff < *(short *)((int)&comp_anim_tick + unaff_A4)) {
    *(undefined2 *)((int)&comp_anim_tick + unaff_A4) = 0x100;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  }
  return;
}

void audio_play_sound_ref_2_also_text_command_fb(sound_id_t *sound_id)

{
  audio_play(*sound_id);
  return;
}

script_t script_seek_if_unowned_e8(script_t script)

{
  script_t script_next;
  bool isnt_owned;

  isnt_owned = item_check_isnt_owned(*script);
  if (isnt_owned) {
    script_next = script + *(short *)(script + 1) + 1;
  } else {
    script_next = script + 3;
  }
  return script_next;
}

script_t script_seek_if_owned_e7(script_t script)

{
  script_t script_next;
  bool isnt_owned;

  isnt_owned = item_check_isnt_owned(*script);
  if (isnt_owned) {
    script_next = script + 3;
  } else {
    script_next = script + *(short *)(script + 1) + 1;
  }
  return script_next;
}

void FUN_00015064(void)

{
  undefined1 uVar1;
  script_state_bit_t index;
  int extraout_A0;
  int extraout_A0_00;
  undefined2 *unaff_A5;
  bool bVar2;

  if (DAT_ffff97e9 == '\0') {
    FUN_0002b58c();
    *(undefined2 *)(&DAT_ffffde74 + extraout_A0) = *unaff_A5;
    *(undefined2 *)(&DAT_ffffde82 + extraout_A0) = unaff_A5[1];
    *(ushort *)(&DAT_ffffde92 + extraout_A0) = (ushort) * (byte *)(unaff_A5 + 2)
                                               << 3;
    *(ushort *)(&DAT_ffffde94 + extraout_A0) =
        (ushort) * (byte *)((int)unaff_A5 + 5) << 3;
    uVar1 = *(undefined1 *)((int)unaff_A5 + 7);
    index = *(script_state_bit_t *)(unaff_A5 + 3);
    *(script_state_bit_t *)(&DAT_ffffdea2 + extraout_A0) = index;
    (&DAT_ffffde73)[extraout_A0] = uVar1;
    bVar2 = script_state_get(index);
    if (!bVar2) {
      (&DAT_ffffde73)[extraout_A0_00] = 6;
    }
  }
  return;
}

void FUN_000150c6(void)

{
  short unaff_D2w;
  entity_id_t e;
  anim_item_t *unaff_A5;

  if (DAT_ffff97e9 == '\0') {
    FUN_0000147a(FUN_0001511e, 1, 0);
    do {
    } while (unaff_D2w < 0);
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    *(undefined2 *)((int)&comp_pos_x + e) = *(undefined2 *)unaff_A5;
    *(undefined2 *)((int)&comp_pos_y + e) = *(undefined2 *)(unaff_A5 + 2);
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x1a;
    (&comp_anim_base_offset)[e] = 0x14;
    (&comp_anim_b)[e] = 0x20;
    ecs_anim_unk_2(e, unaff_A5, 0);
  }
  return;
}

undefined2 FUN_0001511e(void)

{
  undefined2 uVar1;
  entity_id_t unaff_A4;
  undefined1 in_ZF;
  bool bVar2;
  undefined1 in_CF;
  bool bVar3;
  undefined6 uVar4;

  uVar4 = FUN_00000ed6(unaff_A4, ENTITY_ID_ASHA);
  uVar1 = (undefined2)((uint6)uVar4 >> 0x20);
  if ((bool)in_CF || (bool)in_ZF) {
    uVar1 = FUN_00012a9a();
  }
  if (component_state_a_pepelogoo != 0x26) {
    bVar3 = component_state_a_pepelogoo < 0x28;
    bVar2 = component_state_a_pepelogoo == 0x28;
    if (!bVar2) {
      uVar4 = FUN_00000ed6(unaff_A4, ENTITY_ID_PEPELOGOO);
      uVar1 = (undefined2)((uint6)uVar4 >> 0x20);
      if (bVar3 || bVar2) {
        uVar1 = FUN_0002abfa();
      }
    }
  }
  return uVar1;
}

void FUN_00015150(void)

{
  ushort uVar1;
  byte *unaff_A5;

  if ((((pepelogoo_state_b & 0x10) != 0) &&
       (uVar1 = ((ushort)unaff_A5[1] * 0x10 + 0x1000) -
                component_pos_y_pepelogoo._0_2_,
        -1 < (short)uVar1)) &&
      (uVar1 < 0x51)) {
    uVar1 =
        ((ushort)*unaff_A5 * 0x10 + 0x1000) - component_pos_x_pepelogoo._0_2_;
    if ((short)uVar1 < 0) {
      uVar1 = -uVar1;
    }
    if (uVar1 < 0x11) {
      (**(code **)(&DAT_000151a4 + (short)((ushort)unaff_A5[2] << 2)))();
    }
  }
  return;
}

script_t script_e6(script_t script)

{
  DAT_ffffcf8a = 0xff;
  DAT_ffffcf8c = *(undefined2 *)script;
  DAT_ffffcf8e = *(undefined2 *)(script + 2);
  return script + 4;
}

void FUN_000151c2(void)

{
  short unaff_D2w;
  entity_id_t e;
  anim_item_t *unaff_A5;

  if (DAT_ffff97e9 == '\0') {
    FUN_0000147a((func *)0x15234, 1, 0);
    do {
    } while (unaff_D2w < 0);
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    *(undefined2 *)((int)&comp_pos_x + e) = *(undefined2 *)unaff_A5;
    *(undefined2 *)((int)&comp_pos_y + e) = *(undefined2 *)(unaff_A5 + 2);
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x1a;
    (&comp_anim_base_offset)[e] = 8;
    (&comp_anim_b)[e] = 0x1a;
    ecs_anim_unk_2(e, unaff_A5, 0);
    *(short *)((int)&comp_pos_y + e) =
        *(short *)((int)&comp_pos_y + e) -
        *(short *)((int)&comp_collision_sensor[0].y + e);
    *(anim_item_t **)(&comp_unk_9 + e) =
        unaff_A5 + (short)*(undefined2 *)(unaff_A5 + 4) + 4;
  }
  return;
}

void FUN_0001524c(void)

{
  DAT_ffffcc92 = 0xf;
  set_to_13a62_when_facing_a_door = 0;
  return;
}

void FUN_00015258(void)

{
  ushort *unaff_A5;

  if ((DAT_ffff97e9 != '\0') && (*unaff_A5 <= DAT_ffffc73a)) {
    script_state_set_true(*(script_state_bit_t *)(unaff_A5 + 1));
  }
  return;
}

void FUN_0001527e(void)

{
  if (DAT_ffff97e9 != '\0') {
    FUN_000152b8();
    if (((ushort)(DAT_ffffc73a - 0x20U) <=
         (ushort)(comp_collision_sensor[0].x + comp_pos_x.fixed.i)) &&
        ((ushort)comp_pos_y.fixed.i < 0x10e1)) {
      return;
    }
    DAT_ffffcc92 = 1;
    DAT_ffffcc93 = 8;
  }
  return;
}

void FUN_000152b8(void)

{
  int unaff_A4;

  if ((((component_unknown_5 & 4) != 0) &&
       ((&comp_func_offset[0].func_offset_from_15ede)[*(
            short *)((int)&DAT_ffffd29a + (int)(short)component_unknown_9)] ==
        0x26)) &&
      (0x1fff < *(ushort *)((int)&comp_pos_x + unaff_A4))) {
    DAT_ffffcc92 = 1;
    DAT_ffffcc93 = 0xc;
  }
  return;
}

script_t script_e5(script_t script)

{
  short unaff_D2w;
  func *f;
  int unaff_A3;
  entity_id_t e;

  if (DAT_ffff97e9 == '\0') {
    FUN_00015374();
    (&DAT_ffffcefe)[unaff_A3] = 0x80;
    (&DAT_ffffceff)[unaff_A3] = *script;
    *(undefined2 *)(&DAT_ffffcf3e + unaff_A3) = *(undefined2 *)(script + 1);
    *(undefined2 *)(&DAT_ffffcf40 + unaff_A3) = *(undefined2 *)(script + 3);
    *(undefined2 *)(&DAT_ffffcf00 + unaff_A3) = *(undefined2 *)(script + 5);
    *(script_t *)(unaff_A3 + -0x30a2) = script + *(short *)(script + 7) + 7;
    FUN_0000147a(f, 0, 0);
    e = (entity_id_t)unaff_D2w;
    *(short *)(&DAT_ffffcf1e + unaff_A3) = unaff_D2w;
    entity_reset(e);
    *(undefined2 *)((int)&comp_pos_y + e) =
        *(undefined2 *)(&DAT_ffffcf40 + unaff_A3);
    *(undefined2 *)((int)&comp_pos_x + e) =
        *(undefined2 *)(&DAT_ffffcf3e + unaff_A3);
    if ((&DAT_ffffceff)[unaff_A3] != '\0') {
      (&comp_state_a)[e] = (&comp_state_a)[e] | ENTITY_STATE_A_08;
      *(short *)((int)&comp_pos_x + e) = *(short *)(&DAT_ffffcf00 + unaff_A3) +
                                         *(short *)((int)&comp_pos_x + e);
    }
    *(short *)((int)&comp_pos_y + e) = *(short *)((int)&comp_pos_y + e) + 0x20;
    FUN_00015388();
    return script + 9;
  }
  return script + 9;
}

void FUN_0001536e(void)

{
  return;
}

void FUN_00015374(void)

{
  uint uVar1;

  uVar1 = 0;
  do {
    if (-1 < (char)(&DAT_ffffcefe)[uVar1]) {
      return;
    }
    uVar1 = uVar1 + 4;
  } while (uVar1 < 0x20);
  return;
}

/*
Unable to decompile 'FUN_00015388'
Cause:
Low-level Error: Assignment to constant at r0x000163c2
*/

void FUN_000153a2(void)

{
  undefined2 *in_A0;
  ushort *unaff_A2;
  int unaff_A3;
  entity_id_t self;
  anim_item_t *unaff_A5;

  *unaff_A2 = *unaff_A2 | 0x8eb;
  *(undefined2 *)(&DAT_ffffcf20 + unaff_A3) = *in_A0;
  self = (entity_id_t) * (short *)(&DAT_ffffcf1e + unaff_A3);
  (&comp_anim_base_offset)[self] = 0x14;
  (&comp_anim_b)[self] = 0x30;
  ecs_anim_unk_2(self, unaff_A5, 6);
  return;
}

void FUN_000153d0(void)

{
  undefined2 *in_A0;
  int unaff_A3;
  entity_id_t self;
  anim_item_t *unaff_A5;

  (&DAT_ffffcefe)[unaff_A3] = (&DAT_ffffcefe)[unaff_A3] & 0xfe;
  *(undefined2 *)(&DAT_ffffcf20 + unaff_A3) = *in_A0;
  *(undefined2 **)(unaff_A3 + -0x30a2) = in_A0 + 1;
  self = (entity_id_t) * (short *)(&DAT_ffffcf1e + unaff_A3);
  (&comp_anim_base_offset)[self] = 0x14;
  (&comp_anim_b)[self] = 0x30;
  ecs_anim_unk_2(self, unaff_A5, 0);
  return;
}

/*
Unable to decompile 'FUN_000153fc'
Cause:
Low-level Error: Assignment to constant at r0x000163c2
*/

void script_e3(void)

{
  DAT_ffffcc85 = 0xff;
  DAT_ffffcc86 = 0;
  return;
}

void script_e2(void)

{
  DAT_ffffcc85 = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00015422(void)

{
  ushort *unaff_A5;

  if (((unaff_A5[1] ==
        (ushort)(comp_collision_sensor[0].y + comp_pos_y.fixed.i)) &&
       (*unaff_A5 <= (ushort)comp_pos_x.fixed.i)) &&
      ((ushort)comp_pos_x.fixed.i <= (ushort)(unaff_A5[2] + *unaff_A5))) {
    set_to_13a62_when_facing_a_door = FUN_00015466;
    _DAT_ffffcf90 = unaff_A5;
  }
  return;
}

void FUN_00015466(void)

{
  DAT_ffffcc92 = 0x13;
  return;
}

void FUN_0001546e(void)

{
  if (DAT_ffff97e9 == '\0') {
    FUN_0001547e();
  }
  FUN_0001552e();
  return;
}

void FUN_0001547e(void)

{
  entity_id_w_t unaff_D2w;
  func *in_A1;
  func *f;
  entity_id_t e;
  entity_id_t e_00;
  anim_item_t *unaff_A5;
  bool bVar1;

  FUN_0000147a(in_A1, 0, 0);
  e_00 = (entity_id_t)(short)unaff_D2w;
  entity_id_w_t_ffffcf94 = unaff_D2w;
  entity_reset(e_00);
  *(undefined2 *)((int)&comp_unk_3 + e_00) = 0x1a;
  *(undefined2 *)(&DAT_ffffba76 + e_00) = *(undefined2 *)unaff_A5;
  *(undefined2 *)((int)&comp_pos_x + e_00) = *(undefined2 *)(unaff_A5 + 2);
  *(undefined2 *)((int)&comp_pos_y + e_00) = *(undefined2 *)(unaff_A5 + 4);
  (&comp_anim_base_offset)[e_00] = 0x14;
  (&comp_anim_b)[e_00] = 0x36;
  ecs_anim_unk_2(e_00, unaff_A5, 0);
  (&DAT_ffffb976)[e_00] = 0;
  bVar1 = script_state_get(*(script_state_bit_t *)(&DAT_ffffba76 + e_00));
  if (!bVar1) {
    (&DAT_ffffb976)[e_00] = 0xff;
    FUN_0000147a(f, 0, 0);
    e = (entity_id_t)(short)unaff_D2w;
    entity_reset(e);
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x18;
    *(undefined2 *)((int)&comp_pos_x + e) =
        *(undefined2 *)((int)&comp_pos_x + e_00);
    *(undefined2 *)((int)&comp_pos_y + e) =
        *(undefined2 *)((int)&comp_pos_y + e_00);
    *(short *)((int)&comp_pos_x + e) = *(short *)((int)&comp_pos_x + e) + 0x18;
    *(short *)((int)&comp_pos_y + e) = *(short *)((int)&comp_pos_y + e) + -0x53;
    *(entity_id_w_t *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + e_00) =
        unaff_D2w;
    (&comp_anim_base_offset)[e] = 0x14;
    (&comp_anim_b)[e] = 0x34;
    ecs_anim_unk_2(e, unaff_A5, 0);
  }
  return;
}

void FUN_0001552e(void)

{
  short sVar1;

  sVar1 = *(short *)((int)&comp_pos_x + (int)(short)entity_id_w_t_ffffcf94);
  if ((((int16_t)(comp_collision_sensor[0].y + comp_pos_y.fixed.i) ==
        *(short *)((int)&comp_pos_y + (int)(short)entity_id_w_t_ffffcf94)) &&
       ((ushort)(sVar1 - 0x20U) <= (ushort)comp_pos_x.fixed.i)) &&
      ((ushort)comp_pos_x.fixed.i <= (ushort)(sVar1 + 0x20U))) {
    set_to_13a62_when_facing_a_door = FUN_00015568;
  }
  return;
}

void FUN_00015568(void)

{
  DAT_ffffcc92 = 0x14;
  return;
}

void FUN_00015570(void)

{
  undefined2 uVar1;
  undefined2 uVar2;
  short unaff_D2w;
  func *in_A1;
  entity_id_t e;
  anim_item_t *unaff_A5;

  if (((DAT_ffff97e9 == '\0') && (2 < script_ctx_bf_0e_arg)) &&
      (script_ctx_bf_0e_arg < 5)) {
    FUN_0000147a(in_A1, 0, 0);
    e = (entity_id_t)unaff_D2w;
    DAT_ffffcf96 = unaff_D2w;
    entity_reset(e);
    uVar1 = *(undefined2 *)unaff_A5;
    uVar2 = *(undefined2 *)(unaff_A5 + 2);
    (&comp_state_a)[e] = 0x88;
    *(undefined2 *)((int)&comp_pos_x + e) = uVar1;
    *(undefined2 *)((int)&comp_pos_y + e) = uVar2;
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x14;
    (&comp_anim_base_offset)[e] = 0x14;
    (&comp_anim_b)[e] = 0x3e;
    if (script_ctx_bf_0e_arg == 4) {
      (&comp_anim_b)[e] = 0x40;
    }
    ecs_anim_unk_2(e, unaff_A5, 0);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000155e4(void)

{
  ushort uVar1;
  short unaff_D2w;
  func *f;
  entity_id_t e;
  anim_item_t *unaff_A5;
  bool bVar2;

  if (DAT_ffff97e9 == '\0') {
    bVar2 = script_state_get(*(script_state_bit_t *)(unaff_A5 + 4));
    if (bVar2) {
      FUN_0000147a(f, 10, 0);
      e = (entity_id_t)unaff_D2w;
      entity_reset(e);
      *(undefined2 *)(&DAT_ffffba76 + e) = *(undefined2 *)(unaff_A5 + 4);
      *(undefined2 *)((int)&comp_pos_x + e) = *(undefined2 *)unaff_A5;
      *(undefined2 *)((int)&comp_pos_y + e) = *(undefined2 *)(unaff_A5 + 2);
      (&comp_anim_base_offset)[e] = 0x14;
      (&comp_anim_b)[e] = 0x4a;
      *(undefined2 *)((int)&comp_unk_3 + e) = 0x1e;
      (&comp_state_a)[e] = 0;
      ecs_anim_unk_2(e, unaff_A5, 0);
    }
  } else if (*(undefined2 *)(unaff_A5 + 2) ==
             (int16_t)(comp_collision_sensor[0].y + comp_pos_y.fixed.i)) {
    uVar1 = *(undefined2 *)unaff_A5 - comp_pos_x._0_2_;
    if ((short)uVar1 < 0) {
      uVar1 = -uVar1;
    }
    if (uVar1 < 0x21) {
      DAT_ffffcf7e = 0x20;
      DAT_ffffcf7f = 0;
      _DAT_ffffcf80 = *(undefined2 *)unaff_A5;
      _DAT_ffffcf82 = *(undefined2 *)(unaff_A5 + 2);
    }
  }
  return;
}

script_t script_e1(script_t script)

{
  script_t pcVar1;

  pcVar1 = audio_play_sound_ref_3(script);
  return pcVar1;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000156b2(void)

{
  byte bVar1;
  short i;
  int iVar2;
  byte *pbVar3;
  byte *pbVar4;

  iVar2 = 0x34;
  i = 0x13;
  do {
    (&comp_has_func_maybe)[iVar2] = 0;
    iVar2 = iVar2 + 4;
    i = i + -1;
  } while (i != -1);
  iVar2 = 0;
  i = 0xf;
  do {
    (&DAT_ffffcf9c)[iVar2] = 0;
    iVar2 = iVar2 + 4;
    i = i + -1;
  } while (i != -1);
  DAT_ffffcf9a = 0;
  pbVar3 = _DAT_ffffd11c;
  while (*pbVar3 != 0xff) {
    FUN_000156f4();
    pbVar3 = pbVar3 + 1;
  }
  _DAT_ffffd166 = 0xffff;
  DAT_ffffd16a = 0;
  DAT_ffffd16b = 0;
  iVar2 = 0;
  pbVar3 = pbVar3 + 1;
  while (true) {
    while (true) {
      pbVar4 = pbVar3 + 1;
      bVar1 = *pbVar3;
      if ((char)bVar1 < '\0')
        break;
      (&DAT_ffffcf9e)[iVar2] = 1;
      (&DAT_ffffcf9f)[iVar2] = 0;
      (&DAT_ffffcf9d)[iVar2] = bVar1;
      (*(FUN_0001580c + *(short *)(FUN_0001580c + (short)(ushort)bVar1)))();
      _DAT_ffffd166 = 0xffff;
      DAT_ffffd16a = 0;
      DAT_ffffd16b = 0;
      iVar2 = iVar2 + 4;
      pbVar3 = pbVar4;
    }
    if (bVar1 == 0xff)
      break;
    if (bVar1 < 0xc0) {
      if (bVar1 == 0x80) {
        _DAT_ffffd166 = *(undefined2 *)pbVar4;
        pbVar3 = pbVar3 + 3;
      } else if (bVar1 == 0x81) {
        DAT_ffffd16a = 0xff;
        pbVar3 = pbVar4;
      } else {
        DAT_ffffd16b = 0xff;
        pbVar3 = pbVar4;
      }
    } else {
      (*(code *)((int)&jmp_text_command_ff_to_e1 +
                 (int)*(short *)((int)&jmp_text_command_ff_to_e1 +
                                 (int)(short)((ushort)(byte)~bVar1 * 2))))();
      pbVar3 = pbVar4;
    }
  }
  return;
}

void FUN_000156f2(void)

{
  return;
}

void FUN_000156f4(void)

{
  short sVar1;
  short sVar2;
  short sVar3;
  short sVar4;
  short in_D0w;
  short sVar5;
  ushort uVar6;
  ushort uVar7;
  ushort uVar8;
  short sVar9;
  ushort unaff_D7w;
  short *psVar10;
  short *psVar11;
  ushort *puVar12;
  ushort *puVar13;
  short *unaff_A4;
  int unaff_A5;

  sVar1 = *(short *)(&DAT_0007d642 + (short)(in_D0w << 3));
  if (sVar1 == 0) {
    return;
  }
  puVar13 = (ushort *)(&DAT_0007d63c + sVar1);
  sVar4 = (0x30 - unaff_D7w) * 2;
  uVar8 = *puVar13;
  if (uVar8 < unaff_D7w) {
    sVar5 = unaff_D7w - uVar8;
    sVar9 = sVar4;
    do {
      psVar10 = (short *)((int)compressed_data_indices + (int)sVar9);
      psVar11 = (short *)(&DAT_0007d63e + sVar1);
      uVar6 = uVar8;
      do {
        sVar2 = *psVar10;
        psVar10 = psVar10 + 1;
        sVar3 = *psVar11;
        psVar11 = psVar11 + 1;
        if (sVar3 != sVar2)
          break;
        uVar6 = uVar6 - 1;
      } while (uVar6 != 0xffff);
      if (sVar3 == sVar2)
        goto LAB_00015778;
      sVar9 = sVar9 + 2;
      sVar5 = sVar5 + -1;
    } while (sVar5 != 0);
  }
  uVar6 = 0;
  sVar9 = (uVar8 + 1) - unaff_D7w;
  if (unaff_D7w <= (ushort)(uVar8 + 1) && sVar9 != 0) {
    sVar9 = sVar9 + -1;
    uVar6 = sVar9 * 2;
    uVar8 = uVar8 - sVar9;
  }
  do {
    uVar6 = uVar6 + 2;
    uVar8 = uVar8 - 1;
    if (uVar8 == 0xffff)
      break;
    psVar10 = (short *)(&DAT_0007d63e + (int)(short)uVar6 + (int)sVar1);
    psVar11 = (short *)((int)compressed_data_indices + (int)sVar4);
    uVar7 = uVar8;
    do {
      sVar9 = *psVar10;
      psVar10 = psVar10 + 1;
      sVar5 = *psVar11;
      psVar11 = psVar11 + 1;
      if (sVar5 != sVar9)
        break;
      uVar7 = uVar7 - 1;
    } while (uVar7 != 0xffff);
  } while (sVar5 != sVar9);
  sVar9 = sVar4 - uVar6;
  uVar6 = uVar6 >> 1;
  puVar12 = (ushort *)((int)compressed_data_indices + (int)sVar9);
  do {
    puVar13 = puVar13 + 1;
    *puVar12 = *puVar13;
    uVar6 = uVar6 - 1;
    puVar12 = puVar12 + 1;
  } while (uVar6 != 0);
LAB_00015778:
  *unaff_A4 = sVar9 << 4;
  *(undefined1 *)(unaff_A4 + 1) = *(undefined1 *)(unaff_A5 + -1);
  DAT_ffffcf9a = DAT_ffffcf9a + 1;
  return;
}

void FUN_0001580c(void)

{
  uint *unaff_A2;
  byte *unaff_A4;
  byte *unaff_A5;

  *unaff_A4 = *unaff_A4 | 0x26;
  *unaff_A2 = *unaff_A2 | 0xa800de;
  FUN_00015832();
  unaff_A4[-0x2fa3] = *unaff_A5;
  *(undefined2 *)(unaff_A4 + -0x2fe2) = *(undefined2 *)(unaff_A5 + 1);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00015832(void)

{
  int unaff_A4;
  undefined1 *unaff_A5;

  (&DAT_ffffcf9c)[unaff_A4] = 0x80;
  *(undefined2 *)(&DAT_ffffd01c + unaff_A4) = _DAT_ffffd166;
  if (DAT_ffffd16a != '\0') {
    (&DAT_ffffcf9c)[unaff_A4] = (&DAT_ffffcf9c)[unaff_A4] | 2;
  }
  if (DAT_ffffd16b != '\0') {
    (&DAT_ffffcf9c)[unaff_A4] = (&DAT_ffffcf9c)[unaff_A4] | 4;
  }
  (&DAT_ffffd05c)[unaff_A4] = *unaff_A5;
  *(ushort *)(&DAT_ffffcfdc + unaff_A4) =
      (ushort)(byte)unaff_A5[1] * 0x10 + 0x1000;
  *(ushort *)(&DAT_ffffcfde + unaff_A4) =
      (ushort)(byte)unaff_A5[2] * 0x10 + 0x1000;
  return;
}

void FUN_0001585a(void)

{
  int unaff_A4;
  byte *unaff_A5;

  *(ushort *)(&DAT_ffffcfdc + unaff_A4) = (ushort)*unaff_A5 * 0x10 + 0x1000;
  *(ushort *)(&DAT_ffffcfde + unaff_A4) = (ushort)unaff_A5[1] * 0x10 + 0x1000;
  return;
}

void FUN_00015878(void)

{
  int unaff_A4;
  undefined1 *unaff_A5;

  (&DAT_ffffcf9c)[unaff_A4] = 0x81;
  (&DAT_ffffd05d)[unaff_A4] = *unaff_A5;
  *(ushort *)(&DAT_ffffd05e + unaff_A4) = (ushort)(byte)unaff_A5[1];
  (&DAT_ffffcf9e)[unaff_A4] = unaff_A5[2];
  *(undefined1 **)(&DAT_ffffd0dc + unaff_A4) =
      unaff_A5 + *(short *)(unaff_A5 + 3) + 3;
  return;
}

void FUN_0001589e(void)

{
  int unaff_A4;
  undefined1 *unaff_A5;

  (&DAT_ffffcf9c)[unaff_A4] = 0x81;
  FUN_0001585a();
  (&DAT_ffffcf9e)[unaff_A4] = *unaff_A5;
  *(undefined2 *)(&DAT_ffffd05e + unaff_A4) = 0x1e;
  return;
}

void FUN_000158b4(void)

{
  char cVar1;
  int unaff_A4;
  char *unaff_A5;

  (&DAT_ffffcf9c)[unaff_A4] = 0x81;
  cVar1 = *unaff_A5;
  if ((cVar1 == '8') && (0xe < blue_hearts)) {
    cVar1 = '6';
  }
  (&DAT_ffffd05c)[unaff_A4] = cVar1;
  (&DAT_ffffcfdc)[unaff_A4] = unaff_A5[1];
  *(char *)(unaff_A4 + -0x3023) = unaff_A5[2];
  (&DAT_ffffcfde)[unaff_A4] = unaff_A5[3];
  *(char *)(unaff_A4 + -0x3021) = unaff_A5[4];
  (&DAT_ffffd01c)[unaff_A4] = unaff_A5[5];
  *(char *)(unaff_A4 + -0x2fe3) = unaff_A5[6];
  return;
}

void FUN_000158ea(void)

{
  int unaff_A4;
  undefined1 *unaff_A5;

  (&DAT_ffffcf9c)[unaff_A4] = 0x81;
  (&DAT_ffffd01c)[unaff_A4] = *unaff_A5;
  *(undefined1 *)(unaff_A4 + -0x2fe3) = unaff_A5[1];
  *(undefined1 **)(&DAT_ffffd0dc + unaff_A4) =
      unaff_A5 + *(short *)(unaff_A5 + 2) + 2;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00015908(void)

{
  int unaff_A4;
  undefined1 *unaff_A5;

  (&DAT_ffffcf9c)[unaff_A4] = 0x80;
  *(undefined2 *)(&DAT_ffffd01c + unaff_A4) = _DAT_ffffd166;
  if (DAT_ffffd16a != '\0') {
    (&DAT_ffffcf9c)[unaff_A4] = (&DAT_ffffcf9c)[unaff_A4] | 2;
  }
  (&DAT_ffffd05c)[unaff_A4] = *unaff_A5;
  (&DAT_ffffcfdc)[unaff_A4] = unaff_A5[1];
  *(undefined1 *)(unaff_A4 + -0x3023) = unaff_A5[2];
  (&DAT_ffffcfde)[unaff_A4] = unaff_A5[3];
  *(undefined1 *)(unaff_A4 + -0x3021) = unaff_A5[4];
  *(undefined1 **)(&DAT_ffffd0dc + unaff_A4) =
      unaff_A5 + *(short *)(unaff_A5 + 5) + 5;
  return;
}

void FUN_00015944(void)

{
  int unaff_A4;
  short *unaff_A5;

  (&DAT_ffffcf9c)[unaff_A4] = 0x81;
  *(int *)(&DAT_ffffd0dc + unaff_A4) = (int)unaff_A5 + (int)*unaff_A5;
  return;
}

void ecs_called_before_run_entity_func_all(void)

{
  uint uVar1;

  uVar1 = 0;
  do {
    if (((char)(&DAT_ffffcf9c)[uVar1] < '\0') &&
        ((((&DAT_ffffcf9c)[uVar1] & 1) != 0 ||
          ((byte)(&DAT_ffffcf9f)[uVar1] < (byte)(&DAT_ffffcf9e)[uVar1])))) {
      (*(code *)((int)&WORD_0001598e +
                 (int)*(short *)((int)&WORD_0001598e +
                                 (int)(short)(ushort)(byte)(&DAT_ffffcf9d)
                                     [uVar1])))();
    }
    uVar1 = uVar1 + 4;
  } while (uVar1 < 0x40);
  return;
}

void FUN_000159a2(void)

{
  return;
}

void FUN_000159be(void)

{
  FUN_000159a2();
  return;
}

void FUN_000159c0(void)

{
  FUN_000159a2();
  return;
}

void FUN_000159ec(void)

{
  FUN_000159c0();
  return;
}

void FUN_000159f2(void)

{
  FUN_000159a2();
  return;
}

void FUN_000159fc(void)

{
  int unaff_A4;
  undefined1 in_NF;

  FUN_000159f2();
  if ((bool)in_NF) {
    FUN_000159ec();
    if ((bool)in_NF) {
      (&DAT_ffffcf9f)[*(short *)((int)&comp_unk_8 + unaff_A4)] =
          (&DAT_ffffcf9f)[*(short *)((int)&comp_unk_8 + unaff_A4)] + -1;
      (&comp_has_func_maybe)[unaff_A4] = 0;
    }
  }
  return;
}

void FUN_00015a1a(void)

{
  entity_id_t e;
  int unaff_A3;
  bool bVar1;

  if (((&DAT_ffffcf9c)[unaff_A3] & 2) == 0) {
    bVar1 = *(short *)(&DAT_ffffcfdc + unaff_A3) < 0;
    FUN_000159be();
    if (bVar1) {
      return;
    }
  }
  bVar1 = (char)(&DAT_ffffd05c)[unaff_A3] < '\0';
  e = FUN_00001a22();
  if (bVar1) {
    return;
  }
  (&DAT_ffffcf9f)[unaff_A3] = (&DAT_ffffcf9f)[unaff_A3] + '\x01';
  entity_reset(e);
  *(undefined2 *)((int)&comp_pos_x + e) =
      *(undefined2 *)(&DAT_ffffcfdc + unaff_A3);
  *(undefined2 *)((int)&comp_pos_y + e) =
      *(undefined2 *)(&DAT_ffffcfde + unaff_A3);
  (&comp_has_func_maybe)[e] = 0x80;
  (&comp_func_offset[0].unk1)[e] = (&DAT_ffffd05c)[unaff_A3];
  *(short *)((int)&comp_unk_8 + e) = (short)unaff_A3;
  FUN_000019ae();
  return;
}

void FUN_00015a62(void)

{
  char cVar1;
  short sVar2;
  char *pcVar3;
  int unaff_A3;
  entity_id_t e;
  bool bVar4;

  sVar2 = *(short *)(&DAT_ffffd05e + unaff_A3) + -1;
  *(short *)(&DAT_ffffd05e + unaff_A3) = sVar2;
  if (sVar2 == 0) {
    pcVar3 = *(char **)(&DAT_ffffd0dc + unaff_A3);
    while (true) {
      cVar1 = *pcVar3;
      (&DAT_ffffd05f)[unaff_A3] = cVar1;
      if (cVar1 != '\0')
        break;
      pcVar3 = pcVar3 + *(short *)(pcVar3 + 1) + 1;
    }
    *(char **)(&DAT_ffffd0dc + unaff_A3) = pcVar3 + 5;
    if ((byte)(&DAT_ffffcf9f)[unaff_A3] < (byte)(&DAT_ffffcf9e)[unaff_A3]) {
      (&DAT_ffffd05c)[unaff_A3] = pcVar3[1];
      (&DAT_ffffd09c)[unaff_A3] = pcVar3[2];
      *(ushort *)(&DAT_ffffcfdc + unaff_A3) =
          (ushort)(byte)pcVar3[3] * 0x10 + 0x1000;
      *(ushort *)(&DAT_ffffcfde + unaff_A3) =
          (ushort)(byte)pcVar3[4] * 0x10 + 0x1000;
      bVar4 =
          *(short *)((int)&WORD_00015b06 +
                     (int)(short)(ushort)(byte)(&DAT_ffffd05d)[unaff_A3]) < 0;
      (*(code *)((int)&WORD_00015b06 +
                 (int)*(short *)((int)&WORD_00015b06 +
                                 (int)(short)(ushort)(byte)(&DAT_ffffd05d)
                                     [unaff_A3])))();
      if (!bVar4) {
        bVar4 = (char)(&DAT_ffffd05c)[unaff_A3] < '\0';
        sVar2 = FUN_00001a22();
        if (!bVar4) {
          (&DAT_ffffcf9f)[unaff_A3] = (&DAT_ffffcf9f)[unaff_A3] + '\x01';
          e = (entity_id_t)sVar2;
          entity_reset(e);
          *(undefined2 *)((int)&comp_pos_x + e) =
              *(undefined2 *)(&DAT_ffffcfdc + unaff_A3);
          *(undefined2 *)((int)&comp_pos_y + e) =
              *(undefined2 *)(&DAT_ffffcfde + unaff_A3);
          (&comp_has_func_maybe)[e] = 0x80;
          (&comp_func_offset[0].unk1)[e] = (&DAT_ffffd05c)[unaff_A3];
          (&comp_unk_4)[e] = (&DAT_ffffd09c)[unaff_A3];
          *(short *)((int)&comp_unk_8 + e) = (short)unaff_A3;
          FUN_000019ae();
          return;
        }
      }
    }
  }
  return;
}

undefined4 FUN_00015b0c(void)

{
  undefined4 uVar1;
  int unaff_A3;
  undefined1 in_NF;

  uVar1 = FUN_00015b2c();
  if (!(bool)in_NF) {
    if ((DAT_ffffc73a <=
         (ushort)(*(short *)(&DAT_ffffcfdc + unaff_A3) + 0x40U)) &&
        ((ushort)((*(short *)(&DAT_ffffcfdc + unaff_A3) + 0x40U) -
                  DAT_ffffc73a) < 0x180)) {
      return 0;
    }
    uVar1 = 0xffffffff;
  }
  return uVar1;
}

undefined4 FUN_00015b10(void)

{
  int unaff_A3;

  if ((DAT_ffffc73a <=
       (ushort)(*(short *)(&DAT_ffffcfdc + unaff_A3) + 0x40U)) &&
      ((ushort)((*(short *)(&DAT_ffffcfdc + unaff_A3) + 0x40U) - DAT_ffffc73a) <
       0x180)) {
    return 0;
  }
  return 0xffffffff;
}

undefined4 FUN_00015b2c(void)

{
  int unaff_A3;

  if ((DAT_ffffc746 <=
       (ushort)(*(short *)(&DAT_ffffcfde + unaff_A3) + 0x20U)) &&
      ((ushort)((*(short *)(&DAT_ffffcfde + unaff_A3) + 0x20U) - DAT_ffffc746) <
       0x140)) {
    return 0;
  }
  return 0xffffffff;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00015b44(void)

{
  uint uVar1;
  short sVar2;
  word wVar3;
  byte bVar5;
  short sVar4;
  undefined2 *puVar6;
  int unaff_A3;
  entity_id_t e;
  bool bVar7;

  if (((*(short *)(&DAT_ffffd05e + unaff_A3) == 0) ||
       (sVar4 = *(short *)(&DAT_ffffd05e + unaff_A3) + -1,
        *(short *)(&DAT_ffffd05e + unaff_A3) = sVar4,
        sVar4 == 0)) &&
      ((byte)(&DAT_ffffcf9f)[unaff_A3] < (byte)(&DAT_ffffcf9e)[unaff_A3])) {
    uVar1 = FUN_00001770();
    if ((uVar1 & 2) != 0) {
      sVar4 = *(short *)(&DAT_ffffcfdc + unaff_A3);
      sVar2 = comp_pos_x.fixed.i + 8;
      if ((comp_state_a & ENTITY_STATE_A_08) != 0) {
        sVar2 = comp_pos_x.fixed.i + -8;
      }
      if ((ushort)((sVar2 - (sVar4 + 8U)) + 4) < 8) {
        *(undefined2 *)(&DAT_ffffd05e + unaff_A3) = 0x5a;
        wVar3 = rand();
        bVar5 = (byte)wVar3 >> 1;
        if (((wVar3 & 1) != 0) &&
            (bVar5 = 0, (ushort)(sVar4 + 8U) < (ushort)comp_pos_x.fixed.i)) {
          bVar5 = 1;
        }
        _DAT_ffffd168 = sVar4 + -8;
        if ((bVar5 & 1) != 0) {
          _DAT_ffffd168 = sVar4 + 0x18;
        }
        bVar7 = (char)(&DAT_ffffd05c)[unaff_A3] < '\0';
        sVar4 = FUN_00001a22();
        if (!bVar7) {
          (&DAT_ffffcf9f)[unaff_A3] = (&DAT_ffffcf9f)[unaff_A3] + '\x01';
          e = (entity_id_t)sVar4;
          entity_reset(e);
          *(short *)((int)&comp_pos_x + e) = _DAT_ffffd168;
          *(short *)((int)&comp_pos_y + e) = DAT_ffffc746 + -0x20;
          (&comp_has_func_maybe)[e] = 0x80;
          (&comp_func_offset[0].unk1)[e] = 0x2e;
          *(short *)((int)&comp_unk_8 + e) = (short)unaff_A3;
          *(undefined2 *)(&DAT_ffffbc76 + e) =
              *(undefined2 *)((int)&comp_pos_x + e);
          *(undefined2 *)(&DAT_ffffbc78 + e) =
              *(undefined2 *)((int)&comp_pos_y + e);
          sVar4 = (ushort)(&comp_func_offset[0].unk1)[e] << 3;
          (&comp_func_offset[0].func_offset_from_15ede)[e] =
              (&DAT_0007d63c)[sVar4];
          (&comp_func_offset[0].unk3)[e] = (&DAT_0007d63d)[sVar4];
          *(undefined2 *)(&comp_anim_base_offset + e) =
              *(undefined2 *)(&DAT_0007d63e + sVar4);
          if (((&DAT_0007d640)[sVar4] & 4) != 0) {
            (&comp_anim[0].unk4)[e] = (&comp_anim[0].unk4)[e] | 0x80;
          }
          *(undefined2 *)((int)&comp_unk_7 + e) = 0;
          if (*(short *)(&DAT_0007d642 + sVar4) != 0) {
            puVar6 = (undefined2 *)&DAT_ffffd126;
            sVar4 = DAT_ffffcf9a;
            while ((&comp_func_offset[0].unk1)[e] != *(byte *)(puVar6 + 1)) {
              puVar6 = puVar6 + 2;
              sVar4 = sVar4 + -1;
              if (sVar4 == 0) {
                do {
                  // WARNING: Do nothing block with infinite loop
                } while (true);
              }
            }
            *(undefined2 *)((int)&comp_unk_7 + e) = *puVar6;
            (&comp_has_func_maybe)[e] = (&comp_has_func_maybe)[e] | 0x20;
          }
          return;
        }
      }
    }
  }
  return;
}

void FUN_00015bf2(void)

{
  byte bVar1;
  entity_state_a_t eVar2;
  byte extraout_D1b;
  short unaff_D2w;
  int unaff_A3;
  entity_id_t e;
  anim_item_t *unaff_A5;
  bool bVar3;

  if (((short)*(script_state_bit_t *)(&DAT_ffffd01c + unaff_A3) < 0) ||
      (bVar3 =
           script_state_get(*(script_state_bit_t *)(&DAT_ffffd01c + unaff_A3)),
       bVar3)) {
    FUN_0000147a(FUN_00015c68, 1, 0);
    if (unaff_D2w < 0) {
      return;
    }
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    (&comp_has_func_maybe)[e] = 0x80;
    *(undefined2 *)(&comp_unk_4 + e) =
        *(undefined2 *)(&DAT_ffffd01c + unaff_A3);
    bVar1 = (&DAT_ffffd05c)[unaff_A3];
    (&comp_collision_related)[e] = bVar1;
    (&comp_collected_item_id_maybe)[e] = bVar1;
    *(undefined2 *)((int)&comp_pos_x + e) =
        *(undefined2 *)(&DAT_ffffcfdc + unaff_A3);
    *(undefined2 *)((int)&comp_pos_y + e) =
        *(undefined2 *)(&DAT_ffffcfde + unaff_A3);
    FUN_00024da0();
    (&comp_func_offset[0].unk1)[e] = extraout_D1b;
    FUN_000019ae();
    *(undefined2 *)((int)&comp_unk_3 + e) = 4;
    eVar2 = 0;
    if (DAT_ffffcc28 != '\0') {
      eVar2 = 0x80;
    }
    (&comp_state_a)[e] = eVar2;
    ecs_anim_unk_2(e, unaff_A5, 0);
  }
  (&DAT_ffffcf9c)[unaff_A3] = 0;
  return;
}

undefined2 FUN_00015c68(void)

{
  sound_id_t sound_id;
  undefined2 uVar1;
  entity_id_t unaff_A4;
  undefined1 in_ZF;
  undefined1 in_CF;
  undefined6 uVar2;

  uVar2 = FUN_00000ed6(unaff_A4, ENTITY_ID_ASHA);
  if ((bool)in_CF || (bool)in_ZF) {
    if (-1 < (short)*(script_state_bit_t *)(&comp_unk_4 + unaff_A4)) {
      script_state_set_true(*(script_state_bit_t *)(&comp_unk_4 + unaff_A4));
    }
    sound_id = SOUND_ID_GET_MEAT;
    if (((&comp_collected_item_id_maybe)[unaff_A4] != 0x36) &&
        ((&comp_collected_item_id_maybe)[unaff_A4] != 0x37)) {
      sound_id = SOUND_ID_ITEM_GET;
    }
    audio_play(sound_id);
    FUN_0000185e();
    (&comp_has_func_maybe)[unaff_A4] = 0;
    uVar1 = FUN_00029824();
    return uVar1;
  }
  return (short)((uint6)uVar2 >> 0x20);
}

void FUN_00015c86(void)

{
  short sVar1;
  undefined1 *extraout_A1;
  char *pcVar2;
  int unaff_A3;
  entity_id_t e;
  bool bVar3;

  bVar3 = script_state_get(*(script_state_bit_t *)(&DAT_ffffd01c + unaff_A3));
  if (!bVar3) {
    script_state_set_false(*(script_state_bit_t *)(&DAT_ffffd01c + unaff_A3));
    pcVar2 = *(char **)(&DAT_ffffd0dc + unaff_A3);
    while (-1 < *pcVar2) {
      sVar1 = ecs_find_some_entity_with_func();
      if (sVar1 < 0) {
        return;
      }
      e = (entity_id_t)sVar1;
      entity_reset(e);
      (&comp_has_func_maybe)[e] = 0x80;
      (&comp_func_offset[0].unk1)[e] = 9;
      (&comp_collision_related)[e] = *extraout_A1;
      *(ushort *)(&comp_unk_4 + e) = (ushort)(byte)extraout_A1[1];
      (&DAT_ffffbe78)[e] = extraout_A1[2];
      *(undefined1 *)(e - 0x4187) = extraout_A1[3];
      *(ushort *)(&comp_unk_1 + e) = (ushort)(byte)extraout_A1[4] << 4;
      FUN_000019ae();
      pcVar2 = extraout_A1 + 5;
    }
  }
  return;
}

void FUN_00015ce6(void)

{
  short sVar1;
  undefined2 *puVar2;
  int unaff_A3;
  entity_id_t e;

  sVar1 = ecs_find_some_entity_with_func();
  if (sVar1 < 0) {
    return;
  }
  e = (entity_id_t)sVar1;
  entity_reset(e);
  *(undefined2 *)((int)&comp_pos_x + e) =
      *(undefined2 *)(&DAT_ffffcfdc + unaff_A3);
  *(undefined2 *)((int)&comp_pos_y + e) =
      *(undefined2 *)(&DAT_ffffcfde + unaff_A3);
  (&comp_has_func_maybe)[e] = 0x80;
  (&comp_func_offset[0].unk1)[e] = (&DAT_ffffd05c)[unaff_A3];
  *(undefined4 *)(&comp_unk_9 + e) = *(undefined4 *)(&DAT_ffffd0dc + unaff_A3);
  (&DAT_ffffcf9c)[unaff_A3] = 0;
  *(undefined2 *)(&DAT_ffffbc76 + e) = *(undefined2 *)((int)&comp_pos_x + e);
  *(undefined2 *)(&DAT_ffffbc78 + e) = *(undefined2 *)((int)&comp_pos_y + e);
  sVar1 = (ushort)(&comp_func_offset[0].unk1)[e] << 3;
  (&comp_func_offset[0].func_offset_from_15ede)[e] = (&DAT_0007d63c)[sVar1];
  (&comp_func_offset[0].unk3)[e] = (&DAT_0007d63d)[sVar1];
  *(undefined2 *)(&comp_anim_base_offset + e) =
      *(undefined2 *)(&DAT_0007d63e + sVar1);
  if (((&DAT_0007d640)[sVar1] & 4) != 0) {
    (&comp_anim[0].unk4)[e] = (&comp_anim[0].unk4)[e] | 0x80;
  }
  *(undefined2 *)((int)&comp_unk_7 + e) = 0;
  if (*(short *)(&DAT_0007d642 + sVar1) != 0) {
    puVar2 = (undefined2 *)&DAT_ffffd126;
    sVar1 = DAT_ffffcf9a;
    while ((&comp_func_offset[0].unk1)[e] != *(byte *)(puVar2 + 1)) {
      puVar2 = puVar2 + 2;
      sVar1 = sVar1 + -1;
      if (sVar1 == 0) {
        do {
          // WARNING: Do nothing block with infinite loop
        } while (true);
      }
    }
    *(undefined2 *)((int)&comp_unk_7 + e) = *puVar2;
    (&comp_has_func_maybe)[e] = (&comp_has_func_maybe)[e] | 0x20;
  }
  return;
}

void FUN_00015d1c(void)

{
  script_state_bit_t *psVar1;
  int iVar2;
  byte extraout_D1b;
  short unaff_D2w;
  byte bVar3;
  int unaff_A3;
  entity_id_t e;
  bool bVar4;

  do {
    psVar1 = *(script_state_bit_t **)(&DAT_ffffd0dc + unaff_A3);
    if (((short)*psVar1 < 0) || (bVar4 = script_state_get(*psVar1), bVar4)) {
      if ((ushort)(DAT_ffffc73a + 0x120) < (ushort)psVar1[1]) {
        return;
      }
      FUN_0000147a(FUN_00015db6, 1, 0);
      if (unaff_D2w < 0) {
        return;
      }
      e = (entity_id_t)unaff_D2w;
      entity_reset(e);
      (&comp_has_func_maybe)[e] = 0x80;
      *(script_state_bit_t *)(&comp_unk_4 + e) = *psVar1;
      *(script_state_bit_t *)((int)&comp_pos_x + e) = psVar1[1];
      *(script_state_bit_t *)((int)&comp_pos_y + e) = psVar1[2];
      bVar3 = *(byte *)(psVar1 + 3);
      if ((bVar3 == 0x38) && (0xe < blue_hearts)) {
        bVar3 = 0x36;
      }
      (&comp_collision_related)[e] = bVar3;
      (&comp_collected_item_id_maybe)[e] = bVar3;
      FUN_00024da0();
      (&comp_func_offset[0].unk1)[e] = extraout_D1b;
      FUN_000019ae();
      *(undefined2 *)((int)&comp_unk_3 + e) = 4;
      (&comp_state_a)[e] = 0x80;
      ecs_anim_unk_2(e, &psVar1[3].field_0x1, 0);
    }
    iVar2 = *(int *)(&DAT_ffffd0dc + unaff_A3);
    *(short **)(&DAT_ffffd0dc + unaff_A3) = (short *)(iVar2 + 8);
    if (*(short *)(iVar2 + 8) == -0x8000) {
      (&DAT_ffffcf9c)[unaff_A3] = 0;
      return;
    }
  } while (true);
}

ushort FUN_00015db6(void)

{
  sound_id_t sound_id;
  ushort uVar1;
  entity_id_t unaff_A4;
  bool bVar2;
  bool bVar3;
  undefined6 uVar4;

  uVar1 = DAT_ffffc73a - 0x20;
  bVar3 = uVar1 < *(ushort *)((int)&comp_pos_x + unaff_A4);
  bVar2 = uVar1 == *(ushort *)((int)&comp_pos_x + unaff_A4);
  if (bVar3) {
    uVar4 = FUN_00000ed6(unaff_A4, ENTITY_ID_ASHA);
    uVar1 = (ushort)((uint6)uVar4 >> 0x20);
    if (bVar3 || bVar2) {
      if (-1 < (short)*(script_state_bit_t *)(&comp_unk_4 + unaff_A4)) {
        script_state_set_true(*(script_state_bit_t *)(&comp_unk_4 + unaff_A4));
      }
      sound_id = SOUND_ID_GET_MEAT;
      if (((&comp_collected_item_id_maybe)[unaff_A4] != 0x36) &&
          ((&comp_collected_item_id_maybe)[unaff_A4] != 0x37)) {
        sound_id = SOUND_ID_ITEM_GET;
      }
      audio_play(sound_id);
      FUN_0000185e();
      (&comp_has_func_maybe)[unaff_A4] = 0;
      uVar1 = FUN_00029824();
      return uVar1;
    }
  } else {
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return uVar1;
}

void FUN_00015de6(void)

{
  undefined2 *puVar1;
  entity_id_t e;
  int unaff_A3;
  bool bVar2;

  while (true) {
    if ((ushort)(DAT_ffffc73a + 0x140U) <
        **(ushort **)(&DAT_ffffd0dc + unaff_A3)) {
      return;
    }
    bVar2 = (char)(&DAT_ffffd05c)[unaff_A3] < '\0';
    e = FUN_00001a22();
    if (bVar2)
      break;
    (&DAT_ffffcf9f)[unaff_A3] = (&DAT_ffffcf9f)[unaff_A3] + '\x01';
    entity_reset(e);
    (&comp_has_func_maybe)[e] = 0x80;
    puVar1 = *(undefined2 **)(&DAT_ffffd0dc + unaff_A3);
    *(undefined2 *)((int)&comp_pos_x + e) = *puVar1;
    *(undefined2 *)((int)&comp_pos_y + e) = puVar1[1];
    *(ushort *)(&DAT_ffffbe78 + e) = (ushort) * (byte *)(puVar1 + 2);
    (&comp_func_offset[0].unk1)[e] = *(byte *)((int)puVar1 + 5);
    *(undefined2 **)(&DAT_ffffd0dc + unaff_A3) = puVar1 + 3;
    *(short *)((int)&comp_unk_8 + e) = (short)unaff_A3;
    FUN_000019ae();
    if (**(short **)(&DAT_ffffd0dc + unaff_A3) == -0x8000) {
      (&DAT_ffffcf9c)[unaff_A3] = 0;
      return;
    }
  }
  return;
}

void FUN_00015e48(void)

{
  entity_id_t e;
  short sVar1;
  undefined2 *puVar2;
  int unaff_A3;
  bool bVar3;

  bVar3 = (char)(&DAT_ffffd05c)[unaff_A3] < '\0';
  e = FUN_00001a22();
  if (bVar3) {
    return;
  }
  (&DAT_ffffcf9f)[unaff_A3] = (&DAT_ffffcf9f)[unaff_A3] + '\x01';
  entity_reset(e);
  *(undefined2 *)((int)&comp_unk_3 + e) = 0x18;
  *(undefined2 *)((int)&comp_pos_x + e) =
      *(undefined2 *)(&DAT_ffffcfdc + unaff_A3);
  *(undefined2 *)((int)&comp_pos_y + e) =
      *(undefined2 *)(&DAT_ffffcfde + unaff_A3);
  (&comp_has_func_maybe)[e] = 0x80;
  (&comp_func_offset[0].unk1)[e] = (&DAT_ffffd05c)[unaff_A3];
  *(short *)((int)&comp_unk_8 + e) = (short)unaff_A3;
  *(undefined2 *)(&DAT_ffffbc76 + e) = *(undefined2 *)((int)&comp_pos_x + e);
  *(undefined2 *)(&DAT_ffffbc78 + e) = *(undefined2 *)((int)&comp_pos_y + e);
  sVar1 = (ushort)(&comp_func_offset[0].unk1)[e] << 3;
  (&comp_func_offset[0].func_offset_from_15ede)[e] = (&DAT_0007d63c)[sVar1];
  (&comp_func_offset[0].unk3)[e] = (&DAT_0007d63d)[sVar1];
  *(undefined2 *)(&comp_anim_base_offset + e) =
      *(undefined2 *)(&DAT_0007d63e + sVar1);
  if (((&DAT_0007d640)[sVar1] & 4) != 0) {
    (&comp_anim[0].unk4)[e] = (&comp_anim[0].unk4)[e] | 0x80;
  }
  *(undefined2 *)((int)&comp_unk_7 + e) = 0;
  if (*(short *)(&DAT_0007d642 + sVar1) != 0) {
    puVar2 = (undefined2 *)&DAT_ffffd126;
    sVar1 = DAT_ffffcf9a;
    while ((&comp_func_offset[0].unk1)[e] != *(byte *)(puVar2 + 1)) {
      puVar2 = puVar2 + 2;
      sVar1 = sVar1 + -1;
      if (sVar1 == 0) {
        do {
          // WARNING: Do nothing block with infinite loop
        } while (true);
      }
    }
    *(undefined2 *)((int)&comp_unk_7 + e) = *puVar2;
    (&comp_has_func_maybe)[e] = (&comp_has_func_maybe)[e] | 0x20;
  }
  return;
}

void FUN_00015e86(void)

{
  short sVar1;
  ushort uVar2;
  char cVar3;
  ushort uVar4;
  int unaff_A4;

  sVar1 = *(short *)((int)&comp_unk_8 + unaff_A4);
  cVar3 = (&DAT_ffffcf9f)[sVar1] + -1;
  (&DAT_ffffcf9f)[sVar1] = cVar3;
  if ((cVar3 == '\0') && (((&DAT_ffffcf9c)[sVar1] & 1) == 0)) {
    (&DAT_ffffcf9c)[sVar1] = (&DAT_ffffcf9c)[sVar1] & 0x7f;
    uVar2 = *(ushort *)(&DAT_ffffd01c + sVar1);
    if (-1 < (short)uVar2) {
      uVar4 = uVar2 & 0xbfff;
      if ((uVar2 & 0x4000) == 0) {
        (&SCRIPT_STATE)[(short)(uVar4 >> 3)] =
            (byte)(1 << ((byte)uVar4 & 7)) |
            (&SCRIPT_STATE)[(short)(uVar4 >> 3)];
        return;
      }
      (&SCRIPT_STATE)[(short)(uVar4 >> 3)] =
          ~(byte)(1 << ((byte)uVar4 & 7)) &
          (&SCRIPT_STATE)[(short)(uVar4 >> 3)];
      return;
    }
  }
  return;
}

// This seemingly iterates over 21 entities, from #34 to #88 (as entities are 4
// appart each).

void ecs_run_entity_func_all(void)

{
  entity_id_t self;

  self = 0x34;
  entity_iter = 0x14;
  do {
    if ((char)(&comp_has_func_maybe)[self] < '\0') {
      (**(code **)((int)&entity_func_start_maybe +
                   (int)(short)(ushort)(&comp_func_offset[0]
                                             .func_offset_from_15ede)[self]))();
    }
    self = self + ENTITY_ID_PEPELOGOO;
    entity_iter = entity_iter + -1;
  } while (entity_iter != 0);
  return;
}

ushort ecs_some_collision_test(entity_id_t self, entity_id_t other)

{
  ushort pos_x_delta;
  short pos_y_delta;

  pos_x_delta = (*(short *)((int)&comp_pos_x + self) -
                 *(short *)((int)&comp_pos_x + other)) +
                8;
  if (pos_x_delta < 0x10) {
    pos_y_delta = *(short *)((int)&comp_pos_y + other) -
                  *(short *)((int)&comp_pos_y + self);
    if ((&comp_collision_related)[self] == '\0') {
      pos_x_delta =
          (*(short *)((int)&comp_collision_sensor[0].y + other) + pos_y_delta) -
          *(short *)((int)&comp_collision_sensor[0].y + self);
    } else {
      pos_x_delta = pos_y_delta + 0x18;
    }
  }
  return pos_x_delta;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00015f28(entity_id_t self)

{
  short sVar1;
  byte bVar2;
  short unaff_D2w;
  anim_item_t *unaff_A5;
  byte *pbVar3;
  byte *script;

  if (((&comp_has_func_maybe)[self] & 0x40) == 0) {
    (&comp_collision_related)[self] = 0;
    ecs_anim_unk_2(self, unaff_A5, 0);
    *(short *)((int)&comp_pos_y + self) =
        *(short *)((int)&comp_pos_y + self) -
        *(short *)((int)&comp_collision_sensor[0].y + self);
    FUN_00016112();
    *(anim_item_t **)(&comp_unk_9 + self) = unaff_A5;
    *(undefined1 *)((int)&comp_state + self) = 0;
    *(undefined2 *)(&DAT_ffffbd76 + self) =
        *(undefined2 *)((int)&comp_pos_x + self);
    *(undefined2 *)(&comp_unk_1 + self) = 0x100;
    (&DAT_ffffb976)[self] = 6;
    *(undefined1 *)(self - 0x4689) = 6;
    (&DAT_ffffb979)[self] = 8;
    *(undefined2 *)(&comp_unk_4 + self) = 1;
  }
  sVar1 = *(short *)((int)&comp_unk_8 + self);
  if (*(short *)(sVar1 + -0x2fe2) != 0) {
    ecs_some_collision_test(self, ENTITY_ID_ASHA);
    if (unaff_D2w != 0) {
      set_to_13a62_when_facing_a_door = FUN_00016326;
      DAT_ffffd916 = *(undefined2 *)(sVar1 + -0x2fe2);
      _DAT_ffffd122 = (undefined2)self;
      _DAT_ffffd120 = sVar1;
    }
  }
  if ((*(short *)(&comp_unk_4 + self) != 0) &&
      (sVar1 = *(short *)(&comp_unk_4 + self) + -1,
       *(short *)(&comp_unk_4 + self) = sVar1,
       sVar1 == 0)) {
    script = *(byte **)(&comp_unk_9 + self);
    do {
      while (true) {
        pbVar3 = script + 1;
        bVar2 = *script;
        if (-1 < (char)bVar2) {
          *(ushort *)(&comp_unk_4 + self) = (ushort)bVar2;
          goto LAB_00015fb8;
        }
        if (bVar2 < 0xc0)
          break;
        script = (byte *)text_command_c0_to_fe((script_t)script);
        self = (entity_id_t)(short)self;
      }
      (*(code *)((int)&WORD_00015ffe +
                 (int)*(
                     short *)((int)&WORD_00015ffe +
                              (int)(short)(ushort)(byte)(bVar2 * '\x02'))))();
      script = pbVar3;
    } while (*(short *)(&comp_unk_4 + self) == 0);
    if (*(short *)(&comp_unk_4 + self) < 0) {
      *(undefined2 *)(&comp_unk_4 + self) = 0;
    }
  LAB_00015fb8:
    *(byte **)(&comp_unk_9 + self) = pbVar3;
  }
  // WARNING: Could not recover jumptable at 0x00015fc6. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00015ff6 +
             (int)*(short *)((int)&WORD_00015ff6 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + self))))();
  return;
}

void FUN_00016024(void)

{
  entity_id_t unaff_A4;
  byte *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5 + 1, *unaff_A5);
  return;
}

void FUN_00016030(void)

{
  int unaff_A4;
  undefined1 *unaff_A5;

  (&DAT_ffffb976)[unaff_A4] = *unaff_A5;
  return;
}

void FUN_00016036(void)

{
  int unaff_A4;

  *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  return;
}

void FUN_0001603c(void)

{
  short sVar1;
  char cVar2;
  short sVar3;
  int unaff_A4;
  undefined1 *unaff_A5;

  (&DAT_ffffb978)[unaff_A4] = *unaff_A5;
  sVar1 = *(short *)((int)&comp_pos_x + unaff_A4);
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  sVar3 = *(short *)(&comp_unk_1 + unaff_A4);
  cVar2 = (&DAT_ffffb978)[unaff_A4];
  if (cVar2 != '\0') {
    if (cVar2 < '\0') {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] + ENTITY_STATE_A_08;
      sVar3 = -sVar3;
    }
    *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar3;
    *(short *)(&DAT_ffffbd76 + unaff_A4) = sVar1 + cVar2 * 0x10;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0xffff;
    return;
  }
  *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  return;
}

void FUN_00016078(void)

{
  ushort uVar1;
  word wVar2;
  char cVar3;
  short sVar4;
  short sVar5;
  int unaff_A4;
  bool bVar6;

  wVar2 = rand();
  uVar1 = wVar2 >> 1 & 7;
  sVar5 = uVar1 - 4;
  if (sVar5 < 0) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    cVar3 = (char)sVar5 + -4;
  } else {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    cVar3 = (char)uVar1;
  }
  (&DAT_ffffb978)[unaff_A4] = cVar3;
  bVar6 = cVar3 == '\0';
  FUN_000162ec();
  if (bVar6) {
    sVar5 = *(short *)(&DAT_ffffbd76 + unaff_A4);
    if (*(ushort *)((int)&comp_pos_x + unaff_A4) < 0x1030) {
      if (-1 < (char)(&DAT_ffffb978)[unaff_A4])
        goto LAB_00016044;
    } else if ((*(ushort *)((int)&comp_pos_x + unaff_A4) <=
                (ushort)(room_boundary_x - 0x30)) ||
               ((char)(&DAT_ffffb978)[unaff_A4] < '\0'))
      goto LAB_00016044;
    (&DAT_ffffb978)[unaff_A4] = -(&DAT_ffffb978)[unaff_A4];
  } else {
    sVar5 = *(short *)(&DAT_ffffbd76 + unaff_A4);
    (&DAT_ffffb978)[unaff_A4] = -(&DAT_ffffb978)[unaff_A4];
  }
LAB_00016044:
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  sVar4 = *(short *)(&comp_unk_1 + unaff_A4);
  cVar3 = (&DAT_ffffb978)[unaff_A4];
  if (cVar3 == '\0') {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
    return;
  }
  if (cVar3 < '\0') {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] + ENTITY_STATE_A_08;
    sVar4 = -sVar4;
  }
  *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar4;
  *(short *)(&DAT_ffffbd76 + unaff_A4) = sVar5 + cVar3 * 0x10;
  *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
  *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0xffff;
  return;
}

void *FUN_000160e0(void *param_1)

{
  // WARNING: Load size is inaccurate
  return (void *)((int)param_1 + (int)*param_1);
}

ushort FUN_000160ec(void)

{
  byte bVar1;
  word wVar2;
  byte *unaff_A5;

  wVar2 = rand();
  bVar1 = (char)wVar2 * '\x02';
  if (bVar1 < *unaff_A5) {
    return (ushort)bVar1;
  }
  return *(ushort *)(unaff_A5 + 1);
}

script_state_bit_t FUN_000160fc(void)

{
  script_state_bit_t extraout_D0w;
  script_state_bit_t index;
  int unaff_A4;
  script_state_bit_t *unaff_A5;
  bool bVar1;

  index = *(script_state_bit_t *)(&DAT_ffffd01c +
                                  *(short *)((int)&comp_unk_8 + unaff_A4));
  if (-1 < (short)index) {
    bVar1 = script_state_get(index);
    index = extraout_D0w;
    if (!bVar1) {
      return *unaff_A5;
    }
  }
  return index;
}

void FUN_00016112(void)

{
  return;
}

void FUN_0001612a(entity_id_t self)

{
  word wVar1;
  byte *unaff_A5;

  wVar1 = rand();
  *(ushort *)(&comp_unk_4 + self) =
      (ushort)(byte)(unaff_A5[1] + (*unaff_A5 & (byte)wVar1));
  return;
}

void FUN_0001613c(void)

{
  int unaff_A4;

  (&comp_collision_related)[unaff_A4] = 0xff;
  *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  return;
}

void FUN_00016148(void)

{
  int unaff_A4;

  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] + ENTITY_STATE_A_08;
  }
  return;
}

void FUN_0001615e(void)

{
  int unaff_A4;

  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  return;
}

void FUN_00016166(void)

{
  int unaff_A4;

  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  return;
}

void FUN_0001616e(void)

{
  short sVar1;
  int iVar2;
  entity_id_t unaff_A4;
  byte *unaff_A5;

  iVar2 = 0x34;
  sVar1 = 0x13;
  while ((-1 < (char)(&comp_has_func_maybe)[iVar2] ||
          (*unaff_A5 != (&comp_func_offset[0].unk1)[iVar2]))) {
    iVar2 = iVar2 + 4;
    sVar1 = sVar1 + -1;
    if (sVar1 == -1) {
      do {
        // WARNING: Do nothing block with infinite loop
      } while (true);
    }
  }
  *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4) =
      (short)iVar2;
  *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0xffff;
  ecs_anim_unk_2(unaff_A4, unaff_A5 + 1, *(byte *)(unaff_A4 - 0x4689));
  (&comp_func_offset[0].unk4)[unaff_A4] = 0;
  (&DAT_ffffb66e)[unaff_A4] = 8;
  return;
}

void FUN_000161b4(void)

{
  int unaff_A4;
  undefined1 *unaff_A5;

  *(undefined1 *)(unaff_A4 + -0x4689) = *unaff_A5;
  return;
}

void FUN_000161ba(void)

{
  int unaff_A4;
  undefined1 *unaff_A5;

  (&DAT_ffffb979)[unaff_A4] = *unaff_A5;
  return;
}

void FUN_000161c0(void)

{
  undefined1 *unaff_A5;

  DAT_ffffd916._0_1_ = *unaff_A5;
  DAT_ffffd916._1_1_ = unaff_A5[1];
  DAT_ffffcc92 = 2;
  DAT_ffffcc93 = 0;
  return;
}

void FUN_000161d4(void)

{
  int unaff_A4;
  byte *unaff_A5;

  *(ushort *)((int)&comp_unk_3 + unaff_A4) = (ushort)*unaff_A5;
  return;
}

void FUN_000161de(void)

{
  return;
}

void FUN_000161e0(void)

{
  ushort uVar1;
  ushort uVar2;
  ulong unaff_A4;
  undefined1 in_ZF;

  player_update_pos_x(unaff_A4);
  FUN_000162ec();
  if ((bool)in_ZF) {
    uVar1 = *(ushort *)((int)&comp_pos_x + unaff_A4);
    uVar2 = *(ushort *)(&DAT_ffffbd76 + unaff_A4);
    if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
      uVar1 = *(ushort *)(&DAT_ffffbd76 + unaff_A4);
      uVar2 = *(ushort *)((int)&comp_pos_x + unaff_A4);
    }
    if (uVar1 < uVar2) {
      return;
    }
  }
  *(undefined2 *)(&comp_unk_4 + unaff_A4) = 1;
  return;
}

void FUN_00016208(void)

{
  int unaff_A4;

  FUN_000162a6();
  *(int *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
      *(int *)((int)&comp_pos_y + unaff_A4);
  return;
}

void FUN_00016218(void)

{
  char cVar1;
  ushort uVar2;
  entity_state_1_b_t state_1_b;
  short sVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_000162a6();
  if (((&DAT_ffffb66e)[unaff_A4] == '\0') ||
      (cVar1 = (&DAT_ffffb66e)[unaff_A4] + -1,
       (&DAT_ffffb66e)[unaff_A4] = cVar1,
       cVar1 == '\0')) {
    if ((&comp_func_offset[0].unk4)[unaff_A4] == 0) {
      sVar3 = *(short *)(&comp_unk_1 + unaff_A4);
      (&comp_state_a)[unaff_A4] =
          (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
      uVar2 =
          *(short *)((int)&comp_pos_x +
                     (int)*(
                         short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                                  unaff_A4)) -
          *(short *)((int)&comp_pos_x + unaff_A4);
      if ((short)uVar2 < 0) {
        (&comp_state_a)[unaff_A4] =
            (&comp_state_a)[unaff_A4] + ENTITY_STATE_A_08;
        uVar2 = -uVar2;
        sVar3 = -sVar3;
      }
      if (uVar2 < 0x30)
        goto LAB_000162a2;
      (&comp_func_offset[0].unk4)[unaff_A4] = 0xff;
      *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar3;
      (&DAT_ffffb66e)[unaff_A4] = 8;
      state_1_b = (&DAT_ffffb979)[unaff_A4];
    } else {
      uVar2 =
          *(short *)((int)&comp_pos_x +
                     (int)*(
                         short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                                  unaff_A4)) -
          *(short *)((int)&comp_pos_x + unaff_A4);
      if ((short)uVar2 < 0) {
        uVar2 = -uVar2;
      }
      if (0x1f < uVar2)
        goto LAB_000162a2;
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      (&comp_func_offset[0].unk4)[unaff_A4] = 0;
      (&DAT_ffffb66e)[unaff_A4] = 8;
      state_1_b = *(entity_state_1_b_t *)(unaff_A4 - 0x4689);
    }
    if (state_1_b != (&comp_anim_c)[unaff_A4]) {
      ecs_anim_unk_2(unaff_A4, unaff_A5, state_1_b);
    }
  }
LAB_000162a2:
  player_update_pos(unaff_A4);
  return;
}

void FUN_000162a6(void)

{
  short sVar1;
  short in_D0w;
  word wVar2;
  short sVar3;
  short sVar4;
  int unaff_A4;

  wVar2 = rand();
  sVar4 = (wVar2 >> 1 & 3) + 0x1c;
  sVar3 = 2;
  sVar1 = *(short *)((int)&comp_vel[0].y + unaff_A4);
  if (sVar1 < 0) {
    sVar3 = -2;
  }
  if ((ushort)(in_D0w + sVar3) < *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    sVar4 = -sVar4;
  }
  sVar4 = sVar4 + sVar1;
  if (sVar4 < 0) {
    if (sVar4 < -0x1c0) {
      sVar4 = -0x1c0;
    }
  } else if (0x180 < sVar4) {
    sVar4 = 0x180;
  }
  *(short *)((int)&comp_vel[0].y + unaff_A4) = sVar4;
  return;
}

undefined2 FUN_000162ec(void)

{
  ushort uVar1;
  undefined2 uVar2;
  short unaff_D3w;

  uVar1 = FUN_000183ce(unaff_D3w);
  if ((uVar1 & 1) != 0) {
    uVar2 = FUN_000183ce(unaff_D3w);
    return uVar2;
  }
  return 0xffff;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00016326(void)

{
  entity_id_t self;
  anim_item_t *unaff_A5;

  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0xe);
  DAT_ffffcc92 = 2;
  DAT_ffffcc93 = 0;
  self = (entity_id_t)_DAT_ffffd122;
  DAT_ffffd124 = (&comp_anim_c)[self];
  ecs_anim_unk_2(self, unaff_A5, (&DAT_ffffb976)[self]);
  set_to_13a62_when_facing_a_door = 0x16366;
  return;
}

void ecs_called_after_run_entity_func_all(void)

{
  (*(code *)((int)&WORD_00016390 +
             (int)*(short *)((int)&WORD_00016390 + (int)DAT_ffffd16c)))();
  FUN_0001639a();
  return;
}

void FUN_0001639a(void)

{
  (*(code *)((int)&WORD_000163ba +
             (int)*(short *)((int)&WORD_000163ba +
                             (int)(short)((ushort)DAT_ffffd17e * 2))))();
  // WARNING: Could not recover jumptable at 0x000163b6. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_000163c0 +
             (int)*(short *)((int)&WORD_000163c0 +
                             (int)(short)((ushort)DAT_ffffd17f * 2))))();
  return;
}

void FUN_000163c6(void)

{
  FUN_000163de();
  FUN_0001642e();
  player_vel_unknown_x_1 = player_vel_unknown_x_2;
  player_vel_unknown_y_1 = player_vel_unknown_y_2;
  player_vel_unknown_x_2 = comp_pos_x.fixed.i - component_pos_old_x[0]._0_2_;
  if (player_vel_unknown_x_2 != 0) {
    if ((short)player_vel_unknown_x_2 < 0) {
      if ((short)player_vel_unknown_x_2 < -4) {
        player_vel_unknown_x_2 = 0xfffb;
      } else {
        player_vel_unknown_x_2 = player_vel_unknown_x_2 - 1;
      }
    } else if (player_vel_unknown_x_2 < 5) {
      player_vel_unknown_x_2 = player_vel_unknown_x_2 + 1;
    } else {
      player_vel_unknown_x_2 = 5;
    }
  }
  player_vel_unknown_y_2 = comp_pos_y.fixed.i - component_pos_old_y[0]._0_2_;
  if (player_vel_unknown_y_2 != 0) {
    if ((short)player_vel_unknown_y_2 < 0) {
      if ((short)player_vel_unknown_y_2 < -4) {
        player_vel_unknown_y_2 = 0xfffb;
      } else {
        player_vel_unknown_y_2 = player_vel_unknown_y_2 - 1;
      }
    } else if (player_vel_unknown_y_2 < 5) {
      player_vel_unknown_y_2 = player_vel_unknown_y_2 + 1;
    } else {
      player_vel_unknown_y_2 = 5;
    }
  }
  return;
}

void FUN_000163de(void)

{
  int unaff_A4;

  FUN_000165b2();
  *(undefined4 *)((int)&DAT_ffffc746 + unaff_A4) = 0;
  *(undefined2 *)((int)&related_to_comp_unk_4_ffffa32a_1 + unaff_A4) = 0xff80;
  return;
}

void FUN_0001642e(void)

{
  int unaff_D2;
  int unaff_A4;

  FUN_000165b2();
  *(int *)((int)&DAT_ffffc73a + unaff_A4) = unaff_D2;
  *(short *)(&related_to_comp_unk_4_ffffa32a_2 + unaff_A4) =
      (short)((uint)(unaff_D2 + -0x800000) >> 0x10);
  return;
}

void FUN_0001647c(void)

{
  player_vel_unknown_x_1 = player_vel_unknown_x_2;
  player_vel_unknown_y_1 = player_vel_unknown_y_2;
  player_vel_unknown_x_2 = comp_pos_x.fixed.i - component_pos_old_x[0]._0_2_;
  if (player_vel_unknown_x_2 != 0) {
    if ((short)player_vel_unknown_x_2 < 0) {
      if ((short)player_vel_unknown_x_2 < -4) {
        player_vel_unknown_x_2 = 0xfffb;
      } else {
        player_vel_unknown_x_2 = player_vel_unknown_x_2 - 1;
      }
    } else if (player_vel_unknown_x_2 < 5) {
      player_vel_unknown_x_2 = player_vel_unknown_x_2 + 1;
    } else {
      player_vel_unknown_x_2 = 5;
    }
  }
  player_vel_unknown_y_2 = comp_pos_y.fixed.i - component_pos_old_y[0]._0_2_;
  if (player_vel_unknown_y_2 != 0) {
    if ((short)player_vel_unknown_y_2 < 0) {
      if ((short)player_vel_unknown_y_2 < -4) {
        player_vel_unknown_y_2 = 0xfffb;
      } else {
        player_vel_unknown_y_2 = player_vel_unknown_y_2 - 1;
      }
    } else if (player_vel_unknown_y_2 < 5) {
      player_vel_unknown_y_2 = player_vel_unknown_y_2 + 1;
    } else {
      player_vel_unknown_y_2 = 5;
    }
  }
  return;
}

void FUN_000164e6(void)

{
  FUN_000164fa();
  FUN_00016538();
  return;
}

void FUN_000164fa(void)

{
  undefined4 unaff_D2;
  int unaff_A4;

  FUN_000165b2();
  *(undefined4 *)((int)&DAT_ffffc73a + unaff_A4) = unaff_D2;
  return;
}

void FUN_00016538(void)

{
  int unaff_A4;

  FUN_000165b2();
  *(undefined4 *)((int)&DAT_ffffc746 + unaff_A4) = 0;
  *(short *)(&related_to_comp_unk_4_ffffa32a_2 + unaff_A4) =
      *(short *)((int)&DAT_ffffc73a + unaff_A4) + -0x80;
  *(undefined2 *)((int)&related_to_comp_unk_4_ffffa32a_1 + unaff_A4) = 0xff80;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00016590(void)

{
  int unaff_A4;

  *(undefined4 *)((int)&DAT_ffffc746 + unaff_A4) = 0xfe00000;
  *(uint *)((int)&DAT_ffffc73a + unaff_A4) =
      (_DAT_ffffc73a + 0xf0000000U >> 0xc & 0xffff) << 0xb;
  return;
}

void FUN_000165b2(void)

{
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000165ec(void)

{
  uint uVar1;
  fixed_t fVar2;
  uint uVar3;
  uint uVar4;
  int iVar5;
  fixed_t fVar6;

  _DAT_ffffd196 = 0;
  _DAT_ffffd194 = 0;
  DAT_ffffd192 = 0;
  player_vel_unknown_x_2 = 0;
  player_vel_unknown_x_1 = 0;
  player_vel_unknown_y_2 = 0;
  player_vel_unknown_y_1 = 0;
  DAT_ffffd16c = 0;
  DAT_ffffc782 = 0;
  _DAT_ffffc786 = 0;
  DAT_ffffc784 = 0;
  _DAT_ffffc788 = 0;
  uVar3 = (uint)(ushort)(DAT_ffffd18e - 0x20) << 0x10;
  uVar1 = (uint)(ushort)(DAT_ffffd190 - 0xdf) << 0x10;
  uVar4 = comp_pos_y.raw - 0x800000;
  if ((uVar3 <= uVar4) && (uVar3 = uVar4, uVar1 < uVar4)) {
    uVar3 = uVar1;
  }
  _DAT_ffffc746 = uVar3 + (uint)DAT_ffffd2e4 * -0x10000;
  related_to_comp_unk_4_ffffa32a_1 =
      (undefined2)((uint)(_DAT_ffffc746 + -0x800000) >> 0x10);
  fVar2.raw = (uint)(ushort)(DAT_ffffd18a + 0x80) << 0x10;
  uVar4 = (uint)(ushort)(DAT_ffffd18c - 0xff) << 0x10;
  fVar6 = comp_pos_x;
  if ((uint)comp_pos_x < (uint)fVar2) {
    fVar6.raw = fVar2.raw;
  }
  _DAT_ffffc73a = fVar6.raw - 0x800000U;
  if (uVar4 <= fVar6.raw - 0x800000U) {
    _DAT_ffffc73a = uVar4;
  }
  _related_to_comp_unk_4_ffffa32a_2 =
      (undefined2)(_DAT_ffffc73a - 0x800000 >> 0x10);
  uVar4 = _DAT_ffffc73a + 0xf0000000;
  if ((int)uVar4 < 0) {
    uVar4 = 0;
  }
  iVar5 = (uVar4 >> 0xc & 0xffff) << 0xb;
  _DAT_ffffc73e = (short)((uint)iVar5 >> 0x10);
  _DAT_ffffc73e = CONCAT22(_DAT_ffffc73e + 0x1000, (short)iVar5);
  _DAT_ffffc74a = (uint)(ushort)(0xfe0 - DAT_ffffd2e4) << 0x10;
  FUN_0001639a();
  return;
}

void FUN_00016708(void)

{
  player_vel_unknown_x_1 = 0x100;
  player_vel_unknown_y_1 = 0x100;
  (*(code *)((int)&WORD_00016736 +
             (int)*(short *)((int)&WORD_00016736 + (int)DAT_ffffd16c)))();
  FUN_0001639a();
  DAT_ffffc746 = DAT_ffffc746 - DAT_ffffd2e4;
  DAT_ffffc74a = DAT_ffffc74a - DAT_ffffd2e4;
  related_to_comp_unk_4_ffffa32a_1 =
      related_to_comp_unk_4_ffffa32a_1 - DAT_ffffd2e4;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00016740(void)

{
  _DAT_ffffc73e = 0x10000000;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001674a(void)

{
  _DAT_ffffc74a = 0xfe00000;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00016754(void)

{
  uint uVar1;
  int iVar2;

  uVar1 = _DAT_ffffc73a + 0xf0000000;
  if ((int)uVar1 < 0) {
    uVar1 = 0;
  }
  iVar2 = (uVar1 >> 0xc & 0xffff) * (uint)DAT_ffffd180 * 0x100;
  _DAT_ffffc73e = (short)((uint)iVar2 >> 0x10);
  _DAT_ffffc73e = CONCAT22(_DAT_ffffc73e + 0x1000, (short)iVar2);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001677c(void)

{
  uint uVar1;
  int iVar2;

  uVar1 = _DAT_ffffc746 + 0xf0200000;
  if ((int)uVar1 < 0) {
    uVar1 = 0;
  }
  iVar2 = (uVar1 >> 0xc & 0xffff) * (uint)DAT_ffffd181 * 0x100;
  DAT_ffffc74a = (short)((uint)iVar2 >> 0x10);
  _DAT_ffffc74a = CONCAT22(DAT_ffffc74a + 0xfe0, (short)iVar2);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000167a4(void)

{
  _DAT_ffffc73e = _DAT_ffffc73a + (uint)_DAT_ffffd17a * 0x10000;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000167b6(void)

{
  _DAT_ffffc74a = _DAT_ffffc746 + (uint)_DAT_ffffd17c * 0x10000;
  return;
}

void FUN_000167c8(void)

{
  FUN_000167e6();
  FUN_00016836();
  player_vel_unknown_x_1 = 3;
  player_vel_unknown_y_1 = 3;
  player_vel_unknown_y_2 = 3;
  return;
}

void FUN_000167e6(void)

{
  int unaff_A4;

  FUN_000165b2();
  *(undefined4 *)((int)&DAT_ffffc746 + unaff_A4) = 0;
  *(undefined2 *)((int)&related_to_comp_unk_4_ffffa32a_1 + unaff_A4) = 0xff80;
  return;
}

void FUN_00016836(void)

{
  int unaff_D2;
  int unaff_A4;

  FUN_000165b2();
  *(int *)((int)&DAT_ffffc73a + unaff_A4) = unaff_D2;
  *(short *)(&related_to_comp_unk_4_ffffa32a_2 + unaff_A4) =
      (short)((uint)(unaff_D2 + -0x800000) >> 0x10);
  return;
}

void FUN_00016884(void)

{
  player_vel_unknown_x_1 = 3;
  player_vel_unknown_y_1 = 3;
  player_vel_unknown_y_2 = 3;
  return;
}

void FUN_0001689e(void)

{
  short in_D0w;

  DAT_ffffd192 = in_D0w;
  // WARNING: Could not recover jumptable at 0x000168ae. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_000168b0 +
             (int)*(short *)((int)&WORD_000168b0 +
                             (int)(short)(in_D0w * 2))))();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000168ba(void)

{
  DAT_ffffc782 = 0;
  DAT_ffffc784 = 0;
  _DAT_ffffc786 = 0;
  _DAT_ffffc788 = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000168d4(void)

{
  _DAT_ffffd196 = 0x1000;
  _DAT_ffffd194 = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000168e0(void)

{
  _DAT_ffffd196 = 0x300;
  _DAT_ffffd194 = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000168ec(void)

{
  _DAT_ffffd196 = 0x300;
  _DAT_ffffd194 = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000168f8(void)

{
  _DAT_ffffd196 = 0x14;
  _DAT_ffffd194 = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00016904(void)

{
  ushort uVar1;

  (*(code *)((int)&WORD_00016924 +
             (int)*(short *)((int)&WORD_00016924 +
                             (int)(short)(DAT_ffffd192 * 2))))();
  if (DAT_ffffd192 != 0) {
    uVar1 = DAT_ffffc73a + DAT_ffffc782;
    if (uVar1 < 0x1001) {
      DAT_ffffc782 = 0x1000 - DAT_ffffc73a;
      uVar1 = DAT_ffffc73a + DAT_ffffc782;
      _DAT_ffffc786 = DAT_ffffc782;
    }
    if ((ushort)(room_boundary_x - 0xff) < uVar1) {
      DAT_ffffc782 = (room_boundary_x - 0xff) - DAT_ffffc73a;
      _DAT_ffffc786 = DAT_ffffc782;
    }
    uVar1 = DAT_ffffc784 + DAT_ffffc746;
    if (uVar1 < 0xfe1) {
      DAT_ffffc784 = DAT_ffffc746;
      _DAT_ffffc788 = DAT_ffffc746;
      uVar1 = DAT_ffffc746 * 2;
    }
    if ((ushort)(camera_pos_x_int - 0xdf) < uVar1) {
      DAT_ffffc784 = (camera_pos_x_int - 0xdf) - DAT_ffffc746;
      _DAT_ffffc788 = DAT_ffffc784;
    }
    return;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001692e(void)

{
  ushort uVar1;

  uVar1 = DAT_ffffc73a + DAT_ffffc782;
  if (uVar1 < 0x1001) {
    DAT_ffffc782 = 0x1000 - DAT_ffffc73a;
    uVar1 = DAT_ffffc73a + DAT_ffffc782;
    _DAT_ffffc786 = DAT_ffffc782;
  }
  if ((ushort)(room_boundary_x - 0xff) < uVar1) {
    DAT_ffffc782 = (room_boundary_x - 0xff) - DAT_ffffc73a;
    _DAT_ffffc786 = DAT_ffffc782;
  }
  uVar1 = DAT_ffffc784 + DAT_ffffc746;
  if (uVar1 < 0xfe1) {
    DAT_ffffc784 = DAT_ffffc746;
    _DAT_ffffc788 = DAT_ffffc746;
    uVar1 = DAT_ffffc746 * 2;
  }
  if ((ushort)(camera_pos_x_int - 0xdf) < uVar1) {
    DAT_ffffc784 = (camera_pos_x_int - 0xdf) - DAT_ffffc746;
    _DAT_ffffc788 = DAT_ffffc784;
  }
  return;
}

void FUN_000169d8(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&camera_pos_x_int + unaff_A4) <=
      (ushort)(*(short *)((int)&DAT_ffffc746 + unaff_A4) +
               *(short *)((int)&DAT_ffffc784 + unaff_A4))) {
    *(short *)((int)&DAT_ffffc784 + unaff_A4) =
        *(short *)((int)&camera_pos_x_int + unaff_A4) -
        *(short *)((int)&DAT_ffffc746 + unaff_A4);
  }
  if ((ushort)(*(short *)((int)&DAT_ffffc746 + unaff_A4) +
               *(short *)((int)&DAT_ffffc784 + unaff_A4)) < 0x1000) {
    *(short *)((int)&DAT_ffffc784 + unaff_A4) =
        0x1000 - *(short *)((int)&DAT_ffffc746 + unaff_A4);
  }
  if (*(ushort *)((int)&room_boundary_x + unaff_A4) <=
      (ushort)(*(short *)((int)&DAT_ffffc73a + unaff_A4) +
               *(short *)((int)&DAT_ffffc782 + unaff_A4))) {
    *(short *)((int)&DAT_ffffc782 + unaff_A4) =
        *(short *)((int)&room_boundary_x + unaff_A4) -
        *(short *)((int)&DAT_ffffc73a + unaff_A4);
  }
  if ((ushort)(*(short *)((int)&DAT_ffffc73a + unaff_A4) +
               *(short *)((int)&DAT_ffffc782 + unaff_A4)) < 0x1000) {
    *(short *)((int)&DAT_ffffc782 + unaff_A4) =
        0x1000 - *(short *)((int)&DAT_ffffc73a + unaff_A4);
  }
  return;
}

void FUN_00016a42(void)

{
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00016a44(void)

{
  int iVar1;
  word *pwVar2;

  _DAT_ffffd196 = _DAT_ffffd196 + -1;
  if (-1 < _DAT_ffffd196) {
    iVar1 = (int)_DAT_ffffd194;
    _DAT_ffffd194 = _DAT_ffffd194 + 2;
    pwVar2 = (word *)((int)&WORD_00016a7c + iVar1);
    while (DAT_ffffc784 = *pwVar2, (short)DAT_ffffc784 < 0) {
      _DAT_ffffd194 = 0;
      pwVar2 = &WORD_00016a7c;
    }
    _DAT_ffffc788 = DAT_ffffc784;
    return;
  }
  DAT_ffffd192 = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00016a82(void)

{
  int iVar1;
  word *pwVar2;

  _DAT_ffffd196 = _DAT_ffffd196 + -1;
  if (-1 < _DAT_ffffd196) {
    iVar1 = (int)_DAT_ffffd194;
    _DAT_ffffd194 = _DAT_ffffd194 + 2;
    pwVar2 = (word *)((int)&WORD_00016aba + iVar1);
    while (DAT_ffffc782 = *pwVar2, (short)DAT_ffffc782 < 0) {
      _DAT_ffffd194 = 0;
      pwVar2 = &WORD_00016aba;
    }
    _DAT_ffffc786 = DAT_ffffc782;
    return;
  }
  DAT_ffffd192 = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00016ac0(void)

{
  int iVar1;
  word *pwVar2;

  _DAT_ffffd196 = _DAT_ffffd196 + -1;
  if (-1 < _DAT_ffffd196) {
    iVar1 = (int)_DAT_ffffd194;
    _DAT_ffffd194 = _DAT_ffffd194 + 2;
    pwVar2 = (word *)((int)&WORD_00016b04 + iVar1);
    while (DAT_ffffc782 = *pwVar2, (short)DAT_ffffc782 < 0) {
      _DAT_ffffd194 = 0;
      pwVar2 = &WORD_00016b04;
    }
    _DAT_ffffc786 = DAT_ffffc782;
    DAT_ffffc784 = DAT_ffffc782;
    _DAT_ffffc788 = DAT_ffffc782;
    return;
  }
  DAT_ffffd192 = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00016b0a(void)

{
  int iVar1;

  _DAT_ffffd196 = _DAT_ffffd196 + -1;
  if (_DAT_ffffd196 != 0) {
    iVar1 = (int)_DAT_ffffd194;
    _DAT_ffffd194 = _DAT_ffffd194 + 4;
    DAT_ffffc782 = *(undefined2 *)((int)WORD_ARRAY_00016b5c + iVar1);
    DAT_ffffc784 = *(undefined2 *)((int)WORD_ARRAY_00016b5c + iVar1 + 2);
    _DAT_ffffc786 = DAT_ffffc782;
    _DAT_ffffc788 = DAT_ffffc784;
    return;
  }
  DAT_ffffd192 = 0;
  DAT_ffffc782 = 0;
  _DAT_ffffc786 = 0;
  DAT_ffffc784 = 0;
  _DAT_ffffc788 = 0;
  return;
}

void FUN_00016bb4(void)

{
  FUN_00016bc8();
  FUN_00016bd0();
  return;
}

void FUN_00016bc8(void)

{
  int unaff_A4;

  *(undefined2 *)((int)&DAT_ffffc73a + unaff_A4) = DAT_ffffd176;
  return;
}

void FUN_00016bd0(void)

{
  int unaff_A4;

  *(word *)((int)&DAT_ffffc746 + unaff_A4) = WORD_ffffd178;
  return;
}

void FUN_00016bd8(void)

{
  FUN_00016bf0();
  FUN_00016c40();
  player_vel_unknown_x_1 = player_vel_unknown_x_2;
  player_vel_unknown_y_1 = player_vel_unknown_y_2;
  player_vel_unknown_x_2 = comp_pos_x.fixed.i - component_pos_old_x[0]._0_2_;
  if (player_vel_unknown_x_2 != 0) {
    if ((short)player_vel_unknown_x_2 < 0) {
      if ((short)player_vel_unknown_x_2 < -4) {
        player_vel_unknown_x_2 = 0xfffb;
      } else {
        player_vel_unknown_x_2 = player_vel_unknown_x_2 - 1;
      }
    } else if (player_vel_unknown_x_2 < 5) {
      player_vel_unknown_x_2 = player_vel_unknown_x_2 + 1;
    } else {
      player_vel_unknown_x_2 = 5;
    }
  }
  player_vel_unknown_y_2 = comp_pos_y.fixed.i - component_pos_old_y[0]._0_2_;
  if (player_vel_unknown_y_2 != 0) {
    if ((short)player_vel_unknown_y_2 < 0) {
      if ((short)player_vel_unknown_y_2 < -4) {
        player_vel_unknown_y_2 = 0xfffb;
      } else {
        player_vel_unknown_y_2 = player_vel_unknown_y_2 - 1;
      }
    } else if (player_vel_unknown_y_2 < 5) {
      player_vel_unknown_y_2 = player_vel_unknown_y_2 + 1;
    } else {
      player_vel_unknown_y_2 = 5;
    }
  }
  return;
}

void FUN_00016bf0(void)

{
  int unaff_A4;

  FUN_000165b2();
  *(undefined4 *)((int)&DAT_ffffc746 + unaff_A4) = 0;
  *(undefined2 *)((int)&related_to_comp_unk_4_ffffa32a_1 + unaff_A4) = 0xff80;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00016c40(void)

{
  ushort uVar1;
  uint uVar2;
  undefined4 unaff_D2;
  uint uVar3;
  ushort uVar4;
  int unaff_A4;

  uVar2 = ((*(int *)((int)&comp_pos_x + (int)_DAT_ffffd198) -
                *(int *)((int)&comp_pos_x + unaff_A4) >>
            1) +
           *(int *)((int)&comp_pos_x + unaff_A4)) -
          0x800000;
  uVar4 = (ushort)(uVar2 >> 0x10);
  if (uVar4 < (ushort)(*(short *)((int)&comp_pos_x + unaff_A4) - 0x20U)) {
    uVar1 = *(short *)((int)&comp_pos_x + unaff_A4) + 0x20;
    uVar3 = CONCAT22((short)((uint)unaff_D2 >> 0x10), uVar1);
    if ((ushort)(uVar4 + 0x100) < uVar1) {
      uVar2 = *(int *)((int)&comp_pos_x + unaff_A4) - 0x1000000;
      uVar3 = uVar2;
    }
  } else {
    uVar2 = *(int *)((int)&comp_pos_x + unaff_A4) + 0x1000000;
    uVar3 = uVar2;
  }
  if (uVar2 < comp_pos_x.raw - 0x200000U) {
    uVar3 = uVar2 + 0x1000000;
  }
  FUN_000165b2();
  *(uint *)((int)&DAT_ffffc73a + unaff_A4) = uVar3;
  *(short *)(&related_to_comp_unk_4_ffffa32a_2 + unaff_A4) =
      (short)(uVar3 - 0x800000 >> 0x10);
  return;
}

void FUN_00016d08(void)

{
  player_vel_unknown_x_1 = player_vel_unknown_x_2;
  player_vel_unknown_y_1 = player_vel_unknown_y_2;
  player_vel_unknown_x_2 = comp_pos_x.fixed.i - component_pos_old_x[0]._0_2_;
  if (player_vel_unknown_x_2 != 0) {
    if ((short)player_vel_unknown_x_2 < 0) {
      if ((short)player_vel_unknown_x_2 < -4) {
        player_vel_unknown_x_2 = 0xfffb;
      } else {
        player_vel_unknown_x_2 = player_vel_unknown_x_2 - 1;
      }
    } else if (player_vel_unknown_x_2 < 5) {
      player_vel_unknown_x_2 = player_vel_unknown_x_2 + 1;
    } else {
      player_vel_unknown_x_2 = 5;
    }
  }
  player_vel_unknown_y_2 = comp_pos_y.fixed.i - component_pos_old_y[0]._0_2_;
  if (player_vel_unknown_y_2 != 0) {
    if ((short)player_vel_unknown_y_2 < 0) {
      if ((short)player_vel_unknown_y_2 < -4) {
        player_vel_unknown_y_2 = 0xfffb;
      } else {
        player_vel_unknown_y_2 = player_vel_unknown_y_2 - 1;
      }
    } else if (player_vel_unknown_y_2 < 5) {
      player_vel_unknown_y_2 = player_vel_unknown_y_2 + 1;
    } else {
      player_vel_unknown_y_2 = 5;
    }
  }
  return;
}

void entity_update_pos(entity_id_t self)

{
  *(undefined4 *)((int)component_pos_old_x + self) =
      *(undefined4 *)((int)&comp_pos_x + self);
  *(undefined4 *)((int)component_pos_old_y + self) =
      *(undefined4 *)((int)&comp_pos_y + self);
  player_update_pos(self);
  *(short *)((int)&component_vel_old[0].x + self) =
      *(short *)((int)&comp_pos_x + self) -
      *(short *)((int)component_pos_old_x + self);
  *(short *)((int)&component_vel_old[0].y + self) =
      *(short *)((int)&comp_pos_y + self) -
      *(short *)((int)component_pos_old_y + self);
  return;
}

void player_update_vel_old(ulong ctx)

{
  *(short *)((int)&component_vel_old[0].x + ctx) =
      *(short *)((int)&comp_pos_x + ctx) -
      *(short *)((int)component_pos_old_x + ctx);
  *(short *)((int)&component_vel_old[0].y + ctx) =
      *(short *)((int)&comp_pos_y + ctx) -
      *(short *)((int)component_pos_old_y + ctx);
  return;
}

void ecs_update_collision(ulong entity, short param_2, word param_3,
                          word param_4)

{
  short sVar1;

  (&component_collision_flags)[entity] = 0;
  (&comp_collision[0].collision.y)[entity] = '\0';
  (&comp_collision[0].collision.x)[entity] = '\0';
  related_to_entity_collision_y(entity, param_2, param_3, param_4);
  sVar1 = player_collision_get_y_pos(entity);
  related_to_entity_collision_x(entity, sVar1, param_3, param_4);
  return;
}

void related_to_entity_collision_y(ulong entity, short param_2, word param_3,
                                   word param_4)

{
  short collision_sensor_diameter_x;

  collision_sensor_diameter_x =
      *(short *)((int)&comp_collision_sensor[0].x + entity) * 2;
  if (*(uint *)((int)component_pos_old_y + entity) <=
      *(uint *)((int)&comp_pos_y + entity)) {
    // Player doesn't move vertically or goes down
    if ((entity != 4) || ((pepelogoo_state_b & 0x80) == 0)) {
      related_to_entity_collision_y_2(
          *(short *)((int)&comp_collision_sensor[0].y + entity) +
              *(short *)((int)&comp_pos_y + entity),
          *(short *)((int)component_pos_old_x + entity) -
              *(short *)((int)&comp_collision_sensor[0].x + entity),
          collision_sensor_diameter_x,
          param_2);
      while (-1 < collision_sensor_diameter_x) {
        param_2 = param_2 * 2;
        (*(code *)((int)&WORD_00016efc +
                   (int)*(short *)((int)&WORD_00016efc + (int)param_2)))();
        collision_sensor_diameter_x = collision_sensor_diameter_x + -1;
        if (collision_sensor_diameter_x < 0) {
          return;
        }
        FUN_0001708c(collision_sensor_diameter_x, param_2, param_3, param_4);
      }
    }
    return;
  }
  // Object goes up
  related_to_entity_collision_y_2(
      *(short *)((int)&comp_pos_y + entity) -
          *(short *)((int)&comp_collision_sensor[0].y + entity),
      *(short *)((int)component_pos_old_x + entity) -
          *(short *)((int)&comp_collision_sensor[0].x + entity),
      collision_sensor_diameter_x,
      param_2);
  while (true) {
    if (collision_sensor_diameter_x < 0) {
      return;
    }
    param_2 = param_2 * 2;
    // Can jump to #16e22
    (*(code *)((int)&WORD_00016e00 +
               (int)*(short *)((int)&WORD_00016e00 + (int)param_2)))();
    collision_sensor_diameter_x = collision_sensor_diameter_x + -1;
    if (collision_sensor_diameter_x < 0)
      break;
    FUN_0001708c(collision_sensor_diameter_x, param_2, param_3, param_4);
  }
  return;
}

void FUN_00016e20(void)

{
  return;
}

void related_to_entity_collision_y_4(entity_id_t self, short param_2)

{
  if (((&comp_collision[0].collision.y)[self] == '\x03') ||
      ((&comp_collision[0].collision.y)[self] == '\b')) {
    uint8_t_ffffcc70 = '\0';
  }
  (&comp_collision[0].collision.y)[self] = '\x01';
  *(short *)((int)&player_collision_offset[0].y + self) = 0x10 - param_2;
  (&component_collision_flags)[self] = (&component_collision_flags)[self] | 8;
  return;
}

void FUN_00016e4c(void)

{
  return;
}

void FUN_00016e4e(void)

{
  byte bVar1;
  short in_D0w;
  int unaff_A4;

  *(short *)((int)&player_collision_offset[0].y + unaff_A4) = 0x10 - in_D0w;
  (&component_collision_flags)[unaff_A4] =
      (&component_collision_flags)[unaff_A4] | 8;
  bVar1 = uint8_t_ffffcc70;
  if (((unaff_A4 == 0) && (comp_collision[0].collision.y == '\0')) &&
      (-1 < (char)uint8_t_ffffcc70)) {
    comp_collision[0].collision.y = '\x03';
    bVar1 = uint8_t_ffffcc70 | 2;
    if ((comp_state_a & ENTITY_STATE_A_08) != 0) {
      bVar1 = uint8_t_ffffcc70 | 0x82;
    }
  }
  uint8_t_ffffcc70 = bVar1;
  return;
}

void FUN_00016e8a(void)

{
  return;
}

void FUN_00016e8c(void)

{
  byte bVar1;
  int unaff_A4;

  bVar1 = uint8_t_ffffcc70;
  if (((unaff_A4 == 0) && (comp_collision[0].collision.y == '\0')) &&
      (-1 < (char)uint8_t_ffffcc70)) {
    comp_collision[0].collision.y = '\b';
    bVar1 = uint8_t_ffffcc70 | 2;
    if ((comp_state_a & ENTITY_STATE_A_08) != 0) {
      bVar1 = uint8_t_ffffcc70 | 0x82;
    }
  }
  uint8_t_ffffcc70 = bVar1;
  return;
}

void FUN_00016f1c(void)

{
  return;
}

void related_to_entity_collision_y_3(void)

{
  short in_D0w;
  int unaff_A4;

  if (((&comp_collision[0].collision.y)[unaff_A4] == '\b') ||
      ((&comp_collision[0].collision.y)[unaff_A4] == '\x03')) {
    uint8_t_ffffcc70 = '\0';
  }
  (&comp_collision[0].collision.y)[unaff_A4] = '\x01';
  *(short *)((int)&player_collision_offset[0].y + unaff_A4) = -in_D0w;
  (&component_collision_flags)[unaff_A4] =
      (&component_collision_flags)[unaff_A4] | 4;
  return;
}

void FUN_00016f48(void)

{
  return;
}

void FUN_00016f4a(void)

{
  byte bVar1;
  short in_D0w;
  int unaff_A4;

  *(short *)((int)&player_collision_offset[0].y + unaff_A4) = -in_D0w;
  (&component_collision_flags)[unaff_A4] =
      (&component_collision_flags)[unaff_A4] | 4;
  bVar1 = uint8_t_ffffcc70;
  if ((unaff_A4 == 0) && (comp_collision[0].collision.y == '\0')) {
    if ((char)uint8_t_ffffcc70 < '\0') {
      comp_collision[0].collision.y = '\x01';
      player_collision_offset[0].y = -in_D0w;
      component_collision_flags = component_collision_flags | 4;
      return;
    }
    comp_collision[0].collision.y = '\x03';
    bVar1 = uint8_t_ffffcc70 | 2;
    if ((comp_state_a & ENTITY_STATE_A_08) != 0) {
      bVar1 = uint8_t_ffffcc70 | 0x82;
    }
  }
  uint8_t_ffffcc70 = bVar1;
  return;
}

void FUN_00016f9c(void)

{
  short in_D0w;
  int unaff_A4;

  if ((&comp_collision[0].collision.y)[unaff_A4] != '\x01') {
    (&comp_collision[0].collision.y)[unaff_A4] = '\x04';
    *(short *)((int)&player_collision_offset[0].y + unaff_A4) = -in_D0w;
    (&component_collision_flags)[unaff_A4] =
        (&component_collision_flags)[unaff_A4] | 4;
  }
  return;
}

void FUN_00016fba(void)

{
  byte bVar1;
  short in_D0w;
  int unaff_A4;

  bVar1 = uint8_t_ffffcc70;
  if ((unaff_A4 == 0) && (comp_collision[0].collision.y == '\0')) {
    if ((char)uint8_t_ffffcc70 < '\0') {
      comp_collision[0].collision.y = '\x01';
      player_collision_offset[0].y = -in_D0w;
      component_collision_flags = component_collision_flags | 4;
      return;
    }
    comp_collision[0].collision.y = '\b';
    bVar1 = uint8_t_ffffcc70 | 2;
    if ((comp_state_a & ENTITY_STATE_A_08) != 0) {
      bVar1 = uint8_t_ffffcc70 | 0x82;
    }
  }
  uint8_t_ffffcc70 = bVar1;
  return;
}

void FUN_00016ffe(void)

{
  short in_D0w;
  int unaff_A4;

  if (((&comp_collision[0].collision.y)[unaff_A4] == '\b') ||
      ((&comp_collision[0].collision.y)[unaff_A4] == '\x03')) {
    uint8_t_ffffcc70 = '\0';
  }
  (&comp_collision[0].collision.y)[unaff_A4] = '\f';
  *(short *)((int)&player_collision_offset[0].y + unaff_A4) = -in_D0w;
  (&component_collision_flags)[unaff_A4] =
      (&component_collision_flags)[unaff_A4] | 4;
  return;
}

void FUN_00017028(void)

{
  short in_D0w;
  int unaff_A4;

  if (((&comp_collision[0].collision.y)[unaff_A4] == '\b') ||
      ((&comp_collision[0].collision.y)[unaff_A4] == '\x03')) {
    uint8_t_ffffcc70 = '\0';
  }
  (&comp_collision[0].collision.y)[unaff_A4] = '\r';
  *(short *)((int)&player_collision_offset[0].y + unaff_A4) = -in_D0w;
  (&component_collision_flags)[unaff_A4] =
      (&component_collision_flags)[unaff_A4] | 4;
  return;
}

void FUN_00017052(void)

{
  short in_D0w;
  int unaff_A4;

  if ((&comp_collision[0].collision.y)[unaff_A4] != '\x01') {
    (&comp_collision[0].collision.y)[unaff_A4] = '\x0e';
    *(short *)((int)&player_collision_offset[0].y + unaff_A4) = -in_D0w;
    (&component_collision_flags)[unaff_A4] =
        (&component_collision_flags)[unaff_A4] | 4;
  }
  return;
}

int related_to_entity_collision_y_2(word sensor_y, word sensor_x, short param_3,
                                    short param_4)

{
  short sVar1;
  word wVar2;
  int extraout_A1;

  sVar1 = ((ushort)(param_3 + -1 + sensor_x) >> 4) - (sensor_x >> 4);
  while (true) {
    wVar2 = FUN_00017330(sensor_x, sensor_y);
    if ((*(char *)(extraout_A1 + (short)wVar2) != '\0') ||
        (sVar1 = sVar1 + -1, sVar1 == -1))
      break;
    sensor_x = sensor_x + 0x10;
  }
  return extraout_A1;
}

ushort FUN_0001708c(short param_1, short param_2, word param_3, word param_4)

{
  ushort extraout_D0w;
  word wVar1;
  int extraout_A1;

  do {
    param_3 = param_3 + 0x10;
    wVar1 = FUN_00017330(param_3, param_4);
    if (*(char *)(extraout_A1 + (short)wVar1) != '\0')
      break;
    param_1 = param_1 + -1;
  } while (param_1 != -1);
  return extraout_D0w & 0xf;
}

void related_to_entity_collision_x(ulong ctx, short param_2, word param_3,
                                   word param_4)

{
  short sVar1;
  short sVar2;

  sVar1 = *(short *)((int)&comp_collision_sensor[0].y + ctx) * 2;
  if (*(uint *)((int)&comp_pos_x + ctx) ==
      *(uint *)((int)component_pos_old_x + ctx)) {
    return;
  }
  if (*(uint *)((int)component_pos_old_x + ctx) <=
      *(uint *)((int)&comp_pos_x + ctx)) {
    sVar2 = *(short *)((int)&comp_collision_sensor[0].y + ctx);
    FUN_000172f6(param_2 - sVar2,
                 *(short *)((int)&comp_collision_sensor[0].x + ctx) +
                     *(short *)((int)&comp_pos_x + ctx),
                 sVar1,
                 sVar2);
    while (true) {
      if (sVar1 < 0) {
        if (sVar2 != 0) {
          (*(code *)((int)&WORD_00017210 +
                     (int)*(short *)((int)&WORD_00017210 +
                                     (int)(short)(sVar2 * 2))))();
        }
        return;
      }
      sVar2 = sVar2 * 2;
      (*(code *)((int)&WORD_00017210 +
                 (int)*(short *)((int)&WORD_00017210 + (int)sVar2)))();
      sVar1 = sVar1 + -1;
      if (sVar1 < 0)
        break;
      FUN_00017312(sVar1, sVar2, param_3, param_4);
    }
    return;
  }
  ecs_moved_left(ctx, param_2, sVar1, param_3, param_4);
  return;
}

void ecs_moved_left(entity_id_t self, short param_2, short param_3,
                    word param_4, word param_5)

{
  short sVar1;

  sVar1 = *(short *)((int)&comp_collision_sensor[0].y + self);
  FUN_000172f6(param_2 - sVar1,
               *(short *)((int)&comp_pos_x + self) -
                   *(short *)((int)&comp_collision_sensor[0].x + self),
               param_3,
               sVar1);
  while (true) {
    if (param_3 < 0) {
      if (sVar1 != 0) {
        (*(code *)((int)&WORD_00017104 +
                   (int)*(short *)((int)&WORD_00017104 +
                                   (int)(short)(sVar1 * 2))))();
      }
      return;
    }
    sVar1 = sVar1 * 2;
    // Can jump to #17126
    (*(code *)((int)&WORD_00017104 +
               (int)*(short *)((int)&WORD_00017104 + (int)sVar1)))();
    param_3 = param_3 + -1;
    if (param_3 < 0)
      break;
    FUN_00017312(param_3, sVar1, param_4, param_5);
  }
  return;
}

void FUN_00017124(void)

{
  return;
}

void ecs_moved_left_2(entity_id_t param_1, short param_2)

{
  if (((&comp_collision[0].collision.x)[param_1] == '\b') ||
      ((&comp_collision[0].collision.x)[param_1] == '\x03')) {
    uint8_t_ffffcc70 = '\0';
  }
  (&comp_collision[0].collision.x)[param_1] = '\x01';
  *(short *)((int)&player_collision_offset[0].x + param_1) = 0x10 - param_2;
  (&component_collision_flags)[param_1] =
      (&component_collision_flags)[param_1] | 2;
  return;
}

void FUN_00017150(void)

{
  return;
}

void FUN_00017152(void)

{
  short in_D1w;
  int unaff_A4;

  *(short *)((int)&player_collision_offset[0].x + unaff_A4) = 0x10 - in_D1w;
  (&component_collision_flags)[unaff_A4] =
      (&component_collision_flags)[unaff_A4] | 2;
  if (unaff_A4 == 0) {
    if ((char)uint8_t_ffffcc70 < '\0') {
      comp_collision[0].collision.x = '\x01';
      player_collision_offset[0].x = 0x10 - in_D1w;
      component_collision_flags = component_collision_flags | 2;
      return;
    }
    if (comp_collision[0].collision.x == '\0') {
      uint8_t_ffffcc70 = uint8_t_ffffcc70 | 2;
      comp_collision[0].collision.x = '\x03';
    }
  }
  return;
}

void FUN_00017196(void)

{
  return;
}

void FUN_00017198(void)

{
  short in_D1w;
  int unaff_A4;

  if (unaff_A4 == 0) {
    if ((char)uint8_t_ffffcc70 < '\0') {
      comp_collision[0].collision.x = '\x01';
      player_collision_offset[0].x = 0x10 - in_D1w;
      component_collision_flags = component_collision_flags | 2;
      return;
    }
    if (comp_collision[0].collision.x == '\0') {
      uint8_t_ffffcc70 = uint8_t_ffffcc70 | 2;
      comp_collision[0].collision.x = '\b';
    }
  }
  return;
}

void ecs_moved_right(entity_id_t self, short param_2, short param_3,
                     word param_4, word param_5)

{
  short sVar1;

  sVar1 = *(short *)((int)&comp_collision_sensor[0].y + self);
  FUN_000172f6(param_2 - sVar1,
               *(short *)((int)&comp_collision_sensor[0].x + self) +
                   *(short *)((int)&comp_pos_x + self),
               param_3,
               sVar1);
  while (true) {
    if (param_3 < 0) {
      if (sVar1 != 0) {
        (*(code *)((int)&WORD_00017210 +
                   (int)*(short *)((int)&WORD_00017210 +
                                   (int)(short)(sVar1 * 2))))();
      }
      return;
    }
    sVar1 = sVar1 * 2;
    (*(code *)((int)&WORD_00017210 +
               (int)*(short *)((int)&WORD_00017210 + (int)sVar1)))();
    param_3 = param_3 + -1;
    if (param_3 < 0)
      break;
    FUN_00017312(param_3, sVar1, param_4, param_5);
  }
  return;
}

void FUN_00017230(void)

{
  return;
}

void ecs_moved_right_2(entity_id_t param_1, short param_2)

{
  if (((&comp_collision[0].collision.x)[param_1] == '\b') ||
      ((&comp_collision[0].collision.x)[param_1] == '\x03')) {
    uint8_t_ffffcc70 = '\0';
  }
  (&comp_collision[0].collision.x)[param_1] = '\x01';
  *(short *)((int)&player_collision_offset[0].x + param_1) = -param_2;
  (&component_collision_flags)[param_1] =
      (&component_collision_flags)[param_1] | 1;
  return;
}

void FUN_0001725c(void)

{
  return;
}

void FUN_0001725e(void)

{
  short in_D1w;
  int unaff_A4;

  *(short *)((int)&player_collision_offset[0].x + unaff_A4) = -in_D1w;
  (&component_collision_flags)[unaff_A4] =
      (&component_collision_flags)[unaff_A4] | 1;
  if (((unaff_A4 == 0) && (-1 < (char)uint8_t_ffffcc70)) &&
      (comp_collision[0].collision.x == '\0')) {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x82;
    comp_collision[0].collision.x = '\x03';
    player_collision_offset[0].x = -in_D1w;
    component_collision_flags = component_collision_flags | 1;
  }
  return;
}

void FUN_0001729a(void)

{
  short in_D1w;
  int unaff_A4;

  (&comp_collision[0].collision.x)[unaff_A4] = '\x01';
  *(short *)((int)&player_collision_offset[0].x + unaff_A4) = -in_D1w;
  (&component_collision_flags)[unaff_A4] =
      (&component_collision_flags)[unaff_A4] | 1;
  return;
}

void FUN_000172b0(void)

{
  return;
}

void FUN_000172b2(void)

{
  short in_D1w;
  int unaff_A4;

  if (((unaff_A4 == 0) && (-1 < (char)uint8_t_ffffcc70)) &&
      (comp_collision[0].collision.x == '\0')) {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x82;
    comp_collision[0].collision.x = '\b';
    player_collision_offset[0].x = -in_D1w;
    component_collision_flags = component_collision_flags | 1;
  }
  return;
}

void FUN_000172e0(void)

{
  short in_D1w;
  int unaff_A4;

  (&comp_collision[0].collision.x)[unaff_A4] = '\x01';
  *(short *)((int)&player_collision_offset[0].x + unaff_A4) = -in_D1w;
  (&component_collision_flags)[unaff_A4] =
      (&component_collision_flags)[unaff_A4] | 1;
  return;
}

int FUN_000172f6(word param_1, word param_2, short param_3, short param_4)

{
  short sVar1;
  word wVar2;
  int extraout_A1;

  sVar1 = ((ushort)(param_3 + -1 + param_1) >> 4) - (param_1 >> 4);
  while (true) {
    wVar2 = FUN_00017330(param_2, param_1);
    if ((*(char *)(extraout_A1 + (short)wVar2) != '\0') ||
        (sVar1 = sVar1 + -1, sVar1 == -1))
      break;
    param_1 = param_1 + 0x10;
  }
  return extraout_A1;
}

int FUN_00017312(short param_1, short param_2, word param_3, word param_4)

{
  word wVar1;
  int extraout_A1;

  do {
    param_4 = param_4 + 0x10;
    wVar1 = FUN_00017330(param_3, param_4);
    if (*(char *)(extraout_A1 + (short)wVar1) != '\0') {
      return extraout_A1;
    }
    param_1 = param_1 + -1;
  } while (param_1 != -1);
  return extraout_A1;
}

word FUN_00017330(word param_1, word param_2)

{
  word wVar1;
  word wVar2;

  wVar1 = room_boundary_x;
  // Max or min D4w to 0x1000
  if ((param_1 < room_boundary_x) && (wVar1 = param_1, param_1 < 0x1000)) {
    wVar1 = 0x1000;
  }
  wVar2 = camera_pos_x_int;
  if ((param_2 < camera_pos_x_int) && (wVar2 = param_2, param_2 < 0x1000)) {
    wVar2 = 0x1000;
  }
  return *(ushort *)(DAT_ffffc722 +
                     (short)(((ushort)(wVar1 - 0x1000) >> 4) * 2 +
                             ((wVar2 - 0x1000 & 0xfff0)
                              << (DAT_ffffc717 & 0x3f)))) &
         0x3ff;
}

void ecs_apply_collision(ulong entity)

{
  player_update_vel_old(entity);
  if (((&component_collision_flags)[entity] & COLLISION_FLAGS_LEFT) != 0) {
    player_collision_right(entity);
  }
  if (((&component_collision_flags)[entity] & COLLISION_FLAGS_RIGHT) != 0) {
    player_collision_left(entity);
  }
  if (((&component_collision_flags)[entity] & COLLISION_FLAGS_FLOOR) != 0) {
    player_collision_floor(entity);
  }
  if (((&component_collision_flags)[entity] & COLLISION_FLAGS_CEIL) != 0) {
    player_collision_ceil(entity);
    if (*(short *)((int)&comp_vel[0].y + entity) < 0) {
      *(undefined2 *)((int)&comp_vel[0].y + entity) = 0;
    }
  }
  return;
}

void player_collision_right(ulong ctx)

{
  *(short *)((int)&comp_pos_x + ctx) =
      *(short *)((int)&player_collision_offset[0].x + ctx) +
      *(short *)((int)&comp_pos_x + ctx);
  *(short *)((int)&component_vel_old[0].x + ctx) =
      *(short *)((int)&comp_pos_x + ctx) -
      *(short *)((int)component_pos_old_x + ctx);
  *(undefined2 *)((int)&comp_pos_x + ctx + 2) = 0x8000;
  *(undefined2 *)((int)component_pos_old_x + ctx + 2) = 0x8000;
  *(undefined2 *)((int)&comp_vel[0].x + ctx) = 0;
  return;
}

void player_collision_left(ulong ctx)

{
  *(short *)((int)&comp_pos_x + ctx) =
      *(short *)((int)&player_collision_offset[0].x + ctx) +
      *(short *)((int)&comp_pos_x + ctx);
  *(short *)((int)&component_vel_old[0].x + ctx) =
      *(short *)((int)&comp_pos_x + ctx) -
      *(short *)((int)component_pos_old_x + ctx);
  *(undefined2 *)((int)&comp_pos_x + ctx + 2) = 0x8000;
  *(undefined2 *)((int)component_pos_old_x + ctx + 2) = 0x8000;
  *(undefined2 *)((int)&comp_vel[0].x + ctx) = 0;
  return;
}

void player_collision_floor(ulong ctx)

{
  short sVar1;
  ushort collision_offset_y;
  short vel_old_y;

  collision_offset_y = *(ushort *)((int)&player_collision_offset[0].y + ctx);
  if ((collision_offset_y != 0) && (-1 < (short)collision_offset_y)) {
  clear_floor_collision:
    (&component_collision_flags)[ctx] =
        (&component_collision_flags)[ctx] & 0xfb;
    return;
  }
  vel_old_y = *(short *)((int)&component_vel_old[0].y + ctx);
  if (vel_old_y == 0) {
    if (collision_offset_y != *(ushort *)((int)&component_vel_old[0].y + ctx))
      goto clear_floor_collision;
  } else if ((vel_old_y < 0) || (collision_offset_y <= (ushort)-vel_old_y &&
                                 (ushort)-collision_offset_y != vel_old_y))
    goto clear_floor_collision;
  if (-1 < *(short *)((int)&comp_vel[0].y + ctx)) {
    *(undefined2 *)((int)&comp_vel[0].y + ctx) = 0;
  }
  *(short *)((int)&comp_pos_y + ctx) =
      collision_offset_y + *(short *)((int)&comp_pos_y + ctx);
  vel_old_y = *(short *)((int)&comp_pos_y + ctx);
  sVar1 = *(short *)((int)component_pos_old_y + ctx);
  *(undefined2 *)((int)&comp_pos_y + ctx + 2) = 0;
  *(undefined2 *)((int)component_pos_old_y + ctx + 2) = 0;
  *(short *)((int)&component_vel_old[0].y + ctx) = vel_old_y - sVar1;
  FUN_00017466();
  return;
}

void FUN_00017466(void)

{
  short sVar1;
  int unaff_A4;

  if (((&component_unknown_6)[unaff_A4] & 2) != 0) {
    sVar1 = *(short *)((int)&component_unknown_9 + unaff_A4);
    if ((short)(*(short *)((int)&comp_pos_x + unaff_A4) -
                *(short *)(&DAT_ffffd1da + sVar1)) < 0) {
      if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
        if ((((&component_unknown_6)[unaff_A4] & 4) == 0) &&
            (((&DAT_ffffd29d)[sVar1] & 4) == 0)) {
          (&component_unknown_6)[unaff_A4] =
              (&component_unknown_6)[unaff_A4] & 0xfd;
        } else if (-1 < *(short *)(&DAT_ffffd21a + sVar1)) {
          (&component_unknown_6)[unaff_A4] =
              (&component_unknown_6)[unaff_A4] & 0xfd;
        }
      }
    } else if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) == 0) {
      if ((((&component_unknown_6)[unaff_A4] & 4) == 0) &&
          (((&DAT_ffffd29d)[sVar1] & 4) == 0)) {
        (&component_unknown_6)[unaff_A4] =
            (&component_unknown_6)[unaff_A4] & 0xfd;
      } else if (*(short *)(&DAT_ffffd21a + sVar1) < 1) {
        (&component_unknown_6)[unaff_A4] =
            (&component_unknown_6)[unaff_A4] & 0xfd;
      }
    }
  }
  return;
}

void player_collision_ceil(ulong ctx)

{
  short sVar1;

  *(short *)((int)&comp_pos_y + ctx) =
      *(short *)((int)&player_collision_offset[0].y + ctx) +
      *(short *)((int)&comp_pos_y + ctx);
  *(undefined2 *)((int)&comp_pos_y + ctx + 2) = 0x8000;
  sVar1 = *(short *)((int)&comp_pos_y + ctx);
  *(undefined2 *)((int)&comp_pos_y + ctx + 2) = 0;
  *(undefined2 *)((int)component_pos_old_y + ctx + 2) = 0;
  *(short *)((int)&component_vel_old[0].y + ctx) =
      sVar1 - *(short *)((int)component_pos_old_y + ctx);
  return;
}

void FUN_00017500(void)

{
  short sVar1;
  int iVar2;

  iVar2 = 0;
  sVar1 = 0xf;
  do {
    (&DAT_ffffd19a)[iVar2] = 0;
    iVar2 = iVar2 + 4;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return;
}

void interact_with_all_other_entities(entity_id_t e, short param_2,
                                      char param_3)

{
  short sVar1;
  int iVar2;
  entity_id_t other;

  (&component_unknown_12)[e] = (&component_unknown_12)[e] << 1;
  (&component_unknown_6)[e] = (&component_unknown_6)[e] & 0xfb;
  if (((&component_unknown_6)[e] & 2) != 0) {
    (&component_unknown_6)[e] = (&component_unknown_6)[e] | 4;
  }
  (&component_unknown_5)[e] = 0;
  FUN_000175c0(e, param_2, param_3);
  other = ENTITY_ID_ASHA;
  sVar1 = 0xf;
  do {
    if ((((e != (int)*(short *)((int)&DAT_ffffd29a + other)) &&
          ((&DAT_ffffd19b)[other] == '\0')) &&
         ((char)(&DAT_ffffd19a)[other] < '\0')) &&
        ((e == ENTITY_ID_ASHA || (((&DAT_ffffd19a)[other] & 2) == 0)))) {
      iVar2 = (int)*(short *)((int)&DAT_ffffd29a + other);
      DAT_ffffd2da = *(short *)((int)&comp_pos_x + iVar2) -
                     *(short *)((int)component_pos_old_x + iVar2);
      DAT_ffffd2dc = *(short *)((int)&comp_pos_y + iVar2) -
                     *(short *)((int)component_pos_old_y + iVar2);
      if (((&DAT_ffffd19a)[other] & 1) == 0) {
        FUN_00017612(e, other, param_2);
      } else {
        FUN_0001763a(e, other, param_2);
      }
    }
    other = other + ENTITY_ID_PEPELOGOO;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  if (((((&component_unknown_12)[e] & 7) == 6) ||
       (((&component_unknown_12)[e] & 7) == 2)) &&
      ((-1 < *(short *)((int)&comp_vel[0].y + e) &&
        (*(ushort *)((int)&comp_vel[0].y + e) < 0x100)))) {
    *(undefined2 *)((int)&comp_vel[0].y + e) = 0x100;
  }
  return;
}

void FUN_000175c0(entity_id_t e, short param_2, char param_3)

{
  entity_id_t other;

  if (((&component_unknown_6)[e] & 2) != 0) {
    other = (entity_id_t) * (short *)((int)&component_unknown_9 + e);
    (&DAT_ffffd29c)[other] = 0;
    if ((char)(&DAT_ffffd19a)[other] < '\0') {
      *(short *)((int)&comp_pos_x + e) =
          *(short *)(&DAT_ffffd21a + other) + *(short *)((int)&comp_pos_x + e);
      *(short *)((int)&component_vel_old[0].x + e) =
          *(short *)((int)&comp_pos_x + e) -
          *(short *)((int)component_pos_old_x + e);
      *(short *)((int)&comp_pos_y + e) =
          *(short *)(&DAT_ffffd21c + other) + *(short *)((int)&comp_pos_y + e);
      *(short *)((int)&component_vel_old[0].y + e) =
          *(short *)((int)&comp_pos_y + e) -
          *(short *)((int)component_pos_old_y + e);
      *(undefined2 *)((int)&comp_pos_y + e + 2) = 0;
      FUN_000176d4(e, other, param_2);
      if (param_3 == '\0') {
        (&component_unknown_6)[e] = (&component_unknown_6)[e] & 0xfd;
      }
    }
  }
  return;
}

void FUN_00017612(entity_id_t e, entity_id_t other, short param_3)

{
  if (((((&component_unknown_6)[e] & 2) == 0) ||
       ((short)other != *(short *)((int)&component_unknown_9 + e))) &&
      (-1 < (short)((*(short *)((int)&comp_pos_y + e) -
                     *(short *)((int)component_pos_old_y + e)) -
                    *(short *)(&DAT_ffffd21c + other)))) {
    FUN_000176d4(e, other, param_3);
    return;
  }
  return;
}

short FUN_0001763a(entity_id_t e, entity_id_t other, short param_3)

{
  short *psVar1;
  short extraout_D0w;
  short sVar2;
  bool bVar3;

  if ((e == ENTITY_ID_PEPELOGOO) &&
      ((&comp_collision_related)[*(short *)((int)&DAT_ffffd29a + other)] ==
       '\b')) {
    FUN_00017728(ENTITY_ID_PEPELOGOO, other, param_3);
    return extraout_D0w;
  }
  if ((((&component_unknown_6)[e] & 2) != 0) &&
      ((short)other == *(short *)((int)&component_unknown_9 + e))) {
    return *(short *)((int)&component_unknown_9 + e);
  }
  if ((short)((*(short *)((int)&comp_pos_y + e) -
               *(short *)((int)component_pos_old_y + e)) -
              *(short *)(&DAT_ffffd21c + other)) < 0) {
    FUN_00017782(e, other);
  } else {
    FUN_000176d4(e, other, param_3);
  }
  sVar2 = *(short *)((int)&comp_pos_x + e) -
          *(short *)((int)component_pos_old_x + e);
  if (sVar2 == DAT_ffffd2da) {
    psVar1 = (short *)((int)&comp_vel[0].x + e);
    bVar3 = *psVar1 < 0;
    if (*psVar1 != 0) {
      if (bVar3)
        goto LAB_000176b8;
      if (!bVar3)
        goto LAB_000176b2;
    }
    if (DAT_ffffd2da == 0) {
      return 0;
    }
    if (-1 < DAT_ffffd2da)
      goto LAB_000176b8;
  } else if ((short)(sVar2 - DAT_ffffd2da) < 0) {
  LAB_000176b8:
    sVar2 = FUN_000177de();
    return sVar2;
  }
LAB_000176b2:
  sVar2 = FUN_000177b2();
  return sVar2;
}

void FUN_000176d4(entity_id_t e, entity_id_t other, short param_3)

{
  ushort uVar1;
  short sVar2;
  bool bVar3;
  bool bVar4;

  if ((((&component_unknown_12)[e] & 7) == 4) &&
      (*(short *)(&DAT_ffffc278 + e) ==
       *(short *)((int)&DAT_ffffd29a + other))) {
    return;
  }
  if ((e != ENTITY_ID_PEPELOGOO) || ((pepelogoo_state_b & 0x80) == 0)) {
    uVar1 = *(ushort *)((int)&comp_collision_sensor[0].y + e);
    bVar4 = CARRY2(uVar1, *(ushort *)((int)&comp_pos_y + e));
    sVar2 = uVar1 + *(ushort *)((int)&comp_pos_y + e);
    bVar3 = sVar2 == 0;
    FUN_00017864(e, other, sVar2);
    if (bVar4 || bVar3) {
      FUN_00017a80(e, other, param_3);
      if (((&component_unknown_5)[e] & 4) != 0) {
        (&DAT_ffffd29c)[other] = (&DAT_ffffd29c)[other] | 4;
      }
    }
  }
  return;
}

void FUN_00017728(entity_id_t e, entity_id_t other, short param_3)

{
  ushort uVar1;
  short sVar2;
  bool bVar3;
  bool bVar4;

  if ((((&component_unknown_12)[e] & 7) == 4) &&
      (*(short *)(&DAT_ffffc278 + e) ==
       *(short *)((int)&DAT_ffffd29a + other))) {
    return;
  }
  if ((e != ENTITY_ID_PEPELOGOO) ||
      ((comp_vel[1].x.raw == 0 && ((pepelogoo_state_b & 0x80) == 0)))) {
    uVar1 = *(ushort *)((int)&comp_collision_sensor[0].y + e);
    bVar4 = CARRY2(uVar1, *(ushort *)((int)&comp_pos_y + e));
    sVar2 = uVar1 + *(ushort *)((int)&comp_pos_y + e);
    bVar3 = sVar2 == 0;
    FUN_00017864(e, other, sVar2);
    if (bVar4 || bVar3) {
      FUN_00017a80(e, other, param_3);
      if (((&component_unknown_5)[e] & 4) != 0) {
        (&DAT_ffffd29c)[other] = (&DAT_ffffd29c)[other] | 4;
      }
    }
  }
  return;
}

void FUN_00017782(entity_id_t e, entity_id_t other)

{
  ushort uVar1;
  short sVar2;
  bool bVar3;
  bool bVar4;

  uVar1 = *(ushort *)((int)&comp_collision_sensor[0].y + e);
  bVar4 = *(ushort *)((int)&comp_pos_y + e) < uVar1;
  sVar2 = *(ushort *)((int)&comp_pos_y + e) - uVar1;
  bVar3 = sVar2 == 0;
  FUN_00017864(e, other, sVar2);
  if (bVar4 || bVar3) {
    *(short *)(&DAT_ffffc376 + e) = (short)other;
    FUN_00017b24(e, other);
    if (((&component_unknown_5)[e] & 8) != 0) {
      (&DAT_ffffd29c)[other] = (&DAT_ffffd29c)[other] | 8;
    }
  }
  return;
}

void FUN_000177b2(void)

{
  ushort uVar1;
  int unaff_A4;
  int unaff_A5;
  bool bVar2;
  bool bVar3;

  uVar1 = *(ushort *)((int)&comp_collision_sensor[0].x + unaff_A4);
  bVar3 = CARRY2(uVar1, *(ushort *)((int)&comp_pos_x + unaff_A4));
  bVar2 = (ushort)(uVar1 + *(ushort *)((int)&comp_pos_x + unaff_A4)) == 0;
  FUN_0001783a();
  if (bVar3 || bVar2) {
    *(short *)(&DAT_ffffc376 + unaff_A4) = (short)unaff_A5;
    FUN_000178e6();
    (&DAT_ffffd29c)[unaff_A5] = (&DAT_ffffd29c)[unaff_A5] | 1;
    (&component_unknown_5)[unaff_A4] = (&component_unknown_5)[unaff_A4] | 1;
  }
  return;
}

void FUN_000177de(void)

{
  ushort uVar1;
  int unaff_A4;
  int unaff_A5;
  bool bVar2;
  bool bVar3;

  uVar1 = *(ushort *)((int)&comp_collision_sensor[0].x + unaff_A4);
  bVar3 = *(ushort *)((int)&comp_pos_x + unaff_A4) < uVar1;
  bVar2 = *(ushort *)((int)&comp_pos_x + unaff_A4) == uVar1;
  FUN_0001783a();
  if (bVar3 || bVar2) {
    *(short *)(&DAT_ffffc376 + unaff_A4) = (short)unaff_A5;
    FUN_000179b4();
    (&DAT_ffffd29c)[unaff_A5] = (&DAT_ffffd29c)[unaff_A5] | 2;
    (&component_unknown_5)[unaff_A4] = (&component_unknown_5)[unaff_A4] | 2;
  }
  return;
}

ushort FUN_0001780a(void)

{
  ushort uVar1;
  int unaff_A4;
  int unaff_A5;

  uVar1 = *(short *)(&DAT_ffffd1da + unaff_A5) -
          *(short *)((int)&comp_pos_x + unaff_A4);
  if ((short)uVar1 < 0) {
    uVar1 = -uVar1;
  }
  if ((uVar1 <=
       (ushort)(*(short *)(&DAT_ffffd25a + unaff_A5) +
                *(short *)((int)&comp_collision_sensor[0].x + unaff_A4))) &&
      (uVar1 = *(short *)(&DAT_ffffd1dc + unaff_A5) -
               *(short *)((int)&comp_pos_y + unaff_A4),
       (short)uVar1 < 0)) {
    uVar1 = -uVar1;
  }
  return uVar1;
}

void FUN_0001783a(void)

{
  return;
}

word FUN_00017864(entity_id_t e, entity_id_t other, short param_3)

{
  word wVar1;

  wVar1 = *(short *)(&DAT_ffffd1da + other) - *(short *)((int)&comp_pos_x + e);
  if ((short)wVar1 < 0) {
    wVar1 = -wVar1;
  }
  if ((wVar1 <= (ushort)((*(short *)(&DAT_ffffd25a + other) +
                          *(short *)((int)&comp_collision_sensor[0].x + e)) -
                         1U)) &&
      (wVar1 = *(short *)(&DAT_ffffd1dc + other) - param_3, (short)wVar1 < 0)) {
    wVar1 = -wVar1;
  }
  return wVar1;
}

void FUN_00017896(void)

{
  short sVar1;
  short unaff_D2w;
  entity_id_t e;
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;
  undefined2 uVar2;

  if (((&component_unknown_5)[unaff_A4] & 0xf) != 0) {
    uVar2 = (undefined2)unaff_A5;
    if (((&component_unknown_5)[unaff_A4] & 4) != 0) {
      *(undefined2 *)(&DAT_ffffc376 + unaff_A4) = uVar2;
      *(undefined2 *)((int)&component_unknown_9 + unaff_A4) = uVar2;
      FUN_00017a80(unaff_A4, unaff_A5, unaff_D2w);
    }
    if (((&component_unknown_5)[unaff_A4] & 8) != 0) {
      *(undefined2 *)(&DAT_ffffc376 + unaff_A4) = uVar2;
      if (((&component_unknown_5)[unaff_A4] & 4) == 0) {
        sVar1 = *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
        FUN_00017bf6(
            unaff_A4,
            (*(short *)(&DAT_ffffd25c + unaff_A5) +
             *(short *)(&DAT_ffffd1dc + unaff_A5)) -
                ((*(short *)((int)&comp_pos_y + unaff_A4) - sVar1) + -1),
            *(short *)((int)&component_vel_old[0].y + unaff_A4) + -1);
        if ((char)sVar1 != '\0') {
          if ((short)unaff_A4 == 0) {
            e = (entity_id_t) * (short *)((int)&DAT_ffffd29a + unaff_A5);
            FUN_00017b82(e);
            FUN_00017ba0(e);
            FUN_00017bb8(e);
          }
          (&component_unknown_5)[unaff_A4] =
              (&component_unknown_5)[unaff_A4] | 8;
          if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
            *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
          }
          *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
          *(undefined2 *)((int)component_pos_old_y + unaff_A4 + 2) = 0;
          return;
        }
      }
      return;
    }
    if (((&component_unknown_5)[unaff_A4] & 1) != 0) {
      *(undefined2 *)(&DAT_ffffc376 + unaff_A4) = uVar2;
      FUN_000178e6();
    }
    if (((&component_unknown_5)[unaff_A4] & 2) != 0) {
      *(undefined2 *)(&DAT_ffffc376 + unaff_A4) = uVar2;
      FUN_000179b4();
    }
  }
  return;
}

void FUN_000178e6(void)

{
  undefined2 uVar1;
  int unaff_A3;
  int unaff_A4;
  int unaff_A5;

  uVar1 = *(undefined2 *)((int)&comp_collision_sensor[0].x + unaff_A4);
  FUN_00017bce();
  if ((char)uVar1 != '\0') {
    if ((short)unaff_A4 == 0) {
      unaff_A3 = (int)*(short *)((int)&DAT_ffffd29a + unaff_A5);
      FUN_0001797e();
      FUN_0001798e();
      FUN_0001799e();
    }
    (&component_unknown_5)[unaff_A4] = (&component_unknown_5)[unaff_A4] | 1;
    if ((((unaff_A3 == 4) && (unaff_A4 == 0)) &&
         (DAT_ffffcc64 = 0xff, comp_collision[0].collision.y != '\r')) &&
        ((DAT_ffffb570 & 4) != 0)) {
      if (comp_vel[0].x.raw < 0x101) {
        comp_vel[1].x = comp_vel[0].x;
      } else {
        comp_vel[1].x.raw = 0x100;
        comp_vel[0].x.raw = 0x100;
      }
    } else if (-1 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    }
    *(undefined2 *)((int)&comp_pos_x + unaff_A4 + 2) = 0x8000;
    *(undefined2 *)((int)component_pos_old_x + unaff_A4 + 2) = 0x8000;
    return;
  }
  return;
}

void FUN_0001797e(void)

{
  int unaff_A3;

  if ((&comp_collision_related)[unaff_A3] == '\x03') {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x82;
  }
  return;
}

void FUN_0001798e(void)

{
  int unaff_A3;

  if ((&comp_collision_related)[unaff_A3] == '\b') {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x82;
  }
  return;
}

void FUN_0001799e(void)

{
  int unaff_A3;

  if ((&comp_collision_related)[unaff_A3] == '\n') {
    DAT_ffffcc93 = 8;
    DAT_ffffcc92 = 1;
  }
  return;
}

void FUN_000179b4(void)

{
  undefined2 uVar1;
  int unaff_A3;
  int unaff_A4;
  int unaff_A5;

  uVar1 = *(undefined2 *)((int)&comp_collision_sensor[0].x + unaff_A4);
  FUN_00017bce();
  if ((char)uVar1 != '\0') {
    if ((short)unaff_A4 == 0) {
      unaff_A3 = (int)*(short *)((int)&DAT_ffffd29a + unaff_A5);
      FUN_00017a4a();
      FUN_00017a5a();
      FUN_00017a6a();
    }
    (&component_unknown_5)[unaff_A4] = (&component_unknown_5)[unaff_A4] | 2;
    if ((((unaff_A3 == 4) && (unaff_A4 == 0)) &&
         (DAT_ffffcc64 = 0xff, comp_collision[0].collision.y != '\r')) &&
        ((DAT_ffffb570 & 4) != 0)) {
      if ((short)comp_vel[0].x < -0x100) {
        comp_vel[1].x.raw = -0x100;
        comp_vel[0].x.raw = -0x100;
      } else {
        comp_vel[1].x = comp_vel[0].x;
      }
    } else if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    }
    *(undefined2 *)((int)&comp_pos_x + unaff_A4 + 2) = 0x8000;
    *(undefined2 *)((int)component_pos_old_x + unaff_A4 + 2) = 0x8000;
    return;
  }
  return;
}

void FUN_00017a4a(void)

{
  int unaff_A3;

  if ((&comp_collision_related)[unaff_A3] == '\x03') {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 2;
  }
  return;
}

void FUN_00017a5a(void)

{
  int unaff_A3;

  if ((&comp_collision_related)[unaff_A3] == '\b') {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 2;
  }
  return;
}

void FUN_00017a6a(void)

{
  int unaff_A3;

  if ((&comp_collision_related)[unaff_A3] == '\n') {
    DAT_ffffcc93 = 8;
    DAT_ffffcc92 = 1;
  }
  return;
}

void FUN_00017a80(entity_id_t e, entity_id_t other, short param_3)

{
  entity_id_t e_00;

  FUN_00017bf6(e,
               -((*(short *)((int)&comp_collision_sensor[0].y + e) +
                  *(short *)((int)&comp_pos_y + e)) -
                 (*(short *)(&DAT_ffffd1dc + other) -
                  *(short *)(&DAT_ffffd25c + other))),
               *(short *)((int)&component_vel_old[0].y + e));
  if (param_3 != 0) {
    if ((short)e == 0) {
      e_00 = (entity_id_t) * (short *)((int)&DAT_ffffd29a + other);
      FUN_00017ad2(e_00);
      FUN_00017af0(e_00);
      FUN_00017b0e(e_00);
    }
    (&component_unknown_5)[e] = (&component_unknown_5)[e] | 4;
    if (-1 < *(short *)((int)&comp_vel[0].y + e)) {
      *(undefined2 *)((int)&comp_vel[0].y + e) = 0;
    }
    *(undefined2 *)((int)&comp_pos_y + e + 2) = 0;
    *(undefined2 *)((int)component_pos_old_y + e + 2) = 0;
    FUN_00017c32(e, other);
    return;
  }
  return;
}

void FUN_00017ad2(entity_id_t e)

{
  byte bVar1;

  bVar1 = uint8_t_ffffcc70;
  if (((&comp_collision_related)[e] == '\x03') &&
      (bVar1 = uint8_t_ffffcc70 | 2, (comp_state_a & ENTITY_STATE_A_08) == 0)) {
    bVar1 = uint8_t_ffffcc70 | 0x82;
  }
  uint8_t_ffffcc70 = bVar1;
  return;
}

void FUN_00017af0(entity_id_t e)

{
  byte bVar1;

  bVar1 = uint8_t_ffffcc70;
  if (((&comp_collision_related)[e] == '\b') &&
      (bVar1 = uint8_t_ffffcc70 | 2, (comp_state_a & ENTITY_STATE_A_08) == 0)) {
    bVar1 = uint8_t_ffffcc70 | 0x82;
  }
  uint8_t_ffffcc70 = bVar1;
  return;
}

void FUN_00017b0e(entity_id_t e)

{
  if ((&comp_collision_related)[e] == '\n') {
    DAT_ffffcc93 = 8;
    DAT_ffffcc92 = 1;
  }
  return;
}

void FUN_00017b24(entity_id_t e, entity_id_t other)

{
  short sVar1;
  entity_id_t e_00;

  if (((&component_unknown_5)[e] & 4) == 0) {
    sVar1 = *(short *)((int)&comp_collision_sensor[0].y + e);
    FUN_00017bf6(e,
                 (*(short *)(&DAT_ffffd25c + other) +
                  *(short *)(&DAT_ffffd1dc + other)) -
                     ((*(short *)((int)&comp_pos_y + e) - sVar1) + -1),
                 *(short *)((int)&component_vel_old[0].y + e) + -1);
    if ((char)sVar1 != '\0') {
      if ((short)e == 0) {
        e_00 = (entity_id_t) * (short *)((int)&DAT_ffffd29a + other);
        FUN_00017b82(e_00);
        FUN_00017ba0(e_00);
        FUN_00017bb8(e_00);
      }
      (&component_unknown_5)[e] = (&component_unknown_5)[e] | 8;
      if (*(short *)((int)&comp_vel[0].y + e) < 0) {
        *(undefined2 *)((int)&comp_vel[0].y + e) = 0;
      }
      *(undefined2 *)((int)&comp_pos_y + e + 2) = 0;
      *(undefined2 *)((int)component_pos_old_y + e + 2) = 0;
      return;
    }
  }
  return;
}

void FUN_00017b82(entity_id_t e)

{
  byte bVar1;

  bVar1 = uint8_t_ffffcc70;
  if (((&comp_collision_related)[e] == '\x03') &&
      (bVar1 = uint8_t_ffffcc70 | 2, (comp_state_a & ENTITY_STATE_A_08) == 0)) {
    bVar1 = uint8_t_ffffcc70 | 0x82;
  }
  uint8_t_ffffcc70 = bVar1;
  return;
}

void FUN_00017ba0(entity_id_t e)

{
  if (((&comp_collision_related)[e] == '\b') &&
      ((comp_state_a & ENTITY_STATE_A_08) == 0)) {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 2;
  }
  return;
}

void FUN_00017bb8(entity_id_t e)

{
  if ((&comp_collision_related)[e] == '\n') {
    DAT_ffffcc93 = 8;
    DAT_ffffcc92 = 1;
  }
  return;
}

void FUN_00017bce(void)

{
  ushort uVar1;
  ushort in_D0w;
  short in_D1w;
  int unaff_A4;

  uVar1 = DAT_ffffd2da - in_D1w;
  if ((short)uVar1 < 0) {
    if (0 < (short)in_D0w) {
      return;
    }
    if ((ushort)-uVar1 < (ushort)-in_D0w) {
      return;
    }
  } else if (uVar1 < in_D0w) {
    return;
  }
  *(short *)((int)&comp_pos_x + unaff_A4) =
      in_D0w + *(short *)((int)&comp_pos_x + unaff_A4);
  return;
}

void FUN_00017bf6(entity_id_t e, ushort param_2, short param_3)

{
  ushort uVar1;

  uVar1 = DAT_ffffd2dc - param_3;
  if ((short)uVar1 < 0) {
    if (0 < (short)param_2) {
      return;
    }
    if ((ushort)-uVar1 < (ushort)-param_2) {
      return;
    }
  } else {
    if ((short)param_2 < 0) {
      return;
    }
    if (uVar1 < param_2) {
      return;
    }
  }
  *(short *)((int)&comp_pos_y + e) = param_2 + *(short *)((int)&comp_pos_y + e);
  if (((short)param_2 < 0) || (*(short *)((int)&comp_vel[0].y + e) < 0)) {
    *(undefined2 *)((int)&comp_vel[0].y + e) = 0;
  }
  return;
}

void FUN_00017c32(entity_id_t e, entity_id_t other)

{
  short sVar1;
  entity_id_w_t other_2;

  other_2 = (entity_id_w_t)other;
  if (((&component_unknown_6)[e] & 2) == 0) {
    if (((&component_collision_flags)[e] & 4) == 0) {
      *(entity_id_w_t *)(&DAT_ffffc376 + e) = other_2;
      *(entity_id_w_t *)((int)&component_unknown_9 + e) = other_2;
      *(undefined2 *)(&DAT_ffffc278 + e) =
          *(undefined2 *)((int)&DAT_ffffd29a + other);
      (&component_unknown_12)[e] = (&component_unknown_12)[e] | 1;
      (&component_unknown_6)[e] = (&component_unknown_6)[e] | 2;
      (&component_unknown_5)[e] = (&component_unknown_5)[e] | 4;
    } else if ((short)(*(short *)(&DAT_ffffd1da + other) -
                       *(short *)((int)&comp_pos_x + e)) < 0) {
      if (*(short *)(&DAT_ffffd21a + other) < 1) {
        *(entity_id_w_t *)(&DAT_ffffc376 + e) = other_2;
        *(entity_id_w_t *)((int)&component_unknown_9 + e) = other_2;
        *(undefined2 *)(&DAT_ffffc278 + e) =
            *(undefined2 *)((int)&DAT_ffffd29a + other);
        (&component_unknown_12)[e] = (&component_unknown_12)[e] | 1;
        (&component_unknown_6)[e] = (&component_unknown_6)[e] | 2;
        (&component_unknown_5)[e] = (&component_unknown_5)[e] | 4;
      }
    } else if (-1 < *(short *)(&DAT_ffffd21a + other)) {
      *(entity_id_w_t *)(&DAT_ffffc376 + e) = other_2;
      *(entity_id_w_t *)((int)&component_unknown_9 + e) = other_2;
      *(undefined2 *)(&DAT_ffffc278 + e) =
          *(undefined2 *)((int)&DAT_ffffd29a + other);
      (&component_unknown_12)[e] = (&component_unknown_12)[e] | 1;
      (&component_unknown_6)[e] = (&component_unknown_6)[e] | 2;
      (&component_unknown_5)[e] = (&component_unknown_5)[e] | 4;
    }
  } else {
    (&component_unknown_12)[e] = (&component_unknown_12)[e] | 1;
    sVar1 = *(short *)((int)&component_unknown_9 + e);
    if ((short)(*(short *)(&DAT_ffffd1da + other) -
                *(short *)(&DAT_ffffd1da + sVar1)) < 0) {
      if ((((&comp_state_a)[e] & ENTITY_STATE_A_08) != 0) &&
          ((((&DAT_ffffd29d)[sVar1] & 4) == 0 ||
            (-1 < (short)(*(short *)(&DAT_ffffd21a + sVar1) -
                          *(short *)(&DAT_ffffd21a + other)))))) {
        *(entity_id_w_t *)(&DAT_ffffc376 + e) = other_2;
        *(entity_id_w_t *)((int)&component_unknown_9 + e) = other_2;
        *(undefined2 *)(&DAT_ffffc278 + e) =
            *(undefined2 *)((int)&DAT_ffffd29a + other);
        (&component_unknown_12)[e] = (&component_unknown_12)[e] | 1;
        (&component_unknown_6)[e] = (&component_unknown_6)[e] | 2;
        (&component_unknown_5)[e] = (&component_unknown_5)[e] | 4;
      }
    } else if (((*(short *)(&DAT_ffffd1da + other) !=
                 *(short *)(&DAT_ffffd1da + sVar1)) &&
                (((&comp_state_a)[e] & ENTITY_STATE_A_08) == 0)) &&
               ((((&DAT_ffffd29d)[sVar1] & 4) == 0 ||
                 ((short)(*(short *)(&DAT_ffffd21a + sVar1) -
                          *(short *)(&DAT_ffffd21a + other)) < 1)))) {
      *(entity_id_w_t *)(&DAT_ffffc376 + e) = other_2;
      *(entity_id_w_t *)((int)&component_unknown_9 + e) = other_2;
      *(undefined2 *)(&DAT_ffffc278 + e) =
          *(undefined2 *)((int)&DAT_ffffd29a + other);
      (&component_unknown_12)[e] = (&component_unknown_12)[e] | 1;
      (&component_unknown_6)[e] = (&component_unknown_6)[e] | 2;
      (&component_unknown_5)[e] = (&component_unknown_5)[e] | 4;
    }
  }
  return;
}

char FUN_00017d6a(entity_id_t self, entity_id_t other, byte param_3)

{
  char extraout_D0b;
  char extraout_D0b_00;
  char extraout_D0b_01;
  char cVar1;
  word wVar2;
  word unaff_D6w;
  word wVar3;
  entity_id_t other_b;

  FUN_00017e76(self, param_3);
  cVar1 = extraout_D0b;
  if (((&comp_func_offset[0].unk4)[self] & 1) == 0) {
    other_b = ENTITY_ID_ASHA;
    wVar3 = 0xf;
    do {
      if (((&DAT_ffffd19b)[other_b] != '\0') &&
          (cVar1 = (&DAT_ffffd19a)[other_b], cVar1 < '\0')) {
        wVar2 = FUN_00017dae(self, other_b);
        (&comp_func_offset[0].unk4)[self] =
            (byte)wVar2 | (&comp_func_offset[0].unk4)[self];
        (&DAT_ffffd29c)[other_b] = (byte)wVar2;
        cVar1 = extraout_D0b_00;
        if (((&comp_func_offset[0].unk4)[self] & 1) != 0) {
          *(short *)((int)&component_unknown_9 + self) = (short)other_b;
          FUN_00017df0(self, other, other_b, unaff_D6w, wVar3);
          return extraout_D0b_01;
        }
      }
      other_b = other_b + ENTITY_ID_PEPELOGOO;
      wVar3 = wVar3 - 1;
    } while (wVar3 != 0xffff);
  }
  return cVar1;
}

word FUN_00017dae(entity_id_t e, entity_id_t other)

{
  word wVar1;
  ushort top_sensor;

  wVar1 = 0;
  top_sensor = *(short *)((int)&comp_pos_y + e) -
               *(short *)((int)&comp_collision_sensor[0].y + e);
  if ((top_sensor <= (ushort)(*(short *)(&DAT_ffffd25c + other) +
                              *(short *)(&DAT_ffffd1dc + other))) &&
      ((ushort)(((*(short *)(&DAT_ffffd25c + other) +
                  *(short *)(&DAT_ffffd1dc + other)) -
                 *(short *)(&DAT_ffffd25c + other)) -
                *(short *)(&DAT_ffffd25c + other)) <= top_sensor)) {
    if ((*(ushort *)((int)&comp_pos_x + e) <=
         (ushort)(*(short *)(&DAT_ffffd25a + other) +
                  *(short *)(&DAT_ffffd1da + other))) &&
        ((ushort)(((*(short *)(&DAT_ffffd25a + other) +
                    *(short *)(&DAT_ffffd1da + other)) -
                   *(short *)(&DAT_ffffd25a + other)) -
                  *(short *)(&DAT_ffffd25a + other)) <=
         *(ushort *)((int)&comp_pos_x + e))) {
      wVar1 = 1;
    }
  }
  return wVar1;
}

void FUN_00017df0(entity_id_t self, entity_id_t other_a, entity_id_t other_b,
                  word param_4, word param_5)

{
  *(undefined2 *)((int)&comp_pos_x + self) =
      *(undefined2 *)(&DAT_ffffd1da + other_b);
  (&comp_anim_b)[self] = 0;
  *(undefined2 *)((int)&comp_state + self) = 0xe;
  ecs_anim_unk_2(self, (anim_item_t *)other_a, 10);
  DAT_ffffd16c = 2;
  DAT_ffffd176 = *(undefined2 *)((int)&comp_pos_x + self);
  WORD_ffffd178 = *(word *)((int)&comp_pos_y + self);
  if (*(short *)((int)&comp_vel[0].x + self) < 0) {
    ecs_held_rope_side = -1;
  } else {
    ecs_held_rope_side = '\x01';
  }
  *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + self) = 0;
  FUN_00017f90(self, param_4, param_5);
  if ((&comp_collision[0].collision.x)[self] == '\x01') {
    *(short *)((int)&comp_pos_x + self) =
        *(short *)((int)&comp_pos_x + self) + -8;
    (&comp_state_a)[self] = (&comp_state_a)[self] & ~ENTITY_STATE_A_08;
  } else {
    FUN_00017f76(self);
    if ((&comp_collision[0].collision.x)[self] != '\x01') {
      return;
    }
    *(short *)((int)&comp_pos_x + self) =
        *(short *)((int)&comp_pos_x + self) + 8;
    (&comp_state_a)[self] = (&comp_state_a)[self] | ENTITY_STATE_A_08;
  }
  *(undefined2 *)((int)&comp_state + self) = 0xc;
  ecs_anim_unk_2(self, (anim_item_t *)other_a, 0xc);
  return;
}

void FUN_00017e76(entity_id_t self, uint8_t value)

{
  short sVar1;
  byte bVar2;
  int iVar3;

  bVar2 = (&comp_func_offset[0].unk4)[self] * '\x02';
  (&comp_func_offset[0].unk4)[self] = bVar2;
  if ((bVar2 & 2) != 0) {
    iVar3 = (int)*(short *)((int)&component_unknown_9 + self);
    *(short *)((int)&comp_vel[0].x + self) = *(short *)(&DAT_ffffd21a + iVar3)
                                             << 8;
    *(short *)((int)&comp_vel[0].y + self) = *(short *)(&DAT_ffffd21c + iVar3)
                                             << 8;
    sVar1 = *(short *)((int)&DAT_ffffd29a + iVar3);
    ecs_check_collides_x_2(self, (int)sVar1);
    (&comp_func_offset[0].unk4)[self] =
        value | (&comp_func_offset[0].unk4)[self];
    DAT_ffffd176 = *(undefined2 *)((int)&comp_pos_x + (int)sVar1);
    player_vel_unknown_x_1 = 7;
  }
  return;
}

undefined2 ecs_check_collides_x_2(entity_id_t e, entity_id_t other)

{
  undefined4 uVar1;

  uVar1 = ecs_check_collides_x(e, other);
  return (short)((uint)uVar1 >> 0x10);
}

void FUN_00017ec4(void)

{
  ushort uVar1;
  char unaff_D4b;
  ulong unaff_A4;

  player_update_vel_old(unaff_A4);
  (&component_collision_flags)[unaff_A4] = 0;
  FUN_00017efa();
  if (((unaff_D4b == '\x01') || (unaff_D4b == '\x04')) &&
      (uVar1 = *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
                   *(short *)((int)&comp_pos_y + unaff_A4) &
               0xf,
       uVar1 <= *(ushort *)((int)&component_vel_old[0].y + unaff_A4))) {
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) - uVar1;
    (&component_collision_flags)[unaff_A4] =
        (&component_collision_flags)[unaff_A4] | 4;
  }
  return;
}

void FUN_00017efa(void)

{
  int unaff_A4;

  FUN_00017330(*(word *)((int)&comp_pos_x + unaff_A4),
               *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
                   *(short *)((int)&comp_pos_y + unaff_A4));
  return;
}

void FUN_00017f38(void)

{
  int unaff_A4;

  FUN_00017330((*(short *)((int)&comp_pos_x + unaff_A4) -
                *(short *)((int)&comp_collision_sensor[0].x + unaff_A4)) -
                   1,
               *(word *)((int)&comp_pos_y + unaff_A4));
  return;
}

void FUN_00017f58(void)

{
  int unaff_A4;

  FUN_00017330(*(short *)((int)&comp_collision_sensor[0].x + unaff_A4) +
                   *(short *)((int)&comp_pos_x + unaff_A4),
               *(word *)((int)&comp_pos_y + unaff_A4));
  return;
}

void FUN_00017f76(entity_id_t self)

{
  word unaff_D6w;
  word unaff_D7w;

  (&component_collision_flags)[self] = 0;
  (&comp_collision[0].collision.x)[self] = '\0';
  ecs_moved_left(self,
                 *(short *)((int)&comp_pos_y + self) + 1,
                 *(short *)((int)&comp_collision_sensor[0].y + self) * 2,
                 unaff_D6w,
                 unaff_D7w);
  return;
}

void FUN_00017f90(entity_id_t self, word param_2, word param_3)

{
  (&component_collision_flags)[self] = 0;
  (&comp_collision[0].collision.x)[self] = '\0';
  ecs_moved_right(self,
                  *(short *)((int)&comp_pos_y + self) + 1,
                  *(short *)((int)&comp_collision_sensor[0].y + self) * 2,
                  param_2,
                  param_3);
  return;
}

void FUN_00017fde(void)

{
  word wVar1;
  int unaff_A4;

  wVar1 = FUN_00017330(*(word *)((int)&comp_pos_x + unaff_A4),
                       *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
                           *(short *)((int)&comp_pos_y + unaff_A4));
  (*(code *)((int)&jmp_00018028 +
             (int)*(short *)((int)&jmp_00018028 +
                             (int)(short)((ushort)(byte)(&DAT_ffff6000)[(
                                              short)wVar1] *
                                          2))))();
  return;
}

void FUN_00018048(void)

{
  word wVar1;
  int unaff_A4;

  wVar1 =
      FUN_00017330(*(word *)((int)&comp_pos_x + unaff_A4),
                   (*(short *)((int)&comp_pos_y + unaff_A4) -
                    *(short *)((int)&comp_collision_sensor[0].y + unaff_A4)) +
                       1);
  (*(code *)((int)&jmp_00018096 +
             (int)*(short *)((int)&jmp_00018096 +
                             (int)(short)((ushort)(byte)(&DAT_ffff6000)[(
                                              short)wVar1] *
                                          2))))();
  return;
}

void FUN_000180b6(void)

{
  word wVar1;
  short unaff_D7w;
  int unaff_A4;

  wVar1 = FUN_00017330(
      *(short *)((int)&comp_collision_sensor[0].x + unaff_A4) +
          *(short *)((int)&comp_pos_x + unaff_A4),
      (*(short *)((int)&comp_collision_sensor[0].y + unaff_A4) + unaff_D7w) -
          1);
  (*(code *)(&UNK_000180ea +
             *(short *)(&UNK_000180ea +
                        (short)((ushort)(byte)(&DAT_ffff6000)[(short)wVar1] *
                                2))))();
  return;
}

void FUN_0001810a(void)

{
  word wVar1;
  short unaff_D7w;
  int unaff_A4;

  wVar1 = FUN_00017330(
      (*(short *)((int)&comp_pos_x + unaff_A4) -
       *(short *)((int)&comp_collision_sensor[0].x + unaff_A4)) -
          1,
      (*(short *)((int)&comp_collision_sensor[0].y + unaff_A4) + unaff_D7w) -
          1);
  (*(code *)(&UNK_00018140 +
             *(short *)(&UNK_00018140 +
                        (short)((ushort)(byte)(&DAT_ffff6000)[(short)wVar1] *
                                2))))();
  return;
}

short FUN_00018160(void)

{
  short sVar1;
  int unaff_A4;

  if (*(short *)((int)&component_vel_old[0].y + unaff_A4) < 0) {
    FUN_00018206();
  } else {
    FUN_00018184();
  }
  sVar1 = *(short *)((int)&component_vel_old[0].x + unaff_A4);
  if (sVar1 != 0) {
    if (sVar1 < 0) {
      sVar1 = FUN_0001830e();
    } else {
      sVar1 = FUN_0001828c();
    }
  }
  return sVar1;
}

void FUN_00018184(void)

{
  short sVar1;
  short sVar2;
  short extraout_D0w;
  word wVar3;
  word wVar4;
  int unaff_A4;

  sVar1 = *(short *)((int)&comp_pos_y + unaff_A4);
  sVar2 = *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  wVar4 = *(short *)((int)&comp_pos_x + unaff_A4) -
          *(short *)((int)&comp_collision_sensor[0].x + unaff_A4);
  do {
    wVar3 = FUN_00017330(wVar4, sVar2 + sVar1);
    if ((&DAT_ffff6000)[(short)wVar3] != 0)
      break;
    wVar4 = wVar4 + 0x10;
  } while (-1 < (short)(extraout_D0w + -0x10));
  // WARNING: Could not recover jumptable at 0x000181c6. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)(&UNK_000181c8 +
             *(short *)(&UNK_000181c8 +
                        (short)((ushort)(byte)(&DAT_ffff6000)[(short)wVar3] *
                                2))))();
  return;
}

void FUN_00018206(void)

{
  short sVar1;
  short sVar2;
  short extraout_D0w;
  word wVar3;
  word wVar4;
  int unaff_A4;

  sVar1 = *(short *)((int)&comp_pos_y + unaff_A4);
  sVar2 = *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  wVar4 = *(short *)((int)&comp_pos_x + unaff_A4) -
          *(short *)((int)&comp_collision_sensor[0].x + unaff_A4);
  do {
    wVar3 = FUN_00017330(wVar4, (sVar1 - sVar2) - 1);
    if ((&DAT_ffff6000)[(short)wVar3] != 0)
      break;
    wVar4 = wVar4 + 0x10;
  } while (-1 < (short)(extraout_D0w + -0x10));
  // WARNING: Could not recover jumptable at 0x0001824a. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)(&UNK_0001824c +
             *(short *)(&UNK_0001824c +
                        (short)((ushort)(byte)(&DAT_ffff6000)[(short)wVar3] *
                                2))))();
  return;
}

void FUN_0001828c(void)

{
  short sVar1;
  short sVar2;
  short in_D0w;
  short extraout_D0w;
  word wVar3;
  word wVar4;
  int unaff_A4;

  sVar1 = *(short *)((int)&comp_pos_y + unaff_A4);
  wVar4 = *(short *)((int)&comp_collision_sensor[0].x + unaff_A4) +
          *(short *)((int)&comp_pos_x + unaff_A4);
  sVar2 = *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  do {
    wVar3 = FUN_00017330(wVar4, sVar1 - (sVar2 + in_D0w));
    if ((&DAT_ffff6000)[(short)wVar3] != 0)
      break;
    wVar4 = wVar4 + 0x10;
  } while (-1 < (short)(extraout_D0w + -0x10));
  // WARNING: Could not recover jumptable at 0x000182ce. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)(&UNK_000182d0 +
             *(short *)(&UNK_000182d0 +
                        (short)((ushort)(byte)(&DAT_ffff6000)[(short)wVar3] *
                                2))))();
  return;
}

void FUN_0001830e(void)

{
  short sVar1;
  short sVar2;
  short extraout_D0w;
  word wVar3;
  word wVar4;
  int unaff_A4;

  sVar1 = *(short *)((int)&comp_pos_y + unaff_A4);
  sVar2 = *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  wVar4 = (*(short *)((int)&comp_pos_x + unaff_A4) -
           *(short *)((int)&comp_collision_sensor[0].x + unaff_A4)) -
          1;
  do {
    wVar3 = FUN_00017330(wVar4, sVar1 - sVar2);
    if ((&DAT_ffff6000)[(short)wVar3] != 0)
      break;
    wVar4 = wVar4 + 0x10;
  } while (-1 < (short)(extraout_D0w + -0x10));
  // WARNING: Could not recover jumptable at 0x00018352. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)(&UNK_00018354 +
             *(short *)(&UNK_00018354 +
                        (short)((ushort)(byte)(&DAT_ffff6000)[(short)wVar3] *
                                2))))();
  return;
}

undefined2 FUN_000183ce(short param_1)

{
  word wVar1;
  word unaff_D6w;
  word unaff_D7w;

  wVar1 = FUN_00017330(unaff_D6w, unaff_D7w);
  return *(
      undefined2 *)((int)&WORD_000183e6 +
                    (int)(short)((ushort)(byte)(&DAT_ffff6000)[(short)wVar1] *
                                 2));
}

short player_collision_get_y_pos(ulong ctx)

{
  short y_pos;

  player_update_vel_old(ctx);
  y_pos = *(short *)((int)&comp_pos_y + ctx);
  if (((&component_collision_flags)[ctx] & 4) != 0) {
    y_pos = player_collision_floor_get_y_pos(ctx);
  }
  if (((&component_collision_flags)[ctx] & 8) != 0) {
    y_pos = player_collision_ceil_get_y_pos(ctx);
    *(undefined2 *)((int)&comp_vel[0].y + ctx) = 0;
  }
  return y_pos;
}

short player_collision_floor_get_y_pos(ulong ctx)

{
  ushort collision_offset_y;
  short vel_old_y;

  collision_offset_y = *(ushort *)((int)&player_collision_offset[0].y + ctx);
  if ((collision_offset_y != 0) && (-1 < (short)collision_offset_y)) {
  didnt_collide:
    return *(short *)((int)&comp_pos_y + ctx);
  }
  vel_old_y = *(short *)((int)&component_vel_old[0].y + ctx);
  if (vel_old_y == 0) {
    if (collision_offset_y != *(ushort *)((int)&component_vel_old[0].y + ctx))
      goto didnt_collide;
  } else if ((vel_old_y < 0) || (collision_offset_y <= (ushort)-vel_old_y &&
                                 (ushort)-collision_offset_y != vel_old_y))
    goto didnt_collide;
  return *(short *)((int)&comp_pos_y + ctx) + collision_offset_y;
}

short player_collision_ceil_get_y_pos(ulong ctx)

{
  return *(short *)((int)&player_collision_offset[0].y + ctx) +
         *(short *)((int)&comp_pos_y + ctx);
}

void vdp_set_window_position(ushort window_pos_y)

{
  union2_t uVar1;

  if (window_pos_y < 5) {
    DAT_ffffd2e4 = 0;
  }
  VDP_CTRL = VDP_REG_WIN_H_POS;
  uVar1.b[0] = 0x92;
  uVar1.b[1] = (char)window_pos_y;
  VDP_CTRL = (union2_t)uVar1.w;
  if (window_pos_y == 0) {
    DAT_ffffd2de = 0;
    DAT_ffffd2e2 = 0x80;
  } else {
    DAT_ffffd2e2 = window_pos_y * 8 + 0x80;
    DAT_ffffd2e0 = window_pos_y * 8 + 0x60;
    DAT_ffffd2de = 0xff;
  }
  return;
}

void FUN_000184a8(void)

{
  int in_D0;

  DAT_ffffd2e6 = (ushort)in_D0;
  if ((in_D0 < 0) || (DAT_ffffd2e6 < 4)) {
    DAT_ffffd2e4 = 0;
  } else {
    DAT_ffffd2e4 = (DAT_ffffd2e6 - 4) * 4;
  }
  FUN_00016708();
  FUN_0000ae60();
  vdp_set_window_position(DAT_ffffd2e6);
  return;
}

void clear_data_and_uncompress_and_copy_to_vram(void)

{
  DAT_ffffd2e8 = 0;
  DAT_ffffd2ea = 0;
  DAT_ffffd2eb = 0;
  uncompress_and_copy_to_vram_2();
  return;
}

void nop_000184ec(void)

{
  return;
}

void uncompress_and_copy_to_vram_2(void)

{
  uncompress_and_copy_to_vram();
  nop_000184ec();
  return;
}

void uncompress_and_copy_to_vram(void)

{
  word compressed_data_index;
  word *pwVar1;
  undefined *dst;

  pwVar1 = compressed_data_indices;
  dst = (undefined *)0x0;
  compressed_data_indices_size = 0x40;
  do {
    compressed_data_index = *pwVar1;
    if ((-1 < (short)compressed_data_index) &&
        (compressed_data_index != pwVar1[0x40])) {
      pwVar1[0x40] = compressed_data_index;
      uncompress_data(compressed_data_index, (uint8_t *)&vdp_gfx_ptr_1);
      vdp_copy_1kb_from_gfx_ptr_1_to_vram(dst);
    }
    pwVar1 = pwVar1 + 1;
    dst = dst + 0x400;
    compressed_data_indices_size = compressed_data_indices_size - 1;
  } while (compressed_data_indices_size != 0);
  return;
}

void FUN_00018508(entity_id_t self, entity_id_t other, bool param_3)

{
  byte state_1_b;
  bool bVar1;

  DAT_ffffd2ed = 0xff;
  DAT_ffffd2eb = 0xff;
  bVar1 = ecs_get_cannot_jump(self);
  if (bVar1) {
    if ((gamepad_held & GAMEPAD_UP) == GAMEPAD_NONE) {
      if ((gamepad_held & GAMEPAD_DOWN) == GAMEPAD_NONE) {
        state_1_b = 8;
        DAT_ffffd2e8 = 8;
      } else {
        DAT_ffffd2e8 = 2;
        state_1_b = 2;
      }
    } else {
      DAT_ffffd2e8 = 0;
      state_1_b = 6;
    }
  } else {
    if ((gamepad_held & GAMEPAD_DOWN) != GAMEPAD_NONE) {
      DAT_ffffd2e8 = 4;
      *(undefined2 *)((int)&comp_state + self) = 0x1c;
      (&comp_anim_b)[self] = 4;
      ecs_anim_unk_2(self, (anim_item_t *)other, 0);
      ecs_holding_a_rope = ecs_holding_a_rope | 1;
      return;
    }
    DAT_ffffd2e8 = 8;
    state_1_b = 10;
  }
  DAT_ffffd2ee = DAT_ffffd2ee + 1;
  if (DAT_ffffde12 < DAT_ffffd2ee) {
    DAT_ffffd2ee = 1;
  }
  (&comp_anim_b)[self] = 2;
  ecs_anim_unk_2(self, (anim_item_t *)other, state_1_b);
  ecs_holding_a_rope = ecs_holding_a_rope | 3;
  return;
}

void FUN_0001859e(void)

{
  if (DAT_ffffd2eb != '\0') {
    (*(code *)((int)&WORD_000185ba +
               (int)*(short *)((int)&WORD_000185ba + (int)DAT_ffffd2e8)))();
  }
  return;
}

void FUN_000185c4(void)

{
  entity_id_t unaff_A4;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    if (DAT_ffffd2ed == '\0') {
      FUN_00000e5c(unaff_A4);
      DAT_ffffd2e8 = 8;
    } else {
      DAT_ffffd2e8 = 6;
      *(undefined1 *)((int)&comp_anim_tick + unaff_A4) = 0x10;
    }
  }
  if ((gamepad_held & GAMEPAD_B) == GAMEPAD_NONE) {
    DAT_ffffd2ed = '\0';
  }
  return;
}

void FUN_00018620(void)

{
  int unaff_A4;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    ecs_holding_a_rope = ecs_holding_a_rope & 0xfb;
    DAT_ffffd2eb = 0;
  }
  return;
}

void FUN_00018632(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar1;

  if ((*(short *)((int)&comp_anim_tick + unaff_A4) == 0) &&
      ((gamepad_held & GAMEPAD_B) == GAMEPAD_NONE)) {
    DAT_ffffd2e8 = 8;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
  }
  bVar1 = ecs_get_cannot_jump(unaff_A4);
  if ((!bVar1) && ((gamepad_held & GAMEPAD_B) != GAMEPAD_NONE)) {
    DAT_ffffd2e8 = 4;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0x1c;
    (&comp_anim_b)[unaff_A4] = 4;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    ecs_holding_a_rope = ecs_holding_a_rope & 0xfd | 1;
  }
  return;
}

void FUN_00018680(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if ((*(short *)((int)&comp_anim_tick + unaff_A4) == 0) &&
      ((gamepad_held & GAMEPAD_DOWN) == GAMEPAD_NONE)) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
    ecs_holding_a_rope = ecs_holding_a_rope & 0xfb;
    DAT_ffffd2eb = 0;
  }
  return;
}

void FUN_000186a0(entity_id_t self)

{
  bool bVar1;

  (&comp_func_offset[0].unk4)[self] = (&comp_func_offset[0].unk4)[self] & 0xf7;
  if ((comp_anim_b == 4) && (bVar1 = comp_anim_c == 0, bVar1)) {
    FUN_00001fdc(self, ENTITY_ID_ASHA, &DAT_000186ee);
    if (bVar1) {
      audio_play(SOUND_ID_DEFENCE);
      (&comp_func_offset[0].unk4)[self] = (&comp_func_offset[0].unk4)[self] | 8;
      if ((ushort)comp_pos_x._0_2_ < *(ushort *)((int)&comp_pos_x + self)) {
        comp_vel[0].x.raw = -0x200;
      } else {
        comp_vel[0].x.raw = 0x200;
      }
    }
  }
  return;
}

void FUN_000186f4(entity_id_t self, byte *param_2)

{
  undefined1 uVar1;

  (&comp_func_offset[0].unk4)[self] = (&comp_func_offset[0].unk4)[self] & 0xcf;
  uVar1 = comp_anim_b == 4;
  if ((((bool)uVar1) && (uVar1 = comp_anim_c == 0, (bool)uVar1)) &&
      (FUN_0000205a(self, ENTITY_ID_ASHA, &DAT_000186ee, param_2),
       (bool)uVar1)) {
    audio_play(SOUND_ID_DEFENCE);
    (&comp_func_offset[0].unk4)[self] =
        (&comp_func_offset[0].unk4)[self] | 0x20;
    if ((ushort)comp_pos_x._0_2_ < *(ushort *)((int)&comp_pos_x + self)) {
      comp_vel[0].x.raw = -0x200;
    } else {
      comp_vel[0].x.raw = 0x200;
    }
  } else {
    FUN_00001fdc(ENTITY_ID_ASHA, self, param_2);
    if ((bool)uVar1) {
      (&comp_func_offset[0].unk4)[self] =
          (&comp_func_offset[0].unk4)[self] | 0x10;
    }
  }
  return;
}

void FUN_00018758(entity_id_t self, byte *param_2)

{
  (&comp_func_offset[0].unk4)[self] = (&comp_func_offset[0].unk4)[self] & 0xbf;
  if ((DAT_ffffd2eb != '\0') && (comp_anim_b != 4)) {
    FUN_00018774(self, param_2);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00018774(entity_id_t self, byte *param_2)

{
  bool bVar1;

  bVar1 = comp_anim_c == ECS_STATE_1_B_FALLING;
  if (bVar1) {
    FUN_0000205a(self, ENTITY_ID_ASHA, BYTE_ARRAY_00018b82, param_2);
    if (bVar1) {
      if (comp_vel[0].y.raw < 0x100) {
        comp_vel[0].y.raw = 0x100;
      }
      audio_play(SOUND_ID_DEFENCE);
      (&comp_func_offset[0].unk4)[self] =
          (&comp_func_offset[0].unk4)[self] | 0x40;
      return;
    }
  } else {
    bVar1 = comp_anim_c == ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
    if (bVar1) {
      FUN_0000205a(self, ENTITY_ID_ASHA, BYTE_ARRAY_00018b90, param_2);
      if (bVar1) {
        _DAT_ffffcc74 = 3;
        audio_play(SOUND_ID_DEFENCE);
        (&comp_func_offset[0].unk4)[self] =
            (&comp_func_offset[0].unk4)[self] | 0x40;
        if ((comp_vel[0].y.raw == 0) || (-1 < comp_vel[0].y.raw)) {
          audio_play(SOUND_ID_JUMP);
          comp_vel[0].y.raw = -0x400;
          if ((comp_state_a & ENTITY_STATE_A_08) == 0) {
            comp_vel[0].x.raw = 0x200;
          } else {
            comp_vel[0].x.raw = -0x200;
          }
        }
        return;
      }
    } else {
      bVar1 = comp_anim_c == ECS_STATE_1_B_ATTACKING_MID_AIR;
      if (bVar1) {
        FUN_0000205a(self, ENTITY_ID_ASHA, BYTE_ARRAY_00018ba4, param_2);
        if (bVar1) {
          audio_play(SOUND_ID_DEFENCE);
          (&comp_func_offset[0].unk4)[self] =
              (&comp_func_offset[0].unk4)[self] | 0x40;
          return;
        }
      } else {
        bVar1 = comp_anim_c == ECS_STATE_1_B_ATTACKING_GROUNDED;
        if (!bVar1) {
          return;
        }
        FUN_0000205a(self, ENTITY_ID_ASHA, BYTE_ARRAY_00018bba, param_2);
        if (bVar1) {
          audio_play(SOUND_ID_DEFENCE);
          (&comp_func_offset[0].unk4)[self] =
              (&comp_func_offset[0].unk4)[self] | 0x40;
          return;
        }
      }
    }
  }
  return;
}

void FUN_0001881c(entity_id_t self, entity_id_t other, byte *param_3,
                  bool param_4)

{
  FUN_0000205a(self, other, BYTE_ARRAY_00018b90 + 0xe, param_3);
  if (param_4) {
    audio_play(SOUND_ID_DEFENCE);
    (&comp_func_offset[0].unk4)[self] =
        (&comp_func_offset[0].unk4)[self] | 0x40;
  }
  return;
}

void FUN_00018870(void)

{
  byte *in_A1;
  entity_id_t unaff_A4;

  (&comp_func_offset[0].unk4)[unaff_A4] =
      (&comp_func_offset[0].unk4)[unaff_A4] & 0x7f;
  if ((DAT_ffffd2eb != '\0') && (comp_anim_b != 4)) {
    FUN_0001888c(unaff_A4, in_A1);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001888c(entity_id_t self, byte *param_2)

{
  bool bVar1;

  bVar1 = comp_anim_c == ECS_STATE_1_B_FALLING;
  if (bVar1) {
    FUN_0000205a(self, ENTITY_ID_ASHA, BYTE_ARRAY_00018b82, param_2);
    if (bVar1) {
      if (comp_vel[0].y.raw < 0x100) {
        comp_vel[0].y.raw = 0x100;
      }
      audio_play(SOUND_ID_DEFENCE);
      (&comp_func_offset[0].unk4)[self] =
          (&comp_func_offset[0].unk4)[self] | 0x80;
      return;
    }
  } else {
    bVar1 = comp_anim_c == ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
    if (bVar1) {
      FUN_0000205a(self, ENTITY_ID_ASHA, BYTE_ARRAY_00018b90, param_2);
      if (bVar1) {
        audio_play(SOUND_ID_DEFENCE);
        _DAT_ffffcc74 = 3;
        (&comp_func_offset[0].unk4)[self] =
            (&comp_func_offset[0].unk4)[self] | 0x80;
        if ((comp_vel[0].y.raw == 0) || (-1 < comp_vel[0].y.raw)) {
          audio_play(SOUND_ID_JUMP);
          comp_vel[0].y.raw = -0x400;
          if ((comp_state_a & ENTITY_STATE_A_08) == 0) {
            comp_vel[0].x.raw = 0x200;
          } else {
            comp_vel[0].x.raw = -0x200;
          }
        }
        return;
      }
    } else {
      bVar1 = comp_anim_c == ECS_STATE_1_B_ATTACKING_MID_AIR;
      if (bVar1) {
        FUN_0000205a(self, ENTITY_ID_ASHA, BYTE_ARRAY_00018ba4, param_2);
        if (bVar1) {
          audio_play(SOUND_ID_DEFENCE);
          (&comp_func_offset[0].unk4)[self] =
              (&comp_func_offset[0].unk4)[self] | 0x80;
          if (*(ushort *)((int)&comp_pos_x + self) < (ushort)comp_pos_x._0_2_) {
            comp_vel[0].x.raw = 0x200;
          } else {
            comp_vel[0].x.raw = -0x200;
          }
          return;
        }
      } else {
        bVar1 = comp_anim_c == ECS_STATE_1_B_ATTACKING_GROUNDED;
        if (!bVar1) {
          return;
        }
        FUN_0000205a(self, ENTITY_ID_ASHA, BYTE_ARRAY_00018bba, param_2);
        if (bVar1) {
          audio_play(SOUND_ID_DEFENCE);
          (&comp_func_offset[0].unk4)[self] =
              (&comp_func_offset[0].unk4)[self] | 0x80;
          if (*(ushort *)((int)&comp_pos_x + self) < (ushort)comp_pos_x._0_2_) {
            comp_vel[0].x.raw = 0x200;
          } else {
            comp_vel[0].x.raw = -0x200;
          }
          return;
        }
      }
    }
  }
  return;
}

void FUN_00018934(entity_id_t self, entity_id_t other, byte *param_3,
                  bool param_4)

{
  FUN_0000205a(self, other, BYTE_ARRAY_00018b90 + 0xe, param_3);
  if (param_4) {
    if (*(ushort *)((int)&comp_pos_x + self) < (ushort)comp_pos_x._0_2_) {
      comp_vel[0].x.raw = 0x200;
    } else {
      comp_vel[0].x.raw = -0x200;
    }
    audio_play(SOUND_ID_DEFENCE);
    (&comp_func_offset[0].unk4)[self] =
        (&comp_func_offset[0].unk4)[self] | 0x80;
  }
  return;
}

void FUN_000189d0(void)

{
  entity_id_t unaff_A4;

  if ((&comp_unk_11)[unaff_A4] == '\0') {
    (&comp_func_offset[0].unk4)[unaff_A4] =
        (&comp_func_offset[0].unk4)[unaff_A4] & 0xfb;
    (&comp_func_offset[0].unk4)[unaff_A4] =
        (&comp_func_offset[0].unk4)[unaff_A4] & 0xfe;
    if ((DAT_ffffd2eb != '\0') && (comp_anim_b != 4)) {
      FUN_00018a20(unaff_A4);
    }
    FUN_0002e4f2();
    return;
  }
  (&comp_func_offset[0].unk4)[unaff_A4] =
      (&comp_func_offset[0].unk4)[unaff_A4] & 0xfb;
  (&comp_func_offset[0].unk4)[unaff_A4] =
      (&comp_func_offset[0].unk4)[unaff_A4] & 0xfe;
  if ((DAT_ffffd2eb != '\0') && (comp_anim_b != 4)) {
    FUN_00018a20(unaff_A4);
  }
  return;
}

void FUN_000189fe(void)

{
  entity_id_t unaff_A4;

  (&comp_func_offset[0].unk4)[unaff_A4] =
      (&comp_func_offset[0].unk4)[unaff_A4] & 0xfb;
  (&comp_func_offset[0].unk4)[unaff_A4] =
      (&comp_func_offset[0].unk4)[unaff_A4] & 0xfe;
  if ((DAT_ffffd2eb != '\0') && (comp_anim_b != 4)) {
    FUN_00018a20(unaff_A4);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00018a20(entity_id_t self)

{
  entity_id_w_t unaff_D2w;
  byte *unaff_A5;
  bool bVar1;

  bVar1 = comp_anim_c == ECS_STATE_1_B_FALLING;
  if (bVar1) {
    FUN_00001fdc(self, ENTITY_ID_ASHA, BYTE_ARRAY_00018b82);
    if (bVar1) {
      if (comp_vel[0].y.raw < 0x100) {
        comp_vel[0].y.raw = 0x100;
      }
      if ((DAT_ffffde12 != 0) && (DAT_ffffd2ee == DAT_ffffde12)) {
        FUN_00018bc8(unaff_A5, unaff_D2w);
        (&comp_func_offset[0].unk4)[self] =
            (&comp_func_offset[0].unk4)[self] | 4;
      }
      (&comp_func_offset[0].unk4)[self] = (&comp_func_offset[0].unk4)[self] | 1;
      return;
    }
  } else {
    bVar1 = comp_anim_c == ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
    if (bVar1) {
      FUN_00001fdc(self, ENTITY_ID_ASHA, BYTE_ARRAY_00018b90);
      if (bVar1) {
        _DAT_ffffcc74 = 3;
        if ((DAT_ffffde12 != 0) && (DAT_ffffd2ee == DAT_ffffde12)) {
          FUN_00018bc8(unaff_A5, unaff_D2w);
          (&comp_func_offset[0].unk4)[self] =
              (&comp_func_offset[0].unk4)[self] | 4;
        }
        (&comp_func_offset[0].unk4)[self] =
            (&comp_func_offset[0].unk4)[self] | 1;
        if ((comp_vel[0].y.raw == 0) || (-1 < comp_vel[0].y.raw)) {
          audio_play(SOUND_ID_JUMP);
          comp_vel[0].y.raw = -0x400;
          if ((comp_state_a & ENTITY_STATE_A_08) == 0) {
            comp_vel[0].x.raw = 0x200;
          } else {
            comp_vel[0].x.raw = -0x200;
          }
        }
        return;
      }
    } else {
      bVar1 = comp_anim_c == ECS_STATE_1_B_ATTACKING_MID_AIR;
      if (bVar1) {
        FUN_00001fdc(self, ENTITY_ID_ASHA, BYTE_ARRAY_00018ba4);
        if (bVar1) {
          if ((DAT_ffffde12 != 0) && (DAT_ffffd2ee == DAT_ffffde12)) {
            FUN_00018bc8(unaff_A5, unaff_D2w);
            (&comp_func_offset[0].unk4)[self] =
                (&comp_func_offset[0].unk4)[self] | 4;
          }
          (&comp_func_offset[0].unk4)[self] =
              (&comp_func_offset[0].unk4)[self] | 1;
          return;
        }
      } else {
        bVar1 = comp_anim_c == ECS_STATE_1_B_ATTACKING_GROUNDED;
        if (!bVar1) {
          return;
        }
        FUN_00001fdc(self, ENTITY_ID_ASHA, BYTE_ARRAY_00018bba);
        if (bVar1) {
          if ((DAT_ffffde12 != 0) && (DAT_ffffd2ee == DAT_ffffde12)) {
            FUN_00018bc8(unaff_A5, unaff_D2w);
            (&comp_func_offset[0].unk4)[self] =
                (&comp_func_offset[0].unk4)[self] | 4;
          }
          (&comp_func_offset[0].unk4)[self] =
              (&comp_func_offset[0].unk4)[self] | 1;
          return;
        }
      }
    }
  }
  return;
}

void FUN_00018af2(void)

{
  entity_id_w_t unaff_D2w;
  entity_id_t unaff_A3;
  entity_id_t unaff_A4;
  byte *unaff_A5;
  undefined1 in_ZF;

  FUN_00001fdc(unaff_A4, unaff_A3, BYTE_ARRAY_00018b90 + 0xe);
  if ((bool)in_ZF) {
    if ((DAT_ffffde12 != 0) && (DAT_ffffd2ee == DAT_ffffde12)) {
      FUN_00018bc8(unaff_A5, unaff_D2w);
      (&comp_func_offset[0].unk4)[unaff_A4] =
          (&comp_func_offset[0].unk4)[unaff_A4] | 4;
    }
    (&comp_func_offset[0].unk4)[unaff_A4] =
        (&comp_func_offset[0].unk4)[unaff_A4] | 1;
  }
  return;
}

void FUN_00018bc8(byte *param_1, entity_id_w_t self)

{
  short pos_x;
  int8_vec2_t *pos_array;

  if (comp_anim_c == ECS_STATE_1_B_FALLING) {
    pos_array = int8_vec2_t_ARRAY_00018c30;
  } else if (comp_anim_c == ECS_STATE_1_B_ATTACKING_GROUNDED) {
    pos_array = int8_vec2_t_ARRAY_00018c3a;
  } else if (comp_anim_c == ECS_STATE_1_B_WALKING_OR_DOWNSTAB) {
    pos_array = int8_vec2_t_ARRAY_00018c44;
  } else {
    pos_array = int8_vec2_t_ARRAY_00018c4c;
  }
  pos_x = (short)(&pos_array->x)[(short)((ushort)comp_anim[0].frame * 2)];
  if ((comp_state_a & ENTITY_STATE_A_08) != 0) {
    pos_x = -pos_x;
  }
  FUN_000018b2(param_1,
               self,
               pos_x + comp_pos_x.fixed.i,
               (&pos_array->x + (short)((ushort)comp_anim[0].frame * 2))[1] +
                   comp_pos_y.fixed.i);
  return;
}

void FUN_00018c56(void)

{
  DAT_ffffd2e8 = 0;
  DAT_ffffd2ea = 0;
  DAT_ffffd2eb = 0;
  ecs_holding_a_rope = ecs_holding_a_rope & 0xf8;
  return;
}

// This seems to find the first uncompressed data ref?
//
// The upper 11 bits are the data offset (floored to a multiple of 4).
// The lower 5 bits are

byte *get_uncompressed_data_address(word id)

{
  compressed_data_ref_t compressed_data_ref;

  compressed_data_ref =
      *(compressed_data_ref_t *)((short)(id >> 3 & 0x1ffc) + 0xc0000);
  do {
    // Block if the reference is invalid (#ffffffff).
  } while ((int)compressed_data_ref < 0);
  do {
    // Block if the data is compressed.
  } while (((uint)compressed_data_ref & COMPRESSION_NONE) == 0);
  return (byte *)((int)(short)((id & 0x1f) << 5) +
                  ((uint)compressed_data_ref & 0xfeffffff));
}

void FUN_00018c8e(void)

{
  return;
}

void uncompress_data(short compressed_data_index, uint8_t *dst)

{
  byte *prev_src;
  short iter_j;
  byte src_value;
  short iter_i;
  byte bVar1;
  byte bVar2;
  uint16_t unused_bits;
  uint l;
  byte bVar4;
  int iVar3;
  undefined *buf1;
  ushort length_maybe;
  short iter_k;
  undefined4 *uncompressed_data_p;
  byte *src;
  uint *puVar5;
  uint8_t *dst2;
  undefined **buf2;
  uint8_t *puVar6;
  uint8_t *tmp;
  byte *pbVar7;
  short *dst_tmp;
  bool operation_overflowed_2;
  compression_related_a_t partial_result;
  compressed_data_ref_t compressed_data_ref;
  uint counter_m;
  bool operation_overflowed_1;
  byte *prev_dst;

  compressed_data_ref =
      *(compressed_data_ref_t *)((short)(compressed_data_index << 2) + 0xc0000);
  // Invalid compressed data pointers are #ffffffff.
  if ((int)compressed_data_ref < 0) {
    iter_i = 0xff;
    do {
      dst[0] = '\0';
      dst[1] = '\0';
      dst[2] = '\0';
      dst[3] = '\0';
      iter_i = iter_i + -1;
      dst = dst + 4;
    } while (iter_i != -1);
    return;
  }
  if (((uint)compressed_data_ref & COMPRESSION_NONE) == 0) {
    prev_src = (byte *)((uint)compressed_data_ref & 0xfcffffff);
    if (((uint)compressed_data_ref & COMPRESSION_LZ77_HUFFMAN) == 0) {
      // Compression 0
      iter_i = 0x1f;
      do {
        src = prev_src + 1;
        src_value = *prev_src;
        if (src_value == 0) {
          iter_j = 0x1f;
          prev_dst = dst;
          do {
            prev_src = src + 1;
            dst = prev_dst + 1;
            *prev_dst = *src;
            iter_j = iter_j + -1;
            src = prev_src;
            prev_dst = dst;
          } while (iter_j != -1);
        } else if ((char)src_value < '\0') {
          prev_src = prev_src + 2;
          bVar2 = *src;
          iter_j = 3;
          src = compression_0_buffer;
          do {
            bVar1 = bVar2 >> 1;
            bVar4 = -((bVar2 & 1) != 0);
            bVar2 = bVar2 >> 2;
            if ((bVar1 & 1) == 0) {
              counter_m = (uint)*prev_src;
              iter_k = 7;
              prev_dst = prev_src + 1;
              pbVar7 = src;
              do {
                l = counter_m & 1;
                counter_m = counter_m >> 1;
                bVar1 = bVar4;
                prev_src = prev_dst;
                if (l != 0) {
                  prev_src = prev_dst + 1;
                  bVar1 = *prev_dst;
                }
                src = pbVar7 + 1;
                *pbVar7 = bVar1;
                iter_k = iter_k + -1;
                prev_dst = prev_src;
                pbVar7 = src;
              } while (iter_k != -1);
            } else {
              iVar3 = (int)(short)(char)bVar4;
              prev_dst = src + 4;
              *(int *)src = iVar3;
              src = src + 8;
              *(int *)prev_dst = iVar3;
            }
            bVar1 = src_value & 1;
            src_value = src_value >> 1;
            if (bVar1 != 0) {
              bVar1 = src[-8];
              iter_k = 6;
              prev_dst = src + -7;
              do {
                bVar1 = *prev_dst ^ bVar1;
                src = prev_dst + 1;
                *prev_dst = bVar1;
                iter_k = iter_k + -1;
                prev_dst = src;
              } while (iter_k != -1);
            }
            iter_j = iter_j + -1;
          } while (iter_j != -1);
          iter_j = 7;
          src = dst;
          prev_dst = compression_0_buffer;
          do {
            dst = src + 4;
            *(uint *)src = CONCAT22(
                *(ushort *)((int)compression_related_8 +
                            (int)(short)(prev_dst[0x18] >> 3 & 0x1e)) |
                    *(ushort *)((int)compression_related_4 +
                                (int)(short)(prev_dst[0x10] >> 3 & 0x1e)) |
                    *(ushort *)((int)compression_related_2 +
                                (int)(short)(prev_dst[8] >> 3 & 0x1e)) |
                    *(ushort *)((int)compression_related_1 +
                                (int)(short)(*prev_dst >> 3 & 0x1e)),
                *(ushort *)((int)compression_related_8 +
                            (int)(short)((prev_dst[0x18] & 0xf) * 2)) |
                    *(ushort *)((int)compression_related_4 +
                                (int)(short)((prev_dst[0x10] & 0xf) * 2)) |
                    *(ushort *)((int)compression_related_2 +
                                (int)(short)((prev_dst[8] & 0xf) * 2)) |
                    *(ushort *)((int)compression_related_1 +
                                (int)(short)((*prev_dst & 0xf) * 2)));
            iter_j = iter_j + -1;
            src = dst;
            prev_dst = prev_dst + 1;
          } while (iter_j != -1);
        } else {
          iter_j = CONCAT11((char)src_value >> 7, src_value - 1);
          counter_m = 0;
          do {
            puVar5 = (uint *)(src + 1);
            src_value = *src;
            src = src + 5;
            l = *puVar5;
            counter_m = l | counter_m;
            prev_src = dst;
            do {
              operation_overflowed_1 = CARRY4(l, l);
              l = l * 2;
              if (operation_overflowed_1) {
                *prev_src = src_value;
              }
              prev_src = prev_src + 1;
            } while (l != 0);
            iter_j = iter_j + -1;
          } while (iter_j != -1);
          counter_m = ~counter_m;
          prev_dst = dst;
          do {
            operation_overflowed_1 = CARRY4(counter_m, counter_m);
            counter_m = counter_m * 2;
            prev_src = src;
            if (operation_overflowed_1) {
              prev_src = src + 1;
              *prev_dst = *src;
            }
            prev_dst = prev_dst + 1;
            src = prev_src;
          } while (counter_m != 0);
          dst = dst + 0x20;
        }
        iter_i = iter_i + -1;
      } while (iter_i != -1);
      return;
    }
    // Compression 2
    //
    // Assumption: decompress with Huffman first, then LZ77.
    src = prev_src + 1;
    // The first byte is half the decompressed size, maybe.
    src_value = *prev_src * '\x02';
    unused_bits = 7;
    buf1 = (undefined *)0xd2f2;
    buf2 = compression_2_buffer;
    operation_overflowed_1 = false;
    iter_i = 0;
    dst_tmp = (short *)dst;
    while (true) {
      while (true) {
        while (true) {
          unused_bits = unused_bits - 1;
          if (unused_bits == 0xffff) {
            src_value = *src;
            unused_bits = 7;
            src = src + 1;
          }
          operation_overflowed_2 = CARRY1(src_value, src_value);
          src_value = src_value * '\x02';
          if (!operation_overflowed_2)
            break;
          buf1 = buf1 + 4;
          if (operation_overflowed_1) {
            buf2[1] = buf1;
            operation_overflowed_1 = false;
          } else {
            *dst_tmp = (short)buf2;
            iter_i = iter_i + 1;
            *buf2 = buf1;
            dst_tmp = dst_tmp + 1;
          }
          buf2 = (undefined **)(int)(short)buf1;
        }
        partial_result =
            compression_2_related_b(src, dst, src_value, unused_bits);
        src = partial_result.a0_src;
        dst = partial_result.a1_dst;
        src_value = partial_result.d0b_src_value;
        unused_bits = partial_result.d1w_unused_bits;
        if (operation_overflowed_1)
          break;
        *buf2 = (undefined *)partial_result.d7w;
        operation_overflowed_1 = true;
      }
      buf2[1] = (undefined *)partial_result.d7w;
      iter_i = iter_i + -1;
      if (iter_i == -1)
        break;
      dst_tmp = dst_tmp + -1;
      buf2 = (undefined **)(int)*dst_tmp;
    }
    // Likely #3ff for #400 iterations, which likely is the size of the
    // uncompressed data as uncompressed blocs are #400 bytes long, aka 1kb.
    //
    // What follows looks a lot like the LZ77 decompression from
    // https://algo.developpez.com/actu/308570/Comprendre-l-algorithme-de-compression-LZ77-un-billet-de-fbonhomm/.
    iter_i = 0x3ff;
    do {
      while (true) {
        // Could this return the (i,l,c) triplet described here?
        // https://algo.developpez.com/actu/308570/Comprendre-l-algorithme-de-compression-LZ77-un-billet-de-fbonhomm/
        partial_result =
            compression_2_related_a(src, dst, src_value, unused_bits);
        src = partial_result.a0_src;
        tmp = partial_result.a1_dst;
        src_value = partial_result.d0b_src_value;
        unused_bits = partial_result.d1w_unused_bits;
        if (0xff < partial_result.d7w)
          break;
        dst = tmp + 1;
        *tmp = (uint8_t)partial_result.d7w;
        iter_i = iter_i + -1;
        if (iter_i == -1) {
          return;
        }
      }
      length_maybe = partial_result.d7w - 0xfd;
      iter_i = iter_i - length_maybe;
      // Could this return the (i,l,c) triplet described here?
      // https://algo.developpez.com/actu/308570/Comprendre-l-algorithme-de-compression-LZ77-un-billet-de-fbonhomm/
      partial_result =
          compression_2_related_a(src, tmp, src_value, unused_bits);
      src = partial_result.a0_src;
      dst = partial_result.a1_dst;
      src_value = partial_result.d0b_src_value;
      unused_bits = partial_result.d1w_unused_bits;
      tmp = dst + (short)-partial_result.d7w + -1;
      while (4 < length_maybe) {
        *dst = *tmp;
        dst[1] = tmp[1];
        dst[2] = tmp[2];
        puVar6 = tmp + 4;
        dst2 = dst + 4;
        dst[3] = tmp[3];
        tmp = tmp + 5;
        dst = dst + 5;
        *dst2 = *puVar6;
        length_maybe = length_maybe - 5;
      }
      length_maybe = length_maybe - 1;
      dst2 = dst;
      if (-1 < (int)((uint)length_maybe << 0x10)) {
        do {
          dst = dst2 + 1;
          *dst2 = *tmp;
          length_maybe = length_maybe - 1;
          dst2 = dst;
          tmp = tmp + 1;
        } while (length_maybe != 0xffff);
      }
    } while (-1 < iter_i);
    return;
  }
  // Uncompressed data
  iter_i = 0xff;
  uncompressed_data_p = (undefined4 *)((uint)compressed_data_ref & 0xfeffffff);
  do {
    *(undefined4 *)dst = *uncompressed_data_p;
    iter_i = iter_i + -1;
    uncompressed_data_p = uncompressed_data_p + 1;
    dst = dst + 4;
  } while (iter_i != -1);
  return;
}

compression_related_a_t compression_2_related_a(uint8_t *src, uint8_t *dst,
                                                uint8_t src_value,
                                                uint16_t unused_bits)

{
  byte bVar1;
  undefined3 uVar2;
  uint uVar3;
  byte bVar4;
  undefined *puVar5;
  byte *pbVar6;
  byte *pbVar7;
  undefined **ppuVar8;
  bool bVar9;
  compression_related_a_t cVar10;
  compression_related_a_t cVar11;
  compression_related_a_t cVar12;
  compression_related_a_t cVar13;
  compression_related_a_t cVar14;

  ppuVar8 = compression_2_buffer;
  while (true) {
    cVar11.d1w_unused_bits = unused_bits - 1;
    pbVar6 = src;
    if (cVar11.d1w_unused_bits == 0xffff) {
      pbVar6 = src + 1;
      src_value = *src;
      cVar11.d1w_unused_bits = 7;
    }
    bVar9 = CARRY1(src_value, src_value);
    src_value = src_value * '\x02';
    if (bVar9) {
      ppuVar8 = ppuVar8 + 1;
    }
    puVar5 = *ppuVar8;
    if (-1 < (short)puVar5)
      break;
    ppuVar8 = (undefined **)(int)(short)puVar5;
    src = pbVar6;
    unused_bits = cVar11.d1w_unused_bits;
  }
  if (puVar5 == (undefined *)0x11f) {
    uVar3 = (uint)(ushort)(cVar11.d1w_unused_bits - 1);
    bVar1 = src_value;
    pbVar7 = pbVar6;
    if ((uint16_t)(cVar11.d1w_unused_bits - 1) == 0xffff) {
      pbVar7 = pbVar6 + 1;
      bVar1 = *pbVar6;
      uVar3 = 7;
    }
    cVar11.d1w_unused_bits = (uint16_t)uVar3;
    src_value = bVar1 * '\x02';
    bVar4 = (byte)uVar3;
    if (CARRY1(bVar1, bVar1)) {
      if (bVar4 == 0) {
        cVar12.a0_src = pbVar7 + 1;
        cVar12.d0b_src_value = *pbVar7 << 5;
        cVar12.d7w = (undefined2)CONCAT31(1, *pbVar7 >> 3);
        cVar12.d1w_unused_bits = 3;
        cVar12.a1_dst = dst;
        return cVar12;
      }
      uVar2 = (undefined3)(uVar3 >> 8);
      if (bVar4 < 5) {
        bVar4 = bVar4 + 3;
        cVar14.a0_src = pbVar7 + 1;
        cVar14.d0b_src_value = *pbVar7 << (8 - bVar4 & 0x3f);
        cVar14.d1w_unused_bits = (undefined2)CONCAT31(uVar2, bVar4);
        cVar14.d7w =
            (undefined2)CONCAT31(1, *pbVar7 >> (bVar4 & 0x3f) | src_value >> 3);
        cVar14.a1_dst = dst;
        return cVar14;
      }
      cVar13.d0b_src_value = bVar1 << 6;
      cVar13.d1w_unused_bits = (undefined2)CONCAT31(uVar2, bVar4 - 5);
      cVar13.d7w = (undefined2)CONCAT31(1, src_value >> 3);
      cVar13.a0_src = pbVar7;
      cVar13.a1_dst = dst;
      return cVar13;
    }
    if (bVar4 != 0) {
      cVar11.a0_src = pbVar7 + 1;
      cVar11.d0b_src_value = *pbVar7 << (8 - bVar4 & 0x3f);
      cVar11.d7w = (ushort)(byte)(*pbVar7 >> (uVar3 & 0x3f) | src_value);
      cVar11.a1_dst = dst;
      return cVar11;
    }
    pbVar6 = pbVar7 + 1;
    puVar5 = (undefined *)(ushort)*pbVar7;
  }
  cVar10.d1w_unused_bits = cVar11.d1w_unused_bits;
  cVar10.d7w = (uint16_t)puVar5;
  cVar10.d0b_src_value = src_value;
  cVar10.a0_src = pbVar6;
  cVar10.a1_dst = dst;
  return cVar10;
}

compression_related_a_t compression_2_related_b(uint8_t *src, uint8_t *dst,
                                                uint8_t src_value,
                                                uint16_t unused_bits)

{
  byte bVar1;
  undefined3 uVar2;
  uint unused_bits_tmp;
  byte bVar3;
  byte *src_tmp;
  compression_related_a_t cVar4;
  compression_related_a_t cVar5;
  compression_related_a_t cVar6;
  compression_related_a_t cVar7;
  compression_related_a_t cVar8;

  unused_bits_tmp = (uint)(ushort)(unused_bits - 1);
  src_tmp = src;
  if ((uint16_t)(unused_bits - 1) == 0xffff) {
    src_tmp = src + 1;
    src_value = *src;
    unused_bits_tmp = 7;
  }
  bVar1 = src_value * '\x02';
  bVar3 = (byte)unused_bits_tmp;
  if (!CARRY1(src_value, src_value)) {
    cVar4.d1w_unused_bits = (undefined2)unused_bits_tmp;
    if (bVar3 != 0) {
      cVar5.a0_src = src_tmp + 1;
      cVar5.d0b_src_value = *src_tmp << (8 - bVar3 & 0x3f);
      cVar5.d7w = (ushort)(byte)(*src_tmp >> (unused_bits_tmp & 0x3f) | bVar1);
      cVar5.d1w_unused_bits = cVar4.d1w_unused_bits;
      cVar5.a1_dst = dst;
      return cVar5;
    }
    cVar4.a0_src = src_tmp + 1;
    cVar4.d7w = (ushort)*src_tmp;
    cVar4.d0b_src_value = bVar1;
    cVar4.a1_dst = dst;
    return cVar4;
  }
  if (bVar3 == 0) {
    cVar6.a0_src = src_tmp + 1;
    cVar6.d0b_src_value = *src_tmp << 5;
    cVar6.d7w = (undefined2)CONCAT31(1, *src_tmp >> 3);
    cVar6.d1w_unused_bits = 3;
    cVar6.a1_dst = dst;
    return cVar6;
  }
  uVar2 = (undefined3)(unused_bits_tmp >> 8);
  if (bVar3 < 5) {
    bVar3 = bVar3 + 3;
    cVar8.a0_src = src_tmp + 1;
    cVar8.d0b_src_value = *src_tmp << (8 - bVar3 & 0x3f);
    cVar8.d1w_unused_bits = (undefined2)CONCAT31(uVar2, bVar3);
    cVar8.d7w =
        (undefined2)CONCAT31(1, *src_tmp >> (bVar3 & 0x3f) | bVar1 >> 3);
    cVar8.a1_dst = dst;
    return cVar8;
  }
  cVar7.d0b_src_value = src_value << 6;
  cVar7.d1w_unused_bits = (undefined2)CONCAT31(uVar2, bVar3 - 5);
  cVar7.d7w = (undefined2)CONCAT31(1, bVar1 >> 3);
  cVar7.a0_src = src_tmp;
  cVar7.a1_dst = dst;
  return cVar7;
}

void FUN_00018f88(void)

{
  bool bVar1;
  byte bVar2;
  ushort uVar4;
  uint uVar3;
  short sVar5;
  undefined *puVar6;
  short unaff_D5w;
  undefined *unaff_D7w;
  char *in_A0;
  byte *pbVar7;
  byte *extraout_A0;
  short *in_A1;
  ushort *extraout_A1;
  undefined2 *extraout_A1_00;
  undefined2 *puVar8;
  undefined2 *puVar9;
  undefined **ppuVar10;
  undefined2 *puVar11;
  undefined2 *puVar12;
  undefined5 uVar13;

  pbVar7 = (byte *)(in_A0 + 1);
  uVar13 = CONCAT14(*in_A0 * '\x02', 7);
  puVar6 = (undefined *)0xd2f2;
  ppuVar10 = compression_2_buffer;
  bVar1 = false;
  sVar5 = 0;
  while (true) {
    while (true) {
      while (true) {
        bVar2 = (byte)((uint5)uVar13 >> 0x20);
        uVar4 = (short)uVar13 - 1;
        uVar3 = (uint)uVar4;
        if (uVar4 == 0xffff) {
          bVar2 = *pbVar7;
          uVar3 = 7;
          pbVar7 = pbVar7 + 1;
        }
        uVar13 = CONCAT14(bVar2 * '\x02', uVar3);
        if (!CARRY1(bVar2, bVar2))
          break;
        puVar6 = puVar6 + 4;
        if (bVar1) {
          ppuVar10[1] = puVar6;
          bVar1 = false;
        } else {
          *in_A1 = (short)ppuVar10;
          sVar5 = sVar5 + 1;
          *ppuVar10 = puVar6;
          in_A1 = in_A1 + 1;
        }
        ppuVar10 = (undefined **)(int)(short)puVar6;
      }
      uVar13 = FUN_00019038();
      pbVar7 = extraout_A0;
      if (bVar1)
        break;
      *ppuVar10 = unaff_D7w;
      bVar1 = true;
    }
    ppuVar10[1] = unaff_D7w;
    sVar5 = sVar5 + -1;
    if (sVar5 < 0)
      break;
    in_A1 = in_A1 + -1;
    ppuVar10 = (undefined **)(int)*in_A1;
  }
  sVar5 = unaff_D5w + -1;
  do {
    while (FUN_00019018(), unaff_D7w < 0x400) {
      *extraout_A1 = (ushort)unaff_D7w;
      sVar5 = sVar5 + -1;
      if (sVar5 == -1) {
        return;
      }
    }
    puVar6 = unaff_D7w + -0x3fd;
    sVar5 = sVar5 - (short)puVar6;
    FUN_00019018();
    unaff_D7w = (undefined *)((short)unaff_D7w * 2);
    puVar11 = (undefined2 *)((int)extraout_A1_00 - (int)(short)unaff_D7w);
    puVar9 = extraout_A1_00;
    while (3 < puVar6) {
      *puVar9 = *puVar11;
      puVar9[1] = puVar11[1];
      puVar12 = puVar11 + 3;
      puVar8 = puVar9 + 3;
      puVar9[2] = puVar11[2];
      puVar11 = puVar11 + 4;
      puVar9 = puVar9 + 4;
      *puVar8 = *puVar12;
      puVar6 = puVar6 + -4;
    }
    puVar6 = puVar6 + -1;
    if (-1 < (short)puVar6) {
      do {
        *puVar9 = *puVar11;
        puVar6 = puVar6 + -1;
        puVar9 = puVar9 + 1;
        puVar11 = puVar11 + 1;
      } while (puVar6 != (undefined *)0xffff);
    }
  } while (-1 < sVar5);
  return;
}

undefined6 FUN_00019018(void)

{
  undefined *puVar1;
  undefined1 uVar2;
  undefined2 in_D0w;
  byte bVar3;
  undefined4 in_D1;
  short sVar5;
  char cVar6;
  undefined4 uVar4;
  char *in_A0;
  char *pcVar7;
  char *pcVar8;
  undefined **ppuVar9;

  ppuVar9 = compression_2_buffer;
  while (true) {
    sVar5 = (short)in_D1 + -1;
    in_D1 = CONCAT22((short)((uint)in_D1 >> 0x10), sVar5);
    pcVar7 = in_A0;
    if (sVar5 == -1) {
      pcVar7 = in_A0 + 1;
      in_D0w = CONCAT11((char)((ushort)in_D0w >> 8), *in_A0);
      in_D1 = 7;
    }
    bVar3 = (byte)in_D0w;
    uVar2 = (undefined1)((ushort)in_D0w >> 8);
    in_D0w = CONCAT11(uVar2, bVar3 * '\x02');
    if (CARRY1(bVar3, bVar3)) {
      ppuVar9 = ppuVar9 + 1;
    }
    puVar1 = *ppuVar9;
    if (-1 < (short)puVar1)
      break;
    ppuVar9 = (undefined **)(int)(short)puVar1;
    in_A0 = pcVar7;
  }
  if (puVar1 == (undefined *)0x4ff) {
    sVar5 = (short)in_D1 + -1;
    in_D1 = CONCAT22((short)((uint)in_D1 >> 0x10), sVar5);
    pcVar8 = pcVar7;
    if (sVar5 == -1) {
      pcVar8 = pcVar7 + 1;
      in_D0w = CONCAT11(uVar2, *pcVar7);
      in_D1 = 7;
    }
    bVar3 = (byte)in_D0w;
    uVar2 = (undefined1)((ushort)in_D0w >> 8);
    in_D0w = CONCAT11(uVar2, bVar3 * '\x02');
    cVar6 = (char)in_D1;
    if (!CARRY1(bVar3, bVar3)) {
      if (cVar6 == '\0') {
        uVar4 = 6;
        cVar6 = pcVar8[1] * '\x02';
      } else {
        sVar5 = (short)in_D1 + -2;
        uVar4 = CONCAT22((short)((uint)in_D1 >> 0x10), sVar5);
        if (sVar5 == 0) {
          return CONCAT24(in_D0w, uVar4);
        }
        if (-1 < sVar5) {
          return CONCAT24(CONCAT11(uVar2, *pcVar8) << (8U - sVar5 & 0x3f),
                          uVar4);
        }
        cVar6 = pcVar8[1];
        uVar4 = 7;
      }
      return CONCAT24(CONCAT11(uVar2, cVar6 * '\x02'), uVar4);
    }
    if (cVar6 != '\0') {
      return CONCAT24(CONCAT11(uVar2, *pcVar8 << (8U - cVar6 & 0x3f)), in_D1);
    }
  }
  return CONCAT24(in_D0w, in_D1);
}

undefined6 FUN_00019038(void)

{
  undefined1 uVar1;
  undefined2 in_D0w;
  byte bVar3;
  undefined4 in_D1;
  short sVar5;
  undefined4 uVar4;
  char cVar6;
  char *in_A0;
  char *pcVar7;
  undefined2 uVar2;

  sVar5 = (short)in_D1 + -1;
  uVar4 = CONCAT22((short)((uint)in_D1 >> 0x10), sVar5);
  pcVar7 = in_A0;
  if (sVar5 == -1) {
    pcVar7 = in_A0 + 1;
    in_D0w = CONCAT11((char)((ushort)in_D0w >> 8), *in_A0);
    uVar4 = 7;
  }
  bVar3 = (byte)in_D0w;
  uVar1 = (undefined1)((ushort)in_D0w >> 8);
  uVar2 = CONCAT11(uVar1, bVar3 * '\x02');
  cVar6 = (char)uVar4;
  if (CARRY1(bVar3, bVar3)) {
    if (cVar6 != '\0') {
      return CONCAT24(CONCAT11(uVar1, *pcVar7 << (8U - cVar6 & 0x3f)), uVar4);
    }
    return CONCAT24(uVar2, uVar4);
  }
  if (cVar6 == '\0') {
    uVar4 = 6;
    cVar6 = pcVar7[1] * '\x02';
  } else {
    sVar5 = (short)uVar4 + -2;
    uVar4 = CONCAT22((short)((uint)uVar4 >> 0x10), sVar5);
    if (sVar5 == 0) {
      return CONCAT24(uVar2, uVar4);
    }
    if (-1 < sVar5) {
      return CONCAT24(CONCAT11(uVar1, *pcVar7) << (8U - sVar5 & 0x3f), uVar4);
    }
    cVar6 = pcVar7[1];
    uVar4 = 7;
  }
  return CONCAT24(CONCAT11(uVar1, cVar6 * '\x02'), uVar4);
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000190a2(void)

{
  byte bVar1;
  byte bVar2;
  char cVar3;
  short sVar4;
  ushort uVar5;
  undefined2 extraout_D1w;
  ushort uVar6;
  undefined2 *puVar7;
  undefined2 *puVar8;
  undefined2 *puVar9;
  undefined2 *puVar10;
  byte *unaff_A5;
  byte *pbVar11;
  byte *pbVar12;
  byte *pbVar13;

  bVar1 = *unaff_A5;
  pbVar11 = unaff_A5 + 3;
  _DAT_ffffd912 = FUN_000191e2();
  _DAT_ffffd914 = extraout_D1w;
  FUN_00018f88();
  while (true) {
    if (*pbVar11 == 0xff)
      break;
    puVar7 = (undefined2 *)((short)(((ushort)*pbVar11 +
                                     (ushort)pbVar11[1] * _DAT_ffffd912) *
                                    2) +
                            0xff6400);
    bVar2 = pbVar11[2];
    pbVar12 = pbVar11 + 4;
    uVar6 = (ushort)pbVar11[3];
    pbVar13 = pbVar11 + 5;
    pbVar11 = pbVar11 + 6;
    cVar3 = (&DAT_ffffc717)[(short)(ushort)bVar1];
    puVar9 = (undefined2 *)((int)(short)(((ushort)*pbVar12 +
                                          ((ushort)*pbVar13
                                           << (cVar3 + 3U & 0x3f))) *
                                         2) +
                            *(int *)((int)&DAT_ffffc722 +
                                     (int)(short)(ushort)bVar1));
    sVar4 = _DAT_ffffd912 - (ushort)bVar2;
    uVar5 = (ushort)bVar2;
    do {
      do {
        puVar8 = puVar7 + 1;
        puVar10 = puVar9 + 1;
        *puVar9 = *puVar7;
        uVar5 = uVar5 - 1;
        puVar7 = puVar8;
        puVar9 = puVar10;
      } while (uVar5 != 0);
      puVar9 = (undefined2 *)((int)(short)(((1 << (cVar3 + 3U & 0x3f)) -
                                            (ushort)bVar2) *
                                           2) +
                              (int)puVar10);
      puVar7 = (undefined2 *)((int)(short)(sVar4 * 2) + (int)puVar8);
      uVar6 = uVar6 - 1;
      uVar5 = (ushort)bVar2;
    } while (uVar6 != 0);
  }
  return;
}

void FUN_00019132(void)

{
  byte bVar1;
  ushort uVar2;
  short extraout_D1w;
  short sVar3;
  short sVar4;
  ushort uVar5;
  short sVar6;
  int iVar7;
  undefined2 *extraout_A1;
  undefined2 *puVar8;
  undefined2 *puVar9;
  int iVar10;
  byte *unaff_A5;

  bVar1 = *unaff_A5;
  iVar10 = (int)(short)(ushort)bVar1;
  uVar2 = FUN_000191e2();
  *(ushort *)((int)&room_boundary_x + iVar10) = uVar2 * 0x10 + 0xfff;
  *(short *)((int)&camera_pos_x_int + iVar10) = extraout_D1w * 0x10 + 0xfff;
  sVar4 = 1;
  for (uVar5 = (ushort)(uVar2 - 1) >> 4; uVar5 != 0; uVar5 = uVar5 >> 1) {
    sVar4 = sVar4 + 1;
  }
  (&DAT_ffffc717)[iVar10] = (char)sVar4;
  iVar7 = -0x10000;
  if (bVar1 != 0) {
    iVar7 = (short)(0x4000 - (extraout_D1w << (sVar4 + 4U & 0x3f))) + -0x10000;
  }
  *(int *)((int)&DAT_ffffc722 + iVar10) = iVar7;
  FUN_00018f88();
  uVar5 = 8 << ((&DAT_ffffc717)[iVar10] & 0x3f);
  sVar4 = uVar5 - uVar2;
  if (uVar2 <= uVar5 && sVar4 != 0) {
    puVar9 =
        (undefined2 *)((int)(short)(extraout_D1w
                                    << ((&DAT_ffffc717)[iVar10] + 4 & 0x3f)) +
                       *(int *)((int)&DAT_ffffc722 + iVar10));
    sVar3 = extraout_D1w;
    puVar8 = extraout_A1;
    while (sVar3 = sVar3 + -1, sVar3 != 0) {
      puVar9 = (undefined2 *)((int)puVar9 - (int)(short)(sVar4 * 2));
      sVar6 = uVar2 - 1;
      do {
        puVar8 = puVar8 + -1;
        puVar9 = puVar9 + -1;
        *puVar9 = *puVar8;
        sVar6 = sVar6 + -1;
      } while (sVar6 != -1);
    }
  }
  return;
}

void FUN_00019146(void)

{
  byte bVar1;
  ushort uVar2;
  short extraout_D1w;
  short sVar3;
  short sVar4;
  ushort uVar5;
  short sVar6;
  int iVar7;
  undefined2 *extraout_A1;
  undefined2 *puVar8;
  undefined2 *puVar9;
  int iVar10;
  byte *unaff_A5;

  bVar1 = *unaff_A5;
  iVar10 = (int)(short)(ushort)bVar1;
  uVar2 = FUN_000191e2();
  *(ushort *)((int)&room_boundary_x + iVar10) = uVar2 * 0x10 + 0xfff;
  *(short *)((int)&camera_pos_x_int + iVar10) = extraout_D1w * 0x10 + 0xfff;
  sVar4 = 1;
  for (uVar5 = (ushort)(uVar2 - 1) >> 4; uVar5 != 0; uVar5 = uVar5 >> 1) {
    sVar4 = sVar4 + 1;
  }
  (&DAT_ffffc717)[iVar10] = (char)sVar4;
  iVar7 = -0x10000;
  if (bVar1 != 0) {
    iVar7 = (short)(0x4000 - (extraout_D1w << (sVar4 + 4U & 0x3f))) + -0x10000;
  }
  *(int *)((int)&DAT_ffffc722 + iVar10) = iVar7;
  FUN_00018f88();
  uVar5 = 8 << ((&DAT_ffffc717)[iVar10] & 0x3f);
  sVar4 = uVar5 - uVar2;
  if (uVar2 <= uVar5 && sVar4 != 0) {
    puVar9 =
        (undefined2 *)((int)(short)(extraout_D1w
                                    << ((&DAT_ffffc717)[iVar10] + 4 & 0x3f)) +
                       *(int *)((int)&DAT_ffffc722 + iVar10));
    sVar3 = extraout_D1w;
    puVar8 = extraout_A1;
    while (sVar3 = sVar3 + -1, sVar3 != 0) {
      puVar9 = (undefined2 *)((int)puVar9 - (int)(short)(sVar4 * 2));
      sVar6 = uVar2 - 1;
      do {
        puVar8 = puVar8 + -1;
        puVar9 = puVar9 + -1;
        *puVar9 = *puVar8;
        sVar6 = sVar6 + -1;
      } while (sVar6 != -1);
    }
  }
  return;
}

ulonglong FUN_000191e2(void)

{
  byte *in_A0;

  return (ulonglong)(CONCAT24(
                         *(undefined2 *)in_A0,
                         CONCAT31((int3)(((uint)*in_A0 << 4) >> 8), in_A0[2])) &
                     0xfffffffffff);
}

void FUN_000191f4(script_ctx_t *script_ctx, word *src)

{
  script_ctx->b = *src;
  script_ctx->i = src[1];
  script_ctx->k = *(union2_t *)(src + 2);
  script_ctx->f = *(union2_t *)(src + 3);
  return;
}

void FUN_00019206(char *text)

{
  ushort uVar1;
  ushort uVar2;
  undefined2 *puVar3;
  ushort *puVar4;

  uVar2 =
      (ushort)(*(short *)(text + 0x10) * *(short *)(text + 0x12) + 0xfU) >> 4;
  uVar1 = *(ushort *)(text + 0xc);
  if (-1 < (short)uVar1) {
    puVar3 = (undefined2 *)(&DAT_ffff9a8a + (short)(uVar1 >> 4));
    do {
      *puVar3 = 0xffff;
      uVar2 = uVar2 - 1;
      puVar3 = puVar3 + 1;
    } while (uVar2 != 0);
    return;
  }
  puVar4 = (ushort *)(int)(short)uVar1;
  do {
    *(undefined2 *)(&DAT_ffff9a8a + (short)(*puVar4 >> 4)) = 0xffff;
    uVar2 = uVar2 - 1;
    puVar4 = puVar4 + 1;
  } while (uVar2 != 0);
  return;
}

void text_do_something_and_set_script(char *script)

{
  SCRIPT_CTX_CURRENT.flags = SCRIPT_CTX_FLAG_A0;
  SCRIPT_CTX_CURRENT.script = script;
  FUN_000191f4(&SCRIPT_CTX_CURRENT, WORD_ARRAY_00019262);
  DAT_ffffd928 = 0x120;
  DAT_ffffd92a = 0xc000e0;
  FUN_00019206((char *)&SCRIPT_CTX_CURRENT);
  return;
}

void FUN_0001926a(void)

{
  short in_D0w;
  ushort uVar1;
  undefined2 *puVar2;
  ushort *puVar3;

  script_ctx_push_string((script_ctx_t *)&DAT_ffffd9f2, in_D0w);
  DAT_ffffd9f2 = 0xe0;
  FUN_000191f4((script_ctx_t *)&DAT_ffffd9f2, WORD_ARRAY_0001928c);
  related_to_text_4((script_ctx_t *)&DAT_ffffd9f2);
  uRamffffda00 = 0x101;
  uVar1 = (ushort)(sRamffffda02 * sRamffffda04 + 0xfU) >> 4;
  if (-1 < (short)uRamffffd9fe) {
    puVar2 = (undefined2 *)(&DAT_ffff9a8a + (short)(uRamffffd9fe >> 4));
    do {
      *puVar2 = 0xffff;
      uVar1 = uVar1 - 1;
      puVar2 = puVar2 + 1;
    } while (uVar1 != 0);
    return;
  }
  puVar3 = (ushort *)(int)(short)uRamffffd9fe;
  do {
    *(undefined2 *)(&DAT_ffff9a8a + (short)(*puVar3 >> 4)) = 0xffff;
    uVar1 = uVar1 - 1;
    puVar3 = puVar3 + 1;
  } while (uVar1 != 0);
  return;
}

void FUN_00019294(void)

{
  short in_D0w;
  ushort uVar1;
  undefined2 *puVar2;
  ushort *puVar3;

  script_ctx_push_string(&SCRIPT_CTX_CURRENT, in_D0w);
  SCRIPT_CTX_CURRENT.flags = SCRIPT_CTX_FLAG_A0;
  FUN_000191f4(&SCRIPT_CTX_CURRENT, WORD_ARRAY_000192ac);
  uVar1 = (ushort)(SCRIPT_CTX_CURRENT.i * SCRIPT_CTX_CURRENT.k.w + 0xf) >> 4;
  if (-1 < (short)SCRIPT_CTX_CURRENT.f.w) {
    puVar2 =
        (undefined2 *)(&DAT_ffff9a8a + (short)(SCRIPT_CTX_CURRENT.f.w >> 4));
    do {
      *puVar2 = 0xffff;
      uVar1 = uVar1 - 1;
      puVar2 = puVar2 + 1;
    } while (uVar1 != 0);
    return;
  }
  puVar3 = (ushort *)(int)(short)SCRIPT_CTX_CURRENT.f.w;
  do {
    *(undefined2 *)(&DAT_ffff9a8a + (short)(*puVar3 >> 4)) = 0xffff;
    uVar1 = uVar1 - 1;
    puVar3 = puVar3 + 1;
  } while (uVar1 != 0);
  return;
}

void FUN_000192b4(void)

{
  script_ctx_push_string(&SCRIPT_CTX_CURRENT, DAT_ffffd916);
  SCRIPT_CTX_CURRENT.flags = SCRIPT_CTX_FLAG_A1;
  FUN_000191f4(&SCRIPT_CTX_CURRENT, WORD_ARRAY_000192d0);
  FUN_00019206((char *)&SCRIPT_CTX_CURRENT);
  return;
}

void FUN_000192d8(void)

{
  short in_D0w;

  script_ctx_push_string(&SCRIPT_CTX_CURRENT, in_D0w);
  SCRIPT_CTX_CURRENT.flags = SCRIPT_CTX_FLAG_E0;
  FUN_000191f4(&SCRIPT_CTX_CURRENT, WORD_ARRAY_000192fe);
  related_to_text_4(&SCRIPT_CTX_CURRENT);
  SCRIPT_CTX_CURRENT.h = 0;
  SCRIPT_CTX_CURRENT.bf_09_arg = '\0';
  FUN_00019206((char *)&SCRIPT_CTX_CURRENT);
  related_to_text_3(&SCRIPT_CTX_CURRENT);
  return;
}

void FUN_00019306(short text_id)

{
  script_ctx_push_string(&SCRIPT_CTX_CURRENT, text_id);
  SCRIPT_CTX_CURRENT.flags = SCRIPT_CTX_FLAG_C0;
  FUN_000191f4(&SCRIPT_CTX_CURRENT, WORD_ARRAY_0001932c);
  related_to_text_4(&SCRIPT_CTX_CURRENT);
  SCRIPT_CTX_CURRENT.h = 1;
  SCRIPT_CTX_CURRENT.bf_09_arg = '\x01';
  FUN_00019206((char *)&SCRIPT_CTX_CURRENT);
  script_ctx_bf_02(&SCRIPT_CTX_CURRENT);
  return;
}

void FUN_00019334(short script_id)

{
  script_ctx_push_string(&SCRIPT_CTX_CURRENT, script_id);
  SCRIPT_CTX_CURRENT.flags = SCRIPT_CTX_FLAG_C1;
  FUN_000191f4(&SCRIPT_CTX_CURRENT, (word *)FUN_00019360);
  related_to_text_4(&SCRIPT_CTX_CURRENT);
  SCRIPT_CTX_CURRENT.h = 1;
  SCRIPT_CTX_CURRENT.bf_09_arg = '\x01';
  SCRIPT_CTX_CURRENT.bf_03_and_bf_06_arg_fed_to_vdp_data = 0x10e;
  FUN_00019206((char *)&SCRIPT_CTX_CURRENT);
  script_ctx_bf_02(&SCRIPT_CTX_CURRENT);
  return;
}

undefined2 FUN_00019360(void)

{
  uint uVar1;
  long extraout_D0;
  long lVar2;
  long extraout_D0_00;
  long extraout_D1;
  long lVar3;
  long extraout_D1_00;
  long unaff_D2;
  uint unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  uint *in_A0;
  entity_id_t unaff_A4;
  void *unaff_A6;

  uVar1 = *in_A0;
  *(byte *)in_A0 = *(byte *)in_A0 | 1;
  RELATED_TO_SAVE = '\0';
  script_ctx_bf_18_related = 0;
  DAT_ffffda70 = '\0';
  DAT_ffffda6f = 0xff;
  FUN_00019496();
  SCRIPT_CTX_CURRENT.flags = SCRIPT_CTX_FLAG_A0;
  FUN_0001944c();
  FUN_000191f4(&SCRIPT_CTX_CURRENT, WORD_ARRAY_00019408);
  script_ctx_push_string(&SCRIPT_CTX_CURRENT, DAT_ffffd916);
  lVar2 = extraout_D0;
  lVar3 = extraout_D1;
  do {
    exception_unk_0(&SCRIPT_CTX_CURRENT,
                    unaff_A4,
                    unaff_A6,
                    lVar2,
                    lVar3,
                    unaff_D2,
                    uVar1 & unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    if (DAT_ffffcc92 != '\x18') {
      FUN_0001a388();
    }
    related_to_text_3(&SCRIPT_CTX_CURRENT);
    lVar2 = extraout_D0_00;
    lVar3 = extraout_D1_00;
  } while ((char)SCRIPT_CTX_CURRENT.flags < '\0');
  if (DAT_ffffda70 != '\0') {
    FUN_00011de4();
  }
  if (RELATED_TO_SAVE != '\0') {
    save_menu_maybe();
    return 0;
  }
  FUN_000195d2();
  return script_ctx_bf_18_related;
}

undefined2 FUN_0001937a(void)

{
  long extraout_D0;
  long lVar1;
  long extraout_D0_00;
  long extraout_D1;
  long lVar2;
  long extraout_D1_00;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  entity_id_t unaff_A4;
  void *unaff_A6;

  RELATED_TO_SAVE = '\0';
  script_ctx_bf_18_related = 0;
  DAT_ffffda70 = '\0';
  DAT_ffffda6f = 0;
  if ((ushort)(comp_pos_y.fixed.i - DAT_ffffc746) < 0x70) {
    DAT_ffffda6f = 0xff;
  }
  FUN_00019496();
  SCRIPT_CTX_CURRENT.flags = SCRIPT_CTX_FLAG_A0;
  FUN_0001944c();
  FUN_000191f4(&SCRIPT_CTX_CURRENT, WORD_ARRAY_00019408);
  script_ctx_push_string(&SCRIPT_CTX_CURRENT, DAT_ffffd916);
  lVar1 = extraout_D0;
  lVar2 = extraout_D1;
  do {
    exception_unk_0(&SCRIPT_CTX_CURRENT,
                    unaff_A4,
                    unaff_A6,
                    lVar1,
                    lVar2,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    if (DAT_ffffcc92 != '\x18') {
      FUN_0001a388();
    }
    related_to_text_3(&SCRIPT_CTX_CURRENT);
    lVar1 = extraout_D0_00;
    lVar2 = extraout_D1_00;
  } while ((char)SCRIPT_CTX_CURRENT.flags < '\0');
  if (DAT_ffffda70 != '\0') {
    FUN_00011de4();
  }
  if (RELATED_TO_SAVE != '\0') {
    save_menu_maybe();
    return 0;
  }
  FUN_000195d2();
  return script_ctx_bf_18_related;
}

void script_ctx_push_string(script_ctx_t *ctx, short script_id)

{
  script_t script;

  script = script_fetch(script_id);
  ctx->script = script;
  return;
}

script_t script_fetch(short script_id)

{
  script_t script;

  script = script_get((script_id + -1) * 2);
  return script;
}

void FUN_00019428(script_ctx_t *ctx, unk1_t *param_2)

{
  undefined1 uVar1;

  param_2->a = 0xe0;
  param_2->h = ctx->b;
  *(undefined4 *)&param_2->p = *(undefined4 *)&ctx->i;
  *(union2_t *)&param_2->l = ctx->f;
  related_to_text_4((script_ctx_t *)param_2);
  uVar1 = ctx->e;
  param_2->j = ctx->d;
  param_2->k = uVar1;
  return;
}

void FUN_0001944c(void)

{
  ushort uVar1;
  short sVar2;
  word *pwVar3;
  ushort *puVar4;
  ushort *puVar5;

  pwVar3 = compressed_data_indices;
  sVar2 = 2;
  uVar1 = 0;
  puVar4 = &DAT_ffffd922;
  do {
    puVar5 = puVar4;
    if (*pwVar3 == 0xffff) {
      *(undefined1 *)(pwVar3 + 0x40) = 0xff;
      puVar5 = puVar4 + 1;
      *puVar4 = uVar1;
      sVar2 = sVar2 + -1;
      if (sVar2 == -1) {
        return;
      }
    }
    pwVar3 = pwVar3 + 1;
    uVar1 = uVar1 + 0x20;
    puVar4 = puVar5;
  } while (uVar1 < 0x600);
  do {
    // WARNING: Do nothing block with infinite loop
  } while (true);
}

void FUN_00019478(void)

{
  short sVar1;

  vdp_set_vram_write_addr((void *)0xd100);
  sVar1 = 0xbf;
  do {
    VDP_DATA = 0x8781;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return;
}

undefined8 FUN_00019496(void)

{
  ushort uVar1;
  long extraout_D0;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  byte *pbVar2;
  byte *extraout_A1;
  word *unaff_A2;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar3;

  FUN_00019478();
  uVar1 = 5;
  if (DAT_ffffda6f == '\0') {
    uVar1 = 5;
  }
  do {
    uVar3 = FUN_000184a8();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar3 >> 0x20),
                    (long)uVar3,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    if (DAT_ffffcc92 != '\x18') {
      FUN_0001a388();
    }
    uVar1 = uVar1 + 1;
  } while (uVar1 < 0xb);
  pbVar2 = &BYTE_000194e4;
  do {
    unaff_D2 = CONCAT22((short)((uint)unaff_D2 >> 0x10), 0xd100);
    FUN_00027ee6(pbVar2, unaff_A2, 0xd100, (char)unaff_D4);
    uVar3 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            extraout_D0,
                            extraout_D1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    pbVar2 = extraout_A1;
  } while (*extraout_A1 != 0);
  return uVar3;
}

void FUN_000195d2(void)

{
  ushort uVar1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar2;

  FUN_00019478();
  uVar1 = 10;
  if (DAT_ffffda6f == '\0') {
    uVar1 = 10;
  }
  do {
    uVar2 = FUN_000184a8();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar2 >> 0x20),
                    (long)uVar2,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar1 = uVar1 - 1;
  } while (3 < uVar1);
  return;
}

void related_to_text_3(script_ctx_t *ctx)

{
  byte *script;
  byte bVar1;
  script_ctx_flag_t sVar2;
  uint8_t uVar3;
  short sVar4;
  script_name_id_t id;
  undefined4 extraout_D0;
  uint unaff_D2;
  void **glyph;
  script_t pcVar5;

  if (-1 < (char)ctx->flags) {
    return;
  }
  sVar2 = ctx->flags;
  ctx->flags = sVar2 | SCRIPT_CTX_FLAG_40;
  if ((sVar2 & SCRIPT_CTX_FLAG_40) == SCRIPT_CTX_FLAG_NONE) {
    related_to_text_4(ctx);
    ctx->h = 4;
    ctx->bf_09_arg = '\x01';
  }
  // WARNING: Switch is manually overridden
  // FIXME Case 0 not handled in C.
  switch (ctx->mode) {
  case SCRIPT_MODE_02:
    // Check if the script should be sped up.
    if ((((ctx->flags & SCRIPT_CTX_FLAG_DISABLE_SPEED_UP) !=
          SCRIPT_CTX_FLAG_NONE) ||
         ((gamepad_held & GAMEPAD_B) == GAMEPAD_NONE)) &&
        (uVar3 = ctx->bf_09_arg + 0xff,
         ctx->bf_09_arg = uVar3,
         uVar3 != '\0')) {
      return;
    }
    ctx->mode = SCRIPT_MODE_00;
    break;
  case SCRIPT_MODE_04:
    FUN_00019fa2();
    if ((gamepad_pressed_prev & (GAMEPAD_ACCEPT | GAMEPAD_B)) == GAMEPAD_NONE) {
      return;
    }
    if ((ctx->flags & SCRIPT_CTX_FLAG_02) != SCRIPT_CTX_FLAG_NONE) {
      FUN_00019fb0();
    }
    ctx->mode = SCRIPT_MODE_00;
    break;
  case SCRIPT_MODE_NEW_LINE:
    // WARNING: Switch is manually overridden
    switch (ctx->prompt_related) {
    case '\x04':
      goto FUN_0001968c;
    }
  case SCRIPT_MODE_08:
    FUN_0001a05a();
    ctx->prompt_related = ctx->prompt_related + '\x02';
    return;
  case SCRIPT_MODE_0A:
  FUN_0001968c:
    ctx->mode = SCRIPT_MODE_00;
    glyph = *(void ***)&ctx->q;
    if (glyph != (void **)0x0) {
      ctx->q = 0;
      ctx->r = 0;
      ctx->t = 0;
      goto FUN_00019ad8;
    }
    return;
  case SCRIPT_MODE_PROMPT:
    // WARNING: Could not recover jumptable at 0x000196ac. Too many branches
    // WARNING: Treating indirect jump as call
    (*(code *)((int)&WORD_000196b0 +
               (int)*(short *)((int)&WORD_000196b0 +
                               (int)(short)(ushort)ctx->prompt_related)))();
    return;
  case SCRIPT_MODE_INCANT_SPELL:
    // WARNING: Could not recover jumptable at 0x000197fa. Too many branches
    // WARNING: Treating indirect jump as call
    (*(code *)((int)&WORD_000197fe +
               (int)*(short *)((int)&WORD_000197fe +
                               (int)(short)(ushort)ctx->prompt_related)))();
    return;
  case SCRIPT_MODE_QUIZZ:
    // WARNING: Could not recover jumptable at 0x00019898. Too many branches
    // WARNING: Treating indirect jump as call
    (*(code *)((int)&WORD_0001989c +
               (int)*(short *)((int)&WORD_0001989c +
                               (int)(short)(ushort)ctx->prompt_related)))();
    return;
  }
  do {
    while (true) {
      while (true) {
        while (true) {
          script = (byte *)ctx->script;
          bVar1 = *script;
          ctx->script = (script_t)(script + 1);
          if (bVar1 != 0xff)
            break;
          if (ctx->script_stack_offset == 0) {
            ctx->flags = SCRIPT_CTX_FLAG_NONE;
            return;
          }
          sVar4 = ctx->script_stack_offset - 4;
          ctx->script = *(script_t *)((int)&ctx->script_stack + (int)sVar4);
          ctx->script_stack_offset = (uint8_t)sVar4;
        }
        if (bVar1 < 0xc0)
          break;
        pcVar5 = text_command_c0_to_fe((script_t)script);
        ctx->script = pcVar5;
      }
      if (bVar1 < 0xb4)
        break;
      if ((byte)(bVar1 + 0x4c) < 4) {
        id.type = bVar1 + 0x4c;
        id.index = *ctx->script;
        ctx->script = ctx->script + 1;
        text_push_name(ctx, id);
      } else {
        (*(code *)((int)&text_command_p +
                   (int)*(short *)((int)&text_command_p +
                                   (int)(short)((ushort)(byte)(bVar1 + 0x48) *
                                                2))))();
        if (ctx->mode != SCRIPT_MODE_00) {
          return;
        }
      }
    }
    glyph = script_get_glyph_info_p(ctx, (ushort)bVar1);
    script_ctx_display_1(
        ctx,
        (short)CONCAT31((int3)((uint)extraout_D0 >> 8), *(undefined1 *)glyph));
    if (ctx->mode != SCRIPT_MODE_00) {
      *(void ***)&ctx->q = glyph;
      return;
    }
  FUN_00019ad8:
    text_unknown_4(ctx, (byte *)glyph, unaff_D2);
    ctx->bf_09_arg = ctx->h;
  } while (ctx->h == '\0');
  ctx->mode = SCRIPT_MODE_02;
  return;
}

void FUN_0001968c(script_ctx_t *ctx)

{
  byte *script;
  byte bVar1;
  short sVar2;
  script_name_id_t id;
  undefined4 extraout_D0;
  uint unaff_D2;
  void **glyph;
  script_t pcVar3;

  ctx->mode = SCRIPT_MODE_00;
  glyph = *(void ***)&ctx->q;
  if (glyph == (void **)0x0) {
    return;
  }
  ctx->q = 0;
  ctx->r = 0;
  ctx->t = 0;
  do {
    text_unknown_4(ctx, (byte *)glyph, unaff_D2);
    ctx->bf_09_arg = ctx->h;
    if (ctx->h != '\0') {
      ctx->mode = SCRIPT_MODE_02;
      return;
    }
    while (true) {
      while (true) {
        while (true) {
          script = (byte *)ctx->script;
          bVar1 = *script;
          ctx->script = (script_t)(script + 1);
          if (bVar1 != 0xff)
            break;
          if (ctx->script_stack_offset == 0) {
            ctx->flags = SCRIPT_CTX_FLAG_NONE;
            return;
          }
          sVar2 = ctx->script_stack_offset - 4;
          ctx->script = *(script_t *)((int)&ctx->script_stack + (int)sVar2);
          ctx->script_stack_offset = (uint8_t)sVar2;
        }
        if (bVar1 < 0xc0)
          break;
        pcVar3 = text_command_c0_to_fe((script_t)script);
        ctx->script = pcVar3;
      }
      if (bVar1 < 0xb4)
        break;
      if ((byte)(bVar1 + 0x4c) < 4) {
        id.type = bVar1 + 0x4c;
        id.index = *ctx->script;
        ctx->script = ctx->script + 1;
        text_push_name(ctx, id);
      } else {
        (*(code *)((int)&text_command_p +
                   (int)*(short *)((int)&text_command_p +
                                   (int)(short)((ushort)(byte)(bVar1 + 0x48) *
                                                2))))();
        if (ctx->mode != SCRIPT_MODE_00) {
          return;
        }
      }
    }
    glyph = script_get_glyph_info_p(ctx, (ushort)bVar1);
    script_ctx_display_1(
        ctx,
        (short)CONCAT31((int3)((uint)extraout_D0 >> 8), *(undefined1 *)glyph));
    if (ctx->mode != SCRIPT_MODE_00) {
      *(void ***)&ctx->q = glyph;
      return;
    }
  } while (true);
}

void FUN_000196a2(script_ctx_t *ctx)

{
  // WARNING: Could not recover jumptable at 0x000196ac. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_000196b0 +
             (int)*(short *)((int)&WORD_000196b0 +
                             (int)(short)(ushort)ctx->prompt_related)))();
  return;
}

void FUN_000196d6(script_ctx_t *ctx)

{
  byte bVar1;
  short extraout_D0w;
  undefined4 extraout_D1;
  void *vram_dst;
  undefined4 *extraout_A0;
  undefined4 *extraout_A0_00;
  undefined4 *extraout_A0_01;
  undefined4 *extraout_A1;
  undefined4 *extraout_A1_00;

  bVar1 = ctx->prompt_related;
  vdp_set_vram_write_addr((void *)(-(ushort)bVar1 + -0x2ec6));
  vram_dst = (void *)(-(ushort)bVar1 + -0x2e86);
  *extraout_A0 = *extraout_A1;
  do {
    vdp_set_vram_write_addr(vram_dst);
    vram_dst = (void *)((short)vram_dst + 0x40);
    *extraout_A0_00 = extraout_D1;
  } while (extraout_D0w != 0);
  vdp_set_vram_write_addr(vram_dst);
  *extraout_A0_01 = *extraout_A1_00;
  ctx->prompt_related = ctx->prompt_related + '\x02';
  return;
}

void FUN_000196e8(script_ctx_t *ctx)

{
  short extraout_D0w;
  undefined4 extraout_D1;
  void *vram_dst;
  undefined4 *extraout_A0;
  undefined4 *extraout_A0_00;
  undefined4 *extraout_A0_01;
  undefined4 *extraout_A1;
  undefined4 *extraout_A1_00;
  byte ctx_arg;

  ctx_arg = ctx->prompt_related;
  vdp_set_vram_write_addr((void *)(-(ushort)ctx_arg + -0x2ec6));
  vram_dst = (void *)(-(ushort)ctx_arg + -0x2e86);
  *extraout_A0 = *extraout_A1;
  do {
    vdp_set_vram_write_addr(vram_dst);
    vram_dst = (void *)((short)vram_dst + 0x40);
    *extraout_A0_00 = extraout_D1;
  } while (extraout_D0w != 0);
  vdp_set_vram_write_addr(vram_dst);
  *extraout_A0_01 = *extraout_A1_00;
  ctx->prompt_related = ctx->prompt_related + '\x02';
  return;
}

void FUN_00019732(script_ctx_t *ctx)

{
  FUN_000196e8(ctx);
  SCRIPT_ID = *(undefined2 *)ctx->script;
  ctx->script = ctx->script + 2;
  SCRIPT_PROMPT_RESPONSE = 0;
  FUN_0001974e(ctx);
  return;
}

void FUN_0001974e(script_ctx_t *ctx)

{
  FUN_00019428(ctx, (unk1_t *)&DAT_ffffda2a);
  ctx->b = ctx->b + 4;
  ctx->h = 0;
  ctx->bf_09_arg = '\0';
  script_ctx_push_string(ctx, SCRIPT_ID);
  related_to_text_3(ctx);
  return;
}

uint FUN_00019770(script_ctx_t *text_p)

{
  uint extraout_D0;
  uint extraout_D0_00;
  gamepad_t gamepad;

  if ((gamepad_pressed_prev & GAMEPAD_ACCEPT) != GAMEPAD_NONE) {
    audio_play(SOUND_ID_RES_KEY);
    text_p->prompt_related = text_p->prompt_related + '\x02';
    return extraout_D0;
  }
  if ((gamepad_pressed_prev & GAMEPAD_UP) == GAMEPAD_NONE) {
    gamepad = gamepad_pressed_prev & GAMEPAD_B;
    if ((gamepad == GAMEPAD_NONE) &&
        ((gamepad_pressed_prev & GAMEPAD_DOWN) == GAMEPAD_NONE)) {
      return (uint)gamepad;
    }
    if (SCRIPT_PROMPT_RESPONSE != 0) {
      return (uint)gamepad;
    }
  } else if (SCRIPT_PROMPT_RESPONSE == 0) {
    return (uint)(gamepad_pressed_prev & GAMEPAD_ACCEPT);
  }
  SCRIPT_PROMPT_RESPONSE = SCRIPT_PROMPT_RESPONSE ^ 1;
  audio_play(SOUND_ID_RES_KEY);
  FUN_0001974e(text_p);
  return extraout_D0_00;
}

void FUN_000197ba(void)

{
  byte bVar1;
  short extraout_D0w;
  undefined4 extraout_D1;
  void *vram_dst;
  undefined4 *extraout_A0;
  undefined4 *extraout_A0_00;
  undefined4 *extraout_A0_01;
  undefined4 *extraout_A1;
  undefined4 *extraout_A1_00;
  int unaff_A3;

  *(undefined1 *)(unaff_A3 + 1) = 0;
  bVar1 = *(byte *)(unaff_A3 + 0x1a);
  vdp_set_vram_write_addr((void *)(bVar1 + 0xd116));
  vram_dst = (void *)(bVar1 + 0xd156);
  *extraout_A0 = *extraout_A1;
  do {
    vdp_set_vram_write_addr(vram_dst);
    vram_dst = (void *)((short)vram_dst + 0x40);
    *extraout_A0_00 = extraout_D1;
  } while (extraout_D0w != 0);
  vdp_set_vram_write_addr(vram_dst);
  *extraout_A0_01 = *extraout_A1_00;
  *(char *)(unaff_A3 + 0x1a) = *(char *)(unaff_A3 + 0x1a) + '\x02';
  return;
}

void FUN_000197d0(void)

{
  byte bVar1;
  short extraout_D0w;
  undefined4 extraout_D1;
  void *vram_dst;
  undefined4 *extraout_A0;
  undefined4 *extraout_A0_00;
  undefined4 *extraout_A0_01;
  undefined4 *extraout_A1;
  undefined4 *extraout_A1_00;
  int unaff_A3;

  bVar1 = *(byte *)(unaff_A3 + 0x1a);
  vdp_set_vram_write_addr((void *)(bVar1 + 0xd116));
  vram_dst = (void *)(bVar1 + 0xd156);
  *extraout_A0 = *extraout_A1;
  do {
    vdp_set_vram_write_addr(vram_dst);
    vram_dst = (void *)((short)vram_dst + 0x40);
    *extraout_A0_00 = extraout_D1;
  } while (extraout_D0w != 0);
  vdp_set_vram_write_addr(vram_dst);
  *extraout_A0_01 = *extraout_A1_00;
  *(char *)(unaff_A3 + 0x1a) = *(char *)(unaff_A3 + 0x1a) + '\x02';
  return;
}

void FUN_000197d4(void)

{
  byte bVar1;
  short extraout_D0w;
  undefined4 extraout_D1;
  void *vram_dst;
  undefined4 *extraout_A0;
  undefined4 *extraout_A0_00;
  undefined4 *extraout_A0_01;
  undefined4 *extraout_A1;
  undefined4 *extraout_A1_00;
  int unaff_A3;

  bVar1 = *(byte *)(unaff_A3 + 0x1a);
  vdp_set_vram_write_addr((void *)(bVar1 + 0xd116));
  vram_dst = (void *)(bVar1 + 0xd156);
  *extraout_A0 = *extraout_A1;
  do {
    vdp_set_vram_write_addr(vram_dst);
    vram_dst = (void *)((short)vram_dst + 0x40);
    *extraout_A0_00 = extraout_D1;
  } while (extraout_D0w != 0);
  vdp_set_vram_write_addr(vram_dst);
  *extraout_A0_01 = *extraout_A1_00;
  *(char *)(unaff_A3 + 0x1a) = *(char *)(unaff_A3 + 0x1a) + '\x02';
  return;
}

void FUN_00019804(script_ctx_t *ctx)

{
  undefined2 extraout_D0w;
  uint unaff_D2;
  undefined2 *extraout_A0;

  script_ctx_push_name(ctx, (script_name_id_t)0xb403, unaff_D2);
  if (SPELL_TO_INCANT[1] == '\0') {
    ctx->bf_05_and_13_arg_vram_address_related = WORD_ffffda24;
    ctx->prompt_related = ctx->prompt_related + '\x02';
    return;
  }
  SPELL_TO_INCANT = SPELL_TO_INCANT + 1;
  script_ctx_display_3(ctx, 0xffff);
  vdp_set_vram_write_addr((void *)unaff_D2);
  *extraout_A0 = extraout_D0w;
  ctx->bf_05_and_13_arg_vram_address_related =
      ctx->bf_05_and_13_arg_vram_address_related + 1;
  return;
}

void FUN_0001982a(script_ctx_t *ctx)

{
  script_name_id_t id;
  undefined2 extraout_D0w;
  uint unaff_D2;
  short *script_next;
  short *psVar1;
  undefined2 *extraout_A0;
  char *script;

  id.type = '\0';
  id.index = '\x01';
  if ((((gamepad_pressed_prev & GAMEPAD_A) == GAMEPAD_NONE) &&
       (id.type = '\0',
        id.index = '\x02',
        (gamepad_pressed_prev & GAMEPAD_B) == GAMEPAD_NONE)) &&
      (id.type = '\0',
       id.index = '\x03',
       (gamepad_pressed_prev & GAMEPAD_C) == GAMEPAD_NONE)) {
    return;
  }
  script_ctx_push_name(ctx, (script_name_id_t)((short)id + -0x4bfd), unaff_D2);
  script = ctx->script;
  script_next = (short *)(script + 1);
  if (id.index == *script) {
    if (*(char *)script_next != '\0') {
      ctx->script = (script_t)script_next;
      script_ctx_display_3(ctx, 0xffff);
      vdp_set_vram_write_addr((void *)unaff_D2);
      *extraout_A0 = extraout_D0w;
      ctx->bf_05_and_13_arg_vram_address_related =
          ctx->bf_05_and_13_arg_vram_address_related + 1;
      return;
    }
    script = script + 4;
  } else {
    do {
      psVar1 = script_next;
      script_next = (short *)((int)psVar1 + 1);
    } while (*(char *)psVar1 != '\0');
    script = (char *)((int)psVar1 + *(short *)((int)psVar1 + 1) + 1);
  }
  ctx->script = script;
  ctx->prompt_related = ctx->prompt_related + '\x02';
  return;
}

void FUN_00019886(void)

{
  byte *script;
  byte bVar1;
  short sVar2;
  script_name_id_t id;
  undefined4 extraout_D0;
  uint unaff_D2;
  void **glyph;
  script_ctx_t *unaff_A3;
  script_t pcVar3;

  unaff_A3->mode = SCRIPT_MODE_00;
  do {
    while (true) {
      while (true) {
        while (true) {
          script = (byte *)unaff_A3->script;
          bVar1 = *script;
          unaff_A3->script = (script_t)(script + 1);
          if (bVar1 != 0xff)
            break;
          if (unaff_A3->script_stack_offset == 0) {
            unaff_A3->flags = SCRIPT_CTX_FLAG_NONE;
            return;
          }
          sVar2 = unaff_A3->script_stack_offset - 4;
          unaff_A3->script =
              *(script_t *)((int)&unaff_A3->script_stack + (int)sVar2);
          unaff_A3->script_stack_offset = (uint8_t)sVar2;
        }
        if (bVar1 < 0xc0)
          break;
        pcVar3 = text_command_c0_to_fe((script_t)script);
        unaff_A3->script = pcVar3;
      }
      if (bVar1 < 0xb4)
        break;
      if ((byte)(bVar1 + 0x4c) < 4) {
        id.type = bVar1 + 0x4c;
        id.index = *unaff_A3->script;
        unaff_A3->script = unaff_A3->script + 1;
        text_push_name(unaff_A3, id);
      } else {
        (*(code *)((int)&text_command_p +
                   (int)*(short *)((int)&text_command_p +
                                   (int)(short)((ushort)(byte)(bVar1 + 0x48) *
                                                2))))();
        if (unaff_A3->mode != SCRIPT_MODE_00) {
          return;
        }
      }
    }
    glyph = script_get_glyph_info_p(unaff_A3, (ushort)bVar1);
    script_ctx_display_1(
        unaff_A3,
        (short)CONCAT31((int3)((uint)extraout_D0 >> 8), *(undefined1 *)glyph));
    if (unaff_A3->mode != SCRIPT_MODE_00) {
      *(void ***)&unaff_A3->q = glyph;
      return;
    }
    text_unknown_4(unaff_A3, (byte *)glyph, unaff_D2);
    unaff_A3->bf_09_arg = unaff_A3->h;
  } while (unaff_A3->h == '\0');
  unaff_A3->mode = SCRIPT_MODE_02;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000198ca(void)

{
  char *pcVar1;
  script_ctx_t *unaff_A3;

  FUN_00019428(unaff_A3, (unk1_t *)&DAT_ffffda2a);
  unaff_A3->h = 8;
  unaff_A3->bf_09_arg = '\x01';
  script_ctx_push_string(unaff_A3,
                         CONCAT11((char)((ushort)_DAT_ffffda60 >> 8),
                                  (&DAT_ffffda62)[_DAT_ffffda60]) +
                             0x30);
  pcVar1 = (char *)((short)unaff_A3 + 0x1a);
  *pcVar1 = *pcVar1 + '\x02';
  return;
}

void FUN_000198f6(void)

{
  short unaff_A3w;

  related_to_text_3((script_ctx_t *)&DAT_ffffda2a);
  if (-1 < DAT_ffffda2a) {
    *(undefined1 *)(unaff_A3w + 0x1a) = 0;
  }
  return;
}

void FUN_0001990e(script_ctx_t *ctx)

{
  FUN_000196e8(ctx);
  SCRIPT_PROMPT_RESPONSE = 0;
  DAT_ffffda6d = 0x3c;
  DAT_ffffda6e = 3;
  FUN_00019428(ctx, (unk1_t *)&DAT_ffffda2a);
  ctx->b = ctx->b + 4;
  ctx->h = 0;
  ctx->bf_09_arg = '\0';
  script_ctx_push_string(ctx, 0x69);
  related_to_text_3(ctx);
  return;
}

// FIXME Where is it called?

uint FUN_00019948(void)

{
  uint extraout_D0;
  uint in_D0;
  script_ctx_t *unaff_A3;

  DAT_ffffda6d = DAT_ffffda6d + -1;
  if (DAT_ffffda6d == '\0') {
    DAT_ffffda6d = '<';
    DAT_ffffda6e = DAT_ffffda6e + -1;
    if (DAT_ffffda6e == '\0') {
      SCRIPT_PROMPT_RESPONSE = 2;
      goto LAB_00019960;
    }
    audio_play(SOUND_ID_COUNT);
  }
  in_D0 = (uint)(gamepad_pressed_prev & (GAMEPAD_ACCEPT | GAMEPAD_B));
  if ((gamepad_pressed_prev & (GAMEPAD_ACCEPT | GAMEPAD_B)) == GAMEPAD_NONE) {
    if ((gamepad_pressed_prev & GAMEPAD_UP) == GAMEPAD_NONE) {
      if ((gamepad_pressed_prev & GAMEPAD_DOWN) == GAMEPAD_NONE) {
        return in_D0;
      }
      if (SCRIPT_PROMPT_RESPONSE != 0) {
        return in_D0;
      }
    } else if (SCRIPT_PROMPT_RESPONSE == 0) {
      return in_D0;
    }
    SCRIPT_PROMPT_RESPONSE = SCRIPT_PROMPT_RESPONSE ^ 1;
    FUN_00019428(unaff_A3, (unk1_t *)&DAT_ffffda2a);
    unaff_A3->b = unaff_A3->b + 4;
    unaff_A3->h = 0;
    unaff_A3->bf_09_arg = '\0';
    script_ctx_push_string(unaff_A3, 0x69);
    related_to_text_3(unaff_A3);
    return extraout_D0;
  }
LAB_00019960:
  unaff_A3->prompt_related = unaff_A3->prompt_related + '\x02';
  return in_D0;
}

// FIXME Where is it called?

void FUN_0001999c(void)

{
  int unaff_A3;

  FUN_000197d4();
  *(undefined1 *)(unaff_A3 + 0x1a) = 0x2a;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address
// FIXME Where is it called?

void script_sphinx_check_response(void)

{
  int *piVar1;
  short *psVar2;
  short unaff_A3w;

  if (SCRIPT_PROMPT_RESPONSE == SCRIPT_SPHINX_CORRECT_ANSWER) {
    audio_play(SOUND_ID_TRUE);
    FUN_00029dda();
    _DAT_ffffda60 = _DAT_ffffda60 + 1;
    if (_DAT_ffffda60 < 10) {
      *(undefined1 *)(unaff_A3w + 0x1a) = 0x26;
      return;
    }
    piVar1 = (int *)(unaff_A3w + 4);
    *piVar1 = *piVar1 + 4;
  } else {
    FUN_00029dc0();
    audio_play(SOUND_ID_FALSE);
    psVar2 = *(short **)(unaff_A3w + 4);
    if (SCRIPT_PROMPT_RESPONSE == '\x02') {
      psVar2 = psVar2 + 1;
    }
    *(int *)(unaff_A3w + 4) = (int)psVar2 + (int)*psVar2;
  }
  *(char *)(unaff_A3w + 0x1a) = *(char *)(unaff_A3w + 0x1a) + '\x02';
  DAT_ffffda6d = 0x28;
  return;
}

void FUN_00019a18(void)

{
  int unaff_A3;

  DAT_ffffda6d = DAT_ffffda6d + -1;
  if (DAT_ffffda6d != '\0') {
    return;
  }
  *(undefined1 *)(unaff_A3 + 1) = 0;
  drop_pepelogoo();
  return;
}

void text_parse(script_ctx_t *ctx)

{
  byte *script_00;
  short sVar1;
  script_name_id_t id;
  undefined4 extraout_D0;
  uint unaff_D2;
  void **glyph_p;
  script_t pcVar2;
  script_t script;
  byte c;

  do {
    while (true) {
      while (true) {
        while (true) {
          script_00 = (byte *)ctx->script;
          c = *script_00;
          ctx->script = (script_t)(script_00 + 1);
          if (c != STRING_END)
            break;
          if (ctx->script_stack_offset == 0) {
            ctx->flags = SCRIPT_CTX_FLAG_NONE;
            return;
          }
          sVar1 = ctx->script_stack_offset - 4;
          ctx->script = *(script_t *)((int)&ctx->script_stack + (int)sVar1);
          ctx->script_stack_offset = (uint8_t)sVar1;
        }
        if (c < 0xc0)
          break;
        // If c is between #c0 and #fe included.
        pcVar2 = text_command_c0_to_fe((script_t)script_00);
        ctx->script = pcVar2;
      }
      if (c < 0xb4)
        break;
      // If c is between #b4 and #b7 included.
      if ((byte)(c + 0x4c) < 4) {
        id.type = c + 0x4c;
        id.index = *ctx->script;
        // The character is one of the following text flow commands:
        // #b4: insert a character name from #158816
        // #b5: insert an item name from FIXME
        // #b6: insert a location name from #1570a0
        // #b7: insert another text from FIXME
        ctx->script = ctx->script + 1;
        text_push_name(ctx, id);
      } else {
        // The character is one of the following text flow commands:
        // #b8: ???
        // #b9: ???
        // #ba: ???
        // #bb: ???
        // #bc: line break
        // #bd: more
        // #be: ???
        // #bf: ???
        //
        // `c + 0x48` really is `c - 0xb8` to get the relative value between #b8
        // and #bf, so a value beween 0 and 7 included. #19ac8 has a jump table
        // containing 8 words, each word being the offset to jumpt to from it to
        // execute the command.
        //
        // Really is just `text_command_p[c - 0xb8]()`
        (*(code *)((int)&text_command_p +
                   (int)*(
                       short *)((int)&text_command_p +
                                (int)(short)((ushort)(byte)(c + 0x48) * 2))))();
        if (ctx->mode != SCRIPT_MODE_00) {
          return;
        }
      }
    }
    glyph_p = script_get_glyph_info_p(ctx, (ushort)c);
    script_ctx_display_1(ctx,
                         (short)CONCAT31((int3)((uint)extraout_D0 >> 8),
                                         *(undefined1 *)glyph_p));
    if (ctx->mode != SCRIPT_MODE_00) {
      *(void ***)&ctx->q = glyph_p;
      return;
    }
    text_unknown_4(ctx, (byte *)glyph_p, unaff_D2);
    ctx->bf_09_arg = ctx->h;
  } while (ctx->h == '\0');
  ctx->mode = SCRIPT_MODE_02;
  return;
}

void FUN_00019ad8(void)

{
  byte *script;
  byte bVar1;
  short sVar2;
  script_name_id_t id;
  undefined4 extraout_D0;
  uint unaff_D2;
  void **in_A0;
  script_ctx_t *unaff_A3;
  script_t pcVar3;

  do {
    text_unknown_4(unaff_A3, (byte *)in_A0, unaff_D2);
    unaff_A3->bf_09_arg = unaff_A3->h;
    if (unaff_A3->h != '\0') {
      unaff_A3->mode = SCRIPT_MODE_02;
      return;
    }
    while (true) {
      while (true) {
        while (true) {
          script = (byte *)unaff_A3->script;
          bVar1 = *script;
          unaff_A3->script = (script_t)(script + 1);
          if (bVar1 != 0xff)
            break;
          if (unaff_A3->script_stack_offset == 0) {
            unaff_A3->flags = SCRIPT_CTX_FLAG_NONE;
            return;
          }
          sVar2 = unaff_A3->script_stack_offset - 4;
          unaff_A3->script =
              *(script_t *)((int)&unaff_A3->script_stack + (int)sVar2);
          unaff_A3->script_stack_offset = (uint8_t)sVar2;
        }
        if (bVar1 < 0xc0)
          break;
        pcVar3 = text_command_c0_to_fe((script_t)script);
        unaff_A3->script = pcVar3;
      }
      if (bVar1 < 0xb4)
        break;
      if ((byte)(bVar1 + 0x4c) < 4) {
        id.type = bVar1 + 0x4c;
        id.index = *unaff_A3->script;
        unaff_A3->script = unaff_A3->script + 1;
        text_push_name(unaff_A3, id);
      } else {
        (*(code *)((int)&text_command_p +
                   (int)*(short *)((int)&text_command_p +
                                   (int)(short)((ushort)(byte)(bVar1 + 0x48) *
                                                2))))();
        if (unaff_A3->mode != SCRIPT_MODE_00) {
          return;
        }
      }
    }
    in_A0 = script_get_glyph_info_p(unaff_A3, (ushort)bVar1);
    script_ctx_display_1(
        unaff_A3,
        (short)CONCAT31((int3)((uint)extraout_D0 >> 8), *(undefined1 *)in_A0));
    if (unaff_A3->mode != SCRIPT_MODE_00) {
      *(void ***)&unaff_A3->q = in_A0;
      return;
    }
  } while (true);
}

void script_get_glyph_info_for_script_p(script_ctx_t *ctx, char *script, word c)

{
  script_t old_script;

  old_script = ctx->script;
  ctx->script = script;
  script_get_glyph_info_p(ctx, c);
  ctx->script = old_script;
  return;
}

// C is wrong.
//
// What happened to the return of `text_get_character_p()`?
// It should be something like `c = text_get_character_p()[c]`.
//
// Also, `text_p[1] = text_p[1] + 1;` should have something like `c =
// *text_p[1]` after it.
//
// c_2 should just be c updated as described.
//
// The last line should just be `return glyph_p[c];` en utilisant des tableaux
// classiques.

void **script_get_glyph_info_p(script_ctx_t *ctx, word c)

{
  short c_2;
  void **glyph_info_p;

  if ((byte)c < 0xb0) {
    script_get_character_p();
  } else {
    ctx->script = ctx->script + 1;
  }
  glyph_info_p = script_get_glyph_info_table();
  return (void **)((int)*(short *)((int)glyph_info_p + (int)(short)(c_2 * 2)) +
                   (int)glyph_info_p);
}

void script_ctx_dakuten(script_ctx_t *script)

{
  script->flags = script->flags | SCRIPT_CTX_FLAG_DAKUTEN;
  script->flags = script->flags & SCRIPT_CTX_FLAG_NOT_HANDAKUTEN;
  return;
}

void script_ctx_handakuten(script_ctx_t *script)

{
  script->flags = script->flags | SCRIPT_CTX_FLAG_DAKUTEN_HANDAKUTEN;
  return;
}

// This space seems to be 12px wide.

void script_ctx_ideographic_space(script_ctx_t *script, ushort param_2)

{
  undefined2 extraout_D0w;
  undefined2 *extraout_A0;

  script_ctx_display_3(script, 0xffff);
  vdp_set_vram_write_addr((void *)param_2);
  *extraout_A0 = extraout_D0w;
  script->bf_05_and_13_arg_vram_address_related =
      script->bf_05_and_13_arg_vram_address_related + 1;
  return;
}

void text_command_bb(script_ctx_t *script, ushort param_2)

{
  undefined2 extraout_D0w;
  undefined2 extraout_D0w_00;
  undefined2 *extraout_A0;
  undefined2 *extraout_A0_00;

  script_ctx_display_3(script, 0);
  *extraout_A0 = extraout_D0w;
  vdp_set_vram_write_addr((void *)param_2);
  *extraout_A0_00 = extraout_D0w_00;
  *extraout_A0_00 = extraout_D0w_00;
  script->bf_05_and_13_arg_vram_address_related =
      script->bf_05_and_13_arg_vram_address_related + 2;
  return;
}

void script_ctx_display_3(script_ctx_t *ctx, undefined2 glyph)

{
  script_ctx_display_1(ctx, glyph);
  script_ctx_set_vram_write_addr(ctx);
  VDP_DATA = (word)CONCAT31(
      0x87,
      *(char *)((int)&ctx->bf_03_and_bf_06_arg_fed_to_vdp_data + 1) + -0x80);
  return;
}

// Handle text command #bc

void text_command_line_break(script_ctx_t *ctx)

{
  ushort uVar1;

  ctx->bf_05_and_13_arg_vram_address_related = 0;
  if ((ushort)(ctx->bf_05_arg2_vram_address_related + 1) < (ctx->k).w) {
    ctx->bf_05_arg2_vram_address_related =
        ctx->bf_05_arg2_vram_address_related + 1;
    return;
  }
  uVar1 = *(short *)&ctx->d + 1;
  if ((ctx->k).w <= uVar1) {
    uVar1 = 0;
  }
  ctx->d = (char)(uVar1 >> 8);
  ctx->e = (char)uVar1;
  ctx->mode = SCRIPT_MODE_NEW_LINE;
  ctx->prompt_related = '\0';
  return;
}

// Handle text command #bd

void text_command_more(char **text_p)

{
  void *vram_dst;
  sbyte sVar1;
  short sVar2;
  undefined4 *extraout_A0;
  undefined4 *extraout_A0_00;
  undefined4 *extraout_A1;
  undefined4 *extraout_A1_00;

  *(byte *)text_p = *(byte *)text_p | 2;
  *(undefined1 *)((int)text_p + 1) = 4;
  *(undefined1 *)(text_p + 6) = 0x14;
  sVar1 = 6;
  sVar2 = 0x40;
  if (((uint)*text_p & 0x1000000) != 0) {
    sVar2 = 0x80;
    sVar1 = 7;
  }
  vram_dst = (void *)(*(short *)(text_p + 2) +
                      (*(short *)(text_p + 4) +
                       (*(short *)((int)text_p + 0x12) + -1 << sVar1)) *
                          2);
  DAT_ffff91ce._0_1_ = 0xff;
  vdp_set_vram_write_addr(vram_dst);
  *extraout_A1 = *extraout_A0;
  vdp_set_vram_write_addr((void *)(sVar2 + (short)vram_dst));
  *extraout_A1_00 = *extraout_A0_00;
  DAT_ffff91ce._0_1_ = 0;
  return;
}

void text_command_be(script_ctx_t *text_p)

{
  char arg;

  arg = *text_p->script;
  text_p->script = text_p->script + 1;
  text_p->h = arg;
  return;
}

void script_ctx_bf(script_ctx_t *text)

{
  byte index;

  index = *text->script;
  text->script = text->script + 1;
  // WARNING: Could not recover jumptable at 0x00019be4. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&script_ctx_bf_table +
             (int)*(short *)((int)&script_ctx_bf_table +
                             (int)(short)((ushort)index * 2))))();
  return;
}

void script_ctx_set_flag_1_bf_00(script_ctx_t *text)

{
  text->flags = text->flags | SCRIPT_CTX_FLAG_01;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void script_ctx_bf_01(script_ctx_t *text)

{
  char *name;
  byte offset;

  name = script_get_name(_BYTE_ffffd918);
  offset = text->script_stack_offset;
  *(script_t *)((int)&text->script_stack + (int)(short)(ushort)offset) =
      text->script;
  text->script = name;
  text->script_stack_offset = offset + 4;
  return;
}

void script_ctx_bf_02(script_ctx_t *text)

{
  undefined2 extraout_D0w;
  short extraout_D1w;
  void *vram_dst;
  uint16_t uVar1;
  short sVar2;
  undefined2 *extraout_A0;

  text->bf_05_and_13_arg_vram_address_related = 0;
  text->bf_05_arg2_vram_address_related = 0;
  text->d = 0;
  text->e = 0;
  sVar2 = (text->k).w * 2;
  vram_dst = (void *)text->b;
  do {
    vdp_set_vram_write_addr(vram_dst);
    uVar1 = text->i;
    do {
      *extraout_A0 = extraout_D0w;
      uVar1 = uVar1 - 1;
    } while (uVar1 != 0);
    vram_dst = (void *)(extraout_D1w + (short)vram_dst);
    sVar2 = sVar2 + -1;
  } while (sVar2 != 0);
  return;
}

void script_ctx_bf_03(script_ctx_t *ctx)

{
  char arg;

  arg = *ctx->script;
  ctx->script = ctx->script + 1;
  *(byte *)&ctx->bf_03_and_bf_06_arg_fed_to_vdp_data = arg & 0xf;
  *(byte *)((int)&ctx->bf_03_and_bf_06_arg_fed_to_vdp_data + 1) =
      (byte)arg >> 4;
  return;
}

void script_ctx_bf_04(script_ctx_t *ctx)

{
  ctx->mode = SCRIPT_MODE_PROMPT;
  ctx->prompt_related = '\0';
  return;
}

void script_ctx_bf_05_scroll_out(script_ctx_t *text)

{
  byte arg1;
  byte arg2;

  arg1 = *text->script;
  text->script = text->script + 1;
  text->bf_05_and_13_arg_vram_address_related = (ushort)arg1;
  arg2 = *text->script;
  text->script = text->script + 1;
  text->bf_05_arg2_vram_address_related = (ushort)arg2;
  return;
}

// Like text_command_bf_03, but uses one of the two possible parameters
// depending on the text condition.

void script_ctx_bf_06(script_ctx_t *text)

{
  byte arg;

  if (SCRIPT_PROMPT_RESPONSE == '\0') {
    arg = *text->script;
    text->script = text->script + 1;
    text->script = text->script + 1;
  } else {
    text->script = text->script + 1;
    arg = *text->script;
    text->script = text->script + 1;
  }
  *(byte *)&text->bf_03_and_bf_06_arg_fed_to_vdp_data = arg & 0xf;
  *(byte *)((int)&text->bf_03_and_bf_06_arg_fed_to_vdp_data + 1) = arg >> 4;
  return;
}

void script_ctx_bf_07_cond_jump(script_ctx_t *ctx)

{
  char arg1;
  char arg2;
  char arg3;
  script_t script;

  if (SCRIPT_PROMPT_RESPONSE == '\0') {
    ctx->script = ctx->script + 3;
    return;
  }
  arg1 = *ctx->script;
  ctx->script = ctx->script + 1;
  script = ctx->script;
  arg2 = *script;
  arg3 = script[1];
  ctx->script = script + 2;
  ctx->script = (script_t)(uint)CONCAT21(CONCAT11(arg1, arg2), arg3);
  return;
}

void script_ctx_toggle_can_speed_up(script_ctx_t *text)

{
  text->flags = text->flags ^ SCRIPT_CTX_FLAG_DISABLE_SPEED_UP;
  return;
}

void script_ctx_bf_09(script_ctx_t *text)

{
  uint8_t arg;

  arg = *text->script;
  text->script = text->script + 1;
  text->bf_09_arg = arg;
  text->mode = SCRIPT_MODE_02;
  return;
}

// WARNING: Unknown calling convention

void script_ctx_set_outline(script_ctx_t *text)

{
  SCRIPT_OUTLINE = *text->script;
  text->script = text->script + 1;
  return;
}

// WARNING: Unknown calling convention

void script_ctx_save(script_ctx_t *text)

{
  byte save_point;

  save_point = *text->script;
  text->script = text->script + 1;
  SAVE_POINT = (ushort)save_point;
  RELATED_TO_SAVE = 0xff;
  text->flags = SCRIPT_CTX_FLAG_NONE;
  text->mode = SCRIPT_MODE_SAVE;
  return;
}

void script_ctx_bf_0c_push_item(script_ctx_t *text)

{
  script_name_id_t id;
  char *item_name;
  byte string_stack_offset;

  id.type = -0x4b;
  id.index = script_ctx_bf_0c_arg_item_name_index;
  item_name = script_get_name(id);
  string_stack_offset = text->script_stack_offset;
  *(script_t *)((int)&text->script_stack +
                (int)(short)(ushort)string_stack_offset) = text->script;
  text->script = item_name;
  text->script_stack_offset = string_stack_offset + 4;
  return;
}

// WARNING: Unknown calling convention -- yet parameter storage is locked

void script_ctx_bf_0d(void)

{
  script_ctx_bf_0d_arg = 0xff;
  return;
}

void script_ctx_bf_0e(script_ctx_t *ctx)

{
  script_ctx_bf_0e_arg = *ctx->script;
  ctx->script = ctx->script + 1;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address WARNING: Unknown calling convention

void script_ctx_bf_0f_set_price(script_ctx_t *text)

{
  _price_maybe = *(undefined2 *)text->script;
  text->script = text->script + 2;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address If we don't have enough to purchase, forward the script by the given
// two-bytes offset.

void script_ctx_bf_10_check_can_buy(script_ctx_t *text)

{
  if ((uint)_price_maybe <= (uint)gold) {
    text->script = text->script + 2;
    return;
  }
  text->script = (script_t)((int)text->script + (int)*(short *)text->script);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address WARNING: Unknown calling convention -- yet parameter storage is
// locked

void script_ctx_bf_11_sell(void)

{
  gold = (uint)_price_maybe + gold;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address WARNING: Unknown calling convention -- yet parameter storage is
// locked

void script_ctx_bf_12_buy(void)

{
  gold = gold - (uint)_price_maybe;
  return;
}

// WARNING: Unknown calling convention

void script_ctx_incant_spell(script_ctx_t *ctx)

{
  SPELL_TO_INCANT = ctx->script;
  ctx->mode = SCRIPT_MODE_INCANT_SPELL;
  WORD_ffffda24 = ctx->bf_05_and_13_arg_vram_address_related;
  ctx->prompt_related = '\0';
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address WARNING: Unknown calling convention

void script_ctx_start_quizz(script_ctx_t *text)

{
  char *pcVar1;
  word wVar3;
  uint uVar2;
  short sVar5;
  ushort uVar6;
  uint uVar7;
  undefined *puVar8;
  char *pcVar9;
  ushort uVar4;

  sVar5 = 9;
  puVar8 = &DAT_ffffda62;
  do {
    *puVar8 = 0xff;
    sVar5 = sVar5 + -1;
    puVar8 = puVar8 + 1;
  } while (sVar5 != -1);
  uVar6 = 10;
  uVar7 = 0x14;
  do {
    wVar3 = rand();
    uVar2 = (uint)(int)(short)(wVar3 >> 1) % uVar7;
    if ((ushort)uVar2 < uVar6) {
      pcVar1 = &DAT_ffffda62;
      do {
        do {
          pcVar9 = pcVar1;
          pcVar1 = pcVar9 + 1;
        } while (-1 < *pcVar9);
        uVar4 = (short)uVar2 - 1;
        uVar2 = (uint)uVar4;
      } while (uVar4 != 0xffff);
      *pcVar9 = '\x14' - (char)uVar7;
      uVar6 = uVar6 - 1;
      if (uVar6 == 0) {
        _DAT_ffffda60 = 0;
        text->mode = SCRIPT_MODE_QUIZZ;
        text->prompt_related = '&';
        return;
      }
    }
    uVar7 = (uint)(ushort)((short)uVar7 - 1);
  } while (true);
}

// WARNING: Unknown calling convention

void script_ctx_bf_15_correct_answer(script_ctx_t *text)

{
  SCRIPT_SPHINX_CORRECT_ANSWER = *text->script;
  text->script = text->script + 1;
  return;
}

// WARNING: Unknown calling convention -- yet parameter storage is locked

void script_ctx_bf_16_pause_sound(void)

{
  AUDIO_PAUSE_COUNT = AUDIO_PAUSE_COUNT + 1;
  audio_play(SOUND_ID_PAUSE);
  return;
}

// WARNING: Unknown calling convention

void script_ctx_bf_17_resume_sound(void)

{
  AUDIO_PAUSE_COUNT = AUDIO_PAUSE_COUNT - 1;
  if ((AUDIO_PAUSE_COUNT == 0) || ((short)AUDIO_PAUSE_COUNT < 0)) {
    audio_play(SOUND_ID_RESUME);
  }
  return;
}

// WARNING: Unknown calling convention

void script_ctx_bf_18(script_ctx_t *text)

{
  script_ctx_bf_18_related = 1;
  script_ctx_bf_18_arg_1 = *(undefined2 *)text->script;
  text->script = text->script + 2;
  script_ctx_bf_18_arg_2 = *(undefined2 *)text->script;
  text->script = text->script + 2;
  return;
}

// WARNING: Unknown calling convention

void script_ctx_bf_19_animate_asha(script_ctx_t *text, entity_id_t entity)

{
  byte state_1_b;
  char *string;

  DAT_ffffda70 = 0xff;
  string = text->script;
  comp_anim_b = *string;
  state_1_b = string[1];
  comp_state_a = string[2];
  text->script = string + 3;
  comp_has_func_maybe = comp_has_func_maybe & 0xfc;
  ecs_anim_unk_2(ENTITY_ID_ASHA, (anim_item_t *)entity, state_1_b);
  return;
}

// WARNING: Unknown calling convention
// Where does that anim item come from? Should it be the script (char *)
// instead?

void script_ctx_animate_bf_1a(script_ctx_t *ctx, anim_item_t *anim)

{
  byte state_1_b;
  entity_id_t entity;
  char *args;

  args = ctx->script;
  entity = (entity_id_t)(short)((ushort)(byte)*args << 2);
  (&comp_anim_base_offset)[entity] = args[1];
  (&comp_anim_b)[entity] = args[2];
  state_1_b = args[3];
  (&comp_state_a)[entity] = args[4];
  ctx->script = args + 5;
  (&comp_has_func_maybe)[entity] = (&comp_has_func_maybe)[entity] & 0xfc;
  ecs_anim_unk_2(entity, anim, state_1_b);
  return;
}

// WARNING: Unknown calling convention

void script_ctx_merchant_bf_1b(script_ctx_t *text)

{
  int iVar1;
  bool string_is_null;

  MERCHANT = text->script;
  string_is_null = MERCHANT == (char *)0x0;
  merchant_items_1();
  if (!string_is_null) {
    text->script = text->script + 7;
    return;
  }
  FUN_0001a9e6();
  iVar1 = (int)(short)text;
  *(char **)(iVar1 + 4) = MERCHANT;
  *(undefined2 *)(iVar1 + 0x14) = 0;
  *(undefined2 *)(iVar1 + 0x16) = 0;
  *(undefined2 *)(iVar1 + 10) = 0;
  return;
}

// WARNING: Unknown calling convention

void script_ctx_remove_item(script_ctx_t *text)

{
  ushort i;
  short j;
  item_t *inventory;
  item_t item;

  item = *text->script;
  text->script = text->script + 1;
  if (ITEM_HEALING_MEDICINE < item) {
    inventory = OWNED_INVENTORY;
    i = 0;
    do {
      if (item == *inventory) {
        j = 9 - i;
        while (j = j + -1, j != -1) {
          *inventory = inventory[1];
          inventory = inventory + 1;
        }
        *inventory = ITEM_NONE;
        return;
      }
      i = i + 1;
      inventory = inventory + 1;
    } while (i < 10);
  }
  return;
}

void script_ctx_bf_1d_gain_hearts(script_ctx_t *text)

{
  sound_id_t sound_id;
  byte total_hearts_gain;
  word total_hearts_old;

  total_hearts_gain = *text->script;
  text->script = text->script + 1;
  total_hearts_old = total_hearts;
  total_hearts = total_hearts + total_hearts_gain;
  if (total_hearts_max < total_hearts) {
    total_hearts = total_hearts_max;
  }
  if (total_hearts_old != total_hearts) {
    sound_id = SOUND_ID_GET_MEAT;
    if ((word)(total_hearts_old - total_hearts) != -1) {
      sound_id = SOUND_ID_LIFE;
    }
    audio_play(sound_id);
    return;
  }
  return;
}

void script_ctx_bf_1e_check_can_gain_hearts(script_ctx_t *text)

{
  if (total_hearts < total_hearts_max) {
    text->script = text->script + 2;
    return;
  }
  text->script = (script_t)((int)text->script + (int)*(short *)text->script);
  return;
}

// This jumps to text_command_line_break() rather than calling it, so most of
// the function is just it.

void script_ctx_display_1(script_ctx_t *ctx, undefined2 glyph)

{
  ushort uVar1;

  if ((ushort)(ctx->bf_05_and_13_arg_vram_address_related +
               -((char)glyph < '\0') + 1) < ctx->i) {
    return;
  }
  ctx->bf_05_and_13_arg_vram_address_related = 0;
  if ((ushort)(ctx->bf_05_arg2_vram_address_related + 1) < (ctx->k).w) {
    ctx->bf_05_arg2_vram_address_related =
        ctx->bf_05_arg2_vram_address_related + 1;
    return;
  }
  uVar1 = *(short *)&ctx->d + 1;
  if ((ctx->k).w <= uVar1) {
    uVar1 = 0;
  }
  ctx->d = (char)(uVar1 >> 8);
  ctx->e = (char)uVar1;
  ctx->mode = SCRIPT_MODE_NEW_LINE;
  ctx->prompt_related = '\0';
  return;
}

void script_ctx_push_name(script_ctx_t *ctx, script_name_id_t id, uint param_3)

{
  script_t pcVar1;
  void **glyph;
  byte *name;
  byte c;

  name = (byte *)script_get_name(id);
  c = *name;
  pcVar1 = ctx->script;
  ctx->script = (script_t)(name + 1);
  glyph = script_get_glyph_info_p(ctx, (ushort)c);
  text_unknown_4(ctx, (byte *)glyph, param_3);
  ctx->script = pcVar1;
  return;
}

// I assume this parses and pushes the name on the text processing stack? So the
// name will be handled and then we would go back to the text which contained
// it.

void text_push_name(script_ctx_t *text, script_name_id_t id)

{
  char *name;
  byte string_stack_offset;

  name = script_get_name(id);
  string_stack_offset = text->script_stack_offset;
  *(script_t *)((int)&text->script_stack +
                (int)(short)(ushort)string_stack_offset) = text->script;
  text->script = name;
  text->script_stack_offset = string_stack_offset + 4;
  return;
}

// C checked, matches assembly.
//
// Get a name for the current locale and given type and index.
//
// Ideally we want two uin8_t parameters, but in the assembly they are mixed in
// a single register.
//
// The first line gets the names for the current locale.
//
// The last line really is just: `name_pp[id.type][id.index]`.
//
// `id_2` and `extraout_D0b` are useless.

char *script_get_name(script_name_id_t id)

{
  undefined1 extraout_D0b;
  script_name_id_t id_2;
  void *name_pp;

  name_pp = text_get_name_pp();
  return (
      char *)((int)name_pp +
              (int)*(
                  short *)((int)name_pp +
                           (int)(short)(CONCAT11(id_2.type, extraout_D0b) * 2) +
                           (int)*(short *)((int)name_pp + (int)(short)id_2)) +
              (int)*(short *)((int)name_pp + (int)(short)id_2));
}

void FUN_00019fa2(void)

{
  void *vram_dst;
  byte bVar1;
  sbyte sVar2;
  short sVar3;
  undefined4 *extraout_A0;
  undefined4 *extraout_A0_00;
  undefined4 *extraout_A1;
  undefined4 *extraout_A1_00;
  byte *unaff_A3;

  bVar1 = unaff_A3[0x18] - 1;
  unaff_A3[0x18] = bVar1;
  if (bVar1 == 0) {
    bVar1 = *unaff_A3;
    *unaff_A3 = bVar1 ^ 2;
    if ((bVar1 & 2) == 0) {
      unaff_A3[0x18] = 0x14;
    } else {
      unaff_A3[0x18] = 10;
    }
    sVar2 = 6;
    sVar3 = 0x40;
    if ((*unaff_A3 & 1) != 0) {
      sVar3 = 0x80;
      sVar2 = 7;
    }
    vram_dst = (void *)(*(short *)(unaff_A3 + 8) +
                        (*(short *)(unaff_A3 + 0x10) +
                         (*(short *)(unaff_A3 + 0x12) + -1 << sVar2)) *
                            2);
    DAT_ffff91ce._0_1_ = 0xff;
    vdp_set_vram_write_addr(vram_dst);
    *extraout_A1 = *extraout_A0;
    vdp_set_vram_write_addr((void *)(sVar3 + (short)vram_dst));
    *extraout_A1_00 = *extraout_A0_00;
    DAT_ffff91ce._0_1_ = 0;
    return;
  }
  return;
}

void FUN_00019fb0(void)

{
  void *vram_dst;
  sbyte sVar1;
  short sVar2;
  undefined4 *extraout_A0;
  undefined4 *extraout_A0_00;
  undefined4 *extraout_A1;
  undefined4 *extraout_A1_00;
  byte *unaff_A3;

  unaff_A3[0x18] = 10;
  sVar1 = 6;
  sVar2 = 0x40;
  if ((*unaff_A3 & 1) != 0) {
    sVar2 = 0x80;
    sVar1 = 7;
  }
  vram_dst = (void *)(*(short *)(unaff_A3 + 8) +
                      (*(short *)(unaff_A3 + 0x10) +
                       (*(short *)(unaff_A3 + 0x12) + -1 << sVar1)) *
                          2);
  DAT_ffff91ce._0_1_ = 0xff;
  vdp_set_vram_write_addr(vram_dst);
  *extraout_A1 = *extraout_A0;
  vdp_set_vram_write_addr((void *)(sVar2 + (short)vram_dst));
  *extraout_A1_00 = *extraout_A0_00;
  DAT_ffff91ce._0_1_ = 0;
  return;
}

undefined8 FUN_0001a028(void)

{
  ushort uVar1;
  int iVar2;
  undefined4 uVar3;
  byte *unaff_A3;

  iVar2 = 6;
  uVar3 = 0x40;
  if ((*unaff_A3 & 1) != 0) {
    iVar2 = 7;
    uVar3 = 0x80;
  }
  uVar1 = *(short *)(unaff_A3 + 8) + (*(short *)(unaff_A3 + 0x14) +
                                      (*(short *)(unaff_A3 + 0x16) << iVar2)) *
                                         2;
  VDP_CTRL = (union2_t)(uVar1 & 0x3fff | 0x4000);
  VDP_CTRL = (union2_t)(uVar1 >> 0xe);
  return CONCAT44(iVar2, uVar3);
}

undefined8 script_ctx_set_vram_write_addr(script_ctx_t *ctx)

{
  int bit_offset;
  undefined4 bit;
  void *vram_dst;

  bit_offset = 6;
  bit = 0x40;
  if ((ctx->flags & SCRIPT_CTX_FLAG_01) != SCRIPT_CTX_FLAG_NONE) {
    bit_offset = 7;
    bit = 0x80;
  }
  vram_dst =
      (void *)(ctx->b + (ctx->bf_05_and_13_arg_vram_address_related +
                         (ctx->bf_05_arg2_vram_address_related << bit_offset)) *
                            2);
  VDP_CTRL = (union2_t)((ushort)vram_dst & 0x3fff | 0x4000);
  VDP_CTRL = (union2_t)((ushort)vram_dst >> 0xe);
  return CONCAT44(bit_offset, bit);
}

void FUN_0001a05a(void)

{
  undefined2 extraout_D0w;
  short extraout_D1w;
  short sVar1;
  short sVar2;
  void *vram_dst;
  undefined2 *extraout_A0;
  byte *unaff_A3;

  vram_dst = *(void **)(unaff_A3 + 8);
  sVar2 = 0x40;
  if ((*unaff_A3 & 1) != 0) {
    sVar2 = 0x80;
  }
  sVar1 = *(short *)(unaff_A3 + 0x12) * 2;
  while (sVar1 != 1) {
    FUN_0001a0a4();
    vram_dst = (void *)(sVar2 + (short)vram_dst);
    sVar1 = extraout_D1w;
  }
  DAT_ffff91ce._0_1_ = 0xff;
  vdp_set_vram_write_addr(vram_dst);
  sVar2 = *(short *)(unaff_A3 + 0x10);
  do {
    *extraout_A0 = extraout_D0w;
    sVar2 = sVar2 + -1;
  } while (sVar2 != 0);
  DAT_ffff91ce._0_1_ = 0;
  return;
}

undefined8 FUN_0001a0a4(void)

{
  int iVar1;
  undefined4 in_D0;
  short sVar3;
  undefined4 uVar2;
  undefined4 in_D1;
  ushort unaff_D2w;
  uint uVar4;
  uint unaff_D5;
  short unaff_D6w;
  undefined2 *in_A0;
  undefined2 *puVar5;

  uVar4 = unaff_D5 << 0x10 | unaff_D5 >> 0x10;
  iVar1 = uVar4 + CONCAT22((ushort)((uint)unaff_D2w << 2) >> 2,
                           (short)(((uint)unaff_D2w << 2) >> 0x10));
  *(int *)(in_A0 + 2) = iVar1;
  puVar5 = (undefined2 *)0xffffd92e;
  sVar3 = unaff_D6w;
  do {
    *puVar5 = *in_A0;
    sVar3 = sVar3 + -1;
    puVar5 = puVar5 + 1;
  } while (sVar3 != -1);
  uVar2 = CONCAT22((short)((uint)in_D0 >> 0x10), unaff_D6w);
  *(uint *)(in_A0 + 2) = iVar1 - uVar4 | 0x40000000;
  puVar5 = (undefined2 *)0xffffd92e;
  do {
    *in_A0 = *puVar5;
    sVar3 = (short)uVar2 + -1;
    uVar2 = CONCAT22((short)((uint)uVar2 >> 0x10), sVar3);
    puVar5 = puVar5 + 1;
  } while (sVar3 != -1);
  DAT_ffff91ce._0_1_ = 0;
  return CONCAT44(uVar2, in_D1);
}

void related_to_text_4(script_ctx_t *ctx)

{
  SCRIPT_OUTLINE = 0xff;
  ctx->mode = SCRIPT_MODE_00;
  ctx->script_stack_offset = '\0';
  ctx->bf_05_and_13_arg_vram_address_related = 0;
  ctx->bf_05_arg2_vram_address_related = 0;
  ctx->d = 0;
  ctx->e = 0;
  ctx->q = 0;
  ctx->r = 0;
  ctx->t = 0;
  ctx->bf_03_and_bf_06_arg_fed_to_vdp_data = 0xf01;
  return;
}

short text_unknown_1(void)

{
  short sVar1;
  ushort uVar2;
  int unaff_A3;

  uVar2 = *(short *)(unaff_A3 + 0x16) + *(short *)(unaff_A3 + 10);
  if (*(ushort *)(unaff_A3 + 0x12) <= uVar2) {
    uVar2 = uVar2 - *(short *)(unaff_A3 + 0x12);
  }
  uVar2 =
      (*(short *)(unaff_A3 + 0x14) + uVar2 * *(short *)(unaff_A3 + 0x10)) * 2;
  sVar1 = *(short *)(unaff_A3 + 0xc);
  if (-1 < sVar1) {
    return sVar1;
  }
  return *(short *)((int)sVar1 + (int)(short)((uVar2 >> 5) * 2)) +
         (uVar2 & 0x1f);
}

void text_unknown_4(script_ctx_t *ctx, byte *glyph, uint param_3)

{
  tile_1bpp_row_t tVar1;
  ushort uVar2;
  ushort uVar3;
  ushort uVar4;
  tile_1bpp_row_t *ptVar5;
  int extraout_D0;
  int iVar6;
  short extraout_D0w;
  tile_1bpp_row_t tVar7;
  int extraout_D0_00;
  byte bVar8;
  short sVar9;
  tile_1bpp_row_t tVar10;
  undefined3 uVar11;
  void *vram_dst;
  word wVar12;
  byte bVar14;
  short sVar13;
  short sVar15;
  byte bVar16;
  byte *extraout_A0;
  tile_1bpp_row_t *ptVar17;
  byte *extraout_A0_00;
  byte *pbVar18;
  int extraout_A1;
  int *piVar19;
  short *extraout_A1_00;
  short *extraout_A1_01;
  bool bVar20;
  undefined8 uVar21;
  script_ctx_flag_t flags;

  text_load_glyph_tiles((glyph_info_2_t *)glyph, text_current_glyph_tiles);
  // Consume and print the diacritic.
  flags = ctx->flags;
  ctx->flags = flags & SCRIPT_CTX_FLAG_NOT_DAKUTEN;
  if ((flags & SCRIPT_CTX_FLAG_DAKUTEN) != SCRIPT_CTX_FLAG_NONE) {
    FUN_00154f90();
    piVar19 = (int *)(extraout_A1 + -8);
    if ((ctx->flags & SCRIPT_CTX_FLAG_HANDAKUTEN) != SCRIPT_CTX_FLAG_NONE) {
      piVar19 = (int *)(extraout_A1 + -4);
    }
    text_current_glyph_tiles._16_4_ =
        *(uint *)*piVar19 | text_current_glyph_tiles._16_4_;
    text_current_glyph_tiles._20_4_ =
        ((uint *)*piVar19)[1] | text_current_glyph_tiles._20_4_;
  }
  if ((char)SCRIPT_OUTLINE < '\0') {
    script_unknown_9(ctx);
    // There are 4 tiles
    if (text_current_glyph_type == 0x10) {
      DAT_ffff91ce._0_1_ = 0;
      return;
    }
    text_unknown_1();
    text_related_data = (word)param_3;
    DAT_ffff91ce._0_1_ = 0xff;
    vram_dst = (void *)(text_related_data << 5);
    vdp_set_vram_write_addr(vram_dst);
    sVar9 = 0xf;
    sVar13 = CONCAT11((char)((ushort)vram_dst >> 8),
                      *(byte *)&ctx->bf_03_and_bf_06_arg_fed_to_vdp_data);
    iVar6 = extraout_D0;
    pbVar18 = extraout_A0;
    do {
      bVar14 = *pbVar18;
      sVar15 = 7;
      do {
        bVar20 = CARRY1(bVar14, bVar14);
        bVar14 = bVar14 * '\x02';
        bVar16 = *(byte *)((int)&ctx->bf_03_and_bf_06_arg_fed_to_vdp_data + 1);
        if (bVar20) {
          bVar16 = *(byte *)&ctx->bf_03_and_bf_06_arg_fed_to_vdp_data;
        }
        iVar6 = CONCAT31((int3)((uint)(iVar6 << 4) >> 8),
                         bVar16 | (byte)(iVar6 << 4));
        sVar15 = sVar15 + -1;
      } while (sVar15 != -1);
      Ram00c00000 = iVar6;
      sVar9 = sVar9 + -1;
      pbVar18 = pbVar18 + 1;
    } while (sVar9 != -1);
  } else {
    sVar13 = 0xd;
    if (text_current_glyph_type == 0x10) {
      tRamffffd9a2 = text_current_glyph_tiles[1];
      ptVar5 = text_current_glyph_tiles + 2;
      tVar7 = text_current_glyph_tiles[0];
      tVar1 = text_current_glyph_tiles[1];
      do {
        tVar10 = tVar1;
        ptVar17 = ptVar5;
        tVar1 = *ptVar17;
        uVar11 = (undefined3)(param_3 >> 8);
        param_3 = CONCAT31(uVar11, tVar1);
        ptVar17[0x1f] =
            (tile_1bpp_row_t)((byte)tVar10 >> 1 | (char)tVar10 * '\x02' |
                              (byte)tVar1 | (byte)tVar7);
        sVar13 = sVar13 + -1;
        ptVar5 = ptVar17 + 1;
        tVar7 = tVar10;
      } while (sVar13 != -1);
      wVar12 = (word)CONCAT31(uVar11, (byte)tVar1 >> 1);
      ptVar17[0x20] = (tile_1bpp_row_t)((byte)tVar1 >> 1 |
                                        (char)tVar1 * '\x02' | (byte)tVar10);
    } else {
      tRamffffd9a2 = text_current_glyph_tiles[1];
      tRamffffd9b2 = text_current_glyph_tiles[0x11];
      ptVar5 = text_current_glyph_tiles + 2;
      uVar3 =
          CONCAT11(text_current_glyph_tiles[1], text_current_glyph_tiles[0x11]);
      uVar2 =
          CONCAT11(text_current_glyph_tiles[0], text_current_glyph_tiles[0x10]);
      do {
        uVar4 = uVar3;
        ptVar17 = ptVar5;
        uVar3 = CONCAT11(*ptVar17, ptVar17[0x10]);
        uVar2 = uVar4 >> 1 | uVar4 * 2 | uVar3 | uVar2;
        ptVar17[0x2f] = SUB21(uVar2, 0);
        ptVar17[0x1f] = SUB21(uVar2 >> 8, 0);
        sVar13 = sVar13 + -1;
        ptVar5 = ptVar17 + 1;
        uVar2 = uVar4;
      } while (sVar13 != -1);
      wVar12 = uVar3 >> 1;
      uVar3 = wVar12 | uVar3 * 2 | uVar4;
      ptVar17[0x30] = SUB21(uVar3, 0);
      ptVar17[0x20] = SUB21(uVar3 >> 8, 0);
    }
    DAT_ffff91ce._0_1_ = 0xff;
    text_unknown_2();
    if (text_current_glyph_type == 0x10) {
      DAT_ffff91ce._0_1_ = 0;
      return;
    }
    text_unknown_1();
    text_related_data = wVar12;
    vdp_set_vram_write_addr((void *)(wVar12 << 5));
    sVar9 = 0xf;
    sVar13 = CONCAT11((char)((ushort)(wVar12 << 5) >> 8),
                      *(byte *)&ctx->bf_03_and_bf_06_arg_fed_to_vdp_data);
    iVar6 = extraout_D0_00;
    pbVar18 = extraout_A0_00;
    do {
      bVar14 = *pbVar18;
      bVar16 = pbVar18[0x20];
      sVar15 = 7;
      do {
        bVar20 = CARRY1(bVar14, bVar14);
        bVar14 = bVar14 * '\x02';
        bVar8 = (byte)(iVar6 << 4);
        uVar11 = (undefined3)((uint)(iVar6 << 4) >> 8);
        if (bVar20) {
          iVar6 = CONCAT31(uVar11,
                           *(byte *)&ctx->bf_03_and_bf_06_arg_fed_to_vdp_data |
                               bVar8);
        } else if (CARRY1(bVar16, bVar16)) {
          iVar6 = CONCAT31(uVar11, SCRIPT_OUTLINE | bVar8);
        } else {
          iVar6 = CONCAT31(
              uVar11,
              *(byte *)((int)&ctx->bf_03_and_bf_06_arg_fed_to_vdp_data + 1) |
                  bVar8);
        }
        bVar16 = bVar16 * '\x02';
        sVar15 = sVar15 + -1;
      } while (sVar15 != -1);
      Ram00c00000 = iVar6;
      sVar9 = sVar9 + -1;
      pbVar18 = pbVar18 + 1;
    } while (sVar9 != -1);
  }
  uVar21 = script_ctx_set_vram_write_addr(ctx);
  *extraout_A1_00 = text_related_data + 0x8000;
  vdp_set_vram_write_addr((void *)((short)uVar21 + sVar13));
  *extraout_A1_01 = extraout_D0w + 1;
  ctx->bf_05_and_13_arg_vram_address_related =
      ctx->bf_05_and_13_arg_vram_address_related + 1;
  DAT_ffff91ce._0_1_ = 0;
  return;
}

void script_unknown_9(script_ctx_t *ctx)

{
  byte bVar1;
  byte bVar2;
  int extraout_D0;
  int iVar3;
  short extraout_D0w;
  short sVar4;
  word unaff_D2w;
  byte bVar5;
  short sVar6;
  byte *extraout_A0;
  byte *pbVar7;
  short *extraout_A1;
  short *extraout_A1_00;
  bool bVar8;
  undefined8 uVar9;

  text_unknown_1();
  DAT_ffff91ce._0_1_ = 0xff;
  text_related_data = unaff_D2w;
  vdp_set_vram_write_addr((void *)(unaff_D2w << 5));
  sVar4 = 0xf;
  bVar1 = *(byte *)&ctx->bf_03_and_bf_06_arg_fed_to_vdp_data;
  iVar3 = extraout_D0;
  pbVar7 = extraout_A0;
  do {
    bVar5 = *pbVar7;
    sVar6 = 7;
    do {
      bVar8 = CARRY1(bVar5, bVar5);
      bVar5 = bVar5 * '\x02';
      bVar2 = *(byte *)((int)&ctx->bf_03_and_bf_06_arg_fed_to_vdp_data + 1);
      if (bVar8) {
        bVar2 = bVar1;
      }
      iVar3 =
          CONCAT31((int3)((uint)(iVar3 << 4) >> 8), bVar2 | (byte)(iVar3 << 4));
      sVar6 = sVar6 + -1;
    } while (sVar6 != -1);
    Ram00c00000 = iVar3;
    sVar4 = sVar4 + -1;
    pbVar7 = pbVar7 + 1;
  } while (sVar4 != -1);
  uVar9 = script_ctx_set_vram_write_addr(ctx);
  *extraout_A1 = text_related_data + 0x8000;
  vdp_set_vram_write_addr(
      (void *)((short)uVar9 +
               CONCAT11((char)((ushort)(unaff_D2w << 5) >> 8), bVar1)));
  *extraout_A1_00 = extraout_D0w + 1;
  ctx->bf_05_and_13_arg_vram_address_related =
      ctx->bf_05_and_13_arg_vram_address_related + 1;
  DAT_ffff91ce._0_1_ = 0;
  return;
}

void text_unknown_2(void)

{
  byte bVar1;
  undefined3 uVar2;
  short extraout_D0w;
  int extraout_D0;
  byte bVar4;
  int iVar3;
  short sVar5;
  word unaff_D2w;
  byte bVar6;
  short sVar7;
  byte bVar8;
  byte *extraout_A0;
  byte *pbVar9;
  short *extraout_A1;
  short *extraout_A1_00;
  script_ctx_t *unaff_A3;
  bool bVar10;
  undefined8 uVar11;

  text_unknown_1();
  text_related_data = unaff_D2w;
  vdp_set_vram_write_addr((void *)(unaff_D2w << 5));
  sVar5 = 0xf;
  bVar1 = *(byte *)&unaff_A3->bf_03_and_bf_06_arg_fed_to_vdp_data;
  iVar3 = extraout_D0;
  pbVar9 = extraout_A0;
  do {
    bVar6 = *pbVar9;
    bVar8 = pbVar9[0x20];
    sVar7 = 7;
    do {
      bVar10 = CARRY1(bVar6, bVar6);
      bVar6 = bVar6 * '\x02';
      bVar4 = (byte)(iVar3 << 4);
      uVar2 = (undefined3)((uint)(iVar3 << 4) >> 8);
      if (bVar10) {
        iVar3 = CONCAT31(uVar2, bVar1 | bVar4);
      } else if (CARRY1(bVar8, bVar8)) {
        iVar3 = CONCAT31(uVar2, SCRIPT_OUTLINE | bVar4);
      } else {
        iVar3 = CONCAT31(
            uVar2,
            *(byte *)((int)&unaff_A3->bf_03_and_bf_06_arg_fed_to_vdp_data + 1) |
                bVar4);
      }
      bVar8 = bVar8 * '\x02';
      sVar7 = sVar7 + -1;
    } while (sVar7 != -1);
    Ram00c00000 = iVar3;
    sVar5 = sVar5 + -1;
    pbVar9 = pbVar9 + 1;
  } while (sVar5 != -1);
  uVar11 = script_ctx_set_vram_write_addr(unaff_A3);
  *extraout_A1 = text_related_data + 0x8000;
  vdp_set_vram_write_addr(
      (void *)((short)uVar11 +
               CONCAT11((char)((ushort)(unaff_D2w << 5) >> 8), bVar1)));
  *extraout_A1_00 = extraout_D0w + 1;
  unaff_A3->bf_05_and_13_arg_vram_address_related =
      unaff_A3->bf_05_and_13_arg_vram_address_related + 1;
  DAT_ffff91ce._0_1_ = 0;
  return;
}

// This loads the 2 or 4 glyph tiles into their expected location.
//
// If the glyph's flag is negative, there are only two tiles, otherwise there
// are four. It does so by running the function to load two glyphs once or
// twice, updating the location to load the two glyph tiles in-between.

text_load_glyph_tiles_result_t text_load_glyph_tiles(glyph_info_2_t *glyph_info,
                                                     tile_1bpp_row_t *tiles_out)

{
  byte bVar1;
  glyph_flag_t glyph_flag;
  short sVar2;
  byte bVar3;
  tile_1bpp_row_t tVar4;
  ushort uVar5;
  short sVar6;
  tile_1bpp_row_t tVar7;
  tile_1bpp_row_t *glyph_tile;
  tile_1bpp_row_t *ptVar8;
  tile_1bpp_row_t *ptVar9;
  tile_1bpp_row_t *ptVar10;
  text_load_glyph_tiles_result_t result;

  text_current_glyph_type = 0x10;
  glyph_tile = &glyph_info->tiles[0].a;
  glyph_flag = glyph_info->flag;
  if (-1 < (char)glyph_flag) {
    text_current_glyph_type = 0x20;
    result = text_load_glyph_tiles_inner(glyph_flag, glyph_tile, tiles_out);
    glyph_flag = result.flags;
    glyph_tile = result.tiles_in;
    tiles_out = result.tiles_out + 0x10;
  }
  if (((byte)glyph_flag & 1) == 0) {
    if (((byte)glyph_flag >> 1 & 1) == 0) {
      sVar2 = 0xf;
      ptVar10 = glyph_tile;
      ptVar8 = tiles_out;
      do {
        glyph_tile = ptVar10 + 1;
        *ptVar8 = *ptVar10;
        sVar2 = sVar2 + -1;
        ptVar10 = glyph_tile;
        ptVar8 = ptVar8 + 1;
      } while (sVar2 != -1);
    } else {
      tVar4 = *glyph_tile;
      bVar1 = (byte)tVar4 & 0xf;
      uVar5 = (ushort)bVar1;
      ptVar10 = tiles_out;
      while (uVar5 = uVar5 - 1, uVar5 != 0xffff) {
        *ptVar10 = (tile_1bpp_row_t)0x0;
        ptVar10 = ptVar10 + 1;
      }
      bVar3 = (byte)tVar4 >> 4;
      uVar5 = (ushort)(byte)(('\x10' - bVar1) - bVar3);
      sVar2 = bVar3 - 1;
      ptVar8 = glyph_tile + 1;
      do {
        glyph_tile = ptVar8 + 1;
        ptVar9 = ptVar10 + 1;
        *ptVar10 = *ptVar8;
        sVar2 = sVar2 + -1;
        ptVar8 = glyph_tile;
        ptVar10 = ptVar9;
      } while (sVar2 != -1);
      while (uVar5 = uVar5 - 1, uVar5 != 0xffff) {
        *ptVar9 = (tile_1bpp_row_t)0x0;
        ptVar9 = ptVar9 + 1;
      }
    }
  } else if (((byte)glyph_flag >> 1 & 1) == 0) {
    *(undefined4 *)tiles_out = 0;
    *(undefined4 *)(tiles_out + 4) = 0;
    *(undefined4 *)(tiles_out + 8) = 0;
    *(undefined4 *)(tiles_out + 0xc) = 0;
    ptVar10 = glyph_tile;
    while (true) {
      glyph_tile = ptVar10 + 1;
      tVar4 = *ptVar10;
      if (0x7f < (byte)tVar4)
        break;
      tiles_out[(short)(ushort)((byte)tVar4 >> 3)] =
          (tile_1bpp_row_t)((byte)tiles_out[(short)(ushort)((byte)tVar4 >> 3)] |
                            '\x01' << ((byte)tVar4 & 7));
      ptVar10 = glyph_tile;
    }
  } else {
    sVar2 = 1;
    ptVar10 = tiles_out;
    do {
      tVar4 = *glyph_tile;
      sVar6 = 7;
      ptVar8 = glyph_tile + 1;
      ptVar9 = ptVar10;
      do {
        tVar7 = (tile_1bpp_row_t)0x0;
        bVar1 = (byte)tVar4 & 1;
        tVar4 = (tile_1bpp_row_t)((byte)tVar4 >> 1);
        glyph_tile = ptVar8;
        if (bVar1 != 0) {
          glyph_tile = ptVar8 + 1;
          tVar7 = *ptVar8;
        }
        ptVar10 = ptVar9 + 1;
        *ptVar9 = tVar7;
        sVar6 = sVar6 + -1;
        ptVar8 = glyph_tile;
        ptVar9 = ptVar10;
      } while (sVar6 != -1);
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
  }
  result.flags = (glyph_flag_t)((byte)glyph_flag >> 3);
  if (((byte)glyph_flag >> 2 & 1) != 0) {
    tVar4 = (tile_1bpp_row_t)0x0;
    sVar2 = 0xf;
    ptVar10 = tiles_out;
    do {
      *ptVar10 = (tile_1bpp_row_t)((byte)tVar4 ^ (byte)*ptVar10);
      tVar4 = *ptVar10;
      sVar2 = sVar2 + -1;
      ptVar10 = ptVar10 + 1;
    } while (sVar2 != -1);
  }
  result.tiles_in = glyph_tile;
  result.tiles_out = tiles_out;
  return result;
}

// Parses the given glyph and loads two of its 1bpp tiles into to given
// location. It is called twice for glyph that have four tiles.

text_load_glyph_tiles_result_t
text_load_glyph_tiles_inner(glyph_flag_t glyph_flag,
                            tile_1bpp_row_t *glyph_tile,
                            tile_1bpp_row_t *tiles_out)

{
  short rows_i;
  byte length;
  ushort empty_rows_i;
  short sVar1;
  tile_1bpp_row_t tVar2;
  tile_1bpp_row_t *current_glyph_tile_row_p_next;
  text_load_glyph_tiles_result_t result;
  byte empty_rows_n;
  tile_1bpp_row_t *row_p;
  tile_1bpp_row_t *tiles_out_3;
  tile_1bpp_row_t type;

  // Always true in English except for out-of-bounds chars.
  if (((byte)glyph_flag & 1) == 0) {
    // Always true in English except for out-of-bounds chars.
    if (((byte)glyph_flag >> 1 & 1) == 0) {
      // Compression 0
      // Copies 2 tiles (16 bytes) at the current glyph RAM location.
      rows_i = 0xf;
      tiles_out_3 = glyph_tile;
      row_p = tiles_out;
      do {
        glyph_tile = tiles_out_3 + 1;
        *row_p = *tiles_out_3;
        rows_i = rows_i + -1;
        tiles_out_3 = glyph_tile;
        row_p = row_p + 1;
      } while (rows_i != -1);
    } else {
      // Compression 2
      // Likely how Japanese glyphs are stored.
      type = *glyph_tile;
      empty_rows_n = (byte)type & 0xf;
      empty_rows_i = (ushort)empty_rows_n;
      tiles_out_3 = tiles_out;
      // First write some empty rows.
      while (empty_rows_i = empty_rows_i - 1, empty_rows_i != 0xffff) {
        *tiles_out_3 = (tile_1bpp_row_t)0x0;
        tiles_out_3 = tiles_out_3 + 1;
      }
      length = (byte)type >> 4;
      empty_rows_i = (ushort)(byte)(('\x10' - empty_rows_n) - length);
      // Then write the actual rows.
      rows_i = length - 1;
      row_p = glyph_tile + 1;
      do {
        glyph_tile = row_p + 1;
        current_glyph_tile_row_p_next = tiles_out_3 + 1;
        *tiles_out_3 = *row_p;
        rows_i = rows_i + -1;
        row_p = glyph_tile;
        tiles_out_3 = current_glyph_tile_row_p_next;
      } while (rows_i != -1);
      // Finally write the remaining empty rows.
      while (empty_rows_i = empty_rows_i - 1, empty_rows_i != 0xffff) {
        *current_glyph_tile_row_p_next = (tile_1bpp_row_t)0x0;
        current_glyph_tile_row_p_next = current_glyph_tile_row_p_next + 1;
      }
    }
  } else {
    // Used for out-of-bound English characters. Maybe used in Japanese, it
    // needs to be checked.
    if (((byte)glyph_flag >> 1 & 1) == 0) {
      // Compression 1
      // Clears the 2 current glyph tiles.
      *(undefined4 *)tiles_out = 0;
      *(undefined4 *)(tiles_out + 4) = 0;
      *(undefined4 *)(tiles_out + 8) = 0;
      *(undefined4 *)(tiles_out + 0xc) = 0;
      tiles_out_3 = glyph_tile;
      while (true) {
        glyph_tile = tiles_out_3 + 1;
        type = *tiles_out_3;
        if (0x7f < (byte)type)
          break;
        tiles_out[(short)(ushort)((byte)type >> 3)] =
            (tile_1bpp_row_t)((byte)
                                  tiles_out[(short)(ushort)((byte)type >> 3)] |
                              '\x01' << ((byte)type & 7));
        tiles_out_3 = glyph_tile;
      }
    } else {
      // Compression 3
      rows_i = 1;
      tiles_out_3 = tiles_out;
      do {
        type = *glyph_tile;
        sVar1 = 7;
        row_p = glyph_tile + 1;
        current_glyph_tile_row_p_next = tiles_out_3;
        do {
          tVar2 = (tile_1bpp_row_t)0x0;
          empty_rows_n = (byte)type & 1;
          type = (tile_1bpp_row_t)((byte)type >> 1);
          glyph_tile = row_p;
          if (empty_rows_n != 0) {
            glyph_tile = row_p + 1;
            tVar2 = *row_p;
          }
          tiles_out_3 = current_glyph_tile_row_p_next + 1;
          *current_glyph_tile_row_p_next = tVar2;
          sVar1 = sVar1 + -1;
          row_p = glyph_tile;
          current_glyph_tile_row_p_next = tiles_out_3;
        } while (sVar1 != -1);
        rows_i = rows_i + -1;
      } while (rows_i != -1);
    }
  }
  result.flags = (glyph_flag_t)((byte)glyph_flag >> 3);
  // What is happening here? Are the glyphs inverted? Or is it a checksum?
  if (((byte)glyph_flag >> 2 & 1) != 0) {
    type = (tile_1bpp_row_t)0x0;
    rows_i = 0xf;
    tiles_out_3 = tiles_out;
    do {
      *tiles_out_3 = (tile_1bpp_row_t)((byte)type ^ (byte)*tiles_out_3);
      type = *tiles_out_3;
      rows_i = rows_i + -1;
      tiles_out_3 = tiles_out_3 + 1;
    } while (rows_i != -1);
  }
  result.tiles_in = glyph_tile;
  result.tiles_out = tiles_out;
  return result;
}

void FUN_0001a388(void)

{
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;
  short local_2;

  FUN_0001a464();
  FUN_0001a5a6();
  related_to_animating_collecting_gold();
  if ((((char)hud_icon_gold_anim_tick < '\0') && (gold == hud_gold)) &&
      (gold == 0x309)) {
    game_lock();
    audio_pause();
    do {
      audio_play(SOUND_ID_JINGLE_1);
      uVar1 = CONCAT44(extraout_D0, extraout_D1);
      gold = gold + 1000;
      local_2 = 0xb4;
      do {
        exception_unk_0(unaff_A3,
                        unaff_A4,
                        unaff_A6,
                        (long)((ulonglong)uVar1 >> 0x20),
                        (long)uVar1,
                        unaff_D2,
                        unaff_D3,
                        unaff_D4,
                        unaff_D5,
                        unaff_D6,
                        unaff_D7);
        uVar1 = related_to_animating_collecting_gold();
        local_2 = local_2 + -1;
      } while (local_2 != 0);
    } while ((uint)gold < 0x1e61);
    audio_resume();
    game_unlock();
  }
  return;
}

void related_to_animating_collecting_gold(void)

{
  short sVar1;
  int iVar2;

  if (-1 < (char)hud_icon_gold_anim_tick) {
    sVar1 = (char)hud_icon_gold_anim_tick * 3;
    hud_icon_gold_anim_unknown_1 =
        (&hud_icon_gold_anim_unknown_1_t_0001a442)[sVar1];
    hud_icon_gold_anim_unknown_2 =
        (&hud_icon_gold_anim_unknown_2_t_0001a443)[sVar1];
    hud_icon_gold_anim_unknown_3 =
        (&hud_icon_gold_anim_unknown_3_t_0001a444)[sVar1];
    hud_icon_gold_anim_tick = hud_icon_gold_anim_tick + 1;
    if (10 < hud_icon_gold_anim_tick) {
      hud_icon_gold_anim_tick = 0xff;
    }
  }
  if (gold - hud_gold != 0) {
    iVar2 = gold - hud_gold >> 5;
    if (iVar2 == 0) {
      iVar2 = 1;
    }
    hud_gold_animate(iVar2 + hud_gold);
    if ((char)hud_icon_gold_anim_tick < '\0') {
      hud_icon_gold_anim_tick = 0;
    }
  }
  return;
}

void FUN_0001a464(void)

{
  // WARNING: Could not recover jumptable at 0x0001a46c. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)(&DAT_0001a470 +
             *(short *)(&DAT_0001a470 + hud_icon_life_anim_unknown_1)))();
  return;
}

void FUN_0001a4e8(void)

{
  hud_icon_life_anim_unknown_2 = 8;
  return;
}

void FUN_0001a4f6(void)

{
  hud_icon_life_anim_unknown_2 = 0;
  return;
}

void FUN_0001a554(void)

{
  char in_D0b;
  short sVar1;
  undefined *puVar2;
  undefined1 *puVar3;

  puVar2 = &UNK_0001a578;
  if (hud_icon_life_anim_unknown_2 != '\0') {
    puVar2 = &UNK_0001a57d;
  }
  sVar1 = 4;
  puVar3 = &hud_icon_life_anim_unknown_4;
  do {
    *puVar3 = *puVar2;
    sVar1 = sVar1 + -1;
    puVar2 = puVar2 + 1;
    puVar3 = puVar3 + 1;
  } while (sVar1 != -1);
  hud_icon_life_anim_unknown_7 = in_D0b * '\b' + '|';
  return;
}

void FUN_0001a582(void)

{
  return;
}

void FUN_0001a5a6(void)

{
  word new_hud_life_drops;

  if ((char)hud_icon_life_drop_anim_tick < '\0') {
    if (life_drops != hud_life_drops) {
      new_hud_life_drops = life_drops;
      if (hud_life_drops <= life_drops) {
        new_hud_life_drops = hud_life_drops + 1;
      }
      hud_life_drop_animate(new_hud_life_drops);
      if ((char)hud_icon_life_drop_anim_tick < '\0') {
        hud_icon_life_drop_anim_tick = hud_icon_life_drop_anim_tick_00;
      }
    }
    return;
  }
  hud_icon_life_drop_anim_unknown_1 =
      hud_icon_life_drop_anim_unknown_1_t_ARRAY_0001a5e8[(
          short)(char)hud_icon_life_drop_anim_tick];
  hud_icon_life_drop_anim_tick = hud_icon_life_drop_anim_tick + 1;
  if (8 < hud_icon_life_drop_anim_tick) {
    hud_icon_life_drop_anim_tick = ~hud_icon_life_drop_anim_tick_00;
  }
  return;
}

void FUN_0001a5f2(void)

{
  FUN_0001a5fa();
  OWNED_HEALING_MEDICINE_COUNT = 0;
  return;
}

void FUN_0001a5fa(void)

{
  game_lock();
  FUN_0001a626();
  audio_play(SOUND_ID_LIFE);
  while (total_hearts < total_hearts_max) {
    total_hearts = total_hearts + 1;
    FUN_0001a626();
  }
  game_unlock();
  return;
}

void FUN_0001a626(void)

{
  short in_D0w;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  do {
    uVar1 = FUN_0001a388();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    in_D0w = in_D0w + -1;
  } while (in_D0w != -1);
  return;
}

void FUN_0001a638(void)

{
  short i;
  short *psVar1;
  undefined1 *puVar3;
  undefined1 *puVar4;
  short *psVar2;

  vdp_set_window_position(4);
  DAT_ffff91ce._0_1_ = 0xff;
  FUN_0001a6da();
  DAT_ffff91ce._0_1_ = 0;
  hud_icon_life_anim_unknown_1 = 0;
  FUN_0001a7f4();
  FUN_0001a80c();
  hud_life_drop_animate(life_drops);
  hud_icon_life_drop_anim_tick = ~hud_icon_life_drop_anim_tick_00;
  hud_gold_animate(gold);
  hud_icon_gold_anim_tick = 0xff;
  psVar1 = &DAT_0001a6b0;
  while (true) {
    psVar2 = psVar1 + 1;
    i = *psVar1;
    if (i == 0)
      break;
    psVar1 = psVar1 + 2;
    *(short *)(i + 0xf0) = *psVar2;
  }
  DAT_ffffa10e = &hud_icon_life_anim_unknown_4;
  i = 0xf;
  puVar3 = &DAT_0001a6ca;
  puVar4 = &hud_icon_life_anim_unknown_4;
  do {
    *puVar4 = *puVar3;
    i = i + -1;
    puVar3 = puVar3 + 1;
    puVar4 = puVar4 + 1;
  } while (i != -1);
  return;
}

void FUN_0001a6da(void)

{
  char cVar1;
  uint uVar2;
  char unaff_D4b;
  word *extraout_A1;
  word *pwVar3;
  word *pwVar4;
  word *unaff_A2;
  ushort i;

  vdp_set_vram_write_addr((void *)0xd000);
  uVar2 = 0;
  pwVar4 = extraout_A1;
  while (true) {
    pwVar3 = (word *)((int)pwVar4 + 1);
    cVar1 = *(char *)pwVar4;
    uVar2 = CONCAT31((int3)(uVar2 >> 8), cVar1);
    if (cVar1 == '\0')
      break;
    if (cVar1 == -1) {
      unaff_D4b = unaff_D4b + -1;
      pwVar4 = pwVar3;
      if (unaff_D4b != '\0') {
        pwVar4 = unaff_A2;
      }
    } else if (cVar1 == -2) {
      pwVar4 = pwVar4 + 1;
      unaff_D4b = *(char *)pwVar3;
      unaff_A2 = pwVar4;
    } else {
      pwVar4 = (word *)((int)pwVar4 + 3);
      do {
        VDP_DATA = *pwVar3;
        i = (short)uVar2 - 1;
        uVar2 = (uint)i;
      } while (i != 0);
    }
  }
  return;
}

void hud_counter_animate(uint new_amount)

{
  void *vram_dst;
  uint extraout_D0;
  undefined2 extraout_D0w;
  undefined2 extraout_D0w_00;
  short extraout_D1w;
  short extraout_D1w_00;
  short extraout_D1w_01;
  void *unaff_D2w;
  short sVar1;
  byte bVar2;
  short *extraout_A0;
  short *extraout_A0_00;
  undefined2 *extraout_A0_01;
  undefined2 *extraout_A0_02;
  bool bVar3;

  DAT_ffff91ce._0_1_ = 0xff;
  while (true) {
    sVar1 = 0x1f;
    bVar2 = 0;
    do {
      bVar3 = CARRY4(new_amount, new_amount);
      new_amount = new_amount * 2;
      bVar2 = bVar2 * '\x02' + bVar3;
      if (9 < bVar2) {
        bVar2 = bVar2 - 10;
        new_amount =
            CONCAT22((short)(new_amount >> 0x10), (short)new_amount + 1);
      }
      sVar1 = sVar1 + -1;
    } while (sVar1 != -1);
    vdp_set_vram_write_addr(unaff_D2w);
    *extraout_A0 = bVar2 + 0x8006;
    vdp_set_vram_write_addr((void *)((short)unaff_D2w + 0x40));
    *extraout_A0_00 = bVar2 + 0x8016;
    unaff_D2w = (void *)((short)unaff_D2w + -2);
    if (extraout_D1w == 1)
      break;
    new_amount = extraout_D0;
    if (extraout_D0 == 0) {
      vram_dst = (void *)((short)unaff_D2w + (extraout_D1w + -2) * -2);
      vdp_set_vram_write_addr(vram_dst);
      sVar1 = extraout_D1w_00;
      do {
        *extraout_A0_01 = extraout_D0w;
        sVar1 = sVar1 + -1;
      } while (sVar1 != -1);
      vdp_set_vram_write_addr((void *)((short)vram_dst + 0x40));
      sVar1 = extraout_D1w_01;
      do {
        *extraout_A0_02 = extraout_D0w_00;
        sVar1 = sVar1 + -1;
      } while (sVar1 != -1);
      DAT_ffff91ce._0_1_ = 0;
      return;
    }
  }
  DAT_ffff91ce._0_1_ = 0;
  return;
}

void FUN_0001a7f4(void)

{
  undefined2 uVar1;
  undefined1 in_D0b;
  word extraout_D0w;
  word wVar2;
  short extraout_D1w;
  short sVar3;
  word wVar4;
  short sVar5;

  wVar4 = blue_hearts;
  uVar1 = DAT_ffff91ce;
  DAT_ffffda87 = (undefined1)blue_hearts;
  DAT_ffff91ce = CONCAT11(0xff, (undefined1)DAT_ffff91ce);
  sVar5 = 0xf - blue_hearts;
  DAT_ffffda86 = in_D0b;
  vdp_set_vram_write_addr((void *)0xd082);
  wVar2 = extraout_D0w;
  sVar3 = extraout_D1w;
  while (wVar4 = wVar4 - 1, wVar4 != 0xffff) {
    sVar3 = sVar3 + -1;
    if (sVar3 == -1) {
      wVar2 = 0x8021;
    }
    VDP_DATA = wVar2;
  }
  while (sVar5 = sVar5 + -1, sVar5 != -1) {
    VDP_DATA = 0x8001;
  }
  DAT_ffff91ce = uVar1;
  return;
}

void FUN_0001a80c(void)

{
  undefined2 uVar1;
  byte in_D0b;
  word extraout_D0w;
  word wVar2;
  short extraout_D1w;
  short sVar3;
  word wVar4;
  short sVar5;

  wVar4 = red_hearts;
  uVar1 = DAT_ffff91ce;
  DAT_ffffda85 = (undefined1)red_hearts;
  DAT_ffff91ce = CONCAT11(0xff, (undefined1)DAT_ffff91ce);
  sVar5 = 0xf - red_hearts;
  life_2 = in_D0b;
  vdp_set_vram_write_addr((void *)0xd042);
  wVar2 = extraout_D0w;
  sVar3 = extraout_D1w;
  while (wVar4 = wVar4 - 1, wVar4 != 0xffff) {
    sVar3 = sVar3 + -1;
    if (sVar3 == -1) {
      wVar2 = 0x8021;
    }
    VDP_DATA = wVar2;
  }
  while (sVar5 = sVar5 + -1, sVar5 != -1) {
    VDP_DATA = 0x8001;
  }
  DAT_ffff91ce = uVar1;
  return;
}

void hud_life_drop_animate(word new_hud_life_drops)

{
  hud_life_drops = new_hud_life_drops;
  hud_counter_animate((int)(short)new_hud_life_drops);
  return;
}

void hud_gold_animate(long new_hud_gold)

{
  hud_gold = new_hud_gold;
  hud_counter_animate(new_hud_gold);
  return;
}

void FUN_0001a878(void)

{
  short sVar1;
  short *psVar2;
  undefined1 *puVar4;
  ushort local_8;
  short *psVar3;

  game_lock();
  audio_pause();
  FUN_000028d8();
  while (-1 < (char)hud_icon_life_drop_anim_tick) {
    FUN_000028ce();
  }
  psVar2 = (short *)&DAT_0001a9cc;
  while (true) {
    psVar3 = psVar2 + 1;
    sVar1 = *psVar2;
    if (sVar1 == 0)
      break;
    psVar2 = psVar2 + 2;
    *(short *)(sVar1 + 0xf4) = *psVar3;
  }
  puVar4 = &DAT_ffffdaa9;
  DAT_ffffa112 = &DAT_ffffdaa9;
  sVar1 = 9;
  do {
    *puVar4 = 1;
    puVar4[1] = 0x80;
    puVar4[2] = 0x4a;
    puVar4 = puVar4 + 5;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  *puVar4 = 0xff;
  local_8 = 0;
  do {
    if (life_drops != 0) {
      life_drops = life_drops - 1;
    }
    FUN_0001a950();
    local_8 = local_8 + 1;
    FUN_0001a96e();
    FUN_000028ce();
  } while (local_8 < 0x40);
  do {
    FUN_0001a950();
    local_8 = local_8 - 1;
    FUN_0001a96e();
    FUN_000028ce();
  } while (local_8 != 0);
  related_to_entering_and_exiting_menu_1 = 0;
  blue_hearts = blue_hearts + 1;
  total_hearts_max = total_hearts_max + 1;
  total_hearts = total_hearts + 1;
  audio_play(SOUND_ID_JINGLE_1);
  FUN_000028d8();
  audio_resume();
  game_unlock();
  return;
}

void FUN_0001a950(void)

{
  short unaff_D4w;
  short unaff_D5w;
  short unaff_D6w;
  short unaff_D7w;
  int unaff_A6;

  DAT_ffffa216 = unaff_D4w + (short)((int)(short)(unaff_D6w - unaff_D4w) *
                                         (int)*(short *)(unaff_A6 + -4) >>
                                     6);
  DAT_ffffa31a = unaff_D5w + (short)((int)(short)(unaff_D7w - unaff_D5w) *
                                         (int)*(short *)(unaff_A6 + -4) >>
                                     6);
  return;
}

void FUN_0001a96e(void)

{
  char extraout_D0b;
  char cVar1;
  word wVar2;
  ushort uVar3;
  int extraout_A0;
  int extraout_A0_00;
  int unaff_A6;

  uVar3 = 0;
  do {
    wVar2 = angle_sin((&angle_t_0001a9c6)[(short)uVar3] +
                      (char)*(undefined2 *)(unaff_A6 + -2));
    cVar1 =
        (char)((uint)((int)*(short *)(unaff_A6 + -4) * (int)(short)wVar2 * 4) >>
               0x10);
    *(char *)(extraout_A0 + 4) = cVar1;
    *(char *)(extraout_A0 + 0x1d) = -cVar1;
    wVar2 = angle_sin(extraout_D0b + 0x40);
    cVar1 = (char)((uint)((int)(short)((*(ushort *)(unaff_A6 + -4) >> 1) +
                                       *(ushort *)(unaff_A6 + -4)) *
                          (int)(short)wVar2 * 4) >>
                   0x10);
    *(char *)(extraout_A0_00 + 3) = cVar1;
    *(char *)(extraout_A0_00 + 0x1c) = -cVar1;
    uVar3 = uVar3 + 1;
  } while (uVar3 < 5);
  *(short *)(unaff_A6 + -2) = *(short *)(unaff_A6 + -2) + 2;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001a9e6(void)

{
  word wVar1;
  ushort uVar3;
  int iVar2;
  short unaff_D2w;
  short sVar4;
  void *extraout_A1;
  func *f;

  FUN_00028010();
  DAT_ffffde0d = 10;
  text_unk_1(&UNK_0001abe6, extraout_A1);
  uncompress_and_copy_to_vram();
  wVar1 = FUN_00027ff6();
  FUN_00027f20((uint3 *)&UNK_0001abee, wVar1);
  FUN_0000147a(f, 0, 4);
  sVar4 = 2;
  _DAT_ffffdb06 = unaff_D2w;
  do {
    FUN_0001afc6();
    sVar4 = sVar4 + -1;
  } while (sVar4 != -1);
  _DAT_ffffdb04 = 0;
  if ((((short)WORD_ffffdaf8 < 0) &&
       (_DAT_ffffdb04 = 1, (short)WORD_ffffdafc < 0)) &&
      (_DAT_ffffdb04 = 2, (short)WORD_ffffdb00 < 0)) {
    _DAT_ffffdb04 = 0xffff;
  }
  FUN_0001af48();
  FUN_00001630();
LAB_0001aa4e:
  while (FUN_0001af28(),
         (gamepad_pressed_prev & GAMEPAD_ACCEPT) != GAMEPAD_NONE) {
    if ((short)_DAT_ffffdb04 < 0) {
      audio_play(SOUND_ID_RES_BTTN);
      iVar2 = 5;
      goto LAB_0001abb6;
    }
    if (*(short *)((int)&WORD_ffffdaf8 + (int)(short)(_DAT_ffffdb04 << 2)) <
        0) {
      audio_play(SOUND_ID_FALSE);
    } else if ((uint)gold <
               (uint) * (ushort *)((short)(_DAT_ffffdb04 << 2) + -0x2506)) {
      audio_play(SOUND_ID_FALSE);
      FUN_0001926a();
      do {
        FUN_0001af28();
        related_to_text_3((script_ctx_t *)&DAT_ffffd9f2);
      } while (DAT_ffffd9f2 < '\0');
      FUN_0001af94();
    } else {
      audio_play(SOUND_ID_RES_KEY);
      while (DAT_ffffd9f2 < '\0') {
        FUN_0001af28();
      }
      script_ctx_bf_0d_arg = '\0';
      FUN_0001926a();
      do {
        FUN_0001af28();
        related_to_text_3((script_ctx_t *)&DAT_ffffd9f2);
      } while (DAT_ffffd9f2 < '\0');
      if (script_ctx_bf_0d_arg != '\0') {
        FUN_0000231c();
        audio_play(SOUND_ID_JINGLE_1);
        FUN_0001af3c();
        sVar4 = _DAT_ffffdb04 << 2;
        (&comp_has_func_maybe)[*(short *)((int)&WORD_ffffdaf8 + (int)sVar4)] =
            0;
        gold = gold - (uint) * (ushort *)(sVar4 + -0x2506);
        FUN_00029824();
        FUN_0001af3c();
        iVar2 = 3;
      LAB_0001abb6:
        MERCHANT = (char *)((int)(MERCHANT + iVar2) +
                            (int)*(short *)(MERCHANT + iVar2));
        FUN_00001646();
        FUN_00028710();
        if (-1 < _DAT_ffffdb06) {
          (&comp_has_func_maybe)[_DAT_ffffdb06] = 0;
        }
        FUN_00028630();
        vdp_set_window_position((ushort)DAT_ffffde0d);
        audio_resume();
        FUN_00001630();
        return;
      }
    }
  }
  uVar3 = 0xffff;
  if (((gamepad_pressed_prev & GAMEPAD_B) == GAMEPAD_NONE) &&
      ((gamepad_pressed_prev & GAMEPAD_DOWN) == GAMEPAD_NONE)) {
    uVar3 = 1;
    if ((gamepad_pressed_prev & GAMEPAD_UP) != GAMEPAD_NONE) {
      if ((short)_DAT_ffffdb04 < 0)
        goto LAB_0001aab2;
      goto LAB_0001aa4e;
    }
    if ((gamepad_pressed_prev & GAMEPAD_LEFT) == GAMEPAD_NONE) {
      if ((gamepad_pressed_prev & GAMEPAD_RIGHT) == GAMEPAD_NONE)
        goto LAB_0001aa4e;
      if ((short)_DAT_ffffdb04 < 0) {
        uVar3 = 2;
      } else {
        if (1 < _DAT_ffffdb04)
          goto LAB_0001aa4e;
        uVar3 = _DAT_ffffdb04 + 1;
      }
    } else {
      if (_DAT_ffffdb04 == 0)
        goto LAB_0001aa4e;
      if ((short)_DAT_ffffdb04 < 0) {
        uVar3 = 0;
      } else {
        uVar3 = _DAT_ffffdb04 - 1;
      }
    }
  } else {
  LAB_0001aab2:
    if (uVar3 == _DAT_ffffdb04)
      goto LAB_0001aa4e;
  }
  _DAT_ffffdb04 = uVar3;
  audio_play(SOUND_ID_RES_KEY);
  FUN_0001af48();
  goto LAB_0001aa4e;
}

void FUN_0001af28(void)

{
  byte bVar1;

  FUN_000028ce();
  if (-1 < (char)DAT_ffffd9f2) {
    return;
  }
  if (-1 < (char)DAT_ffffd9f2) {
    return;
  }
  bVar1 = DAT_ffffd9f2 & 0x40;
  DAT_ffffd9f2 = DAT_ffffd9f2 | 0x40;
  if (bVar1 == 0) {
    related_to_text_4((script_ctx_t *)&DAT_ffffd9f2);
    uRamffffda00 = 0x401;
  }
  // WARNING: Could not recover jumptable at 0x0001961a. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0001961e +
             (int)*(short *)((int)&WORD_0001961e +
                             (int)(short)(ushort)bRamffffd9f3)))();
  return;
}

void FUN_0001af3c(void)

{
  short in_D0w;
  undefined2 uStack_2;

  uStack_2 = in_D0w;
  do {
    FUN_0001af28();
    uStack_2 = uStack_2 + -1;
  } while (uStack_2 != 0);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001af48(void)

{
  ushort uVar1;
  undefined2 *puVar2;
  ushort *puVar3;
  entity_id_t unaff_A5;

  if (-1 < _DAT_ffffdb06) {
    ecs_init_entity_state(
        (int)_DAT_ffffdb06,
        unaff_A5,
        (component_mixed_1_t *)(&UNK_0001af6c +
                                (short)((_DAT_ffffdb04 + 1) * 10)));
  }
  DAT_ffffd9f2 = 0;
  FUN_00028710();
  if ((-1 < _DAT_ffffdb04) &&
      (-1 <
       *(short *)((int)&WORD_ffffdaf8 + (int)(short)(_DAT_ffffdb04 << 2)))) {
    script_ctx_push_string((script_ctx_t *)&DAT_ffffd9f2,
                           (byte)MERCHANT[_DAT_ffffdb04] + 0x8c);
    DAT_ffffd9f2 = 0xe0;
    FUN_000191f4((script_ctx_t *)&DAT_ffffd9f2, WORD_ARRAY_0001928c);
    related_to_text_4((script_ctx_t *)&DAT_ffffd9f2);
    uRamffffda00 = 0x101;
    uVar1 = (ushort)(sRamffffda02 * sRamffffda04 + 0xfU) >> 4;
    if (-1 < (short)uRamffffd9fe) {
      puVar2 = (undefined2 *)(&DAT_ffff9a8a + (short)(uRamffffd9fe >> 4));
      do {
        *puVar2 = 0xffff;
        uVar1 = uVar1 - 1;
        puVar2 = puVar2 + 1;
      } while (uVar1 != 0);
      return;
    }
    puVar3 = (ushort *)(int)(short)uRamffffd9fe;
    do {
      *(undefined2 *)(&DAT_ffff9a8a + (short)(*puVar3 >> 4)) = 0xffff;
      uVar1 = uVar1 - 1;
      puVar3 = puVar3 + 1;
    } while (uVar1 != 0);
    return;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001af94(void)

{
  ushort uVar1;
  undefined2 *puVar2;
  ushort *puVar3;

  DAT_ffffd9f2 = 0;
  FUN_00028710();
  if ((-1 < _DAT_ffffdb04) &&
      (-1 <
       *(short *)((int)&WORD_ffffdaf8 + (int)(short)(_DAT_ffffdb04 << 2)))) {
    script_ctx_push_string((script_ctx_t *)&DAT_ffffd9f2,
                           (byte)MERCHANT[_DAT_ffffdb04] + 0x8c);
    DAT_ffffd9f2 = 0xe0;
    FUN_000191f4((script_ctx_t *)&DAT_ffffd9f2, WORD_ARRAY_0001928c);
    related_to_text_4((script_ctx_t *)&DAT_ffffd9f2);
    uRamffffda00 = 0x101;
    uVar1 = (ushort)(sRamffffda02 * sRamffffda04 + 0xfU) >> 4;
    if (-1 < (short)uRamffffd9fe) {
      puVar2 = (undefined2 *)(&DAT_ffff9a8a + (short)(uRamffffd9fe >> 4));
      do {
        *puVar2 = 0xffff;
        uVar1 = uVar1 - 1;
        puVar2 = puVar2 + 1;
      } while (uVar1 != 0);
      return;
    }
    puVar3 = (ushort *)(int)(short)uRamffffd9fe;
    do {
      *(undefined2 *)(&DAT_ffff9a8a + (short)(*puVar3 >> 4)) = 0xffff;
      uVar1 = uVar1 - 1;
      puVar3 = puVar3 + 1;
    } while (uVar1 != 0);
    return;
  }
  return;
}

void FUN_0001afc6(void)

{
  short sVar1;
  byte bVar2;
  undefined4 extraout_D0;
  void *vram_dst;
  short unaff_D7w;
  entity_id_t e;
  anim_item_t *unaff_A5;

  sVar1 = *(short *)((int)&WORD_ffffdaf8 + (int)(short)(unaff_D7w << 2));
  if (sVar1 < 0) {
    return;
  }
  e = (entity_id_t)sVar1;
  (&comp_has_func_maybe)[e] = COMPONENT_STATE_B_C0;
  entity_reset(e);
  *(undefined2 *)((int)&comp_unk_3 + e) = 0;
  *(undefined2 *)((int)&comp_pos_x + e) =
      *(undefined2 *)((int)&WORD_0001b03e + (int)(short)(unaff_D7w * 2));
  *(undefined2 *)((int)&comp_pos_y + e) = 0x70;
  *(undefined2 *)((int)&comp_unk_4 + e) = 4;
  bVar2 = MERCHANT[unaff_D7w];
  (&comp_state_a)[e] = 0x80;
  (&comp_anim_base_offset)[e] = 0x18;
  (&comp_anim_b)[e] = (&DAT_0001b04a)[(short)((ushort)bVar2 * 2)];
  ecs_anim_unk_2(e, unaff_A5, (&DAT_0001b04b)[(short)((ushort)bVar2 * 2)]);
  vram_dst = *(void **)(&DAT_0001b044 + (short)(unaff_D7w * 2));
  do {
    vdp_set_vram_write_addr(vram_dst);
    vram_dst = (void *)((short)vram_dst + -2);
    VDP_DATA = (word)extraout_D0;
  } while ((short)((uint)extraout_D0 >> 0x10) != 0);
  return;
}

ushort merchant_items_1(void)

{
  word *extraout_A1;
  word *extraout_A1_00;

  item_something((item_t *)MERCHANT, &WORD_ffffdaf8, 0xf4);
  item_something((item_t *)(MERCHANT + 1), extraout_A1, 0xf4);
  item_something((item_t *)(MERCHANT + 2), extraout_A1_00, 0xf4);
  return WORD_ffffdb00 & WORD_ffffdafc & WORD_ffffdaf8 & 0x8000;
}

void item_something(item_t *item_p, word *param_2, word param_3)

{
  item_t item;
  word *extraout_A1;
  undefined2 *extraout_A1_00;
  undefined2 *extraout_A1_01;
  undefined2 *puVar1;
  bool can_be_sold;

  item = *item_p;
  // If the item is valid (negative items are invaid).
  if ((-1 < (char)item) && (can_be_sold = item_can_be_sold(item),
                            param_2 = extraout_A1,
                            can_be_sold)) {
    *extraout_A1 = param_3;
    can_be_sold = item_check_isnt_owned(item);
    puVar1 = extraout_A1_00;
    if (can_be_sold) {
      FUN_0001b116();
      puVar1 = extraout_A1_01;
    }
    *puVar1 = 100;
    return;
  }
  *param_2 = 0xffff;
  param_2[1] = 0;
  return;
}

void FUN_0001b116(void)

{
  return;
}

void menu_in_game_handle_input(void)

{
  word wVar1;
  char cVar2;
  short sVar3;
  undefined1 *puVar4;
  entity_id_t unaff_A5;
  bool bVar5;

  if (((gamepad_held & GAMEPAD_B) != GAMEPAD_NONE) && (DAT_ffff915f == -0x20)) {
    FUN_0001b744();
    return;
  }
  audio_play(SOUND_ID_RES_BTTN);
  wVar1 = FUN_0002867e();
  FUN_00027f20((uint3 *)&DAT_0001b21c, wVar1);
  DAT_ffffdadc = OWNED_SWORD;
  DAT_ffffdadd = OWNED_SHIELD;
  DAT_ffffdade = OWNED_ARMOR;
  DAT_ffffdadf = 0xfe;
  DAT_ffffdae0 = 0xff;
  if (OWNED_HEALING_MEDICINE_COUNT != '\0') {
    DAT_ffffdae0 = 0x1c;
  }
  sVar3 = 4;
  puVar4 = &DAT_ffffdae1;
  do {
    *puVar4 = 0xfe;
    sVar3 = sVar3 + -1;
    puVar4 = puVar4 + 1;
  } while (sVar3 != -1);
  FUN_0001b252();
  FUN_0001b238();
  DAT_ffffdaf0 = 0;
  DAT_ffffdaf2 = 0;
  ecs_init_entity_state(ENTITY_ID_F4, unaff_A5, &component_mixed_1_t_0001b22e);
  FUN_0001b72a();
  FUN_00001630();
  do {
    while (FUN_000028ce(),
           (gamepad_pressed_prev & GAMEPAD_ACCEPT) == GAMEPAD_NONE) {
    LAB_0001b206:
      if ((gamepad_pressed_prev & GAMEPAD_CANCEL) != GAMEPAD_NONE)
        goto LAB_0001b216;
      menu_in_game_handle_movement();
    }
    audio_play(SOUND_ID_RES_BTTN);
    cVar2 = FUN_0001b714();
    bVar5 = cVar2 == '\0';
    if (cVar2 < '\0')
      goto LAB_0001b206;
    FUN_0001b274();
  } while (bVar5);
LAB_0001b216:
  FUN_0002861a();
  return;
}

void FUN_0001b238(void)

{
  short sVar1;
  short sVar2;
  item_t *piVar3;
  item_t *piVar4;
  char *pcVar5;
  char *pcVar6;

  sVar1 = 9;
  piVar3 = OWNED_INVENTORY;
  piVar4 = &DAT_ffffdae6;
  do {
    *piVar4 = *piVar3;
    sVar1 = sVar1 + -1;
    piVar3 = piVar3 + 1;
    piVar4 = piVar4 + 1;
  } while (sVar1 != -1);
  pcVar5 = &DAT_ffffdae6;
  sVar1 = 1;
  do {
    sVar2 = 4;
    pcVar6 = pcVar5;
    do {
      pcVar5 = pcVar6 + 1;
      if (*pcVar6 != -2) {
        FUN_00028736();
      }
      sVar2 = sVar2 + -1;
      pcVar6 = pcVar5;
    } while (sVar2 != -1);
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return;
}

void FUN_0001b252(void)

{
  short sVar1;
  short unaff_D7w;
  char *unaff_A3;
  char *pcVar2;

  do {
    sVar1 = 4;
    pcVar2 = unaff_A3;
    do {
      unaff_A3 = pcVar2 + 1;
      if (*pcVar2 != -2) {
        FUN_00028736();
      }
      sVar1 = sVar1 + -1;
      pcVar2 = unaff_A3;
    } while (sVar1 != -1);
    unaff_D7w = unaff_D7w + -1;
  } while (unaff_D7w != -1);
  return;
}

void FUN_0001b274(void)

{
  byte in_D0b;

  // WARNING: Could not recover jumptable at 0x0001b280. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)(&DAT_0001b284 +
             *(short *)(&DAT_0001b284 + (short)(ushort)(byte)(&DAT_0001b2a0)[(
                                            short)(ushort)in_D0b])))();
  return;
}

longlong FUN_0001b33e(void)

{
  undefined2 uVar1;
  undefined2 in_D0w;
  uint uVar2;
  short sVar3;
  ushort uVar4;
  short unaff_D5w;
  ushort unaff_D6w;
  short unaff_D7w;
  int iVar5;

  uVar2 = FUN_00001770();
  uVar1 = (undefined2)(uVar2 >> 0x10);
  if ((uVar2 & 1) != 0) {
    iVar5 = 0x84;
    sVar3 = 0x11;
    do {
      if (((((&comp_has_func_maybe)[iVar5] & COMPONENT_STATE_B_C0) ==
            COMPONENT_STATE_B_C0) &&
           (unaff_D7w == *(short *)(&comp_unk_1 + iVar5))) &&
          ((int16_t)((comp_collision_sensor[0].y + comp_pos_y.fixed.i) -
                     unaff_D5w) == *(short *)((int)&comp_pos_y + iVar5))) {
        uVar4 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + iVar5);
        if ((short)uVar4 < 0) {
          uVar4 = -uVar4;
        }
        if (uVar4 < unaff_D6w) {
          return CONCAT44(CONCAT22(uVar1, in_D0w), 0xffffffff);
        }
      }
      iVar5 = iVar5 + 4;
      sVar3 = sVar3 + -1;
    } while (sVar3 != -1);
  }
  return (ulonglong)CONCAT22(uVar1, in_D0w) << 0x20;
}

longlong FUN_0001b394(void)

{
  short sVar1;
  undefined2 uVar2;
  undefined2 in_D0w;
  uint uVar3;
  short sVar4;
  ushort uVar5;
  ushort unaff_D6w;
  byte unaff_D7b;
  int iVar6;

  uVar3 = FUN_00001770();
  if ((uVar3 & 1) != 0) {
    iVar6 = 0x34;
    sVar4 = 0x13;
    do {
      if ((((&comp_has_func_maybe)[iVar6] & COMPONENT_STATE_B_C0) ==
           COMPONENT_STATE_B_C0) &&
          (unaff_D7b == (&comp_func_offset[0].unk1)[iVar6])) {
        uVar2 = (undefined2)(uVar3 >> 0x10);
        sVar1 = *(short *)((int)&comp_collision_sensor[0].y + iVar6) +
                *(short *)((int)&comp_pos_y + iVar6);
        uVar3 = CONCAT22(uVar2, sVar1);
        if (sVar1 == (short)(comp_collision_sensor[0].y + comp_pos_y.fixed.i)) {
          uVar5 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + iVar6);
          if ((short)uVar5 < 0) {
            uVar5 = -uVar5;
          }
          if (uVar5 < unaff_D6w) {
            return CONCAT44(CONCAT22(uVar2, in_D0w), 0xffffffff);
          }
        }
      }
      iVar6 = iVar6 + 4;
      sVar4 = sVar4 + -1;
    } while (sVar4 != -1);
  }
  return (ulonglong)CONCAT22((short)(uVar3 >> 0x10), in_D0w) << 0x20;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_0001b496(void)

{
  ushort in_D0w;
  ushort uVar1;
  undefined2 uVar2;
  undefined2 extraout_A0w;
  int extraout_A0;
  int extraout_A0_00;
  bool bVar3;
  undefined2 uStack_6;
  undefined4 uStack_4;

  if (DAT_ffffcf7e == '\"') {
    if (DAT_ffffcf7f != '\0') {
      uStack_4 = 0x1b4aa;
      uVar1 = FUN_00001770();
      in_D0w = 0x23;
      if ((uVar1 & 1) != 0) {
        uStack_4 = 0x1b490;
        item_remove_from_inventory(0x23);
        DAT_ffffcc92 = 0xc;
        return 0xffffffff;
      }
    }
  } else {
    bVar3 = false;
    uStack_4 = 0x1b4c2;
    FUN_0001b33e();
    if (!bVar3) {
      uVar2 = 10;
      uStack_6 = extraout_A0w;
    LAB_0001b4f0:
      *(undefined2 *)((int)register0x0000003c + -2) = uVar2;
      *(undefined4 *)((int)register0x0000003c + -6) = 0x1b4fa;
      _DAT_ffffda72 = uStack_6;
      FUN_0001b732();
      OWNED_INVENTORY[extraout_A0_00] = 0x22;
      DAT_ffffcc92 = (char)*(undefined2 *)((int)register0x0000003c + -2);
      return 0xffffffff;
    }
    bVar3 = false;
    uStack_4 = 0x1b4d0;
    in_D0w = FUN_0001b394();
    if (!bVar3) {
      uStack_4 = CONCAT22((short)extraout_A0, uStack_4._2_2_);
      bVar3 = script_state_get(
          *(script_state_bit_t *)(&DAT_ffffd01c +
                                  *(short *)((int)&comp_unk_8 + extraout_A0)));
      register0x0000003c = (BADSPACEBASE *)&uStack_4;
      if (bVar3) {
        uVar2 = 0xd;
        goto LAB_0001b4f0;
      }
    }
  }
  _BYTE_ffffd918 = (in_D0w & 0xff) + 0x7541;
  *(undefined4 *)((int)register0x0000003c + -4) = 0x1b2f2;
  FUN_00028710();
  *(undefined4 *)((int)register0x0000003c + -4) = 0x1b2fc;
  text_do_something_and_set_script(&DAT_0001b314);
  do {
    *(undefined4 *)((int)register0x0000003c + -4) = 0x1b300;
    FUN_000028ce();
    *(undefined4 *)((int)register0x0000003c + -4) = 0x1b308;
    related_to_text_3(&SCRIPT_CTX_CURRENT);
    // While flag 7 is set.
  } while ((char)SCRIPT_CTX_CURRENT.flags < '\0');
  *(undefined4 *)((int)register0x0000003c + -4) = 0x1b310;
  FUN_0001b72a();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_0001b506(void)

{
  item_t in_D0b;

  if (DAT_ffffcf7e == '%') {
    DAT_ffffcf7e = in_D0b;
    item_remove_from_inventory(in_D0b);
    DAT_ffffcc92 = 0xe;
    return 0xffffffff;
  }
  _BYTE_ffffd918 = in_D0b + 0x7541;
  FUN_00028710();
  text_do_something_and_set_script(&DAT_0001b314);
  do {
    FUN_000028ce();
    related_to_text_3(&SCRIPT_CTX_CURRENT);
  } while ((char)SCRIPT_CTX_CURRENT.flags < '\0');
  FUN_0001b72a();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_0001b520(void)

{
  ushort in_D0w;

  if (DAT_ffffcbb2 == 0x11) {
    FUN_0002804c();
    return 0xffffffff;
  }
  _BYTE_ffffd918 = (in_D0w & 0xff) + 0x7541;
  FUN_00028710();
  text_do_something_and_set_script(&DAT_0001b314);
  do {
    FUN_000028ce();
    related_to_text_3(&SCRIPT_CTX_CURRENT);
  } while ((char)SCRIPT_CTX_CURRENT.flags < '\0');
  FUN_0001b72a();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_0001b534(void)

{
  item_t item;
  int extraout_A0;
  bool bVar1;

  bVar1 = false;
  item = FUN_0001b33e();
  if ((!bVar1) && (item == (&comp_collected_item_id_maybe)[extraout_A0])) {
    _DAT_ffffda72 = (undefined2)extraout_A0;
    item_remove_from_inventory(item);
    DAT_ffffcc92 = 0x11;
    return 0xffffffff;
  }
  _BYTE_ffffd918 = item + 0x7541;
  FUN_00028710();
  text_do_something_and_set_script(&DAT_0001b314);
  do {
    FUN_000028ce();
    related_to_text_3(&SCRIPT_CTX_CURRENT);
  } while ((char)SCRIPT_CTX_CURRENT.flags < '\0');
  FUN_0001b72a();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_0001b55a(void)

{
  byte in_D0b;
  uint uVar1;

  if (in_D0b == DAT_ffffcf7e) {
    uVar1 = FUN_00001770();
    if ((uVar1 & 1) != 0) {
      DAT_ffffcc92 = 0x12;
      return 0xffffffff;
    }
    in_D0b = 0x2f;
  }
  _BYTE_ffffd918 = in_D0b + 0x7541;
  FUN_00028710();
  text_do_something_and_set_script(&DAT_0001b314);
  do {
    FUN_000028ce();
    related_to_text_3(&SCRIPT_CTX_CURRENT);
  } while ((char)SCRIPT_CTX_CURRENT.flags < '\0');
  FUN_0001b72a();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_0001b578(void)

{
  byte in_D0b;
  uint uVar1;

  if (in_D0b == DAT_ffffcf7e) {
    uVar1 = FUN_00001770();
    if ((uVar1 & 1) != 0) {
      item_remove_from_inventory(0x1f);
      DAT_ffffcc92 = 0x15;
      return 0xffffffff;
    }
    in_D0b = 0x1f;
  }
  _BYTE_ffffd918 = in_D0b + 0x7541;
  FUN_00028710();
  text_do_something_and_set_script(&DAT_0001b314);
  do {
    FUN_000028ce();
    related_to_text_3(&SCRIPT_CTX_CURRENT);
  } while ((char)SCRIPT_CTX_CURRENT.flags < '\0');
  FUN_0001b72a();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_0001b59e(void)

{
  byte in_D0b;
  uint uVar1;

  if (in_D0b == DAT_ffffcf7e) {
    uVar1 = FUN_00001770();
    if ((uVar1 & 1) != 0) {
      item_remove_from_inventory(0x1e);
      DAT_ffffcc92 = 0x16;
      return 0xffffffff;
    }
    in_D0b = 0x1e;
  }
  _BYTE_ffffd918 = in_D0b + 0x7541;
  FUN_00028710();
  text_do_something_and_set_script(&DAT_0001b314);
  do {
    FUN_000028ce();
    related_to_text_3(&SCRIPT_CTX_CURRENT);
  } while ((char)SCRIPT_CTX_CURRENT.flags < '\0');
  FUN_0001b72a();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address
// FIXME Where is it called?

undefined4 FUN_0001b5c4(void)

{
  ushort uVar1;
  undefined2 extraout_D0u;
  undefined2 extraout_D0u_00;
  ushort in_D0w;
  word wVar4;
  long extraout_D0;
  long extraout_D0_00;
  long lVar2;
  long extraout_D0_01;
  undefined4 extraout_D0_02;
  short sVar5;
  undefined4 uVar3;
  long extraout_D1;
  long extraout_D1_00;
  long lVar6;
  long extraout_D1_01;
  undefined4 extraout_D1_02;
  undefined4 extraout_D1_03;
  undefined4 extraout_D1_04;
  undefined2 uVar7;
  undefined4 unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  char *script;
  component_mixed_1_t *state;
  void *extraout_A1;
  func *f;
  void *extraout_A1_00;
  script_ctx_t *unaff_A3;
  entity_id_t self;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  bool bVar9;
  undefined1 uVar10;
  undefined8 uVar11;
  long lVar8;

  uVar1 = DAT_ffffcbb2;
  uVar7 = (undefined2)((uint)unaff_D2 >> 0x10);
  lVar8 = CONCAT22(uVar7, DAT_ffffcbb2);
  if ((1 << (DAT_ffffcbb2 & 0x1f) & 0x3f5c0U) == 0) {
    _BYTE_ffffd918 = (in_D0w & 0xff) + 0x7541;
    FUN_00028710();
    script = &DAT_0001b314;
  } else {
    bVar9 = script_state_get((script_state_bit_t)0x7c);
    if (bVar9) {
      FUN_00001646();
      _DAT_ffffdd50 = UNION_sound_id_word_union_t_ffff97e6;
      FUN_0000192a((sound_id_word_t)0x6);
      text_unk_1(&DAT_000261c8, extraout_A1);
      uncompress_and_copy_to_vram();
      wVar4 = FUN_00027ff6();
      FUN_00027f20((uint3 *)&DAT_00026200, wVar4);
      ecs_init_entity_state(
          ENTITY_ID_F8, (entity_id_t)unaff_A5, &component_mixed_1_t_000261e2);
      self = ENTITY_ID_F4;
      ecs_init_entity_state(
          ENTITY_ID_F4, (entity_id_t)unaff_A5, &component_mixed_1_t_000261ec);
      _DAT_ffffdd48 = 0xffff;
      if ((-1 < (char)script_ctx_bf_0e_arg) && (script_ctx_bf_0e_arg < 3)) {
        FUN_0000147a(f, 0, 4);
        if (-1 < (short)uVar1) {
          _DAT_ffffdd48 = uVar1;
          self = (entity_id_t)(short)uVar1;
          ecs_init_entity_state(
              self, (entity_id_t)unaff_A5, &component_mixed_1_t_000261f6);
          (&comp_anim_b)[self] = script_ctx_bf_0e_arg * '\x02' + 0x1c;
          ecs_anim_unk_2(self, unaff_A5, 0);
        }
      }
      _DAT_ffff9ae4 = 0xffff;
      _DAT_ffff9ae6 = 0xffffffff;
      uVar11 = FUN_00001630();
      do {
        uVar11 = exception_unk_0(unaff_A3,
                                 self,
                                 unaff_A6,
                                 (long)((ulonglong)uVar11 >> 0x20),
                                 (long)uVar11,
                                 lVar8,
                                 unaff_D3,
                                 unaff_D4,
                                 unaff_D5,
                                 unaff_D6,
                                 unaff_D7);
      } while (_DAT_ffffa62c != 0);
      ecs_anim_unk_2(ENTITY_ID_F4, unaff_A5, 2);
      ecs_init_entity_state(
          ENTITY_ID_FC, (entity_id_t)unaff_A5, &component_mixed_1_t_000261d8);
      DAT_ffffdd40 = -0x17;
      do {
        uVar11 = FUN_0002669a();
        exception_unk_0(unaff_A3,
                        ENTITY_ID_FC,
                        unaff_A6,
                        (long)((ulonglong)uVar11 >> 0x20),
                        (long)uVar11,
                        lVar8,
                        unaff_D3,
                        unaff_D4,
                        unaff_D5,
                        unaff_D6,
                        unaff_D7);
        bVar9 = script_state_get((script_state_bit_t)0x3e7);
        if ((!bVar9) && ((gamepad_held & GAMEPAD_B) != GAMEPAD_NONE)) {
          FUN_000265a6();
          goto LAB_00026182;
        }
        DAT_ffffdd40 = DAT_ffffdd40 + 1;
        if (DAT_ffffdd40 < 0x40) {
          DAT_ffffa322 = DAT_ffffa322 + -1;
        }
      } while (DAT_ffffdd40 < 0x58);
      _DAT_ffffbe74 = DAT_ffffa322;
      lVar2 = extraout_D0;
      lVar6 = extraout_D1;
      do {
        exception_unk_0(unaff_A3,
                        ENTITY_ID_FC,
                        unaff_A6,
                        lVar2,
                        lVar6,
                        lVar8,
                        unaff_D3,
                        unaff_D4,
                        unaff_D5,
                        unaff_D6,
                        unaff_D7);
        FUN_000267f4();
        DAT_ffffa52a = DAT_ffffa52a + 0x10;
        if (0x100 < DAT_ffffa52a) {
          DAT_ffffa52a = 0x100;
        }
        player_update_pos(0xfc);
        lVar2 = extraout_D0_00;
        lVar6 = extraout_D1_00;
      } while (uRamffffa21e < 0xa0);
      do {
        exception_unk_0(unaff_A3,
                        ENTITY_ID_FC,
                        unaff_A6,
                        lVar2,
                        lVar6,
                        lVar8,
                        unaff_D3,
                        unaff_D4,
                        unaff_D5,
                        unaff_D6,
                        unaff_D7);
        FUN_000267f4();
        DAT_ffffa52a = DAT_ffffa52a + -8;
        if (DAT_ffffa52a < 0) {
          DAT_ffffa52a = 0;
        }
        player_update_pos(0xfc);
        lVar2 = extraout_D0_01;
        lVar6 = extraout_D1_01;
      } while (DAT_ffffa52a != 0);
    LAB_00026182:
      uVar11 = FUN_00019294();
      do {
        exception_unk_0(unaff_A3,
                        ENTITY_ID_FC,
                        unaff_A6,
                        (long)((ulonglong)uVar11 >> 0x20),
                        (long)uVar11,
                        lVar8,
                        unaff_D3,
                        unaff_D4,
                        unaff_D5,
                        unaff_D6,
                        unaff_D7);
        unaff_A3 = &SCRIPT_CTX_CURRENT;
        related_to_text_3(&SCRIPT_CTX_CURRENT);
        FUN_000267f4();
        player_update_pos(0xfc);
        uVar11 = CONCAT44(extraout_D0_02, extraout_D1_02);
        // While flag 7 is set.
      } while ((char)SCRIPT_CTX_CURRENT.flags < '\0');
      uVar10 = SCRIPT_PROMPT_RESPONSE == '\0';
      if (!(bool)uVar10) {
        if (-1 < (short)_DAT_ffffdd48) {
          (&comp_has_func_maybe)[(short)_DAT_ffffdd48] = 0;
        }
        FUN_0000192a((sound_id_word_t)_DAT_ffffdd50);
        FUN_00028630();
        vdp_set_window_position((ushort)DAT_ffffde0d);
        audio_resume();
        uVar3 = FUN_00001630();
        return uVar3;
      }
      uVar11 = palette_set_fade_black_ease_in_all();
      do {
        exception_unk_0(&SCRIPT_CTX_CURRENT,
                        ENTITY_ID_FC,
                        unaff_A6,
                        (long)((ulonglong)uVar11 >> 0x20),
                        (long)uVar11,
                        lVar8,
                        unaff_D3,
                        unaff_D4,
                        unaff_D5,
                        unaff_D6,
                        unaff_D7);
        FUN_000267f4();
        player_update_pos(0xfc);
        sVar5 = palette_iterate_for_unknown_reasons();
        uVar11 = CONCAT44(CONCAT22(extraout_D0u, sVar5), extraout_D1_03);
      } while ((bool)uVar10);
      FUN_00001646();
      lVar8 = CONCAT22(uVar7, DAT_ffffcbb2);
      DAT_ffffdd4a = 1;
      if ((1 << (DAT_ffffcbb2 & 0x1f) & 0x29500U) != 0) {
        DAT_ffffdd4a = -1;
      }
      FUN_00001580();
      DAT_ffff91ce._0_1_ = 0xff;
      text_unk_1(&DAT_00026914, extraout_A1_00);
      state = &component_mixed_1_t_00026926;
      if (script_ctx_bf_0e_arg < 3) {
        state = (component_mixed_1_t
                     *)((int)&component_mixed_1_t_00026926.unknown_3 +
                        (int)(short)((script_ctx_bf_0e_arg + 1) * 10));
      }
      ecs_init_entity_state(ENTITY_ID_08, (entity_id_t)unaff_A5, state);
      comp_vel[2].x.raw = -0x200;
      if (DAT_ffffdd4a < 0) {
        comp_vel[2].x.raw = 0x200;
        DAT_ffff9f23 = DAT_ffff9f23 | 8;
        DAT_ffffa12a = 0;
      }
      FUN_0002694e();
      DAT_ffffdd4f = 0;
      DAT_ffffdd4e = 0;
      DAT_ffffdd4c = 0;
      FUN_000271b4();
      VDP_CTRL = 0x8b03;
      uncompress_and_copy_to_vram();
      _DAT_ffff9812 = 0x248;
      vdp_palettes_something();
      DAT_ffff91ce._0_1_ = 0;
      uVar11 = palette_set_fade_black_ease_out_all();
      do {
        exception_unk_0(&SCRIPT_CTX_CURRENT,
                        ENTITY_ID_08,
                        unaff_A6,
                        (long)((ulonglong)uVar11 >> 0x20),
                        (long)uVar11,
                        lVar8,
                        unaff_D3,
                        unaff_D4,
                        unaff_D5,
                        unaff_D6,
                        unaff_D7);
        FUN_000271b4();
        uVar11 = FUN_000270e4();
        uVar10 = DAT_ffffdd4f == 3;
      } while (DAT_ffffdd4f < 3);
      uVar11 = palette_set_fade_black_ease_in_all();
      do {
        exception_unk_0(&SCRIPT_CTX_CURRENT,
                        ENTITY_ID_08,
                        unaff_A6,
                        (long)((ulonglong)uVar11 >> 0x20),
                        (long)uVar11,
                        lVar8,
                        unaff_D3,
                        unaff_D4,
                        unaff_D5,
                        unaff_D6,
                        unaff_D7);
        FUN_000271b4();
        FUN_000270e4();
        sVar5 = palette_iterate_for_unknown_reasons();
        uVar11 = CONCAT44(CONCAT22(extraout_D0u_00, sVar5), extraout_D1_04);
      } while ((bool)uVar10);
      FUN_00001646();
      DAT_ffff97ee = 0xff;
      uVar3 = audio_play_sound_asha_dies();
      DAT_ffff97ea = 0xe7;
      DAT_ffffcc92 = 1;
      DAT_ffffcc93 = 9;
      return uVar3;
    }
    FUN_00028710();
    script = script_fetch(0xd5);
  }
  text_do_something_and_set_script(script);
  do {
    FUN_000028ce();
    related_to_text_3(&SCRIPT_CTX_CURRENT);
  } while ((char)SCRIPT_CTX_CURRENT.flags < '\0');
  FUN_0001b72a();
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_0001b5fc(void)

{
  short sVar1;
  ushort in_D0w;

  script_ctx_bf_0d_arg = '\0';
  _BYTE_ffffd918 = (in_D0w & 0xff) + 0x7541;
  FUN_00028710();
  func_0x0001b2f6();
  if (script_ctx_bf_0d_arg != '\0') {
    sVar1 = DAT_ffffdaf0 + (DAT_ffffdaf2 + -2) * 5;
    FUN_000299c0(OWNED_INVENTORY + sVar1, (item_t)sVar1);
    DAT_ffff91ce._0_1_ = 0xff;
    FUN_0001b238();
    DAT_ffff91ce._0_1_ = 0;
    asha_gain_hearts(3);
  }
  return 0;
}

void menu_in_game_handle_movement(void)

{
  ushort uVar1;
  ushort uVar2;
  ushort extraout_D1w;
  ushort extraout_D1w_00;
  ushort extraout_D1w_01;
  ushort uVar3;
  ushort extraout_D1w_02;
  ushort uVar4;
  ushort uVar5;
  bool bVar6;

  uVar5 = DAT_ffffdaf2;
  uVar3 = DAT_ffffdaf2;
  uVar2 = DAT_ffffdaf0;
  uVar1 = DAT_ffffdaf0;
  if ((gamepad_pressed_prev & GAMEPAD_RIGHT) == GAMEPAD_NONE) {
  LAB_0001b67a:
    uVar2 = uVar1;
    uVar1 = uVar2;
    if ((gamepad_pressed_prev & GAMEPAD_LEFT) == GAMEPAD_NONE) {
    LAB_0001b690:
      uVar4 = uVar5;
      uVar2 = uVar1;
      if ((gamepad_pressed_prev & GAMEPAD_DOWN) == GAMEPAD_NONE) {
      LAB_0001b6a8:
        uVar4 = uVar3;
        uVar5 = uVar3;
        if ((gamepad_pressed_prev & GAMEPAD_UP) != GAMEPAD_NONE) {
          do {
            uVar5 = uVar5 - 1;
            bVar6 = uVar5 == 0;
            uVar4 = uVar3;
            if ((short)uVar5 < 0)
              break;
            uVar2 = FUN_0001b6dc();
            uVar3 = extraout_D1w_02;
            uVar4 = uVar5;
          } while (bVar6);
        }
      } else {
        do {
          uVar4 = uVar4 + 1;
          bVar6 = uVar4 == 4;
          if (3 < uVar4)
            goto LAB_0001b6a8;
          uVar2 = FUN_0001b6dc();
          uVar3 = extraout_D1w_01;
        } while (bVar6);
      }
    } else {
      do {
        uVar2 = uVar2 - 1;
        bVar6 = uVar2 == 0;
        if ((short)uVar2 < 0)
          goto LAB_0001b690;
        uVar1 = FUN_0001b6dc();
        uVar4 = extraout_D1w_00;
        uVar3 = extraout_D1w_00;
      } while (bVar6);
    }
  } else {
    do {
      uVar2 = uVar2 + 1;
      bVar6 = uVar2 == 5;
      if (4 < uVar2)
        goto LAB_0001b67a;
      uVar1 = FUN_0001b6dc();
      uVar4 = extraout_D1w;
      uVar3 = extraout_D1w;
    } while (bVar6);
  }
  if ((uVar2 == DAT_ffffdaf0) && (uVar4 == DAT_ffffdaf2)) {
    return;
  }
  DAT_ffffdaf0 = uVar2;
  DAT_ffffdaf2 = uVar4;
  audio_play(SOUND_ID_RES_KEY);
  FUN_0001b6ee();
  FUN_0001b72a();
  return;
}

void FUN_0001b6dc(void)

{
  return;
}

void FUN_0001b6ee(void)

{
  anim_item_t *unaff_A5;

  DAT_ffffa216 = DAT_ffffdaf0 * 0x20 + 100;
  DAT_ffffa31a = DAT_ffffdaf2 * 0x20 + 100;
  ecs_anim_unk_2(ENTITY_ID_F4, unaff_A5, 0);
  return;
}

undefined2 FUN_0001b714(void)

{
  short sVar1;

  sVar1 = DAT_ffffdaf0 + DAT_ffffdaf2 * 5;
  return CONCAT11((char)((ushort)sVar1 >> 8), (&DAT_ffffdadc)[sVar1]);
}

void FUN_0001b72a(void)

{
  script_ctx_t *unaff_A3;

  FUN_0001b714();
  FUN_00028948(unaff_A3);
  return;
}

undefined4 FUN_0001b732(void)

{
  undefined2 uVar1;
  undefined4 in_D0;
  short sVar2;

  uVar1 = (undefined2)((uint)in_D0 >> 0x10);
  sVar2 = DAT_ffffdaf2 + -2;
  if (sVar2 != 0) {
    sVar2 = 5;
    uVar1 = 0;
  }
  return CONCAT22(uVar1, DAT_ffffdaf0 + sVar2);
}

// WARNING: Removing unreachable block (ram,0x00018484)

void FUN_0001b744(void)

{
  short i;
  undefined4 unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  FUN_00001646();
  vdp_set_window_position(0x1c);
  DAT_ffff91ce._0_1_ = 0xff;
  vdp_set_vram_write_addr((void *)0xd100);
  i = 0x2ff;
  do {
    VDP_DATA = 0x8781;
    i = i + -1;
  } while (i != -1);
  FUN_0001baec();
  FUN_0001b9c6();
  DAT_ffffdb0c = 0;
  DAT_ffffdb0e = 0;
  DAT_ffff91ce._0_1_ = 0;
  DAT_ffffdb09 = gamepad_held;
  DAT_ffffdb0a = '\x10';
  DAT_ffffdb0b = '\n';
  uVar1 = FUN_00001630();
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    CONCAT22((short)((uint)unaff_D2 >> 0x10), 0xd100),
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    DAT_ffffdb08 = GAMEPAD_NONE;
    if (gamepad_held == DAT_ffffdb09) {
      if (DAT_ffffdb0a != '\0') {
        DAT_ffffdb0b = DAT_ffffdb0b + -1;
        if (DAT_ffffdb0b != '\0')
          goto LAB_0001b7e8;
        DAT_ffffdb0a = DAT_ffffdb0a + -1;
        DAT_ffffdb0b = '\x04';
      }
      DAT_ffffdb08 = gamepad_held;
    } else {
      DAT_ffffdb09 = gamepad_held;
      DAT_ffffdb08 = gamepad_held;
      DAT_ffffdb0a = '\x10';
      DAT_ffffdb0b = '\n';
    }
  LAB_0001b7e8:
    if ((gamepad_pressed_prev & GAMEPAD_START) != GAMEPAD_NONE) {
      if ((gamepad_held & GAMEPAD_B) != GAMEPAD_NONE) {
        (*(code *)(&UNK_0001b87e +
                   *(short *)(&UNK_0001b87e + (short)(DAT_ffffdb0e * 2))))();
      }
      if ((DAT_ffff915f & 0x40) != 0) {
        DAT_ffffcc92 = 0x18;
      }
      DAT_ffffd2e4 = 0;
      VDP_CTRL = 0x9100;
      VDP_CTRL = 0x9204;
      DAT_ffffd2e2 = 0xa0;
      DAT_ffffd2e0 = 0x80;
      DAT_ffffd2de = 0xff;
      return;
    }
    if ((DAT_ffffdb08 & GAMEPAD_DOWN) == GAMEPAD_NONE) {
      if ((DAT_ffffdb08 & GAMEPAD_UP) == GAMEPAD_NONE) {
        if (DAT_ffffdb08 == GAMEPAD_NONE) {
          uVar1 = FUN_0001b9f2();
        } else {
          uVar1 = (*(
              code *)(&DAT_0001b878 +
                      *(short *)(&DAT_0001b878 + (short)(DAT_ffffdb0e * 2))))();
        }
      } else {
        uVar1 = FUN_0001ba5a();
        DAT_ffffdb0e = DAT_ffffdb0e - 1;
        if ((short)DAT_ffffdb0e < 0) {
          DAT_ffffdb0e = 2;
        }
      }
    } else {
      uVar1 = FUN_0001ba5a();
      DAT_ffffdb0e = DAT_ffffdb0e + 1;
      if (2 < DAT_ffffdb0e) {
        DAT_ffffdb0e = 0;
      }
    }
  } while (true);
}

void FUN_0001b902(void)

{
  undefined2 *puVar1;
  char *pcVar2;

  if (((DAT_ffffdb08 & 8) == 0) && ((DAT_ffffdb08 & 4) == 0)) {
    puVar1 = &DAT_ffffcbb2;
    if (DAT_ffffdb0c != 0) {
      puVar1 = &DAT_ffffcbb4;
    }
    pcVar2 = (char *)((int)puVar1 + 1);
    if ((DAT_ffffdb08 & 0x20) == 0) {
      if ((DAT_ffffdb08 & 0x40) == 0) {
        return;
      }
      *pcVar2 = *pcVar2 + -1;
    } else {
      *pcVar2 = *pcVar2 + '\x01';
    }
    FUN_0001ba5a();
    return;
  }
  FUN_0001ba5a();
  if (DAT_ffffdb0c == 0) {
    DAT_ffffdb0c = 1;
    return;
  }
  DAT_ffffdb0c = 0;
  return;
}

void FUN_0001b9c6(void)

{
  DAT_ffffdb0e = 0;
  DAT_ffffdb0c = 0;
  FUN_0001ba5a();
  DAT_ffffdb0c = DAT_ffffdb0c + 1;
  FUN_0001ba5a();
  DAT_ffffdb0e = DAT_ffffdb0e + 1;
  DAT_ffffdb0c = 0;
  FUN_0001ba5a();
  DAT_ffffdb0c = DAT_ffffdb0c + 1;
  FUN_0001ba5a();
  DAT_ffffdb0e = DAT_ffffdb0e + 1;
  FUN_0001ba5a();
  return;
}

void FUN_0001b9f2(void)

{
  DAT_ffffdb11 = DAT_ffffdb11 + -1;
  if (DAT_ffffdb11 != '\0') {
    return;
  }
  if (DAT_ffffdb10 == '\0') {
    DAT_ffffdb10 = 0xff;
    DAT_ffffdb11 = 4;
    // WARNING: Could not recover jumptable at 0x0001ba12. Too many branches
    // WARNING: Treating indirect jump as call
    (*(code *)(&DAT_0001ba16 +
               *(short *)(&DAT_0001ba16 + (short)(DAT_ffffdb0e * 2))))();
    return;
  }
  DAT_ffffdb10 = 0;
  DAT_ffffdb11 = 4;
  // WARNING: Could not recover jumptable at 0x0001ba6e. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0001ba72 +
             (int)*(short *)((int)&WORD_0001ba72 +
                             (int)(short)(DAT_ffffdb0e * 2))))();
  return;
}

word FUN_0001ba5a(void)

{
  byte extraout_D0b;
  ushort uVar1;
  void *vram_dst;
  short sVar2;

  DAT_ffffdb10 = 0;
  DAT_ffffdb11 = 4;
  // WARNING: Switch is manually overridden
  switch (DAT_ffffdb0e) {
  case 0:
    vram_dst = (void *)0xd21c;
    if (DAT_ffffdb0c != 0) {
      vram_dst = (void *)0xd222;
    }
    goto code_r0x0001babc;
  case 1:
    sVar2 = -0x2d64;
    if (DAT_ffffdb0c != 0) {
      sVar2 = -0x2d5a;
    }
    break;
  case 2:
    sVar2 = -0x2ce4;
  }
  FUN_0001babc();
  vram_dst = (void *)(sVar2 + 4);
code_r0x0001babc:
  vdp_set_vram_write_addr(vram_dst);
  FUN_0001bac8();
  uVar1 = extraout_D0b & 0xf;
  if (9 < (byte)uVar1) {
    uVar1 = uVar1 + 7;
  }
  VDP_DATA = uVar1 + 0x87b0;
  return uVar1 + 0x87b0;
}

word FUN_0001babc(void)

{
  byte extraout_D0b;
  ushort uVar1;
  void *unaff_D2w;

  vdp_set_vram_write_addr(unaff_D2w);
  FUN_0001bac8();
  uVar1 = extraout_D0b & 0xf;
  if (9 < (byte)uVar1) {
    uVar1 = uVar1 + 7;
  }
  VDP_DATA = uVar1 + 0x87b0;
  return uVar1 + 0x87b0;
}

word FUN_0001bac8(void)

{
  ushort in_D0w;
  ushort uVar1;

  uVar1 = in_D0w & 0xf;
  if (9 < (byte)uVar1) {
    uVar1 = uVar1 + 7;
  }
  VDP_DATA = uVar1 + 0x87b0;
  return uVar1 + 0x87b0;
}

void FUN_0001baec(void)

{
  byte bVar1;
  byte *in_A0;
  byte *extraout_A0;
  word *vdp_data;
  word *extraout_A1;

  vdp_data = &VDP_DATA;
  while (true) {
    while (true) {
      bVar1 = *in_A0;
      if (-1 < (char)bVar1)
        break;
      vdp_set_vram_write_addr(
          (void *)(((ushort)in_A0[2] * 0x20 + (ushort)in_A0[1]) * 2 + -0x3000));
      in_A0 = extraout_A0;
      vdp_data = extraout_A1;
    }
    if (bVar1 == 0)
      break;
    *vdp_data = bVar1 + 0x8780;
    in_A0 = in_A0 + 1;
  }
  return;
}

void ecs_very_complex_jump(entity_id_t self)

{
  char cVar1;
  byte bVar2;

  if ((char)(&comp_unk_10)[self] < '\0') {
    return;
  }
  if (((&comp_has_func_maybe)[self] & 0x40) == 0) {
    (&comp_has_func_maybe)[self] = (&comp_has_func_maybe)[self] | 0x20;
    *(undefined2 *)((int)&comp_state + self) = 0;
    (&comp_unk_11)[self] = 0;
    bVar2 = ecs_unk_3(self, 2);
    (&comp_collected_item_id_maybe)[self] = bVar2;
  }
  if ((((&comp_unk_11)[self] != '\0') &&
       (((&comp_anim[0].unk4)[self] & 0x40) == 0)) &&
      (cVar1 = (&comp_unk_11)[self] + -1,
       (&comp_unk_11)[self] = cVar1,
       cVar1 == '\0')) {
    *(undefined2 *)(&comp_has_func_maybe + self) =
        *(undefined2 *)(&comp_has_func_maybe + self) & 0xf7fb;
  }
  // WARNING: Could not recover jumptable at 0x0001bb6a. Too many branches
  // WARNING: Treating indirect jump as call
  (**(code **)((int)&PTR_FUN_0001bb6c +
               (int)(short)((ushort)(&comp_func_offset[0].unk3)[self] * 2)))();
  return;
}

void FUN_0001bc5c(void)

{
  short sVar1;
  word wVar2;
  short unaff_D3w;
  word unaff_D6w;
  ushort unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  ushort *unaff_A6;

  ecs_jump_table(unaff_A4);
  *unaff_A6 = *unaff_A6 | 0x8ec;
  if ((byte)((byte)unaff_D7w | 0x66) == 0) {
    wVar2 = rand();
    *(word *)(&comp_unk_4 + unaff_A4) = (wVar2 & 0x1f) + 0x10;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00002256();
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w | 0x66);
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    }
  }
  return;
}

void FUN_0001bc6a(void)

{
  byte bVar1;
  short sVar2;
  word wVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    wVar3 = rand();
    *(word *)(&comp_unk_4 + unaff_A4) = (wVar3 & 0x1f) + 0x10;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00002256();
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    }
  }
  return;
}

void FUN_0001bcb6(void)

{
  byte bVar1;
  short sVar2;
  word wVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    wVar3 = rand();
    *(word *)(&comp_unk_4 + unaff_A4) = (wVar3 & 0x1f) + 0x10;
    FUN_000022a0();
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    }
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001bd06(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_0001bd18(void)

{
  byte bVar1;
  short sVar2;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_sprite_face_asha(unaff_A4);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x20;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00002256();
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001bd52(void)

{
  byte bVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00002256();
  FUN_00002272();
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    FUN_000023a0();
    // WARNING: Bad instruction - Truncating control flow here
    halt_baddata();
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001bd86(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

ushort FUN_0001bd98(void)

{
  short *psVar1;
  byte bVar2;
  ushort uVar3;
  short sVar4;
  short sVar5;
  int iVar6;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  (&DAT_ffffb976)[unaff_A4] = 0;
  FUN_00002678();
  sVar4 = 0x40;
  sVar5 = _DAT_ffffdb12;
  if ((DAT_ffffdb16 < 0x50) || (sVar5 = -_DAT_ffffdb12, 0x5f < DAT_ffffdb16)) {
    if (-1 < sVar5) {
      sVar4 = -0x40;
    }
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = sVar4 + *psVar1;
    FUN_00002590();
  } else {
    (&DAT_ffffb976)[unaff_A4] = (&DAT_ffffb976)[unaff_A4] + '\x02';
    FUN_00002256();
  }
  FUN_000026aa();
  FUN_000025d0();
  player_update_pos(unaff_A4);
  uVar3 = (*(short *)((int)&comp_pos_y + unaff_A4) -
           *(short *)(&DAT_ffffbc78 + unaff_A4)) +
          8;
  if (uVar3 < 0x10) {
    (&DAT_ffffb976)[unaff_A4] = (&DAT_ffffb976)[unaff_A4] + '\x01';
  }
  if (((&DAT_ffffb976)[unaff_A4] == '\x03') &&
      (uVar3 = CONCAT11((char)(uVar3 >> 8),
                        component_unknown_5 | component_collision_flags) &
               0xff04,
       ((component_unknown_5 | component_collision_flags) & 4) != 0)) {
    uVar3 = comp_collision_sensor[0].y + comp_pos_y.fixed.i;
    if (uVar3 == DAT_ffffce0a) {
      iVar6 = 0x34;
      uVar3 = 0x13;
      while ((-1 < (char)(&comp_has_func_maybe)[iVar6] ||
              ((&comp_func_offset[0].unk1)[iVar6] != 0x8e))) {
        iVar6 = iVar6 + 4;
        uVar3 = uVar3 - 1;
        if (uVar3 == 0xffff) {
          *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
          return 0xffff;
        }
      }
    } else {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    }
  }
  return uVar3;
}

void FUN_0001be64(void)

{
  char cVar1;
  ushort uVar2;
  short sVar3;
  byte bVar5;
  word wVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar5 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar5 | 0x80;
  if ((bVar5 & 0x80) == 0) {
    ecs_sprite_face_asha(unaff_A4);
    FUN_000025fe();
    if (0xf < *(ushort *)(&comp_unk_4 + unaff_A4)) {
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x10;
    }
    (&comp_collision_related)[unaff_A4] = 0;
    (&DAT_ffffb978)[unaff_A4] = 0;
    bVar5 = ecs_unk_3(unaff_A4, 2);
    if ((&comp_collected_item_id_maybe)[unaff_A4] <= bVar5 >> 1) {
      wVar4 = rand();
      if ((((wVar4 & 8) != 0) &&
           (uVar2 = *(short *)(&comp_unk_4 + unaff_A4) - 10,
            -1 < (short)uVar2)) &&
          (uVar2 < 0x100)) {
        (&comp_collision_related)[unaff_A4] = (char)uVar2;
      }
    }
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if ((&DAT_ffffb978)[unaff_A4] == '\0') {
    player_update_pos(unaff_A4);
    if (((&comp_collision_related)[unaff_A4] != '\0') &&
        (cVar1 = (&comp_collision_related)[unaff_A4] + -1,
         (&comp_collision_related)[unaff_A4] = cVar1,
         cVar1 == '\0')) {
      (&DAT_ffffb978)[unaff_A4] = 0x10;
    }
    sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
    if (sVar3 == 0) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    }
  } else {
    (&DAT_ffffb978)[unaff_A4] = (&DAT_ffffb978)[unaff_A4] + -1;
  }
  return;
}

void FUN_0001bef6(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x400;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_0000237a();
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + -0x10;
  player_update_pos(unaff_A4);
  sVar3 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
    sVar3 = -sVar3;
  }
  if (sVar3 < -0xf) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001bf4a(void)

{
  byte bVar1;
  char cVar2;
  short sVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 8;
    (&comp_collision_related)[unaff_A4] = 8;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if (*(short *)(&comp_unk_4 + unaff_A4) == 0) {
    cVar2 = (&comp_collision_related)[unaff_A4] + -1;
    (&comp_collision_related)[unaff_A4] = cVar2;
    if (cVar2 == '\0') {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    }
  } else {
    sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
    if (sVar3 == 0) {
      FUN_000023a0();
      // WARNING: Bad instruction - Truncating control flow here
      halt_baddata();
    }
  }
  return;
}

void FUN_0001bf90(void)

{
  byte bVar1;
  char cVar2;
  short sVar3;
  word wVar4;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  uint *self;
  anim_item_t *unaff_A5;
  bool bVar5;

  ecs_jump_table(unaff_A4);
  self = (uint *)(unaff_A4 - ENTITY_ID_PEPELOGOO);
  *self = *self | 0xf8;
  bVar1 = (&DAT_ffffb462)[unaff_A4];
  (&DAT_ffffb462)[unaff_A4] = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2((entity_id_t)self, unaff_A5, 6);
    *(undefined2 *)(&DAT_ffffa42a + unaff_A4) = 0;
    FUN_0001c000();
  }
  FUN_00002272();
  FUN_00002288((ulong)self, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00001fd2();
  FUN_000021e2((entity_id_t)self);
  cVar2 = (&DAT_ffffb76e)[unaff_A4] + -1;
  (&DAT_ffffb76e)[unaff_A4] = cVar2;
  bVar5 = cVar2 == '\0';
  if (!bVar5) {
    return;
  }
  FUN_00002248();
  if (!bVar5) {
    FUN_0001c016();
    if (bVar5) {
      return;
    }
    FUN_000159fc();
    if (-1 < (char)(&DAT_ffff9f16)[unaff_A4]) {
      return;
    }
    sVar3 = FUN_000022cc();
    if (-1 < (short)(sVar3 + 0x30)) {
      wVar4 = rand();
      if ((&DAT_0001c012)[(short)(wVar4 & 3)] != '\0') {
        (&DAT_ffffb462)[unaff_A4] = (&DAT_0001c012)[(short)(wVar4 & 3)];
        return;
      }
    }
  }
  wVar4 = rand();
  (&DAT_ffffb76e)[unaff_A4] = ((byte)wVar4 & 0x1f) + 8;
  ecs_sprite_face_asha((entity_id_t)self);
  return;
}

void FUN_0001bfa2(void)

{
  byte bVar1;
  char cVar2;
  short sVar3;
  word wVar4;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    FUN_0001c000();
  }
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  cVar2 = (&comp_unk_4)[unaff_A4] + -1;
  (&comp_unk_4)[unaff_A4] = cVar2;
  bVar5 = cVar2 == '\0';
  if (!bVar5) {
    return;
  }
  FUN_00002248();
  if (!bVar5) {
    FUN_0001c016();
    if (bVar5) {
      return;
    }
    FUN_000159fc();
    if (-1 < (char)(&comp_has_func_maybe)[unaff_A4]) {
      return;
    }
    sVar3 = FUN_000022cc();
    if (-1 < (short)(sVar3 + 0x30)) {
      wVar4 = rand();
      if ((&DAT_0001c012)[(short)(wVar4 & 3)] != '\0') {
        *(undefined *)((int)&comp_state + unaff_A4) =
            (&DAT_0001c012)[(short)(wVar4 & 3)];
        return;
      }
    }
  }
  wVar4 = rand();
  (&comp_unk_4)[unaff_A4] = ((byte)wVar4 & 0x1f) + 8;
  ecs_sprite_face_asha(unaff_A4);
  return;
}

void FUN_0001c000(void)

{
  word wVar1;
  entity_id_t unaff_A4;

  wVar1 = rand();
  (&comp_unk_4)[unaff_A4] = ((byte)wVar1 & 0x1f) + 8;
  ecs_sprite_face_asha(unaff_A4);
  return;
}

ushort FUN_0001c016(void)

{
  ushort uVar1;
  int unaff_A4;
  undefined1 in_ZF;

  uVar1 = FUN_000022cc();
  if ((bool)in_ZF) {
    uVar1 = *(short *)((int)&comp_pos_x + unaff_A4) - comp_pos_x._0_2_;
    if ((short)uVar1 < 0) {
      uVar1 = -uVar1;
    }
    if (uVar1 < 0x28) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
      uVar1 = 0;
    }
  }
  return uVar1;
}

void FUN_0001c038(void)

{
  byte bVar1;
  char cVar2;
  word wVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar4;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    FUN_000022a2();
    wVar3 = rand();
    (&comp_unk_4)[unaff_A4] = ((byte)wVar3 & 0x3f) + 8;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  uVar4 = ((&comp_unk_4)[unaff_A4] & 3) == 0;
  if (((bool)uVar4) && (FUN_0001c016(), (bool)uVar4)) {
    return;
  }
  FUN_00002248();
  if (((bool)uVar4) || (cVar2 = (&comp_unk_4)[unaff_A4] + -1,
                        (&comp_unk_4)[unaff_A4] = cVar2,
                        cVar2 == '\0')) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

uint FUN_0001c08c(void)

{
  byte bVar2;
  uint extraout_D0;
  uint uVar1;
  short sVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar4;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if (*(ushort *)(&comp_unk_4 + unaff_A4) == 0) {
    if ((&comp_anim[0].frame)[unaff_A4] < 4) {
      FUN_00002256();
      FUN_000186f4(unaff_A4, &UNK_0001c11c);
      if (((&comp_func_offset[0].unk4)[unaff_A4] & 0x10) != 0) {
        bVar2 = ecs_unk_3(unaff_A4, 3);
        uint8_t_ffffcc70 = (uint8_t_ffffcc70 | bVar2) & 0x7f;
        if ((ushort)comp_pos_x.fixed.i <
            *(ushort *)((int)&comp_pos_x + unaff_A4)) {
          uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x80;
        }
        return (uint)uint8_t_ffffcc70;
      }
      return extraout_D0;
    }
    sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + 1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
    bVar4 = sVar3 == 0;
    uVar1 = FUN_00002248();
    if (bVar4) {
      return uVar1;
    }
    uVar1 = FUN_000022a2();
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfe80;
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
    return uVar1;
  }
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    return (uint) * (ushort *)(&comp_unk_4 + unaff_A4);
  }
  bVar4 = *(ushort *)(&comp_unk_4 + unaff_A4) == 2;
  if (*(ushort *)(&comp_unk_4 + unaff_A4) < 2) {
    uVar1 = FUN_00002248();
    if (bVar4) {
      return uVar1;
    }
    *(short *)(&comp_unk_4 + unaff_A4) = *(short *)(&comp_unk_4 + unaff_A4) + 1;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfec0;
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
    return uVar1;
  }
  sVar3 = *(short *)((int)&comp_vel[0].x + unaff_A4);
  if (sVar3 == 0) {
    return 0x20;
  }
  if (sVar3 < 0) {
    sVar3 = sVar3 + 0x20;
    if (sVar3 < 0)
      goto LAB_0000226c;
  } else {
    sVar3 = sVar3 + -0x20;
    if (-1 < sVar3)
      goto LAB_0000226c;
  }
  sVar3 = 0;
LAB_0000226c:
  *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar3;
  return 0x20;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001c126(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_0001c138(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar4;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  bVar4 = (bVar2 & 0x80) == 0;
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if (bVar4) {
    FUN_00002248();
    if (!bVar4) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    }
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 8;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x50;
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
  if (sVar3 == 0) {
    FUN_000159fc();
    bVar4 = (&comp_has_func_maybe)[unaff_A4] == 0;
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      FUN_00002248();
      if (!bVar4) {
        FUN_00002678();
        FUN_000026aa();
        if ((DAT_ffffdb16 < 0xc0) && (DAT_ffffdb18 < 0x50)) {
          *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
          return;
        }
      }
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
    }
  }
  return;
}

void FUN_0001c1a8(void)

{
  short *psVar1;
  byte bVar2;
  undefined4 uVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x50;
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00002678();
  FUN_000026aa();
  uVar3 = FUN_000022a2();
  if ((((&component_unknown_5)[unaff_A4] |
        (&component_collision_flags)[unaff_A4]) &
       4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    return;
  }
  if ((CONCAT31((int3)((uint)uVar3 >> 8),
                (&component_unknown_5)[unaff_A4] |
                    (&component_collision_flags)[unaff_A4]) &
       1 << (uint)(((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0)) !=
      0) {
  LAB_0001c1fe:
    *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
    return;
  }
  if (DAT_ffffdb16 < 0x34) {
    if (0xf < DAT_ffffdb18)
      goto LAB_0001c1fe;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  }
  return;
}

uint FUN_0001c21e(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  uint uVar4;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    FUN_000022a2();
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar3 = *psVar1 + 0x50;
  *psVar1 = sVar3;
  uVar5 = sVar3 == 0;
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  uVar4 = FUN_00002248();
  if ((((bool)uVar5) ||
       (uVar4 = CONCAT31((int3)(uVar4 >> 8),
                         (&component_unknown_5)[unaff_A4] |
                             (&component_collision_flags)[unaff_A4]) &
                0xffffff03,
        (((&component_unknown_5)[unaff_A4] |
          (&component_collision_flags)[unaff_A4]) &
         3) != 0)) ||
      (sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1,
       *(short *)(&comp_unk_4 + unaff_A4) = sVar3,
       sVar3 == 0)) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return uVar4;
}

void FUN_0001c26e(void)

{
  short *psVar1;
  byte bVar2;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x50;
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_000186f4(unaff_A4, BYTE_ARRAY_0001c2c0);
  FUN_00002238();
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    FUN_00002678();
    if (DAT_ffffdb16 < 0x50) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
    }
  }
  return;
}

/*
Unable to decompile 'FUN_0001c2ca'
Cause: Exception while decompiling 0001c2ca: Decompiler process died

*/

// FIXME Where is this used?

void FUN_0001c2e0(void)

{
  return;
}

void FUN_0001c2e2(void)

{
  int iVar1;
  short sVar2;
  undefined1 uVar3;
  byte state_1_b;
  byte *pbVar4;
  undefined *puVar5;
  entity_id_t unaff_A4;
  int iVar6;
  anim_item_t *unaff_A5;

  (&comp_anim[0].unk4)[unaff_A4] = (&comp_anim[0].unk4)[unaff_A4] | 0x40;
  FUN_0001fd94();
  *(undefined2 *)((int)&comp_pos_x +
                  *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                             unaff_A4) +
                  2) = 0;
  puVar5 = &UNK_0001c37a;
  while (true) {
    (&comp_state_a)[unaff_A4] = 0x80;
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x18;
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x20;
    uVar3 = *puVar5;
    (&DAT_ffffb978)[unaff_A4] = uVar3;
    (&DAT_ffffb979)[unaff_A4] = uVar3;
    pbVar4 = puVar5 + 2;
    (&DAT_ffffb976)[unaff_A4] = puVar5[1];
    puVar5 = puVar5 + 3;
    state_1_b = *pbVar4;
    (&comp_func_offset[0].unk1)[unaff_A4] = (&comp_func_offset[0].unk1)[*(
        short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4)];
    FUN_000019ae();
    ecs_anim_unk_2(unaff_A4, unaff_A5, state_1_b);
    sVar2 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
    if (sVar2 < 0)
      break;
    unaff_A4 = (entity_id_t)sVar2;
  }
  iVar6 =
      (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4);
  *(undefined1 *)((int)&comp_state + iVar6) = 3;
  iVar1 = iVar6 + (short)((ushort)(byte)(&DAT_ffffb976)[iVar6] << 2);
  *(short *)((int)&comp_pos_y + iVar1) =
      DAT_ffffce0a - *(short *)((int)&comp_collision_sensor[0].y + iVar1);
  *(undefined2 *)((int)&comp_pos_x + iVar1) =
      *(undefined2 *)((int)&comp_pos_x + iVar6);
  FUN_0001c94c();
  (&DAT_ffffb976)[iVar6] = 3;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001c390(void)

{
  short sVar1;
  byte bVar2;
  ushort uVar3;
  short sVar4;
  char extraout_D1b;
  char cVar5;
  int16_t unaff_D6w;
  int16_t unaff_D7w;
  int iVar6;
  int extraout_A0;
  vdp_color_t *pvVar7;
  vdp_color_t *pvVar8;
  int unaff_A4;
  int iVar9;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    _DAT_ffffdb3e = 0xb4;
    audio_play_sound_asha_dies();
    while (true) {
      IO_Z80BUS = 0x100;
      do {
        bVar2 = IO_Z80BUS._0_1_;
      } while ((bVar2 & 1) != 0);
      if (z80_ram_something_1 == '\0')
        break;
      IO_Z80BUS = 0;
      sVar4 = 0x1f;
      do {
        sVar4 = sVar4 + -1;
      } while (sVar4 != -1);
    }
    (&z80_ram)[(
        short)(((byte)(z80_ram_something_3 + z80_ram_something_2) & 0xf) +
               0x1c30)] = 0x4c;
    z80_ram_something_3 = z80_ram_something_3 + '\x01';
    IO_Z80BUS = 0;
    return;
  }
  if (_DAT_ffffdb3e != 0) {
    _DAT_ffffdb3e = _DAT_ffffdb3e + -1;
    if (_DAT_ffffdb3e == 0) {
      (&comp_collision_related)[unaff_A4] = 1;
      *(short *)(&comp_unk_4 + unaff_A4) = (short)unaff_A4;
      FUN_0001fd5e();
      cVar5 = extraout_D1b;
    } else {
      for (uVar3 = (0xb4 - _DAT_ffffdb3e) * 2; 0x53 < uVar3;
           uVar3 = uVar3 - 0x54) {
      }
      sVar4 = 0xf;
      pvVar7 = palettes_2;
      do {
        *pvVar7 = *(vdp_color_t *)(&UNK_0001fdd8 + (short)uVar3);
        uVar3 = uVar3 + 2;
        if (0x53 < uVar3) {
          uVar3 = 0;
        }
        sVar4 = sVar4 + -1;
        pvVar7 = pvVar7 + 1;
      } while (sVar4 != -1);
      cVar5 = -1;
    }
    sVar4 = 7;
    pvVar7 = palettes_2;
    pvVar8 = palettes[1];
    do {
      *(undefined4 *)pvVar8 = *(undefined4 *)pvVar7;
      sVar4 = sVar4 + -1;
      pvVar7 = pvVar7 + 2;
      pvVar8 = pvVar8 + 2;
    } while (sVar4 != -1);
    palette_set_fade(PALETTE_ID_FLAG_1,
                     PALETTE_FADE_1,
                     cVar5,
                     (palette_color_iter_t)0xffffffff);
    return;
  }
  cVar5 = (&comp_collision_related)[unaff_A4] + -1;
  (&comp_collision_related)[unaff_A4] = cVar5;
  if (cVar5 == '\0') {
    (&comp_collision_related)[unaff_A4] = 8;
    sVar4 = *(short *)(&comp_unk_4 + unaff_A4);
    iVar9 = (int)sVar4;
    FUN_00025398();
    if (iVar9 ==
        *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + iVar9)) {
      ecs_collect_or_spawn_item_maybe(unaff_D6w, unaff_D7w, 0x31);
      (&comp_has_func_maybe)[iVar9] = (&comp_has_func_maybe)[iVar9] | 8;
      iVar6 = (int)sVar4;
    } else {
      FUN_00024d78();
      iVar6 = extraout_A0;
    }
    sVar4 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + iVar9);
    sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar6);
    *(short *)(&comp_unk_4 + sVar4) = sVar1;
    if (sVar1 < 0) {
      FUN_00015e86();
      (&comp_has_func_maybe)[sVar4] = 0;
    }
  }
  return;
}

byte FUN_0001c41a(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  int iVar4;
  int unaff_A4;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    (&comp_unk_11)[unaff_A4] = 0x1e;
  }
  FUN_0001fe84();
  if ((&comp_unk_11)[unaff_A4] == '\0') {
    *(undefined1 *)((int)&comp_state + unaff_A4) =
        *(undefined1 *)(unaff_A4 + -0x4788);
  }
  FUN_0001c802();
  FUN_0001c850();
  FUN_0001c94c();
  FUN_0001c8a0();
  iVar4 =
      (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  if (((&component_collision_flags)[unaff_A4] & 3) == 0) {
    psVar1 = (short *)((int)&comp_pos_x + iVar4 + 2);
    if (*psVar1 == 0)
      goto LAB_0001c842;
    if (*psVar1 < 0) {
      psVar1 = (short *)((int)&comp_pos_x + iVar4 + 2);
      sVar3 = *psVar1 + 0x40;
      *psVar1 = sVar3;
      if (sVar3 < 0)
        goto LAB_0001c842;
    } else {
      psVar1 = (short *)((int)&comp_pos_x + iVar4 + 2);
      sVar3 = *psVar1 + -0x40;
      *psVar1 = sVar3;
      if (-1 < sVar3)
        goto LAB_0001c842;
    }
  }
  *(undefined2 *)((int)&comp_pos_x + iVar4 + 2) = 0;
LAB_0001c842:
  bVar2 = (&component_collision_flags)[unaff_A4];
  if ((bVar2 & 0xc) != 0) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  return bVar2 & 0xc;
}

void FUN_0001c44e(void)

{
  byte bVar1;
  byte bVar2;
  word wVar3;
  byte bVar4;
  ushort uVar5;
  undefined1 uVar6;
  int unaff_A4;

  uVar5 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
    uVar5 = -uVar5;
  }
  if ((short)uVar5 < 0) {
    uVar6 = 7;
  } else {
    uVar6 = 4;
    if (uVar5 < 0x28) {
      uVar6 = 8;
      wVar3 = rand();
      if ((wVar3 & 1) != 0) {
        uVar6 = 6;
      }
    }
  }
  *(undefined1 *)((int)&comp_state + unaff_A4) = uVar6;
  FUN_0001c746();
  if (((&comp_func_offset[0].unk4)[unaff_A4] & 1) != 0) {
    audio_play(SOUND_ID_DAMAGE_2);
    bVar4 = DAT_ffffde0e;
    if (((&comp_func_offset[0].unk4)[unaff_A4] & 4) != 0) {
      bVar4 = DAT_ffffde0f;
    }
    bVar1 = (&comp_collected_item_id_maybe)[unaff_A4];
    bVar2 = bVar1 - bVar4;
    (&comp_collected_item_id_maybe)[unaff_A4] = bVar2;
    if (bVar1 < bVar4 || bVar2 == 0) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
    } else {
      *(undefined1 *)(unaff_A4 + -0x4788) =
          *(undefined1 *)((int)&comp_state + unaff_A4);
      *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    }
  }
  return;
}

void FUN_0001c48a(void)

{
  byte bVar1;
  byte bVar2;
  short sVar3;
  byte bVar4;
  short extraout_D1w;
  undefined1 uVar5;
  undefined *puVar6;
  int iVar7;
  int unaff_A4;

  bVar4 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar4 | 0x80;
  if ((bVar4 & 0x80) == 0) {
    sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
    puVar6 = &UNK_0001c590;
    do {
      iVar7 = (int)sVar3;
      *(undefined *)(iVar7 + -0x4788) = *puVar6;
      *(undefined2 *)(&comp_unk_4 + iVar7) = 0;
      sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar7);
      puVar6 = puVar6 + 1;
    } while (-1 < sVar3);
    (&DAT_ffffb978)[unaff_A4] = 0;
    (&comp_collision_related)[unaff_A4] = 0;
  }
  if ((&comp_collision_related)[unaff_A4] == '\0') {
    FUN_0001ca38();
    if (extraout_D1w == 0) {
      uVar5 = 2;
      if (*(char *)((int)&comp_state + unaff_A4) != -0x7c) {
        uVar5 = 5;
      }
      (&DAT_ffffb976)[unaff_A4] = uVar5;
      FUN_000022a2();
      (&comp_collision_related)[unaff_A4] = 0xff;
      *(undefined2 *)(&DAT_ffffb77e + unaff_A4) = 0;
      *(undefined2 *)(&DAT_ffffb782 + unaff_A4) = 3;
      *(undefined2 *)(unaff_A4 + -0x487a) = 6;
    }
  } else {
    FUN_0001c508();
    FUN_0001c508();
    FUN_0001c508();
  }
  FUN_0001c746();
  if (((&comp_func_offset[0].unk4)[unaff_A4] & 1) != 0) {
    audio_play(SOUND_ID_DAMAGE_2);
    bVar4 = DAT_ffffde0e;
    if (((&comp_func_offset[0].unk4)[unaff_A4] & 4) != 0) {
      bVar4 = DAT_ffffde0f;
    }
    bVar1 = (&comp_collected_item_id_maybe)[unaff_A4];
    bVar2 = bVar1 - bVar4;
    (&comp_collected_item_id_maybe)[unaff_A4] = bVar2;
    if (bVar1 < bVar4 || bVar2 == 0) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
    } else {
      *(undefined1 *)(unaff_A4 + -0x4788) =
          *(undefined1 *)((int)&comp_state + unaff_A4);
      *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    }
  }
  return;
}

char FUN_0001c508(void)

{
  char cVar1;
  char cVar2;
  int unaff_A3;
  int unaff_A4;

  cVar1 = (&comp_unk_4)[unaff_A3];
  if (cVar1 == '\0') {
    if ((&DAT_ffffb773)[unaff_A3] != '\0') {
      (&DAT_ffffb773)[unaff_A3] = (&DAT_ffffb773)[unaff_A3] + -1;
      return cVar1;
    }
    *(undefined2 *)(&comp_unk_4 + unaff_A3) = 0x104;
  }
  if (cVar1 == '\x01') {
    (&DAT_ffffb978)[unaff_A3] = (&DAT_ffffb978)[unaff_A3] + -1;
    cVar1 = (&DAT_ffffb773)[unaff_A3] + -1;
    (&DAT_ffffb773)[unaff_A3] = cVar1;
    cVar2 = '\0';
    if (cVar1 != '\0') {
      return '\0';
    }
    if (*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                   (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                                   unaff_A3)) < 0) {
      cVar2 = '\x05';
      if (*(char *)((int)&comp_state + unaff_A4) != -0x7c) {
        cVar2 = '\x02';
      }
      (&DAT_ffffb976)[unaff_A4] = cVar2;
    }
  } else {
    if ((char)(cVar1 + -2) == '\0') {
      cVar2 = (&DAT_ffffb773)[unaff_A3] + -1;
      (&DAT_ffffb773)[unaff_A3] = cVar2;
      if (cVar2 != '\0') {
        return '\0';
      }
      *(short *)(&comp_unk_4 + unaff_A3) =
          *(short *)(&comp_unk_4 + unaff_A3) + 0x104;
      return cVar1 + -2;
    }
    cVar1 = cVar1 + -3;
    if (cVar1 != '\0') {
      return cVar1;
    }
    (&DAT_ffffb978)[unaff_A3] = (&DAT_ffffb978)[unaff_A3] + '\x01';
    cVar2 = (&DAT_ffffb773)[unaff_A3] + -1;
    (&DAT_ffffb773)[unaff_A3] = cVar2;
    if (cVar2 != '\0') {
      return '\0';
    }
    (&comp_unk_4)[unaff_A3] = (&comp_unk_4)[unaff_A3] + '\x01';
    cVar2 = '\0';
    if (*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                   (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                                   unaff_A3)) < 0) {
      (&DAT_ffffb976)[unaff_A4] = 3;
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
      return cVar1;
    }
  }
  *(short *)(&comp_unk_4 + unaff_A3) =
      *(short *)(&comp_unk_4 + unaff_A3) + 0x108;
  return cVar2;
}

void FUN_0001c596(void)

{
  byte bVar1;
  byte bVar2;
  short sVar3;
  byte bVar4;
  short extraout_D1w;
  undefined *puVar5;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar6;

  bVar4 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar4 | 0x80;
  if ((bVar4 & 0x80) == 0) {
    (&DAT_ffffb976)[unaff_A4] = 5;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
    (&DAT_ffffb978)[unaff_A4] = 1;
    (&comp_collision_related)[unaff_A4] = 0;
    FUN_0001c636();
  }
  bVar6 = (&comp_collision_related)[unaff_A4] == '\0';
  if (bVar6) {
    FUN_0001c652();
    if (bVar6) {
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      (&DAT_ffffb978)[unaff_A4] = 2;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
      FUN_0001c636();
    }
  } else {
    bVar6 = (&comp_collision_related)[unaff_A4] == '\x01';
    if (bVar6) {
      FUN_0001c652();
      if (bVar6) {
        (&comp_collision_related)[unaff_A4] =
            (&comp_collision_related)[unaff_A4] + '\x01';
        (&DAT_ffffb978)[unaff_A4] = 0;
        ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
        sVar3 =
            *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
        puVar5 = &UNK_0001c590;
        do {
          *(undefined *)(unaff_A4 - 0x4788) = *puVar5;
          sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                             (int)sVar3);
          puVar5 = puVar5 + 1;
        } while (-1 < sVar3);
      } else {
        FUN_000186f4(unaff_A4, &UNK_0001c6a6);
        FUN_00002238();
      }
    } else {
      FUN_0001ca38();
      if (extraout_D1w == 0) {
        (&DAT_ffffb976)[unaff_A4] = 3;
        *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
      }
    }
  }
  FUN_0001c746();
  if (((&comp_func_offset[0].unk4)[unaff_A4] & 1) != 0) {
    audio_play(SOUND_ID_DAMAGE_2);
    bVar4 = DAT_ffffde0e;
    if (((&comp_func_offset[0].unk4)[unaff_A4] & 4) != 0) {
      bVar4 = DAT_ffffde0f;
    }
    bVar1 = (&comp_collected_item_id_maybe)[unaff_A4];
    bVar2 = bVar1 - bVar4;
    (&comp_collected_item_id_maybe)[unaff_A4] = bVar2;
    if (bVar1 < bVar4 || bVar2 == 0) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
    } else {
      *(undefined1 *)(unaff_A4 - 0x4788) =
          *(undefined1 *)((int)&comp_state + unaff_A4);
      *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    }
  }
  return;
}

void FUN_0001c636(void)

{
  short sVar1;
  undefined1 *in_A0;
  undefined1 *puVar2;
  int iVar3;
  int unaff_A4;

  sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  do {
    iVar3 = (int)sVar1;
    *(undefined *)(iVar3 + -0x4788) = (&DAT_ffffb976)[iVar3];
    puVar2 = in_A0 + 1;
    *(undefined1 *)(iVar3 + -0x4787) = *in_A0;
    in_A0 = in_A0 + 2;
    (&comp_collision_related)[iVar3] = *puVar2;
    sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar3);
  } while (-1 < sVar1);
  return;
}

short FUN_0001c652(void)

{
  char cVar1;
  short sVar2;
  short extraout_D1w;
  int iVar3;
  int unaff_A4;

  sVar2 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  do {
    iVar3 = (int)sVar2;
    if (((&comp_collision_related)[iVar3] != '\0') &&
        (cVar1 = (&comp_collision_related)[iVar3] + -1,
         (&comp_collision_related)[iVar3] = cVar1,
         cVar1 == '\0')) {
      *(undefined1 *)(iVar3 + -0x4788) = *(undefined1 *)(iVar3 + -0x4787);
    }
    sVar2 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar3);
  } while (-1 < sVar2);
  sVar2 = FUN_0001ca38();
  if (extraout_D1w == 0) {
    sVar2 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
    do {
      if ((&comp_collision_related)[sVar2] != '\0') {
        return sVar2;
      }
      sVar2 =
          *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + (int)sVar2);
    } while (-1 < sVar2);
    sVar2 = 0;
  }
  return sVar2;
}

void FUN_0001c6ac(void)

{
  char cVar1;
  byte bVar2;
  byte bVar3;
  short sVar4;
  byte bVar5;
  byte *pbVar6;
  int iVar7;
  int unaff_A4;

  bVar5 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar5 | 0x80;
  if ((bVar5 & 0x80) == 0) {
    sVar4 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
    pbVar6 = &UNK_0001c740;
    do {
      iVar7 = (int)sVar4;
      *(ushort *)(&comp_unk_4 + iVar7) = (ushort)*pbVar6;
      (&comp_collision_related)[iVar7] = (&DAT_ffffb978)[iVar7];
      sVar4 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar7);
      pbVar6 = pbVar6 + 1;
    } while (-1 < sVar4);
  }
  sVar4 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  do {
    iVar7 = (int)sVar4;
    if ((&DAT_ffffb773)[iVar7] == '\0') {
      if ((&comp_unk_4)[iVar7] == '\0') {
        if ((&DAT_ffffb978)[iVar7] == '\0') {
          (&comp_state_a)[iVar7] = (&comp_state_a)[iVar7] ^ ENTITY_STATE_A_08;
          if (iVar7 == *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                                  unaff_A4)) {
            (&comp_state_a)[unaff_A4] =
                (&comp_state_a)[unaff_A4] ^ ENTITY_STATE_A_08;
          }
          (&comp_unk_4)[iVar7] = (&comp_unk_4)[iVar7] + '\x01';
        } else {
          (&DAT_ffffb978)[iVar7] = (&DAT_ffffb978)[iVar7] + -1;
        }
      } else if ((((&comp_unk_4)[iVar7] == '\x01') &&
                  (cVar1 = (&DAT_ffffb978)[iVar7],
                   (&DAT_ffffb978)[iVar7] = cVar1 + '\x01',
                   (char)(cVar1 + '\x01') ==
                       (&comp_collision_related)[iVar7])) &&
                 ((&comp_unk_4)[iVar7] = (&comp_unk_4)[iVar7] + '\x01',
                  *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                             iVar7) < 0)) {
        *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
      }
    } else {
      (&DAT_ffffb773)[iVar7] = (&DAT_ffffb773)[iVar7] + -1;
    }
    sVar4 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar7);
  } while (-1 < sVar4);
  FUN_0001c746();
  if (((&comp_func_offset[0].unk4)[unaff_A4] & 1) != 0) {
    audio_play(SOUND_ID_DAMAGE_2);
    bVar5 = DAT_ffffde0e;
    if (((&comp_func_offset[0].unk4)[unaff_A4] & 4) != 0) {
      bVar5 = DAT_ffffde0f;
    }
    bVar2 = (&comp_collected_item_id_maybe)[unaff_A4];
    bVar3 = bVar2 - bVar5;
    (&comp_collected_item_id_maybe)[unaff_A4] = bVar3;
    if (bVar2 < bVar5 || bVar3 == 0) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
    } else {
      *(undefined1 *)(unaff_A4 + -0x4788) =
          *(undefined1 *)((int)&comp_state + unaff_A4);
      *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
    }
  }
  return;
}

void FUN_0001c746(void)

{
  undefined2 uVar1;
  short unaff_A4w;
  entity_id_t self;
  int iVar2;
  bool bVar3;
  undefined1 uVar4;

  FUN_0001c802();
  FUN_0001c850();
  FUN_0001c94c();
  FUN_0001c8a0();
  FUN_0001ca78();
  FUN_0001c818();
  while (true) {
    uVar4 = 0;
    self = (entity_id_t)unaff_A4w;
    FUN_000189d0();
    bVar3 = ((&comp_func_offset[0].unk4)[self] & 1) == 0;
    if (!bVar3) {
      iVar2 =
          (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + self);
      uVar1 = 0x400;
      if (*(ushort *)((int)&comp_pos_x + iVar2 +
                      (short)((ushort)(byte)(&DAT_ffffb976)[iVar2] << 2)) <
          (ushort)comp_pos_x.fixed.i) {
        uVar1 = 0xfc00;
      }
      *(undefined2 *)((int)&comp_pos_x +
                      *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                                 iVar2) +
                      2) = uVar1;
      return;
    }
    FUN_00000ed6(self, ENTITY_ID_ASHA);
    if ((bool)uVar4 || bVar3)
      break;
    unaff_A4w = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + self);
    if (unaff_A4w < 0) {
      (&comp_func_offset[0].unk4)[*(
          short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + self)] =
          (&comp_func_offset[0].unk4)[*(
              short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + self)] &
          0xfd;
      return;
    }
  }
  FUN_00002124(self, 1);
  (&comp_func_offset[0]
        .unk4)[*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + self)] =
      (&comp_func_offset[0].unk4)[*(
          short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + self)] |
      2;
  return;
}

void FUN_0001c802(void)

{
  short *psVar1;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x40;
  if (0x800 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x800;
  }
  return;
}

byte FUN_0001c818(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  int iVar4;
  int unaff_A4;

  iVar4 =
      (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  if (((&component_collision_flags)[unaff_A4] & 3) == 0) {
    psVar1 = (short *)((int)&comp_pos_x + iVar4 + 2);
    if (*psVar1 == 0)
      goto LAB_0001c842;
    if (*psVar1 < 0) {
      psVar1 = (short *)((int)&comp_pos_x + iVar4 + 2);
      sVar3 = *psVar1 + 0x40;
      *psVar1 = sVar3;
      if (sVar3 < 0)
        goto LAB_0001c842;
    } else {
      psVar1 = (short *)((int)&comp_pos_x + iVar4 + 2);
      sVar3 = *psVar1 + -0x40;
      *psVar1 = sVar3;
      if (-1 < sVar3)
        goto LAB_0001c842;
    }
  }
  *(undefined2 *)((int)&comp_pos_x + iVar4 + 2) = 0;
LAB_0001c842:
  bVar2 = (&component_collision_flags)[unaff_A4];
  if ((bVar2 & 0xc) != 0) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  return bVar2 & 0xc;
}

void FUN_0001c850(void)

{
  int iVar1;
  short sVar2;
  byte *pbVar3;
  byte bVar4;
  char cVar5;
  byte bVar6;
  short sVar7;
  int unaff_A4;

  iVar1 = unaff_A4 + (short)((ushort)(byte)(&DAT_ffffb976)[unaff_A4] << 2);
  sVar7 = *(short *)((int)&comp_pos_x +
                     *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                                unaff_A4) +
                     2);
  if ((*(byte *)((int)&comp_state + unaff_A4) & 0x7f) != 2) {
    sVar7 = *(short *)((int)&comp_vel[0].x + unaff_A4) + sVar7;
  }
  sVar2 = *(short *)((int)&comp_pos_x + iVar1);
  pbVar3 = (byte *)((int)&comp_pos_x + unaff_A4 + 2);
  bVar4 = *pbVar3;
  *pbVar3 = (byte)sVar7 + bVar4;
  *(ushort *)((int)&comp_pos_x + iVar1) =
      (sVar7 >> 8) + sVar2 + (ushort)CARRY1((byte)sVar7, bVar4);
  bVar4 = *(byte *)((int)&comp_vel[0].y + unaff_A4 + 1);
  cVar5 = *(char *)((int)&comp_vel[0].y + unaff_A4);
  sVar7 = *(short *)((int)&comp_pos_y + iVar1);
  pbVar3 = (byte *)((int)&comp_pos_y + unaff_A4 + 2);
  bVar6 = *pbVar3;
  *pbVar3 = bVar4 + bVar6;
  *(ushort *)((int)&comp_pos_y + iVar1) =
      cVar5 + sVar7 + (ushort)CARRY1(bVar4, bVar6);
  return;
}

void FUN_0001c8a0(void)

{
  short *psVar1;
  short sVar2;
  ushort uVar3;
  ushort uVar4;
  short sVar5;
  short sVar6;
  ushort uVar7;
  ushort uVar8;
  ushort uVar9;
  int iVar10;
  int unaff_A4;

  sVar6 = (short)unaff_A4;
  iVar10 = (int)sVar6;
  sVar2 = *(short *)((int)&comp_collision_sensor[0].x + unaff_A4);
  uVar7 = *(short *)((int)&comp_pos_x + unaff_A4) - sVar2;
  uVar8 = sVar2 + *(short *)((int)&comp_pos_x + unaff_A4);
  uVar9 = *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
          *(short *)((int)&comp_pos_y + unaff_A4);
  while (sVar2 =
             *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar10),
         -1 < sVar2) {
    iVar10 = (int)sVar2;
    sVar2 = *(short *)((int)&comp_collision_sensor[0].x + iVar10);
    uVar4 = *(short *)((int)&comp_pos_x + iVar10) - sVar2;
    uVar3 = sVar2 + *(short *)((int)&comp_pos_x + iVar10);
    if (uVar4 < uVar7) {
      uVar7 = uVar4;
    }
    if (uVar8 < uVar3) {
      uVar8 = uVar3;
    }
    uVar3 = *(short *)((int)&comp_collision_sensor[0].y + iVar10) +
            *(short *)((int)&comp_pos_y + iVar10);
    if (uVar9 < uVar3) {
      uVar9 = uVar3;
    }
  }
  (&component_collision_flags)[unaff_A4] =
      (&component_collision_flags)[unaff_A4] & 0xf0;
  sVar2 = uVar7 - DAT_ffffce04;
  if ((uVar7 < DAT_ffffce04 || sVar2 == 0) &&
      ((&component_collision_flags)[unaff_A4] =
           (&component_collision_flags)[unaff_A4] | 2,
       sVar5 = sVar6,
       sVar2 != 0)) {
    do {
      psVar1 = (short *)((int)&comp_pos_x + (int)sVar5);
      *psVar1 = *psVar1 - sVar2;
      sVar5 =
          *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + (int)sVar5);
    } while (-1 < sVar5);
  }
  sVar2 = uVar8 - DAT_ffffce08;
  if ((DAT_ffffce08 <= uVar8) &&
      ((&component_collision_flags)[unaff_A4] =
           (&component_collision_flags)[unaff_A4] | 1,
       sVar5 = sVar6,
       sVar2 != 0)) {
    do {
      psVar1 = (short *)((int)&comp_pos_x + (int)sVar5);
      *psVar1 = *psVar1 - sVar2;
      sVar5 =
          *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + (int)sVar5);
    } while (-1 < sVar5);
  }
  sVar2 = uVar9 - DAT_ffffce0a;
  if ((DAT_ffffce0a <= uVar9) &&
      ((&component_collision_flags)[unaff_A4] =
           (&component_collision_flags)[unaff_A4] | 4,
       sVar2 != 0)) {
    do {
      psVar1 = (short *)((int)&comp_pos_y + (int)sVar6);
      *psVar1 = *psVar1 - sVar2;
      sVar6 =
          *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + (int)sVar6);
    } while (-1 < sVar6);
  }
  return;
}

void FUN_0001c94c(void)

{
  short extraout_D1w;
  short extraout_D1w_00;
  short sVar1;
  short unaff_D2w;
  int extraout_A1;
  int extraout_A1_00;
  int iVar2;
  int iVar3;
  short sVar4;
  int unaff_A4;

  iVar3 = unaff_A4 + (short)((ushort)(byte)(&DAT_ffffb976)[unaff_A4] << 2);
  sVar1 = (short)iVar3;
  while (iVar2 = (int)sVar1,
         -1 < *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar2)) {
    FUN_0001c9b6();
    *(short *)((int)&comp_pos_x + extraout_A1) =
        *(short *)((int)&comp_pos_x + iVar2) + extraout_D1w;
    unaff_D2w = *(short *)((int)&comp_pos_y + iVar2) + unaff_D2w;
    *(short *)((int)&comp_pos_y + extraout_A1) = unaff_D2w;
    sVar1 = (short)extraout_A1;
  }
  do {
    FUN_0001c9b6();
    sVar4 = (short)(iVar3 + -4);
    sVar1 = extraout_D1w_00;
    if (unaff_A4 == sVar4) {
      sVar1 = 8;
      if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
        sVar1 = -8;
      }
      sVar1 = sVar1 + extraout_D1w_00;
      unaff_D2w = unaff_D2w + -0x10;
    }
    *(short *)(iVar3 + -0x5ee2) =
        *(short *)((int)&comp_pos_x + extraout_A1_00) + sVar1;
    unaff_D2w = *(short *)((int)&comp_pos_y + extraout_A1_00) + unaff_D2w;
    *(short *)(iVar3 + -0x5dde) = unaff_D2w;
    iVar3 = iVar3 + -4;
  } while (unaff_A4 != sVar4);
  return;
}

void FUN_0001c9b6(void)

{
  int extraout_A1;

  FUN_0001c9d6();
  FUN_0001c9d6();
  if (((&comp_state_a)[extraout_A1] & ENTITY_STATE_A_08) != 0) {
    return;
  }
  return;
}

void FUN_0001c9d6(void)

{
  return;
}

void FUN_0001ca38(void)

{
  byte bVar1;
  char cVar2;
  short sVar3;
  byte bVar4;
  char cVar5;
  int iVar6;
  int unaff_A4;

  sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  bVar1 = (&DAT_ffffb978)[unaff_A4];
  do {
    iVar6 = (int)sVar3;
    cVar2 = *(char *)(iVar6 + -0x4788);
    cVar5 = (&DAT_ffffb976)[iVar6];
    if (cVar2 != cVar5) {
      bVar4 = ((char)(cVar2 - cVar5) < '\0') * -2 + '\x01' << (bVar1 & 0x3f);
      cVar5 = bVar4 + cVar5;
      if (((byte)(cVar2 - cVar5) != 0) &&
          ((char)(bVar4 ^ cVar2 - cVar5) < '\0')) {
        cVar5 = *(char *)(iVar6 + -0x4788);
      }
      (&DAT_ffffb976)[iVar6] = cVar5;
    }
    sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar6);
  } while (-1 < sVar3);
  return;
}

void FUN_0001ca78(void)

{
  short sVar1;
  int unaff_A4;
  int iVar2;
  short sVar3;

  iVar2 = (short)((ushort)(byte)(&DAT_ffffb976)[unaff_A4] << 2) + unaff_A4;
  sVar3 = (short)iVar2;
  FUN_0001cac4();
  while (
      (sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar2),
       -1 < sVar1 &&
           (iVar2 = (int)sVar1,
            -1 < *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                            iVar2)))) {
    FUN_0001cabe();
  }
  sVar1 =
      *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                 (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                                 iVar2));
  do {
    sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + (int)sVar1);
    FUN_0001cabe();
  } while (sVar1 != sVar3);
  return;
}

void FUN_0001cabe(void)

{
  byte bVar1;
  entity_state_1_b_t eVar2;
  int unaff_A3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = (&DAT_ffffb976)[unaff_A3];
  if (bVar1 == 0) {
    eVar2 = ECS_STATE_1_B_ATTACKING_MID_AIR;
    bVar1 =
        *(byte *)((int)&comp_state +
                  (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                                  unaff_A4)) &
        0x7f;
    if ((bVar1 == 4) || (bVar1 == 8))
      goto LAB_0001caf6;
  } else if (((char)bVar1 < '\0') && (bVar1 < 0xf0)) {
    if (bVar1 < 0xd0) {
      eVar2 = ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
    } else {
      eVar2 = ECS_STATE_1_B_JUMPING_OR_UNSHIELDING;
    }
    goto LAB_0001caf6;
  }
  eVar2 = ECS_STATE_1_B_FALLING;
LAB_0001caf6:
  if (eVar2 == (&comp_anim_c)[unaff_A4]) {
    return;
  }
  if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
    BYTE_ffffc709 = 0;
  }
  if (unaff_A4 == ENTITY_ID_ASHA) {
    BYTE_ffffc70a = 0;
  }
  (&comp_state_1_a)[unaff_A4] = 0;
  (&comp_anim_c)[unaff_A4] = eVar2;
  ecs_anim_unk_1(unaff_A4, unaff_A5);
  (&comp_has_func_maybe)[unaff_A4] =
      (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
  return;
}

void FUN_0001cac4(void)

{
  byte bVar1;
  entity_state_1_b_t eVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  eVar2 = ECS_STATE_1_B_ATTACKING_MID_AIR;
  bVar1 = *(byte *)((int)&comp_state +
                    (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                                    unaff_A4)) &
          0x7f;
  if ((bVar1 != 4) && (bVar1 != 8)) {
    eVar2 = ECS_STATE_1_B_FALLING;
  }
  if (eVar2 != (&comp_anim_c)[unaff_A4]) {
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = eVar2;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001cb02(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

// WARNING: Possible PIC construction at 0x0001cb46: Changing call to branch

uint FUN_0001cb16(void)

{
  byte bVar1;
  uint extraout_D0;
  ushort uVar3;
  uint extraout_D0_00;
  short sVar4;
  word wVar5;
  entity_state_1_b_t eVar6;
  uint uVar2;
  ushort extraout_D1w;
  ushort extraout_D1w_00;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined4 uStack_4;

  if ((&comp_anim_c)[unaff_A4] != 0) {
    bVar1 = *(byte *)((int)&comp_state + unaff_A4);
    *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
    if ((bVar1 & 0x80) != 0) {
      uStack_4 = 0x1cb4c;
      FUN_00002256();
      uStack_4 = 0x1cb50;
      FUN_00002272();
      uStack_4 = 0x1cb54;
      FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
      uStack_4 = 0x1cb58;
      FUN_00001fd2();
      uStack_4 = 0x1cb5c;
      FUN_000021e2(unaff_A4);
      sVar4 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
      *(short *)(&comp_unk_4 + unaff_A4) = sVar4;
      uVar2 = extraout_D0_00;
      if (sVar4 == 0) {
        uStack_4 = 0x1cb68;
        uVar2 = FUN_000159fc();
        if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
          uStack_4 = 0x1cb72;
          sVar4 = FUN_000022cc();
          uVar2 = (uint)(ushort)(sVar4 + 0x30U);
          if ((short)(sVar4 + 0x30U) < 0)
            goto SUB_0001cb80;
          *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
        }
      }
      return uVar2;
    }
    uStack_4 = 0x1cb34;
    uVar3 = FUN_000022fa();
    if ((uVar3 < 0x60) && (extraout_D1w < 0x50)) {
      uStack_4 = 0x1cb46;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
      register0x0000003c = (BADSPACEBASE *)&uStack_4;
      uStack_4 = 0x1cb48;
    SUB_0001cb80:
      *(undefined4 *)((int)register0x0000003c + -4) = 0x1cb84;
      wVar5 = rand();
      uVar3 = (wVar5 & 0x1f) + 0x20;
      *(ushort *)(&comp_unk_4 + unaff_A4) = uVar3;
      return (uint)uVar3;
    }
  }
  *(undefined1 *)((int)&comp_state + unaff_A4) = 7;
  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    (&comp_collision_related)[unaff_A4] = 0;
    if ((&comp_anim_c)[unaff_A4] != 0) {
      eVar6 = 0x10;
      goto code_r0x00001106;
    }
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x01';
  }
  uStack_4 = 0x1cc5e;
  FUN_00002272();
  uStack_4 = 0x1cc62;
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  uStack_4 = 0x1cc66;
  FUN_00001fd2();
  uStack_4 = 0x1cc6a;
  FUN_000021e2(unaff_A4);
  bVar1 = (&comp_collision_related)[unaff_A4];
  uVar2 = (uint)bVar1;
  if (bVar1 == 0) {
    if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      eVar6 = 0;
    code_r0x00001106:
      if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
        BYTE_ffffc709 = 0;
      }
      if (unaff_A4 == ENTITY_ID_ASHA) {
        BYTE_ffffc70a = 0;
      }
      (&comp_state_1_a)[unaff_A4] = 0;
      (&comp_anim_c)[unaff_A4] = eVar6;
      uStack_4 = 0x1126;
      ecs_anim_unk_1(unaff_A4, unaff_A5);
      (&comp_has_func_maybe)[unaff_A4] =
          (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
      return extraout_D0;
    }
  } else {
    uVar2 = (uint)(byte)(bVar1 - 1);
    if ((byte)(bVar1 - 1) == 0) {
      uStack_4 = 0x1cc96;
      uVar2 = FUN_000022fa();
      if (((ushort)uVar2 < 0x40) && (extraout_D1w_00 < 0x30)) {
        (&comp_collision_related)[unaff_A4] =
            (&comp_collision_related)[unaff_A4] + '\x01';
        eVar6 = ECS_STATE_1_B_TALKING_OR_ENTERING_BACK_DOOR;
        goto code_r0x00001106;
      }
    } else if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    }
  }
  return uVar2;
}

void FUN_0001cb92(void)

{
  byte bVar1;
  short sVar2;
  word wVar3;
  undefined1 uVar4;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    wVar3 = rand();
    *(word *)(&comp_unk_4 + unaff_A4) = (wVar3 & 0x1f) + 0x10;
    FUN_000022a0();
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      wVar3 = rand();
      uVar4 = 4;
      if ((wVar3 & 1) != 0) {
        uVar4 = 6;
      }
      *(undefined1 *)((int)&comp_state + unaff_A4) = uVar4;
    }
  }
  return;
}

void FUN_0001cbec(void)

{
  byte bVar1;
  char cVar2;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    (&comp_unk_4)[unaff_A4] = 0x10;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00002256();
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if (((&comp_unk_4)[unaff_A4] != '\0') &&
      (cVar2 = (&comp_unk_4)[unaff_A4] + -1,
       (&comp_unk_4)[unaff_A4] = cVar2,
       cVar2 == '\0')) {
    FUN_000023a0();
  }
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

uint FUN_0001cc36(void)

{
  byte bVar1;
  uint extraout_D0;
  entity_state_1_b_t eVar3;
  uint uVar2;
  ushort extraout_D1w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    (&comp_collision_related)[unaff_A4] = 0;
    if ((&comp_anim_c)[unaff_A4] != 0) {
      eVar3 = 0x10;
      goto ecs_anim_unk_2;
    }
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x01';
  }
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  bVar1 = (&comp_collision_related)[unaff_A4];
  uVar2 = (uint)bVar1;
  if (bVar1 == 0) {
    if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      eVar3 = 0;
    ecs_anim_unk_2:
      if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
        BYTE_ffffc709 = 0;
      }
      if (unaff_A4 == ENTITY_ID_ASHA) {
        BYTE_ffffc70a = 0;
      }
      (&comp_state_1_a)[unaff_A4] = 0;
      (&comp_anim_c)[unaff_A4] = eVar3;
      ecs_anim_unk_1(unaff_A4, unaff_A5);
      (&comp_has_func_maybe)[unaff_A4] =
          (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
      return extraout_D0;
    }
  } else {
    uVar2 = (uint)(byte)(bVar1 - 1);
    if ((byte)(bVar1 - 1) == 0) {
      uVar2 = FUN_000022fa();
      if (((ushort)uVar2 < 0x40) && (extraout_D1w < 0x30)) {
        (&comp_collision_related)[unaff_A4] =
            (&comp_collision_related)[unaff_A4] + '\x01';
        eVar3 = ECS_STATE_1_B_TALKING_OR_ENTERING_BACK_DOOR;
        goto ecs_anim_unk_2;
      }
    } else if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    }
  }
  return uVar2;
}

void FUN_0001ccac(void)

{
  byte bVar1;
  byte bVar2;
  ushort uVar3;
  char cVar4;
  short sVar5;
  short sVar6;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if (*(char *)((int)&comp_state + unaff_A4) == '\0') {
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x18;
    ecs_clear_x_vel_round_up_pos(unaff_A4);
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0xff;
    bVar2 = (&comp_func_offset[0].unk1)[unaff_A4] - 0x1b;
    (&comp_unk_4)[unaff_A4] = bVar2;
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    if ((bVar2 & 1) != 0) {
      if (bVar2 >> 1 == 0) {
        (&comp_state_a)[unaff_A4] =
            (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
      } else {
        (&comp_state_a)[unaff_A4] =
            (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_H_FLIP;
      }
    }
    (&comp_collision_related)[unaff_A4] = 0;
  }
  bVar2 = (&comp_collision_related)[unaff_A4];
  uVar3 = (ushort)bVar2;
  if ((char)bVar2 < '\0') {
    if (10 < (bVar2 & 0x7f)) {
      uVar3 = 0;
      goto LAB_0001cd0e;
    }
    uVar3 = ~(ushort)(bVar2 & 0x7f) + 0xb;
  }
  if (10 < (byte)uVar3) {
    uVar3 = 10;
  }
LAB_0001cd0e:
  sVar5 = (short)(char)(&DAT_0001cd57)[(short)(uVar3 * 2)];
  cVar4 = (&DAT_0001cd56)[(short)(uVar3 * 2)];
  sVar6 = 0x10;
  bVar2 = (&comp_unk_4)[unaff_A4];
  if (bVar2 != 0) {
    if (bVar2 < 2) {
      sVar5 = -sVar5;
    } else {
      sVar6 = sVar5;
      if (bVar2 != 2) {
        sVar6 = -sVar5;
      }
      sVar5 = 0x10;
      cVar4 = cVar4 + '\x03';
    }
  }
  *(short *)((int)&comp_pos_x + unaff_A4) =
      *(short *)(&DAT_ffffbc76 + unaff_A4) + sVar5;
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)(&DAT_ffffbc78 + unaff_A4) + sVar6;
  ecs_anim_unk_2(unaff_A4, unaff_A5, cVar4 * '\x02');
  bVar2 = (&comp_collision_related)[unaff_A4];
  bVar1 = bVar2 + 1;
  (&comp_collision_related)[unaff_A4] = bVar1;
  FUN_000021c2(unaff_A4, bVar1 == 0, 0xfe < bVar2);
  FUN_000159fc();
  return;
}

void FUN_0001cd6c(entity_id_t self, entity_id_t other_a, entity_id_t other_b)

{
  uint *puVar1;
  uint uVar2;
  short sVar3;
  ushort uVar4;

  ecs_jump_table(self);
  puVar1 = (uint *)(self + 0x66 + (short)other_b * 4);
  uVar2 = *puVar1 | 0x8ec0007;
  *puVar1 = uVar2;
  if (uVar2 == 0) {
    (&comp_state_a)[self] = (&comp_state_a)[self] & ~ENTITY_STATE_A_08;
    uVar4 =
        *(short *)(&DAT_ffffbc76 + self) - *(short *)((int)&comp_pos_x + self);
    if ((short)uVar4 < 0) {
      (&comp_state_a)[self] = (&comp_state_a)[self] | ENTITY_STATE_A_08;
      uVar4 = -uVar4;
    }
    if (uVar4 < 0x60) {
      ecs_sprite_face_asha(self);
    }
    FUN_0000248e(self);
    ecs_anim_unk_2(self, (anim_item_t *)other_a, 6);
  }
  FUN_00002258();
  FUN_0001cdd2();
  entity_update_pos(self);
  FUN_00001fd2();
  FUN_000021e2(self);
  sVar3 = *(short *)(&comp_unk_4 + self) + -1;
  *(short *)(&comp_unk_4 + self) = sVar3;
  if (sVar3 == 0) {
    *(undefined1 *)((int)&comp_state + self) = 4;
  }
  return;
}

void FUN_0001cd7a(void)

{
  byte bVar1;
  short sVar2;
  ushort uVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    uVar3 = *(short *)(&DAT_ffffbc76 + unaff_A4) -
            *(short *)((int)&comp_pos_x + unaff_A4);
    if ((short)uVar3 < 0) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
      uVar3 = -uVar3;
    }
    if (uVar3 < 0x60) {
      ecs_sprite_face_asha(unaff_A4);
    }
    FUN_0000248e(unaff_A4);
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00002258();
  FUN_0001cdd2();
  entity_update_pos(unaff_A4);
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

short FUN_0001cdd2(void)

{
  ushort uVar1;
  short sVar2;
  short sVar3;
  short sVar4;
  int unaff_A4;

  sVar2 = 1;
  if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
    sVar2 = -1;
  }
  sVar4 = comp_pos_y.fixed.i + 3;
  if (0x7f < (ushort)((sVar4 - *(short *)(&DAT_ffffbc78 + unaff_A4)) + 0x40U)) {
    sVar4 = *(short *)(&DAT_ffffbc78 + unaff_A4);
  }
  sVar3 = *(short *)((int)&comp_vel[0].y + unaff_A4);
  uVar1 = *(ushort *)((int)&comp_pos_y + unaff_A4);
  if ((ushort)(sVar4 + sVar2) < uVar1) {
    sVar3 = sVar3 + -0x10;
    if (sVar3 < -0x100) {
      sVar3 = -0x100;
    }
  } else {
    sVar3 = sVar3 + 0x10;
    if (0x100 < sVar3) {
      sVar3 = 0x100;
    }
  }
  *(short *)((int)&comp_vel[0].y + unaff_A4) = sVar3;
  return (sVar4 + sVar2) - uVar1;
}

void FUN_0001ce24(void)

{
  byte bVar1;
  short sVar2;
  ushort uVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x3c;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  sVar2 = *(short *)((int)&comp_vel[0].x + unaff_A4);
  if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) == 0) {
    sVar2 = sVar2 + 0x10;
    if (0x140 < sVar2) {
      sVar2 = 0x140;
    }
  } else {
    sVar2 = sVar2 + -0x10;
    if (sVar2 < -0x140) {
      sVar2 = -0x140;
    }
  }
  *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar2;
  FUN_0001cdd2();
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  entity_update_pos(unaff_A4);
  if ((*(short *)(&comp_unk_4 + unaff_A4) == 0) ||
      (sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1,
       *(short *)(&comp_unk_4 + unaff_A4) = sVar2,
       sVar2 == 0)) {
    if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
      if ((ushort)(comp_pos_x.fixed.i - 0x40U) <
          *(ushort *)((int)&comp_pos_x + unaff_A4)) {
        return;
      }
    } else {
      uVar3 = comp_pos_x.fixed.i + 0x40U;
      if ((ushort)(*(short *)(&DAT_ffffbc76 + unaff_A4) + 0x60U) <=
          (ushort)(comp_pos_x.fixed.i + 0x40U)) {
        uVar3 = *(short *)(&DAT_ffffbc76 + unaff_A4) + 0x60U;
      }
      if (*(ushort *)((int)&comp_pos_x + unaff_A4) <= uVar3) {
        return;
      }
    }
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_0001cec4(void)

{
  short sVar1;
  undefined2 uVar2;
  short unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  uint *extraout_A0;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  int unaff_A6;
  undefined1 uVar3;

  ecs_jump_table(unaff_A4);
  *extraout_A0 = *extraout_A0 | 0x8ec0007;
  if (unaff_D2w == *(short *)(unaff_A6 + -2)) {
    (&comp_collision_related)[unaff_A4] = 0;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  uVar3 = (&comp_collision_related)[unaff_A4] == '\0';
  if ((bool)uVar3) {
    FUN_00002272();
    FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
    FUN_00002248();
    if ((bool)uVar3) {
      return;
    }
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x01';
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  } else {
    player_update_pos_x(unaff_A4);
    FUN_00002500();
    if (((bool)uVar3) && (sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1,
                          *(short *)(&comp_unk_4 + unaff_A4) = sVar1,
                          sVar1 != 0)) {
      return;
    }
  }
  FUN_000159fc();
  if (-1 < (char)(&comp_has_func_maybe)[unaff_A4]) {
    return;
  }
  (&comp_collision_related)[unaff_A4] =
      (&comp_collision_related)[unaff_A4] + '\x01';
  if ((byte)(&comp_collision_related)[unaff_A4] < 4) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] ^ ENTITY_STATE_A_08;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x20;
    uVar2 = 0x40;
    if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
      uVar2 = 0xffc0;
    }
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = uVar2;
    return;
  }
  *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  return;
}

void FUN_0001ced6(void)

{
  byte bVar1;
  short sVar2;
  undefined2 uVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar4;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    (&comp_collision_related)[unaff_A4] = 0;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  uVar4 = (&comp_collision_related)[unaff_A4] == '\0';
  if ((bool)uVar4) {
    FUN_00002272();
    FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
    FUN_00002248();
    if ((bool)uVar4) {
      return;
    }
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x01';
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  } else {
    player_update_pos_x(unaff_A4);
    FUN_00002500();
    if (((bool)uVar4) && (sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1,
                          *(short *)(&comp_unk_4 + unaff_A4) = sVar2,
                          sVar2 != 0)) {
      return;
    }
  }
  FUN_000159fc();
  if (-1 < (char)(&comp_has_func_maybe)[unaff_A4]) {
    return;
  }
  (&comp_collision_related)[unaff_A4] =
      (&comp_collision_related)[unaff_A4] + '\x01';
  if ((byte)(&comp_collision_related)[unaff_A4] < 4) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] ^ ENTITY_STATE_A_08;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x20;
    uVar3 = 0x40;
    if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
      uVar3 = 0xffc0;
    }
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = uVar3;
    return;
  }
  *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  return;
}

// WARNING: Instruction at (ram,0x0001cf92) overlaps instruction at
// (ram,0x0001cf8e)
//

void FUN_0001cf58(void)

{
  byte bVar1;
  entity_state_1_a_t eVar2;
  entity_state_1_b_t eVar3;
  short unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  code *pcVar4;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_sprite_face_asha(unaff_A4);
    (&comp_collision_related)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  eVar3 =
      ECS_STATE_1_B_ATTACKING_MID_AIR | ECS_STATE_1_B_JUMPING_OR_UNSHIELDING;
  if ((&comp_collision_related)[unaff_A4] != '\0') {
    if ((&comp_collision_related)[unaff_A4] != '\x01') {
      if (*(short *)((int)&comp_anim_tick + unaff_A4) != 0) {
        return;
      }
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
      return;
    }
    eVar2 = (&comp_state_1_a)[unaff_A4];
    (&comp_state_1_a)[unaff_A4] = eVar2 & 0xdf;
    if ((eVar2 & 0x20) == 0) {
      eVar3 = 0x10;
    } else {
      FUN_000023a0();
      pcVar4 =
          (code *)callm(0, *(undefined4 *)(unaff_A4 + 0x10 + (int)unaff_D7w));
      eVar3 = (*pcVar4)();
      register0x0000003c = (BADSPACEBASE *)&stack0x00000004;
    }
  }
  if (*(short *)((int)&comp_anim_tick + unaff_A4) != 0) {
    return;
  }
  (&comp_collision_related)[unaff_A4] =
      (&comp_collision_related)[unaff_A4] + '\x01';
  if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
    BYTE_ffffc709 = 0;
  }
  if (unaff_A4 == ENTITY_ID_ASHA) {
    BYTE_ffffc70a = 0;
  }
  (&comp_state_1_a)[unaff_A4] = 0;
  (&comp_anim_c)[unaff_A4] = eVar3;
  *(undefined4 *)((int)register0x0000003c + -4) = 0x1126;
  ecs_anim_unk_1(unaff_A4, unaff_A5);
  (&comp_has_func_maybe)[unaff_A4] =
      (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
  return;
}

void FUN_0001cfb0(void)

{
  byte bVar1;
  short sVar2;
  ushort uVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  int unaff_A6;
  bool bVar4;
  undefined1 uVar5;

  ecs_jump_table(unaff_A4);
  *(undefined2 *)(unaff_A6 + 0xde) = *(undefined2 *)(unaff_A6 + 0xde);
  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    FUN_0000248e(unaff_A4);
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    uVar5 = 0;
    bVar4 = (&comp_has_func_maybe)[unaff_A4] == 0;
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      FUN_00002248();
      if ((!bVar4) && (uVar3 = FUN_000024ae(), (bool)uVar5)) {
        *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
        if (uVar3 < 0x30) {
          return;
        }
        FUN_000024d2();
        *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
        return;
      }
      FUN_0000248e(unaff_A4);
      return;
    }
  }
  return;
}

void FUN_0001cfc2(void)

{
  byte bVar1;
  short sVar2;
  ushort uVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar4;
  undefined1 uVar5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    FUN_0000248e(unaff_A4);
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    uVar5 = 0;
    bVar4 = (&comp_has_func_maybe)[unaff_A4] == 0;
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      FUN_00002248();
      if ((!bVar4) && (uVar3 = FUN_000024ae(), (bool)uVar5)) {
        *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
        if (uVar3 < 0x30) {
          return;
        }
        FUN_000024d2();
        *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
        return;
      }
      FUN_0000248e(unaff_A4);
      return;
    }
  }
  return;
}

void FUN_0001d022(void)

{
  byte bVar1;
  short sVar2;
  word wVar3;
  ushort uVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 in_CF;
  bool bVar5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    FUN_0000248e(unaff_A4);
    FUN_000022a2();
    in_CF = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  entity_update_pos(unaff_A4);
  FUN_00002538();
  uVar4 = FUN_000024ae();
  if (((bool)in_CF) && (uVar4 < 0x40)) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    return;
  }
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    bVar5 = false;
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      FUN_000024ae();
      if (bVar5) {
        FUN_000024d2();
        FUN_000022a2();
        wVar3 = rand();
        *(word *)(&comp_unk_4 + unaff_A4) = (wVar3 & 0x1f) + 0x10;
        return;
      }
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    }
  }
  return;
}

void FUN_0001d092(void)

{
  byte bVar1;
  entity_state_1_a_t eVar2;
  short sVar3;
  int unaff_D2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar4;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  bVar4 = *(short *)((int)&comp_anim_tick + unaff_A4) < 0;
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    return;
  }
  eVar2 = (&comp_state_1_a)[unaff_A4];
  (&comp_state_1_a)[unaff_A4] = eVar2 & 0xdf;
  if ((eVar2 & 0x20) != 0) {
    sVar3 = FUN_000023a0();
    if (unaff_D2 < *(char *)(uint)FUN_00021b08 ||
        ((char *)(uint)FUN_00021b08)[1] < unaff_D2) {
      __m68k_trap(6);
    }
    if (!bVar4) {
      *(undefined2 *)(&comp_unk_4 + sVar3) =
          *(undefined2 *)(&comp_unk_4 + unaff_A4);
      *(short *)(&comp_unk_4 + unaff_A4) =
          *(short *)(&comp_unk_4 + unaff_A4) + 1;
    }
  }
  return;
}

void FUN_0001d0e0(void)

{
  short sVar1;
  short unaff_D3w;
  word unaff_D6w;
  ushort unaff_D7w;
  int unaff_A2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar2;
  undefined1 uVar3;

  ecs_jump_table(unaff_A4);
  *(ushort *)(unaff_A2 + -2) = *(ushort *)(unaff_A2 + -2) | 0x8ec;
  if ((byte)((byte)unaff_D7w | 0x66) == 0) {
    FUN_0000248e(unaff_A4);
    ecs_sprite_face_asha(unaff_A4);
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w | 0x66);
  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    FUN_000159fc();
    uVar3 = 0;
    bVar2 = (&comp_has_func_maybe)[unaff_A4] == 0;
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      FUN_00002248();
      if ((!bVar2) && (FUN_000024ae(), (bool)uVar3)) {
        *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
        return;
      }
      FUN_0000248e(unaff_A4);
      return;
    }
  }
  return;
}

void FUN_0001d0f2(void)

{
  byte bVar1;
  short sVar2;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar3;
  undefined1 uVar4;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    FUN_0000248e(unaff_A4);
    ecs_sprite_face_asha(unaff_A4);
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    uVar4 = 0;
    bVar3 = (&comp_has_func_maybe)[unaff_A4] == 0;
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      FUN_00002248();
      if ((!bVar3) && (FUN_000024ae(), (bool)uVar4)) {
        *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
        return;
      }
      FUN_0000248e(unaff_A4);
      return;
    }
  }
  return;
}

void FUN_0001d146(void)

{
  short *psVar1;
  byte bVar2;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    ecs_sprite_face_asha(unaff_A4);
    (&comp_collision_related)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x20;
  if ((&comp_collision_related)[unaff_A4] != '\0') {
    FUN_000021a2();
    if (((((&comp_func_offset[0].unk4)[unaff_A4] & 2) != 0) ||
         (FUN_000189d0(), ((&comp_func_offset[0].unk4)[unaff_A4] & 1) != 0)) &&
        (-1 < (short)(*(ushort *)((int)&comp_vel[0].x + unaff_A4) ^
                      comp_pos_x.fixed.i -
                          *(short *)((int)&comp_pos_x + unaff_A4)))) {
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = -*psVar1;
    }
    *(undefined2 *)(&comp_unk_4 + unaff_A4) =
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4);
    FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
    if ((((&component_unknown_5)[unaff_A4] |
          (&component_collision_flags)[unaff_A4]) &
         4) == 0) {
      if ((((&component_unknown_5)[unaff_A4] |
            (&component_collision_flags)[unaff_A4]) &
           3) != 0) {
        (&comp_state_a)[unaff_A4] =
            (&comp_state_a)[unaff_A4] ^ ENTITY_STATE_A_08;
        *(short *)((int)&comp_vel[0].x + unaff_A4) =
            -*(short *)(&comp_unk_4 + unaff_A4);
        return;
      }
    } else {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    }
    return;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  if (((&comp_state_1_a)[unaff_A4] & 0x20) == 0) {
    return;
  }
  (&comp_collision_related)[unaff_A4] = 0xff;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 64000;
  FUN_000022a2();
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001d1f6(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_0001d208(void)

{
  byte bVar1;
  char cVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_clear_x_vel_round_up_pos(unaff_A4);
    (&comp_state_a)[unaff_A4] = ENTITY_STATE_A_08;
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 6;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) -
        *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
    (&comp_collision_related)[unaff_A4] = 0;
    return;
  }
  if ((&comp_collision_related)[unaff_A4] == '\0') {
    if ((ushort)((comp_pos_x.fixed.i -
                  *(short *)((int)&comp_pos_x + unaff_A4)) +
                 0x28U) < 0x50) {
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
      (&comp_collision_related)[unaff_A4] = 0x14;
      return;
    }
  } else {
    cVar2 = (&comp_collision_related)[unaff_A4] + -1;
    (&comp_collision_related)[unaff_A4] = cVar2;
    if (cVar2 == '\0') {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    }
  }
  return;
}

void FUN_0001d268(void)

{
  short *psVar1;
  byte bVar2;
  char cVar3;
  entity_id_t unaff_A4;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    (&comp_collision_related)[unaff_A4] = 0x3c;
    FUN_0001d2e2();
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  ecs_sprite_face_asha(unaff_A4);
  FUN_00002258();
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0xc;
  FUN_000025b0();
  entity_update_pos(unaff_A4);
  if (((&comp_state_1_a)[unaff_A4] & 0x20) != 0) {
    if ((ushort)(*(short *)(&DAT_ffffbc78 + unaff_A4) -
                 *(short *)(&comp_unk_4 + unaff_A4)) <
        *(ushort *)((int)&comp_pos_y + unaff_A4)) {
      FUN_0001d2e2();
    }
    cVar3 = (&comp_collision_related)[unaff_A4] + -1;
    (&comp_collision_related)[unaff_A4] = cVar3;
    if (cVar3 == '\0') {
      FUN_000159fc();
      if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
        (&comp_collision_related)[unaff_A4] = 0x1e;
        FUN_00002678();
        if (0x1f < DAT_ffffdb16) {
          *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
        }
      }
    }
  }
  return;
}

void FUN_0001d2e2(void)

{
  short *psVar1;
  ushort uVar2;
  word wVar3;
  ushort uVar4;
  short sVar5;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  wVar3 = rand();
  *(word *)(&comp_unk_4 + unaff_A4) = ((wVar3 & 0x1c0) >> 4) + 0x10;
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 - ((wVar3 & 0x3f) + 0x100);
  sVar5 = 0x180;
  uVar2 = *(short *)(&DAT_ffffbc76 + unaff_A4) -
          *(short *)((int)&comp_pos_x + unaff_A4);
  uVar4 = uVar2;
  if ((short)uVar2 < 0) {
    uVar4 = -uVar2;
  }
  if (uVar4 < 0x60) {
    if (0x5f < (ushort)((comp_pos_x.fixed.i -
                         *(short *)((int)&comp_pos_x + unaff_A4)) +
                        0x30U)) {
      return;
    }
    if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0)
      goto LAB_0001d342;
  } else if (-1 < (short)uVar2)
    goto LAB_0001d342;
  sVar5 = -0x180;
LAB_0001d342:
  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  *psVar1 = sVar5 + *psVar1;
  FUN_00002590();
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001d350(void)

{
  byte bVar1;
  char cVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    (&comp_collision_related)[unaff_A4] = 8;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if ((*(short *)((int)&comp_anim_tick + unaff_A4) == 0) &&
      (cVar2 = (&comp_collision_related)[unaff_A4] + -1,
       (&comp_collision_related)[unaff_A4] = cVar2,
       cVar2 == '\0')) {
    FUN_000023a0();
    // WARNING: Bad instruction - Truncating control flow here
    halt_baddata();
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001d388(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_0001d39a(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_clear_x_vel_round_up_pos(unaff_A4);
  (&comp_state_a)[unaff_A4] = 0x80;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x1a;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
      *(short *)((int)&comp_pos_y + unaff_A4);
  *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  return;
}

void FUN_0001d3c0(void)

{
  byte bVar1;
  short sVar2;
  word wVar3;
  int unaff_A4;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    wVar3 = rand();
    *(word *)(&comp_unk_4 + unaff_A4) = (wVar3 & 0x1f) + 0x10;
    return;
  }
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
          *(undefined2 *)(&DAT_ffffbc76 + unaff_A4);
      *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
    }
  }
  return;
}

void FUN_0001d3ec(void)

{
  byte bVar1;
  short unaff_D2w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    (&comp_collision_related)[unaff_A4] = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 10);
  }
  FUN_00002272();
  if ((&comp_collision_related)[unaff_A4] == '\0') {
    FUN_00001fd2();
    FUN_000021e2(unaff_A4);
    ecs_update_pos_y(unaff_A4);
    if (DAT_ffffcbf6 <= *(ushort *)((int)&comp_pos_y + unaff_A4)) {
      FUN_000017da(unaff_A4, unaff_A5, unaff_D2w);
      (&comp_collision_related)[unaff_A4] = 0xff;
      if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
        BYTE_ffffc709 = 0;
      }
      if (unaff_A4 == ENTITY_ID_ASHA) {
        BYTE_ffffc70a = 0;
      }
      (&comp_state_1_a)[unaff_A4] = 0;
      (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_TALKING_OR_ENTERING_BACK_DOOR;
      ecs_anim_unk_1(unaff_A4, unaff_A5);
      (&comp_has_func_maybe)[unaff_A4] =
          (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
      return;
    }
  } else {
    ecs_update_pos_y(unaff_A4);
    if (*(ushort *)(&DAT_ffffbc78 + unaff_A4) <=
        (ushort)(*(short *)((int)&comp_pos_y + unaff_A4) -
                 *(short *)((int)&comp_collision_sensor[0].y + unaff_A4))) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    }
  }
  return;
}

void FUN_0001d44a(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  short unaff_D2w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    ecs_sprite_face_asha(unaff_A4);
    (&comp_collision_related)[unaff_A4] = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 64000;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  }
  if ((&comp_collision_related)[unaff_A4] == '\0') {
    ecs_update_pos_y(unaff_A4);
    if (*(ushort *)((int)&comp_pos_y + unaff_A4) < DAT_ffffcbf6) {
      FUN_000017da(unaff_A4, unaff_A5, unaff_D2w);
      rand();
      FUN_000022a2();
      (&comp_collision_related)[unaff_A4] = 0xff;
      if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
        BYTE_ffffc709 = 0;
      }
      if (unaff_A4 == ENTITY_ID_ASHA) {
        BYTE_ffffc70a = 0;
      }
      (&comp_state_1_a)[unaff_A4] = 0;
      (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_ATTACKING_MID_AIR;
      ecs_anim_unk_1(unaff_A4, unaff_A5);
      (&comp_has_func_maybe)[unaff_A4] =
          (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
      return;
    }
  } else {
    FUN_00001fd2();
    FUN_000021e2(unaff_A4);
    player_update_pos(unaff_A4);
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    sVar3 = *psVar1 + 0x30;
    *psVar1 = sVar3;
    if (-1 < sVar3) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
      *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    }
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001d4b8(void)

{
  byte bVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    FUN_000023a0();
    // WARNING: Bad instruction - Truncating control flow here
    halt_baddata();
  }
  return;
}

void FUN_0001d4e4(void)

{
  undefined2 *puVar1;
  short *psVar2;
  byte bVar3;
  ushort uVar4;
  short extraout_D0w;
  short sVar5;
  ushort uVar6;
  int extraout_A0;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_jump_table(unaff_A4);
  puVar1 = (undefined2 *)(extraout_A0 + -0xc + (int)extraout_D0w);
  *puVar1 = *puVar1;
  bVar3 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar3 | 0x80;
  if ((bVar3 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  psVar2 = (short *)((int)&comp_vel[0].x + unaff_A4);
  *psVar2 = *psVar2 - (*(short *)((int)&comp_vel[0].x + unaff_A4) >> 5);
  sVar5 = *(short *)((int)&comp_vel[0].y + unaff_A4) + 0x10;
  if (0x200 < sVar5) {
    sVar5 = 0x200;
  }
  *(short *)((int)&comp_vel[0].y + unaff_A4) = sVar5;
  player_update_pos(unaff_A4);
  uVar6 = *(ushort *)(&DAT_ffffbc78 + unaff_A4);
  uVar4 = comp_pos_y.fixed.i - 0x1c;
  if ((uVar4 <= uVar6) && ((ushort)(uVar6 - uVar4) < 0x60)) {
    uVar6 = uVar4;
  }
  if (uVar6 < *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

void FUN_0001d4f6(void)

{
  short *psVar1;
  byte bVar2;
  ushort uVar3;
  short sVar4;
  ushort uVar5;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  *psVar1 = *psVar1 - (*(short *)((int)&comp_vel[0].x + unaff_A4) >> 5);
  sVar4 = *(short *)((int)&comp_vel[0].y + unaff_A4) + 0x10;
  if (0x200 < sVar4) {
    sVar4 = 0x200;
  }
  *(short *)((int)&comp_vel[0].y + unaff_A4) = sVar4;
  player_update_pos(unaff_A4);
  uVar5 = *(ushort *)(&DAT_ffffbc78 + unaff_A4);
  uVar3 = comp_pos_y.fixed.i - 0x1c;
  if ((uVar3 <= uVar5) && ((ushort)(uVar5 - uVar3) < 0x60)) {
    uVar5 = uVar3;
  }
  if (uVar5 < *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

void FUN_0001d558(void)

{
  short *psVar1;
  short sVar2;
  byte bVar3;
  ushort uVar4;
  word wVar5;
  ushort uVar6;
  undefined1 uVar7;
  ushort uVar8;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar3 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar3 | 0x80;
  if ((bVar3 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfc80;
    wVar5 = rand();
    uVar6 = (wVar5 & 0x3ff) - 0x200;
    uVar4 = *(short *)(&DAT_ffffbc76 + unaff_A4) -
            *(short *)((int)&comp_pos_x + unaff_A4);
    uVar8 = uVar4;
    if ((short)uVar4 < 0) {
      uVar8 = -uVar4;
    }
    if ((0x3f < uVar8) && ((short)(uVar6 ^ uVar4) < 0)) {
      uVar6 = -uVar6;
    }
    *(ushort *)((int)&comp_vel[0].x + unaff_A4) = uVar6;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  player_update_pos(unaff_A4);
  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  *psVar1 = *psVar1 - (*(short *)((int)&comp_vel[0].x + unaff_A4) >> 4);
  sVar2 = *(short *)((int)&comp_vel[0].y + unaff_A4);
  sVar2 = sVar2 - (sVar2 >> 4);
  *(short *)((int)&comp_vel[0].y + unaff_A4) = sVar2;
  if (-0x80 < sVar2) {
    uVar7 = 3;
    uVar6 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
    if ((short)uVar6 < 0) {
      uVar6 = -uVar6;
    }
    if (uVar6 < 0x50) {
      uVar7 = 6;
    }
    *(undefined1 *)((int)&comp_state + unaff_A4) = uVar7;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001d5dc(void)

{
  byte bVar1;
  short sVar2;
  undefined4 uVar3;
  undefined1 extraout_A0b;
  int unaff_A3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if ((*(short *)(&comp_unk_4 + unaff_A4) != 0) &&
      (sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1,
       *(short *)(&comp_unk_4 + unaff_A4) = sVar2,
       sVar2 == 0)) {
    uVar3 = FUN_000023a0();
    *(short *)(unaff_A3 + -2) =
        (short)CONCAT31((int3)((uint)uVar3 >> 8), extraout_A0b);
    FUN_000023a0();
    // WARNING: Bad instruction - Truncating control flow here
    halt_baddata();
  }
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_0001d626(void)

{
  byte bVar1;
  short sVar2;
  undefined2 uVar3;
  byte unaff_D7b;
  ushort *unaff_A2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_jump_table(unaff_A4);
  *unaff_A2 = *unaff_A2 | 0x8ec;
  if ((unaff_D7b | 0x66) == 0) {
    uVar3 = 0x78;
    bVar1 = (&comp_collision_related)[unaff_A4];
    (&comp_collision_related)[unaff_A4] = bVar1 ^ 1;
    if ((bVar1 & 1) != 0) {
      uVar3 = 0x14;
    }
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = uVar3;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  ecs_sprite_face_asha(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    }
  }
  return;
}

void FUN_0001d638(void)

{
  byte bVar1;
  short sVar2;
  undefined2 uVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    uVar3 = 0x78;
    bVar1 = (&comp_collision_related)[unaff_A4];
    (&comp_collision_related)[unaff_A4] = bVar1 ^ 1;
    if ((bVar1 & 1) != 0) {
      uVar3 = 0x14;
    }
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = uVar3;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  ecs_sprite_face_asha(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    }
  }
  return;
}

void FUN_0001d67c(void)

{
  byte bVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_000186f4(unaff_A4, &UNK_0001d6ae);
  FUN_00002238();
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001d6c4(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_0001d6d6(void)

{
  int unaff_A4;

  (&comp_state_a)[unaff_A4] = 0;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x18;
  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x48;
  *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  return;
}

void FUN_0001d6ee(void)

{
  ushort uVar1;
  byte bVar2;
  int unaff_A4;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 8;
  } else {
    uVar1 = *(ushort *)(&DAT_ffffbc76 + unaff_A4);
    if (uVar1 < *(ushort *)(&DAT_ffffbd76 + unaff_A4)) {
      if ((ushort)(uVar1 - 0x18) < (ushort)comp_pos_x.fixed.i) {
        return;
      }
    } else if ((ushort)comp_pos_x.fixed.i <= (ushort)(uVar1 + 0x18)) {
      return;
    }
    uVar1 = (*(short *)(&DAT_ffffbc78 + unaff_A4) - comp_pos_y._0_2_) -
            comp_collision_sensor[0].y;
    if ((-1 < (short)uVar1) && (uVar1 < 0x60)) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
      return;
    }
  }
  *(int16_t *)(&DAT_ffffbd76 + unaff_A4) = comp_pos_x.fixed.i;
  return;
}

void FUN_0001d742(void)

{
  byte bVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_TALKING_OR_ENTERING_BACK_DOOR;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

uint FUN_0001d75e(void)

{
  ushort uVar1;
  byte bVar2;
  entity_state_1_a_t eVar3;
  uint extraout_D0;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
        *(undefined2 *)(&DAT_ffffbc76 + unaff_A4);
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
        *(undefined2 *)(&DAT_ffffbc78 + unaff_A4);
    ecs_sprite_face_asha(unaff_A4);
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] & 0xb7;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x40;
    uVar1 = *(ushort *)((int)&comp_collision_sensor[0].y + unaff_A4);
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) - uVar1;
    (&comp_collision_related)[unaff_A4] = 0;
    return (uint)uVar1;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if ((&comp_collision_related)[unaff_A4] == 0) {
    if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
        BYTE_ffffc709 = 0;
      }
      if (unaff_A4 == ENTITY_ID_ASHA) {
        BYTE_ffffc70a = 0;
      }
      (&comp_state_1_a)[unaff_A4] = 0;
      (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_ATTACKING_MID_AIR |
                                 ECS_STATE_1_B_JUMPING_OR_UNSHIELDING;
      ecs_anim_unk_1(unaff_A4, unaff_A5);
      (&comp_has_func_maybe)[unaff_A4] =
          (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
      return extraout_D0;
    }
  } else {
    eVar3 = (&comp_state_1_a)[unaff_A4];
    (&comp_state_1_a)[unaff_A4] = eVar3 & 0xdf;
    if ((eVar3 & 0x20) != 0) {
      FUN_000023a0();
      // WARNING: Bad instruction - Truncating control flow here
      halt_baddata();
    }
    if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    }
  }
  return (uint)(byte)(&comp_collision_related)[unaff_A4];
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001d7d2(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

uint FUN_0001d7e4(void)

{
  byte bVar1;
  short sVar3;
  uint extraout_D0;
  ushort uVar4;
  word wVar5;
  uint uVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar6;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) != 0) {
  LAB_0001d848:
    FUN_00001fd2();
    FUN_000021e2(unaff_A4);
    sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
    if (sVar3 != 0) {
      return extraout_D0;
    }
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    uVar4 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
    if ((short)uVar4 < 0) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
      uVar4 = -uVar4;
    }
    uVar2 = (uint)uVar4;
    if (uVar4 < 0x60) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] ^ ENTITY_STATE_A_08;
    } else if (uVar4 < 0xa0) {
      if (uVar4 < 0x80) {
        wVar5 = rand();
        uVar2 = wVar5 & 0xffffff0c;
        if (((wVar5 & 0xc) == 0) &&
            ((byte)(&DAT_ffffcf9f)[*(short *)((int)&comp_unk_8 + unaff_A4)] <
             4)) {
          *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
          return uVar2;
        }
      }
      *(byte *)((int)&comp_state + unaff_A4) =
          *(byte *)((int)&comp_state + unaff_A4) & 0x7f;
      return uVar2;
    }
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    return uVar2;
  }
  sVar3 = *(short *)((int)&comp_collision_sensor[0].x + unaff_A4);
  if ((ushort)(sVar3 + DAT_ffffce08) <
      *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    sVar3 = sVar3 + DAT_ffffc73a;
  } else {
    if ((ushort)(DAT_ffffce04 - sVar3) <
        *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      ecs_sprite_face_asha(unaff_A4);
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 8;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
      goto LAB_0001d848;
    }
    sVar3 = (DAT_ffffc73a + 0x100) - sVar3;
  }
  *(short *)((int)&comp_pos_x + unaff_A4) = sVar3;
  *(short *)((int)&comp_pos_y + unaff_A4) =
      DAT_ffffce06 - *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  uVar6 = (bVar1 & 0x80) == 0;
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bool)uVar6) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    uVar6 = 1;
    ecs_sprite_face_asha(unaff_A4);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002272();
  FUN_00002256();
  player_update_pos(unaff_A4);
  uVar2 = FUN_00002856();
  if (!(bool)uVar6) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return uVar2;
}

void FUN_0001d8b6(void)

{
  byte bVar1;
  short sVar2;
  ushort uVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x10;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    FUN_000022a2();
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  player_update_pos_x(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    uVar3 = FUN_000024a0();
    if (uVar3 < 0x70) {
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x10;
      return;
    }
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_0001d8fe(void)

{
  byte bVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar2;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  uVar2 = (bVar1 & 0x80) == 0;
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bool)uVar2) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    uVar2 = 1;
    ecs_sprite_face_asha(unaff_A4);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002272();
  FUN_00002256();
  player_update_pos(unaff_A4);
  FUN_00002856();
  if (!(bool)uVar2) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_0001d936(void)

{
  byte bVar1;
  char cVar2;
  short sVar3;
  entity_id_w_t unaff_D2w;
  entity_id_t e;
  int extraout_A0;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    (&comp_collision_related)[unaff_A4] = 2;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    if (*(short *)(&comp_unk_4 + unaff_A4) == 0) {
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x10;
      FUN_0000165c((ushort *)&UNK_0001d9f2,
                   unaff_A5,
                   unaff_D2w,
                   *(short *)((int)&comp_pos_x + unaff_A4),
                   *(short *)((int)&comp_pos_y + unaff_A4) + -6,
                   0);
      sVar3 = ecs_find_some_entity_with_func();
      if (-1 < sVar3) {
        entity_reset(e);
        (&comp_has_func_maybe)[e] = 0x80;
        sVar3 = *(short *)((int)&comp_pos_y + extraout_A0);
        *(undefined2 *)((int)&comp_pos_x + e) =
            *(undefined2 *)((int)&comp_pos_x + extraout_A0);
        *(short *)((int)&comp_pos_y + e) = sVar3 + 2;
        sVar3 = *(short *)((int)&comp_unk_8 + extraout_A0);
        (&DAT_ffffcf9f)[sVar3] = (&DAT_ffffcf9f)[sVar3] + '\x01';
        *(short *)((int)&comp_unk_8 + e) = sVar3;
        (&comp_func_offset[0].unk1)[e] = 0x13;
        *(undefined1 *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + e) = 0xff;
        FUN_000019ae();
        (&comp_unk_10)[e] = 0x40;
        return;
      }
    } else {
      sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
      *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
      if (sVar3 == 0) {
        cVar2 = (&comp_collision_related)[unaff_A4] + -1;
        (&comp_collision_related)[unaff_A4] = cVar2;
        if ((cVar2 != '\0') &&
            ((byte)(&DAT_ffffcf9f)[*(short *)((int)&comp_unk_8 + unaff_A4)] <
             4)) {
          if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
            BYTE_ffffc709 = 0;
          }
          if (unaff_A4 == ENTITY_ID_ASHA) {
            BYTE_ffffc70a = 0;
          }
          (&comp_state_1_a)[unaff_A4] = 0;
          (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_ATTACKING_MID_AIR |
                                     ECS_STATE_1_B_JUMPING_OR_UNSHIELDING;
          ecs_anim_unk_1(unaff_A4, unaff_A5);
          (&comp_has_func_maybe)[unaff_A4] =
              (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
          return;
        }
        *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
      }
    }
  }
  return;
}

void FUN_0001d9f8(void)

{
  short *psVar1;
  byte bVar2;
  word wVar3;
  short sVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar5;

  ecs_jump_table(unaff_A4);
  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    (&comp_collision_related)[unaff_A4] = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 8;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x12);
    return;
  }
  if ((byte)(&comp_collision_related)[unaff_A4] < 4) {
    if (*(short *)(&comp_unk_4 + unaff_A4) != 0) {
      sVar4 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
      *(short *)(&comp_unk_4 + unaff_A4) = sVar4;
      if (sVar4 != 0) {
        return;
      }
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
      return;
    }
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + 0x40;
    player_update_pos(unaff_A4);
    bVar5 = *(short *)((int)&comp_vel[0].y + unaff_A4) == 0;
    if ((bVar5) &&
        (bVar5 = (&comp_collision_related)[unaff_A4] == '\x03', bVar5)) {
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0x14);
      return;
    }
    FUN_00002856();
    if (!bVar5) {
      psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
      *psVar1 = -*psVar1;
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0x10);
      if (*(short *)((int)&comp_vel[0].x + unaff_A4) == 0) {
        *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfd00;
        wVar3 = rand();
        sVar4 = (wVar3 & 0x7f) + 0xc0;
        if (((ushort)(DAT_ffffce04 + 0x50U) <
             *(ushort *)((int)&comp_pos_x + unaff_A4)) &&
            (((ushort)(DAT_ffffce08 - 0x50U) <
                  *(ushort *)((int)&comp_pos_x + unaff_A4) ||
              ((ushort)comp_pos_x.fixed.i <
               *(ushort *)((int)&comp_pos_x + unaff_A4))))) {
          sVar4 = -sVar4;
        }
        *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar4;
      }
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      if (2 < (byte)(&comp_collision_related)[unaff_A4]) {
        *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfc00;
      }
    }
  } else if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) + 5;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x16);
    return;
  }
  return;
}

void FUN_0001da0a(void)

{
  short *psVar1;
  byte bVar2;
  word wVar3;
  short sVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    (&comp_collision_related)[unaff_A4] = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 8;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x12);
    return;
  }
  if ((byte)(&comp_collision_related)[unaff_A4] < 4) {
    if (*(short *)(&comp_unk_4 + unaff_A4) != 0) {
      sVar4 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
      *(short *)(&comp_unk_4 + unaff_A4) = sVar4;
      if (sVar4 != 0) {
        return;
      }
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
      return;
    }
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + 0x40;
    player_update_pos(unaff_A4);
    bVar5 = *(short *)((int)&comp_vel[0].y + unaff_A4) == 0;
    if ((bVar5) &&
        (bVar5 = (&comp_collision_related)[unaff_A4] == '\x03', bVar5)) {
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0x14);
      return;
    }
    FUN_00002856();
    if (!bVar5) {
      psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
      *psVar1 = -*psVar1;
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0x10);
      if (*(short *)((int)&comp_vel[0].x + unaff_A4) == 0) {
        *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfd00;
        wVar3 = rand();
        sVar4 = (wVar3 & 0x7f) + 0xc0;
        if (((ushort)(DAT_ffffce04 + 0x50U) <
             *(ushort *)((int)&comp_pos_x + unaff_A4)) &&
            (((ushort)(DAT_ffffce08 - 0x50U) <
                  *(ushort *)((int)&comp_pos_x + unaff_A4) ||
              ((ushort)comp_pos_x.fixed.i <
               *(ushort *)((int)&comp_pos_x + unaff_A4))))) {
          sVar4 = -sVar4;
        }
        *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar4;
      }
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      if (2 < (byte)(&comp_collision_related)[unaff_A4]) {
        *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfc00;
      }
    }
  } else if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) + 5;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x16);
    return;
  }
  return;
}

void FUN_0001dae6(void)

{
  byte bVar1;
  short sVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x3c;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002258();
  if ((ushort)(*(short *)(&DAT_ffffbc78 + unaff_A4) - 0x20U) !=
      *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    if ((ushort)(*(short *)(&DAT_ffffbc78 + unaff_A4) - 0x20U) <
        *(ushort *)((int)&comp_pos_y + unaff_A4)) {
      *(short *)((int)&comp_pos_y + unaff_A4) =
          *(short *)((int)&comp_pos_y + unaff_A4) + -1;
    } else {
      *(short *)((int)&comp_pos_y + unaff_A4) =
          *(short *)((int)&comp_pos_y + unaff_A4) + 1;
    }
  }
  player_update_pos_x(unaff_A4);
  ecs_sprite_face_asha(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  }
  return;
}

void FUN_0001db38(void)

{
  byte bVar1;
  short sVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    FUN_000025fe();
    *(short *)(&comp_unk_4 + unaff_A4) = *(short *)(&comp_unk_4 + unaff_A4) + 4;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  player_update_pos(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001db6c(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_0001db7e(void)

{
  short sVar1;
  int iVar2;
  short unaff_A4w;
  entity_id_t eVar3;
  anim_item_t *unaff_A5;

  sVar1 = ecs_find_some_entity_with_func();
  if (-1 < sVar1) {
    iVar2 = (int)unaff_A4w;
    eVar3 = (entity_id_t)sVar1;
    entity_reset(eVar3);
    (&comp_func_offset[0].unk1)[eVar3] = (&comp_func_offset[0].unk1)[iVar2];
    *(undefined2 *)((int)&comp_pos_x + eVar3) =
        *(undefined2 *)((int)&comp_pos_x + iVar2);
    *(undefined2 *)((int)&comp_pos_y + eVar3) =
        *(undefined2 *)((int)&comp_pos_y + iVar2);
    FUN_000019ae();
    ecs_anim_unk_2(eVar3, unaff_A5, 0);
    *(short *)((int)&comp_pos_y + eVar3) =
        *(short *)((int)&comp_pos_y + eVar3) -
        *(short *)((int)&comp_collision_sensor[0].y + eVar3);
    (&comp_has_func_maybe)[eVar3] = (&comp_has_func_maybe)[eVar3] | 0x20;
    (&comp_unk_10)[eVar3] = 0x80;
    *(undefined2 *)((int)&comp_unk_3 + eVar3) = 0x18;
    eVar3 = (entity_id_t)unaff_A4w;
    (&comp_state_a)[eVar3] = 0;
    *(undefined2 *)((int)&comp_unk_3 + eVar3) = 0x1a;
    ecs_anim_unk_2(eVar3, unaff_A5, 0);
    (&comp_has_func_maybe)[eVar3] = (&comp_has_func_maybe)[eVar3] | 0x48;
    *(undefined1 *)((int)&comp_state + eVar3) = 3;
  }
  return;
}

void FUN_0001dbe4(void)

{
  byte bVar1;
  char cVar2;
  word wVar3;
  short sVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    wVar3 = rand();
    *(word *)(&comp_unk_4 + unaff_A4) = (wVar3 & 0x1f) + 0x20;
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 8;
  } else if (*(short *)(&comp_unk_4 + unaff_A4) == 0) {
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) + -2;
    cVar2 = (&comp_collision_related)[unaff_A4] + -1;
    (&comp_collision_related)[unaff_A4] = cVar2;
    if (cVar2 == '\0') {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    } else if ((&comp_collision_related)[unaff_A4] == '\b') {
      if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
        BYTE_ffffc709 = 0;
      }
      if (unaff_A4 == ENTITY_ID_ASHA) {
        BYTE_ffffc70a = 0;
      }
      (&comp_state_1_a)[unaff_A4] = 0;
      (&comp_anim_c)[unaff_A4] = 0x10;
      ecs_anim_unk_1(unaff_A4, unaff_A5);
      (&comp_has_func_maybe)[unaff_A4] =
          (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
      return;
    }
  } else {
    sVar4 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar4;
    if (sVar4 == 0) {
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
      (&comp_has_func_maybe)[unaff_A4] =
          (&comp_has_func_maybe)[unaff_A4] & 0xf7;
      sVar4 = 4;
      if ((&comp_func_offset[0].unk1)[unaff_A4] == 0x51) {
        sVar4 = -8;
      }
      *(short *)((int)&comp_pos_y + unaff_A4) =
          *(short *)(&DAT_ffffbc78 + unaff_A4) + sVar4;
      (&comp_collision_related)[unaff_A4] = 0x10;
      return;
    }
  }
  return;
}

void FUN_0001dc58(void)

{
  byte bVar1;
  short sVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x10;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x10);
    return;
  }
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_pos_y + unaff_A4) + 2;
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 8;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  } else if (*(short *)(&comp_unk_4 + unaff_A4) == 8) {
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_TALKING_OR_ENTERING_BACK_DOOR;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001dc92(void)

{
  byte bVar1;
  entity_state_1_a_t eVar2;
  entity_state_1_b_t eVar4;
  short sVar3;
  undefined1 *unaff_A2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_sprite_face_asha(unaff_A4);
    (&comp_collision_related)[unaff_A4] = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
    eVar4 = ECS_STATE_1_B_FALLING;
  ecs_anim_unk_2:
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = eVar4;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if ((&comp_collision_related)[unaff_A4] == '\0') {
    ecs_sprite_face_asha(unaff_A4);
    sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
    if (sVar3 == 0) {
      (&DAT_ffffb976)[unaff_A4] = (&comp_func_offset[0].unk1)[unaff_A4] != 0x51;
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      eVar4 = ECS_STATE_1_B_ATTACKING_MID_AIR |
              ECS_STATE_1_B_JUMPING_OR_UNSHIELDING;
      goto ecs_anim_unk_2;
    }
  } else {
    eVar2 = (&comp_state_1_a)[unaff_A4];
    (&comp_state_1_a)[unaff_A4] = eVar2 & 0xdf;
    if ((eVar2 & 0x20) != 0) {
      if ((&comp_func_offset[0].unk1)[unaff_A4] == 0x51) {
      LAB_0001dcfa:
        FUN_000023a0();
        // WARNING: Bad instruction - Truncating control flow here
        halt_baddata();
      }
      sVar3 = FUN_000023a0();
      *unaff_A2 = 0x42;
      if (sVar3 < 0)
        goto LAB_0001dcfa;
      (&comp_collision_related)[sVar3] = (&DAT_ffffb976)[unaff_A4];
    }
    if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
      if (((&comp_func_offset[0].unk1)[unaff_A4] != 0x3f) &&
          ((&DAT_ffffb976)[unaff_A4] = (&DAT_ffffb976)[unaff_A4] + '\x01',
           (byte)(&DAT_ffffb976)[unaff_A4] < 3)) {
        eVar4 = ECS_STATE_1_B_ATTACKING_MID_AIR |
                ECS_STATE_1_B_JUMPING_OR_UNSHIELDING;
        goto ecs_anim_unk_2;
      }
      *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    }
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001dd36(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

// WARNING: Possible PIC construction at 0x0001dd60: Changing call to branch

void FUN_0001dd4a(void)

{
  byte bVar1;
  entity_state_1_b_t eVar3;
  ushort uVar2;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar4;
  undefined1 uVar5;
  undefined4 uStack_4;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    bVar4 = true;
    uStack_4 = 0x1dd5a;
    FUN_00002248();
    if (!bVar4) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    }
    register0x0000003c = (BADSPACEBASE *)&uStack_4;
    uStack_4 = 0x1dd62;
    goto SUB_0001dddc;
  }
  uVar5 = (&comp_func_offset[0].unk1)[unaff_A4] == 0x41;
  if ((bool)uVar5) {
  LAB_0001dd70:
    uStack_4 = 0x1dd74;
    FUN_00001fd2();
    uStack_4 = 0x1dd78;
    FUN_000021e2(unaff_A4);
  } else {
    uStack_4 = 0x1dd6e;
    FUN_0001e0e8();
    if ((bool)uVar5)
      goto LAB_0001dd70;
  }
  uStack_4 = 0x1dd7c;
  FUN_00002272();
  uStack_4 = 0x1dd80;
  FUN_00002256();
  uStack_4 = 0x1dd84;
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  uStack_4 = 0x1dd88;
  FUN_00002678();
  uStack_4 = 0x1dd8c;
  FUN_000026aa();
  uStack_4 = 0x1dd90;
  FUN_0001e23c();
  if (!(bool)uVar5) {
    return;
  }
  uStack_4 = 0x1dd98;
  FUN_0001e174();
  if (!(bool)uVar5) {
    return;
  }
  uStack_4 = 0x1dda0;
  FUN_0001e1a8();
  if (!(bool)uVar5) {
    return;
  }
  uStack_4 = 0x1dda8;
  FUN_0001e134();
  if (!(bool)uVar5) {
    return;
  }
  if ((DAT_ffffdb16 < 0x70) &&
      (((0x27 < DAT_ffffdb16 || (DAT_ffffdb16 < 0x1c)) ||
        ((DAT_ffffdb18 != 0 &&
          (((component_unknown_5 | component_collision_flags) & 0x10) ==
           0)))))) {
    uStack_4 = 0x1de22;
    uVar2 = FUN_000183ce(unaff_D3w);
    if ((uVar2 & 2) == 0) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
      return;
    }
  }
SUB_0001dddc:
  eVar3 = ECS_STATE_1_B_FALLING;
  if (((&comp_func_offset[0].unk1)[unaff_A4] != 0x43) &&
      (DAT_ffffdb16 < 0x48)) {
    eVar3 = ECS_STATE_1_B_TALKING_OR_ENTERING_BACK_DOOR;
  }
  if (eVar3 == (&comp_anim_c)[unaff_A4]) {
    return;
  }
  if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
    BYTE_ffffc709 = 0;
  }
  if (unaff_A4 == ENTITY_ID_ASHA) {
    BYTE_ffffc70a = 0;
  }
  (&comp_state_1_a)[unaff_A4] = 0;
  (&comp_anim_c)[unaff_A4] = eVar3;
  *(undefined4 *)((int)register0x0000003c + -4) = 0x1126;
  ecs_anim_unk_1(unaff_A4, unaff_A5);
  (&comp_has_func_maybe)[unaff_A4] =
      (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
  return;
}

uint FUN_0001de30(void)

{
  byte bVar1;
  short sVar2;
  uint extraout_D0;
  uint uVar3;
  ushort uVar4;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar5;
  undefined1 uVar6;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
    FUN_00002678();
    FUN_0001e08a();
    FUN_0001dece();
  }
  bVar5 = (&comp_func_offset[0].unk1)[unaff_A4] == 0x41;
  if ((bVar5) || (FUN_0001e0e8(), bVar5)) {
    FUN_00001fd2();
    FUN_000021e2(unaff_A4);
  }
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  uVar3 = ((&component_unknown_5)[unaff_A4] |
           (&component_collision_flags)[unaff_A4]) &
          0xffffff03;
  if ((((&component_unknown_5)[unaff_A4] |
        (&component_collision_flags)[unaff_A4]) &
       3) == 0) {
    sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
    if (sVar2 != 0) {
      return uVar3;
    }
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
    uVar6 = 0;
    FUN_00002678();
    uVar3 = FUN_0001e174();
    if (!(bool)uVar6) {
      return uVar3;
    }
    uVar3 = FUN_0001e1a8();
    if (!(bool)uVar6) {
      return uVar3;
    }
    uVar3 = FUN_0001e134();
    if (!(bool)uVar6) {
      return uVar3;
    }
    uVar3 = (uint)DAT_ffffdb16;
    if (DAT_ffffdb16 < 0x70) {
      if ((DAT_ffffdb16 < 0x1c) || (0x27 < DAT_ffffdb16))
        goto LAB_0001deca;
    } else {
      uVar4 = *(short *)(&DAT_ffffbc76 + unaff_A4) -
              *(short *)((int)&comp_pos_x + unaff_A4);
      if ((short)uVar4 < 0) {
        uVar4 = -uVar4;
      }
      uVar3 = (uint)uVar4;
      if (0xf < uVar4) {
      LAB_0001deca:
        FUN_0001e08a();
        uVar3 = 8;
        if (((&comp_func_offset[0].unk1)[unaff_A4] != 0x43) &&
            (DAT_ffffdb16 < 0x48)) {
          uVar3 = 0x10;
        }
        if ((entity_state_1_b_t)uVar3 == (&comp_anim_c)[unaff_A4]) {
          return uVar3;
        }
        if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
          BYTE_ffffc709 = 0;
        }
        if (unaff_A4 == ENTITY_ID_ASHA) {
          BYTE_ffffc70a = 0;
        }
        (&comp_state_1_a)[unaff_A4] = 0;
        (&comp_anim_c)[unaff_A4] = (entity_state_1_b_t)uVar3;
        ecs_anim_unk_1(unaff_A4, unaff_A5);
        (&comp_has_func_maybe)[unaff_A4] =
            (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
        return extraout_D0;
      }
    }
  }
  *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  return uVar3;
}

void FUN_0001dece(void)

{
  entity_state_1_b_t eVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  eVar1 = ECS_STATE_1_B_ATTACKING_MID_AIR;
  if (((&comp_func_offset[0].unk1)[unaff_A4] != 0x43) &&
      (DAT_ffffdb16 < 0x48)) {
    eVar1 = 0x10;
  }
  if (eVar1 != (&comp_anim_c)[unaff_A4]) {
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = eVar1;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  return;
}

void FUN_0001deec(void)

{
  byte bVar1;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar2;
  undefined1 uVar3;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    bVar2 = true;
    FUN_00002248();
    if (!bVar2) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    }
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x12);
  }
  FUN_00018870();
  uVar3 = ((&comp_func_offset[0].unk4)[unaff_A4] & 0x80) == 0;
  if ((bool)uVar3) {
    FUN_00001fd2();
    FUN_000021e2(unaff_A4);
  }
  FUN_00002272();
  FUN_00002256();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00002678();
  FUN_0001e188();
  if ((bool)uVar3) {
    FUN_0001e1a8();
    if ((bool)uVar3) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    }
  } else if (7 < DAT_ffffdb16) {
    if (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
        (ushort)comp_pos_x.fixed.i) {
      (&comp_state_a)[unaff_A4] =
          (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
      return;
    }
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    return;
  }
  return;
}

void FUN_0001df6a(void)

{
  byte bVar1;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  byte *pbVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar3;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  pbVar2 = &UNK_0001dfe2;
  if ((&comp_func_offset[0].unk1)[unaff_A4] == 0x43) {
    pbVar2 = &UNK_0001dff8;
  }
  FUN_000186f4(unaff_A4, pbVar2);
  if (((&comp_func_offset[0].unk4)[unaff_A4] & 0x20) == 0) {
    FUN_00018758(unaff_A4, pbVar2);
    if (((&comp_func_offset[0].unk4)[unaff_A4] & 0x40) == 0) {
      FUN_00002238();
      goto LAB_0001dfbe;
    }
  }
  FUN_0001e118();
LAB_0001dfbe:
  FUN_00002272();
  FUN_00002256();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  uVar3 = *(short *)((int)&comp_anim_tick + unaff_A4) == 0;
  if ((bool)uVar3) {
    FUN_00002678();
    FUN_0001e1a8();
    if ((bool)uVar3) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    }
  }
  return;
}

void FUN_0001e016(void)

{
  byte bVar1;
  entity_state_1_a_t eVar2;
  int iVar3;
  short unaff_D3w;
  int unaff_D4;
  undefined4 unaff_D6;
  word unaff_D7w;
  int extraout_A1;
  entity_id_t unaff_A4;
  entity_id_t self;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x14);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002272();
  FUN_00002256();
  FUN_00002288(unaff_A4, unaff_D3w, (word)unaff_D6, unaff_D7w);
  if ((&comp_anim_c)[unaff_A4] == 0x14) {
    eVar2 = (&comp_state_1_a)[unaff_A4];
    (&comp_state_1_a)[unaff_A4] = eVar2 & 0xdf;
    if ((eVar2 & 0x20) != 0) {
      iVar3 = FUN_000023a0();
      *(undefined4 *)(extraout_A1 + -4) = unaff_D6;
      if (iVar3 * unaff_D4 < 0) {
        if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
          BYTE_ffffc709 = 0;
        }
        if (unaff_A4 == ENTITY_ID_ASHA) {
          BYTE_ffffc70a = 0;
        }
        (&comp_state_1_a)[unaff_A4] = 0;
        (&comp_anim_c)[unaff_A4] = 0x16;
        ecs_anim_unk_1(unaff_A4, unaff_A5);
        (&comp_has_func_maybe)[unaff_A4] =
            (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
        return;
      }
      self = (entity_id_t)(short)iVar3;
      *(undefined2 *)((int)&comp_unk_3 + self) = 0x16;
      *(undefined1 *)((int)&comp_state + self) = 0;
      ecs_anim_unk_2(self, unaff_A5, 0);
      (&comp_has_func_maybe)[self] = (&comp_has_func_maybe)[self] | 0x20;
      return;
    }
  } else if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_0001e08a(void)

{
  undefined2 uVar1;
  ushort uVar2;
  short sVar3;
  int unaff_A4;

  if (DAT_ffffdb16 < 0x70) {
    uVar2 = FUN_000026aa();
    if (((DAT_ffffdb18 == 0) || (0x37 < uVar2)) && (0x1b < uVar2)) {
      sVar3 = 0x100;
    } else {
      sVar3 = -0x100;
    }
    if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
      sVar3 = -sVar3;
    }
    *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar3;
    return;
  }
  uVar1 = 0x100;
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  if (*(ushort *)(&DAT_ffffbc76 + unaff_A4) <
      *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    uVar1 = 0xff00;
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  }
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = uVar1;
  return;
}

undefined4 FUN_0001e0e8(void)

{
  undefined4 uVar1;
  int unaff_A4;

  uVar1 = FUN_00018870();
  if (((&comp_func_offset[0].unk4)[unaff_A4] & 0x80) != 0) {
    FUN_0001e118();
    uVar1 = 0xffffffff;
  }
  return uVar1;
}

void FUN_0001e118(void)

{
  short *psVar1;
  short sVar2;
  int unaff_A4;

  sVar2 = -0x100;
  if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    sVar2 = 0x100;
  }
  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  *psVar1 = sVar2 + *psVar1;
  if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
    if (*(ushort *)((int)&comp_vel[0].x + unaff_A4) < 0xfe01) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfe00;
    }
  } else if (0x200 < *(ushort *)((int)&comp_vel[0].x + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x200;
    return;
  }
  return;
}

ushort FUN_0001e134(void)

{
  uint uVar1;
  ushort uVar2;
  int unaff_A4;

  uVar1 = FUN_00001770();
  if ((uVar1 & 0x80) == 0) {
    uVar2 = DAT_ffffdb16;
    if (DAT_ffffdb18 == 0) {
      if (((0x1b < DAT_ffffdb16) && (DAT_ffffdb16 < 0x38)) &&
          (0x2b < DAT_ffffdb16))
        goto LAB_0001e168;
    } else if ((0x2f < DAT_ffffdb16) && (DAT_ffffdb16 < 0x38)) {
    LAB_0001e168:
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
      return uVar2;
    }
  }
  return 0;
}

void FUN_0001e174(void)

{
  int unaff_A4;
  bool bVar1;

  bVar1 = (&comp_func_offset[0].unk1)[unaff_A4] == 0x41;
  if (!bVar1) {
    FUN_0001e188();
    if (!bVar1) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
    }
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_0001e188(void)

{
  if ((((_DAT_ffffdb14 < 0) && ((short)(_DAT_ffffdb14 + 2) < 0)) &&
       (-0x51 < (short)(_DAT_ffffdb14 + 2))) &&
      (DAT_ffffdb16 < 0x20)) {
    return 0xffffffff;
  }
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

ushort FUN_0001e1a8(void)

{
  ushort uVar1;
  word wVar2;
  ushort uVar3;
  int unaff_A4;

  if (DAT_ffffdb18 < 8) {
    if (_DAT_ffffdb12 < 0) {
      if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) == 0) {
        return 0;
      }
    } else if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
      return 0;
    }
    uVar3 = 0x28;
    if ((&comp_func_offset[0].unk1)[unaff_A4] != 0x41) {
      uVar3 = 0x24;
    }
    if (uVar3 < DAT_ffffdb16) {
      if (0x2f < DAT_ffffdb16) {
        return 0;
      }
      wVar2 = rand();
      if (-1 < (short)(wVar2 * 2)) {
        return 0;
      }
    } else if (DAT_ffffdb16 < 0x1c) {
      return 0;
    }
    uVar3 = FUN_00001770();
    if ((uVar3 & 0x100) == 0) {
      if ((&comp_func_offset[0].unk1)[unaff_A4] == 0x41)
        goto LAB_0001e230;
      wVar2 = rand();
      uVar1 = wVar2 & 0xf00;
      uVar3 = 0;
    } else {
      uVar3 = (ushort)(comp_state_a ^ (&comp_state_a)[unaff_A4]);
      if (((comp_state_a ^ (&comp_state_a)[unaff_A4]) & ENTITY_STATE_A_08) == 0)
        goto LAB_0001e230;
      wVar2 = rand();
      uVar1 = wVar2 & 0x3e;
      uVar3 = wVar2 & 0x3e;
    }
    if (uVar1 == 0) {
    LAB_0001e230:
      *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
      return uVar3;
    }
  }
  return 0;
}

ushort FUN_0001e23c(void)

{
  ushort uVar1;
  int unaff_A4;

  if (((&comp_func_offset[0].unk1)[unaff_A4] == 0x43) && (DAT_ffffdb18 == 0)) {
    uVar1 = DAT_ffffdb16;
    if ((DAT_ffffdb16 < 0x70) && (0x47 < DAT_ffffdb16)) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 7;
      return uVar1;
    }
  }
  return 0;
}

void FUN_0001e266(void)

{
  uint uVar1;
  short sVar2;
  ushort uVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  int unaff_A6;

  ecs_jump_table(unaff_A4);
  uVar1 = *(uint *)((int)&comp_state + unaff_A6) | 0x8ec0007;
  *(uint *)((int)&comp_state + unaff_A6) = uVar1;
  if (uVar1 == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      uVar3 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
      if ((short)uVar3 < 0) {
        uVar3 = -uVar3;
      }
      if (0x4f < uVar3) {
        *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
        return;
      }
      *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    }
  }
  return;
}

void FUN_0001e278(void)

{
  byte bVar1;
  short sVar2;
  ushort uVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      uVar3 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
      if ((short)uVar3 < 0) {
        uVar3 = -uVar3;
      }
      if (0x4f < uVar3) {
        *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
        return;
      }
      *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    }
  }
  return;
}

void FUN_0001e2c8(void)

{
  byte bVar1;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar2;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  uVar2 = (bVar1 & 0x80) == 0;
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bool)uVar2) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    if (*(ushort *)(&DAT_ffffbc76 + unaff_A4) <
        *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    }
    ecs_anim_unk_2(unaff_A4, unaff_A5, 10);
    FUN_000022a2();
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfb00;
    uVar2 = false;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00002248();
  if (!(bool)uVar2) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001e318(void)

{
  byte bVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_sprite_face_asha(unaff_A4);
    (&comp_collision_related)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if (((&comp_collision_related)[unaff_A4] == '\0') &&
      (((&comp_state_1_a)[unaff_A4] & 0x20) != 0)) {
    (&comp_collision_related)[unaff_A4] = 0xff;
    FUN_000023a0();
    // WARNING: Bad instruction - Truncating control flow here
    halt_baddata();
  }
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001e36e(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_0001e37e(void)

{
  int unaff_A4;

  FUN_00001d8a();
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) * 2 +
      *(short *)((int)&comp_pos_y + unaff_A4);
  return;
}

void FUN_0001e38e(void)

{
  byte bVar1;
  short sVar2;
  ushort uVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined2 *)(&DAT_ffffbd76 + unaff_A4) =
        *(undefined2 *)((int)&comp_pos_x + unaff_A4);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 8;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
    uVar3 = comp_pos_y.fixed.i - *(short *)((int)&comp_pos_y + unaff_A4);
    if ((-1 < (short)uVar3) && (uVar3 < 0xa0)) {
      uVar3 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
      if ((short)uVar3 < 0) {
        uVar3 = -uVar3;
      }
      if (uVar3 < 0x70) {
        *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
        return;
      }
    }
    FUN_000159fc();
  }
  return;
}

void FUN_0001e3f2(void)

{
  byte bVar1;
  char cVar2;
  word wVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0;
    (&comp_collision_related)[unaff_A4] = 10;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  wVar3 = angle_sin((angle_t)(*(ushort *)(&comp_unk_4 + unaff_A4) >> 2));
  *(short *)((int)&comp_pos_x + unaff_A4) =
      *(short *)(&DAT_ffffbd76 + unaff_A4) +
      (short)((uint)((short)wVar3 * 0xc0) >> 0x10);
  wVar3 = angle_sin((angle_t)(*(ushort *)(&comp_unk_4 + unaff_A4) >> 1));
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
      *(short *)(&DAT_ffffbc78 + unaff_A4) +
      (short)((uint)((short)wVar3 * 0x60) >> 0x10);
  *(short *)(&comp_unk_4 + unaff_A4) = *(short *)(&comp_unk_4 + unaff_A4) + 10;
  cVar2 = (&comp_collision_related)[unaff_A4] + -1;
  (&comp_collision_related)[unaff_A4] = cVar2;
  if (cVar2 == '\0') {
    FUN_00002678();
    if ((0x9f < DAT_ffffdb16) || (0x9f < DAT_ffffdb18)) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
      return;
    }
    (&comp_collision_related)[unaff_A4] = 0x78;
    FUN_000023a0();
  }
  return;
}

void FUN_0001e484(void)

{
  byte bVar1;
  short sVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    FUN_00002606();
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  player_update_pos(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001e4c0(void)

{
  byte *extraout_A0;
  uint *unaff_A4;

  ecs_jump_table((entity_id_t)unaff_A4);
  *extraout_A0 = *extraout_A0 | 1;
  *unaff_A4 = *unaff_A4 | 0xe64eb8;
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_0001e4d4(void)

{
  int unaff_A4;

  FUN_00001d8a();
  *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001e4e0(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if (*(short *)(&comp_unk_4 + unaff_A4) != 0) {
    *(short *)(&comp_unk_4 + unaff_A4) =
        *(short *)(&comp_unk_4 + unaff_A4) + -1;
  }
  player_update_pos(unaff_A4);
  FUN_00002678();
  FUN_000026aa();
  func_0x0001e5f8();
  sVar3 = 0x20;
  if (DAT_ffffdb16 < 0x30) {
    sVar3 = -0x20;
  LAB_0001e538:
    if (_DAT_ffffdb12 < 0) {
      sVar3 = -sVar3;
    }
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = sVar3 + *psVar1;
    if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
      if (*(ushort *)((int)&comp_vel[0].x + unaff_A4) < 0xfd01) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfd00;
      }
    } else if (0x300 < *(ushort *)((int)&comp_vel[0].x + unaff_A4)) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x300;
      return;
    }
    return;
  }
  if (0x47 < DAT_ffffdb16) {
    if (DAT_ffffdb16 < 0x60) {
      if (*(short *)(&comp_unk_4 + unaff_A4) == 0) {
        *(undefined1 *)((int)&comp_state + unaff_A4) = 7;
      }
      return;
    }
    goto LAB_0001e538;
  }
  if (*(short *)((int)&comp_vel[0].x + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    return;
  }
  sVar3 = *(short *)((int)&comp_vel[0].x + unaff_A4);
  if (sVar3 == 0) {
    return;
  }
  if (sVar3 < 0) {
    sVar3 = sVar3 + 0x20;
    if (sVar3 < 0)
      goto LAB_0000226c;
  } else {
    sVar3 = sVar3 + -0x20;
    if (-1 < sVar3)
      goto LAB_0000226c;
  }
  sVar3 = 0;
LAB_0000226c:
  *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar3;
  return;
}

void FUN_0001e560(void)

{
  byte bVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_000186f4(unaff_A4, &UNK_0001e59c);
  FUN_00002238();
  FUN_00018758(unaff_A4, &UNK_0001e59c);
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_0001e5aa(void)

{
  byte bVar1;
  entity_state_1_a_t eVar2;
  short sVar3;
  ushort uVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 *unaff_A6;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x3c;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  eVar2 = (&comp_state_1_a)[unaff_A4];
  (&comp_state_1_a)[unaff_A4] = eVar2 & 0xdf;
  if ((eVar2 & 0x20) != 0) {
    uVar4 = 0;
    do {
      sVar3 = FUN_000023a0();
      *unaff_A6 = 8;
      if (sVar3 < 0)
        break;
      (&comp_collision_related)[sVar3] = (char)uVar4;
      uVar4 = uVar4 + 1;
      unaff_A6 = unaff_A6 + 1;
    } while (uVar4 < 5);
  }
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_0001e622(void)

{
  byte bVar1;
  short sVar2;
  undefined2 uVar3;
  int extraout_A0;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar4;

  ecs_jump_table(unaff_A4);
  *(undefined2 *)(extraout_A0 + 0xf6) = *(undefined2 *)(extraout_A0 + 0xf6);
  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
  }
  uVar4 = 0;
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002554();
  if ((bool)uVar4) {
    uVar3 = 8;
    if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      uVar3 = 0xfff8;
    }
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = uVar3;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    return;
  }
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    }
  }
  return;
}

void FUN_0001e634(void)

{
  byte bVar1;
  short sVar2;
  undefined2 uVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar4;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
  }
  uVar4 = 0;
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002554();
  if ((bool)uVar4) {
    uVar3 = 8;
    if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      uVar3 = 0xfff8;
    }
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = uVar3;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    return;
  }
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    }
  }
  return;
}

void FUN_0001e68e(void)

{
  short *psVar1;
  byte bVar2;
  short sVar4;
  uint uVar3;
  short sVar5;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar6;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    *(undefined2 *)(&DAT_ffffbd76 + unaff_A4) =
        *(undefined2 *)((int)&comp_pos_x + unaff_A4);
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x78;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  sVar4 = 8;
  if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
    sVar4 = -8;
  }
  sVar5 = 0x20;
  if ((ushort)(*(short *)(&DAT_ffffbd76 + unaff_A4) + sVar4) <
      *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    sVar5 = -0x20;
  }
  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  *psVar1 = sVar5 + *psVar1;
  FUN_00002590();
  uVar3 = func_0x0001e7ae();
  bVar6 = (uVar3 & 4) == 0;
  if (!bVar6) {
    FUN_00002554();
    if ((bVar6) &&
        (-1 <
         (short)(comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4) ^
                 *(ushort *)((int)&comp_vel[0].x + unaff_A4)))) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
      return;
    }
  }
  sVar4 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar4;
  bVar6 = sVar4 == 0;
  if (bVar6) {
    FUN_00002248();
    if (bVar6) {
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
      bVar6 = false;
      FUN_000159f2();
      if (bVar6) {
        FUN_000159ec();
        if (bVar6) {
          (&DAT_ffffcf9f)[*(short *)((int)&comp_unk_8 + unaff_A4)] =
              (&DAT_ffffcf9f)[*(short *)((int)&comp_unk_8 + unaff_A4)] + -1;
          (&comp_has_func_maybe)[unaff_A4] = 0;
        }
      }
      return;
    }
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_0001e71c(void)

{
  short *psVar1;
  byte bVar2;
  ushort uVar3;
  byte bVar4;
  byte bVar5;
  char cVar6;
  undefined4 extraout_D0;
  short sVar7;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar8;
  bool bVar9;

  bVar5 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar5 | 0x80;
  if ((bVar5 & 0x80) == 0) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    }
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
  }
  uVar8 = ((&comp_state_1_a)[unaff_A4] & 0x20) == 0;
  if ((bool)uVar8) {
    FUN_00001fd2();
    if (((&comp_unk_11)[unaff_A4] == '\0') &&
        (((&comp_func_offset[0].unk4)[unaff_A4] & 1) != 0)) {
      bVar5 = DAT_ffffde0e;
      if (((&comp_func_offset[0].unk4)[unaff_A4] & 4) != 0) {
        bVar5 = DAT_ffffde0f;
      }
      bVar2 = (&comp_collected_item_id_maybe)[unaff_A4];
      bVar4 = bVar2 - bVar5;
      (&comp_collected_item_id_maybe)[unaff_A4] = bVar4;
      if (bVar2 < bVar5 || bVar4 == 0) {
        *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
      } else {
        cVar6 = ecs_unk_3(unaff_A4, 1);
        if (cVar6 == -1) {
          audio_play(SOUND_ID_DAMAGE_2);
          (&comp_unk_11)[unaff_A4] = 0x40;
          FUN_0000231c();
          return;
        }
        *(undefined1 *)((int)&comp_state + unaff_A4) = 2;
      }
    }
    return;
  }
  FUN_00002140();
  if ((!(bool)uVar8) &&
      (uVar3 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4) ^
               *(ushort *)((int)&comp_vel[0].x + unaff_A4),
       uVar8 = uVar3 == 0,
       -1 < (short)uVar3)) {
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    sVar7 = -*psVar1;
    *psVar1 = sVar7;
    uVar8 = sVar7 == 0;
  }
  FUN_00002248();
  if ((bool)uVar8)
    goto LAB_0001e7a2;
  bVar9 = *(short *)(&comp_unk_4 + unaff_A4) == 0;
  if (bVar9) {
  LAB_0001e77e:
    FUN_00002554();
    if (!bVar9) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
      return;
    }
  } else {
    sVar7 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar7;
    bVar9 = sVar7 == 0;
    if (bVar9)
      goto LAB_0001e77e;
  }
  sVar7 = 0x40;
  if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
    sVar7 = -0x40;
  }
  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  *psVar1 = sVar7 + *psVar1;
  FUN_00002590();
LAB_0001e7a2:
  FUN_000159fc();
  if (-1 < (char)(&comp_has_func_maybe)[unaff_A4]) {
    return;
  }
  *(undefined2 *)(&comp_unk_1 + unaff_A4) =
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4);
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  sVar7 = *(short *)(&comp_unk_1 + unaff_A4);
  if ((((&component_unknown_5)[unaff_A4] |
        (&component_collision_flags)[unaff_A4]) &
       3) != 0) {
    if ((CONCAT31((int3)((uint)extraout_D0 >> 8),
                  (&component_unknown_5)[unaff_A4] |
                      (&component_collision_flags)[unaff_A4]) &
         1 << (uint)(sVar7 < 0)) != 0) {
      sVar7 = -sVar7;
    }
    *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar7;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001e7e0(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_0001e7f2(void)

{
  byte bVar1;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  bool bVar2;
  undefined1 uVar3;

  uVar3 = 0;
  if (-1 < *(char *)((int)&comp_state + unaff_A4)) {
    unaff_D6w = *(short *)((int)&comp_pos_x + unaff_A4) - 4;
    unaff_D7w = *(short *)((int)&comp_pos_y + unaff_A4) - 0x10;
    uVar3 = 0;
    ecs_collect_or_spawn_item_maybe(unaff_D6w, unaff_D7w, 0x30);
  }
  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    FUN_00001ec8();
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff00;
    uVar3 = false;
  }
  FUN_000021c2(unaff_A4, false, (bool)uVar3);
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  bVar2 = *(short *)((int)&comp_anim_tick + unaff_A4) == 0;
  if (bVar2) {
    FUN_00002248();
    if (!bVar2) {
      *(undefined2 *)(&comp_has_func_maybe + unaff_A4) =
          *(undefined2 *)(&comp_has_func_maybe + unaff_A4) & 0xf7fb;
      uVar3 = ecs_unk_3(unaff_A4, 1);
      *(undefined1 *)((int)&comp_state + unaff_A4) = uVar3;
    }
  }
  return;
}

void FUN_0001e810(void)

{
  byte bVar1;
  short sVar2;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar3;
  bool bVar4;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
  }
  uVar3 = 0;
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002256();
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  func_0x0001e866();
  if ((bool)uVar3) {
    sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
    bVar4 = sVar2 == 0;
    if (bVar4) {
      FUN_00002248();
      if (bVar4) {
        *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
        return;
      }
      FUN_000159fc();
      if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
        *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
      }
    }
  }
  return;
}

void FUN_0001e884(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar4;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    FUN_000022a2();
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
  }
  uVar4 = 0;
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00002248();
  if ((bool)uVar4)
    goto LAB_0001e8ec;
  func_0x0001e866();
  if (!(bool)uVar4) {
    return;
  }
  if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
    if (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
        (ushort)(*(short *)(&DAT_ffffbc76 + unaff_A4) - 0x20U))
      goto LAB_0001e8dc;
  } else if ((ushort)(*(short *)(&DAT_ffffbc76 + unaff_A4) + 0x20U) <
             *(ushort *)((int)&comp_pos_x + unaff_A4)) {
  LAB_0001e8dc:
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = -*psVar1;
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] ^ ENTITY_STATE_A_08;
  }
  sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
  if (sVar3 != 0) {
    return;
  }
LAB_0001e8ec:
  *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  return;
}

void FUN_0001e8f4(void)

{
  byte bVar1;
  short sVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar3;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_sprite_face_asha(unaff_A4);
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
    *(int16_t *)(&comp_unk_1 + unaff_A4) =
        (comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4)) * 4;
    (&comp_collision_related)[unaff_A4] = 5;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 1;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if ((((&comp_collision_related)[unaff_A4] != '\0') &&
       (((&comp_state_1_a)[unaff_A4] & 0x20) == 0)) &&
      (sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1,
       *(short *)(&comp_unk_4 + unaff_A4) = sVar2,
       sVar2 == 0)) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 5;
    bVar1 = (&comp_collision_related)[unaff_A4] - 1;
    (&comp_collision_related)[unaff_A4] = bVar1;
    bVar3 = (short)((ushort)bVar1 << 8) < 0;
    sVar2 = FUN_000023a0();
    if (!bVar3) {
      *(undefined2 *)((int)&comp_vel[0].x + (int)sVar2) =
          *(undefined2 *)(&comp_unk_1 + unaff_A4);
    }
  }
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_0001e968(void)

{
  short sVar1;
  byte unaff_D7b;
  int unaff_A2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_jump_table(unaff_A4);
  *(ushort *)(unaff_A2 + -2) = *(ushort *)(unaff_A2 + -2) | 0x8ec;
  if ((unaff_D7b | 0x66) == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
    ecs_sprite_face_asha(unaff_A4);
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 8;
      FUN_00002678();
      FUN_000026aa();
      if ((DAT_ffffdb18 < 0x38) && (DAT_ffffdb16 < 0x50)) {
        *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
      }
    }
  }
  return;
}

void FUN_0001e976(void)

{
  byte bVar1;
  short sVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
    ecs_sprite_face_asha(unaff_A4);
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 8;
      FUN_00002678();
      FUN_000026aa();
      if ((DAT_ffffdb18 < 0x38) && (DAT_ffffdb16 < 0x50)) {
        *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
      }
    }
  }
  return;
}

void FUN_0001e9ce(void)

{
  byte bVar1;
  char cVar2;
  word wVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar4;
  bool bVar5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  uVar4 = (bVar1 & 0x80) == 0;
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bool)uVar4) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x78;
    ecs_sprite_face_asha(unaff_A4);
    (&comp_collision_related)[unaff_A4] = 8;
    uVar4 = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_000186f4(unaff_A4, &UNK_0001ea84);
  FUN_00002238();
  FUN_00002248();
  if (!(bool)uVar4) {
    FUN_000022a2();
  }
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  bVar5 = *(short *)(&comp_unk_4 + unaff_A4) == 0;
  if (bVar5) {
    FUN_00002248();
    if (!bVar5) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
      return;
    }
  } else {
    *(short *)(&comp_unk_4 + unaff_A4) =
        *(short *)(&comp_unk_4 + unaff_A4) + -1;
  }
  cVar2 = (&comp_collision_related)[unaff_A4] + -1;
  (&comp_collision_related)[unaff_A4] = cVar2;
  if (cVar2 == '\0') {
    (&comp_collision_related)[unaff_A4] = 8;
    bVar1 = (&component_unknown_5)[unaff_A4] |
            (&component_collision_flags)[unaff_A4];
    if ((bVar1 & 1) != 0) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
      return;
    }
    uVar4 = bVar1 >> 2 == 0;
    if ((bVar1 >> 1 & 1) != 0) {
      (&comp_state_a)[unaff_A4] =
          (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
      return;
    }
    FUN_00002678();
    FUN_000026aa();
    FUN_00002248();
    if ((!(bool)uVar4) && (DAT_ffffdb16 < 0x30)) {
      wVar3 = rand();
      if ((wVar3 & 2) != 0) {
        *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfb00;
      }
    }
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001ea92(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_0001eaa4(void)

{
  short sVar1;
  ushort uVar2;
  word wVar3;
  word wVar4;
  short unaff_D6w;
  short unaff_D7w;
  int iVar5;
  int unaff_A4;
  entity_id_t self;
  int iVar6;
  anim_item_t *unaff_A5;

  FUN_00001d8a();
  *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
  FUN_0000281e();
  self = (entity_id_t) *
         (short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  (&comp_state_a)[self] = (&comp_state_a)[self] | 0x80;
  *(undefined2 *)((int)&comp_unk_3 + self) = 8;
  ecs_anim_unk_2(self, unaff_A5, 0x10);
  while (sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + self),
         -1 < sVar1) {
    self = (entity_id_t)sVar1;
    (&comp_state_a)[self] = (&comp_state_a)[self] | 0x80;
    *(undefined2 *)((int)&comp_unk_3 + self) = 10;
    ecs_anim_unk_2(self, unaff_A5, 0xe);
  }
  iVar6 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + self);
  func_0x0001ecbc();
  FUN_00000bfe();
  if (*(char *)(iVar6 + -0x4689) != '\0') {
    func_0x0001ee12();
    wVar3 = angle_sin((&DAT_ffffb976)[iVar6] + 0x40);
    if (((&comp_state_a)[iVar6] & ENTITY_STATE_A_08) != 0) {
      wVar3 = -wVar3;
    }
    wVar4 = angle_sin((&DAT_ffffb976)[iVar6]);
    uVar2 = (ushort)(byte)(&DAT_ffffb978)[iVar6];
    iVar5 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar6);
    sVar1 = (byte)(&DAT_ffffb978)[iVar6] + 0xe;
    *(short *)((int)&comp_pos_x + iVar5) =
        unaff_D6w + (short)((uint)((int)sVar1 * (int)(short)wVar3 * 4) >> 0x10);
    *(short *)((int)&comp_pos_y + iVar5) =
        unaff_D7w + (short)((uint)((int)sVar1 * (int)(short)wVar4 * 4) >> 0x10);
    while (true) {
      if ((short)uVar2 < 4) {
        while (sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                                  iVar5),
               -1 < sVar1) {
          iVar5 = (int)sVar1;
          (&comp_has_func_maybe)[iVar5] = (&comp_has_func_maybe)[iVar5] | 8;
        }
        return;
      }
      sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar5);
      if (sVar1 < 0)
        break;
      iVar5 = (int)sVar1;
      (&comp_has_func_maybe)[iVar5] = (&comp_has_func_maybe)[iVar5] & 0xf7;
      *(short *)((int)&comp_pos_x + iVar5) =
          unaff_D6w +
          (short)((uint)((int)(short)uVar2 * (int)(short)wVar3 * 4) >> 0x10);
      *(short *)((int)&comp_pos_y + iVar5) =
          unaff_D7w +
          (short)((uint)((int)(short)uVar2 * (int)(short)wVar4 * 4) >> 0x10);
      uVar2 = uVar2 - 8;
    }
    return;
  }
  func_0x0001ee12();
  iVar6 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar6);
  *(short *)((int)&comp_pos_x + iVar6) = unaff_D6w;
  *(short *)((int)&comp_pos_y + iVar6) = unaff_D7w;
  return;
}

void FUN_0001eaf0(void)

{
  short sVar1;
  byte bVar2;
  entity_id_t unaff_A4;
  undefined1 uVar3;
  undefined1 in_CF;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  uVar3 = (bVar2 & 0x80) == 0;
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bool)uVar3) {
    *(undefined2 *)((int)&comp_anim_speed + unaff_A4) = 0x100;
    FUN_00001ec8();
    sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
    FUN_0000231c();
    unaff_A4 =
        (entity_id_t) *
        (short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + (int)sVar1);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    uVar3 = 1;
    in_CF = 0;
    func_0x0001ecbc();
  }
  FUN_000021c2(unaff_A4, (bool)uVar3, (bool)in_CF);
  player_update_pos_x(unaff_A4);
  func_0x0001ed12();
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined2 *)(&comp_has_func_maybe + unaff_A4) =
        *(undefined2 *)(&comp_has_func_maybe + unaff_A4) & 0xf7fb;
    *(undefined2 *)(&comp_has_func_maybe +
                    *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                               unaff_A4)) =
        *(undefined2 *)(&comp_has_func_maybe +
                        *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                                   unaff_A4)) &
        0xf7fb;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

// WARNING: Possible PIC construction at 0x0001ebac: Changing call to branch
// WARNING: Removing unreachable block (ram,0x0001ebb0)
// WARNING: Removing unreachable block (ram,0x0001ebcc)
// WARNING: Removing unreachable block (ram,0x0001ebd2)
// WARNING: Removing unreachable block (ram,0x00002258)
// WARNING: Removing unreachable block (ram,0x0000225e)
// WARNING: Removing unreachable block (ram,0x00002266)
// WARNING: Removing unreachable block (ram,0x00002260)
// WARNING: Removing unreachable block (ram,0x00002264)
// WARNING: Removing unreachable block (ram,0x0000226a)
// WARNING: Removing unreachable block (ram,0x0000226c)
// WARNING: Removing unreachable block (ram,0x00002270)
// WARNING: Removing unreachable block (ram,0x0001ebc8)
// WARNING: Removing unreachable block (ram,0x0001ebd6)
// WARNING: Removing unreachable block (ram,0x0001ebdc)
// WARNING: Removing unreachable block (ram,0x0001ebde)
// WARNING: Removing unreachable block (ram,0x00002590)
// WARNING: Removing unreachable block (ram,0x000025a2)
// WARNING: Removing unreachable block (ram,0x000025aa)
// WARNING: Removing unreachable block (ram,0x00002596)
// WARNING: Removing unreachable block (ram,0x000025ae)
// WARNING: Removing unreachable block (ram,0x0000259c)

void FUN_0001eb42(void)

{
  short sVar1;
  angle_t angle;
  byte bVar2;
  char cVar3;
  ushort uVar4;
  word wVar5;
  word wVar6;
  short unaff_D6w;
  short unaff_D7w;
  int iVar7;
  entity_id_t unaff_A4;
  ulong ctx;
  anim_item_t *unaff_A5;
  undefined4 uStack_4;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x5a;
    uStack_4 = 0x1eb54;
    func_0x0001ecd6();
    (&DAT_ffffb978)[unaff_A4] = 1;
    uStack_4 = 0x1eb60;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  uStack_4 = 0x1eb64;
  FUN_00001fd2();
  uStack_4 = 0x1eb68;
  FUN_000021e2(unaff_A4);
  sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  uStack_4 = 0x1eb70;
  FUN_00002140();
  ctx = (ulong) *
        (short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + (int)sVar1);
  uStack_4 = 0x1eb78;
  player_update_pos(ctx);
  (&DAT_ffffb976)[ctx] = (&DAT_ffffb976)[ctx] + '\x06';
  if (*(short *)(&comp_unk_4 + ctx) == 0) {
    cVar3 = (&DAT_ffffb978)[ctx] + -1;
    (&DAT_ffffb978)[ctx] = cVar3;
    if (cVar3 == '\0') {
      *(undefined1 *)((int)&comp_state + ctx) = 6;
      uStack_4 = 0x1eba8;
      func_0x0001ecbc();
      goto SUB_0001ed12;
    }
  } else {
    *(short *)(&comp_unk_4 + ctx) = *(short *)(&comp_unk_4 + ctx) + -1;
    (&DAT_ffffb978)[ctx] = (&DAT_ffffb978)[ctx] + '\x01';
    if (0x1c < (byte)(&DAT_ffffb978)[ctx]) {
      (&DAT_ffffb978)[ctx] = 0x1c;
    }
  }
  register0x0000003c = (BADSPACEBASE *)&uStack_4;
  uStack_4 = 0x1ebb0;
SUB_0001ed12:
  *(undefined4 *)((int)register0x0000003c + -4) = 0x1ed16;
  FUN_00000bfe();
  if (*(char *)(ctx - 0x4689) == '\0') {
    *(undefined4 *)((int)register0x0000003c + -4) = 0x1ed24;
    func_0x0001ee12();
    iVar7 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + ctx);
    *(short *)((int)&comp_pos_x + iVar7) = unaff_D6w;
    *(short *)((int)&comp_pos_y + iVar7) = unaff_D7w;
    return;
  }
  *(undefined4 *)((int)register0x0000003c + -4) = 0x1ed3a;
  func_0x0001ee12();
  cVar3 = (&DAT_ffffb976)[ctx];
  *(undefined4 *)((int)register0x0000003c + -4) = 0x1ed44;
  wVar5 = angle_sin(cVar3 + 0x40);
  if (((&comp_state_a)[ctx] & ENTITY_STATE_A_08) != 0) {
    wVar5 = -wVar5;
  }
  angle = (&DAT_ffffb976)[ctx];
  *(undefined4 *)((int)register0x0000003c + -4) = 0x1ed58;
  wVar6 = angle_sin(angle);
  uVar4 = (ushort)(byte)(&DAT_ffffb978)[ctx];
  iVar7 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + ctx);
  sVar1 = (byte)(&DAT_ffffb978)[ctx] + 0xe;
  *(short *)((int)&comp_pos_x + iVar7) =
      unaff_D6w + (short)((uint)((int)sVar1 * (int)(short)wVar5 * 4) >> 0x10);
  *(short *)((int)&comp_pos_y + iVar7) =
      unaff_D7w + (short)((uint)((int)sVar1 * (int)(short)wVar6 * 4) >> 0x10);
  while (true) {
    if ((short)uVar4 < 4) {
      while (sVar1 =
                 *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar7),
             -1 < sVar1) {
        iVar7 = (int)sVar1;
        (&comp_has_func_maybe)[iVar7] = (&comp_has_func_maybe)[iVar7] | 8;
      }
      return;
    }
    sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar7);
    if (sVar1 < 0)
      break;
    iVar7 = (int)sVar1;
    (&comp_has_func_maybe)[iVar7] = (&comp_has_func_maybe)[iVar7] & 0xf7;
    *(short *)((int)&comp_pos_x + iVar7) =
        unaff_D6w +
        (short)((uint)((int)(short)uVar4 * (int)(short)wVar5 * 4) >> 0x10);
    *(short *)((int)&comp_pos_y + iVar7) =
        unaff_D7w +
        (short)((uint)((int)(short)uVar4 * (int)(short)wVar6 * 4) >> 0x10);
    uVar4 = uVar4 - 8;
  }
  return;
}

ushort FUN_0001ebea(void)

{
  char cVar1;
  byte bVar2;
  short sVar3;
  byte bVar4;
  ushort uVar5;
  word wVar6;
  word wVar7;
  short unaff_D6w;
  short unaff_D7w;
  int iVar8;
  entity_id_t unaff_A4;
  entity_id_t self;
  int iVar9;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    (&comp_collision_related)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  self = (entity_id_t) *
         (short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  FUN_000186a0(self);
  if (((&comp_func_offset[0].unk4)[self] & 8) == 0) {
    FUN_00002140();
  }
  iVar9 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + self);
  cVar1 = (&comp_collision_related)[iVar9];
  if (cVar1 == '\0') {
    (&comp_collision_related)[iVar9] =
        (&comp_collision_related)[iVar9] + '\x01';
  } else if (cVar1 == '\x01') {
    if (((&comp_state_1_a)[iVar9] & 0x20) != 0) {
      (&comp_collision_related)[iVar9] =
          (&comp_collision_related)[iVar9] + '\x01';
      *(undefined2 *)((int)&comp_anim_speed + iVar9) = 0;
      func_0x0001ecd6();
      wVar6 = rand();
      (&DAT_ffffb976)[iVar9] = ((byte)wVar6 & 0xf) + 0x14;
      (&DAT_ffffb978)[iVar9] = 3;
    }
  } else if (cVar1 == '\x02') {
    if (((&comp_func_offset[0].unk4)[*(
             short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar9)] &
         8) == 0) {
      (&DAT_ffffb978)[iVar9] = (&DAT_ffffb978)[iVar9] + '\x06';
      if ((byte)(&DAT_ffffb978)[iVar9] < 0x3a)
        goto SUB_0001ed12;
      (&DAT_ffffb978)[iVar9] = 0x39;
    }
    (&comp_collision_related)[iVar9] =
        (&comp_collision_related)[iVar9] + '\x01';
  } else {
    if ((byte)(cVar1 - 3U) != 0) {
      if (*(short *)((int)&comp_anim_tick + iVar9) == 0) {
        *(undefined1 *)((int)&comp_state + iVar9) = 3;
      }
      return (ushort)(byte)(cVar1 - 3U);
    }
    bVar2 = (&DAT_ffffb978)[iVar9];
    bVar4 = bVar2 - 3;
    (&DAT_ffffb978)[iVar9] = bVar4;
    if (bVar2 < 3 || bVar4 == 0) {
      func_0x0001ecbc();
      (&comp_collision_related)[iVar9] =
          (&comp_collision_related)[iVar9] + '\x01';
      *(undefined2 *)((int)&comp_anim_speed + iVar9) = 0x100;
      *(undefined2 *)((int)&comp_anim_tick + iVar9) = 0x100;
    }
  }
SUB_0001ed12:
  FUN_00000bfe();
  if (*(char *)(iVar9 + -0x4689) == '\0') {
    uVar5 = func_0x0001ee12();
    iVar9 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar9);
    *(short *)((int)&comp_pos_x + iVar9) = unaff_D6w;
    *(short *)((int)&comp_pos_y + iVar9) = unaff_D7w;
    return uVar5;
  }
  func_0x0001ee12();
  wVar6 = angle_sin((&DAT_ffffb976)[iVar9] + 0x40);
  if (((&comp_state_a)[iVar9] & ENTITY_STATE_A_08) != 0) {
    wVar6 = -wVar6;
  }
  wVar7 = angle_sin((&DAT_ffffb976)[iVar9]);
  uVar5 = (ushort)(byte)(&DAT_ffffb978)[iVar9];
  iVar8 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar9);
  sVar3 = (byte)(&DAT_ffffb978)[iVar9] + 0xe;
  *(short *)((int)&comp_pos_x + iVar8) =
      unaff_D6w + (short)((uint)((int)sVar3 * (int)(short)wVar6 * 4) >> 0x10);
  *(short *)((int)&comp_pos_y + iVar8) =
      unaff_D7w + (short)((uint)((int)sVar3 * (int)(short)wVar7 * 4) >> 0x10);
  while (true) {
    if ((short)uVar5 < 4) {
      while (sVar3 =
                 *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar8),
             -1 < sVar3) {
        iVar8 = (int)sVar3;
        (&comp_has_func_maybe)[iVar8] = (&comp_has_func_maybe)[iVar8] | 8;
      }
      return uVar5;
    }
    sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar8);
    if (sVar3 < 0)
      break;
    iVar8 = (int)sVar3;
    (&comp_has_func_maybe)[iVar8] = (&comp_has_func_maybe)[iVar8] & 0xf7;
    *(short *)((int)&comp_pos_x + iVar8) =
        unaff_D6w +
        (short)((uint)((int)(short)uVar5 * (int)(short)wVar6 * 4) >> 0x10);
    *(short *)((int)&comp_pos_y + iVar8) =
        unaff_D7w +
        (short)((uint)((int)(short)uVar5 * (int)(short)wVar7 * 4) >> 0x10);
    uVar5 = uVar5 - 8;
  }
  return uVar5;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001ee44(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_0001ee56(void)

{
  byte bVar1;
  short sVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 8;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      FUN_00002566();
      *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    }
  }
  return;
}

void FUN_0001ee94(void)

{
  short *psVar1;
  byte bVar2;
  ushort uVar3;
  undefined1 uVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    FUN_000022a2();
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x200;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + -0x20;
  player_update_pos(unaff_A4);
  uVar3 = *(short *)(&DAT_ffffbc78 + unaff_A4) -
          *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  if (*(ushort *)((int)&comp_pos_y + unaff_A4) <= uVar3) {
    *(ushort *)((int)&comp_pos_y + unaff_A4) = uVar3;
    uVar3 = FUN_000024a0();
    uVar4 = 6;
    if (0x30 < uVar3) {
      uVar4 = 3;
    }
    *(undefined1 *)((int)&comp_state + unaff_A4) = uVar4;
  }
  return;
}

void FUN_0001eee8(void)

{
  byte bVar1;
  entity_state_1_a_t eVar2;
  undefined1 *extraout_A0;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_sprite_face_asha(unaff_A4);
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    return;
  }
  eVar2 = (&comp_state_1_a)[unaff_A4];
  (&comp_state_1_a)[unaff_A4] = eVar2 & 0xdf;
  if ((eVar2 & 0x20) != 0) {
    FUN_000023a0();
    *extraout_A0 = *extraout_A0;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001ef22(void)

{
  entity_state_1_a_t eVar1;
  char cVar2;
  char *pcVar3;
  uint extraout_D0;
  short sVar5;
  uint uVar4;
  short unaff_D2w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  int unaff_A6;
  undefined1 uVar6;

  ecs_jump_table(unaff_A4);
  uVar4 = extraout_D0 | 0xe;
  pcVar3 = (char *)(uint) * (byte *)(unaff_A4 + 7 + (int)(short)uVar4);
  if ((int)uVar4 < (int)*pcVar3 || (int)pcVar3[1] < (int)uVar4) {
    __m68k_trap(6);
  }
  if (unaff_D2w == *(short *)(unaff_A6 + -2)) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    *(undefined2 *)(&DAT_ffffbe78 + unaff_A4) = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if (*(short *)(&DAT_ffffbe78 + unaff_A4) == 0) {
    if ((&comp_unk_11)[unaff_A4] != '\0') {
      (&DAT_ffffbe78)[unaff_A4] = 0xff;
    }
  } else if ((&comp_unk_11)[unaff_A4] == '\0')
    goto LAB_0001f012;
  if (*(short *)(&comp_unk_4 + unaff_A4) == 0) {
    eVar1 = (&comp_state_1_a)[unaff_A4];
    (&comp_state_1_a)[unaff_A4] = eVar1 & 0xdf;
    if ((eVar1 & 0x20) != 0) {
      FUN_00002678();
      sVar5 = 0x400;
      if (DAT_ffffdb16 < 0x20) {
        sVar5 = -0x400;
      }
      if (_DAT_ffffdb12 < 0) {
        sVar5 = -sVar5;
      }
      *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar5;
      *(short *)((int)component_pos_old_x + unaff_A4) =
          *(short *)((int)&comp_pos_x + unaff_A4);
      uVar6 = *(short *)((int)&comp_pos_x + unaff_A4) == 0;
      player_update_pos_x(unaff_A4);
      FUN_00002500();
      if ((bool)uVar6) {
        cVar2 = (&comp_collision_related)[unaff_A4] + -1;
        (&comp_collision_related)[unaff_A4] = cVar2;
        if (cVar2 != '\0') {
          return;
        }
      } else {
        *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
            *(undefined2 *)((int)component_pos_old_x + unaff_A4);
      }
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x10;
    }
  } else {
    sVar5 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar5;
    if ((sVar5 == 0) &&
        (FUN_000159fc(), (char)(&comp_has_func_maybe)[unaff_A4] < '\0')) {
      FUN_00002678();
      FUN_000026aa();
      if (DAT_ffffdb18 < 0x18) {
        if ((DAT_ffffdb16 < 0x20) || (0x3f < DAT_ffffdb16)) {
          (&comp_collision_related)[unaff_A4] = 4;
          (&comp_state_1_a)[unaff_A4] = (&comp_state_1_a)[unaff_A4] & 0xdf;
          return;
        }
        uVar4 = FUN_00001770();
        if ((uVar4 & 0x100) == 0) {
        LAB_0001f012:
          *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
          return;
        }
      }
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x10;
      return;
    }
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001ef34(void)

{
  byte bVar1;
  entity_state_1_a_t eVar2;
  char cVar3;
  short sVar5;
  uint uVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar6;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    *(undefined2 *)(&DAT_ffffbe78 + unaff_A4) = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if (*(short *)(&DAT_ffffbe78 + unaff_A4) == 0) {
    if ((&comp_unk_11)[unaff_A4] != '\0') {
      (&DAT_ffffbe78)[unaff_A4] = 0xff;
    }
  } else if ((&comp_unk_11)[unaff_A4] == '\0')
    goto LAB_0001f012;
  if (*(short *)(&comp_unk_4 + unaff_A4) == 0) {
    eVar2 = (&comp_state_1_a)[unaff_A4];
    (&comp_state_1_a)[unaff_A4] = eVar2 & 0xdf;
    if ((eVar2 & 0x20) != 0) {
      FUN_00002678();
      sVar5 = 0x400;
      if (DAT_ffffdb16 < 0x20) {
        sVar5 = -0x400;
      }
      if (_DAT_ffffdb12 < 0) {
        sVar5 = -sVar5;
      }
      *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar5;
      *(short *)((int)component_pos_old_x + unaff_A4) =
          *(short *)((int)&comp_pos_x + unaff_A4);
      uVar6 = *(short *)((int)&comp_pos_x + unaff_A4) == 0;
      player_update_pos_x(unaff_A4);
      FUN_00002500();
      if ((bool)uVar6) {
        cVar3 = (&comp_collision_related)[unaff_A4] + -1;
        (&comp_collision_related)[unaff_A4] = cVar3;
        if (cVar3 != '\0') {
          return;
        }
      } else {
        *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
            *(undefined2 *)((int)component_pos_old_x + unaff_A4);
      }
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x10;
    }
  } else {
    sVar5 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar5;
    if ((sVar5 == 0) &&
        (FUN_000159fc(), (char)(&comp_has_func_maybe)[unaff_A4] < '\0')) {
      FUN_00002678();
      FUN_000026aa();
      if (DAT_ffffdb18 < 0x18) {
        if ((DAT_ffffdb16 < 0x20) || (0x3f < DAT_ffffdb16)) {
          (&comp_collision_related)[unaff_A4] = 4;
          (&comp_state_1_a)[unaff_A4] = (&comp_state_1_a)[unaff_A4] & 0xdf;
          return;
        }
        uVar4 = FUN_00001770();
        if ((uVar4 & 0x100) == 0) {
        LAB_0001f012:
          *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
          return;
        }
      }
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x10;
      return;
    }
  }
  return;
}

void FUN_0001f01a(void)

{
  byte bVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_000186f4(unaff_A4, &UNK_0001f04c);
  FUN_00002238();
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001f052(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_0001f060(void)

{
  int unaff_A4;

  FUN_00001d8a();
  // WARNING: Could not recover jumptable at 0x0001f06e. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)(&UNK_0001f072 +
             *(short *)(&UNK_0001f072 +
                        (short)(*(short *)(&DAT_ffffbe78 + unaff_A4) * 2))))();
  return;
}

void FUN_0001f0b6(void)

{
  byte bVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if (((bVar1 & 0x80) == 0) &&
      ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_ATTACKING_MID_AIR)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
      (ushort)(DAT_ffffc73a - 0x20U)) {
    FUN_00015e86();
    (&comp_has_func_maybe)[unaff_A4] = 0;
    return;
  }
  FUN_0001f0f8();
  *(int *)((int)&comp_pos_x + unaff_A4) =
      *(short *)((int)&comp_vel[0].x + unaff_A4) * 0x100 +
      *(int *)((int)&comp_pos_x + unaff_A4);
  *(int *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
      *(int *)((int)&comp_pos_y + unaff_A4);
  return;
}

void FUN_0001f0f8(void)

{
  short *psVar1;
  short sVar2;
  short sVar3;
  int unaff_A4;

  sVar2 = 1;
  if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
    sVar2 = -1;
  }
  sVar3 = 0x20;
  if ((ushort)(*(short *)(&DAT_ffffbc78 + unaff_A4) + sVar2) <
      *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    sVar3 = -0x20;
  }
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = sVar3 + *psVar1;
  FUN_000025b0();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001f11c(void)

{
  byte bVar1;
  ushort uVar2;
  short sVar3;
  int iVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x3c;
    (&comp_collision_related)[unaff_A4] = 0x10;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if (*(short *)(&comp_unk_4 + unaff_A4) == 0) {
    iVar4 = (int)_DAT_ffffcc5c;
    if (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
        (ushort)(*(short *)((int)&comp_pos_x + iVar4) + 0x20U)) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    }
    sVar3 = 1;
    uVar2 = *(short *)((int)&comp_pos_y + iVar4) - 0x20;
    if (uVar2 != *(ushort *)((int)&comp_pos_y + unaff_A4)) {
      if (uVar2 < *(ushort *)((int)&comp_pos_y + unaff_A4)) {
        sVar3 = -1;
      }
      *(short *)(&DAT_ffffbc78 + unaff_A4) =
          sVar3 + *(short *)(&DAT_ffffbc78 + unaff_A4);
    }
    FUN_0001f0f8();
    goto player_update_pos;
  }
  if (*(short *)((int)&comp_vel[0].x + unaff_A4) == 0) {
    if (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
        (ushort)(DAT_ffffc73a + 0xe0U)) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x100;
      goto LAB_0001f162;
    }
  } else {
  LAB_0001f162:
    sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
    if (sVar3 == 0) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xff80;
    }
  }
  FUN_0001f0f8();
player_update_pos:
  *(int *)((int)&comp_pos_x + unaff_A4) =
      *(short *)((int)&comp_vel[0].x + unaff_A4) * 0x100 +
      *(int *)((int)&comp_pos_x + unaff_A4);
  *(int *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
      *(int *)((int)&comp_pos_y + unaff_A4);
  return;
}

void FUN_0001f1ac(void)

{
  byte bVar1;
  char cVar2;
  ushort uVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  byte *pbVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar5;

  ecs_jump_table(unaff_A4);
  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  uVar5 = (bVar1 & 0x80) == 0;
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bool)uVar5) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    pbVar4 = &DAT_0001f242;
    while (true) {
      if ((*pbVar4 == 0) || (*pbVar4 == (&comp_func_offset[0].unk1)[unaff_A4]))
        break;
      pbVar4 = pbVar4 + 2;
    }
    bVar1 = pbVar4[1];
    (&comp_unk_4)[unaff_A4] = bVar1;
    uVar5 = bVar1 == 0;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002256();
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00002248();
  if ((!(bool)uVar5) && (cVar2 = (&comp_unk_4)[unaff_A4] + -1,
                         (&comp_unk_4)[unaff_A4] = cVar2,
                         cVar2 == '\0')) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      uVar3 = comp_pos_x.fixed.i - *(short *)(&DAT_ffffbc76 + unaff_A4);
      if ((short)uVar3 < 0) {
        uVar3 = -uVar3;
      }
      if (uVar3 < 0x60) {
        ecs_sprite_face_asha(unaff_A4);
      } else {
        (&comp_state_a)[unaff_A4] =
            (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
        if (*(ushort *)(&DAT_ffffbc76 + unaff_A4) <
            *(ushort *)((int)&comp_pos_x + unaff_A4)) {
          (&comp_state_a)[unaff_A4] =
              (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
        }
      }
      *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
    }
  }
  return;
}

void FUN_0001f1bc(void)

{
  byte bVar1;
  char cVar2;
  ushort uVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  byte *pbVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  uVar5 = (bVar1 & 0x80) == 0;
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bool)uVar5) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    pbVar4 = &DAT_0001f242;
    while (true) {
      if ((*pbVar4 == 0) || (*pbVar4 == (&comp_func_offset[0].unk1)[unaff_A4]))
        break;
      pbVar4 = pbVar4 + 2;
    }
    bVar1 = pbVar4[1];
    (&comp_unk_4)[unaff_A4] = bVar1;
    uVar5 = bVar1 == 0;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002256();
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00002248();
  if ((!(bool)uVar5) && (cVar2 = (&comp_unk_4)[unaff_A4] + -1,
                         (&comp_unk_4)[unaff_A4] = cVar2,
                         cVar2 == '\0')) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      uVar3 = comp_pos_x.fixed.i - *(short *)(&DAT_ffffbc76 + unaff_A4);
      if ((short)uVar3 < 0) {
        uVar3 = -uVar3;
      }
      if (uVar3 < 0x60) {
        ecs_sprite_face_asha(unaff_A4);
      } else {
        (&comp_state_a)[unaff_A4] =
            (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
        if (*(ushort *)(&DAT_ffffbc76 + unaff_A4) <
            *(ushort *)((int)&comp_pos_x + unaff_A4)) {
          (&comp_state_a)[unaff_A4] =
              (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
        }
      }
      *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
    }
  }
  return;
}

void FUN_0001f248(void)

{
  byte bVar1;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar2;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    (&comp_collision_related)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 10);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00000bfe();
  if ((&comp_collision_related)[unaff_A4] == '\0') {
    if (((&comp_state_1_a)[unaff_A4] & 0x20) == 0) {
      return;
    }
    (&comp_collision_related)[unaff_A4] = 0xff;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfac0;
  }
  uVar2 = 0;
  FUN_000022a2();
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00002248();
  if (!(bool)uVar2) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_0001f2a4(void)

{
  byte bVar1;
  short sVar2;
  byte extraout_D0b;
  ushort uVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  byte *unaff_A2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar4;

  ecs_jump_table(unaff_A4);
  *unaff_A2 = *unaff_A2 ^ '\x01' << ((extraout_D0b | 0xe) & 7);
  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x40;
  }
  uVar4 = 0;
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002256();
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00002678();
  FUN_00002248();
  if (!(bool)uVar4) {
    FUN_000026aa();
    uVar3 = 0x40;
    if ((&comp_func_offset[0].unk1)[unaff_A4] != 0x73) {
      uVar3 = 0x60;
    }
    if (DAT_ffffdb16 <= uVar3) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
      return;
    }
    sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
    if (sVar2 == 0) {
      FUN_000159fc();
      if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
        *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
      }
    }
  }
  return;
}

void FUN_0001f2b6(void)

{
  byte bVar1;
  short sVar2;
  ushort uVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar4;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x40;
  }
  uVar4 = 0;
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002256();
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00002678();
  FUN_00002248();
  if (!(bool)uVar4) {
    FUN_000026aa();
    uVar3 = 0x40;
    if ((&comp_func_offset[0].unk1)[unaff_A4] != 0x73) {
      uVar3 = 0x60;
    }
    if (DAT_ffffdb16 <= uVar3) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
      return;
    }
    sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
    if (sVar2 == 0) {
      FUN_000159fc();
      if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
        *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
      }
    }
  }
  return;
}

void FUN_0001f324(void)

{
  byte bVar1;
  short sVar2;
  short sVar3;
  word wVar4;
  undefined4 extraout_D0;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    sVar3 = 0x180;
    if ((&comp_func_offset[0].unk1)[unaff_A4] != 0x73) {
      sVar3 = 0x300;
    }
    if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
      sVar3 = -sVar3;
    }
    *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar3;
    *(short *)(&DAT_ffffbd76 + unaff_A4) = sVar3;
    wVar4 = rand();
    *(word *)(&comp_unk_4 + unaff_A4) = (wVar4 & 0x3f) + 0x20;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  bVar5 = (CONCAT31((int3)((uint)extraout_D0 >> 8),
                    (&component_unknown_5)[unaff_A4] |
                        (&component_collision_flags)[unaff_A4]) &
           1 << (uint)(*(short *)(&DAT_ffffbd76 + unaff_A4) < 0)) == 0;
  if ((bVar5) && (FUN_00002500(), bVar5)) {
    if ((&comp_collision_related)[unaff_A4] != '\0') {
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + -1;
      goto LAB_0001f3e8;
    }
    sVar3 = 0x40;
    if ((&comp_func_offset[0].unk1)[unaff_A4] != 0x73) {
      sVar3 = 0x60;
    }
    if (*(short *)(&DAT_ffffbd76 + unaff_A4) < 0) {
      if ((ushort)(*(short *)(&DAT_ffffbc76 + unaff_A4) - sVar3) <
          *(ushort *)((int)&comp_pos_x + unaff_A4))
        goto LAB_0001f3e8;
    } else if (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
               (ushort)(*(short *)(&DAT_ffffbc76 + unaff_A4) + sVar3))
      goto LAB_0001f3e8;
  }
  (&comp_collision_related)[unaff_A4] = 8;
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  sVar3 = *(short *)(&DAT_ffffbd76 + unaff_A4);
  sVar2 = -sVar3;
  *(short *)(&DAT_ffffbd76 + unaff_A4) = sVar2;
  *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar2;
  if (0 < sVar3) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  }
LAB_0001f3e8:
  sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
  if (sVar3 == 0) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_0001f3fa(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  word wVar4;
  undefined2 uVar5;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar6;
  undefined1 in_CF;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
    wVar4 = rand();
    uVar5 = 0xfc00;
    if ((wVar4 & 2) == 0) {
      uVar5 = 0xfb00;
    }
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = uVar5;
    in_CF = 0;
    FUN_000022a2();
  }
  FUN_000189d0();
  FUN_000021e2(unaff_A4);
  bVar2 = (&comp_func_offset[0].unk4)[unaff_A4];
  uVar6 = (bVar2 & 2) == 0;
  (&comp_func_offset[0].unk4)[unaff_A4] = bVar2 & 0xfd;
  FUN_00000ed6(unaff_A4, ENTITY_ID_ASHA);
  if ((bool)in_CF || (bool)uVar6) {
    FUN_00002120(unaff_A4, 3);
    (&comp_func_offset[0].unk4)[unaff_A4] =
        (&comp_func_offset[0].unk4)[unaff_A4] | 2;
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] ^ ENTITY_STATE_A_08;
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    sVar3 = -*psVar1;
    *psVar1 = sVar3;
    uVar6 = sVar3 == 0;
  }
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00002272();
  FUN_00002248();
  if (!(bool)uVar6) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001f476(void)

{
  entity_id_t unaff_A4;
  undefined2 *unaff_A6;

  ecs_jump_table(unaff_A4);
  *unaff_A6 = *unaff_A6;
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001f488(void)

{
  short sVar1;
  short sVar2;
  int iVar3;
  int unaff_A4;

  _DAT_ffffd17a = 0x1058 - *(short *)((int)&comp_pos_x + unaff_A4);
  _DAT_ffffd17c = 0x1070 - *(short *)((int)&comp_pos_y + unaff_A4);
  sVar1 = (*(short *)((int)&comp_pos_x + unaff_A4) + 0x28) - comp_pos_x._0_2_;
  sVar2 = (*(short *)((int)&comp_pos_y + unaff_A4) + -0x10) - comp_pos_y._0_2_;
  if ((uint)((int)sVar2 * (int)sVar2 + (int)sVar1 * (int)sVar1) < 0x1440) {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x81;
  }
  iVar3 =
      (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  *(short *)((int)&comp_pos_x + iVar3) =
      *(short *)((int)&comp_pos_x + unaff_A4) + 0x28;
  *(short *)((int)&comp_pos_y + iVar3) =
      *(short *)((int)&comp_pos_y + unaff_A4) + -0x10;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001f4e8(void)

{
  short sVar1;
  short sVar2;
  int iVar3;
  int unaff_A4;
  entity_id_t eVar4;
  anim_item_t *unaff_A5;

  FUN_0000281e();
  *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  eVar4 = (entity_id_t) *
          (short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  ecs_anim_unk_2(eVar4, unaff_A5, 6);
  (&comp_state_a)[eVar4] = 0x80;
  *(undefined2 *)((int)&comp_unk_3 + eVar4) = 0x1a;
  eVar4 = (entity_id_t) *
          (short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + eVar4);
  (&comp_collision_related)[eVar4] = 10;
  *(short *)((int)&comp_pos_y + eVar4) = DAT_ffffce0a + -0x10;
  *(short *)((int)&comp_pos_x + eVar4) =
      *(short *)((int)&comp_pos_x + eVar4) + -0x20;
  (&comp_state_a)[eVar4] = 0x80;
  *(undefined2 *)((int)&comp_unk_3 + eVar4) = 0x1c;
  ecs_anim_unk_2(eVar4, unaff_A5, 0);
  _DAT_ffffd17a = 0x1058 - *(short *)((int)&comp_pos_x + eVar4);
  _DAT_ffffd17c = 0x1070 - *(short *)((int)&comp_pos_y + eVar4);
  sVar1 = (*(short *)((int)&comp_pos_x + eVar4) + 0x28) - comp_pos_x._0_2_;
  sVar2 = (*(short *)((int)&comp_pos_y + eVar4) + -0x10) - comp_pos_y._0_2_;
  if ((uint)((int)sVar2 * (int)sVar2 + (int)sVar1 * (int)sVar1) < 0x1440) {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x81;
  }
  iVar3 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + eVar4);
  *(short *)((int)&comp_pos_x + iVar3) =
      *(short *)((int)&comp_pos_x + eVar4) + 0x28;
  *(short *)((int)&comp_pos_y + iVar3) =
      *(short *)((int)&comp_pos_y + eVar4) + -0x10;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001f538(void)

{
  byte bVar1;
  short sVar2;
  short sVar3;
  ushort uVar4;
  undefined2 uVar5;
  int iVar6;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x78;
  }
  sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
  if ((sVar3 == 0) &&
      (*(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x78,
       (byte)(&DAT_ffffcf9f)[*(short *)((int)&comp_unk_8 + unaff_A4)] < 4)) {
    if (((&comp_collision_related)[unaff_A4] == '\0') &&
        (bVar1 = (&DAT_ffffb66e)[unaff_A4],
         (&DAT_ffffb66e)[unaff_A4] = bVar1 ^ 1,
         (bVar1 & 1) == 0)) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
    } else {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
    }
  } else if ((&comp_collision_related)[unaff_A4] == '\0') {
    uVar5 = 0x40;
    uVar4 = (DAT_ffffc73a + 0xe0) - *(short *)((int)&comp_pos_x + unaff_A4);
    if ((short)uVar4 < 0) {
      uVar4 = -uVar4;
      uVar5 = 0xffc0;
    }
    if (5 < uVar4) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = uVar5;
      player_update_pos_x(unaff_A4);
    }
  }
  _DAT_ffffd17a = 0x1058 - *(short *)((int)&comp_pos_x + unaff_A4);
  _DAT_ffffd17c = 0x1070 - *(short *)((int)&comp_pos_y + unaff_A4);
  sVar3 = (*(short *)((int)&comp_pos_x + unaff_A4) + 0x28) - comp_pos_x._0_2_;
  sVar2 = (*(short *)((int)&comp_pos_y + unaff_A4) + -0x10) - comp_pos_y._0_2_;
  if ((uint)((int)sVar2 * (int)sVar2 + (int)sVar3 * (int)sVar3) < 0x1440) {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x81;
  }
  iVar6 =
      (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  *(short *)((int)&comp_pos_x + iVar6) =
      *(short *)((int)&comp_pos_x + unaff_A4) + 0x28;
  *(short *)((int)&comp_pos_y + iVar6) =
      *(short *)((int)&comp_pos_y + unaff_A4) + -0x10;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001f5ac(void)

{
  byte bVar1;
  short sVar2;
  short sVar3;
  int iVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
  }
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    func_0x0001f67e();
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  _DAT_ffffd17a = 0x1058 - *(short *)((int)&comp_pos_x + unaff_A4);
  _DAT_ffffd17c = 0x1070 - *(short *)((int)&comp_pos_y + unaff_A4);
  sVar2 = (*(short *)((int)&comp_pos_x + unaff_A4) + 0x28) - comp_pos_x._0_2_;
  sVar3 = (*(short *)((int)&comp_pos_y + unaff_A4) + -0x10) - comp_pos_y._0_2_;
  if ((uint)((int)sVar3 * (int)sVar3 + (int)sVar2 * (int)sVar2) < 0x1440) {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x81;
  }
  iVar4 =
      (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  *(short *)((int)&comp_pos_x + iVar4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + 0x28;
  *(short *)((int)&comp_pos_y + iVar4) =
      *(short *)((int)&comp_pos_y + unaff_A4) + -0x10;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0001f5ce(void)

{
  short *psVar1;
  byte bVar2;
  char cVar3;
  short sVar4;
  short sVar5;
  int iVar6;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x20;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x100;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfd00;
  } else {
    if ((&comp_unk_4)[unaff_A4] == '\0') {
      psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
      *psVar1 = *psVar1 + 0x28;
      player_update_pos(unaff_A4);
      if (*(ushort *)((int)&comp_pos_y + unaff_A4) <
          (ushort)(DAT_ffffce0a - 0x10U))
        goto FUN_0001f488;
      *(ushort *)((int)&comp_pos_y + unaff_A4) = DAT_ffffce0a - 0x10U;
      (&comp_unk_4)[unaff_A4] = 0xff;
      FUN_0001689e();
    }
    if ((&DAT_ffffb773)[unaff_A4] != '\0') {
      cVar3 = (&DAT_ffffb773)[unaff_A4] + -1;
      (&DAT_ffffb773)[unaff_A4] = cVar3;
      if (cVar3 != '\0')
        goto FUN_0001f488;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
    }
    FUN_000186f4(unaff_A4, &UNK_0001f64c);
    FUN_00002238();
    if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    }
  }
FUN_0001f488:
  _DAT_ffffd17a = 0x1058 - *(short *)((int)&comp_pos_x + unaff_A4);
  _DAT_ffffd17c = 0x1070 - *(short *)((int)&comp_pos_y + unaff_A4);
  sVar4 = (*(short *)((int)&comp_pos_x + unaff_A4) + 0x28) - comp_pos_x._0_2_;
  sVar5 = (*(short *)((int)&comp_pos_y + unaff_A4) + -0x10) - comp_pos_y._0_2_;
  if ((uint)((int)sVar5 * (int)sVar5 + (int)sVar4 * (int)sVar4) < 0x1440) {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x81;
  }
  iVar6 =
      (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  *(short *)((int)&comp_pos_x + iVar6) =
      *(short *)((int)&comp_pos_x + unaff_A4) + 0x28;
  *(short *)((int)&comp_pos_y + iVar6) =
      *(short *)((int)&comp_pos_y + unaff_A4) + -0x10;
  return;
}

void FUN_0001f6ec(void)

{
  byte *pbVar1;
  short *psVar2;
  short sVar3;
  uint extraout_D0;
  byte unaff_D7b;
  byte *extraout_A0;
  entity_id_t unaff_A4;
  undefined1 uVar4;

  ecs_jump_table(unaff_A4);
  *extraout_A0 = *extraout_A0 | 0x4e;
  pbVar1 = (byte *)((unaff_A4 - 0x14) + (extraout_D0 | 0xd1));
  *pbVar1 = *pbVar1 & ~('\x01' << (extraout_D0 & 7 | 1));
  if ((unaff_D7b | 0x66) == 0) {
    FUN_00001ec8();
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff00;
  }
  FUN_000021c2(unaff_A4, false, false);
  psVar2 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar3 = *psVar2 + 0x30;
  *psVar2 = sVar3;
  uVar4 = sVar3 == 0;
  player_update_pos(unaff_A4);
  FUN_00002866();
  if ((!(bool)uVar4) && (*(short *)((int)&comp_anim_tick + unaff_A4) == 0)) {
    *(undefined2 *)(&comp_has_func_maybe + unaff_A4) =
        *(undefined2 *)(&comp_has_func_maybe + unaff_A4) & 0xf7fb;
    uVar4 = ecs_unk_3(unaff_A4, 1);
    *(undefined1 *)((int)&comp_state + unaff_A4) = uVar4;
  }
  return;
}

void FUN_0001f700(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  entity_id_t unaff_A4;
  undefined1 uVar4;
  undefined1 in_CF;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    FUN_00001ec8();
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff00;
    in_CF = false;
  }
  FUN_000021c2(unaff_A4, false, (bool)in_CF);
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar3 = *psVar1 + 0x30;
  *psVar1 = sVar3;
  uVar4 = sVar3 == 0;
  player_update_pos(unaff_A4);
  FUN_00002866();
  if ((!(bool)uVar4) && (*(short *)((int)&comp_anim_tick + unaff_A4) == 0)) {
    *(undefined2 *)(&comp_has_func_maybe + unaff_A4) =
        *(undefined2 *)(&comp_has_func_maybe + unaff_A4) & 0xf7fb;
    uVar4 = ecs_unk_3(unaff_A4, 1);
    *(undefined1 *)((int)&comp_state + unaff_A4) = uVar4;
  }
  return;
}

void FUN_0001f73e(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  char cVar4;
  ushort uVar5;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar6;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    (&comp_unk_4)[unaff_A4] = 8;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002256();
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar3 = *psVar1 + 0x30;
  *psVar1 = sVar3;
  uVar6 = sVar3 == 0;
  player_update_pos(unaff_A4);
  FUN_00002866();
  if ((!(bool)uVar6) && (cVar4 = (&comp_unk_4)[unaff_A4] + -1,
                         (&comp_unk_4)[unaff_A4] = cVar4,
                         cVar4 == '\0')) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    uVar5 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
    if ((short)uVar5 < 0) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] + ENTITY_STATE_A_08;
      uVar5 = -uVar5;
    }
    if (uVar5 < 0x38) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] ^ ENTITY_STATE_A_08;
    } else if (((uVar5 < 0x60) || (uVar5 < 0xa0)) &&
               ((byte)(&DAT_ffffcf9f)[*(short *)((int)&comp_unk_8 + unaff_A4)] <
                3)) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 7;
      return;
    }
    *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
  }
  return;
}

uint FUN_0001f7c0(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  uint extraout_D0;
  uint uVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    (&comp_collision_related)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00000bfe();
  bVar2 = (&comp_collision_related)[unaff_A4];
  if (bVar2 == 0) {
    if (((&comp_state_1_a)[unaff_A4] & 0x20) == 0) {
      return (uint)bVar2;
    }
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x01';
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 64000;
    uVar5 = 0;
    FUN_000022a2();
  } else {
    bVar2 = bVar2 - 1;
    if (bVar2 != 0) {
      if (*(short *)((int)&comp_anim_tick + unaff_A4) != 0) {
        return (uint)bVar2;
      }
      *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
      return (uint)bVar2;
    }
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    sVar3 = *psVar1 + 0x40;
    *psVar1 = sVar3;
    uVar5 = sVar3 == 0;
  }
  player_update_pos(unaff_A4);
  uVar4 = FUN_00002866();
  if ((bool)uVar5) {
    return uVar4;
  }
  (&comp_collision_related)[unaff_A4] =
      (&comp_collision_related)[unaff_A4] + '\x01';
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
    BYTE_ffffc709 = 0;
  }
  if (unaff_A4 == ENTITY_ID_ASHA) {
    BYTE_ffffc70a = 0;
  }
  (&comp_state_1_a)[unaff_A4] = 0;
  (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_ATTACKING_GROUNDED;
  ecs_anim_unk_1(unaff_A4, unaff_A5);
  (&comp_has_func_maybe)[unaff_A4] =
      (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
  return extraout_D0;
}

void FUN_0001f834(void)

{
  byte bVar1;
  char cVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    (&comp_collision_related)[unaff_A4] = 0x10;
    ecs_sprite_face_asha(unaff_A4);
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if ((&comp_collision_related)[unaff_A4] != '\0') {
    cVar2 = (&comp_collision_related)[unaff_A4] + -1;
    (&comp_collision_related)[unaff_A4] = cVar2;
    if (cVar2 != '\0') {
      return;
    }
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_000186f4(unaff_A4, &UNK_0001f882);
  FUN_00002238();
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_0001f8a4(void)

{
  short sVar1;
  byte bVar2;
  entity_state_1_a_t eVar3;
  short sVar4;
  word wVar5;
  entity_id_t e;
  int extraout_A0;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  eVar3 = (&comp_state_1_a)[unaff_A4];
  (&comp_state_1_a)[unaff_A4] = eVar3 & 0xdf;
  if ((eVar3 & 0x20) != 0) {
    sVar4 = ecs_find_some_entity_with_func();
    unaff_A4 = (entity_id_t)(short)unaff_A4;
    if (-1 < sVar4) {
      entity_reset(e);
      (&comp_has_func_maybe)[e] = 0x80;
      sVar4 = 4;
      if (((&comp_state_a)[e] & ENTITY_STATE_A_08) != 0) {
        sVar4 = -4;
      }
      sVar1 = *(short *)((int)&comp_pos_y + extraout_A0);
      *(short *)((int)&comp_pos_x + e) =
          *(short *)((int)&comp_pos_x + extraout_A0) + sVar4;
      *(short *)((int)&comp_pos_y + e) = sVar1 + -0x1a;
      (&comp_state_a)[e] = (&comp_state_a)[extraout_A0];
      sVar4 = *(short *)((int)&comp_unk_8 + extraout_A0);
      (&DAT_ffffcf9f)[sVar4] = (&DAT_ffffcf9f)[sVar4] + '\x01';
      *(short *)((int)&comp_unk_8 + e) = sVar4;
      (&comp_func_offset[0].unk1)[e] = 0x83;
      *(undefined1 *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + e) = 0xff;
      FUN_000019ae();
      (&comp_unk_10)[e] = 0x40;
      wVar5 = rand();
      sVar4 = (wVar5 & 0xf0) + 0x100;
      if (((&comp_state_a)[e] & ENTITY_STATE_A_08) != 0) {
        sVar4 = -sVar4;
      }
      *(short *)(&comp_unk_1 + e) = sVar4;
      unaff_A4 = (entity_id_t)(short)extraout_A0;
    }
  }
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_0001f94a(void)

{
  ushort *puVar1;
  short sVar2;
  ushort extraout_D0w;
  short unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  int unaff_A2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  int unaff_A6;
  bool bVar3;

  ecs_jump_table(unaff_A4);
  puVar1 = (ushort *)(unaff_A2 + 7 + (int)(short)(extraout_D0w | 0xe));
  *puVar1 = *puVar1 | 0x8ec;
  if (unaff_D2w == *(short *)(unaff_A6 + -2)) {
    if ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_FALLING) {
      ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    }
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002256();
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
      bVar3 = false;
      FUN_00002248();
      if (!bVar3) {
        FUN_00002678();
        FUN_000026aa();
        if (DAT_ffffdb16 < 0x50) {
          *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
        }
      }
    }
  }
  return;
}

void FUN_0001f95c(void)

{
  byte bVar1;
  short sVar2;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar3;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    if ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_FALLING) {
      ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    }
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002256();
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    FUN_000159fc();
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
      bVar3 = false;
      FUN_00002248();
      if (!bVar3) {
        FUN_00002678();
        FUN_000026aa();
        if (DAT_ffffdb16 < 0x50) {
          *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
        }
      }
    }
  }
  return;
}

void FUN_0001f9c0(void)

{
  short *psVar1;
  byte bVar2;
  entity_state_1_a_t eVar3;
  short sVar4;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00000bfe();
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_000186f4(unaff_A4, &UNK_0001fa2e);
  FUN_00002238();
  eVar3 = (&comp_state_1_a)[unaff_A4];
  (&comp_state_1_a)[unaff_A4] = eVar3 & 0xdf;
  if ((eVar3 & 0x20) != 0) {
    FUN_0001689e();
    sVar4 = 0xf00;
    if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
      sVar4 = -0xf00;
    }
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = sVar4 + *psVar1;
    FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  }
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_FALLING;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001fa3c(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_0001fa4c(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) =
      *(undefined2 *)(&comp_unk_1 + unaff_A4);
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfc00;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x18;
  *(undefined1 *)((int)&comp_state + unaff_A4) = 0x85;
  (&comp_collision_related)[unaff_A4] = 0xff;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
    BYTE_ffffc709 = 0;
  }
  if (unaff_A4 == ENTITY_ID_ASHA) {
    BYTE_ffffc70a = 0;
  }
  (&comp_state_1_a)[unaff_A4] = 0;
  (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_ATTACKING_GROUNDED;
  ecs_anim_unk_1(unaff_A4, unaff_A5);
  (&comp_has_func_maybe)[unaff_A4] =
      (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
  return;
}

void FUN_0001fa74(void)

{
  short sVar1;
  byte bVar2;
  component_state_b_t cVar3;
  entity_state_a_t eVar4;
  char unaff_D5b;
  int iVar5;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if (((-1 < *(char *)((int)&comp_state + unaff_A4)) &&
       ((&comp_func_offset[0].unk1)[unaff_A4] == 0x75)) &&
      (sVar1 =
           *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4),
       (&comp_collision_related)[sVar1] != '\0')) {
    (&comp_collision_related)[sVar1] = (&comp_collision_related)[sVar1] + -1;
  }
  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    audio_play(SOUND_ID_EN_DEAD);
    FUN_0000231c();
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
    FUN_00001eac();
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    FUN_00015e86();
    iVar5 = (int)(short)unaff_A4;
    while (sVar1 =
               *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar5),
           -1 < sVar1) {
      iVar5 = (int)sVar1;
      (&comp_has_func_maybe)[iVar5] = 0;
    }
    ecs_unk_1(unaff_A4);
    if (unaff_D5b != -1) {
      FUN_00024d78();
      cVar3 = (&comp_has_func_maybe)[unaff_A4];
      (&comp_has_func_maybe)[unaff_A4] = cVar3 | 0x40;
      if ((cVar3 & 0x40) == 0) {
        FUN_000019ae();
        *(undefined2 *)((int)&comp_anim_speed + unaff_A4) = 0x100;
        eVar4 = 0;
        if (DAT_ffffcc28 != '\0') {
          eVar4 = 0x80;
        }
        (&comp_state_a)[unaff_A4] = eVar4;
        *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 4;
        *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
      }
      // WARNING: Could not recover jumptable at 0x00024e1e. Too many branches
      // WARNING: Treating indirect jump as call
      (*(code *)((int)&WORD_00024e22 +
                 (int)*(
                     short *)((int)&WORD_00024e22 +
                              (int)(short)(ushort)(&comp_func_offset[0]
                                                        .unk3)[unaff_A4])))();
      return;
    }
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

void FUN_0001fa94(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar4;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    if (*(short *)(&comp_unk_1 + unaff_A4) < 0) {
      if (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
          (ushort)(DAT_ffffce04 -
                   *(short *)((int)&comp_collision_sensor[0].x + unaff_A4)))
        goto LAB_0001fac0;
    } else if ((ushort)(*(short *)((int)&comp_collision_sensor[0].x +
                                   unaff_A4) +
                        DAT_ffffce08) <
               *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    LAB_0001fac0:
      FUN_00015e86();
      (&comp_has_func_maybe)[unaff_A4] = 0;
      return;
    }
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00002256();
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar3 = *psVar1 + 0x40;
  *psVar1 = sVar3;
  uVar4 = sVar3 == 0;
  player_update_pos(unaff_A4);
  FUN_00002856();
  if ((!(bool)uVar4) && (sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1,
                         *(short *)(&comp_unk_4 + unaff_A4) = sVar3,
                         sVar3 == 0)) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
  }
  return;
}

void FUN_0001fb02(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  undefined2 uVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) != 0)
    goto LAB_0001fb32;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  (&comp_collision_related)[unaff_A4] = 0;
  if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) == 0) {
    if (*(short *)(&comp_unk_1 + unaff_A4) < 0) {
    LAB_0001fb28:
      *(short *)(&comp_unk_1 + unaff_A4) = -*(short *)(&comp_unk_1 + unaff_A4);
    }
  } else if (-1 < *(short *)(&comp_unk_1 + unaff_A4))
    goto LAB_0001fb28;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 10);
LAB_0001fb32:
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  FUN_00000bfe();
  if ((&comp_collision_related)[unaff_A4] == '\0') {
    if (((&comp_state_1_a)[unaff_A4] & 0x20) == 0) {
      return;
    }
    (&comp_collision_related)[unaff_A4] = 0xff;
    uVar4 = 0xfe00;
    if ((&comp_func_offset[0].unk1)[unaff_A4] != 0x83) {
      uVar4 = 0xfd00;
    }
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = uVar4;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) =
        *(undefined2 *)(&comp_unk_1 + unaff_A4);
  }
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar3 = *psVar1 + 0x40;
  *psVar1 = sVar3;
  uVar5 = sVar3 == 0;
  player_update_pos(unaff_A4);
  FUN_00002856();
  if (!(bool)uVar5) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_0001fb86(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_0001fb98(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar4;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  bVar4 = (bVar2 & 0x80) == 0;
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if (bVar4) {
    FUN_00002248();
    if (!bVar4) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    }
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 8;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x50;
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
  if (sVar3 == 0) {
    FUN_000159fc();
    bVar4 = (&comp_has_func_maybe)[unaff_A4] == 0;
    if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
      FUN_00002248();
      if (!bVar4) {
        FUN_00002678();
        FUN_000026aa();
        if ((DAT_ffffdb16 < 0xc0) && (DAT_ffffdb18 < 0x50)) {
          *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
          return;
        }
      }
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
    }
  }
  return;
}

void FUN_0001fc08(void)

{
  short *psVar1;
  byte bVar2;
  undefined4 uVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x50;
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00002678();
  FUN_000026aa();
  uVar3 = FUN_000022a2();
  if ((((&component_unknown_5)[unaff_A4] |
        (&component_collision_flags)[unaff_A4]) &
       4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    return;
  }
  if ((CONCAT31((int3)((uint)uVar3 >> 8),
                (&component_unknown_5)[unaff_A4] |
                    (&component_collision_flags)[unaff_A4]) &
       1 << (uint)(((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0)) !=
      0) {
  LAB_0001fc5e:
    *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
    return;
  }
  if (DAT_ffffdb16 < 0x34) {
    if (0xf < DAT_ffffdb18)
      goto LAB_0001fc5e;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 6;
  }
  return;
}

void FUN_0001fc7e(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar4;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    if ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_ATTACKING_MID_AIR) {
      ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    }
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfb00;
    FUN_000022a2();
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar3 = *psVar1 + 0x50;
  *psVar1 = sVar3;
  uVar4 = sVar3 == 0;
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00002248();
  if (!(bool)uVar4) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_0001fcc0(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 10);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x50;
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  FUN_00002256();
  FUN_000186f4(unaff_A4, &UNK_0001fd4c);
  FUN_00002238();
  if (((&comp_func_offset[0].unk4)[unaff_A4] & 0x20) == 0) {
    FUN_00018758(unaff_A4, &UNK_0001fd4c);
    if (((&comp_func_offset[0].unk4)[unaff_A4] & 0x40) != 0) {
      sVar3 = -0x200;
      if ((ushort)comp_pos_x.fixed.i <
          *(ushort *)((int)&comp_pos_x + unaff_A4)) {
        sVar3 = 0x200;
      }
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = sVar3 + *psVar1;
      FUN_00002590();
    }
  }
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
    FUN_00002678();
    if (DAT_ffffdb16 < 0x50) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
    }
  }
  return;
}

void FUN_0001fd5e(void)

{
  short i;
  undefined4 *src;
  vdp_color_t *dst;

  i = 7;
  src = (undefined4 *)&DAT_ffffdb1e;
  dst = palettes_2;
  do {
    *(undefined4 *)dst = *src;
    i = i + -1;
    src = src + 1;
    dst = dst + 2;
  } while (i != -1);
  return;
}

void FUN_0001fd70(void)

{
  short i;
  vdp_color_t *dst;

  i = 7;
  dst = palettes_2;
  do {
    dst[0] = 0;
    dst[1] = 0;
    i = i + -1;
    dst = dst + 2;
  } while (i != -1);
  return;
}

void FUN_0001fd80(void)

{
  short i;
  vdp_color_t *dst;

  i = 7;
  dst = palettes_2;
  do {
    dst[0] = 0xeee;
    dst[1] = 0xeee;
    i = i + -1;
    dst = dst + 2;
  } while (i != -1);
  return;
}

void FUN_0001fd94(void)

{
  short i;
  undefined4 *src;
  vdp_color_t *dst;

  FUN_0000aba0(&DAT_ffffdb1e);
  DAT_ffff9813 = 0xfc;
  i = 7;
  src = (undefined4 *)&DAT_ffffdb1e;
  dst = palettes_2;
  do {
    *(undefined4 *)dst = *src;
    i = i + -1;
    src = src + 1;
    dst = dst + 2;
  } while (i != -1);
  return;
}

void palette_copy_from_palettes2(char param_1)

{
  short i;
  vdp_color_t *src;
  vdp_color_t *dst;

  i = 7;
  src = palettes_2;
  dst = palettes[1];
  do {
    *(undefined4 *)dst = *(undefined4 *)src;
    i = i + -1;
    src = src + 2;
    dst = dst + 2;
  } while (i != -1);
  palette_set_fade(PALETTE_ID_FLAG_1,
                   PALETTE_FADE_1,
                   param_1,
                   (palette_color_iter_t)0xffffffff);
  return;
}

void FUN_0001fe84(void)

{
  byte bVar1;
  char extraout_D1b;
  char extraout_D1b_00;
  char extraout_D1b_01;
  int unaff_A4;

  if ((&comp_unk_11)[unaff_A4] == '\0') {
    return;
  }
  bVar1 = (&comp_unk_11)[unaff_A4] - 1;
  (&comp_unk_11)[unaff_A4] = bVar1;
  if ((bVar1 & 1) != 0) {
    if ((bVar1 >> 1 & 1) != 0) {
      FUN_0001fd80();
      palette_copy_from_palettes2(extraout_D1b);
      return;
    }
    FUN_0001fd70();
    palette_copy_from_palettes2(extraout_D1b_00);
    return;
  }
  FUN_0001fd5e();
  palette_copy_from_palettes2(extraout_D1b_01);
  return;
}

void FUN_0001feac(void)

{
  short sVar1;
  char cVar2;
  int unaff_A4;

  FUN_0001fe84();
  cVar2 = *(char *)((int)&comp_state + unaff_A4);
  if (-1 < cVar2) {
    (&comp_collision_related)[unaff_A4] = 0;
    *(byte *)((int)&comp_state + unaff_A4) =
        *(byte *)((int)&comp_state + unaff_A4) | 0x80;
  }
  sVar1 = *(short *)((int)&WORD_0001fedc +
                     (int)(short)(ushort)(byte)(cVar2 * '\x02'));
  (*(code *)((int)&WORD_0001fedc +
             (int)*(short *)((int)&WORD_0001fedc +
                             (int)(short)(ushort)(byte)(&comp_collision_related)
                                 [unaff_A4] +
                             (int)sVar1) +
             (int)sVar1))();
  return;
}

void FUN_0001fef0(void)

{
  word wVar1;
  short sVar2;
  byte state_1_b;
  char cVar4;
  ushort uVar3;
  ushort uVar5;
  byte *pbVar6;
  byte *pbVar7;
  word *pwVar8;
  word *extraout_A1;
  entity_id_t unaff_A4;
  entity_id_t self;
  int iVar9;
  anim_item_t *unaff_A5;

  (&comp_collision_related)[unaff_A4] =
      (&comp_collision_related)[unaff_A4] + '\x02';
  DAT_ffffdb40 = 0;
  FUN_0000281e();
  FUN_0001fd94();
  (&comp_anim[0].unk4)[unaff_A4] = (&comp_anim[0].unk4)[unaff_A4] | 0x40;
  *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x1c;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  pbVar7 = &UNK_0001ff6c;
  while (true) {
    if (*pbVar7 == 0)
      break;
    self = (int)(short)(ushort)*pbVar7 + unaff_A4;
    (&DAT_ffffb978)[self] = 0;
    pbVar6 = pbVar7 + 2;
    *(ushort *)((int)&comp_unk_3 + self) = (ushort)pbVar7[1];
    pbVar7 = pbVar7 + 3;
    ecs_anim_unk_2(self, unaff_A5, *pbVar6);
    (&comp_has_func_maybe)[self] = (&comp_has_func_maybe)[self] | 0x20;
    unaff_A4 = (entity_id_t)(short)unaff_A4;
  }
  *(undefined2 *)(&DAT_ffffb77e + unaff_A4) = 0;
  *(undefined2 *)(&DAT_ffffb782 + unaff_A4) = 0xe0f8;
  FUN_000201de();
  *(undefined2 *)(unaff_A4 - 0x487a) = 0xe0f8;
  FUN_000201f6();
  pwVar8 = WORD_ARRAY_000202d0;
  while (true) {
    if ((short)*pwVar8 < 0)
      break;
    unaff_A4 =
        (entity_id_t)(short)(*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0]
                                            .unk1 +
                                        unaff_A4) +
                             *pwVar8);
    wVar1 = pwVar8[1];
    sVar2 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4) +
            wVar1;
    *(short *)(&DAT_ffffbc76 + unaff_A4) = sVar2;
    cVar4 = (&DAT_ffffb979)[unaff_A4];
    if (wVar1 != 0) {
      cVar4 = (&DAT_ffffb976)[sVar2] + cVar4;
    }
    (&DAT_ffffb976)[unaff_A4] = cVar4;
    FUN_000028aa();
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    pwVar8 = extraout_A1;
    if ((short)((ushort)(byte)((&DAT_ffffb976)[unaff_A4] + 0x40) << 8) < 0) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    }
  }
  sVar2 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4);
  iVar9 = (int)sVar2;
  if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + iVar9)) {
    uVar3 = *(short *)(&DAT_ffffb77e + iVar9) - 1;
    if ((short)uVar3 < -0xc) {
      uVar3 = 0xfff4;
    }
  } else {
    uVar3 = *(short *)(&DAT_ffffb77e + iVar9) + 1;
    if (0xc < (short)uVar3) {
      uVar3 = 0xc;
    }
  }
  *(ushort *)(&DAT_ffffb77e + iVar9) = uVar3;
  (&DAT_ffff9f27)[iVar9] = (&DAT_ffff9f27)[iVar9] & 0xf7;
  uVar5 = uVar3;
  if ((short)uVar3 < 0) {
    uVar5 = -uVar3;
    (&DAT_ffff9f27)[iVar9] = (&DAT_ffff9f27)[iVar9] | 8;
  }
  state_1_b = 10;
  if (5 < uVar5) {
    state_1_b = 0xc;
  }
  *(ushort *)((int)&DAT_ffffa12e + iVar9) =
      *(short *)((int)&comp_pos_x + iVar9) + uVar3;
  *(short *)((int)&DAT_ffffa232 + iVar9) =
      *(short *)((int)&comp_pos_y + iVar9) + -0x10;
  if (state_1_b != (&DAT_ffffa644)[iVar9]) {
    ecs_anim_unk_2((int)(short)(sVar2 + 0xc), unaff_A5, state_1_b);
  }
  return;
}

void FUN_0001ff88(void)

{
  int unaff_A4;

  if (DAT_ffffdb40 < '\0') {
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x02';
  }
  return;
}

void FUN_0001ff94(void)

{
  word wVar1;
  short *psVar2;
  short sVar3;
  byte state_1_b;
  char cVar5;
  ushort uVar4;
  ushort uVar6;
  word *pwVar7;
  word *extraout_A1;
  entity_id_t unaff_A4;
  int iVar8;
  anim_item_t *unaff_A5;
  undefined1 uVar9;

  psVar2 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar3 = *psVar2 + 0x40;
  *psVar2 = sVar3;
  uVar9 = sVar3 == 0;
  ecs_update_pos_y(unaff_A4);
  FUN_00002856();
  if (!(bool)uVar9) {
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x02';
  }
  pwVar7 = WORD_ARRAY_000202d0;
  while (true) {
    if ((short)*pwVar7 < 0)
      break;
    unaff_A4 =
        (entity_id_t)(short)(*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0]
                                            .unk1 +
                                        unaff_A4) +
                             *pwVar7);
    wVar1 = pwVar7[1];
    sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4) +
            wVar1;
    *(short *)(&DAT_ffffbc76 + unaff_A4) = sVar3;
    cVar5 = (&DAT_ffffb979)[unaff_A4];
    if (wVar1 != 0) {
      cVar5 = (&DAT_ffffb976)[sVar3] + cVar5;
    }
    (&DAT_ffffb976)[unaff_A4] = cVar5;
    FUN_000028aa();
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    pwVar7 = extraout_A1;
    if ((short)((ushort)(byte)((&DAT_ffffb976)[unaff_A4] + 0x40) << 8) < 0) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    }
  }
  sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4);
  iVar8 = (int)sVar3;
  if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + iVar8)) {
    uVar4 = *(short *)(&DAT_ffffb77e + iVar8) - 1;
    if ((short)uVar4 < -0xc) {
      uVar4 = 0xfff4;
    }
  } else {
    uVar4 = *(short *)(&DAT_ffffb77e + iVar8) + 1;
    if (0xc < (short)uVar4) {
      uVar4 = 0xc;
    }
  }
  *(ushort *)(&DAT_ffffb77e + iVar8) = uVar4;
  (&DAT_ffff9f27)[iVar8] = (&DAT_ffff9f27)[iVar8] & 0xf7;
  uVar6 = uVar4;
  if ((short)uVar4 < 0) {
    uVar6 = -uVar4;
    (&DAT_ffff9f27)[iVar8] = (&DAT_ffff9f27)[iVar8] | 8;
  }
  state_1_b = 10;
  if (5 < uVar6) {
    state_1_b = 0xc;
  }
  *(ushort *)((int)&DAT_ffffa12e + iVar8) =
      *(short *)((int)&comp_pos_x + iVar8) + uVar4;
  *(short *)((int)&DAT_ffffa232 + iVar8) =
      *(short *)((int)&comp_pos_y + iVar8) + -0x10;
  if (state_1_b != (&DAT_ffffa644)[iVar8]) {
    ecs_anim_unk_2((int)(short)(sVar3 + 0xc), unaff_A5, state_1_b);
  }
  return;
}

void FUN_0001ffac(void)

{
  word wVar1;
  byte state_1_b;
  ushort uVar2;
  ushort uVar3;
  short sVar4;
  char cVar5;
  char *pcVar6;
  int iVar7;
  word *pwVar8;
  word *extraout_A1;
  int unaff_A4;
  anim_item_t *unaff_A5;

  cVar5 = '\0';
  sVar4 = 7;
  iVar7 = unaff_A4 + 0x10;
  pcVar6 = "((\x14\x14\x14\x14\x16\x16";
  do {
    if ((char)(&DAT_ffffb978)[iVar7] < *pcVar6) {
      cVar5 = -1;
      (&DAT_ffffb978)[iVar7] = (&DAT_ffffb978)[iVar7] + '\x01';
    }
    iVar7 = iVar7 + 4;
    sVar4 = sVar4 + -1;
    pcVar6 = pcVar6 + 1;
  } while (sVar4 != -1);
  if (cVar5 == '\0') {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
  }
  pwVar8 = WORD_ARRAY_000202d0;
  while (true) {
    if ((short)*pwVar8 < 0)
      break;
    unaff_A4 =
        (int)(short)(*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                                unaff_A4) +
                     *pwVar8);
    wVar1 = pwVar8[1];
    sVar4 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4) +
            wVar1;
    *(short *)(&DAT_ffffbc76 + unaff_A4) = sVar4;
    cVar5 = (&DAT_ffffb979)[unaff_A4];
    if (wVar1 != 0) {
      cVar5 = (&DAT_ffffb976)[sVar4] + cVar5;
    }
    (&DAT_ffffb976)[unaff_A4] = cVar5;
    FUN_000028aa();
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    pwVar8 = extraout_A1;
    if ((short)((ushort)(byte)((&DAT_ffffb976)[unaff_A4] + 0x40) << 8) < 0) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    }
  }
  sVar4 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4);
  iVar7 = (int)sVar4;
  if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + iVar7)) {
    uVar2 = *(short *)(&DAT_ffffb77e + iVar7) - 1;
    if ((short)uVar2 < -0xc) {
      uVar2 = 0xfff4;
    }
  } else {
    uVar2 = *(short *)(&DAT_ffffb77e + iVar7) + 1;
    if (0xc < (short)uVar2) {
      uVar2 = 0xc;
    }
  }
  *(ushort *)(&DAT_ffffb77e + iVar7) = uVar2;
  (&DAT_ffff9f27)[iVar7] = (&DAT_ffff9f27)[iVar7] & 0xf7;
  uVar3 = uVar2;
  if ((short)uVar2 < 0) {
    uVar3 = -uVar2;
    (&DAT_ffff9f27)[iVar7] = (&DAT_ffff9f27)[iVar7] | 8;
  }
  state_1_b = 10;
  if (5 < uVar3) {
    state_1_b = 0xc;
  }
  *(ushort *)((int)&DAT_ffffa12e + iVar7) =
      *(short *)((int)&comp_pos_x + iVar7) + uVar2;
  *(short *)((int)&DAT_ffffa232 + iVar7) =
      *(short *)((int)&comp_pos_y + iVar7) + -0x10;
  if (state_1_b != (&DAT_ffffa644)[iVar7]) {
    ecs_anim_unk_2((int)(short)(sVar4 + 0xc), unaff_A5, state_1_b);
  }
  return;
}

void FUN_0001ffec(void)

{
  int unaff_A4;

  FUN_00020308();
  if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    (&DAT_ffffb476)[unaff_A4] = 0;
    (&DAT_ffffb47a)[unaff_A4] = 2;
  } else {
    (&DAT_ffffb476)[unaff_A4] = 2;
    (&DAT_ffffb47a)[unaff_A4] = 0;
  }
  (&DAT_ffffb784)[unaff_A4] = 0;
  (&DAT_ffffb788)[unaff_A4] = 0;
  (&comp_collision_related)[unaff_A4] =
      (&comp_collision_related)[unaff_A4] + '\x02';
  return;
}

ushort FUN_0002001e(void)

{
  ushort uVar1;
  int unaff_A4;

  FUN_00020308();
  FUN_00020086();
  FUN_000201de();
  FUN_00020086();
  FUN_000201f6();
  FUN_00020216();
  uVar1 = (ushort)(byte)((&DAT_ffffb47a)[unaff_A4] | (&DAT_ffffb476)[unaff_A4]);
  if (((&DAT_ffffb47a)[unaff_A4] | (&DAT_ffffb476)[unaff_A4]) == 0) {
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x02';
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xf800;
    uVar1 = 0x100;
    if ((0x8f <
         (ushort)(*(ushort *)((int)&comp_pos_x + unaff_A4) - DAT_ffffce04)) &&
        (((ushort)(DAT_ffffce08 - *(short *)((int)&comp_pos_x + unaff_A4)) <
              0x90 ||
          ((ushort)comp_pos_x.fixed.i <=
           *(ushort *)((int)&comp_pos_x + unaff_A4))))) {
      uVar1 = 0xff00;
    }
    *(ushort *)((int)&comp_vel[0].x + unaff_A4) = uVar1;
  }
  return uVar1;
}

void FUN_00020086(void)

{
  int unaff_A2;

  // WARNING: Could not recover jumptable at 0x00020090. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00020094 +
             (int)*(short *)((int)&WORD_00020094 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A2))))();
  return;
}

void FUN_0002009c(void)

{
  int unaff_A4;

  FUN_00020308();
  FUN_0002012c();
  FUN_000201de();
  FUN_0002012c();
  FUN_000201f6();
  FUN_00020216();
  if ((&DAT_ffffb782)[unaff_A4] == -0x10) {
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x02';
  }
  return;
}

void FUN_000200d2(void)

{
  word wVar1;
  short *psVar2;
  short sVar3;
  byte state_1_b;
  char cVar5;
  ushort uVar4;
  ushort uVar6;
  word *pwVar7;
  word *extraout_A1;
  ulong unaff_A4;
  int iVar8;
  anim_item_t *unaff_A5;
  undefined1 uVar9;

  FUN_00020308();
  psVar2 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar3 = *psVar2 + 0x40;
  *psVar2 = sVar3;
  uVar9 = sVar3 == 0;
  player_update_pos(unaff_A4);
  FUN_00002856();
  if (!(bool)uVar9) {
    FUN_0001689e();
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x02';
  }
  pwVar7 = WORD_ARRAY_000202d0;
  while (true) {
    if ((short)*pwVar7 < 0)
      break;
    unaff_A4 =
        (ulong)(short)(*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                                  unaff_A4) +
                       *pwVar7);
    wVar1 = pwVar7[1];
    sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4) +
            wVar1;
    *(short *)(&DAT_ffffbc76 + unaff_A4) = sVar3;
    cVar5 = (&DAT_ffffb979)[unaff_A4];
    if (wVar1 != 0) {
      cVar5 = (&DAT_ffffb976)[sVar3] + cVar5;
    }
    (&DAT_ffffb976)[unaff_A4] = cVar5;
    FUN_000028aa();
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    pwVar7 = extraout_A1;
    if ((short)((ushort)(byte)((&DAT_ffffb976)[unaff_A4] + 0x40) << 8) < 0) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    }
  }
  sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4);
  iVar8 = (int)sVar3;
  if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + iVar8)) {
    uVar4 = *(short *)(&DAT_ffffb77e + iVar8) - 1;
    if ((short)uVar4 < -0xc) {
      uVar4 = 0xfff4;
    }
  } else {
    uVar4 = *(short *)(&DAT_ffffb77e + iVar8) + 1;
    if (0xc < (short)uVar4) {
      uVar4 = 0xc;
    }
  }
  *(ushort *)(&DAT_ffffb77e + iVar8) = uVar4;
  (&DAT_ffff9f27)[iVar8] = (&DAT_ffff9f27)[iVar8] & 0xf7;
  uVar6 = uVar4;
  if ((short)uVar4 < 0) {
    uVar6 = -uVar4;
    (&DAT_ffff9f27)[iVar8] = (&DAT_ffff9f27)[iVar8] | 8;
  }
  state_1_b = 10;
  if (5 < uVar6) {
    state_1_b = 0xc;
  }
  *(ushort *)((int)&DAT_ffffa12e + iVar8) =
      *(short *)((int)&comp_pos_x + iVar8) + uVar4;
  *(short *)((int)&DAT_ffffa232 + iVar8) =
      *(short *)((int)&comp_pos_y + iVar8) + -0x10;
  if (state_1_b != (&DAT_ffffa644)[iVar8]) {
    ecs_anim_unk_2((int)(short)(sVar3 + 0xc), unaff_A5, state_1_b);
  }
  return;
}

void FUN_000200f6(void)

{
  int unaff_A4;

  FUN_00020308();
  FUN_0002013e();
  FUN_000201de();
  FUN_0002013e();
  FUN_000201f6();
  FUN_00020216();
  if ((&DAT_ffffb782)[unaff_A4] == -0x20) {
    (&comp_collision_related)[unaff_A4] = 0;
  }
  return;
}

void FUN_0002012c(void)

{
  int unaff_A2;

  if ((&comp_unk_4)[unaff_A2] != -0x10) {
    (&comp_unk_4)[unaff_A2] = (&comp_unk_4)[unaff_A2] + '\x01';
    (&DAT_ffffb773)[unaff_A2] = (&DAT_ffffb773)[unaff_A2] + -1;
  }
  return;
}

void FUN_0002013e(void)

{
  int unaff_A2;

  if ((&comp_unk_4)[unaff_A2] != -0x20) {
    (&comp_unk_4)[unaff_A2] = (&comp_unk_4)[unaff_A2] + -1;
    (&DAT_ffffb773)[unaff_A2] = (&DAT_ffffb773)[unaff_A2] + '\x01';
  }
  return;
}

void FUN_00020150(void)

{
  return;
}

void FUN_00020152(void)

{
  int unaff_A2;

  if ((&comp_collision_related)[unaff_A2] == '\0') {
    (&DAT_ffffb773)[unaff_A2] = (&DAT_ffffb773)[unaff_A2] + -1;
    if ((char)(&DAT_ffffb773)[unaff_A2] < -0x17) {
      (&comp_collision_related)[unaff_A2] = 0xff;
    }
  } else {
    if ((char)(&DAT_ffffb773)[unaff_A2] < -6) {
      (&DAT_ffffb773)[unaff_A2] = (&DAT_ffffb773)[unaff_A2] + '\x02';
    }
    (&comp_unk_4)[unaff_A2] = (&comp_unk_4)[unaff_A2] + '\x04';
    if ('\x0e' < (char)(&comp_unk_4)[unaff_A2]) {
      (&comp_unk_4)[unaff_A2] = 0xf;
      audio_play(SOUND_ID_TOW_STOP);
      FUN_0001689e();
      (&comp_collision_related)[unaff_A2] = 0x14;
      *(char *)((int)&comp_state + unaff_A2) =
          *(char *)((int)&comp_state + unaff_A2) + '\x02';
    }
  }
  return;
}

void FUN_000201a2(void)

{
  char cVar1;
  int unaff_A2;

  cVar1 = (&comp_collision_related)[unaff_A2] + -1;
  (&comp_collision_related)[unaff_A2] = cVar1;
  if (cVar1 == '\0') {
    *(char *)((int)&comp_state + unaff_A2) =
        *(char *)((int)&comp_state + unaff_A2) + '\x02';
  }
  return;
}

void FUN_000201ae(void)

{
  int unaff_A2;

  if ((&comp_unk_4)[unaff_A2] == -0x20) {
    (&DAT_ffffb773)[unaff_A2] = (&DAT_ffffb773)[unaff_A2] + -1;
    if ((char)(&DAT_ffffb773)[unaff_A2] < -7) {
      (&comp_collision_related)[unaff_A2] = 0;
      *(undefined1 *)((int)&comp_state + unaff_A2) = 0;
      return;
    }
  } else {
    if ((char)(&DAT_ffffb773)[unaff_A2] < '\x10') {
      (&DAT_ffffb773)[unaff_A2] = (&DAT_ffffb773)[unaff_A2] + '\x01';
    }
    (&comp_unk_4)[unaff_A2] = (&comp_unk_4)[unaff_A2] + -1;
  }
  return;
}

void FUN_000201de(void)

{
  undefined1 uVar1;
  undefined1 *in_A0;
  int unaff_A4;

  (&DAT_ffffb989)[unaff_A4] = *in_A0;
  uVar1 = in_A0[1];
  (&DAT_ffffb991)[unaff_A4] = uVar1;
  (&DAT_ffffb999)[unaff_A4] = uVar1;
  (&DAT_ffffb9a1)[unaff_A4] = uVar1;
  return;
}

void FUN_000201f6(void)

{
  char cVar1;
  char *in_A0;
  int unaff_A4;

  (&DAT_ffffb98d)[unaff_A4] = -(*in_A0 + -0x80);
  cVar1 = -in_A0[1];
  (&DAT_ffffb995)[unaff_A4] = cVar1;
  (&DAT_ffffb99d)[unaff_A4] = cVar1;
  (&DAT_ffffb9a5)[unaff_A4] = cVar1;
  return;
}

void FUN_00020216(void)

{
  word wVar1;
  short sVar2;
  byte state_1_b;
  char cVar4;
  ushort uVar3;
  ushort uVar5;
  word *pwVar6;
  word *extraout_A1;
  int unaff_A4;
  int iVar7;
  anim_item_t *unaff_A5;

  pwVar6 = WORD_ARRAY_000202d0;
  while (true) {
    if ((short)*pwVar6 < 0)
      break;
    unaff_A4 =
        (int)(short)(*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                                unaff_A4) +
                     *pwVar6);
    wVar1 = pwVar6[1];
    sVar2 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4) +
            wVar1;
    *(short *)(&DAT_ffffbc76 + unaff_A4) = sVar2;
    cVar4 = (&DAT_ffffb979)[unaff_A4];
    if (wVar1 != 0) {
      cVar4 = (&DAT_ffffb976)[sVar2] + cVar4;
    }
    (&DAT_ffffb976)[unaff_A4] = cVar4;
    FUN_000028aa();
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    pwVar6 = extraout_A1;
    if ((short)((ushort)(byte)((&DAT_ffffb976)[unaff_A4] + 0x40) << 8) < 0) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    }
  }
  sVar2 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4);
  iVar7 = (int)sVar2;
  if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + iVar7)) {
    uVar3 = *(short *)(&DAT_ffffb77e + iVar7) - 1;
    if ((short)uVar3 < -0xc) {
      uVar3 = 0xfff4;
    }
  } else {
    uVar3 = *(short *)(&DAT_ffffb77e + iVar7) + 1;
    if (0xc < (short)uVar3) {
      uVar3 = 0xc;
    }
  }
  *(ushort *)(&DAT_ffffb77e + iVar7) = uVar3;
  (&DAT_ffff9f27)[iVar7] = (&DAT_ffff9f27)[iVar7] & 0xf7;
  uVar5 = uVar3;
  if ((short)uVar3 < 0) {
    uVar5 = -uVar3;
    (&DAT_ffff9f27)[iVar7] = (&DAT_ffff9f27)[iVar7] | 8;
  }
  state_1_b = 10;
  if (5 < uVar5) {
    state_1_b = 0xc;
  }
  *(ushort *)((int)&DAT_ffffa12e + iVar7) =
      *(short *)((int)&comp_pos_x + iVar7) + uVar3;
  *(short *)((int)&DAT_ffffa232 + iVar7) =
      *(short *)((int)&comp_pos_y + iVar7) + -0x10;
  if (state_1_b != (&DAT_ffffa644)[iVar7]) {
    ecs_anim_unk_2((int)(short)(sVar2 + 0xc), unaff_A5, state_1_b);
  }
  return;
}

void FUN_000202f2(void)

{
  undefined1 in_ZF;

  FUN_00002140();
  if ((bool)in_ZF) {
    FUN_00002140();
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00020308(void)

{
  ushort uVar1;
  ushort uVar2;
  byte bVar3;
  byte bVar4;
  byte bVar5;
  word *pwVar6;
  ushort *extraout_A0;
  entity_id_t unaff_A4;
  int iVar7;
  bool bVar8;
  undefined1 uVar9;

  _DAT_ffffdb1a = FUN_000189d0;
  if ((&comp_unk_11)[*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                                unaff_A4)] != '\0') {
    _DAT_ffffdb1a = FUN_000189fe;
  }
  bVar8 = _DAT_ffffdb1a == (code *)0x0;
  FUN_000202f2();
  if (bVar8) {
    pwVar6 = &WORD_000203a8;
    while (true) {
      uVar1 = *pwVar6;
      if ((short)uVar1 < 0)
        break;
      uVar2 =
          *(ushort *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4);
      uVar9 = CARRY2(uVar2, uVar1);
      unaff_A4 = (entity_id_t)(short)(uVar2 + uVar1);
      (*_DAT_ffffdb1a)(pwVar6 + 1);
      bVar8 = ((&comp_func_offset[0].unk4)[unaff_A4] & 1) == 0;
      if (!bVar8) {
        audio_play(SOUND_ID_DAMAGE_2);
        bVar5 = DAT_ffffde0e;
        if (((&comp_func_offset[0].unk4)[unaff_A4] & 4) != 0) {
          bVar5 = DAT_ffffde0f;
        }
        iVar7 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                                unaff_A4);
        if ((&comp_unk_11)[iVar7] != '\0') {
          return;
        }
        bVar3 = (&comp_collected_item_id_maybe)[iVar7];
        bVar4 = bVar3 - bVar5;
        (&comp_collected_item_id_maybe)[iVar7] = bVar4;
        if (bVar3 < bVar5 || bVar4 == 0) {
          (&comp_collected_item_id_maybe)[iVar7] = 10;
          *(undefined1 *)((int)&comp_state + iVar7) = 2;
        }
        (&comp_unk_11)[iVar7] = 0x1e;
        return;
      }
      FUN_00000ed6(unaff_A4, ENTITY_ID_ASHA);
      pwVar6 = extraout_A0;
      if ((bool)uVar9 || bVar8) {
        FUN_00002124(unaff_A4, 4);
        (&comp_func_offset[0].unk4)[*(
            short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4)] =
            (&comp_func_offset[0]
                  .unk4)[*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                                    unaff_A4)] |
            2;
        return;
      }
    }
  }
  return;
}

void FUN_000203bc(void)

{
  short sVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  sVar1 = *(short *)((int)&comp_pos_y + unaff_A4);
  *(short *)((int)&comp_pos_y + unaff_A4) = sVar1 + 0x25;
  sVar1 = sVar1 + -0x12;
  *(short *)((int)&component_pos_y_pepelogoo + unaff_A4) = sVar1;
  *(short *)((int)&DAT_ffffa22e + unaff_A4) = sVar1;
  *(short *)((int)&component_pos_x_pepelogoo + unaff_A4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + -0x20;
  *(short *)((int)&DAT_ffffa12a + unaff_A4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + 0x20;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x1c;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
  *(undefined2 *)((int)&component_unknown_3_pepelogoo + unaff_A4) = 0x1c;
  ecs_anim_unk_2(unaff_A4 + ENTITY_ID_PEPELOGOO, unaff_A5, 4);
  (&component_state_b_pepelogoo)[unaff_A4] =
      (&component_state_b_pepelogoo)[unaff_A4] | 0x20;
  *(undefined2 *)((int)&DAT_ffff9f24 + unaff_A4) = 0x1c;
  ecs_anim_unk_2(unaff_A4 + ENTITY_ID_08, unaff_A5, 4);
  (&DAT_ffff9f22)[unaff_A4] = (&DAT_ffff9f22)[unaff_A4] | 0x20;
  sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[2].unk1 + unaff_A4);
  FUN_00020a34();
  (&comp_collision_related)[sVar1] = (&comp_collision_related)[sVar1] + '\x02';
  return;
}

void FUN_00020432(void)

{
  short *psVar1;
  short sVar2;
  ulong unaff_A4;
  ulong ctx;
  undefined1 uVar3;
  bool bVar4;
  short sStack_4;
  char cStack_2;

  cStack_2 = '\0';
  sStack_4 = 0xc;
  do {
    ctx = unaff_A4;
    if ((&comp_unk_4)[ctx] == '\0') {
      cStack_2 = -1;
      psVar1 = (short *)((int)&comp_vel[0].y + ctx);
      sVar2 = *psVar1 + 0x10;
      *psVar1 = sVar2;
      uVar3 = sVar2 == 0;
      player_update_pos(ctx);
      FUN_0000287a();
      if (!(bool)uVar3) {
        psVar1 = (short *)((int)&comp_vel[0].x + ctx);
        *psVar1 = -*psVar1;
      }
      psVar1 = (short *)((int)&comp_vel[0].y + ctx);
      bVar4 = *psVar1 == 0;
      if (-1 < *psVar1) {
        FUN_00002856();
        if (!bVar4) {
          (&comp_unk_4)[ctx] = 0xff;
        }
      }
    }
    sStack_4 = sStack_4 + -1;
    unaff_A4 = ctx + 4;
  } while (sStack_4 != 0);
  if (cStack_2 == '\0') {
    *(undefined1 *)(ctx - 0x4bc6) = 3;
  }
  return;
}

void FUN_00020484(void)

{
  ushort uVar1;
  undefined2 *puVar2;
  int unaff_A4;
  int iVar3;

  uVar1 = 0;
  puVar2 = (undefined2 *)&UNK_000204b2;
  do {
    iVar3 = unaff_A4;
    (&DAT_ffffb978)[iVar3] = (char)uVar1;
    *(undefined2 *)((int)component_pos_old_x + iVar3) =
        *(undefined2 *)((int)&comp_pos_x + iVar3);
    *(undefined2 *)((int)component_pos_old_y + iVar3) =
        *(undefined2 *)((int)&comp_pos_y + iVar3);
    *(undefined2 *)(&comp_unk_4 + iVar3) = *puVar2;
    uVar1 = uVar1 + 1;
    puVar2 = puVar2 + 1;
    unaff_A4 = iVar3 + 4;
  } while (uVar1 < 0xc);
  *(char *)(iVar3 + -0x48b8) = *(char *)(iVar3 + -0x48b8) + '\x02';
  return;
}

void FUN_000204ca(void)

{
  short sVar1;
  ushort uVar2;
  short sVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  short sStack_4;
  char cStack_2;

  cStack_2 = '\0';
  sStack_4 = 0xc;
  do {
    if (*(short *)(&comp_unk_4 + unaff_A4) != 0) {
      cStack_2 = -1;
      sVar3 = (ushort)(byte)(&DAT_ffffb978)[unaff_A4] << 2;
      uVar2 = *(short *)(&comp_unk_4 + unaff_A4) - 1;
      *(ushort *)(&comp_unk_4 + unaff_A4) = uVar2;
      if (uVar2 == 0) {
        *(short *)((int)&comp_pos_x + unaff_A4) =
            *(short *)(&UNK_0002055c + sVar3);
        *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
            *(undefined2 *)(&UNK_0002055e + sVar3);
        if ((short)((short)unaff_A4 -
                    *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                               unaff_A4)) == 0x14) {
          ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
        }
      } else if (uVar2 < 0x40) {
        sVar1 = 0x1000 - uVar2 * uVar2;
        *(short *)((int)&comp_pos_x + unaff_A4) =
            *(short *)((int)component_pos_old_x + unaff_A4) +
            (short)((uint)((int)(short)(*(short *)(&UNK_0002055c + sVar3) -
                                        *(short *)((int)component_pos_old_x +
                                                   unaff_A4)) *
                           (int)sVar1 * 0x10) >>
                    0x10);
        *(short *)((int)&comp_pos_y + unaff_A4) =
            *(short *)((int)component_pos_old_y + unaff_A4) +
            (short)((uint)((int)(short)(*(short *)(&UNK_0002055e + sVar3) -
                                        *(short *)((int)component_pos_old_y +
                                                   unaff_A4)) *
                           (int)sVar1 * 0x10) >>
                    0x10);
      }
    }
    unaff_A4 = unaff_A4 + ENTITY_ID_PEPELOGOO;
    sStack_4 = sStack_4 + -1;
  } while (sStack_4 != 0);
  if (cStack_2 == '\0') {
    FUN_000205a6();
  }
  return;
}

void FUN_000205a6(void)

{
  short sVar1;
  short *psVar2;
  undefined *puVar3;
  int unaff_A4;

  *(undefined1 *)((int)&comp_state + unaff_A4) = 4;
  *(undefined2 *)(unaff_A4 + -0x488a) = 0;
  *(undefined2 *)(unaff_A4 + -0x4886) = 0;
  (&DAT_ffffb778)[unaff_A4] = 0;
  (&DAT_ffffb976)[unaff_A4] = 0;
  (&DAT_ffffb780)[unaff_A4] = 2;
  *(undefined1 *)(unaff_A4 + -0x4874) = 1;
  *(undefined1 *)(unaff_A4 + -0x4870) = 0;
  *(undefined1 *)(unaff_A4 + -0x486c) = 0;
  *(undefined1 *)(unaff_A4 + -0x4868) = 0;
  psVar2 = (short *)&UNK_0002058c;
  while (true) {
    if (*psVar2 < 0)
      break;
    sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4) +
            *psVar2;
    puVar3 = (undefined *)((int)psVar2 + 3);
    (&DAT_ffffb976)[sVar1] = *(undefined1 *)(psVar2 + 1);
    psVar2 = psVar2 + 2;
    (&DAT_ffffb978)[sVar1] = *puVar3;
  }
  return;
}

void FUN_000205f0(void)

{
  short sVar1;
  short sVar2;
  undefined2 uVar3;
  ushort uVar4;
  undefined1 uVar5;
  ulong unaff_A4;

  uVar3 = 0xffc0;
  if (*(ushort *)((int)&comp_pos_x + unaff_A4) <= (ushort)comp_pos_x.fixed.i) {
    uVar3 = 0x40;
  }
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = uVar3;
  player_update_pos_x(unaff_A4);
  uVar4 = DAT_ffffce04 + 0x40;
  if ((*(ushort *)((int)&comp_pos_x + unaff_A4) <= uVar4) ||
      (uVar4 = DAT_ffffce08 - 0x40,
       uVar4 < *(ushort *)((int)&comp_pos_x + unaff_A4))) {
    *(ushort *)((int)&comp_pos_x + unaff_A4) = uVar4;
  }
  FUN_00020948();
  FUN_0002070e();
  sVar1 = *(short *)(unaff_A4 - 0x4886);
  sVar2 = sVar1 + *(short *)(unaff_A4 - 0x488a);
  *(short *)(unaff_A4 - 0x488a) = sVar2;
  (&DAT_ffffb976)[unaff_A4] = (char)((ushort)sVar2 >> 8);
  if ((&DAT_ffffb778)[unaff_A4] == '\0') {
    uVar4 = sVar1 + 4;
    if (0x7ff < (short)uVar4) {
      (&DAT_ffffb778)[unaff_A4] = 0xff;
    }
  } else {
    uVar4 = sVar1 - 4;
    if ((short)uVar4 < -0x7ff) {
      (&DAT_ffffb778)[unaff_A4] = 0;
    }
  }
  *(ushort *)(unaff_A4 - 0x4886) = uVar4;
  if ((short)uVar4 < 0) {
    uVar4 = -uVar4;
  }
  uVar5 = (undefined1)(uVar4 >> 8);
  if (uVar4 >> 8 == 0) {
    uVar5 = 1;
  }
  (&DAT_ffffb780)[unaff_A4] = uVar5;
  FUN_00020682();
  FUN_00020682();
  return;
}

void FUN_00020682(void)

{
  char cVar1;
  int in_A1;
  int unaff_A4;

  cVar1 = (&DAT_ffffb780)[unaff_A4];
  if (((&comp_collision_related)[in_A1] & 0x80) == 0) {
    if (((&comp_collision_related)[in_A1] & 1) == 0) {
      if (((&comp_collision_related)[in_A1] & 0x40) == 0) {
        (&DAT_ffffb976)[in_A1] = cVar1 + (&DAT_ffffb976)[in_A1];
        if ((char)(&DAT_ffffb976)[in_A1] < ' ') {
          return;
        }
      } else {
        (&DAT_ffffb976)[in_A1] = (&DAT_ffffb976)[in_A1] - cVar1;
        if (-0x18 < (char)(&DAT_ffffb976)[in_A1]) {
          return;
        }
      }
    } else if (((&comp_collision_related)[in_A1] & 0x40) == 0) {
      (&DAT_ffffb976)[in_A1] = cVar1 + (&DAT_ffffb976)[in_A1];
      if ((byte)(&DAT_ffffb976)[in_A1] < 0x98) {
        return;
      }
    } else {
      (&DAT_ffffb976)[in_A1] = (&DAT_ffffb976)[in_A1] - cVar1;
      if (0x60 < (byte)(&DAT_ffffb976)[in_A1]) {
        return;
      }
    }
    (&comp_collision_related)[in_A1] = (&comp_collision_related)[in_A1] | 0x80;
    return;
  }
  if (((&comp_collision_related)[in_A1] & 0x40) == 0) {
    (&DAT_ffffb778)[in_A1] = cVar1 + (&DAT_ffffb778)[in_A1];
    if ((char)(&DAT_ffffb778)[in_A1] < '\f') {
      return;
    }
  } else {
    (&DAT_ffffb778)[in_A1] = (&DAT_ffffb778)[in_A1] - cVar1;
    if (-0xc < (char)(&DAT_ffffb778)[in_A1]) {
      return;
    }
  }
  (&comp_collision_related)[in_A1] = (&comp_collision_related)[in_A1] ^ 0xc0;
  return;
}

void FUN_0002070e(void)

{
  char cVar1;
  char extraout_D0b;
  short sVar2;
  short sVar3;
  ushort uVar4;
  short unaff_D3w;
  word wVar5;
  word wVar6;
  short unaff_D4w;
  short *psVar7;
  short *extraout_A0;
  short *psVar8;
  short *extraout_A0_00;
  int iVar9;
  int extraout_A1;
  int extraout_A1_00;
  int iVar10;
  int unaff_A4;
  anim_item_t *unaff_A5;
  ushort uStack_28;
  ushort uStack_26;
  short asStack_24[9];
  short asStack_12[7];
  undefined1 *puStack_4;

  uStack_26 = 0;
  uStack_28 = 0;
  cVar1 = *(char *)(unaff_A4 + -0x4870) + (&DAT_ffffb98e)[unaff_A4];
  *(char *)(unaff_A4 + -0x466e) = cVar1;
  *(char *)(unaff_A4 + -0x465e) = *(char *)(unaff_A4 + -0x4870) + cVar1;
  cVar1 = *(char *)(unaff_A4 + -0x4868) + (&DAT_ffffb996)[unaff_A4];
  *(char *)(unaff_A4 + -0x4666) = cVar1;
  *(char *)(unaff_A4 + -0x4662) = *(char *)(unaff_A4 + -0x4868) + cVar1;
  psVar8 = (short *)&UNK_000208d8;
  while (true) {
    if (*psVar8 < 0)
      break;
    iVar9 = (int)(short)(*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                                    unaff_A4) +
                         *psVar8);
    psVar7 = psVar8 + 2;
    *(short *)((int)component_pos_old_x + iVar9) = psVar8[1];
    psVar8 = psVar8 + 3;
    *(short *)((int)component_pos_old_y + iVar9) = *psVar7;
  }
  psVar8 = (short *)&UNK_000208f8;
  while (-1 < *psVar8) {
    FUN_000026c0();
    iVar9 =
        (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4) +
        (int)*extraout_A0;
    unaff_D3w = *(short *)((int)component_pos_old_x + iVar9) + unaff_D3w;
    *(short *)((int)component_pos_old_x + extraout_A1) = unaff_D3w;
    unaff_D4w = *(short *)((int)component_pos_old_y + iVar9) + unaff_D4w;
    *(short *)((int)component_pos_old_y + extraout_A1) = unaff_D4w;
    psVar8 = extraout_A0 + 1;
  }
  psVar8 = (short *)&UNK_00020912;
LAB_0002078c:
  if (*psVar8 < 0) {
    iVar9 = unaff_A4 + 4;
    sVar2 = 10;
    do {
      *(short *)((int)&comp_pos_x + iVar9) =
          *(short *)((int)&comp_pos_x + unaff_A4) +
          *(short *)((int)component_pos_old_x + iVar9);
      *(short *)((int)&comp_pos_y + iVar9) =
          *(short *)((int)&comp_pos_y + unaff_A4) +
          *(short *)((int)component_pos_old_y + iVar9);
      iVar9 = iVar9 + 4;
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
    sVar2 = uStack_28 + 4;
    *(short *)((int)&comp_unk_3 + unaff_A4) = sVar2;
    *(short *)((int)&DAT_ffff9f2c + unaff_A4) = sVar2;
    *(short *)((int)&DAT_ffff9f30 + unaff_A4) = sVar2;
    sVar3 = sVar2;
    for (uVar4 = 0; uVar4 < uStack_28; uVar4 = uVar4 + 2) {
      sVar3 = sVar3 + -2;
      *(short *)((int)&comp_unk_3 +
                 (int)*(short *)((int)asStack_24 + (int)(short)uVar4)) = sVar3;
    }
    if (uStack_26 != 0) {
      sVar3 = 0;
      do {
        sVar2 = sVar2 + 2;
        *(short *)((int)&comp_unk_3 +
                   (int)*(short *)((int)asStack_12 + (int)sVar3)) = sVar2;
        sVar3 = sVar3 + 2;
        uStack_26 = uStack_26 - 2;
      } while (uStack_26 != 0);
    }
    uVar4 = (byte)((&DAT_ffffb976)[unaff_A4] + 0x10) >> 4 & 0xe;
    (&DAT_ffff9f27)[unaff_A4] =
        (&UNK_00020938)[(short)uVar4] | (&DAT_ffff9f27)[unaff_A4] & 0xf7;
    if ((&UNK_00020939)[(short)uVar4] != (&DAT_ffffa644)[unaff_A4]) {
      puStack_4 = &LAB_000208d2;
      ecs_anim_unk_2(
          unaff_A4 + ENTITY_ID_0C, unaff_A5, (&UNK_00020939)[(short)uVar4]);
    }
    return;
  }
  wVar5 = angle_sin((&DAT_ffffb976)[unaff_A4]);
  wVar6 = angle_sin(extraout_D0b + 0x40);
  psVar8 = extraout_A0_00 + 1;
  sVar2 = *extraout_A0_00;
  sVar3 = *(short *)((int)component_pos_old_x + extraout_A1_00);
  *(short *)((int)component_pos_old_x + extraout_A1_00) =
      (short)((uint)(((int)sVar3 * (int)(short)wVar6 +
                      (int)sVar2 * (int)(short)wVar5) *
                     4) >>
              0x10);
  iVar9 = ((int)sVar2 * (int)(short)wVar6 - (int)sVar3 * (int)(short)wVar5) * 4;
  sVar2 = (short)((uint)iVar9 >> 0x10);
  *(short *)(&DAT_ffffbc76 + extraout_A1_00) = sVar2;
  if (iVar9 < 0) {
    for (uVar4 = 0; iVar9 = extraout_A1_00, uVar4 < uStack_26;
         uVar4 = uVar4 + 2) {
      iVar10 = (int)*(short *)((int)asStack_12 + (int)(short)uVar4);
      if (*(short *)(&DAT_ffffbc76 + iVar10) < sVar2)
        goto LAB_00020820;
    }
    goto LAB_0002082c;
  }
  for (uVar4 = 0; iVar9 = extraout_A1_00, uVar4 < uStack_28;
       uVar4 = uVar4 + 2) {
    iVar10 = (int)*(short *)((int)asStack_24 + (int)(short)uVar4);
    if (sVar2 < *(short *)(&DAT_ffffbc76 + iVar10))
      goto LAB_000207ee;
  }
  goto LAB_000207fa;
LAB_00020820:
  while (true) {
    *(short *)((int)asStack_12 + (int)(short)uVar4) = (short)iVar9;
    iVar9 = (int)(short)iVar10;
    uVar4 = uVar4 + 2;
    if (uStack_26 <= uVar4)
      break;
    iVar10 = (int)*(short *)((int)asStack_12 + (int)(short)uVar4);
  }
LAB_0002082c:
  *(short *)((int)asStack_12 + (int)(short)uStack_26) = (short)iVar9;
  uStack_26 = uStack_26 + 2;
  goto LAB_0002078c;
LAB_000207ee:
  while (true) {
    *(short *)((int)asStack_24 + (int)(short)uVar4) = (short)iVar9;
    iVar9 = (int)(short)iVar10;
    uVar4 = uVar4 + 2;
    if (uStack_28 <= uVar4)
      break;
    iVar10 = (int)*(short *)((int)asStack_24 + (int)(short)uVar4);
  }
LAB_000207fa:
  *(short *)((int)asStack_24 + (int)(short)uStack_28) = (short)iVar9;
  uStack_28 = uStack_28 + 2;
  goto LAB_0002078c;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00020948(void)

{
  ushort uVar1;
  ushort uVar2;
  byte bVar3;
  byte bVar4;
  byte bVar5;
  word *pwVar6;
  ushort *extraout_A0;
  entity_id_t unaff_A4;
  entity_id_t self;
  bool bVar7;
  undefined1 uVar8;

  _DAT_ffffdb1a = FUN_000189d0;
  if ((&comp_unk_11)[*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                                unaff_A4)] != '\0') {
    _DAT_ffffdb1a = FUN_000189fe;
  }
  pwVar6 = &WORD_00020a26;
  if ((0x1f < (ushort)((comp_pos_x.fixed.i + 0x10) -
                       *(short *)((int)&comp_pos_x + unaff_A4))) &&
      (bVar5 = (&DAT_ffffb976)[unaff_A4] + 0xc & 0x7f,
       bVar7 = bVar5 == 0x18,
       pwVar6 = &WORD_00020a26,
       bVar5 < 0x18)) {
    FUN_000202f2();
    if (!bVar7) {
      return;
    }
    pwVar6 = &WORD_00020a10;
  }
  while (true) {
    uVar1 = *pwVar6;
    if ((short)uVar1 < 0) {
      return;
    }
    uVar2 = *(ushort *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4);
    uVar8 = CARRY2(uVar2, uVar1);
    unaff_A4 = (entity_id_t)(short)(uVar2 + uVar1);
    (*_DAT_ffffdb1a)(pwVar6 + 1);
    bVar7 = ((&comp_func_offset[0].unk4)[unaff_A4] & 1) == 0;
    if (!bVar7)
      break;
    FUN_00000ed6(unaff_A4, ENTITY_ID_ASHA);
    pwVar6 = extraout_A0;
    if ((bool)uVar8 || bVar7) {
      FUN_00002124(unaff_A4, 4);
      (&comp_func_offset[0].unk4)[*(
          short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4)] =
          (&comp_func_offset[0].unk4)[*(
              short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4)] |
          2;
      return;
    }
  }
  audio_play(SOUND_ID_DAMAGE_2);
  bVar5 = DAT_ffffde0e;
  if (((&comp_func_offset[0].unk4)[unaff_A4] & 4) != 0) {
    bVar5 = DAT_ffffde0f;
  }
  self = (entity_id_t) *
         (short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4);
  if ((&comp_unk_11)[self] != '\0') {
    return;
  }
  bVar3 = (&comp_collected_item_id_maybe)[self];
  bVar4 = bVar3 - bVar5;
  (&comp_collected_item_id_maybe)[self] = bVar4;
  if (bVar3 < bVar5 || bVar4 == 0) {
    bVar5 = ecs_unk_3(self, 2);
    (&comp_collected_item_id_maybe)[self] = bVar5;
    *(undefined1 *)((int)&comp_state + self) = 5;
  }
  (&comp_unk_11)[self] = 0x1e;
  return;
}

void FUN_00020a34(void)

{
  word wVar1;
  short sVar2;
  short unaff_D6w;
  int unaff_A4;

  sVar2 = 0xb;
  do {
    (&comp_unk_4)[unaff_A4] = 0;
    wVar1 = rand();
    *(short *)((int)&comp_vel[0].x + unaff_A4) =
        ((short)wVar1 >> 10) +
        (*(short *)((int)&comp_pos_x + unaff_A4) - unaff_D6w) * 4;
    *(word *)((int)&comp_vel[0].y + unaff_A4) = (wVar1 & 0xff) - 0x400;
    unaff_A4 = unaff_A4 + 4;
    sVar2 = sVar2 + -1;
  } while (sVar2 != -1);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00020a72(void)

{
  byte bVar1;
  short sVar2;
  int unaff_A4;

  (&comp_collision_related)[unaff_A4] =
      (&comp_collision_related)[unaff_A4] + '\x02';
  _DAT_ffffdb3e = 0xb4;
  audio_play_sound_asha_dies();
  while (true) {
    IO_Z80BUS = 0x100;
    do {
      bVar1 = IO_Z80BUS._0_1_;
    } while ((bVar1 & 1) != 0);
    if (z80_ram_something_1 == '\0')
      break;
    IO_Z80BUS = 0;
    sVar2 = 0x1f;
    do {
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
  }
  (&z80_ram)[(short)(((byte)(z80_ram_something_3 + z80_ram_something_2) & 0xf) +
                     0x1c30)] = 0x4c;
  z80_ram_something_3 = z80_ram_something_3 + '\x01';
  IO_Z80BUS = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00020a86(void)

{
  ushort uVar1;
  short sVar2;
  char duration;
  char extraout_D1b;
  vdp_color_t *pvVar3;
  vdp_color_t *pvVar4;
  int unaff_A4;

  _DAT_ffffdb3e = _DAT_ffffdb3e + -1;
  if (_DAT_ffffdb3e == 0) {
    DAT_ffffdc61 = 0;
    DAT_ffffdc62 = 1;
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x02';
    FUN_0001fd5e();
    duration = extraout_D1b;
  } else {
    for (uVar1 = (0xb4 - _DAT_ffffdb3e) * 2; 0x53 < uVar1;
         uVar1 = uVar1 - 0x54) {
    }
    sVar2 = 0xf;
    pvVar3 = palettes_2;
    do {
      *pvVar3 = *(vdp_color_t *)(&UNK_0001fdd8 + (short)uVar1);
      uVar1 = uVar1 + 2;
      if (0x53 < uVar1) {
        uVar1 = 0;
      }
      sVar2 = sVar2 + -1;
      pvVar3 = pvVar3 + 1;
    } while (sVar2 != -1);
    duration = -1;
  }
  sVar2 = 7;
  pvVar3 = palettes_2;
  pvVar4 = palettes[1];
  do {
    *(undefined4 *)pvVar4 = *(undefined4 *)pvVar3;
    sVar2 = sVar2 + -1;
    pvVar3 = pvVar3 + 2;
    pvVar4 = pvVar4 + 2;
  } while (sVar2 != -1);
  palette_set_fade(PALETTE_ID_FLAG_1,
                   PALETTE_FADE_1,
                   duration,
                   (palette_color_iter_t)0xffffffff);
  return;
}

void FUN_00020aa8(void)

{
  short *psVar1;
  short sVar2;
  short sVar3;
  undefined *puVar4;
  int unaff_A4;
  int iVar5;

  FUN_00020a34();
  sVar2 = *(short *)((int)&comp_pos_y + unaff_A4);
  sVar3 = 0xb;
  puVar4 = &UNK_00020ae0;
  do {
    iVar5 = unaff_A4;
    *(undefined2 *)((int)&comp_unk_3 + iVar5) = 0x18;
    (&DAT_ffffb773)[iVar5] = *puVar4;
    psVar1 = (short *)((int)&comp_vel[0].y + iVar5);
    *psVar1 = *psVar1 + (*(short *)((int)&comp_pos_y + iVar5) - sVar2) * -2;
    sVar3 = sVar3 + -1;
    puVar4 = puVar4 + 1;
    unaff_A4 = iVar5 + 4;
  } while (sVar3 != -1);
  *(char *)(iVar5 + -0x48b8) = *(char *)(iVar5 + -0x48b8) + '\x02';
  return;
}

void FUN_00020aec(void)

{
  short *psVar1;
  short sVar2;
  char cVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar4;
  bool bVar5;
  short sStack_4;

  sStack_4 = 0xc;
  do {
    if ((&comp_func_offset[0].func_offset_from_15ede)[unaff_A4] == 4) {
      if ((&DAT_ffffb773)[unaff_A4] == '\0') {
        if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
          sVar2 =
              *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4);
          if (unaff_A4 == (int)sVar2) {
            if (10 < (byte)(&comp_unk_4)[sVar2]) {
              FUN_00015e86();
              FUN_00020b78();
              return;
            }
            (&comp_has_func_maybe)[unaff_A4] =
                (&comp_has_func_maybe)[unaff_A4] | 8;
          } else {
            (&comp_unk_4)[sVar2] = (&comp_unk_4)[sVar2] + '\x01';
            FUN_00020b78();
          }
        }
      } else {
        cVar3 = (&DAT_ffffb773)[unaff_A4] + -1;
        (&DAT_ffffb773)[unaff_A4] = cVar3;
        if (cVar3 != '\0') {
          psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
          sVar2 = *psVar1 + 0x10;
          *psVar1 = sVar2;
          uVar4 = sVar2 == 0;
          player_update_pos(unaff_A4);
          FUN_0000287a();
          if (!(bool)uVar4) {
            psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
            *psVar1 = -*psVar1;
          }
          psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
          bVar5 = *psVar1 == 0;
          if ((*psVar1 < 0) || (FUN_00002856(), bVar5))
            goto LAB_00020b6c;
          (&DAT_ffffb773)[unaff_A4] = 0;
        }
        (&comp_has_func_maybe)[unaff_A4] =
            (&comp_has_func_maybe)[unaff_A4] & 0xdf;
        (&comp_anim_base_offset + unaff_A4)[0] = 0x14;
        (&comp_anim_base_offset + unaff_A4)[1] = 0;
        ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
      }
    }
  LAB_00020b6c:
    unaff_A4 = unaff_A4 + ENTITY_ID_PEPELOGOO;
    sStack_4 = sStack_4 + -1;
    if (sStack_4 == 0) {
      return;
    }
  } while (true);
}

void FUN_00020b78(void)

{
  int unaff_A4;

  (&comp_unk_10)[unaff_A4] = 0;
  FUN_00024d78();
  FUN_00024dea();
  return;
}

void FUN_00020b92(void)

{
  char cVar1;
  char cVar2;
  undefined1 *extraout_A0;
  undefined1 *extraout_A0_00;
  undefined1 *puVar3;
  undefined *puVar4;
  undefined *extraout_A1;
  byte *unaff_A3;

  cVar1 = (char)*(undefined2 *)(unaff_A3 + 0xc);
  cVar2 = (char)*(undefined2 *)(unaff_A3 + 0xe);
  if ((*unaff_A3 & 1) == 0) {
    FUN_00020c96();
    FUN_00020c96();
    FUN_00020c96();
    FUN_00020c96();
    FUN_00020c96();
    FUN_00020c96();
    puVar4 = &UNK_00020cc2;
    puVar3 = extraout_A0;
    if ((*unaff_A3 & 4) != 0) {
      puVar4 = &UNK_00020cc7;
    }
  } else {
    FUN_00020c96();
    FUN_00020c96();
    FUN_00020c96();
    FUN_00020c96();
    FUN_00020c96();
    FUN_00020c96();
    cVar1 = '\0';
    cVar2 = '\0';
    puVar3 = extraout_A0_00;
    puVar4 = extraout_A1;
  }
  *puVar3 = *puVar4;
  puVar3[1] = puVar4[1];
  puVar3[2] = puVar4[2];
  puVar3[3] = puVar4[3] + cVar1;
  puVar3[4] = puVar4[4] + cVar2;
  return;
}

void FUN_00020c96(void)

{
  char in_D0b;
  char in_D1b;
  undefined1 *in_A0;
  undefined1 *in_A1;

  *in_A0 = *in_A1;
  in_A0[1] = in_A1[1];
  in_A0[2] = in_A1[2];
  in_A0[3] = in_A1[3] + in_D0b;
  in_A0[4] = in_A1[4] + in_D1b;
  return;
}

angle_t angle_something_1(angle_t angle)

{
  angle_t angle_2;

  angle_2 = angle - 0x40;
  if ((char)angle_2 < '\0') {
    if ((angle_2 & 0x40) == 0) {
      return angle_2;
    }
  } else if ((angle_2 & 0x40) != 0) {
    return angle_2;
  }
  return (angle_2 ^ 0x7f) + 1;
}

void angle_something_2(angle_t *angle)

{
  angle_t angle_2;
  angle_t angle_3;
  angle_t angle_4;
  angle_t aVar1;
  word sin;

  sin = angle_sin(angle[6]);
  *(short *)(angle + 10) = (short)((uint)((int)(short)sin << 7) >> 0x10);
  sin = angle_sin(angle_2 + 0x40);
  *(short *)(angle + 8) = (short)((uint)((int)(short)sin << 7) >> 0x10);
  sin = angle_sin(angle[7] + angle_3);
  *(short *)(angle + 0xc) = *(short *)(angle + 8) + (short)(char)(sin >> 8);
  sin = angle_sin(angle_4 - 0x40);
  *(short *)(angle + 0xe) = *(short *)(angle + 10) + (short)(char)(sin >> 8);
  sin = angle_sin(angle[5] + angle[1]);
  *(short *)(angle + 8) =
      (short)((uint)((int)(short)sin * (int)*(short *)(angle + 8) * 4) >> 0x10);
  *(short *)(angle + 0xc) =
      (short)((uint)((int)(short)sin * (int)*(short *)(angle + 0xc) * 4) >>
              0x10);
  sin = angle_sin(angle[1]);
  *(short *)(angle + 0x10) = (short)((uint)((short)sin * 0x88) >> 0x10);
  aVar1 = angle_something_1(angle[1]);
  (&DAT_ffffbe76)[*(short *)(angle + 2)] = aVar1;
  return;
}

void FUN_00020d84(entity_id_t self, entity_id_t other)

{
  short sVar1;
  word sin;
  entity_id_t self_00;
  entity_id_w_t other_b;

  other_b =
      *(entity_id_w_t *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + self);
  sin = angle_sin(angle_t_ffffdc6e);
  *(short *)((int)&comp_pos_x + (int)(short)other_b) =
      *(short *)((int)&comp_pos_x + self) +
      (short)((uint)((short)sin * 0x58) >> 0x10);
  *(short *)((int)&comp_pos_y + (int)(short)other_b) =
      *(short *)((int)&comp_pos_y + self) + -0x16;
  self_00 = (entity_id_t)(short)other_b;
  sVar1 = (short)((uint)(byte)(angle_t_ffffdc6e - 0x35) * 0xc00 >> 0x10) * 2;
  (&comp_state_a)[self_00] =
      (&entity_state_mixed_a_t_ARRAY_00020de6[0].field0_0x0)[sVar1] |
      (&comp_state_a)[self_00] & ~ENTITY_STATE_A_08;
  if ((&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar1] !=
      (&comp_anim_c)[self_00]) {
    ecs_anim_unk_2(
        self_00,
        (anim_item_t *)other,
        (&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar1]);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00020dfe(entity_id_t self)

{
  short sVar1;
  byte bVar2;
  angle_t aVar5;
  short sVar3;
  ushort uVar4;
  short sVar6;
  ushort uVar7;
  byte bVar8;
  undefined2 *puVar9;
  short *psVar10;
  int iVar11;
  short *psVar12;

  if ((DAT_ffffdc60 & 0x40) == 0) {
    aVar5 = angle_something_1(angle_t_ffffdc6e);
    (&DAT_ffffbe76)[*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                               self)] = aVar5;
  }
  FUN_00020ef6(&DAT_ffffdb40);
  FUN_00020ef6(&DAT_ffffdb40);
  FUN_00020ef6(&DAT_ffffdb40);
  FUN_00020ef6(&DAT_ffffdb40);
  DAT_ffffdc70 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + self);
  _DAT_ffffdc72 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                             (int)DAT_ffffdc70);
  sRamffffdc74 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                            (int)_DAT_ffffdc72);
  sRamffffdc76 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                            (int)sRamffffdc74);
  uRamffffdc78 = *(undefined2 *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                                 (int)sRamffffdc76);
  sVar3 = 3;
  puVar9 = &DAT_ffffdc70;
  do {
    psVar10 = (short *)(int)(short)puVar9;
    iVar11 = (int)*psVar10;
    bVar8 = (&DAT_ffffbe76)[iVar11];
    sVar6 = sVar3;
    do {
      psVar10 = psVar10 + 1;
      sVar1 = *psVar10;
      bVar2 = (&DAT_ffffbe76)[sVar1];
      if (bVar2 < bVar8) {
        *psVar10 = (short)iVar11;
        iVar11 = (int)sVar1;
        bVar8 = bVar2;
      }
      sVar6 = sVar6 + -1;
    } while (sVar6 != -1);
    *puVar9 = (short)iVar11;
    sVar3 = sVar3 + -1;
    puVar9 = puVar9 + 1;
  } while (sVar3 != -1);
  psVar10 = &DAT_ffffdc70;
  uVar4 = 0;
  do {
    if ((char)(&DAT_ffffbe76)[*psVar10] < '\0')
      break;
    psVar10 = psVar10 + 1;
    uVar4 = uVar4 + 1;
  } while (uVar4 < 5);
  psVar12 = (short *)(int)(short)psVar10;
  sVar3 = 0x10;
  uVar7 = uVar4;
  while (uVar7 = uVar7 - 1, -1 < (short)uVar7) {
    psVar12 = psVar12 + -1;
    sVar6 = *psVar12;
    sVar3 = sVar3 + -2;
    *(short *)((int)&comp_unk_3 + (int)sVar6) = sVar3;
    sVar6 = *(short *)(&DAT_ffffbe78 + sVar6);
    if (sVar6 < 0) {
      *(byte *)(int)sVar6 = *(byte *)(int)sVar6 | 1;
    }
  }
  sVar3 = 0x10;
  while (uVar4 < 5) {
    uVar4 = uVar4 + 1;
    psVar12 = psVar10 + 1;
    sVar6 = *psVar10;
    sVar3 = sVar3 + 2;
    *(short *)((int)&comp_unk_3 + (int)sVar6) = sVar3;
    sVar6 = *(short *)(&DAT_ffffbe78 + sVar6);
    psVar10 = psVar12;
    if (sVar6 < 0) {
      *(byte *)(int)sVar6 = *(byte *)(int)sVar6 & 0xfe;
    }
  }
  FUN_00020b92();
  FUN_00020b92();
  FUN_00020b92();
  FUN_00020b92();
  return;
}

void FUN_00020ef6(angle_t *angle)

{
  angle[1] = angle[4] + angle_t_ffffdc6e;
  angle_something_2(angle);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

short FUN_00020f0c(void)

{
  entity_id_w_t eVar1;

  eVar1 = entity_id_w_t_ffffdb4e;
  if ((short)entity_id_w_t_ffffdb4e < (short)_DAT_ffffdb8e) {
    eVar1 = _DAT_ffffdb8e;
  }
  if ((short)eVar1 < (short)_DAT_ffffdbce) {
    eVar1 = _DAT_ffffdbce;
  }
  if ((short)eVar1 < (short)_DAT_ffffdc0e) {
    eVar1 = _DAT_ffffdc0e;
  }
  return (DAT_ffffce0a - (eVar1 + 6)) + -8;
}

void FUN_00020f3a(void)

{
  undefined2 uVar1;
  int unaff_A4;

  uVar1 = FUN_00020f0c();
  *(undefined2 *)((int)&comp_pos_y + unaff_A4) = uVar1;
  return;
}

undefined4 FUN_00020f42(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = FUN_00020f0c();
  if (sVar1 <= *(short *)((int)&comp_pos_y + unaff_A4)) {
    *(short *)((int)&comp_pos_y + unaff_A4) = sVar1;
    return 0xffffffff;
  }
  return 0;
}

void FUN_00020f56(void)

{
  short sVar1;
  word wVar2;
  short sVar3;
  undefined *puVar4;
  entity_id_t self;
  int unaff_A4;
  anim_item_t *unaff_A5;

  sVar3 = 3;
  puVar4 = &DAT_ffffdb40;
  do {
    sVar1 = *(short *)(puVar4 + 2);
    *(short *)((int)&comp_pos_x + (int)sVar1) =
        *(short *)(puVar4 + 0x10) + *(short *)((int)&comp_pos_x + unaff_A4);
    *(short *)((int)&comp_pos_y + (int)sVar1) =
        *(short *)((int)&comp_pos_y + unaff_A4) + 6;
    puVar4 = puVar4 + 0x40;
    sVar3 = sVar3 + -1;
  } while (sVar3 != -1);
  if ((DAT_ffffdc60 & 0x40) == 0) {
    sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
    wVar2 = angle_sin(angle_t_ffffdc6e);
    *(short *)((int)&comp_pos_x + (int)sVar3) =
        *(short *)((int)&comp_pos_x + unaff_A4) +
        (short)((uint)((short)wVar2 * 0x58) >> 0x10);
    *(short *)((int)&comp_pos_y + (int)sVar3) =
        *(short *)((int)&comp_pos_y + unaff_A4) + -0x16;
    self = (entity_id_t)sVar3;
    sVar3 = (short)((uint)(byte)(angle_t_ffffdc6e - 0x35) * 0xc00 >> 0x10) * 2;
    (&comp_state_a)[self] =
        (&entity_state_mixed_a_t_ARRAY_00020de6[0].field0_0x0)[sVar3] |
        (&comp_state_a)[self] & ~ENTITY_STATE_A_08;
    if ((&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar3] !=
        (&comp_anim_c)[self]) {
      ecs_anim_unk_2(
          self,
          unaff_A5,
          (&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar3]);
    }
    return;
  }
  return;
}

void FUN_00020f8a(void)

{
  undefined1 uVar1;
  undefined1 extraout_D1b;
  undefined1 unaff_D2b;
  int unaff_A3;

  uVar1 = FUN_00020f9a();
  *(undefined1 *)(unaff_A3 + 5) = uVar1;
  *(undefined1 *)(unaff_A3 + 6) = extraout_D1b;
  *(undefined1 *)(unaff_A3 + 7) = unaff_D2b;
  return;
}

undefined2 FUN_00020f9a(void)

{
  byte bVar1;
  byte *unaff_A3;

  bVar1 = BYTE_ARRAY_ARRAY_00020fba[0][(short)((ushort)unaff_A3[0x12] * 3)];
  if ((*unaff_A3 & 2) != 0) {
    bVar1 = -bVar1;
  }
  return CONCAT11((char)((ushort)((ushort)unaff_A3[0x12] * 3) >> 8), bVar1);
}

void FUN_0002107a(void)

{
  short sVar1;
  char cVar2;
  int unaff_A4;

  DAT_ffffdc63 = DAT_ffffdc63 + '\x01';
  FUN_0001fe84();
  cVar2 = *(char *)((int)&comp_state + unaff_A4);
  if (-1 < cVar2) {
    (&comp_collision_related)[unaff_A4] = 0;
    *(byte *)((int)&comp_state + unaff_A4) =
        *(byte *)((int)&comp_state + unaff_A4) | 0x80;
  }
  sVar1 = *(short *)((int)&WORD_000210ae +
                     (int)(short)(ushort)(byte)(cVar2 * '\x02'));
  (*(code *)((int)&WORD_000210ae +
             (int)*(short *)((int)&WORD_000210ae +
                             (int)(short)(ushort)(byte)(&comp_collision_related)
                                 [unaff_A4] +
                             (int)sVar1) +
             (int)sVar1))();
  return;
}

void FUN_000210ba(void)

{
  short sVar1;
  word wVar2;
  short sVar3;
  undefined *puVar4;
  entity_id_t unaff_A4;
  entity_id_t eVar5;
  anim_item_t *unaff_A5;

  *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
  angle_t_ffffdc6e = 0xb8;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x10;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
  (&component_state_b_pepelogoo)[unaff_A4] =
      (&component_state_b_pepelogoo)[unaff_A4] | 0x20;
  *(undefined2 *)(unaff_A4 - 0x4184) = 0;
  (&DAT_ffffa63c)[unaff_A4] = 0xff;
  FUN_0002110e();
  FUN_0002110e();
  FUN_0002110e();
  FUN_0002110e();
  eVar5 = (entity_id_t) *
          (short *)((int)&comp_unkown_t_ARRAY_ffffb362[1].unk1 + unaff_A4);
  FUN_00020dfe(eVar5);
  FUN_00020f3a();
  sVar3 = 3;
  puVar4 = &DAT_ffffdb40;
  do {
    sVar1 = *(short *)(puVar4 + 2);
    *(short *)((int)&comp_pos_x + (int)sVar1) =
        *(short *)(puVar4 + 0x10) + *(short *)((int)&comp_pos_x + eVar5);
    *(short *)((int)&comp_pos_y + (int)sVar1) =
        *(short *)((int)&comp_pos_y + eVar5) + 6;
    puVar4 = puVar4 + 0x40;
    sVar3 = sVar3 + -1;
  } while (sVar3 != -1);
  if ((DAT_ffffdc60 & 0x40) == 0) {
    sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + eVar5);
    wVar2 = angle_sin(angle_t_ffffdc6e);
    *(short *)((int)&comp_pos_x + (int)sVar3) =
        *(short *)((int)&comp_pos_x + eVar5) +
        (short)((uint)((short)wVar2 * 0x58) >> 0x10);
    *(short *)((int)&comp_pos_y + (int)sVar3) =
        *(short *)((int)&comp_pos_y + eVar5) + -0x16;
    eVar5 = (entity_id_t)sVar3;
    sVar3 = (short)((uint)(byte)(angle_t_ffffdc6e - 0x35) * 0xc00 >> 0x10) * 2;
    (&comp_state_a)[eVar5] =
        (&entity_state_mixed_a_t_ARRAY_00020de6[0].field0_0x0)[sVar3] |
        (&comp_state_a)[eVar5] & ~ENTITY_STATE_A_08;
    if ((&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar3] !=
        (&comp_anim_c)[eVar5]) {
      ecs_anim_unk_2(
          eVar5,
          unaff_A5,
          (&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar3]);
    }
    return;
  }
  return;
}

void FUN_0002110e(void)

{
  undefined1 uVar1;
  undefined1 extraout_D1b;
  undefined1 unaff_D2b;
  undefined1 *unaff_A2;
  undefined1 *unaff_A3;
  int unaff_A4;

  *(short *)(unaff_A3 + 2) = (short)unaff_A4 + 4;
  *(short *)(unaff_A4 + -0x4184) = (short)unaff_A3;
  *unaff_A3 = *unaff_A2;
  unaff_A3[4] = unaff_A2[1];
  unaff_A3[0x12] = 0x10;
  *(undefined1 **)(unaff_A4 + -0x5fde) = unaff_A3 + 0x1c;
  unaff_A3[0x3f] = 0xff;
  *(undefined2 *)(&component_state_b_pepelogoo + unaff_A4) = 0xe300;
  *(undefined2 *)((int)&DAT_ffffa32e + unaff_A4) = 0;
  uVar1 = FUN_00020f9a();
  unaff_A3[5] = uVar1;
  unaff_A3[6] = extraout_D1b;
  unaff_A3[7] = unaff_D2b;
  return;
}

void FUN_0002114e(void)

{
  short sVar1;
  ushort uVar2;
  byte bVar3;
  ushort uVar4;
  word wVar5;
  short sVar6;
  undefined *puVar7;
  entity_id_t self;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar8;

  FUN_000214da((entity_id_t)unaff_A5);
  bVar3 = DAT_ffffdc60 & 0x80;
  DAT_ffffdc60 = DAT_ffffdc60 | 0x80;
  if (bVar3 == 0) {
    DAT_ffffdb52._0_1_ = 0x10;
    DAT_ffffdb92 = 0x10;
    DAT_ffffdbd2 = 0x10;
    DAT_ffffdc12 = 0x10;
  }
  bVar8 = false;
  FUN_000214b2();
  if (!bVar8) {
    FUN_00021468();
    FUN_00020dfe(unaff_A4);
    sVar6 = 3;
    puVar7 = &DAT_ffffdb40;
    do {
      sVar1 = *(short *)(puVar7 + 2);
      *(short *)((int)&comp_pos_x + (int)sVar1) =
          *(short *)(puVar7 + 0x10) + *(short *)((int)&comp_pos_x + unaff_A4);
      *(short *)((int)&comp_pos_y + (int)sVar1) =
          *(short *)((int)&comp_pos_y + unaff_A4) + 6;
      puVar7 = puVar7 + 0x40;
      sVar6 = sVar6 + -1;
    } while (sVar6 != -1);
    if ((DAT_ffffdc60 & 0x40) == 0) {
      sVar6 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
      wVar5 = angle_sin(angle_t_ffffdc6e);
      *(short *)((int)&comp_pos_x + (int)sVar6) =
          *(short *)((int)&comp_pos_x + unaff_A4) +
          (short)((uint)((short)wVar5 * 0x58) >> 0x10);
      *(short *)((int)&comp_pos_y + (int)sVar6) =
          *(short *)((int)&comp_pos_y + unaff_A4) + -0x16;
      self = (entity_id_t)sVar6;
      sVar6 =
          (short)((uint)(byte)(angle_t_ffffdc6e - 0x35) * 0xc00 >> 0x10) * 2;
      (&comp_state_a)[self] =
          (&entity_state_mixed_a_t_ARRAY_00020de6[0].field0_0x0)[sVar6] |
          (&comp_state_a)[self] & ~ENTITY_STATE_A_08;
      if ((&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar6] !=
          (&comp_anim_c)[self]) {
        ecs_anim_unk_2(
            self,
            unaff_A5,
            (&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar6]);
      }
      return;
    }
    return;
  }
  FUN_00020dfe(unaff_A4);
  FUN_00020f56();
  uVar2 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  uVar4 = uVar2;
  if ((short)uVar2 < 0) {
    uVar4 = -uVar2;
  }
  if ((short)(uVar2 ^ (short)(char)angle_t_ffffdc6e) < 0) {
    (&comp_collision_related)[unaff_A4] = 4;
  } else {
    if (uVar4 < 0x60) {
      DAT_ffffdc60 = DAT_ffffdc60 | 2;
    } else {
      if (uVar4 < 0x90) {
        (&comp_collision_related)[unaff_A4] = 6;
        goto LAB_000211ce;
      }
      DAT_ffffdc60 = DAT_ffffdc60 & 0xfd;
    }
    (&comp_collision_related)[unaff_A4] = 2;
  }
LAB_000211ce:
  DAT_ffffdc60 = DAT_ffffdc60 & 0x7f;
  return;
}

void FUN_000211d6(void)

{
  short sVar1;
  ushort uVar2;
  byte bVar3;
  byte bVar4;
  angle_t aVar5;
  undefined2 uVar6;
  ushort uVar7;
  word wVar8;
  short sVar9;
  undefined *puVar10;
  entity_id_t self;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar11;

  FUN_000214da((entity_id_t)unaff_A5);
  bVar4 = DAT_ffffdc60;
  bVar3 = DAT_ffffdc60 & 0x80;
  DAT_ffffdc60 = DAT_ffffdc60 | 0x80;
  if (bVar3 == 0) {
    DAT_ffffdb52._0_1_ = '0';
    DAT_ffffdc12 = 0x30;
    uVar6 = 0x180;
    aVar5 = angle_t_ffffdc6e;
    if ((bVar4 & 2) != 0) {
      aVar5 = -angle_t_ffffdc6e;
    }
    if ((char)aVar5 < '\0') {
      uVar6 = 0xfe80;
    }
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = uVar6;
    DAT_ffffdc61 = '\0';
  }
  uVar11 = DAT_ffffdc61 == '\0';
  if ((bool)uVar11) {
    FUN_00021468();
    FUN_000214b2();
    if ((bool)uVar11) {
      DAT_ffffdc61 = DAT_ffffdc61 + '\x01';
    }
  } else {
    FUN_00021436();
    player_update_pos_x(unaff_A4);
    if ((DAT_ffffdb52._0_1_ == '\x10') || (DAT_ffffdb92 == '\x10')) {
      uVar2 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
      uVar7 = uVar2;
      if ((short)uVar2 < 0) {
        uVar7 = -uVar2;
      }
      if ((DAT_ffffdc60 & 2) == 0) {
        if ((-1 < (short)(uVar2 ^ (short)(char)angle_t_ffffdc6e)) &&
            (0x8f < uVar7))
          goto FUN_00020f56;
      } else if (uVar7 < 0x80)
        goto FUN_00020f56;
      (&comp_collision_related)[unaff_A4] = 0;
      DAT_ffffdc60 = 0;
    }
  }
FUN_00020f56:
  FUN_00020dfe(unaff_A4);
  sVar9 = 3;
  puVar10 = &DAT_ffffdb40;
  do {
    sVar1 = *(short *)(puVar10 + 2);
    *(short *)((int)&comp_pos_x + (int)sVar1) =
        *(short *)(puVar10 + 0x10) + *(short *)((int)&comp_pos_x + unaff_A4);
    *(short *)((int)&comp_pos_y + (int)sVar1) =
        *(short *)((int)&comp_pos_y + unaff_A4) + 6;
    puVar10 = puVar10 + 0x40;
    sVar9 = sVar9 + -1;
  } while (sVar9 != -1);
  if ((DAT_ffffdc60 & 0x40) != 0) {
    return;
  }
  sVar9 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  wVar8 = angle_sin(angle_t_ffffdc6e);
  *(short *)((int)&comp_pos_x + (int)sVar9) =
      *(short *)((int)&comp_pos_x + unaff_A4) +
      (short)((uint)((short)wVar8 * 0x58) >> 0x10);
  *(short *)((int)&comp_pos_y + (int)sVar9) =
      *(short *)((int)&comp_pos_y + unaff_A4) + -0x16;
  self = (entity_id_t)sVar9;
  sVar9 = (short)((uint)(byte)(angle_t_ffffdc6e - 0x35) * 0xc00 >> 0x10) * 2;
  (&comp_state_a)[self] =
      (&entity_state_mixed_a_t_ARRAY_00020de6[0].field0_0x0)[sVar9] |
      (&comp_state_a)[self] & ~ENTITY_STATE_A_08;
  if ((&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar9] !=
      (&comp_anim_c)[self]) {
    ecs_anim_unk_2(
        self,
        unaff_A5,
        (&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar9]);
  }
  return;
}

void FUN_00021280(void)

{
  short sVar1;
  word wVar2;
  short sVar3;
  undefined *puVar4;
  entity_id_t self;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar5;

  FUN_000214da((entity_id_t)unaff_A5);
  if (DAT_ffffdc60 == 0) {
    DAT_ffffdb52._0_1_ = '0';
    DAT_ffffdc12 = 0x30;
    DAT_ffffdc60 = 0x82;
    uVar5 = 0x48;
    if (-1 < (char)angle_t_ffffdc6e) {
      DAT_ffffdc60 = 0x80;
      uVar5 = 0xb8;
    }
    *(undefined1 *)(unaff_A4 - 0x4689) = uVar5;
    DAT_ffffdc61 = '\0';
  }
  uVar5 = DAT_ffffdc61 == '\0';
  if ((bool)uVar5) {
    FUN_00021468();
    FUN_000214b2();
    if ((bool)uVar5) {
      DAT_ffffdc61 = DAT_ffffdc61 + '\x01';
    }
  } else {
    FUN_00021436();
    if (*(angle_t *)(unaff_A4 - 0x4689) == angle_t_ffffdc6e) {
      if ((DAT_ffffdb52._0_1_ == '\x10') || (DAT_ffffdb92 == '\x10')) {
        (&comp_collision_related)[unaff_A4] = 0;
        DAT_ffffdc60 = 0;
      }
    } else if ((char)*(angle_t *)(unaff_A4 - 0x4689) < '\0') {
      angle_t_ffffdc6e = angle_t_ffffdc6e + 1;
    } else {
      angle_t_ffffdc6e = angle_t_ffffdc6e - 1;
    }
  }
  FUN_00020dfe(unaff_A4);
  sVar3 = 3;
  puVar4 = &DAT_ffffdb40;
  do {
    sVar1 = *(short *)(puVar4 + 2);
    *(short *)((int)&comp_pos_x + (int)sVar1) =
        *(short *)(puVar4 + 0x10) + *(short *)((int)&comp_pos_x + unaff_A4);
    *(short *)((int)&comp_pos_y + (int)sVar1) =
        *(short *)((int)&comp_pos_y + unaff_A4) + 6;
    puVar4 = puVar4 + 0x40;
    sVar3 = sVar3 + -1;
  } while (sVar3 != -1);
  if ((DAT_ffffdc60 & 0x40) == 0) {
    sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
    wVar2 = angle_sin(angle_t_ffffdc6e);
    *(short *)((int)&comp_pos_x + (int)sVar3) =
        *(short *)((int)&comp_pos_x + unaff_A4) +
        (short)((uint)((short)wVar2 * 0x58) >> 0x10);
    *(short *)((int)&comp_pos_y + (int)sVar3) =
        *(short *)((int)&comp_pos_y + unaff_A4) + -0x16;
    self = (entity_id_t)sVar3;
    sVar3 = (short)((uint)(byte)(angle_t_ffffdc6e - 0x35) * 0xc00 >> 0x10) * 2;
    (&comp_state_a)[self] =
        (&entity_state_mixed_a_t_ARRAY_00020de6[0].field0_0x0)[sVar3] |
        (&comp_state_a)[self] & ~ENTITY_STATE_A_08;
    if ((&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar3] !=
        (&comp_anim_c)[self]) {
      ecs_anim_unk_2(
          self,
          unaff_A5,
          (&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar3]);
    }
    return;
  }
  return;
}

void FUN_0002130a(void)

{
  short sVar1;
  short *psVar2;
  byte bVar3;
  word wVar4;
  short sVar5;
  undefined *puVar6;
  entity_id_t self;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar7;

  FUN_000214da((entity_id_t)unaff_A5);
  bVar3 = DAT_ffffdc60 & 0x80;
  DAT_ffffdc60 = DAT_ffffdc60 | 0x80;
  if (bVar3 == 0) {
    DAT_ffffdc61 = '\0';
    DAT_ffffdc62 = 0;
  }
  if (DAT_ffffdc61 == '\0') {
    if (DAT_ffffdc62 < 0x16) {
      DAT_ffffdc62 = DAT_ffffdc62 + 1;
      FUN_000213be();
      FUN_00020dfe(unaff_A4);
      FUN_00020f3a();
      goto FUN_00020f56;
    }
    DAT_ffffdc61 = '\x01';
    *(int16_t *)((int)&comp_vel[0].x + unaff_A4) =
        (comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4)) * 4;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xf800;
  } else {
    if (DAT_ffffdc61 != '\x01') {
      DAT_ffffdc62 = DAT_ffffdc62 - 1;
      FUN_000213be();
      FUN_00020dfe(unaff_A4);
      FUN_00020f3a();
      if (DAT_ffffdc62 == 0) {
        (&comp_collision_related)[unaff_A4] = 0;
        DAT_ffffdc60 = 0;
      }
      goto FUN_00020f56;
    }
    angle_t_ffffdc6e = angle_t_ffffdc6e + 4;
  }
  player_update_pos(unaff_A4);
  psVar2 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar2 = *psVar2 + 0x40;
  if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
    uVar7 = DAT_ffffdc62 == 0x22;
    if (DAT_ffffdc62 < 0x22) {
      DAT_ffffdc62 = DAT_ffffdc62 + 1;
    LAB_0002138a:
      uVar7 = DAT_ffffdc62 == 0;
      FUN_000213be();
    }
  } else {
    uVar7 = DAT_ffffdc62 == 0x17;
    if (0x16 < DAT_ffffdc62) {
      DAT_ffffdc62 = DAT_ffffdc62 - 1;
      goto LAB_0002138a;
    }
  }
  FUN_00020dfe(unaff_A4);
  FUN_00020f42();
  if (!(bool)uVar7) {
    DAT_ffffdc61 = DAT_ffffdc61 + '\x01';
  }
FUN_00020f56:
  sVar5 = 3;
  puVar6 = &DAT_ffffdb40;
  do {
    sVar1 = *(short *)(puVar6 + 2);
    *(short *)((int)&comp_pos_x + (int)sVar1) =
        *(short *)(puVar6 + 0x10) + *(short *)((int)&comp_pos_x + unaff_A4);
    *(short *)((int)&comp_pos_y + (int)sVar1) =
        *(short *)((int)&comp_pos_y + unaff_A4) + 6;
    puVar6 = puVar6 + 0x40;
    sVar5 = sVar5 + -1;
  } while (sVar5 != -1);
  if ((DAT_ffffdc60 & 0x40) == 0) {
    sVar5 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
    wVar4 = angle_sin(angle_t_ffffdc6e);
    *(short *)((int)&comp_pos_x + (int)sVar5) =
        *(short *)((int)&comp_pos_x + unaff_A4) +
        (short)((uint)((short)wVar4 * 0x58) >> 0x10);
    *(short *)((int)&comp_pos_y + (int)sVar5) =
        *(short *)((int)&comp_pos_y + unaff_A4) + -0x16;
    self = (entity_id_t)sVar5;
    sVar5 = (short)((uint)(byte)(angle_t_ffffdc6e - 0x35) * 0xc00 >> 0x10) * 2;
    (&comp_state_a)[self] =
        (&entity_state_mixed_a_t_ARRAY_00020de6[0].field0_0x0)[sVar5] |
        (&comp_state_a)[self] & ~ENTITY_STATE_A_08;
    if ((&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar5] !=
        (&comp_anim_c)[self]) {
      ecs_anim_unk_2(
          self,
          unaff_A5,
          (&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar5]);
    }
    return;
  }
  return;
}

void FUN_000213be(void)

{
  DAT_ffffdb46 = *(undefined1 *)((int)WORD_ARRAY_000213f0 +
                                 (int)(short)((ushort)DAT_ffffdc62 * 2));
  DAT_ffffdb86 = DAT_ffffdb46;
  DAT_ffffdbc6 = DAT_ffffdb46;
  DAT_ffffdc06 = DAT_ffffdb46;
  DAT_ffffdb47 = *(undefined1 *)((int)WORD_ARRAY_000213f0 +
                                 (short)((ushort)DAT_ffffdc62 * 2) + 1);
  DAT_ffffdb87 = DAT_ffffdb47;
  DAT_ffffdbc7 = DAT_ffffdb47;
  DAT_ffffdc07 = DAT_ffffdb47;
  return;
}

void FUN_00021436(void)

{
  byte bVar1;
  undefined *puVar2;
  short sStack_2;

  sStack_2 = 4;
  puVar2 = &DAT_ffffdb40;
  do {
    if ((DAT_ffffdc60 & 2) == 0) {
      bVar1 = puVar2[0x12] + 1;
    } else {
      bVar1 = puVar2[0x12] - 1;
    }
    puVar2[0x12] = bVar1 & 0x3f;
    FUN_00020f8a();
    puVar2 = puVar2 + 0x40;
    sStack_2 = sStack_2 + -1;
  } while (sStack_2 != 0);
  return;
}

void FUN_00021468(void)

{
  char cVar1;
  char extraout_D1b;
  char unaff_D2b;
  short sVar2;
  undefined *puVar3;

  puVar3 = &DAT_ffffdb40;
  sVar2 = 3;
  do {
    cVar1 = FUN_00020f9a();
    if (extraout_D1b != puVar3[6]) {
      if ((char)(extraout_D1b - puVar3[6]) < '\0') {
        puVar3[6] = puVar3[6] + -1;
      } else {
        puVar3[6] = puVar3[6] + '\x01';
      }
    }
    if (cVar1 != puVar3[5]) {
      if ((char)(cVar1 - puVar3[5]) < '\0') {
        puVar3[5] = puVar3[5] + -1;
      } else {
        puVar3[5] = puVar3[5] + '\x01';
      }
    }
    if (unaff_D2b != puVar3[7]) {
      if ((char)(unaff_D2b - puVar3[7]) < '\0') {
        puVar3[7] = puVar3[7] + -1;
      } else {
        puVar3[7] = puVar3[7] + '\x01';
      }
    }
    puVar3 = puVar3 + 0x40;
    sVar2 = sVar2 + -1;
  } while (sVar2 != -1);
  return;
}

undefined4 FUN_000214b2(void)

{
  undefined4 uVar1;
  char extraout_D1b;
  char unaff_D2b;
  short sVar2;
  undefined *puVar3;

  sVar2 = 3;
  puVar3 = &DAT_ffffdb40;
  do {
    uVar1 = FUN_00020f9a();
    if ((char)uVar1 != puVar3[5]) {
      return uVar1;
    }
    if (extraout_D1b != puVar3[6]) {
      return uVar1;
    }
    if (unaff_D2b != puVar3[7]) {
      return uVar1;
    }
    puVar3 = puVar3 + 0x40;
    sVar2 = sVar2 + -1;
  } while (sVar2 != -1);
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000214da(entity_id_t self)

{
  short sVar1;
  byte bVar2;
  byte bVar3;
  fixed_t pos_x;
  byte bVar4;
  fixed_t extraout_D1w;
  word wVar5;
  short sVar6;
  byte *pbVar7;
  undefined *puVar8;
  word *pbVar8;
  byte *pbVar9;
  entity_id_t other_a;
  entity_id_t other_b;
  bool bVar10;
  bool bVar11;
  word awVar12[4];

  _DAT_ffffdb1a = FUN_000189d0;
  if ((&comp_unk_11)[_DAT_ffffdc66] != '\0') {
    _DAT_ffffdb1a = FUN_000189fe;
  }
  pbVar8 = (word *)&DAT_ffffdb40;
  DAT_ffffdc64 = '\x04';
  do {
    _DAT_ffffdc6c = (short)pbVar8;
    awVar12 = kind_of_clamp(0, 0, pbVar8[4], 0, 0, pbVar8[5]).array;
    awVar12 = kind_of_clamp(awVar12[0],
                            awVar12[1],
                            pbVar8[6],
                            awVar12[2],
                            awVar12[3],
                            pbVar8[7])
                  .array;
    pos_x.fixed.f = awVar12[0];
    extraout_D1w.fixed.f = awVar12[2];
    other_a = (entity_id_t)(short)pbVar8[1];
    if (((((ushort)(*(short *)((int)&comp_pos_x + other_a) + pos_x.fixed.f +
                    -0x20) < (ushort)comp_pos_x.fixed.i) &&
          ((ushort)comp_pos_x.fixed.i <=
           (ushort)(*(short *)((int)&comp_pos_x + other_a) + awVar12[1] +
                    0x20))) &&
         ((ushort)(*(short *)((int)&comp_pos_y + other_a) +
                   extraout_D1w.fixed.f + -0x20) <
          (ushort)comp_pos_y.fixed.i)) &&
        ((ushort)comp_pos_y.fixed.i <=
         (ushort)(*(short *)((int)&comp_pos_y + other_a) + awVar12[3] +
                  0x20))) {
      _DAT_ffffdc68 = *(short *)((int)&comp_pos_x + other_a);
      _DAT_ffffdc6a = *(short *)((int)&comp_pos_y + other_a);
      sVar6 = pbVar8[7] + _DAT_ffffdc6a;
      *(word *)((int)&comp_pos_x + other_a) = pbVar8[6] + _DAT_ffffdc68;
      *(short *)((int)&comp_pos_y + other_a) = sVar6;
      (&comp_collision[0].set_by_anim_command_fb)[other_a] = 9;
      (&comp_collision[0].unk2)[other_a] = 6;
      bVar11 = false;
      bVar10 = (*pbVar8 & 0x400) == 0;
      if (bVar10) {
        FUN_00002140();
        if (!bVar10)
          break;
      } else {
        (*_DAT_ffffdb1a)();
        FUN_000021c2(other_a, bVar10, bVar11);
        if (((&comp_func_offset[0].unk4)[other_a] & 1) != 0)
          goto LAB_00021614;
      }
      DAT_ffffdc65 = '\x06';
      (&comp_collision[0].set_by_anim_command_fb)[other_a] = 6;
      (&comp_collision[0].unk2)[other_a] = 6;
      pbVar9 = (byte *)(int)_DAT_ffffdc6c;
      pbVar7 = pbVar9 + 0x1c;
      if ((*pbVar9 & 1) != 0) {
        pbVar7 = pbVar9 + 0x21;
      }
      do {
        *(short *)((int)&comp_pos_x + other_a) =
            _DAT_ffffdc68 + (char)pbVar7[3] + 8;
        *(short *)((int)&comp_pos_y + other_a) =
            _DAT_ffffdc6a + (char)pbVar7[4] + 8;
        bVar10 = (*pbVar9 & 4) == 0;
        if (bVar10) {
          FUN_00002140();
          if (!bVar10)
            goto LAB_0002167a;
        } else {
          FUN_00001fd2();
          if (((&comp_func_offset[0].unk4)[other_a] & 1) != 0)
            goto LAB_00021614;
          if (((&comp_func_offset[0].unk4)[other_a] & 2) != 0) {
            uint8_t_ffffcc70 = uint8_t_ffffcc70 | 1;
            goto LAB_0002167a;
          }
        }
        pbVar7 = (byte *)(int)(short)((short)pbVar7 + 5);
        DAT_ffffdc65 = DAT_ffffdc65 + -1;
      } while (DAT_ffffdc65 != '\0');
    }
    pbVar8 = (word *)(_DAT_ffffdc6c + 0x40);
    DAT_ffffdc64 = DAT_ffffdc64 + -1;
  } while (DAT_ffffdc64 != '\0');
LAB_0002167a:
  other_a = (entity_id_t)_DAT_ffffdc66;
  FUN_00001fd2();
  if (((&comp_func_offset[0].unk4)[other_a] & 1) == 0) {
    return;
  }
LAB_00021614:
  audio_play(SOUND_ID_DAMAGE_2);
  bVar4 = DAT_ffffde0e;
  if (((&comp_func_offset[0].unk4)[other_a] & 4) != 0) {
    bVar4 = DAT_ffffde0f;
  }
  other_b = (entity_id_t)_DAT_ffffdc66;
  if ((&comp_unk_11)[other_b] == '\0') {
    bVar2 = (&comp_collected_item_id_maybe)[other_b];
    bVar3 = bVar2 - bVar4;
    (&comp_collected_item_id_maybe)[other_b] = bVar3;
    if (bVar2 < bVar4 || bVar3 == 0) {
      *(undefined1 *)((int)&comp_state + other_b) = 2;
      FUN_00020dfe(other_b);
      sVar6 = 3;
      puVar8 = &DAT_ffffdb40;
      do {
        sVar1 = *(short *)(puVar8 + 2);
        *(short *)((int)&comp_pos_x + (int)sVar1) =
            *(short *)(puVar8 + 0x10) + *(short *)((int)&comp_pos_x + other_b);
        *(short *)((int)&comp_pos_y + (int)sVar1) =
            *(short *)((int)&comp_pos_y + other_b) + 6;
        puVar8 = puVar8 + 0x40;
        sVar6 = sVar6 + -1;
      } while (sVar6 != -1);
      if ((DAT_ffffdc60 & 0x40) != 0) {
        return;
      }
      sVar6 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + other_b);
      wVar5 = angle_sin(angle_t_ffffdc6e);
      *(short *)((int)&comp_pos_x + (int)sVar6) =
          *(short *)((int)&comp_pos_x + other_b) +
          (short)((uint)((short)wVar5 * 0x58) >> 0x10);
      *(short *)((int)&comp_pos_y + (int)sVar6) =
          *(short *)((int)&comp_pos_y + other_b) + -0x16;
      other_a = (entity_id_t)sVar6;
      sVar6 =
          (short)((uint)(byte)(angle_t_ffffdc6e - 0x35) * 0xc00 >> 0x10) * 2;
      (&comp_state_a)[other_a] =
          (&entity_state_mixed_a_t_ARRAY_00020de6[0].field0_0x0)[sVar6] |
          (&comp_state_a)[other_a] & ~ENTITY_STATE_A_08;
      if ((&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar6] !=
          (&comp_anim_c)[other_a]) {
        ecs_anim_unk_2(
            other_a,
            (anim_item_t *)self,
            (&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar6]);
      }
      return;
    }
    (&comp_unk_11)[other_b] = 0x1e;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00021652(void)

{
  short sVar1;
  byte bVar2;
  byte bVar3;
  byte bVar4;
  word wVar5;
  short sVar6;
  byte *unaff_A2;
  undefined *puVar7;
  byte *unaff_A3;
  int iVar8;
  entity_id_t eVar9;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar10;
  bool bVar11;
  word awVar12[4];

  while (((&comp_func_offset[0].unk4)[unaff_A4] & 2) == 0) {
    while (true) {
      DAT_ffffdc65 = DAT_ffffdc65 + -1;
      if (DAT_ffffdc65 == '\0') {
        do {
          iVar8 = (int)_DAT_ffffdc6c;
          DAT_ffffdc64 = DAT_ffffdc64 + -1;
          if (DAT_ffffdc64 == '\0')
            goto LAB_0002167a;
          _DAT_ffffdc6c = (short)(byte *)(iVar8 + 0x40);
          awVar12 =
              kind_of_clamp(
                  0, 0, *(word *)(iVar8 + 0x48), 0, 0, *(word *)(iVar8 + 0x4a))
                  .array;
          awVar12 = kind_of_clamp(awVar12[0],
                                  awVar12[1],
                                  *(word *)(iVar8 + 0x4c),
                                  awVar12[2],
                                  awVar12[3],
                                  *(word *)(iVar8 + 0x4e))
                        .array;
          unaff_A4 = (entity_id_t) * (short *)(iVar8 + 0x42);
        } while (
            ((((ushort)comp_pos_x.fixed.i <=
               (ushort)(*(short *)((int)&comp_pos_x + unaff_A4) +
                        (awVar12[0] - 0x20))) ||
              ((ushort)(*(short *)((int)&comp_pos_x + unaff_A4) + awVar12[1] +
                        0x20) < (ushort)comp_pos_x.fixed.i)) ||
             ((ushort)comp_pos_y.fixed.i <=
              (ushort)(*(short *)((int)&comp_pos_y + unaff_A4) +
                       (awVar12[2] - 0x20)))) ||
            ((ushort)(*(short *)((int)&comp_pos_y + unaff_A4) + awVar12[3] +
                      0x20) < (ushort)comp_pos_y.fixed.i));
        _DAT_ffffdc68 = *(short *)((int)&comp_pos_x + unaff_A4);
        _DAT_ffffdc6a = *(short *)((int)&comp_pos_y + unaff_A4);
        sVar6 = *(short *)(iVar8 + 0x4e) + _DAT_ffffdc6a;
        *(short *)((int)&comp_pos_x + unaff_A4) =
            *(short *)(iVar8 + 0x4c) + _DAT_ffffdc68;
        *(short *)((int)&comp_pos_y + unaff_A4) = sVar6;
        (&comp_collision[0].set_by_anim_command_fb)[unaff_A4] = 9;
        (&comp_collision[0].unk2)[unaff_A4] = 6;
        bVar11 = false;
        bVar10 = (*(byte *)(iVar8 + 0x40) & 4) == 0;
        if (bVar10) {
          FUN_00002140();
          if (!bVar10)
            goto LAB_0002167a;
        } else {
          (*_DAT_ffffdb1a)();
          FUN_000021c2(unaff_A4, bVar10, bVar11);
          if (((&comp_func_offset[0].unk4)[unaff_A4] & 1) != 0)
            goto LAB_00021614;
        }
        DAT_ffffdc65 = '\x06';
        (&comp_collision[0].set_by_anim_command_fb)[unaff_A4] = 6;
        (&comp_collision[0].unk2)[unaff_A4] = 6;
        unaff_A3 = (byte *)(int)_DAT_ffffdc6c;
        unaff_A2 = unaff_A3 + 0x1c;
        if ((*unaff_A3 & 1) != 0) {
          unaff_A2 = unaff_A3 + 0x21;
        }
      }
      *(short *)((int)&comp_pos_x + unaff_A4) =
          _DAT_ffffdc68 + (char)unaff_A2[3] + 8;
      sVar6 = (short)unaff_A2 + 5;
      *(short *)((int)&comp_pos_y + unaff_A4) =
          _DAT_ffffdc6a + (char)unaff_A2[4] + 8;
      bVar10 = (*unaff_A3 & 4) == 0;
      if (!bVar10)
        break;
      FUN_00002140();
      unaff_A2 = (byte *)(int)sVar6;
      if (!bVar10)
        goto LAB_0002167a;
    }
    FUN_00001fd2();
    unaff_A2 = (byte *)(int)sVar6;
    if (((&comp_func_offset[0].unk4)[unaff_A4] & 1) != 0)
      goto LAB_00021614;
  }
  uint8_t_ffffcc70 = uint8_t_ffffcc70 | 1;
LAB_0002167a:
  unaff_A4 = (entity_id_t)_DAT_ffffdc66;
  FUN_00001fd2();
  if (((&comp_func_offset[0].unk4)[unaff_A4] & 1) == 0) {
    return;
  }
LAB_00021614:
  audio_play(SOUND_ID_DAMAGE_2);
  bVar4 = DAT_ffffde0e;
  if (((&comp_func_offset[0].unk4)[unaff_A4] & 4) != 0) {
    bVar4 = DAT_ffffde0f;
  }
  eVar9 = (entity_id_t)_DAT_ffffdc66;
  if ((&comp_unk_11)[eVar9] == '\0') {
    bVar2 = (&comp_collected_item_id_maybe)[eVar9];
    bVar3 = bVar2 - bVar4;
    (&comp_collected_item_id_maybe)[eVar9] = bVar3;
    if (bVar2 < bVar4 || bVar3 == 0) {
      *(undefined1 *)((int)&comp_state + eVar9) = 2;
      FUN_00020dfe(eVar9);
      sVar6 = 3;
      puVar7 = &DAT_ffffdb40;
      do {
        sVar1 = *(short *)(puVar7 + 2);
        *(short *)((int)&comp_pos_x + (int)sVar1) =
            *(short *)(puVar7 + 0x10) + *(short *)((int)&comp_pos_x + eVar9);
        *(short *)((int)&comp_pos_y + (int)sVar1) =
            *(short *)((int)&comp_pos_y + eVar9) + 6;
        puVar7 = puVar7 + 0x40;
        sVar6 = sVar6 + -1;
      } while (sVar6 != -1);
      if ((DAT_ffffdc60 & 0x40) != 0) {
        return;
      }
      sVar6 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + eVar9);
      wVar5 = angle_sin(angle_t_ffffdc6e);
      *(short *)((int)&comp_pos_x + (int)sVar6) =
          *(short *)((int)&comp_pos_x + eVar9) +
          (short)((uint)((short)wVar5 * 0x58) >> 0x10);
      *(short *)((int)&comp_pos_y + (int)sVar6) =
          *(short *)((int)&comp_pos_y + eVar9) + -0x16;
      eVar9 = (entity_id_t)sVar6;
      sVar6 =
          (short)((uint)(byte)(angle_t_ffffdc6e - 0x35) * 0xc00 >> 0x10) * 2;
      (&comp_state_a)[eVar9] =
          (&entity_state_mixed_a_t_ARRAY_00020de6[0].field0_0x0)[sVar6] |
          (&comp_state_a)[eVar9] & ~ENTITY_STATE_A_08;
      if ((&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar6] !=
          (&comp_anim_c)[eVar9]) {
        ecs_anim_unk_2(
            eVar9,
            unaff_A5,
            (&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar6]);
      }
      return;
    }
    (&comp_unk_11)[eVar9] = 0x1e;
  }
  return;
}

// a = min(a, c)
// b = max(b, c)
// x = min(x, z)
// y = max(y, z)

word_4 kind_of_clamp(word a, word b, word c, word x, word y, word z)

{
  word awVar1[4];

  if ((short)c < (short)a) {
    a = c;
  }
  if ((short)b < (short)c) {
    b = c;
  }
  if ((short)z < (short)x) {
    x = z;
  }
  if ((short)y < (short)z) {
    y = z;
  }
  awVar1[2] = x;
  awVar1[3] = y;
  awVar1[0] = a;
  awVar1[1] = b;
  return awVar1;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000216ac(void)

{
  byte bVar1;
  short sVar2;
  int unaff_A4;

  (&comp_collision_related)[unaff_A4] =
      (&comp_collision_related)[unaff_A4] + '\x02';
  _DAT_ffffdb3e = 0xb4;
  audio_play_sound_asha_dies();
  while (true) {
    IO_Z80BUS = 0x100;
    do {
      bVar1 = IO_Z80BUS._0_1_;
    } while ((bVar1 & 1) != 0);
    if (z80_ram_something_1 == '\0')
      break;
    IO_Z80BUS = 0;
    sVar2 = 0x1f;
    do {
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
  }
  (&z80_ram)[(short)(((byte)(z80_ram_something_3 + z80_ram_something_2) & 0xf) +
                     0x1c30)] = 0x4c;
  z80_ram_something_3 = z80_ram_something_3 + '\x01';
  IO_Z80BUS = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000216c0(void)

{
  ushort uVar1;
  short sVar2;
  char duration;
  char extraout_D1b;
  vdp_color_t *pvVar3;
  vdp_color_t *pvVar4;
  int unaff_A4;

  _DAT_ffffdb3e = _DAT_ffffdb3e + -1;
  if (_DAT_ffffdb3e == 0) {
    DAT_ffffdc61 = 0;
    DAT_ffffdc62 = 1;
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x02';
    FUN_0001fd5e();
    duration = extraout_D1b;
  } else {
    for (uVar1 = (0xb4 - _DAT_ffffdb3e) * 2; 0x53 < uVar1;
         uVar1 = uVar1 - 0x54) {
    }
    sVar2 = 0xf;
    pvVar3 = palettes_2;
    do {
      *pvVar3 = *(vdp_color_t *)(&UNK_0001fdd8 + (short)uVar1);
      uVar1 = uVar1 + 2;
      if (0x53 < uVar1) {
        uVar1 = 0;
      }
      sVar2 = sVar2 + -1;
      pvVar3 = pvVar3 + 1;
    } while (sVar2 != -1);
    duration = -1;
  }
  sVar2 = 7;
  pvVar3 = palettes_2;
  pvVar4 = palettes[1];
  do {
    *(undefined4 *)pvVar4 = *(undefined4 *)pvVar3;
    sVar2 = sVar2 + -1;
    pvVar3 = pvVar3 + 2;
    pvVar4 = pvVar4 + 2;
  } while (sVar2 != -1);
  palette_set_fade(PALETTE_ID_FLAG_1,
                   PALETTE_FADE_1,
                   duration,
                   (palette_color_iter_t)0xffffffff);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000216de(void)

{
  short sVar1;
  int unaff_A4;
  int iVar2;

  DAT_ffffdc62 = DAT_ffffdc62 + -1;
  if (DAT_ffffdc62 == '\0') {
    DAT_ffffdc62 = '\b';
    if (DAT_ffffdc61 == 4) {
      sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
      DAT_ffffdc61 = DAT_ffffdc61 + 1;
      FUN_00021758();
      (&comp_has_func_maybe)[sVar1] = 0;
      FUN_00021758();
      iVar2 = (int)_DAT_ffffdc66;
      FUN_00015e86();
      (&comp_has_func_maybe)[iVar2] = 0;
      return;
    }
    sVar1 = *(short *)((int)&DAT_ffffdb42 +
                       (int)(short)((ushort)DAT_ffffdc61 * 0x40));
    DAT_ffffdc61 = DAT_ffffdc61 + 1;
    FUN_00021758();
    FUN_00021758();
    FUN_00021758();
    (&comp_has_func_maybe)[sVar1] = 0;
  }
  return;
}

// WARNING: Removing unreachable block (ram,0x00024d8a)
// WARNING: Removing unreachable block (ram,0x00024d92)

void FUN_00021758(void)

{
  short sVar1;
  byte extraout_D1b;
  int extraout_A0;
  undefined2 unaff_A3w;
  entity_id_t e;
  undefined2 uStack_a;

  FUN_000253a0();
  sVar1 = ecs_find_some_entity_with_func();
  if (-1 < sVar1) {
    e = (entity_id_t)sVar1;
    *(undefined2 *)((int)&comp_pos_x + e) = unaff_A3w;
    *(undefined2 *)((int)&comp_pos_y + e) = uStack_a;
    entity_reset(e);
    (&comp_has_func_maybe)[sVar1] = 0x80;
    (&comp_func_offset[0].func_offset_from_15ede)[sVar1] = 8;
    (&comp_collected_item_id_maybe)[sVar1] = 0x32;
    FUN_00024da0();
    (&comp_func_offset[0].unk1)[extraout_A0] = extraout_D1b;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002178a(void)

{
  short sVar1;
  entity_state_a_t state_1_b;
  undefined *puVar2;
  int unaff_A4;
  entity_id_t eVar3;
  int iVar4;
  anim_item_t *unaff_A5;

  _DAT_ffffdc66 = (short)unaff_A4;
  DAT_ffffdc60 = 0;
  (&comp_anim[0].unk4)[unaff_A4] = (&comp_anim[0].unk4)[unaff_A4] | 0x40;
  FUN_0000281e();
  FUN_0001fd94();
  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x48;
  sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  *(undefined2 *)((int)&comp_pos_x + (int)sVar1) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  *(short *)((int)&comp_pos_y + (int)sVar1) = DAT_ffffce0a + 0x60;
  eVar3 = (entity_id_t)sVar1;
  (&comp_has_func_maybe + eVar3)[0] = 0xe0;
  (&comp_has_func_maybe + eVar3)[1] = 0x80;
  *(undefined2 *)((int)&comp_unk_3 + eVar3) = 6;
  ecs_anim_unk_2(eVar3, unaff_A5, 6);
  *(undefined2 *)(&DAT_ffffbc76 + eVar3) = 0;
  *(undefined2 *)(&DAT_ffffbc78 + eVar3) = 0;
  *(undefined2 *)(&DAT_ffffbd76 + eVar3) = 0;
  *(undefined2 *)(&DAT_ffffbd78 + eVar3) = 0;
  while (sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + eVar3),
         -1 < sVar1) {
    (&comp_has_func_maybe + sVar1)[0] = 0xe0;
    (&comp_has_func_maybe + sVar1)[1] = 0x80;
    *(undefined2 *)((int)&comp_unk_3 + (int)sVar1) = 6;
    eVar3 = (entity_id_t)sVar1;
    *(undefined2 *)((int)&comp_pos_x + eVar3) = 0;
    *(undefined2 *)((int)&comp_pos_y + eVar3) = 0;
    *(undefined2 *)(&DAT_ffffbc76 + eVar3) = 0;
    *(undefined2 *)(&DAT_ffffbc78 + eVar3) = 0;
    *(undefined2 *)(&DAT_ffffbd76 + eVar3) = 0;
    *(undefined2 *)(&DAT_ffffbd78 + eVar3) = 0;
    ecs_anim_unk_2(eVar3, unaff_A5, 0x10);
  }
  iVar4 = (int)_DAT_ffffdc66;
  (&comp_collision_related)[iVar4] = 10;
  DAT_ffffdc40 = 0;
  FUN_00021918();
  puVar2 = &UNK_000219c2;
  if ((DAT_ffffdc60 & 1) != 0) {
    puVar2 = &UNK_000219d2;
  }
  eVar3 = (entity_id_t) *
          (short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar4);
  (&comp_state_a)[eVar3] =
      puVar2[(
          short)(ushort)(byte)(((byte)((&DAT_ffffb976)[eVar3] + 0x10) >> 5) *
                               '\x02')] |
      (&comp_state_a)[eVar3] & ~(ENTITY_STATE_A_H_FLIP | ENTITY_STATE_A_08);
  state_1_b =
      (puVar2 +
       (short)(ushort)(byte)(((byte)((&DAT_ffffb976)[eVar3] + 0x10) >> 5) *
                             '\x02'))[1];
  if (state_1_b != (&comp_anim_c)[eVar3]) {
    ecs_anim_unk_2(eVar3, unaff_A5, state_1_b);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00021832(void)

{
  int iVar1;
  int unaff_A4;

  FUN_00021a16();
  FUN_0002193c();
  iVar1 =
      (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  *(short *)((int)&comp_pos_y + iVar1) =
      *(short *)((int)&comp_pos_y + iVar1) + -5;
  if (*(short *)((int)&comp_pos_y + iVar1) <= DAT_ffffce0a) {
    _DAT_ffffdc6a = *(undefined2 *)((int)&comp_pos_y + iVar1);
    _DAT_ffffdc68 = *(short *)((int)&comp_pos_x + iVar1) + -0x33;
    (&comp_collision_related)[unaff_A4] = 4;
    if ((DAT_ffffdc60 & 1) == 0) {
      _DAT_ffffdc68 = _DAT_ffffdc68 + 0x66;
      (&comp_collision_related)[unaff_A4] = 6;
    }
  }
  return;
}

void FUN_0002187a(void)

{
  int unaff_A4;

  FUN_00021a16();
  FUN_0002193c();
  (&DAT_ffffb976)[*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                             unaff_A4)] =
      (&DAT_ffffb976)[*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                                 unaff_A4)] +
      -4;
  FUN_000219e2();
  FUN_00021984();
  if ((&DAT_ffffb976)[*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                                 unaff_A4)] == -0x80) {
    (&comp_collision_related)[unaff_A4] = 8;
  }
  return;
}

void FUN_000218a6(void)

{
  int unaff_A4;

  FUN_00021a16();
  FUN_0002193c();
  (&DAT_ffffb976)[*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                             unaff_A4)] =
      (&DAT_ffffb976)[*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                                 unaff_A4)] +
      '\x04';
  FUN_000219e2();
  FUN_00021984();
  if ((&DAT_ffffb976)[*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                                 unaff_A4)] == '\0') {
    (&comp_collision_related)[unaff_A4] = 8;
  }
  return;
}

void FUN_000218d0(void)

{
  short *psVar1;
  short sVar2;
  int iVar3;
  int extraout_A0;
  int unaff_A4;

  FUN_00021a16();
  FUN_0002193c();
  iVar3 =
      (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  psVar1 = (short *)((int)&comp_pos_y + iVar3);
  *psVar1 = *psVar1 + 5;
  if ((short)(DAT_ffffce0a + 0x60) <= *(short *)((int)&comp_pos_y + iVar3)) {
    FUN_00021918();
    sVar2 = 0x10;
    if ((DAT_ffffdc60 & 1) != 0) {
      sVar2 = -0x10;
    }
    *(short *)((int)&comp_pos_x + extraout_A0) =
        sVar2 + *(short *)((int)&comp_pos_x + extraout_A0);
    (&comp_collision_related)[unaff_A4] = 2;
  }
  return;
}

void FUN_0002190a(void)

{
  int unaff_A4;

  if (DAT_ffffdc40 != '\0') {
    (&comp_collision_related)[unaff_A4] = 2;
  }
  return;
}

void FUN_00021918(void)

{
  int iVar1;
  int unaff_A4;

  iVar1 =
      (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  DAT_ffffdc60 = DAT_ffffdc60 & 0xfe;
  (&DAT_ffffb976)[iVar1] = 0x80;
  if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + iVar1)) {
    DAT_ffffdc60 = DAT_ffffdc60 + 1;
    (&DAT_ffffb976)[iVar1] = 0;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002193c(void)

{
  undefined2 uVar1;
  undefined2 uVar2;
  short sVar3;
  undefined2 uVar4;
  undefined2 uVar5;
  int iVar6;

  iVar6 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                          (int)_DAT_ffffdc66);
  uVar4 = *(undefined2 *)((int)&comp_pos_x + iVar6);
  uVar5 = *(undefined2 *)((int)&comp_pos_y + iVar6);
  while (true) {
    uVar1 = *(undefined2 *)(&DAT_ffffbd76 + iVar6);
    uVar2 = *(undefined2 *)(&DAT_ffffbd78 + iVar6);
    *(undefined2 *)(&DAT_ffffbd76 + iVar6) =
        *(undefined2 *)(&DAT_ffffbc76 + iVar6);
    *(undefined2 *)(&DAT_ffffbc76 + iVar6) =
        *(undefined2 *)((int)&comp_pos_x + iVar6);
    *(undefined2 *)(&DAT_ffffbd78 + iVar6) =
        *(undefined2 *)(&DAT_ffffbc78 + iVar6);
    *(undefined2 *)(&DAT_ffffbc78 + iVar6) =
        *(undefined2 *)((int)&comp_pos_y + iVar6);
    *(undefined2 *)((int)&comp_pos_x + iVar6) = uVar4;
    *(undefined2 *)((int)&comp_pos_y + iVar6) = uVar5;
    sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar6);
    if (sVar3 < 0)
      break;
    iVar6 = (int)sVar3;
    uVar4 = uVar1;
    uVar5 = uVar2;
  }
  return;
}

void FUN_00021984(void)

{
  entity_state_a_t state_1_b;
  undefined *puVar1;
  int unaff_A4;
  entity_id_t self;
  anim_item_t *unaff_A5;

  puVar1 = &UNK_000219c2;
  if ((DAT_ffffdc60 & 1) != 0) {
    puVar1 = &UNK_000219d2;
  }
  self = (entity_id_t) *
         (short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  (&comp_state_a)[self] =
      puVar1[(short)(ushort)(byte)(((byte)((&DAT_ffffb976)[self] + 0x10) >> 5) *
                                   '\x02')] |
      (&comp_state_a)[self] & ~(ENTITY_STATE_A_H_FLIP | ENTITY_STATE_A_08);
  state_1_b =
      (puVar1 +
       (short)(ushort)(byte)(((byte)((&DAT_ffffb976)[self] + 0x10) >> 5) *
                             '\x02'))[1];
  if (state_1_b != (&comp_anim_c)[self]) {
    ecs_anim_unk_2(self, unaff_A5, state_1_b);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000219e2(void)

{
  word wVar1;
  int iVar2;
  int unaff_A4;

  iVar2 =
      (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  wVar1 = angle_sin((&DAT_ffffb976)[iVar2] + 0x40);
  *(short *)((int)&comp_pos_x + iVar2) =
      _DAT_ffffdc68 + (short)((uint)((short)wVar1 * 0xcc) >> 0x10);
  wVar1 = angle_sin((&DAT_ffffb976)[iVar2]);
  *(short *)((int)&comp_pos_y + iVar2) =
      _DAT_ffffdc6a + (short)((uint)((short)wVar1 * 0xcc) >> 0x10);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00021a16(void)

{
  short sVar1;
  byte bVar2;
  byte bVar3;
  byte bVar4;
  int unaff_A4;
  int iVar5;

  iVar5 =
      (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  FUN_00001fd2();
  if (((&comp_func_offset[0].unk4)[iVar5] & 2) == 0) {
    bVar4 = (&comp_func_offset[0].unk4)[iVar5];
    while ((bVar4 & 1) == 0) {
      sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar5);
      if (sVar1 < 0) {
        return;
      }
      iVar5 = (int)sVar1;
      FUN_00001fd2();
      if (((&comp_func_offset[0].unk4)[iVar5] & 2) != 0) {
        uint8_t_ffffcc70 = uint8_t_ffffcc70 | 1;
        return;
      }
      bVar4 = (&comp_func_offset[0].unk4)[iVar5];
    }
    audio_play(SOUND_ID_DAMAGE_2);
    bVar4 = DAT_ffffde0e;
    if (((&comp_func_offset[0].unk4)[iVar5] & 4) != 0) {
      bVar4 = DAT_ffffde0f;
    }
    iVar5 = (int)_DAT_ffffdc66;
    if ((&comp_unk_11)[iVar5] == '\0') {
      bVar2 = (&comp_collected_item_id_maybe)[iVar5];
      bVar3 = bVar2 - bVar4;
      (&comp_collected_item_id_maybe)[iVar5] = bVar3;
      if (bVar2 < bVar4 || bVar3 == 0) {
        *(undefined1 *)((int)&comp_state + iVar5) = 4;
        return;
      }
      (&comp_unk_11)[iVar5] = 0x1e;
    }
  } else {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 2;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00021aa4(void)

{
  short sVar1;
  int unaff_A4;
  int iVar2;

  iVar2 =
      (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  *(undefined2 *)((int)&comp_vel[0].y + iVar2) = 64000;
  *(ushort *)((int)&comp_vel[0].x + iVar2) =
      ((DAT_ffffce04 + ((ushort)(DAT_ffffce08 - DAT_ffffce04) >> 1)) -
       *(short *)((int)&comp_pos_x + iVar2)) *
      4;
  sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar2);
  do {
    iVar2 = (int)sVar1;
    *(short *)((int)&comp_vel[0].x + iVar2) =
        (*(short *)((int)&comp_pos_x + iVar2) - _DAT_ffffdc68) * 0x20;
    *(short *)((int)&comp_vel[0].y + iVar2) =
        ((*(short *)((int)&comp_pos_y + iVar2) - DAT_ffffce0a) + -0x80) * 0x20;
    FUN_0000231c();
    sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar2);
  } while (-1 < sVar1);
  (&comp_collision_related)[_DAT_ffffdc66] =
      (&comp_collision_related)[_DAT_ffffdc66] + '\x02';
  DAT_ffffdc62 = 0x3c;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00021b08(void)

{
  short *psVar1;
  ushort uVar2;
  short sVar3;
  int unaff_A4;
  ulong ctx;
  bool bVar4;

  ctx = (ulong) *
        (short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  player_update_pos(ctx);
  if (*(ushort *)((int)&comp_pos_y + ctx) <= DAT_ffffce0a) {
    psVar1 = (short *)((int)&comp_vel[0].y + ctx);
    *psVar1 = *psVar1 + 0x30;
  }
  psVar1 = (short *)((int)&comp_vel[0].y + ctx);
  bVar4 = *psVar1 == 0;
  if ((-1 < *psVar1) && (FUN_00002856(), !bVar4)) {
    psVar1 = (short *)((int)&comp_vel[0].x + ctx);
    *psVar1 = *psVar1 >> 1;
    uVar2 = *(short *)((int)&comp_vel[0].y + ctx) >> 1;
    if ((DAT_ffffdc62 == '\0') && (uVar2 < 0x100)) {
      (&comp_collision_related)[_DAT_ffffdc66] =
          (&comp_collision_related)[_DAT_ffffdc66] + '\x02';
      DAT_ffffdc62 = 0x3c;
      return;
    }
    *(ushort *)((int)&comp_vel[0].y + ctx) = -uVar2;
  }
  if (DAT_ffffdc62 != '\0') {
    DAT_ffffdc62 = DAT_ffffdc62 + -1;
    if (DAT_ffffdc62 == '\0') {
      sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + ctx);
      do {
        (&comp_has_func_maybe + sVar3)[0] = 0xe8;
        (&comp_has_func_maybe + sVar3)[1] = 0;
        sVar3 =
            *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + (int)sVar3);
      } while (-1 < sVar3);
    } else {
      sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + ctx);
      do {
        player_update_pos((int)sVar3);
        sVar3 =
            *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + (int)sVar3);
      } while (-1 < sVar3);
    }
  }
  return;
}

void FUN_00021b8e(void)

{
  int unaff_A4;

  DAT_ffffdc62 = DAT_ffffdc62 + -1;
  if (DAT_ffffdc62 == '\0') {
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x02';
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00021b9a(void)

{
  short sVar1;
  byte bVar2;
  word wVar3;
  short sVar4;
  undefined *puVar5;
  entity_id_t unaff_A4;
  int iVar6;
  entity_id_t eVar7;
  anim_item_t *unaff_A5;

  (&comp_collision_related)[unaff_A4] =
      (&comp_collision_related)[unaff_A4] + '\x02';
  DAT_ffffdc60 = 0x40;
  *(short *)((int)&comp_pos_y + unaff_A4) = DAT_ffffce0a + 0x80;
  bVar2 = ecs_unk_3(unaff_A4, 2);
  (&comp_collected_item_id_maybe)[unaff_A4] = bVar2;
  *(undefined2 *)(&comp_has_func_maybe + unaff_A4) =
      *(undefined2 *)(&comp_has_func_maybe + unaff_A4) & 0xf708;
  angle_t_ffffdc6e = 0xb8;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x10;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
  iVar6 =
      (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  (&comp_state_a)[iVar6] =
      (&comp_state_a)[iVar6] & ~(ENTITY_STATE_A_H_FLIP | ENTITY_STATE_A_08);
  *(undefined2 *)(&DAT_ffffbe78 + iVar6) = 0;
  FUN_00021c26();
  FUN_00021c26();
  FUN_00021c26();
  FUN_00021c26();
  while (sVar4 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar6),
         -1 < sVar4) {
    iVar6 = (int)sVar4;
    (&comp_has_func_maybe)[iVar6] = 0;
  }
  eVar7 = (entity_id_t)_DAT_ffffdc66;
  DAT_ffffdc62 = 0x17;
  FUN_000213be();
  *(undefined2 *)((int)&comp_vel[0].y + eVar7) = 0xf400;
  FUN_00020dfe(eVar7);
  sVar4 = 3;
  puVar5 = &DAT_ffffdb40;
  do {
    sVar1 = *(short *)(puVar5 + 2);
    *(short *)((int)&comp_pos_x + (int)sVar1) =
        *(short *)(puVar5 + 0x10) + *(short *)((int)&comp_pos_x + eVar7);
    *(short *)((int)&comp_pos_y + (int)sVar1) =
        *(short *)((int)&comp_pos_y + eVar7) + 6;
    puVar5 = puVar5 + 0x40;
    sVar4 = sVar4 + -1;
  } while (sVar4 != -1);
  if ((DAT_ffffdc60 & 0x40) == 0) {
    sVar4 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + eVar7);
    wVar3 = angle_sin(angle_t_ffffdc6e);
    *(short *)((int)&comp_pos_x + (int)sVar4) =
        *(short *)((int)&comp_pos_x + eVar7) +
        (short)((uint)((short)wVar3 * 0x58) >> 0x10);
    *(short *)((int)&comp_pos_y + (int)sVar4) =
        *(short *)((int)&comp_pos_y + eVar7) + -0x16;
    eVar7 = (entity_id_t)sVar4;
    sVar4 = (short)((uint)(byte)(angle_t_ffffdc6e - 0x35) * 0xc00 >> 0x10) * 2;
    (&comp_state_a)[eVar7] =
        (&entity_state_mixed_a_t_ARRAY_00020de6[0].field0_0x0)[sVar4] |
        (&comp_state_a)[eVar7] & ~ENTITY_STATE_A_08;
    if ((&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar4] !=
        (&comp_anim_c)[eVar7]) {
      ecs_anim_unk_2(
          eVar7,
          unaff_A5,
          (&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar4]);
    }
    return;
  }
  return;
}

void FUN_00021c26(void)

{
  short sVar1;
  undefined1 *unaff_A2;
  undefined1 *unaff_A3;
  int unaff_A4;
  int iVar2;

  sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  iVar2 = (int)sVar1;
  *(short *)(unaff_A3 + 2) = sVar1;
  *(short *)(&DAT_ffffbe78 + iVar2) = (short)unaff_A3;
  *unaff_A3 = *unaff_A2;
  unaff_A3[4] = unaff_A2[1];
  unaff_A3[0x12] = 0x10;
  FUN_00020f8a();
  *(undefined1 **)((int)&comp_anim_frame_p + iVar2) = unaff_A3 + 0x1c;
  unaff_A3[0x3f] = 0xff;
  (&comp_has_func_maybe + iVar2)[0] = 0xe3;
  (&comp_has_func_maybe + iVar2)[1] = 0x80;
  *(undefined2 *)((int)&comp_unk_4 + iVar2) = 0;
  return;
}

void FUN_00021c62(void)

{
  short sVar1;
  short *psVar2;
  word wVar3;
  short sVar4;
  undefined *puVar5;
  entity_id_t self;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar6;

  player_update_pos(unaff_A4);
  psVar2 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar2 = *psVar2 + 0x40;
  FUN_00020dfe(unaff_A4);
  psVar2 = (short *)((int)&comp_vel[0].y + unaff_A4);
  bVar6 = *psVar2 == 0;
  if ((-1 < *psVar2) && (FUN_00020f42(), !bVar6)) {
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x02';
  }
  sVar4 = 3;
  puVar5 = &DAT_ffffdb40;
  do {
    sVar1 = *(short *)(puVar5 + 2);
    *(short *)((int)&comp_pos_x + (int)sVar1) =
        *(short *)(puVar5 + 0x10) + *(short *)((int)&comp_pos_x + unaff_A4);
    *(short *)((int)&comp_pos_y + (int)sVar1) =
        *(short *)((int)&comp_pos_y + unaff_A4) + 6;
    puVar5 = puVar5 + 0x40;
    sVar4 = sVar4 + -1;
  } while (sVar4 != -1);
  if ((DAT_ffffdc60 & 0x40) == 0) {
    sVar4 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
    wVar3 = angle_sin(angle_t_ffffdc6e);
    *(short *)((int)&comp_pos_x + (int)sVar4) =
        *(short *)((int)&comp_pos_x + unaff_A4) +
        (short)((uint)((short)wVar3 * 0x58) >> 0x10);
    *(short *)((int)&comp_pos_y + (int)sVar4) =
        *(short *)((int)&comp_pos_y + unaff_A4) + -0x16;
    self = (entity_id_t)sVar4;
    sVar4 = (short)((uint)(byte)(angle_t_ffffdc6e - 0x35) * 0xc00 >> 0x10) * 2;
    (&comp_state_a)[self] =
        (&entity_state_mixed_a_t_ARRAY_00020de6[0].field0_0x0)[sVar4] |
        (&comp_state_a)[self] & ~ENTITY_STATE_A_08;
    if ((&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar4] !=
        (&comp_anim_c)[self]) {
      ecs_anim_unk_2(
          self,
          unaff_A5,
          (&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar4]);
    }
    return;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00021c84(void)

{
  short sVar1;
  undefined2 uVar2;
  undefined2 uVar3;
  word wVar4;
  short sVar5;
  int iVar6;
  undefined *puVar7;
  entity_id_t self;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  DAT_ffffdc62 = DAT_ffffdc62 + -1;
  FUN_000213be();
  FUN_00020dfe(unaff_A4);
  FUN_00020f3a();
  if (DAT_ffffdc62 == '\0') {
    iVar6 =
        (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
    *(undefined2 *)(&DAT_ffffbc76 + iVar6) =
        *(undefined2 *)((int)&comp_pos_x + iVar6);
    *(undefined2 *)(&DAT_ffffbc78 + iVar6) =
        *(undefined2 *)((int)&comp_pos_y + iVar6);
    FUN_00020d84(unaff_A4, (entity_id_t)unaff_A5);
    iVar6 =
        (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
    uVar2 = *(undefined2 *)((int)&comp_pos_x + iVar6);
    uVar3 = *(undefined2 *)((int)&comp_pos_y + iVar6);
    *(undefined2 *)((int)&comp_pos_x + iVar6) =
        *(undefined2 *)(&DAT_ffffbc76 + iVar6);
    *(undefined2 *)((int)&comp_pos_y + iVar6) =
        *(undefined2 *)(&DAT_ffffbc78 + iVar6);
    *(undefined2 *)(&DAT_ffffbc76 + iVar6) = uVar2;
    *(undefined2 *)(&DAT_ffffbc78 + iVar6) = uVar3;
    FUN_00002606();
    unaff_A4 = (entity_id_t)_DAT_ffffdc66;
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x02';
  }
  sVar5 = 3;
  puVar7 = &DAT_ffffdb40;
  do {
    sVar1 = *(short *)(puVar7 + 2);
    *(short *)((int)&comp_pos_x + (int)sVar1) =
        *(short *)(puVar7 + 0x10) + *(short *)((int)&comp_pos_x + unaff_A4);
    *(short *)((int)&comp_pos_y + (int)sVar1) =
        *(short *)((int)&comp_pos_y + unaff_A4) + 6;
    puVar7 = puVar7 + 0x40;
    sVar5 = sVar5 + -1;
  } while (sVar5 != -1);
  if ((DAT_ffffdc60 & 0x40) == 0) {
    sVar5 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
    wVar4 = angle_sin(angle_t_ffffdc6e);
    *(short *)((int)&comp_pos_x + (int)sVar5) =
        *(short *)((int)&comp_pos_x + unaff_A4) +
        (short)((uint)((short)wVar4 * 0x58) >> 0x10);
    *(short *)((int)&comp_pos_y + (int)sVar5) =
        *(short *)((int)&comp_pos_y + unaff_A4) + -0x16;
    self = (entity_id_t)sVar5;
    sVar5 = (short)((uint)(byte)(angle_t_ffffdc6e - 0x35) * 0xc00 >> 0x10) * 2;
    (&comp_state_a)[self] =
        (&entity_state_mixed_a_t_ARRAY_00020de6[0].field0_0x0)[sVar5] |
        (&comp_state_a)[self] & ~ENTITY_STATE_A_08;
    if ((&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar5] !=
        (&comp_anim_c)[self]) {
      ecs_anim_unk_2(
          self,
          unaff_A5,
          (&entity_state_mixed_a_t_ARRAY_00020de6[0].field1_0x1)[sVar5]);
    }
    return;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00021ce2(void)

{
  short sVar1;
  short sVar2;
  int unaff_A4;
  int iVar3;

  sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  player_update_pos((int)sVar1);
  iVar3 = (int)_DAT_ffffdc66;
  sVar2 = *(short *)(&comp_unk_4 + sVar1) + -1;
  *(short *)(&comp_unk_4 + sVar1) = sVar2;
  if (sVar2 == 0) {
    DAT_ffffdc60 = 0;
    *(undefined1 *)((int)&comp_state + iVar3) = 1;
  }
  return;
}

void FUN_00021d02(void)

{
  short sVar1;
  char cVar2;
  int unaff_A4;

  FUN_0001fe84();
  cVar2 = *(char *)((int)&comp_state + unaff_A4);
  if (-1 < cVar2) {
    DAT_ffffdcc1 = 0;
    *(byte *)((int)&comp_state + unaff_A4) =
        *(byte *)((int)&comp_state + unaff_A4) | 0x80;
  }
  sVar1 = *(short *)((int)&WORD_00021d32 +
                     (int)(short)(ushort)(byte)(cVar2 * '\x02'));
  (*(code *)((int)&WORD_00021d32 +
             (int)*(short *)((int)&WORD_00021d32 +
                             (int)(short)(ushort)DAT_ffffdcc1 + (int)sVar1) +
             (int)sVar1))();
  return;
}

void FUN_00021d3e(void)

{
  ushort uVar1;
  uint uVar2;
  short sVar3;
  short sVar4;
  byte *pbVar5;
  undefined *puVar6;
  int iVar7;
  undefined *puVar8;
  undefined1 *puVar9;
  uint unaff_A4;
  entity_id_t self;
  anim_item_t *unaff_A5;

  DAT_ffffdcc0 = 0;
  DAT_ffffdcc1 = DAT_ffffdcc1 + '\x02';
  DAT_ffffdcc2 = (short)unaff_A4;
  FUN_0000281e();
  FUN_0001fd94();
  (&comp_anim[0].unk4)[unaff_A4] = (&comp_anim[0].unk4)[unaff_A4] | 0x40;
  puVar6 = &UNK_00021e02;
  puVar8 = &DAT_ffffdb40;
  uVar2 = unaff_A4 & 0xffff;
  do {
    self = (entity_id_t)(short)uVar2;
    *(short *)(puVar8 + 2) = (short)uVar2;
    *puVar8 = *puVar6;
    pbVar5 = puVar6 + 2;
    *(ushort *)(&comp_unk_4 + self) = (ushort)(byte)puVar6[1];
    puVar6 = puVar6 + 3;
    ecs_anim_unk_2(self, unaff_A5, *pbVar5);
    (&comp_has_func_maybe + self)[0] = 0xe0;
    (&comp_has_func_maybe + self)[1] = 0x80;
    puVar8 = puVar8 + 0x18;
    uVar1 = *(ushort *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + self);
    uVar2 = (uint)uVar1;
  } while (-1 < (short)uVar1);
  DAT_ffffdcc0 = 1;
  DAT_ffffdccc = 0x80;
  FUN_000222c0();
  FUN_000222d0();
  puVar9 = &DAT_ffffdb58;
  sVar4 = 0xe;
  do {
    *(short *)(puVar9 + 0x10) =
        *(short *)(puVar9 + 10) + *(short *)(puVar9 + 0x10);
    *(short *)(puVar9 + 0x12) =
        *(short *)(puVar9 + 0xc) + *(short *)(puVar9 + 0x12);
    *(short *)(puVar9 + 0x14) =
        *(short *)(puVar9 + 0xe) + *(short *)(puVar9 + 0x14);
    sVar3 = DAT_ffffdcc2;
    puVar9 = puVar9 + 0x18;
    sVar4 = sVar4 + -1;
  } while (sVar4 != -1);
  (&DAT_ffffb976)[*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                             (int)DAT_ffffdcc2)] = 0x80;
  FUN_0002224c();
  FUN_0002246e();
  do {
    iVar7 = (int)sVar3;
    *(undefined2 *)((int)&comp_vel[0].y + iVar7) = 0;
    *(short *)(&DAT_ffffbd78 + iVar7) = *(short *)((int)&comp_pos_y + iVar7);
    *(short *)((int)&comp_pos_y + iVar7) =
        *(short *)((int)&comp_pos_y + iVar7) + -0xc0;
    sVar3 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar7);
  } while (-1 < sVar3);
  return;
}

void FUN_00021e32(void)

{
  if ((DAT_ffffdcc0 & 0x80) != 0) {
    DAT_ffffdcc1 = DAT_ffffdcc1 + '\x02';
  }
  return;
}

void FUN_00021e40(void)

{
  short sVar1;
  short *psVar2;
  bool bVar3;
  entity_id_t unaff_A4;

  bVar3 = false;
  do {
    if (-1 < *(short *)(&comp_unk_4 + unaff_A4)) {
      if (*(short *)(&comp_unk_4 + unaff_A4) == 0) {
        psVar2 = (short *)((int)&comp_vel[0].y + unaff_A4);
        *psVar2 = *psVar2 + 0x40;
        ecs_update_pos_y(unaff_A4);
        if (*(ushort *)(&DAT_ffffbd78 + unaff_A4) <=
            *(ushort *)((int)&comp_pos_y + unaff_A4)) {
          *(ushort *)(&DAT_ffffbd78 + unaff_A4) =
              *(ushort *)(&DAT_ffffbd78 + unaff_A4);
          goto LAB_00021e66;
        }
      } else {
      LAB_00021e66:
        *(short *)(&comp_unk_4 + unaff_A4) =
            *(short *)(&comp_unk_4 + unaff_A4) + -1;
      }
      bVar3 = true;
    }
    sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
    if (sVar1 < 0) {
      if (!bVar3) {
        *(undefined1 *)((int)&comp_state + (int)DAT_ffffdcc2) = 1;
      }
      return;
    }
    unaff_A4 = (entity_id_t)sVar1;
  } while (true);
}

void FUN_00021ea0(void)

{
  ushort uVar1;
  uint uVar2;
  short sVar3;
  short sVar4;
  short *extraout_A0;
  short *psVar5;
  uint unaff_A4;

  DAT_ffffdccf = 0;
  DAT_ffffdcc1 = DAT_ffffdcc1 + '\x02';
  *(undefined2 *)(&comp_unk_4 + unaff_A4) = 8;
  FUN_000222c0();
  if (DAT_ffffdcc4 == 0) {
    FUN_00022192();
    FUN_00022068();
  } else {
    FUN_00022192();
  }
  FUN_000222d0();
  FUN_0002224c();
  FUN_00022500();
  uVar2 = unaff_A4 & 0xffff;
  psVar5 = &DAT_ffffdce0;
  do {
    *psVar5 = (short)uVar2;
    uVar1 = *(ushort *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                        (int)(short)uVar2);
    uVar2 = (uint)uVar1;
    psVar5 = psVar5 + 1;
  } while (-1 < (short)uVar1);
  FUN_000224a0();
  sVar3 = 0xf;
  sVar4 = 4;
  psVar5 = extraout_A0;
  do {
    *(short *)((int)&comp_unk_3 + (int)*psVar5) = sVar4;
    sVar4 = sVar4 + 2;
    sVar3 = sVar3 + -1;
    psVar5 = psVar5 + 1;
  } while (sVar3 != -1);
  FUN_00022552();
  return;
}

void FUN_00021eb8(void)

{
  short sVar1;
  short sVar2;
  short *extraout_A0;
  short *psVar3;
  short unaff_A4w;

  if (DAT_ffffdcc4 == 0) {
    FUN_00022192();
    FUN_00022068();
  } else {
    FUN_00022192();
  }
  FUN_000222d0();
  FUN_0002224c();
  FUN_00022500();
  psVar3 = &DAT_ffffdce0;
  do {
    *psVar3 = unaff_A4w;
    unaff_A4w =
        *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + (int)unaff_A4w);
    psVar3 = psVar3 + 1;
  } while (-1 < unaff_A4w);
  FUN_000224a0();
  sVar1 = 0xf;
  sVar2 = 4;
  psVar3 = extraout_A0;
  do {
    *(short *)((int)&comp_unk_3 + (int)*psVar3) = sVar2;
    sVar2 = sVar2 + 2;
    sVar1 = sVar1 + -1;
    psVar3 = psVar3 + 1;
  } while (sVar1 != -1);
  FUN_00022552();
  return;
}

void FUN_00021ec4(void)

{
  short sVar1;
  short sVar2;
  short *extraout_A0;
  short *psVar3;
  short unaff_A4w;

  FUN_00022192();
  FUN_00022068();
  FUN_000222d0();
  FUN_0002224c();
  FUN_00022500();
  psVar3 = &DAT_ffffdce0;
  do {
    *psVar3 = unaff_A4w;
    unaff_A4w =
        *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + (int)unaff_A4w);
    psVar3 = psVar3 + 1;
  } while (-1 < unaff_A4w);
  FUN_000224a0();
  sVar1 = 0xf;
  sVar2 = 4;
  psVar3 = extraout_A0;
  do {
    *(short *)((int)&comp_unk_3 + (int)*psVar3) = sVar2;
    sVar2 = sVar2 + 2;
    sVar1 = sVar1 + -1;
    psVar3 = psVar3 + 1;
  } while (sVar1 != -1);
  FUN_00022552();
  return;
}

void FUN_00021ed8(void)

{
  ushort uVar1;
  uint uVar2;
  short sVar3;
  short sVar4;
  short *extraout_A0;
  short *psVar5;
  uint unaff_A4;

  DAT_ffffdccf = 1;
  DAT_ffffdcc1 = DAT_ffffdcc1 + '\x02';
  *(undefined2 *)(&comp_unk_4 + unaff_A4) = 8;
  FUN_000222c0();
  FUN_00022192();
  FUN_00022068();
  FUN_000222d0();
  FUN_0002224c();
  FUN_00022500();
  uVar2 = unaff_A4 & 0xffff;
  psVar5 = &DAT_ffffdce0;
  do {
    *psVar5 = (short)uVar2;
    uVar1 = *(ushort *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                        (int)(short)uVar2);
    uVar2 = (uint)uVar1;
    psVar5 = psVar5 + 1;
  } while (-1 < (short)uVar1);
  FUN_000224a0();
  sVar3 = 0xf;
  sVar4 = 4;
  psVar5 = extraout_A0;
  do {
    *(short *)((int)&comp_unk_3 + (int)*psVar5) = sVar4;
    sVar4 = sVar4 + 2;
    sVar3 = sVar3 + -1;
    psVar5 = psVar5 + 1;
  } while (sVar3 != -1);
  FUN_00022552();
  return;
}

void FUN_00021ef2(void)

{
  short sVar1;
  short sVar2;
  short *extraout_A0;
  short *psVar3;
  short unaff_A4w;

  DAT_ffffdccf = 2;
  DAT_ffffdcc1 = DAT_ffffdcc1 + '\x02';
  FUN_000222c0();
  FUN_00022192();
  if (DAT_ffffdcc4 == 0) {
    DAT_ffffdcc1 = '\0';
  }
  FUN_000222d0();
  FUN_0002224c();
  FUN_00022500();
  psVar3 = &DAT_ffffdce0;
  do {
    *psVar3 = unaff_A4w;
    unaff_A4w =
        *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + (int)unaff_A4w);
    psVar3 = psVar3 + 1;
  } while (-1 < unaff_A4w);
  FUN_000224a0();
  sVar1 = 0xf;
  sVar2 = 4;
  psVar3 = extraout_A0;
  do {
    *(short *)((int)&comp_unk_3 + (int)*psVar3) = sVar2;
    sVar2 = sVar2 + 2;
    sVar1 = sVar1 + -1;
    psVar3 = psVar3 + 1;
  } while (sVar1 != -1);
  FUN_00022552();
  return;
}

void FUN_00021f04(void)

{
  short sVar1;
  short sVar2;
  short *extraout_A0;
  short *psVar3;
  short unaff_A4w;

  FUN_00022192();
  if (DAT_ffffdcc4 == 0) {
    DAT_ffffdcc1 = 0;
  }
  FUN_000222d0();
  FUN_0002224c();
  FUN_00022500();
  psVar3 = &DAT_ffffdce0;
  do {
    *psVar3 = unaff_A4w;
    unaff_A4w =
        *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + (int)unaff_A4w);
    psVar3 = psVar3 + 1;
  } while (-1 < unaff_A4w);
  FUN_000224a0();
  sVar1 = 0xf;
  sVar2 = 4;
  psVar3 = extraout_A0;
  do {
    *(short *)((int)&comp_unk_3 + (int)*psVar3) = sVar2;
    sVar2 = sVar2 + 2;
    sVar1 = sVar1 + -1;
    psVar3 = psVar3 + 1;
  } while (sVar1 != -1);
  FUN_00022552();
  return;
}

void FUN_00021f1e(void)

{
  ushort uVar1;
  byte bVar2;
  undefined2 uVar4;
  uint uVar3;
  short sVar5;
  short sVar6;
  short *extraout_A0;
  short *psVar7;
  ulong unaff_A4;

  DAT_ffffdcc1 = DAT_ffffdcc1 + '\x02';
  FUN_000222c0();
  bVar2 = DAT_ffffdcc0;
  DAT_ffffdcc0 = DAT_ffffdcc0 | 4;
  uVar4 = 0xfe00;
  if ((bVar2 & 1) != 0) {
    uVar4 = 0x200;
  }
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = uVar4;
  FUN_00022192();
  FUN_00002256();
  psVar7 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar7 = *psVar7 + 0x40;
  player_update_pos(unaff_A4);
  if (((DAT_ffffdcc0 & 2) == 0) && (DAT_ffffdcc4 == 0)) {
    DAT_ffffdcc1 = '\0';
  }
  FUN_000222d0();
  FUN_0002224c();
  FUN_00022500();
  uVar3 = unaff_A4 & 0xffff;
  psVar7 = &DAT_ffffdce0;
  do {
    *psVar7 = (short)uVar3;
    uVar1 = *(ushort *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                        (int)(short)uVar3);
    uVar3 = (uint)uVar1;
    psVar7 = psVar7 + 1;
  } while (-1 < (short)uVar1);
  FUN_000224a0();
  sVar5 = 0xf;
  sVar6 = 4;
  psVar7 = extraout_A0;
  do {
    *(short *)((int)&comp_unk_3 + (int)*psVar7) = sVar6;
    sVar6 = sVar6 + 2;
    sVar5 = sVar5 + -1;
    psVar7 = psVar7 + 1;
  } while (sVar5 != -1);
  FUN_00022552();
  return;
}

void FUN_00021f50(void)

{
  ushort uVar1;
  uint uVar2;
  short sVar3;
  short sVar4;
  short *extraout_A0;
  short *psVar5;
  ulong unaff_A4;

  FUN_00022192();
  FUN_00002256();
  psVar5 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar5 = *psVar5 + 0x40;
  player_update_pos(unaff_A4);
  if (((DAT_ffffdcc0 & 2) == 0) && (DAT_ffffdcc4 == 0)) {
    DAT_ffffdcc1 = 0;
  }
  FUN_000222d0();
  FUN_0002224c();
  FUN_00022500();
  uVar2 = unaff_A4 & 0xffff;
  psVar5 = &DAT_ffffdce0;
  do {
    *psVar5 = (short)uVar2;
    uVar1 = *(ushort *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                        (int)(short)uVar2);
    uVar2 = (uint)uVar1;
    psVar5 = psVar5 + 1;
  } while (-1 < (short)uVar1);
  FUN_000224a0();
  sVar3 = 0xf;
  sVar4 = 4;
  psVar5 = extraout_A0;
  do {
    *(short *)((int)&comp_unk_3 + (int)*psVar5) = sVar4;
    sVar4 = sVar4 + 2;
    sVar3 = sVar3 + -1;
    psVar5 = psVar5 + 1;
  } while (sVar3 != -1);
  FUN_00022552();
  return;
}

void FUN_00021f80(void)

{
  ushort uVar1;
  undefined2 uVar3;
  uint uVar2;
  short sVar4;
  short sVar5;
  short *extraout_A0;
  short *psVar6;
  ulong unaff_A4;

  DAT_ffffdcc1 = DAT_ffffdcc1 + '\x02';
  FUN_000222c0();
  FUN_00022192();
  if (DAT_ffffdcc4 == 0) {
    DAT_ffffdcc1 = DAT_ffffdcc1 + '\x02';
    DAT_ffffdcc0 = DAT_ffffdcc0 | 2;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfe00;
    uVar3 = 0x80;
    if ((DAT_ffffdcc0 & 1) != 0) {
      uVar3 = 0xff80;
    }
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = uVar3;
    player_update_pos(unaff_A4);
  }
  FUN_000222d0();
  FUN_0002224c();
  FUN_00022500();
  uVar2 = unaff_A4 & 0xffff;
  psVar6 = &DAT_ffffdce0;
  do {
    *psVar6 = (short)uVar2;
    uVar1 = *(ushort *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                        (int)(short)uVar2);
    uVar2 = (uint)uVar1;
    psVar6 = psVar6 + 1;
  } while (-1 < (short)uVar1);
  FUN_000224a0();
  sVar4 = 0xf;
  sVar5 = 4;
  psVar6 = extraout_A0;
  do {
    *(short *)((int)&comp_unk_3 + (int)*psVar6) = sVar5;
    sVar5 = sVar5 + 2;
    sVar4 = sVar4 + -1;
    psVar6 = psVar6 + 1;
  } while (sVar4 != -1);
  FUN_00022552();
  return;
}

void FUN_00021f8c(void)

{
  ushort uVar1;
  undefined2 uVar3;
  uint uVar2;
  short sVar4;
  short sVar5;
  short *extraout_A0;
  short *psVar6;
  ulong unaff_A4;

  FUN_00022192();
  if (DAT_ffffdcc4 == 0) {
    DAT_ffffdcc1 = DAT_ffffdcc1 + '\x02';
    DAT_ffffdcc0 = DAT_ffffdcc0 | 2;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfe00;
    uVar3 = 0x80;
    if ((DAT_ffffdcc0 & 1) != 0) {
      uVar3 = 0xff80;
    }
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = uVar3;
    player_update_pos(unaff_A4);
  }
  FUN_000222d0();
  FUN_0002224c();
  FUN_00022500();
  uVar2 = unaff_A4 & 0xffff;
  psVar6 = &DAT_ffffdce0;
  do {
    *psVar6 = (short)uVar2;
    uVar1 = *(ushort *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                        (int)(short)uVar2);
    uVar2 = (uint)uVar1;
    psVar6 = psVar6 + 1;
  } while (-1 < (short)uVar1);
  FUN_000224a0();
  sVar4 = 0xf;
  sVar5 = 4;
  psVar6 = extraout_A0;
  do {
    *(short *)((int)&comp_unk_3 + (int)*psVar6) = sVar5;
    sVar5 = sVar5 + 2;
    sVar4 = sVar4 + -1;
    psVar6 = psVar6 + 1;
  } while (sVar4 != -1);
  FUN_00022552();
  return;
}

void FUN_00021fc8(void)

{
  short *psVar1;
  ulong unaff_A4;

  FUN_00022192();
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x40;
  player_update_pos(unaff_A4);
  FUN_000222d0();
  FUN_0002224c();
  FUN_0002246e();
  if ((DAT_ffffdcc0 & 2) == 0) {
    DAT_ffffdcc1 = 0;
  }
  return;
}

void FUN_00021ff0(void)

{
  byte bVar1;
  byte bVar2;
  ushort uVar3;
  char extraout_D1b;

  DAT_ffffdcc1 = DAT_ffffdcc1 + '\x02';
  FUN_000222c0();
  FUN_00022192();
  if ((DAT_ffffdcc4 == 0) &&
      (uVar3 = FUN_000022ec(), DAT_ffffdcc1 = extraout_D1b, uVar3 < 0x50)) {
    DAT_ffffdcc1 = '\f';
  }
  bVar2 = DAT_ffffdcc0;
  bVar1 = DAT_ffffdcc0 & 8;
  DAT_ffffdcc0 = DAT_ffffdcc0 & 0xf7;
  if (bVar1 != 0) {
    DAT_ffffdcc0 = bVar2 & 0xf3;
    uVar3 = FUN_000022ec();
    if (uVar3 < 0x30) {
      DAT_ffffdcc0 = DAT_ffffdcc0 | 4;
    }
  }
  FUN_000222d0();
  FUN_0002224c();
  FUN_0002246e();
  return;
}

void FUN_00021ffc(void)

{
  byte bVar1;
  byte bVar2;
  ushort uVar3;
  undefined1 extraout_D1b;

  FUN_00022192();
  if ((DAT_ffffdcc4 == 0) &&
      (uVar3 = FUN_000022ec(), DAT_ffffdcc1 = extraout_D1b, uVar3 < 0x50)) {
    DAT_ffffdcc1 = 0xc;
  }
  bVar2 = DAT_ffffdcc0;
  bVar1 = DAT_ffffdcc0 & 8;
  DAT_ffffdcc0 = DAT_ffffdcc0 & 0xf7;
  if (bVar1 != 0) {
    DAT_ffffdcc0 = bVar2 & 0xf3;
    uVar3 = FUN_000022ec();
    if (uVar3 < 0x30) {
      DAT_ffffdcc0 = DAT_ffffdcc0 | 4;
    }
  }
  FUN_000222d0();
  FUN_0002224c();
  FUN_0002246e();
  return;
}

void FUN_00022042(void)

{
  short sVar1;
  short sVar2;
  short *extraout_A0;
  short *psVar3;
  short unaff_A4w;

  DAT_ffffdcc1 = DAT_ffffdcc1 + '\x02';
  FUN_000222c0();
  FUN_00022192();
  if (DAT_ffffdcc4 == 0) {
    DAT_ffffdcc1 = '\0';
  }
  FUN_000222d0();
  FUN_0002224c();
  FUN_00022500();
  psVar3 = &DAT_ffffdce0;
  do {
    *psVar3 = unaff_A4w;
    unaff_A4w =
        *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + (int)unaff_A4w);
    psVar3 = psVar3 + 1;
  } while (-1 < unaff_A4w);
  FUN_000224a0();
  sVar1 = 0xf;
  sVar2 = 4;
  psVar3 = extraout_A0;
  do {
    *(short *)((int)&comp_unk_3 + (int)*psVar3) = sVar2;
    sVar2 = sVar2 + 2;
    sVar1 = sVar1 + -1;
    psVar3 = psVar3 + 1;
  } while (sVar1 != -1);
  FUN_00022552();
  return;
}

void FUN_0002204e(void)

{
  short sVar1;
  short sVar2;
  short *extraout_A0;
  short *psVar3;
  short unaff_A4w;

  FUN_00022192();
  if (DAT_ffffdcc4 == 0) {
    DAT_ffffdcc1 = 0;
  }
  FUN_000222d0();
  FUN_0002224c();
  FUN_00022500();
  psVar3 = &DAT_ffffdce0;
  do {
    *psVar3 = unaff_A4w;
    unaff_A4w =
        *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + (int)unaff_A4w);
    psVar3 = psVar3 + 1;
  } while (-1 < unaff_A4w);
  FUN_000224a0();
  sVar1 = 0xf;
  sVar2 = 4;
  psVar3 = extraout_A0;
  do {
    *(short *)((int)&comp_unk_3 + (int)*psVar3) = sVar2;
    sVar2 = sVar2 + 2;
    sVar1 = sVar1 + -1;
    psVar3 = psVar3 + 1;
  } while (sVar1 != -1);
  FUN_00022552();
  return;
}

void FUN_00022068(void)

{
  short sVar1;
  ushort uVar2;
  int unaff_A4;

  if ((DAT_ffffdcc0 & 0x40) == 0) {
    DAT_ffffdcc0 = DAT_ffffdcc0 & 0xfe;
  }
  uVar2 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  if (((short)uVar2 < 0) && (uVar2 = -uVar2, (DAT_ffffdcc0 & 0x40) == 0)) {
    DAT_ffffdcc0 = DAT_ffffdcc0 | 1;
  }
  if (uVar2 < 0x20) {
    if (DAT_ffffdccf != '\x02') {
      DAT_ffffdcc1 = 0xc;
      return;
    }
  } else if (uVar2 < 0x48) {
    sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
    if (sVar1 == 0) {
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 8;
      if ((int16_t)(comp_collision_sensor[0].y + comp_pos_y.fixed.i) !=
          DAT_ffffce0a) {
        DAT_ffffdcc1 = 0x1a;
        return;
      }
      if ((int16_t)(comp_collision_sensor[0].y + comp_pos_y.fixed.i) ==
          DAT_ffffce0a) {
        DAT_ffffdcc1 = 0x16;
        return;
      }
    }
    if (DAT_ffffdccf != '\0') {
      DAT_ffffdcc1 = 0;
      return;
    }
  } else if (DAT_ffffdccf != '\x01') {
    DAT_ffffdcc1 = 8;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002210a(void)

{
  byte bVar1;
  short sVar2;

  DAT_ffffdcc1 = DAT_ffffdcc1 + '\x02';
  _DAT_ffffdb3e = 0xb4;
  audio_play_sound_asha_dies();
  while (true) {
    IO_Z80BUS = 0x100;
    do {
      bVar1 = IO_Z80BUS._0_1_;
    } while ((bVar1 & 1) != 0);
    if (z80_ram_something_1 == '\0')
      break;
    IO_Z80BUS = 0;
    sVar2 = 0x1f;
    do {
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
  }
  (&z80_ram)[(short)(((byte)(z80_ram_something_3 + z80_ram_something_2) & 0xf) +
                     0x1c30)] = 0x4c;
  z80_ram_something_3 = z80_ram_something_3 + '\x01';
  IO_Z80BUS = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002211e(void)

{
  ushort uVar2;
  uint uVar1;
  short i;
  short sVar3;
  char extraout_D1b;
  vdp_color_t *pvVar4;
  short *extraout_A0;
  short *psVar5;
  vdp_color_t *pvVar6;
  uint unaff_A4;

  _DAT_ffffdb3e = _DAT_ffffdb3e + -1;
  if (_DAT_ffffdb3e == 0) {
    DAT_ffffdcc1 = DAT_ffffdcc1 + '\x02';
    FUN_0001fd5e();
    palette_copy_from_palettes2(extraout_D1b);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff00;
    FUN_000222c0();
    DAT_ffffdcce = 0x40;
    DAT_ffffdcc0 = DAT_ffffdcc0 | 0x20;
    FUN_000222d0();
    FUN_00022500();
    uVar1 = unaff_A4 & 0xffff;
    psVar5 = &DAT_ffffdce0;
    do {
      *psVar5 = (short)uVar1;
      uVar2 = *(ushort *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                          (int)(short)uVar1);
      uVar1 = (uint)uVar2;
      psVar5 = psVar5 + 1;
    } while (-1 < (short)uVar2);
    FUN_000224a0();
    i = 0xf;
    sVar3 = 4;
    psVar5 = extraout_A0;
    do {
      *(short *)((int)&comp_unk_3 + (int)*psVar5) = sVar3;
      sVar3 = sVar3 + 2;
      i = i + -1;
      psVar5 = psVar5 + 1;
    } while (i != -1);
    FUN_00022552();
    return;
  }
  for (uVar2 = (0xb4 - _DAT_ffffdb3e) * 2; 0x53 < uVar2; uVar2 = uVar2 - 0x54) {
  }
  sVar3 = 0xf;
  pvVar4 = palettes_2;
  do {
    *pvVar4 = *(vdp_color_t *)(&UNK_0001fdd8 + (short)uVar2);
    uVar2 = uVar2 + 2;
    if (0x53 < uVar2) {
      uVar2 = 0;
    }
    sVar3 = sVar3 + -1;
    pvVar4 = pvVar4 + 1;
  } while (sVar3 != -1);
  sVar3 = 7;
  pvVar4 = palettes_2;
  pvVar6 = palettes[1];
  do {
    *(undefined4 *)pvVar6 = *(undefined4 *)pvVar4;
    sVar3 = sVar3 + -1;
    pvVar4 = pvVar4 + 2;
    pvVar6 = pvVar6 + 2;
  } while (sVar3 != -1);
  palette_set_fade(
      PALETTE_ID_FLAG_1, PALETTE_FADE_1, -1, (palette_color_iter_t)0xffffffff);
  return;
}

void FUN_00022154(void)

{
  ushort uVar1;
  component_state_b_t cVar2;
  entity_id_t eVar3;
  short sVar4;
  entity_state_a_t eVar5;
  short sVar6;
  short *extraout_A0;
  short *psVar7;
  entity_id_t unaff_A4;
  int iVar8;
  short sStack_2;

  if (DAT_ffffdcc4 != 0) {
    ecs_update_pos_y(unaff_A4);
    FUN_000222d0();
    FUN_00022500();
    eVar3 = unaff_A4 & 0xffff;
    psVar7 = &DAT_ffffdce0;
    do {
      *psVar7 = (short)eVar3;
      uVar1 = *(ushort *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                          (int)(short)eVar3);
      eVar3 = (entity_id_t)uVar1;
      psVar7 = psVar7 + 1;
    } while (-1 < (short)uVar1);
    FUN_000224a0();
    sVar4 = 0xf;
    sVar6 = 4;
    psVar7 = extraout_A0;
    do {
      *(short *)((int)&comp_unk_3 + (int)*psVar7) = sVar6;
      sVar6 = sVar6 + 2;
      sVar4 = sVar4 + -1;
      psVar7 = psVar7 + 1;
    } while (sVar4 != -1);
    FUN_00022552();
    return;
  }
  FUN_00015e86();
  sStack_2 = 0x10;
  do {
    FUN_00025398();
    FUN_00024d78();
    sStack_2 = sStack_2 + -1;
  } while (sStack_2 != 0);
  iVar8 = (int)DAT_ffffdcc2;
  cVar2 = (&comp_has_func_maybe)[iVar8];
  (&comp_has_func_maybe)[iVar8] = cVar2 | 0x40;
  if ((cVar2 & 0x40) == 0) {
    FUN_000019ae();
    *(undefined2 *)((int)&comp_anim_speed + iVar8) = 0x100;
    eVar5 = 0;
    if (DAT_ffffcc28 != '\0') {
      eVar5 = 0x80;
    }
    (&comp_state_a)[iVar8] = eVar5;
    *(undefined2 *)((int)&comp_unk_3 + iVar8) = 4;
    *(undefined1 *)((int)&comp_state + iVar8) = 0;
  }
  // WARNING: Could not recover jumptable at 0x00024e1e. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00024e22 +
             (int)*(short *)((int)&WORD_00024e22 +
                             (int)(short)(ushort)(&comp_func_offset[0]
                                                       .unk3)[iVar8])))();
  return;
}

void FUN_00022192(void)

{
  short sVar1;
  byte bVar2;
  byte bVar3;
  byte bVar4;
  short *psVar5;
  byte *pbVar7;
  int iVar8;
  bool bVar9;
  short *psVar6;

  psVar5 = SHORT_ARRAY_0002222a;
  do {
    while (true) {
      psVar6 = psVar5 + 1;
      if (*psVar5 < 0) {
        return;
      }
      pbVar7 = (byte *)(int)(short)(*psVar5 + -0x24c0);
      sVar1 = *(short *)(pbVar7 + 2);
      psVar5 = psVar6;
      if ((*pbVar7 & 2) == 0)
        break;
      bVar9 = psVar6 == (short *)0x0;
      FUN_00002140();
      if (!bVar9) {
        return;
      }
    }
    (&comp_unk_11)[sVar1] = (&comp_unk_11)[DAT_ffffdcc2];
    FUN_00001fd2();
  } while (((&comp_func_offset[0].unk4)[sVar1] & 1) == 0);
  audio_play(SOUND_ID_DAMAGE_2);
  bVar4 = DAT_ffffde0e;
  if (((&comp_func_offset[0].unk4)[sVar1] & 4) != 0) {
    bVar4 = DAT_ffffde0f;
  }
  iVar8 = (int)DAT_ffffdcc2;
  if ((&comp_unk_11)[iVar8] != '\0') {
    return;
  }
  bVar2 = (&comp_collected_item_id_maybe)[iVar8];
  bVar3 = bVar2 - bVar4;
  (&comp_collected_item_id_maybe)[iVar8] = bVar3;
  if (bVar2 < bVar4 || bVar3 == 0) {
    *(undefined1 *)((int)&comp_state + iVar8) = 2;
    return;
  }
  DAT_ffffdcc0 = DAT_ffffdcc0 & 0xfe;
  if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + iVar8)) {
    DAT_ffffdcc0 = DAT_ffffdcc0 | 1;
  }
  (&comp_unk_11)[iVar8] = 0x40;
  DAT_ffffdcc1 = 4;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

ulonglong FUN_0002224c(void)

{
  short sVar1;
  undefined4 in_D0;
  uint uVar2;
  uint uVar3;
  undefined4 in_D1;
  uint uVar4;
  short sVar5;
  int unaff_A4;

  uVar2 = CONCAT22((short)((uint)in_D0 >> 0x10), _DAT_ffffdc72);
  uVar4 = CONCAT22((short)((uint)in_D1 >> 0x10), _DAT_ffffdcba);
  uVar3 = uVar2;
  if (_DAT_ffffdc72 == _DAT_ffffdcba) {
    if ((DAT_ffffdcc0 & 4) == 0)
      goto LAB_00022274;
  } else {
    if (_DAT_ffffdcba <= _DAT_ffffdc72) {
      DAT_ffffdcc0 = DAT_ffffdcc0 & 0xfb;
      goto LAB_00022274;
    }
    DAT_ffffdcc0 = DAT_ffffdcc0 | 4;
  }
  uVar3 = uVar4;
  uVar4 = uVar2;
LAB_00022274:
  sVar1 = DAT_ffffce0a - ((short)uVar3 + 4);
  if ((DAT_ffffdcc0 & 2) == 0) {
    if ((DAT_ffffdcc0 & 4) == 0) {
      sVar5 = DAT_ffffdc70 - _DAT_ffffdcd0;
    } else {
      sVar5 = DAT_ffffdcb8 - _DAT_ffffdcd2;
    }
    uVar4 = CONCAT22((short)(uVar4 >> 0x10), sVar5);
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_pos_x + unaff_A4) - sVar5;
  } else {
    if (*(short *)((int)&comp_pos_y + unaff_A4) < sVar1) {
      return (ulonglong)uVar4;
    }
    DAT_ffffdcc0 = DAT_ffffdcc0 & 0xfd;
  }
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(short *)((int)&comp_pos_y + unaff_A4) = sVar1;
  return CONCAT44(0xffffffff, uVar4);
}

void FUN_000222c0(void)

{
  undefined4 in_A0;

  DAT_ffffdcc8 = in_A0;
  DAT_ffffdcc0 = DAT_ffffdcc0 | 0x10;
  DAT_ffffdcc4._0_1_ = 0xff;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000222d0(void)

{
  byte bVar1;
  short sVar2;
  short sVar3;
  ushort uVar4;
  byte *pbVar5;
  byte *pbVar6;
  undefined1 *puVar7;
  byte *pbVar8;

  _DAT_ffffdcd0 = DAT_ffffdc70;
  _DAT_ffffdcd2 = DAT_ffffdcb8;
  bVar1 = DAT_ffffdcc0 & 0x10;
  DAT_ffffdcc0 = DAT_ffffdcc0 & 0xef;
  if (bVar1 == 0) {
    if (DAT_ffffdcc4 == 0) {
      _DAT_ffffdcd0 = DAT_ffffdc70;
      _DAT_ffffdcd2 = DAT_ffffdcb8;
      return;
    }
    uVar4 = DAT_ffffdcc4 + DAT_ffffdcc6;
    if (uVar4 < 0x4000) {
      puVar7 = &DAT_ffffdb58;
      sVar3 = 0xe;
      DAT_ffffdcc6 = uVar4;
      do {
        *(short *)(puVar7 + 0x10) =
            *(short *)(puVar7 + 4) +
            (short)((uint)((int)*(short *)(puVar7 + 10) * (int)(short)uVar4 *
                           4) >>
                    0x10);
        *(short *)(puVar7 + 0x12) =
            *(short *)(puVar7 + 6) +
            (short)((uint)((int)*(short *)(puVar7 + 0xc) * (int)(short)uVar4 *
                           4) >>
                    0x10);
        *(short *)(puVar7 + 0x14) =
            *(short *)(puVar7 + 8) +
            (short)((uint)((int)*(short *)(puVar7 + 0xe) * (int)(short)uVar4 *
                           4) >>
                    0x10);
        puVar7 = puVar7 + 0x18;
        sVar3 = sVar3 + -1;
      } while (sVar3 != -1);
      return;
    }
    puVar7 = &DAT_ffffdb58;
    sVar3 = 0xe;
    do {
      sVar2 = *(short *)(puVar7 + 4);
      *(short *)(puVar7 + 4) = *(short *)(puVar7 + 10) + sVar2;
      *(short *)(puVar7 + 0x10) = *(short *)(puVar7 + 10) + sVar2;
      sVar2 = *(short *)(puVar7 + 6);
      *(short *)(puVar7 + 6) = *(short *)(puVar7 + 0xc) + sVar2;
      *(short *)(puVar7 + 0x12) = *(short *)(puVar7 + 0xc) + sVar2;
      sVar2 = *(short *)(puVar7 + 8);
      *(short *)(puVar7 + 8) = *(short *)(puVar7 + 0xe) + sVar2;
      *(short *)(puVar7 + 0x14) = *(short *)(puVar7 + 0xe) + sVar2;
      puVar7 = puVar7 + 0x18;
      sVar3 = sVar3 + -1;
    } while (sVar3 != -1);
  } else {
    puVar7 = &DAT_ffffdb58;
    sVar3 = 0xe;
    do {
      *(undefined2 *)(puVar7 + 4) = *(undefined2 *)(puVar7 + 0x10);
      *(undefined2 *)(puVar7 + 6) = *(undefined2 *)(puVar7 + 0x12);
      *(undefined2 *)(puVar7 + 8) = *(undefined2 *)(puVar7 + 0x14);
      puVar7 = puVar7 + 0x18;
      sVar3 = sVar3 + -1;
    } while (sVar3 != -1);
  }
  DAT_ffffdcc6 = 0;
  pbVar8 = DAT_ffffdcc8;
  while (true) {
    while (true) {
      pbVar6 = pbVar8 + 1;
      bVar1 = *pbVar8;
      if (bVar1 == 0) {
        DAT_ffffdcc6 = 0;
        DAT_ffffdcc4 = 0;
        return;
      }
      if (bVar1 != 0xff)
        break;
      pbVar8 = pbVar8 + *(short *)pbVar6 + 1;
    }
    if (bVar1 != 0xfe)
      break;
    DAT_ffffdcc0 = DAT_ffffdcc0 | 8;
    pbVar8 = pbVar6;
  }
  if (bVar1 != 0xfd) {
    DAT_ffffdcc4 = (ushort)bVar1 * DAT_ffffdccc;
    pbVar8 = &DAT_ffffdb58;
    sVar3 = 4;
    do {
      DAT_ffffdcc8 = pbVar6 + 2;
      pbVar6 = pbVar6 + *(short *)pbVar6;
      uVar4 = (ushort)*pbVar6;
      do {
        pbVar5 = pbVar6 + 2;
        sVar2 = (short)(char)pbVar6[1];
        if ((DAT_ffffdcc0 & 1) != 0) {
          sVar2 = -sVar2;
        }
        *(short *)(pbVar8 + 10) = sVar2 - *(short *)(pbVar8 + 4);
        pbVar6 = pbVar6 + 3;
        *(short *)(pbVar8 + 0xc) =
            (short)(char)*pbVar5 - *(short *)(pbVar8 + 6);
        sVar2 = (short)(char)*pbVar6;
        if ((*pbVar8 & 1) != 0) {
          sVar2 = -sVar2;
        }
        *(short *)(pbVar8 + 0xe) = sVar2 - *(short *)(pbVar8 + 8);
        pbVar8 = pbVar8 + 0x18;
        uVar4 = uVar4 - 1;
      } while (uVar4 != 0xffff);
      sVar3 = sVar3 + -1;
      pbVar6 = DAT_ffffdcc8;
    } while (sVar3 != -1);
    return;
  }
  DAT_ffffdcc8 = pbVar8 + 2;
  DAT_ffffdcc4 = (ushort)*pbVar6 * DAT_ffffdccc;
  puVar7 = &DAT_ffffdb58;
  sVar3 = 0xe;
  do {
    *(undefined2 *)(puVar7 + 10) = 0;
    *(undefined2 *)(puVar7 + 0xc) = 0;
    *(undefined2 *)(puVar7 + 0xe) = 0;
    puVar7 = puVar7 + 0x18;
    sVar3 = sVar3 + -1;
  } while (sVar3 != -1);
  return;
}

void FUN_0002246e(void)

{
  short i;
  short sVar1;
  short *extraout_A0;
  short *psVar2;
  short unaff_A4w;

  FUN_00022500();
  psVar2 = &DAT_ffffdce0;
  do {
    *psVar2 = unaff_A4w;
    unaff_A4w =
        *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + (int)unaff_A4w);
    psVar2 = psVar2 + 1;
  } while (-1 < unaff_A4w);
  FUN_000224a0();
  i = 0xf;
  sVar1 = 4;
  psVar2 = extraout_A0;
  do {
    *(short *)((int)&comp_unk_3 + (int)*psVar2) = sVar1;
    sVar1 = sVar1 + 2;
    i = i + -1;
    psVar2 = psVar2 + 1;
  } while (i != -1);
  FUN_00022552();
  return;
}

void FUN_000224a0(void)

{
  int iVar1;
  short sVar2;
  short sVar3;
  ushort uVar4;
  ushort in_D0w;
  short in_D1w;
  ushort uVar5;
  ushort uVar6;
  ushort uVar7;
  int in_A0;
  int extraout_A0;

  do {
    iVar1 =
        *(int *)((int)&comp_some_function +
                 (int)*(short *)(in_A0 + -2 +
                                 (int)(short)(((short)(in_D1w + in_D0w) >> 2) *
                                              2)));
    uVar6 = in_D1w + 2;
    uVar4 = in_D0w - 2;
    do {
      do {
        uVar5 = uVar4;
        uVar4 = uVar5 + 2;
        sVar2 = *(short *)(in_A0 + -2 + (int)(short)uVar4);
      } while (iVar1 < *(int *)((int)&comp_some_function + (int)sVar2));
      do {
        uVar7 = uVar6;
        uVar6 = uVar7 - 2;
        sVar3 = *(short *)(in_A0 + -2 + (int)(short)uVar6);
      } while (*(int *)((int)&comp_some_function + (int)sVar3) < iVar1);
      *(short *)(in_A0 + -2 + (int)(short)uVar4) = sVar3;
      *(short *)(in_A0 + -2 + (int)(short)uVar6) = sVar2;
    } while (uVar4 < uVar6);
    *(short *)(in_A0 + -2 + (int)(short)uVar4) = sVar2;
    *(short *)(in_A0 + -2 + (int)(short)uVar6) = sVar3;
    if ((short)in_D0w < (short)uVar5) {
      FUN_000224a0();
      in_A0 = extraout_A0;
    }
    in_D0w = uVar7;
  } while ((short)uVar7 < in_D1w);
  return;
}

void FUN_00022500(void)

{
  short sVar1;
  short sVar2;
  short sVar3;
  short sVar4;
  int iVar5;
  undefined1 *puVar6;
  int unaff_A4;

  *(uint *)((int)&comp_some_function + unaff_A4) =
      (uint)(ushort)(0x9000 - *(short *)((int)&comp_pos_y + unaff_A4));
  puVar6 = &DAT_ffffdb58;
  sVar4 = 0xe;
  do {
    iVar5 = (int)*(short *)(puVar6 + 2);
    sVar1 = *(short *)(puVar6 + 0x14);
    sVar3 = sVar1 >> 3;
    *(short *)((int)&comp_pos_x + iVar5) =
        sVar3 + *(short *)((int)&comp_pos_x + unaff_A4) +
        *(short *)(puVar6 + 0x10);
    sVar2 = *(short *)((int)&comp_pos_y + unaff_A4) + *(short *)(puVar6 + 0x12);
    *(short *)((int)&comp_pos_y + iVar5) = sVar3 + sVar2;
    *(uint *)((int)&comp_some_function + iVar5) =
        CONCAT22(sVar1, -0x7000 - sVar2);
    puVar6 = puVar6 + 0x18;
    sVar4 = sVar4 + -1;
  } while (sVar4 != -1);
  return;
}

void FUN_00022552(void)

{
  short sVar1;
  byte bVar2;
  char cVar3;
  int unaff_A4;
  entity_id_t self;
  anim_item_t *unaff_A5;

  bVar2 = DAT_ffffdcc0;
  self = (entity_id_t) *
         (short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
  DAT_ffffdcc0 = DAT_ffffdcc0 & 0xbf;
  cVar3 = DAT_ffffdcce;
  if (((bVar2 & 0x20) == 0) && (cVar3 = '\0', (bVar2 & 1) != 0)) {
    cVar3 = -0x80;
  }
  if (cVar3 != (&DAT_ffffb976)[self]) {
    DAT_ffffdcc0 = DAT_ffffdcc0 | 0x40;
    (&DAT_ffffb976)[self] = (&DAT_ffffb976)[self] + '\x04';
  }
  sVar1 = (ushort)((byte)((&DAT_ffffb976)[self] + 0x10) >> 5) * 2;
  (&comp_state_a)[self] =
      (&DAT_000225b3)[sVar1] |
      (&comp_state_a)[self] & ~(ENTITY_STATE_A_H_FLIP | ENTITY_STATE_A_08);
  if ((&DAT_000225b2)[sVar1] != (&comp_anim_c)[self]) {
    ecs_anim_unk_2(self, unaff_A5, (&DAT_000225b2)[sVar1]);
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_00022a0c(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_00022a1c(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_00001980();
  (&comp_state_a)[unaff_A4] = 0;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x18;
  ecs_clear_x_vel_round_up_pos(unaff_A4);
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_pos_y + unaff_A4) -
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  ecs_sprite_face_asha(unaff_A4);
  return;
}

char FUN_00022a24(void)

{
  byte bVar1;
  short sVar2;
  char in_D0b;
  char cVar3;
  int unaff_A4;
  bool bVar4;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    (&comp_collision_related)[unaff_A4] = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x3c;
    return in_D0b;
  }
  cVar3 = (&comp_collision_related)[unaff_A4];
  bVar4 = cVar3 == '\0';
  if (bVar4) {
    cVar3 = FUN_000022de();
    if (!bVar4) {
      comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
      sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
      *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
      if (sVar2 == 0) {
        (&comp_collision_related)[unaff_A4] =
            (&comp_collision_related)[unaff_A4] + '\x01';
        *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
        DAT_ffffcc92 = 2;
        DAT_ffffcc93 = 0;
        DAT_ffffd916 = 0xcd;
        return cVar3;
      }
    }
  } else {
    sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
    if (sVar2 == 0) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
    }
  }
  return cVar3;
}

void FUN_00022a7a(void)

{
  byte bVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfb00;
  }
  ecs_update_pos_y(unaff_A4);
  if (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
      (ushort)(0xf80U -
               *(short *)((int)&comp_collision_sensor[0].y + unaff_A4))) {
    DAT_ffffdb40 = DAT_ffffdb40 | 0x80;
    DAT_ffffcc85 = 0;
    FUN_00015e86();
    (&comp_has_func_maybe)[unaff_A4] = 0;
    if (UNION_sound_id_word_union_t_ffff97e6.as_word != 9) {
      UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
      audio_stop_all();
      UNION_sound_id_word_union_t_ffff97e6.as_word = 9;
      audio_play(SOUND_ID_KOOL_DUDE);
    }
    return;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_00022abc(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_00022acc(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_00001980();
  (&comp_state_a)[unaff_A4] = 0x80;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 6;
  ecs_clear_x_vel_round_up_pos(unaff_A4);
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_pos_y + unaff_A4) -
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  ecs_sprite_face_asha(unaff_A4);
  return;
}

char FUN_00022ad4(void)

{
  byte bVar1;
  short sVar2;
  char in_D0b;
  char cVar3;
  int unaff_A4;
  bool bVar4;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    (&comp_collision_related)[unaff_A4] = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x3c;
    return in_D0b;
  }
  cVar3 = (&comp_collision_related)[unaff_A4];
  bVar4 = cVar3 == '\0';
  if (bVar4) {
    cVar3 = FUN_000022de();
    if (!bVar4) {
      comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
      sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
      *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
      if (sVar2 == 0) {
        (&comp_collision_related)[unaff_A4] =
            (&comp_collision_related)[unaff_A4] + '\x01';
        *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
        DAT_ffffcc92 = 2;
        DAT_ffffcc93 = 0;
        DAT_ffffd916 = 0xce;
        return cVar3;
      }
    }
  } else {
    sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
    if (sVar2 == 0) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
    }
  }
  return cVar3;
}

void FUN_00022b2a(void)

{
  short *psVar1;
  byte bVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfb00;
  }
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x40;
  ecs_update_pos_y(unaff_A4);
  if ((ushort)(DAT_ffffc746 + 0x160U) <
      *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    DAT_ffffdc40 = 0xff;
    DAT_ffffcc85 = 0;
    FUN_00015e86();
    (&comp_has_func_maybe)[unaff_A4] = 0;
    if (UNION_sound_id_word_union_t_ffff97e6.as_word != 9) {
      UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
      audio_stop_all();
      UNION_sound_id_word_union_t_ffff97e6.as_word = 9;
      audio_play(SOUND_ID_KOOL_DUDE);
    }
    return;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_00022b70(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_00022b80(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_00001980();
  (&comp_state_a)[unaff_A4] = 0x80;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 6;
  ecs_clear_x_vel_round_up_pos(unaff_A4);
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_pos_y + unaff_A4) -
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  ecs_sprite_face_asha(unaff_A4);
  return;
}

char FUN_00022b88(void)

{
  byte bVar1;
  short sVar2;
  char in_D0b;
  char cVar3;
  int unaff_A4;
  bool bVar4;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    (&comp_collision_related)[unaff_A4] = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x3c;
    return in_D0b;
  }
  cVar3 = (&comp_collision_related)[unaff_A4];
  bVar4 = cVar3 == '\0';
  if (bVar4) {
    cVar3 = FUN_000022de();
    if ((!bVar4) && (sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1,
                     *(short *)(&comp_unk_4 + unaff_A4) = sVar2,
                     sVar2 == 0)) {
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
      DAT_ffffcc92 = 2;
      DAT_ffffcc93 = 0;
      DAT_ffffd916 = 0xcf;
      return cVar3;
    }
  } else {
    sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
    if (sVar2 == 0) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
    }
  }
  return cVar3;
}

void FUN_00022bd8(void)

{
  byte bVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfb00;
  }
  ecs_update_pos_y(unaff_A4);
  if (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
      (ushort)(DAT_ffffc746 - 0x60U)) {
    DAT_ffffdcc0 = DAT_ffffdcc0 | 0x80;
    DAT_ffffcc85 = 0;
    FUN_00015e86();
    (&comp_has_func_maybe)[unaff_A4] = 0;
    if (UNION_sound_id_word_union_t_ffff97e6.as_word != 9) {
      UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
      audio_stop_all();
      UNION_sound_id_word_union_t_ffff97e6.as_word = 9;
      audio_play(SOUND_ID_KOOL_DUDE);
    }
    return;
  }
  return;
}

void FUN_00022c18(void)

{
  ulong unaff_A4;

  FUN_0001fe84();
  FUN_00022c20(unaff_A4);
  return;
}

void FUN_00022c20(ulong ctx)

{
  short sVar1;
  char cVar2;
  ushort uVar3;
  byte state_1_b;
  anim_item_t *unaff_A5;

  cVar2 = *(char *)((int)&comp_state + ctx);
  if (-1 < cVar2) {
    DAT_ffffdb41 = 0;
    *(byte *)((int)&comp_state + ctx) =
        *(byte *)((int)&comp_state + ctx) | 0x80;
  }
  sVar1 = *(short *)((int)&WORD_00022c8a +
                     (int)(short)(ushort)(byte)(cVar2 * '\x02'));
  (*(code *)((int)&WORD_00022c8a +
             (int)*(short *)((int)&WORD_00022c8a +
                             (int)(short)(ushort)DAT_ffffdb41 + (int)sVar1) +
             (int)sVar1))();
  if ((DAT_ffffdb40 & 1) == 0) {
    state_1_b = 0x1a;
    uVar3 = (comp_pos_x.fixed.i + 0x20) - *(short *)((int)&comp_pos_x + ctx);
    if ((-1 < (short)uVar3) && (state_1_b = 0x1c, 0x3f < uVar3)) {
      state_1_b = 0x1e;
    }
    if (state_1_b != (&DAT_ffffa664)[ctx]) {
      ecs_anim_unk_2(ctx + 0x2c, unaff_A5, state_1_b);
    }
    *(undefined2 *)(&DAT_ffffa14e + ctx) =
        *(undefined2 *)((int)&comp_pos_x + ctx);
    *(undefined2 *)(&DAT_ffffa252 + ctx) =
        *(undefined2 *)((int)&comp_pos_y + ctx);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00022c96(void)

{
  byte bVar1;
  short sVar2;
  undefined2 *puVar3;
  short sVar4;
  short sVar5;
  undefined2 *puVar6;
  int iVar7;
  int extraout_A0;
  entity_id_t unaff_A4;
  entity_id_t self;
  int iVar8;
  anim_item_t *unaff_A5;
  short sStack_2;

  DAT_ffffdb40 = 0;
  *(short *)((int)&comp_pos_y + unaff_A4) = DAT_ffffce0a + 0x80;
  DAT_ffffdb42 = (short)unaff_A4;
  FUN_0000281e();
  FUN_0001fd94();
  (&comp_anim[0].unk4)[unaff_A4] = (&comp_anim[0].unk4)[unaff_A4] | 0x40;
  sStack_2 = 9;
  puVar3 = (undefined2 *)&UNK_00022d26;
  do {
    self = unaff_A4;
    puVar6 = puVar3;
    *(undefined2 *)((int)&comp_unk_3 + self) = *puVar6;
    bVar1 = *(byte *)(puVar6 + 1);
    (&comp_state_a)[self] = *(entity_state_a_t *)((int)puVar6 + 3);
    ecs_anim_unk_2(self, unaff_A5, bVar1);
    sStack_2 = sStack_2 + -1;
    puVar3 = puVar6 + 2;
    unaff_A4 = self + ENTITY_ID_PEPELOGOO;
  } while (sStack_2 != 0);
  *(undefined2 *)((int)&DAT_ffff9f28 + self) = puVar6[2];
  bVar1 = *(byte *)(puVar6 + 3);
  (&DAT_ffff9f27)[self] = *(undefined *)((int)puVar6 + 7);
  ecs_anim_unk_2(self + ENTITY_ID_0C, unaff_A5, bVar1);
  iVar8 = (int)DAT_ffffdb42;
  DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
  DAT_ffffdb60._0_1_ = 0;
  FUN_00022d12();
  DAT_ffffdb80._0_1_ = 1;
  FUN_00022d12();
  FUN_000230e4();
  FUN_0002339c();
  (*(code *)((int)&WORD_000230fc +
             (int)*(short *)((int)&WORD_000230fc +
                             (int)(short)(ushort)(byte)(DAT_ffffdb86 *
                                                        '\x02'))))();
  iVar7 = (int)DAT_ffffdb82;
  sVar4 = sRamffffdb88 + 0x18;
  sVar2 = *(short *)((int)&comp_pos_y + iVar8) + sRamffffdb8a + -0x1c;
  sVar5 = sVar4 + sRamffffdb8c;
  if ((DAT_ffffdb80._0_1_ & 1) != 0) {
    sVar5 = -sVar5;
  }
  *(short *)((int)&comp_pos_x + iVar7) =
      *(short *)((int)&comp_pos_x + iVar8) + sVar5;
  *(short *)((int)&comp_pos_y + iVar7) = sVar2 + _DAT_ffffdb8e;
  iVar7 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar7);
  sVar5 = sVar4 + (sRamffffdb8c >> 1);
  if ((DAT_ffffdb80._0_1_ & 1) != 0) {
    sVar5 = -sVar5;
  }
  *(short *)((int)&comp_pos_x + iVar7) =
      *(short *)((int)&comp_pos_x + iVar8) + sVar5;
  *(short *)((int)&comp_pos_y + iVar7) = sVar2 + (_DAT_ffffdb8e >> 1);
  iVar7 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar7);
  if ((DAT_ffffdb80._0_1_ & 1) != 0) {
    sVar4 = -sVar4;
  }
  *(short *)((int)&comp_pos_x + iVar7) =
      *(short *)((int)&comp_pos_x + iVar8) + sVar4;
  *(short *)((int)&comp_pos_y + iVar7) = sVar2;
  iVar7 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar7);
  sVar4 = (sRamffffdb88 >> 1) + 0x18;
  if ((DAT_ffffdb80._0_1_ & 1) != 0) {
    sVar4 = -sVar4;
  }
  *(short *)((int)&comp_pos_x + iVar7) =
      *(short *)((int)&comp_pos_x + iVar8) + sVar4;
  *(short *)((int)&comp_pos_y + iVar7) =
      *(short *)((int)&comp_pos_y + iVar8) + (sRamffffdb8a >> 1) + -0x1c;
  if ((DAT_ffffdb80._0_1_ & 2) != 0) {
    FUN_0002307a();
    iVar7 = (int)DAT_ffffdb82;
    *(undefined2 *)((int)&comp_pos_x + extraout_A0) =
        *(undefined2 *)((int)&comp_pos_x + iVar7);
    *(undefined2 *)((int)&comp_pos_y + extraout_A0) =
        *(undefined2 *)((int)&comp_pos_y + iVar7);
  }
  return;
}

void FUN_00022d12(void)

{
  angle_t angle;
  short unaff_D3w;
  word wVar1;
  undefined2 in_A0w;
  int unaff_A3;

  *(undefined2 *)(unaff_A3 + 2) = in_A0w;
  *(undefined2 *)(unaff_A3 + 4) = 0xffc0;
  *(undefined1 *)(unaff_A3 + 6) = 0;
  FUN_000026e4();
  *(short *)(unaff_A3 + 8) = (short)((uint)(unaff_D3w * 0x30) >> 0x10) + 8;
  wVar1 = angle_sin((angle_t) * (undefined2 *)(unaff_A3 + 4));
  *(short *)(unaff_A3 + 10) =
      (short)((uint)((short)wVar1 * 0x30) >> 0x10) + 0x10;
  FUN_000026e4();
  *(short *)(unaff_A3 + 0xc) = (short)((uint)((short)wVar1 * 0x80) >> 0x10);
  wVar1 = angle_sin(angle);
  *(short *)(unaff_A3 + 0xe) = (short)((uint)((short)wVar1 * 0x80) >> 0x10);
  if ((DAT_ffffdb40 & 2) != 0) {
    *(short *)(unaff_A3 + 4) = *(short *)(unaff_A3 + 4) + 0x10;
    return;
  }
  *(short *)(unaff_A3 + 4) = *(short *)(unaff_A3 + 4) + 8;
  return;
}

void FUN_00022d4e(void)

{
  if (DAT_ffffdb40 < '\0') {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00022d5a(void)

{
  short sVar1;
  short sVar2;
  short sVar3;
  int iVar4;
  int extraout_A0;
  int unaff_A4;

  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_pos_y + unaff_A4) + -1;
  if (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
      (ushort)(DAT_ffffce0a - 0x30U)) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
    DAT_ffffdb44 = 0;
    DAT_ffffdb45 = 0;
    iVar4 = unaff_A4 + 4;
    sVar2 = 7;
    do {
      (&comp_state_a)[iVar4] = (&comp_state_a)[iVar4] | 0x80;
      iVar4 = iVar4 + 4;
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
  }
  FUN_000230e4();
  FUN_0002339c();
  (*(code *)((int)&WORD_000230fc +
             (int)*(short *)((int)&WORD_000230fc +
                             (int)(short)(ushort)(byte)(DAT_ffffdb86 *
                                                        '\x02'))))();
  iVar4 = (int)DAT_ffffdb82;
  sVar2 = sRamffffdb88 + 0x18;
  sVar1 = *(short *)((int)&comp_pos_y + unaff_A4) + sRamffffdb8a + -0x1c;
  sVar3 = sVar2 + sRamffffdb8c;
  if ((DAT_ffffdb80._0_1_ & 1) != 0) {
    sVar3 = -sVar3;
  }
  *(short *)((int)&comp_pos_x + iVar4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + sVar3;
  *(short *)((int)&comp_pos_y + iVar4) = sVar1 + _DAT_ffffdb8e;
  iVar4 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar4);
  sVar3 = sVar2 + (sRamffffdb8c >> 1);
  if ((DAT_ffffdb80._0_1_ & 1) != 0) {
    sVar3 = -sVar3;
  }
  *(short *)((int)&comp_pos_x + iVar4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + sVar3;
  *(short *)((int)&comp_pos_y + iVar4) = sVar1 + (_DAT_ffffdb8e >> 1);
  iVar4 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar4);
  if ((DAT_ffffdb80._0_1_ & 1) != 0) {
    sVar2 = -sVar2;
  }
  *(short *)((int)&comp_pos_x + iVar4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + sVar2;
  *(short *)((int)&comp_pos_y + iVar4) = sVar1;
  iVar4 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar4);
  sVar2 = (sRamffffdb88 >> 1) + 0x18;
  if ((DAT_ffffdb80._0_1_ & 1) != 0) {
    sVar2 = -sVar2;
  }
  *(short *)((int)&comp_pos_x + iVar4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + sVar2;
  *(short *)((int)&comp_pos_y + iVar4) =
      *(short *)((int)&comp_pos_y + unaff_A4) + (sRamffffdb8a >> 1) + -0x1c;
  if ((DAT_ffffdb80._0_1_ & 2) != 0) {
    FUN_0002307a();
    iVar4 = (int)DAT_ffffdb82;
    *(undefined2 *)((int)&comp_pos_x + extraout_A0) =
        *(undefined2 *)((int)&comp_pos_x + iVar4);
    *(undefined2 *)((int)&comp_pos_y + extraout_A0) =
        *(undefined2 *)((int)&comp_pos_y + iVar4);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00022da4(void)

{
  byte bVar1;
  word wVar2;
  ushort uVar3;
  int unaff_A4;

  bVar1 = DAT_ffffdb44 & 0x80;
  DAT_ffffdb44 = DAT_ffffdb44 | 0x80;
  if (bVar1 == 0) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    DAT_ffffdb64 = 0xffc0;
    DAT_ffffdb84 = 0xffc0;
    DAT_ffffdb66._0_1_ = 1;
    DAT_ffffdb86 = 1;
    uVar3 = 0;
    if ((DAT_ffffdb40 & 2) == 0) {
      wVar2 = rand();
      uVar3 = wVar2 & 0x18;
      if (uVar3 == 0) {
        uVar3 = 0x10;
      }
    }
    _DAT_ffffdb46 = uVar3 * 0x20 + 0xc0;
  }
  FUN_00022e00();
  FUN_000230da();
  if (DAT_ffffdb45 != '\0') {
    DAT_ffffdb45 = '\0';
    DAT_ffffdb44 = 0;
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
  }
  return;
}

void FUN_00022e00(void)

{
  short *psVar1;
  short sVar2;
  ulong unaff_A4;

  sVar2 = 8;
  if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    sVar2 = -8;
  }
  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  *psVar1 = sVar2 + *psVar1;
  FUN_00002590();
  player_update_pos_x(unaff_A4);
  if (*(ushort *)((int)&comp_pos_x + unaff_A4) <
      (ushort)(DAT_ffffce08 - 0x30U)) {
    if ((ushort)(DAT_ffffce04 + 0x30U) <
        *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      return;
    }
    *(ushort *)((int)&comp_pos_x + unaff_A4) = DAT_ffffce04 + 0x30U;
  } else {
    *(ushort *)((int)&comp_pos_x + unaff_A4) = DAT_ffffce08 - 0x30U;
  }
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  return;
}

void FUN_00022e4a(void)

{
  byte bVar1;
  undefined2 *puVar2;
  undefined2 *puVar3;
  int unaff_A4;

  bVar1 = DAT_ffffdb44 & 0x80;
  DAT_ffffdb44 = DAT_ffffdb44 | 0x80;
  if (bVar1 == 0) {
    puVar3 = &DAT_ffffdb60;
    puVar2 = &DAT_ffffdb80;
    if ((short)(comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4)) <
        0) {
      puVar2 = &DAT_ffffdb60;
      puVar3 = &DAT_ffffdb80;
    }
    *(undefined1 *)(puVar3 + 3) = 2;
    *(undefined1 *)(puVar2 + 3) = 0;
  }
  FUN_000230da();
  if (DAT_ffffdb45 != '\0') {
    DAT_ffffdb45 = '\0';
    DAT_ffffdb44 = 0;
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
  }
  return;
}

void FUN_00022e76(void)

{
  byte bVar1;

  bVar1 = DAT_ffffdb44 & 0x80;
  DAT_ffffdb44 = DAT_ffffdb44 | 0x80;
  if (bVar1 == 0) {
    DAT_ffffdb66._0_1_ = 3;
    DAT_ffffdb86 = 3;
  }
  FUN_000230da();
  if (DAT_ffffdb45 != '\0') {
    DAT_ffffdb45 = '\0';
    DAT_ffffdb44 = 0;
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
  }
  return;
}

void FUN_00022e90(void)

{
  byte bVar1;
  undefined2 *puVar2;
  undefined2 *puVar3;
  int unaff_A4;

  bVar1 = DAT_ffffdb44 & 0x80;
  DAT_ffffdb44 = DAT_ffffdb44 | 0x80;
  if (bVar1 == 0) {
    puVar3 = &DAT_ffffdb60;
    puVar2 = &DAT_ffffdb80;
    if ((short)(comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4)) <
        0) {
      puVar2 = &DAT_ffffdb60;
      puVar3 = &DAT_ffffdb80;
    }
    *(undefined1 *)(puVar3 + 3) = 4;
    *(undefined1 *)(puVar2 + 3) = 0;
  }
  FUN_000230da();
  if (DAT_ffffdb45 != '\0') {
    DAT_ffffdb45 = '\0';
    DAT_ffffdb44 = 0;
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
  }
  return;
}

void FUN_00022ebe(void)

{
  short sVar1;
  char cVar2;
  ushort uVar3;
  byte state_1_b;
  int unaff_A4;
  anim_item_t *unaff_A5;

  DAT_ffffdb41 = 0;
  cVar2 = *(char *)((int)&comp_state + unaff_A4);
  if (-1 < cVar2) {
    DAT_ffffdb41 = 0;
    *(byte *)((int)&comp_state + unaff_A4) =
        *(byte *)((int)&comp_state + unaff_A4) | 0x80;
  }
  sVar1 = *(short *)((int)&WORD_00022c8a +
                     (int)(short)(ushort)(byte)(cVar2 * '\x02'));
  (*(code *)((int)&WORD_00022c8a +
             (int)*(short *)((int)&WORD_00022c8a +
                             (int)(short)(ushort)DAT_ffffdb41 + (int)sVar1) +
             (int)sVar1))();
  if ((DAT_ffffdb40 & 1) == 0) {
    state_1_b = 0x1a;
    uVar3 =
        (comp_pos_x.fixed.i + 0x20) - *(short *)((int)&comp_pos_x + unaff_A4);
    if ((-1 < (short)uVar3) && (state_1_b = 0x1c, 0x3f < uVar3)) {
      state_1_b = 0x1e;
    }
    if (state_1_b != (&DAT_ffffa664)[unaff_A4]) {
      ecs_anim_unk_2(unaff_A4 + 0x2c, unaff_A5, state_1_b);
    }
    *(undefined2 *)(&DAT_ffffa14e + unaff_A4) =
        *(undefined2 *)((int)&comp_pos_x + unaff_A4);
    *(undefined2 *)(&DAT_ffffa252 + unaff_A4) =
        *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  }
  return;
}

void FUN_00022f86(void)

{
  angle_t angle;
  short unaff_D3w;
  word wVar1;
  int unaff_A3;

  FUN_000026e4();
  *(short *)(unaff_A3 + 8) = (short)((uint)(unaff_D3w * 0x30) >> 0x10) + 8;
  wVar1 = angle_sin((angle_t) * (undefined2 *)(unaff_A3 + 4));
  *(short *)(unaff_A3 + 10) =
      (short)((uint)((short)wVar1 * 0x30) >> 0x10) + 0x10;
  FUN_000026e4();
  *(short *)(unaff_A3 + 0xc) = (short)((uint)((short)wVar1 * 0x80) >> 0x10);
  wVar1 = angle_sin(angle);
  *(short *)(unaff_A3 + 0xe) = (short)((uint)((short)wVar1 * 0x80) >> 0x10);
  if ((DAT_ffffdb40 & 2) != 0) {
    *(short *)(unaff_A3 + 4) = *(short *)(unaff_A3 + 4) + 0x10;
    return;
  }
  *(short *)(unaff_A3 + 4) = *(short *)(unaff_A3 + 4) + 8;
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_00023016(void)

{
  short sVar1;
  undefined2 uVar2;
  char cVar3;
  char *pcVar4;
  int unaff_A3;
  undefined2 unaff_A4w;
  anim_item_t *unaff_A5;
  undefined4 *puVar5;

  if ((*(char *)(unaff_A3 + 0x14) != '\0') &&
      (cVar3 = *(char *)(unaff_A3 + 0x14) + -1,
       *(char *)(unaff_A3 + 0x14) = cVar3,
       cVar3 == '\0')) {
    pcVar4 = *(char **)(unaff_A3 + 0x10);
    while (true) {
      cVar3 = *pcVar4;
      *(char *)(unaff_A3 + 0x14) = cVar3;
      if (cVar3 != '\0')
        break;
      uVar2 = *(undefined2 *)((int)&override::jmp_00023034::case_0 +
                              (int)(short)(ushort)(byte)pcVar4[1]);
      // WARNING: Switch is manually overridden
      switch (uVar2) {
      case 0:
        // WARNING: Bad instruction - Truncating control flow here
        halt_baddata();
      case 2:
        *(char **)((int)register0x0000003c + -4) = pcVar4 + 2;
        *(undefined2 *)((int)register0x0000003c + -8) = unaff_A4w;
        *(short *)((int)register0x0000003c + -0xc) = (short)unaff_A3;
        sVar1 = *(short *)(unaff_A3 + 2);
        *(undefined4 *)((int)register0x0000003c + -0x10) = 0x23072;
        ecs_anim_unk_2((int)sVar1, unaff_A5, (byte)uVar2);
        unaff_A3 = (int)*(short *)((int)register0x0000003c + -0xc);
        unaff_A4w = *(undefined2 *)((int)register0x0000003c + -10);
        puVar5 = (undefined4 *)((int)register0x0000003c + -8);
        register0x0000003c = (BADSPACEBASE *)((int)register0x0000003c + -4);
        pcVar4 = (char *)*puVar5;
      }
    }
    *(short *)(unaff_A3 + 8) = (short)pcVar4[1];
    *(short *)(unaff_A3 + 10) = (short)pcVar4[2];
    *(short *)(unaff_A3 + 0xc) = (short)pcVar4[3];
    *(short *)(unaff_A3 + 0xe) = (short)pcVar4[4];
    *(char **)(unaff_A3 + 0x10) = pcVar4 + 5;
  }
  return;
}

void FUN_00023062(void)

{
  char cVar1;
  byte *in_A0;
  int unaff_A3;
  int iVar2;
  undefined2 unaff_A4w;
  anim_item_t *unaff_A5;
  char *pcStack_8;

  pcStack_8 = (char *)CONCAT22(unaff_A4w, pcStack_8._2_2_);
  ecs_anim_unk_2((int)*(short *)(unaff_A3 + 2), unaff_A5, *in_A0);
  iVar2 = (int)(short)unaff_A3;
  cVar1 = *pcStack_8;
  *(char *)(iVar2 + 0x14) = cVar1;
  if (cVar1 == '\0') {
    // WARNING: Could not recover jumptable at 0x00023034. Too many branches
    // WARNING: Treating indirect jump as call
    (*(code *)((int)&FUN_00023016::override::jmp_00023034::case_0 +
               (int)*(
                   short *)((int)&FUN_00023016::override::jmp_00023034::case_0 +
                            (int)(short)(ushort)(byte)pcStack_8[1])))();
    return;
  }
  *(short *)(iVar2 + 8) = (short)pcStack_8[1];
  *(short *)(iVar2 + 10) = (short)pcStack_8[2];
  *(short *)(iVar2 + 0xc) = (short)pcStack_8[3];
  *(short *)(iVar2 + 0xe) = (short)pcStack_8[4];
  *(char **)(iVar2 + 0x10) = pcStack_8 + 5;
  return;
}

void FUN_0002307a(void)

{
  return;
}

void FUN_000230ca(void)

{
  int extraout_A0;
  byte *unaff_A3;

  *unaff_A3 = *unaff_A3 & 0xfd;
  FUN_0002307a();
  (&comp_has_func_maybe)[extraout_A0] =
      (&comp_has_func_maybe)[extraout_A0] & 0xbf;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000230da(void)

{
  short sVar1;
  short sVar2;
  short sVar3;
  int iVar4;
  int extraout_A0;
  int unaff_A4;

  FUN_000230e4();
  FUN_0002339c();
  (*(code *)((int)&WORD_000230fc +
             (int)*(short *)((int)&WORD_000230fc +
                             (int)(short)(ushort)(byte)(DAT_ffffdb86 *
                                                        '\x02'))))();
  iVar4 = (int)DAT_ffffdb82;
  sVar2 = sRamffffdb88 + 0x18;
  sVar1 = *(short *)((int)&comp_pos_y + unaff_A4) + sRamffffdb8a + -0x1c;
  sVar3 = sVar2 + sRamffffdb8c;
  if ((DAT_ffffdb80._0_1_ & 1) != 0) {
    sVar3 = -sVar3;
  }
  *(short *)((int)&comp_pos_x + iVar4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + sVar3;
  *(short *)((int)&comp_pos_y + iVar4) = sVar1 + _DAT_ffffdb8e;
  iVar4 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar4);
  sVar3 = sVar2 + (sRamffffdb8c >> 1);
  if ((DAT_ffffdb80._0_1_ & 1) != 0) {
    sVar3 = -sVar3;
  }
  *(short *)((int)&comp_pos_x + iVar4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + sVar3;
  *(short *)((int)&comp_pos_y + iVar4) = sVar1 + (_DAT_ffffdb8e >> 1);
  iVar4 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar4);
  if ((DAT_ffffdb80._0_1_ & 1) != 0) {
    sVar2 = -sVar2;
  }
  *(short *)((int)&comp_pos_x + iVar4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + sVar2;
  *(short *)((int)&comp_pos_y + iVar4) = sVar1;
  iVar4 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar4);
  sVar2 = (sRamffffdb88 >> 1) + 0x18;
  if ((DAT_ffffdb80._0_1_ & 1) != 0) {
    sVar2 = -sVar2;
  }
  *(short *)((int)&comp_pos_x + iVar4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + sVar2;
  *(short *)((int)&comp_pos_y + iVar4) =
      *(short *)((int)&comp_pos_y + unaff_A4) + (sRamffffdb8a >> 1) + -0x1c;
  if ((DAT_ffffdb80._0_1_ & 2) != 0) {
    FUN_0002307a();
    iVar4 = (int)DAT_ffffdb82;
    *(undefined2 *)((int)&comp_pos_x + extraout_A0) =
        *(undefined2 *)((int)&comp_pos_x + iVar4);
    *(undefined2 *)((int)&comp_pos_y + extraout_A0) =
        *(undefined2 *)((int)&comp_pos_y + iVar4);
  }
  return;
}

void FUN_000230e4(void)

{
  short sVar1;
  short sVar2;
  short sVar3;
  int iVar4;
  int extraout_A0;
  byte *unaff_A3;
  int unaff_A4;

  FUN_0002339c();
  (*(code *)((int)&WORD_000230fc +
             (int)*(
                 short *)((int)&WORD_000230fc +
                          (int)(short)(ushort)(byte)(unaff_A3[6] * '\x02'))))();
  iVar4 = (int)*(short *)(unaff_A3 + 2);
  sVar2 = *(short *)(unaff_A3 + 8) + 0x18;
  sVar1 = *(short *)((int)&comp_pos_y + unaff_A4) + *(short *)(unaff_A3 + 10) +
          -0x1c;
  sVar3 = sVar2 + *(short *)(unaff_A3 + 0xc);
  if ((*unaff_A3 & 1) != 0) {
    sVar3 = -sVar3;
  }
  *(short *)((int)&comp_pos_x + iVar4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + sVar3;
  *(short *)((int)&comp_pos_y + iVar4) = sVar1 + *(short *)(unaff_A3 + 0xe);
  iVar4 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar4);
  sVar3 = sVar2 + (*(short *)(unaff_A3 + 0xc) >> 1);
  if ((*unaff_A3 & 1) != 0) {
    sVar3 = -sVar3;
  }
  *(short *)((int)&comp_pos_x + iVar4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + sVar3;
  *(short *)((int)&comp_pos_y + iVar4) =
      sVar1 + (*(short *)(unaff_A3 + 0xe) >> 1);
  iVar4 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar4);
  if ((*unaff_A3 & 1) != 0) {
    sVar2 = -sVar2;
  }
  *(short *)((int)&comp_pos_x + iVar4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + sVar2;
  *(short *)((int)&comp_pos_y + iVar4) = sVar1;
  iVar4 = (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar4);
  sVar2 = (*(short *)(unaff_A3 + 8) >> 1) + 0x18;
  if ((*unaff_A3 & 1) != 0) {
    sVar2 = -sVar2;
  }
  *(short *)((int)&comp_pos_x + iVar4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + sVar2;
  *(short *)((int)&comp_pos_y + iVar4) =
      *(short *)((int)&comp_pos_y + unaff_A4) +
      (*(short *)(unaff_A3 + 10) >> 1) + -0x1c;
  if ((*unaff_A3 & 2) != 0) {
    FUN_0002307a();
    sVar2 = *(short *)(unaff_A3 + 2);
    *(undefined2 *)((int)&comp_pos_x + extraout_A0) =
        *(undefined2 *)((int)&comp_pos_x + (int)sVar2);
    *(undefined2 *)((int)&comp_pos_y + extraout_A0) =
        *(undefined2 *)((int)&comp_pos_y + (int)sVar2);
  }
  return;
}

void FUN_00023106(void)

{
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023108(void)

{
  int unaff_A3;

  FUN_00022f86();
  if (_DAT_ffffdb46 <= *(short *)(unaff_A3 + 4)) {
    DAT_ffffdb45 = 0xff;
  }
  return;
}

uint FUN_0002311c(void)

{
  byte bVar2;
  byte bVar3;
  uint extraout_D0;
  uint in_D0;
  uint uVar1;
  short sVar4;
  undefined *puVar5;
  short extraout_A0w;
  byte *unaff_A3;
  entity_id_t self;
  anim_item_t *unaff_A5;

  bVar2 = unaff_A3[6];
  unaff_A3[6] = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    unaff_A3[7] = 0;
    puVar5 = &UNK_000231ca;
  LAB_0002300a:
    *(undefined **)(unaff_A3 + 0x10) = puVar5;
    unaff_A3[0x14] = 1;
    return in_D0;
  }
  if (unaff_A3[7] == 0) {
    uVar1 = FUN_00023016();
    if (unaff_A3[0x14] == 0) {
      unaff_A3[7] = unaff_A3[7] + 1;
      unaff_A3[0x14] = 0x40;
      sVar4 = comp_pos_x.fixed.i -
              *(short *)((int)&comp_pos_x + (int)*(short *)(unaff_A3 + 2));
      if ((*unaff_A3 & 1) != 0) {
        sVar4 = -sVar4;
      }
      bVar2 = 0;
      if ((((-0x30 < sVar4) && (bVar2 = 1, -0x20 < sVar4)) &&
           (bVar2 = 2, -0x10 < sVar4)) &&
          (((bVar2 = 3, -1 < sVar4 && (bVar2 = 4, 0x10 < sVar4)) &&
            ((bVar2 = 5, 0x20 < sVar4 && (bVar2 = 6, 0x30 < sVar4)))))) {
        bVar2 = 7;
      }
      unaff_A3[0x15] = bVar2;
      *unaff_A3 = *unaff_A3 | 2;
      bVar2 = FUN_0002307a();
      self = (entity_id_t)extraout_A0w;
      if ((*unaff_A3 & 1) != 0) {
        bVar2 = 7 - bVar2;
      }
      *(undefined2 *)((int)&comp_unk_3 + self) = 0x16;
      (&comp_state_a)[self] = 0x80;
      bVar3 = bVar2 - 4;
      if (bVar2 < 4) {
        bVar3 = ~bVar3;
        (&comp_state_a)[self] = 0x88;
      }
      (&comp_collision_related)[self] = bVar3;
      ecs_anim_unk_2(self, unaff_A5, (bVar3 + 8) * '\x02');
      return extraout_D0;
    }
  } else {
    bVar2 = unaff_A3[7] - 1;
    uVar1 = (uint)bVar2;
    if (bVar2 == 0) {
      bVar2 = unaff_A3[0x14] - 1;
      unaff_A3[0x14] = bVar2;
      if (bVar2 == 0) {
        unaff_A3[7] = unaff_A3[7] + 1;
        in_D0 = FUN_000230ca();
        puVar5 = &UNK_000231d9;
        goto LAB_0002300a;
      }
    } else {
      uVar1 = FUN_00023016();
      if (unaff_A3[0x14] == 0) {
        DAT_ffffdb45 = 0xff;
      }
    }
  }
  return uVar1;
}

char FUN_000231e8(void)

{
  byte bVar1;
  byte bVar2;
  char extraout_D0b;
  char in_D0b;
  char cVar3;
  undefined *puVar4;
  short extraout_A0w;
  byte *unaff_A3;
  entity_id_t self;
  anim_item_t *unaff_A5;

  bVar1 = unaff_A3[6];
  unaff_A3[6] = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    unaff_A3[7] = 0;
    puVar4 = &UNK_000231ca;
  } else {
    if (unaff_A3[7] == 0) {
      cVar3 = FUN_00023016();
      if (unaff_A3[0x14] != 0) {
        return cVar3;
      }
      unaff_A3[7] = unaff_A3[7] + 1;
      unaff_A3[0x14] = 1;
      *(undefined **)(unaff_A3 + 0x10) = &UNK_00023260;
    } else {
      cVar3 = unaff_A3[7] - 1;
      if (cVar3 != '\0') {
        cVar3 = FUN_00023016();
        if (unaff_A3[0x14] != 0) {
          return cVar3;
        }
        DAT_ffffdb45 = 0xff;
        return cVar3;
      }
    }
    bVar1 = unaff_A3[0x14] - 1;
    unaff_A3[0x14] = bVar1;
    if (bVar1 != 0) {
      return cVar3;
    }
    if (-1 < **(char **)(unaff_A3 + 0x10)) {
      *(char **)(unaff_A3 + 0x10) = *(char **)(unaff_A3 + 0x10) + 1;
      unaff_A3[0x14] = 4;
      *unaff_A3 = *unaff_A3 | 2;
      bVar1 = FUN_0002307a();
      self = (entity_id_t)extraout_A0w;
      if ((*unaff_A3 & 1) != 0) {
        bVar1 = 7 - bVar1;
      }
      *(undefined2 *)((int)&comp_unk_3 + self) = 0x16;
      (&comp_state_a)[self] = 0x80;
      bVar2 = bVar1 - 4;
      if (bVar1 < 4) {
        bVar2 = ~bVar2;
        (&comp_state_a)[self] = 0x88;
      }
      (&comp_collision_related)[self] = bVar2;
      ecs_anim_unk_2(self, unaff_A5, (bVar2 + 8) * '\x02');
      return extraout_D0b;
    }
    unaff_A3[7] = unaff_A3[7] + 1;
    in_D0b = FUN_000230ca();
    puVar4 = &UNK_000231d9;
  }
  *(undefined **)(unaff_A3 + 0x10) = puVar4;
  unaff_A3[0x14] = 1;
  return in_D0b;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023270(void)

{
  byte bVar1;
  short sVar2;
  undefined *puVar3;
  byte *unaff_A3;
  int unaff_A4;

  bVar1 = unaff_A3[6];
  unaff_A3[6] = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    unaff_A3[7] = 0;
    puVar3 = &UNK_00023382;
  LAB_0002300a:
    *(undefined **)(unaff_A3 + 0x10) = puVar3;
    unaff_A3[0x14] = 1;
    return;
  }
  bVar1 = unaff_A3[7];
  if (bVar1 == 0) {
    FUN_00023016();
    if (unaff_A3[0x14] == 0) {
      unaff_A3[7] = unaff_A3[7] + 1;
      sVar2 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
      if ((*unaff_A3 & 1) != 0) {
        sVar2 = -sVar2;
      }
      *(short *)(unaff_A3 + 0x18) = sVar2 + -0x18;
      *(short *)(unaff_A3 + 0x1a) =
          (DAT_ffffce0a + 0x10) - *(short *)((int)&comp_pos_y + unaff_A4);
      unaff_A3[0x16] = 0;
      unaff_A3[0x17] = 0;
      *unaff_A3 = *unaff_A3 | 4;
      return;
    }
  } else if (bVar1 == 1) {
    *(short *)(unaff_A3 + 0x16) = *(short *)(unaff_A3 + 0x16) + 8;
    FUN_00023334();
    if (0x3f < *(ushort *)(unaff_A3 + 0x16)) {
      unaff_A3[7] = unaff_A3[7] + 1;
      unaff_A3[0x14] = 0x14;
      audio_play(SOUND_ID_TOW_STOP);
      DAT_ffffd192 = 4;
      _DAT_ffffd196 = 0x14;
      _DAT_ffffd194 = 0;
      return;
    }
  } else if (bVar1 == 2) {
    bVar1 = unaff_A3[0x14] - 1;
    unaff_A3[0x14] = bVar1;
    if (bVar1 == 0) {
      unaff_A3[7] = unaff_A3[7] + 1;
      return;
    }
  } else if (bVar1 == 3) {
    *(short *)(unaff_A3 + 0x16) = *(short *)(unaff_A3 + 0x16) + -4;
    FUN_00023334();
    if (*(short *)(unaff_A3 + 0x16) == 0) {
      unaff_A3[7] = unaff_A3[7] + 1;
      *unaff_A3 = *unaff_A3 & 0xfb;
      puVar3 = &UNK_00023391;
      goto LAB_0002300a;
    }
  } else {
    FUN_00023016();
    if (unaff_A3[0x14] == 0) {
      DAT_ffffdb45 = 0xff;
    }
  }
  return;
}

void FUN_00023334(void)

{
  short sVar1;
  short sVar2;
  int unaff_A3;

  sVar1 = (short)((int)(short)(*(short *)(unaff_A3 + 0x18) + -0xc) *
                      (int)*(short *)(unaff_A3 + 0x16) >>
                  6) +
          0xc;
  sVar2 = (sVar1 >> 1) - (sVar1 >> 3);
  *(short *)(unaff_A3 + 8) = sVar2;
  *(short *)(unaff_A3 + 0xc) = sVar1 - sVar2;
  sVar1 = (short)((int)(short)(*(short *)(unaff_A3 + 0x1a) + 0x30) *
                      (int)*(short *)(unaff_A3 + 0x16) >>
                  6) +
          -0x30;
  sVar2 = (sVar1 >> 1) - (sVar1 >> 3);
  *(short *)(unaff_A3 + 10) = sVar2;
  *(short *)(unaff_A3 + 0xe) = sVar1 - sVar2;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

uint FUN_0002339c(void)

{
  byte bVar1;
  byte bVar2;
  byte bVar6;
  uint uVar3;
  short sVar4;
  ushort uVar5;
  uint extraout_D0;
  ushort uVar7;
  int extraout_A0;
  int iVar8;
  byte *pbVar9;
  byte *pbVar10;
  byte *pbVar11;
  int unaff_A3;
  entity_id_t eVar12;
  bool bVar13;
  bool bVar14;

  bVar6 = *(char *)((int)&comp_state + (int)DAT_ffffdb42) * '\x02' - 2;
  if (bVar6 != 0) {
    return (uint)bVar6;
  }
  _DAT_ffffdb1a = FUN_000189d0;
  if ((&comp_unk_11)[DAT_ffffdb42] != '\0') {
    _DAT_ffffdb1a = FUN_000189fe;
  }
  sVar4 = (short)unaff_A3;
  bVar13 = sVar4 == 0;
  bVar14 = false;
  eVar12 = (entity_id_t) * (short *)(unaff_A3 + 2);
  FUN_00000ed6(eVar12, ENTITY_ID_ASHA);
  if (bVar14 || bVar13) {
    bVar6 = 1;
    if ((*(byte *)(int)sVar4 & 4) != 0) {
      bVar6 = 2;
    }
    FUN_00002124(eVar12, bVar6);
  }
  uVar3 = (*_DAT_ffffdb1a)();
  if (((&comp_func_offset[0].unk4)[eVar12] & 1) != 0) {
    audio_play(SOUND_ID_DAMAGE_2);
    bVar6 = DAT_ffffde0e;
    if (((&comp_func_offset[0].unk4)[eVar12] & 4) != 0) {
      bVar6 = DAT_ffffde0f;
    }
    uVar3 = (uint)bVar6;
    iVar8 = (int)DAT_ffffdb42;
    if ((&comp_unk_11)[iVar8] == '\0') {
      bVar1 = (&comp_collected_item_id_maybe)[iVar8];
      bVar2 = bVar1 - bVar6;
      (&comp_collected_item_id_maybe)[iVar8] = bVar2;
      if (bVar1 < bVar6 || bVar2 == 0) {
        *(undefined1 *)((int)&comp_state + iVar8) = 2;
        return uVar3;
      }
      if ((&comp_collected_item_id_maybe)[iVar8] < 0x28) {
        DAT_ffffdb40 = DAT_ffffdb40 | 2;
      }
      (&comp_unk_11)[iVar8] = 0x3c;
    }
  }
  if ((*(byte *)(int)sVar4 & 2) != 0) {
    eVar12 = (entity_id_t)DAT_ffffdb42;
    FUN_0002307a();
    pbVar11 =
        &UNK_000234b4 +
        *(short
              *)(&UNK_000234b4 +
                 (short)((ushort)(byte)(&comp_collision_related)[extraout_A0] *
                         2));
    do {
      bVar6 = *pbVar11;
      if (bVar6 == 0x80) {
        return (uint)bVar6;
      }
      sVar4 = (short)(char)bVar6;
      if (((&comp_state_a)[extraout_A0] & ENTITY_STATE_A_08) != 0) {
        sVar4 = -sVar4;
      }
      uVar5 = (*(short *)((int)&comp_pos_x + extraout_A0) + sVar4) -
              comp_pos_x._0_2_;
      if ((short)uVar5 < 0) {
        uVar5 = -uVar5;
      }
      pbVar9 = pbVar11 + 2;
      uVar7 = (*(short *)((int)&comp_pos_y + extraout_A0) +
               (short)(char)pbVar11[1]) -
              comp_pos_y._0_2_;
      if ((short)uVar7 < 0) {
        uVar7 = -uVar7;
      }
      pbVar10 = pbVar11 + 3;
      pbVar11 = pbVar11 + 4;
    } while (
        ((ushort)((ushort)comp_collision[0].set_by_anim_command_fb +
                  (ushort)*pbVar9) < uVar5) ||
        ((ushort)((ushort)comp_collision[0].unk2 + (ushort)*pbVar10) < uVar7));
    FUN_00002124(eVar12, 8);
    uVar3 = extraout_D0;
  }
  return uVar3;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002350c(void)

{
  byte bVar1;
  short sVar2;

  DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
  DAT_ffffdb40 = DAT_ffffdb40 | 1;
  if ((DAT_ffffdb60._0_1_ & 2) != 0) {
    FUN_000230ca();
  }
  if ((DAT_ffffdb80._0_1_ & 2) != 0) {
    FUN_000230ca();
  }
  _DAT_ffffdb3e = 0xb4;
  audio_play_sound_asha_dies();
  while (true) {
    IO_Z80BUS = 0x100;
    do {
      bVar1 = IO_Z80BUS._0_1_;
    } while ((bVar1 & 1) != 0);
    if (z80_ram_something_1 == '\0')
      break;
    IO_Z80BUS = 0;
    sVar2 = 0x1f;
    do {
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
  }
  (&z80_ram)[(short)(((byte)(z80_ram_something_3 + z80_ram_something_2) & 0xf) +
                     0x1c30)] = 0x4c;
  z80_ram_something_3 = z80_ram_something_3 + '\x01';
  IO_Z80BUS = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023542(void)

{
  ushort uVar1;
  short sVar2;
  char duration;
  char extraout_D1b;
  vdp_color_t *pvVar3;
  vdp_color_t *pvVar4;

  _DAT_ffffdb3e = _DAT_ffffdb3e + -1;
  if (_DAT_ffffdb3e == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    _DAT_ffffdb48 = 0x3c;
    FUN_0001fd5e();
    duration = extraout_D1b;
  } else {
    for (uVar1 = (0xb4 - _DAT_ffffdb3e) * 2; 0x53 < uVar1;
         uVar1 = uVar1 - 0x54) {
    }
    sVar2 = 0xf;
    pvVar3 = palettes_2;
    do {
      *pvVar3 = *(vdp_color_t *)(&UNK_0001fdd8 + (short)uVar1);
      uVar1 = uVar1 + 2;
      if (0x53 < uVar1) {
        uVar1 = 0;
      }
      sVar2 = sVar2 + -1;
      pvVar3 = pvVar3 + 1;
    } while (sVar2 != -1);
    duration = -1;
  }
  sVar2 = 7;
  pvVar3 = palettes_2;
  pvVar4 = palettes[1];
  do {
    *(undefined4 *)pvVar4 = *(undefined4 *)pvVar3;
    sVar2 = sVar2 + -1;
    pvVar3 = pvVar3 + 2;
    pvVar4 = pvVar4 + 2;
  } while (sVar2 != -1);
  palette_set_fade(PALETTE_ID_FLAG_1,
                   PALETTE_FADE_1,
                   duration,
                   (palette_color_iter_t)0xffffffff);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002355c(void)

{
  _DAT_ffffdb48 = _DAT_ffffdb48 + -1;
  if (_DAT_ffffdb48 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    _DAT_ffffdb48 = 1;
    _DAT_ffffdb4a = 0;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023572(void)

{
  short sVar1;
  short sVar2;
  component_state_b_t cVar3;
  int16_t pos_x;
  undefined1 *puVar4;
  entity_state_a_t eVar5;
  int unaff_A4;
  int iVar6;
  undefined1 *puVar7;

  _DAT_ffffdb48 = _DAT_ffffdb48 - 1;
  if (_DAT_ffffdb48 == 0) {
    if (7 < _DAT_ffffdb4a) {
      (&DAT_ffff9f46)[unaff_A4] = 0;
      puVar4 = (undefined1 *)register0x0000003c;
      do {
        puVar7 = puVar4;
        sVar1 = *(short *)((int)&int16_vec2_t_0002361a.x +
                           (int)(short)(_DAT_ffffdb48 << 2));
        sVar2 = *(short *)((int)&comp_pos_x + (int)DAT_ffffdb42);
        *(short *)(puVar7 + -4) =
            *(short *)((int)&comp_pos_y + (int)DAT_ffffdb42) +
            *(short *)((int)&int16_vec2_t_0002361a.y +
                       (int)(short)(_DAT_ffffdb48 << 2));
        *(short *)(puVar7 + -8) = sVar2 + sVar1;
        *(undefined4 *)(puVar7 + -0xc) = 0x235d6;
        FUN_000253a0();
        pos_x = *(int16_t *)(puVar7 + -8);
        *(undefined4 *)(puVar7 + -8) = 0x235e2;
        ecs_collect_or_spawn_item_maybe(pos_x, *(int16_t *)(puVar7 + -6), 0x32);
        _DAT_ffffdb48 = _DAT_ffffdb48 + 1;
        puVar4 = puVar7 + -4;
      } while (_DAT_ffffdb48 < 4);
      iVar6 = (int)DAT_ffffdb42;
      *(undefined4 *)(puVar7 + -8) = 0x235f8;
      FUN_00015e86();
      script_ctx_bf_0e_arg = 4;
      *(short *)((int)&comp_pos_y + iVar6) =
          *(short *)((int)&comp_pos_y + iVar6) + -0x30;
      *(undefined4 *)(puVar7 + -8) = 0x2360a;
      FUN_00025398();
      *(undefined4 *)(puVar7 + -8) = 0x23614;
      FUN_00024d78();
      cVar3 = (&comp_has_func_maybe)[iVar6];
      (&comp_has_func_maybe)[iVar6] = cVar3 | 0x40;
      if ((cVar3 & 0x40) == 0) {
        *(undefined4 *)(puVar7 + -8) = 0x24df6;
        FUN_000019ae();
        *(undefined2 *)((int)&comp_anim_speed + iVar6) = 0x100;
        eVar5 = 0;
        if (DAT_ffffcc28 != '\0') {
          eVar5 = 0x80;
        }
        (&comp_state_a)[iVar6] = eVar5;
        *(undefined2 *)((int)&comp_unk_3 + iVar6) = 4;
        *(undefined1 *)((int)&comp_state + iVar6) = 0;
      }
      // WARNING: Could not recover jumptable at 0x00024e1e. Too many branches
      // WARNING: Treating indirect jump as call
      (*(code *)((int)&WORD_00024e22 +
                 (int)*(short *)((int)&WORD_00024e22 +
                                 (int)(short)(ushort)(&comp_func_offset[0]
                                                           .unk3)[iVar6])))();
      return;
    }
    _DAT_ffffdb48 = 4;
    FUN_00025398();
    FUN_00024d78();
    FUN_00024dea();
    _DAT_ffffdb4a = _DAT_ffffdb4a + 1;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002362a(void)

{
  char cVar1;
  int unaff_A4;
  int iVar2;
  short jmp_offset_1;

  FUN_000236c4();
  cVar1 = *(char *)((int)&comp_state + unaff_A4);
  if (-1 < cVar1) {
    DAT_ffffdb41 = 0;
    *(byte *)((int)&comp_state + unaff_A4) =
        *(byte *)((int)&comp_state + unaff_A4) | 0x80;
  }
  jmp_offset_1 = *(short *)((int)&jmp_000236be +
                            (int)(short)(ushort)(byte)(cVar1 * '\x02'));
  (*(code *)((int)&jmp_000236be +
             (int)*(short *)((int)&jmp_000236be +
                             (int)(short)(ushort)DAT_ffffdb41 +
                             (int)jmp_offset_1) +
             (int)jmp_offset_1))();
  iVar2 = (int)DAT_ffffdb42;
  if ((((&comp_has_func_maybe)[iVar2] & 8) == 0) &&
      ((*(byte *)((int)&comp_state + iVar2) & 0x7f) != 0)) {
    *(short *)((int)&comp_pos_x + iVar2) = DAT_ffffdb50;
    *(short *)((int)&comp_pos_y + iVar2) = DAT_ffffdb52;
  }
  _DAT_ffffd17a = 0x1090 - DAT_ffffdb50;
  _DAT_ffffd17c = 0x1110 - DAT_ffffdb52;
  if ((byte)(*(char *)((int)&comp_state + iVar2) * '\x02') < 4) {
    if (((&component_state_b_pepelogoo)[iVar2] & 8) == 0) {
      FUN_000242d4();
    }
    if (((&DAT_ffff9f22)[iVar2] & 8) == 0) {
      FUN_000242d4();
    }
  }
  return;
}

void FUN_000236c4(void)

{
  byte bVar1;
  char extraout_D1b;
  char extraout_D1b_00;
  char extraout_D1b_01;
  int unaff_A4;

  if ((&comp_unk_11)[unaff_A4] == '\0') {
    return;
  }
  bVar1 = (&comp_unk_11)[unaff_A4] - 1;
  (&comp_unk_11)[unaff_A4] = bVar1;
  if ((bVar1 & 1) != 0) {
    if ((bVar1 >> 1 & 1) != 0) {
      FUN_000236fe();
      FUN_00023710();
      palette_copy_from_palettes2(extraout_D1b);
      return;
    }
    FUN_000236fe();
    FUN_00023710();
    palette_copy_from_palettes2(extraout_D1b_00);
    return;
  }
  FUN_0001fd5e();
  palette_copy_from_palettes2(extraout_D1b_01);
  return;
}

void FUN_000236fe(void)

{
  short i;
  vdp_color_t *src;
  vdp_color_t *dst;

  i = 5;
  src = &DAT_ffffdb1e;
  dst = palettes_2;
  do {
    *dst = *src;
    i = i + -1;
    src = src + 1;
    dst = dst + 1;
  } while (i != -1);
  return;
}

void FUN_00023710(void)

{
  undefined2 in_D0w;
  short sVar1;
  undefined2 *in_A1;
  undefined2 *puVar2;

  sVar1 = 8;
  do {
    puVar2 = in_A1 + 1;
    *in_A1 = in_D0w;
    sVar1 = sVar1 + -1;
    in_A1 = puVar2;
  } while (sVar1 != -1);
  *puVar2 = DAT_ffffdb3c;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023744(void)

{
  short sVar1;
  int iVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
  DAT_ffffdb40 = 0;
  DAT_ffffdb42 = (short)unaff_A4;
  (&comp_anim[0].unk4)[unaff_A4] = (&comp_anim[0].unk4)[unaff_A4] | 0x40;
  DAT_ffffdb59 = 0x28;
  (&comp_func_offset[0].unk1)[unaff_A4] = 0x92;
  FUN_0000281e();
  iVar2 = (int)(short)unaff_A4;
  while (sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar2),
         -1 < sVar1) {
    iVar2 = (int)sVar1;
    (&comp_has_func_maybe)[iVar2] = (&comp_has_func_maybe)[iVar2] | 8;
  }
  DAT_ffffdb50 = 0x1090;
  DAT_ffffdb52 = 0x1110;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 8;
  FUN_0000199c();
  _DAT_ffffdb44 = 0x3c;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002379c(void)

{
  int unaff_A4;

  _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
  if (_DAT_ffffdb44 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    audio_play(SOUND_ID_CARPET);
    FUN_000237ca();
    _DAT_ffffdb46 = (short)unaff_A4;
    FUN_000237ca();
    _DAT_ffffdb48 = (short)unaff_A4;
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) = 0x10a8;
    _DAT_ffffdb44 = 10;
  }
  return;
}

void FUN_000237ca(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_00023ca4();
  *(undefined2 *)((int)&comp_pos_x + unaff_A4) = 0x1080;
  *(undefined2 *)((int)&comp_pos_y + unaff_A4) = 0x1028;
  if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
    BYTE_ffffc709 = 0;
  }
  if (unaff_A4 == ENTITY_ID_ASHA) {
    BYTE_ffffc70a = 0;
  }
  (&comp_state_1_a)[unaff_A4] = 0;
  (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
  ecs_anim_unk_1(unaff_A4, unaff_A5);
  (&comp_has_func_maybe)[unaff_A4] =
      (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000237e0(void)

{
  _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
  if (_DAT_ffffdb44 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    FUN_00012eea();
    _DAT_ffffdb44 = 0x32;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000237f8(void)

{
  int unaff_A4;

  _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
  if (_DAT_ffffdb44 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    FUN_00023820();
    _DAT_ffffdb4a = (short)unaff_A4;
    FUN_00023820();
    _DAT_ffffdb4c = (short)unaff_A4;
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) = 0x10f8;
    _DAT_ffffdb44 = 0x3c;
  }
  return;
}

void FUN_00023820(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_00023ca4();
  *(undefined2 *)((int)&comp_pos_x + unaff_A4) = 0x1030;
  *(undefined2 *)((int)&comp_pos_y + unaff_A4) = 0x1038;
  if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
    BYTE_ffffc709 = 0;
  }
  if (unaff_A4 == ENTITY_ID_ASHA) {
    BYTE_ffffc70a = 0;
  }
  (&comp_state_1_a)[unaff_A4] = 0;
  (&comp_anim_c)[unaff_A4] = 0;
  ecs_anim_unk_1(unaff_A4, unaff_A5);
  (&comp_has_func_maybe)[unaff_A4] =
      (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023836(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
  if (_DAT_ffffdb44 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    _DAT_ffffdb44 = 0x3c;
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] & 0xf7;
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x1e;
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) = 0x1090;
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) = 0x1048;
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_JUMPING_OR_UNSHIELDING;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023866(void)

{
  _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
  if (_DAT_ffffdb44 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    DAT_ffffd916 = 0xbe;
    FUN_0001937a();
    _DAT_ffff9814 = 0x7778;
    vdp_palettes_something();
    palette_set_fade(PALETTE_ID_FLAG_3 | PALETTE_ID_FLAG_2,
                     PALETTE_FADE_BLACK_EASE_OUT,
                     '\x02',
                     (palette_color_iter_t)0xffffffff);
    audio_play(SOUND_ID_FE);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000238a2(void)

{
  short *psVar1;
  int iVar2;
  int unaff_A4;
  anim_item_t *unaff_A5;

  if ((palette_fade_done_2 != 0xff) || (palette_fade_done_3 != 0xff)) {
    return;
  }
  DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
  FUN_0000192a((sound_id_word_t)0x9);
  _DAT_ffffdb44 = 0;
  *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x14;
  DAT_ffffdb5a = 0;
  do {
    FUN_000238e8();
    DAT_ffffdb5a = DAT_ffffdb5a + 1;
  } while (DAT_ffffdb5a < 4);
  DAT_ffffcc85 = 0;
  comp_state = COMP_STATE_STAND;
  if ((char)pepelogoo_state_b < '\0') {
    if (script_ctx_bf_0e_arg != '\x02') {
      if ((comp_anim_b != 6) || (comp_anim_c != 0)) {
        comp_anim_b = 6;
        ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
      }
      return;
    }
    if ((comp_anim_b != 6) ||
        (comp_anim_c != ECS_STATE_1_B_TALKING_OR_ENTERING_BACK_DOOR)) {
      comp_anim_b = 6;
      ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0xe);
    }
    comp_state = 0x4a;
    return;
  }
  if (comp_collision[0].collision.y == '\r') {
    if ((comp_anim_b != 0x10) || (comp_anim_c != 0)) {
      comp_anim_b = 0x10;
      ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
    }
    return;
  }
  if ((component_unknown_5 & 4) != 0) {
    iVar2 =
        (int)*(short *)((int)&DAT_ffffd29a + (int)(short)component_unknown_9);
    if (((&comp_func_offset[0].func_offset_from_15ede)[iVar2] == 0x28) ||
        ((&comp_func_offset[0].func_offset_from_15ede)[iVar2] == 0x26)) {
      comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
      if ((comp_anim_b != 0x12) || (comp_anim_c != 0)) {
        comp_anim_b = 0x12;
        ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
      }
      return;
    }
    if (((&comp_collision_related)[iVar2] == '\x0f') ||
        ((&comp_collision_related)[iVar2] == '\x10')) {
      if ((&comp_func_offset[0].func_offset_from_15ede)[iVar2] == 0x22) {
        psVar1 = (short *)((int)&comp_vel[0].x + iVar2);
        if (*psVar1 != 0) {
          if (*psVar1 < 0) {
            comp_state_a = comp_state_a | ENTITY_STATE_A_08;
          } else {
            comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
          }
        }
      } else {
        comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
        if (((&DAT_ffffb66f)[iVar2] & 4) != 0) {
          comp_state_a = comp_state_a | ENTITY_STATE_A_08;
        }
      }
      if ((comp_anim_b != 0x12) ||
          (comp_anim_c != ECS_STATE_1_B_ATTACKING_MID_AIR)) {
        comp_anim_b = 0x12;
        ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 8);
      }
      return;
    }
  }
  if ((comp_anim_b != 0) || (comp_anim_c != 0)) {
    comp_anim_b = 0;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  }
  return;
}

void FUN_000238e8(void)

{
  short other;
  undefined2 extraout_D1w;
  entity_id_t self;
  short pos_index;

  other = ecs_find_some_entity_with_func();
  pos_index = DAT_ffffdb5a;
  *(short *)((int)&DAT_ffffdb60 + (int)(short)(DAT_ffffdb5a * 2)) = other;
  if (-1 < other) {
    entity_reset(self);
    (&comp_has_func_maybe)[self] = 0x80;
    *(undefined2 *)(&comp_unk_5 + self) = extraout_D1w;
    *(undefined2 *)((int)&comp_pos_x + self) =
        *(undefined2 *)((int)&int16_vec2_t_00023942.x +
                        (int)(short)(pos_index * 4));
    *(undefined2 *)((int)&comp_pos_y + self) =
        *(undefined2 *)((int)&int16_vec2_t_00023942.y +
                        (int)(short)(pos_index * 4));
    pos_index = *(short *)((int)&comp_unk_8 + (int)DAT_ffffdb42);
    (&DAT_ffffcf9f)[pos_index] = (&DAT_ffffcf9f)[pos_index] + '\x01';
    *(short *)((int)&comp_unk_8 + self) = pos_index;
    (&comp_func_offset[0].unk1)[self] = 0x8f;
    *(undefined1 *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + self) = 0xff;
    FUN_000019ae();
    (&comp_unk_10)[self] = 0x40;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023952(void)

{
  short sVar1;
  ushort uVar2;
  short sVar3;
  ushort *puVar4;
  short *psVar5;
  int iVar6;
  int unaff_A4;

  sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
  if (sVar3 == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x14;
    uVar2 = 0xffff;
    sVar3 = 3;
    puVar4 = &DAT_ffffdb60;
    do {
      uVar2 = *puVar4 & uVar2;
      sVar3 = sVar3 + -1;
      puVar4 = puVar4 + 1;
    } while (sVar3 != -1);
    if ((short)uVar2 < 0) {
      audio_play(SOUND_ID_FE);
      DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
      _DAT_ffffdb44 = 0x78;
      return;
    }
    for (; _DAT_ffffdb44 < 4; _DAT_ffffdb44 = _DAT_ffffdb44 + 1) {
      psVar5 = (short *)((int)&DAT_ffffdb60 + (int)(short)(_DAT_ffffdb44 * 2));
      if (-1 < *psVar5) {
        _DAT_ffffdb44 = _DAT_ffffdb44 + 1;
        iVar6 = (int)*psVar5;
        if ((*(byte *)((int)&comp_state + iVar6) & 0x7f) != 3) {
          return;
        }
        *(undefined1 *)((int)&comp_state + iVar6) = 4;
        return;
      }
    }
    sVar3 = 3;
    psVar5 = &DAT_ffffdb60;
    do {
      sVar1 = *psVar5;
      if ((-1 < sVar1) &&
          ((*(byte *)((int)&comp_state + (int)sVar1) & 0x7f) == 3)) {
        *(undefined1 *)((int)&comp_state + (int)sVar1) = 6;
      }
      sVar3 = sVar3 + -1;
      psVar5 = psVar5 + 1;
    } while (sVar3 != -1);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x3c;
    _DAT_ffffdb44 = 0;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000239e8(entity_id_t self, entity_id_t other)

{
  _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
  if (_DAT_ffffdb44 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    DAT_ffff9808 = 0xff;
    FUN_00023ca4();
    entity_id_w_t_ffffdb4e = (entity_id_w_t)self;
    *(undefined2 *)((int)&comp_unk_3 + self) = 0x1a;
    *(undefined2 *)((int)&comp_pos_x + self) = 0x1090;
    *(undefined2 *)((int)&comp_pos_y + self) = 0x1060;
    ecs_anim_unk_2(self, (anim_item_t *)other, 6);
    FUN_0001689e();
    audio_play(SOUND_ID_TOW_APPEAR);
    _DAT_ffffdb44 = 0x3c;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023a30(void)

{
  int unaff_A4;

  _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
  if (_DAT_ffffdb44 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x80;
    ecs_anim_unk_4();
    ecs_anim_unk_4();
    ecs_anim_unk_4();
    ecs_anim_unk_4();
    _DAT_ffffdb44 = 0x50;
  }
  return;
}

void ecs_anim_unk_4(void)

{
  entity_state_1_b_t in_D0b;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  *(undefined2 *)(&comp_unk_1 + unaff_A4) = 1;
  *(code **)((int)&comp_some_function + unaff_A4) = FUN_00023a7e;
  if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
    BYTE_ffffc709 = 0;
  }
  if (unaff_A4 == ENTITY_ID_ASHA) {
    BYTE_ffffc70a = 0;
  }
  (&comp_state_1_a)[unaff_A4] = 0;
  (&comp_anim_c)[unaff_A4] = in_D0b;
  ecs_anim_unk_1(unaff_A4, unaff_A5);
  (&comp_has_func_maybe)[unaff_A4] =
      (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
  return;
}

void FUN_00023a7e(entity_id_t self)

{
  if (*(short *)((int)&comp_anim_tick + self) == 0) {
    (&comp_has_func_maybe)[self] = 0;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023a8a(void)

{
  entity_id_t unaff_A4;

  ecs_update_pos_y(unaff_A4);
  _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
  if (_DAT_ffffdb44 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    (&comp_has_func_maybe)[(short)entity_id_w_t_ffffdb4e] = 0;
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 8;
    _DAT_ffffdb44 = 0;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023aac(void)

{
  ushort uVar1;
  undefined2 uVar2;
  ushort uVar3;

  uVar3 = _DAT_ffffdb44 & 0xfffe;
  if ((_DAT_ffffdb44 & 1) == 0) {
    uncompress_data(*(short *)((int)&WORD_00023b10 + (int)(short)uVar3),
                    (uint8_t *)&vdp_gfx_ptr_1);
    _DAT_ffffdb44 = _DAT_ffffdb44 + 1;
    return;
  }
  uVar1 = *(ushort *)((int)&WORD_00023b20 + (int)(short)uVar3);
  uVar2 = *(undefined2 *)((int)&WORD_00023b10 + (int)(short)uVar3);
  *(undefined2 *)((int)compressed_data_indices + (int)(short)uVar1) = uVar2;
  *(undefined2 *)(&DAT_ffff9a8a + (short)uVar1) = uVar2;
  vdp_copy(VDP_MEM_VIDEO_RAM,
           &vdp_gfx_ptr_1,
           (void *)(uint)(ushort)(uVar1 << 9 | uVar1 >> 7),
           0x200,
           '\0');
  _DAT_ffffdb44 = _DAT_ffffdb44 + 1;
  if (0xf < _DAT_ffffdb44) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    _DAT_ffffdb44 = 0x78;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023b30(void)

{
  char extraout_D1b;

  _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
  if (_DAT_ffffdb44 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    FUN_0001fd94();
    palette_copy_from_palettes2(extraout_D1b);
    FUN_0000ac92();
    _DAT_ffffdb44 = 0x90;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023b5e(void)

{
  DAT_ffffdb52 = DAT_ffffdb52 + -1;
  _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
  if (_DAT_ffffdb44 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    _DAT_ffffdb44 = 0x3c;
    FUN_0001689e();
    DAT_ffff9808 = 0;
    audio_play(SOUND_ID_TOW_STOP);
    FUN_000019ae();
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023b8a(void)

{
  short sVar1;
  entity_id_t self;
  anim_item_t *unaff_A5;

  _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
  if (_DAT_ffffdb44 == 0) {
    comp_has_func_maybe = comp_has_func_maybe | COMPONENT_STATE_B_ACTIVE;
    DAT_ffffd916 = 0xd3;
    FUN_0001937a();
    sVar1 = DAT_ffffdb42;
    comp_has_func_maybe = comp_has_func_maybe & ~COMPONENT_STATE_B_ACTIVE;
    self = (entity_id_t)DAT_ffffdb42;
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    FUN_00023ca4();
    _DAT_ffffdb46 = sVar1;
    *(short *)((int)&comp_pos_x + self) = DAT_ffffdb50 + 0x20;
    *(short *)((int)&comp_pos_y + self) = DAT_ffffdb52 + -0x20;
    (&comp_state_a)[self] = 0x80;
    *(undefined2 *)((int)&comp_unk_3 + self) = 0x1e;
    ecs_anim_unk_2(self, unaff_A5, 0x1a);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023be4(void)

{
  byte bVar1;
  short sVar2;
  int unaff_A4;

  if (*(short *)((int)&comp_anim_tick + (int)_DAT_ffffdb46) != 0) {
    return;
  }
  DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
  _DAT_ffffdb44 = 0x18;
  (&DAT_ffffba7c)[unaff_A4] = 0;
  DAT_ffffdb58 = 0x24;
  FUN_0002493e();
  while (true) {
    IO_Z80BUS = 0x100;
    do {
      bVar1 = IO_Z80BUS._0_1_;
    } while ((bVar1 & 1) != 0);
    if (z80_ram_something_1 == '\0')
      break;
    IO_Z80BUS = 0;
    sVar2 = 0x1f;
    do {
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
  }
  (&z80_ram)[(short)(((byte)(z80_ram_something_3 + z80_ram_something_2) & 0xf) +
                     0x1c30)] = 0x48;
  z80_ram_something_3 = z80_ram_something_3 + '\x01';
  IO_Z80BUS = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023c12(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
  if (_DAT_ffffdb44 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    FUN_00023ca4();
    _DAT_ffffdb46 = (undefined2)unaff_A4;
    *(short *)((int)&comp_pos_x + unaff_A4) = DAT_ffffdb50 + -0x1c;
    *(short *)((int)&comp_pos_y + unaff_A4) = DAT_ffffdb52 + -0x24;
    (&comp_state_a)[unaff_A4] = 0x80;
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x1e;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x18);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023c50(void)

{
  byte bVar1;
  short sVar2;
  int unaff_A4;

  if (*(short *)((int)&comp_anim_tick + (int)_DAT_ffffdb46) != 0) {
    return;
  }
  DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
  _DAT_ffffdb44 = 0x18;
  (&DAT_ffffba80)[unaff_A4] = 1;
  DAT_ffffdb58 = 0x5c;
  FUN_0002493e();
  while (true) {
    IO_Z80BUS = 0x100;
    do {
      bVar1 = IO_Z80BUS._0_1_;
    } while ((bVar1 & 1) != 0);
    if (z80_ram_something_1 == '\0')
      break;
    IO_Z80BUS = 0;
    sVar2 = 0x1f;
    do {
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
  }
  (&z80_ram)[(short)(((byte)(z80_ram_something_3 + z80_ram_something_2) & 0xf) +
                     0x1c30)] = 0x48;
  z80_ram_something_3 = z80_ram_something_3 + '\x01';
  IO_Z80BUS = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023c80(void)

{
  int unaff_A4;

  _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
  if (_DAT_ffffdb44 == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 1;
    (&comp_collision_related)[unaff_A4] = 0;
    (&comp_state_a)[unaff_A4] = 0x80;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x78;
    if (UNION_sound_id_word_union_t_ffff97e6.as_word != 0x10) {
      UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
      audio_stop_all();
      UNION_sound_id_word_union_t_ffff97e6.as_word = 0x10;
      audio_play(SOUND_ID_MALEVOLENT_DEITY);
    }
    return;
  }
  return;
}

void FUN_00023ca4(void)

{
  short unaff_D2w;
  entity_id_t e;

  FUN_0000147a((func *)0x23cc6, 0, 4);
  e = (entity_id_t)unaff_D2w;
  entity_reset(e);
  *(undefined2 *)((int)&comp_unk_3 + e) = 0x1e;
  *(undefined2 *)(&comp_anim_base_offset + e) =
      *(undefined2 *)(&comp_anim_base_offset + DAT_ffffdb42);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00023cde(void)

{
  char cVar1;
  short unaff_D2w;
  int unaff_A4;
  entity_id_t self;
  int iVar2;
  anim_item_t *unaff_A5;
  bool bVar3;

  cVar1 = (&comp_collision_related)[unaff_A4];
  if (cVar1 == '\0') {
    FUN_00023e78();
    if (-1 < unaff_D2w) {
      (&comp_collision_related)[DAT_ffffdb42] =
          (&comp_collision_related)[DAT_ffffdb42] + '\x01';
      return;
    }
  } else if (cVar1 == '\x01') {
    self = (entity_id_t)(short)entity_id_w_t_ffffdb4e;
    ecs_update_pos_y(self);
    if (0x107f < *(ushort *)((int)&comp_pos_y + self)) {
      *(short *)((int)&comp_pos_y + self) =
          *(short *)((int)&comp_pos_y + self) -
          (*(ushort *)((int)&comp_pos_y + self) + 0xef80);
      (&comp_collision_related)[DAT_ffffdb42] =
          (&comp_collision_related)[DAT_ffffdb42] + '\x01';
      FUN_0001689e();
      _DAT_ffffdb44 = 0x3c;
      return;
    }
  } else if (cVar1 == '\x02') {
    FUN_00023f66();
    _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
    if (_DAT_ffffdb44 == 0) {
      FUN_0001689e();
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      ecs_anim_unk_2((int)(short)entity_id_w_t_ffffdb4e, unaff_A5, 4);
    }
  } else {
    bVar3 = cVar1 == '\x03';
    if (bVar3) {
      FUN_00023f66();
      if (bVar3) {
        (&comp_collision_related)[unaff_A4] =
            (&comp_collision_related)[unaff_A4] + '\x01';
        return;
      }
    } else if (cVar1 == '\x04') {
      bVar3 = _DAT_ffffdb44 == 0;
      if (!bVar3) {
        _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
        bVar3 = _DAT_ffffdb44 == 0;
      }
      FUN_00023f94();
      if ((bVar3) && (_DAT_ffffdb44 == 0)) {
        (&comp_collision_related)[unaff_A4] =
            (&comp_collision_related)[unaff_A4] + '\x01';
        comp_has_func_maybe = comp_has_func_maybe | COMPONENT_STATE_B_ACTIVE;
        DAT_ffffd916 = 0xbd;
        FUN_0001937a();
        comp_has_func_maybe = comp_has_func_maybe & ~COMPONENT_STATE_B_ACTIVE;
        palette_set_effect(PALETTE_ID_FLAG_3 | PALETTE_ID_FLAG_2,
                           true,
                           (palette_effect_t *)&UNK_00024c68);
        _DAT_ffffdb44 = 0x20;
        return;
      }
    } else {
      if (cVar1 != '\x05') {
        iVar2 =
            (int)*(short *)((int)&WORD_00023e30 + (int)(short)_DAT_ffffdb44);
        DAT_ffffc8de = *(undefined2 *)((int)&WORD_00023e30 + iVar2);
        DAT_ffffc8dc = *(undefined2 *)((int)&WORD_00023e32 + iVar2);
        DAT_ffffc8e2 = *(undefined2 *)((int)&WORD_00023e34 + iVar2);
        DAT_ffffc8e0 = 1;
        FUN_0000b85e((undefined2 *)((int)&WORD_00023e36 + iVar2));
        iVar2 = (int)DAT_ffffdb42;
        _DAT_ffffdb44 = _DAT_ffffdb44 + 2;
        if (7 < _DAT_ffffdb44) {
          (&comp_has_func_maybe)[(short)entity_id_w_t_ffffdb4e] = 0;
          DAT_ffffdb41 = 0;
          *(undefined2 *)(&comp_unk_4 + iVar2) = 0xb4;
          (&comp_collision_related)[iVar2] = 0;
          DAT_ffff9808 = 0;
          *(undefined1 *)((int)&component_state_a_pepelogoo + iVar2) = 3;
          (&DAT_ffffb46e)[iVar2] = 3;
        }
        return;
      }
      _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
      if (_DAT_ffffdb44 == 0) {
        (&comp_collision_related)[unaff_A4] =
            (&comp_collision_related)[unaff_A4] + '\x01';
        ecs_anim_unk_2((int)(short)entity_id_w_t_ffffdb4e, unaff_A5, 6);
        return;
      }
    }
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

uint FUN_00023d52(void)

{
  char in_D0b;
  uint uVar1;
  uint extraout_D0;
  uint extraout_D0_00;
  uint extraout_D0_01;
  int unaff_A4;
  int iVar2;
  anim_item_t *unaff_A5;
  bool bVar3;

  bVar3 = in_D0b == '\x01';
  if (bVar3) {
    uVar1 = FUN_00023f66();
    if (bVar3) {
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      return uVar1;
    }
  } else if (in_D0b == '\x02') {
    bVar3 = _DAT_ffffdb44 == 0;
    if (!bVar3) {
      _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
      bVar3 = _DAT_ffffdb44 == 0;
    }
    uVar1 = FUN_00023f94();
    if ((bVar3) && (_DAT_ffffdb44 == 0)) {
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      comp_has_func_maybe = comp_has_func_maybe | COMPONENT_STATE_B_ACTIVE;
      DAT_ffffd916 = 0xbd;
      FUN_0001937a();
      comp_has_func_maybe = comp_has_func_maybe & ~COMPONENT_STATE_B_ACTIVE;
      palette_set_effect(PALETTE_ID_FLAG_3 | PALETTE_ID_FLAG_2,
                         true,
                         (palette_effect_t *)&UNK_00024c68);
      _DAT_ffffdb44 = 0x20;
      return extraout_D0;
    }
  } else {
    uVar1 = (uint)(byte)(in_D0b - 3U);
    if ((byte)(in_D0b - 3U) != 0) {
      iVar2 = (int)*(short *)((int)&WORD_00023e30 + (int)(short)_DAT_ffffdb44);
      DAT_ffffc8de = *(undefined2 *)((int)&WORD_00023e30 + iVar2);
      DAT_ffffc8dc = *(undefined2 *)((int)&WORD_00023e32 + iVar2);
      DAT_ffffc8e2 = *(undefined2 *)((int)&WORD_00023e34 + iVar2);
      DAT_ffffc8e0 = 1;
      FUN_0000b85e((undefined2 *)((int)&WORD_00023e36 + iVar2));
      iVar2 = (int)DAT_ffffdb42;
      _DAT_ffffdb44 = _DAT_ffffdb44 + 2;
      if (7 < _DAT_ffffdb44) {
        (&comp_has_func_maybe)[(short)entity_id_w_t_ffffdb4e] = 0;
        DAT_ffffdb41 = 0;
        *(undefined2 *)(&comp_unk_4 + iVar2) = 0xb4;
        (&comp_collision_related)[iVar2] = 0;
        DAT_ffff9808 = 0;
        *(undefined1 *)((int)&component_state_a_pepelogoo + iVar2) = 3;
        (&DAT_ffffb46e)[iVar2] = 3;
      }
      return extraout_D0_01;
    }
    _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
    if (_DAT_ffffdb44 == 0) {
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      ecs_anim_unk_2((int)(short)entity_id_w_t_ffffdb4e, unaff_A5, 6);
      return extraout_D0_00;
    }
  }
  return uVar1;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

uint FUN_00023db2(void)

{
  char in_D0b;
  uint extraout_D0;
  uint extraout_D0_00;
  int unaff_A4;
  int iVar1;
  anim_item_t *unaff_A5;

  if ((byte)(in_D0b - 1U) != 0) {
    iVar1 = (int)*(short *)((int)&WORD_00023e30 + (int)(short)_DAT_ffffdb44);
    DAT_ffffc8de = *(undefined2 *)((int)&WORD_00023e30 + iVar1);
    DAT_ffffc8dc = *(undefined2 *)((int)&WORD_00023e32 + iVar1);
    DAT_ffffc8e2 = *(undefined2 *)((int)&WORD_00023e34 + iVar1);
    DAT_ffffc8e0 = 1;
    FUN_0000b85e((undefined2 *)((int)&WORD_00023e36 + iVar1));
    iVar1 = (int)DAT_ffffdb42;
    _DAT_ffffdb44 = _DAT_ffffdb44 + 2;
    if (7 < _DAT_ffffdb44) {
      (&comp_has_func_maybe)[(short)entity_id_w_t_ffffdb4e] = 0;
      DAT_ffffdb41 = 0;
      *(undefined2 *)(&comp_unk_4 + iVar1) = 0xb4;
      (&comp_collision_related)[iVar1] = 0;
      DAT_ffff9808 = 0;
      *(undefined1 *)((int)&component_state_a_pepelogoo + iVar1) = 3;
      (&DAT_ffffb46e)[iVar1] = 3;
    }
    return extraout_D0_00;
  }
  _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
  if (_DAT_ffffdb44 == 0) {
    (&comp_collision_related)[unaff_A4] =
        (&comp_collision_related)[unaff_A4] + '\x01';
    ecs_anim_unk_2((int)(short)entity_id_w_t_ffffdb4e, unaff_A5, 6);
    return extraout_D0;
  }
  return (uint)(byte)(in_D0b - 1U);
}

void FUN_00023e78(void)

{
  entity_id_w_t unaff_D2w;
  entity_id_t e;
  anim_item_t *unaff_A5;

  FUN_0000147a((func *)0x23ec6, 0, 4);
  if (-1 < (short)unaff_D2w) {
    e = (entity_id_t)(short)unaff_D2w;
    entity_id_w_t_ffffdb4e = unaff_D2w;
    entity_reset(e);
    (&comp_anim_base_offset + e)[0] = 0x10;
    (&comp_anim_base_offset + e)[1] = 8;
    (&comp_state_a)[e] = 0x80;
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x1c;
    *(undefined2 *)((int)&comp_pos_x + e) = 0x1090;
    *(undefined2 *)((int)&comp_pos_y + e) = 0xfc0;
    *(undefined2 *)((int)&comp_vel[0].y + e) = 0x200;
    ecs_anim_unk_2(e, unaff_A5, 0);
    ecs_anim_unk_2(e, unaff_A5, 2);
  }
  return;
}

void FUN_00023ec8(void)

{
  char cVar1;
  entity_state_1_a_t eVar2;
  short sVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar4;

  if ((DAT_ffffdb40 & 1) != 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    return;
  }
  cVar1 = (&comp_collision_related)[unaff_A4];
  if (cVar1 == '\0') {
    sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
    if (sVar3 == 0) {
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      return;
    }
  } else {
    bVar4 = cVar1 == '\x01';
    if (bVar4) {
      FUN_00023f66();
      if (bVar4) {
        (&comp_collision_related)[unaff_A4] =
            (&comp_collision_related)[unaff_A4] + '\x01';
        return;
      }
    } else {
      bVar4 = cVar1 == '\x02';
      if (bVar4) {
        FUN_00023f94();
        if (bVar4) {
          (&comp_collision_related)[unaff_A4] =
              (&comp_collision_related)[unaff_A4] + '\x01';
          (&comp_has_func_maybe)[unaff_A4] =
              (&comp_has_func_maybe)[unaff_A4] & 0xf7;
          if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
            BYTE_ffffc709 = 0;
          }
          if (unaff_A4 == ENTITY_ID_ASHA) {
            BYTE_ffffc70a = 0;
          }
          (&comp_state_1_a)[unaff_A4] = 0;
          (&comp_anim_c)[unaff_A4] = 0x16;
          ecs_anim_unk_1(unaff_A4, unaff_A5);
          (&comp_has_func_maybe)[unaff_A4] =
              (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
          return;
        }
      } else {
        eVar2 = (&comp_state_1_a)[unaff_A4];
        (&comp_state_1_a)[unaff_A4] = eVar2 & 0xdf;
        if ((eVar2 & 0x20) != 0) {
          DAT_ffff9808 = 0xff;
          palette_set_effect(PALETTE_ID_FLAG_3 | PALETTE_ID_FLAG_2,
                             true,
                             (palette_effect_t *)&UNK_00024c68);
          unaff_A4 = (entity_id_t)DAT_ffffdb42;
        }
        if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
          FUN_00012ea4();
          *(undefined1 *)((int)&component_state_a_pepelogoo + unaff_A4) = 3;
          (&DAT_ffffb46e)[unaff_A4] = 3;
          (&comp_has_func_maybe)[unaff_A4] =
              (&comp_has_func_maybe)[unaff_A4] | 8;
          (&comp_collision_related)[unaff_A4] = 0;
          DAT_ffff9808 = 0;
          DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
          *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0xb4;
        }
      }
    }
  }
  return;
}

byte FUN_00023f66(void)

{
  byte bVar1;
  int unaff_A4;

  bVar1 = *(byte *)((int)&component_state_a_pepelogoo + unaff_A4) & 0x7f;
  if (bVar1 != 4) {
    if (bVar1 != 3) {
      return bVar1;
    }
    if (((&DAT_ffffb46e)[unaff_A4] & 0x7f) != 3) {
      return (&DAT_ffffb46e)[unaff_A4] & 0x7f;
    }
    *(undefined1 *)((int)&component_state_a_pepelogoo + unaff_A4) = 4;
    (&DAT_ffffb46e)[unaff_A4] = 4;
  }
  return 0;
}

void FUN_00023f94(void)

{
  return;
}

void FUN_00023fa4(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0xb4;
    FUN_0002405c();
  }
  return;
}

void FUN_00023fba(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0xb4;
    FUN_00024076();
  }
  return;
}

void FUN_00023fd0(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0xb4;
    FUN_00024096();
  }
  return;
}

void FUN_00023fe6(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0xb4;
    FUN_000240b0();
  }
  return;
}

void FUN_00023ffc(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0xb4;
    FUN_0002405c();
    FUN_000240b0();
    FUN_0002403e();
  }
  return;
}

void FUN_0002401a(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0xb4;
    FUN_00024076();
    FUN_00024096();
    FUN_0002403e();
  }
  return;
}

void FUN_00024038(void)

{
  DAT_ffffdb41 = 0;
  return;
}

void FUN_0002403e(void)

{
  int unaff_A4;

  if ((*(char *)((int)&component_state_a_pepelogoo + unaff_A4) == '\x06') &&
      ((&DAT_ffffb46e)[unaff_A4] == '\x06')) {
    (&DAT_ffffba7c)[unaff_A4] = (&DAT_ffffba7c)[unaff_A4] | 8;
    (&DAT_ffffba80)[unaff_A4] = (&DAT_ffffba80)[unaff_A4] | 8;
  }
  return;
}

void FUN_0002405c(void)

{
  int unaff_A4;

  if ((*(byte *)((int)&component_state_a_pepelogoo + unaff_A4) & 0x7f) == 3) {
    *(undefined1 *)((int)&component_state_a_pepelogoo + unaff_A4) = 6;
    (&DAT_ffffba7c)[unaff_A4] = (&DAT_ffffba7c)[unaff_A4] & 0xf3;
  }
  return;
}

void FUN_00024076(void)

{
  int unaff_A4;

  if ((*(byte *)((int)&component_state_a_pepelogoo + unaff_A4) & 0x7f) == 3) {
    *(undefined1 *)((int)&component_state_a_pepelogoo + unaff_A4) = 6;
    (&DAT_ffffba7c)[unaff_A4] = (&DAT_ffffba7c)[unaff_A4] & 0xf3;
    (&DAT_ffffba7c)[unaff_A4] = (&DAT_ffffba7c)[unaff_A4] | 4;
  }
  return;
}

void FUN_00024096(void)

{
  int unaff_A4;

  if (((&DAT_ffffb46e)[unaff_A4] & 0x7f) == 3) {
    (&DAT_ffffb46e)[unaff_A4] = 6;
    (&DAT_ffffba80)[unaff_A4] = (&DAT_ffffba80)[unaff_A4] & 0xf3;
  }
  return;
}

void FUN_000240b0(void)

{
  int unaff_A4;

  if (((&DAT_ffffb46e)[unaff_A4] & 0x7f) == 3) {
    (&DAT_ffffb46e)[unaff_A4] = 6;
    (&DAT_ffffba80)[unaff_A4] = (&DAT_ffffba80)[unaff_A4] & 0xf3;
    (&DAT_ffffba80)[unaff_A4] = (&DAT_ffffba80)[unaff_A4] | 4;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000240e2(void)

{
  DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
  _DAT_ffffdb44 = 0x78;
  DAT_ffff9808 = 0xff;
  FUN_00001980();
  AUDIO_PAUSE_COUNT = 0;
  UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
  audio_play(SOUND_ID_F9);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000240f8(void)

{
  byte bVar1;
  short sVar2;
  int iVar3;
  anim_item_t *unaff_A5;

  DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
  comp_has_func_maybe = comp_has_func_maybe | COMPONENT_STATE_B_ACTIVE;
  DAT_ffffd916 = 0xd4;
  FUN_0001937a();
  comp_has_func_maybe = comp_has_func_maybe & ~COMPONENT_STATE_B_ACTIVE;
  DAT_ffffcc85 = 0;
  iVar3 = (int)DAT_ffffdb42;
  FUN_0002465e();
  ecs_anim_unk_2(iVar3 + ENTITY_ID_PEPELOGOO, unaff_A5, 0);
  FUN_0002465e();
  ecs_anim_unk_2(iVar3 + ENTITY_ID_08, unaff_A5, 0);
  _DAT_ffffdb3e = 0xb4;
  while (true) {
    IO_Z80BUS = 0x100;
    do {
      bVar1 = IO_Z80BUS._0_1_;
    } while ((bVar1 & 1) != 0);
    if (z80_ram_something_1 == '\0')
      break;
    IO_Z80BUS = 0;
    sVar2 = 0x1f;
    do {
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
  }
  (&z80_ram)[(short)(((byte)(z80_ram_something_3 + z80_ram_something_2) & 0xf) +
                     0x1c30)] = 0x4c;
  z80_ram_something_3 = z80_ram_something_3 + '\x01';
  IO_Z80BUS = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00024144(void)

{
  ushort uVar1;
  short sVar2;
  char duration;
  char extraout_D1b;
  vdp_color_t *pvVar3;
  vdp_color_t *pvVar4;
  int unaff_A4;

  _DAT_ffffdb3e = _DAT_ffffdb3e + -1;
  if (_DAT_ffffdb3e == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    *(undefined1 *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4) =
        0xff;
    _DAT_ffffdb44 = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x3c;
    FUN_0001fd5e();
    duration = extraout_D1b;
  } else {
    for (uVar1 = (0xb4 - _DAT_ffffdb3e) * 2; 0x53 < uVar1;
         uVar1 = uVar1 - 0x54) {
    }
    sVar2 = 8;
    pvVar3 = palettes_2 + 6;
    do {
      *pvVar3 = *(vdp_color_t *)(&UNK_0001fdd8 + (short)uVar1);
      uVar1 = uVar1 + 2;
      if (0x53 < uVar1) {
        uVar1 = 0;
      }
      sVar2 = sVar2 + -1;
      pvVar3 = pvVar3 + 1;
    } while (sVar2 != -1);
    duration = -1;
  }
  sVar2 = 7;
  pvVar3 = palettes_2;
  pvVar4 = palettes[1];
  do {
    *(undefined4 *)pvVar4 = *(undefined4 *)pvVar3;
    sVar2 = sVar2 + -1;
    pvVar3 = pvVar3 + 2;
    pvVar4 = pvVar4 + 2;
  } while (sVar2 != -1);
  palette_set_fade(PALETTE_ID_FLAG_1,
                   PALETTE_FADE_1,
                   duration,
                   (palette_color_iter_t)0xffffffff);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00024166(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
    (&component_state_b_pepelogoo)[unaff_A4 + (short)_DAT_ffffdb44] = 0;
    FUN_0002427a();
    _DAT_ffffdb44 = _DAT_ffffdb44 + 4;
    if (0x27 < _DAT_ffffdb44) {
      DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    }
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002419c(void)

{
  DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
  _DAT_ffffdb44 = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000241a6(void)

{
  _DAT_ffffdb44 = _DAT_ffffdb44 + 2;
  if (7 < _DAT_ffffdb44) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    _DAT_ffffdb44 = 0x1e;
    FUN_0001689e();
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000241c6(void)

{
  int unaff_A4;

  _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
  if (_DAT_ffffdb44 == 0) {
    DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
    _DAT_ffffdb44 = 0xc0;
    DAT_ffffdb5c = 1;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

uint FUN_000241e4(void)

{
  undefined2 extraout_D0u;
  uint in_D0;
  short sVar1;
  uint extraout_D0;
  word wVar2;
  ushort extraout_D1u;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  bool bVar3;
  undefined8 uVar4;

  bVar3 = _DAT_ffffdb44 == 0;
  if (bVar3) {
    sVar1 = palette_iterate_for_unknown_reasons();
    in_D0 = CONCAT22(extraout_D0u, sVar1);
    if (!bVar3) {
      DAT_ffffdb41 = DAT_ffffdb41 + '\x02';
      DAT_ffffcc92 = 0x18;
      if (((undefined1)vdp_ctrl_mode_set_2_state & 0x40) != 0) {
        related_to_palette_maybe_1 = 0xff;
        related_to_palette_maybe_2 = 0;
        uVar4 = exception_unk_0(unaff_A3,
                                unaff_A4,
                                unaff_A6,
                                in_D0,
                                extraout_D1,
                                unaff_D2,
                                unaff_D3,
                                unaff_D4,
                                unaff_D5,
                                unaff_D6,
                                unaff_D7);
        in_D0 = (uint)((ulonglong)uVar4 >> 0x20);
      }
      return in_D0;
    }
  } else {
    _DAT_ffffdb44 = _DAT_ffffdb44 + -1;
    if (_DAT_ffffdb44 == 0) {
      palette_set_fade(~PALETTE_ID_FLAG_NONE,
                       PALETTE_FADE_BLACK_EASE_IN,
                       '\x06',
                       (palette_color_iter_t)0xffffffff);
      unaff_A4 = (entity_id_t)DAT_ffffdb42;
      in_D0 = extraout_D0;
    }
  }
  DAT_ffffdb5c = DAT_ffffdb5c + -1;
  if (DAT_ffffdb5c == 0) {
    DAT_ffffdb5c = 2;
    DAT_ffffdb52 = DAT_ffffdb52 + 1;
  }
  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
    sVar1 = -DAT_ffffdb52;
    if (DAT_ffffdb52 < 0x10d1 && sVar1 != -0x10d0) {
      wVar2 = rand();
      in_D0 = (uint)wVar2;
      if ((ushort)(extraout_D1u % 0x50) < (ushort)(sVar1 + 0x10d0U)) {
        rand();
        in_D0 = FUN_0002427a();
      }
    }
  }
  return in_D0;
}

void FUN_00024278(void)

{
  return;
}

void FUN_0002427a(void)

{
  short unaff_D2w;
  undefined2 unaff_D6w;
  entity_id_t e;
  anim_item_t *unaff_A5;
  undefined2 uStack_8;

  FUN_0000147a(FUN_000242c4, 1, 4);
  if (-1 < unaff_D2w) {
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    *(undefined2 *)((int)&comp_pos_x + e) = unaff_D6w;
    *(undefined2 *)((int)&comp_pos_y + e) = uStack_8;
    *(undefined2 *)((int)&comp_vel[0].y + e) = 0xfe00;
    (&comp_state_a)[e] = 0x80;
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x16;
    (&comp_anim_base_offset + e)[0] = 0x14;
    (&comp_anim_base_offset + e)[1] = 0x48;
    ecs_anim_unk_2(e, unaff_A5, 0);
  }
  return;
}

void FUN_000242c4(void)

{
  entity_id_t unaff_A4;

  ecs_update_pos_y(unaff_A4);
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

/*
Unable to decompile 'FUN_000242d4'
Cause: Exception while decompiling 000242d4: Decompiler process died

*/

void FUN_0002430c(void)

{
  byte bVar1;
  short sVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
  }
  FUN_0002486c();
  FUN_0002486c();
  FUN_0002486c();
  FUN_0002486c();
  FUN_0002486c();
  FUN_000248c4();
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_0002434c(void)

{
  undefined1 uVar1;
  byte bVar2;
  char cVar3;
  short sVar4;
  entity_state_1_b_t eVar5;
  short sVar6;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar7;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    uVar1 = *(undefined1 *)(unaff_A4 - 0x4689);
    (&DAT_ffffb979)[unaff_A4] = uVar1;
    (&comp_unk_5)[unaff_A4] = uVar1;
    *(undefined1 *)(unaff_A4 - 0x3e87) = uVar1;
  } else {
    cVar3 = (&comp_collision_related)[unaff_A4] + -1;
    (&comp_collision_related)[unaff_A4] = cVar3;
    bVar7 = cVar3 == '\0';
    if (!bVar7)
      goto LAB_0002439e;
  }
  (&comp_collision_related)[unaff_A4] = 0x18;
  sVar4 = 0;
  sVar6 = 0;
  if ((*(byte *)((int)&component_unknown_9 + unaff_A4) & 1) != 0) {
    sVar6 = 2;
  }
  if ((*(byte *)(unaff_A4 - 0x4689) <= (byte)(&UNK_000243e7)[sVar6]) &&
      (sVar4 = -1,
       (byte)(&UNK_000243e6)[sVar6] < *(byte *)(unaff_A4 - 0x4689))) {
    sVar4 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  }
  *(short *)(unaff_A4 - 0x4788) = sVar4;
  bVar7 = sVar4 == 0;
LAB_0002439e:
  FUN_0002470c(unaff_A4);
  if (bVar7) {
    if (*(short *)(unaff_A4 - 0x4788) < 0) {
      *(char *)(unaff_A4 - 0x4689) = *(char *)(unaff_A4 - 0x4689) + '\x01';
    } else {
      *(char *)(unaff_A4 - 0x4689) = *(char *)(unaff_A4 - 0x4689) + -1;
    }
    FUN_00024884();
    FUN_000247f0();
    FUN_000248c4();
    sVar4 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
    eVar5 = ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
    if ((-0x20 < sVar4) &&
        (eVar5 = ECS_STATE_1_B_JUMPING_OR_UNSHIELDING, sVar4 < 0x20)) {
      eVar5 = 0;
    }
    if (eVar5 != (&comp_anim_c)[unaff_A4]) {
      if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
        BYTE_ffffc709 = 0;
      }
      if (unaff_A4 == ENTITY_ID_ASHA) {
        BYTE_ffffc70a = 0;
      }
      (&comp_state_1_a)[unaff_A4] = 0;
      (&comp_anim_c)[unaff_A4] = eVar5;
      ecs_anim_unk_1(unaff_A4, unaff_A5);
      (&comp_has_func_maybe)[unaff_A4] =
          (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
      return;
    }
  }
  return;
}

undefined4 FUN_00024564(void)

{
  undefined4 uVar1;
  int unaff_A4;

  uVar1 = 0x24;
  if ((*(byte *)((int)&component_unknown_9 + unaff_A4) & 1) != 0) {
    uVar1 = 0x5c;
  }
  return uVar1;
}

void FUN_00024572(void)

{
  char *pcVar1;
  char cVar2;
  short sVar3;
  int iVar4;
  int unaff_A4;

  cVar2 = FUN_00024564();
  if (cVar2 != *(char *)(unaff_A4 + -0x4689)) {
    if ((char)(cVar2 - *(char *)(unaff_A4 + -0x4689)) < '\0') {
      *(char *)(unaff_A4 + -0x4689) = *(char *)(unaff_A4 + -0x4689) + -1;
    } else {
      *(char *)(unaff_A4 + -0x4689) = *(char *)(unaff_A4 + -0x4689) + '\x01';
    }
  }
  FUN_00024884();
  FUN_00024848();
  FUN_000248c4();
  if ((*(byte *)((int)&component_unknown_9 + unaff_A4) & 2) == 0) {
    cVar2 = FUN_00024564();
    iVar4 = (int)(short)unaff_A4;
    sVar3 = 4;
    do {
      pcVar1 = (char *)(iVar4 + -0x4689);
      iVar4 = iVar4 + 8;
      if (cVar2 != *pcVar1) {
        return;
      }
      sVar3 = sVar3 + -1;
    } while (sVar3 != -1);
  }
  return;
}

void FUN_000245ae(void)

{
  undefined1 uVar1;
  short unaff_D2w;
  undefined *puVar2;
  short unaff_A4w;
  entity_id_t e;
  anim_item_t *unaff_A5;
  ushort uStack_6;
  short sStack_4;

  sStack_4 = -1;
  uStack_6 = 0;
  do {
    FUN_0000147a((func *)0x2464c, 0, 4);
    if (unaff_D2w < 0) {
      FUN_0002465e();
      return;
    }
    e = (entity_id_t)unaff_D2w;
    *(undefined1 *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + e) = 0xff;
    if (sStack_4 < 0) {
      *(short *)(&comp_unk_2 + unaff_A4w) = unaff_D2w;
    } else {
      *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + (int)sStack_4) =
          unaff_D2w;
    }
    entity_reset(e);
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x18;
    (&comp_state_a)[e] = 0x80;
    *(undefined2 *)(&comp_anim_base_offset + e) =
        *(undefined2 *)(&comp_anim_base_offset + unaff_A4w);
    puVar2 = &UNK_00024658;
    if ((*(byte *)((int)&component_unknown_9 + (int)unaff_A4w) & 1) != 0) {
      puVar2 = &UNK_00024652;
    }
    ecs_anim_unk_2(e, unaff_A5, puVar2[(short)uStack_6]);
    (&comp_has_func_maybe)[e] = (&comp_has_func_maybe)[e] | 8;
    uStack_6 = uStack_6 + 1;
    sStack_4 = unaff_D2w;
  } while (uStack_6 < 6);
  uVar1 = 0x28;
  if ((*(byte *)((int)&component_unknown_9 + (int)unaff_A4w) & 4) != 0) {
    uVar1 = 0x58;
  }
  (&DAT_ffffb976)[*(short *)(&comp_unk_2 + unaff_A4w)] = uVar1;
  return;
}

void FUN_0002465e(void)

{
  short sVar1;
  int unaff_A4;

  for (sVar1 = *(short *)(&comp_unk_2 + unaff_A4); -1 < sVar1;
       sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 +
                          (int)sVar1)) {
    (&comp_has_func_maybe)[sVar1] = 0;
  }
  (&comp_unk_2)[unaff_A4] = 0xff;
  return;
}

void FUN_00024678(void)

{
  short sVar1;
  word wVar2;
  int extraout_A0;
  int iVar3;
  short *psVar4;
  int unaff_A4;
  short *psVar5;

  wVar2 = angle_sin((&DAT_ffffb976)[*(short *)(&comp_unk_2 + unaff_A4)]);
  FUN_000026e4();
  psVar4 = (short *)&UNK_000246c2;
  iVar3 = extraout_A0;
  while (true) {
    psVar5 = psVar4 + 1;
    sVar1 = *psVar4;
    *(short *)((int)&comp_pos_x + iVar3) =
        *(short *)((int)&comp_pos_x + unaff_A4) +
        (short)((uint)((int)sVar1 * (int)(short)wVar2) >> 0x10);
    sVar1 = *(short *)((int)&comp_pos_y + unaff_A4) +
            (short)((uint)((int)sVar1 * (int)(short)wVar2) >> 0x10);
    psVar4 = psVar4 + 2;
    if (0x10af < (ushort)(*psVar5 + sVar1)) {
      sVar1 = sVar1 - (*psVar5 + sVar1 + 0xef50U);
    }
    *(short *)((int)&comp_pos_y + iVar3) = sVar1;
    sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + iVar3);
    if (sVar1 < 0)
      break;
    iVar3 = (int)sVar1;
  }
  return;
}

undefined4 FUN_0002470c(entity_id_t self)

{
  byte bVar1;
  byte bVar2;
  byte bVar3;
  int iVar4;
  undefined1 uVar5;
  undefined1 uVar6;

  if ((*(byte *)((int)&comp_state + (int)DAT_ffffdb42) & 0x7f) != 0) {
    uVar6 = 0;
    uVar5 = (&comp_unk_11)[DAT_ffffdb42] == '\0';
    if ((bool)uVar5) {
      FUN_000189d0();
    } else {
      FUN_000189fe();
    }
    FUN_00000ed6(self, ENTITY_ID_ASHA);
    if ((bool)uVar6 || (bool)uVar5) {
      FUN_00002124(self, 2);
      (&comp_func_offset[0].unk4)[self] = (&comp_func_offset[0].unk4)[self] | 2;
    } else {
      (&comp_func_offset[0].unk4)[self] =
          (&comp_func_offset[0].unk4)[self] & 0xfd;
    }
    if (((&comp_func_offset[0].unk4)[self] & 1) != 0) {
      audio_play(SOUND_ID_DAMAGE_2);
      bVar3 = DAT_ffffde0e;
      if (((&comp_func_offset[0].unk4)[self] & 4) != 0) {
        bVar3 = DAT_ffffde0f;
      }
      iVar4 = (int)DAT_ffffdb42;
      if ((&comp_unk_11)[iVar4] == '\0') {
        bVar1 = (&comp_collected_item_id_maybe)[iVar4];
        bVar2 = bVar1 - bVar3;
        (&comp_collected_item_id_maybe)[iVar4] = bVar2;
        if (bVar1 < bVar3 || bVar2 == 0) {
          *(undefined1 *)((int)&comp_state + iVar4) = 2;
        } else {
          (&comp_unk_11)[iVar4] = 0x1e;
          *(undefined1 *)((int)&comp_state + self) = 2;
          if (((DAT_ffffdb40 & 1) == 0) &&
              ((&comp_collected_item_id_maybe)[iVar4] <= DAT_ffffdb59)) {
            DAT_ffffdb40 = DAT_ffffdb40 | 1;
            (&comp_collision_related)[iVar4] = 0;
            DAT_ffffdb41 = 0x14;
            DAT_ffff9808 = 0xff;
          }
        }
        return 0xffffffff;
      }
    }
  }
  return 0;
}

void FUN_000247bc(void)

{
  ushort uVar1;
  byte bVar2;
  short sVar3;
  int unaff_A4;
  int iVar4;

  uVar1 = 0;
  sVar3 = *(short *)(&DAT_ffffbe78 + unaff_A4);
  do {
    iVar4 = unaff_A4;
    if (-1 < sVar3) {
      bVar2 = (&UNK_000247ea)[(short)uVar1];
      if ((byte)sVar3 <= (byte)(&UNK_000247ea)[(short)uVar1]) {
        bVar2 = (byte)sVar3;
      }
      (&DAT_ffffb978)[iVar4] = bVar2;
      sVar3 = sVar3 + -1;
    }
    uVar1 = uVar1 + 1;
    unaff_A4 = iVar4 + 8;
  } while (uVar1 < 5);
  *(short *)(iVar4 + -0x41a8) = *(short *)(iVar4 + -0x41a8) + 1;
  return;
}

void FUN_000247f0(void)

{
  char cVar1;
  char extraout_D1b;
  char extraout_D1b_00;
  short sVar2;
  int unaff_A4;

  if (((*(byte *)((int)&component_unknown_9 + unaff_A4) & 2) != 0) ||
      (0x3f < (ushort)((comp_pos_x.fixed.i + 0x20) -
                       *(short *)((int)&comp_pos_x + unaff_A4)))) {
    FUN_0002486c();
    FUN_0002486c();
    FUN_0002486c();
    FUN_0002486c();
    FUN_0002486c();
    *(byte *)((int)&component_unknown_9 + unaff_A4) =
        *(byte *)((int)&component_unknown_9 + unaff_A4) | 2;
    if (extraout_D1b_00 == '\0') {
      *(byte *)((int)&component_unknown_9 + unaff_A4) =
          *(byte *)((int)&component_unknown_9 + unaff_A4) & 0xfd;
    }
    return;
  }
  FUN_0002486c();
  sVar2 = 2;
  do {
    cVar1 = FUN_0002486c();
    if (extraout_D1b != '\0') {
      return;
    }
    sVar2 = sVar2 + -1;
  } while (sVar2 != -1);
  if (cVar1 == '\f') {
    if ((&DAT_ffffb996)[unaff_A4] == '\b') {
      *(byte *)((int)&component_unknown_9 + unaff_A4) =
          *(byte *)((int)&component_unknown_9 + unaff_A4) | 2;
    }
    return;
  }
  sVar2 = (short)unaff_A4;
  if ((&DAT_ffffb976)[sVar2] != '\f') {
    if ((char)('\f' - (&DAT_ffffb976)[sVar2]) < '\0') {
      (&DAT_ffffb976)[sVar2] = (&DAT_ffffb976)[sVar2] + -1;
    } else {
      (&DAT_ffffb976)[sVar2] = (&DAT_ffffb976)[sVar2] + '\x01';
    }
  }
  return;
}

void FUN_00024848(void)

{
  char extraout_D1b;
  int unaff_A4;

  FUN_0002486c();
  FUN_0002486c();
  FUN_0002486c();
  FUN_0002486c();
  FUN_0002486c();
  *(byte *)((int)&component_unknown_9 + unaff_A4) =
      *(byte *)((int)&component_unknown_9 + unaff_A4) | 2;
  if (extraout_D1b == '\0') {
    *(byte *)((int)&component_unknown_9 + unaff_A4) =
        *(byte *)((int)&component_unknown_9 + unaff_A4) & 0xfd;
  }
  return;
}

void FUN_0002486c(void)

{
  char in_D0b;
  int in_A0;

  if (in_D0b != (&DAT_ffffb976)[in_A0]) {
    if ((char)(in_D0b - (&DAT_ffffb976)[in_A0]) < '\0') {
      (&DAT_ffffb976)[in_A0] = (&DAT_ffffb976)[in_A0] + -1;
    } else {
      (&DAT_ffffb976)[in_A0] = (&DAT_ffffb976)[in_A0] + '\x01';
    }
  }
  return;
}

void FUN_00024884(void)

{
  char cVar1;
  char cVar2;
  short sVar3;
  int iVar4;
  int unaff_A4;

  cVar2 = (&DAT_ffffb979)[unaff_A4];
  (&DAT_ffffb979)[unaff_A4] = *(undefined1 *)(unaff_A4 + -0x4689);
  iVar4 = unaff_A4 + 8;
  sVar3 = 3;
  do {
    cVar1 = *(char *)(iVar4 + -0x4689);
    if (cVar2 != cVar1) {
      if ((char)(cVar2 - cVar1) < '\0') {
        *(char *)(iVar4 + -0x4689) = *(char *)(iVar4 + -0x4689) + -1;
      } else {
        *(char *)(iVar4 + -0x4689) = *(char *)(iVar4 + -0x4689) + '\x01';
      }
    }
    cVar2 = (&DAT_ffffb979)[iVar4];
    (&DAT_ffffb979)[iVar4] = *(undefined1 *)(iVar4 + -0x3e87);
    *(undefined *)(iVar4 + -0x3e87) = (&comp_unk_5)[iVar4];
    (&comp_unk_5)[iVar4] = cVar1;
    iVar4 = iVar4 + 8;
    sVar3 = sVar3 + -1;
  } while (sVar3 != -1);
  return;
}

void FUN_000248c4(void)

{
  short sVar1;
  short extraout_D1w;
  short extraout_D1w_00;
  word wVar2;
  int unaff_A4;
  int iVar3;

  DAT_ffffdb54 = DAT_ffffdb50 + *(short *)(&DAT_ffffbc76 + unaff_A4);
  DAT_ffffdb56 = DAT_ffffdb52 + *(short *)(&DAT_ffffbc78 + unaff_A4);
  DAT_ffffdb58 = 0;
  DAT_ffffdb5a = 5;
  iVar3 = unaff_A4 + 0x28;
  do {
    DAT_ffffdb58 = DAT_ffffdb58 + *(char *)(iVar3 + -0x4692);
    wVar2 = angle_sin(DAT_ffffdb58);
    sVar1 = DAT_ffffdb56 +
            (short)((uint)((int)(short)wVar2 * (int)extraout_D1w * 4) >> 0x10);
    DAT_ffffdb56 = sVar1;
    *(short *)(iVar3 + -0x5de2) = sVar1;
    FUN_000026e4();
    FUN_000026e4();
    DAT_ffffdb54 = DAT_ffffdb54 +
                   (short)((uint)((int)sVar1 * (int)extraout_D1w_00) >> 0x10);
    *(short *)(iVar3 + -0x5ee6) = DAT_ffffdb54;
    DAT_ffffdb5a = DAT_ffffdb5a + -1;
    iVar3 = iVar3 + -8;
  } while (DAT_ffffdb5a != 0);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002493e(void)

{
  undefined2 in_D0w;
  int unaff_A4;

  *(undefined2 *)(&DAT_ffffbc76 + unaff_A4) = in_D0w;
  *(undefined2 *)(&DAT_ffffbc78 + unaff_A4) = 0xffdc;
  *(undefined2 *)(&DAT_ffffbe78 + unaff_A4) = 0;
  *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x18;
  FUN_00024980();
  FUN_0002497e();
  FUN_0002497e();
  FUN_0002497e();
  FUN_0002497e();
  *(undefined1 *)(unaff_A4 + -0x4692) = 0xdc;
  FUN_000248c4();
  (&comp_has_func_maybe)[_DAT_ffffdb46] = 0;
  return;
}

void FUN_0002497e(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&DAT_ffffb978)[unaff_A4] = 0;
  *(undefined1 *)(unaff_A4 - 0x4689) = DAT_ffffdb58;
  (&DAT_ffffb976)[unaff_A4] = 8;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x1a;
  (&comp_state_a)[unaff_A4] = 0x80;
  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] & 0xf7;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  return;
}

void FUN_00024980(void)

{
  byte in_D0b;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&DAT_ffffb978)[unaff_A4] = 0;
  *(undefined1 *)(unaff_A4 - 0x4689) = DAT_ffffdb58;
  (&DAT_ffffb976)[unaff_A4] = 8;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x1a;
  (&comp_state_a)[unaff_A4] = 0x80;
  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] & 0xf7;
  ecs_anim_unk_2(unaff_A4, unaff_A5, in_D0b);
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_000249ac(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_000249be(void)

{
  short sVar1;
  byte bVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    (&comp_state_a)[unaff_A4] = 0x80;
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 6;
    ecs_clear_x_vel_round_up_pos(unaff_A4);
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    sVar1 = *(short *)(&comp_unk_5 + unaff_A4);
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) =
        *(undefined2 *)(&UNK_00024a1c + (short)(sVar1 << 2));
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) =
        *(undefined2 *)(&UNK_00024a1e + (short)(sVar1 << 2));
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x14;
    if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    }
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_ATTACKING_MID_AIR;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  player_update_pos(unaff_A4);
  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_00024a2c(void)

{
  short *psVar1;
  byte bVar2;
  entity_state_1_b_t eVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    audio_play(SOUND_ID_CRYS_FLASH);
    (&comp_collision_related)[unaff_A4] = 0;
    eVar3 = ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
  ecs_anim_unk_2:
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = eVar3;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  if ((&comp_collision_related)[unaff_A4] == '\0') {
    if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
      eVar3 = ECS_STATE_1_B_TALKING_OR_ENTERING_BACK_DOOR;
      goto ecs_anim_unk_2;
    }
  } else {
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + -4;
    FUN_000025b0();
    ecs_update_pos_y(unaff_A4);
    if (*(ushort *)((int)&comp_pos_y + unaff_A4) < 0xff0) {
      FUN_00015e86();
      *(undefined1 *)((int)&DAT_ffffdb60 +
                      (int)(short)(*(short *)(&comp_unk_5 + unaff_A4) * 2)) =
          0xff;
      (&comp_has_func_maybe)[unaff_A4] = 0;
    }
  }
  return;
}

void FUN_00024a8e(void)

{
  byte bVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  if (*(ushort *)((int)&comp_pos_x + unaff_A4) <= (ushort)comp_pos_x.fixed.i) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    return;
  }
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  return;
}

void FUN_00024aa8(void)

{
  byte bVar1;
  short sVar2;
  word wVar3;
  angle_t unaff_D4b;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    FUN_00002678();
    FUN_00002782();
    (&DAT_ffffb976)[unaff_A4] = unaff_D4b;
    wVar3 = angle_sin(unaff_D4b);
    sVar2 = ((short)wVar3 >> 6) + ((short)wVar3 >> 5);
    *(short *)((int)&comp_vel[0].y + unaff_A4) = sVar2;
    FUN_000026e4();
    *(short *)((int)&comp_vel[0].x + unaff_A4) = (sVar2 >> 6) + (sVar2 >> 5);
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x10;
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  player_update_pos(unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
  if (sVar2 == 0) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

void FUN_00024b6a(void)

{
  byte bVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  }
  FUN_00001fd2();
  FUN_000021e2(unaff_A4);
  ecs_sprite_face_asha(unaff_A4);
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    FUN_000023a0();
    *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  }
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_00024b9a(void)

{
  entity_id_t unaff_A4;

  ecs_jump_table(unaff_A4);
  // WARNING: Bad instruction - Truncating control flow here
  halt_baddata();
}

void FUN_00024baa(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_00001980();
  (&comp_state_a)[unaff_A4] = 0x80;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 6;
  ecs_clear_x_vel_round_up_pos(unaff_A4);
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_pos_y + unaff_A4) -
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
  ecs_sprite_face_asha(unaff_A4);
  return;
}

char FUN_00024bb2(void)

{
  byte bVar1;
  short sVar2;
  char in_D0b;
  char cVar3;
  int unaff_A4;
  bool bVar4;

  bVar1 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar1 | 0x80;
  if ((bVar1 & 0x80) == 0) {
    (&comp_collision_related)[unaff_A4] = 0;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x3c;
    return in_D0b;
  }
  cVar3 = (&comp_collision_related)[unaff_A4];
  bVar4 = cVar3 == '\0';
  if (bVar4) {
    cVar3 = FUN_000022de();
    if ((!bVar4) && (sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1,
                     *(short *)(&comp_unk_4 + unaff_A4) = sVar2,
                     sVar2 == 0)) {
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] + '\x01';
      *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
      DAT_ffffcc92 = 2;
      DAT_ffffcc93 = 0;
      DAT_ffffd916 = 0xd0;
      return cVar3;
    }
  } else {
    sVar2 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar2;
    if (sVar2 == 0) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 5;
    }
  }
  return cVar3;
}

void FUN_00024c02(void)

{
  short *psVar1;
  byte bVar2;
  short sVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar2 = *(byte *)((int)&comp_state + unaff_A4);
  *(byte *)((int)&comp_state + unaff_A4) = bVar2 | 0x80;
  if ((bVar2 & 0x80) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfb00;
  }
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar3 = *psVar1 + 0x40;
  *psVar1 = sVar3;
  if (-1 < sVar3) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & 0x7f;
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x1e;
  }
  ecs_update_pos_y(unaff_A4);
  if ((ushort)(*(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
               DAT_ffffce0a) < *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    DAT_ffffdb40 = DAT_ffffdb40 | 0x80;
    DAT_ffffcc85 = 0;
    FUN_00015e86();
    (&comp_has_func_maybe)[unaff_A4] = 0;
    if (UNION_sound_id_word_union_t_ffff97e6.as_word != 9) {
      UNION_sound_id_word_union_t_ffff97e6.as_word = 0xffff;
      audio_stop_all();
      UNION_sound_id_word_union_t_ffff97e6.as_word = 9;
      audio_play(SOUND_ID_KOOL_DUDE);
    }
    return;
  }
  return;
}

void ecs_unk_1(entity_id_t self)

{
  char cVar2;
  word wVar1;
  byte *extraout_A0;
  byte *pbVar3;

  if (((((&comp_unk_10)[self] & 0x40) == 0) &&
       (((*(short *)((int)&comp_unk_8 + self) < 0 ||
          (((&DAT_ffffcf9c)[*(short *)((int)&comp_unk_8 + self)] & 4) == 0)) &&
         (cVar2 = ecs_unk_3(self, 4), -1 < cVar2)))) &&
      ((cVar2 != '\f' || (DAT_ffffcbb2 != 0xc)))) {
    wVar1 = rand();
    for (pbVar3 = extraout_A0; *pbVar3 < (byte)(wVar1 >> 1);
         pbVar3 = pbVar3 + 2) {
    }
  }
  return;
}

void ecs_collect_or_spawn_item_maybe(int16_t pos_x, int16_t pos_y,
                                     byte item_id_maybe)

{
  entity_id_w_t self_w;
  byte extraout_D1b;
  int extraout_A0;
  entity_id_t self;

  self_w = ecs_find_some_entity_with_func();
  if (-1 < (short)self_w) {
    self = (entity_id_t)(short)self_w;
    *(int16_t *)((int)&comp_pos_x + self) = pos_x;
    *(int16_t *)((int)&comp_pos_y + self) = pos_y;
    entity_reset(self);
    (&comp_has_func_maybe)[(short)self_w] = 0x80;
    (&comp_func_offset[0].func_offset_from_15ede)[(short)self_w] = 8;
    if ((item_id_maybe == 0x38) && (0xe < blue_hearts)) {
      item_id_maybe = 0x36;
    }
    (&comp_collected_item_id_maybe)[(short)self_w] = item_id_maybe;
    FUN_00024da0();
    (&comp_func_offset[0].unk1)[extraout_A0] = extraout_D1b;
  }
  return;
}

void FUN_00024d78(void)

{
  byte extraout_D1b;
  byte unaff_D5b;
  int in_A0;
  int extraout_A0;

  (&comp_has_func_maybe)[in_A0] = 0x80;
  (&comp_func_offset[0].func_offset_from_15ede)[in_A0] = 8;
  if ((unaff_D5b == 0x38) && (0xe < blue_hearts)) {
    unaff_D5b = 0x36;
  }
  (&comp_collected_item_id_maybe)[in_A0] = unaff_D5b;
  FUN_00024da0();
  (&comp_func_offset[0].unk1)[extraout_A0] = extraout_D1b;
  return;
}

void FUN_00024da0(void)

{
  return;
}

void FUN_00024dea(void)

{
  component_state_b_t cVar1;
  entity_state_a_t eVar2;
  int unaff_A4;

  cVar1 = (&comp_has_func_maybe)[unaff_A4];
  (&comp_has_func_maybe)[unaff_A4] = cVar1 | 0x40;
  if ((cVar1 & 0x40) == 0) {
    FUN_000019ae();
    *(undefined2 *)((int)&comp_anim_speed + unaff_A4) = 0x100;
    eVar2 = 0;
    if (DAT_ffffcc28 != '\0') {
      eVar2 = 0x80;
    }
    (&comp_state_a)[unaff_A4] = eVar2;
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 4;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0;
  }
  // WARNING: Could not recover jumptable at 0x00024e1e. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00024e22 +
             (int)*(short *)((int)&WORD_00024e22 +
                             (int)(short)(ushort)(&comp_func_offset[0]
                                                       .unk3)[unaff_A4])))();
  return;
}

void FUN_00024e52(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x00024e5c. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00024e60 +
             (int)*(short *)((int)&WORD_00024e60 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  return;
}

void ecs_goes_up_somehow(entity_id_t self, entity_id_t other)

{
  *(short *)(&DAT_ffffbc76 + self) = *(short *)((int)&comp_pos_y + self) + -4;
  ecs_anim_unk_2(self, (anim_item_t *)other, 0);
  *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + self) = 0xfc00;
  audio_play(SOUND_ID_ITEM_EXIST);
  *(char *)((int)&comp_state + self) =
      *(char *)((int)&comp_state + self) + '\x02';
  return;
}

void FUN_00024e90(void)

{
  short *psVar1;
  int unaff_A4;

  if ((-1 < *(short *)((int)&comp_vel[0].y + unaff_A4)) &&
      (*(ushort *)(&DAT_ffffbc76 + unaff_A4) <
       *(ushort *)((int)&comp_pos_y + unaff_A4))) {
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x02';
  }
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x40;
  *(int *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
      *(int *)((int)&comp_pos_y + unaff_A4);
  return;
}

void FUN_00024eae(void)

{
  entity_id_t unaff_A4;
  undefined1 in_ZF;

  FUN_00024ef2();
  ecs_update_pos_y(unaff_A4);
  FUN_00002408();
  if (!(bool)in_ZF) {
    FUN_00002420();
    (&comp_collision_related)[unaff_A4] = 0x78;
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x02';
    return;
  }
  return;
}

void FUN_00024eca(void)

{
  char cVar1;
  int unaff_A4;

  FUN_00024ef2();
  cVar1 = (&comp_collision_related)[unaff_A4] + -1;
  (&comp_collision_related)[unaff_A4] = cVar1;
  if (cVar1 == '\0') {
    *(undefined2 *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4) =
        0x78;
    FUN_0000231c();
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x02';
    return;
  }
  return;
}

void FUN_00024ee4(void)

{
  char cVar1;
  int unaff_A4;

  FUN_00024ef2();
  cVar1 = (&comp_collision_related)[unaff_A4] + -1;
  (&comp_collision_related)[unaff_A4] = cVar1;
  if (cVar1 == '\0') {
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

void FUN_00024ef2(void)

{
  entity_id_t unaff_A4;
  undefined1 in_ZF;
  undefined1 in_CF;

  FUN_00000ed6(unaff_A4, ENTITY_ID_ASHA);
  if ((bool)in_CF || (bool)in_ZF) {
    play_sound_item_or_heart_collected(unaff_A4);
  }
  return;
}

void play_sound_item_or_heart_collected(entity_id_t self)

{
  sound_id_t sound_id;

  sound_id = SOUND_ID_GET_MEAT;
  if (((&comp_collected_item_id_maybe)[self] != 0x36) &&
      ((&comp_collected_item_id_maybe)[self] != 0x37)) {
    sound_id = SOUND_ID_ITEM_GET;
  }
  audio_play(sound_id);
  FUN_0000185e();
  (&comp_has_func_maybe)[self] = 0;
  FUN_00029824();
  return;
}

void FUN_00024f30(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x00024f3a. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00024f3e +
             (int)*(short *)((int)&WORD_00024f3e +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  return;
}

void FUN_00024f48(entity_id_t self, entity_id_t other)

{
  *(short *)(&DAT_ffffbc76 + self) = *(short *)((int)&comp_pos_y + self) + -4;
  ecs_anim_unk_2(self, (anim_item_t *)other, 0);
  (&comp_has_func_maybe)[self] = (&comp_has_func_maybe)[self] | 0x20;
  *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + self) = 0xfc00;
  audio_play(SOUND_ID_ITEM_EXIST);
  *(char *)((int)&comp_state + self) =
      *(char *)((int)&comp_state + self) + '\x02';
  return;
}

void FUN_00024f74(void)

{
  short sVar1;
  short *psVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  sVar1 = *(short *)((int)&comp_vel[0].y + unaff_A4);
  if (sVar1 < 0) {
    if ((-0x81 < sVar1) &&
        ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_WALKING_OR_DOWNSTAB)) {
      ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
    }
  } else if ((-1 < *(short *)((int)&comp_vel[0].y + unaff_A4)) &&
             (*(ushort *)(&DAT_ffffbc76 + unaff_A4) <
              *(ushort *)((int)&comp_pos_y + unaff_A4))) {
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x02';
  }
  psVar2 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar2 = *psVar2 + 0x40;
  *(int *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
      *(int *)((int)&comp_pos_y + unaff_A4);
  return;
}

void FUN_00024fac(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 in_ZF;

  FUN_00024ef2();
  ecs_update_pos_y(unaff_A4);
  FUN_00002408();
  if (!(bool)in_ZF) {
    FUN_00002420();
    ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
    (&comp_collision_related)[unaff_A4] = 0x78;
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x02';
  }
  return;
}

short FUN_00024fd0(void)

{
  short sVar1;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar2;
  undefined1 uVar3;
  undefined6 uVar4;

  uVar2 = *(char *)((int)&comp_state + unaff_A4) == '\0';
  uVar3 = 0;
  if ((bool)uVar2) {
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x01';
    *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    sVar1 = *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) - sVar1;
    return sVar1;
  }
  FUN_00002272();
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  uVar4 = FUN_00000ed6(unaff_A4, ENTITY_ID_ASHA);
  sVar1 = (short)((uint6)uVar4 >> 0x20);
  if ((bool)uVar3 || (bool)uVar2) {
    FUN_00029824();
    sVar1 = FUN_0000185e();
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return sVar1;
}

void FUN_00025012(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x0002501c. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00025020 +
             (int)*(short *)((int)&WORD_00025020 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  return;
}

void FUN_00025028(entity_id_t self, entity_id_t other)

{
  word wVar1;
  ushort uVar2;

  audio_play(SOUND_ID_ITEM_EXIST);
  *(char *)((int)&comp_state + self) =
      *(char *)((int)&comp_state + self) + '\x02';
  wVar1 = rand();
  uVar2 = wVar1 & 0x1ff;
  if (0xff < uVar2) {
    uVar2 = uVar2 | 0xff00;
  }
  *(ushort *)((int)&comp_vel[0].x + self) = uVar2;
  *(undefined2 *)((int)&comp_vel[0].y + self) = 64000;
  (&comp_collision_related)[self] = 0x1e;
  (&comp_has_func_maybe)[self] = (&comp_has_func_maybe)[self] | 0x20;
  if (self == ENTITY_ID_PEPELOGOO) {
    BYTE_ffffc709 = 0;
  }
  if (self == ENTITY_ID_ASHA) {
    BYTE_ffffc70a = 0;
  }
  (&comp_state_1_a)[self] = 0;
  (&comp_anim_c)[self] = 0;
  ecs_anim_unk_1(self, (anim_item_t *)other);
  (&comp_has_func_maybe)[self] =
      (&comp_has_func_maybe)[self] | COMPONENT_STATE_B_C0;
  return;
}

void FUN_00025060(void)

{
  short *psVar1;
  short sVar2;
  short sVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar4;

  FUN_000250f2(unaff_A4);
  if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
    FUN_00002272();
    sVar2 = *(short *)((int)&comp_vel[0].y + unaff_A4);
    FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
    bVar4 = sVar2 == 0;
    FUN_00002248();
    if (!bVar4) {
      sVar3 = *(short *)((int)&comp_vel[0].x + unaff_A4);
      if ((sVar3 != 0) && (sVar3 = sVar3 >> 2, sVar3 == 0)) {
        sVar3 = 1;
      }
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 - sVar3;
      sVar2 = -((sVar2 >> 2) + (sVar2 >> 1));
      if ((*(short *)((int)&comp_vel[0].x + unaff_A4) == 0) &&
          (-0x101 < sVar2)) {
        *(char *)((int)&comp_state + unaff_A4) =
            *(char *)((int)&comp_state + unaff_A4) + '\x02';
        *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
        *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x3c;
        if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
          BYTE_ffffc709 = 0;
        }
        if (unaff_A4 == ENTITY_ID_ASHA) {
          BYTE_ffffc70a = 0;
        }
        (&comp_state_1_a)[unaff_A4] = 0;
        (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
        ecs_anim_unk_1(unaff_A4, unaff_A5);
        (&comp_has_func_maybe)[unaff_A4] =
            (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
        return;
      }
      *(short *)((int)&comp_vel[0].y + unaff_A4) = sVar2;
    }
  }
  return;
}

void FUN_000250be(void)

{
  short sVar1;
  short unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;

  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x02';
    FUN_0000231c();
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x3c;
  }
  FUN_000250f2(unaff_A4);
  if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
    FUN_00002272();
    entity_update_pos(unaff_A4);
    interact_with_all_other_entities(unaff_A4, unaff_D2w, (char)unaff_D3w);
    ecs_update_collision(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
    ecs_apply_collision(unaff_A4);
    return;
  }
  return;
}

void FUN_000250d6(void)

{
  short sVar1;
  short unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;

  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
    return;
  }
  FUN_000250f2(unaff_A4);
  if ((char)(&comp_has_func_maybe)[unaff_A4] < '\0') {
    FUN_00002272();
    entity_update_pos(unaff_A4);
    interact_with_all_other_entities(unaff_A4, unaff_D2w, (char)unaff_D3w);
    ecs_update_collision(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
    ecs_apply_collision(unaff_A4);
    return;
  }
  return;
}

void FUN_000250f2(entity_id_t self)

{
  bool bVar1;
  bool bVar2;

  bVar2 = false;
  bVar1 = (&comp_collision_related)[self] == '\0';
  if (!bVar1) {
    (&comp_collision_related)[self] = (&comp_collision_related)[self] + -1;
    return;
  }
  FUN_00000ed6(self, ENTITY_ID_ASHA);
  if (bVar2 || bVar1) {
    FUN_00029824();
    audio_play(SOUND_ID_ITEM_GET);
    FUN_0000185e();
    (&comp_has_func_maybe)[self] = 0;
  }
  return;
}

void FUN_00025122(entity_id_t self)

{
  component_state_b_t cVar1;

  cVar1 = (&comp_has_func_maybe)[self];
  (&comp_has_func_maybe)[self] = cVar1 | 0x40;
  if ((cVar1 & 0x40) == 0) {
    *(undefined2 *)((int)&comp_unk_3 + self) = 0x16;
    *(undefined1 *)((int)&comp_state + self) = 0;
  }
  // WARNING: Could not recover jumptable at 0x00025140. Too many branches
  // WARNING: Treating indirect jump as call
  (**(code **)((int)&WORD_00025142 +
               (int)(short)((ushort)(&comp_func_offset[0].unk3)[self] * 2)))();
  return;
}

void FUN_00025144(void)

{
  entity_id_t unaff_A4;
  bool bVar1;
  bool bVar2;

  bVar2 = false;
  FUN_000186a0(unaff_A4);
  bVar1 = ((&comp_func_offset[0].unk4)[unaff_A4] & 8) == 0;
  if (bVar1) {
    FUN_000021c2(unaff_A4, bVar1, bVar2);
  }
  return;
}

void FUN_000251a6(void)

{
  entity_id_t unaff_A4;
  bool bVar1;
  undefined1 in_CF;

  FUN_000186a0(unaff_A4);
  bVar1 = ((&comp_func_offset[0].unk4)[unaff_A4] & 8) == 0;
  if (bVar1) {
    FUN_000021c2(unaff_A4, bVar1, (bool)in_CF);
  }
  return;
}

void FUN_000251c0(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x000251ca. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_000251ce +
             (int)*(short *)((int)&WORD_000251ce +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  return;
}

void FUN_000251d2(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x20;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  FUN_000022a2();
  *(char *)((int)&comp_state + unaff_A4) =
      *(char *)((int)&comp_state + unaff_A4) + '\x02';
  return;
}

void FUN_000251ec(void)

{
  entity_id_t unaff_A4;
  bool bVar1;
  undefined1 in_CF;

  FUN_0000246a();
  if ((bool)in_CF) {
    player_update_pos_x(unaff_A4);
    FUN_000186a0(unaff_A4);
    bVar1 = ((&comp_func_offset[0].unk4)[unaff_A4] & 8) == 0;
    if ((bVar1) && (FUN_000021c2(unaff_A4, bVar1, (bool)in_CF),
                    ((&comp_func_offset[0].unk4)[unaff_A4] & 2) == 0)) {
      return;
    }
    FUN_00025398();
  }
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

void FUN_0002521a(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x00025224. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00025228 +
             (int)*(short *)((int)&WORD_00025228 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  return;
}

void FUN_0002522e(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x20;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  FUN_000022a2();
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(char *)((int)&comp_state + unaff_A4) =
      *(char *)((int)&comp_state + unaff_A4) + '\x02';
  return;
}

void FUN_0002524c(void)

{
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar1;
  bool bVar2;

  bVar2 = FUN_00000eae(unaff_A4);
  if (bVar2) {
  LAB_00025290:
    (&comp_has_func_maybe)[unaff_A4] = 0;
    return;
  }
  entity_update_pos(unaff_A4);
  ecs_update_collision(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  ecs_apply_collision(unaff_A4);
  bVar2 = false;
  if (((&component_collision_flags)[unaff_A4] & 3) == 0) {
    FUN_000186a0(unaff_A4);
    bVar1 = ((&comp_func_offset[0].unk4)[unaff_A4] & 8) == 0;
    if (bVar1) {
      FUN_000021c2(unaff_A4, bVar1, bVar2);
      if (((&comp_func_offset[0].unk4)[unaff_A4] & 2) == 0) {
        return;
      }
      goto LAB_00025290;
    }
  }
  *(char *)((int)&comp_state + unaff_A4) =
      *(char *)((int)&comp_state + unaff_A4) + '\x02';
  if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
    BYTE_ffffc709 = 0;
  }
  if (unaff_A4 == ENTITY_ID_ASHA) {
    BYTE_ffffc70a = 0;
  }
  (&comp_state_1_a)[unaff_A4] = 0;
  (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
  ecs_anim_unk_1(unaff_A4, unaff_A5);
  (&comp_has_func_maybe)[unaff_A4] =
      (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
  return;
}

void FUN_00025296(void)

{
  int unaff_A4;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) != 0) {
    return;
  }
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

void FUN_0002529e(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x000252a8. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_000252ac +
             (int)*(short *)((int)&WORD_000252ac +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  return;
}

void FUN_000252b0(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x20;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  FUN_000022a2();
  *(char *)((int)&comp_state + unaff_A4) =
      *(char *)((int)&comp_state + unaff_A4) + '\x02';
  return;
}

void FUN_000252ca(void)

{
  entity_id_t unaff_A4;
  bool bVar1;
  undefined1 uVar2;

  uVar2 = FUN_00000eae(unaff_A4);
  if (!(bool)uVar2) {
    player_update_pos_x(unaff_A4);
    FUN_000186a0(unaff_A4);
    bVar1 = ((&comp_func_offset[0].unk4)[unaff_A4] & 8) == 0;
    if (bVar1) {
      FUN_000021c2(unaff_A4, bVar1, (bool)uVar2);
      bVar1 = ((&comp_func_offset[0].unk4)[unaff_A4] & 2) == 0;
      if ((bVar1) && (FUN_00002432(), bVar1)) {
        return;
      }
    }
    FUN_00025398();
  }
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

void FUN_000252fe(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x00025308. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0002530c +
             (int)*(short *)((int)&WORD_0002530c +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  return;
}

void FUN_00025312(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x20;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  *(short *)((int)&comp_unk_3 + unaff_A4) =
      *(short *)((int)&comp_unk_3 + unaff_A4) + 2;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(char *)((int)&comp_state + unaff_A4) =
      *(char *)((int)&comp_state + unaff_A4) + '\x02';
  return;
}

void FUN_0002532c(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar1;

  bVar1 = *(short *)((int)&comp_anim_tick + unaff_A4) == 0;
  if (bVar1) {
    *(short *)((int)&comp_unk_3 + unaff_A4) =
        *(short *)((int)&comp_unk_3 + unaff_A4) + -2;
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x02';
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  FUN_000021c2(unaff_A4, bVar1, false);
  if (((&comp_func_offset[0].unk4)[unaff_A4] & 2) != 0) {
    FUN_00025398();
    FUN_00015e86();
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

void FUN_00025340(void)

{
  short *psVar1;
  entity_id_t unaff_A4;
  undefined1 in_ZF;
  bool bVar2;
  undefined1 in_CF;

  ecs_update_pos_y(unaff_A4);
  FUN_00000ed6(unaff_A4, ENTITY_ID_PEPELOGOO);
  if ((bool)in_CF || (bool)in_ZF) {
    FUN_0002a8b6();
  } else {
    if (*(ushort *)((int)&comp_vel[0].y + unaff_A4) < 0x500) {
      psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
      *psVar1 = *psVar1 + 0x50;
    }
    bVar2 = (ushort)(DAT_ffffc746 + 0xe0U) ==
            *(ushort *)((int)&comp_pos_y + unaff_A4);
    if ((ushort)(DAT_ffffc746 + 0xe0U) <
        *(ushort *)((int)&comp_pos_y + unaff_A4))
      goto LAB_0002538c;
    FUN_00002408();
    if (bVar2) {
      if ((char)pepelogoo_state_b < '\0') {
        return;
      }
      FUN_000021c2(unaff_A4, pepelogoo_state_b == '\0', false);
      if (((&comp_func_offset[0].unk4)[unaff_A4] & 2) == 0) {
        return;
      }
    }
  }
  FUN_00025398();
LAB_0002538c:
  FUN_00015e86();
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

void FUN_00025398(void)

{
  entity_id_w_t unaff_D2w;
  int unaff_A4;
  byte *unaff_A5;

  FUN_0000165c((ushort *)FUN_000253b2,
               unaff_A5,
               unaff_D2w,
               *(short *)((int)&comp_pos_x + unaff_A4),
               *(short *)((int)&comp_pos_y + unaff_A4),
               0x80);
  return;
}

void FUN_000253a0(void)

{
  entity_id_w_t unaff_D2w;
  short unaff_D3w;
  short unaff_D4w;
  byte *unaff_A5;

  FUN_0000165c(
      (ushort *)FUN_000253b2, unaff_A5, unaff_D2w, unaff_D3w, unaff_D4w, 0x80);
  return;
}

void FUN_000253b2(void)

{
  undefined2 in_D0w;
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x000253c2. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_000253c6 +
             (int)*(short *)((int)&WORD_000253c6 +
                             (int)CONCAT11((char)((ushort)in_D0w >> 8),
                                           *(undefined1 *)((int)&comp_state +
                                                           unaff_A4)))))();
  return;
}

void FUN_000253d0(void)

{
  undefined2 uVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x20;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  uVar1 = 0x200;
  if (((&comp_unk_4)[unaff_A4] & 1) != 0) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    uVar1 = 0xfe00;
  }
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = uVar1;
  (&comp_collision_related)[unaff_A4] = 5;
  *(char *)((int)&comp_state + unaff_A4) =
      *(char *)((int)&comp_state + unaff_A4) + '\x02';
  return;
}

void FUN_00025400(void)

{
  char cVar1;
  ulong unaff_A4;

  player_update_pos_x(unaff_A4);
  cVar1 = (&comp_collision_related)[unaff_A4] + -1;
  (&comp_collision_related)[unaff_A4] = cVar1;
  if (cVar1 == '\0') {
    (&comp_collision_related)[unaff_A4] = 0x14;
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x02';
    return;
  }
  return;
}

void FUN_00025412(void)

{
  char cVar1;
  int unaff_A4;

  cVar1 = (&comp_collision_related)[unaff_A4] + -1;
  (&comp_collision_related)[unaff_A4] = cVar1;
  if (cVar1 != '\0') {
    return;
  }
  *(char *)((int)&comp_state + unaff_A4) =
      *(char *)((int)&comp_state + unaff_A4) + '\x02';
  return;
}

void FUN_0002541a(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar1;
  undefined1 uVar2;
  undefined1 in_CF;

  FUN_000186a0(unaff_A4);
  bVar1 = ((&comp_func_offset[0].unk4)[unaff_A4] & 8) == 0;
  if (bVar1) {
    FUN_000021c2(unaff_A4, bVar1, (bool)in_CF);
    uVar2 = ((&comp_func_offset[0].unk4)[unaff_A4] & 2) == 0;
    if ((bool)uVar2) {
      FUN_0000246a();
      if ((bool)in_CF) {
        player_update_pos_x(unaff_A4);
        FUN_00002432();
        if (!(bool)uVar2)
          goto ecs_anim_unk_2;
      } else {
        FUN_00015e86();
        (&comp_has_func_maybe)[unaff_A4] = 0;
      }
      return;
    }
  }
ecs_anim_unk_2:
  *(char *)((int)&comp_state + unaff_A4) =
      *(char *)((int)&comp_state + unaff_A4) + '\x02';
  if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
    BYTE_ffffc709 = 0;
  }
  if (unaff_A4 == ENTITY_ID_ASHA) {
    BYTE_ffffc70a = 0;
  }
  (&comp_state_1_a)[unaff_A4] = 0;
  (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
  ecs_anim_unk_1(unaff_A4, unaff_A5);
  (&comp_has_func_maybe)[unaff_A4] =
      (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
  return;
}

void FUN_0002544e(void)

{
  int unaff_A4;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    FUN_00025398();
    FUN_00015e86();
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

void FUN_00025464(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x0002546e. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00025472 +
             (int)*(short *)((int)&WORD_00025472 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  return;
}

void FUN_00025478(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x20;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  *(undefined2 *)(&comp_unk_4 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 64000;
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_pos_y + unaff_A4) + -8;
  (&comp_collision_related)[unaff_A4] = 0x14;
  *(char *)((int)&comp_state + unaff_A4) =
      *(char *)((int)&comp_state + unaff_A4) + '\x02';
  return;
}

void FUN_000254a0(void)

{
  char cVar1;
  int unaff_A4;

  cVar1 = (&comp_collision_related)[unaff_A4] + -1;
  (&comp_collision_related)[unaff_A4] = cVar1;
  if (cVar1 == '\0') {
    FUN_00025530();
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x02';
    return;
  }
  return;
}

void FUN_000254b2(void)

{
  ushort in_D0w;
  entity_state_1_b_t state_1_b;
  ushort uVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar2;
  undefined1 uVar3;

  if ((*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) ||
      (in_D0w = *(ushort *)(&comp_unk_4 + unaff_A4) -
                *(ushort *)((int)&comp_pos_y + unaff_A4),
       *(ushort *)((int)&comp_pos_y + unaff_A4) <=
           *(ushort *)(&comp_unk_4 + unaff_A4))) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & 0x7f;
    if (0x17 < in_D0w) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | 0x80;
    }
    ecs_update_pos_y(unaff_A4);
    state_1_b = ECS_STATE_1_B_JUMPING_OR_UNSHIELDING;
    uVar1 = *(short *)((int)&comp_vel[0].y + unaff_A4) + 0x30;
    *(ushort *)((int)&comp_vel[0].y + unaff_A4) = uVar1;
    if ((short)uVar1 < 0) {
      state_1_b = ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
      uVar1 = -uVar1;
    }
    if (uVar1 < 0x81) {
      state_1_b = 0;
    }
    uVar3 = state_1_b < (&comp_anim_c)[unaff_A4];
    uVar2 = state_1_b == (&comp_anim_c)[unaff_A4];
    if (!(bool)uVar2) {
      ecs_anim_unk_2(unaff_A4, unaff_A5, state_1_b);
    }
    FUN_00000ed6(unaff_A4, ENTITY_ID_PEPELOGOO);
    if ((bool)uVar3 || (bool)uVar2) {
      FUN_0002a8b6();
    } else {
      FUN_000021c2(unaff_A4, (bool)uVar2, (bool)uVar3);
      if (((&comp_func_offset[0].unk4)[unaff_A4] & 2) == 0) {
        return;
      }
    }
    FUN_00025398();
  } else {
    FUN_00025530();
  }
  FUN_00015e86();
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00025530(void)

{
  undefined2 uVar1;
  short sVar2;
  short unaff_D2w;
  entity_id_t e;
  int unaff_A4;
  anim_item_t *unaff_A5;

  uVar1 = *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  sVar2 = *(short *)(&comp_unk_4 + unaff_A4);
  FUN_0000147a(FUN_000016a6, 1, _FUN_00025544);
  do {
  } while (unaff_D2w < 0);
  e = (entity_id_t)unaff_D2w;
  entity_reset(e);
  (&comp_state_a)[e] = (&comp_state_a)[e];
  *(undefined2 *)((int)&comp_unk_7 + e) =
      *(undefined2 *)((int)&comp_unk_7 + unaff_A4);
  *(undefined2 *)((int)&comp_pos_x + e) = uVar1;
  *(short *)((int)&comp_pos_y + e) = sVar2 + -0xc;
  *(ushort *)((int)&comp_unk_3 + e) = (ushort)bRam00025546;
  (&comp_anim_base_offset)[e] = bRam00025547;
  (&comp_anim_b)[e] = bRam00025548;
  ecs_anim_unk_2(e, unaff_A5, bRam00025549);
  (&comp_has_func_maybe)[e] = (&comp_has_func_maybe)[e] | 0x20;
  return;
}

void FUN_00025544(void)

{
  undefined2 in_D0w;
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x00025554. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00025558 +
             (int)*(short *)((int)&WORD_00025558 +
                             (int)CONCAT11((char)((ushort)in_D0w >> 8),
                                           *(undefined1 *)((int)&comp_state +
                                                           unaff_A4)))))();
  return;
}

void FUN_0002555e(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x20;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | 0x80;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x500;
  *(char *)((int)&comp_state + unaff_A4) =
      *(char *)((int)&comp_state + unaff_A4) + '\x02';
  return;
}

void FUN_00025580(void)

{
  short extraout_D1w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 in_CF;

  FUN_00002456();
  if (!(bool)in_CF) {
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x02';
    *(short *)((int)&comp_pos_y + unaff_A4) =
        (extraout_D1w -
         *(short *)((int)&comp_collision_sensor[0].y + unaff_A4)) +
        0x18;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 8;
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = 0;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  *(int *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
      *(int *)((int)&comp_pos_y + unaff_A4);
  return;
}

void FUN_000255a6(void)

{
  short sVar1;
  entity_id_t unaff_A4;
  bool in_ZF;
  bool bVar2;
  bool in_CF;
  undefined1 uVar3;

  FUN_000021c2(unaff_A4, in_ZF, in_CF);
  if (((&comp_func_offset[0].unk4)[unaff_A4] & 2) == 0) {
    uVar3 = 0;
    bVar2 = *(short *)(&comp_unk_4 + unaff_A4) == 0;
    if (bVar2) {
      FUN_00002408();
      if (!bVar2)
        goto LAB_000255ce;
    } else {
      sVar1 = *(short *)(&comp_unk_4 + unaff_A4);
      uVar3 = sVar1 == 0;
      *(short *)(&comp_unk_4 + unaff_A4) = sVar1 + -1;
    }
    FUN_00002456();
    if ((bool)uVar3) {
      *(int *)((int)&comp_pos_y + unaff_A4) =
          *(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
          *(int *)((int)&comp_pos_y + unaff_A4);
      return;
    }
  } else {
  LAB_000255ce:
    FUN_00025398();
  }
  FUN_00015e86();
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

void FUN_000255de(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x000255e8. Too many branches
  // WARNING: Treating indirect jump as call
  (*(FUN_000255ec +
     *(short *)(FUN_000255ec +
                (short)(ushort) * (byte *)((int)&comp_state + unaff_A4))))();
  return;
}

void FUN_000255ec(entity_id_t self, entity_id_t other)

{
  short sVar1;

  (&comp_has_func_maybe)[self] = (&comp_has_func_maybe)[self] | 0x20;
  ecs_anim_unk_2(self, (anim_item_t *)other, 0);
  *(undefined2 *)((int)&comp_unk_3 + self) = 0x16;
  sVar1 = *(short *)(&comp_unk_4 + self);
  *(undefined2 *)((int)&comp_vel[0].x + self) =
      *(undefined2 *)(&UNK_00025658 + (short)(sVar1 << 2));
  *(undefined2 *)((int)&comp_vel[0].y + self) =
      *(undefined2 *)(&UNK_0002565a + (short)(sVar1 << 2));
  *(undefined2 *)(&comp_unk_4 + self) = 0x3c;
  *(char *)((int)&comp_state + self) =
      *(char *)((int)&comp_state + self) + '\x02';
  return;
}

void FUN_00025620(entity_id_t self)

{
  short *psVar1;
  short sVar2;
  bool bVar3;
  bool bVar4;

  bVar4 = FUN_00000eae(self);
  if (!bVar4) {
    FUN_000186a0(self);
    bVar3 = ((&comp_func_offset[0].unk4)[self] & 8) == 0;
    if ((bVar3) && (FUN_000021c2(self, bVar3, bVar4),
                    ((&comp_func_offset[0].unk4)[self] & 2) == 0)) {
      psVar1 = (short *)((int)&comp_vel[0].y + self);
      *psVar1 = *psVar1 + 0x40;
      entity_update_pos(self);
      sVar2 = *(short *)(&comp_unk_4 + self) + -1;
      *(short *)(&comp_unk_4 + self) = sVar2;
      if (sVar2 != 0) {
        return;
      }
    }
  }
  (&comp_has_func_maybe)[self] = 0;
  return;
}

void FUN_000256dc(void)

{
  entity_id_t unaff_A4;
  undefined1 in_ZF;
  bool bVar1;

  FUN_000251a6();
  if ((bool)in_ZF) {
    bVar1 = FUN_00000eae(unaff_A4);
    if (!bVar1) {
      *(int *)((int)&comp_pos_x + unaff_A4) =
          *(short *)((int)&comp_vel[0].x + unaff_A4) * 0x100 +
          *(int *)((int)&comp_pos_x + unaff_A4);
      *(int *)((int)&comp_pos_y + unaff_A4) =
          *(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
          *(int *)((int)&comp_pos_y + unaff_A4);
      return;
    }
  }
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

void FUN_000256f2(void)

{
  short *psVar1;
  byte bVar2;
  char cVar3;
  undefined1 uVar4;
  entity_id_t unaff_A4;
  undefined1 in_ZF;
  bool bVar5;

  FUN_000251a6();
  if ((bool)in_ZF) {
    bVar5 = FUN_00000eae(unaff_A4);
    if (!bVar5) {
      player_update_pos(unaff_A4);
      cVar3 = (&comp_unk_4)[unaff_A4] + -1;
      (&comp_unk_4)[unaff_A4] = cVar3;
      if (cVar3 == '\0') {
        uVar4 = 8;
        bVar2 = (&DAT_ffffb773)[unaff_A4];
        (&DAT_ffffb773)[unaff_A4] = bVar2 ^ 1;
        if ((bVar2 & 1) != 0) {
          uVar4 = 2;
        }
        (&comp_unk_4)[unaff_A4] = uVar4;
        psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
        *psVar1 = -*psVar1;
        (&comp_state_a)[unaff_A4] =
            (&comp_state_a)[unaff_A4] ^ ENTITY_STATE_A_H_FLIP;
      }
      return;
    }
  }
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

void FUN_00025724(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x0002572e. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00025732 +
             (int)*(short *)((int)&WORD_00025732 +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  return;
}

void FUN_00025738(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  *(undefined2 *)(&comp_has_func_maybe + unaff_A4) =
      *(undefined2 *)(&comp_has_func_maybe + unaff_A4) | 0x2880;
  *(char *)((int)&comp_state + unaff_A4) =
      *(char *)((int)&comp_state + unaff_A4) + '\x02';
  if (*(short *)(&comp_unk_4 + unaff_A4) != 0) {
    *(short *)(&comp_unk_4 + unaff_A4) =
        *(short *)(&comp_unk_4 + unaff_A4) + -1;
    return;
  }
  *(undefined2 *)(&comp_has_func_maybe + unaff_A4) =
      *(undefined2 *)(&comp_has_func_maybe + unaff_A4) & 0xf780;
  *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(char *)((int)&comp_state + unaff_A4) =
      *(char *)((int)&comp_state + unaff_A4) + '\x02';
  // WARNING: Could not recover jumptable at 0x0002576e. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00025772 +
             (int)*(
                 short *)((int)&WORD_00025772 +
                          (int)(short)((ushort)(byte)(&comp_collision_related)
                                           [unaff_A4] *
                                       2))))();
  return;
}

void FUN_0002577a(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  *(short *)((int)&comp_pos_x + unaff_A4) =
      DAT_ffffc73a - *(short *)((int)&comp_collision_sensor[0].x + unaff_A4);
  *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
      *(undefined2 *)(&DAT_ffffbe78 + unaff_A4);
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) =
      *(undefined2 *)(&comp_unk_1 + unaff_A4);
  return;
}

void FUN_0002579a(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
      *(undefined2 *)(&DAT_ffffbe78 + unaff_A4);
  *(short *)((int)&comp_pos_y + unaff_A4) =
      (DAT_ffffc746 + 0x18) -
      *(short *)((int)&comp_collision_sensor[0].x + unaff_A4);
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) =
      *(undefined2 *)(&comp_unk_1 + unaff_A4);
  return;
}

void FUN_000257be(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  *(short *)((int)&comp_pos_x + unaff_A4) =
      *(short *)((int)&comp_collision_sensor[0].x + unaff_A4) + DAT_ffffc73a +
      0x100;
  *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
      *(undefined2 *)(&DAT_ffffbe78 + unaff_A4);
  *(short *)((int)&comp_vel[0].x + unaff_A4) =
      -*(short *)(&comp_unk_1 + unaff_A4);
  return;
}

void FUN_000257ec(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_H_FLIP;
  *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
      *(undefined2 *)(&DAT_ffffbe78 + unaff_A4);
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_collision_sensor[0].x + unaff_A4) + DAT_ffffc746 +
      0xe8;
  *(short *)((int)&comp_vel[0].y + unaff_A4) =
      -*(short *)(&comp_unk_1 + unaff_A4);
  return;
}

void FUN_0002581a(void)

{
  short *psVar1;
  int unaff_A4;
  undefined1 in_ZF;

  FUN_000251a6();
  if (!(bool)in_ZF) {
    FUN_00025398();
    goto LAB_00025888;
  }
  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  if (*psVar1 == 0) {
    if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
      if ((ushort)((DAT_ffffc746 + 0x20) -
                   *(short *)((int)&comp_collision_sensor[0].y + unaff_A4)) <
          *(ushort *)((int)&comp_pos_y + unaff_A4))
        goto player_update_pos;
    } else if (*(ushort *)((int)&comp_pos_y + unaff_A4) <=
               (ushort)(*(short *)((int)&comp_collision_sensor[0].y +
                                   unaff_A4) +
                        DAT_ffffc746 + 0xe0))
      goto player_update_pos;
  } else if (*psVar1 < 0) {
    if ((ushort)(DAT_ffffc73a -
                 *(short *)((int)&comp_collision_sensor[0].x + unaff_A4)) <
        *(ushort *)((int)&comp_pos_x + unaff_A4))
      goto player_update_pos;
  } else if (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
             (ushort)(*(short *)((int)&comp_collision_sensor[0].x + unaff_A4) +
                      DAT_ffffc73a + 0x100)) {
  player_update_pos:
    *(int *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_vel[0].x + unaff_A4) * 0x100 +
        *(int *)((int)&comp_pos_x + unaff_A4);
    *(int *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
        *(int *)((int)&comp_pos_y + unaff_A4);
    return;
  }
LAB_00025888:
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

void FUN_0002588e(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x00025898. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0002589c +
             (int)*(short *)((int)&WORD_0002589c +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  return;
}

void FUN_000258a0(void)

{
  short *psVar1;
  byte bVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x20;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  bVar2 = (&comp_collision_related)[unaff_A4];
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) =
      *(undefined2 *)((int)&fixed_w_vec2_t_ARRAY_000258ec[0].x +
                      (int)(short)((ushort)bVar2 << 2));
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) =
      *(undefined2 *)((int)&fixed_w_vec2_t_ARRAY_000258ec[0].y +
                      (int)(short)((ushort)bVar2 << 2));
  if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = -*psVar1;
  }
  *(char *)((int)&comp_state + unaff_A4) =
      *(char *)((int)&comp_state + unaff_A4) + '\x02';
  return;
}

void FUN_000258d2(void)

{
  entity_id_t unaff_A4;
  undefined1 in_ZF;
  bool bVar1;

  bVar1 = FUN_00000eae(unaff_A4);
  if (!bVar1) {
    FUN_000251a6();
    if ((bool)in_ZF) {
      *(int *)((int)&comp_pos_x + unaff_A4) =
          *(short *)((int)&comp_vel[0].x + unaff_A4) * 0x100 +
          *(int *)((int)&comp_pos_x + unaff_A4);
      *(int *)((int)&comp_pos_y + unaff_A4) =
          *(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
          *(int *)((int)&comp_pos_y + unaff_A4);
      return;
    }
    FUN_00025398();
  }
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

void FUN_000258f8(void)

{
  short *psVar1;
  word wVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar3;

  bVar3 = *(char *)((int)&comp_state + unaff_A4) == '\0';
  if (bVar3) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0xff;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x20;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) =
        *(undefined2
              *)((int)&UNION_fixed_w_t_00025932 +
                 (int)(short)(ushort)(byte)(&comp_collision_related)[unaff_A4]);
    if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = -*psVar1;
    }
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 64000;
    (&comp_collision_related)[unaff_A4] = 0;
    return;
  }
  FUN_000021c2(unaff_A4, bVar3, false);
  if (((&comp_func_offset[0].unk4)[unaff_A4] & 2) == 0) {
    bVar3 = FUN_00000eae(unaff_A4);
    if (!bVar3) {
      player_update_pos(unaff_A4);
      if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
        FUN_00002256();
        psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
        *psVar1 = *psVar1 + 0x60;
        return;
      }
      wVar2 = rand();
      psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
      *psVar1 = ((wVar2 & 0x1f) - 8) + *psVar1;
      FUN_000025b0();
      if ((&comp_collision_related)[unaff_A4] == '\0') {
        psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
        *psVar1 = *psVar1 + 0x30;
        if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0x100) {
          return;
        }
      } else {
        psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
        *psVar1 = *psVar1 + -0x30;
        if (-0x100 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
          return;
        }
      }
      (&comp_collision_related)[unaff_A4] =
          (&comp_collision_related)[unaff_A4] ^ 0xff;
      return;
    }
  } else {
    FUN_00025398();
  }
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

void FUN_000259ac(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x000259b6. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_000259ba +
             (int)*(short *)((int)&WORD_000259ba +
                             (int)(short)(ushort) *
                                 (byte *)((int)&comp_state + unaff_A4))))();
  return;
}

char FUN_000259c2(void)

{
  short sVar1;
  char cVar2;
  char *pcVar3;
  char *pcVar5;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  char *pcVar4;

  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x20;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)(&comp_unk_4 + unaff_A4) = 1;
  cVar2 = FUN_00025a82();
  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    pcVar4 = *(char **)(&comp_unk_9 + unaff_A4);
    while (true) {
      pcVar3 = pcVar4 + 1;
      cVar2 = *pcVar4;
      if (cVar2 != '\0')
        break;
      pcVar4 = pcVar4 + CONCAT11(*pcVar3, pcVar4[2]) + 1;
    }
    *(char *)((int)&comp_state + unaff_A4) = cVar2;
    if (cVar2 == '\x02') {
      pcVar5 = pcVar4 + 2;
      (&DAT_ffffb773)[unaff_A4] = *pcVar3;
      cVar2 = '\0';
    } else {
      (&DAT_ffffbe78)[unaff_A4] = *pcVar3;
      *(char *)(unaff_A4 - 0x4187) = pcVar4[2];
      pcVar5 = pcVar4 + 4;
      cVar2 = cVar2 + -4;
      if (cVar2 == '\0') {
        *(short *)((int)&comp_vel[0].x + unaff_A4) = (short)pcVar4[3] << 4;
      } else {
        *(short *)((int)&comp_vel[0].y + unaff_A4) = (short)pcVar4[3] << 4;
      }
    }
    *(char **)(&comp_unk_9 + unaff_A4) = pcVar5;
    return cVar2;
  }
  return cVar2;
}

char FUN_000259d8(void)

{
  short sVar1;
  char cVar2;
  short *psVar3;
  char *pcVar5;
  int unaff_A4;
  char *pcVar4;

  cVar2 = FUN_00025a82();
  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    pcVar4 = *(char **)(&comp_unk_9 + unaff_A4);
    while (true) {
      psVar3 = (short *)(pcVar4 + 1);
      cVar2 = *pcVar4;
      if (cVar2 != '\0')
        break;
      pcVar4 = pcVar4 + *psVar3 + 1;
    }
    *(char *)((int)&comp_state + unaff_A4) = cVar2;
    if (cVar2 == '\x02') {
      pcVar5 = pcVar4 + 2;
      (&DAT_ffffb773)[unaff_A4] = *(char *)psVar3;
      cVar2 = '\0';
    } else {
      (&DAT_ffffbe78)[unaff_A4] = *(char *)psVar3;
      *(char *)(unaff_A4 + -0x4187) = pcVar4[2];
      pcVar5 = pcVar4 + 4;
      cVar2 = cVar2 + -4;
      if (cVar2 == '\0') {
        *(short *)((int)&comp_vel[0].x + unaff_A4) = (short)pcVar4[3] << 4;
      } else {
        *(short *)((int)&comp_vel[0].y + unaff_A4) = (short)pcVar4[3] << 4;
      }
    }
    *(char **)(&comp_unk_9 + unaff_A4) = pcVar5;
    return cVar2;
  }
  return cVar2;
}

ushort FUN_00025a2c(void)

{
  char cVar1;
  undefined1 uVar2;
  ushort uVar3;
  ushort *puVar4;
  char *pcVar6;
  ulong unaff_A4;
  char *pcVar5;

  FUN_00025a82();
  player_update_pos_x(unaff_A4);
  uVar3 = *(ushort *)(&DAT_ffffbe78 + unaff_A4);
  if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
    if (uVar3 <= *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      return uVar3;
    }
    *(ushort *)((int)&comp_pos_x + unaff_A4) = uVar3;
  } else {
    if (*(ushort *)((int)&comp_pos_x + unaff_A4) < uVar3) {
      return uVar3;
    }
    *(ushort *)((int)&comp_pos_x + unaff_A4) = uVar3;
  }
  *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  pcVar5 = *(char **)(&comp_unk_9 + unaff_A4);
  while (true) {
    puVar4 = (ushort *)(pcVar5 + 1);
    cVar1 = *pcVar5;
    uVar2 = (undefined1)(uVar3 >> 8);
    if (cVar1 != '\0')
      break;
    uVar3 = *puVar4;
    pcVar5 = pcVar5 + (short)uVar3 + 1;
  }
  *(char *)((int)&comp_state + unaff_A4) = cVar1;
  uVar3 = CONCAT11(uVar2, cVar1 + -2);
  if ((char)(cVar1 + -2) == '\0') {
    pcVar6 = pcVar5 + 2;
    (&DAT_ffffb773)[unaff_A4] = *(undefined1 *)puVar4;
  } else {
    (&DAT_ffffbe78)[unaff_A4] = *(undefined1 *)puVar4;
    *(char *)(unaff_A4 - 0x4187) = pcVar5[2];
    pcVar6 = pcVar5 + 4;
    uVar3 = CONCAT11(uVar2, cVar1 + -4);
    if ((char)(cVar1 + -4) == '\0') {
      *(short *)((int)&comp_vel[0].x + unaff_A4) = (short)pcVar5[3] << 4;
    } else {
      *(short *)((int)&comp_vel[0].y + unaff_A4) = (short)pcVar5[3] << 4;
    }
  }
  *(char **)(&comp_unk_9 + unaff_A4) = pcVar6;
  return uVar3;
}

ushort FUN_00025a54(void)

{
  char cVar1;
  undefined1 uVar2;
  ushort uVar3;
  ushort *puVar4;
  char *pcVar6;
  entity_id_t unaff_A4;
  char *pcVar5;

  FUN_00025a82();
  ecs_update_pos_y(unaff_A4);
  uVar3 = *(ushort *)(&DAT_ffffbe78 + unaff_A4);
  if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
    if (uVar3 <= *(ushort *)((int)&comp_pos_y + unaff_A4)) {
      return uVar3;
    }
    *(ushort *)((int)&comp_pos_y + unaff_A4) = uVar3;
  } else {
    if (*(ushort *)((int)&comp_pos_y + unaff_A4) < uVar3) {
      return uVar3;
    }
    *(ushort *)((int)&comp_pos_y + unaff_A4) = uVar3;
  }
  *(undefined4 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  pcVar5 = *(char **)(&comp_unk_9 + unaff_A4);
  while (true) {
    puVar4 = (ushort *)(pcVar5 + 1);
    cVar1 = *pcVar5;
    uVar2 = (undefined1)(uVar3 >> 8);
    if (cVar1 != '\0')
      break;
    uVar3 = *puVar4;
    pcVar5 = pcVar5 + (short)uVar3 + 1;
  }
  *(char *)((int)&comp_state + unaff_A4) = cVar1;
  uVar3 = CONCAT11(uVar2, cVar1 + -2);
  if ((char)(cVar1 + -2) == '\0') {
    pcVar6 = pcVar5 + 2;
    (&DAT_ffffb773)[unaff_A4] = *(undefined1 *)puVar4;
  } else {
    (&DAT_ffffbe78)[unaff_A4] = *(undefined1 *)puVar4;
    *(char *)(unaff_A4 - 0x4187) = pcVar5[2];
    pcVar6 = pcVar5 + 4;
    uVar3 = CONCAT11(uVar2, cVar1 + -4);
    if ((char)(cVar1 + -4) == '\0') {
      *(short *)((int)&comp_vel[0].x + unaff_A4) = (short)pcVar5[3] << 4;
    } else {
      *(short *)((int)&comp_vel[0].y + unaff_A4) = (short)pcVar5[3] << 4;
    }
  }
  *(char **)(&comp_unk_9 + unaff_A4) = pcVar6;
  return uVar3;
}

void FUN_00025a82(void)

{
  short sVar1;
  byte bVar3;
  ushort uVar2;
  int unaff_A4;

  uVar2 = (*(short *)((int)&comp_pos_x + unaff_A4) + 0x30) - DAT_ffffc73a;
  if (((((short)uVar2 < 0) || (0x15f < uVar2)) ||
       (uVar2 = (*(short *)((int)&comp_pos_y + unaff_A4) + 0x10) - DAT_ffffc746,
        (short)uVar2 < 0)) ||
      (0x11f < uVar2)) {
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 8;
  } else {
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] & 0xf7;
    uVar2 = comp_pos_y.fixed.i - *(short *)((int)&comp_pos_y + unaff_A4);
    if ((short)uVar2 < 0) {
      uVar2 = -uVar2;
    }
    uVar2 = uVar2 - (uVar2 >> 4);
    sVar1 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
    if ((int)sVar1 * (int)sVar1 + (uint)uVar2 * (uint)uVar2 < 0x640) {
      bVar3 = uint8_t_ffffcc70 & 0x7f | 2;
      if ((ushort)comp_pos_x.fixed.i <
          *(ushort *)((int)&comp_pos_x + unaff_A4)) {
        bVar3 = uint8_t_ffffcc70 & 0x7f | 0x82;
      }
      uint8_t_ffffcc70 = bVar3;
      return;
    }
  }
  return;
}

void FUN_00025aae(void)

{
  short sVar1;
  byte bVar3;
  ushort uVar2;
  int unaff_A4;

  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] & 0xf7;
  uVar2 = comp_pos_y.fixed.i - *(short *)((int)&comp_pos_y + unaff_A4);
  if ((short)uVar2 < 0) {
    uVar2 = -uVar2;
  }
  uVar2 = uVar2 - (uVar2 >> 4);
  sVar1 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  if ((int)sVar1 * (int)sVar1 + (uint)uVar2 * (uint)uVar2 < 0x640) {
    bVar3 = uint8_t_ffffcc70 & 0x7f | 2;
    if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      bVar3 = uint8_t_ffffcc70 & 0x7f | 0x82;
    }
    uint8_t_ffffcc70 = bVar3;
    return;
  }
  return;
}

uint FUN_00025ae2(void)

{
  short sVar1;
  undefined4 uVar2;
  uint uVar3;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar4;

  uVar4 = *(char *)((int)&comp_state + unaff_A4) == '\0';
  if ((bool)uVar4) {
    *(undefined2 *)(&comp_has_func_maybe + unaff_A4) =
        *(undefined2 *)(&comp_has_func_maybe + unaff_A4) | 0x2080;
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 4;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x78;
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0xff;
    uVar4 = 1;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  }
  FUN_000251a6();
  if (!(bool)uVar4) {
    uVar3 = FUN_00025398();
    goto LAB_00025b84;
  }
  FUN_00002272();
  sVar1 = *(short *)((int)&comp_vel[0].x + unaff_A4);
  *(short *)(&comp_unk_1 + unaff_A4) = sVar1;
  uVar4 = sVar1 == 0;
  FUN_00002288(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  uVar2 = FUN_00002248();
  if (((bool)uVar4) ||
      (*(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfe00,
       *(short *)((int)&comp_vel[0].x + unaff_A4) != 0)) {
    uVar3 = CONCAT31((int3)((uint)uVar2 >> 8),
                     (&component_unknown_5)[unaff_A4] |
                         (&component_collision_flags)[unaff_A4]) &
            0xffffff03;
    if ((((&component_unknown_5)[unaff_A4] |
          (&component_collision_flags)[unaff_A4]) &
         3) != 0) {
      uVar3 = (uint)(ushort) - *(short *)(&comp_unk_1 + unaff_A4);
      goto LAB_00025b5c;
    }
  } else {
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x18;
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & 0x7f;
    uVar3 = 0x300;
    if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      uVar3 = 0xfd00;
    }
  LAB_00025b5c:
    *(short *)((int)&comp_vel[0].x + unaff_A4) = (short)uVar3;
  }
  if (*(short *)((int)&comp_vel[0].x + unaff_A4) == 0) {
    return uVar3;
  }
  sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
  *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
  if (sVar1 != 0) {
    return uVar3;
  }
  if (((&comp_has_func_maybe)[unaff_A4] & 8) == 0) {
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x1e;
    (&DAT_ffffab42)[unaff_A4] = 0;
    (&DAT_ffffab43)[unaff_A4] = 0;
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | 4;
    return 0;
  }
LAB_00025b84:
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return uVar3;
}

void FUN_00025b8a(void)

{
  short *psVar1;
  short sVar2;
  undefined2 uVar3;
  undefined2 uVar4;
  int iVar5;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar6;
  bool bVar7;

  if (*(char *)((int)&comp_state + unaff_A4) == '\0') {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0xff;
    (&comp_collision_related)[unaff_A4] = 0;
    sVar2 = FUN_000022a2();
    *(short *)(&comp_unk_1 + unaff_A4) = -sVar2;
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x20;
    (&DAT_ffffb976)[unaff_A4] = 8;
  }
  if ((*(byte *)((int)&comp_state +
                 (int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                                 unaff_A4)) &
       0x7f) != 7)
    goto LAB_00025c94;
  if (*(short *)(&comp_unk_4 + unaff_A4) == 0) {
  LAB_00025bf4:
    sVar2 = *(short *)(&comp_unk_1 + unaff_A4);
    if (sVar2 < 0) {
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + -0x40;
      if (*(short *)((int)&comp_vel[0].x + unaff_A4) < sVar2)
        goto LAB_00025c14;
    } else {
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + 0x40;
      if (sVar2 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
      LAB_00025c14:
        *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar2;
      }
    }
  } else {
    if ((&DAT_ffffb976)[unaff_A4] == '\0') {
      uVar3 = comp_pos_x.fixed.i;
      uVar4 = *(ushort *)((int)&comp_pos_x + unaff_A4);
      if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
        uVar3 = *(ushort *)((int)&comp_pos_x + unaff_A4);
        uVar4 = comp_pos_x.fixed.i;
      }
      if ((ushort)uVar3 < (ushort)uVar4) {
        *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0;
        goto LAB_00025bf4;
      }
    } else {
      (&DAT_ffffb976)[unaff_A4] = (&DAT_ffffb976)[unaff_A4] + -1;
    }
    *(short *)(&comp_unk_4 + unaff_A4) =
        *(short *)(&comp_unk_4 + unaff_A4) + -1;
  }
  bVar7 = false;
  if ((&comp_collision_related)[unaff_A4] == '\0') {
    FUN_000186a0(unaff_A4);
    bVar6 = ((&comp_func_offset[0].unk4)[unaff_A4] & 8) == 0;
    if (bVar6) {
      FUN_000021c2(unaff_A4, bVar6, bVar7);
    } else {
      (&comp_collision_related)[unaff_A4] = 0xff;
      if ((short)(*(ushort *)((int)&comp_vel[0].x + unaff_A4) ^
                  *(ushort *)(&comp_unk_1 + unaff_A4)) < 0) {
        *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0;
        psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
        *psVar1 = -*psVar1;
        FUN_0000231c();
      }
    }
  }
  player_update_pos_x(unaff_A4);
  sVar2 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + unaff_A4);
  iVar5 = (int)sVar2;
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_pos_y + iVar5) + 6;
  if (*(short *)(&comp_unk_4 + unaff_A4) != 0) {
    return;
  }
  if (*(short *)(&comp_unk_1 + unaff_A4) < 0) {
    if ((ushort)(*(short *)((int)&comp_pos_x + iVar5) + 0x23U) <
        *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      return;
    }
  } else if (*(ushort *)((int)&comp_pos_x + unaff_A4) <
             (ushort)(*(short *)((int)&comp_pos_x + iVar5) - 0x23U)) {
    return;
  }
  ecs_anim_unk_2((int)sVar2, unaff_A5, 0x16);
  unaff_A4 = (entity_id_t)(short)unaff_A4;
LAB_00025c94:
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

void FUN_00025c9a(void)

{
  byte bVar1;
  short sVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar3;

  bVar3 = *(char *)((int)&comp_state + unaff_A4) == '\0';
  if (bVar3) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0xff;
    bVar1 = (&comp_collision_related)[unaff_A4];
    sVar2 = *(short *)((int)&fixed_w_vec2_t_ARRAY_00025cdc[0].x +
                       (int)(short)((ushort)bVar1 << 2));
    if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
      sVar2 = -sVar2;
    }
    *(short *)((int)&comp_vel[0].x + unaff_A4) = sVar2;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) =
        *(undefined2 *)((int)&fixed_w_vec2_t_ARRAY_00025cdc[0].y +
                        (int)(short)((ushort)bVar1 << 2));
    *(undefined2 *)(&comp_unk_4 + unaff_A4) = 0x10;
    *(undefined2 *)(&comp_has_func_maybe + unaff_A4) =
        *(undefined2 *)(&comp_has_func_maybe + unaff_A4) | 0x2080;
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 4;
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = 0;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  FUN_000251a6();
  if (bVar3) {
    player_update_pos(unaff_A4);
    if (*(short *)(&comp_unk_4 + unaff_A4) != 0) {
      *(short *)(&comp_unk_4 + unaff_A4) =
          *(short *)(&comp_unk_4 + unaff_A4) + -1;
      return;
    }
    bVar3 = FUN_00000eae(unaff_A4);
    if (!bVar3) {
      return;
    }
  } else {
    FUN_00025398();
  }
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

void FUN_00025d18(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar1;

  bVar1 = *(char *)((int)&comp_state + unaff_A4) == '\0';
  if (bVar1) {
    *(undefined1 *)((int)&comp_state + unaff_A4) = 0xff;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x20;
    *(undefined2 *)(&DAT_ffffbc78 + unaff_A4) =
        *(undefined2 *)((int)&comp_pos_y + unaff_A4);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfb80;
    return;
  }
  FUN_000251a6();
  if (bVar1) {
    FUN_00002272();
    player_update_pos(unaff_A4);
    bVar1 = *(short *)((int)&comp_pos_y + unaff_A4) ==
            *(short *)(&DAT_ffffbc78 + unaff_A4);
    if (*(short *)((int)&comp_pos_y + unaff_A4) <=
        *(short *)(&DAT_ffffbc78 + unaff_A4)) {
      return;
    }
    FUN_00002408();
    if (bVar1) {
      return;
    }
  }
  FUN_00025398();
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

// WARNING: Control flow encountered bad instruction data

void FUN_00025d64(void)

{
  short sVar1;
  undefined2 uVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar3;
  undefined1 uVar4;
  undefined1 uVar5;

  if ((&comp_collision_related)[unaff_A4] == '\0') {
    bVar3 = *(char *)((int)&comp_state + unaff_A4) == '\0';
    if (bVar3) {
      (&comp_state_a)[unaff_A4] =
          (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
      *(char *)((int)&comp_state + unaff_A4) =
          *(char *)((int)&comp_state + unaff_A4) + '\x01';
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
      (&comp_has_func_maybe)[unaff_A4] =
          (&comp_has_func_maybe)[unaff_A4] | 0x20;
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x400;
      return;
    }
    FUN_000021c2(unaff_A4, bVar3, false);
    if (((&comp_func_offset[0].unk4)[unaff_A4] & 2) == 0) {
      uVar5 = 0;
      uVar4 = *(char *)((int)&comp_state + unaff_A4) == '\0';
      if (*(char *)((int)&comp_state + unaff_A4) < '\0') {
        sVar1 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
        *(short *)(&comp_unk_4 + unaff_A4) = sVar1;
        if (sVar1 != 0) {
          return;
        }
      } else {
        ecs_update_pos_y(unaff_A4);
        FUN_00002408();
        if (!(bool)uVar4) {
          *(undefined1 *)((int)&comp_state + unaff_A4) = 0xff;
          FUN_00002420();
          FUN_000023a0();
          // WARNING: Bad instruction - Truncating control flow here
          halt_baddata();
        }
        FUN_00002456();
        if ((bool)uVar5) {
          return;
        }
      }
      goto LAB_00025e20;
    }
  } else {
    uVar5 = 0;
    uVar4 = *(char *)((int)&comp_state + unaff_A4) == '\0';
    if ((bool)uVar4) {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 0xff;
      uVar2 = 0x280;
      if ((&comp_collision_related)[unaff_A4] != '\x01') {
        uVar2 = 0xfd80;
        (&comp_state_a)[unaff_A4] =
            (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
      }
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = uVar2;
      if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
        BYTE_ffffc709 = 0;
      }
      if (unaff_A4 == ENTITY_ID_ASHA) {
        BYTE_ffffc70a = 0;
      }
      (&comp_state_1_a)[unaff_A4] = 0;
      (&comp_anim_c)[unaff_A4] = ECS_STATE_1_B_WALKING_OR_DOWNSTAB;
      ecs_anim_unk_1(unaff_A4, unaff_A5);
      (&comp_has_func_maybe)[unaff_A4] =
          (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
      return;
    }
    FUN_000251a6();
    if ((bool)uVar4) {
      player_update_pos_x(unaff_A4);
      FUN_00002432();
      if ((bool)uVar4) {
        FUN_0000246a();
        if ((bool)uVar5) {
          return;
        }
        goto LAB_00025e20;
      }
    }
  }
  FUN_00025398();
LAB_00025e20:
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

void FUN_00025e26(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar1;
  undefined1 uVar2;

  uVar2 = 0;
  bVar1 = *(char *)((int)&comp_state + unaff_A4) == '\0';
  if (bVar1) {
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x01';
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xff00;
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x20;
    if (unaff_A4 == ENTITY_ID_PEPELOGOO) {
      BYTE_ffffc709 = 0;
    }
    if (unaff_A4 == ENTITY_ID_ASHA) {
      BYTE_ffffc70a = 0;
    }
    (&comp_state_1_a)[unaff_A4] = 0;
    (&comp_anim_c)[unaff_A4] = 0;
    ecs_anim_unk_1(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] =
        (&comp_has_func_maybe)[unaff_A4] | COMPONENT_STATE_B_C0;
    return;
  }
  FUN_000251a6();
  if (bVar1) {
    player_update_pos_x(unaff_A4);
    FUN_0000246a();
    if ((bool)uVar2) {
      return;
    }
  } else {
    FUN_00025398();
  }
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

uint FUN_00025e5e(void)

{
  char cVar1;
  ushort uVar2;
  short sVar3;
  uint extraout_D0;
  uint uVar4;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar5;

  cVar1 = *(char *)((int)&comp_state + unaff_A4);
  if (cVar1 == '\0') {
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 4;
    if ((&comp_collision_related)[unaff_A4] != '\0') {
      *(undefined1 *)((int)&comp_state + unaff_A4) = 3;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
      uVar2 = DAT_ffffce0a -
              *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
      *(ushort *)((int)&comp_pos_y + unaff_A4) = uVar2;
      return (uint)uVar2;
    }
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x01';
    FUN_000022a2();
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x400;
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] & 0xbf;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] | 0x40;
    return extraout_D0;
  }
  bVar5 = cVar1 == '\x01';
  if (bVar5) {
    FUN_000251a6();
    if (!bVar5) {
      uVar4 = FUN_00025398();
    LAB_00025f5c:
      (&comp_has_func_maybe)[unaff_A4] = 0;
      return uVar4;
    }
    player_update_pos(unaff_A4);
    uVar2 =
        DAT_ffffce0a - *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
    if (*(ushort *)((int)&comp_pos_y + unaff_A4) < uVar2) {
      return (uint)uVar2;
    }
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x01';
    *(ushort *)((int)&comp_pos_y + unaff_A4) = uVar2;
    (&comp_collision_related)[unaff_A4] = 5;
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] + 8;
  } else {
    if ((byte)(cVar1 - 2U) != 0) {
      uVar4 = FUN_000251a6();
      if (*(short *)((int)&comp_anim_tick + unaff_A4) != 0) {
        return uVar4;
      }
      ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
      if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) == 0) {
        sVar3 = *(short *)((int)&comp_pos_x + unaff_A4);
        *(short *)((int)&comp_pos_x + unaff_A4) = sVar3 + 0x50;
        uVar2 = sVar3 + 0x58;
        uVar4 = (uint)uVar2;
        if (uVar2 < DAT_ffffce08) {
          return uVar4;
        }
      } else {
        sVar3 = *(short *)((int)&comp_pos_x + unaff_A4);
        *(short *)((int)&comp_pos_x + unaff_A4) = sVar3 + -0x50;
        uVar2 = sVar3 - 0x58;
        uVar4 = CONCAT22(0xffff, uVar2);
        if (DAT_ffffce04 <= uVar2) {
          return uVar4;
        }
      }
      goto LAB_00025f5c;
    }
    sVar3 = *(short *)(&comp_unk_4 + unaff_A4) + -1;
    *(short *)(&comp_unk_4 + unaff_A4) = sVar3;
    if (sVar3 != 0) {
      return (uint)(byte)(cVar1 - 2U);
    }
  }
  *(undefined2 *)(&comp_unk_4 + unaff_A4) = 4;
  FUN_000023a0();
  uVar4 = 0x10;
  if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) != 0) {
    uVar4 = 0xfff0;
  }
  *(short *)((int)&comp_pos_x + unaff_A4) =
      (short)uVar4 + *(short *)((int)&comp_pos_x + unaff_A4);
  cVar1 = (&comp_collision_related)[unaff_A4] + -1;
  (&comp_collision_related)[unaff_A4] = cVar1;
  if (cVar1 != '\0') {
    return uVar4;
  }
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return uVar4;
}

void FUN_00025f62(void)

{
  word wVar1;
  angle_t unaff_D4b;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar2;

  bVar2 = *(char *)((int)&comp_state + unaff_A4) == '\0';
  if (bVar2) {
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x01';
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 4;
    (&comp_state_a)[unaff_A4] = 0x80;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    FUN_00002782();
    (&DAT_ffffb976)[unaff_A4] = unaff_D4b;
    wVar1 = angle_sin(unaff_D4b);
    *(short *)((int)&comp_vel[0].y + unaff_A4) = (short)wVar1 >> 4;
    FUN_000026e4();
    *(short *)((int)&comp_vel[0].x + unaff_A4) = (short)wVar1 >> 8;
    if ((short)wVar1 >> 8 < 0) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    }
    return;
  }
  FUN_000251a6();
  if (bVar2) {
    player_update_pos(unaff_A4);
    bVar2 = FUN_00000eae(unaff_A4);
    if (!bVar2) {
      return;
    }
  } else {
    FUN_00025398();
  }
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

void FUN_00025fd2(void)

{
  word wVar1;
  angle_t unaff_D4b;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar2;

  bVar2 = *(char *)((int)&comp_state + unaff_A4) == '\0';
  if (bVar2) {
    *(char *)((int)&comp_state + unaff_A4) =
        *(char *)((int)&comp_state + unaff_A4) + '\x01';
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 4;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
    FUN_00002782();
    (&DAT_ffffb976)[unaff_A4] = unaff_D4b;
    wVar1 = angle_sin(unaff_D4b);
    *(short *)((int)&comp_vel[0].y + unaff_A4) = (short)wVar1 >> 4;
    FUN_000026e4();
    *(short *)((int)&comp_vel[0].x + unaff_A4) = (short)wVar1 >> 8;
    if ((short)wVar1 >> 8 < 0) {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    }
    return;
  }
  FUN_000251a6();
  if (bVar2) {
    player_update_pos(unaff_A4);
    bVar2 = FUN_00000eae(unaff_A4);
    if (!bVar2) {
      return;
    }
  } else {
    FUN_00025398();
  }
  (&comp_has_func_maybe)[unaff_A4] = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000265a6(void)

{
  short sVar1;
  ushort uVar2;
  undefined2 uVar3;
  undefined2 uVar4;
  long extraout_D0;
  long lVar5;
  byte bVar6;
  uint extraout_D1;
  ushort uVar8;
  uint uVar7;
  uint unaff_D2;
  uint unaff_D3;
  uint unaff_D4;
  long unaff_D5;
  uint3 uVar9;
  long unaff_D6;
  uint uVar10;
  long unaff_D7;
  byte *pbVar11;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  bool bVar12;
  undefined8 uVar13;

  DAT_ffffa732 = 0x1402;
  ecs_anim_unk_2(ENTITY_ID_FC, unaff_A5, 0);
  uRamffffa21e = 0xb0;
  DAT_ffffa322 = 0x88;
  _DAT_ffffbe74 = 0x88;
  DAT_ffffdd40 = 0;
  lVar5 = extraout_D0;
  uVar7 = extraout_D1;
  uVar3 = DAT_ffffdd44;
  uVar4 = DAT_ffffdd46;
  do {
    DAT_ffffdd46 = uVar4;
    DAT_ffffdd44 = uVar3;
    uVar13 = exception_unk_0(unaff_A3,
                             ENTITY_ID_FC,
                             unaff_A6,
                             lVar5,
                             uVar7,
                             unaff_D2,
                             unaff_D3,
                             unaff_D4,
                             unaff_D5,
                             unaff_D6,
                             unaff_D7);
    lVar5 = (long)((ulonglong)uVar13 >> 0x20);
    DAT_ffffdd46 = 8;
    do {
      sVar1 = *(short *)(&DAT_0002783e + (short)(DAT_ffffdd40 * 2));
      unaff_D7 =
          CONCAT22(2,
                   (short)CONCAT31((int3)(CONCAT22(2, DAT_ffffdd40 << 3) >> 8),
                                   (byte)(DAT_ffffdd40 << 3) >> 3) *
                           4 +
                       0x7400);
      DAT_ffffdd44 = 6;
      uVar8 = (ushort)(byte)(&DAT_0002783e)[sVar1];
      uVar10 = 0;
      while (bVar12 = 7 < uVar8, uVar8 = uVar8 - 8, bVar12) {
        Ram00c00004 = unaff_D7;
        Ram00c00000 = 0;
        DAT_ffffdd44 = DAT_ffffdd44 + -1;
        unaff_D7 =
            CONCAT22((short)((uint)unaff_D7 >> 0x10), (short)unaff_D7 + 0x80);
      }
      uVar8 = ~uVar8;
      pbVar11 = &DAT_00027840 + sVar1;
      unaff_D2 = (uint)(byte)(&DAT_0002783f)[sVar1];
      unaff_D3 = 0;
      while (true) {
        bVar12 = unaff_D3 == 0;
        unaff_D3 = unaff_D3 ^ 1;
        uVar9 = (uint3)((uVar10 << 4) >> 8);
        if (bVar12) {
          unaff_D4 = (uint)(*pbVar11 & 0xf);
          bVar6 = *pbVar11 >> 4;
          lVar5 = CONCAT31((int3)((uint)lVar5 >> 8), bVar6);
          pbVar11 = pbVar11 + 1;
        } else {
          bVar6 = (byte)unaff_D4;
        }
        uVar10 = CONCAT31(uVar9, bVar6 | (byte)(uVar10 << 4));
        uVar2 = (short)unaff_D2 - 1;
        unaff_D2 = (uint)uVar2;
        if (uVar2 == 0)
          break;
        uVar8 = uVar8 - 1;
        if (uVar8 == 0xffff) {
          uVar8 = 7;
          uVar10 = uVar10 << 0x10 | (uint)(uVar9 >> 8);
          Ram00c00004 = unaff_D7;
          Ram00c00000 = uVar10;
          unaff_D7 =
              CONCAT22((short)((uint)unaff_D7 >> 0x10), (short)unaff_D7 + 0x80);
          DAT_ffffdd44 = DAT_ffffdd44 + -1;
        }
      }
      uVar8 = (uVar8 + 1) * 4;
      uVar7 = (uint)uVar8;
      uVar10 = uVar10 << (uVar8 & 0x3f);
      Ram00c00004 = unaff_D7;
      Ram00c00000 = uVar10 << 0x10 | uVar10 >> 0x10;
      unaff_D6 = 0;
      while (true) {
        unaff_D7 =
            CONCAT22((short)((uint)unaff_D7 >> 0x10), (short)unaff_D7 + 0x80);
        DAT_ffffdd44 = DAT_ffffdd44 + -1;
        if (DAT_ffffdd44 == 0)
          break;
        Ram00c00004 = unaff_D7;
        Ram00c00000 = 0;
      }
      DAT_ffffdd40 = DAT_ffffdd40 + 1;
      DAT_ffffdd46 = DAT_ffffdd46 + -1;
    } while (DAT_ffffdd46 != 0);
    uVar3 = 0;
    uVar4 = 0;
  } while (DAT_ffffdd40 < 0x58);
  DAT_ffffa732 = 0x1816;
  ecs_anim_unk_2(ENTITY_ID_FC, unaff_A5, 0);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002669a(void)

{
  int iVar1;
  int iVar2;
  byte bVar3;
  byte bVar5;
  ushort uVar4;
  int unaff_D3;
  short sVar6;
  int iVar7;
  short sVar8;
  short *psVar9;
  int *piVar10;

  DAT_ffffdd46 = 0x18;
  if (DAT_ffffdd40 < 0) {
    DAT_ffffdd46 = DAT_ffffdd40 + 0x18;
    sVar8 = -DAT_ffffdd40;
    sVar6 = 0;
  } else {
    sVar8 = 0;
    sVar6 = DAT_ffffdd40;
    if ((ushort)(DAT_ffffdd40 - 0x40U) < 0x18) {
      DAT_ffffdd46 = 0x18 - (DAT_ffffdd40 - 0x40U);
    }
  }
  psVar9 =
      (short *)((int)WORD_ARRAY_ARRAY_0002675e[0] + (int)(short)(sVar8 * 6));
  _DAT_ffffdd42 = sVar6 << 2;
  do {
    iVar7 = CONCAT22(CONCAT11((char)((ushort)(_DAT_ffffdd42 * 2) >> 8),
                              (byte)(_DAT_ffffdd42 * 2) >> 3) *
                             4 +
                         0x7400,
                     2);
    iVar1 = (int)*(short *)(&DAT_0002783e + (short)(_DAT_ffffdd42 >> 1));
    iVar2 = 0;
    piVar10 = (int *)(psVar9 + 1);
    sVar8 = *psVar9;
    psVar9 = psVar9 + 3;
    DAT_ffffdd44 = 6;
    do {
      sVar6 = 7;
      do {
        unaff_D3 = unaff_D3 << 4;
        sVar8 = sVar8 + -1;
        if (sVar8 == -1) {
          sVar8 = 0;
          iVar2 = *piVar10 + iVar2;
          bVar5 = (byte)((uint)iVar2 >> 0x10);
          bVar3 = bVar5 - (&DAT_0002783e)[iVar1];
          if ((byte)(&DAT_0002783e)[iVar1] <= bVar5) {
            if (bVar3 < (byte)(&DAT_0002783f)[iVar1]) {
              uVar4 = CONCAT11((char)((uint)iVar2 >> 0x18), bVar3) >> 1;
              if ((bVar3 & 1) == 0) {
                bVar3 = (byte)(&DAT_00027840)[(short)uVar4 + iVar1] >> 4;
              } else {
                bVar3 = (&DAT_00027840)[(short)uVar4 + iVar1] & 0xf;
              }
              unaff_D3 =
                  CONCAT31((int3)((uint)unaff_D3 >> 8), bVar3 | (byte)unaff_D3);
            } else {
              sVar8 = -1;
            }
          }
        }
        sVar6 = sVar6 + -1;
      } while (sVar6 != -1);
      Ram00c00004 = iVar7;
      Ram00c00000 = unaff_D3;
      iVar7 = iVar7 + 0x800000;
      DAT_ffffdd44 = DAT_ffffdd44 + -1;
    } while (DAT_ffffdd44 != 0);
    _DAT_ffffdd42 = _DAT_ffffdd42 + 4;
    DAT_ffffdd46 = DAT_ffffdd46 + -1;
  } while (DAT_ffffdd46 != 0);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000267f4(void)

{
  short sVar1;
  undefined2 uVar2;

  sVar1 = 1;
  uVar2 = 0x80;
  if (DAT_ffffa52c < 0) {
    sVar1 = -1;
  }
  if ((ushort)(_DAT_ffffbe74 + sVar1) < DAT_ffffa322) {
    uVar2 = 0xff80;
    if (-0x81 < (short)(DAT_ffffa52c + -8)) {
      DAT_ffffa52c = DAT_ffffa52c + -8;
      return;
    }
  } else if ((short)(DAT_ffffa52c + 8) < 0x81) {
    DAT_ffffa52c = DAT_ffffa52c + 8;
    return;
  }
  DAT_ffffa52c = uVar2;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002681e(void)

{
  undefined2 extraout_D0u;
  short sVar1;
  undefined4 extraout_D1;
  undefined4 unaff_D2;
  long lVar2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  component_mixed_1_t *state;
  void *extraout_A1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A5;
  void *unaff_A6;
  undefined1 uVar3;
  undefined8 uVar4;

  FUN_00001646();
  lVar2 = CONCAT22((short)((uint)unaff_D2 >> 0x10), DAT_ffffcbb2);
  DAT_ffffdd4a = 1;
  if ((1 << (DAT_ffffcbb2 & 0x1f) & 0x29500U) != 0) {
    DAT_ffffdd4a = -1;
  }
  FUN_00001580();
  DAT_ffff91ce._0_1_ = 0xff;
  text_unk_1(&DAT_00026914, extraout_A1);
  state = &component_mixed_1_t_00026926;
  if (script_ctx_bf_0e_arg < 3) {
    state =
        (component_mixed_1_t *)((int)&component_mixed_1_t_00026926.unknown_3 +
                                (int)(short)((script_ctx_bf_0e_arg + 1) * 10));
  }
  ecs_init_entity_state(ENTITY_ID_08, unaff_A5, state);
  comp_vel[2].x.raw = -0x200;
  if (DAT_ffffdd4a < 0) {
    comp_vel[2].x.raw = 0x200;
    DAT_ffff9f23 = DAT_ffff9f23 | 8;
    DAT_ffffa12a = 0;
  }
  FUN_0002694e();
  DAT_ffffdd4f = 0;
  DAT_ffffdd4e = 0;
  DAT_ffffdd4c = 0;
  FUN_000271b4();
  VDP_CTRL = 0x8b03;
  uncompress_and_copy_to_vram();
  _DAT_ffff9812 = 0x248;
  vdp_palettes_something();
  DAT_ffff91ce._0_1_ = 0;
  uVar4 = palette_set_fade_black_ease_out_all();
  do {
    exception_unk_0(unaff_A3,
                    ENTITY_ID_08,
                    unaff_A6,
                    (long)((ulonglong)uVar4 >> 0x20),
                    (long)uVar4,
                    lVar2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_000271b4();
    uVar4 = FUN_000270e4();
    uVar3 = DAT_ffffdd4f == 3;
  } while (DAT_ffffdd4f < 3);
  uVar4 = palette_set_fade_black_ease_in_all();
  do {
    exception_unk_0(unaff_A3,
                    ENTITY_ID_08,
                    unaff_A6,
                    (long)((ulonglong)uVar4 >> 0x20),
                    (long)uVar4,
                    lVar2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_000271b4();
    FUN_000270e4();
    sVar1 = palette_iterate_for_unknown_reasons();
    uVar4 = CONCAT44(CONCAT22(extraout_D0u, sVar1), extraout_D1);
  } while ((bool)uVar3);
  FUN_00001646();
  DAT_ffff97ee = 0xff;
  audio_play_sound_asha_dies();
  DAT_ffff97ea = 0xe7;
  DAT_ffffcc92 = 1;
  DAT_ffffcc93 = 9;
  return;
}

void FUN_0002694e(void)

{
  something(&DAT_0002696a);
  something(&DAT_0002696a);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

long FUN_00026b72(void)

{
  undefined2 extraout_D0u;
  long lVar1;
  short sVar2;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  void *extraout_A1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A5;
  void *unaff_A6;
  undefined1 uVar3;
  undefined8 uVar4;

  FUN_00001646();
  FUN_00001580();
  DAT_ffff91ce._0_1_ = 0xff;
  DAT_ffffdd4a = 0xffff;
  text_unk_1(&BYTE_00026c08, extraout_A1);
  ecs_init_entity_state(ENTITY_ID_08, unaff_A5, &component_mixed_1_t_00026c16);
  comp_vel[2].x.raw = 0x80;
  FUN_0002694e();
  DAT_ffffdd4f = 4;
  DAT_ffffdd4e = 0;
  DAT_ffffdd4c = 0;
  FUN_000271b4();
  VDP_CTRL = 0x8b03;
  uncompress_and_copy_to_vram();
  _DAT_ffff9812 = 0x248;
  vdp_palettes_something();
  DAT_ffff91ce._0_1_ = 0;
  uVar4 = palette_set_fade_black_ease_out_all();
  do {
    exception_unk_0(unaff_A3,
                    ENTITY_ID_08,
                    unaff_A6,
                    (long)((ulonglong)uVar4 >> 0x20),
                    (long)uVar4,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_000271b4();
    uVar4 = FUN_000270e4();
    uVar3 = DAT_ffffa12a == 0x100;
  } while (DAT_ffffa12a < 0x100);
  uVar4 = palette_set_fade_black_ease_in_all();
  do {
    exception_unk_0(unaff_A3,
                    ENTITY_ID_08,
                    unaff_A6,
                    (long)((ulonglong)uVar4 >> 0x20),
                    (long)uVar4,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    FUN_000271b4();
    FUN_000270e4();
    sVar2 = palette_iterate_for_unknown_reasons();
    lVar1 = CONCAT22(extraout_D0u, sVar2);
    uVar4 = CONCAT44(lVar1, extraout_D1);
  } while ((bool)uVar3);
  if (((undefined1)vdp_ctrl_mode_set_2_state & 0x40) != 0) {
    related_to_palette_maybe_1 = 0xff;
    related_to_palette_maybe_2 = 0;
    uVar4 = exception_unk_0(unaff_A3,
                            ENTITY_ID_08,
                            unaff_A6,
                            lVar1,
                            extraout_D1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    lVar1 = (long)((ulonglong)uVar4 >> 0x20);
  }
  return lVar1;
}

void FUN_00026d54(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;
  undefined2 uStack_2;

  uVar1 = CONCAT44(in_D0, in_D1);
  uStack_2 = (short)in_D0;
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    uStack_2 = uStack_2 + -1;
  } while (uStack_2 != 0);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000270e4(void)

{
  undefined *puVar1;

  FUN_000025d0();
  puVar1 = &DAT_0002711a;
  if (DAT_ffffdd4a < 0) {
    puVar1 = &UNK_00027122;
  }
  (*(code *)(puVar1 +
             *(short *)(puVar1 + (short)((ushort)DAT_ffffdd4f * 2))))();
  _DAT_ffffa12a = comp_vel[2].x.raw * 0x100 + _DAT_ffffa12a;
  _DAT_ffffa22e = comp_vel[2].y.raw * 0x100 + _DAT_ffffa22e;
  return;
}

void FUN_000271b4(void)

{
  short sVar1;
  char extraout_D0b;
  short extraout_D1w;
  short sVar2;
  word wVar3;
  short *extraout_A0;
  angle_t angle;

  sVar1 = DAT_ffffdd4a;
  sVar2 = 0x7f;
  angle = DAT_ffffdd4e;
  do {
    wVar3 = angle_sin(angle);
    angle = extraout_D0b + 5;
    *extraout_A0 = extraout_D1w + ((short)wVar3 >> 9);
    sVar2 = sVar2 + -1;
  } while (sVar2 != -1);
  DAT_ffffdd4e = DAT_ffffdd4e + 2;
  DAT_ffffdd4c = sVar1 * 4 + DAT_ffffdd4c;
  vdp_related_to_display_asha = vdp_related_to_display_asha | 2;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000271ec(void)

{
  int iVar1;
  char duration;
  word *state;
  void *extraout_A1;
  void *extraout_A1_00;
  entity_id_t self;
  entity_id_t unaff_A5;
  undefined1 uVar2;

  FUN_00001646();
  FUN_00001580();
  DAT_ffff91ce._0_1_ = 0xff;
  FUN_000272c4();
  FUN_000272c4();
  text_unk_1(&DAT_000272d8, extraout_A1);
  _DAT_ffff9812 = 0x2000000;
  iVar1 = (int)*(
      short *)(&DAT_000272de +
               (short)((ushort)(script_ctx_bf_0c_arg_item_name_index & 3) * 2));
  text_unk_1((undefined *)((int)(&DAT_000272de + iVar1) +
                           (int)*(short *)(&DAT_000272de + iVar1)),
             extraout_A1_00);
  DAT_ffffd916 = *(undefined2 *)(&DAT_000272e0 + iVar1);
  _DAT_ffff9812 =
      CONCAT22(_DAT_ffff9812, *(undefined2 *)(&DAT_000272e2 + iVar1));
  self = ENTITY_ID_08;
  state = (word *)((int)&WORD_000272e4 + iVar1);
  while (true) {
    state = state + 1;
    if (*state == 0)
      break;
    ecs_init_entity_state(
        self,
        unaff_A5,
        (component_mixed_1_t *)((int)state + (int)(short)*state));
    self = self + ENTITY_ID_PEPELOGOO;
    state = state;
  }
  uncompress_and_copy_to_vram();
  vdp_palettes_something();
  palette_set_fade(~PALETTE_ID_FLAG_NONE,
                   PALETTE_FADE_1,
                   duration,
                   (palette_color_iter_t)0xffffffff);
  something(&DAT_00027352);
  FUN_000192b4();
  audio_play_sound_asha_dies();
  uVar2 = 0;
  audio_play(SOUND_ID_SPIRITS);
  palette_set_fade_black_ease_out_all();
  do {
    FUN_0002782e();
    palette_iterate_for_unknown_reasons();
  } while ((bool)uVar2);
  do {
    FUN_0002782e();
    related_to_text_3(&SCRIPT_CTX_CURRENT);
    // While flag 7 is set.
    uVar2 = SCRIPT_CTX_CURRENT.flags == SCRIPT_CTX_FLAG_NONE;
  } while ((char)SCRIPT_CTX_CURRENT.flags < '\0');
  palette_set_fade_black_ease_in_all();
  do {
    FUN_0002782e();
    palette_iterate_for_unknown_reasons();
  } while ((bool)uVar2);
  FUN_0002681e();
  return;
}

undefined2 FUN_000272c4(void)

{
  short extraout_D1w;
  short sVar1;
  void *unaff_D2w;

  vdp_set_vram_write_addr(unaff_D2w);
  sVar1 = extraout_D1w;
  do {
    VDP_DATA = 0x8781;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return 0x8781;
}

undefined8 FUN_0002782e(void)

{
  long in_D0;
  long in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = exception_unk_0(unaff_A3,
                          unaff_A4,
                          unaff_A6,
                          in_D0,
                          in_D1,
                          unaff_D2,
                          unaff_D3,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  vdp_gfx_ptr_6 = vdp_gfx_ptr_6 + 4;
  vdp_related_to_display_asha = vdp_related_to_display_asha | 8;
  return uVar1;
}

void FUN_00027ec8(void)

{
  short sVar1;

  vdp_set_vram_write_addr((void *)0xd100);
  sVar1 = 0x2ff;
  do {
    VDP_DATA = 0x8781;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return;
}

void FUN_00027ee6(byte *param_1, word *param_2, ushort param_3, char param_4)

{
  char cVar1;
  uint uVar2;
  word *extraout_A1;
  word *pwVar3;
  word *pwVar4;
  ushort i;

  vdp_set_vram_write_addr((void *)param_3);
  uVar2 = 0;
  pwVar4 = extraout_A1;
  while (true) {
    pwVar3 = (word *)((int)pwVar4 + 1);
    cVar1 = *(char *)pwVar4;
    uVar2 = CONCAT31((int3)(uVar2 >> 8), cVar1);
    if (cVar1 == '\0')
      break;
    if (cVar1 == -1) {
      param_4 = param_4 + -1;
      pwVar4 = pwVar3;
      if (param_4 != '\0') {
        pwVar4 = param_2;
      }
    } else if (cVar1 == -2) {
      pwVar4 = pwVar4 + 1;
      param_4 = *(char *)pwVar3;
      param_2 = pwVar4;
    } else {
      pwVar4 = (word *)((int)pwVar4 + 3);
      do {
        VDP_DATA = *pwVar3;
        i = (short)uVar2 - 1;
        uVar2 = (uint)i;
      } while (i != 0);
    }
  }
  return;
}

void FUN_00027f20(uint3 *param_1, word param_2)

{
  short sVar1;
  byte bVar2;
  void *vram_dst;
  uint3 uVar3;
  undefined1 uVar4;
  word extraout_D0w;
  ushort uVar5;
  word wVar6;
  short sVar7;
  word *pwVar8;
  word *extraout_A0;
  uint3 *puVar9;
  uint3 *extraout_A1;
  uint3 *puVar10;
  short *psVar11;
  ushort *puVar12;
  short *psVar13;

  sVar7 = 0;
  pwVar8 = &VDP_DATA;
  psVar11 = (short *)register0x0000003c;
LAB_00027f28:
  do {
    while (true) {
      puVar9 = (uint3 *)((int)param_1 + 1);
      bVar2 = *(byte *)param_1;
      uVar4 = (undefined1)(param_2 >> 8);
      param_2 = CONCAT11(uVar4, bVar2);
      puVar10 = puVar9;
      if (0xf6 < bVar2)
        break;
    LAB_00027f30:
      *pwVar8 = param_2;
      param_1 = puVar10;
    }
    if (bVar2 == 0xff) {
      if (sVar7 == 0) {
        return;
      }
      sVar7 = sVar7 + -1;
      param_1 = *(uint3 **)psVar11;
      psVar11 = psVar11 + 2;
      goto LAB_00027f28;
    }
    if (bVar2 == 0xfe) {
      param_2 = CONCAT11(uVar4, *(byte *)puVar9) << 8;
      param_1 = (uint3 *)((int)param_1 + 2);
    } else if (bVar2 == 0xfd) {
      vram_dst = *(void **)puVar9;
      psVar11[-0xffffffff00000002] = 2;
      psVar11[-0xffffffff00000001] = 0x7f5e;
      vdp_set_vram_write_addr(vram_dst);
      param_2 = extraout_D0w;
      pwVar8 = extraout_A0;
      param_1 = extraout_A1;
    } else if (bVar2 == 0xfc) {
      uVar5 = (ushort) * (byte *)puVar9;
      puVar10 = (uint3 *)((int)param_1 + 3);
      param_2 = CONCAT11(uVar4, (byte)*param_1);
      do {
        *pwVar8 = param_2;
        uVar5 = uVar5 - 1;
        param_1 = puVar10;
      } while (uVar5 != 0xffff);
    } else if (bVar2 == 0xfb) {
      uVar5 = (ushort) * (byte *)puVar9;
      puVar10 = (uint3 *)((int)param_1 + 3);
      wVar6 = CONCAT11(uVar4, (byte)*param_1);
      do {
        *pwVar8 = wVar6;
        wVar6 = wVar6 + 1;
        uVar5 = uVar5 - 1;
        param_1 = puVar10;
      } while (uVar5 != 0xffff);
    } else {
      if (bVar2 == 0xfa) {
        puVar10 = (uint3 *)((int)param_1 + 2);
        param_2 = CONCAT11(uVar4, *(byte *)puVar9);
        goto LAB_00027f30;
      }
      if (bVar2 == 0xf9) {
        sVar1 = *psVar11;
        *psVar11 = sVar1 + -1;
        if ((short)(sVar1 + -1) == 0) {
          psVar11 = psVar11 + 3;
          param_1 = puVar9;
        } else {
          param_1 = *(uint3 **)(psVar11 + 1);
        }
      } else if (bVar2 == 0xf8) {
        bVar2 = *(byte *)puVar9;
        *(uint3 **)(psVar11 + -2) = (uint3 *)((int)param_1 + 2);
        puVar12 = (ushort *)(psVar11 + -3);
        psVar11 = psVar11 + -3;
        *puVar12 = (ushort)bVar2;
        param_1 = (uint3 *)((int)param_1 + 2);
      } else {
        uVar3 = *puVar9;
        psVar13 = psVar11 + -2;
        psVar11 = psVar11 + -2;
        *(uint3 **)psVar13 = param_1 + 1;
        sVar7 = sVar7 + 1;
        param_1 = (uint3 *)(uint)uVar3;
      }
    }
  } while (true);
}

void ecs_init_entity_state(entity_id_t self, entity_id_t other,
                           component_mixed_1_t *state)

{
  entity_reset(self);
  (&comp_has_func_maybe)[self] = COMPONENT_STATE_B_C0;
  *(word *)((int)&comp_unk_3 + self) = state->unknown_3;
  *(word *)((int)&comp_pos_x + self) = state->x;
  *(word *)((int)&comp_pos_y + self) = state->y;
  *(word *)(&comp_anim_base_offset + self) = state->state_1_d;
  *(undefined2 *)((int)&comp_unk_4 + self) = 4;
  (&comp_state_a)[self] = state->state_a;
  ecs_anim_unk_2(self, (anim_item_t *)other, state->state_1_b);
  return;
}

void FUN_00027ff6(void)

{
  undefined1 in_D0b;
  char duration;

  DAT_ffff9813 = in_D0b;
  FUN_0000aba0(palettes[1]);
  palette_set_fade(PALETTE_ID_FLAG_1,
                   PALETTE_FADE_1,
                   duration,
                   (palette_color_iter_t)0xffffffff);
  return;
}

void FUN_00028010(void)

{
  short i;
  word *pwVar1;
  undefined4 *puVar2;

  FUN_00001646();
  audio_pause();
  vdp_set_window_position(0x1c);
  DAT_ffffde0d = 4;
  i = 0x1f;
  pwVar1 = compressed_data_indices;
  puVar2 = &DAT_ffffdd52;
  do {
    *puVar2 = *(undefined4 *)pwVar1;
    i = i + -1;
    pwVar1 = pwVar1 + 2;
    puVar2 = puVar2 + 1;
  } while (i != -1);
  i = 0x1f;
  pwVar1 = compressed_data_indices;
  do {
    pwVar1[0] = 0xffff;
    pwVar1[1] = 0xffff;
    i = i + -1;
    pwVar1 = pwVar1 + 2;
  } while (i != -1);
  DAT_ffffddd2 = DAT_ffff9813;
  return;
}

void FUN_00028018(void)

{
  short i;
  word *pwVar1;
  undefined4 *puVar2;

  vdp_set_window_position(0x1c);
  DAT_ffffde0d = 4;
  i = 0x1f;
  pwVar1 = compressed_data_indices;
  puVar2 = &DAT_ffffdd52;
  do {
    *puVar2 = *(undefined4 *)pwVar1;
    i = i + -1;
    pwVar1 = pwVar1 + 2;
    puVar2 = puVar2 + 1;
  } while (i != -1);
  i = 0x1f;
  pwVar1 = compressed_data_indices;
  do {
    pwVar1[0] = 0xffff;
    pwVar1[1] = 0xffff;
    i = i + -1;
    pwVar1 = pwVar1 + 2;
  } while (i != -1);
  DAT_ffffddd2 = DAT_ffff9813;
  return;
}

void FUN_0002804c(void)

{
  word wVar1;
  short sVar2;
  void *extraout_A1;
  char *pcVar3;

  FUN_00001646();
  related_to_entering_and_exiting_menu_1 = 0;
  text_unk_1(&DAT_000280f6, extraout_A1);
  uncompress_and_copy_to_vram();
  sVar2 = (ushort)(byte)(&DAT_00028150)[DAT_ffffcbb4] * 6;
  wVar1 = *(word *)(&DAT_00028198 + sVar2);
  DAT_ffffddd3 = (&DAT_0002819a)[sVar2];
  DAT_ffffddd4 = (&DAT_0002819b)[sVar2];
  FUN_00027f20((uint3 *)((int)(&DAT_00028198 + sVar2) + (int)(short)wVar1),
               wVar1);
  pcVar3 = (char *)((int)(&DAT_0002819c + sVar2) +
                    (int)*(short *)(&DAT_0002819c + sVar2));
  while (*pcVar3 != -1) {
    FUN_000280fc();
    pcVar3 = pcVar3 + 1;
  }
  FUN_000280fc();
  FUN_00001630();
  DAT_ffffddd5 = '\x10';
  DAT_ffffddd6 = 0;
  do {
    FUN_000028ce();
    DAT_ffffddd5 = DAT_ffffddd5 + -1;
    if (DAT_ffffddd5 == '\0') {
      DAT_ffffddd5 = '\x10';
      DAT_ffffddd6 = DAT_ffffddd6 ^ 1;
      FUN_000280fc();
    }
  } while (gamepad_pressed_prev < GAMEPAD_B);
  return;
}

void FUN_000280fc(void)

{
  char cVar1;
  char cVar2;
  int iVar3;
  short in_D0w;
  char extraout_D1b;
  char cVar4;
  ushort unaff_D6w;
  ushort *extraout_A0;
  ushort *puVar5;
  ushort *extraout_A1;
  ushort *puVar6;

  iVar3 = (int)(short)(in_D0w << 2);
  cVar1 = DAT_ffffddd3 + (&DAT_0002835a)[iVar3];
  cVar2 = DAT_ffffddd4 + (&DAT_0002835b)[iVar3];
  puVar5 =
      (ushort *)(&DAT_0002835c + *(short *)(&DAT_0002835c + iVar3) + iVar3);
  while (*(char *)puVar5 != '\0') {
    vdp_set_vram_write_addr(
        (void *)(((ushort)(byte)(*(char *)(puVar5 + 1) + cVar2) * 0x20 +
                  (ushort)(byte)((char)*puVar5 + cVar1)) *
                     2 +
                 -0x3000));
    cVar4 = extraout_D1b;
    puVar6 = extraout_A1;
    do {
      puVar5 = puVar6 + 1;
      *extraout_A0 = unaff_D6w | *puVar6;
      cVar4 = cVar4 + -1;
      puVar6 = puVar5;
    } while (cVar4 != '\0');
  }
  return;
}

void FUN_0002861a(void)

{
  FUN_00028630();
  vdp_set_window_position((ushort)DAT_ffffde0d);
  audio_resume();
  FUN_00001630();
  return;
}

void FUN_00028630(void)

{
  short i;
  char duration;
  undefined4 *src;
  word *dst;

  FUN_00001646();
  i = 0x1f;
  src = &DAT_ffffdd52;
  dst = compressed_data_indices;
  do {
    *(undefined4 *)dst = *src;
    i = i + -1;
    src = src + 1;
    dst = dst + 2;
  } while (i != -1);
  DAT_ffff91ce._0_1_ = 0xff;
  uncompress_and_copy_to_vram();
  DAT_ffff91ce._0_1_ = 0;
  related_to_entering_and_exiting_menu_1 = 0;
  related_to_entering_and_exiting_menu_2 = 0;
  related_to_entering_and_exiting_menu_2 = 0;
  DAT_ffff9813 = DAT_ffffddd2;
  FUN_0000aba0(palettes[1]);
  palette_set_fade(PALETTE_ID_FLAG_1,
                   PALETTE_FADE_1,
                   duration,
                   (palette_color_iter_t)0xffffffff);
  return;
}

void FUN_0002867e(void)

{
  char unaff_D4b;
  void *extraout_A1;
  void *extraout_A1_00;
  word *unaff_A2;

  FUN_00028010();
  FUN_00027ec8();
  text_unk_1(BYTE_ARRAY_000286ae, extraout_A1);
  text_unk_1(BYTE_ARRAY_0000c8bc, extraout_A1_00);
  uncompress_and_copy_to_vram();
  FUN_00027ff6();
  FUN_00027ee6((byte *)(WORD_ARRAY_000286be + 1), unaff_A2, 0xd102, unaff_D4b);
  return;
}

void FUN_00028710(void)

{
  undefined2 extraout_D0w;
  short extraout_D1w;
  void *vram_dst;
  short sVar1;
  undefined2 *extraout_A0;

  vram_dst = (void *)0xd144;
  do {
    vdp_set_vram_write_addr(vram_dst);
    vram_dst = (void *)((short)vram_dst + 0x40);
    sVar1 = 0x1b;
    do {
      *extraout_A0 = extraout_D0w;
      sVar1 = sVar1 + -1;
    } while (sVar1 != -1);
  } while (extraout_D1w != 0);
  return;
}

byte FUN_00028736(void)

{
  byte in_D0b;
  byte unaff_D5b;
  word *pwVar1;

  pwVar1 = WORD_ARRAY_0002893c;
  if (-1 < (char)in_D0b) {
    pwVar1 = (word *)((int)WORD_ARRAY_00028786 +
                      (int)*(short *)((int)WORD_ARRAY_00028786 +
                                      (int)(short)((ushort)in_D0b * 2)));
  }
  FUN_00028756((char *)pwVar1);
  return unaff_D5b;
}

void FUN_00028756(char *param_1)

{
  char cVar1;
  undefined1 uVar2;
  short extraout_D0w;
  short sVar3;
  short sVar4;
  void *unaff_D2w;
  short unaff_D4w;
  short unaff_D5w;
  short *extraout_A0;
  char *extraout_A1;
  char *pcVar5;
  char *pcVar6;

  do {
    vdp_set_vram_write_addr(unaff_D2w);
    unaff_D2w = (void *)((short)unaff_D2w + 0x40);
    sVar3 = extraout_D0w;
    sVar4 = unaff_D4w;
    pcVar5 = extraout_A1;
  LAB_00028766:
    do {
      uVar2 = (undefined1)((ushort)sVar3 >> 8);
      sVar3 = CONCAT11(uVar2, *pcVar5);
      pcVar6 = pcVar5 + 1;
      if (*pcVar5 == -1) {
        pcVar6 = pcVar5 + 2;
        cVar1 = pcVar5[1];
        sVar3 = CONCAT11(uVar2, cVar1);
        if (cVar1 != -1) {
          sVar3 = sVar3 << 8;
          pcVar5 = pcVar6;
          goto LAB_00028766;
        }
      }
      *extraout_A0 = sVar3;
      sVar4 = sVar4 + -1;
      pcVar5 = pcVar6;
    } while (sVar4 != -1);
    unaff_D5w = unaff_D5w + -1;
    if (unaff_D5w == -1) {
      return;
    }
  } while (true);
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00028948(script_ctx_t *text)

{
  byte in_D0b;

  FUN_00028710();
  if (-1 < (char)in_D0b) {
    _BYTE_ffffd918 = in_D0b | 0xb500;
    text_do_something_and_set_script(script_1);
    related_to_text_3(text);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void purchase_regen_item(void)

{
  word wVar1;
  void *extraout_A1;
  void *extraout_A1_00;
  script_state_bit_t *purchasable_regen_item_p;
  anim_item_t *unaff_A5;
  bool bVar2;
  undefined1 uVar3;

  _DAT_ffffddd8 = *(int *)(&comp_unk_9 + _DAT_ffffda72);
  FUN_00028010();
  text_unk_1(&DAT_00028ba4, extraout_A1);
  text_unk_1(BYTE_ARRAY_0000c8bc, extraout_A1_00);
  uncompress_and_copy_to_vram();
  wVar1 = FUN_00027ff6();
  FUN_00027f20((uint3 *)&DAT_00028bc1, wVar1);
  _DAT_ffffdddc = 0;
  FUN_00028b24();
  _DAT_ffffdddc = _DAT_ffffdddc + 2;
  FUN_00028b24();
  _DAT_ffffdddc = _DAT_ffffdddc + 2;
  FUN_00028b24();
  ecs_init_entity_state(
      ENTITY_ID_F4, (entity_id_t)unaff_A5, &component_mixed_1_t_00028b7c);
  _DAT_ffffdddc = 0;
  FUN_00028b90();
  FUN_00001630();
  do {
    do {
      while (true) {
        FUN_000028ce();
        if (((gamepad_pressed_prev & GAMEPAD_START) != GAMEPAD_NONE) ||
            ((gamepad_pressed_prev & GAMEPAD_B) != GAMEPAD_NONE))
          goto FUN_0002861a;
        if ((gamepad_pressed_prev & GAMEPAD_LEFT) == GAMEPAD_NONE)
          break;
        if (_DAT_ffffdddc != 0) {
          _DAT_ffffdddc = _DAT_ffffdddc - 2;
        }
      LAB_00028a1c:
        audio_play(SOUND_ID_RES_KEY);
        FUN_00028b90();
      }
      if ((gamepad_pressed_prev & GAMEPAD_RIGHT) != GAMEPAD_NONE) {
        if (_DAT_ffffdddc < 4) {
          _DAT_ffffdddc = _DAT_ffffdddc + 2;
        }
        goto LAB_00028a1c;
      }
    } while ((gamepad_pressed_prev & GAMEPAD_ACCEPT) == GAMEPAD_NONE);
    if (total_hearts < total_hearts_max) {
      purchasable_regen_item_p =
          (script_state_bit_t *)((short)(_DAT_ffffdddc * 2) + _DAT_ffffddd8);
      if (-1 < *(char *)(purchasable_regen_item_p + 1)) {
        if (-1 < (short)*purchasable_regen_item_p) {
          bVar2 = script_state_get(*purchasable_regen_item_p);
          if (!bVar2)
            goto LAB_00028a70;
        }
        if ((uint) * (ushort *)((int)&regen_item_price_jump_table +
                                (int)(short)((ushort)(byte)
                                                 purchasable_regen_item_p[1]
                                                     .field_0x1 *
                                             2)) <=
            (uint)gold) {
          audio_play(SOUND_ID_RES_BTTN);
          ecs_init_entity_state(ENTITY_ID_F8,
                                (entity_id_t)unaff_A5,
                                &component_mixed_1_t_00028b86);
          DAT_ffffa21a = *(undefined2 *)(&DAT_00028b9e + (short)_DAT_ffffdddc);
          ecs_anim_unk_2(ENTITY_ID_F4, unaff_A5, 4);
          do {
            FUN_000028ce();
          } while (_DAT_ffffa62c != 0);
          purchasable_regen_item_p =
              (script_state_bit_t *)((short)(_DAT_ffffdddc * 2) +
                                     _DAT_ffffddd8);
          if (-1 < (short)*purchasable_regen_item_p) {
            script_state_set_true(*purchasable_regen_item_p);
            FUN_00028b24();
          }
          total_hearts =
              total_hearts +
              (&regen_item_hearts_jump_table)
                  [(short)(ushort) * (byte *)(purchasable_regen_item_p + 1)];
          if (total_hearts_max < total_hearts) {
            total_hearts = total_hearts_max;
          }
          gold =
              gold -
              (uint) * (ushort *)((int)&regen_item_price_jump_table +
                                  (int)(short)((ushort)(byte)
                                                   purchasable_regen_item_p[1]
                                                       .field_0x1 *
                                               2));
          uVar3 = 0;
          audio_play(SOUND_ID_LIFE);
          do {
            FUN_000028ce();
            FUN_0001a582();
          } while (!(bool)uVar3);
          FUN_000028d8();
        FUN_0002861a:
          FUN_00028630();
          vdp_set_window_position((ushort)DAT_ffffde0d);
          audio_resume();
          FUN_00001630();
          return;
        }
      }
    }
  LAB_00028a70:
    audio_play(SOUND_ID_SLAPPED);
  } while (true);
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00028b24(void)

{
  char cVar1;
  byte bVar2;
  script_state_bit_t index;
  undefined3 uVar3;
  uint extraout_D0;
  uint uVar4;
  short sVar5;
  void *vram_dst;
  short sVar6;
  undefined2 *extraout_A0;
  char *extraout_A1;
  char *pcVar7;
  char *extraout_A1_00;
  char *pcVar8;
  script_state_bit_t *psVar9;
  bool bVar10;

  sVar6 = *(short *)(&UNK_00028b1e + _DAT_ffffdddc);
  psVar9 = (script_state_bit_t *)((short)(_DAT_ffffdddc * 2) + _DAT_ffffddd8);
  pcVar8 = &UNK_00028e0b;
  index = *psVar9;
  bVar2 = *(byte *)(psVar9 + 1);
  if ((-1 < (char)bVar2) &&
      (((short)index < 0 ||
        (bVar10 = script_state_get(index), pcVar8 = extraout_A1_00, bVar10)))) {
    pcVar8 =
        &UNK_00028bac + *(short *)(&UNK_00028bac + (short)((ushort)bVar2 * 2));
  }
  FUN_00028756(pcVar8);
  vram_dst = (void *)(sVar6 + 0x42);
  sVar6 = 3;
  do {
    vdp_set_vram_write_addr(vram_dst);
    vram_dst = (void *)((short)vram_dst + 0x40);
    sVar5 = 3;
    uVar4 = extraout_D0;
    pcVar8 = extraout_A1;
  LAB_00028766:
    do {
      uVar3 = (undefined3)(uVar4 >> 8);
      uVar4 = CONCAT31(uVar3, *pcVar8);
      pcVar7 = pcVar8 + 1;
      if (*pcVar8 == -1) {
        pcVar7 = pcVar8 + 2;
        cVar1 = pcVar8[1];
        uVar4 = CONCAT31(uVar3, cVar1);
        if (cVar1 != -1) {
          uVar4 = (uint)(ushort)((short)uVar4 << 8);
          pcVar8 = pcVar7;
          goto LAB_00028766;
        }
      }
      *extraout_A0 = (short)uVar4;
      sVar5 = sVar5 + -1;
      pcVar8 = pcVar7;
    } while (sVar5 != -1);
    sVar6 = sVar6 + -1;
    if (sVar6 == -1) {
      return;
    }
  } while (true);
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00028b90(void)

{
  DAT_ffffa216 = *(undefined2 *)(&DAT_00028b9e + _DAT_ffffdddc);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_00028e9e(void)

{
  char duration;
  short sVar1;
  void *extraout_A1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A5;

  FUN_00001646();
  FUN_00001580();
  _DAT_ffffc6fc = 0xff80;
  _DAT_ffffc6fe = 0xff80;
  DAT_ffff91ce._0_1_ = 0xff;
  DAT_ffff9812 = 2;
  vdp_palettes_something();
  palette_set_fade(PALETTE_ID_FLAG_ALL,
                   PALETTE_FADE_1,
                   duration,
                   (palette_color_iter_t)0xffffffff);
  FUN_00028018();
  vdp_set_vram_write_addr((void *)0xd000);
  sVar1 = 0x7f;
  do {
    VDP_DATA = 0x8781;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  DAT_ffffddde = 0;
  FUN_00028f32(unaff_A5, unaff_A3, extraout_A1);
  FUN_00028630();
  if (DAT_ffffdddf < '\0') {
    return 0xffffffff;
  }
  DAT_ffffcb2c = DAT_ffffdddf;
  return 0;
}

void save_menu_maybe(void)

{
  void *extraout_A1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A5;

  FUN_00155e78();
  DAT_ffffddde = 0xff;
  FUN_00028f32(unaff_A5, unaff_A3, extraout_A1);
  if (-1 < (char)DAT_ffffdddf) {
    DAT_ffffcb2c = DAT_ffffdddf;
    DAT_ffff96bf = 0xff;
    FUN_00156000((uint)DAT_ffffdddf);
  }
  FUN_0002861a();
  return;
}

// WARNING: Removing unreachable block (ram,0x000291ca)
// WARNING: Removing unreachable block (ram,0x000291de)
// WARNING: Removing unreachable block (ram,0x000291f4)
// WARNING: Removing unreachable block (ram,0x0002920a)
// WARNING: Removing unreachable block (ram,0x00029210)
// WARNING: Removing unreachable block (ram,0x00029218)

ushort FUN_00028f32(entity_id_t other, script_ctx_t *text_p, void *param_3)

{
  entity_state_1_a_t eVar1;
  char cVar2;
  word wVar3;
  undefined2 uVar4;
  gamepad_t gVar5;
  byte state_1_b;
  short sVar6;
  undefined2 *puVar7;
  short *psVar8;
  void *extraout_A1;
  func *extraout_A1_00;
  func *extraout_A1_01;
  func *f;
  func *f_00;
  entity_id_t self;
  entity_id_t other_b;
  int iVar9;

  text_unk_1(&DAT_00029228, param_3);
  text_unk_1(BYTE_ARRAY_0000c8bc, extraout_A1);
  uncompress_and_copy_to_vram();
  wVar3 = FUN_00027ff6();
  FUN_00027f20((uint3 *)&DAT_00029230, wVar3);
  ecs_init_entity_state(ENTITY_ID_F8, other, &component_mixed_1_t_000294c8);
  ecs_init_entity_state(ENTITY_ID_FC, other, &component_mixed_1_t_000294d2);
  FUN_0000c42c();
  uVar4 = 99;
  if ((DAT_ffffcbb0 & 1) != 0) {
    uVar4 = FUN_00029630();
  }
  DAT_ffffddf6 = uVar4;
  FUN_0000c42c();
  uVar4 = 99;
  if ((DAT_ffffcbb0 & 2) != 0) {
    uVar4 = FUN_00029630();
  }
  DAT_ffffddf8 = uVar4;
  FUN_000296dc();
  FUN_00029710();
  FUN_000296dc();
  FUN_00029710();
  FUN_000192d8();
  related_to_text_3(text_p);
  DAT_ffffdddf = DAT_ffffcb2c;
  FUN_00029686();
  do {
    related_to_text_3(&SCRIPT_CTX_CURRENT);
    // While flag 7 is set.
  } while ((char)SCRIPT_CTX_CURRENT.flags < '\0');
  DAT_ffff91ce._0_1_ = 0;
  FUN_00001630();
LAB_0002901e:
  do {
    while (true) {
      gVar5 = FUN_00155e88();
      if (((gamepad_pressed & gVar5) != GAMEPAD_NONE) ||
          ((gamepad_pressed & GAMEPAD_START) != GAMEPAD_NONE)) {
        if ((char)DAT_ffffdddf < '\0') {
          return (ushort)DAT_ffffdddf;
        }
        if (DAT_ffffdddf == 0) {
          self = ENTITY_ID_F8;
          state_1_b = 8;
          DAT_ffffdde0 = 0x40;
        } else {
          self = ENTITY_ID_FC;
          state_1_b = 0xc;
          DAT_ffffdde0 = 0xc0;
        }
        (&comp_collision_related)[self] = 0x2c;
        DAT_ffffddfa = (short)self;
        ecs_anim_unk_2(self, (anim_item_t *)other, state_1_b);
        entity_id_w_t_ffffddfc =
            CONCAT11(0xff, (undefined1)entity_id_w_t_ffffddfc);
        audio_play(SOUND_ID_RES_BTTN);
        do {
          while (true) {
            while (FUN_00029610(), -1 < (short)entity_id_w_t_ffffddfc) {
              other_b = (entity_id_t)(short)entity_id_w_t_ffffddfc;
              *(short *)((int)&comp_pos_y + other_b) =
                  *(short *)((int)&comp_vel[0].y + other_b) +
                  *(short *)((int)&comp_pos_y + other_b);
              psVar8 = (short *)((int)&comp_vel[0].y + other_b);
              *psVar8 = *psVar8 + 1;
              sVar6 = *(short *)(&comp_unk_4 + other_b) + -1;
              *(short *)(&comp_unk_4 + other_b) = sVar6;
              if (sVar6 == 0) {
                entity_id_w_t_ffffddfc =
                    CONCAT11(0xff, (undefined1)entity_id_w_t_ffffddfc);
                (&comp_has_func_maybe)[other_b] = 0;
              }
            }
            iVar9 = (int)DAT_ffffddfa;
            f = extraout_A1_00;
            if (((&comp_collision_related)[iVar9] != '\0') &&
                (cVar2 = (&comp_collision_related)[iVar9] + -1,
                 (&comp_collision_related)[iVar9] = cVar2,
                 cVar2 == '\0')) {
              audio_play(SOUND_ID_LOAD);
              f = extraout_A1_01;
            }
            eVar1 = (&comp_state_1_a)[iVar9];
            (&comp_state_1_a)[iVar9] = eVar1 & 0xdf;
            if ((eVar1 & 0x20) == 0)
              break;
            FUN_0000147a(f, 0, 4);
            entity_id_w_t_ffffddfc = 0xd5e8;
            ecs_init_entity_state(
                0xffffd5e8, other, &component_mixed_1_t_000294dc);
            DAT_ffff770a = DAT_ffffdde0;
            DAT_ffff8d5a = 8;
            DAT_ffff7a18 = 0xffec;
          }
        } while (*(short *)((int)&comp_anim_tick + iVar9) != 0);
        sVar6 = 7;
        puVar7 = &DAT_ffffddfa;
        do {
          *puVar7 = 0xffff;
          sVar6 = sVar6 + -1;
          puVar7 = puVar7 + 1;
        } while (sVar6 != -1);
        audio_play(SOUND_ID_FLOW);
        DAT_ffffde0a = ' ';
        DAT_ffffde0b = '\x04';
        DAT_ffffde0c = 2;
        do {
          FUN_00029610();
          if (DAT_ffffde0a == '\0') {
            sVar6 = 7;
            psVar8 = &DAT_ffffddfa;
            while (*psVar8 < 0) {
              sVar6 = sVar6 + -1;
              psVar8 = psVar8 + 1;
              if (sVar6 == -1) {
                if (DAT_ffffddde == '\0') {
                  return 0xffff;
                }
                FUN_0000147a(f_00, 0, 4);
                do {
                } while (true);
              }
            }
          } else if ((DAT_ffffde0b == '\0') ||
                     (DAT_ffffde0b = DAT_ffffde0b + -1, DAT_ffffde0b == '\0')) {
            FUN_000294e6();
          }
          FUN_00029582();
        } while (true);
      }
      if (((gamepad_pressed & GAMEPAD_B) != GAMEPAD_NONE) ||
          ((gamepad_pressed & GAMEPAD_DOWN) != GAMEPAD_NONE))
        goto LAB_00029046;
      if ((gamepad_pressed & GAMEPAD_LEFT) == GAMEPAD_NONE)
        break;
      if ((DAT_ffffdddf != 0) &&
          ((DAT_ffffddde != '\0' || ((DAT_ffffcbb0 & 1) != 0)))) {
        DAT_ffffdddf = 0;
        goto LAB_0002909e;
      }
    }
  } while ((((gamepad_pressed & GAMEPAD_RIGHT) == GAMEPAD_NONE) ||
            (DAT_ffffdddf == 1)) ||
           ((DAT_ffffddde == '\0' && ((DAT_ffffcbb0 & 2) == 0))));
  DAT_ffffdddf = 1;
  goto LAB_0002909e;
LAB_00029046:
  if ((char)DAT_ffffdddf < '\0')
    goto LAB_0002901e;
  DAT_ffffdddf = 0xff;
LAB_0002909e:
  audio_play(SOUND_ID_RES_KEY);
  FUN_00029686();
  goto LAB_0002901e;
}

void FUN_000294e6(void)

{
  short sVar1;
  word wVar2;
  undefined1 uVar3;
  short unaff_D2w;
  short *psVar4;
  func *in_A1;
  entity_id_t e;

  psVar4 = &DAT_ffffddfa;
  sVar1 = 7;
  while (-1 < *psVar4) {
    psVar4 = psVar4 + 1;
    sVar1 = sVar1 + -1;
    if (sVar1 == -1) {
      return;
    }
  }
  FUN_0000147a(in_A1, 0, 4);
  if (-1 < unaff_D2w) {
    DAT_ffffde0b = 4;
    DAT_ffffde0a = DAT_ffffde0a + -1;
    *(short *)(int)(short)psVar4 = unaff_D2w;
    e = (entity_id_t)unaff_D2w;
    *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 + e) = (short)psVar4;
    entity_reset(e);
    (&comp_has_func_maybe + e)[0] = COMPONENT_STATE_B_C0;
    (&comp_has_func_maybe + e)[1] = 0x80;
    *(undefined2 *)((int)&comp_unk_3 + e) = 0;
    (&comp_anim_base_offset + e)[0] = 0x14;
    (&comp_anim_base_offset + e)[1] = 0x26;
    (&comp_anim_c)[e] = 0xff;
    *(undefined2 *)((int)&comp_unk_4 + e) = 4;
    wVar2 = rand();
    *(short *)(&DAT_ffffbd76 + e) = (short)((wVar2 & 0x7fff) % 0x60) + -0x30;
    wVar2 = rand();
    *(word *)(&DAT_ffffbd78 + e) = (wVar2 | 0xffe0) - 0x20;
    uVar3 = 0;
    if (DAT_ffffddde != '\0') {
      uVar3 = 0x3f;
    }
    (&comp_collision_related)[e] = uVar3;
    if ((DAT_ffffddde == '\0') && (DAT_ffffde0a == '\0')) {
      palette_set_fade_black_ease_in_all();
      return;
    }
  }
  return;
}

short FUN_00029582(void)

{
  short sVar1;
  short *psVar2;
  short *psVar3;
  short local_2;

  local_2 = 8;
  psVar2 = &DAT_ffffddfa;
  do {
    psVar3 = psVar2 + 1;
    sVar1 = *psVar2;
    if (-1 < sVar1) {
      sVar1 = FUN_000295a0();
      psVar3 = (short *)(int)(short)psVar3;
    }
    local_2 = local_2 + -1;
    psVar2 = psVar3;
  } while (local_2 != 0);
  return sVar1;
}

void FUN_000295a0(void)

{
  byte bVar1;
  char cVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if (DAT_ffffddde == '\0') {
    bVar1 = (&comp_collision_related)[unaff_A4] + DAT_ffffde0c;
    (&comp_collision_related)[unaff_A4] = bVar1;
    if (bVar1 < 0x40) {
    LAB_000295cc:
      bVar1 = (&comp_collision_related)[unaff_A4];
      *(short *)((int)&comp_pos_x + unaff_A4) =
          DAT_ffffdde0 +
          (short)((uint)((int)(short)((ushort)bVar1 * (ushort)bVar1) *
                         (int)*(short *)(&DAT_ffffbd76 + unaff_A4) * 0x10) >>
                  0x10);
      *(short *)((int)&comp_pos_y + unaff_A4) =
          (short)((int)(short)(ushort)bVar1 *
                      (int)*(short *)(&DAT_ffffbd78 + unaff_A4) >>
                  6) +
          0x85;
      if ((&DAT_0002960c)[(
              short)(ushort)((byte)(&comp_collision_related)[unaff_A4] >> 4)] ==
          (&comp_anim_c)[unaff_A4]) {
        return;
      }
      ecs_anim_unk_2(
          unaff_A4,
          unaff_A5,
          (&DAT_0002960c)[(
              short)(ushort)((byte)(&comp_collision_related)[unaff_A4] >> 4)]);
      return;
    }
  } else {
    cVar2 = (&comp_collision_related)[unaff_A4] - DAT_ffffde0c;
    (&comp_collision_related)[unaff_A4] = cVar2;
    if (-1 < cVar2)
      goto LAB_000295cc;
  }
  (&comp_has_func_maybe)[unaff_A4] = 0;
  *(undefined1 *)(int)*(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk1 +
                                 unaff_A4) = 0xff;
  return;
}

void FUN_00029610(void)

{
  long in_D0;
  long in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;

  if (DAT_ffffddde == '\0') {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    in_D0,
                    in_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  } else {
    FUN_000028ce();
  }
  // If flag 7 is set.
  if ((char)SCRIPT_CTX_CURRENT.flags < '\0') {
    related_to_text_3(&SCRIPT_CTX_CURRENT);
  }
  return;
}

void FUN_00029630(void)

{
  word in_D0w;
  word *pwVar1;

  for (pwVar1 = &WORD_00029644; (-1 < (short)*pwVar1 && (in_D0w != *pwVar1));
       pwVar1 = pwVar1 + 2) {
  }
  return;
}

void FUN_00029686(void)

{
  short text_id;
  component_mixed_1_t *state;
  entity_id_t unaff_A5;

  state = &component_mixed_1_t_000296be;
  if ((-1 < DAT_ffffdddf) &&
      (state = &component_mixed_1_t_000296c8, DAT_ffffdddf != '\0')) {
    state = &component_mixed_1_t_000296d2;
  }
  ecs_init_entity_state(ENTITY_ID_F4, unaff_A5, state);
  text_id = 0x62;
  if ((-1 < DAT_ffffdddf) && (text_id = DAT_ffffddf6, DAT_ffffdddf != '\0')) {
    text_id = DAT_ffffddf8;
  }
  FUN_00019306(text_id);
  return;
}

void FUN_000296dc(void)

{
  short extraout_D0w;
  uint uVar1;
  uint extraout_D1;
  void *unaff_D2w;
  short sVar2;
  byte bVar3;
  uint *in_A0;
  bool bVar4;

  uVar1 = *in_A0;
  do {
    bVar3 = 0;
    sVar2 = 0x1f;
    do {
      bVar4 = CARRY4(uVar1, uVar1);
      uVar1 = uVar1 * 2;
      bVar3 = bVar3 * '\x02' + bVar4;
      if (9 < bVar3) {
        bVar3 = bVar3 - 10;
        uVar1 = CONCAT22((short)(uVar1 >> 0x10), (short)uVar1 + 1);
      }
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
    vdp_set_vram_write_addr(unaff_D2w);
    unaff_D2w = (void *)((short)unaff_D2w + -2);
    VDP_DATA = bVar3 + 0x85c4;
  } while ((extraout_D1 != 0) && (uVar1 = extraout_D1, extraout_D0w != 0));
  return;
}

void FUN_00029710(void)

{
  byte bVar1;
  ushort uVar2;
  short sVar3;
  short extraout_D1w;
  short unaff_D2w;
  short sVar4;
  ushort uVar5;
  ushort uVar6;
  int in_A0;

  bVar1 = *(byte *)(in_A0 + 6);
  uVar5 = (ushort)bVar1;
  sVar3 = (ushort) * (byte *)(in_A0 + 8) - (ushort)bVar1;
  uVar6 = uVar5;
  if (sVar3 < 0) {
    uVar6 = sVar3 + (ushort)bVar1;
  }
  FUN_0002973e();
  vdp_set_vram_write_addr((void *)(unaff_D2w + 0x40));
  sVar3 = 7;
  do {
    sVar4 = 5;
    uVar2 = uVar5;
    if (uVar6 != 0) {
      uVar6 = uVar6 - 2;
      if ((short)uVar6 < 0) {
        uVar6 = 0;
        sVar4 = 1;
        if (uVar5 != 0) {
          sVar4 = 3;
        }
      } else {
        sVar4 = 0;
        if (uVar5 != 0) {
          sVar4 = 4;
          uVar2 = uVar5 - 1;
          if ((ushort)(uVar5 - 1) != 0) {
            sVar4 = 2;
            uVar2 = uVar5 - 2;
          }
        }
      }
    }
    uVar5 = uVar2;
    VDP_DATA = extraout_D1w + sVar4;
    sVar3 = sVar3 + -1;
  } while (sVar3 != -1);
  return;
}

void FUN_0002973e(void)

{
  short sVar1;
  short extraout_D1w;
  void *unaff_D2w;
  short sVar2;
  short unaff_D4w;
  short unaff_D5w;
  short sVar3;

  vdp_set_vram_write_addr(unaff_D2w);
  sVar1 = 7;
  do {
    sVar2 = 5;
    sVar3 = unaff_D5w;
    if (unaff_D4w != 0) {
      unaff_D4w = unaff_D4w + -2;
      if (unaff_D4w < 0) {
        unaff_D4w = 0;
        sVar2 = 1;
        if (unaff_D5w != 0) {
          sVar2 = 3;
        }
      } else {
        sVar2 = 0;
        if (unaff_D5w != 0) {
          sVar2 = 4;
          sVar3 = unaff_D5w + -1;
          if ((short)(unaff_D5w + -1) != 0) {
            sVar2 = 2;
            sVar3 = unaff_D5w + -2;
          }
        }
      }
    }
    VDP_DATA = extraout_D1w + sVar2;
    sVar1 = sVar1 + -1;
    unaff_D5w = sVar3;
  } while (sVar1 != -1);
  return;
}

void FUN_00029778(void)

{
  ushort uVar1;

  uVar1 = (ushort)OWNED_SWORD;
  DAT_ffffde0e = (&DAT_000297d4)[(short)uVar1];
  DAT_ffffde0f = (&DAT_000297dc)[(short)uVar1];
  DAT_ffffde12 = (ushort)(byte)(&DAT_000297e4)[(short)uVar1];
  if (((&DAT_000297e4)[(short)uVar1] != 0) && (DAT_ffffde29 == 'd')) {
    DAT_ffffde12 = 3;
  }
  DAT_ffffde10 = (&DAT_000297f4)[(short)(ushort)(OWNED_SHIELD & 7)];
  DAT_ffffde14 =
      (ushort)(byte)(&DAT_000297ec)[(short)(ushort)(OWNED_SHIELD & 7)];
  red_hearts = get_red_hearts((ushort)OWNED_ARMOR);
  total_hearts_max = blue_hearts + red_hearts;
  if (total_hearts_max < total_hearts) {
    total_hearts = total_hearts_max;
  }
  return;
}

short get_red_hearts(ushort index)

{
  return (ushort)BYTE_ARRAY_00029806[(short)(index & 7)];
}

void FUN_0002980e(void)

{
  ushort uVar1;

  uVar1 = 0;
  do {
    if ((char)OWNED_INVENTORY[(short)uVar1] < '\0') {
      return;
    }
    uVar1 = uVar1 + 1;
  } while (uVar1 < 10);
  return;
}

// WARNING: Control flow encountered bad instruction data
// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

uint FUN_00029824(void)

{
  ushort uVar1;
  script_t *ppcVar2;
  item_t iVar3;
  item_t iVar4;
  undefined4 extraout_D0;
  undefined4 extraout_D0_00;
  uint in_D0;
  item_t iVar7;
  uint uVar5;
  word wVar6;
  uint extraout_D0_01;
  uint uVar8;
  ushort uVar9;
  undefined4 extraout_D1;
  undefined4 extraout_D1_00;
  short extraout_D1w;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  int iVar10;
  int unaff_D6;
  long unaff_D7;
  word *in_A0;
  ushort *extraout_A0;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar11;
  ushort in_stack_00000000;

  iVar7 = (item_t)in_D0;
  if (0x2f < iVar7) {
    uVar9 = (ushort)in_D0 & 0xf;
    uVar1 = uVar9 * 2;
    uVar5 = (uint)uVar1;
    switch (uVar9) {
    default:
      wVar6 = rand();
      gold = (uint)(ushort)(extraout_A0[1] + (*extraout_A0 & wVar6)) + gold;
      return (uint)wVar6;
    case 6:
      uVar9 = total_hearts + 1;
      if (uVar9 <= total_hearts_max) {
        total_hearts = uVar9;
      }
      return (uint)uVar9;
    case 7:
      uVar5 = FUN_0001a5fa();
      return uVar5;
    case 8:
      life_drops = life_drops + 1;
      if ((9 < life_drops) && (blue_hearts < 0xf)) {
        in_D0 = FUN_0001a878();
      }
      return in_D0;
    case 0xb:
      while (true) {
        iVar10 = CONCAT22((short)((uint)unaff_D6 >> 0x10), 2);
        uVar8 = 5;
        do {
          *(int *)(in_A0 + 2) = iVar10;
          in_A0[0] = 0;
          in_A0[1] = 0;
          iVar10 = iVar10 + 0x800000;
          uVar9 = (short)uVar8 - 1;
          uVar8 = (uint)uVar9;
        } while (uVar9 != 0xffff);
        in_stack_00000000 = in_stack_00000000 + 1;
        if (0x5f < in_stack_00000000)
          break;
        uVar11 = exception_unk_0(unaff_A3,
                                 unaff_A4,
                                 unaff_A6,
                                 0,
                                 uVar8,
                                 uVar5,
                                 unaff_D3,
                                 unaff_D4,
                                 unaff_D5,
                                 iVar10,
                                 unaff_D7);
        exception_unk_0(unaff_A3,
                        unaff_A4,
                        unaff_A6,
                        (long)((ulonglong)uVar11 >> 0x20),
                        (long)uVar11,
                        uVar5,
                        unaff_D3,
                        unaff_D4,
                        unaff_D5,
                        iVar10,
                        unaff_D7);
        in_A0 = &VDP_DATA;
        unaff_D6 =
            (uint)(ushort)(CONCAT11(
                               (char)((ushort)(in_stack_00000000 * 8) >> 8),
                               (byte)(in_stack_00000000 * 8) >> 3) *
                               4 +
                           0x7400)
            << 0x10;
      }
      audio_play(SOUND_ID_FA);
      DAT_ffff9f26 = 0;
      FUN_00026d54();
      ecs_anim_unk_2(ENTITY_ID_08, unaff_A5, 4);
      uVar11 = CONCAT44(extraout_D0, extraout_D1);
      do {
        uVar11 = exception_unk_0(unaff_A3,
                                 ENTITY_ID_08,
                                 unaff_A6,
                                 (long)((ulonglong)uVar11 >> 0x20),
                                 (long)uVar11,
                                 uVar5,
                                 unaff_D3,
                                 unaff_D4,
                                 unaff_D5,
                                 iVar10,
                                 unaff_D7);
      } while (_DAT_ffffa53c != 0);
      ecs_anim_unk_2(ENTITY_ID_0C, unaff_A5, 6);
      uVar11 = CONCAT44(extraout_D0_00, extraout_D1_00);
      DAT_ffffa12e = 0x80;
      DAT_ffffa232 = 0xa4;
      do {
        uVar11 = exception_unk_0(unaff_A3,
                                 ENTITY_ID_0C,
                                 unaff_A6,
                                 (long)((ulonglong)uVar11 >> 0x20),
                                 (long)uVar11,
                                 uVar5,
                                 unaff_D3,
                                 unaff_D4,
                                 unaff_D5,
                                 iVar10,
                                 unaff_D7);
      } while ((gamepad_pressed & GAMEPAD_START) == GAMEPAD_NONE);
      audio_play(SOUND_ID_FE);
      palette_set_fade_black_ease_in_all();
      uVar11 = FUN_00026d54();
      uVar8 = (uint)((ulonglong)uVar11 >> 0x20);
      if (((undefined1)vdp_ctrl_mode_set_2_state & 0x40) != 0) {
        related_to_palette_maybe_1 = 0xff;
        related_to_palette_maybe_2 = 0;
        uVar11 = exception_unk_0(unaff_A3,
                                 ENTITY_ID_0C,
                                 unaff_A6,
                                 uVar8,
                                 (long)uVar11,
                                 uVar5,
                                 unaff_D3,
                                 unaff_D4,
                                 unaff_D5,
                                 iVar10,
                                 unaff_D7);
        uVar8 = (uint)((ulonglong)uVar11 >> 0x20);
      }
      return uVar8;
    case 0xc:
      // WARNING: Bad instruction - Truncating control flow here
      halt_baddata();
    case 0xd:
      // WARNING: Bad instruction - Truncating control flow here
      halt_baddata();
    case 0xe:
      *(char *)((int)unaff_A3 + (short)uVar1 + -1) = (char)unaff_D3 + '\x01';
      return in_D0;
    case 0xf:
      while (true) {
        DAT_ffffc8e0 = 2;
        FUN_0000b85e(*(undefined2 **)unaff_A3);
        ppcVar2 = &unaff_A3->script;
        DAT_ffffc8de = *(short *)&unaff_A3->script;
        if (DAT_ffffc8de < 0)
          break;
        unaff_A3 = (script_ctx_t *)&unaff_A3->b;
        DAT_ffffc8dc = *(undefined2 *)((int)ppcVar2 + 2);
        DAT_ffffc8e2 = 2;
      }
      return extraout_D0_01;
    }
  }
  if ((iVar7 != 0x1b) && (iVar7 < ITEM_MAGIC_LAMP)) {
    if (iVar7 == ITEM_HEALING_MEDICINE) {
      OWNED_HEALING_MEDICINE_COUNT = 0xff;
      return in_D0;
    }
    OWNED_EQUIPMENT_FLAGS[(short)((in_D0 & 0xf8) >> 3)] =
        OWNED_EQUIPMENT_FLAGS[(short)((in_D0 & 0xf8) >> 3)] |
        '\x01' << (iVar7 & 7);
    iVar4 = OWNED_ARMOR;
    if (iVar7 < ITEM_PLAIN_SHIELD) {
      DAT_ffffde29 = '\0';
      OWNED_SWORD = iVar7;
      iVar3 = OWNED_SHIELD;
    } else {
      iVar3 = iVar7;
      if ((0xf < iVar7) &&
          (iVar3 = OWNED_SHIELD, iVar4 = iVar7, 0x17 < iVar7)) {
        return in_D0;
      }
    }
    OWNED_ARMOR = iVar4;
    OWNED_SHIELD = iVar3;
    uVar9 = (ushort)OWNED_SWORD;
    DAT_ffffde0e = (&DAT_000297d4)[(short)uVar9];
    DAT_ffffde0f = (&DAT_000297dc)[(short)uVar9];
    DAT_ffffde12 = (ushort)(byte)(&DAT_000297e4)[(short)uVar9];
    if (((&DAT_000297e4)[(short)uVar9] != 0) && (DAT_ffffde29 == 'd')) {
      DAT_ffffde12 = 3;
    }
    DAT_ffffde10 = (&DAT_000297f4)[(short)(ushort)(OWNED_SHIELD & 7)];
    DAT_ffffde14 =
        (ushort)(byte)(&DAT_000297ec)[(short)(ushort)(OWNED_SHIELD & 7)];
    red_hearts = get_red_hearts((ushort)OWNED_ARMOR);
    total_hearts_max = blue_hearts + red_hearts;
    if (total_hearts_max < total_hearts) {
      total_hearts = total_hearts_max;
    }
    return (uint)total_hearts_max;
  }
  uVar5 = FUN_0002980e();
  if (9 < (byte)extraout_D1w) {
    return uVar5;
  }
  OWNED_INVENTORY[extraout_D1w] = (item_t)uVar5;
  return uVar5;
}

void FUN_00029908(void)

{
  FUN_0001a5fa();
  return;
}

// While the code seem to return D1, the only call site actually usez ZF, which
// has the opposite value of D1. Hence, let's return ZF.

bool item_can_be_sold(item_t item)

{
  bool owned;

  if (item < ITEM_PLAIN_SHIELD) {
    // If it is a sword
    owned = item == OWNED_SWORD;
  } else if (item < ITEM_TRAVELER_ARMOR) {
    // If it is a shield
    owned = item == OWNED_SHIELD;
  } else {
    if (0x17 < item) {
      if (item != ITEM_HEALING_MEDICINE) {
        return true;
      }
      if (OWNED_HEALING_MEDICINE_COUNT == '\0') {
        return true;
      }
      return false;
    }
    owned = item == OWNED_ARMOR;
  }
  if (!owned) {
    return true;
  }
  return false;
}

bool item_check_isnt_owned(item_t item)

{
  short i;

  if (item < ITEM_MAGIC_LAMP) {
    if (item == ITEM_HEALING_MEDICINE) {
      return OWNED_HEALING_MEDICINE_COUNT == '\0';
    }
    return (OWNED_EQUIPMENT_FLAGS[(short)(ushort)(item >> 3)] &
            '\x01' << (item & 7)) == 0;
  }
  i = 0;
  do {
    if (item == OWNED_INVENTORY[i]) {
      return item == ITEM_ASHA_SWORD;
    }
    i = i + 1;
  } while (i != 10);
  return i == 10;
}

// This removes all instances of an item in the inventory, leaving no gap in the
// process.

void item_remove_from_inventory(item_t item)

{
  ushort i;
  short j;
  item_t *inventory;

  if (ITEM_HEALING_MEDICINE < item) {
    inventory = OWNED_INVENTORY;
    i = 0;
    do {
      if (item == *inventory) {
        j = 9 - i;
        while (j = j + -1, j != -1) {
          *inventory = inventory[1];
          inventory = inventory + 1;
        }
        *inventory = ITEM_NONE;
        return;
      }
      i = i + 1;
      inventory = inventory + 1;
    } while (i < 10);
  }
  return;
}

void FUN_000299c0(item_t *inventory, item_t item)

{
  undefined1 in_register_00000006;
  short i;

  i = 9 - CONCAT11(in_register_00000006, item);
  // Iterate over the 10 items of the inventory.
  while (i = i + -1, i != -1) {
    *inventory = inventory[1];
    inventory = inventory + 1;
  }
  *inventory = ITEM_NONE;
  return;
}

void asha_gain_hearts(short total_hearts_gain)

{
  sound_id_t sound_id;
  word total_hearts_old;

  total_hearts_old = total_hearts;
  total_hearts = total_hearts + total_hearts_gain;
  if (total_hearts_max < total_hearts) {
    total_hearts = total_hearts_max;
  }
  if (total_hearts_old != total_hearts) {
    sound_id = SOUND_ID_GET_MEAT;
    if ((word)(total_hearts_old - total_hearts) != -1) {
      sound_id = SOUND_ID_LIFE;
    }
    audio_play(sound_id);
    return;
  }
  return;
}

void related_to_entering_a_room(void)

{
  if ((-1 < (char)script_ctx_bf_0e_arg) && (script_ctx_bf_0e_arg < 3)) {
    pepelogoo_state_b = '\0';
    related_to_entering_a_room_2 = 0;
    related_to_entering_a_room_3 = 0;
    related_to_entering_a_room_4 = 0;
    related_to_entering_a_room_5 = 0xff;
    related_to_entering_a_room_6 = 0xff;
    if (related_to_entering_a_room_7 == '\0') {
      FUN_00029a6a();
    }
  }
  return;
}

void FUN_00029a2c(void)

{
  if ((-1 < (char)script_ctx_bf_0e_arg) && (script_ctx_bf_0e_arg < 3)) {
    FUN_00029a46();
    return;
  }
  component_state_b_pepelogoo = 0;
  return;
}

void FUN_00029a46(void)

{
  DAT_ffff9a28 =
      *(undefined2 *)(&DAT_00029a62 +
                      (short)(ushort)(byte)(script_ctx_bf_0e_arg * '\x02'));
  return;
}

void FUN_00029a6a(void)

{
  anim_item_t *unaff_A5;
  bool bVar1;
  undefined8 uVar2;

  entity_reset(ENTITY_ID_PEPELOGOO);
  component_unknown_3_pepelogoo = 0xe;
  DAT_ffff9f1f = DAT_ffff9f1f | 0x80;
  DAT_ffffa63a = 0x10;
  DAT_ffffa63b = script_ctx_bf_0e_arg * '\x02';
  uVar2 = FUN_0002a19e();
  component_pos_x_pepelogoo.raw = (long)((ulonglong)uVar2 >> 0x20);
  component_pos_y_pepelogoo.raw = (long)uVar2;
  bVar1 = false;
  FUN_00029ac6();
  if (bVar1) {
    if ((comp_state_a & ENTITY_STATE_A_08) == 0) {
      component_pos_x_pepelogoo.fixed.i =
          component_pos_x_pepelogoo.fixed.i + 0x40;
    } else {
      component_pos_x_pepelogoo.fixed.i =
          component_pos_x_pepelogoo.fixed.i + -0x40;
    }
  }
  component_state_a_pepelogoo = 0;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 0);
  return;
}

void FUN_00029ac6(void)

{
  return;
}

void FUN_00029aee(void)

{
  short unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;

  if (((related_to_entering_a_room_7 == '\0') &&
       (-1 < (char)script_ctx_bf_0e_arg)) &&
      (script_ctx_bf_0e_arg < 3)) {
    player_collision_offset[1].x = 0;
    player_collision_offset[1].y = 0;
    entity_update_pos(ENTITY_ID_PEPELOGOO);
    DAT_ffffde3f = DAT_ffffb570;
    if ((related_to_entering_a_room_2 & 4) != 0) {
      interact_with_all_other_entities(
          ENTITY_ID_PEPELOGOO, unaff_D2w, (char)unaff_D3w);
      ecs_update_collision(4, unaff_D3w, unaff_D6w, unaff_D7w);
      ecs_apply_collision(4);
    }
    comp_func_offset[1].func_offset_from_15ede = 0;
    (*(code *)(&UNK_00029b54 +
               *(short *)(&UNK_00029b54 +
                          (short)component_state_a_pepelogoo)))();
    FUN_0002a6c4();
    FUN_0002a8ea();
  }
  return;
}

undefined4 FUN_00029b9c(void)

{
  undefined4 uVar1;
  int unaff_A4;

  uVar1 = 0;
  if ((DAT_ffffcbf6 != 0) &&
      (DAT_ffffcbf6 <=
       (ushort)(*(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
                *(short *)((int)&comp_pos_y + unaff_A4)))) {
    uVar1 = 0xffffffff;
  }
  return uVar1;
}

undefined4 FUN_00029bb4(void)

{
  ushort uVar1;
  undefined4 uVar2;
  int unaff_A4;

  uVar2 = 0;
  if ((DAT_ffffcbf6 != 0) &&
      (uVar1 = *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
               *(short *)((int)&comp_pos_y + unaff_A4),
       DAT_ffffcbf6 <= uVar1)) {
    *(ushort *)((int)&comp_pos_y + unaff_A4) =
        uVar1 - *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
    uVar2 = 0xffffffff;
  }
  return uVar2;
}

void FUN_00029c48(void)

{
  int unaff_A4;

  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfc00;
  return;
}

void FUN_00029c54(void)

{
  short *psVar1;
  entity_id_t unaff_A4;
  bool bVar2;

  bVar2 = ecs_get_cannot_jump(unaff_A4);
  if (bVar2) {
    related_to_entering_a_room_5 = 0xe;
  } else {
    related_to_entering_a_room_5 = 0x10;
  }
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x20;
  if (0x200 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x200;
  }
  return;
}

void FUN_00029c7e(void)

{
  short *psVar1;
  int unaff_A4;

  if ((related_to_entering_a_room_2 & 0x80) == 0) {
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + -0x20;
    if (*(short *)((int)&comp_vel[0].y + unaff_A4) < -0x100) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xff00;
    }
  } else {
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + 0x20;
    if (0x100 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x100;
    }
  }
  if (related_to_entering_a_room_3 == '\0') {
    related_to_entering_a_room_3 = ' ';
    related_to_entering_a_room_2 = related_to_entering_a_room_2 ^ 0x80;
  }
  related_to_entering_a_room_3 = related_to_entering_a_room_3 + -1;
  return;
}

void FUN_00029cc8(void)

{
  ushort uVar1;
  ushort uVar2;
  int unaff_A4;

  uVar1 = *(ushort *)((int)&comp_pos_x + unaff_A4);
  uVar2 = *(ushort *)((int)&comp_pos_y + unaff_A4);
  if ((ushort)comp_pos_x._0_2_ < uVar1) {
    if ((ushort)(comp_pos_x.fixed.i + 0x70U) < uVar1)
      goto LAB_00029d04;
  } else if (uVar1 <= (ushort)(comp_pos_x.fixed.i - 0x70U))
    goto LAB_00029d04;
  if ((ushort)comp_pos_y._0_2_ < uVar2) {
    if (uVar2 <= (ushort)(comp_pos_y.fixed.i + 0x70U)) {
      return;
    }
  } else if ((ushort)(comp_pos_y.fixed.i - 0x70U) < uVar2) {
    return;
  }
LAB_00029d04:
  *(undefined2 *)((int)&comp_state + unaff_A4) = 8;
  return;
}

void FUN_00029d0c(void)

{
  int unaff_A4;

  related_to_entering_a_room_2 = related_to_entering_a_room_2 & 0xfa;
  pepelogoo_state_b = pepelogoo_state_b & 0xaf;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0xe;
  if (*(short *)((int)&comp_state + unaff_A4) != 2) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    pepelogoo_state_b = pepelogoo_state_b & 0x7f;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
    related_to_entering_a_room_3 = 0;
    related_to_entering_a_room_2 = related_to_entering_a_room_2 & 0x7f;
    related_to_entering_a_room_5 = 4;
  }
  return;
}

void drop_pepelogoo(void)

{
  uint8_t old_state;

  // Called to drop Pepelogoo by pressing down when on the ground.
  old_state = pepelogoo_state_b;
  pepelogoo_state_b = pepelogoo_state_b & 0xbf;
  component_unknown_3_pepelogoo = 0xe;
  comp_vel[1].x.raw = 0;
  comp_vel[1].y.raw = 0;
  if (component_state_a_pepelogoo != 2) {
    pepelogoo_state_b = old_state & 0x2f;
    component_state_a_pepelogoo = 2;
    related_to_entering_a_room_3 = 0;
    related_to_entering_a_room_2 = related_to_entering_a_room_2 & 0x6f;
    if ((DAT_ffffcbf6 == 0) ||
        ((ushort)(comp_collision_sensor[1].y +
                  component_pos_y_pepelogoo.fixed.i) < DAT_ffffcbf6)) {
      related_to_entering_a_room_5 = 4;
    } else {
      related_to_entering_a_room_5 = 0x1a;
    }
  }
  return;
}

void FUN_00029dc0(void)

{
  anim_item_t *unaff_A5;

  component_unknown_3_pepelogoo = 0xe;
  component_state_b_pepelogoo = 0;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 0x18);
  return;
}

void FUN_00029dda(void)

{
  anim_item_t *unaff_A5;

  component_unknown_3_pepelogoo = 0xe;
  component_state_b_pepelogoo = 0;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 0x1a);
  return;
}

void FUN_00029ede(void)

{
  int unaff_A4;

  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0xe;
  if ((pepelogoo_state_b & 8) != 0) {
    related_to_entering_a_room_5 = 8;
  }
  if ((pepelogoo_state_b & 4) != 0) {
    related_to_entering_a_room_5 = 0xc;
  }
  if ((pepelogoo_state_b & 2) != 0) {
    related_to_entering_a_room_5 = 10;
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  }
  if ((pepelogoo_state_b & 1) != 0) {
    related_to_entering_a_room_5 = 10;
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  }
  return;
}

void FUN_00029f2a(void)

{
  short sVar1;
  entity_id_t unaff_A4;
  bool bVar2;

  if (((((&component_unknown_5)[unaff_A4] & 0xf) == 0) &&
       (*(short *)((int)&player_collision_offset[0].x + unaff_A4) == 0)) &&
      (*(short *)((int)&player_collision_offset[0].y + unaff_A4) == 0)) {
    bVar2 = FUN_00000eae(unaff_A4);
    if (!bVar2) {
      sVar1 = FUN_00029bb4();
      if (sVar1 == 0) {
        return;
      }
    }
  }
  related_to_entering_a_room_2 = related_to_entering_a_room_2 & 0xfa;
  pepelogoo_state_b = pepelogoo_state_b & 0xaf;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0xe;
  if (*(short *)((int)&comp_state + unaff_A4) != 2) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    pepelogoo_state_b = pepelogoo_state_b & 0x7f;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
    related_to_entering_a_room_3 = 0;
    related_to_entering_a_room_2 = related_to_entering_a_room_2 & 0x7f;
    related_to_entering_a_room_5 = 4;
  }
  return;
}

void FUN_0002a088(void)

{
  short *psVar1;
  uint in_D1;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + -0x20;
  if (*(short *)((int)&comp_vel[0].y + unaff_A4) < -0x200) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfe00;
  }
  if ((uint)(*(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
             *(int *)((int)&comp_pos_y + unaff_A4)) < in_D1) {
    *(short *)((int)&comp_vel[0].y + unaff_A4) =
        (short)(in_D1 - *(int *)((int)&comp_pos_y + unaff_A4) >> 8);
  }
  return;
}

void FUN_0002a136(void)

{
  short *psVar1;
  uint in_D1;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x20;
  if (0x400 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x400;
  }
  if (in_D1 < (uint)(*(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
                     *(int *)((int)&comp_pos_y + unaff_A4))) {
    *(short *)((int)&comp_vel[0].y + unaff_A4) =
        (short)(in_D1 - *(int *)((int)&comp_pos_y + unaff_A4) >> 8);
  }
  return;
}

void FUN_0002a16a(void)

{
  short *psVar1;
  uint in_D1;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + -0x20;
  if (*(short *)((int)&comp_vel[0].y + unaff_A4) < -0x400) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfc00;
  }
  if ((uint)(*(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
             *(int *)((int)&comp_pos_y + unaff_A4)) < in_D1) {
    *(short *)((int)&comp_vel[0].y + unaff_A4) =
        (short)(in_D1 - *(int *)((int)&comp_pos_y + unaff_A4) >> 8);
  }
  return;
}

undefined8 FUN_0002a19e(void)

{
  int iVar1;
  uint uVar2;

  uVar2 = comp_pos_y.raw - 0x200000;
  if ((comp_state_a & ENTITY_STATE_A_08) == 0) {
    iVar1 = comp_pos_x.raw + -0x200000;
  } else {
    iVar1 = comp_pos_x.raw + 0x200000;
  }
  if (DAT_ffffcbf6 != 0) {
    uVar2 = uVar2 & 0xffff0000;
  }
  return CONCAT44(iVar1, uVar2);
}

int16_t FUN_0002a1d8(void)

{
  return comp_pos_x.fixed.i;
}

void FUN_0002a270(void)

{
  related_to_entering_a_room_2 = related_to_entering_a_room_2 | 0x10;
  related_to_entering_a_room_3 = related_to_entering_a_room_3 + -1;
  if (related_to_entering_a_room_3 == '\0') {
    FUN_00029d0c();
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002a286(void)

{
  short *psVar1;
  short sVar2;
  entity_id_t unaff_A4;

  sVar2 = FUN_00001948();
  if (sVar2 != 0) {
    related_to_entering_a_room_2 = related_to_entering_a_room_2 & 0xfa;
    pepelogoo_state_b = pepelogoo_state_b & 0xaf;
    *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0xe;
    if (*(short *)((int)&comp_state + unaff_A4) != 2) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      pepelogoo_state_b = pepelogoo_state_b & 0x7f;
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
      *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
      related_to_entering_a_room_3 = 0;
      related_to_entering_a_room_2 = related_to_entering_a_room_2 & 0x7f;
      related_to_entering_a_room_5 = 4;
    }
    return;
  }
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & 0x7f;
  pepelogoo_state_b = pepelogoo_state_b & 0xbf;
  related_to_entering_a_room_2 = related_to_entering_a_room_2 | 0x10;
  if (((&component_unknown_5)[unaff_A4] & 4) != 0) {
    ecs_entity_something_1(unaff_A4);
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    DAT_ffffde2f = 4;
  }
  if ((DAT_ffffde2f & 8) != 0) {
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + -0x40;
    if (*(short *)((int)&comp_vel[0].y + unaff_A4) < -0x200) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfe00;
    }
    if ((ushort)(*(short *)((int)&comp_pos_y + (int)_DAT_ffffde30) -
                 *(short *)((int)&comp_collision_sensor[0].y +
                            (int)_DAT_ffffde30)) <=
        (ushort)(*(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
                 *(short *)((int)&comp_pos_y + unaff_A4) + 0x10U)) {
      return;
    }
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    DAT_ffffde2f = 4;
  }
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x40;
  if (0x200 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x200;
  }
  return;
}

void ecs_entity_something_1(entity_id_t self)

{
  *(undefined2 *)((int)&comp_unk_3 + self) = 0xe;
  if ((&comp_anim_c)[self] != 0x16) {
    audio_play(SOUND_ID_PEPE_VOICE_2);
    related_to_entering_a_room_5 = 0x16;
  }
  return;
}

void FUN_0002a338(void)

{
  int unaff_A4;

  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0xe;
  related_to_entering_a_room_5 = 4;
  return;
}

void FUN_0002a346(void)

{
  undefined2 uVar1;
  undefined2 uVar2;
  int16_t iVar3;
  int16_t extraout_D1w;
  short unaff_D2w;

  component_unknown_3_pepelogoo = 0xe;
  iVar3 = FUN_0002a1d8();
  uVar2 = component_pos_y_pepelogoo.fixed.i;
  uVar1 = component_pos_x_pepelogoo.fixed.i;
  component_pos_x_pepelogoo.fixed.i = iVar3;
  component_pos_y_pepelogoo.fixed.i = extraout_D1w;
  FUN_0002a3a8();
  if (unaff_D2w == 0) {
    DAT_ffffb571 = 0;
    DAT_ffffb570 = 0;
    DAT_ffffb674 = 0;
    pepelogoo_state_b = pepelogoo_state_b | 0x80;
    comp_vel[1].x.raw = 0;
    comp_vel[1].y.raw = 0;
    component_state_a_pepelogoo = 4;
    related_to_entering_a_room_5 = 0x12;
    return;
  }
  component_pos_x_pepelogoo.fixed.i = uVar1;
  component_pos_y_pepelogoo.fixed.i = uVar2;
  return;
}

byte FUN_0002a3a8(void)

{
  int unaff_A4;

  (&component_collision_flags)[unaff_A4] = 0;
  (&component_unknown_5)[unaff_A4] = 0;
  FUN_00018184();
  FUN_00018206();
  FUN_0001830e();
  FUN_0001828c();
  return (&component_collision_flags)[unaff_A4] & 0xf;
}

void ecs_pepelogoo_something_3(entity_id_t self)

{
  if (component_state_a_pepelogoo != 0x26) {
    if ((component_state_a_pepelogoo != 10) &&
        (related_to_entering_a_room_2 = related_to_entering_a_room_2 & 0xfb,
         (pepelogoo_state_b & 0x20) == 0)) {
      audio_play(SOUND_ID_PEPE_VOICE_1);
      component_state_a_pepelogoo = 10;
      related_to_entering_a_room_5 = 6;
    }
    return;
  }
  ecs_holding_a_rope = ecs_holding_a_rope | 8;
  component_unknown_3_pepelogoo = 0xe;
  component_state_a_pepelogoo = 0x28;
  component_state_b_pepelogoo = 0;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, (anim_item_t *)self, 0x1e);
  audio_play(SOUND_ID_PEPE_VOICE_1);
  return;
}

void ecs_pepelogoo_something_2(void)

{
  if ((component_state_a_pepelogoo != 0x18) &&
      ((pepelogoo_state_b & 0x20) == 0)) {
    audio_play(SOUND_ID_PEPE_VOICE_1);
    component_state_a_pepelogoo = 0x18;
    related_to_entering_a_room_5 = 6;
  }
  return;
}

void FUN_0002a504(void)

{
  byte bVar1;
  gamepad_t state_1_b;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  bVar1 = pepelogoo_state_b & 0x60;
  pepelogoo_state_b = bVar1 | 0x40;
  component_unknown_3_pepelogoo = 0xe;
  state_1_b = gamepad_held & GAMEPAD_DPAD_ANY;
  if (state_1_b == GAMEPAD_NONE) {
    if ((comp_state_a & ENTITY_STATE_A_08) == 0) {
      pepelogoo_state_b = bVar1 | 0x41;
      state_1_b = GAMEPAD_RIGHT | GAMEPAD_DOWN;
      DAT_ffff9f1f = DAT_ffff9f1f & 0xf7;
    } else {
      pepelogoo_state_b = bVar1 | 0x42;
      state_1_b = GAMEPAD_RIGHT | GAMEPAD_DOWN;
      DAT_ffff9f1f = DAT_ffff9f1f | 8;
    }
  } else {
    if ((gamepad_held & GAMEPAD_UP) != GAMEPAD_NONE) {
      pepelogoo_state_b = bVar1 | 0x48;
      state_1_b = GAMEPAD_RIGHT;
    }
    if ((gamepad_held & GAMEPAD_DOWN) != GAMEPAD_NONE) {
      pepelogoo_state_b = pepelogoo_state_b | 4;
      state_1_b = GAMEPAD_DPAD_X;
    }
    if ((gamepad_held & GAMEPAD_LEFT) != GAMEPAD_NONE) {
      pepelogoo_state_b = pepelogoo_state_b | 2;
      state_1_b = GAMEPAD_RIGHT | GAMEPAD_DOWN;
      DAT_ffff9f1f = DAT_ffff9f1f | 8;
    }
    if ((gamepad_held & GAMEPAD_RIGHT) != GAMEPAD_NONE) {
      pepelogoo_state_b = pepelogoo_state_b | 1;
      state_1_b = GAMEPAD_RIGHT | GAMEPAD_DOWN;
      DAT_ffff9f1f = DAT_ffff9f1f & 0xf7;
    }
  }
  component_state_a_pepelogoo = 6;
  related_to_entering_a_room_2 = related_to_entering_a_room_2 | 4;
  comp_vel[1].x.raw = 0;
  comp_vel[1].y.raw = 0;
  related_to_entering_a_room_5 = state_1_b;
  (&comp_anim_b)[unaff_A4] = 6;
  if ((pepelogoo_state_b & 8) != 0) {
    state_1_b = GAMEPAD_RIGHT | GAMEPAD_DOWN;
  }
  if ((pepelogoo_state_b & 4) != 0) {
    state_1_b = GAMEPAD_DPAD_X;
  }
  if ((pepelogoo_state_b & 2) != 0) {
    state_1_b = GAMEPAD_RIGHT;
  }
  if ((pepelogoo_state_b & 1) != 0) {
    state_1_b = GAMEPAD_RIGHT;
  }
  ecs_anim_unk_2(unaff_A4, unaff_A5, state_1_b);
  return;
}

void FUN_0002a5ec(void)

{
  short sVar1;
  int iVar2;
  int unaff_A4;

  if (*(short *)((int)&comp_state + unaff_A4) == 6) {
    iVar2 = 8;
    sVar1 = 10;
    do {
      if (((char)(&comp_has_func_maybe)[iVar2] < '\0') &&
          (-1 < *(short *)((int)&comp_unk_8 + iVar2))) {
        FUN_0002a612();
      }
      iVar2 = iVar2 + 4;
      sVar1 = sVar1 + -1;
    } while (sVar1 != -1);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002a612(void)

{
  ushort uVar1;
  int unaff_A3;
  int unaff_A4;
  bool bVar2;
  bool bVar3;

  bVar3 = (byte)(&comp_collision_related)[unaff_A3] < 8;
  bVar2 = (&comp_collision_related)[unaff_A3] == 8;
  if (!bVar2) {
    return;
  }
  ecs_check_collides_x(unaff_A4, unaff_A3);
  if (bVar3 || bVar2) {
    if (*(short *)((int)&comp_vel[0].x + unaff_A4) < 0) {
      if (*(ushort *)((int)&comp_pos_x + unaff_A3) <
          *(ushort *)((int)&comp_pos_x + unaff_A4)) {
        return;
      }
    } else if (*(ushort *)((int)&comp_pos_x + unaff_A4) <
               *(ushort *)((int)&comp_pos_x + unaff_A3)) {
      return;
    }
  } else {
    uVar1 = *(ushort *)((int)&comp_pos_x + unaff_A3);
    if (*(ushort *)((int)component_pos_old_x + unaff_A4) < uVar1) {
      if (*(ushort *)((int)&comp_pos_x + unaff_A4) < uVar1) {
        return;
      }
    } else if (uVar1 <= *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      return;
    }
  }
  _DAT_ffffde30 = (undefined2)unaff_A3;
  DAT_ffffde2f = 0;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0xe;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 0xe;
  related_to_entering_a_room_2 = related_to_entering_a_room_2 | 4;
  *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A3);
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  bVar2 = true;
  bVar3 = false;
  ecs_check_collides_x(unaff_A4, unaff_A3);
  if (bVar3 || bVar2) {
    DAT_ffffde2f = DAT_ffffde2f | 8;
  } else if ((ushort)(*(short *)((int)&comp_pos_y + unaff_A3) -
                      *(short *)((int)&comp_collision_sensor[0].y + unaff_A3)) <
             (ushort)(*(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
                      *(short *)((int)&comp_pos_y + unaff_A4) + 0x10U)) {
    DAT_ffffde2f = DAT_ffffde2f | 8;
  } else {
    DAT_ffffde2f = DAT_ffffde2f | 4;
  }
  FUN_0002a338();
  return;
}

void FUN_0002a6c4(void)

{
  FUN_0002a6d4();
  FUN_0002a738();
  return;
}

void FUN_0002a6d4(void)

{
  FUN_0002a5ec();
  return;
}

void FUN_0002a6da(void)

{
  int16_t extraout_D1w;
  anim_item_t *unaff_A5;

  if ((-1 < (char)script_ctx_bf_0e_arg) && (script_ctx_bf_0e_arg < 3)) {
    component_state_b_pepelogoo = 0;
    DAT_ffffa63d = 0;
    if (-1 < (char)pepelogoo_state_b) {
      component_state_a_pepelogoo = 0;
      ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 0);
      return;
    }
    ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, DAT_ffffa63c);
    component_pos_x_pepelogoo.fixed.i = FUN_0002a1d8();
    component_pos_y_pepelogoo.fixed.i = extraout_D1w;
  }
  return;
}

void FUN_0002a720(void)

{
  if ((-1 < (char)script_ctx_bf_0e_arg) && (script_ctx_bf_0e_arg < 3)) {
    component_state_b_pepelogoo = 0;
  }
  return;
}

void FUN_0002a738(void)

{
  short *psVar1;
  ushort uVar2;
  undefined1 extraout_var;
  entity_id_t self;
  int unaff_A4;
  bool bVar3;

  if (*(short *)((int)&comp_state + unaff_A4) == 6) {
    self = 0x84;
    do {
      if (((*(short *)(&comp_unk_1 + self) == 5) &&
           (bVar3 = FUN_00000eae(self), !bVar3)) &&
          (CONCAT11(extraout_var,
                    *(undefined1 *)((int)&comp_pos_y + unaff_A4)) <
           *(ushort *)((int)&comp_pos_y + self))) {
        uVar2 = *(ushort *)((int)&comp_pos_x + self);
        psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
        if (*psVar1 != 0) {
          if (*psVar1 < 0) {
            if ((uVar2 <= *(ushort *)((int)component_pos_old_x + unaff_A4)) &&
                (*(ushort *)((int)&comp_pos_x + unaff_A4) <= uVar2))
              goto LAB_0002a784;
          } else if ((*(ushort *)((int)component_pos_old_x + unaff_A4) <=
                      uVar2) &&
                     (uVar2 <= *(ushort *)((int)&comp_pos_x + unaff_A4))) {
          LAB_0002a784:
            *(ushort *)((int)&comp_pos_x + unaff_A4) = uVar2;
            FUN_00014960();
            *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
            *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x200;
            related_to_entering_a_room_5 = 4;
            *(undefined2 *)((int)&comp_state + unaff_A4) = 0x10;
            return;
          }
        }
      }
      self = self + ENTITY_ID_PEPELOGOO;
    } while (self < 0xcc);
  }
  return;
}

void FUN_0002a8b6(void)

{
  anim_item_t *unaff_A5;

  if (((-1 < (char)script_ctx_bf_0e_arg) && (script_ctx_bf_0e_arg < 3)) &&
      (DAT_ffffa63c != '\x1a')) {
    related_to_entering_a_room_6 = DAT_ffffa63c;
    related_to_entering_a_room_2 = related_to_entering_a_room_2 | 8;
    ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 0x1a);
  }
  return;
}

void FUN_0002a8ea(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if (-1 < (char)related_to_entering_a_room_5) {
    related_to_entering_a_room_6 = related_to_entering_a_room_5;
    related_to_entering_a_room_5 = 0xff;
  }
  if ((related_to_entering_a_room_2 & 8) == 0) {
    if ((-1 < (char)related_to_entering_a_room_6) &&
        (related_to_entering_a_room_6 != (&comp_anim_c)[unaff_A4])) {
      ecs_anim_unk_2(unaff_A4, unaff_A5, related_to_entering_a_room_6);
      related_to_entering_a_room_6 = 0xff;
    }
  } else if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, related_to_entering_a_room_6);
    related_to_entering_a_room_2 = related_to_entering_a_room_2 & 0xf7;
  }
  return;
}

void ecs_pepelogoo_something_1(entity_id_t self)

{
  if ((related_to_entering_a_room_2 & 1) == 0) {
    component_unknown_3_pepelogoo = 0xe;
    related_to_entering_a_room_2 = related_to_entering_a_room_2 | 1;
    comp_vel[1].x.raw = 0;
    comp_vel[1].y.raw = 0;
    audio_play(SOUND_ID_PEPE_VOICE_1);
    component_state_a_pepelogoo = 0x18;
    ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, (anim_item_t *)self, 6);
  }
  return;
}

void FUN_0002aa82(void)

{
  anim_item_t *unaff_A5;

  component_unknown_3_pepelogoo = 0xe;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 0x16);
  component_state_a_pepelogoo = 0x1e;
  comp_vel[1].x.raw = 0;
  comp_vel[1].y.raw = 0;
  return;
}

void FUN_0002aae6(void)

{
  FUN_000016b2();
  return;
}

void FUN_0002ab26(void)

{
  int unaff_A4;

  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | 0x80;
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    FUN_00029d0c();
  }
  pepelogoo_state_b = pepelogoo_state_b & 0x2f;
  related_to_entering_a_room_2 = related_to_entering_a_room_2 & 0x7a;
  related_to_entering_a_room_3 = 0;
  return;
}

void FUN_0002ab66(void)

{
  anim_item_t *unaff_A5;

  pepelogoo_state_b = pepelogoo_state_b & 0x7f;
  component_unknown_3_pepelogoo = 0xe;
  component_state_a_pepelogoo = 0x20;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 0x24);
  comp_vel[1].x.raw = 0;
  comp_vel[1].y.raw = 0;
  return;
}

void FUN_0002ab90(void)

{
  anim_item_t *unaff_A5;

  component_unknown_3_pepelogoo = 0xe;
  component_state_b_pepelogoo = 0;
  related_to_entering_a_room_2 = related_to_entering_a_room_2 | 0x10;
  component_state_a_pepelogoo = 0x22;
  comp_vel[1].x.raw = 0;
  comp_vel[1].y.raw = 0x200;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 2);
  return;
}

void FUN_0002abee(void)

{
  int unaff_A4;

  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x100;
  return;
}

void FUN_0002abfa(void)

{
  anim_item_t *unaff_A5;

  ecs_holding_a_rope = ecs_holding_a_rope & 0xf7;
  component_unknown_3_pepelogoo = 0xe;
  if (component_state_a_pepelogoo != 0x26) {
    audio_play(SOUND_ID_CRYS_FLASH);
    ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 0x1c);
    component_state_a_pepelogoo = 0x26;
    comp_vel[1].x.raw = 0;
    comp_vel[1].y.raw = 0;
    related_to_entering_a_room_6 = 0xff;
  }
  return;
}

void FUN_0002ad72(void)

{
  uint uVar1;

  DAT_ffffde43 = 0;
  DAT_ffffde42 = 0xff;
  uVar1 = 0;
  do {
    (&DAT_ffffde72)[uVar1] = 0;
    uVar1 = uVar1 + 4;
  } while (uVar1 < 0x10);
  return;
}

void FUN_0002ad92(void)

{
  if ((DAT_ffffde42 != 0) && (-1 < (char)DAT_ffffde42)) {
    (*(code *)((int)&PTR_DAT_0002adac +
               (int)*(short *)((int)&PTR_DAT_0002adac +
                               (int)(short)((ushort)DAT_ffffde42 * 2))))();
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002af62(void)

{
  int iVar1;
  byte extraout_D1b;
  short unaff_D2w;
  short unaff_D7w;
  func *in_A1;
  entity_id_t e;
  anim_item_t *unaff_A5;

  FUN_0000147a(in_A1, 8, 0);
  e = (entity_id_t)unaff_D2w;
  entity_reset(e);
  FUN_00024da0();
  (&comp_func_offset[0].unk1)[e] = extraout_D1b;
  FUN_000019ae();
  iVar1 = _DAT_ffffde4c;
  *(undefined2 *)((int)&comp_pos_x + e) =
      *(undefined2 *)(_DAT_ffffde4c + (short)(unaff_D7w * 6));
  *(undefined2 *)((int)&comp_pos_y + e) =
      *(undefined2 *)(iVar1 + 2 + (int)(short)(unaff_D7w * 6));
  *(undefined2 *)((int)&comp_unk_3 + e) = 0x1a;
  ecs_anim_unk_2(e, unaff_A5, 0);
  *(short *)((int)&comp_pos_y + e) =
      *(short *)((int)&comp_pos_y + e) -
      *(short *)((int)&comp_collision_sensor[0].y + e);
  return;
}

void FUN_0002afb0(void)

{
  if ((DAT_ffffde42 != 0) && (-1 < (char)DAT_ffffde42)) {
    (*(code *)((int)&WORD_0002afca +
               (int)*(short *)((int)&WORD_0002afca +
                               (int)(short)((ushort)DAT_ffffde42 * 2))))();
  }
  return;
}

void FUN_0002afda(void)

{
  // WARNING: Could not recover jumptable at 0x0002afec. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0002aff0 +
             (int)*(short *)((int)&WORD_0002aff0 +
                             (int)(short)((ushort)DAT_ffffde43 * 2))))();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002b000(void)

{
  bool bVar1;

  bVar1 = script_state_get((script_state_bit_t)0x80);
  if (!bVar1) {
    FUN_0001689e();
    script_state_set_true((script_state_bit_t)0x3ff);
    DAT_ffffde43 = 1;
    _DAT_ffffde44 = 0;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002b02a(void)

{
  if (-1 < *(short *)((int)&WORD_0002b196 + (int)(short)(_DAT_ffffde44 << 3))) {
    FUN_0002b1fa();
    DAT_ffffde43 = DAT_ffffde43 + '\x01';
    return;
  }
  FUN_0001689e();
  DAT_ffffde43 = 7;
  return;
}

void FUN_0002b05a(void)

{
  return;
}

void FUN_0002b05c(void)

{
  FUN_0002b286();
  DAT_ffffde43 = DAT_ffffde43 + '\x01';
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002b082(void)

{
  short sVar1;

  sVar1 = _DAT_ffffde44 << 3;
  DAT_ffffc8de = *(undefined2 *)((int)&WORD_0002b196 + (int)sVar1);
  DAT_ffffc8dc = *(undefined2 *)((int)&WORD_0002b198 + (int)sVar1);
  DAT_ffffc8e2 = 2;
  DAT_ffffc8e0 = 2;
  FUN_0000b85e(*(undefined2 **)((int)&WORD_0002b19a + (int)sVar1));
  DAT_ffffde43 = DAT_ffffde43 + '\x01';
  return;
}

void FUN_0002b0be(void)

{
  short *psVar1;
  short sVar2;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t self;

  for (self = 0x84; (-1 < (char)(&comp_has_func_maybe)[self] ||
                     (*(short *)(&comp_unk_1 + self) != 6));
       self = self + ENTITY_ID_PEPELOGOO) {
  }
  psVar1 = (short *)((int)&comp_vel[0].y + self);
  *psVar1 = *psVar1 + 0x40;
  if (0x5ff < *(ushort *)((int)&comp_vel[0].y + self)) {
    *(undefined2 *)((int)&comp_vel[0].y + self) = 0x600;
  }
  entity_update_pos(self);
  ecs_update_collision(self, unaff_D3w, unaff_D6w, unaff_D7w);
  ecs_apply_collision(self);
  (&comp_unk_10)[self] = 0;
  FUN_0000e75a();
  sVar2 = FUN_0002b11a();
  if ((-1 < sVar2) && (((&component_collision_flags)[self] & 4) != 0)) {
    DAT_ffffde43 = DAT_ffffde43 + '\x01';
  }
  return;
}

undefined4 FUN_0002b11a(void)

{
  int unaff_A4;
  undefined1 in_ZF;
  undefined1 in_CF;

  ecs_check_collides_x(unaff_A4, 0);
  if ((bool)in_CF || (bool)in_ZF) {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 2;
    return 0xffffffff;
  }
  return 0;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002b132(void)

{
  short sVar1;
  int iVar2;

  for (iVar2 = 0x84; (-1 < (char)(&comp_has_func_maybe)[iVar2] ||
                      (*(short *)(&comp_unk_1 + iVar2) != 6));
       iVar2 = iVar2 + 4) {
  }
  (&DAT_ffffd19a)[*(short *)((int)&comp_unk_8 + iVar2)] = 0;
  (&comp_has_func_maybe)[iVar2] = 0;
  sVar1 = _DAT_ffffde44 << 3;
  DAT_ffffc8de = *(undefined2 *)((int)&WORD_0002b1c8 + (int)sVar1);
  DAT_ffffc8dc = *(undefined2 *)((int)&WORD_0002b1ca + (int)sVar1);
  DAT_ffffc8e2 = 2;
  DAT_ffffc8e0 = 2;
  FUN_0000b85e(*(undefined2 **)((int)&WORD_0002b1cc + (int)sVar1));
  _DAT_ffffde44 = _DAT_ffffde44 + 1;
  DAT_ffffde43 = 1;
  return;
}

void FUN_0002b1fa(void)

{
  short unaff_D2w;
  undefined2 unaff_D5w;
  entity_id_t e;
  anim_item_t *unaff_A5;

  FUN_0000147a(FUN_0002b256, 1, 0);
  if (-1 < unaff_D2w) {
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    (&comp_func_offset[0].unk1)[e] = 0x2e;
    FUN_000019ae();
    *(undefined2 *)((int)&comp_unk_3 + e) = 4;
    *(short *)((int)&comp_pos_y + e) = DAT_ffffc746 + -8;
    *(undefined2 *)((int)&comp_pos_x + e) = unaff_D5w;
    (&comp_anim_base_offset)[e] = 4;
    (&comp_anim_b)[e] = 0xe;
    ecs_anim_unk_2(e, unaff_A5, 2);
    (&comp_has_func_maybe)[e] = (&comp_has_func_maybe)[e] | 0x20;
    *(undefined2 *)((int)&comp_vel[0].x + e) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + e) = 0;
  }
  return;
}

void FUN_0002b256(void)

{
  short *psVar1;
  ulong unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x20;
  if (0x2ff < *(ushort *)((int)&comp_vel[0].y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x300;
  }
  player_update_pos(unaff_A4);
  if ((ushort)(DAT_ffffc746 + 0xd0U) <
      *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
    DAT_ffffde43 = DAT_ffffde43 + '\x01';
  }
  return;
}

void FUN_0002b286(void)

{
  short unaff_D2w;
  undefined2 unaff_D5w;
  undefined2 unaff_D6w;
  func *in_A1;
  entity_id_t e;
  anim_item_t *unaff_A5;

  FUN_0000147a(in_A1, 6, 0);
  if (-1 < unaff_D2w) {
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x1c;
    (&comp_anim_base_offset)[e] = 6;
    (&comp_anim_b)[e] = 2;
    *(undefined2 *)((int)&comp_pos_x + e) = unaff_D5w;
    *(undefined2 *)((int)&comp_pos_y + e) = unaff_D6w;
    ecs_anim_unk_2(e, unaff_A5, 4);
    *(undefined2 *)((int)&comp_vel[0].x + e) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + e) = 0;
  }
  return;
}

void FUN_0002b2c2(void)

{
  uint uVar1;

  uVar1 = 0;
  do {
    if ((char)(&DAT_ffffde72)[uVar1] < '\0') {
      (*(code *)((int)&WORD_0002b2e8 +
                 (int)*(short *)((int)&WORD_0002b2e8 +
                                 (int)(short)(ushort)(byte)(&DAT_ffffde73)
                                     [uVar1])))();
    }
    uVar1 = uVar1 + 4;
  } while (uVar1 < 0x10);
  return;
}

void FUN_0002b2f0(void)

{
  ushort uVar1;
  short sVar2;
  int unaff_A5;

  sVar2 = FUN_0002b362();
  if ((((-1 < sVar2) && ((pepelogoo_state_b & 0x10) != 0)) &&
       ((ushort)component_pos_y_pepelogoo.fixed.i <
        (ushort)(*(short *)(&DAT_ffffde82 + unaff_A5) -
                 *(short *)(&DAT_ffffde94 + unaff_A5)))) &&
      ((ushort)((*(short *)(&DAT_ffffde82 + unaff_A5) -
                 *(short *)(&DAT_ffffde94 + unaff_A5)) -
                component_pos_y_pepelogoo._0_2_) < 0x51)) {
    uVar1 = *(ushort *)(&DAT_ffffde74 + unaff_A5);
    if (comp_vel[1].x.raw != 0) {
      if (comp_vel[1].x.raw < 0) {
        if ((ushort)component_pos_old_x[1]._0_2_ <= uVar1) {
          return;
        }
        if (uVar1 < (ushort)component_pos_x_pepelogoo.fixed.i) {
          return;
        }
      } else {
        if (uVar1 <= (ushort)component_pos_old_x[1]._0_2_) {
          return;
        }
        if ((ushort)component_pos_x_pepelogoo.fixed.i < uVar1) {
          return;
        }
      }
      (&DAT_ffffde73)[unaff_A5] = 2;
      component_pos_x_pepelogoo.fixed.i = uVar1;
      FUN_0002ab90();
    }
  }
  return;
}

undefined4 FUN_0002b362(void)

{
  ushort uVar1;
  undefined4 uVar2;
  int unaff_A5;

  uVar2 = 0xffffffff;
  uVar1 = *(short *)(&DAT_ffffde94 + unaff_A5) +
          *(short *)(&DAT_ffffde82 + unaff_A5);
  if ((DAT_ffffc746 <= uVar1) &&
      ((ushort)(uVar1 + *(short *)(&DAT_ffffde94 + unaff_A5) * -4) <=
       (ushort)(DAT_ffffc746 + 0x100))) {
    uVar1 = *(short *)(&DAT_ffffde92 + unaff_A5) +
            *(short *)(&DAT_ffffde74 + unaff_A5);
    if ((DAT_ffffc73a <= uVar1) &&
        ((ushort)(uVar1 + *(short *)(&DAT_ffffde92 + unaff_A5) * -4) <=
         (ushort)(DAT_ffffc73a + 0x100))) {
      uVar2 = 0;
    }
  }
  return uVar2;
}

void FUN_0002b3a4(void)

{
  int unaff_A5;

  if (component_pos_x_pepelogoo.fixed.i ==
      *(short *)(&DAT_ffffde74 + unaff_A5)) {
    if ((short)(*(short *)(&DAT_ffffde82 + unaff_A5) -
                *(short *)(&DAT_ffffde94 + unaff_A5)) ==
        (short)(comp_collision_sensor[1].y +
                component_pos_y_pepelogoo.fixed.i)) {
      (&DAT_ffffde73)[unaff_A5] = 4;
      FUN_0002b3e0();
    }
  } else {
    (&DAT_ffffde73)[unaff_A5] = 0;
  }
  return;
}

void FUN_0002b3e0(void)

{
  undefined2 uVar1;
  undefined2 uVar2;
  short unaff_D2w;
  entity_id_t e;
  anim_item_t *unaff_A5;

  FUN_0000147a(FUN_0002b520, 1, 4);
  if (-1 < unaff_D2w) {
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    *(undefined2 *)((int)&comp_pos_x + e) = *(undefined2 *)(unaff_A5 + -0x218c);
    uVar1 = *(undefined2 *)(unaff_A5 + -0x217e);
    uVar2 = *(undefined2 *)(unaff_A5 + -0x216c);
    if ((ushort) * (undefined2 *)(unaff_A5 + -0x216c) < ~ANIM_COMMAND_F6) {
      *(undefined2 *)((int)&comp_state + e) = 2;
    } else {
      *(undefined2 *)((int)&comp_state + e) = 0;
    }
    *(short *)((int)&comp_pos_y + e) = (uVar1 - uVar2) + 8;
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x1a;
    (&comp_anim_base_offset)[e] = 0x14;
    (&comp_anim_b)[e] = 0x1e;
    *(undefined2 *)((int)&comp_vel[0].x + e) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + e) = 0;
    ecs_anim_unk_2(e, unaff_A5, 0);
  }
  return;
}

void FUN_0002b446(void)

{
  int unaff_A5;
  short sVar1;

  DAT_ffffc8de = *(short *)(&DAT_ffffde74 + unaff_A5) -
                 *(short *)(&DAT_ffffde92 + unaff_A5);
  DAT_ffffc8dc = *(short *)(&DAT_ffffde82 + unaff_A5) -
                 *(short *)(&DAT_ffffde94 + unaff_A5);
  DAT_ffffc8e0 = 1;
  DAT_ffffc8e2 = 2;
  sVar1 = (short)unaff_A5;
  FUN_0000b85e(WORD_ARRAY_0002b4a8);
  (&DAT_ffffde73)[sVar1] = 2;
  *(short *)(&DAT_ffffde94 + sVar1) = *(short *)(&DAT_ffffde94 + sVar1) + -8;
  *(short *)(&DAT_ffffde82 + sVar1) = *(short *)(&DAT_ffffde82 + sVar1) + 8;
  if ((*(short *)(&DAT_ffffde94 + sVar1) == 0) ||
      (*(short *)(&DAT_ffffde94 + sVar1) < 0)) {
    (&DAT_ffffde72)[sVar1] = 0;
    script_state_set_true(*(script_state_bit_t *)(&DAT_ffffdea2 + sVar1));
  }
  return;
}

void FUN_0002b4b0(void)

{
  int unaff_A5;

  do {
    DAT_ffffc8de = *(short *)(&DAT_ffffde74 + unaff_A5) -
                   *(short *)(&DAT_ffffde92 + unaff_A5);
    DAT_ffffc8dc = *(short *)(&DAT_ffffde82 + unaff_A5) -
                   *(short *)(&DAT_ffffde94 + unaff_A5);
    DAT_ffffc8e0 = 1;
    DAT_ffffc8e2 = 2;
    FUN_0000b85e(WORD_ARRAY_0002b518);
    unaff_A5 = (int)(short)unaff_A5;
    *(short *)(&DAT_ffffde94 + unaff_A5) =
        *(short *)(&DAT_ffffde94 + unaff_A5) + -8;
    *(short *)(&DAT_ffffde82 + unaff_A5) =
        *(short *)(&DAT_ffffde82 + unaff_A5) + 8;
    if (*(short *)(&DAT_ffffde94 + unaff_A5) == 0)
      break;
  } while (-1 < *(short *)(&DAT_ffffde94 + unaff_A5));
  (&DAT_ffffde72)[unaff_A5] = 0;
  script_state_set_true(*(script_state_bit_t *)(&DAT_ffffdea2 + unaff_A5));
  drop_pepelogoo();
  return;
}

void FUN_0002b520(void)

{
  short *psVar1;
  entity_state_1_a_t eVar2;
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;

  *(undefined4 *)((int)component_pos_old_x + unaff_A4) =
      *(undefined4 *)((int)&comp_pos_x + unaff_A4);
  *(undefined4 *)((int)component_pos_old_y + unaff_A4) =
      *(undefined4 *)((int)&comp_pos_y + unaff_A4);
  player_update_pos(unaff_A4);
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    FUN_0000e898(unaff_A4, unaff_A5);
    (&comp_has_func_maybe)[unaff_A4] = 0;
    if ((*(short *)((int)&comp_state + unaff_A4) == 2) &&
        (component_state_a_pepelogoo == 0x24)) {
      drop_pepelogoo();
    }
  } else {
    eVar2 = (&comp_state_1_a)[unaff_A4];
    (&comp_state_1_a)[unaff_A4] = eVar2 & 0xdf;
    if ((eVar2 & 0x20) != 0) {
      psVar1 = (short *)((int)&comp_collision_sensor[0].y + unaff_A4);
      *psVar1 = *psVar1 + -1;
    }
    eVar2 = (&comp_state_1_a)[unaff_A4];
    (&comp_state_1_a)[unaff_A4] = eVar2 & 0xef;
    if ((eVar2 & 0x10) != 0) {
      *(short *)((int)&comp_pos_y + unaff_A4) =
          *(short *)((int)&comp_pos_y + unaff_A4) + 1;
    }
    FUN_0000e75a();
    if (-1 < *(short *)((int)&comp_unk_8 + unaff_A4)) {
      *(undefined2 *)(&DAT_ffffd21c + *(short *)((int)&comp_unk_8 + unaff_A4)) =
          1;
    }
  }
  return;
}

void FUN_0002b58c(void)

{
  uint uVar1;

  uVar1 = 0;
  do {
    if (-1 < (char)(&DAT_ffffde72)[uVar1])
      break;
    uVar1 = uVar1 + 4;
  } while (uVar1 < 0x10);
  (&DAT_ffffde72)[uVar1] = 0x80;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002b5a6(void)

{
  short sVar1;
  ushort uVar2;
  undefined2 *extraout_A0;
  bool bVar3;

  bVar3 = script_state_get(*(script_state_bit_t *)(_DAT_ffffde4c + 0x22));
  if (bVar3) {
    uVar2 = 0;
    do {
      if ((char)(&DAT_ffffde46)[(short)uVar2] < '\0') {
        sVar1 = FUN_0002b5ea();
        if (sVar1 != 0) {
          DAT_ffffcf7e = 0x25;
          _DAT_ffffcf80 = *extraout_A0;
          _DAT_ffffcf82 = extraout_A0[1];
          DAT_ffffde4b = (char)uVar2;
          return;
        }
      }
      uVar2 = uVar2 + 1;
    } while (uVar2 < 5);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_0002b5ea(void)

{
  short sVar1;
  short unaff_D7w;
  short *psVar2;
  bool bVar3;

  bVar3 = ecs_get_cannot_jump(ENTITY_ID_ASHA);
  if (!bVar3) {
    psVar2 = (short *)((short)(unaff_D7w * 6) + _DAT_ffffde4c);
    sVar1 = *psVar2;
    if ((((ushort)(sVar1 - 0x10U) <= (ushort)comp_pos_x.fixed.i) &&
         ((ushort)comp_pos_x.fixed.i <= (ushort)(sVar1 + 0x10U))) &&
        (psVar2[1] == comp_pos_y.fixed.i)) {
      return 0xffffffff;
    }
  }
  return 0;
}

// WARNING: Type propagation algorithm not settling
// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002b62c(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  uint uVar1;
  ushort uVar2;
  short sVar3;
  undefined1 *puVar4;
  script_ctx_t *psVar5;
  void *unaff_A6;
  undefined8 uVar6;
  script_ctx_t *ctx;

  audio_play(SOUND_ID_WARP);
  FUN_0002b7b0();
  while (true) {
    uVar1 = 4;
    psVar5 = (script_ctx_t *)&DAT_ffffde52;
    do {
      ctx = (script_ctx_t *)&psVar5->bf_03_and_bf_06_arg_fed_to_vdp_data;
      sVar3._0_1_ = psVar5->flags;
      sVar3._1_1_ = psVar5->mode;
      uVar6 = FUN_0002b8bc();
      uVar2 = (short)uVar1 - 1;
      uVar1 = (uint)uVar2;
      psVar5 = ctx;
    } while (uVar2 != 0xffff);
    DAT_ffffde6a = DAT_ffffde6a + -1;
    DAT_ffffde6c = DAT_ffffde6c + 2 & 0xff;
    if (DAT_ffffde6a == 1)
      break;
    exception_unk_0(ctx,
                    (int)sVar3,
                    unaff_A6,
                    (long)((ulonglong)uVar6 >> 0x20),
                    (long)uVar6,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    uVar1);
  }
  FUN_00001896();
  uVar2 = 0;
  do {
    (&comp_has_func_maybe)[*(short *)((int)&DAT_ffffde52 + (int)(short)uVar2)] =
        0;
    uVar2 = uVar2 + 2;
  } while (uVar2 < 10);
  FUN_0002b6aa();
  script_state_set_true(*(script_state_bit_t *)(_DAT_ffffde4c + 0x22));
  sVar3 = 4;
  puVar4 = &DAT_ffffde46;
  do {
    *puVar4 = 0xff;
    sVar3 = sVar3 + -1;
    puVar4 = puVar4 + 1;
  } while (sVar3 != -1);
  return;
}

void FUN_0002b6aa(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  word *pwVar1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar2;
  word wStack_6;
  word *pwStack_4;

  pwStack_4 = WORD_ARRAY_0002b6e2;
  while (true) {
    if (*pwStack_4 == 0xffff)
      break;
    unaff_D3 = CONCAT22((short)((uint)unaff_D3 >> 0x10),
                        *pwStack_4 + related_to_pos_x_int);
    pwVar1 = pwStack_4 + 2;
    unaff_D4 = CONCAT22((short)((uint)unaff_D4 >> 0x10),
                        pwStack_4[1] + related_to_pos_y_int);
    pwStack_4 = pwStack_4 + 3;
    wStack_6 = *pwVar1;
    unaff_D7 = CONCAT22((short)((uint)unaff_D7 >> 0x10), wStack_6);
    uVar2 = FUN_00001896();
    while (true) {
      wStack_6 = wStack_6 - 1;
      unaff_D7 = CONCAT22((short)((uint)unaff_D7 >> 0x10), wStack_6);
      if ((short)wStack_6 < 0)
        break;
      uVar2 = exception_unk_0(unaff_A3,
                              unaff_A4,
                              unaff_A6,
                              (long)((ulonglong)uVar2 >> 0x20),
                              (long)uVar2,
                              unaff_D2,
                              unaff_D3,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
    }
  }
  return;
}

// WARNING: Type propagation algorithm not settling
// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002b708(void)

{
  short sVar1;
  ushort extraout_D1w;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  undefined4 unaff_D6;
  script_state_bit_t index;
  uint uVar2;
  ushort uVar3;
  short sVar4;
  undefined1 *puVar5;
  script_ctx_t *psVar6;
  short *psVar7;
  void *unaff_A6;
  undefined8 uVar8;
  script_ctx_t *ctx;

  audio_play(SOUND_ID_WARP);
  FUN_0002b7b0();
  sVar4 = 0x70;
  while (true) {
    uVar2 = 4;
    psVar6 = (script_ctx_t *)&DAT_ffffde52;
    do {
      ctx = (script_ctx_t *)&psVar6->bf_03_and_bf_06_arg_fed_to_vdp_data;
      sVar1._0_1_ = psVar6->flags;
      sVar1._1_1_ = psVar6->mode;
      uVar8 = FUN_0002b8bc();
      uVar3 = (short)uVar2 - 1;
      uVar2 = (uint)uVar3;
      psVar6 = ctx;
    } while (uVar3 != 0xffff);
    DAT_ffffde6a = DAT_ffffde6a + 2;
    DAT_ffffde6c = DAT_ffffde6c + 2 & 0xff;
    sVar4 = sVar4 + -1;
    if (sVar4 == 0)
      break;
    exception_unk_0(ctx,
                    (int)sVar1,
                    unaff_A6,
                    (long)((ulonglong)uVar8 >> 0x20),
                    (long)uVar8,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    CONCAT22((short)((uint)unaff_D6 >> 0x10), sVar4),
                    uVar2);
  }
  sVar4 = 4;
  puVar5 = &DAT_ffffde46;
  do {
    *puVar5 = 0xff;
    sVar4 = sVar4 + -1;
    puVar5 = puVar5 + 1;
  } while (sVar4 != -1);
  sVar4 = 4;
  psVar7 = &DAT_ffffde52;
  do {
    (&comp_has_func_maybe)[*psVar7] = 0;
    sVar4 = sVar4 + -1;
    psVar7 = psVar7 + 1;
  } while (sVar4 != -1);
  index = *(script_state_bit_t *)(_DAT_ffffde4c + 0x22);
  uVar3 = 0x25;
  while (true) {
    index = (script_state_bit_t)((short)index + 1);
    FUN_0002980e();
    if (9 < extraout_D1w) {
      while (true) {
        script_state_set_false(index);
        index = (script_state_bit_t)((short)index + 1);
        if (0x28 < uVar3)
          break;
        uVar3 = uVar3 + 1;
      }
      return;
    }
    FUN_00029824();
    if (0x28 < uVar3)
      break;
    uVar3 = uVar3 + 1;
  }
  return;
}

void FUN_0002b7b0(void)

{
  FUN_0002b7be();
  FUN_0002b848();
  FUN_0002b8f6();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002b7be(void)

{
  short sVar1;
  short sVar2;
  undefined2 uVar3;
  undefined2 *puVar4;
  undefined2 *puVar5;
  short *psVar6;
  byte *pbVar7;
  int iVar8;
  int iVar9;

  iVar9 = 0x84;
  sVar1 = 0x11;
  puVar4 = &DAT_ffffde52;
  do {
    puVar5 = puVar4;
    if (((char)(&comp_has_func_maybe)[iVar9] < '\0') &&
        (*(short *)(&comp_unk_1 + iVar9) == 8)) {
      puVar5 = puVar4 + 1;
      *puVar4 = (short)iVar9;
      *(undefined2 *)((int)&comp_unk_3 + iVar9) = 4;
      (&comp_state_a)[iVar9] = (&comp_state_a)[iVar9] | 0x80;
    }
    iVar9 = iVar9 + 4;
    sVar1 = sVar1 + -1;
    puVar4 = puVar5;
  } while (sVar1 != -1);
  DAT_ffffde6a = 0x40;
  DAT_ffffde6c = 0;
  iVar9 = (int)_DAT_ffffda72;
  related_to_pos_x_int = *(undefined2 *)((int)&comp_pos_x + iVar9);
  related_to_pos_y_int = *(undefined2 *)((int)&comp_pos_y + iVar9);
  sVar1 = 4;
  psVar6 = &DAT_ffffde52;
  pbVar7 = BYTE_ARRAY_0002b842;
  do {
    iVar8 = (int)*psVar6;
    uVar3 = 0;
    sVar2 = *(short *)((int)&comp_pos_x + iVar8) -
            *(short *)((int)&comp_pos_x + iVar9);
    if (sVar2 < 0) {
      uVar3 = 0x8000;
      sVar2 = -sVar2;
    }
    *(short *)(&DAT_ffffbe76 + iVar8) = sVar2 + -0x40;
    *(undefined2 *)(&DAT_ffffbe78 + iVar8) = uVar3;
    *(ushort *)(&DAT_ffffbd76 + iVar8) = (ushort)*pbVar7 << 8;
    sVar1 = sVar1 + -1;
    psVar6 = psVar6 + 1;
    pbVar7 = pbVar7 + 1;
  } while (sVar1 != -1);
  return;
}

// WARNING: Type propagation algorithm not settling

void FUN_0002b848(void)

{
  short sVar1;
  long extraout_D1;
  int iVar2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  uint uVar3;
  uint uVar4;
  ushort uVar5;
  script_ctx_t *psVar6;
  entity_id_t self;
  void *unaff_A6;
  script_ctx_t *ctx;

  while (true) {
    uVar4 = 4;
    uVar3 = 0;
    psVar6 = (script_ctx_t *)&DAT_ffffde52;
    do {
      ctx = (script_ctx_t *)&psVar6->bf_03_and_bf_06_arg_fed_to_vdp_data;
      sVar1._0_1_ = psVar6->flags;
      sVar1._1_1_ = psVar6->mode;
      self = (entity_id_t)sVar1;
      FUN_0002b8bc();
      if ((*(short *)(&DAT_ffffbe76 + self) == 0) &&
          (*(short *)(&DAT_ffffbd76 + self) ==
           *(short *)(&DAT_ffffbe78 + self))) {
        uVar3 = (uint)(ushort)((short)uVar3 + 1);
      }
      if (*(short *)(&DAT_ffffbe76 + self) != 0) {
        if (*(short *)(&DAT_ffffbe76 + self) < 0) {
          *(short *)(&DAT_ffffbe76 + self) =
              *(short *)(&DAT_ffffbe76 + self) + 1;
        } else {
          *(short *)(&DAT_ffffbe76 + self) =
              *(short *)(&DAT_ffffbe76 + self) + -1;
        }
      }
      sVar1 = *(short *)(&DAT_ffffbe78 + self);
      iVar2 = (uint) * (ushort *)(&DAT_ffffbd78 + self) -
              (uint)(ushort)(*(short *)(&DAT_ffffbd76 + self) - sVar1);
      if (iVar2 < 0) {
        iVar2 = CONCAT22((short)((uint)iVar2 >> 0x10),
                         *(short *)(&DAT_ffffbd78 + self));
        *(short *)(&DAT_ffffbe78 + self) =
            *(short *)(&DAT_ffffbd78 + self) + *(short *)(&DAT_ffffbe78 + self);
      } else {
        *(undefined2 *)(&DAT_ffffbe78 + self) =
            *(undefined2 *)(&DAT_ffffbd76 + self);
      }
      uVar5 = (short)uVar4 - 1;
      uVar4 = (uint)uVar5;
      psVar6 = ctx;
    } while (uVar5 != 0xffff);
    if ((short)uVar3 == 5)
      break;
    DAT_ffffde6c = DAT_ffffde6c + 2 & 0xff;
    exception_unk_0(ctx,
                    self,
                    unaff_A6,
                    (uint)(ushort)(*(short *)(&DAT_ffffbd76 + self) - sVar1),
                    extraout_D1,
                    iVar2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    uVar3,
                    uVar4);
  }
  return;
}

void FUN_0002b8bc(void)

{
  short sVar1;
  short sVar2;
  short extraout_D1w;
  int unaff_A4;

  sVar2 = FUN_000012a8();
  sVar1 = related_to_pos_y_int + extraout_D1w;
  *(short *)((int)&comp_pos_x + unaff_A4) = related_to_pos_x_int + sVar2;
  *(short *)((int)&comp_pos_y + unaff_A4) = sVar1;
  *(short *)(&DAT_ffffbd78 + unaff_A4) =
      0x200 - *(short *)(&DAT_ffffbe76 + unaff_A4);
  return;
}

// WARNING: Type propagation algorithm not settling

void FUN_0002b8f6(void)

{
  short sVar1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  uint uVar2;
  ushort uVar3;
  undefined4 unaff_D7;
  short sVar4;
  script_ctx_t *psVar5;
  void *unaff_A6;
  undefined8 uVar6;
  script_ctx_t *ctx;

  sVar4 = 0x3c;
  while (true) {
    uVar2 = 4;
    psVar5 = (script_ctx_t *)&DAT_ffffde52;
    do {
      ctx = (script_ctx_t *)&psVar5->bf_03_and_bf_06_arg_fed_to_vdp_data;
      sVar1._0_1_ = psVar5->flags;
      sVar1._1_1_ = psVar5->mode;
      uVar6 = FUN_0002b8bc();
      uVar3 = (short)uVar2 - 1;
      uVar2 = (uint)uVar3;
      psVar5 = ctx;
    } while (uVar3 != 0xffff);
    DAT_ffffde6c = DAT_ffffde6c + 2 & 0xff;
    sVar4 = sVar4 + -1;
    if (sVar4 == 0)
      break;
    exception_unk_0(ctx,
                    (int)sVar1,
                    unaff_A6,
                    (long)((ulonglong)uVar6 >> 0x20),
                    (long)uVar6,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    uVar2,
                    CONCAT22((short)((uint)unaff_D7 >> 0x10), sVar4));
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002b922(void)

{
  bool bVar1;

  _DAT_ffffd17a = 0;
  bVar1 = script_state_get((script_state_bit_t)0x3ec);
  if (bVar1) {
    _DAT_ffffd17c = 8;
  } else {
    _DAT_ffffd17c = 0x560;
  }
  return;
}

void FUN_0002b944(void)

{
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002b946(void)

{
  anim_item_t *unaff_A5;

  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  comp_pos_x.fixed.i = _DAT_ffffde74;
  comp_pos_y.fixed.i = _DAT_ffffde82;
  comp_vel[0].y.raw = 0;
  if (_DAT_ffffde74 < _DAT_ffffde92) {
    comp_vel[0].x.raw = 0x200;
    comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
  } else {
    comp_vel[0].x.raw = -0x200;
    comp_state_a = comp_state_a | ENTITY_STATE_A_08;
  }
  if ((-1 < (char)script_ctx_bf_0e_arg) && (script_ctx_bf_0e_arg < 3)) {
    drop_pepelogoo();
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002b9a8(void)

{
  anim_item_t *unaff_A5;

  if (comp_anim_c != ECS_STATE_1_B_WALKING_OR_DOWNSTAB) {
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 2);
  }
  entity_update_pos(ENTITY_ID_ASHA);
  if (comp_vel[0].x.raw < 0) {
    if (_DAT_ffffde92 < (ushort)comp_pos_x.fixed.i) {
      return;
    }
  } else if ((ushort)comp_pos_x.fixed.i < _DAT_ffffde92) {
    return;
  }
  comp_vel[0].x.raw = 0;
  comp_pos_x.fixed.i = _DAT_ffffde92;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x3e);
  script_state_set_true(_DAT_ffffdea2);
  DAT_ffffde42 = 0;
  return;
}

void FUN_0002b9f6(void)

{
  DAT_ffffdeb2 = 0;
  pepelogoo_state_b = '\0';
  return;
}

void FUN_0002ba00(entity_id_t e, ushort param_2, short param_3, word param_4,
                  word param_5)

{
  byte bVar1;

  pepelogoo_state_b = pepelogoo_state_b & 0xdf;
  ecs_update_pos(e);
  if ((-1 < (char)script_ctx_bf_0e_arg) && (script_ctx_bf_0e_arg < 3)) {
    bVar1 = DAT_ffffdeb2 & 1;
    DAT_ffffdeb2 = bVar1 * '\x02';
    if (bVar1 != 0) {
      ecs_move_with_entity_pepelogoo(e);
    }
    if ((pepelogoo_state_b & 0x80) != 0) {
      FUN_0002bb4e();
      return;
    }
    if ((related_to_entering_a_room_2 & 0x10) != 0) {
      FUN_0002bab0(param_2, param_3, param_4, param_5);
      return;
    }
  }
  ecs_update_vel_old(e);
  interact_with_all_other_entities(e, param_2, (char)param_3);
  ecs_update_collision(e, param_3, param_4, param_5);
  ecs_apply_collision(e);
  return;
}

void ecs_update_pos(ulong ctx)

{
  *(undefined4 *)((int)component_pos_old_x + ctx) =
      *(undefined4 *)((int)&comp_pos_x + ctx);
  *(undefined4 *)((int)component_pos_old_y + ctx) =
      *(undefined4 *)((int)&comp_pos_y + ctx);
  player_update_pos(ctx);
  return;
}

void ecs_move_with_entity_pepelogoo(entity_id_t e)

{
  short vel_y_int_pepelogoo;

  vel_y_int_pepelogoo =
      component_pos_y_pepelogoo.fixed.i - component_pos_old_y[1]._0_2_;
  *(short *)((int)&comp_pos_x + e) =
      (component_pos_x_pepelogoo.fixed.i - component_pos_old_x[1]._0_2_) +
      *(short *)((int)&comp_pos_x + e);
  *(short *)((int)&comp_pos_y + e) =
      vel_y_int_pepelogoo + *(short *)((int)&comp_pos_y + e);
  return;
}

void ecs_update_vel_old(entity_id_t e)

{
  *(short *)((int)&component_vel_old[0].x + e) =
      *(short *)((int)&comp_pos_x + e) -
      *(short *)((int)component_pos_old_x + e);
  *(short *)((int)&component_vel_old[0].y + e) =
      *(short *)((int)&comp_pos_y + e) -
      *(short *)((int)component_pos_old_y + e);
  return;
}

void FUN_0002bab0(ushort param_1, short param_2, word param_3, word param_4)

{
  undefined1 uVar1;
  undefined1 uVar2;

  FUN_0002bbee();
  uVar2 = 0;
  uVar1 = (char)param_1 == '\0';
  if (!(bool)uVar1) {
    ecs_update_vel_old(ENTITY_ID_PEPELOGOO);
    ecs_update_vel_old(ENTITY_ID_ASHA);
    ecs_check_collides_x(0, 4);
    if (((((bool)uVar2 || (bool)uVar1) &&
          (-1 < (short)(component_vel_old[0].y - component_vel_old[1].y))) &&
         (param_1 =
              (comp_collision_sensor[0].y + comp_pos_y.fixed.i) -
              (component_pos_y_pepelogoo.fixed.i - comp_collision_sensor[1].y),
          -1 < (short)param_1)) &&
        (param_1 <=
         (ushort)(component_vel_old[0].y - component_vel_old[1].y))) {
      comp_pos_y.fixed.i = comp_pos_y.fixed.i - param_1;
      ecs_update_vel_old(ENTITY_ID_ASHA);
      interact_with_all_other_entities(ENTITY_ID_ASHA, param_1, (char)param_2);
      ecs_update_collision(0, param_2, param_3, param_4);
      ecs_apply_collision(0);
      pepelogoo_state_b = pepelogoo_state_b | 0x20;
      comp_vel[0].y.raw = 0;
      comp_pos_y.fixed.f = 0;
      component_collision_flags = component_collision_flags | 4;
      comp_collision[0].collision.y = '\0';
      DAT_ffffdeb2 = DAT_ffffdeb2 | 1;
      return;
    }
  }
  ecs_update_vel_old(ENTITY_ID_ASHA);
  interact_with_all_other_entities(ENTITY_ID_ASHA, param_1, (char)param_2);
  ecs_update_collision(0, param_2, param_3, param_4);
  ecs_apply_collision(0);
  return;
}

void FUN_0002bb4e(void)

{
  short unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;

  // This code runs when Asha and Pepelogoo are connected
  if ((comp_state_a & ENTITY_STATE_A_08) == 0) {
    DAT_ffff9f1f = DAT_ffff9f1f & 0xf7;
  } else {
    DAT_ffff9f1f = DAT_ffff9f1f | 8;
  }
  ecs_update_vel_old(unaff_A4);
  related_to_moving_two_objects_together_maybe(ENTITY_ID_PEPELOGOO);
  interact_with_all_other_entities(unaff_A4, unaff_D2w, (char)unaff_D3w);
  ecs_update_collision(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  ecs_apply_collision(unaff_A4);
  component_pos_old_x[1] = component_pos_x_pepelogoo;
  component_pos_old_y[1] = component_pos_y_pepelogoo;
  component_pos_x_pepelogoo.fixed.i =
      *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  component_pos_y_pepelogoo.fixed.i =
      (*(short *)((int)&comp_pos_y + unaff_A4) -
       *(short *)((int)&comp_collision_sensor[0].y + unaff_A4)) -
      comp_collision_sensor[1].y;
  FUN_0002c0bc();
  ecs_update_vel_old(ENTITY_ID_PEPELOGOO);
  interact_with_all_other_entities(
      ENTITY_ID_PEPELOGOO, unaff_D2w, (char)unaff_D3w);
  ecs_update_collision(4, unaff_D3w, unaff_D6w, unaff_D7w);
  ecs_apply_collision(4);
  if ((DAT_ffffb571 & 4) != 0) {
    comp_pos_y.fixed.f = 0;
  }
  ecs_update_vel_old(ENTITY_ID_PEPELOGOO);
  ecs_update_vel_old(ENTITY_ID_ASHA);
  FUN_0002bd32();
  return;
}

void FUN_0002bbee(void)

{
  char unaff_D2b;

  FUN_0002bc16();
  if (unaff_D2b != '\0') {
    return;
  }
  FUN_0002bc48();
  FUN_0002bc7c();
  FUN_0002bcae();
  return;
}

void FUN_0002bc16(void)

{
  ushort uVar1;
  ushort uVar2;
  char unaff_D2b;
  ushort uVar3;
  int unaff_A4;

  uVar3 = *(short *)((int)&comp_pos_y + unaff_A4) -
          *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  while (true) {
    uVar2 = FUN_0002bce2();
    if ((unaff_D2b != '\0') || (uVar1 = 0x10 - (uVar3 & 0xf), uVar2 < uVar1))
      break;
    uVar3 = uVar1 + uVar3;
  }
  return;
}

void FUN_0002bc48(void)

{
  ushort uVar1;
  ushort uVar2;
  char unaff_D2b;
  ushort uVar3;
  int unaff_A4;

  uVar3 = *(short *)((int)&comp_pos_y + unaff_A4) -
          *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  while (true) {
    uVar2 = FUN_0002bce2();
    if ((unaff_D2b != '\0') || (uVar1 = 0x10 - (uVar3 & 0xf), uVar2 < uVar1))
      break;
    uVar3 = uVar1 + uVar3;
  }
  return;
}

void FUN_0002bc7c(void)

{
  ushort uVar1;
  ushort uVar2;
  char unaff_D2b;
  ushort uVar3;
  int unaff_A4;

  uVar3 = *(short *)((int)&comp_pos_x + unaff_A4) -
          *(short *)((int)&comp_collision_sensor[0].x + unaff_A4);
  while (true) {
    uVar2 = FUN_0002bce2();
    if ((unaff_D2b != '\0') || (uVar1 = 0x10 - (uVar3 & 0xf), uVar2 < uVar1))
      break;
    uVar3 = uVar1 + uVar3;
  }
  return;
}

void FUN_0002bcae(void)

{
  ushort uVar1;
  ushort uVar2;
  char unaff_D2b;
  ushort uVar3;
  int unaff_A4;

  uVar3 = *(short *)((int)&comp_pos_x + unaff_A4) -
          *(short *)((int)&comp_collision_sensor[0].x + unaff_A4);
  while (true) {
    uVar2 = FUN_0002bd0a();
    if ((unaff_D2b != '\0') || (uVar1 = 0x10 - (uVar3 & 0xf), uVar2 < uVar1))
      break;
    uVar3 = uVar1 + uVar3;
  }
  return;
}

void FUN_0002bce2(void)

{
  word unaff_D6w;
  word unaff_D7w;

  FUN_00017330(unaff_D6w, unaff_D7w);
  return;
}

void FUN_0002bd0a(void)

{
  word unaff_D6w;
  word unaff_D7w;

  FUN_00017330(unaff_D6w, unaff_D7w);
  return;
}

void FUN_0002bd32(void)

{
  short sVar1;

  FUN_0002bf6c();
  sVar1 = FUN_0002bf7e();
  (*(code *)((int)&WORD_0002bd5e +
             (int)*(short *)((int)&WORD_0002bd5e + (int)(short)(sVar1 * 2))))();
  FUN_0002bf90();
  sVar1 = FUN_0002bfa2();
  // WARNING: Could not recover jumptable at 0x0002bd5c. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0002bd7e +
             (int)*(short *)((int)&WORD_0002bd7e + (int)(short)(sVar1 * 2))))();
  return;
}

void FUN_0002bd9e(void)

{
  short in_D1w;

  // WARNING: Could not recover jumptable at 0x0002bdaa. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0002bdac +
             (int)*(short *)((int)&WORD_0002bdac +
                             (int)(short)(in_D1w * 2))))();
  return;
}

void FUN_0002bdcc(void)

{
  short in_D1w;

  // WARNING: Could not recover jumptable at 0x0002bdd8. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0002bdda +
             (int)*(short *)((int)&WORD_0002bdda +
                             (int)(short)(in_D1w * 2))))();
  return;
}

void FUN_0002bdfa(void)

{
  short in_D1w;

  // WARNING: Could not recover jumptable at 0x0002be06. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0002be08 +
             (int)*(short *)((int)&WORD_0002be08 +
                             (int)(short)(in_D1w * 2))))();
  return;
}

void FUN_0002be28(void)

{
  short in_D1w;

  // WARNING: Could not recover jumptable at 0x0002be34. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0002be36 +
             (int)*(short *)((int)&WORD_0002be36 +
                             (int)(short)(in_D1w * 2))))();
  return;
}

void FUN_0002be56(void)

{
  short in_D1w;

  // WARNING: Could not recover jumptable at 0x0002be62. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0002be64 +
             (int)*(short *)((int)&WORD_0002be64 +
                             (int)(short)(in_D1w * 2))))();
  return;
}

void FUN_0002be84(void)

{
  short in_D1w;

  // WARNING: Could not recover jumptable at 0x0002be90. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0002be92 +
             (int)*(short *)((int)&WORD_0002be92 +
                             (int)(short)(in_D1w * 2))))();
  return;
}

void FUN_0002beb2(void)

{
  short in_D1w;

  // WARNING: Could not recover jumptable at 0x0002bebe. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0002bec0 +
             (int)*(short *)((int)&WORD_0002bec0 +
                             (int)(short)(in_D1w * 2))))();
  return;
}

void FUN_0002bee0(void)

{
  short in_D1w;

  // WARNING: Could not recover jumptable at 0x0002beec. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0002beee +
             (int)*(short *)((int)&WORD_0002beee +
                             (int)(short)(in_D1w * 2))))();
  return;
}

void FUN_0002bf0e(void)

{
  short in_D1w;

  // WARNING: Could not recover jumptable at 0x0002bf1a. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0002bf1c +
             (int)*(short *)((int)&WORD_0002bf1c +
                             (int)(short)(in_D1w * 2))))();
  return;
}

void FUN_0002bf3c(void)

{
  short in_D1w;

  // WARNING: Could not recover jumptable at 0x0002bf48. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0002bf4a +
             (int)*(short *)((int)&WORD_0002bf4a +
                             (int)(short)(in_D1w * 2))))();
  return;
}

void FUN_0002bf6a(void)

{
  return;
}

byte FUN_0002bf6c(void)

{
  int unaff_A3;

  return (&component_unknown_5)[unaff_A3] & 3 |
         ((&component_collision_flags)[unaff_A3] & 3) << 2;
}

void FUN_0002bf7e(void)

{
  return;
}

byte FUN_0002bf90(void)

{
  int unaff_A3;

  return ((&component_unknown_5)[unaff_A3] & 0xc) >> 2 |
         (&component_collision_flags)[unaff_A3] & 0xc;
}

void FUN_0002bfa2(void)

{
  return;
}

void FUN_0002bfb4(void)

{
  int unaff_A3;
  int unaff_A4;

  *(undefined4 *)((int)&comp_pos_x + unaff_A3) =
      *(undefined4 *)((int)&comp_pos_x + unaff_A4);
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A3) = 0;
  (&component_collision_flags)[unaff_A3] =
      (&component_collision_flags)[unaff_A3] & 0xc;
  return;
}

void FUN_0002bfc8(void)

{
  uint uVar1;
  uint uVar2;
  short *psVar3;
  int unaff_A3;
  int unaff_A4;

  uVar1 = *(uint *)((int)&comp_pos_x + unaff_A3);
  uVar2 = *(uint *)((int)&comp_pos_x + unaff_A4);
  *(uint *)((int)&comp_pos_x + unaff_A4) = uVar1;
  (&component_collision_flags)[unaff_A4] =
      (&component_collision_flags)[unaff_A4] & 0xc;
  if (-1 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
    if (uVar2 == uVar1) {
      return;
    }
    if (uVar2 < uVar1) {
      psVar3 = (short *)((int)&comp_vel[0].x + unaff_A4);
      if (*psVar3 == 0) {
        return;
      }
      if (-1 < *psVar3) {
        return;
      }
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      return;
    }
  }
  if (-1 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  }
  return;
}

void FUN_0002c000(void)

{
  uint uVar1;
  uint uVar2;
  short *psVar3;
  ushort uVar4;
  ushort uVar5;
  int unaff_A3;
  int unaff_A4;

  uVar4 = *(ushort *)((int)&component_vel_old[0].x + unaff_A4);
  if ((short)uVar4 < 0) {
    uVar4 = -uVar4;
  }
  uVar5 = *(ushort *)((int)&component_vel_old[0].x + unaff_A3);
  if ((short)uVar5 < 0) {
    uVar5 = -uVar5;
  }
  if (uVar5 == uVar4) {
    return;
  }
  if (uVar4 <= uVar5) {
    *(undefined4 *)((int)&comp_pos_x + unaff_A3) =
        *(undefined4 *)((int)&comp_pos_x + unaff_A4);
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A3) = 0;
    (&component_collision_flags)[unaff_A3] =
        (&component_collision_flags)[unaff_A3] & 0xc;
    return;
  }
  uVar1 = *(uint *)((int)&comp_pos_x + unaff_A3);
  uVar2 = *(uint *)((int)&comp_pos_x + unaff_A4);
  *(uint *)((int)&comp_pos_x + unaff_A4) = uVar1;
  (&component_collision_flags)[unaff_A4] =
      (&component_collision_flags)[unaff_A4] & 0xc;
  if (-1 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
    if (uVar2 == uVar1) {
      return;
    }
    if (uVar2 < uVar1) {
      psVar3 = (short *)((int)&comp_vel[0].x + unaff_A4);
      if (*psVar3 == 0) {
        return;
      }
      if (-1 < *psVar3) {
        return;
      }
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      return;
    }
  }
  if (-1 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  }
  return;
}

void FUN_0002c01e(void)

{
  int unaff_A3;
  int unaff_A4;

  *(short *)((int)&comp_pos_y + unaff_A3) =
      (*(short *)((int)&comp_pos_y + unaff_A4) -
       *(short *)((int)&comp_collision_sensor[0].y + unaff_A4)) -
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A3);
  *(undefined2 *)((int)&comp_pos_y + unaff_A3 + 2) = 0;
  (&component_collision_flags)[unaff_A3] =
      (&component_collision_flags)[unaff_A3] & 3;
  return;
}

void FUN_0002c03a(void)

{
  undefined4 uVar1;
  short *psVar2;
  ushort uVar3;
  ushort uVar4;
  int unaff_A3;
  int unaff_A4;

  uVar3 = *(ushort *)((int)&comp_pos_y + unaff_A3 + 2);
  uVar1 = *(undefined4 *)((int)&comp_pos_y + unaff_A4);
  *(uint *)((int)&comp_pos_y + unaff_A4) =
      CONCAT22(*(short *)((int)&comp_collision_sensor[0].y + unaff_A3) +
                   *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
                   *(short *)((int)&comp_pos_y + unaff_A3),
               uVar3);
  (&component_collision_flags)[unaff_A4] =
      (&component_collision_flags)[unaff_A4] & 3;
  uVar4 = (ushort)uVar1;
  if (uVar4 != uVar3) {
    if (uVar4 < uVar3) {
      if (-1 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
        *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
      }
    } else {
      psVar2 = (short *)((int)&comp_vel[0].y + unaff_A4);
      if ((*psVar2 != 0) && (*psVar2 < 0)) {
        *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
      }
    }
  }
  return;
}

void FUN_0002c07a(void)

{
  undefined4 uVar1;
  short *psVar2;
  ushort uVar3;
  ushort uVar4;
  int unaff_A3;
  int unaff_A4;

  uVar3 = *(ushort *)((int)&component_vel_old[0].y + unaff_A4);
  if ((short)uVar3 < 0) {
    uVar3 = -uVar3;
  }
  uVar4 = *(ushort *)((int)&component_vel_old[0].y + unaff_A3);
  if ((short)uVar4 < 0) {
    uVar4 = -uVar4;
  }
  if (uVar4 != uVar3) {
    if (uVar4 < uVar3) {
      uVar3 = *(ushort *)((int)&comp_pos_y + unaff_A3 + 2);
      uVar1 = *(undefined4 *)((int)&comp_pos_y + unaff_A4);
      *(uint *)((int)&comp_pos_y + unaff_A4) =
          CONCAT22(*(short *)((int)&comp_collision_sensor[0].y + unaff_A3) +
                       *(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
                       *(short *)((int)&comp_pos_y + unaff_A3),
                   uVar3);
      (&component_collision_flags)[unaff_A4] =
          (&component_collision_flags)[unaff_A4] & 3;
      uVar4 = (ushort)uVar1;
      if (uVar4 != uVar3) {
        if (uVar4 < uVar3) {
          if (-1 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
            *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
          }
        } else {
          psVar2 = (short *)((int)&comp_vel[0].y + unaff_A4);
          if ((*psVar2 != 0) && (*psVar2 < 0)) {
            *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
          }
        }
      }
      return;
    }
    *(short *)((int)&comp_pos_y + unaff_A3) =
        (*(short *)((int)&comp_pos_y + unaff_A4) -
         *(short *)((int)&comp_collision_sensor[0].y + unaff_A4)) -
        *(short *)((int)&comp_collision_sensor[0].y + unaff_A3);
    *(undefined2 *)((int)&comp_pos_y + unaff_A3 + 2) = 0;
    (&component_collision_flags)[unaff_A3] =
        (&component_collision_flags)[unaff_A3] & 3;
    return;
  }
  return;
}

void related_to_moving_two_objects_together_maybe(entity_id_t e)

{
  short sVar1;

  if ((((&component_unknown_6)[e] & 2) != 0) &&
      (sVar1 = *(short *)((int)&component_unknown_9 + e),
       (char)(&DAT_ffffd19a)[sVar1] < '\0')) {
    comp_pos_x.fixed.i = *(short *)(&DAT_ffffd21a + sVar1) + comp_pos_x.fixed.i;
    comp_pos_y.fixed.i = *(short *)(&DAT_ffffd21c + sVar1) + comp_pos_y.fixed.i;
  }
  return;
}

void FUN_0002c0bc(void)

{
  short sVar1;
  int unaff_A3;

  if ((((&component_unknown_6)[unaff_A3] & 2) != 0) &&
      (sVar1 = *(short *)((int)&component_unknown_9 + unaff_A3),
       (char)(&DAT_ffffd19a)[sVar1] < '\0')) {
    *(short *)((int)&comp_pos_x + unaff_A3) =
        *(short *)((int)&comp_pos_x + unaff_A3) -
        *(short *)(&DAT_ffffd21a + sVar1);
    *(short *)((int)&comp_pos_y + unaff_A3) =
        *(short *)((int)&comp_pos_y + unaff_A3) -
        *(short *)(&DAT_ffffd21c + sVar1);
  }
  return;
}

long FUN_0002c0e0(void)

{
  long lVar1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined1 in_ZF;
  undefined8 uVar2;

  lVar1 = FUN_0002d898();
  if (!(bool)in_ZF) {
    return lVar1;
  }
  FUN_00001646();
  vdp_set_window_position(0);
  uVar2 = FUN_0002c140();
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar2 >> 0x20),
                    (long)uVar2,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar2 = related_to_text_1();
    lVar1 = (long)((ulonglong)uVar2 >> 0x20);
  } while (DAT_ffffdeb4 < '\0');
  if (((undefined1)vdp_ctrl_mode_set_2_state & 0x40) != 0) {
    related_to_palette_maybe_1 = 0xff;
    related_to_palette_maybe_2 = 0;
    uVar2 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            lVar1,
                            (long)uVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    lVar1 = (long)((ulonglong)uVar2 >> 0x20);
  }
  return lVar1;
}

undefined8 FUN_0002c10e(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  FUN_00001646();
  audio_play_sound_asha_dies();
  vdp_set_window_position(0);
  FUN_0002c140();
  do {
    uVar1 = related_to_text_1();
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    if ((gamepad_pressed & GAMEPAD_START) != GAMEPAD_NONE)
      break;
  } while (DAT_ffffdeb4 < '\0');
  if (((undefined1)vdp_ctrl_mode_set_2_state & 0x40) != 0) {
    related_to_palette_maybe_1 = 0xff;
    related_to_palette_maybe_2 = 0;
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  }
  return uVar1;
}

void FUN_0002c140(void)

{
  undefined4 in_A0;

  SCRIPT_CTX_CURRENT.flags = SCRIPT_CTX_FLAG_NONE;
  DAT_ffffdeb6 = in_A0;
  DAT_ffffdeb5 = 0;
  DAT_ffffdeb4 = 0xff;
  DAT_ffffdef0 = 0;
  DAT_ffffdeba = 0;
  DAT_ffffdecc = 0;
  DAT_ffffdede = 0;
  return;
}

void related_to_text_1(void)

{
  byte bVar1;

  FUN_0002c4e2();
  // If flag 7 is set.
  if ((char)SCRIPT_CTX_CURRENT.flags < '\0') {
    related_to_text_3(&SCRIPT_CTX_CURRENT);
  }
  while ((DAT_ffffdeb4 != '\0' &&
          ((DAT_ffffdeb5 == '\0' ||
            (DAT_ffffdeb5 = DAT_ffffdeb5 + -1, DAT_ffffdeb5 == '\0'))))) {
    bVar1 = *DAT_ffffdeb6;
    DAT_ffffdeb6 = DAT_ffffdeb6 + 1;
    (*(code *)((int)&WORD_0002c1a4 +
               (int)*(short *)((int)&WORD_0002c1a4 +
                               (int)(short)(ushort)bVar1)))();
  }
  return;
}

void FUN_0002c1de(void)

{
  DAT_ffffdeb4 = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002c1e4(void)

{
  ushort uVar1;
  ushort extraout_D0u;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  palette_effect_t *in_A1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar2;

  DAT_ffffdef0 = 0;
  DAT_ffffdeba = 0;
  DAT_ffffdebc = 0;
  DAT_ffffdec0 = 0;
  DAT_ffffdecc = 0;
  DAT_ffffdece = 0;
  DAT_ffffded2 = 0;
  DAT_ffffdede = 0;
  _DAT_ffffc6fc = 0xff80;
  _DAT_ffffc6fe = 0xff80;
  DAT_ffffdee0 = 0x800000;
  DAT_ffffdee4 = 0x800000;
  DAT_ffffc782 = 0;
  DAT_ffffc784 = 0;
  _DAT_ffffc786 = 0;
  _DAT_ffffc788 = 0;
  DAT_ffff91c6 = 0;
  DAT_ffffc716 = 0;
  DAT_ffffc71a = 0;
  VDP_CTRL = 0x8b00;
  palette_set_effect(~PALETTE_ID_FLAG_NONE, false, in_A1);
  uVar1 = DAT_ffff91ce;
  DAT_ffff91ce = DAT_ffff91ce & 0xff;
  uVar2 = FUN_00001646();
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar2 >> 0x20),
                  (long)uVar2,
                  -1,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  DAT_ffff91ce = CONCAT11(0xff, (char)uVar1);
  DAT_ffff96ba = 0;
  VDP_CTRL = 0x856f;
  VDP_CTRL = 0x8c00;
  FUN_0000ba1a();
  clear_unk_1();
  vdp_write_something_to_vram();
  palette_set_fade(0xffff000f,
                   (uint)extraout_D0u << 0x10,
                   '\0',
                   (palette_color_iter_t)0xffffffff);
  FUN_0000140c();
  vdp_set_window_position(0);
  DAT_ffff9690 = 0;
  DAT_ffff9694 = 0;
  DAT_ffff9698 = 0;
  DAT_ffff969c = 0;
  DAT_ffff91ce = uVar1;
  return;
}

void FUN_0002c220(void)

{
  int unaff_A3;

  DAT_ffffdeb6 = unaff_A3 + 4;
  DAT_ffff91ce._0_1_ = 0xff;
  something((byte *)(unaff_A3 + 2 + (int)*(short *)(unaff_A3 + 2)));
  DAT_ffff91ce._0_1_ = 0;
  return;
}

void FUN_0002c244(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = palette_set_fade_black_ease_out_all();
  do {
    do {
      uVar1 = exception_unk_0(unaff_A3,
                              unaff_A4,
                              unaff_A6,
                              (long)((ulonglong)uVar1 >> 0x20),
                              (long)uVar1,
                              unaff_D2,
                              unaff_D3,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
    } while (palette_fade_done_0 == 0);
  } while (((palette_fade_done_1 == 0) || (palette_fade_done_2 == 0)) ||
           (palette_fade_done_3 == 0));
  return;
}

long FUN_0002c24c(void)

{
  long lVar1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar2;

  palette_set_fade_black_ease_in_all();
  uVar2 = FUN_00000966();
  lVar1 = (long)((ulonglong)uVar2 >> 0x20);
  if (((undefined1)vdp_ctrl_mode_set_2_state & 0x40) != 0) {
    related_to_palette_maybe_1 = 0xff;
    related_to_palette_maybe_2 = 0;
    uVar2 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            lVar1,
                            (long)uVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    lVar1 = (long)((ulonglong)uVar2 >> 0x20);
  }
  return lVar1;
}

void FUN_0002c258(void)

{
  undefined1 *unaff_A3;

  DAT_ffffdeb5 = *unaff_A3;
  DAT_ffffdeb6 = unaff_A3 + 1;
  return;
}

void FUN_0002c262(entity_id_t other, undefined *param_2)

{
  component_mixed_1_t *state;
  entity_id_t self;

  state = (component_mixed_1_t *)(param_2 + 1);
  self = (entity_id_t)(short)(ushort)(byte)*param_2;
  if (((uint)state & 1) != 0) {
    state = (component_mixed_1_t *)(param_2 + 2);
  }
  DAT_ffffdeb6 = state + 1;
  entity_reset(self);
  (&comp_has_func_maybe)[self] = COMPONENT_STATE_B_C0;
  *(word *)((int)&comp_unk_3 + self) = state->unknown_3;
  *(word *)((int)&comp_pos_x + self) = state->x;
  *(word *)((int)&comp_pos_y + self) = state->y;
  *(word *)(&comp_anim_base_offset + self) = state->state_1_d;
  *(undefined2 *)((int)&comp_unk_4 + self) = 4;
  (&comp_state_a)[self] = state->state_a;
  ecs_anim_unk_2(self, (anim_item_t *)other, state->state_1_b);
  return;
}

undefined2 FUN_0002c282(void)

{
  undefined2 *unaff_A3;

  DAT_ffffdeb6 = unaff_A3 + 2;
  return *unaff_A3;
}

void FUN_0002c2a0(void)

{
  undefined2 extraout_D1w;
  undefined4 unaff_D2;
  undefined4 unaff_D3;

  vdp_hblank_effect_asha_p = FUN_0002c282();
  vdp_gfx_ptr_5._0_2_ = extraout_D1w;
  DAT_ffffdebc = unaff_D2;
  DAT_ffffdec0 = unaff_D3;
  if (DAT_ffffdef0 != '\0') {
    FUN_0002c5d6();
  }
  vdp_related_to_display_asha = vdp_related_to_display_asha | 5;
  return;
}

void FUN_0002c2c4(void)

{
  undefined2 extraout_D1w;
  undefined4 unaff_D2;
  undefined4 unaff_D3;

  vdp_hblank_effect_pepelogoo_p = FUN_0002c282();
  vdp_gfx_ptr_6 = extraout_D1w;
  DAT_ffffdece = unaff_D2;
  DAT_ffffded2 = unaff_D3;
  vdp_related_to_display_asha = vdp_related_to_display_asha | 10;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002c2de(void)

{
  short sVar1;
  short extraout_D1w;
  undefined4 unaff_D2;
  undefined4 unaff_D3;

  sVar1 = FUN_0002c282();
  _DAT_ffffc6fc = -0x80 - sVar1;
  _DAT_ffffc6fe = -0x80 - extraout_D1w;
  DAT_ffffdee0 = unaff_D2;
  DAT_ffffdee4 = unaff_D3;
  return;
}

void FUN_0002c2fe(void)

{
  uint uVar1;
  palette_fade_type_long_t extraout_D0;
  palette_fade_type_long_t extraout_D0_00;
  palette_fade_type_long_t extraout_D0_01;
  palette_fade_type_long_t fade_type;
  byte extraout_D1b;
  byte extraout_D1b_00;
  byte extraout_D1b_01;
  byte duration;
  byte *unaff_A3;

  DAT_ffffdeb6 = unaff_A3 + 2;
  duration = unaff_A3[1];
  uVar1 = 1 << (*unaff_A3 & 0x1f);
  fade_type = PALETTE_FADE_BLACK_EASE_IN;
  if ((uVar1 & 1) != 0) {
    palette_set_fade_inner(PALETTE_ID_OFFSET_0,
                           PALETTE_FADE_BLACK_EASE_IN,
                           duration,
                           (palette_color_iter_t)0xf);
    fade_type = extraout_D0;
    duration = extraout_D1b;
  }
  if ((uVar1 & 2) != 0) {
    palette_set_fade_inner(
        PALETTE_ID_OFFSET_1, fade_type, duration, (palette_color_iter_t)0xf);
    fade_type = extraout_D0_00;
    duration = extraout_D1b_00;
  }
  if ((uVar1 & 4) != 0) {
    palette_set_fade_inner(
        PALETTE_ID_OFFSET_2, fade_type, duration, (palette_color_iter_t)0xf);
    fade_type = extraout_D0_01;
    duration = extraout_D1b_01;
  }
  if ((uVar1 & 8) != 0) {
    palette_set_fade_inner(
        PALETTE_ID_OFFSET_3, fade_type, duration, (palette_color_iter_t)0xf);
  }
  return;
}

void FUN_0002c314(void)

{
  byte bVar1;
  byte bVar2;
  short sVar3;
  byte *pbVar4;
  byte *unaff_A3;

  bVar2 = *unaff_A3;
  pbVar4 = &palette_fade_done_0;
  sVar3 = 3;
  while (
      (bVar1 = bVar2 & 1, bVar2 = bVar2 >> 1, bVar1 == 0 || (*pbVar4 != 0))) {
    pbVar4 = pbVar4 + 4;
    sVar3 = sVar3 + -1;
    if (sVar3 == -1) {
      DAT_ffffdeb6 = unaff_A3 + 1;
      return;
    }
  }
  DAT_ffffdeb6 = (byte *)((int)DAT_ffffdeb6 + -1);
  return;
}

void FUN_0002c338(void)

{
  short sVar1;
  short *unaff_A3;

  sVar1 = (ushort) * (byte *)((int)unaff_A3 + 3) << 6;
  SCRIPT_CTX_CURRENT.b = CONCAT11((char)((ushort)sVar1 >> 8),
                                  *(char *)(unaff_A3 + 1) + (char)sVar1) *
                             2 +
                         0xc000;
  SCRIPT_CTX_CURRENT._16_3_ =
      (undefined3)(((uint) * (byte *)(unaff_A3 + 2) << 0x10) >> 8);
  SCRIPT_CTX_CURRENT.k.b[1] = *(undefined1 *)((int)unaff_A3 + 5);
  DAT_ffffdeb6 = unaff_A3 + 4;
  SCRIPT_CTX_CURRENT.f = *(union2_t *)(unaff_A3 + 3);
  script_ctx_push_string(&SCRIPT_CTX_CURRENT, *unaff_A3);
  FUN_00019206((char *)&SCRIPT_CTX_CURRENT);
  SCRIPT_CTX_CURRENT.flags = SCRIPT_CTX_FLAG_80 | SCRIPT_CTX_FLAG_01;
  return;
}

// FIXME Where is it called?

void FUN_0002c386(void)

{
  // If flag 7 is set.
  if ((char)SCRIPT_CTX_CURRENT.flags < '\0') {
    DAT_ffffdeb6 = DAT_ffffdeb6 + -1;
  }
  return;
}

void FUN_0002c394(void)

{
  word compressed_data_index;
  void *in_A1;
  short *unaff_A3;
  word *pwVar1;
  undefined *dst;

  DAT_ffffdeb6 = unaff_A3 + 1;
  text_unk_1((void *)((int)unaff_A3 + (int)*unaff_A3), in_A1);
  pwVar1 = compressed_data_indices;
  dst = (undefined *)0x0;
  compressed_data_indices_size = 0x40;
  do {
    compressed_data_index = *pwVar1;
    if ((-1 < (short)compressed_data_index) &&
        (compressed_data_index != pwVar1[0x40])) {
      pwVar1[0x40] = compressed_data_index;
      uncompress_data(compressed_data_index, (uint8_t *)&vdp_gfx_ptr_1);
      vdp_copy_1kb_from_gfx_ptr_1_to_vram(dst);
    }
    pwVar1 = pwVar1 + 1;
    dst = dst + 0x400;
    compressed_data_indices_size = compressed_data_indices_size - 1;
  } while (compressed_data_indices_size != 0);
  return;
}

void FUN_0002c3ac(void)

{
  byte bVar1;
  short sVar2;
  short sVar3;
  short sVar4;
  ushort uVar5;
  byte *pbVar6;
  vdp_palette_t *pavVar7;
  vdp_color_t *pvVar8;
  byte *pbVar9;
  vdp_color_t *pvVar10;
  undefined1 *unaff_A3;
  bool bVar11;

  DAT_ffff9812 = *unaff_A3;
  DAT_ffff9813 = unaff_A3[1];
  DAT_ffff9814 = unaff_A3[2];
  DAT_ffffdeb6 = unaff_A3 + 4;
  DAT_ffff9815 = unaff_A3[3];
  pavVar7 = palettes;
  sVar4 = 3;
  pbVar6 = &DAT_ffff9812;
  do {
    (*pavVar7)[0] = DAT_ffff9810;
    bVar1 = *pbVar6;
    if (bVar1 < 0xfc) {
      sVar3 = (ushort)bVar1 + (ushort)bVar1 * 0x10;
      uVar5 = *(ushort *)(&DAT_0007c034 + sVar3);
      sVar2 = 0xe;
      pvVar8 = (vdp_color_t *)((int)pavVar7 + 2);
      pbVar9 = &DAT_0007c036 + sVar3;
      do {
        bVar1 = *pbVar9;
        sVar3 = (ushort)(bVar1 & 0xe0) * 2;
        sVar3 =
            CONCAT11((char)((ushort)sVar3 >> 8), bVar1 & 0x1c | (byte)sVar3) *
            2;
        bVar11 = CARRY2(uVar5, uVar5);
        uVar5 = uVar5 * 2;
        pavVar7 = (vdp_palette_t *)(pvVar8 + 1);
        *pvVar8 =
            (CONCAT11((char)((ushort)sVar3 >> 8), bVar1 & 3 | (byte)sVar3) * 2 +
             (ushort)bVar11) *
            2;
        sVar2 = sVar2 + -1;
        pvVar8 = (vdp_color_t *)pavVar7;
        pbVar9 = pbVar9 + 1;
      } while (sVar2 != -1);
    } else {
      sVar3 = 0xf;
      pvVar8 = *pavVar7;
      pvVar10 = (vdp_color_t *)((int)palettes_2 +
                                (int)(short)((bVar1 - 0xfc) * 0x20));
      do {
        pavVar7 = (vdp_palette_t *)(pvVar8 + 1);
        *pvVar8 = *pvVar10;
        sVar3 = sVar3 + -1;
        pvVar8 = (vdp_color_t *)pavVar7;
        pvVar10 = pvVar10 + 1;
      } while (sVar3 != -1);
    }
    sVar4 = sVar4 + -1;
    pbVar6 = pbVar6 + 1;
  } while (sVar4 != -1);
  return;
}

void related_to_text_2(void)

{
  script_ctx_flag_t sVar1;

  if (-1 < (char)SCRIPT_CTX_CURRENT.flags) {
    return;
  }
  sVar1 = SCRIPT_CTX_CURRENT.flags & SCRIPT_CTX_FLAG_40;
  SCRIPT_CTX_CURRENT.flags = SCRIPT_CTX_CURRENT.flags | SCRIPT_CTX_FLAG_40;
  if (sVar1 == SCRIPT_CTX_FLAG_NONE) {
    related_to_text_4(&SCRIPT_CTX_CURRENT);
    SCRIPT_CTX_CURRENT.h = 4;
    SCRIPT_CTX_CURRENT.bf_09_arg = '\x01';
  }
  // WARNING: Could not recover jumptable at 0x0001961a. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0001961e +
             (int)*(short *)((int)&WORD_0001961e +
                             (int)(short)(ushort)SCRIPT_CTX_CURRENT.mode)))();
  return;
}

void thunk_FUN_00001646(void)

{
  long in_D0;
  long in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;

  if (((undefined1)vdp_ctrl_mode_set_2_state & 0x40) != 0) {
    related_to_palette_maybe_1 = 0xff;
    related_to_palette_maybe_2 = 0;
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    in_D0,
                    in_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  return;
}

void FUN_0002c3de(void)

{
  byte bVar1;
  short sVar2;
  short sVar3;
  short sVar4;
  ushort uVar5;
  byte *pbVar6;
  undefined4 *puVar7;
  vdp_palette_t *pavVar8;
  vdp_color_t *pvVar9;
  byte *pbVar10;
  vdp_color_t *pvVar11;
  byte *unaff_A3;
  bool bVar12;

  DAT_ffffdeb6 = unaff_A3 + 1;
  bVar1 = *unaff_A3;
  (&DAT_ffff9812)[(short)(ushort)bVar1] = bVar1 - 4;
  sVar2 = 7;
  puVar7 = (undefined4 *)((int)palettes_2 + (int)(short)((ushort)bVar1 << 5));
  do {
    *puVar7 = 0;
    sVar2 = sVar2 + -1;
    puVar7 = puVar7 + 1;
  } while (sVar2 != -1);
  pavVar8 = palettes;
  sVar2 = 3;
  pbVar6 = &DAT_ffff9812;
  do {
    (*pavVar8)[0] = DAT_ffff9810;
    bVar1 = *pbVar6;
    if (bVar1 < 0xfc) {
      sVar4 = (ushort)bVar1 + (ushort)bVar1 * 0x10;
      uVar5 = *(ushort *)(&DAT_0007c034 + sVar4);
      sVar3 = 0xe;
      pvVar9 = (vdp_color_t *)((int)pavVar8 + 2);
      pbVar10 = &DAT_0007c036 + sVar4;
      do {
        bVar1 = *pbVar10;
        sVar4 = (ushort)(bVar1 & 0xe0) * 2;
        sVar4 =
            CONCAT11((char)((ushort)sVar4 >> 8), bVar1 & 0x1c | (byte)sVar4) *
            2;
        bVar12 = CARRY2(uVar5, uVar5);
        uVar5 = uVar5 * 2;
        pavVar8 = (vdp_palette_t *)(pvVar9 + 1);
        *pvVar9 =
            (CONCAT11((char)((ushort)sVar4 >> 8), bVar1 & 3 | (byte)sVar4) * 2 +
             (ushort)bVar12) *
            2;
        sVar3 = sVar3 + -1;
        pvVar9 = (vdp_color_t *)pavVar8;
        pbVar10 = pbVar10 + 1;
      } while (sVar3 != -1);
    } else {
      sVar4 = 0xf;
      pvVar9 = *pavVar8;
      pvVar11 = (vdp_color_t *)((int)palettes_2 +
                                (int)(short)((bVar1 - 0xfc) * 0x20));
      do {
        pavVar8 = (vdp_palette_t *)(pvVar9 + 1);
        *pvVar9 = *pvVar11;
        sVar4 = sVar4 + -1;
        pvVar9 = (vdp_color_t *)pavVar8;
        pvVar11 = pvVar11 + 1;
      } while (sVar4 != -1);
    }
    sVar2 = sVar2 + -1;
    pbVar6 = pbVar6 + 1;
  } while (sVar2 != -1);
  return;
}

void FUN_0002c408(void)

{
  byte bVar1;
  palette_fade_type_long_t extraout_D0;
  palette_fade_type_long_t extraout_D0_00;
  palette_fade_type_long_t extraout_D0_01;
  palette_fade_type_long_t fade_type;
  char extraout_D1b;
  char extraout_D1b_00;
  char extraout_D1b_01;
  char duration;
  ushort uVar2;
  byte *unaff_A3;

  bVar1 = *unaff_A3;
  DAT_ffffdeb6 = unaff_A3 + 2;
  (&DAT_ffff9812)[(short)(ushort)bVar1] = unaff_A3[1];
  vdp_palettes_something();
  fade_type = PALETTE_FADE_BLACK_EASE_OUT;
  duration = '\x01';
  uVar2 = 1 << (bVar1 & 0x3f);
  if ((uVar2 & 1) != 0) {
    palette_set_fade_inner(PALETTE_ID_OFFSET_0,
                           PALETTE_FADE_BLACK_EASE_OUT,
                           '\x01',
                           (palette_color_iter_t)0xffffffff);
    fade_type = extraout_D0;
    duration = extraout_D1b;
  }
  if ((uVar2 & 2) != 0) {
    palette_set_fade_inner(PALETTE_ID_OFFSET_1,
                           fade_type,
                           duration,
                           (palette_color_iter_t)0xffffffff);
    fade_type = extraout_D0_00;
    duration = extraout_D1b_00;
  }
  if ((uVar2 & 4) != 0) {
    palette_set_fade_inner(PALETTE_ID_OFFSET_2,
                           fade_type,
                           duration,
                           (palette_color_iter_t)0xffffffff);
    fade_type = extraout_D0_01;
    duration = extraout_D1b_01;
  }
  if ((uVar2 & 8) != 0) {
    palette_set_fade_inner(PALETTE_ID_OFFSET_3,
                           fade_type,
                           duration,
                           (palette_color_iter_t)0xffffffff);
  }
  return;
}

longlong FUN_0002c430(void)

{
  int unaff_A3;

  DAT_ffffdeb6 = unaff_A3 + 6;
  return (ulonglong)CONCAT43((uint)CONCAT21((short)*(char *)(unaff_A3 + 2),
                                            *(undefined1 *)(unaff_A3 + 3))
                                 << 8,
                             CONCAT21((short)*(char *)(unaff_A3 + 4),
                                      *(undefined1 *)(unaff_A3 + 5)))
         << 8;
}

void FUN_0002c450(void)

{
  undefined2 unaff_D2w;
  undefined8 uVar1;

  uVar1 = FUN_0002c430();
  DAT_ffffdec4 = (int)((ulonglong)uVar1 >> 0x20);
  DAT_ffffdec8 = (int)uVar1;
  DAT_ffffdeba = unaff_D2w;
  vdp_related_to_display_asha = vdp_related_to_display_asha | 5;
  return;
}

void FUN_0002c466(void)

{
  undefined2 unaff_D2w;
  undefined8 uVar1;

  uVar1 = FUN_0002c430();
  DAT_ffffded6 = (int)((ulonglong)uVar1 >> 0x20);
  DAT_ffffdeda = (int)uVar1;
  DAT_ffffdecc = unaff_D2w;
  vdp_related_to_display_asha = vdp_related_to_display_asha | 10;
  return;
}

void FUN_0002c47c(void)

{
  undefined2 unaff_D2w;
  undefined8 uVar1;

  uVar1 = FUN_0002c430();
  DAT_ffffdee8 = (int)((ulonglong)uVar1 >> 0x20);
  DAT_ffffdeec = (int)uVar1;
  DAT_ffffdede = unaff_D2w;
  return;
}

void FUN_0002c48c(void)

{
  palette_fade_type_long_t fade_type;
  palette_fade_type_long_t fade_type_00;
  palette_fade_type_long_t fade_type_01;
  char duration;
  char duration_00;
  char duration_01;

  palette_set_fade_inner(PALETTE_ID_OFFSET_0,
                         PALETTE_FADE_BLACK_EASE_OUT,
                         '\x01',
                         (palette_color_iter_t)0xffffffff);
  palette_set_fade_inner(PALETTE_ID_OFFSET_1,
                         fade_type,
                         duration,
                         (palette_color_iter_t)0xffffffff);
  palette_set_fade_inner(PALETTE_ID_OFFSET_2,
                         fade_type_00,
                         duration_00,
                         (palette_color_iter_t)0xffffffff);
  palette_set_fade_inner(PALETTE_ID_OFFSET_3,
                         fade_type_01,
                         duration_01,
                         (palette_color_iter_t)0xffffffff);
  return;
}

void FUN_0002c49a(void)

{
  palette_fade_type_long_t fade_type;
  palette_fade_type_long_t fade_type_00;
  palette_fade_type_long_t fade_type_01;
  char duration;
  char duration_00;
  char duration_01;

  palette_set_fade_inner(PALETTE_ID_OFFSET_0,
                         PALETTE_FADE_BLACK_EASE_IN,
                         '\x01',
                         (palette_color_iter_t)0xffffffff);
  palette_set_fade_inner(PALETTE_ID_OFFSET_1,
                         fade_type,
                         duration,
                         (palette_color_iter_t)0xffffffff);
  palette_set_fade_inner(PALETTE_ID_OFFSET_2,
                         fade_type_00,
                         duration_00,
                         (palette_color_iter_t)0xffffffff);
  palette_set_fade_inner(PALETTE_ID_OFFSET_3,
                         fade_type_01,
                         duration_01,
                         (palette_color_iter_t)0xffffffff);
  return;
}

void FUN_0002c4a8(void)

{
  char cVar1;
  undefined4 *puVar2;
  uint3 *unaff_A3;

  DAT_ffffdeb6 = (int)unaff_A3 + 3;
  DAT_ffffdef2 = (char *)(uint)*unaff_A3;
  cVar1 = *DAT_ffffdef2;
  puVar2 = &DAT_ffffdef6;
  do {
    *puVar2 = 0;
    cVar1 = cVar1 + -1;
    puVar2 = puVar2 + 1;
  } while (cVar1 != '\0');
  DAT_ffffdef0 = 0xff;
  FUN_0002c5d6();
  VDP_CTRL = 0x8b03;
  vdp_related_to_display_asha = vdp_related_to_display_asha | 0xf;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002c4e2(void)

{
  int iVar1;
  char cVar2;
  char cVar3;
  char *pcVar4;
  char *pcVar5;
  char *pcVar6;
  int *piVar7;
  undefined2 *puVar8;
  undefined2 *puVar9;

  if (DAT_ffffdeba != 0) {
    if (-1 < DAT_ffffdeba) {
      DAT_ffffdeba = DAT_ffffdeba + -1;
    }
    DAT_ffffdebc = DAT_ffffdec4 + DAT_ffffdebc;
    vdp_hblank_effect_asha_p = (word)((uint)DAT_ffffdebc >> 0x10);
    DAT_ffffdec0 = DAT_ffffdec8 + DAT_ffffdec0;
    vdp_gfx_ptr_5._0_2_ = (undefined2)((uint)DAT_ffffdec0 >> 0x10);
    vdp_related_to_display_asha = vdp_related_to_display_asha | 5;
  }
  if ((DAT_ffffdef0 == '\0') && (DAT_ffffdecc != 0)) {
    if (-1 < DAT_ffffdecc) {
      DAT_ffffdecc = DAT_ffffdecc + -1;
    }
    DAT_ffffdece = DAT_ffffded6 + DAT_ffffdece;
    vdp_hblank_effect_pepelogoo_p = (undefined2)((uint)DAT_ffffdece >> 0x10);
    DAT_ffffded2 = DAT_ffffdeda + DAT_ffffded2;
    vdp_gfx_ptr_6 = (undefined2)((uint)DAT_ffffded2 >> 0x10);
    vdp_related_to_display_asha = vdp_related_to_display_asha | 10;
  }
  if (DAT_ffffdede != 0) {
    if (-1 < DAT_ffffdede) {
      DAT_ffffdede = DAT_ffffdede + -1;
    }
    DAT_ffffdee0 = DAT_ffffdee8 + DAT_ffffdee0;
    _DAT_ffffc6fc = -0x80 - (short)((uint)DAT_ffffdee0 >> 0x10);
    DAT_ffffdee4 = DAT_ffffdeec + DAT_ffffdee4;
    _DAT_ffffc6fe = -0x80 - (short)((uint)DAT_ffffdee4 >> 0x10);
  }
  if (DAT_ffffdef0 != '\0') {
    FUN_0002c5d6();
    puVar8 = &vdp_hblank_effect_pepelogoo_p;
    cVar2 = *DAT_ffffdef2;
    piVar7 = &DAT_ffffdef6;
    pcVar6 = DAT_ffffdef2;
    do {
      pcVar4 = pcVar6 + 1;
      pcVar5 = pcVar6 + 2;
      pcVar6 = pcVar6 + 3;
      iVar1 = *piVar7 + (uint)CONCAT21((short)*pcVar4, *pcVar5) * 0x100;
      *piVar7 = iVar1;
      cVar3 = *pcVar6;
      puVar9 = puVar8;
      do {
        puVar8 = puVar9 + 1;
        *puVar9 = (short)((uint)iVar1 >> 0x10);
        cVar3 = cVar3 + -1;
        puVar9 = puVar8;
      } while (cVar3 != '\0');
      cVar2 = cVar2 + -1;
      piVar7 = piVar7 + 1;
    } while (cVar2 != '\0');
    vdp_related_to_display_asha = vdp_related_to_display_asha | 10;
  }
  return;
}

void audio_play_sound_ref(sound_id_t *sound_id_p)

{
  byte bVar1;
  short sVar2;

  DAT_ffffdeb6 = sound_id_p + 1;
  while (true) {
    IO_Z80BUS = 0x100;
    do {
      bVar1 = IO_Z80BUS._0_1_;
    } while ((bVar1 & 1) != 0);
    if (z80_ram_something_1 == '\0')
      break;
    IO_Z80BUS = 0;
    sVar2 = 0x1f;
    do {
      sVar2 = sVar2 + -1;
    } while (sVar2 != -1);
  }
  (&z80_ram)[(short)(((byte)(z80_ram_something_3 + z80_ram_something_2) & 0xf) +
                     0x1c30)] = *sound_id_p;
  z80_ram_something_3 = z80_ram_something_3 + '\x01';
  IO_Z80BUS = 0;
  return;
}

void FUN_0002c5d6(void)

{
  word wVar1;
  short sVar2;
  word *pwVar3;

  wVar1 = vdp_hblank_effect_asha_p;
  sVar2 = 0xde;
  pwVar3 = (word *)&DAT_ffff91d4;
  do {
    *pwVar3 = wVar1;
    sVar2 = sVar2 + -1;
    pwVar3 = pwVar3 + 1;
  } while (sVar2 != -1);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002d37e(void)

{
  undefined2 extraout_D0u;
  undefined2 extraout_D0u_00;
  short in_D0w;
  short sVar1;
  undefined4 extraout_D1;
  undefined4 extraout_D1_00;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  undefined4 unaff_D7;
  long lVar2;
  void *extraout_A1;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined1 uVar3;
  undefined8 uVar4;
  short sStack_2;

  FUN_00001646();
  FUN_00001580();
  text_unk_1(&DAT_0002d438, extraout_A1);
  uncompress_and_copy_to_vram();
  _DAT_ffff9812 = 0x6c000000;
  vdp_palettes_something();
  DAT_ffff91ce._0_1_ = 0xff;
  something(&DAT_0002d445);
  something(&DAT_0002d55d);
  lVar2 = CONCAT22((short)((uint)unaff_D7 >> 0x10), 0xe040);
  something(&DAT_0002d55d);
  DAT_ffff91ce._0_1_ = 0;
  FUN_00019334(in_D0w);
  do {
    related_to_text_3(&SCRIPT_CTX_CURRENT);
    // While flag 7 is set.
  } while ((char)SCRIPT_CTX_CURRENT.flags < '\0');
  audio_play(SOUND_ID_PREMONITION);
  sStack_2 = 0x1ea;
  uVar3 = 0;
  uVar4 = palette_set_fade_black_ease_out_all();
  while (true) {
    exception_unk_0(&SCRIPT_CTX_CURRENT,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar4 >> 0x20),
                    (long)uVar4,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    lVar2);
    FUN_0002d42c();
    sVar1 = palette_iterate_for_unknown_reasons();
    uVar4 = CONCAT44(CONCAT22(extraout_D0u, sVar1), extraout_D1);
    if ((!(bool)uVar3) &&
        ((gamepad_pressed_prev & GAMEPAD_START) != GAMEPAD_NONE))
      break;
    sStack_2 = sStack_2 + -1;
    uVar3 = sStack_2 == 0;
    if ((bool)uVar3) {
    LAB_0002d416:
      uVar4 = palette_set_fade_black_ease_in_all();
      do {
        exception_unk_0(&SCRIPT_CTX_CURRENT,
                        unaff_A4,
                        unaff_A6,
                        (long)((ulonglong)uVar4 >> 0x20),
                        (long)uVar4,
                        unaff_D2,
                        unaff_D3,
                        unaff_D4,
                        unaff_D5,
                        unaff_D6,
                        lVar2);
        FUN_0002d42c();
        sVar1 = palette_iterate_for_unknown_reasons();
        uVar4 = CONCAT44(CONCAT22(extraout_D0u_00, sVar1), extraout_D1_00);
      } while ((bool)uVar3);
      FUN_00001646();
      return;
    }
  }
  uVar3 = 0;
  audio_play(SOUND_ID_FE);
  goto LAB_0002d416;
}

void FUN_0002d42c(void)

{
  vdp_hblank_effect_pepelogoo_p = vdp_hblank_effect_pepelogoo_p + -1;
  vdp_related_to_display_asha = vdp_related_to_display_asha | 2;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_0002d898(void)

{
  undefined2 extraout_D0u;
  word wVar1;
  word wVar2;
  undefined4 extraout_D1;
  short sVar3;
  short sVar5;
  uint uVar4;
  ushort uVar6;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  vdp_color_t *pvVar7;
  void *extraout_A1;
  vdp_color_t *pvVar8;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar9;

  FUN_00001646();
  FUN_00001580();
  DAT_ffff91ce._0_1_ = 0xff;
  text_unk_1(&UNK_0002d992, extraout_A1);
  uncompress_and_copy_to_vram();
  something(&UNK_0002dfc8);
  vdp_set_vram_write_addr((void *)0xc700);
  wVar1 = 0;
  wVar2 = 0x200;
  sVar3 = 0xd;
  do {
    sVar5 = 0x1f;
    do {
      VDP_DATA = wVar1;
      wVar1 = wVar1 + 1;
      sVar5 = sVar5 + -1;
    } while (sVar5 != -1);
    uVar4 = 0x1f;
    do {
      VDP_DATA = wVar2;
      wVar2 = wVar2 + 1;
      uVar6 = (short)uVar4 - 1;
      uVar4 = (uint)uVar6;
    } while (uVar6 != 0xffff);
    sVar3 = sVar3 + -1;
  } while (sVar3 != -1);
  vdp_set_vram_write_addr((void *)0x0);
  sVar3 = 0x1fff;
  do {
    Ram00c00000 = 0;
    sVar3 = sVar3 + -1;
  } while (sVar3 != -1);
  sVar3 = 0xf;
  pvVar7 = (vdp_color_t *)&UNK_0002d99e;
  pvVar8 = palettes_2;
  do {
    *pvVar8 = *pvVar7;
    sVar3 = sVar3 + -1;
    pvVar7 = pvVar7 + 1;
    pvVar8 = pvVar8 + 1;
  } while (sVar3 != -1);
  text_unknown_7();
  _DAT_ffff9812 = 0xfc32;
  vdp_palettes_something();
  DAT_ffff91ce._0_1_ = 0;
  DAT_ffffdf18 = 0;
  audio_play(SOUND_ID_TALES_FROM_MONSTER_WORLD);
  palette_set_fade_black_ease_out_all();
  uVar9 = FUN_00000966();
  DAT_ffffdf1c = 1;
  vdp_hblank_effect_asha_p = 0;
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar9 >> 0x20),
                    (long)uVar9,
                    0,
                    uVar4,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    if ((gamepad_held_4 & GAMEPAD_START) != GAMEPAD_NONE) {
      audio_stop_all();
      FUN_00001646();
      return 0xffffffff;
    }
    FUN_0002d9be();
    vdp_hblank_effect_asha_p = vdp_hblank_effect_asha_p ^ 0x100;
    DAT_ffffdf1c = DAT_ffffdf1c ^ 1;
    vdp_related_to_display_asha = vdp_related_to_display_asha | 1;
    DAT_ffffdf18 = DAT_ffffdf18 + 2;
    uVar9 = CONCAT44(CONCAT22(extraout_D0u, DAT_ffffdf1a + 0x90), extraout_D1);
  } while (DAT_ffffdf18 <= (short)(DAT_ffffdf1a + 0x90));
  audio_play(SOUND_ID_FE);
  palette_set_fade_black_ease_in_all();
  FUN_00000966();
  return 0;
}

void FUN_0002d9be(void)

{
  ushort uVar1;
  ushort uVar2;
  uint uVar3;
  short sVar4;
  ushort uVar5;
  uint uVar6;
  ushort uVar7;
  uint uVar8;
  undefined4 uVar9;
  byte *pbVar10;
  short *psVar11;

  psVar11 = (short *)&UNK_0002dc08;
  DAT_ffffdf16 = 0;
  do {
    uVar5 = ((DAT_ffffdf16 & 7) + (DAT_ffffdf16 & 0xfff8) * 0x20) * 4 + 0x4000;
    uVar8 = CONCAT22(uVar5, DAT_ffffdf1c) << 0x10 | (uint)uVar5;
    uVar1 = *psVar11 + DAT_ffffdf18;
    if ((((int)((uint)uVar1 << 0x10) < 0) || (DAT_ffffdf1a <= uVar1)) ||
        (*(short *)(&DAT_00ff0100 + (short)(uVar1 * 2)) == 0)) {
      sVar4 = 0x1f;
      do {
        Ram00c00004 = uVar8;
        Ram00c00000 = 0;
        uVar8 = CONCAT22((short)(uVar8 >> 0x10), (short)uVar8 + 0x20);
        sVar4 = sVar4 + -1;
      } while (sVar4 != -1);
    } else {
      uVar2 = 0x80 - ((ushort)psVar11[1] >> 1);
      uVar7 = uVar2 & 7 ^ 7;
      uVar6 = 0;
      uVar9 = CONCAT22(DAT_ffffdf1c, (uVar2 & 0xfff8) * 4 + uVar5);
      pbVar10 = &DAT_00ff0100 + (int)(short)(ushort) * (byte *)(psVar11 + 4) +
                (int)*(short *)(&DAT_00ff0100 + (short)(uVar1 * 2));
      uVar8 = (uint)(ushort)psVar11[3] << 0x14 |
              ((uint)(ushort)psVar11[3] << 4) >> 0x10;
      sVar4 = psVar11[1] - 1;
      do {
        uVar3 =
            (uint)(ushort)psVar11[2] * 0x10 + (uVar8 << 0x10 | uVar8 >> 0x10);
        uVar8 = uVar3 * 0x10000 | uVar3 >> 0x10;
        uVar5 = (ushort)(uVar3 >> 0x10);
        if (0x7ffff < uVar3) {
          pbVar10 = pbVar10 + (short)(uVar5 >> 3);
          uVar8 = CONCAT22((short)uVar3, uVar5) & 0xffff0007;
        }
        uVar6 = uVar6 << 4;
        if ((*pbVar10 & '\x01' << (uVar8 & 7)) != 0) {
          uVar6 = CONCAT31((int3)(uVar6 >> 8),
                           *(byte *)((int)psVar11 + 9) | (byte)uVar6);
        }
        uVar7 = uVar7 - 1;
        if (uVar7 == 0xffff) {
          uVar7 = 7;
          uVar6 = uVar6 << 0x10 | uVar6 >> 0x10;
          Ram00c00004 = uVar9;
          Ram00c00000 = uVar6;
          uVar9 = CONCAT22((short)((uint)uVar9 >> 0x10), (short)uVar9 + 0x20);
        }
        sVar4 = sVar4 + -1;
      } while (sVar4 != -1);
      uVar5 = uVar7 + 1 & 7;
      if (uVar5 != 0) {
        uVar6 = uVar6 << (uVar5 << 2);
        Ram00c00004 = uVar9;
        Ram00c00000 = uVar6 << 0x10 | uVar6 >> 0x10;
      }
    }
    psVar11 = psVar11 + 5;
    DAT_ffffdf16 = DAT_ffffdf16 + 1;
  } while (DAT_ffffdf16 < 0x60);
  return;
}

void text_unknown_7(void)

{
  ushort uVar1;
  ushort uVar3;
  undefined4 *puVar2;
  short c;
  ushort uVar4;
  char unaff_D2b;
  short sVar5;
  char *pcVar6;
  byte *string;
  void **glyph_info_p;
  short *psVar7;
  int extraout_A1;
  int *piVar8;
  byte *string_2;
  undefined4 *puVar9;
  short *psStack_4;
  byte c_2;

  DAT_ffffdf1a = 0;
  DAT_ffffdf1e = 0;
  puVar9 = (undefined4 *)0xff0800;
  uVar3 = 0;
  pcVar6 = &DAT_00ff0000;
  do {
    uVar4 = uVar3 & 0xff;
    sVar5 = 7;
    do {
      uVar1 = uVar4 & 1;
      uVar4 = uVar4 >> 1;
      unaff_D2b = unaff_D2b * '\x02' + (uVar1 != 0);
      sVar5 = sVar5 + -1;
    } while (sVar5 != -1);
    *pcVar6 = unaff_D2b;
    uVar3 = uVar3 + 1;
    pcVar6 = pcVar6 + 1;
  } while (uVar3 < 0x100);
  string = (byte *)script_fetch(0x8a);
  psStack_4 = (short *)&DAT_00ff0100;
  do {
    sVar5 = 0x5f;
    puVar2 = puVar9;
    do {
      *puVar2 = 0;
      sVar5 = sVar5 + -1;
      puVar2 = puVar2 + 1;
    } while (sVar5 != -1);
    sVar5 = 0xf;
    puVar2 = puVar9;
    do {
      psVar7 = psStack_4;
      psStack_4 = psVar7 + 1;
      *psVar7 = (short)puVar2 + -0x100;
      puVar2 = puVar2 + 6;
      sVar5 = sVar5 + -1;
    } while (sVar5 != -1);
    psStack_4[0] = 0;
    psStack_4[1] = 0;
    psVar7[3] = 0;
    psVar7[4] = 0;
    psVar7[5] = 0;
    psVar7[6] = 0;
    psStack_4 = psVar7 + 9;
    psVar7[7] = 0;
    psVar7[8] = 0;
    DAT_ffffdf1a = DAT_ffffdf1a + 0x18;
    puVar9 = puVar9 + 0x60;
    string_2 = string;
    do {
      while (true) {
        while (true) {
          while (true) {
            string = string_2 + 1;
            c_2 = *string_2;
            // Break if it's a command
            if (0xb3 < c_2)
              break;
            if (c_2 < 0xb0) {
              script_get_character_p();
            } else {
              string = string_2 + 2;
            }
            glyph_info_p = script_get_glyph_info_table();
            text_load_glyph_tiles(
                (glyph_info_2_t *)((int)*(short *)((int)glyph_info_p +
                                                   (int)(short)(c * 2)) +
                                   (int)glyph_info_p),
                text_current_glyph_tiles);
            c_2 = DAT_ffffdf1e & 1;
            DAT_ffffdf1e = DAT_ffffdf1e & 0xfe;
            if (c_2 != 0) {
              FUN_00154f90();
              piVar8 = (int *)(extraout_A1 + -8);
              if ((DAT_ffffdf1e & 2) != 0) {
                piVar8 = (int *)(extraout_A1 + -4);
              }
              text_current_glyph_tiles._16_4_ =
                  *(uint *)*piVar8 | text_current_glyph_tiles._16_4_;
              text_current_glyph_tiles._20_4_ =
                  ((uint *)*piVar8)[1] | text_current_glyph_tiles._20_4_;
            }
            text_unknown_8();
            string_2 = string;
            // If not a 4 tiles glyph
            if (text_current_glyph_type != 0x10) {
              text_unknown_8();
            }
          }
          if (c_2 == 0xff) {
            return;
          }
          do {
          } while (c_2 < 0xb8);
          do {
          } while (4 < (byte)(c_2 + 0x48));
          string_2 = string;
          if (c_2 != 0xb8)
            break;
          DAT_ffffdf1e = 1;
        }
        if (c_2 != 0xb9)
          break;
        DAT_ffffdf1e = 3;
      }
    } while (((byte)(c_2 + 0x47) < 2) || ((byte)(c_2 + 0x47) == 2));
  } while (true);
}

void text_unknown_8(void)

{
  short sVar1;
  byte *in_A0;
  int unaff_A2;
  undefined1 *unaff_A4;

  sVar1 = 0xf;
  do {
    *unaff_A4 = *(undefined1 *)(unaff_A2 + (short)(ushort)*in_A0);
    unaff_A4 = unaff_A4 + 0x18;
    sVar1 = sVar1 + -1;
    in_A0 = in_A0 + 1;
  } while (sVar1 != -1);
  return;
}

undefined4 FUN_0002e3ee(void)

{
  DAT_ffff9fe6 = 0;
  DAT_ffffdf20 = 0;
  return 2;
}

void FUN_0002e3fe(void)

{
  short in_D0w;

  (*(code *)((int)&WORD_0002e412 +
             (int)*(short *)((int)&WORD_0002e412 +
                             (int)(short)(in_D0w * 2))))();
  return;
}

void FUN_0002e414(void)

{
  anim_item_t *unaff_A5;

  entity_reset(0xcc);
  DAT_ffffdf21 = 0;
  uRamffffba44 = 4;
  comp_func_offset[0x33].func_offset_from_15ede = 0;
  uRamffffb532 = 0;
  uRamffffa702 = 2;
  uRamffffa703 = 0;
  if ((comp_state_a & ENTITY_STATE_A_08) == 0) {
    bRamffff9fe7 = bRamffff9fe7 & 0xf7;
    comp_vel[0x33].x.raw = 0x400;
    sRamffffa1ee = comp_pos_x.fixed.i + 0xf;
  } else {
    bRamffff9fe7 = bRamffff9fe7 | 8;
    comp_vel[0x33].x.raw = -0x400;
    sRamffffa1ee = comp_pos_x.fixed.i + -0xf;
  }
  sRamffffa2f2 = comp_pos_y.fixed.i + 10;
  ecs_anim_unk_2(0xcc, unaff_A5, 0);
  return;
}

void FUN_0002e48a(void)

{
  (*(code *)((int)&WORD_0002e49e +
             (int)*(short *)((int)&WORD_0002e49e +
                             (int)(short)(ushort)DAT_ffffdf20)))();
  return;
}

void FUN_0002e4a0(void)

{
  short sVar1;
  int iVar2;

  iVar2 = 0xcc;
  sVar1 = 2;
  do {
    if ((char)(&comp_has_func_maybe)[iVar2] < '\0') {
      (*(code *)((int)&WORD_0002e4ce +
                 (int)*(short *)((int)&WORD_0002e4ce +
                                 (int)*(short *)((int)&comp_state + iVar2))))();
      iVar2 = (int)(short)iVar2;
    }
    iVar2 = iVar2 + 4;
    sVar1 = sVar1 + -1;
  } while (sVar1 != -1);
  return;
}

void FUN_0002e4d0(void)

{
  char cVar1;
  entity_id_t unaff_A4;
  undefined1 uVar2;
  bool bVar3;

  cVar1 = (&DAT_ffffb978)[unaff_A4] + -1;
  (&DAT_ffffb978)[unaff_A4] = cVar1;
  uVar2 = cVar1 == '\0';
  if ((bool)uVar2) {
    FUN_0002e520();
  }
  player_update_pos(unaff_A4);
  bVar3 = FUN_00000eae(unaff_A4);
  if (bVar3 || (bool)uVar2) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
    FUN_0001689e();
  }
  return;
}

void FUN_0002e4f2(void)

{
  (*(code *)((int)&WORD_0002e506 +
             (int)*(short *)((int)&WORD_0002e506 +
                             (int)(short)(ushort)DAT_ffffdf20)))();
  return;
}

void FUN_0002e508(void)

{
  entity_id_t unaff_A4;
  bool bVar1;

  bVar1 = false;
  if (DAT_ffff9fe6 < '\0') {
    FUN_00000ed6(unaff_A4, 0xcc);
    if (bVar1) {
      (&comp_func_offset[0].unk4)[unaff_A4] =
          (&comp_func_offset[0].unk4)[unaff_A4] | 1;
    }
  }
  return;
}

void FUN_0002e520(void)

{
  undefined4 extraout_D0;
  short sVar1;
  entity_id_w_t unaff_D2w;
  int16_vec2_t *extraout_A0;
  int16_vec2_t *piVar2;
  int iVar3;
  int unaff_A4;
  byte *unaff_A5;

  FUN_0000165c((ushort *)&int16_vec2_t_0002e5ca,
               unaff_A5,
               unaff_D2w,
               *(short *)((int)&comp_pos_x + unaff_A4),
               *(short *)((int)&comp_pos_y + unaff_A4),
               0);
  if ((short)unaff_D2w < 0) {
    sVar1 = (short)CONCAT31((int3)((uint)extraout_D0 >> 8), DAT_ffffdf21) * 6;
    piVar2 = extraout_A0;
  } else {
    iVar3 = (int)(short)unaff_A4;
    piVar2 = &int16_vec2_t_0002e5a0;
    sVar1 = (ushort)DAT_ffffdf21 * 6;
    if (((&comp_state_a)[unaff_A4] & ENTITY_STATE_A_08) == 0) {
      *(short *)((int)&comp_pos_x + iVar3) =
          *(short *)((int)&int16_vec2_t_0002e5a0.x + (int)sVar1) +
          *(short *)((int)&comp_pos_x + iVar3);
    } else {
      *(short *)((int)&comp_pos_x + iVar3) =
          *(short *)((int)&comp_pos_x + iVar3) -
          *(short *)((int)&int16_vec2_t_0002e5a0.x + (int)sVar1);
    }
    *(short *)((int)&comp_pos_y + iVar3) =
        *(short *)((int)&int16_vec2_t_0002e5a0.y + (int)sVar1) +
        *(short *)((int)&comp_pos_y + iVar3);
  }
  (&DAT_ffffb978)[unaff_A4] =
      (char)*(undefined2 *)((int)&piVar2[1].x + (int)sVar1);
  if (DAT_ffffdf21 < 6) {
    DAT_ffffdf21 = DAT_ffffdf21 + 1;
  } else {
    DAT_ffffdf21 = '\0';
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002e5d0(void)

{
  undefined2 extraout_D1w;

  FUN_0002e5f6();
  FUN_0002e5f6();
  FUN_0002e5f6();
  _DAT_ffffe224 = extraout_D1w;
  _DAT_ffffe226 = extraout_D1w;
  _DAT_ffffe228 = extraout_D1w;
  _DAT_ffffe22a = extraout_D1w;
  return;
}

void FUN_0002e5f6(void)

{
  short sVar1;
  undefined4 in_D1;
  undefined4 *in_A0;

  sVar1 = 0x3f;
  do {
    *in_A0 = in_D1;
    sVar1 = sVar1 + -1;
    in_A0 = in_A0 + 1;
  } while (sVar1 != -1);
  return;
}

void FUN_0002e600(void)

{
  char cVar1;
  short sVar2;
  short extraout_D1w;
  short sVar3;

  do {
    if (DAT_ffffe230 != '\0') {
      FUN_0002e640();
      FUN_0002e68e();
      cVar1 = '\0';
      do {
        sVar2 = 0xff;
        sVar3 = 0;
        DAT_ffffe222 = '\0';
        do {
          if (cVar1 == (&DAT_ffffdf22)[sVar3]) {
            cVar1 = FUN_0002e6a2();
            DAT_ffffe222 = -1;
            sVar2 = extraout_D1w;
          }
          sVar3 = sVar3 + 1;
          sVar2 = sVar2 + -1;
        } while (sVar2 != -1);
        cVar1 = cVar1 + '\x01';
      } while (DAT_ffffe222 != '\0');
    }
    FUN_0002e7a6();
  } while (true);
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002e640(void)

{
  _DAT_ffffe224 = DAT_ffffc73a & 0xfff0;
  if (_DAT_ffffe228 == 0) {
    _DAT_ffffe228 = _DAT_ffffe224;
    _DAT_ffffe22a = _DAT_ffffe224;
  }
  _DAT_ffffe226 = DAT_ffffc746 & 0xfff0;
  return;
}

void FUN_0002e68e(void)

{
  short sVar1;
  undefined1 *in_A1;
  undefined4 *puVar2;

  sVar1 = 0x3f;
  puVar2 = (undefined4 *)&DAT_ffffdf22;
  do {
    *puVar2 = 0xffffffff;
    sVar1 = sVar1 + -1;
    puVar2 = puVar2 + 1;
  } while (sVar1 != -1);
  *in_A1 = 0;
  return;
}

void FUN_0002e6a2(void)

{
  FUN_0002e6ba();
  FUN_0002e6ec();
  FUN_0002e722();
  FUN_0002e758();
  return;
}

void FUN_0002e6ba(void)

{
  char extraout_D0b;
  short unaff_D2w;
  word wVar1;
  word unaff_D6w;
  word unaff_D7w;
  int unaff_A2;
  int unaff_A3;

  if (-1 < (short)(unaff_D2w + -0x10)) {
    FUN_0002e790();
    if (*(char *)(unaff_A3 + -0x10 + (int)unaff_D2w) == -1) {
      wVar1 = FUN_00017330(unaff_D6w, unaff_D7w);
      if (*(char *)(unaff_A2 + (short)wVar1) == '\0') {
        *(char *)(unaff_A3 + -0x10 + (int)unaff_D2w) = extraout_D0b + '\x01';
      } else {
        *(undefined1 *)(unaff_A3 + -0x10 + (int)unaff_D2w) = 0xfe;
      }
    }
  }
  return;
}

void FUN_0002e6ec(void)

{
  char extraout_D0b;
  short unaff_D2w;
  word wVar1;
  word unaff_D6w;
  word unaff_D7w;
  int unaff_A2;
  int unaff_A3;

  if (((ushort)(unaff_D2w + 0x10U) < 0x100) &&
      (*(char *)(unaff_A3 + 0x10 + (int)unaff_D2w) == -1)) {
    FUN_0002e790();
    wVar1 = FUN_00017330(unaff_D6w, unaff_D7w);
    if (*(char *)(unaff_A2 + (short)wVar1) == '\0') {
      *(char *)(unaff_A3 + 0x10 + (int)unaff_D2w) = extraout_D0b + '\x01';
    } else {
      *(undefined1 *)(unaff_A3 + 0x10 + (int)unaff_D2w) = 0xfe;
    }
  }
  return;
}

void FUN_0002e722(void)

{
  char extraout_D0b;
  ushort unaff_D2w;
  word wVar1;
  word unaff_D6w;
  word unaff_D7w;
  int unaff_A2;
  int unaff_A3;

  if (((unaff_D2w & 0xf) != 0) &&
      (*(char *)(unaff_A3 + -1 + (int)(short)unaff_D2w) == -1)) {
    FUN_0002e790();
    wVar1 = FUN_00017330(unaff_D6w, unaff_D7w);
    if (*(char *)(unaff_A2 + (short)wVar1) == '\0') {
      *(char *)(unaff_A3 + -1 + (int)(short)unaff_D2w) = extraout_D0b + '\x01';
    } else {
      *(undefined1 *)(unaff_A3 + -1 + (int)(short)unaff_D2w) = 0xfe;
    }
  }
  return;
}

void FUN_0002e758(void)

{
  char extraout_D0b;
  short unaff_D2w;
  word wVar1;
  word unaff_D6w;
  word unaff_D7w;
  int unaff_A2;
  int unaff_A3;

  if ((((byte)unaff_D2w & 0xf) != 0xf) &&
      (*(char *)(unaff_A3 + 1 + (int)unaff_D2w) == -1)) {
    FUN_0002e790();
    wVar1 = FUN_00017330(unaff_D6w, unaff_D7w);
    if (*(char *)(unaff_A2 + (short)wVar1) == '\0') {
      *(char *)(unaff_A3 + 1 + (int)unaff_D2w) = extraout_D0b + '\x01';
    } else {
      *(undefined1 *)(unaff_A3 + 1 + (int)unaff_D2w) = 0xfe;
    }
  }
  return;
}

void FUN_0002e790(void)

{
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002e7a6(void)

{
  short sVar1;
  undefined4 *puVar2;
  undefined4 *puVar3;

  _DAT_ffffe22a = _DAT_ffffe226;
  _DAT_ffffe228 = _DAT_ffffe224;
  sVar1 = 0x3f;
  puVar2 = (undefined4 *)&DAT_ffffdf22;
  puVar3 = (undefined4 *)&DAT_ffffe022;
  do {
    *puVar3 = *puVar2;
    sVar1 = sVar1 + -1;
    puVar2 = puVar2 + 1;
    puVar3 = puVar3 + 1;
  } while (sVar1 != -1);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002e7c4(void)

{
  void *extraout_A1;

  FUN_00001580();
  DAT_ffff91ce._0_1_ = 0xff;
  text_unk_1(&WORD_0002e826, extraout_A1);
  uncompress_and_copy_to_vram();
  if (DAT_ffffe232 == 2) {
    _DAT_ffff9812 = 0x357f8000;
  } else {
    _DAT_ffff9812 = 0x25262900;
  }
  vdp_palettes_something();
  something(&UNK_0002e92c);
  something(&UNK_0002ebf4);
  // WARNING: Could not recover jumptable at 0x0002e81e. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0002e820 +
             (int)*(short *)((int)&WORD_0002e820 +
                             (int)(short)((ushort)DAT_ffffe232 * 2))))();
  return;
}

void FUN_0002e82e(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  FUN_0002ef66();
  DAT_ffff91ce._0_1_ = 0;
  palette_set_fade_black_ease_out_all();
  uVar1 = FUN_00000966();
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar1 = FUN_0002f010();
  } while (palette_fade_done_0 == 0);
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar1 = FUN_0002f010();
  } while (gamepad_pressed_prev == GAMEPAD_NONE);
  uVar1 = palette_set_fade_black_ease_in_all();
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar1 = FUN_0002f010();
  } while (palette_fade_done_0 == 0);
  return;
}

void FUN_0002e870(void)

{
  short sVar1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar2;

  FUN_0002ef66();
  DAT_ffff91ce._0_1_ = 0;
  palette_set_fade_black_ease_out_all();
  do {
    uVar2 = FUN_0002f010();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar2 >> 0x20),
                    (long)uVar2,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  } while (palette_fade_done_0 == 0);
  FUN_0002f1f0();
  sVar1 = 600;
  do {
    FUN_0002f248();
    FUN_00014722();
    uVar2 = FUN_0002f010();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar2 >> 0x20),
                    (long)uVar2,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    sVar1 = sVar1 + -1;
  } while (sVar1 != 0);
  palette_set_effect(
      PALETTE_ID_FLAG_0, true, (palette_effect_t *)&UNK_0002f0d4);
  palette_set_effect(
      PALETTE_ID_FLAG_1, true, (palette_effect_t *)&UNK_0002f11c);
  palette_set_effect(
      PALETTE_ID_FLAG_2, true, (palette_effect_t *)&UNK_0002f1a8);
  sVar1 = 0xa0;
  do {
    FUN_0002f248();
    FUN_00014722();
    uVar2 = FUN_0002f074();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar2 >> 0x20),
                    (long)uVar2,
                    4,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    sVar1 = sVar1 + -1;
  } while (sVar1 != 0);
  uVar2 = palette_set_fade_black_ease_in_all();
  do {
    do {
      uVar2 = exception_unk_0(unaff_A3,
                              unaff_A4,
                              unaff_A6,
                              (long)((ulonglong)uVar2 >> 0x20),
                              (long)uVar2,
                              4,
                              unaff_D3,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
    } while (palette_fade_done_0 == 0);
  } while (((palette_fade_done_1 == 0) || (palette_fade_done_2 == 0)) ||
           (palette_fade_done_3 == 0));
  return;
}

void FUN_0002e904(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  FUN_0002ef66();
  DAT_ffff91ce._0_1_ = 0;
  palette_set_fade_black_ease_out_all();
  uVar1 = FUN_00000966();
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    uVar1 = FUN_0002f0ba();
  } while (gamepad_pressed_prev == GAMEPAD_NONE);
  uVar1 = palette_set_fade_black_ease_in_all();
  do {
    do {
      uVar1 = exception_unk_0(unaff_A3,
                              unaff_A4,
                              unaff_A6,
                              (long)((ulonglong)uVar1 >> 0x20),
                              (long)uVar1,
                              unaff_D2,
                              unaff_D3,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
    } while (palette_fade_done_0 == 0);
  } while (((palette_fade_done_1 == 0) || (palette_fade_done_2 == 0)) ||
           (palette_fade_done_3 == 0));
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002ef66(void)

{
  DAT_ffff91ce._0_1_ = 0xff;
  DAT_ffffc716 = 0;
  DAT_ffffc71a = 0;
  _DAT_ffffe238 = 0;
  _DAT_ffffe23a = 0;
  _DAT_ffffe234 = &UNK_0002efbe;
  FUN_0002efa4();
  FUN_0002efb4();
  FUN_0002f010();
  _DAT_ffffe23e = 0x10;
  vdp_related_to_display_asha = vdp_related_to_display_asha | 1;
  DAT_ffff91ce._0_1_ = 0;
  return;
}

void FUN_0002efa4(void)

{
  short sVar1;
  word *pwVar2;

  sVar1 = 0x6f;
  pwVar2 = &vdp_hblank_effect_asha_p;
  do {
    pwVar2[0] = 0;
    pwVar2[1] = 0;
    sVar1 = sVar1 + -1;
    pwVar2 = pwVar2 + 2;
  } while (sVar1 != -1);
  return;
}

void FUN_0002efb4(void)

{
  VDP_CTRL = 0x8b0b;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002f010(void)

{
  short sVar1;
  int iVar2;
  short sVar3;
  short sVar4;
  short *psVar5;
  short *psVar6;
  word *pwVar7;

  sVar1 = _DAT_ffffe238;
  psVar5 = _DAT_ffffe234;
  _DAT_ffffe23e = _DAT_ffffe23e + -1;
  if (_DAT_ffffe23e == 0) {
    _DAT_ffffe23e = 0x10;
    psVar6 = _DAT_ffffe234 + 1;
    _DAT_ffffe234 = _DAT_ffffe234 + 1;
    if (*psVar6 < 0) {
      _DAT_ffffe234 = (short *)&UNK_0002efbe;
    }
    sVar4 = 0xdf;
    pwVar7 = &vdp_hblank_effect_asha_p;
    do {
      psVar6 = psVar5 + 1;
      sVar3 = *psVar5;
      if (sVar3 < 0) {
        psVar6 = (short *)&UNK_0002efc0;
        sVar3 = 0;
      }
      *pwVar7 = sVar1 + sVar3;
      sVar4 = sVar4 + -1;
      psVar5 = psVar6;
      pwVar7 = pwVar7 + 1;
    } while (sVar4 != -1);
    vdp_related_to_display_asha = vdp_related_to_display_asha | 1;
  }
  _DAT_ffffe23a = _DAT_ffffe23a + 0x8000;
  iVar2 = _DAT_ffffe23a;
  _DAT_ffffe23a = (undefined2)((uint)_DAT_ffffe23a >> 0x10);
  vdp_gfx_ptr_5._0_2_ = _DAT_ffffe23a;
  vdp_related_to_display_asha = vdp_related_to_display_asha | 4;
  _DAT_ffffe23a = iVar2;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002f074(void)

{
  short sVar1;
  int iVar2;
  word wVar3;
  short sVar4;
  word *pwVar5;

  sVar1 = _DAT_ffffe238;
  _DAT_ffffe23e = _DAT_ffffe23e + -1;
  if (_DAT_ffffe23e == 0) {
    _DAT_ffffe23e = 0x10;
    sVar4 = 0xdf;
    pwVar5 = &vdp_hblank_effect_asha_p;
    do {
      wVar3 = sVar1 + *pwVar5;
      if (wVar3 != 0) {
        wVar3 = wVar3 - 1;
      }
      *pwVar5 = wVar3;
      sVar4 = sVar4 + -1;
      pwVar5 = pwVar5 + 1;
    } while (sVar4 != -1);
    vdp_related_to_display_asha = vdp_related_to_display_asha | 1;
  }
  _DAT_ffffe23a = _DAT_ffffe23a + 0x8000;
  iVar2 = _DAT_ffffe23a;
  _DAT_ffffe23a = (undefined2)((uint)_DAT_ffffe23a >> 0x10);
  vdp_gfx_ptr_5._0_2_ = _DAT_ffffe23a;
  vdp_related_to_display_asha = vdp_related_to_display_asha | 4;
  _DAT_ffffe23a = iVar2;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002f0ba(void)

{
  int iVar1;

  _DAT_ffffe23a = _DAT_ffffe23a + 0x8000;
  iVar1 = _DAT_ffffe23a;
  _DAT_ffffe23a = (undefined2)((uint)_DAT_ffffe23a >> 0x10);
  vdp_gfx_ptr_5._0_2_ = _DAT_ffffe23a;
  vdp_related_to_display_asha = vdp_related_to_display_asha | 4;
  _DAT_ffffe23a = iVar1;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002f1f0(void)

{
  _DAT_ffffe244 = 0x1e;
  _DAT_ffffe240 = &UNK_0002f208;
  FUN_0002f268();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002f248(void)

{
  short sVar1;

  if (_DAT_ffffe244 == 0) {
    sVar1 = *_DAT_ffffe240;
    if (-1 < sVar1) {
      _DAT_ffffe240 = _DAT_ffffe240 + 1;
      _DAT_ffffe244 = sVar1;
      FUN_0002f268();
    }
  }
  _DAT_ffffe244 = _DAT_ffffe244 + -1;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002f268(void)

{
  undefined2 uVar1;
  short unaff_D2w;
  entity_id_t e;
  anim_item_t *unaff_A5;

  FUN_0000147a(FUN_0002f2c6, 1, 0);
  if (-1 < unaff_D2w) {
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    *(undefined2 *)((int)&comp_unk_3 + e) = 4;
    *(undefined2 *)((int)&comp_pos_x + e) = 0x83;
    *(undefined2 *)((int)&comp_pos_y + e) = 0x5f;
    (&comp_state_a)[e] = 0;
    (&comp_anim_base_offset)[e] = 0x18;
    (&comp_anim_b)[e] = 0x3c;
    *(undefined2 *)(&DAT_ffffbd76 + e) = 0;
    *(undefined2 *)(&DAT_ffffbd78 + e) = 0;
    uVar1 = *_DAT_ffffe240;
    _DAT_ffffe240 = _DAT_ffffe240 + 1;
    ecs_anim_unk_2(e, unaff_A5, (byte)uVar1);
    *(undefined2 *)((int)&comp_unk_4 + e) = 4;
  }
  return;
}

void FUN_0002f2c6(void)

{
  short sVar1;
  short extraout_D1w;
  int unaff_A4;

  *(short *)(&DAT_ffffbd76 + unaff_A4) =
      *(short *)(&DAT_ffffbd76 + unaff_A4) + 0x40;
  *(short *)(&DAT_ffffbd78 + unaff_A4) =
      *(short *)(&DAT_ffffbd78 + unaff_A4) + 0x200;
  sVar1 = FUN_000012a8();
  *(short *)((int)&comp_pos_x + unaff_A4) = sVar1 + 0x83;
  *(short *)((int)&comp_pos_y + unaff_A4) = extraout_D1w + 0x5f;
  if ((*(short *)((int)&comp_pos_y + unaff_A4) < 0) ||
      (0x10f < *(ushort *)((int)&comp_pos_y + unaff_A4))) {
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002f306(void)

{
  uint uVar1;
  uint uVar2;
  word wVar3;
  word wVar4;
  undefined4 extraout_D0;
  char duration;
  undefined4 extraout_D1;
  short sVar5;
  short sVar6;
  uint uVar7;
  ushort uVar8;
  uint uVar9;
  uint uVar10;
  uint *puVar11;
  uint *puVar12;
  void *extraout_A1;
  script_ctx_t *unaff_A3;
  short *psVar13;
  byte *other;
  byte *pbVar14;
  void *unaff_A6;
  undefined8 uVar15;
  short sStack_2;

  FUN_00001646();
  FUN_00001580();
  DAT_ffff91ce._0_1_ = 0xff;
  FUN_0000c6fe();
  text_unk_1(&DAT_0002f482, extraout_A1);
  uncompress_and_copy_to_vram();
  _DAT_ffff9812 = 0x24d0045;
  vdp_palettes_something();
  palette_set_fade(~PALETTE_ID_FLAG_NONE,
                   PALETTE_FADE_1,
                   duration,
                   (palette_color_iter_t)0xffffffff);
  other = (byte *)0xff6000;
  sStack_2 = 3;
  psVar13 = (short *)&UNK_0002f708;
  do {
    uncompress_data(*psVar13, &DAT_00ff0000);
    puVar11 = (uint *)&DAT_00ff0000;
    uVar10 = 3;
    do {
      uVar9 = 7;
      do {
        uVar7 = 7;
        do {
          puVar12 = puVar11;
          uVar2 = *puVar12;
          sVar6 = 7;
          pbVar14 = other;
          do {
            uVar1 = uVar2 << 4;
            uVar2 = uVar1 | uVar2 >> 0x1c;
            other = pbVar14 + 1;
            *pbVar14 = (byte)uVar2 & 0xf;
            sVar6 = sVar6 + -1;
            pbVar14 = other;
          } while (sVar6 != -1);
          uVar8 = (short)uVar7 - 1;
          uVar7 = (uint)uVar8;
          puVar11 = puVar12 + 8;
        } while (uVar8 != 0xffff);
        puVar11 = puVar12 + -0x37;
        uVar8 = (short)uVar9 - 1;
        uVar9 = (uint)uVar8;
      } while (uVar8 != 0xffff);
      puVar11 = puVar12 + 1;
      uVar8 = (short)uVar10 - 1;
      uVar10 = (uint)uVar8;
    } while (uVar8 != 0xffff);
    sStack_2 = sStack_2 + -1;
    psVar13 = psVar13 + 1;
  } while (sStack_2 != 0);
  sVar6 = 0x15ff;
  puVar11 = (uint *)&DAT_00ff0000;
  do {
    *puVar11 = uVar1 & 0xffff0000;
    sVar6 = sVar6 + -1;
    puVar11 = puVar11 + 1;
  } while (sVar6 != -1);
  vdp_set_vram_write_addr((void *)0xc000);
  sVar6 = 0xbf;
  do {
    VDP_DATA = 0x781;
    sVar6 = sVar6 + -1;
  } while (sVar6 != -1);
  wVar3 = 0x2000;
  sVar6 = 0x15;
  do {
    sVar5 = 1;
    do {
      uVar2 = 0x1f;
      do {
        wVar4 = wVar3;
        VDP_DATA = wVar4;
        uVar8 = (short)uVar2 - 1;
        uVar2 = (uint)uVar8;
        wVar3 = wVar4 + 1;
      } while (uVar8 != 0xffff);
      wVar3 = wVar4 + 0x2a1;
      sVar5 = sVar5 + -1;
    } while (sVar5 != -1);
    wVar3 = wVar4 - 0x2bf;
    sVar6 = sVar6 + -1;
  } while (sVar6 != -1);
  sVar6 = 0xbf;
  do {
    VDP_DATA = 0x781;
    sVar6 = sVar6 + -1;
  } while (sVar6 != -1);
  something(&DAT_0002f70e);
  ecs_init_entity_state(
      ENTITY_ID_08, (entity_id_t)other, &component_mixed_1_t_0002f498);
  comp_vel[2].y.raw = -8;
  _DAT_ffffe246 = 0x80;
  FUN_0002f55e();
  vdp_copy(VDP_MEM_VIDEO_RAM, &DAT_00ff0000, (void *)0x0, 0x2c00, '\0');
  DAT_ffff91ce._0_1_ = 0;
  DAT_ffffe24d = 0;
  _DAT_ffffe248 = 0;
  _DAT_ffffe24a = 0;
  DAT_ffffe24c = 0x80;
  PTR_ffff96b6 = FUN_0002f4a2;
  PTR_ffff96b2 = FUN_0002f51c;
  DAT_ffff96b0 = -1;
  uVar15 = palette_set_fade_black_ease_out_all();
  do {
    exception_unk_0(unaff_A3,
                    ENTITY_ID_08,
                    unaff_A6,
                    (long)((ulonglong)uVar15 >> 0x20),
                    (long)uVar15,
                    1,
                    uVar2,
                    0x20,
                    uVar7,
                    uVar9,
                    uVar10);
    ecs_update_pos_y(ENTITY_ID_08);
    uVar15 = CONCAT44(extraout_D0, extraout_D1);
  } while (DAT_ffff96b0 != '\0');
  palette_set_fade_black_ease_in_all();
  FUN_00000966();
  FUN_00001646();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002f434(entity_id_t self)

{
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  void *unaff_A6;
  undefined8 uVar1;

  DAT_ffff91ce._0_1_ = 0;
  DAT_ffffe24d = 0;
  _DAT_ffffe248 = 0;
  _DAT_ffffe24a = 0;
  DAT_ffffe24c = 0x80;
  PTR_ffff96b6 = FUN_0002f4a2;
  PTR_ffff96b2 = FUN_0002f51c;
  DAT_ffff96b0 = -1;
  uVar1 = palette_set_fade_black_ease_out_all();
  do {
    exception_unk_0(unaff_A3,
                    self,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    self = ENTITY_ID_08;
    ecs_update_pos_y(ENTITY_ID_08);
    uVar1 = CONCAT44(extraout_D0, extraout_D1);
  } while (DAT_ffff96b0 != '\0');
  palette_set_fade_black_ease_in_all();
  FUN_00000966();
  FUN_00001646();
  return;
}

// WARNING: Removing unreachable block (ram,0x00000606)
// WARNING: Removing unreachable block (ram,0x000005aa)
// WARNING: Removing unreachable block (ram,0x0000061e)
// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002f4a2(void)

{
  union2_t uVar1;
  union2_t uVar2;
  byte bVar3;
  ushort uVar4;
  ushort uVar5;
  uint uVar6;
  word wVar7;
  short sVar8;
  ushort uVar9;
  word *pwVar10;
  undefined1 uStack_5;
  undefined1 uStack_4;
  undefined1 uStack_3;

  uVar4 = _DAT_ffffe24a;
  uVar9 = _DAT_ffffe248 & 0xfff8;
  uVar5 = uVar9 - _DAT_ffffe24a;
  if (_DAT_ffffe24a <= uVar9 && uVar5 != 0) {
    sVar8 = 0;
    if ((char)DAT_ffffe24c < '\0') {
      sVar8 = 0x5800;
    }
    if (0x17 < uVar5) {
      uVar5 = 0x18;
    }
    _DAT_ffffe24a = uVar5 + _DAT_ffffe24a;
    if ((DAT_ffffe24d < '\0') && (uVar9 == _DAT_ffffe24a)) {
      wVar7 = 0;
      DAT_ffffe24d = '\0';
      _DAT_ffffe248 = 0;
      _DAT_ffffe24a = 0;
      bVar3 = DAT_ffffe24c & 0x80;
      DAT_ffffe24c = DAT_ffffe24c ^ 0x80;
      if (bVar3 != 0) {
        wVar7 = 0x100;
      }
      Ram00c00004 = 0x58000003;
      VDP_DATA = wVar7;
    }
    uVar9 = uVar4 * 0x80 + sVar8;
    pwVar10 = (word *)((short)(uVar4 * 0x80) + 0xff0000);
    io_z80bus_tmp = IO_Z80BUS;
    IO_Z80BUS = 0x100;
    do {
      bVar3 = IO_Z80BUS._0_1_;
    } while ((bVar3 & 1) != 0);
    VDP_CTRL = (union2_t)(vdp_ctrl_mode_set_2_state | 0x10);
    VDP_CTRL = (union2_t)(word)CONCAT31(0x93, (char)(uVar5 << 6));
    VDP_CTRL = (union2_t)((ushort)(uVar5 << 6) >> 8 | 0x9400);
    uVar6 = (uint)pwVar10 >> 1;
    uStack_3 = (undefined1)uVar6;
    VDP_CTRL = (union2_t)(word)CONCAT31(0x95, uStack_3);
    uStack_4 = (undefined1)(uVar6 >> 8);
    VDP_CTRL = (union2_t)(word)CONCAT31(0x96, uStack_4);
    uStack_5 = (undefined1)(uVar6 >> 0x10);
    VDP_CTRL = (union2_t)((ushort)CONCAT31(0x97, uStack_5) & 0xff7f);
    uVar1.w = uVar9 & 0x3fff | 0x4000;
    uVar2.w = uVar9 >> 0xe;
    VDP_CTRL = (union2_t)uVar1.w;
    VDP_CTRL = (union2_t)(uVar2.w | 0x80);
    VDP_CTRL = (union2_t)vdp_ctrl_mode_set_2_state;
    VDP_CTRL = (union2_t)uVar1.w;
    VDP_CTRL = (union2_t)uVar2.w;
    VDP_DATA = *pwVar10;
    IO_Z80BUS = ~io_z80bus_tmp;
    VDP_CTRL = 0x8f02;
    return;
  }
  return;
}

// WARNING: Removing unreachable block (ram,0x0002f558)
// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002f51c(void)

{
  do {
    do {
    } while (DAT_ffffe24d < '\0');
    if (_DAT_ffffe246 < 0x101) {
      FUN_0002f55e();
    } else {
      FUN_0002f600();
    }
    _DAT_ffffe248 = 0xb0;
    DAT_ffffe24d = -1;
    _DAT_ffffe246 = (_DAT_ffffe246 >> 5) + _DAT_ffffe246;
  } while (_DAT_ffffe246 < 0x601);
  do {
  } while (true);
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002f55e(void)

{
  ushort uVar1;
  uint uVar2;
  ushort uVar3;
  uint uVar4;
  uint uVar5;
  int iVar6;
  int iVar7;
  int *piVar8;

  iVar7 = (short)(0x200000 / _DAT_ffffe246) * 8;
  uVar1 = 0x80 - (_DAT_ffffe246 >> 3);
  _DAT_ffffe248 = 0x58 - ((ushort)(_DAT_ffffe246 + (_DAT_ffffe246 >> 1)) >> 3);
  uVar5 = 0;
  do {
    uVar3 = 7 - (uVar1 & 7);
    piVar8 = (int *)((int)(short)((uVar1 & 0xfff8) << 2) +
                     (short)(_DAT_ffffe248 << 2 & 0x1cU |
                             (_DAT_ffffe248 << 2 & 0xffe0U) << 5) +
                     0xff0000);
    uVar4 = 0;
    iVar6 = 0;
    while (true) {
      iVar6 = CONCAT31(
          (int3)((uint)(iVar6 << 4) >> 8),
          *(byte *)((short)((short)uVar5 << 6) + 0xff6000 + (int)(short)uVar4) |
              (byte)(iVar6 << 4));
      uVar2 = iVar7 + (uVar4 << 0x10 | uVar4 >> 0x10);
      uVar4 = uVar2 * 0x10000 | uVar2 >> 0x10;
      if (0x3f < (ushort)(uVar2 >> 0x10))
        break;
      uVar3 = uVar3 - 1;
      if (uVar3 == 0xffff) {
        uVar3 = 7;
        *piVar8 = iVar6;
        piVar8 = piVar8 + 8;
      }
    }
    *piVar8 = iVar6 << ((uVar3 & 0xf) << 2);
    _DAT_ffffe248 = _DAT_ffffe248 + 1;
    uVar4 = iVar7 + (uVar5 << 0x10 | uVar5 >> 0x10);
    uVar5 = uVar4 * 0x10000 | uVar4 >> 0x10;
  } while ((ushort)(uVar4 >> 0x10) < 0x60);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002f600(void)

{
  ushort uVar1;
  uint uVar2;
  ushort uVar3;
  uint uVar4;
  ushort uVar5;
  uint uVar6;
  uint uVar7;
  ushort uVar8;
  short sVar9;
  int iVar10;
  int *piVar11;
  int *piVar12;
  int *piVar13;

  uVar4 = (short)(0x800000 / _DAT_ffffe246) * 2;
  uVar1 = 0x80 - (_DAT_ffffe246 >> 3);
  _DAT_ffffe248 = 0x58 - ((ushort)(_DAT_ffffe246 + (_DAT_ffffe246 >> 1)) >> 3);
  uVar7 = 0;
  if ((short)_DAT_ffffe248 < 0) {
    uVar7 = (uint)(ushort)-_DAT_ffffe248 * (uVar4 & 0xffff);
    uVar7 = uVar7 * 0x10000 | uVar7 >> 0x10;
    _DAT_ffffe248 = 0;
  }
  do {
    piVar11 = (int *)((short)(_DAT_ffffe248 << 2 & 0x1c |
                              (_DAT_ffffe248 << 2 & 0xffe0) << 5) +
                      0xff0000);
    uVar6 = 0;
    if ((short)uVar1 < 0) {
      uVar6 = (uint)(ushort)-uVar1 * (uVar4 & 0xffff);
      uVar6 = uVar6 * 0x10000 | uVar6 >> 0x10;
      uVar5 = 7;
      piVar12 = piVar11;
    } else {
      uVar5 = 7 - (uVar1 & 7);
      piVar12 = (int *)((int)(short)((uVar1 & 0xfff8) << 2) + (int)piVar11);
    }
    sVar9 = 0x100;
    iVar10 = 0;
    while (true) {
      iVar10 = CONCAT31(
          (int3)((uint)(iVar10 << 4) >> 8),
          *(byte *)((short)((short)uVar7 << 6) + 0xff6000 + (int)(short)uVar6) |
              (byte)(iVar10 << 4));
      uVar2 = uVar4 + (uVar6 << 0x10 | uVar6 >> 0x10);
      uVar6 = uVar2 * 0x10000 | uVar2 >> 0x10;
      if ((0x3f < (ushort)(uVar2 >> 0x10)) || (sVar9 = sVar9 + -1, sVar9 == 0))
        break;
      uVar5 = uVar5 - 1;
      if (uVar5 == 0xffff) {
        uVar5 = 7;
        *piVar12 = iVar10;
        piVar12 = piVar12 + 8;
      }
    }
    *piVar12 = iVar10 << ((uVar5 & 0xf) << 2);
    while (true) {
      piVar12 = piVar11;
      uVar5 = _DAT_ffffe248 + 1;
      if (0xaf < uVar5) {
        return;
      }
      uVar3 = (ushort)uVar7;
      uVar6 = uVar4 + (uVar7 << 0x10 | uVar7 >> 0x10);
      uVar7 = uVar6 * 0x10000 | uVar6 >> 0x10;
      uVar8 = (ushort)(uVar6 >> 0x10);
      if (0x5f < uVar8) {
        _DAT_ffffe248 = uVar5;
        return;
      }
      _DAT_ffffe248 = uVar5;
      if (uVar3 != uVar8)
        break;
      piVar11 = (int *)((short)(uVar5 * 4 & 0x1c | (uVar5 * 4 & 0xffe0) << 5) +
                        0xff0000);
      sVar9 = 0x1f;
      piVar13 = piVar11;
      do {
        *piVar13 = *piVar12;
        piVar13 = piVar13 + 8;
        piVar12 = piVar12 + 8;
        sVar9 = sVar9 + -1;
      } while (sVar9 != -1);
    }
  } while (true);
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002f828(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
code_r0x0002f828:
  do {
    if (0x1ff < _DAT_ffffe24e) {
      return;
    }
    _DAT_ffffe24e = _DAT_ffffe24e + 1;
    vdp_gfx_ptr_5._0_2_ = 0;
    vdp_gfx_ptr_6 = 0;
    vdp_related_to_display_asha = 0xc;
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    if (-1 < DAT_ffffe250) {
      if (vdp_related_to_hblank_y_pos_pepelogoo.w != 0xc0) {
        vdp_related_to_hblank_y_pos_pepelogoo.w =
            vdp_related_to_hblank_y_pos_pepelogoo.w + 1;
        goto code_r0x0002f828;
      }
      DAT_ffffe250 = -1;
    }
    if (vdp_related_to_hblank_y_pos_pepelogoo.w < 0x71) {
      DAT_ffffe250 = '\0';
    } else {
      vdp_related_to_hblank_y_pos_pepelogoo.w =
          vdp_related_to_hblank_y_pos_pepelogoo.w - 1;
    }
  } while (true);
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void hblank_set_cb_something_1(void)

{
  _HBLANK = _hblank_cb_something_1;
  DAT_ffff91ce._0_1_ = 0;
  DAT_ffff9630 = 0x8a00;
  vdp_related_to_display_1 = 0xff;
  DAT_ffff9628 = 0;
  _DAT_ffff962e = 0x60;
  vdp_related_to_hblank_effects_2 = 0;
  vdp_related_to_hblank_y_pos_pepelogoo.w = 0x60;
  DAT_ffff9629 = 0;
  _DAT_ffff962a = 0xffff;
  _DAT_ffff962c = 0;
  FUN_0002f8cc();
  VDP_CTRL = 0x8004;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 hblank_cb_something_1(void)

{
  int iVar1;
  vdp_draw_pos_t vVar2;
  undefined4 in_D0;

  vVar2 = VDP_DRAW_POS;
  if ((union2_t)((ushort)vVar2 >> 8) != (union2_t)_DAT_ffff962e) {
    return in_D0;
  }
  iVar1 = (int)(short)vdp_related_to_hblank_effects_2;
  if (-1 < DAT_ffff9629) {
    vdp_related_to_hblank_effects_2 = vdp_related_to_hblank_effects_2 + 2;
  }
  VDP_CTRL = 0x4000;
  VDP_CTRL = 0x10;
  VDP_DATA = vdp_gfx_ptr_5._0_2_ + *(short *)(iVar1 + -0x69ce);
  _DAT_ffff962e = _DAT_ffff962e + 1;
  if ((word)(vdp_related_to_hblank_y_pos_pepelogoo.w + 0x28) == _DAT_ffff962e) {
    DAT_ffff9629 = -1;
  }
  if ((word)(vdp_related_to_hblank_y_pos_pepelogoo.w + 0x50) == _DAT_ffff962e) {
    VDP_CTRL = 0x4000;
    VDP_CTRL = 0x10;
    VDP_DATA = vdp_gfx_ptr_5._0_2_;
    if (_DAT_ffff962c == 0x28) {
      DAT_ffff9628 = 0;
      _DAT_ffff962e = vdp_related_to_hblank_y_pos_pepelogoo;
      DAT_ffff9629 = 0;
      _DAT_ffff962a = 0xffff;
      _DAT_ffff962c = 0;
      return in_D0;
    }
    *(short *)(_DAT_ffff962c + -0x69ce) = _DAT_ffff962a;
    _DAT_ffff962e = vdp_related_to_hblank_y_pos_pepelogoo;
    vdp_related_to_hblank_effects_2 = 0;
    DAT_ffff9629 = '\0';
    _DAT_ffff962a = _DAT_ffff962a + -1;
    _DAT_ffff962c = _DAT_ffff962c + -1;
  }
  return in_D0;
}

void FUN_0002f8cc(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (true);
}

void FUN_0002f8d2(void)

{
  return;
}

void FUN_0002f8d4(void)

{
  VDP_CTRL = 0x8004;
  hblank_set_cb_something_3();
  FUN_0002f920();
  VDP_CTRL = 0x8004;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void hblank_set_cb_something_3(void)

{
  vdp_related_to_hblank_effects_2 = 0x80;
  vdp_related_to_hblank_y_pos_pepelogoo.w = 0x20;
  DAT_ffff9628 = 0;
  FUN_0002f94e();
  _HBLANK = _hblank_cb_something_3;
  DAT_ffff91ce._0_1_ = 0;
  DAT_ffff9630 = 0x8a00;
  vdp_related_to_display_1 = 0xff;
  return;
}

undefined4 hblank_cb_something_3(void)

{
  vdp_draw_pos_t vVar1;
  undefined4 in_D0;

  vVar1 = VDP_DRAW_POS;
  if ((ushort)vVar1 >> 8 == vdp_related_to_hblank_y_pos_pepelogoo.w) {
    if ((ushort)vVar1 >> 8 == 0x80) {
      VDP_CTRL = 0x4000;
      VDP_CTRL = 0x10;
      VDP_DATA = 0;
      vdp_related_to_hblank_y_pos_pepelogoo.w = 0x20;
      if ((DAT_ffff9628 & 2) != 0) {
        DAT_ffff9628 = DAT_ffff9628 & 0xfd;
        DAT_ffff9628 = DAT_ffff9628 ^ 1;
      }
    } else {
      FUN_00003d2a();
    }
  }
  return in_D0;
}

void FUN_0002f920(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  while (true) {
    vdp_related_to_hblank_effects_2 = vdp_related_to_hblank_effects_2 - 1;
    if (vdp_related_to_hblank_effects_2 == 0)
      break;
    uVar1 = FUN_0002f94e();
    uVar1 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    DAT_ffff9628 = DAT_ffff9628 | 2;
  }
  return;
}

void FUN_0002f94e(void)

{
  word wVar1;
  short i;
  word *in_A0;

  i = 0xa0;
  wVar1 = vdp_related_to_hblank_effects_2;
  do {
    *in_A0 = wVar1;
    wVar1 = wVar1 - 1;
    if ((short)wVar1 < 0) {
      wVar1 = 0;
    }
    i = i + -1;
    in_A0 = in_A0 + 1;
  } while (i != -1);
  return;
}

void FUN_0002f964(void)

{
  VDP_CTRL = 0x8004;
  hblank_set_cb_something_4();
  FUN_0002f9b0();
  VDP_CTRL = 0x8004;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void hblank_set_cb_something_4(void)

{
  vdp_related_to_hblank_y_pos_pepelogoo.w = 0x47;
  DAT_ffff9629 = 0;
  _DAT_ffff962a = 3;
  FUN_0002f9d4();
  _HBLANK = _hblank_cb_something_4;
  DAT_ffff91ce._0_1_ = 0;
  DAT_ffff9630 = 0x8a00;
  vdp_related_to_display_1 = 0xff;
  return;
}

undefined4 hblank_cb_something_4(void)

{
  vdp_draw_pos_t vVar1;
  undefined4 in_D0;

  vVar1 = VDP_DRAW_POS;
  if ((ushort)vVar1 >> 8 == vdp_related_to_hblank_y_pos_pepelogoo.w) {
    if ((ushort)vVar1 >> 8 == 0x80) {
      VDP_CTRL = 0x4000;
      VDP_CTRL = 0x10;
      VDP_DATA = 0;
      vdp_related_to_hblank_y_pos_pepelogoo.w = 0x47;
      if ((DAT_ffff9628 & 2) != 0) {
        DAT_ffff9628 = DAT_ffff9628 & 0xfd;
        DAT_ffff9628 = DAT_ffff9628 ^ 1;
      }
    } else {
      FUN_00003dc0();
    }
  }
  return in_D0;
}

void FUN_0002f9b0(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  do {
    uVar1 = FUN_0002f9d4();
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    DAT_ffff9628 = DAT_ffff9628 | 2;
  } while (true);
}

void FUN_0002f9d2(void)

{
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002f9d4(void)

{
  FUN_0002fa10();
  FUN_0002fa38();
  FUN_0002fa6a();
  if (DAT_ffff9629 == '\0') {
    if (_DAT_ffff962a == 7) {
      DAT_ffff9629 = -1;
    } else {
      _DAT_ffff962a = _DAT_ffff962a + 1;
    }
  } else if (_DAT_ffff962a == 0) {
    DAT_ffff9629 = '\0';
  } else {
    _DAT_ffff962a = _DAT_ffff962a + -1;
  }
  return;
}

void FUN_0002fa10(void)

{
  short sVar1;
  short in_D0w;
  short sVar2;
  short sVar3;
  short *psVar4;

  sVar1 = *(short *)((int)SHORT_ARRAY_0002fa28 + (int)(short)(in_D0w * 2));
  sVar3 = 0x10;
  sVar2 = sVar1;
  psVar4 = (short *)&DAT_ffffe4d2;
  do {
    *psVar4 = sVar2;
    sVar2 = sVar1 + sVar2;
    sVar3 = sVar3 + -1;
    psVar4 = psVar4 + 1;
  } while (sVar3 != -1);
  return;
}

void FUN_0002fa38(void)

{
  short sVar1;
  ushort uVar2;
  int in_A0;
  ushort *puVar3;
  short *psVar4;

  uVar2 = 0;
  psVar4 = (short *)(in_A0 + 0x20);
  puVar3 = (ushort *)&DAT_ffffe4d2;
  do {
    if (*puVar3 >> 8 < 0xd) {
      sVar1 = (*puVar3 >> 8) - uVar2;
    } else {
      sVar1 = -0x8b - uVar2;
    }
    psVar4 = psVar4 + -1;
    *psVar4 = sVar1;
    uVar2 = uVar2 + 1;
    puVar3 = puVar3 + 1;
  } while (uVar2 < 0x10);
  return;
}

void FUN_0002fa6a(void)

{
  short sVar1;
  ushort uVar2;
  int in_A0;
  ushort *puVar3;
  short *psVar4;

  uVar2 = 0;
  puVar3 = (ushort *)&DAT_ffffe4d2;
  psVar4 = (short *)(in_A0 + 0x20);
  do {
    if (*puVar3 >> 8 < 0xd) {
      sVar1 = -((*puVar3 >> 8) - uVar2);
    } else {
      sVar1 = uVar2 - 0x8b;
    }
    *psVar4 = sVar1;
    uVar2 = uVar2 + 1;
    puVar3 = puVar3 + 1;
    psVar4 = psVar4 + 1;
  } while (uVar2 < 0x10);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002fa9e(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar1;

  DAT_ffffe55a = 0;
  DAT_ffffe55c = 0;
  DAT_ffffe55b = 0;
  *(undefined4 *)(&comp_unk_2 + unaff_A4) = 0xffffffff;
  FUN_0000281e();
  _DAT_ffffe556 = 0;
  DAT_ffffe552 = (undefined2)unaff_A4;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x18;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 7;
  (&DAT_ffffb976)[unaff_A4] = 0;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_pos_y + unaff_A4) -
      *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  bVar1 = script_state_get((script_state_bit_t)0x3ea);
  if (bVar1) {
    related_to_entering_a_room_7 = 0xff;
    DAT_ffffcc85 = 0xff;
    DAT_ffffcc86 = 1;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 10;
    (&DAT_ffffb976)[unaff_A4] = 0;
    FUN_00030f2a();
  }
  FUN_0000ebcc();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0002fb1e(void)

{
  short *psVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_0000281e();
  _DAT_ffffe556 = 0;
  _DAT_ffffe554 = (undefined2)unaff_A4;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x16;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 5;
  (&DAT_ffffb976)[unaff_A4] = 0;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + -0x20;
  return;
}

void FUN_0002fb50(void)

{
  entity_id_t unaff_A4;
  entity_id_t unaff_A5;
  bool bVar1;

  if ((DAT_ffff915f & 0x78) == 0x78) {
    DAT_ffffe55c = -1;
  }
  if ((DAT_ffff915f & 0x74) == 0x74) {
    DAT_ffffe55c = '\0';
  }
  if ((((*(short *)((int)&comp_state + unaff_A4) != 0) &&
        (*(short *)((int)&comp_state + unaff_A4) != 10)) &&
       (*(short *)((int)&comp_state + unaff_A4) != 0xb)) &&
      (*(short *)((int)&comp_state + unaff_A4) != 0xc)) {
    FUN_0002fc4c();
    if (DAT_ffffe55c == '\0') {
      FUN_0002fd40(unaff_A4);
    } else {
      FUN_0002ffa8();
    }
    FUN_0002ff26(unaff_A4);
  }
  (*(code *)((int)&WORD_0002fc32 +
             (int)*(
                 short *)((int)&WORD_0002fc32 +
                          (int)(short)(*(short *)((int)&comp_state + unaff_A4) *
                                       2))))();
  if (((*(short *)((int)&comp_state + unaff_A4) != 10) &&
       (*(short *)((int)&comp_state + unaff_A4) != 0xb)) &&
      (*(short *)((int)&comp_state + unaff_A4) != 0xc)) {
    FUN_0002fc66(unaff_A4, unaff_A5);
    FUN_0002fd24();
  }
  if ((*(short *)((int)&comp_state + unaff_A4) != 0xb) &&
      (*(short *)((int)&comp_state + unaff_A4) != 0xc)) {
    bVar1 = script_state_get((script_state_bit_t)0x3ea);
    if ((!bVar1) && (total_hearts == 1)) {
      *(undefined2 *)((int)&comp_state + unaff_A4) = 0xc;
      DAT_ffffcc85 = 0xff;
      DAT_ffffcc86 = 1;
      (&DAT_ffffb976)[unaff_A4] = 0;
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      uint8_t_ffffcc70 = '\0';
      comp_state_a = comp_state_a & 0xfb;
      comp_has_func_maybe = comp_has_func_maybe & 0xf7;
      if (*(short *)((int)&comp_vel[0].y + unaff_A4) < 0) {
        *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
      }
    }
  }
  return;
}

void FUN_0002fc4c(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&comp_pos_x + unaff_A4) < (ushort)comp_pos_x._0_2_) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  } else {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  }
  return;
}

void FUN_0002fc66(entity_id_t self, entity_id_t other)

{
  char cVar1;
  undefined1 uVar2;
  bool bVar3;
  undefined1 uVar4;
  byte item_id_likely;

  if (*(short *)((int)&comp_state + self) != 6) {
    uVar4 = *(ushort *)((int)&comp_state + self) < 7;
    uVar2 = *(ushort *)((int)&comp_state + self) == 7;
    if (!(bool)uVar2) {
      FUN_000189d0();
      FUN_00000ed6(self, ENTITY_ID_ASHA);
      if ((bool)uVar4 || (bool)uVar2) {
        if ((ushort)comp_pos_x._0_2_ < *(ushort *)((int)&comp_pos_x + self)) {
          uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x81;
        } else {
          uint8_t_ffffcc70 = uint8_t_ffffcc70 | 1;
        }
      }
      if (((&comp_func_offset[0].unk4)[self] & 1) != 0) {
        cVar1 = DAT_ffffde0e;
        if (((&comp_func_offset[0].unk4)[self] & 4) != 0) {
          cVar1 = DAT_ffffde0f;
        }
        bVar3 = script_state_get((script_state_bit_t)0x3ea);
        if (bVar3) {
          item_id_likely = (&comp_collected_item_id_maybe)[self] - cVar1;
          (&comp_collected_item_id_maybe)[self] = item_id_likely;
          if (((char)item_id_likely < '\0') || (item_id_likely == 0)) {
            *(undefined2 *)((int)&comp_state + self) = 0xb;
            (&DAT_ffffb976)[self] = 0;
            DAT_ffffcc85 = 0xff;
            DAT_ffffcc86 = 1;
            related_to_entering_a_room_7 = 0xff;
            return;
          }
        }
        *(undefined2 *)((int)&comp_state + self) = 6;
        *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
        *(undefined2 *)((int)&comp_vel[0].y + self) = 0;
        (&DAT_ffffb976)[self] = 0;
        ecs_anim_unk_2(self, (anim_item_t *)other, 6);
        (&comp_state_a)[self] = (&comp_state_a)[self] | 4;
        (&DAT_ffffab42)[self] = 0x21;
        (&DAT_ffffab43)[self] = 0;
        (&DAT_ffffb978)[self] = 0x1e;
      }
    }
  }
  return;
}

void FUN_0002fd24(void)

{
  short sVar1;
  int unaff_A4;

  while (sVar1 =
             *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4),
         -1 < sVar1) {
    unaff_A4 = (int)sVar1;
    if (((&comp_has_func_maybe)[unaff_A4] & 0x40) != 0) {
      FUN_000307c8();
    }
  }
  return;
}

void FUN_0002fd40(entity_id_t self)

{
  word wVar1;

  if (*(short *)((int)&comp_state + self) != 0) {
    if (*(short *)((int)&comp_state + self) != 1) {
      return;
    }
    if (*(int *)(&comp_unk_2 + self) != -1) {
      if (*(short *)((int)&comp_state + self) == 6) {
        return;
      }
      if (*(short *)((int)&comp_state + self) == 7) {
        return;
      }
      if (*(short *)((int)&comp_state + self) == 9) {
        return;
      }
      if (-1 < **(short **)(&comp_unk_2 + self)) {
        (*(code *)((int)&WORD_0002fdaa +
                   (int)*(
                       short *)((int)&WORD_0002fdaa +
                                (int)(short)(**(short **)(&comp_unk_2 + self) *
                                             2))))();
        return;
      }
    }
  }
  wVar1 = rand();
  *(int *)(&comp_unk_2 + self) =
      (int)&WORD_0002fda2 +
      (int)*(short *)((int)&WORD_0002fda2 + (int)(short)(wVar1 >> 5 & 6));
  return;
}

void FUN_0002fde8(void)

{
  ushort uVar1;
  int unaff_A4;

  uVar1 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  if ((short)uVar1 < 0) {
    uVar1 = -uVar1;
  }
  if (uVar1 < 0x40) {
    *(undefined2 *)(&DAT_ffffbd78 + unaff_A4) = 0;
    *(undefined2 *)(&DAT_ffffbd76 + unaff_A4) = 0x40;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 5;
    (&DAT_ffffb976)[unaff_A4] = 0;
    FUN_0002ff08();
  } else {
    *(int *)(&comp_unk_2 + unaff_A4) = *(int *)(&comp_unk_2 + unaff_A4) + 2;
  }
  return;
}

void FUN_0002fe1a(void)

{
  ushort uVar1;
  int unaff_A4;

  uVar1 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  if ((short)uVar1 < 0) {
    uVar1 = -uVar1;
  }
  if (uVar1 < 0x30) {
    *(undefined2 *)(&DAT_ffffbd78 + unaff_A4) = 0;
    *(undefined2 *)(&DAT_ffffbd76 + unaff_A4) = 0x30;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 5;
    (&DAT_ffffb976)[unaff_A4] = 0;
    FUN_0002ff08();
  } else {
    *(int *)(&comp_unk_2 + unaff_A4) = *(int *)(&comp_unk_2 + unaff_A4) + 2;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 2;
    (&DAT_ffffb976)[unaff_A4] = 0;
  }
  return;
}

void FUN_0002fe56(void)

{
  ushort uVar1;
  int unaff_A4;

  uVar1 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  if ((short)uVar1 < 0) {
    uVar1 = -uVar1;
  }
  if (uVar1 < 0x41) {
    *(int *)(&comp_unk_2 + unaff_A4) = *(int *)(&comp_unk_2 + unaff_A4) + 2;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 3;
    (&DAT_ffffb976)[unaff_A4] = 0;
  } else {
    *(undefined2 *)(&DAT_ffffbd78 + unaff_A4) = 0xffff;
    *(undefined2 *)(&DAT_ffffbd76 + unaff_A4) = 0x40;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 5;
    (&DAT_ffffb976)[unaff_A4] = 0;
  }
  return;
}

void FUN_0002fe90(void)

{
  ushort uVar1;
  int unaff_A4;

  uVar1 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  if ((short)uVar1 < 0) {
    uVar1 = -uVar1;
  }
  if (uVar1 < 0x60) {
    *(undefined2 *)(&DAT_ffffbd78 + unaff_A4) = 0;
    *(undefined2 *)(&DAT_ffffbd76 + unaff_A4) = 0x60;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 5;
    (&DAT_ffffb976)[unaff_A4] = 0;
    FUN_0002ff08();
  } else {
    *(int *)(&comp_unk_2 + unaff_A4) = *(int *)(&comp_unk_2 + unaff_A4) + 2;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
    (&DAT_ffffb976)[unaff_A4] = 0;
  }
  return;
}

void FUN_0002fecc(void)

{
  ushort uVar1;
  int unaff_A4;

  uVar1 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  if ((short)uVar1 < 0) {
    uVar1 = -uVar1;
  }
  if (uVar1 < 0x60) {
    *(undefined2 *)(&DAT_ffffbd78 + unaff_A4) = 0;
    *(undefined2 *)(&DAT_ffffbd76 + unaff_A4) = 0x60;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 5;
    (&DAT_ffffb976)[unaff_A4] = 0;
    FUN_0002ff08();
  } else {
    *(int *)(&comp_unk_2 + unaff_A4) = *(int *)(&comp_unk_2 + unaff_A4) + 2;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 8;
    (&DAT_ffffb976)[unaff_A4] = 0;
  }
  return;
}

void FUN_0002ff08(void)

{
  ushort uVar1;
  int unaff_A4;

  uVar1 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  if ((short)uVar1 < 0) {
    uVar1 = -uVar1;
  }
  if (uVar1 < 0x30) {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 3;
    (&DAT_ffffb976)[unaff_A4] = 0;
  }
  return;
}

void FUN_0002ff26(ulong ctx)

{
  short unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;

  entity_update_pos(ctx);
  interact_with_all_other_entities(ctx, unaff_D2w, (char)unaff_D3w);
  ecs_update_collision(ctx, unaff_D3w, unaff_D6w, unaff_D7w);
  ecs_apply_collision(ctx);
  if (((*(short *)((int)&comp_state + ctx) != 0xc) &&
       (*(short *)((int)&comp_state + ctx) != 5)) &&
      (((&component_collision_flags)[ctx] & 4) != 0)) {
    FUN_0002ff64();
  }
  FUN_0002ff70();
  return;
}

void FUN_0002ff64(void)

{
  undefined2 uVar1;
  int unaff_A4;

  uVar1 = FUN_0002ff90();
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = uVar1;
  return;
}

void FUN_0002ff70(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = *(short *)((int)&comp_vel[0].y + unaff_A4);
  if ((*(short *)((int)&comp_state + unaff_A4) != 8) &&
      (sVar1 = sVar1 + 0x40, 0x500 < sVar1)) {
    sVar1 = 0x500;
  }
  *(short *)((int)&comp_vel[0].y + unaff_A4) = sVar1;
  return;
}

void FUN_0002ff90(void)

{
  return;
}

void FUN_0002ffa8(void)

{
  int unaff_A4;

  if ((*(short *)((int)&comp_state + unaff_A4) == 1) &&
      ((DAT_ffff915d & 0x40) != 0)) {
    (&DAT_ffffb976)[unaff_A4] = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 8;
  }
  if ((*(short *)((int)&comp_state + unaff_A4) == 1) ||
      (*(short *)((int)&comp_state + unaff_A4) == 5)) {
    if ((DAT_ffff915d & 0x10) != 0) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
      (&DAT_ffffb976)[unaff_A4] = 0;
      *(undefined2 *)((int)&comp_state + unaff_A4) = 3;
    }
    if ((DAT_ffff915d & 0x20) != 0) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
      (&DAT_ffffb976)[unaff_A4] = 0;
      *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
    }
    if ((((&component_collision_flags)[unaff_A4] & 4) != 0) &&
        (((DAT_ffff915d & 4) != 0 || ((DAT_ffff915d & 8) != 0)))) {
      (&DAT_ffffb976)[unaff_A4] = 0;
      *(undefined2 *)((int)&comp_state + unaff_A4) = 5;
    }
  }
  return;
}

void FUN_0003002a(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_FALLING) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  return;
}

void FUN_0003003a(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x0003004a. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0003004c +
             (int)*(
                 short *)((int)&WORD_0003004c +
                          (int)(short)((ushort)(byte)(&DAT_ffffb976)[unaff_A4] *
                                       2))))();
  return;
}

void FUN_00030052(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5, 0x12);
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  (&comp_state_1_a)[unaff_A4] = (&comp_state_1_a)[unaff_A4] & 0xdf;
  (&DAT_ffffb976)[unaff_A4] = 1;
  return;
}

void FUN_0003006e(void)

{
  entity_state_1_a_t eVar1;
  int unaff_A4;

  eVar1 = (&comp_state_1_a)[unaff_A4];
  (&comp_state_1_a)[unaff_A4] = eVar1 & 0xdf;
  if ((eVar1 & 0x20) != 0) {
    FUN_0003020a();
    (&DAT_ffffb976)[unaff_A4] = 2;
  }
  return;
}

void FUN_00030082(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    (&DAT_ffffb976)[unaff_A4] = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 1;
  }
  return;
}

void FUN_0003009c(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x000300ac. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_000300ae +
             (int)*(
                 short *)((int)&WORD_000300ae +
                          (int)(short)((ushort)(byte)(&DAT_ffffb976)[unaff_A4] *
                                       2))))();
  return;
}

void FUN_000300b4(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5, 0x10);
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  (&DAT_ffffb976)[unaff_A4] = 1;
  return;
}

void FUN_000300ca(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar1;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    FUN_00030c0e();
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    (&DAT_ffffb976)[unaff_A4] = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 1;
  }
  FUN_000186f4(unaff_A4, &DAT_00030132);
  FUN_00018758(unaff_A4, &DAT_00030132);
  if (((&comp_func_offset[0].unk4)[unaff_A4] & 0x10) != 0) {
    bVar1 = script_state_get((script_state_bit_t)0x3ea);
    if (bVar1) {
      uint8_t_ffffcc70 = uint8_t_ffffcc70 | 2;
    } else {
      uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x20;
    }
    if ((ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x80;
    }
  }
  return;
}

void FUN_00030140(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    (&DAT_ffffb976)[unaff_A4] = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 1;
  }
  return;
}

void FUN_0003015a(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x0003016a. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_0003016c +
             (int)*(
                 short *)((int)&WORD_0003016c +
                          (int)(short)((ushort)(byte)(&DAT_ffffb976)[unaff_A4] *
                                       2))))();
  return;
}

void FUN_00030176(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
  (&comp_state_1_a)[unaff_A4] = (&comp_state_1_a)[unaff_A4] & 0xdf;
  (&DAT_ffffb976)[unaff_A4] = 4;
  return;
}

void FUN_0003018a(void)

{
  short *psVar1;
  short sVar2;
  ulong unaff_A4;

  player_update_pos(unaff_A4);
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar2 = *psVar1 + 0x20;
  *psVar1 = sVar2;
  if (-1 < sVar2) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    FUN_00030298();
    (&DAT_ffffb976)[unaff_A4] = 2;
  }
  *(undefined1 *)(unaff_A4 - 0x4689) = 0x14;
  return;
}

void FUN_000301ac(void)

{
  char cVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  cVar1 = *(char *)(unaff_A4 - 0x4689) + -1;
  *(char *)(unaff_A4 - 0x4689) = cVar1;
  if (cVar1 == '\0') {
    (&DAT_ffffb976)[unaff_A4] = 3;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
  }
  return;
}

void FUN_000301c0(void)

{
  short *psVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if (((&component_collision_flags)[unaff_A4] & 4) == 0) {
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + 0x20;
    if (0x500 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x500;
    }
  } else {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 1;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    (&DAT_ffffb976)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  return;
}

void FUN_000301f4(void)

{
  entity_state_1_a_t eVar1;
  int unaff_A4;

  eVar1 = (&comp_state_1_a)[unaff_A4];
  (&comp_state_1_a)[unaff_A4] = eVar1 & 0xdf;
  if ((eVar1 & 0x20) != 0) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 64000;
    (&DAT_ffffb976)[unaff_A4] = 1;
  }
  return;
}

void FUN_0003020a(void)

{
  short *psVar1;
  short sVar2;
  int unaff_A4;

  sVar2 = FUN_00030282();
  if (-1 < sVar2) {
    FUN_00030246();
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x300;
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_pos_x + unaff_A4) + 0x16;
    *(short *)((int)&comp_pos_y + unaff_A4) =
        *(short *)((int)&comp_pos_y + unaff_A4) + 8;
    if (((&comp_state_a)[(short)unaff_A4] & ENTITY_STATE_A_08) != 0) {
      *(short *)((int)&comp_pos_x + unaff_A4) =
          *(short *)((int)&comp_pos_x + unaff_A4) + -0x2c;
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = -*psVar1;
    }
    *(undefined2 *)((int)&comp_state + unaff_A4) = 0;
  }
  return;
}

void FUN_00030246(void)

{
  int unaff_A3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  entity_reset(unaff_A4);
  (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A3];
  *(undefined2 *)((int)&comp_unk_7 + unaff_A4) =
      *(undefined2 *)((int)&comp_unk_7 + unaff_A3);
  *(undefined2 *)((int)&comp_pos_x + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A3);
  *(undefined2 *)((int)&comp_pos_y + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A3);
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 6;
  (&comp_state_a)[unaff_A4] = 0x80;
  (&comp_anim_base_offset)[unaff_A4] = 4;
  (&comp_anim_b)[unaff_A4] = 0x28;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0);
  return;
}

undefined4 FUN_00030282(void)

{
  short sVar1;
  int unaff_A4;

  do {
    sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
    if (sVar1 < 0) {
      return 0xffffffff;
    }
    unaff_A4 = (int)sVar1;
  } while (((&comp_has_func_maybe)[unaff_A4] & 0x40) != 0);
  return 0;
}

void FUN_00030298(void)

{
  short *psVar1;
  int unaff_A4;
  short sVar3;
  int iVar2;

  sVar3 = (short)unaff_A4;
  FUN_00030282();
  FUN_00030246();
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x105;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x2d1;
  if (((&comp_state_a)[sVar3] & ENTITY_STATE_A_08) != 0) {
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = -*psVar1;
  }
  iVar2 = (int)sVar3;
  FUN_00030282();
  FUN_00030246();
  *(undefined2 *)((int)&comp_vel[0].y + iVar2) = 0x1eb;
  *(undefined2 *)((int)&comp_vel[0].x + iVar2) = 0x24f;
  if (((&comp_state_a)[sVar3] & ENTITY_STATE_A_08) != 0) {
    psVar1 = (short *)((int)&comp_vel[0].x + iVar2);
    *psVar1 = -*psVar1;
  }
  iVar2 = (int)sVar3;
  FUN_00030282();
  FUN_00030246();
  *(undefined2 *)((int)&comp_vel[0].y + iVar2) = 0x29c;
  *(undefined2 *)((int)&comp_vel[0].x + iVar2) = 0x180;
  if (((&comp_state_a)[sVar3] & ENTITY_STATE_A_08) != 0) {
    psVar1 = (short *)((int)&comp_vel[0].x + iVar2);
    *psVar1 = -*psVar1;
  }
  iVar2 = (int)sVar3;
  FUN_00030282();
  FUN_00030246();
  *(undefined2 *)((int)&comp_vel[0].y + iVar2) = 0x2f0;
  *(undefined2 *)((int)&comp_vel[0].x + iVar2) = 0x82;
  if (((&comp_state_a)[sVar3] & ENTITY_STATE_A_08) != 0) {
    psVar1 = (short *)((int)&comp_vel[0].x + iVar2);
    *psVar1 = -*psVar1;
  }
  return;
}

void FUN_0003031a(void)

{
  short *psVar1;
  int unaff_A4;
  short sVar3;
  int iVar2;

  sVar3 = (short)unaff_A4;
  FUN_00030282();
  FUN_00030246();
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x1bd;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x26e;
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)((int)&comp_pos_y + unaff_A4) + 0x1e;
  *(short *)((int)&comp_pos_x + unaff_A4) =
      *(short *)((int)&comp_pos_x + unaff_A4) + 1;
  if (((&comp_state_a)[sVar3] & ENTITY_STATE_A_08) != 0) {
    *(short *)((int)&comp_pos_x + unaff_A4) =
        *(short *)((int)&comp_pos_x + unaff_A4) + -2;
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = -*psVar1;
  }
  iVar2 = (int)sVar3;
  FUN_00030282();
  FUN_00030246();
  *(undefined2 *)((int)&comp_vel[0].y + iVar2) = 0x2d9;
  *(undefined2 *)((int)&comp_vel[0].x + iVar2) = 0xee;
  *(short *)((int)&comp_pos_y + iVar2) =
      *(short *)((int)&comp_pos_y + iVar2) + 0x1e;
  *(short *)((int)&comp_pos_x + iVar2) =
      *(short *)((int)&comp_pos_x + iVar2) + 1;
  if (((&comp_state_a)[sVar3] & ENTITY_STATE_A_08) != 0) {
    *(short *)((int)&comp_pos_x + iVar2) =
        *(short *)((int)&comp_pos_x + iVar2) + -2;
    psVar1 = (short *)((int)&comp_vel[0].x + iVar2);
    *psVar1 = -*psVar1;
  }
  iVar2 = (int)sVar3;
  FUN_00030282();
  FUN_00030246();
  *(undefined2 *)((int)&comp_vel[0].y + iVar2) = 0x2d9;
  *(undefined2 *)((int)&comp_vel[0].x + iVar2) = 0xff12;
  *(short *)((int)&comp_pos_y + iVar2) =
      *(short *)((int)&comp_pos_y + iVar2) + 0x1e;
  *(short *)((int)&comp_pos_x + iVar2) =
      *(short *)((int)&comp_pos_x + iVar2) + 1;
  if (((&comp_state_a)[sVar3] & ENTITY_STATE_A_08) != 0) {
    *(short *)((int)&comp_pos_x + iVar2) =
        *(short *)((int)&comp_pos_x + iVar2) + -2;
    psVar1 = (short *)((int)&comp_vel[0].x + iVar2);
    *psVar1 = -*psVar1;
  }
  iVar2 = (int)sVar3;
  FUN_00030282();
  FUN_00030246();
  *(undefined2 *)((int)&comp_vel[0].y + iVar2) = 0x1bd;
  *(undefined2 *)((int)&comp_vel[0].x + iVar2) = 0xfd92;
  *(short *)((int)&comp_pos_y + iVar2) =
      *(short *)((int)&comp_pos_y + iVar2) + 0x1e;
  *(short *)((int)&comp_pos_x + iVar2) =
      *(short *)((int)&comp_pos_x + iVar2) + 1;
  if (((&comp_state_a)[sVar3] & ENTITY_STATE_A_08) != 0) {
    *(short *)((int)&comp_pos_x + iVar2) =
        *(short *)((int)&comp_pos_x + iVar2) + -2;
    psVar1 = (short *)((int)&comp_vel[0].x + iVar2);
    *psVar1 = -*psVar1;
  }
  return;
}

void FUN_000303e0(void)

{
  short *psVar1;
  int unaff_A4;
  short sVar3;
  int iVar2;

  sVar3 = (short)unaff_A4;
  FUN_00030282();
  FUN_00030246();
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x314;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x28f;
  if (((&comp_state_a)[sVar3] & ENTITY_STATE_A_08) != 0) {
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = -*psVar1;
  }
  iVar2 = (int)sVar3;
  FUN_00030282();
  FUN_00030246();
  *(undefined2 *)((int)&comp_vel[0].y + iVar2) = 0x3c2;
  *(undefined2 *)((int)&comp_vel[0].x + iVar2) = 0x15c;
  if (((&comp_state_a)[sVar3] & ENTITY_STATE_A_08) != 0) {
    psVar1 = (short *)((int)&comp_vel[0].x + iVar2);
    *psVar1 = -*psVar1;
  }
  iVar2 = (int)sVar3;
  FUN_00030282();
  FUN_00030246();
  *(undefined2 *)((int)&comp_vel[0].y + iVar2) = 0x400;
  *(undefined2 *)((int)&comp_vel[0].x + iVar2) = 0;
  if (((&comp_state_a)[sVar3] & ENTITY_STATE_A_08) != 0) {
    psVar1 = (short *)((int)&comp_vel[0].x + iVar2);
    *psVar1 = -*psVar1;
  }
  iVar2 = (int)sVar3;
  FUN_00030282();
  FUN_00030246();
  *(undefined2 *)((int)&comp_vel[0].y + iVar2) = 0x3c2;
  *(undefined2 *)((int)&comp_vel[0].x + iVar2) = 0xfea4;
  if (((&comp_state_a)[sVar3] & ENTITY_STATE_A_08) != 0) {
    psVar1 = (short *)((int)&comp_vel[0].x + iVar2);
    *psVar1 = -*psVar1;
  }
  iVar2 = (int)sVar3;
  FUN_00030282();
  FUN_00030246();
  *(undefined2 *)((int)&comp_vel[0].y + iVar2) = 0x314;
  *(undefined2 *)((int)&comp_vel[0].x + iVar2) = 0xfd71;
  if (((&comp_state_a)[sVar3] & ENTITY_STATE_A_08) != 0) {
    psVar1 = (short *)((int)&comp_vel[0].x + iVar2);
    *psVar1 = -*psVar1;
  }
  return;
}

void FUN_00030490(void)

{
  short *psVar1;
  ushort uVar2;
  ushort uVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_ATTACKING_MID_AIR) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  if (DAT_ffffe55c != '\0') {
    if ((DAT_ffff915f & 4) == 0) {
      if ((DAT_ffff915f & 8) == 0) {
        *(undefined2 *)((int)&comp_state + unaff_A4) = 1;
        ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
        return;
      }
      (&comp_state_a)[unaff_A4] =
          (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + 0x40;
      if (0x300 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x300;
      }
    } else {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + -0x40;
      if (*(short *)((int)&comp_vel[0].x + unaff_A4) < -0x300) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfd00;
      }
    }
    return;
  }
  uVar2 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  uVar3 = uVar2;
  if ((short)uVar2 < 0) {
    uVar3 = -uVar2;
  }
  if (*(short *)(&DAT_ffffbd78 + unaff_A4) == 0) {
    if (*(ushort *)(&DAT_ffffbd76 + unaff_A4) <= uVar3)
      goto LAB_0003052c;
    if (-1 < (short)uVar2)
      goto LAB_0003055a;
  } else {
    if (uVar3 < *(ushort *)(&DAT_ffffbd76 + unaff_A4)) {
    LAB_0003052c:
      *(undefined2 *)((int)&comp_state + unaff_A4) = 1;
      (&DAT_ffffb976)[unaff_A4] = 0;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
      return;
    }
    if ((short)uVar2 < 0) {
    LAB_0003055a:
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + -0x40;
      if (*(short *)((int)&comp_vel[0].x + unaff_A4) < -0x280) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfd80;
      }
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
      return;
    }
  }
  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  *psVar1 = *psVar1 + 0x40;
  if (0x280 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x280;
  }
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  return;
}

void FUN_000304fc(void)

{
  short *psVar1;
  ushort uVar2;
  ushort uVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  uVar2 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  uVar3 = uVar2;
  if ((short)uVar2 < 0) {
    uVar3 = -uVar2;
  }
  if (*(short *)(&DAT_ffffbd78 + unaff_A4) == 0) {
    if (*(ushort *)(&DAT_ffffbd76 + unaff_A4) <= uVar3)
      goto LAB_0003052c;
    if (-1 < (short)uVar2)
      goto LAB_0003055a;
  } else {
    if (uVar3 < *(ushort *)(&DAT_ffffbd76 + unaff_A4)) {
    LAB_0003052c:
      *(undefined2 *)((int)&comp_state + unaff_A4) = 1;
      (&DAT_ffffb976)[unaff_A4] = 0;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
      return;
    }
    if ((short)uVar2 < 0) {
    LAB_0003055a:
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + -0x40;
      if (*(short *)((int)&comp_vel[0].x + unaff_A4) < -0x280) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfd80;
      }
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
      return;
    }
  }
  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  *psVar1 = *psVar1 + 0x40;
  if (0x280 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x280;
  }
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  return;
}

void FUN_00030576(void)

{
  int unaff_A4;

  (*(code *)((int)&JMP_0003058a +
             (int)*(
                 short *)((int)&JMP_0003058a +
                          (int)(short)((ushort)(byte)(&DAT_ffffb976)[unaff_A4] *
                                       2))))();
  return;
}

void FUN_00030590(void)

{
  char cVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  cVar1 = (&DAT_ffffb978)[unaff_A4] + -1;
  (&DAT_ffffb978)[unaff_A4] = cVar1;
  if (cVar1 == '\0') {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x16);
    (&DAT_ffffb976)[unaff_A4] = 1;
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & 0xfb;
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] & 0xf7;
    audio_play(SOUND_ID_UTSUSEMI);
  }
  return;
}

void FUN_000305b8(void)

{
  int unaff_A4;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    (&DAT_ffffb976)[unaff_A4] = 2;
    *(undefined1 *)(unaff_A4 + -0x4689) = 0x10;
  }
  return;
}

void FUN_000305cc(void)

{
  ushort uVar1;
  char cVar2;
  ushort extraout_D0u;
  word wVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  cVar2 = *(char *)(unaff_A4 - 0x4689) + -1;
  *(char *)(unaff_A4 - 0x4689) = cVar2;
  if (cVar2 == '\0') {
    do {
      do {
        wVar3 = rand();
        uVar1 = wVar3 & 0x7f;
      } while (uVar1 < 0x30);
      if ((extraout_D0u & 0x10) != 0) {
        if ((ushort)(uVar1 + comp_pos_x.fixed.i) <
            (ushort)(DAT_ffffce08 - 0x30U)) {
          *(ushort *)((int)&comp_pos_x + unaff_A4) = uVar1 + comp_pos_x.fixed.i;
        } else {
          do {
          } while ((ushort)(comp_pos_x.fixed.i - uVar1) <
                   (ushort)(DAT_ffffce04 + 0x30U));
          *(ushort *)((int)&comp_pos_x + unaff_A4) =
              *(short *)((int)&comp_collision_sensor[0].x + unaff_A4) +
              (comp_pos_x.fixed.i - uVar1);
        }
        goto LAB_0003064c;
      }
      if ((ushort)(DAT_ffffce04 + 0x30U) <=
          (ushort)(comp_pos_x.fixed.i - uVar1)) {
        *(ushort *)((int)&comp_pos_x + unaff_A4) =
            *(short *)((int)&comp_collision_sensor[0].x + unaff_A4) +
            (comp_pos_x.fixed.i - uVar1);
        goto LAB_0003064c;
      }
    } while ((ushort)(DAT_ffffce08 - 0x30U) <=
             (ushort)(uVar1 + comp_pos_x.fixed.i));
    *(ushort *)((int)&comp_pos_x + unaff_A4) =
        (uVar1 + comp_pos_x.fixed.i) -
        *(short *)((int)&comp_collision_sensor[0].x + unaff_A4);
  LAB_0003064c:
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) = 0x1020;
    *(undefined2 *)((int)&comp_pos_y + unaff_A4 + 2) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x18);
    *(undefined2 *)((int)&comp_state + unaff_A4) = 9;
    (&DAT_ffffb976)[unaff_A4] = 0;
  }
  return;
}

void FUN_0003066e(void)

{
  int unaff_A4;

  (*(code *)((int)&WORD_00030682 +
             (int)*(
                 short *)((int)&WORD_00030682 +
                          (int)(short)((ushort)(byte)(&DAT_ffffb976)[unaff_A4] *
                                       2))))();
  return;
}

void FUN_0003068a(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_00030c0e();
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    (&DAT_ffffb976)[unaff_A4] = 1;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  return;
}

void FUN_000306d2(void)

{
  char cVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  cVar1 = *(char *)(unaff_A4 - 0x4689) + -1;
  *(char *)(unaff_A4 - 0x4689) = cVar1;
  if (cVar1 == '\0') {
    (&DAT_ffffb976)[unaff_A4] = 3;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
  }
  return;
}

void FUN_000306e6(void)

{
  short *psVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if (((&component_collision_flags)[unaff_A4] & 4) == 0) {
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + 0x20;
    if (0x500 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x500;
    }
  } else {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 1;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    (&DAT_ffffb976)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  return;
}

void FUN_0003071a(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  *(undefined2 *)((int)&comp_state + unaff_A4) = 1;
  return;
}

void FUN_00030728(void)

{
  int unaff_A4;

  (*(code *)((int)&WORD_0003073c +
             (int)*(
                 short *)((int)&WORD_0003073c +
                          (int)(short)((ushort)(byte)(&DAT_ffffb976)[unaff_A4] *
                                       2))))();
  return;
}

void FUN_00030748(void)

{
  short sVar1;
  int unaff_A4;

  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  sVar1 = FUN_00030e48();
  if (-1 < sVar1) {
    (&DAT_ffffb976)[unaff_A4] = 1;
    return;
  }
  *(undefined2 *)((int)&comp_state + unaff_A4) = 1;
  return;
}

void FUN_00030768(void)

{
  return;
}

void FUN_0003076a(void)

{
  word wVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  wVar1 = rand();
  if ((wVar1 & 0xf) == 8) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0x14);
    (&DAT_ffffb976)[unaff_A4] = 3;
  }
  return;
}

void FUN_00030786(void)

{
  int unaff_A4;

  if (((&comp_state_1_a)[unaff_A4] & 0x20) != 0) {
    FUN_0003031a();
    *(undefined1 *)(unaff_A4 + -0x4689) = 0x1e;
    (&DAT_ffffb976)[unaff_A4] = 4;
  }
  return;
}

void FUN_000307a0(void)

{
  char cVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  cVar1 = *(char *)(unaff_A4 - 0x4689) + -1;
  *(char *)(unaff_A4 - 0x4689) = cVar1;
  if (cVar1 == '\0') {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 10);
    (&DAT_ffffb976)[unaff_A4] = 2;
  }
  return;
}

void FUN_000307b4(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
  *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
  (&DAT_ffffb976)[unaff_A4] = 3;
  return;
}

void FUN_000307c8(void)

{
  component_state_b_t cVar1;
  ulong unaff_A4;
  undefined1 in_ZF;
  bool bVar2;
  undefined1 in_CF;

  player_update_pos(unaff_A4);
  FUN_00030802();
  if (!(bool)in_CF) {
    cVar1 = (&comp_has_func_maybe)[unaff_A4];
    in_ZF = (cVar1 & 0x40) == 0;
    (&comp_has_func_maybe)[unaff_A4] = cVar1 & 0xbf;
  }
  FUN_000251a6();
  if (!(bool)in_ZF) {
    if ((uint8_t_ffffcc70 & 2) != 0) {
      bVar2 = script_state_get((script_state_bit_t)0x3ea);
      if (!bVar2) {
        uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x20;
      }
    }
    (&comp_has_func_maybe)[unaff_A4] = (&comp_has_func_maybe)[unaff_A4] & 0xbf;
  }
  return;
}

void FUN_00030802(void)

{
  return;
}

void FUN_0003083a(entity_id_t self)

{
  if (*(short *)((int)&comp_state + self) != 8) {
    entity_update_pos(self);
    (*(code *)((int)&WORD_0003085e +
               (int)*(
                   short *)((int)&WORD_0003085e +
                            (int)(short)(*(short *)((int)&comp_state + self) *
                                         2))))();
    FUN_000308ac();
  }
  return;
}

void FUN_00030872(void)

{
  return;
}

void FUN_00030874(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&comp_pos_x + unaff_A4) < (ushort)comp_pos_x._0_2_) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  } else {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  }
  return;
}

void FUN_0003088e(void)

{
  int unaff_A4;

  if (*(ushort *)((int)&comp_pos_x + unaff_A4) <
      *(ushort *)((int)&comp_pos_x + (int)DAT_ffffe552)) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  } else {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  }
  return;
}

void FUN_000308ac(void)

{
  int iVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  undefined1 uVar2;
  undefined1 uVar3;

  uVar3 = *(ushort *)((int)&comp_state + unaff_A4) < 7;
  uVar2 = *(ushort *)((int)&comp_state + unaff_A4) == 7;
  if (!(bool)uVar2) {
    FUN_000189d0();
  }
  FUN_00000ed6(unaff_A4, ENTITY_ID_ASHA);
  if ((bool)uVar3 || (bool)uVar2) {
    if ((ushort)comp_pos_x._0_2_ < *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x81;
    } else {
      uint8_t_ffffcc70 = uint8_t_ffffcc70 | 1;
    }
  }
  if ((*(short *)((int)&comp_state + unaff_A4) != 7) &&
      (((&comp_func_offset[0].unk4)[unaff_A4] & 1) != 0)) {
    iVar1 = (int)DAT_ffffe552;
    if (*(short *)((int)&comp_state + iVar1) == 8) {
      *(undefined2 *)((int)&comp_state + iVar1) = 1;
      (&DAT_ffffb976)[iVar1] = 0;
    }
    *(undefined2 *)((int)&comp_state + unaff_A4) = 7;
    (&DAT_ffffb976)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | 4;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    (&DAT_ffffab42)[unaff_A4] = 0x21;
    (&DAT_ffffab43)[unaff_A4] = 0;
  }
  return;
}

void FUN_0003092e(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&DAT_ffffb976)[unaff_A4] = 0;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 1;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  return;
}

void FUN_00030940(void)

{
  int unaff_A4;

  FUN_00030874();
  (*(code *)((int)&WORD_00030958 +
             (int)*(
                 short *)((int)&WORD_00030958 +
                          (int)(short)((ushort)(byte)(&DAT_ffffb976)[unaff_A4] *
                                       2))))();
  return;
}

void FUN_00030960(void)

{
  int unaff_A4;

  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x200;
  (&DAT_ffffb976)[unaff_A4] = 1;
  return;
}

void FUN_0003096e(void)

{
  short *psVar1;
  short sVar2;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar2 = *psVar1 + -0x10;
  *psVar1 = sVar2;
  if ((sVar2 == 0) || (sVar2 < 0)) {
    (&DAT_ffffb976)[unaff_A4] = 2;
  }
  return;
}

void FUN_00030980(void)

{
  int unaff_A4;

  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfe00;
  (&DAT_ffffb976)[unaff_A4] = 3;
  return;
}

void FUN_0003098e(void)

{
  short *psVar1;
  short sVar2;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  sVar2 = *psVar1 + 0x10;
  *psVar1 = sVar2;
  if (-1 < sVar2) {
    (&DAT_ffffb976)[unaff_A4] = 0;
  }
  return;
}

void FUN_0003099e(void)

{
  int unaff_A4;

  (*(code *)((int)&WORD_000309b2 +
             (int)*(
                 short *)((int)&WORD_000309b2 +
                          (int)(short)((ushort)(byte)(&DAT_ffffb976)[unaff_A4] *
                                       2))))();
  return;
}

void FUN_000309b8(void)

{
  short *psVar1;
  int unaff_A4;

  FUN_00030874();
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + -0x40;
  if (*(short *)((int)&comp_vel[0].y + unaff_A4) < -0x600) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 64000;
  }
  if (*(ushort *)((int)&comp_pos_y + unaff_A4) < 0x1021) {
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) = 0x1020;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    (&DAT_ffffb976)[unaff_A4] = 1;
  }
  return;
}

void FUN_000309ee(void)

{
  ushort uVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  FUN_00030874();
  uVar1 = comp_pos_x.fixed.i - *(short *)((int)&comp_pos_x + unaff_A4);
  if ((short)uVar1 < 0) {
    uVar1 = -uVar1;
  }
  if (uVar1 < 5) {
    (&DAT_ffffb976)[unaff_A4] = 2;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 0xc);
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  } else {
    FUN_00030a20();
  }
  return;
}

void FUN_00030a20(void)

{
  short *psVar1;
  int unaff_A4;

  if ((ushort)comp_pos_x._0_2_ < *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = *psVar1 + -0x40;
    if (*(short *)((int)&comp_vel[0].x + unaff_A4) < -0x300) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfd00;
    }
  } else {
    psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
    *psVar1 = *psVar1 + 0x40;
    if (0x300 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x300;
    }
  }
  return;
}

void FUN_00030a56(void)

{
  short *psVar1;
  ushort uVar2;
  byte bVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;
  bool bVar4;
  bool bVar5;

  FUN_0003088e();
  player_update_pos(unaff_A4);
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x40;
  uVar2 = *(ushort *)((int)&comp_vel[0].y + unaff_A4);
  if (0x300 < (short)uVar2) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x300;
  }
  bVar4 = uVar2 == 0x300;
  bVar5 = uVar2 < 0x300;
  FUN_00000ed6(unaff_A4, ENTITY_ID_ASHA);
  bVar3 = uint8_t_ffffcc70;
  if ((bVar5 || bVar4) &&
      (bVar3 = uint8_t_ffffcc70 | 2,
       (ushort)comp_pos_x.fixed.i < *(ushort *)((int)&comp_pos_x + unaff_A4))) {
    uint8_t_ffffcc70 = uint8_t_ffffcc70 | 0x82;
    bVar3 = uint8_t_ffffcc70;
  }
  uint8_t_ffffcc70 = bVar3;
  if (DAT_ffffce0a <=
      (ushort)(*(short *)((int)&comp_collision_sensor[0].y + unaff_A4) +
               *(short *)((int)&comp_pos_y + unaff_A4))) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    (&DAT_ffffb976)[unaff_A4] = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
  }
  return;
}

void FUN_00030abc(void)

{
  return;
}

void FUN_00030abe(void)

{
  short sVar1;
  short sVar2;
  uint extraout_D1;
  uint extraout_D1_00;
  uint uVar3;
  int iVar4;
  int unaff_A4;

  iVar4 = (int)DAT_ffffe552;
  uVar3 = *(int *)((int)&comp_pos_y + iVar4) - 0x300000;
  if (*(uint *)((int)&comp_pos_x + iVar4) !=
      *(uint *)((int)&comp_pos_x + unaff_A4)) {
    if (*(uint *)((int)&comp_pos_x + iVar4) <
        *(uint *)((int)&comp_pos_x + unaff_A4)) {
      FUN_00030b6c();
      uVar3 = extraout_D1_00;
    } else {
      FUN_00030b32();
      uVar3 = extraout_D1;
    }
  }
  if (uVar3 != *(uint *)((int)&comp_pos_y + unaff_A4)) {
    if (uVar3 < *(uint *)((int)&comp_pos_y + unaff_A4)) {
      FUN_00030bda();
    } else {
      FUN_00030ba6();
    }
  }
  sVar1 = *(short *)((int)&comp_pos_x + iVar4);
  sVar2 = *(short *)((int)&comp_pos_y + iVar4) + -0x30;
  if (sVar2 == *(short *)((int)&comp_pos_y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  if (sVar1 == *(short *)((int)&comp_pos_x + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  }
  if ((sVar1 == *(short *)((int)&comp_pos_x + unaff_A4)) &&
      (sVar2 == *(short *)((int)&comp_pos_y + unaff_A4))) {
    *(undefined2 *)((int)&comp_state + unaff_A4) = 1;
    (&DAT_ffffb976)[unaff_A4] = 0;
    DAT_ffffe55a = DAT_ffffe55a & 0xdf;
  }
  return;
}

void FUN_00030b32(void)

{
  short *psVar1;
  uint in_D0;
  int unaff_A4;

  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  *psVar1 = *psVar1 + 0x20;
  if (0x400 < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x400;
  }
  if (in_D0 < (uint)(*(short *)((int)&comp_vel[0].x + unaff_A4) * 0x100 +
                     *(int *)((int)&comp_pos_x + unaff_A4))) {
    *(short *)((int)&comp_vel[0].x + unaff_A4) =
        (short)(in_D0 - *(int *)((int)&comp_pos_x + unaff_A4) >> 8);
  }
  return;
}

void FUN_00030b6c(void)

{
  short *psVar1;
  uint in_D0;
  int unaff_A4;

  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  *psVar1 = *psVar1 + -0x20;
  if (*(short *)((int)&comp_vel[0].x + unaff_A4) < -0x400) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfc00;
  }
  if ((uint)(*(short *)((int)&comp_vel[0].x + unaff_A4) * 0x100 +
             *(int *)((int)&comp_pos_x + unaff_A4)) < in_D0) {
    *(short *)((int)&comp_vel[0].x + unaff_A4) =
        (short)(in_D0 - *(int *)((int)&comp_pos_x + unaff_A4) >> 8);
  }
  return;
}

void FUN_00030ba6(void)

{
  short *psVar1;
  uint in_D1;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x20;
  if (0x400 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x400;
  }
  if (in_D1 < (uint)(*(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
                     *(int *)((int)&comp_pos_y + unaff_A4))) {
    *(short *)((int)&comp_vel[0].y + unaff_A4) =
        (short)(in_D1 - *(int *)((int)&comp_pos_y + unaff_A4) >> 8);
  }
  return;
}

void FUN_00030bda(void)

{
  short *psVar1;
  uint in_D1;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + -0x20;
  if (*(short *)((int)&comp_vel[0].y + unaff_A4) < -0x400) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0xfc00;
  }
  if ((uint)(*(short *)((int)&comp_vel[0].y + unaff_A4) * 0x100 +
             *(int *)((int)&comp_pos_y + unaff_A4)) < in_D1) {
    *(short *)((int)&comp_vel[0].y + unaff_A4) =
        (short)(in_D1 - *(int *)((int)&comp_pos_y + unaff_A4) >> 8);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00030c0e(void)

{
  int iVar1;
  int unaff_A4;

  if ((*(short *)((int)&comp_state + unaff_A4) != 7) &&
      ((DAT_ffffe55a & 0x20) == 0)) {
    DAT_ffffe55a = DAT_ffffe55a | 0x20;
    iVar1 = (int)_DAT_ffffe554;
    (&DAT_ffffb976)[iVar1] = 0;
    *(undefined2 *)((int)&comp_state + iVar1) = 2;
    (&comp_state_a)[iVar1] = (&comp_state_a)[iVar1] & 0xfb;
    (&comp_has_func_maybe)[iVar1] = (&comp_has_func_maybe)[iVar1] & 0xf7;
  }
  return;
}

void FUN_00030c40(void)

{
  int unaff_A4;

  (*(code *)((int)&WORD_00030c54 +
             (int)*(
                 short *)((int)&WORD_00030c54 +
                          (int)(short)((ushort)(byte)(&DAT_ffffb976)[unaff_A4] *
                                       2))))();
  return;
}

void FUN_00030c5e(void)

{
  short sVar1;
  short sVar2;
  ushort uVar3;
  uint extraout_D1;
  uint extraout_D1_00;
  uint uVar4;
  int iVar5;
  int unaff_A4;

  iVar5 = (int)DAT_ffffe552;
  uVar4 = *(int *)((int)&comp_pos_y + iVar5) - 0x1e0000;
  if (*(uint *)((int)&comp_pos_x + iVar5) !=
      *(uint *)((int)&comp_pos_x + unaff_A4)) {
    if (*(uint *)((int)&comp_pos_x + iVar5) <
        *(uint *)((int)&comp_pos_x + unaff_A4)) {
      FUN_00030b6c();
      uVar4 = extraout_D1_00;
    } else {
      FUN_00030b32();
      uVar4 = extraout_D1;
    }
  }
  if (uVar4 != *(uint *)((int)&comp_pos_y + unaff_A4)) {
    if (uVar4 < *(uint *)((int)&comp_pos_y + unaff_A4)) {
      FUN_00030bda();
    } else {
      FUN_00030ba6();
    }
  }
  sVar1 = *(short *)((int)&comp_pos_x + iVar5);
  sVar2 = *(short *)((int)&comp_pos_y + iVar5) + -0x1e;
  if (sVar2 == *(short *)((int)&comp_pos_y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  if (sVar1 == *(short *)((int)&comp_pos_x + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  }
  uVar3 = sVar1 - *(short *)((int)&comp_pos_x + unaff_A4);
  if ((int)((uint)uVar3 << 0x10) < 0) {
    uVar3 = -uVar3;
  }
  if (((uVar3 < 3) && (uVar3 = sVar2 - *(short *)((int)&comp_pos_y + unaff_A4),
                       -1 < (int)((uint)uVar3 << 0x10))) &&
      (uVar3 < 3)) {
    (&DAT_ffffb976)[unaff_A4] = 1;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  return;
}

void FUN_00030cde(void)

{
  entity_id_t self;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  self = (entity_id_t)DAT_ffffe552;
  if ((*(short *)((int)&comp_state + self) == 8) &&
      ((&DAT_ffffb976)[self] == '\x01')) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 10);
    (&DAT_ffffb976)[unaff_A4] = 2;
    ecs_anim_unk_2(self, unaff_A5, 10);
    return;
  }
  ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  (&DAT_ffffb976)[unaff_A4] = 0;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
  return;
}

void FUN_00030d0e(void)

{
  short *psVar1;
  int iVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  iVar2 = (int)DAT_ffffe552;
  if ((*(short *)((int)&comp_state + iVar2) == 8) &&
      ((&DAT_ffffb976)[iVar2] == '\x01')) {
    psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
    *psVar1 = *psVar1 + -0x40;
    if (*(ushort *)((int)&comp_pos_y + unaff_A4) < 0x1021) {
      *(undefined2 *)((int)&comp_pos_y + unaff_A4) = 0x1020;
      *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      (&DAT_ffffb976)[unaff_A4] = 3;
      (&DAT_ffffb978)[unaff_A4] = 2;
      *(undefined2 *)(&DAT_ffffbd76 + unaff_A4) =
          *(undefined2 *)((int)&comp_pos_x + iVar2);
      (&DAT_ffffb976)[iVar2] = 2;
    }
    *(undefined2 *)((int)&comp_pos_x + iVar2) =
        *(undefined2 *)((int)&comp_pos_x + unaff_A4);
    *(undefined2 *)((int)&comp_pos_y + iVar2) =
        *(undefined2 *)((int)&comp_pos_y + unaff_A4);
    *(short *)((int)&comp_pos_y + iVar2) =
        *(short *)((int)&comp_pos_y + iVar2) + 0x1e;
    DAT_ffffe56e = 0;
    return;
  }
  ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  (&DAT_ffffb976)[unaff_A4] = 0;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
  return;
}

void FUN_00030d72(void)

{
  int iVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  iVar1 = (int)DAT_ffffe552;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x200;
  if (*(short *)((int)&comp_state + iVar1) == 8) {
    if ((ushort)(DAT_ffffce08 - 0x10U) <=
        *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      *(ushort *)((int)&comp_pos_x + unaff_A4) = DAT_ffffce08 - 0x10U;
      *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
      (&DAT_ffffb976)[unaff_A4] = 4;
    }
    *(undefined2 *)((int)&comp_pos_x + iVar1) =
        *(undefined2 *)((int)&comp_pos_x + unaff_A4);
    *(undefined2 *)((int)&comp_pos_y + iVar1) =
        *(undefined2 *)((int)&comp_pos_y + unaff_A4);
    *(short *)((int)&comp_pos_y + iVar1) =
        *(short *)((int)&comp_pos_y + iVar1) + 0x1e;
    return;
  }
  ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  (&DAT_ffffb976)[unaff_A4] = 0;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
  return;
}

void FUN_00030db6(void)

{
  char cVar1;
  int iVar2;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  iVar2 = (int)DAT_ffffe552;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfe00;
  if (*(short *)((int)&comp_state + iVar2) != 8) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    (&DAT_ffffb976)[unaff_A4] = 0;
    *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
    return;
  }
  if ((ushort)(DAT_ffffce04 + 0x10U) <
      *(ushort *)((int)&comp_pos_x + unaff_A4)) {
  LAB_00030df2:
    if (((*(ushort *)(&DAT_ffffbd76 + unaff_A4) <=
          *(ushort *)((int)&comp_pos_x + unaff_A4)) ||
         (*(ushort *)((int)component_pos_old_x + unaff_A4) <
          *(ushort *)(&DAT_ffffbd76 + unaff_A4))) ||
        (cVar1 = (&DAT_ffffb978)[unaff_A4] + -1,
         (&DAT_ffffb978)[unaff_A4] = cVar1,
         cVar1 != '\0'))
      goto LAB_00030e18;
  } else {
    *(ushort *)((int)&comp_pos_x + unaff_A4) = DAT_ffffce04 + 0x10U;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    (&DAT_ffffb976)[unaff_A4] = 3;
    DAT_ffffe56e = DAT_ffffe56e + 1;
    if (DAT_ffffe56e < 3)
      goto LAB_00030df2;
  }
  (&DAT_ffffb976)[iVar2] = 5;
  FUN_00030e2c();
LAB_00030e18:
  *(undefined2 *)((int)&comp_pos_x + iVar2) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  *(undefined2 *)((int)&comp_pos_y + iVar2) =
      *(undefined2 *)((int)&comp_pos_y + unaff_A4);
  *(short *)((int)&comp_pos_y + iVar2) =
      *(short *)((int)&comp_pos_y + iVar2) + 0x1e;
  return;
}

void FUN_00030e2c(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  (&DAT_ffffb976)[unaff_A4] = 0;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined4 FUN_00030e48(void)

{
  undefined4 uVar1;
  int iVar2;
  int unaff_A4;

  uVar1 = 0xffffffff;
  if (*(short *)((int)&comp_state + unaff_A4) != 7) {
    iVar2 = (int)_DAT_ffffe554;
    *(undefined2 *)((int)&comp_state + iVar2) = 6;
    (&DAT_ffffb976)[iVar2] = 0;
    uVar1 = 0;
    (&comp_state_a)[iVar2] = (&comp_state_a)[iVar2] & 0xfb;
    (&comp_has_func_maybe)[iVar2] = (&comp_has_func_maybe)[iVar2] & 0xf7;
  }
  return uVar1;
}

void FUN_00030e70(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & 0xfb;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    (&DAT_ffffab42)[unaff_A4] = 0;
    (&DAT_ffffab43)[unaff_A4] = 0;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
    *(undefined2 *)((int)&comp_state + unaff_A4) = 4;
    (&DAT_ffffb976)[unaff_A4] = 0;
  }
  return;
}

void FUN_00030ea2(void)

{
  short sVar1;
  uint extraout_D1;
  uint extraout_D1_00;
  uint uVar2;
  int iVar3;
  int unaff_A4;

  iVar3 = (int)DAT_ffffe552;
  uVar2 = *(int *)((int)&comp_pos_y + iVar3) - 0x300000;
  if (*(uint *)((int)&comp_pos_x + iVar3) !=
      *(uint *)((int)&comp_pos_x + unaff_A4)) {
    if (*(uint *)((int)&comp_pos_x + iVar3) <
        *(uint *)((int)&comp_pos_x + unaff_A4)) {
      FUN_00030b6c();
      uVar2 = extraout_D1_00;
    } else {
      FUN_00030b32();
      uVar2 = extraout_D1;
    }
  }
  if (uVar2 != *(uint *)((int)&comp_pos_y + unaff_A4)) {
    if (uVar2 < *(uint *)((int)&comp_pos_y + unaff_A4)) {
      FUN_00030bda();
    } else {
      FUN_00030ba6();
    }
  }
  sVar1 = *(short *)((int)&comp_pos_x + iVar3);
  if ((short)(*(short *)((int)&comp_pos_y + iVar3) + -0x30) ==
      *(short *)((int)&comp_pos_y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  if (sVar1 == *(short *)((int)&comp_pos_x + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  }
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  return;
}

void FUN_00030f00(void)

{
  int unaff_A4;

  (*(code *)((int)&WORD_00030f14 +
             (int)*(
                 short *)((int)&WORD_00030f14 +
                          (int)(short)((ushort)(byte)(&DAT_ffffb976)[unaff_A4] *
                                       2))))();
  return;
}

void FUN_00030f2a(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  drop_pepelogoo();
  comp_pos_x.fixed.i = 0x1020;
  comp_pos_y.fixed.i = 0x10a0;
  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  comp_anim_b = 0;
  comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  component_pos_x_pepelogoo.fixed.i = 0x1010;
  component_pos_y_pepelogoo.fixed.i = 0x1090;
  component_unknown_3_pepelogoo = 10;
  comp_vel[1].x.raw = 0;
  comp_vel[1].y.raw = 0;
  DAT_ffff9f1f = DAT_ffff9f1f & 0x77;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 4);
  (&DAT_ffffb976)[(short)unaff_A4] = 1;
  DAT_ffffd16c = 6;
  DAT_ffffd176 = 0x1000;
  WORD_ffffd178 = 0xfe8;
  return;
}

void FUN_00030fae(void)

{
  short unaff_A4w;
  anim_item_t *unaff_A5;

  if (comp_anim_c != ECS_STATE_1_B_WALKING_OR_DOWNSTAB) {
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 2);
  }
  comp_vel[0].x.raw = 0x200;
  player_update_pos(0);
  DAT_ffffd176 = DAT_ffffd176 + 2;
  if (0x106f < DAT_ffffd176) {
    DAT_ffffd176 = 0x1070;
  }
  if (DAT_ffffa63c != '\n') {
    ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 10);
  }
  comp_vel[1].x.raw = 0x200;
  player_update_pos(4);
  if (component_pos_x_pepelogoo.fixed.i == 0x10a0) {
    comp_vel[1].x.raw = 0;
    comp_vel[0].x.raw = 0;
    comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x3e);
    (&DAT_ffffb976)[unaff_A4w] = 2;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00031026(void)

{
  short unaff_A4w;

  DAT_ffffd916 = 0xb1;
  FUN_0001937a();
  (&DAT_ffffb976)[unaff_A4w] = 3;
  *(undefined2 *)((int)&comp_state + (int)_DAT_ffffe554) = 8;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00031048(void)

{
  uint uVar1;
  uint extraout_D1;
  uint extraout_D1_00;
  entity_id_t self;
  int unaff_A4;
  anim_item_t *unaff_A5;

  self = (entity_id_t)_DAT_ffffe554;
  player_update_pos(self);
  uVar1 = 0x10700000;
  if (*(uint *)((int)&comp_pos_x + self) != 0x11300000) {
    if (*(uint *)((int)&comp_pos_x + self) < 0x11300001) {
      FUN_00030b32();
      uVar1 = extraout_D1;
    } else {
      FUN_00030b6c();
      uVar1 = extraout_D1_00;
    }
  }
  if (uVar1 != *(uint *)((int)&comp_pos_y + self)) {
    if (uVar1 < *(uint *)((int)&comp_pos_y + self)) {
      FUN_00030bda();
    } else {
      FUN_00030ba6();
    }
  }
  if (*(short *)((int)&comp_pos_y + self) == 0x1070) {
    *(undefined2 *)((int)&comp_vel[0].y + self) = 0;
  }
  if (*(short *)((int)&comp_pos_x + self) == 0x1130) {
    *(undefined2 *)((int)&comp_vel[0].x + self) = 0;
  }
  if ((*(short *)((int)&comp_pos_x + self) == 0x1130) &&
      (*(short *)((int)&comp_pos_y + self) == 0x1070)) {
    ecs_anim_unk_2(self, unaff_A5, 0xe);
    (&DAT_ffffb976)[unaff_A4] = 4;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000310ba(void)

{
  entity_state_1_a_t eVar1;
  short unaff_D2w;
  func *in_A1;
  entity_id_t e;
  short unaff_A4w;
  int iVar2;
  anim_item_t *unaff_A5;

  iVar2 = (int)_DAT_ffffe554;
  eVar1 = (&comp_state_1_a)[iVar2];
  (&comp_state_1_a)[iVar2] = eVar1 & 0xdf;
  if ((eVar1 & 0x20) != 0) {
    FUN_0000147a(in_A1, 0, 0);
    e = (entity_id_t)unaff_D2w;
    _DAT_ffffe558 = unaff_D2w;
    entity_reset(e);
    *(undefined2 *)((int)&comp_pos_x + e) =
        *(undefined2 *)((int)&comp_pos_x + iVar2);
    *(undefined2 *)((int)&comp_pos_y + e) =
        *(undefined2 *)((int)&comp_pos_y + iVar2);
    (&comp_has_func_maybe)[e] = (&comp_has_func_maybe)[iVar2];
    *(undefined2 *)((int)&comp_unk_7 + e) =
        *(undefined2 *)((int)&comp_unk_7 + iVar2);
    *(undefined2 *)((int)&comp_pos_x + e) =
        *(undefined2 *)((int)&comp_pos_x + iVar2);
    *(undefined2 *)((int)&comp_pos_y + e) =
        *(undefined2 *)((int)&comp_pos_y + iVar2);
    *(short *)((int)&comp_pos_x + e) = *(short *)((int)&comp_pos_x + e) + -0xb;
    *(short *)((int)&comp_pos_y + e) = *(short *)((int)&comp_pos_y + e) + 2;
    *(undefined2 *)(&DAT_ffffbd76 + e) = *(undefined2 *)((int)&comp_pos_x + e);
    *(short *)(&DAT_ffffbd76 + e) = *(short *)(&DAT_ffffbd76 + e) + -0x10;
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x18;
    (&comp_state_a)[e] = 0x80;
    (&comp_state_a)[e] = (&comp_state_a)[e] | ENTITY_STATE_A_08;
    (&comp_anim_base_offset)[e] = (&comp_anim_base_offset)[iVar2];
    (&comp_anim_b)[e] = (&comp_anim_b)[iVar2];
    (&DAT_ffffb976)[e] = 0;
    ecs_anim_unk_2(e, unaff_A5, 0x10);
    (&DAT_ffffb976)[unaff_A4w] = 5;
    uRamffffb97a = 0;
  }
  return;
}

void FUN_00031156(void)

{
  FUN_00031164();
  FUN_00031244();
  return;
}

void FUN_00031164(void)

{
  (*(code *)((int)&WORD_0003117c +
             (int)*(short *)((int)&WORD_0003117c +
                             (int)(short)((ushort)bRamffffb97a * 2))))();
  return;
}

void FUN_00031184(void)

{
  int unaff_A4;

  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x300;
  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x40;
  *(undefined2 *)(&DAT_ffffbd76 + unaff_A4) =
      *(undefined2 *)((int)&comp_pos_x + unaff_A4);
  (&DAT_ffffb976)[unaff_A4] = 1;
  return;
}

void FUN_000311a4(void)

{
  ulong unaff_A4;

  player_update_pos(unaff_A4);
  if ((ushort)(*(short *)(&DAT_ffffbd76 + unaff_A4) + 0x40U) <=
      *(ushort *)((int)&comp_pos_x + unaff_A4)) {
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
    *(ushort *)((int)&comp_pos_x + unaff_A4) =
        *(short *)(&DAT_ffffbd76 + unaff_A4) + 0x40U;
    *(int16_t *)(&DAT_ffffbd76 + unaff_A4) =
        comp_collision_sensor[0].x + comp_pos_x.fixed.i;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfd00;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    (&DAT_ffffb976)[unaff_A4] = 2;
  }
  return;
}

void FUN_000311de(void)

{
  ushort uVar1;
  ulong unaff_A4;
  anim_item_t *unaff_A5;

  player_update_pos(unaff_A4);
  uVar1 = *(ushort *)(&DAT_ffffbd76 + unaff_A4);
  if (*(ushort *)((int)&comp_pos_x + unaff_A4) <= uVar1) {
    (&DAT_ffffb976)[unaff_A4] = 3;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    *(ushort *)((int)&comp_pos_x + unaff_A4) = uVar1;
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
    DAT_ffffb976 = 0;
    comp_anim_b = 8;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 2);
    comp_vel[0].x.raw = -0x380;
  }
  return;
}

void FUN_00031220(void)

{
  anim_item_t *unaff_A5;

  player_update_pos(0);
  comp_vel[0].x.raw = comp_vel[0].x.raw + 0x20;
  if ((-1 < comp_vel[0].x.raw) && (comp_vel[0].x.raw = 0, comp_anim_c != 0)) {
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00031244(void)

{
  (*(code *)((int)&WORD_0003125c +
             (int)*(short *)((int)&WORD_0003125c +
                             (int)(short)((ushort)(byte)(&DAT_ffffb976)
                                              [_DAT_ffffe558] *
                                          2))))();
  return;
}

void FUN_00031262(void)

{
  ulong unaff_A4;

  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xff00;
  player_update_pos(unaff_A4);
  if (*(ushort *)((int)&comp_pos_x + unaff_A4) <=
      *(ushort *)(&DAT_ffffbd76 + unaff_A4)) {
    *(ushort *)((int)&comp_pos_x + unaff_A4) =
        *(ushort *)(&DAT_ffffbd76 + unaff_A4);
    (&DAT_ffffb976)[unaff_A4] = 1;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  }
  return;
}

void FUN_00031286(void)

{
  ulong unaff_A4;

  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x100;
  player_update_pos(unaff_A4);
  if (*(short *)((int)&comp_pos_y + unaff_A4) == 0x1090) {
    (&DAT_ffffb976)[unaff_A4] = 2;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  return;
}

void FUN_000312a4(void)

{
  short *psVar1;
  ulong unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
  *psVar1 = *psVar1 + -0x20;
  if (*(short *)((int)&comp_vel[0].x + unaff_A4) < -0x400) {
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfc00;
  }
  player_update_pos(unaff_A4);
  if (*(ushort *)((int)&comp_pos_x + unaff_A4) < 0x10d9) {
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) = 0x10d8;
    (&DAT_ffffb976)[DAT_ffffe552] = 6;
    audio_play(SOUND_ID_SLASH);
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000312dc(void)

{
  int unaff_A4;
  anim_item_t *unaff_A5;

  (&DAT_ffffb976)[unaff_A4] = 7;
  uRamffffb97a = 0;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 0x24);
  _DAT_ffffe562 = 0;
  _DAT_ffffe564 = 0;
  _DAT_ffffe55e = &UNK_00031312;
  ecs_anim_unk_2((int)_DAT_ffffe554, unaff_A5, 6);
  return;
}

void FUN_00031344(void)

{
  FUN_00031352();
  FUN_000313e2();
  return;
}

void FUN_00031352(void)

{
  player_update_pos(4);
  (*(code *)((int)&WORD_0003136e +
             (int)*(short *)((int)&WORD_0003136e +
                             (int)(short)((ushort)bRamffffb97a * 2))))();
  return;
}

void FUN_00031374(void)

{
  int unaff_A4;

  *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 64000;
  (&DAT_ffffb976)[unaff_A4] = 1;
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & 0x7f;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0x14;
  return;
}

void FUN_0003138e(void)

{
  short *psVar1;
  ushort uVar2;
  int unaff_A4;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x40;
  uVar2 = 0x10b0 - *(short *)((int)&comp_collision_sensor[0].y + unaff_A4);
  if (uVar2 <= *(ushort *)((int)&comp_pos_y + unaff_A4)) {
    *(ushort *)((int)&comp_pos_y + unaff_A4) = uVar2;
    (&DAT_ffffb976)[unaff_A4] = 2;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
  }
  return;
}

void FUN_000313b2(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(unaff_A4, unaff_A5, 0x26);
  (&DAT_ffffb976)[DAT_ffffe552] = 8;
  uRamffffb977 = 0;
  comp_anim_b = 0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0x3e);
  audio_play(SOUND_ID_DEATH_OF_PEPELOGOO);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000313e2(void)

{
  short sVar1;

  if ((_DAT_ffffe562 == 0) &&
      (sVar1 = _DAT_ffffe564 + -1, _DAT_ffffe564 = sVar1, sVar1 < 0)) {
    _DAT_ffffe564 = *_DAT_ffffe55e;
    if (_DAT_ffffe564 < 0) {
      _DAT_ffffe564 = sVar1;
      (&comp_has_func_maybe)[_DAT_ffffe558] = 0;
      _DAT_ffffe562 = 2;
      return;
    }
    _DAT_ffffe55e = _DAT_ffffe55e + 3;
    FUN_00001880();
  }
  return;
}

void FUN_00031424(void)

{
  (*(code *)((int)&WORD_00031440 +
             (int)*(short *)((int)&WORD_00031440 +
                             (int)(short)((ushort)bRamffffb977 * 2))))();
  return;
}

void FUN_00031446(void)

{
  int unaff_A4;

  (&DAT_ffffb976)[unaff_A4] = 0x3c;
  *(undefined1 *)(unaff_A4 + -0x4689) = 1;
  return;
}

void FUN_00031454(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if ((&DAT_ffffb976)[unaff_A4] == '\0') {
    (&comp_anim_b)[unaff_A4] = 8;
    if ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_JUMPING_OR_UNSHIELDING) {
      ecs_anim_unk_2(unaff_A4, unaff_A5, 4);
    }
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x200;
    DAT_ffffd176 = DAT_ffffd176 + 1;
    player_update_pos(unaff_A4);
    if ((ushort)(component_pos_x_pepelogoo.fixed.i - 0x14U) <=
        *(ushort *)((int)&comp_pos_x + unaff_A4)) {
      *(ushort *)((int)&comp_pos_x + unaff_A4) =
          component_pos_x_pepelogoo.fixed.i - 0x14U;
      *(undefined1 *)(unaff_A4 - 0x4689) = 2;
      ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
      (&DAT_ffffb976)[unaff_A4] = 0xf0;
    }
  } else {
    (&DAT_ffffb976)[unaff_A4] = (&DAT_ffffb976)[unaff_A4] + -1;
  }
  return;
}

void FUN_000314ac(void)

{
  char cVar1;
  int unaff_A4;

  cVar1 = (&DAT_ffffb976)[unaff_A4] + -1;
  (&DAT_ffffb976)[unaff_A4] = cVar1;
  if (cVar1 == '\0') {
    (&DAT_ffffb976)[DAT_ffffe552] = 9;
  }
  return;
}

void FUN_000314be(void)

{
  short unaff_A4w;

  DAT_ffffd916 = 0xb2;
  FUN_0001937a();
  *(undefined2 *)(&DAT_ffffbd76 + unaff_A4w) = 0x3c;
  (&DAT_ffffb976)[unaff_A4w] = 10;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000314dc(void)

{
  short sVar1;
  int iVar2;
  int unaff_A4;

  sVar1 = *(short *)(&DAT_ffffbd76 + unaff_A4) + -1;
  *(short *)(&DAT_ffffbd76 + unaff_A4) = sVar1;
  if (sVar1 != 0) {
    return;
  }
  DAT_ffffcc85 = 0;
  related_to_entering_a_room_7 = 0;
  *(undefined2 *)((int)&comp_state + unaff_A4) = 7;
  (&DAT_ffffb976)[unaff_A4] = 0;
  iVar2 = (int)_DAT_ffffe554;
  *(undefined2 *)((int)&comp_state + iVar2) = 1;
  (&DAT_ffffb976)[iVar2] = 0;
  script_ctx_bf_0e_arg = script_ctx_bf_0e_arg + '\x01';
  component_state_a_pepelogoo = 0x2c;
  _DAT_ffffd198 = DAT_ffffe552;
  DAT_ffffd16c = 8;
  player_vel_unknown_x_1 = 0;
  player_vel_unknown_y_1 = 0;
  player_vel_unknown_x_2 = 0;
  player_vel_unknown_y_2 = 0;
  component_pos_old_x[0].fixed.i = comp_pos_x.fixed.i;
  component_pos_old_y[0].fixed.i = comp_pos_y.fixed.i;
  FUN_00011de4();
  (&comp_collected_item_id_maybe)[(short)unaff_A4] = 0x14;
  FUN_0000192a((sound_id_word_t)0x9);
  return;
}

void FUN_0003155e(void)

{
  int unaff_A4;

  comp_state_a = comp_state_a & 0xfb;
  comp_has_func_maybe = comp_has_func_maybe & 0xf7;
  (*(code *)((int)&WORD_0003157e +
             (int)*(
                 short *)((int)&WORD_0003157e +
                          (int)(short)((ushort)(byte)(&DAT_ffffb976)[unaff_A4] *
                                       2))))();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0003158a(void)

{
  short sVar1;
  long extraout_D0;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  int unaff_A4;
  short sVar3;
  entity_id_t eVar2;
  anim_item_t *unaff_A5;
  void *unaff_A6;

  sVar3 = (short)unaff_A4;
  while (sVar1 =
             *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4),
         -1 < sVar1) {
    unaff_A4 = (int)sVar1;
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  ecs_anim_unk_2((int)_DAT_ffffe554, unaff_A5, 6);
  eVar2 = (entity_id_t)DAT_ffffe552;
  ecs_anim_unk_2(eVar2, unaff_A5, 6);
  (&DAT_ffffb976)[eVar2] = 1;
  *(undefined1 *)(eVar2 - 0x4689) = 0;
  DAT_ffffb976 = 0;
  comp_vel[0].x.raw = 0;
  *(undefined2 *)((int)&comp_vel[0].y + eVar2) = 0x40;
  *(undefined2 *)((int)&comp_state + (int)_DAT_ffffe554) = 9;
  *(undefined2 *)((int)&comp_state + (int)_DAT_ffffe554) = 8;
  ecs_anim_unk_2((int)sVar3, unaff_A5, 6);
  exception_unk_0(unaff_A3,
                  (int)sVar3,
                  unaff_A6,
                  extraout_D0,
                  extraout_D1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  DAT_ffffd916 = 0xb3;
  FUN_0001937a();
  ecs_anim_unk_2((int)sVar3, unaff_A5, 0x16);
  (&DAT_ffffb976)[sVar3] = 1;
  eVar2 = (entity_id_t)_DAT_ffffe554;
  ecs_anim_unk_2(eVar2, unaff_A5, 8);
  *(undefined2 *)((int)&comp_vel[0].x + eVar2) = 0;
  *(undefined2 *)((int)&comp_vel[0].y + eVar2) = 0;
  _DAT_ffffe564 = 0x1e;
  return;
}

void FUN_00031628(void)

{
  FUN_00031632();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00031632(void)

{
  entity_id_t self;
  bool bVar1;

  self = (entity_id_t)_DAT_ffffe554;
  *(short *)((int)&comp_pos_y + self) =
      *(short *)((int)&comp_pos_y + self) + -0x40;
  player_update_pos(self);
  bVar1 = FUN_00000eae(self);
  if (bVar1) {
    (&DAT_ffffb976)[DAT_ffffe552] = 2;
  }
  return;
}

void FUN_00031652(void)

{
  FUN_0003165c();
  return;
}

void FUN_0003165c(void)

{
  short unaff_D2w;
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  anim_item_t *unaff_A5;

  if ((comp_anim_b != 0) || (comp_anim_c != 0)) {
    comp_anim_b = 0;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  }
  comp_vel[0].y.raw = comp_vel[0].y.raw + 0x40;
  entity_update_pos(ENTITY_ID_ASHA);
  interact_with_all_other_entities(ENTITY_ID_ASHA, unaff_D2w, (char)unaff_D3w);
  ecs_update_collision(0, unaff_D3w, unaff_D6w, unaff_D7w);
  ecs_apply_collision(0);
  if ((component_collision_flags & 4) != 0) {
    (&DAT_ffffb976)[DAT_ffffe552] = 3;
    comp_vel[0].y.raw = 0;
  }
  return;
}

void FUN_000316b2(void)

{
  FUN_000316bc();
  return;
}

void FUN_000316bc(void)

{
  fixed_t fVar1;
  anim_item_t *unaff_A5;

  if ((comp_anim_b != 8) ||
      (comp_anim_c != ECS_STATE_1_B_JUMPING_OR_UNSHIELDING)) {
    comp_anim_b = 8;
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 4);
  }
  player_update_pos_x(0);
  fVar1.raw =
      (uint)(ushort)(component_pos_x_pepelogoo.fixed.i - 0x14) * 0x10000;
  if (fVar1.raw != comp_pos_x.raw) {
    if ((uint)fVar1 < (uint)comp_pos_x) {
      comp_state_a = comp_state_a | ENTITY_STATE_A_08;
      FUN_00030b6c();
    } else {
      comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
      FUN_00030b32();
    }
  }
  if ((int16_t)(component_pos_x_pepelogoo.fixed.i + -0x14) ==
      comp_pos_x.fixed.i) {
    (&DAT_ffffb976)[DAT_ffffe552] = 4;
    comp_vel[0].x.raw = 0;
    uRamffffb977 = 0xf0;
  }
  return;
}

void FUN_00031732(void)

{
  FUN_0003173c();
  return;
}

void FUN_0003173c(void)

{
  anim_item_t *unaff_A5;

  comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
  if (comp_anim_c != ECS_STATE_1_B_FALLING) {
    ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 6);
  }
  cRamffffb977 = cRamffffb977 + -1;
  if (cRamffffb977 == '\0') {
    (&DAT_ffffb976)[DAT_ffffe552] = 5;
  }
  return;
}

void FUN_00031768(void)

{
  DAT_ffffcc92 = 1;
  DAT_ffffcc93 = 9;
  DAT_ffff97ea = 0xf2;
  script_state_set_true((script_state_bit_t)0x3ea);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00031786(void)

{
  short unaff_D2w;
  entity_id_t e;
  anim_item_t *unaff_A5;

  FUN_0000147a((func *)&UNK_000317e8, 1, 0);
  if (-1 < unaff_D2w) {
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    *(undefined2 *)(&DAT_ffffbd78 + e) = 0x140;
    *(undefined2 *)(&DAT_ffffbd76 + e) = 0x4000;
    *(undefined2 *)((int)&comp_unk_3 + e) = 4;
    *(undefined2 *)((int)&comp_pos_x + e) = 0x1130;
    *(undefined2 *)((int)&comp_pos_y + e) = 0x1090;
    (&comp_state_a)[e] = 0x80;
    (&comp_anim_base_offset)[e] = 0x14;
    (&comp_anim_b)[e] = 0x44;
    *(undefined4 *)((int)&player_collision_offset[0].x + e) = 0x900000;
    ecs_anim_unk_2((int)unaff_D2w,
                   unaff_A5,
                   (byte) * (undefined2 *)(&comp_unk_5 + _DAT_ffffe558));
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0003185c(void)

{
  short unaff_D2w;
  entity_id_t e;
  anim_item_t *unaff_A5;

  FUN_0000147a(FUN_000318c6, 1, 0);
  if (-1 < unaff_D2w) {
    e = (entity_id_t)unaff_D2w;
    entity_reset(e);
    *(undefined2 *)((int)&comp_unk_3 + e) = 4;
    *(undefined2 *)((int)&comp_pos_x + e) = 0x1000;
    *(undefined2 *)((int)&comp_pos_y + e) = 0x1000;
    *(undefined2 *)(&DAT_ffffb876 + e) = 0x78;
    *(undefined2 *)(&DAT_ffffbe76 + e) = 0xc0;
    *(undefined4 *)(&DAT_ffffbd76 + e) = 0xc80000;
    *(undefined4 *)((int)&player_collision_offset[0].x + e) = 0x900000;
    (&comp_state_a)[e] = 0x80;
    (&comp_anim_base_offset)[e] = 0x14;
    (&comp_anim_b)[e] = 0x44;
    ecs_anim_unk_2((int)unaff_D2w,
                   unaff_A5,
                   (byte) * (undefined2 *)(&comp_unk_5 + _DAT_ffffe558));
  }
  return;
}

void FUN_000318c6(void)

{
  short sVar1;
  short sVar2;
  short sVar3;
  short extraout_D1w;
  int unaff_A4;

  *(short *)(&DAT_ffffbe76 + unaff_A4) =
      *(short *)(&DAT_ffffbe76 + unaff_A4) + 1;
  sVar3 = FUN_000012a8();
  sVar1 = *(short *)(&DAT_ffffbd76 + unaff_A4);
  sVar2 = *(short *)((int)&player_collision_offset[0].x + unaff_A4);
  *(int *)(&DAT_ffffbd76 + unaff_A4) =
      *(int *)(&DAT_ffffbd76 + unaff_A4) + 0x4000;
  if (*(short *)(&DAT_ffffb876 + unaff_A4) != 0x10) {
    *(short *)(&DAT_ffffb876 + unaff_A4) =
        *(short *)(&DAT_ffffb876 + unaff_A4) + -1;
    *(short *)(&DAT_ffffbe76 + unaff_A4) =
        *(short *)(&DAT_ffffbe76 + unaff_A4) + 1;
    *(short *)((int)&comp_pos_x + unaff_A4) = sVar1 + sVar3 + 0x1090;
    *(short *)((int)&comp_pos_y + unaff_A4) = sVar2 + extraout_D1w + 0xff8;
    return;
  }
  *(undefined2 *)(&DAT_ffffbd76 + unaff_A4) = 0x1178;
  *(undefined2 *)(&DAT_ffffbd78 + unaff_A4) = 0x109c;
  *(undefined2 *)(&DAT_ffffb876 + unaff_A4) = 0x20;
  *(undefined2 *)(&DAT_ffffbe76 + unaff_A4) = 0xa8;
  *(code **)((int)&comp_some_function + unaff_A4) = FUN_0003192e;
  return;
}

void FUN_0003192e(void)

{
  short sVar1;
  short extraout_D1w;
  int unaff_A4;

  sVar1 = FUN_000012a8();
  *(short *)((int)&comp_pos_x + unaff_A4) =
      *(short *)(&DAT_ffffbd76 + unaff_A4) + sVar1;
  *(short *)((int)&comp_pos_y + unaff_A4) =
      *(short *)(&DAT_ffffbd78 + unaff_A4) + extraout_D1w;
  *(short *)(&DAT_ffffbe76 + unaff_A4) =
      *(short *)(&DAT_ffffbe76 + unaff_A4) + 3;
  return;
}

void FUN_00031954(void)

{
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;
  entity_id_t unaff_A4;

  script_ctx_bf_0e_arg = 5;
  comp_state_a = comp_state_a & 0xfb;
  comp_has_func_maybe = comp_has_func_maybe & 0xf7;
  entity_update_pos(unaff_A4);
  ecs_update_collision(unaff_A4, unaff_D3w, unaff_D6w, unaff_D7w);
  ecs_apply_collision(unaff_A4);
  (*(code *)((int)&WORD_00031990 +
             (int)*(
                 short *)((int)&WORD_00031990 +
                          (int)(short)((ushort)(byte)(&DAT_ffffb976)[unaff_A4] *
                                       2))))();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000319a2(void)

{
  short sVar1;
  int unaff_A4;
  int iVar2;
  anim_item_t *unaff_A5;

  while (true) {
    audio_play_sound_asha_dies();
    sVar1 = *(short *)((int)&comp_unkown_t_ARRAY_ffffb362[0].unk2 + unaff_A4);
    if (sVar1 < 0)
      break;
    unaff_A4 = (int)sVar1;
    (&comp_has_func_maybe)[unaff_A4] = 0;
  }
  iVar2 = (int)DAT_ffffe552;
  (&DAT_ffffb976)[iVar2] = 1;
  *(undefined1 *)(iVar2 + -0x4689) = 0;
  DAT_ffffb976 = 0;
  comp_vel[0].x.raw = 0;
  *(undefined2 *)((int)&comp_vel[0].y + iVar2) = 0x40;
  sVar1 = _DAT_ffffe554;
  *(undefined2 *)((int)&comp_state + (int)_DAT_ffffe554) = 9;
  ecs_anim_unk_2((int)sVar1, unaff_A5, 8);
  return;
}

void FUN_000319ea(void)

{
  short unaff_A4w;
  int iVar1;

  FUN_00031a1a();
  FUN_00031af8();
  FUN_00031bd2();
  iVar1 = (int)unaff_A4w;
  if ((*(char *)(iVar1 + -0x4689) == '\x02') && (DAT_ffffb976 == '\x01')) {
    (&DAT_ffffb976)[iVar1] = 2;
    *(undefined1 *)(iVar1 + -0x4689) = 0;
    *(undefined2 *)((int)&comp_vel[0].x + iVar1) = 0;
  }
  return;
}

void FUN_00031a1a(void)

{
  int unaff_A4;

  (*(code *)((int)&WORD_00031a30 +
             (int)*(
                 short *)((int)&WORD_00031a30 +
                          (int)(short)((ushort) * (byte *)(unaff_A4 + -0x4689) *
                                       2))))();
  return;
}

void FUN_00031a36(void)

{
  short *psVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x40;
  if (0x500 < *(short *)((int)&comp_vel[0].y + unaff_A4)) {
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0x500;
  }
  if (((&component_collision_flags)[unaff_A4] & 4) == 0) {
    if ((&comp_anim_c)[unaff_A4] !=
        ECS_STATE_1_B_TALKING_OR_ENTERING_BACK_DOOR) {
      ecs_anim_unk_2(unaff_A4, unaff_A5, 0xe);
    }
  } else {
    *(undefined1 *)(unaff_A4 - 0x4689) = 1;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
  }
  return;
}

void FUN_00031a70(void)

{
  short *psVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_ATTACKING_MID_AIR) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  if (*(ushort *)((int)&comp_pos_x + unaff_A4) == 0x1188) {
  LAB_00031ab6:
    if (*(ushort *)((int)&comp_pos_x + unaff_A4) < 0x1188) {
      (&comp_state_a)[unaff_A4] =
          (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + 0x40;
      if (0x1ff < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x200;
      }
    } else {
      (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + -0x40;
      if (*(short *)((int)&comp_vel[0].x + unaff_A4) < -0x1ff) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfe00;
      }
    }
  } else {
    if (*(ushort *)((int)&comp_pos_x + unaff_A4) < 0x1188) {
      if (-1 < *(short *)((int)&comp_vel[0].x + unaff_A4))
        goto LAB_00031ab6;
    } else {
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      if ((*psVar1 == 0) || (*psVar1 < 0))
        goto LAB_00031ab6;
    }
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) = 0x1188;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 6);
    *(undefined1 *)(unaff_A4 - 0x4689) = 2;
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] | ENTITY_STATE_A_08;
  }
  return;
}

void FUN_00031af6(void)

{
  return;
}

void FUN_00031af8(void)

{
  short unaff_D3w;
  word unaff_D6w;
  word unaff_D7w;

  entity_update_pos(ENTITY_ID_ASHA);
  ecs_update_collision(0, unaff_D3w, unaff_D6w, unaff_D7w);
  ecs_apply_collision(0);
  (*(FUN_00031b22 +
     *(short *)(FUN_00031b22 + (short)((ushort)DAT_ffffb976 * 2))))();
  return;
}

void FUN_00031b22(void)

{
  short *psVar1;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  if (((&comp_anim_b)[unaff_A4] != 8) ||
      ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_WALKING_OR_DOWNSTAB)) {
    (&comp_anim_b)[unaff_A4] = 8;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  }
  if (*(ushort *)((int)&comp_pos_x + unaff_A4) != 0x1110) {
    if (*(ushort *)((int)&comp_pos_x + unaff_A4) < 0x1110) {
      if (-1 < *(short *)((int)&comp_vel[0].x + unaff_A4))
        goto LAB_00031b88;
    } else {
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      if ((*psVar1 == 0) || (*psVar1 < 0))
        goto LAB_00031b88;
    }
  }
  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
  *(undefined2 *)((int)&comp_pos_x + unaff_A4) = 0x1110;
  if ((&comp_anim_c)[unaff_A4] != ECS_STATE_1_B_ATTACKING_MID_AIR) {
    ecs_anim_unk_2(unaff_A4, unaff_A5, 8);
  }
  if (((&component_collision_flags)[unaff_A4] & 4) != 0) {
    (&DAT_ffffb976)[unaff_A4] = 1;
  }
LAB_00031b88:
  psVar1 = (short *)((int)&comp_vel[0].y + unaff_A4);
  *psVar1 = *psVar1 + 0x40;
  if (*(ushort *)((int)&comp_pos_x + unaff_A4) != 0x1110) {
    if (*(ushort *)((int)&comp_pos_x + unaff_A4) < 0x1110) {
      (&comp_state_a)[unaff_A4] =
          (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + 0x40;
      if (0x1ff < *(short *)((int)&comp_vel[0].x + unaff_A4)) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0x200;
      }
    } else {
      (&comp_state_a)[unaff_A4] =
          (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
      psVar1 = (short *)((int)&comp_vel[0].x + unaff_A4);
      *psVar1 = *psVar1 + -0x40;
      if (*(short *)((int)&comp_vel[0].x + unaff_A4) < -0x1ff) {
        *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0xfe00;
      }
    }
  }
  return;
}

void FUN_00031bd0(void)

{
  return;
}

void FUN_00031bd2(void)

{
  ushort uVar1;

  if (DAT_ffffd16c == 6) {
    uVar1 = 0x10d0 - DAT_ffffd176;
    if (uVar1 != 0) {
      if ((short)uVar1 < 0) {
        if ((ushort)-uVar1 < 3 || uVar1 == 0xfffd) {
          DAT_ffffd176 = 0x10d0;
        } else {
          DAT_ffffd176 = DAT_ffffd176 + -3;
        }
      } else if (uVar1 < 4) {
        DAT_ffffd176 = 0x10d0;
      } else {
        DAT_ffffd176 = DAT_ffffd176 + 3;
      }
    }
  } else {
    DAT_ffffd16c = 6;
    WORD_ffffd178 = DAT_ffffc746;
    DAT_ffffd176 = DAT_ffffc73a;
  }
  return;
}

void FUN_00031c24(void)

{
  int unaff_A4;

  (*(code *)((int)&WORD_00031c3e +
             (int)*(
                 short *)((int)&WORD_00031c3e +
                          (int)(short)((ushort) * (byte *)(unaff_A4 + -0x4689) *
                                       2))))();
  return;
}

void FUN_00031c4a(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  *(undefined1 *)(unaff_A4 - 0x4689) = 1;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 0x1a);
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0xc);
  return;
}

void FUN_00031c66(void)

{
  int unaff_A4;

  if (*(short *)((int)&comp_anim_tick + unaff_A4) == 0) {
    *(undefined1 *)(unaff_A4 + -0x4689) = 2;
  }
  return;
}

void FUN_00031c74(void)

{
  int iVar1;

  DAT_ffffd916 = 0xb4;
  FUN_0001937a();
  iVar1 = (int)DAT_ffffe552;
  *(undefined1 *)(iVar1 + -0x4689) = 3;
  *(undefined2 *)(&comp_unk_2 + iVar1) = 300;
  return;
}

void ecs_call_pepelogoo(entity_id_t self)

{
  short sVar1;

  sVar1 = *(short *)(&comp_unk_2 + self) + -1;
  *(short *)(&comp_unk_2 + self) = sVar1;
  if (sVar1 < 0) {
    *(undefined1 *)(self - 0x4689) = 4;
  }
  if ((gamepad_held & GAMEPAD_A) != GAMEPAD_NONE) {
    audio_play(SOUND_ID_PEPE_VOICE_1);
    *(undefined1 *)(self - 0x4689) = 5;
    *(undefined2 *)(&DAT_ffffbe76 + self) = 0x78;
  }
  return;
}

void FUN_00031cbc(void)

{
  int iVar1;

  DAT_ffffd916 = 0xb5;
  FUN_0001937a();
  iVar1 = (int)DAT_ffffe552;
  *(undefined1 *)(iVar1 + -0x4689) = 3;
  *(undefined2 *)(&comp_unk_2 + iVar1) = 300;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00031cda(void)

{
  short sVar1;
  undefined2 unaff_D2w;
  func *in_A1;
  int unaff_A4;

  sVar1 = *(short *)(&DAT_ffffbe76 + unaff_A4) + -1;
  *(short *)(&DAT_ffffbe76 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    (&DAT_ffffb976)[unaff_A4] = 3;
    *(undefined1 *)(unaff_A4 + -0x4689) = 0;
    DAT_ffffb976 = 0;
    FUN_0000147a(in_A1, 0, 1);
    _DAT_ffffe558 = unaff_D2w;
    audio_play(SOUND_ID_SLASH);
    audio_play(SOUND_ID_BIRTH_OF_PEPELOGOO);
  }
  return;
}

void FUN_00031d08(void)

{
  int unaff_A4;

  (*(code *)(&UNK_00031d24 +
             *(short *)(&UNK_00031d24 +
                        (short)((ushort) * (byte *)(unaff_A4 + -0x4689) *
                                2))))();
  return;
}

void FUN_00031dd4(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  (&comp_state_a)[unaff_A4] = (&comp_state_a)[unaff_A4] & ~ENTITY_STATE_A_08;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  *(undefined2 *)(&comp_unk_2 + unaff_A4) = 0x3c;
  *(undefined1 *)(DAT_ffffe552 + -0x4689) = 3;
  return;
}

void FUN_00031df2(void)

{
  short sVar1;
  int unaff_A4;

  sVar1 = *(short *)(&comp_unk_2 + unaff_A4) + -1;
  *(short *)(&comp_unk_2 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    *(undefined1 *)(DAT_ffffe552 + -0x4689) = 4;
  }
  return;
}

void FUN_00031e04(void)

{
  entity_id_t self;
  anim_item_t *unaff_A5;

  self = (entity_id_t)DAT_ffffe552;
  *(undefined1 *)(self - 0x4689) = 5;
  ecs_anim_unk_2(self, unaff_A5, 0x1c);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00031e16(void)

{
  int iVar1;

  if (*(short *)((int)&comp_anim_tick + (int)DAT_ffffe552) == 0) {
    iVar1 = (int)_DAT_ffffe558;
    *(undefined **)((int)&comp_some_function + iVar1) = &UNK_00031e46;
    *(undefined2 *)(&comp_unk_2 + iVar1) = 0;
    *(undefined2 *)(&comp_unk_5 + iVar1) = 0;
    iVar1 = (int)DAT_ffffe552;
    *(undefined1 *)(iVar1 + -0x4689) = 0;
    (&DAT_ffffb976)[iVar1] = 8;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00031f20(void)

{
  short unaff_A4w;
  anim_item_t *unaff_A5;

  DAT_ffffd916 = 0xcc;
  FUN_0001937a();
  ecs_anim_unk_2((int)_DAT_ffffe558, unaff_A5, 6);
  audio_stop_all();
  audio_play(SOUND_ID_A_CRADLE_SONG_OF_PEPELOGOO);
  *(undefined1 *)(unaff_A4w + -0x4689) = 0;
  (&DAT_ffffb976)[unaff_A4w] = 4;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00031f52(void)

{
  short *psVar1;
  short sVar2;
  entity_id_t self;
  anim_item_t *unaff_A5;

  sVar2 = _DAT_ffffe558;
  self = (entity_id_t)_DAT_ffffe558;
  if (*(short *)(&comp_unk_2 + self) == 0) {
    psVar1 = *(short **)((int)&comp_some_function + self);
    if (*psVar1 < 0) {
      *(undefined **)((int)&comp_some_function + self) = &UNK_00031fb8;
      *(undefined2 *)(&comp_unk_5 + self) = 0;
      ecs_anim_unk_2(self, unaff_A5, 2);
      DAT_ffffd916 = 0xb6;
      FUN_0001937a();
      *(undefined2 *)(&comp_unk_2 + sVar2) = 0x2d0;
      (&DAT_ffffb976)[DAT_ffffe552] = 5;
      return;
    }
    *(short *)(&comp_unk_2 + self) = *psVar1;
    *(short *)(&comp_unk_5 + self) = psVar1[1];
    *(short **)((int)&comp_some_function + self) = psVar1 + 2;
    FUN_00031786();
    self = (entity_id_t)_DAT_ffffe558;
  }
  *(short *)(&comp_unk_2 + self) = *(short *)(&comp_unk_2 + self) + -1;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00031fda(void)

{
  short *psVar1;
  int iVar2;

  iVar2 = (int)_DAT_ffffe558;
  if (*(short *)(&comp_unk_2 + iVar2) == 0) {
    psVar1 = *(short **)((int)&comp_some_function + iVar2);
    if (*psVar1 < 0) {
      iVar2 = (int)DAT_ffffe552;
      (&DAT_ffffb976)[iVar2] = 6;
      *(undefined1 *)(iVar2 + -0x4689) = 0;
      *(undefined2 *)(&comp_unk_2 + iVar2) = 0x100;
      return;
    }
    *(short *)(&comp_unk_2 + iVar2) = *psVar1;
    *(short *)(&comp_unk_5 + iVar2) = psVar1[1];
    *(short **)((int)&comp_some_function + iVar2) = psVar1 + 2;
    FUN_0003185c();
    iVar2 = (int)_DAT_ffffe558;
  }
  *(short *)(&comp_unk_2 + iVar2) = *(short *)(&comp_unk_2 + iVar2) + -1;
  return;
}

void FUN_00032020(void)

{
  int unaff_A4;

  // WARNING: Could not recover jumptable at 0x00032030. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)((int)&WORD_00032032 +
             (int)*(
                 short *)((int)&WORD_00032032 +
                          (int)(short)((ushort) * (byte *)(unaff_A4 + -0x4689) *
                                       2))))();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00032036(void)

{
  short sVar1;
  int iVar2;
  int unaff_A4;

  sVar1 = *(short *)(&comp_unk_2 + unaff_A4) + -1;
  *(short *)(&comp_unk_2 + unaff_A4) = sVar1;
  if (sVar1 == 0) {
    *(undefined1 *)(unaff_A4 + -0x4689) = 1;
    iVar2 = (int)_DAT_ffffe554;
    *(undefined2 *)((int)&comp_vel[0].x + iVar2) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + iVar2) = 0;
  }
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00032050(void)

{
  short *psVar1;
  entity_id_t self;
  bool bVar2;

  self = (entity_id_t)_DAT_ffffe554;
  psVar1 = (short *)((int)&comp_vel[0].x + self);
  *psVar1 = *psVar1 + -0x40;
  player_update_pos(self);
  bVar2 = FUN_00000eae(self);
  if (bVar2) {
    (&DAT_ffffb976)[DAT_ffffe552] = 7;
  }
  return;
}

void FUN_00032074(void)

{
  DAT_ffff97ea = 0x109;
  DAT_ffffcd3d = 0xff;
  DAT_ffffcd3e = 0;
  DAT_ffffcc92 = 1;
  DAT_ffffcc93 = 7;
  DAT_ffffe232 = 1;
  script_state_set_true((script_state_bit_t)0x3e9);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000320a0(void)

{
  FUN_0000ac2a();
  FUN_000320e0();
  audio_play(SOUND_ID_F9);
  audio_play(SOUND_ID_FINALE_PART_1);
  do {
    (*(FUN_000320f2 + *(short *)(FUN_000320f2 + (short)(_DAT_ffffe570 * 2))))();
    _DAT_ffffe570 = _DAT_ffffe570 + 1;
  } while (_DAT_ffffe570 != 0xd);
  return;
}

// WARNING: Removing unreachable block (ram,0x00018490)
// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000320e0(void)

{
  FUN_00001580();
  _DAT_ffffe570 = 0;
  DAT_ffffd2e4 = 0;
  VDP_CTRL = 0x9100;
  VDP_CTRL = 0x9200;
  DAT_ffffd2de = 0;
  DAT_ffffd2e2 = 0x80;
  return;
}

void FUN_000320f0(void)

{
  return;
}

void FUN_000320f2(void)

{
  short in_D0w;
  byte *unaff_A2;
  int unaff_A6;

  *unaff_A2 = *unaff_A2 | 0x26;
  unaff_A2[1] = unaff_A2[1] | 0x2e;
  unaff_A2[2] = unaff_A2[2] | 0x4c;
  unaff_A2[3] = unaff_A2[3] | 0x66;
  *(undefined1 *)(unaff_A6 + 0x19 + (int)in_D0w) =
      *(undefined1 *)(unaff_A6 + -1);
  unaff_A2[4] = unaff_A2[4] | 6;
  FUN_00034b00();
  return;
}

void FUN_00032118(void)

{
  FUN_00026b72();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00032120(void)

{
  FUN_00001580();
  _DAT_ffff9812 = 0x22f0d0f;
  vdp_palettes_something();
  FUN_00032a0e();
  FUN_000327ee();
  FUN_00032842();
  palette_set_fade_black_ease_out_all();
  FUN_00000966();
  FUN_00032956();
  FUN_00032980();
  FUN_00032a00();
  FUN_0003299a();
  FUN_000329b4();
  FUN_000329ea();
  FUN_00032a00();
  palette_set_fade_black_ease_in_all();
  FUN_00000966();
  return;
}

void FUN_000327ee(void)

{
  anim_item_t *unaff_A5;

  entity_reset(ENTITY_ID_ASHA);
  comp_unk_4 = 4;
  comp_pos_x.fixed.i = 0x80;
  comp_pos_y.fixed.i = 0x90;
  comp_state_a = comp_state_a & ~ENTITY_STATE_A_08;
  comp_unk_3 = 0x10;
  comp_anim_base_offset = 0x18;
  comp_anim_b = 0x40;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 6);
  comp_pos_x.fixed.i = -0x20;
  comp_pos_y.fixed.i = 0xa0;
  comp_vel[0].x.raw = 0;
  comp_vel[0].y.raw = 0;
  return;
}

void FUN_00032842(void)

{
  anim_item_t *unaff_A5;

  entity_reset(ENTITY_ID_PEPELOGOO);
  DAT_ffffa32e = 4;
  component_pos_x_pepelogoo.fixed.i = 0x80;
  component_pos_y_pepelogoo.fixed.i = 0xa0;
  component_unknown_3_pepelogoo = 0x18;
  DAT_ffffa63a = 0x18;
  DAT_ffffa63b = 0x44;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 0);
  DAT_ffff9f1f = DAT_ffff9f1f | 8;
  comp_vel[1].x.raw = 0;
  comp_vel[1].y.raw = 0;
  entity_reset(ENTITY_ID_08);
  DAT_ffff9f24 = 0x18;
  DAT_ffffa332 = 4;
  DAT_ffffa12a = 0x16;
  DAT_ffffa22e = 0xa0;
  DAT_ffffa63e = 0x18;
  DAT_ffffa63f = 0x42;
  ecs_anim_unk_2(ENTITY_ID_08, unaff_A5, 0);
  entity_reset(ENTITY_ID_0C);
  DAT_ffff9f28 = 0x18;
  DAT_ffffa336 = 4;
  DAT_ffffa12e = 0xc0;
  DAT_ffffa232 = 0xa0;
  DAT_ffffa642 = 0x18;
  DAT_ffffa643 = 0x42;
  DAT_ffff9f27 = DAT_ffff9f27 | 8;
  ecs_anim_unk_2(ENTITY_ID_0C, unaff_A5, 4);
  entity_reset(0x10);
  DAT_ffff9f2c = 0x18;
  DAT_ffffa33a = 4;
  DAT_ffffa132 = 0x88;
  DAT_ffffa236 = 0x70;
  DAT_ffffa646 = 0x18;
  DAT_ffffa647 = 0x42;
  DAT_ffff9f2b = DAT_ffff9f2b | 8;
  ecs_anim_unk_2(0x10, unaff_A5, 6);
  entity_reset(0x14);
  DAT_ffff9f30 = 0x18;
  DAT_ffffa33e = 4;
  DAT_ffffa136 = 0xb0;
  DAT_ffffa23a = 0x90;
  DAT_ffffa64a = 0x18;
  DAT_ffffa64b = 0x42;
  DAT_ffff9f2f = DAT_ffff9f2f | 8;
  ecs_anim_unk_2(0x14, unaff_A5, 2);
  return;
}

void FUN_00032956(void)

{
  long extraout_D0;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;

  while (true) {
    comp_vel[0].x.raw = 0x100;
    player_update_pos_x(0);
    if (0x4f < comp_pos_x.fixed.i)
      break;
    exception_unk_0(unaff_A3,
                    ENTITY_ID_ASHA,
                    unaff_A6,
                    extraout_D0,
                    extraout_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
  }
  comp_pos_x.fixed.i = 0x50;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  return;
}

void FUN_00032980(void)

{
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 8);
  uVar1 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            ENTITY_ID_ASHA,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (comp_anim_tick != 0);
  return;
}

void FUN_0003299a(void)

{
  undefined4 extraout_D0;
  undefined4 extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 2);
  uVar1 = CONCAT44(extraout_D0, extraout_D1);
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            ENTITY_ID_ASHA,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  } while (comp_anim_tick != 0);
  return;
}

void FUN_000329b4(void)

{
  long extraout_D0;
  long lVar1;
  long extraout_D0_00;
  long extraout_D1;
  long lVar2;
  long extraout_D1_00;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;

  comp_vel[1].y.raw = 0;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 4);
  lVar1 = extraout_D0;
  lVar2 = extraout_D1;
  do {
    exception_unk_0(unaff_A3,
                    ENTITY_ID_PEPELOGOO,
                    unaff_A6,
                    lVar1,
                    lVar2,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    comp_vel[1].x.raw = -0x80;
    player_update_pos_x(4);
    lVar1 = extraout_D0_00;
    lVar2 = extraout_D1_00;
  } while (0x65 < (ushort)component_pos_x_pepelogoo.fixed.i);
  component_pos_x_pepelogoo.fixed.i = 0x65;
  comp_vel[1].x.raw = 0;
  return;
}

void FUN_000329ea(void)

{
  anim_item_t *unaff_A5;

  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 4);
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 6);
  return;
}

void FUN_00032a00(void)

{
  short sVar1;
  long in_D0;
  long in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar2;

  do {
    uVar2 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            in_D0,
                            in_D1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    in_D1 = (long)uVar2;
    sVar1 = (short)in_D0 + -1;
    in_D0 = CONCAT22((short)((ulonglong)uVar2 >> 0x30), sVar1);
  } while (sVar1 != 0);
  return;
}

void FUN_00032a0e(void)

{
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  void *in_A0;
  byte *in_A1;
  byte *unaff_A2;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  text_unk_1(in_A0, in_A1);
  uVar1 = uncompress_and_copy_to_vram();
  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  (long)((ulonglong)uVar1 >> 0x20),
                  (long)uVar1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  DAT_ffff91ce._0_1_ = 0xff;
  something(in_A1);
  something(unaff_A2);
  DAT_ffff91ce._0_1_ = 0;
  return;
}

void FUN_000331ea(void)

{
  VDP_CTRL = 0x8b0b;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000331f4(void)

{
  word wVar1;
  short sVar2;
  word *pwVar3;
  undefined2 *puVar4;

  wVar1 = 0;
  pwVar3 = &vdp_hblank_effect_asha_p;
  do {
    *pwVar3 = wVar1;
    wVar1 = wVar1 - 1;
    pwVar3 = pwVar3 + 1;
  } while (wVar1 != 0xffff);
  sVar2 = 0xdf;
  puVar4 = &vdp_hblank_effect_pepelogoo_p;
  do {
    *puVar4 = 0;
    sVar2 = sVar2 + -1;
    puVar4 = puVar4 + 1;
  } while (sVar2 != -1);
  vdp_related_to_display_asha = 3;
  _DAT_ffffe572 = 0;
  _DAT_ffffe576 = 0;
  _DAT_ffffe57a = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00033228(void)

{
  int iVar1;
  undefined2 uVar2;
  short sVar3;
  undefined2 *puVar4;

  iVar1 = _DAT_ffffe572 + 0x4000;
  _DAT_ffffe576 = _DAT_ffffe576 + 0x8000;
  _DAT_ffffe572 = (undefined2)((uint)iVar1 >> 0x10);
  uVar2 = _DAT_ffffe572;
  sVar3 = 0x2f;
  puVar4 = (undefined2 *)&DAT_ffff9432;
  _DAT_ffffe572 = iVar1;
  do {
    *puVar4 = uVar2;
    sVar3 = sVar3 + -1;
    puVar4 = puVar4 + 1;
  } while (sVar3 != -1);
  vdp_related_to_display_asha = 2;
  return;
}

void FUN_00033256(void)

{
  short sVar1;
  short *psVar2;
  short *psVar3;
  entity_id_t e;
  anim_item_t *unaff_A5;

  e = ENTITY_ID_PEPELOGOO;
  psVar2 = (short *)&UNK_000332a4;
  while (true) {
    entity_reset(e);
    *(undefined2 *)((int)&comp_unk_4 + e) = 4;
    if (*psVar2 < 0)
      break;
    *(short *)((int)&comp_pos_x + e) = *psVar2;
    psVar3 = psVar2 + 2;
    *(short *)((int)&comp_pos_y + e) = psVar2[1];
    psVar2 = psVar2 + 3;
    sVar1 = *psVar3;
    (&comp_anim_base_offset)[e] = 0x18;
    (&comp_anim_b)[e] = 0x46;
    (&comp_state_a)[e] = (entity_state_a_t)((ushort)sVar1 >> 8);
    ecs_anim_unk_2(e, unaff_A5, (byte)sVar1);
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x18;
    *(undefined2 *)((int)&comp_state + e) = 0;
    e = e + ENTITY_ID_PEPELOGOO;
  }
  return;
}

void FUN_000332b8(void)

{
  short sVar1;
  short *psVar2;
  short *psVar3;
  entity_id_t e;
  anim_item_t *unaff_A5;

  e = 0x10;
  psVar2 = (short *)&UNK_00033306;
  while (true) {
    entity_reset(e);
    *(undefined2 *)((int)&comp_unk_4 + e) = 4;
    if (*psVar2 < 0)
      break;
    *(short *)((int)&comp_pos_x + e) = *psVar2;
    psVar3 = psVar2 + 2;
    *(short *)((int)&comp_pos_y + e) = psVar2[1];
    psVar2 = psVar2 + 3;
    sVar1 = *psVar3;
    (&comp_anim_base_offset)[e] = 0x18;
    (&comp_anim_b)[e] = (byte)sVar1;
    ecs_anim_unk_2(e, unaff_A5, 0);
    *(undefined2 *)((int)&comp_state + e) = 0;
    *(undefined2 *)((int)&comp_unk_3 + e) = 6;
    if (e == 0x10) {
      DAT_ffff9f2c = 0x18;
    }
    e = e + ENTITY_ID_PEPELOGOO;
  }
  return;
}

void FUN_00033314(void)

{
  anim_item_t *unaff_A5;

  entity_reset(ENTITY_ID_ASHA);
  comp_unk_4 = 4;
  comp_pos_x.fixed.i = 0x70;
  comp_pos_y.fixed.i = 0xa0;
  comp_anim_base_offset = 0x18;
  comp_anim_b = 0x4a;
  comp_unk_3 = 0x10;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  comp_state._0_1_ = COMP_STATE_STAND;
  return;
}

void FUN_00033322(entity_id_t self, entity_id_t other)

{
  *(undefined2 *)((int)&comp_pos_x + self) = 0x70;
  *(undefined2 *)((int)&comp_pos_y + self) = 0xa0;
  (&comp_anim_base_offset)[self] = 0x18;
  (&comp_anim_b)[self] = 0x4a;
  *(undefined2 *)((int)&comp_unk_3 + self) = 0x10;
  ecs_anim_unk_2(self, (anim_item_t *)other, 0);
  *(undefined1 *)((int)&comp_state + self) = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_0003334c(void)

{
  // WARNING: Could not recover jumptable at 0x0003335c. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)(&UNK_0003335e + *(short *)(&UNK_0003335e + _DAT_ffffb476)))();
  return;
}

void FUN_000333b8(void)

{
  // WARNING: Could not recover jumptable at 0x000333c8. Too many branches
  // WARNING: Treating indirect jump as call
  (*(code *)(&UNK_000333ca + *(short *)(&UNK_000333ca + (short)comp_state)))();
  return;
}

void FUN_00033b96(void)

{
  anim_item_t *unaff_A5;

  entity_reset(ENTITY_ID_ASHA);
  comp_unk_4 = 4;
  comp_pos_x.fixed.i = 0x80;
  comp_pos_y.fixed.i = 0xb0;
  comp_anim_base_offset = 0x18;
  comp_anim_b = 0x50;
  comp_unk_3 = 0x10;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  comp_state_a = 0;
  return;
}

void FUN_00033bce(void)

{
  anim_item_t *unaff_A5;

  entity_reset(ENTITY_ID_PEPELOGOO);
  DAT_ffffa32e = 4;
  component_pos_x_pepelogoo.fixed.i = 0xbf;
  component_pos_y_pepelogoo.fixed.i = 0xb0;
  DAT_ffffa63a = 0x18;
  DAT_ffffa63b = 0x4c;
  component_unknown_3_pepelogoo = 0x18;
  ecs_anim_unk_2(ENTITY_ID_PEPELOGOO, unaff_A5, 0);
  DAT_ffff9f1f = 8;
  entity_reset(0x30);
  uRamffffa35a = 4;
  uRamffffa152 = 0x80;
  uRamffffa256 = 0x80;
  uRamffffa666 = 0x18;
  uRamffffa667 = 0x52;
  uRamffff9f4c = 0x1e;
  ecs_anim_unk_2(0x30, unaff_A5, 0);
  return;
}

void FUN_00033c3a(void)

{
  DAT_ffffd916 = 0xe1;
  FUN_0001937a();
  return;
}

void FUN_00033c48(void)

{
  FUN_00033c56();
  FUN_00033c8c();
  return;
}

void FUN_00033c56(void)

{
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  entity_reset(unaff_A4);
  *(undefined2 *)((int)&comp_unk_4 + unaff_A4) = 4;
  *(undefined2 *)((int)&comp_pos_x + unaff_A4) = 0x80;
  *(undefined2 *)((int)&comp_pos_y + unaff_A4) = 0x10;
  (&comp_anim_base_offset)[unaff_A4] = 0x18;
  (&comp_anim_b)[unaff_A4] = 0x4e;
  *(undefined2 *)((int)&comp_unk_3 + unaff_A4) = 0xe;
  ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
  (&comp_state_a)[unaff_A4] = 0;
  return;
}

void FUN_00033c8c(void)

{
  short *psVar1;
  short *psVar2;
  entity_id_t e;
  anim_item_t *unaff_A5;

  e = ENTITY_ID_0C;
  psVar1 = (short *)&UNK_00033cf2;
  while (true) {
    if (-1 < (char)(&comp_has_func_maybe)[e]) {
      entity_reset(e);
    }
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x18;
    *(undefined2 *)((int)&comp_unk_4 + e) = 4;
    *(undefined2 *)((int)&comp_pos_x + e) = DAT_ffffa12a;
    *(undefined2 *)((int)&comp_pos_y + e) = DAT_ffffa22e;
    if (*psVar1 == 0)
      break;
    *(short *)((int)&comp_pos_x + e) =
        *psVar1 + *(short *)((int)&comp_pos_x + e);
    psVar2 = psVar1 + 2;
    *(short *)((int)&comp_pos_y + e) =
        psVar1[1] + *(short *)((int)&comp_pos_y + e);
    psVar1 = psVar1 + 3;
    (&comp_state_a)[e] = (entity_state_a_t)*psVar2;
    (&comp_anim_base_offset)[e] = 0x18;
    (&comp_anim_b)[e] = 0x4e;
    if (-1 < (char)(&comp_has_func_maybe)[e]) {
      ecs_anim_unk_2(e, unaff_A5, 0);
      *(undefined2 *)((int)&comp_vel[0].x + e) = 0;
      *(undefined2 *)((int)&comp_vel[0].y + e) = 0;
    }
    e = e + ENTITY_ID_PEPELOGOO;
  }
  return;
}

void FUN_00033d0c(void)

{
  undefined4 in_D0;
  undefined4 in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar1;

  uVar1 = CONCAT44(in_D0, in_D1);
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    (long)((ulonglong)uVar1 >> 0x20),
                    (long)uVar1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    comp_vel[2].y.raw = 0x100;
    ecs_update_pos_y(ENTITY_ID_08);
    uVar1 = FUN_00033c8c();
    unaff_A4 = ENTITY_ID_08;
  } while (DAT_ffffa22e != 0x60);
  return;
}

void FUN_00033d30(void)

{
  short sVar1;
  undefined2 extraout_D0u;
  long lVar2;
  long in_D1;
  long extraout_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;

  lVar2 = 0x10;
  do {
    exception_unk_0(unaff_A3,
                    unaff_A4,
                    unaff_A6,
                    lVar2,
                    in_D1,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    comp_vel[3].x.raw = -0x100;
    player_update_pos_x(0xc);
    comp_vel[4].x.raw = -0x100;
    player_update_pos_x(0x10);
    comp_vel[5].x.raw = 0x100;
    player_update_pos_x(0x14);
    unaff_A4 = 0x18;
    comp_vel[6].x.raw = 0x100;
    player_update_pos_x(0x18);
    sVar1 = (short)lVar2 + -1;
    lVar2 = CONCAT22(extraout_D0u, sVar1);
    in_D1 = extraout_D1;
  } while (sVar1 != 0);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00033d72(void)

{
  long in_D0;
  long in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  entity_id_t self;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar1;

  exception_unk_0(unaff_A3,
                  unaff_A4,
                  unaff_A6,
                  in_D0,
                  in_D1,
                  unaff_D2,
                  unaff_D3,
                  unaff_D4,
                  unaff_D5,
                  unaff_D6,
                  unaff_D7);
  ecs_anim_unk_2(ENTITY_ID_08, unaff_A5, 4);
  self = 0x20;
  uVar1 = FUN_00033da2();
  do {
    uVar1 = exception_unk_0(unaff_A3,
                            self,
                            unaff_A6,
                            (long)((ulonglong)uVar1 >> 0x20),
                            (long)uVar1,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    self = ENTITY_ID_08;
  } while (_DAT_ffffa53c != 0);
  FUN_00032a00();
  return;
}

void FUN_00033da2(void)

{
  short sVar1;
  short *psVar2;
  short *psVar3;
  entity_id_t unaff_A4;
  anim_item_t *unaff_A5;

  psVar2 = (short *)&UNK_00033df2;
  while (true) {
    entity_reset(unaff_A4);
    *(undefined2 *)((int)&comp_pos_x + unaff_A4) = DAT_ffffa12a;
    *(undefined2 *)((int)&comp_pos_y + unaff_A4) = DAT_ffffa22e;
    sVar1 = *psVar2;
    if (sVar1 == 0)
      break;
    *(undefined2 *)((int)&comp_unk_4 + unaff_A4) = 4;
    *(short *)((int)&comp_pos_x + unaff_A4) =
        sVar1 + *(short *)((int)&comp_pos_x + unaff_A4);
    psVar3 = psVar2 + 2;
    *(short *)((int)&comp_pos_y + unaff_A4) =
        psVar2[1] + *(short *)((int)&comp_pos_y + unaff_A4);
    psVar2 = psVar2 + 3;
    (&comp_state_a)[unaff_A4] = (entity_state_a_t)*psVar3;
    (&comp_anim_base_offset)[unaff_A4] = 0x18;
    (&comp_anim_b)[unaff_A4] = 0x52;
    ecs_anim_unk_2(unaff_A4, unaff_A5, 2);
    *(undefined2 *)((int)&comp_vel[0].x + unaff_A4) = 0;
    *(undefined2 *)((int)&comp_vel[0].y + unaff_A4) = 0;
    unaff_A4 = unaff_A4 + ENTITY_ID_PEPELOGOO;
  }
  return;
}

void FUN_00033e24(void)

{
  short sVar1;
  undefined2 extraout_D0u;
  long extraout_D0;
  long extraout_D0_00;
  long lVar2;
  long extraout_D1;
  long extraout_D1_00;
  long extraout_D1_01;
  long lVar3;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  script_ctx_t *unaff_A3;
  anim_item_t *unaff_A5;
  void *unaff_A6;
  undefined8 uVar4;

  ecs_anim_unk_2(ENTITY_ID_08, unaff_A5, 6);
  DAT_ffff9f23 = DAT_ffff9f23 | 8;
  comp_vel[2].x.raw = -0x100;
  comp_vel[2].y.raw = -0x300;
  lVar3 = extraout_D0;
  lVar2 = extraout_D1;
  do {
    exception_unk_0(unaff_A3,
                    ENTITY_ID_08,
                    unaff_A6,
                    lVar3,
                    lVar2,
                    unaff_D2,
                    unaff_D3,
                    unaff_D4,
                    unaff_D5,
                    unaff_D6,
                    unaff_D7);
    player_update_pos(8);
    comp_vel[2].y.raw = comp_vel[2].y.raw + 0x18;
    lVar3 = extraout_D0_00;
    lVar2 = extraout_D1_00;
  } while (DAT_ffffa12a != 0x30);
  ecs_anim_unk_2(ENTITY_ID_08, unaff_A5, 8);
  DAT_ffffa12a = 0x30;
  DAT_ffffa22e = 0xa0;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 4);
  comp_state_a = comp_state_a | ENTITY_STATE_A_08;
  lVar2 = CONCAT22(extraout_D0u, 0x1e);
  lVar3 = extraout_D1_01;
  do {
    uVar4 = exception_unk_0(unaff_A3,
                            ENTITY_ID_ASHA,
                            unaff_A6,
                            lVar2,
                            lVar3,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    lVar3 = (long)uVar4;
    sVar1 = (short)lVar2 + -1;
    lVar2 = CONCAT22((short)((ulonglong)uVar4 >> 0x30), sVar1);
  } while (sVar1 != 0);
  DAT_ffff9f23 = DAT_ffff9f23 & 0xf7;
  return;
}

void FUN_00034310(void)

{
  anim_item_t *unaff_A5;

  entity_reset(ENTITY_ID_ASHA);
  comp_unk_4 = 4;
  comp_pos_x.fixed.i = 0xa6;
  comp_pos_y.fixed.i = 0x69;
  comp_anim_base_offset = 0x18;
  comp_anim_b = 0x5c;
  ecs_anim_unk_2(ENTITY_ID_ASHA, unaff_A5, 0);
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_000349c8(void)

{
  word wVar1;
  short sVar2;
  word *pwVar3;
  undefined2 *puVar4;

  wVar1 = 0;
  pwVar3 = &vdp_hblank_effect_asha_p;
  do {
    *pwVar3 = wVar1;
    wVar1 = wVar1 - 1;
    pwVar3 = pwVar3 + 1;
  } while (wVar1 != 0xffff);
  sVar2 = 0xdf;
  puVar4 = &vdp_hblank_effect_pepelogoo_p;
  do {
    *puVar4 = 0;
    sVar2 = sVar2 + -1;
    puVar4 = puVar4 + 1;
  } while (sVar2 != -1);
  vdp_related_to_display_asha = 3;
  _DAT_ffffe572 = 0;
  _DAT_ffffe576 = 0;
  _DAT_ffffe57a = 0;
  _DAT_ffffe57e = 0;
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

void FUN_00034a00(void)

{
  int iVar1;
  undefined2 uVar2;
  short sVar3;
  undefined2 *puVar4;
  undefined2 *puVar5;

  iVar1 = _DAT_ffffe572 + 0x10000;
  _DAT_ffffe576 = _DAT_ffffe576 + 0x4000;
  _DAT_ffffe57a = _DAT_ffffe57a + 0x8000;
  _DAT_ffffe57e = _DAT_ffffe57e + 0x10000;
  _DAT_ffffe572 = (undefined2)((uint)iVar1 >> 0x10);
  uVar2 = _DAT_ffffe572;
  sVar3 = 0xf;
  puVar5 = (undefined2 *)&DAT_ffff9432;
  _DAT_ffffe572 = iVar1;
  do {
    puVar4 = puVar5;
    *puVar4 = uVar2;
    sVar3 = sVar3 + -1;
    puVar5 = puVar4 + 1;
  } while (sVar3 != -1);
  uVar2 = _DAT_ffffe576;
  sVar3 = 7;
  puVar5 = puVar4 + 0x51;
  do {
    puVar4 = puVar5 + 1;
    *puVar5 = uVar2;
    sVar3 = sVar3 + -1;
    puVar5 = puVar4;
  } while (sVar3 != -1);
  uVar2 = _DAT_ffffe57a;
  sVar3 = 0xf;
  do {
    puVar5 = puVar4 + 1;
    *puVar4 = uVar2;
    sVar3 = sVar3 + -1;
    puVar4 = puVar5;
  } while (sVar3 != -1);
  uVar2 = _DAT_ffffe57e;
  sVar3 = 7;
  do {
    *puVar5 = uVar2;
    sVar3 = sVar3 + -1;
    puVar5 = puVar5 + 1;
  } while (sVar3 != -1);
  vdp_related_to_display_asha = 2;
  return;
}

void FUN_00034a6c(void)

{
  short sVar1;
  short *psVar2;
  short *psVar3;
  entity_id_t e;
  anim_item_t *unaff_A5;

  e = ENTITY_ID_ASHA;
  psVar2 = (short *)&UNK_00034ab0;
  while (true) {
    entity_reset(e);
    sVar1 = *psVar2;
    if (sVar1 < 0)
      break;
    *(undefined2 *)((int)&comp_unk_4 + e) = 4;
    *(short *)((int)&comp_pos_x + e) = sVar1;
    *(short *)((int)&comp_pos_y + e) = psVar2[1];
    psVar3 = psVar2 + 3;
    (&comp_state_a)[e] = (entity_state_a_t)psVar2[2];
    (&comp_anim_base_offset)[e] = 0x18;
    (&comp_anim_b)[e] = 0x56;
    psVar2 = psVar2 + 4;
    sVar1 = *psVar3;
    *(undefined2 *)((int)&comp_unk_3 + e) = 0x10;
    ecs_anim_unk_2(e, unaff_A5, (byte)sVar1);
    e = e + ENTITY_ID_PEPELOGOO;
  }
  return;
}

char FUN_00034b00(void)

{
  uint in_D0;
  uint uVar1;
  long in_D1;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  char *pcVar2;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar3;
  short sStack_2;

  uVar1 = in_D0 & 0xffff00ff;
  if ((in_D0 & 0xff) == 0) {
    sStack_2 = 0x3c;
    do {
      uVar3 = exception_unk_0(unaff_A3,
                              unaff_A4,
                              unaff_A6,
                              uVar1,
                              in_D1,
                              unaff_D2,
                              unaff_D3,
                              unaff_D4,
                              unaff_D5,
                              unaff_D6,
                              unaff_D7);
      uVar1 = (uint)((ulonglong)uVar3 >> 0x20);
      in_D1 = (long)uVar3;
      sStack_2 = sStack_2 + -1;
    } while (sStack_2 != 0);
    uVar1 = 0;
  }
  pcVar2 =
      &UNK_00034b32 + *(short *)(&UNK_00034b32 + (short)((short)uVar1 * 2));
  while (true) {
    if (*pcVar2 < '\0')
      break;
    FUN_00034b62();
    pcVar2 = pcVar2 + 1;
  }
  return *pcVar2;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

long FUN_00034b62(void)

{
  long lVar1;
  short sVar2;
  undefined2 extraout_D1w;
  undefined4 unaff_D2;
  long lVar3;
  short sVar5;
  uint uVar4;
  ushort uVar6;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  undefined2 *extraout_A0;
  void *extraout_A1;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  undefined8 uVar7;
  short sStack_2;

  FUN_00001646();
  FUN_00001580();
  _DAT_ffff9812 = 0x8300;
  vdp_palettes_something();
  text_unk_1(&UNK_00034c32, extraout_A1);
  uncompress_and_copy_to_vram();
  DAT_ffff91ce._0_1_ = 0xff;
  vdp_set_vram_write_addr((void *)0xc000);
  lVar3 = CONCAT22((short)((uint)unaff_D2 >> 0x10), 0x780);
  FUN_00034c1c();
  sVar2 = 5;
  do {
    *extraout_A0 = extraout_D1w;
    sVar5 = 0x1d;
    do {
      *extraout_A0 = 0x780;
      sVar5 = sVar5 + -1;
    } while (sVar5 != -1);
    *extraout_A0 = extraout_D1w;
    uVar4 = 0x1f;
    do {
      *extraout_A0 = 0x780;
      uVar6 = (short)uVar4 - 1;
      uVar4 = (uint)uVar6;
    } while (uVar6 != 0xffff);
    sVar2 = sVar2 + -1;
  } while (sVar2 != -1);
  FUN_00034c1c();
  uVar7 = FUN_00034c78();
  DAT_ffff91ce._0_1_ = 0;
  sStack_2 = 0x14;
  do {
    uVar7 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar7 >> 0x20),
                            (long)uVar7,
                            lVar3,
                            uVar4,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    sStack_2 = sStack_2 + -1;
  } while (sStack_2 != 0);
  VDP_CTRL = 0x8b03;
  palette_set_fade_black_ease_out_all();
  DAT_ffffe586 = 0;
  _DAT_ffffe582 = 0x40;
  do {
    FUN_00034c3a();
    _DAT_ffffe584 = _DAT_ffffe584 + -1;
  } while (_DAT_ffffe584 != 0);
  _DAT_ffffe584 = 0x30;
  do {
    vdp_gfx_ptr_6 = vdp_gfx_ptr_6 + 1;
    uVar7 = FUN_00034c3a();
    lVar1 = (long)((ulonglong)uVar7 >> 0x20);
    _DAT_ffffe584 = _DAT_ffffe584 + -1;
  } while (_DAT_ffffe584 != 0);
  if (((undefined1)vdp_ctrl_mode_set_2_state & 0x40) != 0) {
    related_to_palette_maybe_1 = 0xff;
    related_to_palette_maybe_2 = 0;
    uVar7 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            lVar1,
                            (long)uVar7,
                            lVar3,
                            uVar4,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
    lVar1 = (long)((ulonglong)uVar7 >> 0x20);
  }
  return lVar1;
}

void FUN_00034c1c(void)

{
  short in_D0w;
  undefined2 in_D1w;
  undefined2 unaff_D2w;
  short sVar1;
  undefined2 *in_A0;

  do {
    sVar1 = 0x1f;
    do {
      *in_A0 = in_D1w;
      sVar1 = sVar1 + -1;
    } while (sVar1 != -1);
    sVar1 = 0x1f;
    do {
      *in_A0 = unaff_D2w;
      sVar1 = sVar1 + -1;
    } while (sVar1 != -1);
    in_D0w = in_D0w + -1;
  } while (in_D0w != -1);
  return;
}

// WARNING: This function may have set the stack pointer
// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined8 FUN_00034c3a(void)

{
  undefined2 uVar1;
  uint in_D0;
  undefined4 extraout_D0;
  undefined4 in_D1;
  undefined4 uVar2;
  undefined4 extraout_D1;
  undefined4 unaff_D2;
  uint unaff_D3;
  word wVar4;
  int iVar3;
  undefined4 unaff_D4;
  undefined4 unaff_D5;
  undefined4 unaff_D6;
  uint uVar5;
  ushort uVar6;
  undefined2 *puVar7;
  ushort *extraout_A0;
  undefined4 in_A1;
  undefined4 extraout_A1;
  undefined4 unaff_A2;
  undefined4 unaff_A3;
  undefined4 unaff_A4;
  short *psVar8;
  undefined4 unaff_A6;
  char in_XF;
  register_t a[5];
  register_t d[8];
  undefined4 uStack_3e;
  undefined4 uStack_3a;
  ushort uStack_6;
  ushort uStack_4;
  ushort uStack_2;

  uVar5 = 0x30;
  uVar2 = CONCAT22((short)((uint)in_D1 >> 0x10), _DAT_ffffe582);
  puVar7 = (undefined2 *)0xffff9472;
  if (_DAT_ffffe582 == 0) {
    do {
      *puVar7 = 0;
      uVar6 = (short)uVar5 - 1;
      uVar5 = (uint)uVar6;
      puVar7 = puVar7 + 1;
    } while (uVar6 != 0xffff);
  } else {
    in_D0 = (uint)DAT_ffffe586;
    DAT_ffffe586 = DAT_ffffe586 + 4;
    do {
      uStack_4 = 3;
      uStack_2 = 0x4c5a;
      wVar4 = angle_sin((angle_t)in_D0);
      in_D0 =
          CONCAT31((int3)((uint)extraout_D0 >> 8), (char)extraout_D0 + '\x14');
      iVar3 = (int)(short)wVar4 * (int)(short)extraout_D1;
      uVar6 = (ushort)((uint)iVar3 >> 0x10);
      unaff_D3 = CONCAT22(uVar6, (short)iVar3 << 2) << 0x10 | (uint)uVar6;
      *extraout_A0 = uVar6;
      uVar6 = (short)uVar5 - 1;
      uVar5 = (uint)uVar6;
    } while (uVar6 != 0xffff);
    in_XF = _DAT_ffffe582 == 0;
    _DAT_ffffe582 = _DAT_ffffe582 + -1;
    uVar2 = extraout_D1;
    in_A1 = extraout_A1;
  }
  vdp_related_to_display_asha = vdp_related_to_display_asha | 10;
  psVar8 = &DAT_ffff9104;
  uVar6 = uStack_4;
  if (DAT_ffff9100 != '\0') {
    uVar1 = (undefined2)(in_D0 >> 0x10);
    uStack_4 = (ushort)unaff_A6;
    uStack_6 = (ushort)((uint)unaff_A6 >> 0x10);
    if (DAT_ffff9102 == 0) {
      uStack_2 = (ushort)(byte)(in_XF << 4 | 4);
      uStack_3e = CONCAT22(uVar1, uStack_2);
      uStack_3a = uVar2;
      if (DAT_ffff9104 == -1) {
        DAT_ffff9104 = 1;
        DAT_ffff910c = (undefined8 *)&uStack_3e;
      }
      goto LAB_00000546;
    }
    in_D0 = CONCAT22(uVar1, DAT_ffff9102 * 2);
    psVar8 = (short *)(int)*(short *)((short)(DAT_ffff9102 * 2) + 0x468);
    if (*psVar8 == -1) {
      *psVar8 = 1;
    }
    *(ushort **)(psVar8 + 4) = &uStack_4;
    uVar6 = uStack_6;
    uStack_2 = uStack_4;
  }
  while (true) {
    uStack_4 = uVar6;
    DAT_ffff9100 = -1;
    DAT_ffff9102 = DAT_ffff9102 + 1;
    if (DAT_ffff9102 == 5)
      break;
    psVar8 = psVar8 + 8;
    uVar6 = uStack_4;
    if (*psVar8 == 1) {
      *psVar8 = -1;
      DAT_ffff9101 = 0;
      return CONCAT44(in_D0, uVar2);
    }
  }
  DAT_ffff9102 = 0;
  if (DAT_ffff9104 == 1) {
    DAT_ffff9104 = 0xffff;
    DAT_ffff9101 = 0;
    return *DAT_ffff910c;
  }
LAB_00000546:
  DAT_ffff9102 = 0;
  DAT_ffff9101 = 0;
  if (DAT_ffff96b0 != '\0') {
    DAT_ffff90fc = 0x564;
    a[3] = unaff_A4;
    a[4] = (register_t)&DAT_ffff9104;
    a[2] = unaff_A3;
    a[0] = in_A1;
    a[1] = unaff_A2;
    d[6] = unaff_D6;
    d[7] = uVar5;
    d[4] = unaff_D4;
    d[5] = unaff_D5;
    d[2] = unaff_D2;
    d[3] = unaff_D3;
    d[1] = uVar2;
    d[0] = 0;
    main_save_registers_into_stack(FUN_00000568, d, a);
  }
  do {
    // WARNING: Do nothing block with infinite loop
  } while (true);
}

char FUN_00034c78(void)

{
  char *in_A0;
  char *pcVar1;
  char *extraout_A0;

  do {
    pcVar1 = in_A0 + 2;
    while (true) {
      if (*pcVar1 == '\0')
        break;
      FUN_00034cb0();
      FUN_00034cb0();
      pcVar1 = extraout_A0;
    }
    in_A0 = pcVar1 + 2;
  } while (pcVar1[1] != '\0');
  DAT_ffffe584 = *in_A0;
  DAT_ffffe585 = pcVar1[3];
  return *pcVar1;
}

word FUN_00034cb0(void)

{
  word extraout_D0w;
  short extraout_D0w_00;
  word wVar1;
  void *unaff_D2w;
  word *in_A1;

  wVar1 = *in_A1;
  if (wVar1 != 0) {
    vdp_set_vram_write_addr(unaff_D2w);
    VDP_DATA = extraout_D0w;
    vdp_set_vram_write_addr((void *)((short)unaff_D2w + 0x80));
    wVar1 = extraout_D0w_00 + 0x10;
    VDP_DATA = wVar1;
  }
  return wVar1;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

script_t script_get(ushort script_offset)

{
  script_t *script_p;
  uint8_t pcb_version;

  _DAT_00fffffe = script_offset;
  script_p = &script_japanese_p;
  pcb_version = IO_PCBVER._1_1_;
  if ((pcb_version & IO_PCBVER_FLAG_INTERNATIONAL) != 0) {
    script_p = &script_english_p;
  }
  return *script_p + *(ushort *)(*script_p + (short)script_offset);
}

void **script_get_glyph_info_table(void)

{
  void ***glyph_info_pp;
  uint8_t pcb_version;

  glyph_info_pp = (void ***)&text_glyph_info_japanese_pp;
  pcb_version = IO_PCBVER._1_1_;
  if ((pcb_version & 0x80) != 0) {
    glyph_info_pp = (void ***)&text_glyph_info_english_pp;
  }
  return *glyph_info_pp;
}

// C checked, matches assembly.
//
// Get a character_p for the current locale.
//
// It's an array mapping a character below #b0 to its printable equivalent.

wchar16 *script_get_character_p(void)

{
  wchar16 **character_p;
  uint8_t pcb_version;

  character_p = (wchar16 **)&text_character_japanese_p;
  pcb_version = IO_PCBVER._1_1_;
  if ((pcb_version & IO_PCBVER_FLAG_INTERNATIONAL) != 0) {
    character_p = (wchar16 **)&text_character_english_p;
  }
  return *character_p;
}

void FUN_00154f90(void)

{
  undefined1 uVar1;

  uVar1 = IO_PCBVER._1_1_;
  return;
}

// C checked, matches assembly.
//
// Get a name_pp for the current locale.
//
// It's an offset array indexed by name category, pointing to offset arrays
// indexed by name id, pointing to name texts.

void *text_get_name_pp(void)

{
  void **text;
  byte pcb_version;

  text = &name_japanese_p;
  pcb_version = IO_PCBVER._1_1_;
  if ((pcb_version & IO_PCBVER_FLAG_INTERNATIONAL) != 0) {
    text = &name_english_p;
  }
  return (undefined *)*text;
}

// C checked, matches assembly.

byte *sram_get_save_offset_likely(uint save_index)

{
  return &SRAM_GAME_0 +
         ((game_save_related_likely & 0x3f) << 2 | save_index & 3) * 0x100;
}

// C checked, matches assembly.
// Maybe add a return type, may not be needed.

void sram_unk_2(uint save_index)

{
  short i;
  byte *save;

  save = sram_get_save_offset_likely(save_index * 2);
  i = 0x7f;
  do {
    *save = save[0x100];
    save = save + 2;
    i = i + -1;
  } while (i != -1);
  return;
}

uint sram_clear_save_likely(uint save_index)

{
  short i;
  byte *save;

  DAT_ffffcbb0 = DAT_ffffcbb0 & ~('\x01' << (save_index & 7));
  save = sram_get_save_offset_likely(save_index * 2);
  i = 0x7f;
  do {
    *save = 0;
    save[2] = 0;
    save = save + 4;
    i = i + -1;
  } while (i != -1);
  return save_index;
}

ulonglong sram_unk_1(uint save_index)

{
  byte *pbVar1;
  short sVar2;
  short i;
  byte bVar3;
  byte *save;
  byte *pbVar4;

  save = sram_get_save_offset_likely(save_index);
  sVar2 = 0;
  i = 0x7b;
  bVar3 = 0;
  pbVar1 = save + 2;
  do {
    pbVar4 = pbVar1;
    bVar3 = *pbVar4 + bVar3;
    sVar2 = (ushort)bVar3 + sVar2;
    i = i + -1;
    pbVar1 = pbVar4 + 2;
  } while (i != -1);
  return (ulonglong)CONCAT24(sVar2 + 0x1324,
                             (uint)CONCAT11(pbVar4[2], pbVar4[4]));
}

void FUN_00155e78(void)

{
  sram_unk_6();
  FUN_00028010();
  DAT_ffff91ce._0_1_ = 0xff;
  return;
}

undefined4 FUN_00155e88(void)

{
  undefined2 uVar1;

  sram_unk_6();
  if (DAT_fffffff9 != '\0') {
    FUN_00155f16();
    uVar1 = 99;
    if ((DAT_ffffcbb0 & 1) != 0) {
      uVar1 = FUN_00029630();
    }
    DAT_ffffddf6 = uVar1;
    FUN_00155f16();
    uVar1 = 99;
    if ((DAT_ffffcbb0 & 2) != 0) {
      uVar1 = FUN_00029630();
    }
    DAT_ffffddf8 = uVar1;
    FUN_000296dc();
    FUN_00029710();
    FUN_000296dc();
    FUN_00029710();
    FUN_00029686();
  }
  DAT_fffffff9 = 0;
  FUN_00029610();
  return 0x60;
}

void FUN_00155f16(void)

{
  uint uVar1;
  uint in_D0;
  short sVar2;
  undefined4 *in_A0;
  uint *extraout_A0;
  undefined1 *extraout_A0_00;
  byte *pbVar3;
  int extraout_A1;

  if ((DAT_ffffcbb0 & '\x01' << (in_D0 & 7)) == 0) {
    *in_A0 = 0;
    in_A0[1] = 0;
    *(undefined1 *)(in_A0 + 2) = 0;
    return;
  }
  pbVar3 = sram_get_save_offset_likely(
      CONCAT22((short)(in_D0 >> 0x10), (short)in_D0 * 2));
  uVar1 = CONCAT21(CONCAT11(pbVar3[2], pbVar3[4]), pbVar3[6]) & 0xfffff;
  *extraout_A0 = uVar1;
  *(byte *)(extraout_A0 + 1) = pbVar3[8];
  *(byte *)((int)extraout_A0 + 5) = pbVar3[10];
  *(byte *)((int)extraout_A0 + 6) = pbVar3[0xc];
  sVar2 = get_red_hearts(
      (ushort)CONCAT31((int3)(uVar1 >> 8), (pbVar3[0x1a] >> 4) + 0x10));
  *extraout_A0_00 = (char)sVar2;
  extraout_A0_00[1] = *(undefined1 *)(extraout_A1 + 0xf5);
  return;
}

void sram_unk_6(void)

{
  short sVar1;
  short extraout_D1w;
  short extraout_D1w_00;
  ulonglong uVar2;

  DAT_ffffcbb0 = '\0';
  DAT_fffffff9 = 0;
  uVar2 = sram_unk_1(0);
  sVar1 = (short)uVar2;
  if (sVar1 != (short)(uVar2 >> 0x20)) {
    uVar2 = sram_unk_1(1);
    if ((short)uVar2 != (short)(uVar2 >> 0x20)) {
      sram_clear_save_likely(0);
      if (DAT_fffffffa != 0) {
        DAT_fffffffa = 0;
        DAT_fffffff9 = 0xff;
        DAT_ffffdddf = 0xff;
      }
      goto LAB_00155fb8;
    }
    sram_unk_2(0);
    sVar1 = extraout_D1w;
  }
  if (sVar1 != DAT_fffffffa) {
    DAT_fffffff9 = 0xff;
  }
  DAT_ffffcbb0 = DAT_ffffcbb0 + '\x01';
  DAT_fffffffa = sVar1;
LAB_00155fb8:
  uVar2 = sram_unk_1(2);
  sVar1 = (short)uVar2;
  if (sVar1 != (short)(uVar2 >> 0x20)) {
    uVar2 = sram_unk_1(3);
    if ((short)uVar2 != (short)(uVar2 >> 0x20)) {
      sram_clear_save_likely(1);
      if (DAT_fffffffc == 0) {
        return;
      }
      DAT_ffffdddf = 0xff;
      DAT_fffffff9 = 0xff;
      DAT_fffffffc = 0;
      return;
    }
    sram_unk_2(1);
    sVar1 = extraout_D1w_00;
  }
  if (sVar1 != DAT_fffffffc) {
    DAT_fffffff9 = 0xff;
  }
  DAT_fffffffc = sVar1;
  DAT_ffffcbb0 = DAT_ffffcbb0 + '\x02';
  return;
}

void FUN_00156000(uint param_1)

{
  DAT_ffffcbb0 = DAT_ffffcbb0 | '\x01' << (param_1 & 7);
  FUN_0000c308();
  FUN_0000c3ee();
  FUN_0000c3ee();
  return;
}

// WARNING: Globals starting with '_' overlap smaller symbols at the same
// address

undefined8 FUN_00156010(void)

{
  byte bVar1;
  uint uVar2;
  uint uVar3;
  undefined2 extraout_D0u;
  undefined2 extraout_D0u_00;
  undefined2 extraout_D0u_01;
  long useless_d0;
  long extraout_D0;
  long extraout_D1;
  long lVar4;
  long extraout_D1_00;
  long extraout_D1_01;
  undefined2 uVar5;
  palette_id_flag_t unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  void *extraout_A1;
  void *extraout_A1_00;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  void *unaff_A6;
  bool bVar6;
  undefined8 uVar7;
  undefined6 uVar8;

  do {
    sram_unk_6();
    if (DAT_ffffcbb0 == '\0') {
      _DAT_ffff96bc = 0;
      lVar4 = extraout_D1_01;
      break;
    }
    _DAT_ffff96bc = CONCAT13(4, _DAT_ffff96bd);
    _DAT_ffff96bc = CONCAT31(_DAT_ffff96bc, 0xff);
    uVar8 = FUN_00028e9e();
    lVar4 = (long)uVar8;
    if ((short)((uint6)uVar8 >> 0x20) == 0)
      break;
    while (true) {
      DAT_ffff9156 = 0;
      audio_stop_all();
      FUN_00001646();
      FUN_00001580();
      vdp_set_window_position(0);
      DAT_ffff96ba = 0xff;
      DAT_ffff91ce._0_1_ = 0;
      VDP_CTRL = 0x856e;
      VDP_CTRL = 0x8c81;
      vdp_hblank_effect_asha_p = 0;
      vdp_gfx_ptr_5._0_2_ = 0;
      vdp_hblank_effect_pepelogoo_p = 0;
      vdp_gfx_ptr_6 = 0;
      vdp_related_to_display_asha = 0xf;
      clear_unk_1();
      FUN_0000ba1a();
      uVar7 = vdp_write_something_to_vram();
      exception_unk_0(unaff_A3,
                      unaff_A4,
                      unaff_A6,
                      (long)((ulonglong)uVar7 >> 0x20),
                      (long)uVar7,
                      unaff_D2,
                      unaff_D3,
                      unaff_D4,
                      unaff_D5,
                      unaff_D6,
                      unaff_D7);
      _DAT_ffff9812 = 0x73708182;
      vdp_palettes_something();
      uVar5 = (undefined2)(unaff_D2 >> 0x10);
      palette_set_fade(CONCAT22(uVar5, 0xf),
                       CONCAT22(extraout_D0u_00, 1),
                       '\0',
                       (palette_color_iter_t)0xffffffff);
      exception_unk_0(unaff_A3,
                      unaff_A4,
                      unaff_A6,
                      extraout_D0,
                      extraout_D1_00,
                      CONCAT22(uVar5, 0xf),
                      -1,
                      unaff_D4,
                      unaff_D5,
                      unaff_D6,
                      unaff_D7);
      FUN_00003ed0();
      FUN_00003f1c();
      _DAT_ffff9813 = CONCAT12(0x73, _DAT_ffff9814);
      vdp_palettes_something();
      palette_set_fade(CONCAT22(uVar5, 0xf),
                       CONCAT22(extraout_D0u_01, 1),
                       '\0',
                       (palette_color_iter_t)0xffffffff);
      uVar7 = FUN_000048de();
      exception_unk_0(unaff_A3,
                      unaff_A4,
                      unaff_A6,
                      (long)((ulonglong)uVar7 >> 0x20),
                      (long)uVar7,
                      CONCAT22(uVar5, 0xf),
                      -1,
                      unaff_D4,
                      unaff_D5,
                      unaff_D6,
                      unaff_D7);
      FUN_00001630();
      audio_play(SOUND_ID_F9);
      _DAT_ffff9812 = 0x73708182;
      vdp_palettes_something();
      unaff_D2 = CONCAT22(uVar5, 0xf);
      unaff_D3 = -1;
      palette_set_fade(unaff_D2,
                       CONCAT22(extraout_D0u, 1),
                       '\0',
                       (palette_color_iter_t)0xffffffff);
      FUN_000048de();
      DAT_ffff9156 = 0xff;
      PTR_ffff96c4 = BYTE_ARRAY_000048d4;
      FUN_000049a6();
      audio_play(SOUND_ID_RES_BTTN);
      DAT_ffff96c1 = 0;
      if ((char)(_DAT_ffff96bc >> 0x10) != '\x01')
        break;
      _DAT_ffff96bc = 0;
      menu_sound_test_sound_id = SOUND_ID_OVERTURE;
      DAT_ffff96c3 = 0;
      FUN_00001646();
      vdp_hblank_effect_asha_p = 0;
      vdp_gfx_ptr_5._0_2_ = 0;
      vdp_hblank_effect_pepelogoo_p = 0;
      vdp_gfx_ptr_6 = 0;
      vdp_related_to_display_asha = 0xf;
      DAT_ffff91ce._0_1_ = 0xff;
      text_unk_3();
      FUN_00001580();
      text_unk_2(extraout_A1);
      FUN_00005858(extraout_A1_00, unaff_A6);
      menu_sound_test_print_title(useless_d0, unaff_D2);
      DAT_ffff91ce._0_1_ = 0;
      menu_sound_test_update();
      FUN_00001630();
      while (true) {
        uVar7 = menu_sound_test_update();
        if ((((gamepad_pressed & GAMEPAD_A) != GAMEPAD_NONE) ||
             ((gamepad_pressed & GAMEPAD_B) != GAMEPAD_NONE)) ||
            ((gamepad_pressed & GAMEPAD_C) != GAMEPAD_NONE))
          break;
        exception_unk_0(unaff_A3,
                        unaff_A4,
                        unaff_A6,
                        (long)((ulonglong)uVar7 >> 0x20),
                        (long)uVar7,
                        unaff_D2,
                        -1,
                        unaff_D4,
                        unaff_D5,
                        unaff_D6,
                        unaff_D7);
      }
    }
    uVar2 = _DAT_ffff96bc >> 8 & 0xffff;
    _DAT_ffff96bc = uVar2 << 8;
    uVar3 = _DAT_ffff96bc;
    DAT_ffff96bd = (char)(uVar2 >> 8);
    bVar6 = DAT_ffff96bd != '\0';
    lVar4 = extraout_D1;
    _DAT_ffff96bc = uVar3;
  } while (bVar6);
  bVar1 = DAT_ffff96be & 3;
  _DAT_ffff96bc = CONCAT13(bVar1 | DAT_ffff96bc, _DAT_ffff96bd);
  DAT_ffff9154 = 0xffff;
  uVar7 = exception_unk_0(unaff_A3,
                          unaff_A4,
                          unaff_A6,
                          (uint)bVar1,
                          lVar4,
                          unaff_D2,
                          unaff_D3,
                          unaff_D4,
                          unaff_D5,
                          unaff_D6,
                          unaff_D7);
  return uVar7;
}

void FUN_00156030(void)

{
  undefined4 in_D0;
  short i;
  byte *pbVar1;
  undefined4 *puVar2;
  byte *pbVar3;
  undefined1 *puVar4;

  pbVar3 = sram_get_save_offset_likely(in_D0);
  i = 0x7f;
  pbVar1 = (byte *)&DAT_ffffcb30;
  do {
    *pbVar1 = *pbVar3;
    pbVar3 = pbVar3 + 2;
    i = i + -1;
    pbVar1 = pbVar1 + 1;
  } while (i != -1);
  i = 0x7f;
  puVar2 = &DAT_ffffcb30;
  puVar4 = &DAT_ffffff00;
  do {
    *puVar4 = *(undefined1 *)puVar2;
    i = i + -1;
    puVar2 = (undefined4 *)((int)puVar2 + 1);
    puVar4 = puVar4 + 1;
  } while (i != -1);
  return;
}

void FUN_00156044(void)

{
  undefined4 in_D0;
  short i;
  byte *pbVar1;
  undefined4 *puVar2;
  byte *pbVar3;
  undefined1 *puVar4;

  pbVar3 = sram_get_save_offset_likely(in_D0);
  i = 0x7f;
  pbVar1 = (byte *)&DAT_ffffcb30;
  do {
    *pbVar3 = *pbVar1;
    pbVar3 = pbVar3 + 2;
    i = i + -1;
    pbVar1 = pbVar1 + 1;
  } while (i != -1);
  i = 0x7f;
  puVar2 = &DAT_ffffcb30;
  puVar4 = &DAT_ffffff00;
  do {
    *puVar4 = *(undefined1 *)puVar2;
    i = i + -1;
    puVar2 = (undefined4 *)((int)puVar2 + 1);
    puVar4 = puVar4 + 1;
  } while (i != -1);
  return;
}

void FUN_00156068(void)

{
  short sVar1;
  undefined1 *puVar2;
  undefined4 *puVar3;

  sVar1 = 0x7f;
  puVar2 = &DAT_ffffff00;
  puVar3 = &DAT_ffffcb30;
  do {
    *(undefined1 *)puVar3 = *puVar2;
    sVar1 = sVar1 + -1;
    puVar2 = puVar2 + 1;
    puVar3 = (undefined4 *)((int)puVar3 + 1);
  } while (sVar1 != -1);
  return;
}

undefined4 main_unk_10(void)

{
  undefined4 extraout_D0;
  undefined4 uVar1;
  undefined4 extraout_D1;
  long lVar2;
  undefined4 extraout_D1_02;
  long unaff_D2;
  long unaff_D3;
  long unaff_D4;
  long unaff_D5;
  long unaff_D6;
  long unaff_D7;
  undefined4 extraout_A1;
  undefined4 extraout_A1_00;
  undefined4 extraout_A1_01;
  undefined4 unaff_A2;
  script_ctx_t *unaff_A3;
  entity_id_t unaff_A4;
  undefined4 unaff_A5;
  void *unaff_A6;
  undefined8 uVar3;
  register_t a[5];
  register_t a_00[5];
  register_t a_01[5];
  register_t d[8];
  register_t d_00[8];
  register_t d_01[8];
  undefined4 extraout_D1_00;
  undefined4 extraout_D1_01;

  DAT_ffff96b0 = 0;
  vdp_set_window_position(0);
  FUN_0000bce8();
  a_01[3] = unaff_A4;
  a_01[4] = unaff_A5;
  a_01[2] = (register_t)unaff_A3;
  a_01[0] = extraout_A1_01;
  a_01[1] = unaff_A2;
  d_01[6] = unaff_D6;
  d_01[7] = unaff_D7;
  d_01[4] = unaff_D4;
  d_01[5] = unaff_D5;
  d_01[2] = unaff_D2;
  d_01[3] = unaff_D3;
  d_01[0] = 4;
  d_01[1] = extraout_D1_02;
  main_save_registers_into_stack(main_unk_3, d_01, a_01);
  if ((DAT_ffff96bc & 4) == 0) {
    FUN_0000bd48();
  } else {
    FUN_00156068();
    DAT_ffffcc93 = 0;
  }
  vdp_write_something_to_vram();
  DAT_ffff9154 = 4;
  DAT_ffff9156 = 0xff;
  a[2] = (register_t)unaff_A3;
  a[3] = unaff_A4;
  a[4] = unaff_A5;
  a[0] = extraout_A1;
  a[1] = unaff_A2;
  d[0] = 3;
  d[1] = extraout_D1;
  d[4] = unaff_D4;
  d[5] = unaff_D5;
  d[6] = unaff_D6;
  d[7] = unaff_D7;
  d[2] = unaff_D2;
  d[3] = unaff_D3;
  main_save_registers_into_stack(main_unk_13, d, a);
  a_00[2] = (register_t)unaff_A3;
  a_00[3] = unaff_A4;
  a_00[4] = unaff_A5;
  a_00[0] = extraout_A1_00;
  a_00[1] = unaff_A2;
  d_00[0] = 2;
  d_00[1] = extraout_D1_00;
  d_00[4] = unaff_D4;
  d_00[5] = unaff_D5;
  d_00[6] = unaff_D6;
  d_00[7] = unaff_D7;
  d_00[2] = unaff_D2;
  d_00[3] = unaff_D3;
  main_save_registers_into_stack(main_unk_2, d_00, a_00);
  uVar3 = CONCAT44(extraout_D0, extraout_D1_01);
  while (true) {
    lVar2 = (long)uVar3;
    if (DAT_ffff9154 == -1) {
      uVar3 = FUN_00000472((ulong)unaff_A6, 3, lVar2);
      return (int)((ulonglong)uVar3 >> 0x20);
    }
    if (DAT_ffff9154 == 0)
      break;
    gamepad_held = gamepad_held_4;
    uVar3 = exception_unk_0(unaff_A3,
                            unaff_A4,
                            unaff_A6,
                            (long)((ulonglong)uVar3 >> 0x20),
                            lVar2,
                            unaff_D2,
                            unaff_D3,
                            unaff_D4,
                            unaff_D5,
                            unaff_D6,
                            unaff_D7);
  }
  FUN_00000472((ulong)unaff_A6, 3, lVar2);
  *(undefined2 *)((int)unaff_A6 + -2) = 0;
  uVar1 = main_unk_4();
  return uVar1;
}

byte FUN_001560b4(void)

{
  sram_unk_6();
  return DAT_ffffcbb0 & 3;
}

undefined4 game_over_maybe(byte *param_1)

{
  byte bVar1;
  undefined4 extraout_D0;

  something(param_1);
  bVar1 = IO_PCBVER._1_1_;
  if ((bVar1 & 0x80) == 0) {
    return extraout_D0;
  }
  game_over_maybe_1(unknown_data_1, 0x44800003, 0x17);
  game_over_maybe_1(tile_game_over_gfx, 0x50000002, 0x8f);
  return extraout_D0;
}

void game_over_maybe_1(void *param_1, size_t param_2, short param_3)

{
  undefined4 *puVar1;

  Ram00c00004 = param_2;
  do {
    // WARNING: Load size is inaccurate
    Ram00c00000 = *param_1;
    Ram00c00000 = *(undefined4 *)((int)param_1 + 4);
    puVar1 = (undefined4 *)((int)param_1 + 0xc);
    Ram00c00000 = *(undefined4 *)((int)param_1 + 8);
    param_1 = (void *)((int)param_1 + 0x10);
    Ram00c00000 = *puVar1;
    param_3 = param_3 + -1;
  } while (param_3 != -1);
  return;
}
