// File: /workspace/github_c_makefile_star2_O1/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 $0x1b8, %rsp            # imm = 0x1B8
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq 0x18(%rsi), %rax
cmpl $0x0, 0x8(%rax)
jle 0xa4ba
leaq 0x1f0(%rsp), %rcx
movsd 0x18(%rcx), %xmm0
movss 0x20(%rcx), %xmm1
movss %xmm1, 0xac(%rsp)
movsd 0x24(%rcx), %xmm1
movss 0x2c(%rcx), %xmm2
movss %xmm2, 0xa8(%rsp)
movsd 0x30(%rcx), %xmm2
movss 0x38(%rcx), %xmm3
movss %xmm3, 0xec(%rsp)
movaps %xmm0, 0x100(%rsp)
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movaps %xmm0, 0x150(%rsp)
movaps %xmm1, 0x130(%rsp)
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
movaps %xmm1, 0x140(%rsp)
movaps %xmm2, 0x120(%rsp)
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movaps %xmm2, 0x110(%rsp)
movl 0x10(%rcx), %ebp
xorl %r13d, %r13d
cmpl %r13d, 0x8(%rbx)
jle 0x9f1c
movslq 0x10(%rbx), %rcx
movslq %r13d, %r12
imulq %rcx, %r12
addq (%rbx), %r12
jmp 0x9f1f
xorl %r12d, %r12d
movslq 0x54(%r12), %rcx
movq (%rax), %rdx
movslq 0x10(%rax), %rax
imulq %rcx, %rax
movslq (%rdx,%rax), %rsi
movslq 0x4(%rdx,%rax), %rcx
movslq 0x8(%rdx,%rax), %rax
movq (%r14), %rdx
decq %rsi
movq (%rdx), %rdi
movslq 0x10(%rdx), %rdx
imulq %rsi, %rdx
movsd (%rdi,%rdx), %xmm3
movss 0x8(%rdi,%rdx), %xmm11
movaps %xmm3, %xmm4
shufps $0x55, %xmm3, %xmm4     # xmm4 = xmm4[1,1],xmm3[1,1]
movaps %xmm4, %xmm1
movaps 0x150(%rsp), %xmm14
mulss %xmm14, %xmm1
movaps %xmm3, %xmm2
movaps 0x100(%rsp), %xmm0
mulss %xmm0, %xmm2
movaps %xmm0, %xmm7
addss %xmm1, %xmm2
movaps %xmm11, %xmm1
movss 0xac(%rsp), %xmm0
mulss %xmm0, %xmm1
movaps %xmm0, %xmm8
addss %xmm2, %xmm1
movaps %xmm4, %xmm2
movaps 0x140(%rsp), %xmm13
mulss %xmm13, %xmm2
movaps %xmm3, %xmm5
movaps 0x130(%rsp), %xmm10
mulss %xmm10, %xmm5
addss %xmm2, %xmm5
movaps %xmm11, %xmm2
movss 0xa8(%rsp), %xmm12
mulss %xmm12, %xmm2
addss %xmm5, %xmm2
movaps %xmm1, %xmm5
unpcklps %xmm2, %xmm5            # xmm5 = xmm5[0],xmm2[0],xmm5[1],xmm2[1]
movaps 0x110(%rsp), %xmm9
mulss %xmm9, %xmm4
mulss 0x120(%rsp), %xmm3
addss %xmm4, %xmm3
movss 0xec(%rsp), %xmm15
mulss %xmm15, %xmm11
addss %xmm3, %xmm11
movlps %xmm5, (%r12)
movss %xmm11, 0x8(%r12)
movq (%r14), %rdx
decq %rcx
movq (%rdx), %rsi
movslq 0x10(%rdx), %rdx
imulq %rcx, %rdx
movsd (%rsi,%rdx), %xmm5
movss 0x8(%rsi,%rdx), %xmm0
movaps %xmm5, %xmm6
shufps $0x55, %xmm5, %xmm6     # xmm6 = xmm6[1,1],xmm5[1,1]
movaps %xmm14, %xmm3
mulss %xmm6, %xmm3
movaps %xmm5, %xmm4
mulss %xmm7, %xmm4
addss %xmm3, %xmm4
movaps %xmm0, %xmm3
mulss %xmm8, %xmm3
addss %xmm4, %xmm3
movaps %xmm13, %xmm4
mulss %xmm6, %xmm4
movaps %xmm5, %xmm7
mulss %xmm10, %xmm7
addss %xmm4, %xmm7
movaps %xmm0, %xmm4
mulss %xmm12, %xmm4
addss %xmm7, %xmm4
movaps %xmm3, %xmm7
unpcklps %xmm4, %xmm7            # xmm7 = xmm7[0],xmm4[0],xmm7[1],xmm4[1]
mulss %xmm9, %xmm6
movaps 0x120(%rsp), %xmm12
mulss %xmm12, %xmm5
addss %xmm6, %xmm5
mulss %xmm15, %xmm0
addss %xmm5, %xmm0
movlps %xmm7, 0xc(%r12)
movss %xmm0, 0x14(%r12)
movq (%r14), %rcx
decq %rax
movq (%rcx), %rdx
movslq 0x10(%rcx), %rcx
imulq %rax, %rcx
movsd (%rdx,%rcx), %xmm7
movss 0x8(%rdx,%rcx), %xmm5
movaps %xmm7, %xmm8
shufps $0x55, %xmm7, %xmm8     # xmm8 = xmm8[1,1],xmm7[1,1]
mulss %xmm8, %xmm14
movaps %xmm7, %xmm9
mulss 0x100(%rsp), %xmm9
addss %xmm14, %xmm9
movaps %xmm5, %xmm6
mulss 0xac(%rsp), %xmm6
addss %xmm9, %xmm6
mulss %xmm8, %xmm13
movaps %xmm7, %xmm10
mulss 0x130(%rsp), %xmm10
addss %xmm13, %xmm10
movaps %xmm5, %xmm9
mulss 0xa8(%rsp), %xmm9
addss %xmm10, %xmm9
mulss 0x110(%rsp), %xmm8
mulss %xmm12, %xmm7
addss %xmm8, %xmm7
mulss %xmm15, %xmm5
addss %xmm7, %xmm5
movaps %xmm6, %xmm7
unpcklps %xmm9, %xmm7            # xmm7 = xmm7[0],xmm9[0],xmm7[1],xmm9[1]
movlps %xmm7, 0x18(%r12)
subss %xmm1, %xmm3
subss %xmm1, %xmm6
subss %xmm2, %xmm4
subss %xmm2, %xmm9
movss %xmm5, 0x20(%r12)
subss %xmm11, %xmm0
subss %xmm11, %xmm5
movaps %xmm0, %xmm1
mulss %xmm9, %xmm1
mulss %xmm6, %xmm0
mulss %xmm4, %xmm6
mulss %xmm5, %xmm4
subss %xmm1, %xmm4
mulss %xmm3, %xmm5
subss %xmm5, %xmm0
mulss %xmm3, %xmm9
movaps %xmm0, %xmm2
subss %xmm6, %xmm9
mulss %xmm0, %xmm0
movaps %xmm4, %xmm1
mulss %xmm4, %xmm1
addss %xmm0, %xmm1
movaps %xmm9, %xmm0
mulss %xmm9, %xmm0
addss %xmm1, %xmm0
ucomiss 0x2b9f(%rip), %xmm0     # 0xcd68
jb 0xa1d1
sqrtss %xmm0, %xmm0
jmp 0xa208
movaps %xmm2, 0xd0(%rsp)
movaps %xmm9, 0xc0(%rsp)
movaps %xmm4, 0xb0(%rsp)
callq 0x3730
movaps 0xb0(%rsp), %xmm4
movaps 0xc0(%rsp), %xmm9
movaps 0xd0(%rsp), %xmm2
movss 0xdf4(%rip), %xmm1      # 0xb004
divss %xmm0, %xmm1
mulss %xmm1, %xmm4
mulss %xmm1, %xmm2
unpcklps %xmm2, %xmm4            # xmm4 = xmm4[0],xmm2[0],xmm4[1],xmm2[1]
mulss %xmm9, %xmm1
movlps %xmm4, 0x48(%r12)
movss %xmm1, 0x50(%r12)
movsd (%r12), %xmm4
movss 0x8(%r12), %xmm2
movaps %xmm4, %xmm3
movss 0x2af7(%rip), %xmm0     # 0xcd40
mulss %xmm0, %xmm3
movaps %xmm2, %xmm1
addss 0x2aec(%rip), %xmm1     # 0xcd44
divss %xmm1, %xmm3
shufps $0x55, %xmm4, %xmm4     # xmm4 = xmm4[1,1,1,1]
mulss %xmm0, %xmm4
divss %xmm1, %xmm4
movss 0x2ad8(%rip), %xmm0     # 0xcd48
mulss %xmm0, %xmm3
addss 0x2ad0(%rip), %xmm3     # 0xcd4c
mulss %xmm0, %xmm4
addss 0x2ac8(%rip), %xmm4     # 0xcd50
testl %ebp, %ebp
je 0xa2e2
movaps %xmm3, %xmm0
movss %xmm2, 0xd0(%rsp)
movss %xmm1, 0xc0(%rsp)
movaps %xmm4, 0xb0(%rsp)
callq 0x3120
movaps %xmm0, 0xf0(%rsp)
movaps 0xb0(%rsp), %xmm0
callq 0x3120
movss 0xc0(%rsp), %xmm1
movaps 0xf0(%rsp), %xmm3
movss 0xd0(%rsp), %xmm2
unpcklps %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1]
jmp 0xa2e5
unpcklps %xmm4, %xmm3            # xmm3 = xmm3[0],xmm4[0],xmm3[1],xmm4[1]
movss 0x2a53(%rip), %xmm0     # 0xcd40
mulss %xmm0, %xmm2
divss %xmm1, %xmm2
movss 0x2a47(%rip), %xmm1     # 0xcd44
addss %xmm1, %xmm2
movlps %xmm3, (%r12)
movss %xmm2, 0x8(%r12)
movsd 0xc(%r12), %xmm5
movss 0x14(%r12), %xmm2
movaps %xmm5, %xmm3
mulss %xmm0, %xmm3
movaps %xmm2, %xmm4
addss %xmm1, %xmm4
divss %xmm4, %xmm3
shufps $0x55, %xmm5, %xmm5     # xmm5 = xmm5[1,1,1,1]
mulss %xmm0, %xmm5
divss %xmm4, %xmm5
movss 0x2a07(%rip), %xmm0     # 0xcd48
mulss %xmm0, %xmm3
addss 0x29ff(%rip), %xmm3     # 0xcd4c
mulss %xmm0, %xmm5
addss 0x29f7(%rip), %xmm5     # 0xcd50
testl %ebp, %ebp
je 0xa3b3
movaps %xmm3, %xmm0
movss %xmm2, 0xd0(%rsp)
movss %xmm4, 0xc0(%rsp)
movaps %xmm5, 0xb0(%rsp)
callq 0x3120
movaps %xmm0, 0xf0(%rsp)
movaps 0xb0(%rsp), %xmm0
callq 0x3120
movss 0xc0(%rsp), %xmm4
movaps 0xf0(%rsp), %xmm3
movss 0xd0(%rsp), %xmm2
unpcklps %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1]
jmp 0xa3b6
unpcklps %xmm5, %xmm3            # xmm3 = xmm3[0],xmm5[0],xmm3[1],xmm5[1]
movss 0x2982(%rip), %xmm0     # 0xcd40
mulss %xmm0, %xmm2
divss %xmm4, %xmm2
movss 0x2976(%rip), %xmm1     # 0xcd44
addss %xmm1, %xmm2
movlps %xmm3, 0xc(%r12)
movss %xmm2, 0x14(%r12)
movsd 0x18(%r12), %xmm5
movss 0x20(%r12), %xmm2
movaps %xmm5, %xmm3
mulss %xmm0, %xmm3
movaps %xmm2, %xmm4
addss %xmm1, %xmm4
divss %xmm4, %xmm3
shufps $0x55, %xmm5, %xmm5     # xmm5 = xmm5[1,1,1,1]
mulss %xmm0, %xmm5
divss %xmm4, %xmm5
movss 0x2935(%rip), %xmm0     # 0xcd48
mulss %xmm0, %xmm3
addss 0x292d(%rip), %xmm3     # 0xcd4c
mulss %xmm0, %xmm5
addss 0x2925(%rip), %xmm5     # 0xcd50
testl %ebp, %ebp
je 0xa485
movaps %xmm3, %xmm0
movss %xmm2, 0xd0(%rsp)
movss %xmm4, 0xc0(%rsp)
movaps %xmm5, 0xb0(%rsp)
callq 0x3120
movaps %xmm0, 0xf0(%rsp)
movaps 0xb0(%rsp), %xmm0
callq 0x3120
movss 0xc0(%rsp), %xmm4
movaps 0xf0(%rsp), %xmm3
movss 0xd0(%rsp), %xmm2
unpcklps %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1]
jmp 0xa488
unpcklps %xmm5, %xmm3            # xmm3 = xmm3[0],xmm5[0],xmm3[1],xmm5[1]
mulss 0x28b0(%rip), %xmm2     # 0xcd40
divss %xmm4, %xmm2
addss 0x28a8(%rip), %xmm2     # 0xcd44
movlps %xmm3, 0x18(%r12)
movss %xmm2, 0x20(%r12)
incl %r13d
movq 0x18(%r14), %rax
cmpl 0x8(%rax), %r13d
jl 0x9f06
leaq 0x1f0(%rsp), %rax
cmpl $0x0, 0x4(%rax)
jne 0xa4df
movq (%rbx), %rdi
movslq 0x8(%rbx), %rsi
movslq 0x10(%rbx), %rdx
leaq -0x1353(%rip), %rcx     # 0x9187
callq 0x37a0
cmpl $0x0, 0x8(%rbx)
jle 0xa5c6
xorl %ebp, %ebp
leaq 0x1f0(%rsp), %rcx
cmpl 0xc(%rcx), %ebp
movl $0x0, %eax
sbbl %eax, %eax
orl $0x1, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss %xmm0, 0x100(%rsp)
movl (%rcx), %r12d
leaq 0x160(%rsp), %r13
movslq 0x10(%rbx), %rax
movslq %ebp, %rsi
imulq %rax, %rsi
addq (%rbx), %rsi
testl %r12d, %r12d
je 0xa555
movl $0x16, %ecx
movq %r13, %rdi
rep  movsl (%rsi), %es:(%rdi)
movl $0xb, %ecx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x92a8
jmp 0xa5bb
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 0x100(%rsp), %xmm0
ucomiss %xmm2, %xmm0
jbe 0xa5bb
movl $0x16, %ecx
movq %r13, %rdi
rep  movsl (%rsi), %es:(%rdi)
movl $0xb, %ecx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x58(%rsp), %rdi
movl $0x9, %ecx
leaq 0x1f0(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
movq %r14, %rsi
callq 0x9331
incl %ebp
cmpl 0x8(%rbx), %ebp
jl 0xa51b
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq