// File: lvandeve[P]lodepng/lodepng_util.cpp
// Function: lodepng::getAdaptationMatrix(float*, int, float, float, float, float, float, float)
static unsigned getAdaptationMatrix(float* m, int type,
                                    float wx0, float wy0, float wz0,
                                    float wx1, float wy1, float wz1) {
  int i;
  static const float bradford[9] = {
    0.8951f, 0.2664f, -0.1614f,
    -0.7502f, 1.7135f, 0.0367f,
    0.0389f, -0.0685f, 1.0296f
  };
  static const float bradfordinv[9] = {
    0.9869929f, -0.1470543f, 0.1599627f,
    0.4323053f, 0.5183603f, 0.0492912f,
   -0.0085287f, 0.0400428f, 0.9684867f
  };
  static const float vonkries[9] = {
    0.40024f, 0.70760f, -0.08081f,
    -0.22630f, 1.16532f, 0.04570f,
    0.00000f, 0.00000f, 0.91822f,
  };
  static const float vonkriesinv[9] = {
    1.8599364f, -1.1293816f, 0.2198974f,
    0.3611914f, 0.6388125f, -0.0000064f,
   0.0000000f, 0.0000000f, 1.0890636f
  };
  if(type == 0) {
    for(i = 0; i < 9; i++) m[i] = 0;
    m[0] = wx1 / wx0;
    m[4] = wy1 / wy0;
    m[8] = wz1 / wz0;
  } else {
    const float* cat = (type == 1) ? bradford : vonkries;
    const float* inv = (type == 1) ? bradfordinv : vonkriesinv;
    float rho0, gam0, bet0, rho1, gam1, bet1, rho2, gam2, bet2;
    mulMatrix(&rho0, &gam0, &bet0, cat, wx0, wy0, wz0);
    mulMatrix(&rho1, &gam1, &bet1, cat, wx1, wy1, wz1);
    rho2 = rho1 / rho0;
    gam2 = gam1 / gam0;
    bet2 = bet1 / bet0;
    /* Multiply diagonal matrix with cat */
    for(i = 0; i < 3; i++) {
      m[i + 0] = rho2 * cat[i + 0];
      m[i + 3] = gam2 * cat[i + 3];
      m[i + 6] = bet2 * cat[i + 6];
    }
    mulMatrixMatrix(m, inv, m);
  }
  return 0; /* ok */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movss %xmm0, -0x10(%rbp)
movss %xmm1, -0x14(%rbp)
movss %xmm2, -0x18(%rbp)
movss %xmm3, -0x1c(%rbp)
movss %xmm4, -0x20(%rbp)
movss %xmm5, -0x24(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x22778
movl $0x0, -0x28(%rbp)
cmpl $0x9, -0x28(%rbp)
jge 0x2273b
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rcx
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2271a
movss -0x1c(%rbp), %xmm0
divss -0x10(%rbp), %xmm0
movq -0x8(%rbp), %rax
movss %xmm0, (%rax)
movss -0x20(%rbp), %xmm0
divss -0x14(%rbp), %xmm0
movq -0x8(%rbp), %rax
movss %xmm0, 0x10(%rax)
movss -0x24(%rbp), %xmm0
divss -0x18(%rbp), %xmm0
movq -0x8(%rbp), %rax
movss %xmm0, 0x20(%rax)
jmp 0x22900
cmpl $0x1, -0xc(%rbp)
jne 0x2278b
leaq 0x9045b(%rip), %rax     # 0xb2be0
movq %rax, -0x68(%rbp)
jmp 0x22798
leaq 0x904ae(%rip), %rax     # 0xb2c40
movq %rax, -0x68(%rbp)
jmp 0x22798
movq -0x68(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpl $0x1, -0xc(%rbp)
jne 0x227b3
leaq 0x90463(%rip), %rax     # 0xb2c10
movq %rax, -0x70(%rbp)
jmp 0x227c0
leaq 0x904b6(%rip), %rax     # 0xb2c70
movq %rax, -0x70(%rbp)
jmp 0x227c0
movq -0x70(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rcx
movss -0x10(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x14(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movss -0x18(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
leaq -0x3c(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x44(%rbp), %rdx
callq 0x21b80
movq -0x30(%rbp), %rcx
movss -0x1c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x20(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movss -0x24(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
leaq -0x48(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x21b80
movss -0x48(%rbp), %xmm0
divss -0x3c(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x4c(%rbp), %xmm0
divss -0x40(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x50(%rbp), %xmm0
divss -0x44(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x3, -0x28(%rbp)
jge 0x228ef
movss -0x54(%rbp), %xmm0
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
mulss (%rax,%rcx,4), %xmm0
movq -0x8(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movss -0x58(%rbp), %xmm0
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
mulss (%rax,%rcx,4), %xmm0
movq -0x8(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movss -0x5c(%rbp), %xmm0
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x6, %ecx
movslq %ecx, %rcx
mulss (%rax,%rcx,4), %xmm0
movq -0x8(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x6, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2285c
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x8(%rbp), %rdx
callq 0x22ac0
xorl %eax, %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)