// File: /workspace/github_cpp_makefile_star2_O1/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, %ebx
movl %ecx, %r14d
movl %esi, %ebp
movq %rdi, %r12
imull %edx, %ebp
movslq %ebp, %rax
movl $0xc, %ecx
mulq %rcx
movq $-0x1, %rdi
cmovnoq %rax, %rdi
callq 0x2040
movq %rax, 0x8(%rsp)
movl %ebp, %eax
imull %r14d, %eax
movl %ebx, %ecx
sarb $0x7, %cl
shrb $0x5, %cl
addb %bl, %cl
sarb $0x3, %cl
movsbl %cl, %ecx
imull %eax, %ecx
movslq %ecx, %r13
movq 0x8(%r12), %r15
movq %r13, %rsi
subq %r15, %rsi
seta (%rsp)
jbe 0x27b0
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x48(%rsp), %rdi
xorl %edx, %edx
callq 0x2320
movq (%r12), %rcx
movq 0x8(%r12), %r8
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22f0
leaq 0x30(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rsi
je 0x27cd
movq %rsi, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x27d5
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%r12), %rsi
leaq (%rsi,%r15), %rdx
leaq 0x20(%rsp), %rdi
callq 0x2bfe
jmp 0x27ed
movupd (%rcx), %xmm0
movupd %xmm0, (%rdx)
movq 0x8(%rax), %rdx
movq %rdx, 0x28(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
cmpq %r15, %r13
jbe 0x280d
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x280d
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x22d0
movsbl %bl, %eax
cmpl $0x8, %eax
je 0x28ae
cmpl $0x10, %eax
jne 0x2958
testl %ebp, %ebp
jle 0x2958
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rdx
movl %ebp, %ecx
movl %r14d, %edi
movl %r14d, %r8d
addl %r14d, %r8d
xorl %r9d, %r9d
xorl %r10d, %r10d
movl %r9d, %r9d
testb %r14b, %r14b
jle 0x2882
movq %r9, %r11
xorl %ebx, %ebx
cmpq %r11, %rdx
jbe 0x299b
leaq 0x1(%r11), %rsi
cmpq %rsi, %rdx
jbe 0x299e
movzwl (%rax,%r11), %esi
rolw $0x8, %si
movw %si, 0x14(%rsp,%rbx,2)
incq %rbx
addq $0x2, %r11
cmpq %rbx, %rdi
jne 0x2852
leaq (%r10,%r10,2), %rsi
movl 0x1b(%rsp), %r11d
movq 0x8(%rsp), %rbx
movl %r11d, 0x7(%rbx,%rsi,4)
movq 0x14(%rsp), %r11
movq %r11, (%rbx,%rsi,4)
incq %r10
addl %r8d, %r9d
cmpq %rcx, %r10
jne 0x2845
jmp 0x2958
testl %ebp, %ebp
jle 0x2958
movq 0x20(%rsp), %r13
movq 0x28(%rsp), %r15
movl %ebp, %eax
movq %rax, 0x40(%rsp)
movl %r14d, %ebx
xorl %ebp, %ebp
xorl %esi, %esi
movl %r14d, 0x10(%rsp)
movq %rsi, (%rsp)
movl %ebp, %ebp
testb %r14b, %r14b
jle 0x2924
movq %rbp, %r12
xorl %r14d, %r14d
cmpq %r12, %r15
jbe 0x2987
movzbl (%r13,%r12), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x3706(%rip), %xmm0     # 0x6008
mulsd 0x3706(%rip), %xmm0     # 0x6010
callq 0x2110
cvttsd2si %xmm0, %eax
movw %ax, 0x14(%rsp,%r14,2)
incq %r14
incq %r12
cmpq %r14, %rbx
jne 0x28e4
movq (%rsp), %rsi
leaq (%rsi,%rsi,2), %rax
movl 0x1b(%rsp), %ecx
movq 0x8(%rsp), %rdx
movl %ecx, 0x7(%rdx,%rax,4)
movq 0x14(%rsp), %rcx
movq %rcx, (%rdx,%rax,4)
incq %rsi
movl 0x10(%rsp), %r14d
addl %r14d, %ebp
cmpq 0x40(%rsp), %rsi
jne 0x28d3
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2973
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x22d0
movq 0x8(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x36b4(%rip), %rdi      # 0x6042
movq %r12, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2370
movq %r11, %rsi
leaq 0x369d(%rip), %rdi      # 0x6042
xorl %eax, %eax
callq 0x2370
movq %rax, %rbx
movb $0x1, (%rsp)
jmp 0x29dc
movq %rax, %rbx
cmpq %r15, %r13
jbe 0x29dc
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
movb $0x1, (%rsp)
cmpq %rax, %rdi
je 0x29dc
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x22d0
cmpb $0x0, (%rsp)
jmp 0x2a02
jmp 0x29e4
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2a02
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x22d0
movq %rbx, %rdi
callq 0x2400