// File: /workspace/github_c_makefile_star2_O3/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 $0x268, %rsp            # imm = 0x268
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0xc8(%rsp)
movq 0x18(%rsi), %rax
cmpl $0x0, 0x8(%rax)
jle 0xa1c6
leaq 0x2a0(%rsp), %rcx
movsd 0x18(%rcx), %xmm0
movups 0x20(%rcx), %xmm1
movsd 0x24(%rcx), %xmm2
movsd 0x30(%rcx), %xmm3
movaps %xmm3, 0x150(%rsp)
movss 0x38(%rcx), %xmm3
movss %xmm3, 0xac(%rsp)
movl 0x10(%rcx), %ebp
movss 0x2c(%rcx), %xmm3
movlhps %xmm1, %xmm3            # xmm3 = xmm3[0],xmm1[0]
shufps $0xe2, %xmm1, %xmm3     # xmm3 = xmm3[2,0],xmm1[2,3]
movaps %xmm3, 0x140(%rsp)
movaps %xmm0, %xmm1
unpcklps %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movaps %xmm1, 0x130(%rsp)
shufps $0x11, %xmm0, %xmm2     # xmm2 = xmm2[1,0],xmm0[1,0]
shufps $0xe2, %xmm0, %xmm2     # xmm2 = xmm2[2,0],xmm0[2,3]
movaps %xmm2, 0x160(%rsp)
xorl %r13d, %r13d
movss 0x3064(%rip), %xmm3     # 0xcd90
movq (%rbx), %r12
movslq 0x10(%rbx), %rcx
movslq %r13d, %r15
imulq %rcx, %r15
movslq 0x54(%r12,%r15), %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), %xmm0
movss 0x8(%rdi,%rdx), %xmm6
movaps %xmm0, %xmm1
movaps 0x150(%rsp), %xmm4
mulps %xmm4, %xmm1
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
movaps %xmm0, %xmm2
mulss %xmm4, %xmm2
addss %xmm1, %xmm2
movaps %xmm6, %xmm8
movss 0xac(%rsp), %xmm5
mulss %xmm5, %xmm8
addss %xmm2, %xmm8
movaps %xmm8, 0x1f0(%rsp)
movss %xmm8, 0x8(%r12,%r15)
decq %rcx
decq %rax
addss %xmm3, %xmm8
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
movaps 0x160(%rsp), %xmm3
mulps %xmm3, %xmm1
shufps $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movaps 0x130(%rsp), %xmm7
mulps %xmm7, %xmm0
addps %xmm1, %xmm0
movaps %xmm6, %xmm1
shufps $0x0, %xmm6, %xmm1      # xmm1 = xmm1[0,0],xmm6[0,0]
movaps 0x140(%rsp), %xmm6
mulps %xmm6, %xmm1
addps %xmm0, %xmm1
movlps %xmm1, (%r12,%r15)
movaps %xmm1, %xmm9
movaps %xmm1, 0x1c0(%rsp)
movq (%r14), %rdx
movq (%rdx), %rsi
movslq 0x10(%rdx), %rdx
imulq %rcx, %rdx
movsd (%rsi,%rdx), %xmm0
movss 0x8(%rsi,%rdx), %xmm10
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
mulps %xmm3, %xmm1
movaps %xmm0, %xmm2
shufps $0x0, %xmm0, %xmm2      # xmm2 = xmm2[0,0],xmm0[0,0]
mulps %xmm7, %xmm2
addps %xmm1, %xmm2
movaps %xmm10, %xmm1
shufps $0x0, %xmm10, %xmm1     # xmm1 = xmm1[0,0],xmm10[0,0]
mulps %xmm6, %xmm1
addps %xmm2, %xmm1
movaps %xmm1, %xmm2
movaps %xmm1, 0x100(%rsp)
movaps %xmm4, %xmm1
mulps %xmm0, %xmm1
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
mulss %xmm4, %xmm0
addss %xmm1, %xmm0
movlps %xmm2, 0xc(%r12,%r15)
movq (%r14), %rcx
movq (%rcx), %rdx
movslq 0x10(%rcx), %rcx
imulq %rax, %rcx
mulss %xmm5, %xmm10
addss %xmm0, %xmm10
movaps %xmm10, 0xf0(%rsp)
movss %xmm10, 0x14(%r12,%r15)
movsd (%rdx,%rcx), %xmm0
movss 0x8(%rdx,%rcx), %xmm10
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
mulps %xmm3, %xmm1
movaps %xmm0, %xmm2
shufps $0x0, %xmm0, %xmm2      # xmm2 = xmm2[0,0],xmm0[0,0]
mulps %xmm7, %xmm2
addps %xmm1, %xmm2
movaps %xmm10, %xmm1
shufps $0x0, %xmm10, %xmm1     # xmm1 = xmm1[0,0],xmm10[0,0]
mulps %xmm6, %xmm1
addps %xmm2, %xmm1
movaps %xmm1, 0xe0(%rsp)
movaps %xmm4, %xmm1
mulps %xmm0, %xmm1
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
mulss %xmm4, %xmm0
addss %xmm1, %xmm0
mulss %xmm5, %xmm10
addss %xmm0, %xmm10
movaps %xmm10, 0xd0(%rsp)
movaps %xmm9, %xmm1
movaps 0x2ebe(%rip), %xmm0     # 0xcdc0
mulps %xmm0, %xmm1
movaps %xmm8, 0x200(%rsp)
movaps %xmm8, %xmm0
shufps $0x0, %xmm8, %xmm0      # xmm0 = xmm0[0,0],xmm8[0,0]
divps %xmm0, %xmm1
movaps 0x2eaf(%rip), %xmm0     # 0xcdd0
mulps %xmm0, %xmm1
movsd 0x2eb4(%rip), %xmm0     # 0xcde0
addps %xmm0, %xmm1
movaps %xmm1, 0x110(%rsp)
movaps %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm0     # xmm0 = xmm0[1,1],xmm1[1,1]
callq 0x3120
movaps %xmm0, 0x1b0(%rsp)
movaps 0x110(%rsp), %xmm0
callq 0x3120
movaps %xmm0, 0x1a0(%rsp)
movaps 0x100(%rsp), %xmm1
mulps 0x2e51(%rip), %xmm1     # 0xcdc0
movaps 0xf0(%rsp), %xmm0
addss 0x2e11(%rip), %xmm0     # 0xcd90
movaps %xmm0, 0x1e0(%rsp)
shufps $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
divps %xmm0, %xmm1
mulps 0x2e3b(%rip), %xmm1     # 0xcdd0
addps 0x2e44(%rip), %xmm1     # 0xcde0
movaps %xmm1, 0xb0(%rsp)
movaps %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm0     # xmm0 = xmm0[1,1],xmm1[1,1]
callq 0x3120
movaps %xmm0, 0x190(%rsp)
movaps 0xb0(%rsp), %xmm0
callq 0x3120
movaps %xmm0, 0x180(%rsp)
movaps 0xe0(%rsp), %xmm1
mulps 0x2de4(%rip), %xmm1     # 0xcdc0
movaps 0xd0(%rsp), %xmm0
addss 0x2da4(%rip), %xmm0     # 0xcd90
movaps %xmm0, 0x1d0(%rsp)
shufps $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
divps %xmm0, %xmm1
mulps 0x2dce(%rip), %xmm1     # 0xcdd0
addps 0x2dd7(%rip), %xmm1     # 0xcde0
movaps %xmm1, 0x120(%rsp)
movaps %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm0     # xmm0 = xmm0[1,1],xmm1[1,1]
callq 0x3120
movaps %xmm0, 0x170(%rsp)
movaps 0x120(%rsp), %xmm0
callq 0x3120
movaps 0xd0(%rsp), %xmm7
movaps 0xf0(%rsp), %xmm6
movaps 0x1f0(%rsp), %xmm5
movaps 0x100(%rsp), %xmm3
movaps %xmm3, %xmm2
movaps 0xe0(%rsp), %xmm4
shufps $0x1, %xmm4, %xmm2      # xmm2 = xmm2[1,0],xmm4[0,0]
shufps $0xe2, %xmm4, %xmm2     # xmm2 = xmm2[2,0],xmm4[2,3]
movaps 0x1c0(%rsp), %xmm1
subps %xmm1, %xmm2
shufps $0x1, %xmm3, %xmm4      # xmm4 = xmm4[1,0],xmm3[0,0]
shufps $0xe2, %xmm3, %xmm4     # xmm4 = xmm4[2,0],xmm3[2,3]
subps %xmm1, %xmm4
movaps %xmm6, %xmm1
unpcklps %xmm7, %xmm1            # xmm1 = xmm1[0],xmm7[0],xmm1[1],xmm7[1]
movaps %xmm5, %xmm3
shufps $0x0, %xmm5, %xmm3      # xmm3 = xmm3[0,0],xmm5[0,0]
subps %xmm3, %xmm1
movaps %xmm1, %xmm3
shufps $0xe1, %xmm1, %xmm3     # xmm3 = xmm3[1,0],xmm1[2,3]
mulps %xmm4, %xmm3
mulps %xmm2, %xmm1
subps %xmm3, %xmm1
movaps %xmm2, %xmm3
shufps $0x55, %xmm2, %xmm3     # xmm3 = xmm3[1,1],xmm2[1,1]
mulss %xmm2, %xmm3
movaps %xmm4, %xmm2
shufps $0x55, %xmm4, %xmm2     # xmm2 = xmm2[1,1],xmm4[1,1]
mulss %xmm4, %xmm2
subss %xmm3, %xmm2
movaps %xmm1, %xmm3
mulss %xmm1, %xmm3
movaps %xmm1, %xmm4
shufps $0x55, %xmm1, %xmm4     # xmm4 = xmm4[1,1],xmm1[1,1]
mulss %xmm4, %xmm4
addss %xmm3, %xmm4
movaps %xmm2, %xmm3
mulss %xmm2, %xmm3
addss %xmm4, %xmm3
sqrtss %xmm3, %xmm3
movss 0xfde(%rip), %xmm4      # 0xb0c0
divss %xmm3, %xmm4
mulss %xmm4, %xmm2
unpcklps %xmm4, %xmm4            # xmm4 = xmm4[0,0,1,1]
shufps $0xe1, %xmm1, %xmm1     # xmm1 = xmm1[1,0,2,3]
mulps %xmm4, %xmm1
movlps %xmm1, 0x48(%r12,%r15)
movss %xmm2, 0x50(%r12,%r15)
movaps 0x110(%rsp), %xmm2
testl %ebp, %ebp
je 0xa11d
movaps 0x1a0(%rsp), %xmm2
unpcklps 0x1b0(%rsp), %xmm2      # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
movss 0x2c6f(%rip), %xmm1     # 0xcd94
mulss %xmm1, %xmm5
divss 0x200(%rsp), %xmm5
movss 0x2c56(%rip), %xmm3     # 0xcd90
addss %xmm3, %xmm5
movlps %xmm2, (%r12,%r15)
movss %xmm5, 0x8(%r12,%r15)
movaps 0xb0(%rsp), %xmm2
je 0xa164
movaps 0x180(%rsp), %xmm2
unpcklps 0x190(%rsp), %xmm2      # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
mulss %xmm1, %xmm6
divss 0x1e0(%rsp), %xmm6
addss %xmm3, %xmm6
movlps %xmm2, 0xc(%r12,%r15)
movss %xmm6, 0x14(%r12,%r15)
movaps 0x120(%rsp), %xmm2
je 0xa197
unpcklps 0x170(%rsp), %xmm0      # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
movaps %xmm0, %xmm2
mulss %xmm1, %xmm7
divss 0x1d0(%rsp), %xmm7
addss %xmm3, %xmm7
movlps %xmm2, 0x18(%r12,%r15)
movss %xmm7, 0x20(%r12,%r15)
incl %r13d
movq 0x18(%r14), %rax
cmpl 0x8(%rax), %r13d
jl 0x9d2c
leaq 0x2a0(%rsp), %rax
cmpl $0x0, 0x4(%rax)
jne 0xa1eb
movq (%rbx), %rdi
movslq 0x8(%rbx), %rsi
movslq 0x10(%rbx), %rdx
leaq -0x1040(%rip), %rcx     # 0x91a6
callq 0x3790
cmpl $0x0, 0x8(%rbx)
movq 0xc8(%rsp), %r12
jle 0xa2da
xorl %ebp, %ebp
leaq 0x2a0(%rsp), %rcx
cmpl 0xc(%rcx), %ebp
movl $0x0, %eax
sbbl %eax, %eax
orl $0x1, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss %xmm0, 0xb0(%rsp)
movl (%rcx), %r15d
leaq 0x210(%rsp), %r13
movslq 0x10(%rbx), %rax
movslq %ebp, %rsi
imulq %rax, %rsi
addq (%rbx), %rsi
testl %r15d, %r15d
je 0xa269
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 %r12, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x92a6
jmp 0xa2cf
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 0xb0(%rsp), %xmm0
ucomiss %xmm2, %xmm0
jbe 0xa2cf
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 0x2a0(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r12, %rdi
movq %r14, %rsi
callq 0x932f
incl %ebp
cmpl 0x8(%rbx), %ebp
jl 0xa22f
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq