// File: lvandeve[P]lodepng/pngdetail.cpp
// Function: loadWithErrorRecovery(Data&, Options const&, bool)
void loadWithErrorRecovery(Data& data, const Options& options, bool show_errors_mode) {
  (void)options;
  unsigned& error = data.error;
  lodepng::State& state = data.state;

  data.loadPixels();

  if(show_errors_mode) {
    if(!error) std::cout << "No errors or warnings" << std::endl;
    return;
  }

  // In case of checksum errors and some other ignorable errors, report it but ignore it and retry
  while(error) {
    // Not showing regular error here, is shown at end of program.
    unsigned error2 = error;
    if(error == 57) {
      showError(data, options);
      if(!show_errors_mode) std::cerr << "Ignoring the error: enabling ignore_crc" << std::endl;
      state.decoder.ignore_crc = 1;
      data.reloadPixels();
    } else if(error == 58) {
      showError(data, options);
      if(!show_errors_mode) std::cerr << "Ignoring the error: enabling ignore_adler32" << std::endl;
      state.decoder.zlibsettings.ignore_adler32 = 1;
      data.reloadPixels();
    } else if(error == 69) {
      showError(data, options);
      if(!show_errors_mode) std::cerr << "Ignoring the error: enabling ignore_critical" << std::endl;
      state.decoder.ignore_critical = 1;
      data.reloadPixels();
    } else if(error == 30 || error == 63) {
      showError(data, options);
      if(!show_errors_mode) std::cerr << "Ignoring the error: enabling ignore_end" << std::endl;
      state.decoder.ignore_end = 1;
      data.reloadPixels();
    } else {
      showError(data, options);
      if(!show_errors_mode) std::cerr << "This error is unrecoverable" << std::endl;
      break;  // other error that we cannot ignore
    }
    if(!show_errors_mode) if(error == 0) std::cerr << "Successfully ignored the error" << std::endl;
    if(error == error2) {
      if(!show_errors_mode) std::cerr << "Failed to ignore the error" << std::endl;
      break; // avoid infinite loop if ignoring did not fix the error code
    }
  }

  if(show_errors_mode) {
    if(!error) std::cout << "The error is recoverable" << std::endl;
    else std::cout << "The error is not recoverable" << std::endl;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
addq $0x2d8, %rax            # imm = 0x2D8
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
addq $0x58, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x326c0
testb $0x1, -0x11(%rbp)
je 0x2bd60
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x2bd5b
movq 0x1b290(%rip), %rdi     # 0x46fd0
leaq 0xe9b9(%rip), %rsi      # 0x3a700
callq 0x2250
movq %rax, %rdi
movq 0x1b26a(%rip), %rsi     # 0x46fc0
callq 0x22a0
jmp 0x2bfda
jmp 0x2bd62
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2bf83
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x39, (%rax)
jne 0x2bdcf
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2bb20
testb $0x1, -0x11(%rbp)
jne 0x2bdb6
movq 0x1b255(%rip), %rdi     # 0x46ff0
leaq 0xe974(%rip), %rsi      # 0x3a716
callq 0x2250
movq %rax, %rdi
movq 0x1b20f(%rip), %rsi     # 0x46fc0
callq 0x22a0
movq -0x28(%rbp), %rax
movl $0x1, 0x28(%rax)
movq -0x8(%rbp), %rdi
callq 0x32700
jmp 0x2bf16
movq -0x20(%rbp), %rax
cmpl $0x3a, (%rax)
jne 0x2be25
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2bb20
testb $0x1, -0x11(%rbp)
jne 0x2be0d
movq 0x1b1fe(%rip), %rdi     # 0x46ff0
leaq 0xe945(%rip), %rsi      # 0x3a73e
callq 0x2250
movq %rax, %rdi
movq 0x1b1b8(%rip), %rsi     # 0x46fc0
callq 0x22a0
movq -0x28(%rbp), %rax
movl $0x1, (%rax)
movq -0x8(%rbp), %rdi
callq 0x32700
jmp 0x2bf14
movq -0x20(%rbp), %rax
cmpl $0x45, (%rax)
jne 0x2be7c
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2bb20
testb $0x1, -0x11(%rbp)
jne 0x2be63
movq 0x1b1a8(%rip), %rdi     # 0x46ff0
leaq 0xe91b(%rip), %rsi      # 0x3a76a
callq 0x2250
movq %rax, %rdi
movq 0x1b162(%rip), %rsi     # 0x46fc0
callq 0x22a0
movq -0x28(%rbp), %rax
movl $0x1, 0x2c(%rax)
movq -0x8(%rbp), %rdi
callq 0x32700
jmp 0x2bf12
movq -0x20(%rbp), %rax
cmpl $0x1e, (%rax)
je 0x2be8e
movq -0x20(%rbp), %rax
cmpl $0x3f, (%rax)
jne 0x2bed9
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2bb20
testb $0x1, -0x11(%rbp)
jne 0x2bec3
movq 0x1b148(%rip), %rdi     # 0x46ff0
leaq 0xe8e8(%rip), %rsi      # 0x3a797
callq 0x2250
movq %rax, %rdi
movq 0x1b102(%rip), %rsi     # 0x46fc0
callq 0x22a0
movq -0x28(%rbp), %rax
movl $0x1, 0x30(%rax)
movq -0x8(%rbp), %rdi
callq 0x32700
jmp 0x2bf10
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2bb20
testb $0x1, -0x11(%rbp)
jne 0x2bf0e
movq 0x1b0fd(%rip), %rdi     # 0x46ff0
leaq 0xe8c5(%rip), %rsi      # 0x3a7bf
callq 0x2250
movq %rax, %rdi
movq 0x1b0b7(%rip), %rsi     # 0x46fc0
callq 0x22a0
jmp 0x2bf83
jmp 0x2bf12
jmp 0x2bf14
jmp 0x2bf16
testb $0x1, -0x11(%rbp)
jne 0x2bf49
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x2bf47
movq 0x1b0c4(%rip), %rdi     # 0x46ff0
leaq 0xe8a8(%rip), %rsi      # 0x3a7db
callq 0x2250
movq %rax, %rdi
movq 0x1b07e(%rip), %rsi     # 0x46fc0
callq 0x22a0
jmp 0x2bf49
movq -0x20(%rbp), %rax
movl (%rax), %eax
cmpl -0x2c(%rbp), %eax
jne 0x2bf7e
testb $0x1, -0x11(%rbp)
jne 0x2bf7c
movq 0x1b08f(%rip), %rdi     # 0x46ff0
leaq 0xe892(%rip), %rsi      # 0x3a7fa
callq 0x2250
movq %rax, %rdi
movq 0x1b049(%rip), %rsi     # 0x46fc0
callq 0x22a0
jmp 0x2bf83
jmp 0x2bd62
testb $0x1, -0x11(%rbp)
je 0x2bfda
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x2bfb6
movq 0x1b037(%rip), %rdi     # 0x46fd0
leaq 0xe875(%rip), %rsi      # 0x3a815
callq 0x2250
movq %rax, %rdi
movq 0x1b011(%rip), %rsi     # 0x46fc0
callq 0x22a0
jmp 0x2bfd8
movq 0x1b013(%rip), %rdi     # 0x46fd0
leaq 0xe86a(%rip), %rsi      # 0x3a82e
callq 0x2250
movq %rax, %rdi
movq 0x1afed(%rip), %rsi     # 0x46fc0
callq 0x22a0
jmp 0x2bfda
addq $0x30, %rsp
popq %rbp
retq