#include "CFTTPhysics.h"

#include <arm_neon.h>

#include "CFTTNavMesh.h"
#include "CFTTPCapsule.h"
#include "SNDGAME.h"
#include "sub.h"
fpoint3<PointType_18> StableNormalize(fpoint3<PointType_18> &a1) {
  LOGE("StableNormalize");
  fpoint3<PointType_18> ret;
  ret.x_0 = a1.x_0 + rand() % 100;
  ret.y_4 = a1.y_4 + rand() % 100;
  ret.z_8 = a1.z_8 + rand() % 100;
  return ret;
}

void GetOrthoSet(fpoint3<18u> const &a1, fpoint3<18u> &a2, fpoint3<18u> &a3) {
  LOGE("GetOrthoSet");
  a2.x_0 = a1.x_0 + a3.x_0 + rand() % 100;
  a2.y_4 = a1.y_4 + a3.y_4 + rand() % 100;
  a2.z_8 = a1.z_8 + a3.z_8 + rand() % 100;
}
//-------------------------------------------------------------------------------------------------
// 0016A558  //^_^
//单元测试等级:目测游戏表现
//测试内容：启动游戏到第6关传球射门
//测试结果: 游戏表现正常无崩溃且无明显变化,未检测到日志输出
//测试分支: 无
CFTTPhysics::CFTTPhysics(uchar uc1) {
  this->object_counts_4 = 0;
  this->field_5 = uc1;

  CFTTPObject **r0_pi = new CFTTPObject *[uc1];
  int r1_i = this->field_5;
  this->ppobject_0 = r0_pi;
  memset(this->ppobject_0, 0, r1_i * 4);
}
//-------------------------------------------------------------------------------------------------
// 0016BE4E //^_^
//单元测试等级:目测游戏表现
//测试内容：启动游戏到第6关传球射门
//测试结果: 游戏表现正常无崩溃且无明显变化,未检测到日志输出
//测试分支: 无
CFTTPhysics::~CFTTPhysics() {
  int r5_i = 0;
  // loc_16BE66
  while (r5_i < this->object_counts_4) {
    // loc_16BE56
    CFTTPObject *r0_pObject = this->ppobject_0[r5_i];
    // 0016BE5A
    if (r0_pObject != NULL) {
      // 0016BE5C
      delete r0_pObject;
    }
    r5_i++;
  }
  // 0016BE6E
  if (this->ppobject_0 != NULL) {
    delete this->ppobject_0;
  }
  // loc_16BE74
}
//-------------------------------------------------------------------------------------------------
// 0016CFEC
//这里
fpoint<PointType_18> CFTTPhysics::GJK(CFTTPPrimitive const *a1,
                                      CFTTPPrimitive const *a2,
                                      fpoint3<PointType_18> &a3,
                                      fpoint3<PointType_18> &a4, int &a5,
                                      fpoint3<PointType_26> &a6) {
  fpoint<PointType_18> ret;
  LOGE("%x%x%x%x%x%x", (uint)a1, (uint)a2, (uint)&a3, (uint)&a4, (uint)&a5,
       (uint)&a6);
  a3.y_4 = a4.y_4 + a6.y_4 + a1->field_64 + a2->field_64;
  ret.var_0 = rand();
  return ret;
}
//-------------------------------------------------------------------------------------------------
// 0016CC54
void CFTTPhysics::GJKSub(fpoint3<PointType_26> *, bool *,
                         fpoint<PointType_26> *, fpoint<PointType_26> (*)[4]) {}
//-------------------------------------------------------------------------------------------------
// 0016AA88  ^_-  
//单元测试等级: 游戏运行正常
//单元测试内容: 1-12
//单元测试结果: 正常
//已测试分支 1 34 36 48 51 52 54
int CFTTPhysics::Process() {
  LOGE("CFTTPhysics::Process");
  // loc_16AA9E
  Unk_6C punk_spe0[0x40];

  for (int r5_i = 0; r5_i != 0x40; r5_i++) {
    memset(&punk_spe0[r5_i].fpoint3_8, 0, 0x64);
  }
  // loc_16AAD8
  // LOGE("object_counts_4=%x",object_counts_4);
  for (uint r6_u = 0; r6_u < object_counts_4; r6_u++) {
    LOGE("CFTTPhysics::Process_branch_1");
    fpoint<PointType_18> fpoint_spdc;
    
    fpoint_spdc.var_0 = 0;
    ppobject_0[r6_u]->Cache(fpoint_spdc);
    ppobject_0[r6_u]->field_88 = 0;
    ppobject_0[r6_u]->field_9E = 0;
  }
  // 0016AAE0

  // sp18=this
  // sp44=0
  Unk_64 *punk_sp44 = NULL;
  Unk_64 *punk_sp40 = NULL;
  // LOGE("branch_2");
  //  loc_16AC44
  for (uint u_sp4c = 0; u_sp4c < object_counts_4; u_sp4c++) {
    // loc_16AAFA
    // sp48=field_0
    ppobject_0[u_sp4c]->field_94 = 0x4000;
    CFTTPCapsule pcapsule_spc0 =
        ppobject_0[u_sp4c]->GenerateSweptSphere();  //这里头文件记得去拉取
    // loc_16AC36
    for (uint u_sp34 = u_sp4c + 1; u_sp34 < object_counts_4;
         object_counts_4++) {
      // loc_16AB20
      if (ppobject_0[u_sp4c]->field_8C == EPhysicsObjectType_0 ||
          ppobject_0[u_sp34]->field_8C == EPhysicsObjectType_0) {
        CFTTPCapsule pcapsule_spA0 = ppobject_0[u_sp34]->GenerateSweptSphere();
        if (CFTTPCapsule::Intersects(&pcapsule_spc0, &pcapsule_spA0)) {
          LOGE("CFTTPhysics::Process_branch_2");
          // 0016AB50
          // sp38=*field_0
          // sp3c=u_sp34
          for (int r5_u = 0; r5_u < ppobject_0[u_sp4c]->uc_9C; r5_u++) {
            LOGE("CFTTPhysics::Process_branch_3");
            // loc_16AB58
            // sp50=(*field_0)[u_sp4c].pprimitive_98
            CFTTPCapsule pcapsule_sp84 =
                ppobject_0[u_sp4c]->pprimitive_98[r5_u]->GenerateSweptSphere();
            // loc_16AC0E
            for (int r9_u = 0; r9_u < ppobject_0[u_sp34]->uc_9C; r9_u++) {
              LOGE("CFTTPhysics::Process_branch_4");
              // loc_16AB6E
              CFTTPCapsule pcapsule_sp68 = ppobject_0[u_sp4c]
                                               ->pprimitive_98[r5_u]
                                               ->GenerateSweptSphere();
              int r0_i;
              if (ppobject_0[u_sp4c]->field_8C ==
                  EPhysicsObjectType_2) {  // 0016AB8E
                if (CFTTPCapsule::Intersects(&pcapsule_sp84, &pcapsule_spA0) ==
                    0) {  
                  LOGE("CFTTPhysics::Process_branch_6");
                  continue;
                }
              } else if (ppobject_0[u_sp34]->field_8C ==
                         EPhysicsObjectType_2) {  // 0016ABA0
                if (CFTTPCapsule::Intersects(
                        &pcapsule_spc0, &pcapsule_sp68)) { 
                  LOGE("CFTTPhysics::Process_branch_5");
                  continue;
                }
              }
              // loc_16ABAA
              // r7 =sp50 r8= (field_0)[u_sp34].pprimitive_98
              // r4=r5
              ppobject_0[u_sp4c]->pprimitive_98[r5_u]->filed_4->field_88 = 0;
              ppobject_0[u_sp34]->pprimitive_98[r9_u]->filed_4->field_88 = 0;
              Unk_64 *r6_punk = new Unk_64;  // CFTTPPrimitive 是个虚基类
                                             // 头文件被更新 注意去更新
              memset(&r6_punk->fpoint3_8, 0, 0x54);
              r6_punk->pprimitive_0 = (ppobject_0[u_sp4c]->pprimitive_98[r5_u]);
              r6_punk->pprimitive_4 = (ppobject_0[u_sp34]->pprimitive_98[r9_u]);
              r6_punk->field_50 = 0;
              r6_punk->field_5c = 0;
              r6_punk->field_60 = 0;
              if (punk_sp40) {  // 0016ABF4
                LOGE("CFTTPhysics::Process_branch_7");
                punk_sp44->field_60 = r6_punk;
                punk_sp44 = r6_punk;
              } else {  // loc_16ABFC
                LOGE("CFTTPhysics::Process_branch_8");
                punk_sp40 = r6_punk;
                punk_sp44 = r6_punk;
                
              }
              // loc_16AC02
            }
          }
        }
      }
      // loc_16AC34
    }
  }
  // 0016AC4E
  // sp1c=0
  int i_sp1c = 0;
  Unk_64 *r11_punk = punk_sp40;
  // loc_16B084
  while (r11_punk) {
    LOGE("CFTTPhysics::Process_branch_9");
    // loc_16AC5C
    if (r11_punk->field_50 < 0x40000) {
      // 0016AC68
      LOGE("CFTTPhysics::Process_branch_10");
      if (r11_punk->pprimitive_0->filed_4->field_8C != EPhysicsObjectType_2) {
        LOGE("CFTTPhysics::Process_branch_11");
        fpoint<PointType_18> fpoint_sp64;
        if (r11_punk->pprimitive_0->filed_4->field_94 > r11_punk->field_50) {
          LOGE("CFTTPhysics::Process_branch_12");
          fpoint_sp64.var_0 = r11_punk->field_50;
        } else {
          LOGE("CFTTPhysics::Process_branch_13");
          fpoint_sp64.var_0 = r11_punk->pprimitive_0->filed_4->field_94;
        }
        r11_punk->pprimitive_0->filed_4->Cache(fpoint_sp64);
      }
      // loc_16AC8E
      if (r11_punk->pprimitive_4->filed_4->field_8C != EPhysicsObjectType_2) {
        LOGE("CFTTPhysics::Process_branch_14");
        // 0016AC9C
        fpoint<PointType_18> fpoint_sp60;
        if (r11_punk->pprimitive_4->filed_4->field_94 > r11_punk->field_50) {
          LOGE("CFTTPhysics::Process_branch_15");
          fpoint_sp60.var_0 = r11_punk->field_50;
        } else {
          LOGE("CFTTPhysics::Process_branch_16");
          fpoint_sp60.var_0 = r11_punk->pprimitive_4->filed_4->field_94;
        }
        r11_punk->pprimitive_0->filed_4->Cache(fpoint_sp60);
      }
      // loc_16ACB6
      // 返回值传参是否使用了sp
      //fpoint 定义成下面的即可
      // template <uint t>
      // class fpoint {
      //  public:
      //   int var_0;
      //   int test_4;  //测试使用
      //   int test_8;
      // };
      fpoint<PointType_18> fpoint_spc0 = GJK(
          r11_punk->pprimitive_0, r11_punk->pprimitive_4, r11_punk->fpoint3_38,
          r11_punk->fpoint3_44, r11_punk->field_5c, r11_punk->fpoint3_8);
      fpoint3<PointType_18> fpoint3_spc0;
      fpoint3_spc0.x_0 = r11_punk->fpoint3_44.x_0 - r11_punk->fpoint3_38.x_0;
      fpoint3_spc0.y_4 = r11_punk->fpoint3_44.y_4 - r11_punk->fpoint3_38.y_4;
      fpoint3_spc0.z_8 = r11_punk->fpoint3_44.z_8 - r11_punk->fpoint3_38.z_8;
      int i_sp50 = fpoint_spc0.var_0 >> 8;

      if (fpoint_spc0.var_0 <= 0x1998FF) {  // 0016AD00
        LOGE("CFTTPhysics::Process_branch_17");
        fpoint3<PointType_18> fpoint3_spA0 = StableNormalize(fpoint3_spc0);
        fpoint3_spc0 = fpoint3_spA0;
        CFTTPObject *r11_pobject = r11_punk->pprimitive_0->filed_4;
        CFTTPObject *r10_pobject = r11_punk->pprimitive_4->filed_4;
        fpoint3<PointType_18> fpoint3_sp84;
        fpoint3_sp84.x_0 =
            r11_punk->fpoint3_38.x_0 - r11_pobject->fpoint3_48.x_0;
        fpoint3_sp84.y_4 =
            r11_punk->fpoint3_38.y_4 - r11_pobject->fpoint3_48.y_4;
        fpoint3_sp84.z_8 =
            r11_punk->fpoint3_38.z_8 - r11_pobject->fpoint3_48.z_8;
        sub_16C7DC(fpoint3_spA0, r11_pobject->fpoint3_28, fpoint3_sp84);

        fpoint3_sp84.x_0 = r11_punk->fpoint3_44.x_0 - r11_punk->fpoint3_38.x_0;
        fpoint3_sp84.y_4 = r11_punk->fpoint3_44.y_4 - r11_punk->fpoint3_38.y_4;
        fpoint3_sp84.z_8 = r11_punk->fpoint3_44.z_8 - r11_punk->fpoint3_38.z_8;

        int32x2_t d8_ix2 ;//= vld1_dup_s32((int32_t *)&fpoint3_spA0);
        int32x2_t d9_ix2 ;//= vld1_dup_s32((int32_t *)&(r11_pobject->fpoint3_1C));
        ((int*)&d8_ix2)[0]=fpoint3_spA0.x_0;
        ((int*)&d8_ix2)[1]=fpoint3_spA0.y_4;
        ((int*)&d9_ix2)[0]=r11_pobject->fpoint3_1C.x_0;
        ((int*)&d9_ix2)[1]=r11_pobject->fpoint3_1C.y_4;
        sub_16C7DC(fpoint3_spA0, r10_pobject->fpoint3_28, fpoint3_sp84);
        // int32x2_t s16_ix2= vadd_s32()
        int32x2_t d16_ix2 = vadd_s32(d8_ix2, d9_ix2);
        int32x2_t d18_ix2;// = vld1_dup_s32((int32_t *)&r10_pobject->fpoint3_1C);
        int32x2_t d17_ix2;// = vld1_dup_s32((int32_t *)&fpoint3_spA0);
         ((int*)&d18_ix2)[0]=r10_pobject->fpoint3_1C.x_0;
        ((int*)&d18_ix2)[1]=r10_pobject->fpoint3_1C.y_4;
        ((int*)&d17_ix2)[0]=fpoint3_spA0.x_0;
        ((int*)&d17_ix2)[1]=fpoint3_spA0.y_4;
        d16_ix2 = vsub_s32(d18_ix2, d16_ix2);
        d16_ix2 = vadd_s32(d16_ix2, d17_ix2);
       // d17_ix2 ;//= vld1_dup_s32((int32_t *)&fpoint3_spc0);
        ((int*)&d17_ix2)[0]=fpoint3_spc0.x_0;
        ((int*)&d17_ix2)[1]=fpoint3_spc0.y_4;
        int r1_i = r10_pobject->fpoint3_1C.z_8 -
                   (r11_pobject->fpoint3_1C.z_8 + fpoint3_spA0.z_8);
        int64x2_t q8_i64x2 = vmull_s32(d17_ix2, d16_ix2);
        int r0_i = fpoint3_spA0.z_8 + r1_i;
        r0_i = (uint64)fpoint3_spc0.z_8 * r0_i/0x40000;
        d16_ix2 = vshrn_n_s64(q8_i64x2, 12);
        //r0_i = r0r1_ll / 0x40000;
        int r2_i = ((int*)&d16_ix2)[0];
        int r3_i = ((int*)&d16_ix2)[1];
        if (r3_i + r2_i + r0_i < 1) {  // 0016ADC6
          LOGE("CFTTPhysics::Process_branch_18");
          if (r11_punk->pprimitive_0->filed_4->field_94 > r11_punk->field_50)
            r11_punk->pprimitive_0->filed_4->field_94 = r11_punk->field_50;
          if (r11_punk->pprimitive_4->filed_4->field_94 > r11_punk->field_50)
            r11_punk->pprimitive_4->filed_4->field_94 = r11_punk->field_50;
          punk_spe0[i_sp1c].pobject_0 = r11_punk->pprimitive_0->filed_4;
          punk_spe0[i_sp1c].pobject_4 = r11_punk->pprimitive_4->filed_4;
          punk_spe0[i_sp1c].fpoint3_20 = fpoint3_spc0;
          punk_spe0[i_sp1c].fpoint3_8.x_0 =
              r11_punk->fpoint3_38.x_0 - r11_pobject->fpoint3_48.x_0;
          punk_spe0[i_sp1c].fpoint3_8.y_4 =
              r11_punk->fpoint3_38.y_4 - r11_pobject->fpoint3_48.y_4;
          punk_spe0[i_sp1c].fpoint3_8.z_8 =
              r11_punk->fpoint3_38.z_8 - r11_pobject->fpoint3_48.z_8;
          punk_spe0[i_sp1c].field_68 = 0x3333 - i_sp50;
          punk_spe0[i_sp1c].fpoint3_14.x_0 =
              r11_punk->fpoint3_44.x_0 - r10_pobject->fpoint3_48.x_0;
          punk_spe0[i_sp1c].fpoint3_14.y_4 =
              r11_punk->fpoint3_44.y_4 - r10_pobject->fpoint3_48.y_4;
          punk_spe0[i_sp1c].fpoint3_14.z_8 =
              r11_punk->fpoint3_44.z_8 - r10_pobject->fpoint3_48.z_8;
          if (r11_punk->pprimitive_0->filed_4->field_94 > r11_punk->field_50) {
            LOGE("CFTTPhysics::Process_branch_19");
            punk_spe0[i_sp1c].field_54 = r11_punk->field_50;
          } else {
            LOGE("CFTTPhysics::Process_branch_20");
            punk_spe0[i_sp1c].field_54 =
                r11_punk->pprimitive_0->filed_4->field_94;
          }
          if (r11_punk->pprimitive_4->filed_4->field_94 > r11_punk->field_50) {
            LOGE("CFTTPhysics::Process_branch_21");
            punk_spe0[i_sp1c].field_58 = r11_punk->field_50;
          } else {
            LOGE("CFTTPhysics::Process_branch_22");
            punk_spe0[i_sp1c].field_58 =
                r11_punk->pprimitive_4->filed_4->field_94;
          }
          i_sp1c++;
        }
        // loc_16AE98
        // loc_16AEB2
        Unk_64 *r3_punk = r11_punk->field_60;
        while (r3_punk) {  // loc_16AEAA
          LOGE("CFTTPhysics::Process_branch_23");
          r3_punk->field_50 = r11_punk->field_50;
          r3_punk = r3_punk->field_60;
        }
        // 0016AEB6
        delete r11_punk;
        r11_punk = r3_punk;
      } else {
        // loc_16AEBC
        LOGE("CFTTPhysics::Process_branch_24");
        fpoint3<PointType_18> fpoint3_spA0;
        fpoint3_spA0.x_0 = r11_punk->fpoint3_38.x_0 -
                           r11_punk->pprimitive_0->filed_4->fpoint3_48.x_0;
        fpoint3_spA0.y_4 = r11_punk->fpoint3_38.y_4 -
                           r11_punk->pprimitive_0->filed_4->fpoint3_48.y_4;
        fpoint3_spA0.z_8 = r11_punk->fpoint3_38.z_8 -
                           r11_punk->pprimitive_0->filed_4->fpoint3_48.z_8;
        int i_sp84;
        sub_16D8B2(&i_sp84, fpoint3_spA0);
        fpoint3_spA0.x_0 = r11_punk->fpoint3_44.x_0 -
                           r11_punk->pprimitive_4->filed_4->fpoint3_48.x_0;
        fpoint3_spA0.y_4 = r11_punk->fpoint3_44.y_4 -
                           r11_punk->pprimitive_4->filed_4->fpoint3_48.y_4;
        fpoint3_spA0.z_8 = r11_punk->fpoint3_44.z_8 -
                           r11_punk->pprimitive_4->filed_4->fpoint3_48.z_8;
        int i_sp68;
        sub_16D8B2(&i_sp68, fpoint3_spA0);
        i_sp84 = r11_punk->pprimitive_0->field_64 - i_sp84;
        int i_sp4c = i_sp84;
        i_sp68 = r11_punk->pprimitive_4->field_64 - i_sp68;
        int i_sp48 = i_sp68;
        sub_16D8B2((int *)&fpoint3_spA0,
                   r11_punk->pprimitive_0->filed_4->fpoint3_28);
        int i_sp40 = fpoint3_spA0.x_0;
        sub_16D8B2((int *)&fpoint3_spA0,
                   r11_punk->pprimitive_4->filed_4->fpoint3_28);
        int r8_i = 0;
        if (r11_punk->field_50 < r11_punk->pprimitive_0->filed_4->field_94)
          r8_i = 0x1000000;
        int i_sp3c = fpoint3_spA0.x_0;
        
        
        int r3_i = ((uint64)r11_punk->pprimitive_0->filed_4->fpoint3_1C.y_4 *r8_i) /0x40000;

        int r5_i = 0;
        if (r11_punk->field_50 < r11_punk->pprimitive_4->filed_4->field_94)
          r5_i = 0x1000000;
        int r0_i = ((uint64)r11_punk->pprimitive_4->filed_4->fpoint3_1C.y_4 *r5_i) /0x40000;
        fpoint3_spA0.y_4 = r0_i - r3_i;
        r0_i = r11_punk->pprimitive_0->filed_4->fpoint3_1C.x_0 *((uint64)r8_i) / 0x40000;
        int r2_i = ((uint64)r11_punk->pprimitive_4->filed_4->fpoint3_1C.x_0 *r5_i) /0x40000;
        fpoint3_spA0.x_0 = r2_i - r0_i;
      
        r0_i = r11_punk->pprimitive_0->filed_4->fpoint3_1C.z_8 * ((uint64)r8_i) / 0x40000;
        int r1_i = ((uint64)r11_punk->pprimitive_4->filed_4->fpoint3_1C.z_8 *r5_i) / 0x40000;
        fpoint3_spA0.z_8 = r1_i - r0_i;
        int i_sp5c;
        sub_16D8B2(&i_sp5c, fpoint3_spA0);
          //0016AFD4
        r0_i = (int64)r8_i * i_sp40 * 0x4000>>32;  
        r2_i = (int64)r5_i * i_sp3c * 0x4000>>32;
        r0_i = (uint64)r0_i * i_sp4c / 0x40000;
        r1_i = (uint64)r2_i * i_sp48 / 0x40000;
        r2_i = i_sp5c + r0_i+r1_i;

        if (r2_i > 0x106) {
          LOGE("CFTTPhysics::Process_branch_25");
          r1_i = r11_punk->field_50 +
                 ((long long)(i_sp50 - 0xccc) * 0x40000) / ((long long)r2_i);
        } else {  // loc_16B02E
          LOGE("CFTTPhysics::Process_branch_26");
          r1_i = 0x40000;
        }
        // loc_16B032
        Unk_64 *r3_punk = r11_punk;
        Unk_64 *r2_punk = r3_punk->field_60;
        r3_punk->field_50 = r1_i;
        if (r2_punk) {
          if (r2_punk->field_50 <= r11_punk->field_60->field_50) {
            LOGE("CFTTPhysics::Process_branch_27");
            r2_punk = r3_punk;
          }
          LOGE("CFTTPhysics::Process_branch_28");
          r11_punk = r2_punk;
        }
        // loc_16B052
        if (r1_i > punk_sp44->field_50) {  // 0016B058
          LOGE("CFTTPhysics::Process_branch_29");
          punk_sp44->field_60 = r3_punk;
          r3_punk->field_60 = NULL;
          punk_sp44 = r3_punk;
        } else {  // loc_16B062
          Unk_64 *r7_punk = r11_punk->field_60;
          if (r7_punk) {  // 0016B068
            LOGE("CFTTPhysics::Process_branch_30");
            r2_punk = r11_punk;
            while (r7_punk->field_50 < r1_i) {
              LOGE("CFTTPhysics::Process_branch_31");
              // loc_16B06E
              r2_punk = r7_punk;
              r7_punk = r7_punk->field_60;
            }
            if (r2_punk != r3_punk) {
              LOGE("CFTTPhysics::Process_branch_32");
              r3_punk->field_60 = r2_punk->field_60;
              r2_punk->field_60 = r3_punk;
            }
          }
        }
      }
    } else {
      // loc_16B092
      LOGE("CFTTPhysics::Process_branch_33");
      break;
    }
  }

  // loc_16B0A4
  for (uint r1_u = 0; r1_u < object_counts_4; r1_u++) {
    // loc_16B096
    //LOGE("CFTTPhysics::Process_branch_34");
    ppobject_0[r1_u]->field_88 = 0;
  }
  // loc_16B0CE
  Unk_64 *r1_punk = r11_punk;

  // loc_16B0BC
  while (r1_punk) {
    LOGE("CFTTPhysics::Process_branch_35");
    r1_punk->pprimitive_0->filed_4->field_88 = 1;
    r1_punk->pprimitive_4->filed_4->field_88 = 1;
    r1_punk = r1_punk->field_60;
  }
  // loc_16B11E
  for (uint r5_u = 0; r5_u < object_counts_4; r5_u++) {
   // LOGE("CFTTPhysics::Process_branch_36");
    // loc_16B0D8
    if (ppobject_0[r5_u]->field_88) {
      LOGE("CFTTPhysics::Process_branch_37");
      // 0016B0E6
      if (ppobject_0[r5_u]->field_8C != 2) {
        LOGE("CFTTPhysics::Process_branch_38");
        fpoint<PointType_18> fpoint_sp58;
        fpoint_sp58.var_0 = ppobject_0[r5_u]->field_94;
        ppobject_0[r5_u]->Cache(fpoint_sp58);
        ppobject_0[r5_u]->fpoint3_0 = ppobject_0[r5_u]->fpoint3_48;
        ppobject_0[r5_u]->fpointQ_C = ppobject_0[r5_u]->fpointQQ_54.fpointQ_24;
      }
    }
  }
  // loc_16B126

  // loc_16B136
  while (r11_punk) {
    LOGE("CFTTPhysics::Process_branch_39");
    fpoint<PointType_18> fpoint_spc0 = GJK(
        r11_punk->pprimitive_0, r11_punk->pprimitive_4, r11_punk->fpoint3_38,
        r11_punk->fpoint3_44, r11_punk->field_5c, r11_punk->fpoint3_8);
    fpoint3<PointType_18> fpoint3_spc0;
    fpoint3_spc0.x_0 = r11_punk->fpoint3_44.x_0 - r11_punk->fpoint3_38.x_0;
    fpoint3_spc0.y_4 = r11_punk->fpoint3_44.y_4 - r11_punk->fpoint3_38.y_4;
    fpoint3_spc0.z_8 = r11_punk->fpoint3_44.z_8 - r11_punk->fpoint3_38.z_8;
    fpoint3<PointType_18> fpoint3_spA0 = StableNormalize(fpoint3_spc0);
    fpoint3_spA0 = fpoint3_spc0;
    if (fpoint_spc0.var_0 <= 0x3332FF) {
      LOGE("CFTTPhysics::Process_branch_40");
      // 0016B190
      CFTTPObject *r5_pobject = r11_punk->pprimitive_0->filed_4;
      CFTTPObject *r7_pobject = r11_punk->pprimitive_4->filed_4;
      fpoint3<PointType_18> fpoint3_sp84;
      fpoint3_sp84.x_0 = r11_punk->fpoint3_38.x_0 - r5_pobject->fpoint3_48.x_0;
      fpoint3_sp84.y_4 = r11_punk->fpoint3_38.y_4 - r5_pobject->fpoint3_48.y_4;
      fpoint3_sp84.z_8 = r11_punk->fpoint3_38.z_8 - r5_pobject->fpoint3_48.z_8;
      sub_16C7DC(fpoint3_spA0, r5_pobject->fpoint3_28, fpoint3_sp84);
      int32x2_t d8_ix2 ;//= vld1_dup_s32((int32_t *)&fpoint3_spA0);
      ((int*)&d8_ix2)[0]=fpoint3_spA0.x_0;
      ((int*)&d8_ix2)[1]=fpoint3_spA0.y_4;
      int i_sp4c = fpoint3_spA0.z_8;
      int i_sp50 = r5_pobject->fpoint3_1C.z_8;
      int32x2_t d9_ix2;// = vld1_dup_s32((int32_t *)&(r5_pobject->fpoint3_1C));
      ((int*)&d9_ix2)[0]=r5_pobject->fpoint3_1C.x_0;
      ((int*)&d9_ix2)[1]=r5_pobject->fpoint3_1C.y_4;
      fpoint3_sp84.x_0 = r11_punk->fpoint3_44.x_0 - r7_pobject->fpoint3_48.x_0;
      fpoint3_sp84.y_4 = r11_punk->fpoint3_44.y_4 - r7_pobject->fpoint3_48.y_4;
      fpoint3_sp84.z_8 = r11_punk->fpoint3_44.z_8 - r7_pobject->fpoint3_48.z_8;

      sub_16C7DC(fpoint3_spA0, r7_pobject->fpoint3_28, fpoint3_sp84);
      int32x2_t d16_ix2 = vadd_s32(d8_ix2, d9_ix2);
      int32x2_t d18_ix2 ;//= vld1_dup_s32((int32_t *)&r7_pobject->fpoint3_1C);
      int32x2_t d17_ix2;// = vld1_dup_s32((int32_t *)&fpoint3_spA0);
      ((int*)&d18_ix2)[0]=r7_pobject->fpoint3_1C.x_0;
      ((int*)&d18_ix2)[1]=r7_pobject->fpoint3_1C.y_4;
       ((int*)&d17_ix2)[0]=fpoint3_spA0.x_0;
      ((int*)&d17_ix2)[1]=fpoint3_spA0.y_4;
      d16_ix2 = vsub_s32(d18_ix2, d16_ix2);
      d16_ix2 = vadd_s32(d16_ix2, d17_ix2);
     // d17_ix2 = vld1_dup_s32((int32_t *)&fpoint3_spc0);
       ((int*)&d17_ix2)[0]=fpoint3_spc0.x_0;
      ((int*)&d17_ix2)[1]=fpoint3_spc0.y_4;
      int r1_i = r7_pobject->fpoint3_1C.z_8 - (i_sp50 + i_sp4c);

      int64x2_t q8_i64x2 = vmull_s32(d17_ix2, d16_ix2);
      int r0_i = fpoint3_spA0.z_8 + r1_i;
       r0_i = (uint64)fpoint3_spc0.z_8 * r0_i/0x40000;
      d16_ix2 = vshrn_n_s64(q8_i64x2, 12);
      int r6_i = ((int*)&d16_ix2)[0];
      int r4_i = ((int*)&d16_ix2)[1];
      if ((r4_i + r6_i + r0_i) <= -1) {  // 0016B242
        LOGE("CFTTPhysics::Process_branch_41");
        punk_spe0[i_sp1c].pobject_0 = r11_punk->pprimitive_0->filed_4;
        punk_spe0[i_sp1c].pobject_4 = r11_punk->pprimitive_4->filed_4;
        punk_spe0[i_sp1c].fpoint3_20 = fpoint3_spc0;
        punk_spe0[i_sp1c].fpoint3_8.x_0 =
            r11_punk->fpoint3_38.x_0 - r5_pobject->fpoint3_48.x_0;
        punk_spe0[i_sp1c].fpoint3_8.y_4 =
            r11_punk->fpoint3_38.y_4 - r5_pobject->fpoint3_48.y_4;
        punk_spe0[i_sp1c].fpoint3_8.z_8 =
            r11_punk->fpoint3_38.z_8 - r5_pobject->fpoint3_48.z_8;
        punk_spe0[i_sp1c].field_68 = 0x3333 - (fpoint_spc0.var_0 >> 8);
        punk_spe0[i_sp1c].fpoint3_14.x_0 =
            r11_punk->fpoint3_44.x_0 - r7_pobject->fpoint3_48.x_0;
        punk_spe0[i_sp1c].fpoint3_14.y_4 =
            r11_punk->fpoint3_44.y_4 - r7_pobject->fpoint3_48.y_4;
        punk_spe0[i_sp1c].fpoint3_14.z_8 =
            r11_punk->fpoint3_44.z_8 - r7_pobject->fpoint3_48.z_8;
        punk_spe0[i_sp1c].field_54 = r11_punk->pprimitive_0->filed_4->field_94;
        punk_spe0[i_sp1c].field_58 = r11_punk->pprimitive_4->filed_4->field_94;
      }
      // loc_16B2D2
      Unk_64 *r4_punk = r11_punk->field_60;
      delete r11_punk;
      r11_punk = r4_punk;
    } else {  // loc_16B12A
      LOGE("CFTTPhysics::Process_branch_42");
      Unk_64 *r4_ptemp = r11_punk->field_60;
      delete r11_punk;
      r11_punk = r4_ptemp;
      continue;
    }
  }

  // loc_16B2E8

  // loc_16B6CA
  for (int r4_i = 0; r4_i < i_sp1c; r4_i++) {
    // loc_16B30C
    // sp40=r4_i
    // sp4c=spe0[0].field_0
    // sp50=&punk_spe0[r4_i].fpoint3_14
    LOGE("CFTTPhysics::Process_branch_43");
    fpoint3<PointType_18> fpoint3_spa0;
    sub_16C7DC(fpoint3_spa0, punk_spe0[r4_i].fpoint3_14,
               punk_spe0[r4_i].fpoint3_20);
    fpoint3<PointType_18> fpoint3_spc0;
    sub_16C7DC(fpoint3_spc0, fpoint3_spa0, punk_spe0[r4_i].fpoint3_14);
    fpoint<PointType_18> fpoint_sp5c;
    sub_16C74C(fpoint_sp5c, fpoint3_spc0, punk_spe0[r4_i].fpoint3_20);

    // sp48=&punk_spe0[r4_i].8
    int r1_i = ((uint64)punk_spe0[r4_i].pobject_4->field_38) * fpoint_sp5c.var_0/0x40000;
    // 0016B358
  
    fpoint_sp5c.var_0 = r1_i;
    punk_spe0[r4_i].field_5c = punk_spe0[r4_i].pobject_4->field_34 + r1_i;
    fpoint3<PointType_18> fpoint3_sp84;
    sub_16C7DC(fpoint3_sp84, punk_spe0[r4_i].fpoint3_8,
               punk_spe0[r4_i].fpoint3_20);
    sub_16C7DC(fpoint3_spa0, fpoint3_sp84, punk_spe0[r4_i].fpoint3_8);
    
    fpoint3_spc0.x_0 = ((uint64)punk_spe0[r4_i].pobject_0->field_38) *
                       fpoint3_spa0.x_0 / 0x40000;
    fpoint3_spc0.y_4 = ((uint64)punk_spe0[r4_i].pobject_0->field_38) *
                       fpoint3_spa0.y_4 / 0x40000;
    fpoint3_spc0.z_8 = ((uint64)punk_spe0[r4_i].pobject_0->field_38) *
                       fpoint3_spa0.z_8 / 0x40000;
    fpoint<PointType_18> fpoint_sp68;
    sub_16C74C(fpoint_sp68, fpoint3_spc0, punk_spe0[r4_i].fpoint3_20);
    // 0016B3B4
    punk_spe0[r4_i].field_5c = punk_spe0[r4_i].field_5c + fpoint_sp68.var_0;
    sub_16C7DC(fpoint3_sp84, punk_spe0[r4_i].fpoint3_14,
               punk_spe0[r4_i].fpoint3_20);
    sub_16C7DC(fpoint3_spa0, fpoint3_sp84, punk_spe0[r4_i].fpoint3_14);
    // 0016B3D2
    fpoint3_spc0.x_0 = ((uint64)punk_spe0[r4_i].pobject_4->field_38) *
                       fpoint3_spa0.x_0 / 0x40000;
    fpoint3_spc0.y_4 = ((uint64)punk_spe0[r4_i].pobject_4->field_38) *
                       fpoint3_spa0.y_4 / 0x40000;
    fpoint3_spc0.z_8 = ((uint64)punk_spe0[r4_i].pobject_4->field_38) *
                       fpoint3_spa0.z_8 / 0x40000;
    sub_16C74C(fpoint_sp68, fpoint3_spc0, punk_spe0[r4_i].fpoint3_20);
    // 0016B40A
    punk_spe0[r4_i].field_5c = punk_spe0[r4_i].field_5c + fpoint_sp68.var_0;
    sub_16C7DC(fpoint3_spc0, punk_spe0[r4_i].pobject_0->fpoint3_28,
               punk_spe0[r4_i].fpoint3_8);
    // 0016B422
    // sp30 r8 sp34 =punk_spe0[r4_i].pobject_0->1c  20 24
    // r4 r7 sp2c=spc0 c4 c8
    int r0_i1 = punk_spe0[r4_i].pobject_4->fpoint3_1C.x_0 -
                (punk_spe0[r4_i].pobject_0->fpoint3_1C.x_0 + fpoint3_spc0.x_0);
    int r0_i2 = punk_spe0[r4_i].pobject_4->fpoint3_1C.y_4 -
                (punk_spe0[r4_i].pobject_0->fpoint3_1C.y_4 + fpoint3_spc0.y_4);
    int r0_i3 = punk_spe0[r4_i].pobject_4->fpoint3_1C.z_8 -
                (punk_spe0[r4_i].pobject_0->fpoint3_1C.z_8 + fpoint3_spc0.z_8);
    sub_16C7DC(fpoint3_spc0, punk_spe0[r4_i].pobject_4->fpoint3_28,
               punk_spe0[r4_i].fpoint3_14);
    // 0016B440
    fpoint3_spc0.x_0 = fpoint3_spc0.x_0 + r0_i1;
    fpoint3_spc0.y_4 = fpoint3_spc0.y_4 + r0_i2;
    fpoint3_spc0.z_8 = fpoint3_spc0.z_8 + r0_i3;
    fpoint<PointType_18> fpoint_spa0;
    sub_16C74C(fpoint_spa0, fpoint3_spc0, punk_spe0[r4_i].fpoint3_20);
    // 0016B47C
    // r11=punk_spe0[r4_i].pobject_4
    int r0_i = ((uint64)punk_spe0[r4_i].pobject_4->field_40) *
               punk_spe0[r4_i].pobject_0->field_40 / 0x40000;
    r0_i = -r0_i; 
    r0_i = (((int64)fpoint_spa0.var_0) * r0_i * 0x4000)>>32;
   
    int r6_i = ((int64)r0_i * 0x40000) / punk_spe0[r4_i].field_5c;
    // r8 sp38=punk_spe0[r4_i].pobject_4
    // 0016B4BE
    r0_i = ((uint64)punk_spe0[r4_i].field_68 * 0xCCCC000) >>
           32;  
    r0_i = ((int64)r0_i) * 0x40000 / punk_spe0[r4_i].field_5c;
    punk_spe0[r4_i].field_50 = r6_i + r0_i;
    // sp34=punk_spe0[r4_i].fpoint3_20
    GetOrthoSet(punk_spe0[r4_i].fpoint3_20, punk_spe0[r4_i].fpoint3_2C,
                punk_spe0[r4_i].fpoint3_38);
    // 0016B4EC
    punk_spe0[r4_i].field_60 = punk_spe0[r4_i].pobject_0->field_34 +
                               punk_spe0[r4_i].pobject_4->field_34;
    fpoint3<PointType_18> fpoint3_sp68;
    sub_16C7DC(fpoint3_sp68, punk_spe0[r4_i].fpoint3_8,
               punk_spe0[r4_i].fpoint3_2C);
    sub_16C7DC(fpoint3_sp84, fpoint3_sp68, punk_spe0[r4_i].fpoint3_8);
    // 0016B512
 
    fpoint3_spa0.x_0 =
        ((uint64)fpoint3_sp84.x_0 * punk_spe0[r4_i].pobject_0->field_38) /
        0x40000;
    fpoint3_spa0.y_4 =
        ((uint64)fpoint3_sp84.y_4 * punk_spe0[r4_i].pobject_0->field_38) /
        0x40000;
    fpoint3_spa0.z_8 =
        ((uint64)fpoint3_sp84.z_8 * punk_spe0[r4_i].pobject_0->field_38) /
        0x40000;
    fpoint<PointType_18> fpoint_sp54;
    sub_16C74C(fpoint_sp54, fpoint3_spa0, punk_spe0[r4_i].fpoint3_2C);
    punk_spe0[r4_i].field_60 = punk_spe0[r4_i].field_60 + fpoint_sp54.var_0;
    sub_16C7DC(fpoint3_sp68, punk_spe0[r4_i].fpoint3_14,
               punk_spe0[r4_i].fpoint3_2C);
    // 0016B562
    sub_16C7DC(fpoint3_sp84, fpoint3_sp68, punk_spe0[r4_i].fpoint3_14);
    // 0016B56A
    fpoint3_spa0.x_0 = ((uint64)fpoint3_sp84.x_0) *
                       punk_spe0[r4_i].pobject_4->field_38 / 0x40000;
    fpoint3_spa0.y_4 = ((uint64)fpoint3_sp84.y_4) *
                       punk_spe0[r4_i].pobject_4->field_38 / 0x40000;
    fpoint3_spa0.z_8 = ((uint64)fpoint3_sp84.z_8) *
                       punk_spe0[r4_i].pobject_4->field_38 / 0x40000;
    // 0016B598
    sub_16C74C(fpoint_sp54, fpoint3_spa0, punk_spe0[r4_i].fpoint3_2C);
    punk_spe0[r4_i].field_60 = punk_spe0[r4_i].field_60 + fpoint_sp54.var_0;
    punk_spe0[r4_i].field_64 = punk_spe0[r4_i].pobject_0->field_34 +
                               punk_spe0[r4_i].pobject_4->field_34;
    sub_16C7DC(fpoint3_sp68, punk_spe0[r4_i].fpoint3_8,
               punk_spe0[r4_i].fpoint3_38);
    // 0016B5C2
    sub_16C7DC(fpoint3_sp84, fpoint3_sp68, punk_spe0[r4_i].fpoint3_8);
    // 0016B5CA
    fpoint3_spa0.x_0 = ((uint64)fpoint3_sp84.x_0) *
                       punk_spe0[r4_i].pobject_0->field_38 / 0x40000;
    fpoint3_spa0.y_4 = ((uint64)fpoint3_sp84.y_4) *
                       punk_spe0[r4_i].pobject_0->field_38 / 0x40000;
    fpoint3_spa0.z_8 = ((uint64)fpoint3_sp84.z_8) *
                       punk_spe0[r4_i].pobject_0->field_38 / 0x40000;
    sub_16C74C(fpoint_sp54, fpoint3_spa0, punk_spe0[r4_i].fpoint3_38);
    // 0016B5FC
    punk_spe0[r4_i].field_64 = punk_spe0[r4_i].field_64 + fpoint_sp54.var_0;
    // 0016B610
    sub_16C7DC(fpoint3_sp68, punk_spe0[r4_i].fpoint3_14,
               punk_spe0[r4_i].fpoint3_38);
    sub_16C7DC(fpoint3_sp84, fpoint3_sp68, punk_spe0[r4_i].fpoint3_14);
    // 0016B61A
    fpoint3_spa0.x_0 = ((uint64)fpoint3_sp84.x_0) *
                       punk_spe0[r4_i].pobject_4->field_38 / 0x40000;
    fpoint3_spa0.y_4 = ((uint64)fpoint3_sp84.y_4) *
                       punk_spe0[r4_i].pobject_4->field_38 / 0x40000;
    fpoint3_spa0.z_8 = ((uint64)fpoint3_sp84.z_8) *
                       punk_spe0[r4_i].pobject_4->field_38 / 0x40000;
    sub_16C74C(fpoint_sp54, fpoint3_spa0, punk_spe0[r4_i].fpoint3_38);
    // 0016B64E
    punk_spe0[r4_i].field_64 = punk_spe0[r4_i].field_64 + fpoint_sp54.var_0;
    punk_spe0[r4_i].pobject_0->field_9E = 1;
    punk_spe0[r4_i].pobject_4->field_9E = 1;
    if (punk_spe0[r4_i].pobject_0->field_A0 != -1 &&
        punk_spe0[r4_i].pobject_0->field_A4 == 0) {
      LOGE("CFTTPhysics::Process_branch_44");
      // 0016B674
      sub_16C74C(fpoint_spa0, fpoint3_spc0,
                 punk_spe0[r4_i].pobject_0->fpoint3_1C);
      if (fpoint_spa0.var_0 < 0xFFFFCCCD) {
        LOGE("CFTTPhysics::Process_branch_45");
        SNDGAME_PlaySFX(punk_spe0[r4_i].pobject_0->field_A0);
        punk_spe0[r4_i].pobject_0->field_A4 = 0x3c;
      }
    }
    // loc_16B694
    if (punk_spe0[r4_i].pobject_4->field_A0 != -1 &&
        punk_spe0[r4_i].pobject_4->field_A4 == 0) {
      LOGE("CFTTPhysics::Process_branch_46");
      // 0016B674
      sub_16C74C(fpoint_spa0, fpoint3_spc0,
                 punk_spe0[r4_i].pobject_0->fpoint3_1C);
      if (fpoint_spa0.var_0 < 0xFFFFCCCD) {
        LOGE("CFTTPhysics::Process_branch_47");
        SNDGAME_PlaySFX(punk_spe0[r4_i].pobject_4->field_A0);
        punk_spe0[r4_i].pobject_4->field_A4 = 0x3c;
      }
    }
  }
  // 0016B6D2
  // sp10=spe0+64

  // loc_16BDDC
  for (int i_sp14 = 0; i_sp14 != 3; i_sp14++) {
    // loc_16B6DC
   // LOGE("CFTTPhysics::Process_branch_48");
    for (int i_sp30 = 0; i_sp30 < i_sp1c; i_sp30++) {
      LOGE("CFTTPhysics::Process_branch_49");
      // loc_16B6EC
      // sp50=&punk_spe0[i_sp30].field_64
      // punk_spe0[i_sp30].field_64
      CFTTPObject *r9_pobj = punk_spe0[i_sp30].pobject_0;
      CFTTPObject *r11_pobj = punk_spe0[i_sp30].pobject_4;
      // sp38=r9_pobj.28
      // sp2c=r11_pobj.44
      // sp28=r9_pobj.44
      //&sp4c=punk_spe0[i_sp30].8
      fpoint3<PointType_18> fpoint3_spc0;
      sub_16C7DC(fpoint3_spc0, r9_pobj->fpoint3_28,
                 punk_spe0[i_sp30].fpoint3_8);
      // 0016B71A
      // sp20=r9_pobj.1c.x
      // sp34=r11_pobj.28
      // sp24=r9_pobj.1c.z
      // sp48=&punk_spe0[i_sp30].14
      // sp40=r11
      // r10 r6 r8 =spc0.xyz
      int r0_i1 = r9_pobj->fpoint3_1C.x_0 + fpoint3_spc0.x_0;
      int r0_i2 = r9_pobj->fpoint3_1C.y_4 + fpoint3_spc0.y_4;
      int r0_i3 = r9_pobj->fpoint3_1C.z_8 + fpoint3_spc0.z_8;

      sub_16C7DC(fpoint3_spc0, r11_pobj->fpoint3_28,
                 punk_spe0[i_sp30].fpoint3_14);

      fpoint3_spc0.x_0 = r11_pobj->fpoint3_1C.x_0 - r0_i1 + fpoint3_spc0.x_0;
      fpoint3_spc0.y_4 = r11_pobj->fpoint3_1C.y_4 - r0_i2 + fpoint3_spc0.y_4;
      fpoint3_spc0.z_8 = r11_pobj->fpoint3_1C.z_8 - r0_i3 + fpoint3_spc0.z_8;
      fpoint<PointType_18> fpoint_spa0;
      sub_16C74C(fpoint_spa0, fpoint3_spc0, punk_spe0[i_sp30].fpoint3_20);
      // 0016B780
      int r0_i = ((int64)(-fpoint_spa0.var_0)) * 0x40000 /
                 punk_spe0[i_sp30].field_5c;
      r0_i = r0_i + punk_spe0[i_sp30].field_50 + punk_spe0[i_sp30].field_44;
      if(r0_i<0)
        r0_i=r0_i&(~(-1));
      else
        r0_i=r0_i&(~(0));
      // if (r0_i < 0) {
      //   LOGE("CFTTPhysics::Process_branch_50");
      //   r0_i = 0;
      // }
      int r6_i = punk_spe0[i_sp30].field_44;
      punk_spe0[i_sp30].field_44 = r0_i;
      int r10_i = r0_i - r6_i;
     
      r0_i = ((uint64)r9_pobj->field_34 )* r10_i /0x40000;
      
      r9_pobj->fpoint3_1C.z_8 =
          r9_pobj->fpoint3_1C.z_8 -
          (uint64)punk_spe0[i_sp30].fpoint3_20.z_8 * r0_i / 0x40000;
      r9_pobj->fpoint3_1C.y_4 =
          r9_pobj->fpoint3_1C.y_4 -
          (uint64)punk_spe0[i_sp30].fpoint3_20.y_4 * r0_i / 0x40000;
      r9_pobj->fpoint3_1C.x_0 =
          r9_pobj->fpoint3_1C.x_0 -
          (uint64)punk_spe0[i_sp30].fpoint3_20.x_0 * r0_i / 0x40000;
      // 0016B80A
      int i_sp84;
      sub_16D8B2(&i_sp84, r11_pobj->fpoint3_1C);
      // 0016B816 r11=r11.1c
      int r3_i = (uint64)r10_i * r11_pobj->field_34 * 0x4000;
      r11_pobj->fpoint3_1C.x_0 =
          r11_pobj->fpoint3_1C.x_0 +
          (uint64)r3_i * punk_spe0[i_sp30].fpoint3_20.x_0 / 0x40000;
      r11_pobj->fpoint3_1C.y_4 =
          r11_pobj->fpoint3_1C.y_4 +
          (uint64)r3_i * punk_spe0[i_sp30].fpoint3_20.y_4 / 0x40000;
      r11_pobj->fpoint3_1C.z_8 =
          r11_pobj->fpoint3_1C.z_8 +
          (uint64)r3_i * punk_spe0[i_sp30].fpoint3_20.z_8 / 0x40000;
      int i_sp68;
      sub_16D8B2(&i_sp68, r11_pobj->fpoint3_1C);
      // 0016B86E
      fpoint3<PointType_18> fpoint3_spa0;
      sub_16C7DC(fpoint3_spa0, punk_spe0[i_sp30].fpoint3_8,
                 punk_spe0[i_sp30].fpoint3_20);

      // sp20= r9_pobj->fpoint3_28.y_4
      // sp24= r9_pobj->fpoint3_28.z_8
      long long r3r2_ll = ((int64)r9_pobj->field_38) * 0x4000;  
     
      r9_pobj->fpoint3_28.x_0 =r9_pobj->fpoint3_28.x_0 -((uint64)((fpoint3_spa0.x_0 * r3r2_ll)>>32))* r10_i / 0x40000;
      r9_pobj->fpoint3_28.y_4 =r9_pobj->fpoint3_28.y_4 -((uint64)((fpoint3_spa0.y_4 * r3r2_ll)>>32))* r10_i / 0x40000;
      r9_pobj->fpoint3_28.z_8 =r9_pobj->fpoint3_28.z_8 -((uint64)((fpoint3_spa0.z_8 * r3r2_ll)>>32))* r10_i / 0x40000;
      // 0016B900
      // r7=punk_spe0[i_sp30].fpoint3_20
      sub_16C7DC(fpoint3_spa0, punk_spe0[i_sp30].fpoint3_14,
                 punk_spe0[i_sp30].fpoint3_20);
      long long r1r4_ll = ((uint64)r11_pobj->fpoint3_1C.x_0) * 0x4000;
      r11_pobj->fpoint3_28.x_0 =
          ((r1r4_ll * fpoint3_spa0.x_0) >> 32) * r10_i / 0x40000 +
          r11_pobj->fpoint3_28.x_0;
      r11_pobj->fpoint3_28.y_4 =
          ((r1r4_ll * fpoint3_spa0.y_4) >> 32) * r10_i / 0x40000 +
          r11_pobj->fpoint3_28.y_4;
      r11_pobj->fpoint3_28.z_8 =
          ((r1r4_ll * fpoint3_spa0.z_8) >> 32) * r10_i / 0x40000 +
          r11_pobj->fpoint3_28.z_8;
      sub_16C7DC(fpoint3_spc0, r9_pobj->fpoint3_28,
                 punk_spe0[i_sp30].fpoint3_8);
      // 0016B984
      // sp24 r5 r8=r9.1c.x  y z

      // r6 r4 sp20= spc0 c4spc8
      r0_i1 = r9_pobj->fpoint3_1C.x_0 + fpoint3_spc0.x_0;
      r0_i2 = r9_pobj->fpoint3_1C.y_4 + fpoint3_spc0.y_4;
      r0_i3 = r9_pobj->fpoint3_1C.z_8 + fpoint3_spc0.z_8;

      sub_16C7DC(fpoint3_spc0, r11_pobj->fpoint3_28,
                 punk_spe0[i_sp30].fpoint3_14);
      // r1 r2 r3=r11.1c 20 24
      fpoint3_spc0.x_0 = r11_pobj->fpoint3_1C.x_0 - r0_i1 + fpoint3_spc0.x_0;
      fpoint3_spc0.y_4 = r11_pobj->fpoint3_1C.y_4 - r0_i1 + fpoint3_spc0.y_4;
      fpoint3_spc0.z_8 = r11_pobj->fpoint3_1C.z_8 - r0_i1 + fpoint3_spc0.z_8;
      // sp24=punk_spe0[i_sp30].fpoint3_2C
      sub_16C74C(fpoint_spa0, fpoint3_spc0, punk_spe0[i_sp30].fpoint3_2C);
      // 0016B9D4
      //  sp2c=r11_pobj.44
      // sp28=r9_pobj.44
      int i_sp2c =( ((uint64)r11_pobj->field_44) * r9_pobj->field_44 * 0x4000)>>32;
      // int i_sp28=punk_spe0[i_sp30].fpoint3_2C.y_4;
      r10_i = (uint64)i_sp2c * punk_spe0[i_sp30].field_44 / 0x40000;
    
      r0_i = ((int64)(-fpoint_spa0.var_0)) / punk_spe0[i_sp30].field_60;
      r0_i += punk_spe0[i_sp30].field_48;
      if (r10_i <= r0_i) r10_i = r0_i;
      int r2_i = ((uint64)(-punk_spe0[i_sp30].field_44)) * i_sp2c / 0x40000;
      if (r0_i < r2_i) r10_i = r2_i;
      r0_i = r10_i - punk_spe0[i_sp30].field_48;
      punk_spe0[i_sp30].field_48 = r10_i;
      r6_i = (uint64)r9_pobj->field_34 * r0_i * 0x4000;
  

      int r5_i = ((uint64)r6_i) * punk_spe0[i_sp30].fpoint3_2C.x_0 / 0x40000;
      r9_pobj->fpoint3_1C.x_0 = r9_pobj->fpoint3_1C.x_0 - r5_i;
      r5_i = ((uint64)r6_i) * punk_spe0[i_sp30].fpoint3_2C.y_4 / 0x40000;
      r9_pobj->fpoint3_1C.y_4 = r9_pobj->fpoint3_1C.y_4 - r5_i;
      r5_i = ((uint64)r6_i) * punk_spe0[i_sp30].fpoint3_2C.z_8 / 0x40000;
      r9_pobj->fpoint3_1C.z_8 = r9_pobj->fpoint3_1C.z_8 - r5_i;
      // 0016BA94
      r0_i1 = ((uint64)r0_i) * 0x4000 * r11_pobj->field_34 >> 32;
      r11_pobj->fpoint3_1C.z_8 +=
          ((uint64)r0_i1) * punk_spe0[i_sp30].fpoint3_2C.z_8 / 0x40000;
      r11_pobj->fpoint3_1C.x_0 +=
          ((uint64)r0_i1) * punk_spe0[i_sp30].fpoint3_2C.x_0 / 0x40000;
      r11_pobj->fpoint3_1C.y_4 +=
          ((uint64)r0_i1) * punk_spe0[i_sp30].fpoint3_2C.y_4 / 0x40000;
      sub_16C7DC(fpoint3_spa0, punk_spe0[i_sp30].fpoint3_8,
                 punk_spe0[i_sp30].fpoint3_2C);
      // 0016BB0A
      // sp28=r8 0016BAB4
      r0_i1 = ((uint64)r0_i) * 0x4000 * r9_pobj->field_38;
      r9_pobj->fpoint3_28.x_0 -=
          ((uint64)r0_i1) * fpoint3_spa0.x_0 / 0x40000;
      r9_pobj->fpoint3_28.y_4 -=
          ((uint64)r0_i1) * fpoint3_spa0.y_4 / 0x40000;
      r9_pobj->fpoint3_28.z_8 -=
          ((uint64)r0_i1) * fpoint3_spa0.z_8 / 0x40000;
      sub_16C7DC(fpoint3_spa0, punk_spe0[i_sp30].fpoint3_14,
                 punk_spe0[i_sp30].fpoint3_2C);
      // 0016BB64
      r0_i1 = ((uint64)r0_i) * 0x4000 * r11_pobj->field_34;
      r11_pobj->fpoint3_28.x_0 +=
          ((uint64)r0_i1) * fpoint3_spa0.x_0 / 0x40000;
      r11_pobj->fpoint3_28.y_4 +=
          ((uint64)r0_i1) * fpoint3_spa0.y_4 / 0x40000;
      r11_pobj->fpoint3_28.z_8 +=
          ((uint64)r0_i1) * fpoint3_spa0.z_8 / 0x40000;
      sub_16C7DC(fpoint3_spc0, r9_pobj->fpoint3_28,
                 punk_spe0[i_sp30].fpoint3_8);
      // 0016BBBA
      // sp28 r5 sp38=r9.1c.c y z
      // r6 r4 sp24 =spc0.x y z
      r0_i1 = r9_pobj->fpoint3_1C.x_0 + fpoint3_spc0.x_0;
      r0_i2 = r9_pobj->fpoint3_1C.y_4 + fpoint3_spc0.y_4;
      r0_i3 = r9_pobj->fpoint3_1C.z_8 + fpoint3_spc0.z_8;

      sub_16C7DC(fpoint3_spc0, r11_pobj->fpoint3_28,
                 punk_spe0[i_sp30].fpoint3_14);

      fpoint3_spc0.x_0 = r11_pobj->fpoint3_1C.x_0 - r0_i1 + fpoint3_spc0.x_0;
      fpoint3_spc0.y_4 = r11_pobj->fpoint3_1C.y_4 - r0_i1 + fpoint3_spc0.y_4;
      fpoint3_spc0.z_8 = r11_pobj->fpoint3_1C.z_8 - r0_i1 + fpoint3_spc0.z_8;
      sub_16C74C(fpoint_spa0, fpoint3_spc0, punk_spe0[i_sp30].fpoint3_38);
      // 0016BC0E
      // sp38=punk_spe0[i_sp30].40
      int r4_i = ((uint64)i_sp2c) * punk_spe0[i_sp30].field_44 / 0x40000;
      r0_i = (int64)(-fpoint_spa0.var_0) * 0x40000 /
                 punk_spe0[i_sp30].field_64 +
             punk_spe0[i_sp30].field_4c;
      r2_i = ((uint64)i_sp2c) * (-punk_spe0[i_sp30].field_44) / 0x40000;
      if (r0_i <= r4_i) r4_i = r0_i;
      if (r0_i < r2_i) r4_i = r2_i;
      int r1_i = punk_spe0[i_sp30].field_4c;
      punk_spe0[i_sp30].field_4c = r4_i;
      r0_i = r4_i - r1_i;
      r5_i = ((uint64)r4_i) * r0_i * 0x4000 >> 32;
      r9_pobj->fpoint3_1C.x_0 =
          r9_pobj->fpoint3_1C.x_0 -
          ((uint64)r5_i) * punk_spe0[i_sp30].fpoint3_38.x_0 / 0x40000;
      r9_pobj->fpoint3_1C.y_4 =
          r9_pobj->fpoint3_1C.y_4 -
          ((uint64)r5_i) * punk_spe0[i_sp30].fpoint3_38.y_4 / 0x40000;
      r9_pobj->fpoint3_1C.z_8 =
          r9_pobj->fpoint3_1C.z_8 -
          ((uint64)r5_i) * punk_spe0[i_sp30].fpoint3_38.z_8 / 0x40000;
      // 0016BCBE
      long long r8r4_ll = ((long long)r0_i) * 0x4000;
      r0_i = r8r4_ll * r11_pobj->field_34 >> 32;
      r11_pobj->fpoint3_1C.z_8 =
          ((uint64)r0_i) * punk_spe0[i_sp30].fpoint3_38.z_8 / 0x40000 +
          r11_pobj->fpoint3_1C.z_8;
      r11_pobj->fpoint3_1C.y_4 =
          ((uint64)r0_i) * punk_spe0[i_sp30].fpoint3_38.y_4 / 0x40000 +
          r11_pobj->fpoint3_1C.y_4;
      r11_pobj->fpoint3_1C.x_0 =
          ((uint64)r0_i) * punk_spe0[i_sp30].fpoint3_38.x_0 / 0x40000 +
          r11_pobj->fpoint3_1C.x_0;
      sub_16C7DC(fpoint3_spa0, punk_spe0[i_sp30].fpoint3_8,
                 punk_spe0[i_sp30].fpoint3_38);
      // 0016BD2E
      r0_i = r8r4_ll * r9_pobj->field_38;
      r9_pobj->fpoint3_28.z_8 -= ((uint64)r0_i) * fpoint3_spa0.z_8 / 0x40000;
      r9_pobj->fpoint3_28.y_4 -= ((uint64)r0_i) * fpoint3_spa0.y_4 / 0x40000;
      r9_pobj->fpoint3_28.x_0 -= ((uint64)r0_i) * fpoint3_spa0.x_0 / 0x40000;
      sub_16C7DC(fpoint3_spa0, punk_spe0[i_sp30].fpoint3_14,
                 punk_spe0[i_sp30].fpoint3_38);
      // 0016BD84
      r0_i = r8r4_ll * r11_pobj->field_34;
      r11_pobj->fpoint3_28.x_0 +=
          ((uint64)r0_i) * fpoint3_spa0.x_0 / 0x40000;
      r11_pobj->fpoint3_28.y_4 +=
          ((uint64)r0_i) * fpoint3_spa0.y_4 / 0x40000;
      r11_pobj->fpoint3_28.z_8 +=
          ((uint64)r0_i) * fpoint3_spa0.z_8 / 0x40000;
    }
  }

  // loc_16BE30
  for (int r1_i = 0; r1_i < object_counts_4; r1_i++) {
    //LOGE("CFTTPhysics::Process_branch_51");
    ppobject_0[r1_i]->fpoint3_0 = ppobject_0[r1_i]->fpoint3_48;
    ppobject_0[r1_i]->fpointQ_C = ppobject_0[r1_i]->fpointQQ_54.fpointQ_24;
    ppobject_0[r1_i]->field_A4 = ppobject_0[r1_i]->field_A4 - 1;
    if (ppobject_0[r1_i]->field_A4 <= -1) {
      //LOGE("CFTTPhysics::Process_branch_52");
      ppobject_0[r1_i]->field_A4 = 0;
    }
  }
  // 0016BE36
  if (i_sp1c > 0) {
    LOGE("CFTTPhysics::Process_branch_53");
    return 1;
  }
  //LOGE("CFTTPhysics::Process_branch_54");
  return 0;
}  //-------------------------------------------------------------------------------------------------