// File: /workspace/github_c_makefile_star2_O3/kopytjuk[P]wasm-image-converter/src/converter.cpp
// Function: image_to_char_array(boost::gil::image<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mp11::mp_list<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t>, boost::mp11::mp_list<std::integral_constant<int, 0>, std::integral_constant<int, 1>, std::integral_constant<int, 2>>>>, false, std::allocator<unsigned char>>&, ImageType, char**, int&)
void image_to_char_array(rgb8_image_t &img, ImageType type, char **arr, int &size){

  stringstream arr_stream(ios_base::in | ios_base::out | ios_base::binary);

  switch (type) {
    case JpegImage:
      write_view(arr_stream, view(img), jpeg_tag() );
      break;
    case PngImage:
      write_view(arr_stream, view(img), png_tag() );
      break;
    default:
      cout << "Cannot write to output image type! Exiting." << endl;
      break;
  }

  arr_stream.seekg(0, ios::end);

  size = arr_stream.tellg();

  cout << "Allocating " << to_string(size/1024) << "KB for the output image."<< endl;

  // allocate memory for file
  *arr = new char [size];

  arr_stream.seekg (0, ios::beg);
  arr_stream.read (*arr, size);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x778, %rsp            # imm = 0x778
movq %rcx, %rbx
movq %rdx, %r14
movl %esi, %r12d
movq %rdi, %r15
leaq -0x1d0(%rbp), %rdi
movl $0x1c, %esi
callq 0x4400
testl %r12d, %r12d
je 0x5817
cmpl $0x1, %r12d
jne 0x5831
leaq -0x48(%rbp), %rdx
movq $0x64, (%rdx)
movb $0x0, 0x8(%rdx)
movl $0x0, 0xa(%rdx)
leaq -0x1c0(%rbp), %rax
leaq -0x38(%rbp), %rsi
movq %rax, (%rsi)
leaq -0x798(%rbp), %rdi
callq 0xc2b2
leaq -0x798(%rbp), %rdi
movq %r15, %rsi
callq 0xc648
leaq -0x798(%rbp), %rdi
callq 0xc27a
jmp 0x5877
leaq -0x1d0(%rbp), %rdi
leaq -0x798(%rbp), %rdx
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x5de7
jmp 0x5877
movq 0xe7a0(%rip), %r15      # 0x13fd8
leaq 0x89e6(%rip), %rsi      # 0xe225
movl $0x2b, %edx
movq %r15, %rdi
callq 0x45a0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x44f0
movsbl %al, %esi
movq 0xe76e(%rip), %rdi      # 0x13fd8
callq 0x4060
movq %rax, %rdi
callq 0x43b0
leaq -0x1d0(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x4620
leaq -0x1d0(%rbp), %rdi
callq 0x4870
movl %eax, (%rbx)
movq 0xe739(%rip), %rdi      # 0x13fd8
leaq 0x89ab(%rip), %rsi      # 0xe251
movl $0xb, %edx
callq 0x45a0
movq %r14, -0x30(%rbp)
movl (%rbx), %r14d
leal 0x3ff(%r14), %eax
testl %r14d, %r14d
cmovnsl %r14d, %eax
sarl $0xa, %eax
movl %eax, %r15d
negl %r15d
cmovsl %eax, %r15d
movl $0x1, %r12d
cmpl $0xa, %r15d
jb 0x5928
movl $0x4, %r12d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r15d, %ecx
cmpl $0x63, %ecx
jbe 0x591f
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x5925
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x5928
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r12d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x58ec
addl $-0x3, %r12d
jmp 0x5928
addl $-0x2, %r12d
jmp 0x5928
decl %r12d
xorl %esi, %esi
cmpl $0xfffffc01, %r14d      # imm = 0xFFFFFC01
setl %sil
addl %r12d, %esi
leaq -0x788(%rbp), %r13
movq %r13, -0x10(%r13)
leaq -0x798(%rbp), %rdi
movl $0x2d, %edx
callq 0x45c0
xorl %edi, %edi
cmpl $0xfffffc01, %r14d      # imm = 0xFFFFFC01
setl %dil
addq -0x798(%rbp), %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x52d7
movq -0x798(%rbp), %rsi
movq -0x790(%rbp), %rdx
movq 0xe650(%rip), %rdi      # 0x13fd8
callq 0x45a0
movq %rax, %r15
leaq 0x88c6(%rip), %rsi      # 0xe25d
movl $0x18, %edx
movq %rax, %rdi
callq 0x45a0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x44f0
movsbl %al, %esi
movq %r15, %rdi
callq 0x4060
movq %rax, %rdi
callq 0x43b0
movq -0x798(%rbp), %rdi
cmpq %r13, %rdi
movq -0x30(%rbp), %r14
je 0x59ea
movq -0x788(%rbp), %rsi
incq %rsi
callq 0x4530
movslq (%rbx), %rdi
callq 0x4040
movq %rax, (%r14)
leaq -0x1d0(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4620
movq (%r14), %rsi
movslq (%rbx), %rdx
leaq -0x1d0(%rbp), %rdi
callq 0x45e0
movq 0xe582(%rip), %rsi      # 0x13fa0
leaq -0x1d0(%rbp), %rdi
callq 0x43e0
leaq -0x150(%rbp), %rdi
callq 0x4210
addq $0x778, %rsp            # imm = 0x778
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x798(%rbp), %rdi
callq 0xc27a
jmp 0x5a84
jmp 0x5a81
jmp 0x5a81
jmp 0x5a81
jmp 0x5a81
movq %rax, %rbx
movq -0x798(%rbp), %rdi
cmpq %r13, %rdi
je 0x5a84
movq -0x788(%rbp), %rsi
incq %rsi
callq 0x4530
jmp 0x5a84
movq %rax, %rbx
movq 0xe515(%rip), %rsi      # 0x13fa0
leaq -0x1d0(%rbp), %rdi
callq 0x43e0
leaq -0x150(%rbp), %rdi
callq 0x4210
movq %rbx, %rdi
callq 0x48b0
nop