// File: /workspace/github_cpp_makefile_star2_O3/shirat74[P]resample/Image.cc
// Function: Image::data_from_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, int, signed char, signed char)
Color *
Image::data_from_string (const std::string raster,
                         int32_t width, int32_t height,
                         int8_t nComps, int8_t bpc)
{
  Color *data = new Color[width*height];

  size_t expected = width * height * nComps * (bpc / 8);
  std::string str = (raster.size() < expected) ?
      raster + std::string(expected - raster.size(), 0) : raster;
  switch (bpc) {
  case 8:
    for (int32_t i = 0; i < width * height; i++) {
      Color   pixel;
      int32_t pos = nComps * i;
      for (int c = 0; c < nComps; c++)
        pixel.v[c] = round(65535 * ((uint8_t) str.at(pos+c) / 255.0));
      data[i] = pixel;
    }
    break;
  case 16:
    for (int32_t i = 0; i < width * height; i++) {
      Color   pixel;
      int32_t pos = 2 * nComps * i;
      for (int c = 0; c < nComps; c++)
        pixel.v[c] = ((uint8_t) str.at(pos+2*c)) * 256  +
                                      (uint8_t) str.at(pos+2*c+1);
      data[i] = pixel;
    }
    break;
  }

  return  data;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r8d, %r14d
movl %ecx, %ebp
movl %esi, %r15d
movq %rdi, %r12
imull %edx, %r15d
movslq %r15d, %rax
movl $0xc, %ecx
mulq %rcx
movq $-0x1, %rdi
cmovnoq %rax, %rdi
callq 0x2040
movq %rax, %rbx
movl %r15d, %eax
movl %ebp, 0xc(%rsp)
imull %ebp, %eax
movl %r14d, %ecx
sarb $0x7, %cl
shrb $0x5, %cl
addb %r14b, %cl
sarb $0x3, %cl
movsbl %cl, %ecx
imull %eax, %ecx
movslq %ecx, %rsi
movq 0x8(%r12), %rdx
subq %rdx, %rsi
jbe 0x27ae
leaq 0x40(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x30(%rsp), %rdi
xorl %edx, %edx
callq 0x2320
movq (%r12), %rcx
movq 0x8(%r12), %r8
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22f0
leaq 0x20(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rsi
je 0x27ca
movq %rsi, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x27d2
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%r12), %rsi
addq %rsi, %rdx
leaq 0x10(%rsp), %rdi
callq 0x2be8
jmp 0x2801
movupd (%rcx), %xmm0
movupd %xmm0, (%rdx)
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x2801
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x22d0
movsbl %r14b, %eax
cmpl $0x8, %eax
je 0x28a3
cmpl $0x10, %eax
jne 0x294d
movq 0x10(%rsp), %r14
testl %r15d, %r15d
jle 0x2952
movq 0x18(%rsp), %rdx
movl %r15d, %eax
movl 0xc(%rsp), %ebp
movl %ebp, %ecx
movl %ebp, %edi
addl %ebp, %edi
xorl %r8d, %r8d
xorl %r9d, %r9d
movl %r8d, %r8d
testb %bpl, %bpl
jle 0x287c
movq %r8, %r10
xorl %r11d, %r11d
cmpq %r10, %rdx
jbe 0x2992
leaq 0x1(%r10), %rsi
cmpq %rsi, %rdx
jbe 0x2995
movzwl (%r14,%r10), %esi
rolw $0x8, %si
movw %si, 0x30(%rsp,%r11,2)
incq %r11
addq $0x2, %r10
cmpq %r11, %rcx
jne 0x284b
leaq (%r9,%r9,2), %rsi
movl 0x37(%rsp), %r10d
movl %r10d, 0x7(%rbx,%rsi,4)
movq 0x30(%rsp), %r10
movq %r10, (%rbx,%rsi,4)
incq %r9
addl %edi, %r8d
cmpq %rax, %r9
jne 0x283d
jmp 0x2952
movq 0x10(%rsp), %r14
testl %r15d, %r15d
jle 0x2952
movq 0x18(%rsp), %r12
movl %r15d, %eax
movq %rax, 0x50(%rsp)
movl 0xc(%rsp), %eax
movl %eax, %r13d
xorl %ebp, %ebp
xorl %edx, %edx
movq %rbx, 0x58(%rsp)
movq %rdx, 0x60(%rsp)
movl %ebp, %ebp
testb %al, %al
jle 0x291c
movq %rbp, %r15
xorl %ebx, %ebx
cmpq %r15, %r12
jbe 0x297e
movzbl (%r14,%r15), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x370d(%rip), %xmm0     # 0x6008
mulsd 0x370d(%rip), %xmm0     # 0x6010
callq 0x2110
cvttsd2si %xmm0, %eax
movw %ax, 0x30(%rsp,%rbx,2)
incq %rbx
incq %r15
cmpq %rbx, %r13
jne 0x28de
movq 0x60(%rsp), %rdx
leaq (%rdx,%rdx,2), %rax
movl 0x37(%rsp), %ecx
movq 0x58(%rsp), %rbx
movl %ecx, 0x7(%rbx,%rax,4)
movq 0x30(%rsp), %rcx
movq %rcx, (%rbx,%rax,4)
incq %rdx
movl 0xc(%rsp), %eax
addl %eax, %ebp
cmpq 0x50(%rsp), %rdx
jne 0x28ce
jmp 0x2952
movq 0x10(%rsp), %r14
leaq 0x20(%rsp), %rax
cmpq %rax, %r14
je 0x296c
movq 0x20(%rsp), %rsi
incq %rsi
movq %r14, %rdi
callq 0x22d0
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x36bd(%rip), %rdi      # 0x6042
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2370
movq %r10, %rsi
leaq 0x36a6(%rip), %rdi      # 0x6042
xorl %eax, %eax
callq 0x2370
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x29dc
movq 0x40(%rsp), %rsi
jmp 0x29d4
movq %rax, %rbx
jmp 0x29dc
jmp 0x29be
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29dc
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x22d0
movq %rbx, %rdi
callq 0x2400