// File: /workspace/github_c_makefile_star2_O2/nkanaev[P]tipsy/src/tipsy.c
// Function: obj_normalize
void obj_normalize(Obj *obj) {
  Vec min = {FLT_MAX, FLT_MAX, FLT_MAX}, max = {FLT_MIN, FLT_MIN, FLT_MIN};
  for (int i = 0; i < obj->v->len; i++) {
    Vec v = VREF(list_get(obj->v, i));
    min.x = fminf(min.x, v.x); max.x = fmaxf(max.x, v.x);
    min.y = fminf(min.y, v.y); max.y = fmaxf(max.y, v.y);
    min.z = fminf(min.z, v.z); max.z = fmaxf(max.z, v.z);
  }

  Vec size = vec_sub(max, min);
  float W = fmaxf(fmaxf(size.x, size.y), size.z);

  for (int i = 0; i < obj->v->len; i++) {
    Vec *v = (Vec*)list_get(obj->v, i);
    v->x = ((v->x - min.x) / W*2 - size.x/W);
    v->y = -((v->y - min.y) / W*2 - size.y/W);
    v->z = -((v->z - min.z) / W*2 - size.z/W);
  }

  for (int i = 0; i < obj->vn->len; i++) {
    Vec *vn = (Vec*)list_get(obj->vn, i);
    Vec nrm = vec_nrm(*vn);
    vn->x = nrm.x;
    vn->y = -nrm.y;
    vn->z = -nrm.z;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rdi, %rbx
movq (%rdi), %r14
movl 0x8(%r14), %ebp
xorl %r15d, %r15d
testl %ebp, %ebp
cmovlel %r15d, %ebp
movss 0x36b0(%rip), %xmm0     # 0xbd28
movaps %xmm0, 0x10(%rsp)
movaps 0x36fc(%rip), %xmm5     # 0xbd80
movss 0x36a0(%rip), %xmm4     # 0xbd2c
movaps 0x36fd(%rip), %xmm7     # 0xbd90
cmpl %r15d, %ebp
je 0x872d
movq (%r14), %rax
movslq 0x10(%r14), %rcx
movslq %r15d, %rdx
imulq %rcx, %rdx
movss 0x8(%rax,%rdx), %xmm1
movss %xmm1, 0xc(%rsp)
movsd (%rax,%rdx), %xmm0
movaps %xmm7, %xmm6
cmpunordps %xmm7, %xmm6
movaps %xmm0, %xmm2
andps %xmm6, %xmm2
movaps %xmm0, %xmm3
maxps %xmm7, %xmm3
andnps %xmm3, %xmm6
orps %xmm2, %xmm6
movaps %xmm6, 0x40(%rsp)
movaps %xmm5, %xmm3
cmpunordps %xmm5, %xmm3
movaps %xmm0, %xmm2
andps %xmm3, %xmm2
minps %xmm5, %xmm0
andnps %xmm0, %xmm3
orps %xmm2, %xmm3
movaps %xmm3, 0x30(%rsp)
movaps 0x10(%rsp), %xmm0
movaps %xmm4, 0x20(%rsp)
callq 0x3290
movaps %xmm0, 0x10(%rsp)
movaps 0x20(%rsp), %xmm0
movss 0xc(%rsp), %xmm1
callq 0x33f0
movaps %xmm0, %xmm4
incl %r15d
movaps 0x40(%rsp), %xmm7
movaps 0x30(%rsp), %xmm5
jmp 0x8693
movaps %xmm7, %xmm0
subss %xmm5, %xmm0
movaps %xmm0, %xmm1
xorps 0x3662(%rip), %xmm1     # 0xbda0
movaps %xmm1, 0x30(%rsp)
shufps $0xd4, %xmm7, %xmm4     # xmm4 = xmm4[0,1],xmm7[1,3]
shufps $0x52, %xmm7, %xmm4     # xmm4 = xmm4[2,0],xmm7[1,1]
movaps 0x10(%rsp), %xmm1
shufps $0xd4, %xmm5, %xmm1     # xmm1 = xmm1[0,1],xmm5[1,3]
shufps $0x52, %xmm5, %xmm1     # xmm1 = xmm1[2,0],xmm5[1,1]
movaps %xmm1, 0x10(%rsp)
subps %xmm1, %xmm4
movaps %xmm4, 0x20(%rsp)
movaps %xmm4, %xmm1
movaps %xmm5, 0x40(%rsp)
callq 0x33f0
movaps 0x20(%rsp), %xmm1
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
callq 0x33f0
movaps 0x30(%rsp), %xmm6
movaps 0x40(%rsp), %xmm5
movaps 0x20(%rsp), %xmm4
movaps 0x10(%rsp), %xmm3
divss %xmm0, %xmm6
xorps 0x3601(%rip), %xmm4     # 0xbda0
movaps %xmm0, %xmm1
shufps $0x0, %xmm0, %xmm1      # xmm1 = xmm1[0,0],xmm0[0,0]
divps %xmm1, %xmm4
xorl %eax, %eax
cmpl %eax, %ebp
je 0x87f9
movq (%r14), %rcx
movslq 0x10(%r14), %rdx
movslq %eax, %rsi
imulq %rdx, %rsi
movss (%rcx,%rsi), %xmm2
subss %xmm5, %xmm2
divss %xmm0, %xmm2
addss %xmm2, %xmm2
addss %xmm6, %xmm2
movss %xmm2, (%rcx,%rsi)
movsd 0x4(%rcx,%rsi), %xmm2
subps %xmm3, %xmm2
divps %xmm1, %xmm2
addps %xmm2, %xmm2
addps %xmm4, %xmm2
xorps 0x35b0(%rip), %xmm2     # 0xbda0
movlps %xmm2, 0x4(%rcx,%rsi)
incl %eax
jmp 0x87ab
movq 0x8(%rbx), %rbx
movl 0x8(%rbx), %ebp
xorl %r14d, %r14d
testl %ebp, %ebp
cmovlel %r14d, %ebp
cmpl %r14d, %ebp
je 0x8858
movq (%rbx), %r15
movslq 0x10(%rbx), %rax
movslq %r14d, %r12
imulq %rax, %r12
movsd (%r15,%r12), %xmm0
movss 0x8(%r15,%r12), %xmm1
callq 0x7c88
movss %xmm0, (%r15,%r12)
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movaps 0x3561(%rip), %xmm2     # 0xbda0
xorps %xmm2, %xmm0
movss %xmm0, 0x4(%r15,%r12)
xorps %xmm2, %xmm1
movss %xmm1, 0x8(%r15,%r12)
incl %r14d
jmp 0x8809
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq