// File: lvandeve[P]lodepng/lodepng_util.cpp
// Function: lodepng::getICCChrm(float*, float*, lodepng::LodePNGICC const*)
static unsigned getICCChrm(float m[9], float whitepoint[3], const LodePNGICC* icc) {
  size_t i;
  if(icc->inputspace == 2) { /* RGB profile */
    float red[3], green[3], blue[3];
    float white[3]; /* the whitepoint of the RGB color space (absolute) */
    /* Adaptation matrix a.
    This is an adaptation needed for ICC's file format (due to it using
    an internal global illuminant unrelated to the actual images) */
    float a[9] = {1,0,0, 0,1,0, 0,0,1};
    /* If the profile has chromatic adaptation matrix "chad", use that one,
    else compute it from the illuminant and whitepoint. */
    if(icc->has_chad) {
      for(i = 0; i < 9; i++) a[i] = icc->chad[i];
      invMatrix(a);
    } else {
      if(getAdaptationMatrix(a, 1, icc->illuminant[0], icc->illuminant[1], icc->illuminant[2],
                             icc->white[0], icc->white[1], icc->white[2])) {
        return 1; /* error computing matrix */
      }
    }
    /* If the profile has a chad, then also the RGB's whitepoint must also be adapted from it (and the one
    given is normally D50). If it did not have a chad, then the whitepoint given is already the adapted one. */
    if(icc->has_chad) {
      mulMatrix(&white[0], &white[1], &white[2], a, icc->white[0], icc->white[1], icc->white[2]);
    } else {
      for(i = 0; i < 3; i++) white[i] = icc->white[i];
    }

    mulMatrix(&red[0], &red[1], &red[2], a, icc->red[0], icc->red[1], icc->red[2]);
    mulMatrix(&green[0], &green[1], &green[2], a, icc->green[0], icc->green[1], icc->green[2]);
    mulMatrix(&blue[0], &blue[1], &blue[2], a, icc->blue[0], icc->blue[1], icc->blue[2]);

    if(getChrmMatrixXYZ(m, white[0], white[1], white[2], red[0], red[1], red[2],
                        green[0], green[1], green[2], blue[0], blue[1], blue[2])) {
      return 1; /* error computing matrix */
    }
    /* output absolute whitepoint of the original RGB model */
    whitepoint[0] = white[0];
    whitepoint[1] = white[1];
    whitepoint[2] = white[2];
  } else {
    /* output the unity matrix, for doing no transform */
    m[0] = m[4] = m[8] = 1;
    m[1] = m[2] = m[3] = m[5] = m[6] = m[7] = 0;
    /* grayscale, don't do anything. That means we are implicitely using equal energy whitepoint "E", indicate
    this to the output. */
    whitepoint[0] = whitepoint[1] = whitepoint[2] = 1;
  }
  return 0; /* success */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x21fa2
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x24, %edx
callq 0x3160
movss 0x90d08(%rip), %xmm0    # 0xb29f4
movss %xmm0, -0x80(%rbp)
movss 0x90cfb(%rip), %xmm0    # 0xb29f4
movss %xmm0, -0x70(%rbp)
movss 0x90cee(%rip), %xmm0    # 0xb29f4
movss %xmm0, -0x60(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
je 0x21d55
movq $0x0, -0x28(%rbp)
cmpq $0x9, -0x28(%rbp)
jae 0x21d4a
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movss 0x20(%rax,%rcx,4), %xmm0
movq -0x28(%rbp), %rax
movss %xmm0, -0x80(%rbp,%rax,4)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x21d1d
leaq -0x80(%rbp), %rdi
callq 0x22250
jmp 0x21dac
leaq -0x80(%rbp), %rdi
movq -0x20(%rbp), %rax
movss 0x10(%rax), %xmm0
movq -0x20(%rbp), %rax
movss 0x14(%rax), %xmm1
movq -0x20(%rbp), %rax
movss 0x18(%rax), %xmm2
movq -0x20(%rbp), %rax
movss 0x48(%rax), %xmm3
movq -0x20(%rbp), %rax
movss 0x4c(%rax), %xmm4
movq -0x20(%rbp), %rax
movss 0x50(%rax), %xmm5
movl $0x1, %esi
callq 0x226e0
cmpl $0x0, %eax
je 0x21daa
movl $0x1, -0x4(%rbp)
jmp 0x22055
jmp 0x21dac
movq -0x20(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
je 0x21dfc
leaq -0x58(%rbp), %rdi
leaq -0x58(%rbp), %rsi
addq $0x4, %rsi
leaq -0x58(%rbp), %rdx
addq $0x8, %rdx
leaq -0x80(%rbp), %rcx
movq -0x20(%rbp), %rax
movss 0x48(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x20(%rbp), %rax
movss 0x4c(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq -0x20(%rbp), %rax
movss 0x50(%rax), %xmm2
cvtss2sd %xmm2, %xmm2
callq 0x21b80
jmp 0x21e33
movq $0x0, -0x28(%rbp)
cmpq $0x3, -0x28(%rbp)
jae 0x21e31
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movss 0x48(%rax,%rcx,4), %xmm0
movq -0x28(%rbp), %rax
movss %xmm0, -0x58(%rbp,%rax,4)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x21e04
jmp 0x21e33
leaq -0x34(%rbp), %rdi
leaq -0x34(%rbp), %rsi
addq $0x4, %rsi
leaq -0x34(%rbp), %rdx
addq $0x8, %rdx
leaq -0x80(%rbp), %rcx
movq -0x20(%rbp), %rax
movss 0x58(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x20(%rbp), %rax
movss 0x5c(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq -0x20(%rbp), %rax
movss 0x60(%rax), %xmm2
cvtss2sd %xmm2, %xmm2
callq 0x21b80
leaq -0x40(%rbp), %rdi
leaq -0x40(%rbp), %rsi
addq $0x4, %rsi
leaq -0x40(%rbp), %rdx
addq $0x8, %rdx
leaq -0x80(%rbp), %rcx
movq -0x20(%rbp), %rax
movss 0x64(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x20(%rbp), %rax
movss 0x68(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq -0x20(%rbp), %rax
movss 0x6c(%rax), %xmm2
cvtss2sd %xmm2, %xmm2
callq 0x21b80
leaq -0x4c(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
addq $0x4, %rsi
leaq -0x4c(%rbp), %rdx
addq $0x8, %rdx
leaq -0x80(%rbp), %rcx
movq -0x20(%rbp), %rax
movss 0x70(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x20(%rbp), %rax
movss 0x74(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq -0x20(%rbp), %rax
movss 0x78(%rax), %xmm2
cvtss2sd %xmm2, %xmm2
callq 0x21b80
movq -0x10(%rbp), %rdi
movss -0x58(%rbp), %xmm0
movss -0x54(%rbp), %xmm1
movss -0x50(%rbp), %xmm2
movss -0x34(%rbp), %xmm3
movss -0x30(%rbp), %xmm4
movss -0x2c(%rbp), %xmm5
movss -0x40(%rbp), %xmm6
movss -0x3c(%rbp), %xmm7
movss -0x38(%rbp), %xmm11
movss -0x4c(%rbp), %xmm10
movss -0x48(%rbp), %xmm9
movss -0x44(%rbp), %xmm8
movss %xmm11, (%rsp)
movss %xmm10, 0x8(%rsp)
movss %xmm9, 0x10(%rsp)
movss %xmm8, 0x18(%rsp)
callq 0x22910
cmpl $0x0, %eax
je 0x21f74
movl $0x1, -0x4(%rbp)
jmp 0x22055
movss -0x58(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, (%rax)
movss -0x54(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x4(%rax)
movss -0x50(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x8(%rax)
jmp 0x2204e
movq -0x10(%rbp), %rax
movss 0x90a46(%rip), %xmm0    # 0xb29f4
movss %xmm0, 0x20(%rax)
movq -0x10(%rbp), %rax
movss 0x90a35(%rip), %xmm0    # 0xb29f4
movss %xmm0, 0x10(%rax)
movq -0x10(%rbp), %rax
movss 0x90a24(%rip), %xmm0    # 0xb29f4
movss %xmm0, (%rax)
movq -0x10(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x1c(%rax)
movq -0x10(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x18(%rax)
movq -0x10(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x14(%rax)
movq -0x10(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0xc(%rax)
movq -0x10(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%rax)
movq -0x10(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x4(%rax)
movq -0x18(%rbp), %rax
movss 0x909cc(%rip), %xmm0    # 0xb29f4
movss %xmm0, 0x8(%rax)
movq -0x18(%rbp), %rax
movss 0x909bb(%rip), %xmm0    # 0xb29f4
movss %xmm0, 0x4(%rax)
movq -0x18(%rbp), %rax
movss 0x909aa(%rip), %xmm0    # 0xb29f4
movss %xmm0, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)