// File: /workspace/github_c_makefile_star2_O2/kopytjuk[P]wasm-image-converter/src/main.cpp
// Function: main
int main ( int argc, char *argv[] )
{
  string input_filename(argv[1]);
  string output_filename(argv[2]);

  int insize = utils::filesize(input_filename);
  cout << insize << endl;

  char *indata = new char[insize];

  utils::print_first_bytes(indata, 10);

  string inext = utils::getExtension(input_filename);
  ImageType intype = resolveImageType(inext);

  utils::read_file_to_char_array(input_filename, indata, insize);


  utils::print_first_bytes(indata, 10);

  // output

  char *outdata;
  int outsize;

  string outext = utils::getExtension(output_filename);
  ImageType outtype = resolveImageType(outext);

  convert_image(&indata, insize, intype, &outdata, outsize, outtype);

  cout << "Output file: " << to_string(outsize) << "B" << endl;

  utils::write_char_array_to_file(output_filename, outdata, outsize);

  cout << "Done!" << endl;

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rsi, %rbx
movq 0x8(%rsi), %rsi
leaq -0x70(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x4e2a
movq 0x10(%rbx), %rsi
leaq -0x50(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0x4e2a
leaq -0x1b0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4640
leaq -0x1b0(%rbp), %rdi
callq 0xc3e5
movl %eax, %ebx
leaq -0x1b0(%rbp), %rdi
callq 0x42a0
movl %ebx, -0x20(%rbp)
movq 0x10470(%rip), %rdi     # 0x14fd8
movl %ebx, %esi
callq 0x4880
movq %rax, %rdi
callq 0x42c0
movslq %ebx, %rdi
callq 0x4040
movq %rax, %r15
movq %rax, -0x30(%rbp)
pushq $0xa
popq %rsi
movq %rax, %rdi
callq 0xc2cf
leaq -0x190(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4640
leaq -0x90(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0xc31d
leaq -0x190(%rbp), %rdi
callq 0x42a0
leaq -0x170(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x4640
leaq -0x170(%rbp), %rdi
callq 0x500c
movl %eax, %r14d
leaq -0x170(%rbp), %rdi
callq 0x42a0
leaq -0x150(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4640
leaq -0x150(%rbp), %rdi
movq %r15, %rsi
movl %ebx, %edx
callq 0xc23c
leaq -0x150(%rbp), %rdi
callq 0x42a0
pushq $0xa
popq %rsi
movq %r15, %rdi
callq 0xc2cf
leaq -0x110(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4640
leaq -0x130(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0xc31d
leaq -0x110(%rbp), %rdi
callq 0x42a0
leaq -0xf0(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x4640
leaq -0xf0(%rbp), %rdi
callq 0x500c
movl %eax, %ebx
leaq -0xf0(%rbp), %rdi
callq 0x42a0
leaq -0x30(%rbp), %rdi
leaq -0x20(%rbp), %rsi
leaq -0x28(%rbp), %rcx
leaq -0x1c(%rbp), %r8
movl %r14d, %edx
movl %ebx, %r9d
callq 0x505d
movq 0x10334(%rip), %rdi     # 0x14fd8
leaq 0x8359(%rip), %rsi      # 0xd004
callq 0x4510
movq %rax, %rbx
movl -0x1c(%rbp), %esi
leaq -0xd0(%rbp), %rdi
callq 0x4e65
leaq -0xd0(%rbp), %rsi
movq %rbx, %rdi
callq 0x44b0
leaq 0x833a(%rip), %rsi      # 0xd012
movq %rax, %rdi
callq 0x4510
movq %rax, %rdi
callq 0x42c0
leaq -0xd0(%rbp), %rdi
callq 0x42a0
leaq -0xb0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4640
movq -0x28(%rbp), %rsi
movl -0x1c(%rbp), %edx
leaq -0xb0(%rbp), %rdi
callq 0xc362
leaq -0xb0(%rbp), %rdi
callq 0x42a0
movq 0x102ae(%rip), %rdi     # 0x14fd8
leaq 0x82e3(%rip), %rsi      # 0xd014
callq 0x4510
movq %rax, %rdi
callq 0x42c0
leaq -0x130(%rbp), %rdi
callq 0x42a0
leaq -0x90(%rbp), %rdi
callq 0x42a0
leaq -0x50(%rbp), %rdi
callq 0x42a0
leaq -0x70(%rbp), %rdi
callq 0x42a0
xorl %eax, %eax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
jmp 0x4de3
jmp 0x4df4
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
jmp 0x4de3
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
jmp 0x4dfe
jmp 0x4dea
movq %rax, %rbx
leaq -0x150(%rbp), %rdi
jmp 0x4dfe
movq %rax, %rbx
leaq -0x170(%rbp), %rdi
jmp 0x4dfe
movq %rax, %rbx
leaq -0x190(%rbp), %rdi
jmp 0x4e0a
jmp 0x4def
movq %rax, %rbx
leaq -0x1b0(%rbp), %rdi
jmp 0x4e0a
movq %rax, %rbx
jmp 0x4e18
jmp 0x4def
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x42a0
jmp 0x4df7
movq %rax, %rbx
jmp 0x4e03
movq %rax, %rbx
jmp 0x4e0f
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
callq 0x42a0
leaq -0x90(%rbp), %rdi
callq 0x42a0
leaq -0x50(%rbp), %rdi
callq 0x42a0
leaq -0x70(%rbp), %rdi
callq 0x42a0
movq %rbx, %rdi
callq 0x48d0
nop