// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/utils.c
// Function: bilinearTexSampling1
unsigned char bilinearTexSampling1(unsigned char *d, int width, int height,
                                   float u, float v) {
  //from jonolick.com
  int ww = width-1, hh = height-1;
  float fu = (u + 1000.0f) * ww; // NOTE: assumes less than 1000 repeats
  float fv = (v + 1000.0f) * hh;
  int u1 = ((int)fu) % ww;
  int v1 = ((int)fv) % hh;
  int u2 = (u1 + 1) % ww;
  int v2 = (v1 + 1) % hh;
  float fracu = fu - floorf( fu );
  float fracv = fv - floorf( fv );
  float w[4] = {(1 - fracu) * (1 - fracv), fracu * (1 - fracv), (1 - fracu) * fracv, fracu *  fracv};
  unsigned char c[4] = { d[v1*width + u1], d[v1*width + u2], d[v2*width + u1], d[v2*width + u2] };
  return (unsigned char)(c[0]*w[0] + c[1]*w[1] + c[2]*w[2] + c[3]*w[3]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movss %xmm0, -0x14(%rbp)
movss %xmm1, -0x18(%rbp)
movl -0xc(%rbp), %eax
decl %eax
movl %eax, -0x1c(%rbp)
movl -0x10(%rbp), %eax
decl %eax
movl %eax, -0x20(%rbp)
movss -0x14(%rbp), %xmm0
movss 0xc4267(%rip), %xmm1    # 0x4e5f10
addss %xmm1, %xmm0
cvtsi2ssl -0x1c(%rbp), %xmm2
mulss %xmm2, %xmm0
movss %xmm0, -0x24(%rbp)
movss -0x18(%rbp), %xmm0
addss %xmm1, %xmm0
cvtsi2ssl -0x20(%rbp), %xmm1
mulss %xmm1, %xmm0
movss %xmm0, -0x28(%rbp)
cvttss2si -0x24(%rbp), %eax
movl -0x1c(%rbp), %ecx
cltd
idivl %ecx
movl %edx, -0x2c(%rbp)
cvttss2si -0x28(%rbp), %eax
movl -0x20(%rbp), %ecx
cltd
idivl %ecx
movl %edx, -0x30(%rbp)
movl -0x2c(%rbp), %eax
incl %eax
movl -0x1c(%rbp), %ecx
cltd
idivl %ecx
movl %edx, -0x34(%rbp)
movl -0x30(%rbp), %eax
incl %eax
movl -0x20(%rbp), %ecx
cltd
idivl %ecx
movl %edx, -0x38(%rbp)
movss -0x24(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
callq 0x401148
movaps %xmm0, %xmm1
movss -0x5c(%rbp), %xmm0
subss %xmm1, %xmm0
movss %xmm0, -0x3c(%rbp)
movss -0x28(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
callq 0x401148
movaps %xmm0, %xmm1
movss -0x58(%rbp), %xmm0
subss %xmm1, %xmm0
movss %xmm0, -0x40(%rbp)
movss -0x3c(%rbp), %xmm2
movss 0xc172d(%rip), %xmm0    # 0x4e3484
movaps %xmm0, %xmm1
subss %xmm2, %xmm1
movss -0x40(%rbp), %xmm3
movaps %xmm0, %xmm2
subss %xmm3, %xmm2
mulss %xmm2, %xmm1
movss %xmm1, -0x50(%rbp)
movss -0x3c(%rbp), %xmm1
movss -0x40(%rbp), %xmm3
movaps %xmm0, %xmm2
subss %xmm3, %xmm2
mulss %xmm2, %xmm1
movss %xmm1, -0x4c(%rbp)
movss -0x3c(%rbp), %xmm1
subss %xmm1, %xmm0
movss -0x40(%rbp), %xmm1
mulss %xmm1, %xmm0
movss %xmm0, -0x48(%rbp)
movss -0x3c(%rbp), %xmm0
movss -0x40(%rbp), %xmm1
mulss %xmm1, %xmm0
movss %xmm0, -0x44(%rbp)
movq -0x8(%rbp), %rax
movl -0x30(%rbp), %ecx
movl -0xc(%rbp), %edx
imull %edx, %ecx
movl -0x2c(%rbp), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0x54(%rbp)
movq -0x8(%rbp), %rax
movl -0x30(%rbp), %ecx
movl -0xc(%rbp), %edx
imull %edx, %ecx
movl -0x34(%rbp), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0x53(%rbp)
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
movl -0xc(%rbp), %edx
imull %edx, %ecx
movl -0x2c(%rbp), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0x52(%rbp)
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
movl -0xc(%rbp), %edx
imull %edx, %ecx
movl -0x34(%rbp), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0x51(%rbp)
movzbl -0x54(%rbp), %eax
cvtsi2ss %eax, %xmm0
movzbl -0x53(%rbp), %eax
cvtsi2ss %eax, %xmm1
movss -0x50(%rbp), %xmm2
movss -0x4c(%rbp), %xmm3
mulss %xmm3, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movzbl -0x52(%rbp), %eax
cvtsi2ss %eax, %xmm1
movss -0x48(%rbp), %xmm2
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movzbl -0x51(%rbp), %eax
cvtsi2ss %eax, %xmm0
movss -0x44(%rbp), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
cvttss2si %xmm0, %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)