// File: 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
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0xd0(%rbp)
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movb %cl, -0x11(%rbp)
movb %al, -0x12(%rbp)
movl -0xc(%rbp), %eax
imull -0x10(%rbp), %eax
cltq
movq %rax, -0xc0(%rbp)
movl $0xc, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0xc8(%rbp)
callq 0x3040
movq %rax, %rcx
movq -0xc0(%rbp), %rax
movq %rcx, -0xb8(%rbp)
cmpq $0x0, %rax
je 0x39cd
movq -0xb8(%rbp), %rax
movq -0xc0(%rbp), %rcx
imulq $0xc, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0xe0(%rbp)
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x42d0
jmp 0x39af
movq -0xe0(%rbp), %rcx
movq -0xe8(%rbp), %rax
addq $0xc, %rax
cmpq %rcx, %rax
movq %rax, -0xd8(%rbp)
jne 0x399a
movq -0xd0(%rbp), %rdi
movq -0xb8(%rbp), %rax
movq %rax, -0x20(%rbp)
movl -0xc(%rbp), %eax
imull -0x10(%rbp), %eax
movsbl -0x11(%rbp), %ecx
imull %ecx, %eax
movl %eax, -0xec(%rbp)
movsbl -0x12(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0xec(%rbp), %eax
imull %ecx, %eax
cltq
movq %rax, -0x38(%rbp)
callq 0x3250
movq -0x38(%rbp), %rcx
movb $0x0, -0x7a(%rbp)
movb $0x0, -0x7b(%rbp)
cmpq %rcx, %rax
jae 0x3a9c
movq -0xd0(%rbp), %rdi
movq -0x38(%rbp), %rax
movq %rax, -0x108(%rbp)
callq 0x3250
movq %rax, %rcx
movq -0x108(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x100(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x3510
movq -0x100(%rbp), %rsi
movq -0xf8(%rbp), %rcx
movb $0x1, -0x7a(%rbp)
leaq -0x78(%rbp), %rdi
xorl %edx, %edx
callq 0x4330
jmp 0x3a80
movq -0xd0(%rbp), %rsi
movb $0x1, -0x7b(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rdx
callq 0x42e0
jmp 0x3a9a
jmp 0x3ab0
movq -0xd0(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x3160
jmp 0x3aae
jmp 0x3ab0
testb $0x1, -0x7b(%rbp)
jne 0x3ab8
jmp 0x3ac1
leaq -0x78(%rbp), %rdi
callq 0x3210
testb $0x1, -0x7a(%rbp)
jne 0x3ac9
jmp 0x3ad2
leaq -0x79(%rbp), %rdi
callq 0x3380
movsbl -0x12(%rbp), %eax
movl %eax, -0x10c(%rbp)
subl $0x8, %eax
je 0x3b5e
jmp 0x3ae3
movl -0x10c(%rbp), %eax
subl $0x10, %eax
je 0x3c81
jmp 0x3dbf
movq -0xc8(%rbp), %rsi
movq -0xb8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x35a0
jmp 0x3de3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x3b48
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
testb $0x1, -0x7b(%rbp)
jne 0x3b3d
jmp 0x3b46
leaq -0x78(%rbp), %rdi
callq 0x3210
jmp 0x3b48
testb $0x1, -0x7a(%rbp)
jne 0x3b50
jmp 0x3b59
leaq -0x79(%rbp), %rdi
callq 0x3380
jmp 0x3de3
movl $0x0, -0x80(%rbp)
movl -0x80(%rbp), %eax
movl -0xc(%rbp), %ecx
imull -0x10(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3c7c
leaq -0x8c(%rbp), %rdi
callq 0x42d0
jmp 0x3b85
movsbl -0x11(%rbp), %eax
imull -0x80(%rbp), %eax
movl %eax, -0x90(%rbp)
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
movsbl -0x11(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3c41
movl -0x90(%rbp), %eax
movl -0x94(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
leaq -0x58(%rbp), %rdi
callq 0x3580
movq %rax, -0x118(%rbp)
jmp 0x3bd2
movq -0x118(%rbp), %rax
movzbl (%rax), %eax
cvtsi2sd %eax, %xmm0
movsd 0x9420(%rip), %xmm1     # 0xd008
divsd %xmm1, %xmm0
movsd 0x941c(%rip), %xmm1     # 0xd010
mulsd %xmm1, %xmm0
callq 0x3150
cvttsd2si %xmm0, %eax
movw %ax, %cx
movslq -0x94(%rbp), %rax
movw %cx, -0x8c(%rbp,%rax,2)
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x3b9d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x3210
jmp 0x3de3
movq -0x20(%rbp), %rax
movslq -0x80(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq -0x8c(%rbp), %rcx
movq %rcx, (%rax)
movw -0x84(%rbp), %cx
movw %cx, 0x8(%rax)
movb -0x82(%rbp), %cl
movb %cl, 0xa(%rax)
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x3b65
jmp 0x3dbf
movl $0x0, -0x98(%rbp)
movl -0x98(%rbp), %eax
movl -0xc(%rbp), %ecx
imull -0x10(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3dbd
leaq -0xa4(%rbp), %rdi
callq 0x42d0
jmp 0x3cae
movsbl -0x11(%rbp), %eax
shll %eax
imull -0x98(%rbp), %eax
movl %eax, -0xa8(%rbp)
movl $0x0, -0xac(%rbp)
movl -0xac(%rbp), %eax
movsbl -0x11(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3d79
movl -0xa8(%rbp), %edx
movl -0xac(%rbp), %eax
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,2), %eax
movslq %eax, %rsi
leaq -0x58(%rbp), %rdi
callq 0x3580
movq %rax, -0x120(%rbp)
jmp 0x3d05
movq -0x120(%rbp), %rax
movzbl (%rax), %eax
shll $0x8, %eax
movl %eax, -0x12c(%rbp)
movl -0xa8(%rbp), %edx
movl -0xac(%rbp), %eax
movl %eax, %ecx
movl %edx, %eax
leal 0x1(%rax,%rcx,2), %eax
movslq %eax, %rsi
leaq -0x58(%rbp), %rdi
callq 0x3580
movq %rax, -0x128(%rbp)
jmp 0x3d41
movl -0x12c(%rbp), %eax
movq -0x128(%rbp), %rcx
movzbl (%rcx), %ecx
addl %ecx, %eax
movw %ax, %cx
movslq -0xac(%rbp), %rax
movw %cx, -0xa4(%rbp,%rax,2)
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x3ccb
movq -0x20(%rbp), %rax
movslq -0x98(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq -0xa4(%rbp), %rcx
movq %rcx, (%rax)
movw -0x9c(%rbp), %cx
movw %cx, 0x8(%rax)
movb -0x9a(%rbp), %cl
movb %cl, 0xa(%rax)
movl -0x98(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x98(%rbp)
jmp 0x3c8b
jmp 0x3dbf
movq -0x20(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x3210
movq -0x138(%rbp), %rax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x34f0
nopl (%rax)