// File: /workspace/github_cpp_makefile_star2_O2/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, %ebp
movl %ecx, %r15d
movl %esi, %ebx
movq %rdi, %r12
imull %edx, %ebx
movslq %ebx, %rax
pushq $0xc
popq %rcx
mulq %rcx
pushq $-0x1
popq %rdi
cmovnoq %rax, %rdi
callq 0x2040
movq %rax, 0x10(%rsp)
movq %rbx, %r13
movl %ebx, %ecx
imull %r15d, %ecx
movsbl %bpl, %eax
movb $0x8, %dl
idivb %dl
movsbl %al, %eax
imull %ecx, %eax
movslq %eax, %rsi
subq 0x8(%r12), %rsi
jbe 0x2764
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x18(%rsp), %rdi
xorl %edx, %edx
callq 0x2310
leaq 0x48(%rsp), %rdi
leaq 0x18(%rsp), %rdx
movq %r12, %rsi
callq 0x2b46
leaq 0x18(%rsp), %rdi
callq 0x2140
jmp 0x2771
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
callq 0x2360
movsbl %bpl, %eax
cmpl $0x10, %eax
je 0x2816
cmpl $0x8, %eax
jne 0x28b0
xorl %ebx, %ebx
testl %r15d, %r15d
movl %r15d, %r12d
cmovlel %ebx, %r12d
movsbq %r15b, %rax
movq %rax, 0x8(%rsp)
testl %r13d, %r13d
cmovlel %ebx, %r13d
leaq 0x48(%rsp), %r15
xorl %ebp, %ebp
cmpq %r13, %rbp
je 0x28b0
xorl %r14d, %r14d
cmpq %r14, %r12
je 0x27f2
leaq (%rbx,%r14), %rsi
movq %r15, %rdi
callq 0x24b0
movzbl (%rax), %eax
cvtsi2sd %eax, %xmm0
divsd 0x3832(%rip), %xmm0     # 0x6008
mulsd 0x3832(%rip), %xmm0     # 0x6010
callq 0x2120
cvttsd2si %xmm0, %eax
movw %ax, 0x18(%rsp,%r14,2)
incq %r14
jmp 0x27b6
imulq $0xc, %rbp, %rax
movl 0x1f(%rsp), %ecx
movq 0x10(%rsp), %rdx
movl %ecx, 0x7(%rdx,%rax)
movq 0x18(%rsp), %rcx
movq %rcx, (%rdx,%rax)
incq %rbp
addq 0x8(%rsp), %rbx
jmp 0x27aa
leal (%r15,%r15), %eax
xorl %ebp, %ebp
testl %r15d, %r15d
cmovlel %ebp, %r15d
cltq
movq %rax, 0x38(%rsp)
testl %r13d, %r13d
cmovlel %ebp, %r13d
movq %r13, 0x40(%rsp)
pushq $0x1
popq %r13
leaq 0x48(%rsp), %r12
cmpq 0x40(%rsp), %rbp
je 0x28b0
movq %r13, 0x8(%rsp)
xorl %r14d, %r14d
cmpq %r14, %r15
je 0x2887
leaq -0x1(%r13), %rsi
movq %r12, %rdi
callq 0x24b0
movzbl (%rax), %ebx
movq %r12, %rdi
movq %r13, %rsi
callq 0x24b0
movzwl %bx, %ecx
shll $0x8, %ecx
movzbl (%rax), %eax
orl %ecx, %eax
movw %ax, 0x18(%rsp,%r14,2)
incq %r14
addq $0x2, %r13
jmp 0x284e
imulq $0xc, %rbp, %rax
movl 0x1f(%rsp), %ecx
movq 0x10(%rsp), %rdx
movl %ecx, 0x7(%rdx,%rax)
movq 0x18(%rsp), %rcx
movq %rcx, (%rdx,%rax)
incq %rbp
movq 0x8(%rsp), %r13
addq 0x38(%rsp), %r13
jmp 0x283f
leaq 0x48(%rsp), %rdi
callq 0x2140
movq 0x10(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
jmp 0x28e7
movq %rax, %rbx
jmp 0x28ec
jmp 0x28df
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x2140
movq %rbx, %rdi
callq 0x2420