// File: jpbalarini[P]otsus/./framework/CImage.cpp
// Function: CImage::load_float_RGB(char*)
void CImage::load_float_RGB(char *filename) {
  int num_channels;
  size_t dummy;
  
  CFramework *fw = CFramework::get_framework();

  FILE *infile = fopen(filename, "rb");
  if (!infile) {
    PRINT_ERROR("CImage: error opening float RGB file %s\n!", filename);
    exit(-1);
  }

  dummy = fread(&this->Nx, sizeof(this->Nx), 1, infile);
  dummy += fread(&this->Ny, sizeof(this->Ny), 1, infile);
  dummy += fread(&num_channels, sizeof(num_channels), 1, infile);
  dummy = dummy; // To prevent the warning

  this->bits = 16;
  PRINT_VERBOSE("CImage load RGB (%dx%d), %d channels, in I_%d\n",
    this->Nx, this->Ny, num_channels, this->id);

  int id_data_all;
  float *data_ALL = fw->create_array(num_channels*this->Nx*this->Ny, id_data_all);
  dummy = fread(data_ALL, sizeof(float), num_channels*this->Nx*this->Ny, infile);
  fclose(infile);

  // Create data channels
  create_channels(num_channels, Nx, Ny);

  int idx_data = 0;
  for (int ch = 0; ch < num_channels; ch++) {
    float *m = this->get_channel(ch);
    for (int y = 0; y < Ny; y++) {
        for (int x = 0; x < Nx; x++) {
          m[y*this->Nx+x] = data_ALL[idx_data];
          idx_data++;
        }
    }
  }

  fw->delete_matrix(id_data_all);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
callq 0x3b50
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x64e6(%rip), %rsi      # 0xd152
callq 0x33c0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x6cc6
movq 0xc335(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
leaq 0x643c(%rip), %rsi      # 0xd0c9
movl $0xb0, %edx
leaq 0x6631(%rip), %rcx      # 0xd2ca
movb $0x0, %al
callq 0x3470
movq 0xc311(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x66f1(%rip), %rsi      # 0xd3a6
movb $0x0, %al
callq 0x3470
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x33e0
movq -0x60(%rbp), %rdi
movq -0x30(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x34c0
movq -0x60(%rbp), %rdi
movq %rax, -0x20(%rbp)
addq $0x4, %rdi
movq -0x30(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x34c0
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x30(%rbp), %rcx
leaq -0x14(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x34c0
movq %rax, %rcx
movq -0x60(%rbp), %rax
addq -0x20(%rbp), %rcx
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq %rcx, -0x20(%rbp)
movl $0x10, 0x8(%rax)
leaq 0xc5e9(%rip), %rax      # 0x13329
testb $0x1, (%rax)
je 0x6d63
movq -0x60(%rbp), %rax
movl (%rax), %esi
movl 0x4(%rax), %edx
movl -0x14(%rbp), %ecx
movl 0xc(%rax), %r8d
leaq 0x6674(%rip), %rdi      # 0xd3d0
movb $0x0, %al
callq 0x3070
movq -0x60(%rbp), %rax
movq -0x28(%rbp), %rdi
movl -0x14(%rbp), %esi
imull (%rax), %esi
imull 0x4(%rax), %esi
leaq -0x34(%rbp), %rdx
callq 0x3d50
movq -0x60(%rbp), %rcx
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %eax
imull (%rcx), %eax
imull 0x4(%rcx), %eax
movslq %eax, %rdx
movq -0x30(%rbp), %rcx
movl $0x4, %esi
callq 0x34c0
movq %rax, -0x20(%rbp)
movq -0x30(%rbp), %rdi
callq 0x32e0
movq -0x60(%rbp), %rdi
movl -0x14(%rbp), %esi
movl (%rdi), %edx
movl 0x4(%rdi), %ecx
callq 0x6740
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x6e69
movq -0x60(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x81e0
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x60(%rbp), %rcx
movl -0x54(%rbp), %eax
cmpl 0x4(%rcx), %eax
jge 0x6e59
movl $0x0, -0x58(%rbp)
movq -0x60(%rbp), %rcx
movl -0x58(%rbp), %eax
cmpl (%rcx), %eax
jge 0x6e4c
movq -0x60(%rbp), %rdx
movq -0x40(%rbp), %rax
movslq -0x44(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x50(%rbp), %rax
movl -0x54(%rbp), %ecx
imull (%rdx), %ecx
addl -0x58(%rbp), %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x6e07
jmp 0x6e4e
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x6df4
jmp 0x6e5b
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x6dd1
movq -0x28(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x3a30
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)