// File: /workspace/github_c_makefile_star2_O2/nkanaev[P]tipsy/src/tipsy.c
// Function: draw
void draw(Tigr *scr, Obj *obj, State state, list *sfaces) {
  for (int i = 0; i < obj->f->len; i++) {
    Surface *sf = (Surface*)list_get(sfaces, i);
    Face f = *(Face*)list_get(obj->f, sf->idx);
    sf->v1 = perspective(VREF(list_get(obj->v, f.v1-1)), state.x, state.y, state.z);
    sf->v2 = perspective(VREF(list_get(obj->v, f.v2-1)), state.x, state.y, state.z);
    sf->v3 = perspective(VREF(list_get(obj->v, f.v3-1)), state.x, state.y, state.z);
    sf->nrm = vec_nrm(vec_cross(vec_sub(sf->v2, sf->v1), vec_sub(sf->v3, sf->v1)));
    sf->v1 = project(sf->v1, state.jitter);
    sf->v2 = project(sf->v2, state.jitter);
    sf->v3 = project(sf->v3, state.jitter);
  }

  if (!state.use_zbuffer) list_sort(sfaces, surface_cmp);

  for (int i = 0; i < sfaces->len; i++) {
    Surface *sf = (Surface*)list_get(sfaces, i);
    if (state.draw_wireframe) {
      draw_wireframe(scr, *sf, tigrRGB(0xFF, 0xFF, 0xFF));
    } else {
      Vec forward = {0, 0, -1};
      float inv = state.inv_bculling ? -1 : 1;
      if (vec_dot(sf->nrm, forward) * inv > 0) draw_surface(scr, obj, *sf, state);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rdx, %rbx
movq %rsi, %rbp
movq %rdi, 0xe8(%rsp)
leaq 0x1d0(%rsp), %rax
movsd 0x18(%rax), %xmm0
movaps %xmm0, 0xd0(%rsp)
movss 0x20(%rax), %xmm0
movss %xmm0, 0xb4(%rsp)
movsd 0x24(%rax), %xmm0
movaps %xmm0, 0x100(%rsp)
movss 0x2c(%rax), %xmm0
movss %xmm0, 0xb0(%rsp)
movsd 0x30(%rax), %xmm0
movaps %xmm0, 0xf0(%rsp)
movss 0x38(%rax), %xmm0
movss %xmm0, 0xac(%rsp)
xorl %r15d, %r15d
movl 0x10(%rax), %eax
movl %eax, 0xc8(%rsp)
movq %rsi, 0xc0(%rsp)
movq 0x18(%rbp), %rax
cmpl 0x8(%rax), %r15d
jge 0x94d1
movq (%rbx), %r12
movslq 0x10(%rbx), %rcx
movslq %r15d, %r13
imulq %rcx, %r13
movslq 0x54(%r12,%r13), %rcx
movq (%rax), %rdx
movslq 0x10(%rax), %rax
imulq %rcx, %rax
movslq (%rdx,%rax), %rcx
movslq 0x4(%rdx,%rax), %rbp
movslq 0x8(%rdx,%rax), %r14
movq 0xc0(%rsp), %rax
movq (%rax), %rax
decq %rcx
movq (%rax), %rdx
movslq 0x10(%rax), %rax
imulq %rcx, %rax
movsd (%rdx,%rax), %xmm0
movss 0x8(%rdx,%rax), %xmm1
movaps 0xd0(%rsp), %xmm2
movss 0xb4(%rsp), %xmm3
movaps 0x100(%rsp), %xmm4
movss 0xb0(%rsp), %xmm5
movaps 0xf0(%rsp), %xmm6
movss 0xac(%rsp), %xmm7
callq 0x7d08
movaps %xmm0, 0x110(%rsp)
movss %xmm1, 0xb8(%rsp)
movlps %xmm0, (%r12,%r13)
movss %xmm1, 0x8(%r12,%r13)
movq 0xc0(%rsp), %rax
movq (%rax), %rax
decq %rbp
movq (%rax), %rcx
movslq 0x10(%rax), %rax
imulq %rbp, %rax
movq 0xc0(%rsp), %rbp
movsd (%rcx,%rax), %xmm0
movss 0x8(%rcx,%rax), %xmm1
movaps 0xd0(%rsp), %xmm2
movss 0xb4(%rsp), %xmm3
movaps 0x100(%rsp), %xmm4
movss 0xb0(%rsp), %xmm5
movaps 0xf0(%rsp), %xmm6
movss 0xac(%rsp), %xmm7
callq 0x7d08
movaps %xmm0, 0x120(%rsp)
movss %xmm1, 0xbc(%rsp)
movlps %xmm0, 0xc(%r12,%r13)
movss %xmm1, 0x14(%r12,%r13)
movq (%rbp), %rax
decq %r14
movq (%rax), %rcx
movslq 0x10(%rax), %rax
imulq %r14, %rax
movsd (%rcx,%rax), %xmm0
movss 0x8(%rcx,%rax), %xmm1
movaps 0xd0(%rsp), %xmm2
movss 0xb4(%rsp), %xmm3
movaps 0x100(%rsp), %xmm4
movss 0xb0(%rsp), %xmm5
movaps 0xf0(%rsp), %xmm6
movss 0xac(%rsp), %xmm7
callq 0x7d08
movaps %xmm0, %xmm2
movaps %xmm0, 0x130(%rsp)
movaps %xmm1, %xmm5
movss %xmm1, 0xcc(%rsp)
movaps 0x120(%rsp), %xmm0
movaps 0x110(%rsp), %xmm3
subps %xmm3, %xmm0
movss 0xbc(%rsp), %xmm1
movss 0xb8(%rsp), %xmm4
subss %xmm4, %xmm1
subps %xmm3, %xmm2
subss %xmm4, %xmm5
movaps %xmm5, %xmm3
callq 0x7cc4
callq 0x7c88
movlps %xmm0, 0x48(%r12,%r13)
movss %xmm1, 0x50(%r12,%r13)
movaps 0x110(%rsp), %xmm0
movss 0xb8(%rsp), %xmm1
movl 0xc8(%rsp), %r14d
movl %r14d, %edi
callq 0x7d66
movlps %xmm0, (%r12,%r13)
movss %xmm1, 0x8(%r12,%r13)
movaps 0x120(%rsp), %xmm0
movss 0xbc(%rsp), %xmm1
movl %r14d, %edi
callq 0x7d66
movlps %xmm0, 0xc(%r12,%r13)
movss %xmm1, 0x14(%r12,%r13)
movaps 0x130(%rsp), %xmm0
movss 0xcc(%rsp), %xmm1
movl %r14d, %edi
callq 0x7d66
movlps %xmm0, 0x18(%r12,%r13)
movss %xmm1, 0x20(%r12,%r13)
incl %r15d
jmp 0x9265
leaq 0x1d0(%rsp), %r14
cmpl $0x0, 0x4(%r14)
jne 0x94ef
leaq -0xc18(%rip), %rsi      # 0x88cf
movq %rbx, %rdi
callq 0x7bf4
xorl %r15d, %r15d
cmpl 0xc(%r14), %r15d
movl $0x0, %eax
sbbl %eax, %eax
orl $0x1, %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, 0xd0(%rsp)
movl (%r14), %r13d
pushq $0x16
popq %r14
leaq 0x140(%rsp), %rbp
pushq $0xb
popq %r12
cmpl 0x8(%rbx), %r15d
jge 0x95d5
movslq 0x10(%rbx), %rax
movslq %r15d, %rsi
imulq %rax, %rsi
addq (%rbx), %rsi
testl %r13d, %r13d
je 0x9563
movq %r14, %rcx
movq %rbp, %rdi
rep  movsl (%rsi), %es:(%rdi)
movq %r12, %rcx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0xe8(%rsp), %rdi
pushq $-0x1
popq %rsi
callq 0x89cf
jmp 0x95cd
movsd 0x48(%rsi), %xmm0
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
xorps %xmm2, %xmm2
mulss %xmm2, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
subss 0x50(%rsi), %xmm0
mulss 0xd0(%rsp), %xmm0
ucomiss %xmm2, %xmm0
jbe 0x95cd
movq %r14, %rcx
movq %rbp, %rdi
rep  movsl (%rsi), %es:(%rdi)
movq %r12, %rcx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x58(%rsp), %rdi
pushq $0x9
popq %rcx
leaq 0x1d0(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0xe8(%rsp), %rdi
movq 0xc0(%rsp), %rsi
callq 0x8a58
incl %r15d
jmp 0x9520
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq