### RAW ASSEMBLY INSTRUCTIONS:

glabel update_action_ratings
/* 195258 80266978 0000302D */  daddu     $a2, $zero, $zero
/* 19525C 8026697C 2409003C */  addiu     $t1, $zero, 0x3C
/* 195260 80266980 24080005 */  addiu     $t0, $zero, 0x5
/* 195264 80266984 3C07800E */  lui       $a3, %hi(gBattleStatus)
/* 195268 80266988 24E7C070 */  addiu     $a3, $a3, %lo(gBattleStatus)
/* 19526C 8026698C 00E0282D */  daddu     $a1, $a3, $zero
.L80266990:
/* 195270 80266990 8CA400E0 */  lw        $a0, 0xE0($a1)
/* 195274 80266994 50800018 */  beql      $a0, $zero, .L802669F8
/* 195278 80266998 24C60001 */   addiu    $a2, $a2, 0x1
/* 19527C 8026699C 80820205 */  lb        $v0, 0x205($a0)
/* 195280 802669A0 14490007 */  bne       $v0, $t1, .L802669C0
/* 195284 802669A4 00000000 */   nop
/* 195288 802669A8 8C820200 */  lw        $v0, 0x200($a0)
/* 19528C 802669AC 10400003 */  beqz      $v0, .L802669BC
/* 195290 802669B0 00000000 */   nop
/* 195294 802669B4 8C42000C */  lw        $v0, 0xC($v0)
/* 195298 802669B8 AC400024 */  sw        $zero, 0x24($v0)
.L802669BC:
/* 19529C 802669BC 80820205 */  lb        $v0, 0x205($a0)
.L802669C0:
/* 1952A0 802669C0 14480007 */  bne       $v0, $t0, .L802669E0
/* 1952A4 802669C4 00000000 */   nop
/* 1952A8 802669C8 8C820200 */  lw        $v0, 0x200($a0)
/* 1952AC 802669CC 10400004 */  beqz      $v0, .L802669E0
/* 1952B0 802669D0 00000000 */   nop
/* 1952B4 802669D4 8C42000C */  lw        $v0, 0xC($v0)
/* 1952B8 802669D8 AC400018 */  sw        $zero, 0x18($v0)
/* 1952BC 802669DC AC800200 */  sw        $zero, 0x200($a0)
.L802669E0:
/* 1952C0 802669E0 80820205 */  lb        $v0, 0x205($a0)
/* 1952C4 802669E4 90830205 */  lbu       $v1, 0x205($a0)
/* 1952C8 802669E8 18400003 */  blez      $v0, .L802669F8
/* 1952CC 802669EC 24C60001 */   addiu    $a2, $a2, 0x1
/* 1952D0 802669F0 2462FFFF */  addiu     $v0, $v1, -0x1
/* 1952D4 802669F4 A0820205 */  sb        $v0, 0x205($a0)
.L802669F8:
/* 1952D8 802669F8 28C20018 */  slti      $v0, $a2, 0x18
/* 1952DC 802669FC 1440FFE4 */  bnez      $v0, .L80266990
/* 1952E0 80266A00 24A50004 */   addiu    $a1, $a1, 0x4
/* 1952E4 80266A04 8CE400D8 */  lw        $a0, 0xD8($a3)
/* 1952E8 80266A08 10800018 */  beqz      $a0, .L80266A6C
/* 1952EC 80266A0C 2402003C */   addiu    $v0, $zero, 0x3C
/* 1952F0 80266A10 80830205 */  lb        $v1, 0x205($a0)
/* 1952F4 80266A14 14620008 */  bne       $v1, $v0, .L80266A38
/* 1952F8 80266A18 24020005 */   addiu    $v0, $zero, 0x5
/* 1952FC 80266A1C 8C820200 */  lw        $v0, 0x200($a0)
/* 195300 80266A20 50400005 */  beql      $v0, $zero, .L80266A38
/* 195304 80266A24 24020005 */   addiu    $v0, $zero, 0x5
/* 195308 80266A28 8C42000C */  lw        $v0, 0xC($v0)
/* 19530C 80266A2C AC400024 */  sw        $zero, 0x24($v0)
/* 195310 80266A30 80830205 */  lb        $v1, 0x205($a0)
/* 195314 80266A34 24020005 */  addiu     $v0, $zero, 0x5
.L80266A38:
/* 195318 80266A38 14620007 */  bne       $v1, $v0, .L80266A58
/* 19531C 80266A3C 00000000 */   nop
/* 195320 80266A40 8C820200 */  lw        $v0, 0x200($a0)
/* 195324 80266A44 10400004 */  beqz      $v0, .L80266A58
/* 195328 80266A48 00000000 */   nop
/* 19532C 80266A4C 8C42000C */  lw        $v0, 0xC($v0)
/* 195330 80266A50 AC400018 */  sw        $zero, 0x18($v0)
/* 195334 80266A54 AC800200 */  sw        $zero, 0x200($a0)
.L80266A58:
/* 195338 80266A58 80820205 */  lb        $v0, 0x205($a0)
/* 19533C 80266A5C 90830205 */  lbu       $v1, 0x205($a0)
/* 195340 80266A60 18400002 */  blez      $v0, .L80266A6C
/* 195344 80266A64 2462FFFF */   addiu    $v0, $v1, -0x1
/* 195348 80266A68 A0820205 */  sb        $v0, 0x205($a0)
.L80266A6C:
/* 19534C 80266A6C 8CE400DC */  lw        $a0, 0xDC($a3)
/* 195350 80266A70 10800018 */  beqz      $a0, .L80266AD4
/* 195354 80266A74 2402003C */   addiu    $v0, $zero, 0x3C
/* 195358 80266A78 80830205 */  lb        $v1, 0x205($a0)
/* 19535C 80266A7C 14620008 */  bne       $v1, $v0, .L80266AA0
/* 195360 80266A80 24020005 */   addiu    $v0, $zero, 0x5
/* 195364 80266A84 8C820200 */  lw        $v0, 0x200($a0)
/* 195368 80266A88 50400005 */  beql      $v0, $zero, .L80266AA0
/* 19536C 80266A8C 24020005 */   addiu    $v0, $zero, 0x5
/* 195370 80266A90 8C42000C */  lw        $v0, 0xC($v0)
/* 195374 80266A94 AC400024 */  sw        $zero, 0x24($v0)
/* 195378 80266A98 80830205 */  lb        $v1, 0x205($a0)
/* 19537C 80266A9C 24020005 */  addiu     $v0, $zero, 0x5
.L80266AA0:
/* 195380 80266AA0 14620007 */  bne       $v1, $v0, .L80266AC0
/* 195384 80266AA4 00000000 */   nop
/* 195388 80266AA8 8C820200 */  lw        $v0, 0x200($a0)
/* 19538C 80266AAC 10400004 */  beqz      $v0, .L80266AC0
/* 195390 80266AB0 00000000 */   nop
/* 195394 80266AB4 8C42000C */  lw        $v0, 0xC($v0)
/* 195398 80266AB8 AC400018 */  sw        $zero, 0x18($v0)
/* 19539C 80266ABC AC800200 */  sw        $zero, 0x200($a0)
.L80266AC0:
/* 1953A0 80266AC0 80820205 */  lb        $v0, 0x205($a0)
/* 1953A4 80266AC4 90830205 */  lbu       $v1, 0x205($a0)
/* 1953A8 80266AC8 18400002 */  blez      $v0, .L80266AD4
/* 1953AC 80266ACC 2462FFFF */   addiu    $v0, $v1, -0x1
/* 1953B0 80266AD0 A0820205 */  sb        $v0, 0x205($a0)
.L80266AD4:
/* 1953B4 80266AD4 03E00008 */  jr        $ra
/* 1953B8 80266AD8 00000000 */   nop

### DECOMPILED C INSTRUCTIONS:

void update_action_ratings(void) {
    BattleStatus* battleStatus = &gBattleStatus;
    Actor* actor;
    s32 i;

    for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) {
        actor = gBattleStatus.enemyActors[i];
        if (actor != NULL) {
            if (actor->actionRatingTime == 60) {
                if (actor->attackResultEffect != NULL) {
                    actor->attackResultEffect->data.attackResultText->isVisible = FALSE;
                }
            }
            if (actor->actionRatingTime == 5) {
                if (actor->attackResultEffect != NULL) {
                    actor->attackResultEffect->data.attackResultText->timeLeft = 0;
                    actor->attackResultEffect = NULL;
                }
            }
            if (actor->actionRatingTime > 0) {
                actor->actionRatingTime--;
            }
        }
    }

    actor = battleStatus->playerActor;
    if (actor != NULL) {
        if (actor->actionRatingTime == 60) {
            if (actor->attackResultEffect != NULL) {
                actor->attackResultEffect->data.attackResultText->isVisible = FALSE;
            }
        }
        if (actor->actionRatingTime == 5) {
            if (actor->attackResultEffect != NULL) {
                actor->attackResultEffect->data.attackResultText->timeLeft = 0;
                actor->attackResultEffect = NULL;
            }
        }
        if (actor->actionRatingTime > 0) {
            actor->actionRatingTime--;
        }
    }

    actor = battleStatus->partnerActor;
    if (actor != NULL) {
        if (actor->actionRatingTime == 60) {
            if (actor->attackResultEffect != NULL) {
                actor->attackResultEffect->data.attackResultText->isVisible = FALSE;
            }
        }
        if (actor->actionRatingTime == 5) {
            if (actor->attackResultEffect != NULL) {
                actor->attackResultEffect->data.attackResultText->timeLeft = 0;
                actor->attackResultEffect = NULL;
            }
        }
        if (actor->actionRatingTime > 0) {
            actor->actionRatingTime--;
        }
    }
}


### RAW ASSEMBLY INSTRUCTIONS:

glabel basic_ai_chase_init
/* 2537C 80049F7C 27BDFFD0 */  addiu     $sp, $sp, -0x30
/* 25380 80049F80 AFB40020 */  sw        $s4, 0x20($sp)
/* 25384 80049F84 0080A02D */  daddu     $s4, $a0, $zero
/* 25388 80049F88 AFBF0024 */  sw        $ra, 0x24($sp)
/* 2538C 80049F8C AFB3001C */  sw        $s3, 0x1C($sp)
/* 25390 80049F90 AFB20018 */  sw        $s2, 0x18($sp)
/* 25394 80049F94 AFB10014 */  sw        $s1, 0x14($sp)
/* 25398 80049F98 AFB00010 */  sw        $s0, 0x10($sp)
/* 2539C 80049F9C F7B40028 */  sdc1      $f20, 0x28($sp)
/* 253A0 80049FA0 8E930148 */  lw        $s3, 0x148($s4)
/* 253A4 80049FA4 86640008 */  lh        $a0, 0x8($s3)
/* 253A8 80049FA8 0C00EABB */  jal       get_npc_unsafe
/* 253AC 80049FAC 00A0902D */   daddu    $s2, $a1, $zero
/* 253B0 80049FB0 3C04800F */  lui       $a0, %hi(gPlayerStatusPtr)
/* 253B4 80049FB4 8C847B30 */  lw        $a0, %lo(gPlayerStatusPtr)($a0)
/* 253B8 80049FB8 908300B4 */  lbu       $v1, 0xB4($a0)
/* 253BC 80049FBC 0040802D */  daddu     $s0, $v0, $zero
/* 253C0 80049FC0 2462FFFD */  addiu     $v0, $v1, -0x3
/* 253C4 80049FC4 2C420003 */  sltiu     $v0, $v0, 0x3
/* 253C8 80049FC8 14400006 */  bnez      $v0, .L80049FE4
/* 253CC 80049FCC 0000882D */   daddu    $s1, $zero, $zero
/* 253D0 80049FD0 00031600 */  sll       $v0, $v1, 24
/* 253D4 80049FD4 00021603 */  sra       $v0, $v0, 24
/* 253D8 80049FD8 24030008 */  addiu     $v1, $zero, 0x8
/* 253DC 80049FDC 1443000F */  bne       $v0, $v1, .L8004A01C
/* 253E0 80049FE0 00000000 */   nop
.L80049FE4:
/* 253E4 80049FE4 C60C0038 */  lwc1      $f12, 0x38($s0)
/* 253E8 80049FE8 C60E0040 */  lwc1      $f14, 0x40($s0)
/* 253EC 80049FEC 8C860028 */  lw        $a2, 0x28($a0)
/* 253F0 80049FF0 0C00A7B5 */  jal       dist2D
/* 253F4 80049FF4 8C870030 */   lw       $a3, 0x30($a0)
/* 253F8 80049FF8 860200A6 */  lh        $v0, 0xA6($s0)
/* 253FC 80049FFC 46000021 */  cvt.d.s   $f0, $f0
/* 25400 8004A000 44821000 */  mtc1      $v0, $f2
/* 25404 8004A004 00000000 */  nop
/* 25408 8004A008 468010A1 */  cvt.d.w   $f2, $f2
/* 2540C 8004A00C 4622003C */  c.lt.d    $f0, $f2
/* 25410 8004A010 00000000 */  nop
/* 25414 8004A014 45030001 */  bc1tl     .L8004A01C
/* 25418 8004A018 24110001 */   addiu    $s1, $zero, 0x1
.L8004A01C:
/* 2541C 8004A01C 56200031 */  bnel      $s1, $zero, .L8004A0E4
/* 25420 8004A020 A600008E */   sh       $zero, 0x8E($s0)
/* 25424 8004A024 C60C0038 */  lwc1      $f12, 0x38($s0)
/* 25428 8004A028 3C02800F */  lui       $v0, %hi(gPlayerStatusPtr)
/* 2542C 8004A02C 8C427B30 */  lw        $v0, %lo(gPlayerStatusPtr)($v0)
/* 25430 8004A030 C60E0040 */  lwc1      $f14, 0x40($s0)
/* 25434 8004A034 8C460028 */  lw        $a2, 0x28($v0)
/* 25438 8004A038 0C00A720 */  jal       atan2
/* 2543C 8004A03C 8C470030 */   lw       $a3, 0x30($v0)
/* 25440 8004A040 46000506 */  mov.s     $f20, $f0
/* 25444 8004A044 C60C000C */  lwc1      $f12, 0xC($s0)
/* 25448 8004A048 0C00A70A */  jal       get_clamped_angle_diff
/* 2544C 8004A04C 4600A386 */   mov.s    $f14, $f20
/* 25450 8004A050 46000086 */  mov.s     $f2, $f0
/* 25454 8004A054 8E42001C */  lw        $v0, 0x1C($s2)
/* 25458 8004A058 46001005 */  abs.s     $f0, $f2
/* 2545C 8004A05C 44822000 */  mtc1      $v0, $f4
/* 25460 8004A060 00000000 */  nop
/* 25464 8004A064 46802120 */  cvt.s.w   $f4, $f4
/* 25468 8004A068 4600203C */  c.lt.s    $f4, $f0
/* 2546C 8004A06C 00000000 */  nop
/* 25470 8004A070 4500000D */  bc1f      .L8004A0A8
/* 25474 8004A074 00000000 */   nop
/* 25478 8004A078 44800000 */  mtc1      $zero, $f0
/* 2547C 8004A07C C614000C */  lwc1      $f20, 0xC($s0)
/* 25480 8004A080 4600103C */  c.lt.s    $f2, $f0
/* 25484 8004A084 00000000 */  nop
/* 25488 8004A088 45000006 */  bc1f      .L8004A0A4
/* 2548C 8004A08C 00021023 */   negu     $v0, $v0
/* 25490 8004A090 44820000 */  mtc1      $v0, $f0
/* 25494 8004A094 00000000 */  nop
/* 25498 8004A098 46800020 */  cvt.s.w   $f0, $f0
/* 2549C 8004A09C 0801282A */  j         .L8004A0A8
/* 254A0 8004A0A0 4600A500 */   add.s    $f20, $f20, $f0
.L8004A0A4:
/* 254A4 8004A0A4 4604A500 */  add.s     $f20, $f20, $f4
.L8004A0A8:
/* 254A8 8004A0A8 0C00A6C9 */  jal       clamp_angle
/* 254AC 8004A0AC 4600A306 */   mov.s    $f12, $f20
/* 254B0 8004A0B0 E600000C */  swc1      $f0, 0xC($s0)
/* 254B4 8004A0B4 8E440020 */  lw        $a0, 0x20($s2)
/* 254B8 8004A0B8 000417C2 */  srl       $v0, $a0, 31
/* 254BC 8004A0BC 00822021 */  addu      $a0, $a0, $v0
/* 254C0 8004A0C0 00042043 */  sra       $a0, $a0, 1
/* 254C4 8004A0C4 0C00A67F */  jal       rand_int
/* 254C8 8004A0C8 24840001 */   addiu    $a0, $a0, 0x1
/* 254CC 8004A0CC 8E430020 */  lw        $v1, 0x20($s2)
/* 254D0 8004A0D0 000327C2 */  srl       $a0, $v1, 31
/* 254D4 8004A0D4 00641821 */  addu      $v1, $v1, $a0
/* 254D8 8004A0D8 00031843 */  sra       $v1, $v1, 1
/* 254DC 8004A0DC 00621821 */  addu      $v1, $v1, $v0
/* 254E0 8004A0E0 A603008E */  sh        $v1, 0x8E($s0)
.L8004A0E4:
/* 254E4 8004A0E4 8E6200CC */  lw        $v0, 0xCC($s3)
/* 254E8 8004A0E8 8C42000C */  lw        $v0, 0xC($v0)
/* 254EC 8004A0EC AE020028 */  sw        $v0, 0x28($s0)
/* 254F0 8004A0F0 C6400018 */  lwc1      $f0, 0x18($s2)
/* 254F4 8004A0F4 2402000D */  addiu     $v0, $zero, 0xD
/* 254F8 8004A0F8 E6000018 */  swc1      $f0, 0x18($s0)
/* 254FC 8004A0FC AE820070 */  sw        $v0, 0x70($s4)
/* 25500 8004A100 8FBF0024 */  lw        $ra, 0x24($sp)
/* 25504 8004A104 8FB40020 */  lw        $s4, 0x20($sp)
/* 25508 8004A108 8FB3001C */  lw        $s3, 0x1C($sp)
/* 2550C 8004A10C 8FB20018 */  lw        $s2, 0x18($sp)
/* 25510 8004A110 8FB10014 */  lw        $s1, 0x14($sp)
/* 25514 8004A114 8FB00010 */  lw        $s0, 0x10($sp)
/* 25518 8004A118 D7B40028 */  ldc1      $f20, 0x28($sp)
/* 2551C 8004A11C 03E00008 */  jr        $ra
/* 25520 8004A120 27BD0030 */   addiu    $sp, $sp, 0x30

### DECOMPILED C INSTRUCTIONS:

void basic_ai_chase_init(Evt* script, MobileAISettings* npcAISettings, EnemyDetectVolume* territory) {
    Enemy* enemy = script->owner1.enemy;
    Npc* npc = get_npc_unsafe(enemy->npcID);
    s32 skipTurnAround = FALSE;

    if ((gPlayerStatusPtr->actionState == ACTION_STATE_JUMP || gPlayerStatusPtr->actionState == ACTION_STATE_BOUNCE ||
        gPlayerStatusPtr->actionState == ACTION_STATE_HOP || gPlayerStatusPtr->actionState == ACTION_STATE_FALLING) &&
        (f64)dist2D(npc->pos.x, npc->pos.z, gPlayerStatusPtr->position.x, gPlayerStatusPtr->position.z) < npc->collisionDiameter)
    {
        skipTurnAround = TRUE;
    }

    if (!skipTurnAround) {
        f32 angle = atan2(npc->pos.x, npc->pos.z, gPlayerStatusPtr->position.x, gPlayerStatusPtr->position.z);
        f32 deltaAngleToPlayer = get_clamped_angle_diff(npc->yaw, angle);

        if (npcAISettings->chaseTurnRate < fabsf(deltaAngleToPlayer)) {
            angle = npc->yaw;
            if (deltaAngleToPlayer < 0.0f) {
                angle += -npcAISettings->chaseTurnRate;
            } else {
                angle += npcAISettings->chaseTurnRate;
            }
        }
        npc->yaw = clamp_angle(angle);
        npc->duration = (npcAISettings->chaseUpdateInterval / 2) + rand_int((npcAISettings->chaseUpdateInterval / 2) + 1);
    } else {
        npc->duration = 0;
    }

    npc->currentAnim = enemy->animList[ENEMY_ANIM_INDEX_CHASE];
    npc->moveSpeed = npcAISettings->chaseSpeed;
    script->AI_TEMP_STATE = AI_STATE_CHASE;
}


### RAW ASSEMBLY INSTRUCTIONS:

glabel step_entity_model_commandlist
/* B76B8 80120FB8 27BDFFE8 */  addiu     $sp, $sp, -0x18
/* B76BC 80120FBC 0080302D */  daddu     $a2, $a0, $zero
/* B76C0 80120FC0 AFBF0010 */  sw        $ra, 0x10($sp)
/* B76C4 80120FC4 8CC50010 */  lw        $a1, 0x10($a2)
/* B76C8 80120FC8 8CA30000 */  lw        $v1, 0x0($a1)
/* B76CC 80120FCC 2C620008 */  sltiu     $v0, $v1, 0x8
/* B76D0 80120FD0 10400057 */  beqz      $v0, .L80121130
/* B76D4 80120FD4 24A50004 */   addiu    $a1, $a1, 0x4
/* B76D8 80120FD8 00031080 */  sll       $v0, $v1, 2
/* B76DC 80120FDC 3C018015 */  lui       $at, %hi(jtbl_801500B0)
/* B76E0 80120FE0 00220821 */  addu      $at, $at, $v0
/* B76E4 80120FE4 8C2200B0 */  lw        $v0, %lo(jtbl_801500B0)($at)
/* B76E8 80120FE8 00400008 */  jr        $v0
/* B76EC 80120FEC 00000000 */   nop
glabel .L80120FF0
/* B76F0 80120FF0 0C048BA5 */  jal       free_entity_model_by_ref
/* B76F4 80120FF4 00C0202D */   daddu    $a0, $a2, $zero
/* B76F8 80120FF8 0804844D */  j         .L80121134
/* B76FC 80120FFC 24020001 */   addiu    $v0, $zero, 0x1
glabel .L80121000
/* B7700 80121000 8CA20000 */  lw        $v0, 0x0($a1)
/* B7704 80121004 44821000 */  mtc1      $v0, $f2
/* B7708 80121008 00000000 */  nop
/* B770C 8012100C 468010A1 */  cvt.d.w   $f2, $f2
/* B7710 80121010 04410006 */  bgez      $v0, .L8012102C
/* B7714 80121014 24A50004 */   addiu    $a1, $a1, 0x4
/* B7718 80121018 3C0141F0 */  lui       $at, (0x41F00000 >> 16)
/* B771C 8012101C 44810800 */  mtc1      $at, $f1
/* B7720 80121020 44800000 */  mtc1      $zero, $f0
/* B7724 80121024 00000000 */  nop
/* B7728 80121028 46201080 */  add.d     $f2, $f2, $f0
.L8012102C:
/* B772C 8012102C 46201020 */  cvt.s.d   $f0, $f2
/* B7730 80121030 E4C00008 */  swc1      $f0, 0x8($a2)
/* B7734 80121034 8CA20000 */  lw        $v0, 0x0($a1)
/* B7738 80121038 24A50004 */  addiu     $a1, $a1, 0x4
/* B773C 8012103C ACC50010 */  sw        $a1, 0x10($a2)
/* B7740 80121040 0804844C */  j         .L80121130
/* B7744 80121044 ACC20014 */   sw       $v0, 0x14($a2)
glabel .L80121048
/* B7748 80121048 8CC30058 */  lw        $v1, 0x58($a2)
/* B774C 8012104C 24020001 */  addiu     $v0, $zero, 0x1
/* B7750 80121050 0804844D */  j         .L80121134
/* B7754 80121054 ACC30010 */   sw       $v1, 0x10($a2)
glabel .L80121058
/* B7758 80121058 24020001 */  addiu     $v0, $zero, 0x1
/* B775C 8012105C ACC50058 */  sw        $a1, 0x58($a2)
/* B7760 80121060 0804844D */  j         .L80121134
/* B7764 80121064 ACC50010 */   sw       $a1, 0x10($a2)
glabel .L80121068
/* B7768 80121068 90A30003 */  lbu       $v1, 0x3($a1)
/* B776C 8012106C 24A50004 */  addiu     $a1, $a1, 0x4
/* B7770 80121070 24020001 */  addiu     $v0, $zero, 0x1
/* B7774 80121074 ACC50010 */  sw        $a1, 0x10($a2)
/* B7778 80121078 0804844D */  j         .L80121134
/* B777C 8012107C A0C30004 */   sb       $v1, 0x4($a2)
glabel .L80121080
/* B7780 80121080 8CA40000 */  lw        $a0, 0x0($a1)
/* B7784 80121084 24A50004 */  addiu     $a1, $a1, 0x4
/* B7788 80121088 8CC30000 */  lw        $v1, 0x0($a2)
/* B778C 8012108C 24020001 */  addiu     $v0, $zero, 0x1
/* B7790 80121090 ACC50010 */  sw        $a1, 0x10($a2)
/* B7794 80121094 00641825 */  or        $v1, $v1, $a0
/* B7798 80121098 0804844D */  j         .L80121134
/* B779C 8012109C ACC30000 */   sw       $v1, 0x0($a2)
glabel .L801210A0
/* B77A0 801210A0 8CA40000 */  lw        $a0, 0x0($a1)
/* B77A4 801210A4 24A50004 */  addiu     $a1, $a1, 0x4
/* B77A8 801210A8 8CC30000 */  lw        $v1, 0x0($a2)
/* B77AC 801210AC 24020001 */  addiu     $v0, $zero, 0x1
/* B77B0 801210B0 ACC50010 */  sw        $a1, 0x10($a2)
/* B77B4 801210B4 00042027 */  nor       $a0, $zero, $a0
/* B77B8 801210B8 00641824 */  and       $v1, $v1, $a0
/* B77BC 801210BC 0804844D */  j         .L80121134
/* B77C0 801210C0 ACC30000 */   sw       $v1, 0x0($a2)
glabel .L801210C4
/* B77C4 801210C4 8CA20000 */  lw        $v0, 0x0($a1)
/* B77C8 801210C8 8CC30014 */  lw        $v1, 0x14($a2)
/* B77CC 801210CC 44821000 */  mtc1      $v0, $f2
/* B77D0 801210D0 00000000 */  nop
/* B77D4 801210D4 468010A1 */  cvt.d.w   $f2, $f2
/* B77D8 801210D8 04410006 */  bgez      $v0, .L801210F4
/* B77DC 801210DC 24A50004 */   addiu    $a1, $a1, 0x4
/* B77E0 801210E0 3C0141F0 */  lui       $at, (0x41F00000 >> 16)
/* B77E4 801210E4 44810800 */  mtc1      $at, $f1
/* B77E8 801210E8 44800000 */  mtc1      $zero, $f0
/* B77EC 801210EC 00000000 */  nop
/* B77F0 801210F0 46201080 */  add.d     $f2, $f2, $f0
.L801210F4:
/* B77F4 801210F4 46201020 */  cvt.s.d   $f0, $f2
/* B77F8 801210F8 E4C00008 */  swc1      $f0, 0x8($a2)
/* B77FC 801210FC 8CA20000 */  lw        $v0, 0x0($a1)
/* B7800 80121100 24A50004 */  addiu     $a1, $a1, 0x4
/* B7804 80121104 AC620000 */  sw        $v0, 0x0($v1)
/* B7808 80121108 8CA20000 */  lw        $v0, 0x0($a1)
/* B780C 8012110C 24A50004 */  addiu     $a1, $a1, 0x4
/* B7810 80121110 AC620004 */  sw        $v0, 0x4($v1)
/* B7814 80121114 8CA20000 */  lw        $v0, 0x0($a1)
/* B7818 80121118 24A50004 */  addiu     $a1, $a1, 0x4
/* B781C 8012111C AC620008 */  sw        $v0, 0x8($v1)
/* B7820 80121120 8CA20000 */  lw        $v0, 0x0($a1)
/* B7824 80121124 24A50004 */  addiu     $a1, $a1, 0x4
/* B7828 80121128 AC62000C */  sw        $v0, 0xC($v1)
/* B782C 8012112C ACC50010 */  sw        $a1, 0x10($a2)
.L80121130:
/* B7830 80121130 0000102D */  daddu     $v0, $zero, $zero
.L80121134:
/* B7834 80121134 8FBF0010 */  lw        $ra, 0x10($sp)
/* B7838 80121138 03E00008 */  jr        $ra
/* B783C 8012113C 27BD0018 */   addiu    $sp, $sp, 0x18

### DECOMPILED C INSTRUCTIONS:

s32 step_entity_model_commandlist(EntityModel* entityModel) {
    SpriteRasterInfo* imageData;

    u32* curPos = *entityModel->cmdListReadPos;
    switch (*curPos++) {
        case 0: // kill model
            free_entity_model_by_ref(entityModel);
            return 1;
        case 1: // set display list ptr
            entityModel->nextFrameTime = (f32) *curPos++;
            entityModel->gfx.displayList = (Gfx*) *curPos++;
            entityModel->cmdListReadPos = (EntityModelScript*) curPos;
            break;
        case 2: // restore saved position
            entityModel->cmdListReadPos = entityModel->cmdListSavedPos;
            return 1;
        case 3: // set saved position
            entityModel->cmdListReadPos = entityModel->cmdListSavedPos = (EntityModelScript*) curPos;
            return 1;
        case 4: // set render mode
            entityModel->renderMode = *curPos++;
            entityModel->cmdListReadPos = (EntityModelScript*) curPos;
            return 1;
        case 5: // set flags
            entityModel->flags |= *curPos++;
            entityModel->cmdListReadPos = (EntityModelScript*) curPos;
            return 1;
        case 6: // clear flags
            entityModel->flags &= ~*curPos++;
            entityModel->cmdListReadPos = (EntityModelScript*) curPos;
            return 1;
        case 7: // set image data
            imageData = entityModel->gfx.imageData;
            entityModel->nextFrameTime = *curPos++;
            imageData->raster = (u8*)*curPos++;
            imageData->defaultPal = (PAL_PTR) *curPos++;
            imageData->width = *curPos++;
            imageData->height = *curPos++;
            entityModel->cmdListReadPos = (EntityModelScript*) curPos;
            break;
    }
    return 0;
}


### RAW ASSEMBLY INSTRUCTIONS:

glabel au_amb_manager_update
/* 2C5BC 800511BC 27BDFFD8 */  addiu     $sp, $sp, -0x28
/* 2C5C0 800511C0 AFB10014 */  sw        $s1, 0x14($sp)
/* 2C5C4 800511C4 0080882D */  daddu     $s1, $a0, $zero
/* 2C5C8 800511C8 0000382D */  daddu     $a3, $zero, $zero
/* 2C5CC 800511CC 24080001 */  addiu     $t0, $zero, 0x1
/* 2C5D0 800511D0 00E0302D */  daddu     $a2, $a3, $zero
/* 2C5D4 800511D4 240507B4 */  addiu     $a1, $zero, 0x7B4
/* 2C5D8 800511D8 AFBF0024 */  sw        $ra, 0x24($sp)
/* 2C5DC 800511DC AFB40020 */  sw        $s4, 0x20($sp)
/* 2C5E0 800511E0 AFB3001C */  sw        $s3, 0x1C($sp)
/* 2C5E4 800511E4 AFB20018 */  sw        $s2, 0x18($sp)
/* 2C5E8 800511E8 AFB00010 */  sw        $s0, 0x10($sp)
.L800511EC:
/* 2C5EC 800511EC 02252021 */  addu      $a0, $s1, $a1
/* 2C5F0 800511F0 90820003 */  lbu       $v0, 0x3($a0)
/* 2C5F4 800511F4 54480008 */  bnel      $v0, $t0, .L80051218
/* 2C5F8 800511F8 24C60048 */   addiu    $a2, $a2, 0x48
/* 2C5FC 800511FC 8E220000 */  lw        $v0, 0x0($s1)
/* 2C600 80051200 00461021 */  addu      $v0, $v0, $a2
/* 2C604 80051204 90431365 */  lbu       $v1, 0x1365($v0)
/* 2C608 80051208 92220022 */  lbu       $v0, 0x22($s1)
/* 2C60C 8005120C 54620001 */  bnel      $v1, $v0, .L80051214
/* 2C610 80051210 AC800000 */   sw       $zero, 0x0($a0)
.L80051214:
/* 2C614 80051214 24C60048 */  addiu     $a2, $a2, 0x48
.L80051218:
/* 2C618 80051218 24E70001 */  addiu     $a3, $a3, 0x1
/* 2C61C 8005121C 2CE20010 */  sltiu     $v0, $a3, 0x10
/* 2C620 80051220 1440FFF2 */  bnez      $v0, .L800511EC
/* 2C624 80051224 24A50008 */   addiu    $a1, $a1, 0x8
/* 2C628 80051228 0000982D */  daddu     $s3, $zero, $zero
/* 2C62C 8005122C 24140001 */  addiu     $s4, $zero, 0x1
/* 2C630 80051230 24120024 */  addiu     $s2, $zero, 0x24
/* 2C634 80051234 02328021 */  addu      $s0, $s1, $s2
.L80051238:
/* 2C638 80051238 8E020008 */  lw        $v0, 0x8($s0)
/* 2C63C 8005123C 50400030 */  beql      $v0, $zero, .L80051300
/* 2C640 80051240 265201E4 */   addiu    $s2, $s2, 0x1E4
/* 2C644 80051244 92220021 */  lbu       $v0, 0x21($s1)
/* 2C648 80051248 10400003 */  beqz      $v0, .L80051258
/* 2C64C 8005124C 0220202D */   daddu    $a0, $s1, $zero
/* 2C650 80051250 0C0144CD */  jal       au_amb_load_track_fade_info
/* 2C654 80051254 0200282D */   daddu    $a1, $s0, $zero
.L80051258:
/* 2C658 80051258 92030024 */  lbu       $v1, 0x24($s0)
/* 2C65C 8005125C 10600018 */  beqz      $v1, .L800512C0
/* 2C660 80051260 24020003 */   addiu    $v0, $zero, 0x3
/* 2C664 80051264 1462000A */  bne       $v1, $v0, .L80051290
/* 2C668 80051268 24020002 */   addiu    $v0, $zero, 0x2
/* 2C66C 8005126C A2020024 */  sb        $v0, 0x24($s0)
/* 2C670 80051270 0220202D */  daddu     $a0, $s1, $zero
/* 2C674 80051274 0C0148AA */  jal       au_amb_save_voices
/* 2C678 80051278 0200282D */   daddu    $a1, $s0, $zero
/* 2C67C 8005127C 0220202D */  daddu     $a0, $s1, $zero
/* 2C680 80051280 0C01487A */  jal       au_amb_player_stop
/* 2C684 80051284 0200282D */   daddu    $a1, $s0, $zero
/* 2C688 80051288 080144C0 */  j         .L80051300
/* 2C68C 8005128C 265201E4 */   addiu    $s2, $s2, 0x1E4
.L80051290:
/* 2C690 80051290 5474001B */  bnel      $v1, $s4, .L80051300
/* 2C694 80051294 265201E4 */   addiu    $s2, $s2, 0x1E4
/* 2C698 80051298 96020028 */  lhu       $v0, 0x28($s0)
/* 2C69C 8005129C 10400003 */  beqz      $v0, .L800512AC
/* 2C6A0 800512A0 A2000024 */   sb       $zero, 0x24($s0)
/* 2C6A4 800512A4 0C014354 */  jal       au_amb_fade_setup
/* 2C6A8 800512A8 0200202D */   daddu    $a0, $s0, $zero
.L800512AC:
/* 2C6AC 800512AC 0220202D */  daddu     $a0, $s1, $zero
/* 2C6B0 800512B0 0C0148CB */  jal       au_amb_restore_voices
/* 2C6B4 800512B4 0200282D */   daddu    $a1, $s0, $zero
/* 2C6B8 800512B8 080144C0 */  j         .L80051300
/* 2C6BC 800512BC 265201E4 */   addiu    $s2, $s2, 0x1E4
.L800512C0:
/* 2C6C0 800512C0 96020028 */  lhu       $v0, 0x28($s0)
/* 2C6C4 800512C4 10400003 */  beqz      $v0, .L800512D4
/* 2C6C8 800512C8 00000000 */   nop
/* 2C6CC 800512CC 0C014354 */  jal       au_amb_fade_setup
/* 2C6D0 800512D0 0200202D */   daddu    $a0, $s0, $zero
.L800512D4:
/* 2C6D4 800512D4 92030025 */  lbu       $v1, 0x25($s0)
/* 2C6D8 800512D8 24020002 */  addiu     $v0, $zero, 0x2
/* 2C6DC 800512DC 14620005 */  bne       $v1, $v0, .L800512F4
/* 2C6E0 800512E0 0220202D */   daddu    $a0, $s1, $zero
/* 2C6E4 800512E4 0C01487A */  jal       au_amb_player_stop
/* 2C6E8 800512E8 0200282D */   daddu    $a1, $s0, $zero
/* 2C6EC 800512EC A2140025 */  sb        $s4, 0x25($s0)
/* 2C6F0 800512F0 0220202D */  daddu     $a0, $s1, $zero
.L800512F4:
/* 2C6F4 800512F4 0C01450D */  jal       au_amb_player_update
/* 2C6F8 800512F8 0200282D */   daddu    $a1, $s0, $zero
/* 2C6FC 800512FC 265201E4 */  addiu     $s2, $s2, 0x1E4
.L80051300:
/* 2C700 80051300 26730001 */  addiu     $s3, $s3, 0x1
/* 2C704 80051304 2A620004 */  slti      $v0, $s3, 0x4
/* 2C708 80051308 1440FFCB */  bnez      $v0, .L80051238
/* 2C70C 8005130C 02328021 */   addu     $s0, $s1, $s2
/* 2C710 80051310 A2200021 */  sb        $zero, 0x21($s1)
/* 2C714 80051314 8FBF0024 */  lw        $ra, 0x24($sp)
/* 2C718 80051318 8FB40020 */  lw        $s4, 0x20($sp)
/* 2C71C 8005131C 8FB3001C */  lw        $s3, 0x1C($sp)
/* 2C720 80051320 8FB20018 */  lw        $s2, 0x18($sp)
/* 2C724 80051324 8FB10014 */  lw        $s1, 0x14($sp)
/* 2C728 80051328 8FB00010 */  lw        $s0, 0x10($sp)
/* 2C72C 8005132C 03E00008 */  jr        $ra
/* 2C730 80051330 27BD0028 */   addiu    $sp, $sp, 0x28

### DECOMPILED C INSTRUCTIONS:

void au_amb_manager_update(AmbienceManager* manager) {
    u32 i;
    s32 j;

    for (i = 0; i < ARRAY_COUNT(manager->voiceStates); i++) {
        AmbienceVoiceState* voiceState = &manager->voiceStates[i];

        if (voiceState->info.released == TRUE && manager->globals->voices[i].priority != manager->priority) {
            voiceState->info.all = 0;
        }
    }

    for (j = 0; j < ARRAY_COUNT(manager->players); j++) {
        AmbiencePlayer* player = &manager->players[j];
        s32 mode;

        if (player->mseqReadPos != NULL) {
            if (manager->loadTracksFadeInfo) {
                au_amb_load_track_fade_info(manager, player);
            }

            mode = player->mode;
            if (mode != AMB_MODE_NORMAL) {
                if (mode == AMB_MODE_PAUSING) {
                    player->mode = AMB_MODE_STOPPED;
                    au_amb_save_voices(manager, player);
                    au_amb_player_stop(manager, player);
                } else if (player->mode == AMB_MODE_RESUMING) {
                    player->mode = AMB_MODE_NORMAL;
                    if (player->fadeSettingsTime != 0) {
                        au_amb_fade_setup(player);
                    }
                    au_amb_restore_voices(manager, player);
                }
            } else {
                // case AMB_MODE_NORMAL
                if (player->fadeSettingsTime != 0) {
                    au_amb_fade_setup(player);
                }
                if (player->playState == AMB_PLAYER_STOPPING) {
                    au_amb_player_stop(manager, player);
                    player->playState = AMB_PLAYER_STOPPED;
                }
                au_amb_player_update(manager, player);
            }
        }
    }

    manager->loadTracksFadeInfo = FALSE;
}


### RAW ASSEMBLY INSTRUCTIONS:

glabel huff_puff_breath_main
/* 3D7A70 E00DC000 27BDFFA8 */  addiu     $sp, $sp, -0x58
/* 3D7A74 E00DC004 F7B40040 */  sdc1      $f20, 0x40($sp)
/* 3D7A78 E00DC008 4485A000 */  mtc1      $a1, $f20
/* 3D7A7C E00DC00C F7B60048 */  sdc1      $f22, 0x48($sp)
/* 3D7A80 E00DC010 4486B000 */  mtc1      $a2, $f22
/* 3D7A84 E00DC014 AFB30034 */  sw        $s3, 0x34($sp)
/* 3D7A88 E00DC018 0080982D */  daddu     $s3, $a0, $zero
/* 3D7A8C E00DC01C F7B80050 */  sdc1      $f24, 0x50($sp)
/* 3D7A90 E00DC020 4487C000 */  mtc1      $a3, $f24
/* 3D7A94 E00DC024 27A40010 */  addiu     $a0, $sp, 0x10
/* 3D7A98 E00DC028 AFB00028 */  sw        $s0, 0x28($sp)
/* 3D7A9C E00DC02C 8FB00074 */  lw        $s0, 0x74($sp)
/* 3D7AA0 E00DC030 3C02E00E */  lui       $v0, %hi(huff_puff_breath_init)
/* 3D7AA4 E00DC034 2442C190 */  addiu     $v0, $v0, %lo(huff_puff_breath_init)
/* 3D7AA8 E00DC038 AFA20018 */  sw        $v0, 0x18($sp)
/* 3D7AAC E00DC03C 3C02E00E */  lui       $v0, %hi(huff_puff_breath_update)
/* 3D7AB0 E00DC040 2442C198 */  addiu     $v0, $v0, %lo(huff_puff_breath_update)
/* 3D7AB4 E00DC044 AFA2001C */  sw        $v0, 0x1C($sp)
/* 3D7AB8 E00DC048 3C02E00E */  lui       $v0, %hi(huff_puff_breath_render)
/* 3D7ABC E00DC04C 2442C2C0 */  addiu     $v0, $v0, %lo(huff_puff_breath_render)
/* 3D7AC0 E00DC050 AFA20020 */  sw        $v0, 0x20($sp)
/* 3D7AC4 E00DC054 2402006E */  addiu     $v0, $zero, 0x6E
/* 3D7AC8 E00DC058 AFBF0038 */  sw        $ra, 0x38($sp)
/* 3D7ACC E00DC05C AFB20030 */  sw        $s2, 0x30($sp)
/* 3D7AD0 E00DC060 AFB1002C */  sw        $s1, 0x2C($sp)
/* 3D7AD4 E00DC064 AFA00010 */  sw        $zero, 0x10($sp)
/* 3D7AD8 E00DC068 AFA00024 */  sw        $zero, 0x24($sp)
/* 3D7ADC E00DC06C 0C080124 */  jal       shim_create_effect_instance
/* 3D7AE0 E00DC070 AFA20014 */   sw       $v0, 0x14($sp)
/* 3D7AE4 E00DC074 24040050 */  addiu     $a0, $zero, 0x50
/* 3D7AE8 E00DC078 24030001 */  addiu     $v1, $zero, 0x1
/* 3D7AEC E00DC07C 0040902D */  daddu     $s2, $v0, $zero
/* 3D7AF0 E00DC080 0C08012C */  jal       shim_general_heap_malloc
/* 3D7AF4 E00DC084 AE430008 */   sw       $v1, 0x8($s2)
/* 3D7AF8 E00DC088 0040882D */  daddu     $s1, $v0, $zero
/* 3D7AFC E00DC08C 16200003 */  bnez      $s1, .LE00DC09C
/* 3D7B00 E00DC090 AE42000C */   sw       $v0, 0xC($s2)
.LE00DC094:
/* 3D7B04 E00DC094 08037025 */  j         .LE00DC094
/* 3D7B08 E00DC098 00000000 */   nop
.LE00DC09C:
/* 3D7B0C E00DC09C AE330000 */  sw        $s3, 0x0($s1)
/* 3D7B10 E00DC0A0 1E000004 */  bgtz      $s0, .LE00DC0B4
/* 3D7B14 E00DC0A4 AE200014 */   sw       $zero, 0x14($s1)
/* 3D7B18 E00DC0A8 240203E8 */  addiu     $v0, $zero, 0x3E8
/* 3D7B1C E00DC0AC 0803702E */  j         .LE00DC0B8
/* 3D7B20 E00DC0B0 AE220010 */   sw       $v0, 0x10($s1)
.LE00DC0B4:
/* 3D7B24 E00DC0B4 AE300010 */  sw        $s0, 0x10($s1)
.LE00DC0B8:
/* 3D7B28 E00DC0B8 241000FF */  addiu     $s0, $zero, 0xFF
/* 3D7B2C E00DC0BC AE200024 */  sw        $zero, 0x24($s1)
/* 3D7B30 E00DC0C0 E6340004 */  swc1      $f20, 0x4($s1)
/* 3D7B34 E00DC0C4 E6360008 */  swc1      $f22, 0x8($s1)
/* 3D7B38 E00DC0C8 E638000C */  swc1      $f24, 0xC($s1)
/* 3D7B3C E00DC0CC C7A00070 */  lwc1      $f0, 0x70($sp)
/* 3D7B40 E00DC0D0 240200E6 */  addiu     $v0, $zero, 0xE6
/* 3D7B44 E00DC0D4 AE22002C */  sw        $v0, 0x2C($s1)
/* 3D7B48 E00DC0D8 24020032 */  addiu     $v0, $zero, 0x32
/* 3D7B4C E00DC0DC AE300018 */  sw        $s0, 0x18($s1)
/* 3D7B50 E00DC0E0 AE30001C */  sw        $s0, 0x1C($s1)
/* 3D7B54 E00DC0E4 AE300020 */  sw        $s0, 0x20($s1)
/* 3D7B58 E00DC0E8 AE300028 */  sw        $s0, 0x28($s1)
/* 3D7B5C E00DC0EC AE220030 */  sw        $v0, 0x30($s1)
/* 3D7B60 E00DC0F0 AE300034 */  sw        $s0, 0x34($s1)
/* 3D7B64 E00DC0F4 E620004C */  swc1      $f0, 0x4C($s1)
/* 3D7B68 E00DC0F8 C7A00068 */  lwc1      $f0, 0x68($sp)
/* 3D7B6C E00DC0FC AE200044 */  sw        $zero, 0x44($s1)
/* 3D7B70 E00DC100 E6200048 */  swc1      $f0, 0x48($s1)
/* 3D7B74 E00DC104 C7A0006C */  lwc1      $f0, 0x6C($sp)
/* 3D7B78 E00DC108 24040020 */  addiu     $a0, $zero, 0x20
/* 3D7B7C E00DC10C 0C080138 */  jal       shim_rand_int
/* 3D7B80 E00DC110 E620003C */   swc1     $f0, 0x3C($s1)
/* 3D7B84 E00DC114 24040010 */  addiu     $a0, $zero, 0x10
/* 3D7B88 E00DC118 44820000 */  mtc1      $v0, $f0
/* 3D7B8C E00DC11C 00000000 */  nop
/* 3D7B90 E00DC120 46800020 */  cvt.s.w   $f0, $f0
/* 3D7B94 E00DC124 0C080138 */  jal       shim_rand_int
/* 3D7B98 E00DC128 E6200038 */   swc1     $f0, 0x38($s1)
/* 3D7B9C E00DC12C 44820000 */  mtc1      $v0, $f0
/* 3D7BA0 E00DC130 00000000 */  nop
/* 3D7BA4 E00DC134 46800020 */  cvt.s.w   $f0, $f0
/* 3D7BA8 E00DC138 0240102D */  daddu     $v0, $s2, $zero
/* 3D7BAC E00DC13C 24030096 */  addiu     $v1, $zero, 0x96
/* 3D7BB0 E00DC140 AE230020 */  sw        $v1, 0x20($s1)
/* 3D7BB4 E00DC144 240300D7 */  addiu     $v1, $zero, 0xD7
/* 3D7BB8 E00DC148 AE230028 */  sw        $v1, 0x28($s1)
/* 3D7BBC E00DC14C 240300D2 */  addiu     $v1, $zero, 0xD2
/* 3D7BC0 E00DC150 AE23002C */  sw        $v1, 0x2C($s1)
/* 3D7BC4 E00DC154 2403000A */  addiu     $v1, $zero, 0xA
/* 3D7BC8 E00DC158 E6200040 */  swc1      $f0, 0x40($s1)
/* 3D7BCC E00DC15C AE300018 */  sw        $s0, 0x18($s1)
/* 3D7BD0 E00DC160 AE30001C */  sw        $s0, 0x1C($s1)
/* 3D7BD4 E00DC164 AE230030 */  sw        $v1, 0x30($s1)
/* 3D7BD8 E00DC168 8FBF0038 */  lw        $ra, 0x38($sp)
/* 3D7BDC E00DC16C 8FB30034 */  lw        $s3, 0x34($sp)
/* 3D7BE0 E00DC170 8FB20030 */  lw        $s2, 0x30($sp)
/* 3D7BE4 E00DC174 8FB1002C */  lw        $s1, 0x2C($sp)
/* 3D7BE8 E00DC178 8FB00028 */  lw        $s0, 0x28($sp)
/* 3D7BEC E00DC17C D7B80050 */  ldc1      $f24, 0x50($sp)
/* 3D7BF0 E00DC180 D7B60048 */  ldc1      $f22, 0x48($sp)
/* 3D7BF4 E00DC184 D7B40040 */  ldc1      $f20, 0x40($sp)
/* 3D7BF8 E00DC188 03E00008 */  jr        $ra
/* 3D7BFC E00DC18C 27BD0058 */   addiu    $sp, $sp, 0x58

### DECOMPILED C INSTRUCTIONS:

EffectInstance* huff_puff_breath_main(s32 type, f32 posX, f32 posY, f32 posZ, f32 angle, f32 speed, f32 scale, s32 timeLeft) {
    EffectBlueprint effectBp;
    EffectInstance* effect;
    HuffPuffBreathFXData* data;
    s32 numParts = 1;

    effectBp.init = huff_puff_breath_init;
    effectBp.update = huff_puff_breath_update;
    effectBp.renderWorld = huff_puff_breath_render;
    effectBp.unk_00 = 0;
    effectBp.renderUI = NULL;
    effectBp.effectID = EFFECT_HUFF_PUFF_BREATH;

    effect = shim_create_effect_instance(&effectBp);
    effect->numParts = numParts;

    data = effect->data.huffPuffBreath = shim_general_heap_malloc(numParts * sizeof(*data));
    ASSERT(data != NULL);

    data->type = type;
    data->lifeTime = 0;
    if (timeLeft <= 0) {
        data->timeLeft = 1000;
    } else {
        data->timeLeft = timeLeft;
    }

    data->primA = 0;
    data->pos.x = posX;
    data->pos.y = posY;
    data->pos.z = posZ;
    data->scale = scale;
    data->primR = 255;
    data->envG = 230;
    data->primG = 255;
    data->primB = 255;
    data->envR = 255;
    data->envB = 50;
    data->envA = 255;
    data->angle = angle;
    data->speedY = 0;
    data->speedX = speed;
    data->texOffsetX = shim_rand_int(32);
    data->texOffsetY = shim_rand_int(16);
    data->primB = 150;
    data->envR = 215;
    data->envG = 210;
    data->primR = 255;
    data->primG = 255;
    data->envB = 10;

    return effect;
}


### RAW ASSEMBLY INSTRUCTIONS:

glabel apply_transform_to_children
/* EDF50 802C95A0 27BDFE70 */  addiu     $sp, $sp, -0x190
/* EDF54 802C95A4 AFB40188 */  sw        $s4, 0x188($sp)
/* EDF58 802C95A8 0080A02D */  daddu     $s4, $a0, $zero
/* EDF5C 802C95AC AFB30184 */  sw        $s3, 0x184($sp)
/* EDF60 802C95B0 00A0982D */  daddu     $s3, $a1, $zero
/* EDF64 802C95B4 AFBF018C */  sw        $ra, 0x18C($sp)
/* EDF68 802C95B8 AFB20180 */  sw        $s2, 0x180($sp)
/* EDF6C 802C95BC AFB1017C */  sw        $s1, 0x17C($sp)
/* EDF70 802C95C0 AFB00178 */  sw        $s0, 0x178($sp)
/* EDF74 802C95C4 8E62000C */  lw        $v0, 0xC($s3)
/* EDF78 802C95C8 2411FFFF */  addiu     $s1, $zero, -0x1
/* EDF7C 802C95CC 8C450000 */  lw        $a1, 0x0($v0)
/* EDF80 802C95D0 0C0B1EAF */  jal       evt_get_variable
/* EDF84 802C95D4 0260202D */   daddu    $a0, $s3, $zero
/* EDF88 802C95D8 0040282D */  daddu     $a1, $v0, $zero
/* EDF8C 802C95DC 3C06800A */  lui       $a2, %hi(mdl_currentModelTreeNodeInfo)
/* EDF90 802C95E0 8CC6A5F4 */  lw        $a2, %lo(mdl_currentModelTreeNodeInfo)($a2)
/* EDF94 802C95E4 00051080 */  sll       $v0, $a1, 2
/* EDF98 802C95E8 00462021 */  addu      $a0, $v0, $a2
/* EDF9C 802C95EC 90830000 */  lbu       $v1, 0x0($a0)
/* EDFA0 802C95F0 286200FF */  slti      $v0, $v1, 0xFF
/* EDFA4 802C95F4 10400004 */  beqz      $v0, .L802C9608
/* EDFA8 802C95F8 0220902D */   daddu    $s2, $s1, $zero
/* EDFAC 802C95FC 0060902D */  daddu     $s2, $v1, $zero
/* EDFB0 802C9600 080B2597 */  j         .L802C965C
/* EDFB4 802C9604 0240882D */   daddu    $s1, $s2, $zero
.L802C9608:
/* EDFB8 802C9608 24B0FFFF */  addiu     $s0, $a1, -0x1
/* EDFBC 802C960C 90850001 */  lbu       $a1, 0x1($a0)
/* EDFC0 802C9610 06000013 */  bltz      $s0, .L802C9660
/* EDFC4 802C9614 27A20010 */   addiu    $v0, $sp, 0x10
/* EDFC8 802C9618 2407FFFF */  addiu     $a3, $zero, -0x1
/* EDFCC 802C961C 00101080 */  sll       $v0, $s0, 2
/* EDFD0 802C9620 00462021 */  addu      $a0, $v0, $a2
.L802C9624:
/* EDFD4 802C9624 90820001 */  lbu       $v0, 0x1($a0)
/* EDFD8 802C9628 00A2102A */  slt       $v0, $a1, $v0
/* EDFDC 802C962C 1040000C */  beqz      $v0, .L802C9660
/* EDFE0 802C9630 27A20010 */   addiu    $v0, $sp, 0x10
/* EDFE4 802C9634 90830000 */  lbu       $v1, 0x0($a0)
/* EDFE8 802C9638 286200FF */  slti      $v0, $v1, 0xFF
/* EDFEC 802C963C 50400005 */  beql      $v0, $zero, .L802C9654
/* EDFF0 802C9640 2610FFFF */   addiu    $s0, $s0, -0x1
/* EDFF4 802C9644 52470001 */  beql      $s2, $a3, .L802C964C
/* EDFF8 802C9648 0060902D */   daddu    $s2, $v1, $zero
.L802C964C:
/* EDFFC 802C964C 0060882D */  daddu     $s1, $v1, $zero
/* EE000 802C9650 2610FFFF */  addiu     $s0, $s0, -0x1
.L802C9654:
/* EE004 802C9654 0601FFF3 */  bgez      $s0, .L802C9624
/* EE008 802C9658 2484FFFC */   addiu    $a0, $a0, -0x4
.L802C965C:
/* EE00C 802C965C 27A20010 */  addiu     $v0, $sp, 0x10
.L802C9660:
/* EE010 802C9660 0260202D */  daddu     $a0, $s3, $zero
/* EE014 802C9664 24830160 */  addiu     $v1, $a0, 0x160
.L802C9668:
/* EE018 802C9668 8C880000 */  lw        $t0, 0x0($a0)
/* EE01C 802C966C 8C890004 */  lw        $t1, 0x4($a0)
/* EE020 802C9670 8C8A0008 */  lw        $t2, 0x8($a0)
/* EE024 802C9674 8C8B000C */  lw        $t3, 0xC($a0)
/* EE028 802C9678 AC480000 */  sw        $t0, 0x0($v0)
/* EE02C 802C967C AC490004 */  sw        $t1, 0x4($v0)
/* EE030 802C9680 AC4A0008 */  sw        $t2, 0x8($v0)
/* EE034 802C9684 AC4B000C */  sw        $t3, 0xC($v0)
/* EE038 802C9688 24840010 */  addiu     $a0, $a0, 0x10
/* EE03C 802C968C 1483FFF6 */  bne       $a0, $v1, .L802C9668
/* EE040 802C9690 24420010 */   addiu    $v0, $v0, 0x10
/* EE044 802C9694 0220802D */  daddu     $s0, $s1, $zero
/* EE048 802C9698 8C880000 */  lw        $t0, 0x0($a0)
/* EE04C 802C969C 8C890004 */  lw        $t1, 0x4($a0)
/* EE050 802C96A0 AC480000 */  sw        $t0, 0x0($v0)
/* EE054 802C96A4 AC490004 */  sw        $t1, 0x4($v0)
/* EE058 802C96A8 8FB1001C */  lw        $s1, 0x1C($sp)
/* EE05C 802C96AC 0250102A */  slt       $v0, $s2, $s0
/* EE060 802C96B0 8E330000 */  lw        $s3, 0x0($s1)
/* EE064 802C96B4 54400011 */  bnel      $v0, $zero, .L802C96FC
/* EE068 802C96B8 AE330000 */   sw       $s3, 0x0($s1)
/* EE06C 802C96BC 27A40010 */  addiu     $a0, $sp, 0x10
.L802C96C0:
/* EE070 802C96C0 3C038015 */  lui       $v1, %hi(gCurrentModels)
/* EE074 802C96C4 8C6312CC */  lw        $v1, %lo(gCurrentModels)($v1)
/* EE078 802C96C8 00101080 */  sll       $v0, $s0, 2
/* EE07C 802C96CC 00431021 */  addu      $v0, $v0, $v1
/* EE080 802C96D0 8C420000 */  lw        $v0, 0x0($v0)
/* EE084 802C96D4 24050001 */  addiu     $a1, $zero, 0x1
/* EE088 802C96D8 AFB1001C */  sw        $s1, 0x1C($sp)
/* EE08C 802C96DC 94420002 */  lhu       $v0, 0x2($v0)
/* EE090 802C96E0 02058021 */  addu      $s0, $s0, $a1
/* EE094 802C96E4 0280F809 */  jalr      $s4
/* EE098 802C96E8 AE220000 */   sw       $v0, 0x0($s1)
/* EE09C 802C96EC 0250102A */  slt       $v0, $s2, $s0
/* EE0A0 802C96F0 1040FFF3 */  beqz      $v0, .L802C96C0
/* EE0A4 802C96F4 27A40010 */   addiu    $a0, $sp, 0x10
/* EE0A8 802C96F8 AE330000 */  sw        $s3, 0x0($s1)
.L802C96FC:
/* EE0AC 802C96FC 8FBF018C */  lw        $ra, 0x18C($sp)
/* EE0B0 802C9700 8FB40188 */  lw        $s4, 0x188($sp)
/* EE0B4 802C9704 8FB30184 */  lw        $s3, 0x184($sp)
/* EE0B8 802C9708 8FB20180 */  lw        $s2, 0x180($sp)
/* EE0BC 802C970C 8FB1017C */  lw        $s1, 0x17C($sp)
/* EE0C0 802C9710 8FB00178 */  lw        $s0, 0x178($sp)
/* EE0C4 802C9714 03E00008 */  jr        $ra
/* EE0C8 802C9718 27BD0190 */   addiu    $sp, $sp, 0x190

### DECOMPILED C INSTRUCTIONS:

void apply_transform_to_children(ApiStatus (*apiFunc)(Evt*, s32), Evt* script) {
    Evt localEvt;
    ModelTreeInfo* parentModelInfo;
    ModelTreeInfo* childModelInfo;
    s32 parentModelID;
    s32 originalArg;
    s32* argsPtr;
    s32 modelIndex;
    s32 firstChild;
    s32 lastChild;
    s32 i;

    firstChild = -1;
    parentModelID = evt_get_variable(script, *script->ptrReadPos);
    modelIndex = (*mdl_currentModelTreeNodeInfo)[parentModelID].modelIndex;
    lastChild = -1;

    if (modelIndex < 0xFF) {
        firstChild = lastChild = modelIndex;
    } else {
        s32 treeDepth = (*mdl_currentModelTreeNodeInfo)[parentModelID].treeDepth;

        // check all models with a lowerID in the tree
        for (i = parentModelID - 1; i >= 0; i--) {
            childModelInfo = &(*mdl_currentModelTreeNodeInfo)[i];

            if (treeDepth < childModelInfo->treeDepth) {
                s32 childModelIndex = childModelInfo->modelIndex;

                if (childModelIndex < 0xFF) {
                    if (lastChild == -1) {
                        lastChild = childModelIndex;
                    }
                    firstChild = childModelIndex;
                }
            } else {
                // if node is no longer deeper than parent, we've exhausted the children
                break;
            }
        }
    }

    // copy the input script into a local one we will modify
    localEvt = *script;

    argsPtr = localEvt.ptrReadPos;
    originalArg = *argsPtr;

    for (i = firstChild; i <= lastChild; i++) {
        Model* model = (*gCurrentModels)[i];

        localEvt.ptrReadPos = argsPtr;
        *argsPtr = model->modelID;

        apiFunc(&localEvt, TRUE);
    }

    *argsPtr = originalArg;
}


### RAW ASSEMBLY INSTRUCTIONS:

glabel falling_leaves_main
/* 35E920 E0058000 27BDFFA8 */  addiu     $sp, $sp, -0x58
/* 35E924 E0058004 F7B40040 */  sdc1      $f20, 0x40($sp)
/* 35E928 E0058008 4485A000 */  mtc1      $a1, $f20
/* 35E92C E005800C AFB1002C */  sw        $s1, 0x2C($sp)
/* 35E930 E0058010 0080882D */  daddu     $s1, $a0, $zero
/* 35E934 E0058014 F7B60048 */  sdc1      $f22, 0x48($sp)
/* 35E938 E0058018 4486B000 */  mtc1      $a2, $f22
/* 35E93C E005801C 27A40010 */  addiu     $a0, $sp, 0x10
/* 35E940 E0058020 F7B80050 */  sdc1      $f24, 0x50($sp)
/* 35E944 E0058024 4487C000 */  mtc1      $a3, $f24
/* 35E948 E0058028 3C02E006 */  lui       $v0, %hi(falling_leaves_init)
/* 35E94C E005802C 244281AC */  addiu     $v0, $v0, %lo(falling_leaves_init)
/* 35E950 E0058030 AFA20018 */  sw        $v0, 0x18($sp)
/* 35E954 E0058034 3C02E006 */  lui       $v0, %hi(falling_leaves_update)
/* 35E958 E0058038 244281B4 */  addiu     $v0, $v0, %lo(falling_leaves_update)
/* 35E95C E005803C AFA2001C */  sw        $v0, 0x1C($sp)
/* 35E960 E0058040 3C02E006 */  lui       $v0, %hi(falling_leaves_render)
/* 35E964 E0058044 24428490 */  addiu     $v0, $v0, %lo(falling_leaves_render)
/* 35E968 E0058048 AFA20020 */  sw        $v0, 0x20($sp)
/* 35E96C E005804C 2402002C */  addiu     $v0, $zero, 0x2C
/* 35E970 E0058050 AFBF0038 */  sw        $ra, 0x38($sp)
/* 35E974 E0058054 AFB30034 */  sw        $s3, 0x34($sp)
/* 35E978 E0058058 AFB20030 */  sw        $s2, 0x30($sp)
/* 35E97C E005805C AFB00028 */  sw        $s0, 0x28($sp)
/* 35E980 E0058060 AFA00010 */  sw        $zero, 0x10($sp)
/* 35E984 E0058064 AFA00024 */  sw        $zero, 0x24($sp)
/* 35E988 E0058068 0C080124 */  jal       shim_create_effect_instance
/* 35E98C E005806C AFA20014 */   sw       $v0, 0x14($sp)
/* 35E990 E0058070 24040104 */  addiu     $a0, $zero, 0x104
/* 35E994 E0058074 24120005 */  addiu     $s2, $zero, 0x5
/* 35E998 E0058078 0040802D */  daddu     $s0, $v0, $zero
/* 35E99C E005807C 0C08012C */  jal       shim_general_heap_malloc
/* 35E9A0 E0058080 AE120008 */   sw       $s2, 0x8($s0)
/* 35E9A4 E0058084 0040182D */  daddu     $v1, $v0, $zero
/* 35E9A8 E0058088 14600003 */  bnez      $v1, .LE0058098
/* 35E9AC E005808C AE03000C */   sw       $v1, 0xC($s0)
.LE0058090:
/* 35E9B0 E0058090 08016024 */  j         .LE0058090
/* 35E9B4 E0058094 00000000 */   nop
.LE0058098:
/* 35E9B8 E0058098 24020064 */  addiu     $v0, $zero, 0x64
/* 35E9BC E005809C AC710000 */  sw        $s1, 0x0($v1)
/* 35E9C0 E00580A0 E4740004 */  swc1      $f20, 0x4($v1)
/* 35E9C4 E00580A4 E4760008 */  swc1      $f22, 0x8($v1)
/* 35E9C8 E00580A8 E478000C */  swc1      $f24, 0xC($v1)
/* 35E9CC E00580AC AC620028 */  sw        $v0, 0x28($v1)
/* 35E9D0 E00580B0 AC60002C */  sw        $zero, 0x2C($v1)
/* 35E9D4 E00580B4 AC600024 */  sw        $zero, 0x24($v1)
/* 35E9D8 E00580B8 24110001 */  addiu     $s1, $zero, 0x1
/* 35E9DC E00580BC 0232102A */  slt       $v0, $s1, $s2
/* 35E9E0 E00580C0 10400030 */  beqz      $v0, .LE0058184
/* 35E9E4 E00580C4 24630034 */   addiu    $v1, $v1, 0x34
/* 35E9E8 E00580C8 3C136666 */  lui       $s3, (0x66666667 >> 16)
/* 35E9EC E00580CC 36736667 */  ori       $s3, $s3, (0x66666667 & 0xFFFF)
/* 35E9F0 E00580D0 24700014 */  addiu     $s0, $v1, 0x14
.LE00580D4:
/* 35E9F4 E00580D4 0C080138 */  jal       shim_rand_int
/* 35E9F8 E00580D8 2404001E */   addiu    $a0, $zero, 0x1E
/* 35E9FC E00580DC 2404001E */  addiu     $a0, $zero, 0x1E
/* 35EA00 E00580E0 2442FFF1 */  addiu     $v0, $v0, -0xF
/* 35EA04 E00580E4 44820000 */  mtc1      $v0, $f0
/* 35EA08 E00580E8 00000000 */  nop
/* 35EA0C E00580EC 46800020 */  cvt.s.w   $f0, $f0
/* 35EA10 E00580F0 E600FFF0 */  swc1      $f0, -0x10($s0)
/* 35EA14 E00580F4 0C080138 */  jal       shim_rand_int
/* 35EA18 E00580F8 AE00FFF4 */   sw       $zero, -0xC($s0)
/* 35EA1C E00580FC 24040168 */  addiu     $a0, $zero, 0x168
/* 35EA20 E0058100 2442FFF1 */  addiu     $v0, $v0, -0xF
/* 35EA24 E0058104 44820000 */  mtc1      $v0, $f0
/* 35EA28 E0058108 00000000 */  nop
/* 35EA2C E005810C 46800020 */  cvt.s.w   $f0, $f0
/* 35EA30 E0058110 0C080138 */  jal       shim_rand_int
/* 35EA34 E0058114 E600FFF8 */   swc1     $f0, -0x8($s0)
/* 35EA38 E0058118 24040168 */  addiu     $a0, $zero, 0x168
/* 35EA3C E005811C 44820000 */  mtc1      $v0, $f0
/* 35EA40 E0058120 00000000 */  nop
/* 35EA44 E0058124 46800020 */  cvt.s.w   $f0, $f0
/* 35EA48 E0058128 0C080138 */  jal       shim_rand_int
/* 35EA4C E005812C E6000004 */   swc1     $f0, 0x4($s0)
/* 35EA50 E0058130 24040064 */  addiu     $a0, $zero, 0x64
/* 35EA54 E0058134 44820000 */  mtc1      $v0, $f0
/* 35EA58 E0058138 00000000 */  nop
/* 35EA5C E005813C 46800020 */  cvt.s.w   $f0, $f0
/* 35EA60 E0058140 0C080138 */  jal       shim_rand_int
/* 35EA64 E0058144 E600000C */   swc1     $f0, 0xC($s0)
/* 35EA68 E0058148 00530018 */  mult      $v0, $s3
/* 35EA6C E005814C 26310001 */  addiu     $s1, $s1, 0x1
/* 35EA70 E0058150 000217C3 */  sra       $v0, $v0, 31
/* 35EA74 E0058154 AE00FFFC */  sw        $zero, -0x4($s0)
/* 35EA78 E0058158 AE000000 */  sw        $zero, 0x0($s0)
/* 35EA7C E005815C 00004010 */  mfhi      $t0
/* 35EA80 E0058160 00081883 */  sra       $v1, $t0, 2
/* 35EA84 E0058164 00621823 */  subu      $v1, $v1, $v0
/* 35EA88 E0058168 44830000 */  mtc1      $v1, $f0
/* 35EA8C E005816C 00000000 */  nop
/* 35EA90 E0058170 46800020 */  cvt.s.w   $f0, $f0
/* 35EA94 E0058174 E6000008 */  swc1      $f0, 0x8($s0)
/* 35EA98 E0058178 0232102A */  slt       $v0, $s1, $s2
/* 35EA9C E005817C 1440FFD5 */  bnez      $v0, .LE00580D4
/* 35EAA0 E0058180 26100034 */   addiu    $s0, $s0, 0x34
.LE0058184:
/* 35EAA4 E0058184 8FBF0038 */  lw        $ra, 0x38($sp)
/* 35EAA8 E0058188 8FB30034 */  lw        $s3, 0x34($sp)
/* 35EAAC E005818C 8FB20030 */  lw        $s2, 0x30($sp)
/* 35EAB0 E0058190 8FB1002C */  lw        $s1, 0x2C($sp)
/* 35EAB4 E0058194 8FB00028 */  lw        $s0, 0x28($sp)
/* 35EAB8 E0058198 D7B80050 */  ldc1      $f24, 0x50($sp)
/* 35EABC E005819C D7B60048 */  ldc1      $f22, 0x48($sp)
/* 35EAC0 E00581A0 D7B40040 */  ldc1      $f20, 0x40($sp)
/* 35EAC4 E00581A4 03E00008 */  jr        $ra
/* 35EAC8 E00581A8 27BD0058 */   addiu    $sp, $sp, 0x58

### DECOMPILED C INSTRUCTIONS:

void falling_leaves_main(s32 arg0, f32 arg1, f32 arg2, f32 arg3) {
    EffectBlueprint bp;
    EffectInstance* effect;
    FallingLeavesFXData* part;
    s32 numParts = 5;
    s32 i;

    bp.init = falling_leaves_init;
    bp.update = falling_leaves_update;
    bp.renderWorld = falling_leaves_render;
    bp.unk_00 = 0;
    bp.renderUI = NULL;
    bp.effectID = EFFECT_FALLING_LEAVES;

    effect = shim_create_effect_instance(&bp);
    effect->numParts = numParts;
    part = effect->data.fallingLeaves = shim_general_heap_malloc(numParts * sizeof(*part));
    ASSERT(effect->data.fallingLeaves != NULL);

    part->unk_00 = arg0;
    part->unk_04 = arg1;
    part->unk_08 = arg2;
    part->unk_0C = arg3;
    part->unk_28 = 100;
    part->unk_2C = 0;
    part->unk_24 = 0;

    part++;
    for (i = 1; i < numParts; i++, part++) {
        part->unk_04 = shim_rand_int(30) - 15;
        part->unk_08 = 0;
        part->unk_0C = shim_rand_int(30) - 15;
        part->unk_18 = shim_rand_int(360);
        part->unk_20 = shim_rand_int(360);
        part->unk_1C = shim_rand_int(100) / 10;
        part->unk_10 = 0;
        part->unk_14 = 0;
    }
}


### RAW ASSEMBLY INSTRUCTIONS:

glabel guPerspective
/* 3F140 80063D40 27BDFF78 */  addiu     $sp, $sp, -0x88
/* 3F144 80063D44 F7B80070 */  sdc1      $f24, 0x70($sp)
/* 3F148 80063D48 C7B80098 */  lwc1      $f24, 0x98($sp)
/* 3F14C 80063D4C F7BA0078 */  sdc1      $f26, 0x78($sp)
/* 3F150 80063D50 C7BA009C */  lwc1      $f26, 0x9C($sp)
/* 3F154 80063D54 F7BC0080 */  sdc1      $f28, 0x80($sp)
/* 3F158 80063D58 C7BC00A0 */  lwc1      $f28, 0xA0($sp)
/* 3F15C 80063D5C F7B40060 */  sdc1      $f20, 0x60($sp)
/* 3F160 80063D60 4486A000 */  mtc1      $a2, $f20
/* 3F164 80063D64 AFB20058 */  sw        $s2, 0x58($sp)
/* 3F168 80063D68 00809021 */  addu      $s2, $a0, $zero
/* 3F16C 80063D6C AFB10054 */  sw        $s1, 0x54($sp)
/* 3F170 80063D70 00A08821 */  addu      $s1, $a1, $zero
/* 3F174 80063D74 AFB00050 */  sw        $s0, 0x50($sp)
/* 3F178 80063D78 27B00010 */  addiu     $s0, $sp, 0x10
/* 3F17C 80063D7C F7B60068 */  sdc1      $f22, 0x68($sp)
/* 3F180 80063D80 4487B000 */  mtc1      $a3, $f22
/* 3F184 80063D84 AFBF005C */  sw        $ra, 0x5C($sp)
/* 3F188 80063D88 0C019D28 */  jal       guMtxIdentF
/* 3F18C 80063D8C 02002021 */   addu     $a0, $s0, $zero
/* 3F190 80063D90 3C01800A */  lui       $at, %hi(D_80099BD0)
/* 3F194 80063D94 D4209BD0 */  ldc1      $f0, %lo(D_80099BD0)($at)
/* 3F198 80063D98 4600A521 */  cvt.d.s   $f20, $f20
/* 3F19C 80063D9C 4620A502 */  mul.d     $f20, $f20, $f0
/* 3F1A0 80063DA0 3C014000 */  lui       $at, (0x40000000 >> 16)
/* 3F1A4 80063DA4 44810000 */  mtc1      $at, $f0
/* 3F1A8 80063DA8 4620A520 */  cvt.s.d   $f20, $f20
/* 3F1AC 80063DAC 4600A503 */  div.s     $f20, $f20, $f0
/* 3F1B0 80063DB0 0C00A874 */  jal       cos_rad
/* 3F1B4 80063DB4 4600A306 */   mov.s    $f12, $f20
/* 3F1B8 80063DB8 4600A306 */  mov.s     $f12, $f20
/* 3F1BC 80063DBC 0C00A85B */  jal       sin_rad
/* 3F1C0 80063DC0 46000506 */   mov.s    $f20, $f0
/* 3F1C4 80063DC4 4600A503 */  div.s     $f20, $f20, $f0
/* 3F1C8 80063DC8 461AC100 */  add.s     $f4, $f24, $f26
/* 3F1CC 80063DCC 461AC081 */  sub.s     $f2, $f24, $f26
/* 3F1D0 80063DD0 46022103 */  div.s     $f4, $f4, $f2
/* 3F1D4 80063DD4 4618C000 */  add.s     $f0, $f24, $f24
/* 3F1D8 80063DD8 461A0002 */  mul.s     $f0, $f0, $f26
/* 3F1DC 80063DDC 46020003 */  div.s     $f0, $f0, $f2
/* 3F1E0 80063DE0 4616A583 */  div.s     $f22, $f20, $f22
/* 3F1E4 80063DE4 3C01BF80 */  lui       $at, (0xBF800000 >> 16)
/* 3F1E8 80063DE8 44811000 */  mtc1      $at, $f2
/* 3F1EC 80063DEC 00002821 */  addu      $a1, $zero, $zero
/* 3F1F0 80063DF0 AFA0004C */  sw        $zero, 0x4C($sp)
/* 3F1F4 80063DF4 E7A2003C */  swc1      $f2, 0x3C($sp)
/* 3F1F8 80063DF8 E7B40024 */  swc1      $f20, 0x24($sp)
/* 3F1FC 80063DFC E7A40038 */  swc1      $f4, 0x38($sp)
/* 3F200 80063E00 E7A00048 */  swc1      $f0, 0x48($sp)
/* 3F204 80063E04 E7B60010 */  swc1      $f22, 0x10($sp)
.L80063E08:
/* 3F208 80063E08 00002021 */  addu      $a0, $zero, $zero
/* 3F20C 80063E0C 02001821 */  addu      $v1, $s0, $zero
.L80063E10:
/* 3F210 80063E10 C4600000 */  lwc1      $f0, 0x0($v1)
/* 3F214 80063E14 461C0002 */  mul.s     $f0, $f0, $f28
/* 3F218 80063E18 24840001 */  addiu     $a0, $a0, 0x1
/* 3F21C 80063E1C 28820004 */  slti      $v0, $a0, 0x4
/* 3F220 80063E20 E4600000 */  swc1      $f0, 0x0($v1)
/* 3F224 80063E24 1440FFFA */  bnez      $v0, .L80063E10
/* 3F228 80063E28 24630004 */   addiu    $v1, $v1, 0x4
/* 3F22C 80063E2C 24A50001 */  addiu     $a1, $a1, 0x1
/* 3F230 80063E30 28A20004 */  slti      $v0, $a1, 0x4
/* 3F234 80063E34 1440FFF4 */  bnez      $v0, .L80063E08
/* 3F238 80063E38 26100010 */   addiu    $s0, $s0, 0x10
/* 3F23C 80063E3C 52200025 */  beql      $s1, $zero, .L80063ED4
/* 3F240 80063E40 27A40010 */   addiu    $a0, $sp, 0x10
/* 3F244 80063E44 461AC080 */  add.s     $f2, $f24, $f26
/* 3F248 80063E48 3C01800A */  lui       $at, %hi(D_80099BD8)
/* 3F24C 80063E4C D4209BD8 */  ldc1      $f0, %lo(D_80099BD8)($at)
/* 3F250 80063E50 460010A1 */  cvt.d.s   $f2, $f2
/* 3F254 80063E54 4620103E */  c.le.d    $f2, $f0
/* 3F258 80063E58 00000000 */  nop
/* 3F25C 80063E5C 00000000 */  nop
/* 3F260 80063E60 4501001A */  bc1t      .L80063ECC
/* 3F264 80063E64 3402FFFF */   ori      $v0, $zero, 0xFFFF
/* 3F268 80063E68 3C01800A */  lui       $at, %hi(D_80099BE0)
/* 3F26C 80063E6C D4209BE0 */  ldc1      $f0, %lo(D_80099BE0)($at)
/* 3F270 80063E70 46220083 */  div.d     $f2, $f0, $f2
/* 3F274 80063E74 3C01800A */  lui       $at, %hi(D_80099BE8)
/* 3F278 80063E78 D4209BE8 */  ldc1      $f0, %lo(D_80099BE8)($at)
/* 3F27C 80063E7C 4622003E */  c.le.d    $f0, $f2
/* 3F280 80063E80 00000000 */  nop
/* 3F284 80063E84 00000000 */  nop
/* 3F288 80063E88 45030006 */  bc1tl     .L80063EA4
/* 3F28C 80063E8C 46201001 */   sub.d    $f0, $f2, $f0
/* 3F290 80063E90 4620100D */  trunc.w.d $f0, $f2
/* 3F294 80063E94 44030000 */  mfc1      $v1, $f0
/* 3F298 80063E98 00000000 */  nop
/* 3F29C 80063E9C 08018FAE */  j         .L80063EB8
/* 3F2A0 80063EA0 00601021 */   addu     $v0, $v1, $zero
.L80063EA4:
/* 3F2A4 80063EA4 4620008D */  trunc.w.d $f2, $f0
/* 3F2A8 80063EA8 44031000 */  mfc1      $v1, $f2
/* 3F2AC 80063EAC 3C028000 */  lui       $v0, (0x80000000 >> 16)
/* 3F2B0 80063EB0 00621825 */  or        $v1, $v1, $v0
/* 3F2B4 80063EB4 00601021 */  addu      $v0, $v1, $zero
.L80063EB8:
/* 3F2B8 80063EB8 A6220000 */  sh        $v0, 0x0($s1)
/* 3F2BC 80063EBC 3042FFFF */  andi      $v0, $v0, 0xFFFF
/* 3F2C0 80063EC0 14400004 */  bnez      $v0, .L80063ED4
/* 3F2C4 80063EC4 27A40010 */   addiu    $a0, $sp, 0x10
/* 3F2C8 80063EC8 24020001 */  addiu     $v0, $zero, 0x1
.L80063ECC:
/* 3F2CC 80063ECC A6220000 */  sh        $v0, 0x0($s1)
/* 3F2D0 80063ED0 27A40010 */  addiu     $a0, $sp, 0x10
.L80063ED4:
/* 3F2D4 80063ED4 0C019D40 */  jal       guMtxF2L
/* 3F2D8 80063ED8 02402821 */   addu     $a1, $s2, $zero
/* 3F2DC 80063EDC 8FBF005C */  lw        $ra, 0x5C($sp)
/* 3F2E0 80063EE0 8FB20058 */  lw        $s2, 0x58($sp)
/* 3F2E4 80063EE4 8FB10054 */  lw        $s1, 0x54($sp)
/* 3F2E8 80063EE8 8FB00050 */  lw        $s0, 0x50($sp)
/* 3F2EC 80063EEC D7BC0080 */  ldc1      $f28, 0x80($sp)
/* 3F2F0 80063EF0 D7BA0078 */  ldc1      $f26, 0x78($sp)
/* 3F2F4 80063EF4 D7B80070 */  ldc1      $f24, 0x70($sp)
/* 3F2F8 80063EF8 D7B60068 */  ldc1      $f22, 0x68($sp)
/* 3F2FC 80063EFC D7B40060 */  ldc1      $f20, 0x60($sp)
/* 3F300 80063F00 03E00008 */  jr        $ra
/* 3F304 80063F04 27BD0088 */   addiu    $sp, $sp, 0x88
/* 3F308 80063F08 00000000 */  nop
/* 3F30C 80063F0C 00000000 */  nop

### DECOMPILED C INSTRUCTIONS:

void guPerspectiveF(f32 mf[4][4], u16 *perspNorm, f32 fovy, f32 aspect, f32 near, f32 far, f32 scale) {
    f32 cot;
    s32 i, j;

    guMtxIdentF(mf);

    fovy *= 3.1415926 / 180.0;
    cot = cos_rad(fovy/2) / sin_rad(fovy/2);

    mf[0][0] = cot / aspect;
    mf[1][1] = cot;
    mf[2][2] = (near + far) / (near - far);
    mf[2][3] = -1;
    mf[3][2] = (2 * near * far) / (near - far);
    mf[3][3] = 0;

    for (i = 0; i < 4; i++) {
        for (j = 0; j < 4; j++) {
            mf[i][j] *= scale;
        }
    }

    if (perspNorm != (u16 *) NULL) {
        if (near + far <= 2.0) {
            *perspNorm = (u16) 0xFFFF;
        } else  {
            *perspNorm = (u16) ((2.0 * 65536.0) / (near + far));
            if (*perspNorm <= 0) {
                *perspNorm = (u16) 0x0001;
            }
        }
    }
}


### RAW ASSEMBLY INSTRUCTIONS:

glabel destroy_popup_menu
/* 8A9E8 800F1538 3C048011 */  lui       $a0, %hi(PopupMenu_EmptybarHEID)
/* 8A9EC 800F153C 8C84D65C */  lw        $a0, %lo(PopupMenu_EmptybarHEID)($a0)
/* 8A9F0 800F1540 27BDFFE0 */  addiu     $sp, $sp, -0x20
/* 8A9F4 800F1544 AFBF0018 */  sw        $ra, 0x18($sp)
/* 8A9F8 800F1548 AFB10014 */  sw        $s1, 0x14($sp)
/* 8A9FC 800F154C 0C05123D */  jal       hud_element_free
/* 8AA00 800F1550 AFB00010 */   sw       $s0, 0x10($sp)
/* 8AA04 800F1554 3C048011 */  lui       $a0, %hi(D_8010D678)
/* 8AA08 800F1558 8C84D678 */  lw        $a0, %lo(D_8010D678)($a0)
/* 8AA0C 800F155C 0C05123D */  jal       hud_element_free
/* 8AA10 800F1560 00000000 */   nop
/* 8AA14 800F1564 3C048011 */  lui       $a0, %hi(D_8010D66C)
/* 8AA18 800F1568 8C84D66C */  lw        $a0, %lo(D_8010D66C)($a0)
/* 8AA1C 800F156C 0C05123D */  jal       hud_element_free
/* 8AA20 800F1570 00000000 */   nop
/* 8AA24 800F1574 3C048011 */  lui       $a0, %hi(D_8010D670)
/* 8AA28 800F1578 8C84D670 */  lw        $a0, %lo(D_8010D670)($a0)
/* 8AA2C 800F157C 0C05123D */  jal       hud_element_free
/* 8AA30 800F1580 00000000 */   nop
/* 8AA34 800F1584 3C048011 */  lui       $a0, %hi(D_8010D674)
/* 8AA38 800F1588 8C84D674 */  lw        $a0, %lo(D_8010D674)($a0)
/* 8AA3C 800F158C 0C05123D */  jal       hud_element_free
/* 8AA40 800F1590 00000000 */   nop
/* 8AA44 800F1594 3C108011 */  lui       $s0, %hi(gPopupMenu)
/* 8AA48 800F1598 2610D69C */  addiu     $s0, $s0, %lo(gPopupMenu)
/* 8AA4C 800F159C 8E020000 */  lw        $v0, 0x0($s0)
/* 8AA50 800F15A0 8C430318 */  lw        $v1, 0x318($v0)
/* 8AA54 800F15A4 24020003 */  addiu     $v0, $zero, 0x3
/* 8AA58 800F15A8 14620009 */  bne       $v1, $v0, .L800F15D0
/* 8AA5C 800F15AC 00000000 */   nop
/* 8AA60 800F15B0 3C048011 */  lui       $a0, %hi(PopupTitleIconHEID)
/* 8AA64 800F15B4 8C84D660 */  lw        $a0, %lo(PopupTitleIconHEID)($a0)
/* 8AA68 800F15B8 0C05123D */  jal       hud_element_free
/* 8AA6C 800F15BC 00000000 */   nop
/* 8AA70 800F15C0 3C048011 */  lui       $a0, %hi(D_8010D664)
/* 8AA74 800F15C4 8C84D664 */  lw        $a0, %lo(D_8010D664)($a0)
/* 8AA78 800F15C8 0C05123D */  jal       hud_element_free
/* 8AA7C 800F15CC 00000000 */   nop
.L800F15D0:
/* 8AA80 800F15D0 8E020000 */  lw        $v0, 0x0($s0)
/* 8AA84 800F15D4 8C420318 */  lw        $v0, 0x318($v0)
/* 8AA88 800F15D8 24110004 */  addiu     $s1, $zero, 0x4
/* 8AA8C 800F15DC 14510009 */  bne       $v0, $s1, .L800F1604
/* 8AA90 800F15E0 00000000 */   nop
/* 8AA94 800F15E4 3C048011 */  lui       $a0, %hi(PopupTitleIconHEID)
/* 8AA98 800F15E8 8C84D660 */  lw        $a0, %lo(PopupTitleIconHEID)($a0)
/* 8AA9C 800F15EC 0C05123D */  jal       hud_element_free
/* 8AAA0 800F15F0 00000000 */   nop
/* 8AAA4 800F15F4 3C048011 */  lui       $a0, %hi(D_8010D664)
/* 8AAA8 800F15F8 8C84D664 */  lw        $a0, %lo(D_8010D664)($a0)
/* 8AAAC 800F15FC 0C05123D */  jal       hud_element_free
/* 8AAB0 800F1600 00000000 */   nop
.L800F1604:
/* 8AAB4 800F1604 8E020000 */  lw        $v0, 0x0($s0)
/* 8AAB8 800F1608 8C430318 */  lw        $v1, 0x318($v0)
/* 8AABC 800F160C 24020001 */  addiu     $v0, $zero, 0x1
/* 8AAC0 800F1610 10620003 */  beq       $v1, $v0, .L800F1620
/* 8AAC4 800F1614 00000000 */   nop
/* 8AAC8 800F1618 14710005 */  bne       $v1, $s1, .L800F1630
/* 8AACC 800F161C 00000000 */   nop
.L800F1620:
/* 8AAD0 800F1620 3C048011 */  lui       $a0, %hi(D_8010D668)
/* 8AAD4 800F1624 8C84D668 */  lw        $a0, %lo(D_8010D668)($a0)
/* 8AAD8 800F1628 0C05123D */  jal       hud_element_free
/* 8AADC 800F162C 00000000 */   nop
.L800F1630:
/* 8AAE0 800F1630 3C108011 */  lui       $s0, %hi(gPopupMenu)
/* 8AAE4 800F1634 2610D69C */  addiu     $s0, $s0, %lo(gPopupMenu)
/* 8AAE8 800F1638 8E020000 */  lw        $v0, 0x0($s0)
/* 8AAEC 800F163C 8C430318 */  lw        $v1, 0x318($v0)
/* 8AAF0 800F1640 24020005 */  addiu     $v0, $zero, 0x5
/* 8AAF4 800F1644 14620005 */  bne       $v1, $v0, .L800F165C
/* 8AAF8 800F1648 00000000 */   nop
/* 8AAFC 800F164C 3C048011 */  lui       $a0, %hi(PopupTitleIconHEID)
/* 8AB00 800F1650 8C84D660 */  lw        $a0, %lo(PopupTitleIconHEID)($a0)
/* 8AB04 800F1654 0C05123D */  jal       hud_element_free
/* 8AB08 800F1658 00000000 */   nop
.L800F165C:
/* 8AB0C 800F165C 8E020000 */  lw        $v0, 0x0($s0)
/* 8AB10 800F1660 8C430318 */  lw        $v1, 0x318($v0)
/* 8AB14 800F1664 28620005 */  slti      $v0, $v1, 0x5
/* 8AB18 800F1668 14400003 */  bnez      $v0, .L800F1678
/* 8AB1C 800F166C 2402000C */   addiu    $v0, $zero, 0xC
/* 8AB20 800F1670 1462000E */  bne       $v1, $v0, .L800F16AC
/* 8AB24 800F1674 00000000 */   nop
.L800F1678:
/* 8AB28 800F1678 3C028007 */  lui       $v0, %hi(gGameStatusPtr)
/* 8AB2C 800F167C 8C42419C */  lw        $v0, %lo(gGameStatusPtr)($v0)
/* 8AB30 800F1680 80420070 */  lb        $v0, 0x70($v0)
/* 8AB34 800F1684 14400009 */  bnez      $v0, .L800F16AC
/* 8AB38 800F1688 00000000 */   nop
/* 8AB3C 800F168C 3C028011 */  lui       $v0, %hi(D_8010D69A)
/* 8AB40 800F1690 8042D69A */  lb        $v0, %lo(D_8010D69A)($v0)
/* 8AB44 800F1694 14400003 */  bnez      $v0, .L800F16A4
/* 8AB48 800F1698 00000000 */   nop
/* 8AB4C 800F169C 0C03A631 */  jal       status_bar_respond_to_changes
/* 8AB50 800F16A0 00000000 */   nop
.L800F16A4:
/* 8AB54 800F16A4 0C03A5EE */  jal       close_status_bar
/* 8AB58 800F16A8 00000000 */   nop
.L800F16AC:
/* 8AB5C 800F16AC 8FBF0018 */  lw        $ra, 0x18($sp)
/* 8AB60 800F16B0 8FB10014 */  lw        $s1, 0x14($sp)
/* 8AB64 800F16B4 8FB00010 */  lw        $s0, 0x10($sp)
/* 8AB68 800F16B8 2402FFFC */  addiu     $v0, $zero, -0x4
/* 8AB6C 800F16BC 3C018011 */  lui       $at, %hi(gPopupState)
/* 8AB70 800F16C0 AC22D640 */  sw        $v0, %lo(gPopupState)($at)
/* 8AB74 800F16C4 03E00008 */  jr        $ra
/* 8AB78 800F16C8 27BD0020 */   addiu    $sp, $sp, 0x20

### DECOMPILED C INSTRUCTIONS:

void destroy_popup_menu(void) {
    hud_element_free(PopupMenu_EmptybarHEID);
    hud_element_free(PopupMenu_EntryIconHEID);
    hud_element_free(PopupMenu_CursorHEID);
    hud_element_free(PopupMenu_UpArrowHEID);
    hud_element_free(PopupMenu_DownArrowHEID);

    if (gPopupMenu->popupType == POPUP_TYPE_TRADE_FOR_BADGE) {
        hud_element_free(PopupMenu_TitleIconHEID);
        hud_element_free(PopupMenu_TimesHEID);
    }

    if (gPopupMenu->popupType == POPUP_TYPE_UPGRADE_PARTNER) {
        hud_element_free(PopupMenu_TitleIconHEID);
        hud_element_free(PopupMenu_TimesHEID);
    }

    if (gPopupMenu->popupType == POPUP_TYPE_SWITCH_PARTNER || gPopupMenu->popupType == POPUP_TYPE_UPGRADE_PARTNER) {
        hud_element_free(PopupMenu_PartnerLevelHEID);
    }

    if (gPopupMenu->popupType == POPUP_TYPE_SELL_ITEM) {
        hud_element_free(PopupMenu_TitleIconHEID);
    }

    if ((gPopupMenu->popupType <= POPUP_TYPE_USE_ITEM ||
         gPopupMenu->popupType == POPUP_TYPE_SWITCH_PARTNER ||
         gPopupMenu->popupType == POPUP_TYPE_THROW_AWAY_ITEM ||
         gPopupMenu->popupType == POPUP_TYPE_TRADE_FOR_BADGE ||
         gPopupMenu->popupType == POPUP_TYPE_UPGRADE_PARTNER ||
         gPopupMenu->popupType == POPUP_TYPE_USE_KEY
        ) && !gGameStatusPtr->isBattle) {
        if (D_8010D69A == 0) {
            status_bar_respond_to_changes();
        }
        close_status_bar();
    }

    gPopupState = POPUP_STATE_MINUS_4;
}


### RAW ASSEMBLY INSTRUCTIONS:

glabel shop_open_item_select_popup
/* 7E17D4 80280954 3C028007 */  lui       $v0, %hi(gGameStatusPtr)
/* 7E17D8 80280958 8C42419C */  lw        $v0, %lo(gGameStatusPtr)($v0)
/* 7E17DC 8028095C 27BDFFC0 */  addiu     $sp, $sp, -0x40
/* 7E17E0 80280960 AFBF003C */  sw        $ra, 0x3C($sp)
/* 7E17E4 80280964 AFBE0038 */  sw        $fp, 0x38($sp)
/* 7E17E8 80280968 AFB70034 */  sw        $s7, 0x34($sp)
/* 7E17EC 8028096C AFB60030 */  sw        $s6, 0x30($sp)
/* 7E17F0 80280970 AFB5002C */  sw        $s5, 0x2C($sp)
/* 7E17F4 80280974 AFB40028 */  sw        $s4, 0x28($sp)
/* 7E17F8 80280978 AFB30024 */  sw        $s3, 0x24($sp)
/* 7E17FC 8028097C AFB20020 */  sw        $s2, 0x20($sp)
/* 7E1800 80280980 AFB1001C */  sw        $s1, 0x1C($sp)
/* 7E1804 80280984 AFB00018 */  sw        $s0, 0x18($sp)
/* 7E1808 80280988 8C420144 */  lw        $v0, 0x144($v0)
/* 7E180C 8028098C 0080B82D */  daddu     $s7, $a0, $zero
/* 7E1810 80280990 24420028 */  addiu     $v0, $v0, 0x28
/* 7E1814 80280994 12E00006 */  beqz      $s7, .L802809B0
/* 7E1818 80280998 AFA20010 */   sw       $v0, 0x10($sp)
/* 7E181C 8028099C 24020001 */  addiu     $v0, $zero, 0x1
/* 7E1820 802809A0 12E20006 */  beq       $s7, $v0, .L802809BC
/* 7E1824 802809A4 24150007 */   addiu    $s5, $zero, 0x7
/* 7E1828 802809A8 080A0271 */  j         .L802809C4
/* 7E182C 802809AC 24140020 */   addiu    $s4, $zero, 0x20
.L802809B0:
/* 7E1830 802809B0 24150005 */  addiu     $s5, $zero, 0x5
/* 7E1834 802809B4 080A0271 */  j         .L802809C4
/* 7E1838 802809B8 2414000A */   addiu    $s4, $zero, 0xA
.L802809BC:
/* 7E183C 802809BC 24150006 */  addiu     $s5, $zero, 0x6
/* 7E1840 802809C0 2414000A */  addiu     $s4, $zero, 0xA
.L802809C4:
/* 7E1844 802809C4 0000902D */  daddu     $s2, $zero, $zero
/* 7E1848 802809C8 12800027 */  beqz      $s4, .L80280A68
/* 7E184C 802809CC 0240982D */   daddu    $s3, $s2, $zero
/* 7E1850 802809D0 2AFE0002 */  slti      $fp, $s7, 0x2
/* 7E1854 802809D4 3C168008 */  lui       $s6, %hi(gItemTable)
/* 7E1858 802809D8 26D678E0 */  addiu     $s6, $s6, %lo(gItemTable)
/* 7E185C 802809DC 3C118011 */  lui       $s1, %hi(gPlayerData)
/* 7E1860 802809E0 2631F290 */  addiu     $s1, $s1, %lo(gPlayerData)
/* 7E1864 802809E4 8FB00010 */  lw        $s0, 0x10($sp)
.L802809E8:
/* 7E1868 802809E8 13C00005 */  beqz      $fp, .L80280A00
/* 7E186C 802809EC 00000000 */   nop
D_802809F0:
/* 7E1870 802809F0 06E00003 */  bltz      $s7, .L80280A00
D_802809F4:
/* 7E1874 802809F4 00000000 */   nop
DemoBattleBeginDelay:
/* 7E1878 802809F8 080A0281 */  j         .L80280A04
bHPDigitHudScripts:
/* 7E187C 802809FC 862401B4 */   lh       $a0, 0x1B4($s1)
.L80280A00:
/* 7E1880 80280A00 862401C8 */  lh        $a0, 0x1C8($s1)
.L80280A04:
/* 7E1884 80280A04 10800014 */  beqz      $a0, .L80280A58
/* 7E1888 80280A08 00041140 */   sll      $v0, $a0, 5
/* 7E188C 80280A0C 00561821 */  addu      $v1, $v0, $s6
/* 7E1890 80280A10 84620004 */  lh        $v0, 0x4($v1)
/* 7E1894 80280A14 3C058009 */  lui       $a1, %hi(gItemHudScripts)
/* 7E1898 80280A18 24A5A680 */  addiu     $a1, $a1, %lo(gItemHudScripts)
/* 7E189C 80280A1C 000210C0 */  sll       $v0, $v0, 3
/* 7E18A0 80280A20 00451021 */  addu      $v0, $v0, $a1
/* 7E18A4 80280A24 8C420000 */  lw        $v0, 0x0($v0)
/* 7E18A8 80280A28 24050001 */  addiu     $a1, $zero, 0x1
/* 7E18AC 80280A2C AE120108 */  sw        $s2, 0x108($s0)
BattleScreenFadeAmt:
/* 7E18B0 80280A30 AE05018C */  sw        $a1, 0x18C($s0)
BtlPutPartnerAway:
/* 7E18B4 80280A34 AE020000 */  sw        $v0, 0x0($s0)
/* 7E18B8 80280A38 8C620000 */  lw        $v0, 0x0($v1)
/* 7E18BC 80280A3C AE020084 */  sw        $v0, 0x84($s0)
/* 7E18C0 80280A40 8C620014 */  lw        $v0, 0x14($v1)
/* 7E18C4 80280A44 02659821 */  addu      $s3, $s3, $a1
/* 7E18C8 80280A48 0C0A02DE */  jal       shop_get_sell_price
/* 7E18CC 80280A4C AE020294 */   sw       $v0, 0x294($s0)
/* 7E18D0 80280A50 AE020210 */  sw        $v0, 0x210($s0)
/* 7E18D4 80280A54 26100004 */  addiu     $s0, $s0, 0x4
.L80280A58:
/* 7E18D8 80280A58 26520001 */  addiu     $s2, $s2, 0x1
/* 7E18DC 80280A5C 0254102A */  slt       $v0, $s2, $s4
/* 7E18E0 80280A60 1440FFE1 */  bnez      $v0, .L802809E8
/* 7E18E4 80280A64 26310002 */   addiu    $s1, $s1, 0x2
.L80280A68:
/* 7E18E8 80280A68 8FA40010 */  lw        $a0, 0x10($sp)
/* 7E18EC 80280A6C AC950318 */  sw        $s5, 0x318($a0)
/* 7E18F0 80280A70 AC930324 */  sw        $s3, 0x324($a0)
/* 7E18F4 80280A74 0C03D3F1 */  jal       create_shop_popup_menu
/* 7E18F8 80280A78 AC800328 */   sw       $zero, 0x328($a0)
/* 7E18FC 80280A7C 0C03A625 */  jal       status_bar_ignore_changes
/* 7E1900 80280A80 00000000 */   nop
/* 7E1904 80280A84 0C03A63B */  jal       func_800E98EC
/* 7E1908 80280A88 00000000 */   nop
/* 7E190C 80280A8C 0C03A5E3 */  jal       open_status_bar_short
/* 7E1910 80280A90 00000000 */   nop
/* 7E1914 80280A94 8FBF003C */  lw        $ra, 0x3C($sp)
/* 7E1918 80280A98 8FBE0038 */  lw        $fp, 0x38($sp)
/* 7E191C 80280A9C 8FB70034 */  lw        $s7, 0x34($sp)
/* 7E1920 80280AA0 8FB60030 */  lw        $s6, 0x30($sp)
/* 7E1924 80280AA4 8FB5002C */  lw        $s5, 0x2C($sp)
/* 7E1928 80280AA8 8FB40028 */  lw        $s4, 0x28($sp)
/* 7E192C 80280AAC 8FB30024 */  lw        $s3, 0x24($sp)
/* 7E1930 80280AB0 8FB20020 */  lw        $s2, 0x20($sp)
/* 7E1934 80280AB4 8FB1001C */  lw        $s1, 0x1C($sp)
/* 7E1938 80280AB8 8FB00018 */  lw        $s0, 0x18($sp)
/* 7E193C 80280ABC 03E00008 */  jr        $ra
/* 7E1940 80280AC0 27BD0040 */   addiu    $sp, $sp, 0x40

### DECOMPILED C INSTRUCTIONS:

void shop_open_item_select_popup(s32 mode) {
    PopupMenu* menu = &gGameStatusPtr->mapShop->itemSelectMenu;
    s32 numItemSlots;
    s32 popupType;
    s32 numEntries;
    s32 itemID;
    s32 i;

    switch (mode) {
        case 0:
            popupType = POPUP_MENU_SELL_ITEM;
            numItemSlots = 10;
            break;
        case 1:
            popupType = POPUP_MENU_CHECK_ITEM;
            numItemSlots = 10;
            break;
        default:
            popupType = POPUP_MENU_CLAIM_ITEM;
            numItemSlots = 32;
            break;
    }

    numEntries = 0;

    for (i = 0; i < numItemSlots; i++) {
        ItemData* itemData;

        switch (mode) {
            case 0:
            case 1:
                itemID = gPlayerData.invItems[i];
                if (itemID == ITEM_NONE) {
                    continue;
                }
                itemData = &gItemTable[itemID];
                break;
            default:
                itemID = gPlayerData.storedItems[i];
                if (itemID == ITEM_NONE) {
                    continue;
                }
                itemData = &gItemTable[itemID];
                break;
        }

        menu->ptrIcon[numEntries] = gItemHudScripts[itemData->hudElemID].enabled;
        menu->userIndex[numEntries] = i;
        menu->enabled[numEntries] = TRUE;
        menu->nameMsg[numEntries] = itemData->nameMsg;
        menu->descMsg[numEntries] = itemData->shortDescMsg;
        menu->value[numEntries] = shop_get_sell_price(itemID);
        numEntries++;
    }

    menu->popupType = popupType;
    menu->numEntries = numEntries;
    menu->initialPos = 0;
    create_shop_popup_menu(menu);
    status_bar_ignore_changes();
    func_800E98EC();
    open_status_bar_short();
}


### RAW ASSEMBLY INSTRUCTIONS:

glabel NpcFacePlayer
/* F3678 802CECC8 27BDFFD0 */  addiu     $sp, $sp, -0x30
/* F367C 802CECCC AFB10014 */  sw        $s1, 0x14($sp)
/* F3680 802CECD0 0080882D */  daddu     $s1, $a0, $zero
/* F3684 802CECD4 AFB40020 */  sw        $s4, 0x20($sp)
/* F3688 802CECD8 3C148011 */  lui       $s4, %hi(gPlayerStatus)
/* F368C 802CECDC 2694EFC8 */  addiu     $s4, $s4, %lo(gPlayerStatus)
/* F3690 802CECE0 AFB60028 */  sw        $s6, 0x28($sp)
/* F3694 802CECE4 26360074 */  addiu     $s6, $s1, 0x74
/* F3698 802CECE8 AFB50024 */  sw        $s5, 0x24($sp)
/* F369C 802CECEC 26350078 */  addiu     $s5, $s1, 0x78
/* F36A0 802CECF0 AFB3001C */  sw        $s3, 0x1C($sp)
/* F36A4 802CECF4 AFBF002C */  sw        $ra, 0x2C($sp)
/* F36A8 802CECF8 AFB20018 */  sw        $s2, 0x18($sp)
/* F36AC 802CECFC AFB00010 */  sw        $s0, 0x10($sp)
/* F36B0 802CED00 8E32000C */  lw        $s2, 0xC($s1)
/* F36B4 802CED04 10A00034 */  beqz      $a1, .L802CEDD8
/* F36B8 802CED08 2633007C */   addiu    $s3, $s1, 0x7C
/* F36BC 802CED0C 8E450000 */  lw        $a1, 0x0($s2)
/* F36C0 802CED10 0C0B1EAF */  jal       evt_get_variable
/* F36C4 802CED14 26520004 */   addiu    $s2, $s2, 0x4
/* F36C8 802CED18 0220202D */  daddu     $a0, $s1, $zero
/* F36CC 802CED1C 0C0B36B0 */  jal       resolve_npc
/* F36D0 802CED20 0040282D */   daddu    $a1, $v0, $zero
/* F36D4 802CED24 0040802D */  daddu     $s0, $v0, $zero
/* F36D8 802CED28 1200004B */  beqz      $s0, .L802CEE58
/* F36DC 802CED2C 24020002 */   addiu    $v0, $zero, 0x2
/* F36E0 802CED30 C600000C */  lwc1      $f0, 0xC($s0)
/* F36E4 802CED34 E6200074 */  swc1      $f0, 0x74($s1)
/* F36E8 802CED38 C60C0038 */  lwc1      $f12, 0x38($s0)
/* F36EC 802CED3C C60E0040 */  lwc1      $f14, 0x40($s0)
/* F36F0 802CED40 8E860028 */  lw        $a2, 0x28($s4)
/* F36F4 802CED44 0C00A720 */  jal       atan2
/* F36F8 802CED48 8E870030 */   lw       $a3, 0x30($s4)
/* F36FC 802CED4C C6220074 */  lwc1      $f2, 0x74($s1)
/* F3700 802CED50 46020001 */  sub.s     $f0, $f0, $f2
/* F3704 802CED54 AE300070 */  sw        $s0, 0x70($s1)
/* F3708 802CED58 E6200078 */  swc1      $f0, 0x78($s1)
/* F370C 802CED5C 8E450000 */  lw        $a1, 0x0($s2)
/* F3710 802CED60 0C0B1EAF */  jal       evt_get_variable
/* F3714 802CED64 0220202D */   daddu    $a0, $s1, $zero
/* F3718 802CED68 AE22007C */  sw        $v0, 0x7C($s1)
/* F371C 802CED6C A600008E */  sh        $zero, 0x8E($s0)
/* F3720 802CED70 C6220078 */  lwc1      $f2, 0x78($s1)
/* F3724 802CED74 3C01C334 */  lui       $at, (0xC3340000 >> 16)
/* F3728 802CED78 44810000 */  mtc1      $at, $f0
/* F372C 802CED7C 00000000 */  nop
/* F3730 802CED80 4600103C */  c.lt.s    $f2, $f0
/* F3734 802CED84 00000000 */  nop
/* F3738 802CED88 45000007 */  bc1f      .L802CEDA8
/* F373C 802CED8C 00000000 */   nop
/* F3740 802CED90 3C0143B4 */  lui       $at, (0x43B40000 >> 16)
/* F3744 802CED94 44810000 */  mtc1      $at, $f0
/* F3748 802CED98 00000000 */  nop
/* F374C 802CED9C 46001000 */  add.s     $f0, $f2, $f0
/* F3750 802CEDA0 E6200078 */  swc1      $f0, 0x78($s1)
/* F3754 802CEDA4 C6220078 */  lwc1      $f2, 0x78($s1)
.L802CEDA8:
/* F3758 802CEDA8 3C014334 */  lui       $at, (0x43340000 >> 16)
/* F375C 802CEDAC 44810000 */  mtc1      $at, $f0
/* F3760 802CEDB0 00000000 */  nop
/* F3764 802CEDB4 4602003C */  c.lt.s    $f0, $f2
/* F3768 802CEDB8 00000000 */  nop
/* F376C 802CEDBC 45000006 */  bc1f      .L802CEDD8
/* F3770 802CEDC0 00000000 */   nop
/* F3774 802CEDC4 3C0143B4 */  lui       $at, (0x43B40000 >> 16)
/* F3778 802CEDC8 44810000 */  mtc1      $at, $f0
/* F377C 802CEDCC 00000000 */  nop
/* F3780 802CEDD0 46001001 */  sub.s     $f0, $f2, $f0
/* F3784 802CEDD4 E6200078 */  swc1      $f0, 0x78($s1)
.L802CEDD8:
/* F3788 802CEDD8 8E620000 */  lw        $v0, 0x0($s3)
/* F378C 802CEDDC 8E300070 */  lw        $s0, 0x70($s1)
/* F3790 802CEDE0 1C400006 */  bgtz      $v0, .L802CEDFC
/* F3794 802CEDE4 24020002 */   addiu    $v0, $zero, 0x2
/* F3798 802CEDE8 C600000C */  lwc1      $f0, 0xC($s0)
/* F379C 802CEDEC C6A20000 */  lwc1      $f2, 0x0($s5)
/* F37A0 802CEDF0 46020000 */  add.s     $f0, $f0, $f2
/* F37A4 802CEDF4 080B3B96 */  j         .L802CEE58
/* F37A8 802CEDF8 E600000C */   swc1     $f0, 0xC($s0)
.L802CEDFC:
/* F37AC 802CEDFC 9602008E */  lhu       $v0, 0x8E($s0)
/* F37B0 802CEE00 24420001 */  addiu     $v0, $v0, 0x1
/* F37B4 802CEE04 A602008E */  sh        $v0, 0x8E($s0)
/* F37B8 802CEE08 00021400 */  sll       $v0, $v0, 16
/* F37BC 802CEE0C 00021403 */  sra       $v0, $v0, 16
/* F37C0 802CEE10 C6A00000 */  lwc1      $f0, 0x0($s5)
/* F37C4 802CEE14 44821000 */  mtc1      $v0, $f2
/* F37C8 802CEE18 00000000 */  nop
/* F37CC 802CEE1C 468010A0 */  cvt.s.w   $f2, $f2
/* F37D0 802CEE20 46020002 */  mul.s     $f0, $f0, $f2
/* F37D4 802CEE24 00000000 */  nop
/* F37D8 802CEE28 C6CC0000 */  lwc1      $f12, 0x0($s6)
/* F37DC 802CEE2C C6620000 */  lwc1      $f2, 0x0($s3)
/* F37E0 802CEE30 468010A0 */  cvt.s.w   $f2, $f2
/* F37E4 802CEE34 46020003 */  div.s     $f0, $f0, $f2
/* F37E8 802CEE38 46006300 */  add.s     $f12, $f12, $f0
/* F37EC 802CEE3C 0C00A6C9 */  jal       clamp_angle
/* F37F0 802CEE40 E60C000C */   swc1     $f12, 0xC($s0)
/* F37F4 802CEE44 8602008E */  lh        $v0, 0x8E($s0)
/* F37F8 802CEE48 E600000C */  swc1      $f0, 0xC($s0)
/* F37FC 802CEE4C 8E630000 */  lw        $v1, 0x0($s3)
/* F3800 802CEE50 0043102A */  slt       $v0, $v0, $v1
/* F3804 802CEE54 38420001 */  xori      $v0, $v0, 0x1
.L802CEE58:
/* F3808 802CEE58 8FBF002C */  lw        $ra, 0x2C($sp)
/* F380C 802CEE5C 8FB60028 */  lw        $s6, 0x28($sp)
/* F3810 802CEE60 8FB50024 */  lw        $s5, 0x24($sp)
/* F3814 802CEE64 8FB40020 */  lw        $s4, 0x20($sp)
/* F3818 802CEE68 8FB3001C */  lw        $s3, 0x1C($sp)
/* F381C 802CEE6C 8FB20018 */  lw        $s2, 0x18($sp)
/* F3820 802CEE70 8FB10014 */  lw        $s1, 0x14($sp)
/* F3824 802CEE74 8FB00010 */  lw        $s0, 0x10($sp)
/* F3828 802CEE78 03E00008 */  jr        $ra
/* F382C 802CEE7C 27BD0030 */   addiu    $sp, $sp, 0x30

### DECOMPILED C INSTRUCTIONS:

ApiStatus NpcFacePlayer(Evt* script, s32 isInitialCall) {
    PlayerStatus* playerStatus = &gPlayerStatus;
    Bytecode* args = script->ptrReadPos;
    f32* initialYaw = &script->functionTempF[1];
    f32* deltaYaw = &script->functionTempF[2];
    s32* turnTime = &script->functionTemp[3];
    Npc* npc;

    if (isInitialCall) {
        s32 npcID = evt_get_variable(script, *args++);

        npc = resolve_npc(script, npcID);
        if (npc == NULL) {
            return ApiStatus_DONE2;
        }

        *initialYaw = npc->yaw;
        *deltaYaw = atan2(npc->pos.x, npc->pos.z, playerStatus->position.x, playerStatus->position.z) - *initialYaw;
        script->functionTempPtr[0] = npc;
        *turnTime = evt_get_variable(script, *args++);
        npc->duration = 0;

        if (*deltaYaw < -180.0f) {
            *deltaYaw += 360.0f;
        }
        if (*deltaYaw > 180.0f) {
            *deltaYaw -= 360.0f;
        }
    }

    npc = script->functionTempPtr[0];
    if (*turnTime > 0) {
        npc->duration++;
        npc->yaw = *initialYaw + ((*deltaYaw * npc->duration) / *turnTime);
        npc->yaw = clamp_angle(npc->yaw);
        return !(npc->duration < *turnTime) * ApiStatus_DONE1;
    }

    npc->yaw += *deltaYaw;
    return ApiStatus_DONE2;
}


### RAW ASSEMBLY INSTRUCTIONS:

glabel CreatePushBlockGrid
/* 7E4160 802832E0 27BDFFC8 */  addiu     $sp, $sp, -0x38
/* 7E4164 802832E4 AFB10014 */  sw        $s1, 0x14($sp)
/* 7E4168 802832E8 0080882D */  daddu     $s1, $a0, $zero
/* 7E416C 802832EC AFBF0034 */  sw        $ra, 0x34($sp)
/* 7E4170 802832F0 AFBE0030 */  sw        $fp, 0x30($sp)
/* 7E4174 802832F4 AFB7002C */  sw        $s7, 0x2C($sp)
/* 7E4178 802832F8 AFB60028 */  sw        $s6, 0x28($sp)
/* 7E417C 802832FC AFB50024 */  sw        $s5, 0x24($sp)
/* 7E4180 80283300 AFB40020 */  sw        $s4, 0x20($sp)
/* 7E4184 80283304 AFB3001C */  sw        $s3, 0x1C($sp)
/* 7E4188 80283308 AFB20018 */  sw        $s2, 0x18($sp)
/* 7E418C 8028330C AFB00010 */  sw        $s0, 0x10($sp)
/* 7E4190 80283310 8E30000C */  lw        $s0, 0xC($s1)
/* 7E4194 80283314 8E050000 */  lw        $a1, 0x0($s0)
/* 7E4198 80283318 0C0B1EAF */  jal       evt_get_variable
/* 7E419C 8028331C 26100004 */   addiu    $s0, $s0, 0x4
/* 7E41A0 80283320 8E050000 */  lw        $a1, 0x0($s0)
/* 7E41A4 80283324 26100004 */  addiu     $s0, $s0, 0x4
/* 7E41A8 80283328 0220202D */  daddu     $a0, $s1, $zero
/* 7E41AC 8028332C 0C0B1EAF */  jal       evt_get_variable
/* 7E41B0 80283330 0040902D */   daddu    $s2, $v0, $zero
/* 7E41B4 80283334 8E050000 */  lw        $a1, 0x0($s0)
/* 7E41B8 80283338 26100004 */  addiu     $s0, $s0, 0x4
/* 7E41BC 8028333C 0220202D */  daddu     $a0, $s1, $zero
/* 7E41C0 80283340 0C0B1EAF */  jal       evt_get_variable
/* 7E41C4 80283344 0040A82D */   daddu    $s5, $v0, $zero
/* 7E41C8 80283348 8E050000 */  lw        $a1, 0x0($s0)
/* 7E41CC 8028334C 26100004 */  addiu     $s0, $s0, 0x4
/* 7E41D0 80283350 0220202D */  daddu     $a0, $s1, $zero
/* 7E41D4 80283354 0C0B1EAF */  jal       evt_get_variable
/* 7E41D8 80283358 0040A02D */   daddu    $s4, $v0, $zero
/* 7E41DC 8028335C 8E050000 */  lw        $a1, 0x0($s0)
/* 7E41E0 80283360 26100004 */  addiu     $s0, $s0, 0x4
/* 7E41E4 80283364 0220202D */  daddu     $a0, $s1, $zero
/* 7E41E8 80283368 0C0B1EAF */  jal       evt_get_variable
/* 7E41EC 8028336C 0040F02D */   daddu    $fp, $v0, $zero
bMarioHideAnims:
/* 7E41F0 80283370 0220202D */  daddu     $a0, $s1, $zero
/* 7E41F4 80283374 8E050000 */  lw        $a1, 0x0($s0)
/* 7E41F8 80283378 0C0B1EAF */  jal       evt_get_variable
/* 7E41FC 8028337C 0040B82D */   daddu    $s7, $v0, $zero
/* 7E4200 80283380 02B40018 */  mult      $s5, $s4
/* 7E4204 80283384 26100004 */  addiu     $s0, $s0, 0x4
/* 7E4208 80283388 0220202D */  daddu     $a0, $s1, $zero
/* 7E420C 8028338C 8E050000 */  lw        $a1, 0x0($s0)
/* 7E4210 80283390 00008812 */  mflo      $s1
/* 7E4214 80283394 0C0B1EAF */  jal       evt_get_variable
/* 7E4218 80283398 0040B02D */   daddu    $s6, $v0, $zero
/* 7E421C 8028339C 2404001C */  addiu     $a0, $zero, 0x1C
/* 7E4220 802833A0 0C00AB0A */  jal       general_heap_malloc
/* 7E4224 802833A4 0040982D */   daddu    $s3, $v0, $zero
/* 7E4228 802833A8 00129080 */  sll       $s2, $s2, 2
/* 7E422C 802833AC 0040802D */  daddu     $s0, $v0, $zero
/* 7E4230 802833B0 3C01802E */  lui       $at, %hi(wPushBlockGrids)
/* 7E4234 802833B4 00320821 */  addu      $at, $at, $s2
/* 7E4238 802833B8 AC30BC88 */  sw        $s0, %lo(wPushBlockGrids)($at)
/* 7E423C 802833BC 0C00AB0A */  jal       general_heap_malloc
/* 7E4240 802833C0 0220202D */   daddu    $a0, $s1, $zero
/* 7E4244 802833C4 1660000D */  bnez      $s3, .L802833FC
/* 7E4248 802833C8 AE020000 */   sw       $v0, 0x0($s0)
/* 7E424C 802833CC 1A200018 */  blez      $s1, .L80283430
/* 7E4250 802833D0 0000282D */   daddu    $a1, $zero, $zero
/* 7E4254 802833D4 0220202D */  daddu     $a0, $s1, $zero
.L802833D8:
/* 7E4258 802833D8 8E020000 */  lw        $v0, 0x0($s0)
/* 7E425C 802833DC 00451021 */  addu      $v0, $v0, $a1
/* 7E4260 802833E0 24A50001 */  addiu     $a1, $a1, 0x1
/* 7E4264 802833E4 A0400000 */  sb        $zero, 0x0($v0)
/* 7E4268 802833E8 00A4102A */  slt       $v0, $a1, $a0
/* 7E426C 802833EC 1440FFFA */  bnez      $v0, .L802833D8
/* 7E4270 802833F0 00000000 */   nop
/* 7E4274 802833F4 080A0D0D */  j         .L80283434
/* 7E4278 802833F8 A2150004 */   sb       $s5, 0x4($s0)
.L802833FC:
/* 7E427C 802833FC 0000282D */  daddu     $a1, $zero, $zero
/* 7E4280 80283400 1A20000B */  blez      $s1, .L80283430
/* 7E4284 80283404 0260302D */   daddu    $a2, $s3, $zero
/* 7E4288 80283408 0220202D */  daddu     $a0, $s1, $zero
bPeachIdleAnims:
/* 7E428C 8028340C 00C51021 */  addu      $v0, $a2, $a1
.L80283410:
/* 7E4290 80283410 8E030000 */  lw        $v1, 0x0($s0)
/* 7E4294 80283414 90420000 */  lbu       $v0, 0x0($v0)
/* 7E4298 80283418 00651821 */  addu      $v1, $v1, $a1
/* 7E429C 8028341C 24A50001 */  addiu     $a1, $a1, 0x1
bMarioDefenseTable:
/* 7E42A0 80283420 A0620000 */  sb        $v0, 0x0($v1)
/* 7E42A4 80283424 00A4102A */  slt       $v0, $a1, $a0
/* 7E42A8 80283428 1440FFF9 */  bnez      $v0, .L80283410
bPlayerStatusTable:
/* 7E42AC 8028342C 00C51021 */   addu     $v0, $a2, $a1
.L80283430:
/* 7E42B0 80283430 A2150004 */  sb        $s5, 0x4($s0)
.L80283434:
/* 7E42B4 80283434 A2140005 */  sb        $s4, 0x5($s0)
/* 7E42B8 80283438 AE1E0008 */  sw        $fp, 0x8($s0)
/* 7E42BC 8028343C AE17000C */  sw        $s7, 0xC($s0)
/* 7E42C0 80283440 AE160010 */  sw        $s6, 0x10($s0)
/* 7E42C4 80283444 AE000014 */  sw        $zero, 0x14($s0)
/* 7E42C8 80283448 8FBF0034 */  lw        $ra, 0x34($sp)
/* 7E42CC 8028344C 8FBE0030 */  lw        $fp, 0x30($sp)
/* 7E42D0 80283450 8FB7002C */  lw        $s7, 0x2C($sp)
/* 7E42D4 80283454 8FB60028 */  lw        $s6, 0x28($sp)
/* 7E42D8 80283458 8FB50024 */  lw        $s5, 0x24($sp)
/* 7E42DC 8028345C 8FB40020 */  lw        $s4, 0x20($sp)
/* 7E42E0 80283460 8FB3001C */  lw        $s3, 0x1C($sp)
/* 7E42E4 80283464 8FB20018 */  lw        $s2, 0x18($sp)
/* 7E42E8 80283468 8FB10014 */  lw        $s1, 0x14($sp)
/* 7E42EC 8028346C 8FB00010 */  lw        $s0, 0x10($sp)
/* 7E42F0 80283470 24020002 */  addiu     $v0, $zero, 0x2
/* 7E42F4 80283474 03E00008 */  jr        $ra
/* 7E42F8 80283478 27BD0038 */   addiu    $sp, $sp, 0x38

### DECOMPILED C INSTRUCTIONS:

API_CALLABLE(CreatePushBlockGrid) {
    Bytecode* arg = script->ptrReadPos;
    s32 blockSystemID = evt_get_variable(script, *arg++);
    s32 sizeNx = evt_get_variable(script, *arg++);
    s32 sizeNz = evt_get_variable(script, *arg++);
    s32 centerX = evt_get_variable(script, *arg++);
    s32 centerY = evt_get_variable(script, *arg++);
    s32 centerZ = evt_get_variable(script, *arg++);
    u8* inputGridData = (u8*) evt_get_variable(script, *arg++);

    PushBlockGrid* blockGrid;
    u8* dataToCopy;
    s32 i;

    wPushBlockGrids[blockSystemID] = blockGrid = general_heap_malloc(sizeof(*blockGrid));

    blockGrid->cells = general_heap_malloc(sizeNx*sizeNz);

    if (inputGridData == NULL) {
        for (i = 0; i < sizeNx*sizeNz; i++) {
            blockGrid->cells[i] = 0;
        }
    } else {
        dataToCopy = inputGridData;
        for (i = 0; i < sizeNx*sizeNz; i++) {
            blockGrid->cells[i] = dataToCopy[i];
        }
    }

    blockGrid->numCellsX = sizeNx;
    blockGrid->numCellsZ = sizeNz;
    blockGrid->centerPos.x = centerX;
    blockGrid->centerPos.y = centerY;
    blockGrid->centerPos.z = centerZ;
    blockGrid->dropCallback = NULL;

    return ApiStatus_DONE2;
}


### RAW ASSEMBLY INSTRUCTIONS:

glabel load_effect
/* 35964 8005A564 27BDFFD8 */  addiu     $sp, $sp, -0x28
/* 35968 8005A568 AFB20020 */  sw        $s2, 0x20($sp)
/* 3596C 8005A56C 0080902D */  daddu     $s2, $a0, $zero
/* 35970 8005A570 3C038008 */  lui       $v1, %hi(gEffectTable)
/* 35974 8005A574 2463F210 */  addiu     $v1, $v1, %lo(gEffectTable)
/* 35978 8005A578 00121040 */  sll       $v0, $s2, 1
/* 3597C 8005A57C 00521021 */  addu      $v0, $v0, $s2
/* 35980 8005A580 000210C0 */  sll       $v0, $v0, 3
/* 35984 8005A584 AFB1001C */  sw        $s1, 0x1C($sp)
/* 35988 8005A588 00438821 */  addu      $s1, $v0, $v1
/* 3598C 8005A58C 0000202D */  daddu     $a0, $zero, $zero
/* 35990 8005A590 AFB00018 */  sw        $s0, 0x18($sp)
/* 35994 8005A594 3C10800A */  lui       $s0, %hi(gEffectGraphicsData)
/* 35998 8005A598 26104000 */  addiu     $s0, $s0, %lo(gEffectGraphicsData)
/* 3599C 8005A59C AFBF0024 */  sw        $ra, 0x24($sp)
.L8005A5A0:
/* 359A0 8005A5A0 8E020000 */  lw        $v0, 0x0($s0)
/* 359A4 8005A5A4 30420001 */  andi      $v0, $v0, 0x1
/* 359A8 8005A5A8 50400005 */  beql      $v0, $zero, .L8005A5C0
/* 359AC 8005A5AC 24840001 */   addiu    $a0, $a0, 0x1
/* 359B0 8005A5B0 8E020004 */  lw        $v0, 0x4($s0)
/* 359B4 8005A5B4 10520006 */  beq       $v0, $s2, .L8005A5D0
/* 359B8 8005A5B8 2882000F */   slti     $v0, $a0, 0xF
/* 359BC 8005A5BC 24840001 */  addiu     $a0, $a0, 0x1
.L8005A5C0:
/* 359C0 8005A5C0 2882000F */  slti      $v0, $a0, 0xF
/* 359C4 8005A5C4 1440FFF6 */  bnez      $v0, .L8005A5A0
/* 359C8 8005A5C8 26100020 */   addiu    $s0, $s0, 0x20
/* 359CC 8005A5CC 2882000F */  slti      $v0, $a0, 0xF
.L8005A5D0:
/* 359D0 8005A5D0 14400030 */  bnez      $v0, .L8005A694
/* 359D4 8005A5D4 24020001 */   addiu    $v0, $zero, 0x1
/* 359D8 8005A5D8 0000202D */  daddu     $a0, $zero, $zero
/* 359DC 8005A5DC 3C10800A */  lui       $s0, %hi(gEffectGraphicsData)
/* 359E0 8005A5E0 26104000 */  addiu     $s0, $s0, %lo(gEffectGraphicsData)
.L8005A5E4:
/* 359E4 8005A5E4 8E020000 */  lw        $v0, 0x0($s0)
/* 359E8 8005A5E8 30420001 */  andi      $v0, $v0, 0x1
/* 359EC 8005A5EC 10400006 */  beqz      $v0, .L8005A608
/* 359F0 8005A5F0 2882000F */   slti     $v0, $a0, 0xF
/* 359F4 8005A5F4 24840001 */  addiu     $a0, $a0, 0x1
/* 359F8 8005A5F8 2882000F */  slti      $v0, $a0, 0xF
/* 359FC 8005A5FC 1440FFF9 */  bnez      $v0, .L8005A5E4
/* 35A00 8005A600 26100020 */   addiu    $s0, $s0, 0x20
/* 35A04 8005A604 2882000F */  slti      $v0, $a0, 0xF
.L8005A608:
/* 35A08 8005A608 14400003 */  bnez      $v0, .L8005A618
/* 35A0C 8005A60C 3C0700FF */   lui      $a3, (0xFFFFFF >> 16)
.L8005A610:
/* 35A10 8005A610 08016984 */  j         .L8005A610
/* 35A14 8005A614 00000000 */   nop
.L8005A618:
/* 35A18 8005A618 34E7FFFF */  ori       $a3, $a3, (0xFFFFFF & 0xFFFF)
/* 35A1C 8005A61C 0000282D */  daddu     $a1, $zero, $zero
/* 35A20 8005A620 2402FFFF */  addiu     $v0, $zero, -0x1
/* 35A24 8005A624 3C038019 */  lui       $v1, %hi(D_80197000)
/* 35A28 8005A628 24637000 */  addiu     $v1, $v1, %lo(D_80197000)
/* 35A2C 8005A62C AFA20010 */  sw        $v0, 0x10($sp)
/* 35A30 8005A630 AFA20014 */  sw        $v0, 0x14($sp)
/* 35A34 8005A634 00041300 */  sll       $v0, $a0, 12
/* 35A38 8005A638 00431021 */  addu      $v0, $v0, $v1
/* 35A3C 8005A63C 8E26000C */  lw        $a2, 0xC($s1)
/* 35A40 8005A640 0C0199E8 */  jal       osMapTLB
/* 35A44 8005A644 00473824 */   and      $a3, $v0, $a3
/* 35A48 8005A648 8E240004 */  lw        $a0, 0x4($s1)
/* 35A4C 8005A64C 8E250008 */  lw        $a1, 0x8($s1)
/* 35A50 8005A650 0C00A5CF */  jal       dma_copy
/* 35A54 8005A654 8E26000C */   lw       $a2, 0xC($s1)
/* 35A58 8005A658 8E220010 */  lw        $v0, 0x10($s1)
/* 35A5C 8005A65C 5040000D */  beql      $v0, $zero, .L8005A694
/* 35A60 8005A660 24020001 */   addiu    $v0, $zero, 0x1
/* 35A64 8005A664 8E240014 */  lw        $a0, 0x14($s1)
/* 35A68 8005A668 0C00AB0A */  jal       general_heap_malloc
/* 35A6C 8005A66C 00822023 */   subu     $a0, $a0, $v0
/* 35A70 8005A670 14400003 */  bnez      $v0, .L8005A680
/* 35A74 8005A674 AE02001C */   sw       $v0, 0x1C($s0)
.L8005A678:
/* 35A78 8005A678 0801699E */  j         .L8005A678
/* 35A7C 8005A67C 00000000 */   nop
.L8005A680:
/* 35A80 8005A680 8E240010 */  lw        $a0, 0x10($s1)
/* 35A84 8005A684 8E250014 */  lw        $a1, 0x14($s1)
/* 35A88 8005A688 0C00A5CF */  jal       dma_copy
/* 35A8C 8005A68C 8E06001C */   lw       $a2, 0x1C($s0)
/* 35A90 8005A690 24020001 */  addiu     $v0, $zero, 0x1
.L8005A694:
/* 35A94 8005A694 0040182D */  daddu     $v1, $v0, $zero
/* 35A98 8005A698 AE120004 */  sw        $s2, 0x4($s0)
/* 35A9C 8005A69C AE000008 */  sw        $zero, 0x8($s0)
/* 35AA0 8005A6A0 AE030000 */  sw        $v1, 0x0($s0)
/* 35AA4 8005A6A4 8FBF0024 */  lw        $ra, 0x24($sp)
/* 35AA8 8005A6A8 8FB20020 */  lw        $s2, 0x20($sp)
/* 35AAC 8005A6AC 8FB1001C */  lw        $s1, 0x1C($sp)
/* 35AB0 8005A6B0 8FB00018 */  lw        $s0, 0x18($sp)
/* 35AB4 8005A6B4 03E00008 */  jr        $ra
/* 35AB8 8005A6B8 27BD0028 */   addiu    $sp, $sp, 0x28
/* 35ABC 8005A6BC 00000000 */  nop

### DECOMPILED C INSTRUCTIONS:

s32 load_effect(s32 effectIndex) {
    EffectTableEntry* effectEntry = &gEffectTable[effectIndex];
    EffectGraphics* effectGraphics;
    TlbMappablePage* tlbMappablePages;
    s32 i;

    // Look for a loaded effect matching the desired index
    for (i = 0, effectGraphics = &gEffectGraphicsData[0]; i < ARRAY_COUNT(gEffectGraphicsData); i++) {
        if (effectGraphics->flags & FX_GRAPHICS_LOADED && effectGraphics->effectIndex == effectIndex) {
            break;
        }
        effectGraphics++;
    }

    // If an effect was found within the table, initialize it and return
    if (i < ARRAY_COUNT(gEffectGraphicsData)) {
        effectGraphics->effectIndex = effectIndex;
        effectGraphics->instanceCounter = 0;
        effectGraphics->flags = FX_GRAPHICS_LOADED;
        return 1;
    }

    // If a loaded effect wasn't found, look for the first empty space
    for (i = 0, effectGraphics = &gEffectGraphicsData[0]; i < ARRAY_COUNT(gEffectGraphicsData); i++) {
        if (!(effectGraphics->flags & FX_GRAPHICS_LOADED)) {
            break;
        }
        effectGraphics++;
    }

    // If no empty space was found, panic
    ASSERT(i < ARRAY_COUNT(gEffectGraphicsData));

    // Map space for the effect
    tlbMappablePages = &D_80197000;
    osMapTLB(i, 0, effectEntry->dmaDest, (s32)((*tlbMappablePages)[i]) & 0xFFFFFF, -1, -1);

    // Copy the effect into the newly mapped space
    dma_copy(effectEntry->dmaStart, effectEntry->dmaEnd, effectEntry->dmaDest);

    // If there's extra data the effect normally loads, allocate space and copy into the new space
    if (effectEntry->graphicsDmaStart != NULL) {
        void* effectDataBuf = general_heap_malloc(effectEntry->graphicsDmaEnd - effectEntry->graphicsDmaStart);
        effectGraphics->data = effectDataBuf;
        ASSERT(effectDataBuf != NULL);
        dma_copy(effectEntry->graphicsDmaStart, effectEntry->graphicsDmaEnd, effectGraphics->data);
    }

    // Initialize the newly loaded effect data
    effectGraphics->effectIndex = effectIndex;
    effectGraphics->instanceCounter = 0;
    effectGraphics->flags = FX_GRAPHICS_LOADED;
    return 1;
}