LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O1/ticky[P]ps2iconsys/src/obj_to_ps2icon.cpp
// Function: IsBMP(char const*)
bool IsBMP(char const* f)
{
	//check for .bmp ending:
	int len = static_cast<int>(strlen(f));
	if( (f[len-3] == 'B' || f[len-3] == 'b') && 
		(f[len-2] == 'M' || f[len-2] == 'm') && 
		(f[len-1] == 'P' || f[len-1] == 'p') ) {
			GhulbusUtil::gbImageType_BMP_T checker;
			std::ifstream tmp(f, std::ios_base::in | std::ios_base::binary);
			return checker.CheckFile(tmp);
	}
	return false;
}

// Assembly:
pushq %rbx
subq $0x220, %rsp            # imm = 0x220
movq %rdi, %rbx
callq 0x20c0
shlq $0x20, %rax
movabsq $-0x300000000, %rcx     # imm = 0xFFFFFFFD00000000
addq %rax, %rcx
sarq $0x20, %rcx
movzbl (%rbx,%rcx), %ecx
orl $0x20, %ecx
cmpl $0x62, %ecx
jne 0x9414
movabsq $-0x200000000, %rcx     # imm = 0xFFFFFFFE00000000
addq %rax, %rcx
sarq $0x20, %rcx
movzbl (%rbx,%rcx), %ecx
orl $0x20, %ecx
cmpl $0x6d, %ecx
jne 0x9414
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rcx, %rax
sarq $0x20, %rax
movzbl (%rbx,%rax), %eax
orl $0x20, %eax
cmpl $0x70, %eax
jne 0x9414
leaq 0x8(%rsp), %rdi
callq 0x7f8e
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
movl $0xc, %edx
callq 0x2370
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x7fd2
movl %eax, %ebx
leaq 0x18(%rsp), %rdi
callq 0x2060
leaq 0x8(%rsp), %rdi
callq 0x7fa0
jmp 0x9416
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x220, %rsp            # imm = 0x220
popq %rbx
retq
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x2060
jmp 0x9433
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x7fa0
movq %rbx, %rdi
callq 0x2350
// File: /workspace/github_cpp_makefile_star2_O1/ticky[P]ps2iconsys/src/obj_to_ps2icon.cpp
// Function: main
int main(int argc, char* argv[])
{
	ParseCommandLine(argc, argv);

	if(!obj_input_file) {
		std::cout << "No input file specified." << std::endl << std::endl;
		PrintHelp(argv[0]);
		exit(1);
	}
	std::cout << "OBJ to PS2Icon Converter  V-1.0\n by Ghulbus Inc.  (http://www.ghulbus-inc.de/)\n" << std::endl;
	if((!list_obj_file) && (!ps2_output_file)) { ps2_output_file = "default.icn"; }

	OBJ_FileLoader* obj_file = LoadOBJFile();

	if(list_obj_file) {
		ListOBJFile(obj_file);
	}

	GhulbusUtil::gbImageLoader* img_loader = NULL;
	if(texture_input_file) {
		img_loader = LoadTexture();
	}
	
	if(ps2_output_file) {
		WriteOutputFile(obj_file, img_loader);
	}

	delete img_loader;
	delete obj_file;

	std::cout << "Success :)" << std::endl;

	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
callq 0x8c73
cmpq $0x0, 0x569e(%rip)      # 0xf260
je 0x9ce2
movq 0x5409(%rip), %rbx      # 0xefd8
leaq 0x11ad(%rip), %rsi      # 0xad83
movl $0x4f, %edx
movq %rbx, %rdi
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
cmpb $0x0, 0x5670(%rip)      # 0xf281
jne 0x9c2b
cmpq $0x0, 0x5655(%rip)      # 0xf270
jne 0x9c2b
leaq 0xd7d(%rip), %rax       # 0xa9a1
movq %rax, 0x5645(%rip)      # 0xf270
callq 0x8eee
movq %rax, %r14
cmpb $0x1, 0x5647(%rip)      # 0xf281
jne 0x9c44
movq %r14, %rdi
callq 0x911b
cmpq $0x0, 0x562c(%rip)      # 0xf278
je 0x9c58
callq 0x9445
movq %rax, %r15
jmp 0x9c5b
xorl %r15d, %r15d
cmpq $0x0, 0x560d(%rip)      # 0xf270
je 0x9c70
movq %r14, %rdi
movq %r15, %rsi
callq 0x96af
testq %r15, %r15
je 0x9c8a
movq %r15, %rdi
callq 0x776a
movl $0x20, %esi
movq %r15, %rdi
callq 0x21d0
movq %r14, %rdi
callq 0x2cd8
movl $0x18, %esi
movq %r14, %rdi
callq 0x21d0
leaq 0x112d(%rip), %rsi      # 0xadd3
movl $0xa, %edx
movq %rbx, %rdi
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
movq 0x52ef(%rip), %rdi      # 0xefd8
leaq 0x107a(%rip), %rsi      # 0xad6a
callq 0x21b0
movq %rax, %rdi
callq 0x20d0
movq %rax, %rdi
callq 0x20d0
movq (%rbx), %rdi
callq 0x871c
movl $0x1, %edi
callq 0x2210
// File: /workspace/github_cpp_makefile_star2_O1/jflemer[P]boost-chat-server/chat_client.cpp
// Function: chat_client<boost::asio::ip::tcp>::handle_connect(boost::system::error_code const&)
void handle_connect(const boost::system::error_code& error)
  {
    if (!error)
    {
      this->async_receive(&read_msg_,
          boost::bind(&chat_client::handle_read,
              this, boost::asio::placeholders::error));
    }
  }

// Assembly:
cmpb $0x0, 0x4(%rsi)
jne 0xd739
subq $0x78, %rsp
leaq 0x58(%rdi), %rcx
leaq 0x8(%rdi), %rdx
leaq 0x31d3(%rip), %rsi      # 0x108a0
leaq 0x18(%rsp), %rax
movq %rsi, 0x38(%rax)
xorl %r8d, %r8d
movq %r8, 0x40(%rax)
movq %rdi, 0x48(%rax)
movq %rdx, (%rax)
movq %rcx, 0x8(%rax)
movq $0x4, 0x10(%rax)
movq %r8, 0x18(%rax)
movl %r8d, 0x20(%rax)
leaq 0x3283(%rip), %rdx      # 0x10982
movq %rdx, 0x28(%rax)
movq %r8, 0x30(%rax)
movq %rcx, 0x50(%rax)
movq %rdi, 0x58(%rax)
leaq 0x8(%rsp), %rsi
movl %r8d, (%rsi)
movb $0x0, 0x4(%rsi)
leaq 0xf6ee(%rip), %rcx      # 0x1ce10
movq %rcx, 0x8(%rsi)
movq %rax, %rdi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x10a46
addq $0x78, %rsp
retq
// File: /workspace/github_cpp_makefile_star2_O1/jflemer[P]boost-chat-server/chat_client.cpp
// Function: chat_client<boost::asio::ip::tcp>::handle_read(boost::system::error_code const&)
void handle_read(const boost::system::error_code& error)
  {
    if (!error)
    {
      std::cout << ">> ";
      std::cout.write(read_msg_.body(), read_msg_.body_length());
      std::cout << "\n";
      this->async_receive(&read_msg_,
          boost::bind(&chat_client::handle_read,
              this, boost::asio::placeholders::error));
    }
    else
    {
      do_close();
    }
  }

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x70, %rsp
movq %rdi, %rbx
cmpb $0x0, 0x4(%rsi)
je 0x108c7
addq $0x8, %rbx
movq %rbx, %rdi
addq $0x70, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x11c8e
movq 0xd6ea(%rip), %r14      # 0x1dfb8
leaq 0x3d8b(%rip), %rsi      # 0x14660
movl $0x3, %edx
movq %r14, %rdi
callq 0x6380
leaq 0x58(%rbx), %r15
leaq 0x5c(%rbx), %rsi
movq 0x260(%rbx), %rdx
movq %r14, %rdi
callq 0x6410
leaq 0x379c(%rip), %rsi      # 0x1409c
movl $0x1, %edx
movq %r14, %rdi
callq 0x6380
leaq 0x8(%rbx), %rax
leaq -0x78(%rip), %rcx       # 0x108a0
leaq 0x10(%rsp), %rdi
movq %rcx, 0x38(%rdi)
xorl %ecx, %ecx
movq %rcx, 0x40(%rdi)
movq %rbx, 0x48(%rdi)
movq %rax, (%rdi)
movq %r15, 0x8(%rdi)
movq $0x4, 0x10(%rdi)
movq %rcx, 0x18(%rdi)
movl %ecx, 0x20(%rdi)
leaq 0x3a(%rip), %rax        # 0x10982
movq %rax, 0x28(%rdi)
movq %rcx, 0x30(%rdi)
movq %r15, 0x50(%rdi)
movq %rbx, 0x58(%rdi)
movq %rsp, %rsi
movl %ecx, (%rsi)
movb $0x0, 0x4(%rsi)
leaq 0xc4a8(%rip), %rax      # 0x1ce10
movq %rax, 0x8(%rsi)
xorl %edx, %edx
movl $0x1, %ecx
callq 0x10a46
addq $0x70, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O1/jflemer[P]boost-chat-server/./stream_msg_client.hpp
// Function: void stream_msg_client<chat_message, boost::asio::ip::tcp>::handle_read_header<boost::_bi::bind_t<void, boost::_mfi::mf1<void, chat_client<boost::asio::ip::tcp>, boost::system::error_code const&>, boost::_bi::list2<boost::_bi::value<chat_client<boost::asio::ip::tcp>*>, boost::arg<1> (*)()>>>(chat_message*, boost::_bi::bind_t<void, boost::_mfi::mf1<void, chat_client<boost::asio::ip::tcp>, boost::system::error_code const&>, boost::_bi::list2<boost::_bi::value<chat_client<boost::asio::ip::tcp>*>, boost::arg<1> (*)()>>, boost::system::error_code const&, unsigned long)
void handle_read_header(Message * msg, ReadHandler handler, const boost::system::error_code& error, std::size_t bytes_transferred)
  {
    if (!error && msg->decode_header())
    {
      boost::asio::async_read(socket_,
          boost::asio::buffer(msg->body(), msg->body_length()),
          handler);
    }
    else
    {
      handler(error);
    }
  }

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %rbx
leaq 0x80(%rsp), %r12
cmpb $0x0, 0x4(%rdx)
jne 0x10a1c
movq %rsi, %r14
movq %rdi, %r15
movq %rsi, %rdi
callq 0x11556
testb %al, %al
je 0x10a1c
addq $0x8, %r15
movq 0x208(%r14), %rax
addq $0x4, %r14
movq 0x10(%r12), %rcx
leaq 0x18(%rsp), %rdi
movq %rcx, 0x38(%rdi)
movups (%r12), %xmm0
movups %xmm0, 0x28(%rdi)
movq %r15, (%rdi)
movq %r14, 0x8(%rdi)
movq %rax, 0x10(%rdi)
movq $0x0, 0x18(%rdi)
xorl %eax, %eax
movl %eax, 0x20(%rdi)
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movb $0x0, 0x4(%rsi)
leaq 0xc410(%rip), %rax      # 0x1ce10
movq %rax, 0x8(%rsi)
xorl %edx, %edx
movl $0x1, %ecx
callq 0x115a6
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq (%r12), %rax
movq 0x10(%r12), %rdi
addq 0x8(%r12), %rdi
testb $0x1, %al
je 0x10a36
movq (%rdi), %rcx
movq -0x1(%rcx,%rax), %rax
movq %rbx, %rsi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmpq *%rax
// File: /workspace/github_cpp_makefile_star2_O1/jflemer[P]boost-chat-server/./chat_message.hpp
// Function: chat_message::decode_header()
bool decode_header()
  {
    using namespace std; // For strncat and atoi.
    char header[header_length + 1] = "";
    strncat(header, data_, header_length);
    body_length_ = atoi(header);
    if (body_length_ > max_body_length)
    {
      body_length_ = 0;
      return false;
    }
    return true;
  }

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
xorl %ebp, %ebp
leaq 0x8(%rsp), %r14
movl %ebp, (%r14)
movb $0x0, 0x4(%r14)
movl $0x4, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x61f0
movq %r14, %rdi
callq 0x6500
cmpl $0x201, %eax            # imm = 0x201
cmovbl %eax, %ebp
setb %al
movslq %ebp, %rcx
movq %rcx, 0x208(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/jflemer[P]boost-chat-server/chat_client.cpp
// Function: chat_client<boost::asio::ip::tcp>::do_write(chat_message)
void do_write(chat_message msg)
  {
    bool write_in_progress = !write_msgs_.empty();
    write_msgs_.push_back(msg);
    if (!write_in_progress)
    {
      boost::asio::async_write(this->socket_,
          boost::asio::buffer(write_msgs_.front().data(),
            write_msgs_.front().length()),
          boost::bind(&chat_client::handle_write, this,
            boost::asio::placeholders::error));
    }
  }

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x50, %rsp
movq %rdi, %rbx
leaq 0x70(%rsp), %rsi
movq 0x278(%rdi), %r15
movq 0x298(%rdi), %r14
movq $-0x210, %rax           # imm = 0xFDF0
addq 0x2a8(%rdi), %rax
cmpq %rax, %r14
je 0x12408
movl $0x210, %edx            # imm = 0x210
movq %r14, %rdi
callq 0x6270
addq $0x210, 0x298(%rbx) # imm = 0x210
jmp 0x12414
leaq 0x268(%rbx), %rdi
callq 0x126f0
cmpq %r15, %r14
jne 0x1247b
leaq 0x8(%rbx), %rax
movq 0x278(%rbx), %rcx
movq 0x208(%rcx), %rdx
addq $0x4, %rdx
leaq 0x10(%rsp), %rdi
movq %rax, (%rdi)
movq %rcx, 0x8(%rdi)
movq %rdx, 0x10(%rdi)
xorl %eax, %eax
movq %rax, 0x18(%rdi)
movl %eax, 0x20(%rdi)
leaq 0x205(%rip), %rcx       # 0x12654
movq %rcx, 0x28(%rdi)
movq %rax, 0x30(%rdi)
movq %rbx, 0x38(%rdi)
movq %rsp, %rsi
movl %eax, (%rsi)
movb $0x0, 0x4(%rsi)
leaq 0xa9a5(%rip), %rax      # 0x1ce10
movq %rax, 0x8(%rsi)
xorl %edx, %edx
movl $0x1, %ecx
callq 0x1291a
addq $0x50, %rsp
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/jflemer[P]boost-chat-server/chat_client.cpp
// Function: chat_client<boost::asio::ip::tcp>::handle_write(boost::system::error_code const&)
void handle_write(const boost::system::error_code& error)
  {
    if (!error)
    {
      write_msgs_.pop_front();
      if (!write_msgs_.empty())
      {
        boost::asio::async_write(this->socket_,
            boost::asio::buffer(write_msgs_.front().data(),
              write_msgs_.front().length()),
            boost::bind(&chat_client::handle_write, this,
              boost::asio::placeholders::error));
      }
    }
    else
    {
      do_close();
    }
  }

// Assembly:
pushq %rbx
subq $0x50, %rsp
movq %rdi, %rbx
cmpb $0x0, 0x4(%rsi)
je 0x12673
addq $0x8, %rbx
movq %rbx, %rdi
addq $0x50, %rsp
popq %rbx
jmp 0x11c8e
leaq 0x268(%rbx), %rdi
callq 0x13128
movq 0x278(%rbx), %rax
cmpq %rax, 0x298(%rbx)
je 0x126ea
leaq 0x8(%rbx), %rcx
movq 0x208(%rax), %rdx
addq $0x4, %rdx
leaq 0x10(%rsp), %rdi
movq %rcx, (%rdi)
movq %rax, 0x8(%rdi)
movq %rdx, 0x10(%rdi)
xorl %eax, %eax
movq %rax, 0x18(%rdi)
movl %eax, 0x20(%rdi)
leaq -0x6a(%rip), %rcx       # 0x12654
movq %rcx, 0x28(%rdi)
movq %rax, 0x30(%rdi)
movq %rbx, 0x38(%rdi)
movq %rsp, %rsi
movl %eax, (%rsi)
movb $0x0, 0x4(%rsi)
leaq 0xa736(%rip), %rax      # 0x1ce10
movq %rax, 0x8(%rsi)
xorl %edx, %edx
movl $0x1, %ecx
callq 0x1291a
addq $0x50, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/ef-gy[P]libefgy/src/test-case/transformation.cpp
// Function: testAffineConstruction(std::ostream&)
bool testAffineConstruction(std::ostream &log) {
  linear<double, 3> phi;

  for (int i = 0; i < 3; i++) {
    for (int k = 0; k < 3; k++) {
      phi.matrix[i][k] = i * k;
    }
  }

  affine<double, 3> psi(phi);

  bool allCorrect = true;

  // check if matrix entries of linear map are in place
  for (int i = 0; i < 3; i++) {
    for (int k = 0; k < 3; k++) {
      allCorrect &= (psi.matrix[i][k] == i * k);
    }
  }

  // check for zeroes in the last row and column
  for (int i = 0; i < 3; i++) {
    allCorrect &= (psi.matrix[i][3] == 0);
    allCorrect &= (psi.matrix[3][i] == 0);
  }

  allCorrect &= (psi.matrix[3][3] == 1);

  if (!allCorrect) {
    log << "An error occurred in constructing an affine transformation";
    log << " from a linear map.\n";

    return false;
  } else {
    return true;
  }
}

// Assembly:
pushq %rbp
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
leaq 0x80(%rsp), %rax
xorl %ecx, %ecx
movsd 0xf2e9(%rip), %xmm0     # 0x14008
xorl %edx, %edx
movapd %xmm0, %xmm1
cmpq %rdx, %rcx
je 0x4d2e
xorpd %xmm1, %xmm1
movsd %xmm1, (%rax,%rdx,8)
incq %rdx
cmpq $0x3, %rdx
jne 0x4d21
incq %rcx
addq $0x18, %rax
cmpq $0x3, %rcx
jne 0x4d1f
leaq 0x80(%rsp), %rax
xorl %ecx, %ecx
xorl %edx, %edx
xorl %esi, %esi
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd %xmm0, (%rax,%rsi,8)
incq %rsi
addl %ecx, %edx
cmpq $0x3, %rsi
jne 0x4d57
incq %rcx
addq $0x18, %rax
cmpq $0x3, %rcx
jne 0x4d53
leaq 0x80(%rsp), %rax
xorl %ecx, %ecx
movq 0x10(%rax), %rdx
movq %rdx, 0x10(%rsp,%rcx)
movupd (%rax), %xmm0
movupd %xmm0, (%rsp,%rcx)
addq $0x18, %rax
addq $0x20, %rcx
cmpq $0x60, %rcx
jne 0x4d85
xorpd %xmm0, %xmm0
movupd %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
movl $0x18, %eax
movq $0x0, (%rsp,%rax)
addq $0x20, %rax
cmpq $0x78, %rax
jne 0x4dbd
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rsp, %rax
movq %rcx, 0x78(%rax)
movb $0x1, %bpl
xorl %ecx, %ecx
xorl %edx, %edx
xorl %esi, %esi
xorl %edi, %edi
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
ucomisd (%rax,%rdi,8), %xmm0
setnp %r8b
sete %r9b
andb %r8b, %r9b
andb %r9b, %bpl
incq %rdi
addl %ecx, %esi
cmpq $0x3, %rdi
jne 0x4deb
incq %rdx
incl %ecx
addq $0x20, %rax
cmpq $0x3, %rdx
jne 0x4de7
movq $-0x18, %rax
xorpd %xmm0, %xmm0
movsd 0x78(%rsp,%rax), %xmm1
cmpeqpd %xmm0, %xmm1
movsd 0x78(%rsp,%rax,4), %xmm2
cmpeqpd %xmm0, %xmm2
andpd %xmm1, %xmm2
movd %xmm2, %ecx
andb %cl, %bpl
addq $0x8, %rax
jne 0x4e2a
movsd 0x78(%rsp), %xmm0
ucomisd 0xf1a9(%rip), %xmm0     # 0x14008
setnp %al
sete %cl
andb %al, %cl
andb %cl, %bpl
jne 0x4e94
leaq 0xf375(%rip), %rsi      # 0x141e8
movl $0x3a, %edx
movq %rbx, %rdi
callq 0x42a0
leaq 0xf39c(%rip), %rsi      # 0x14223
movl $0x14, %edx
movq %rbx, %rdi
callq 0x42a0
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/ef-gy[P]libefgy/include/ef.gy/matrix.h
// Function: std::ostream& efgy::math::operator<<<double, 3ul, 3ul, char>(std::basic_ostream<char, std::char_traits<char>>&, efgy::math::matrix<double, 3ul, 3ul> const&)
std::ostream &operator<<(std::basic_ostream<C> &stream,
                         const matrix<Q, n, m> &matrix) {
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < m; k++) {
      stream << matrix[i][k] << "\t";
    }
    stream << "\n";
  }
  return stream;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
xorl %r13d, %r13d
leaq 0xf94f(%rip), %r15      # 0x14bde
leaq 0xeeea(%rip), %r12      # 0x14180
xorl %ebp, %ebp
movsd (%r14,%rbp,8), %xmm0
movq %rbx, %rdi
callq 0x4360
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x42a0
incq %rbp
cmpq $0x3, %rbp
jne 0x5298
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x42a0
incq %r13
addq $0x18, %r14
cmpq $0x3, %r13
jne 0x5296
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/wdt_ct.cpp
// Function: print_help(char const*)
void print_help(const char *prog_name)
{
	print_version();
	
	printf("\nUsage: %s [OPTIONS] [FW_FILE|SUB-ARGU]\n", prog_name);
	printf("\t-h, --help\tPrint this message\n");
	printf("\t-d, --device\ti2c device file associated with the device\n");	
	printf("\t-u, --update\tUpdate firmware with verification\n");
	printf("\t-f, --no_force\tNot to force updating firmware\n");
	printf("\t-b, --no_bind\tNot to rebind driver after firmware updated\n");	
	printf("\t-r, --no_rpara\tNo need to update the recovery parameter\n");
	printf("\t-s, --info\tPrint the info associated with the devcie\n");
	printf("\t-w, --wif-info\tPrint the info associated with wif image file.\n");
	printf("\t-v, --fw-ver\tRead the fw version from the device\n");	
	printf("\t-c, --cfg-ver\tRead the cfg version from the device\n");		
	printf("\t-i, --hw-id\tRead the hardware id from the device\n");			
	printf("\t-x, --ext-info\tShow more information\n");
	printf("\t-k, --block\tUpdate fw by block\n");
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
leaq 0xa111(%rip), %rdi      # 0xc554
leaq 0x8c16(%rip), %rsi      # 0xb060
leaq 0x8c24(%rip), %rdx      # 0xb075
xorl %eax, %eax
callq 0x2050
leaq 0x8c1e(%rip), %rdi      # 0xb07d
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2050
leaq 0x8cb5(%rip), %rdi      # 0xb125
callq 0x2270
leaq 0x8cc8(%rip), %rdi      # 0xb144
callq 0x2270
leaq 0x8cf5(%rip), %rdi      # 0xb17d
callq 0x2270
leaq 0x8d19(%rip), %rdi      # 0xb1ad
callq 0x2270
leaq 0x8d3c(%rip), %rdi      # 0xb1dc
callq 0x2270
leaq 0x8d6b(%rip), %rdi      # 0xb217
callq 0x2270
leaq 0x8d98(%rip), %rdi      # 0xb250
callq 0x2270
leaq 0x8dc2(%rip), %rdi      # 0xb286
callq 0x2270
leaq 0x8df5(%rip), %rdi      # 0xb2c5
callq 0x2270
leaq 0x8e1b(%rip), %rdi      # 0xb2f7
callq 0x2270
leaq 0x8e43(%rip), %rdi      # 0xb32b
callq 0x2270
leaq 0x8e69(%rip), %rdi      # 0xb35d
callq 0x2270
leaq 0x8e83(%rip), %rdi      # 0xb383
popq %rbx
jmp 0x2270
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_exec_report_type_write(WdtDevice*, unsigned char, unsigned char*, int)
int wh_w8755_dev_exec_report_type_write(WDT_DEV* pdev, BYTE type, BYTE *pbuf, int size)
{
	W8755_WRITE_DATA write_data;

	if (!pdev || !pbuf)
		return 0;

	memset(&write_data, 0, sizeof(write_data));

	write_data.DD.rpt_id = W8755_RPTID_WRITE_DATA;
	write_data.DD.type = type;
	write_data.DD.size = size;

	memcpy(&write_data.DD.data[0], pbuf, size);

	if (g_func_dev_basic.p_wh_set_feature)
		return g_func_dev_basic.p_wh_set_feature(pdev, write_data.buffer, 4 + write_data.DD.size);		

	return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x40, %rsp
movl %ecx, %r14d
testq %rdi, %rdi
sete %al
testq %rdx, %rdx
sete %cl
xorl %ebp, %ebp
orb %al, %cl
jne 0x2a0e
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq 0x4(%rsp), %rdi
movaps %xmm0, -0x4(%rdi)
movaps %xmm0, 0x2c(%rdi)
movaps %xmm0, 0x1c(%rdi)
movaps %xmm0, 0xc(%rdi)
movb $0x8, -0x4(%rdi)
movb %sil, -0x3(%rdi)
movw %r14w, -0x2(%rdi)
movslq %r14d, %rax
movq %rdx, %rsi
movq %rax, %rdx
callq 0x2150
cmpq $0x0, 0xe995(%rip)      # 0x11388
je 0x2a0e
cmpl $0x2, (%rbx)
jne 0x2a0e
movzwl %r14w, %edx
addl $0x4, %edx
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x9a74
movl %eax, %ebp
movl %ebp, %eax
addq $0x40, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_exec_set_report_read(WdtDevice*, unsigned char, unsigned char*, int)
int wh_w8755_dev_exec_set_report_read(WDT_DEV* pdev, BYTE type, BYTE *pbuf, int size)
{
	W8755_WRITE_DATA write_data;

	if (!pdev || !pbuf || !g_func_dev_basic.p_wh_set_feature)
		return 0;

	write_data.DD.rpt_id = W8755_RPTID_REQ_READ;	
	write_data.DD.type = type;
	write_data.DD.size = size;
	
	return g_func_dev_basic.p_wh_set_feature(pdev, write_data.buffer, 4);	
}

// Assembly:
xorl %eax, %eax
testq %rdi, %rdi
je 0x2a5a
testq %rdx, %rdx
je 0x2a5a
cmpq $0x0, 0xe95b(%rip)      # 0x11388
je 0x2a5a
subq $0x48, %rsp
movb $0x6, 0x8(%rsp)
movb %sil, 0x9(%rsp)
movw %cx, 0xa(%rsp)
cmpl $0x2, (%rdi)
jne 0x2a56
leaq 0x8(%rsp), %rsi
movl $0x4, %edx
callq 0x9a74
addq $0x48, %rsp
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_exec_get_report_read(WdtDevice*, unsigned char, unsigned char*, int)
int wh_w8755_dev_exec_get_report_read(WDT_DEV* pdev, BYTE type, BYTE *pbuf, int size)
{
	W8755_READ_DATA read_data;
	int retval;
	UINT32 read_checksum, calc_checksum;
	
	if (!pdev || !pbuf || !g_func_dev_basic.p_wh_get_feature)
		return 0;

	memset(&read_data.buffer[0], 0xff, 4);
	memset(&read_data.buffer[4], 0, 60);
			
	read_data.DD.rpt_id = W8755_RPTID_READ_DATA;
	read_data.DD.type = type;
	retval = g_func_dev_basic.p_wh_get_feature(pdev, read_data.buffer, 64);
	if (!retval)
		return 0;

	if (read_data.DD.rpt_id != W8755_RPTID_READ_DATA) {
		wh_printf("%s: wrong rpt_id\n", __func__);
		return 0;
	}
		
	read_checksum = read_data.DD.checksum;
	calc_checksum = 0;
	for (int i=0; i<60; i++)
		calc_checksum += read_data.DD.data[i];
		
	if (read_checksum != calc_checksum) {
		wh_printf("%s: wrong chksum\n", __func__);
		return 0;
	}
	
	memcpy(pbuf, read_data.DD.data, size);
	return 1;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x40, %rsp
xorl %r14d, %r14d
testq %rdi, %rdi
je 0x2b25
movq %rdx, %rbx
testq %rdx, %rdx
je 0x2b25
cmpq $0x0, 0xe90d(%rip)      # 0x11390
je 0x2b25
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rsp)
movups %xmm0, 0x14(%rsp)
movups %xmm0, 0x24(%rsp)
movups %xmm0, 0x30(%rsp)
movb $0x7, (%rsp)
movb %sil, 0x1(%rsp)
cmpl $0x2, (%rdi)
jne 0x2b25
movl %ecx, %ebp
movq %rsp, %rsi
movl $0x40, %edx
callq 0x95fc
testl %eax, %eax
je 0x2b25
cmpb $0x7, (%rsp)
jne 0x2b04
leaq 0x4(%rsp), %rsi
movzwl -0x2(%rsi), %eax
xorl %ecx, %ecx
movl $0x4, %edx
movzbl (%rsp,%rdx), %edi
addl %edi, %ecx
incq %rdx
cmpq $0x40, %rdx
jne 0x2ade
cmpl %eax, %ecx
jne 0x2b0d
movslq %ebp, %rdx
movq %rbx, %rdi
callq 0x2150
movl $0x1, %r14d
jmp 0x2b25
leaq 0x8951(%rip), %rdi      # 0xb45c
jmp 0x2b14
leaq 0x897c(%rip), %rdi      # 0xb490
leaq 0x8953(%rip), %rsi      # 0xb46e
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x2506
movl %r14d, %eax
addq $0x40, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_exec_report_type_read(WdtDevice*, unsigned char, unsigned char*, int, int)
int wh_w8755_dev_exec_report_type_read(WDT_DEV* pdev, BYTE type, BYTE *pbuf, int size, int offset)
{
	int retval;
	int i_size;

	if (offset & TYPE_READ_OFFSET_SET)
		i_size = offset & 0xFF;
	else
		i_size = size;

	retval = wh_w8755_dev_exec_set_report_read(pdev, type, pbuf, i_size);
	if (!retval)
		return 0;

	return wh_w8755_dev_exec_get_report_read(pdev, type, pbuf, size);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %ecx, %ebx
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
btl $0x10, %r8d
movzbl %r8b, %ecx
cmovael %ebx, %ecx
callq 0x2a19
testl %eax, %eax
je 0x2b72
movzbl %bpl, %esi
movq %r15, %rdi
movq %r14, %rdx
movl %ebx, %ecx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2a5b
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_flash_write_data_page(WdtDevice*, unsigned char*, unsigned int, int)
int wh_w8755_dev_flash_write_data_page(WDT_DEV* pdev, BYTE* data, UINT32 address, int length)
{
	int	addr_start, data_len, packet_size;
	BYTE*	psource_data = 0;
	int	count = 0;
	int	retval = 1;

	if (!data)
		return 0;

	/* address and length should be align to 4 */
	if ((address & 0x3) != 0 || (length & 0x3) != 0)
		return 0;

	/* to make sure the data not exceed a sector */
	if ((address >> 8) != ((address + length - 1) >> 8))		
		return 0;

	data_len = length;
	addr_start = address;
	psource_data = data;

	packet_size = W8755_PACKET_SIZE;
	
	/* set the address to the device first */
	retval = wh_w8755_dev_exec_report_type_write(pdev, W8755_ISP_SET_FLASH_ADDRESS,
						     (BYTE *) &addr_start, 4);
	if (!retval)
		return 0;

	/* since the address is incremental, the following step just keep writting the flash data */
	while(data_len)	{		
		if (data_len < W8755_PACKET_SIZE)
			packet_size = data_len;

		if (!wh_w8755_dev_exec_report_type_write(pdev, W8755_ISP_SET_FLASH,
							 psource_data, packet_size)) {
			printf("can't set flash: 0x%x\n", addr_start);
			retval = 0;
			break;			
		}

		data_len = data_len - packet_size;
		psource_data = psource_data + packet_size;
		addr_start = addr_start + packet_size;


		wh_udelay(FLASH_PAGE_WRITE_DELAY_US);
		count++;
	}

	return retval; 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
xorl %ebp, %ebp
testq %rsi, %rsi
je 0x2c77
movl %ecx, %ebx
movl %ecx, %eax
orl %edx, %eax
testb $0x3, %al
jne 0x2c77
leal (%rdx,%rbx), %eax
decl %eax
xorl %edx, %eax
cmpl $0xff, %eax
ja 0x2c77
movq %rsi, %r14
movq %rdi, %r15
leaq 0xc(%rsp), %rax
movl %edx, (%rax)
movl $0x87, %esi
movq %rax, %rdx
movl $0x4, %ecx
callq 0x2998
testl %eax, %eax
je 0x2c77
movl %eax, %r12d
testl %ebx, %ebx
je 0x2c5e
movl $0x3c, %ebp
cmpl $0x3c, %ebx
cmovll %ebx, %ebp
movq %r15, %rdi
movl $0x83, %esi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x2998
testl %eax, %eax
je 0x2c63
movslq %ebp, %rax
addq %rax, %r14
addl %ebp, 0xc(%rsp)
movl $0x64, %edi
callq 0x25a7
subl %ebp, %ebx
jne 0x2c2a
movl %r12d, %ebp
jmp 0x2c77
movl 0xc(%rsp), %esi
leaq 0x8834(%rip), %rdi      # 0xb4a2
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2050
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_flash_write_data(WdtDevice*, unsigned char*, unsigned int, int)
int wh_w8755_dev_flash_write_data(WDT_DEV* pdev, BYTE* pdata, UINT32 start_addr, int size)
{
	int retval = 0;
	unsigned int	write_base;
	unsigned int	write_size;

	write_base = 0x100;

	if (start_addr & 0xFF) {
		unsigned int 	size_partial;
		size_partial = write_base - (start_addr & 0xFF);
		
		WRITE_FLASH_PAGE(size_partial);			
	}

	while (size) {
		if ((start_addr & 0xfff) == 0)
			printf("base addr: 0x%x\n", start_addr);
	
		WRITE_FLASH_PAGE(write_base);			
	}

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r12d
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
movl %edx, %eax
andl $0xff, %eax
je 0x2ce5
movl $0x100, %r13d           # imm = 0x100
subl %eax, %r13d
movl %r13d, %eax
subl %r12d, %eax
movl %r12d, %ecx
cmovll %r13d, %ecx
negl %eax
cmpl %r13d, %r12d
movl $0x0, %r12d
cmovgl %eax, %r12d
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x2bc8
testl %eax, %eax
cmovel %eax, %r13d
je 0x2d5c
addl %r13d, %ebx
addq %r13, %r14
movl $0x1, %eax
testl %r12d, %r12d
je 0x2d5c
xorl %r13d, %r13d
movl $0x100, %ebp            # imm = 0x100
testl $0xfff, %ebx            # imm = 0xFFF
jne 0x2d0f
leaq 0x87b3(%rip), %rdi      # 0xb4b9
movl %ebx, %esi
xorl %eax, %eax
callq 0x2050
cmpl %ebp, %r12d
movl $0x100, %ecx            # imm = 0x100
cmovll %r12d, %ecx
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x2bc8
testl %eax, %eax
je 0x2d5a
cmpl $0x101, %r12d           # imm = 0x101
leal -0x100(%r12), %eax
cmovll %r13d, %eax
addq $0x100, %r14            # imm = 0x100
addl $0x100, %ebx            # imm = 0x100
movl %eax, %r12d
testl %eax, %eax
jne 0x2cf7
movl $0x1, %eax
jmp 0x2d5c
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_enable_spi_flash_protection(WdtDevice*, int)
int wh_w8755_dev_enable_spi_flash_protection(WDT_DEV* pdev, int protect)
{
	if (protect) {
		int retval = wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_PROTECTION_ON, 0);
			
		wh_sleep(20);
		return retval;
	}	
	else
	{
		if (wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_PROTECTION_OFF, 0)) {
			wh_sleep(20);

			return 1;
		}
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
testl %esi, %esi
je 0x3098
movl $0x16, %esi
xorl %edx, %edx
callq 0x2d6b
movl %eax, %ebx
jmp 0x30af
xorl %ebp, %ebp
movl $0x17, %esi
xorl %edx, %edx
callq 0x2d6b
movl $0x1, %ebx
testl %eax, %eax
je 0x30bb
movl $0x14, %edi
callq 0x259c
movl %ebx, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_i2c_delay(WdtDevice*, unsigned long)
int wh_w8755_i2c_delay(WDT_DEV* pdev, unsigned long delay)
{
        /* if the fw version is not supported,  just delay the max period and return */
        if (pdev->board_info.dev_info.w8755_dev_info.protocol_version < 0x01000006)
                wh_sleep(delay);
        else {
                BYTE rc = W8755_ISP_RSP_BUSY;
                unsigned long   start_tick = get_current_ms();
                int retval;
                BYTE readByte[8];
                int count = 0;
                unsigned long time_period = 0;
                int delay_slot = 10;

                if (delay < 100)
                        delay_slot = 5;

                if (!pdev || !pdev->dev_handle)
                                return 0;

                while (rc != W8755_ISP_RSP_OK && ((get_current_ms() - start_tick) < (delay + 100))) {

                        /* polling interval => 10ms */
                        wh_sleep(delay_slot);

                        retval = wh_i2c_rx(pdev, 0x2C, readByte, 3);
                        if (!retval)
                                continue;
                        else
                                /* 3 byte format: 0x0, 0x0, status */
                                rc = readByte[2];

                        count ++;
                }

                time_period = (get_current_ms() - start_tick);
                if (time_period > (delay + 50))
                        wh_printf("%s: timeout %d occured!\n", __func__, (int) time_period);

                return time_period;
        }

        return delay;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
cmpl $0x1000005, 0x1f8(%rdi) # imm = 0x1000005
ja 0x30ed
movl %ebx, %edi
callq 0x259c
movl %ebx, %r12d
jmp 0x3180
movq %rdi, %r14
callq 0x25ac
movq %rax, %r15
xorl %eax, %eax
cmpq $0x64, %rbx
setae %cl
xorl %r12d, %r12d
testq %r14, %r14
je 0x3180
cmpq $0x0, 0x50(%r14)
je 0x3180
movb %cl, %al
leal (%rax,%rax,4), %ebp
addl $0x5, %ebp
leaq 0x64(%rbx), %r13
movq %rsp, %r12
callq 0x25ac
subq %r15, %rax
cmpq %r13, %rax
jae 0x3154
movl %ebp, %edi
callq 0x259c
movq %r14, %rdi
movl $0x2c, %esi
movq %r12, %rdx
movl $0x3, %ecx
callq 0x99cc
testl %eax, %eax
je 0x311f
movb 0x2(%rsp), %al
negb %al
jno 0x311f
callq 0x25ac
movq %rax, %r12
subq %r15, %r12
addq $0x32, %rbx
cmpq %rbx, %r12
jbe 0x3180
leaq 0x85b3(%rip), %rdi      # 0xb722
leaq 0x85c5(%rip), %rsi      # 0xb73b
movl %r12d, %edx
xorl %eax, %eax
callq 0x2506
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_read_flash_status_register(WdtDevice*, unsigned int*)
unsigned int wh_w8755_dev_read_flash_status_register(WDT_DEV* pdev, unsigned int *pdata)
{
	BYTE				buf[64];

	*pdata = 0xff;

 	if (!wh_w8755_dev_exec_report_type_read(pdev, W8755_ISP_GET_FLASH_STATUS, buf, DataPayloadSize, 0)) {
		wh_printf("%s: report type read error\n", __func__);
		return 0;
	}

	*pdata = (unsigned int) buf[0];

	return 1;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
movl $0xff, (%rsi)
movq %rsp, %rdx
xorl %ebx, %ebx
movl $0x64, %esi
movl $0x3c, %ecx
xorl %r8d, %r8d
callq 0x2b31
testl %eax, %eax
je 0x31cb
movzbl (%rsp), %eax
movl %eax, (%r14)
movl $0x1, %ebx
jmp 0x31e0
leaq 0x830a(%rip), %rdi      # 0xb4dc
leaq 0x831f(%rip), %rsi      # 0xb4f8
xorl %eax, %eax
callq 0x2506
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_write_flash_status_register(WdtDevice*, unsigned int)
unsigned int wh_w8755_dev_write_flash_status_register(WDT_DEV* pdev, unsigned int r)
{
	BYTE				data;
	unsigned int		result;
	int					timeout_count = 0;
	
	data = (BYTE) (r & 0xff);

	if (!wh_w8755_dev_exec_report_type_write(pdev, W8755_ISP_SET_FLASH_STATUS, &data, 1)) {
		wh_printf("%s: report type write error\n", __func__);
		return 0;
	}

	/* timeout should be limit to 1 second */
	result = 0xFF;
	while ((result & 0x01) && (timeout_count < 100) ) {
		wh_w8755_dev_read_flash_status_register(pdev, &result);
		wh_printf("count: %d, (%d)\n", timeout_count, result);
		wh_sleep(10);
		timeout_count ++;
	}

	if (timeout_count >= 100)
		wh_printf("%s: error in timeout !\n", __func__);

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0xb(%rsp), %rdx
movb %sil, (%rdx)
movl $0x84, %esi
movl $0x1, %ecx
callq 0x2998
testl %eax, %eax
je 0x3275
leaq 0xc(%rsp), %r14
movl $0xff, (%r14)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq 0x833a(%rip), %r15      # 0xb566
incl %ebp
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3192
movl 0xc(%rsp), %r12d
movq %r15, %rdi
movl %ebp, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2506
movl $0xa, %edi
callq 0x259c
testb $0x1, %r12b
je 0x3262
cmpl $0x63, %ebp
jb 0x322c
movl $0x1, %ebx
cmpl $0x63, %ebp
jb 0x328c
leaq 0x8304(%rip), %rdi      # 0xb577
jmp 0x327e
xorl %ebx, %ebx
leaq 0x82a2(%rip), %rdi      # 0xb520
leaq 0x82b8(%rip), %rsi      # 0xb53d
xorl %eax, %eax
callq 0x2506
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_flash_erase(WdtDevice*, unsigned int, int)
int wh_w8755_dev_flash_erase(WDT_DEV* pdev, unsigned int address, int size)
{
	if (address == 0 && size == FLS_SZ) {
		if (!wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_ERASEALL, 0)) {			
			printf("Flash chip erase fails\n");
			return 0;
		}

		return 1;
	} else {
		if (!IS_ADDR_SECTOR_ALIGNED(address))
			return 0;
		
		while (size > 0)
		{
			if (IS_ADDR_BLK64_ALIGNED(address) && size >= FLS_BLK64_SZ) {
				if (!wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_ERASE64K, address)) {
					printf("Flash 64k block erase fails: 0x%x\n", address);
					break;
				}			
				
				address += FLS_BLK64_SZ;
				size -= FLS_BLK64_SZ;
			} else if (IS_ADDR_BLK64_ALIGNED(address) && size >= FLS_BLK32_SZ) {
				if (!wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_ERASE32K, address)) {
					printf("Flash 32k block erase fails: 0x%x\n", address);
					break;
				}
				
				address += FLS_BLK32_SZ;
				size -= FLS_BLK32_SZ;
			} else	{
				if (!wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_ERASE4K, address)) {
					printf("Flash 4k block erase fails: 0x%x\n", address);
					break;
				}
		
				address += FLS_SEC_SZ;
				size -= FLS_SEC_SZ;
			}
		}
	}
	
	return (size <= 0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r15
movl %edx, %eax
xorl $0x80000, %eax          # imm = 0x80000
orl %esi, %eax
jne 0x32de
movq %r15, %rdi
movl $0x12, %esi
xorl %edx, %edx
callq 0x2d6b
movl $0x1, %r14d
testl %eax, %eax
jne 0x32eb
leaq 0x8492(%rip), %rdi      # 0xb766
callq 0x2270
xorl %r14d, %r14d
jmp 0x32eb
movl %esi, %ebp
xorl %r14d, %r14d
testl $0xfff, %esi            # imm = 0xFFF
je 0x32fd
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %edx, %ebx
movl $0x1, %r14d
testl %edx, %edx
jle 0x32eb
leaq 0x827f(%rip), %r13      # 0xb58f
leaq 0x82be(%rip), %r12      # 0xb5d5
testw %bp, %bp
setne %al
cmpl $0x10000, %ebx          # imm = 0x10000
setb %cl
orb %al, %cl
jne 0x334a
movq %r15, %rdi
movl $0x14, %esi
movl %ebp, %edx
callq 0x2d6b
testl %eax, %eax
je 0x33a5
addl $0x10000, %ebp          # imm = 0x10000
movl $0xffff0000, %eax       # imm = 0xFFFF0000
jmp 0x3398
testw %bp, %bp
setne %al
cmpl $0x8000, %ebx           # imm = 0x8000
setb %cl
movq %r15, %rdi
orb %al, %cl
jne 0x337d
movl $0x15, %esi
movl %ebp, %edx
callq 0x2d6b
testl %eax, %eax
je 0x33aa
orl $0x8000, %ebp           # imm = 0x8000
movl $0xffff8000, %eax       # imm = 0xFFFF8000
jmp 0x3398
movl $0x13, %esi
movl %ebp, %edx
callq 0x2d6b
testl %eax, %eax
je 0x33b1
addl $0x1000, %ebp           # imm = 0x1000
movl $0xfffff000, %eax       # imm = 0xFFFFF000
addl %eax, %ebx
jg 0x3317
jmp 0x32eb
movq %r13, %r12
jmp 0x33b1
leaq 0x8201(%rip), %r12      # 0xb5b2
movq %r12, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x2050
xorl %r14d, %r14d
testl %ebx, %ebx
setle %r14b
jmp 0x32eb
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_flash_get_checksum(WdtDevice*, unsigned int*, unsigned int, int)
int wh_w8755_dev_flash_get_checksum(WDT_DEV* pdev, UINT32* pchecksum, UINT32 address, int size)
{
	BYTE			buf[64];
	unsigned int	checksum;
	int				delay;	

	put_unaligned_le32(address, &buf[0]);
	put_unaligned_le32(size, &buf[4]);
	
	if (!wh_w8755_dev_exec_report_type_write(pdev, W8755_ISP_SET_CHECKSUM_CALC, buf, 8)) {
		printf("%s: report type write error!\n", __func__);
		return 0;
	}

	delay = (size + 1023) / 1024;
	delay = wh_w8755_i2c_delay(pdev, delay * 4);
	wh_printf("chksum delay: %d ms\n", delay);

	if (!wh_w8755_dev_exec_report_type_read(pdev, W8755_ISP_GET_CHECKSUM, buf, DataPayloadSize, 0)) {
		wh_printf("%s: report type read chksum error!\n", __func__);
		return 0;
	}

	checksum = get_unaligned_le16(buf);
	*pchecksum = checksum;

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movl %ecx, %r15d
movq %rsi, %rbx
movq %rdi, %r14
movq %rsp, %r12
movl %edx, %edi
movq %r12, %rsi
callq 0x7032
leaq 0x4(%rsp), %rsi
movl %r15d, %edi
callq 0x7032
movq %r14, %rdi
movl $0x88, %esi
movq %r12, %rdx
movl $0x8, %ecx
callq 0x2998
testl %eax, %eax
je 0x347c
leal 0x3ff(%r15), %eax
addl $0x7fe, %r15d           # imm = 0x7FE
testl %eax, %eax
cmovnsl %eax, %r15d
sarl $0xa, %r15d
shll $0x2, %r15d
movslq %r15d, %rsi
movq %r14, %rdi
callq 0x30c4
leaq 0x81f4(%rip), %rdi      # 0xb635
xorl %ebp, %ebp
movl %eax, %esi
xorl %eax, %eax
callq 0x2506
movq %rsp, %rdx
movq %r14, %rdi
movl $0x65, %esi
movl $0x3c, %ecx
xorl %r8d, %r8d
callq 0x2b31
testl %eax, %eax
je 0x3495
movq %rsp, %rdi
callq 0x7027
movzwl %ax, %eax
movl %eax, (%rbx)
movl $0x1, %ebp
jmp 0x34aa
leaq 0x8174(%rip), %rdi      # 0xb5f7
leaq 0x818b(%rip), %rsi      # 0xb615
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2050
jmp 0x34aa
leaq 0x81ae(%rip), %rdi      # 0xb64a
leaq 0x8172(%rip), %rsi      # 0xb615
xorl %eax, %eax
callq 0x2506
movl %ebp, %eax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_parse_new_dev_info(WdtDevice*, WeidaDeviceInfoNew*)
int wh_w8755_dev_parse_new_dev_info(WDT_DEV* pdev, W8755_DEV_INFO_NEW *pdev_info_new)
{
	BYTE	buffer[32];
	int	retval;

	retval = wh_w8755_dev_get_new_device_info(pdev, buffer, 0, 32);
	if (!retval)
		return 0;
	
	pdev_info_new->protocol_version = get_unaligned_le32(&buffer[0x00]);
	pdev_info_new->firmware_id = get_unaligned_le32(&buffer[0x04]);
	pdev_info_new->status = get_unaligned_le32(&buffer[0x08]);
	pdev_info_new->config_size = get_unaligned_le16(&buffer[0x10]);
	pdev_info_new->parameter_map_sum = get_unaligned_le16(&buffer[0x12]);
	pdev_info_new->firmware_revision = get_unaligned_le16(&buffer[0x14]);
	pdev_info_new->max_points = buffer[0x16];
	pdev_info_new->bytes_per_point = buffer[0x16];
	pdev_info_new->customer_config_id = get_unaligned_le32(&buffer[0x18]);

	pdev_info_new->boot_partition = W8755_BP_DEFAULT;
	if (pdev_info_new->protocol_version >= 0x01010000) {
		if (buffer[0x001E] == 0xB1)
			pdev_info_new->boot_partition = W8755_BP_PRIMARY;
		else if (buffer[0x001E] == 0xB2)
			pdev_info_new->boot_partition = W8755_BP_SECONDARY;
	}	



	return true;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x68, %rsp
movq %rsi, %rbx
leaq 0x20(%rsp), %rdx
movl $0x73, %esi
movl $0x20, %ecx
movl $0x10000, %r8d          # imm = 0x10000
callq 0x2b31
testl %eax, %eax
je 0x359c
movaps 0x20(%rsp), %xmm0
movaps 0x30(%rsp), %xmm1
leaq 0x10(%rsp), %r14
movaps %xmm1, (%r14)
movaps %xmm0, -0x10(%r14)
movq %rsp, %rdi
callq 0x702b
movl %eax, (%rbx)
leaq 0x4(%rsp), %rdi
callq 0x702b
movl %eax, 0x4(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x702b
movl %eax, 0x8(%rbx)
movq %r14, %rdi
callq 0x7027
movzwl %ax, %eax
movl %eax, 0xc(%rbx)
leaq 0x12(%rsp), %rdi
callq 0x7027
movzwl %ax, %eax
movl %eax, 0x10(%rbx)
leaq 0x14(%rsp), %r14
movq %r14, %rdi
callq 0x7027
movzwl %ax, %eax
movl %eax, 0x14(%rbx)
movzbl 0x2(%r14), %eax
movl %eax, 0x18(%rbx)
movl %eax, 0x1c(%rbx)
leaq 0x18(%rsp), %rdi
callq 0x702b
movl %eax, 0x20(%rbx)
movl $0x0, 0x24(%rbx)
movl $0x1, %eax
cmpl $0x1010000, (%rbx)      # imm = 0x1010000
jb 0x35a7
movzbl 0x1e(%rsp), %ecx
cmpl $0xb2, %ecx
je 0x35a0
cmpl $0xb1, %ecx
jne 0x35a7
movl $0x1, 0x24(%rbx)
jmp 0x35a7
xorl %eax, %eax
jmp 0x35a7
movl $0x2, 0x24(%rbx)
addq $0x68, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_verify_chunk_by_read_checksum(WdtDevice*, ChunkInfoEx*)
int wh_w8755_dev_verify_chunk_by_read_checksum(WDT_DEV* pdev, CHUNK_INFO_EX* pChunk)
{
	int retval = 0, result = 1;
	UINT32	bin_checksum;
	UINT32	read_checksum;
	
	retval = wh_w8755_dev_send_commands(pdev, WH_CMD_ALGO_STOP, 0);
	if (!retval)
		return retval;
		
	printf("Calculating checksum...\n");
	
	bin_checksum = misr_for_bytes(0, pChunk->pData, 0, pChunk->chuckInfo.length);

	retval = wh_w8755_dev_flash_get_checksum(pdev, &read_checksum, pChunk->chuckInfo.targetStartAddr, pChunk->chuckInfo.length);
	if (!retval)
		return retval;

	if (bin_checksum != read_checksum) {
		printf("Checksum mismatch!!! Original=0x%x, Flash checksum=0x%x", bin_checksum, read_checksum);
		result = 0;
	}
	
	retval = wh_w8755_dev_send_commands(pdev, WH_CMD_ALGO_START, 0);
	if (!retval)
		return retval;
		
	return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
xorl %ebp, %ebp
movl $0x2, %esi
xorl %edx, %edx
callq 0x2d6b
testl %eax, %eax
je 0x385e
leaq 0x7ff2(%rip), %rdi      # 0xb7e8
callq 0x2270
movq 0x18(%r14), %rsi
movl 0x4(%r14), %ecx
xorl %ebp, %ebp
xorl %edi, %edi
xorl %edx, %edx
callq 0x8966
movl %eax, %r15d
movl (%r14), %edx
movl 0x4(%r14), %ecx
leaq 0x4(%rsp), %rsi
movq %rbx, %rdi
callq 0x33cb
testl %eax, %eax
je 0x385e
movzwl %r15w, %esi
movl 0x4(%rsp), %edx
movl $0x1, %ebp
cmpl %esi, %edx
je 0x384a
leaq 0x7e4d(%rip), %rdi      # 0xb68e
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2050
movq %rbx, %rdi
movl $0x3, %esi
xorl %edx, %edx
callq 0x2d6b
testl %eax, %eax
cmovel %eax, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_program_chunk_verify(WdtDevice*, ChunkInfoEx*, int)
int wh_w8755_dev_program_chunk_verify(WDT_DEV* pdev, CHUNK_INFO_EX* pInputChunk, int option)
{
	int retval = 0;
	int ret = 0;

	CHUNK_INFO_EX	*pChunk = pInputChunk;
	FUNC_PTR_STRUCT_DEV_OPERATION funcs;

	memset(&funcs, 0, sizeof(FUNC_PTR_STRUCT_DEV_OPERATION));	

	retval = wh_w8755_dev_send_commands(pdev, WH_CMD_ALGO_STOP, 0);
	if (!retval)
		return retval;
		
	retval = wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_UNLOCK, 0);
	if (!retval)
		return retval;

	retval = wh_w8755_dev_flash_erase(pdev, pChunk->chuckInfo.targetStartAddr, pChunk->chuckInfo.length);
	if (!retval)
		goto chunk_exit;
		
	printf("Chunk program begin ...\n");
	retval = wh_w8755_dev_flash_write_data(pdev, pChunk->pData, pChunk->chuckInfo.targetStartAddr, pChunk->chuckInfo.length);
	if (!retval)
		goto chunk_exit;
	printf("Chunk program end...\n");

	if (wh_w8755_dev_verify_chunk(pdev, pInputChunk) <= 0) {
		printf("Checksum failed\n");
		goto chunk_exit;
	}
		
chunk_exit:
	ret = wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_LOCK, 0);
	if (!ret)
		return ret;
	
	ret = wh_w8755_dev_send_commands(pdev, WH_CMD_ALGO_START, 0);
	if (!ret)
		return ret;
		
	return retval;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
xorl %ebp, %ebp
movl $0x2, %esi
xorl %edx, %edx
callq 0x2d6b
testl %eax, %eax
je 0x3944
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3081
testl %eax, %eax
je 0x3944
movl (%r14), %esi
movl 0x4(%r14), %edx
movq %rbx, %rdi
callq 0x329b
xorl %ebp, %ebp
movl $0x0, %r12d
testl %eax, %eax
je 0x3919
leaq 0x7f3b(%rip), %rdi      # 0xb800
callq 0x2270
movq 0x18(%r14), %rsi
movl (%r14), %edx
movl 0x4(%r14), %ecx
movq %rbx, %rdi
callq 0x2c86
movl $0x0, %r12d
testl %eax, %eax
je 0x3919
movl %eax, %r15d
leaq 0x7f27(%rip), %rdi      # 0xb818
callq 0x2270
testq %rbx, %rbx
je 0x390a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x37d0
testl %eax, %eax
jne 0x3916
leaq 0x7f1c(%rip), %rdi      # 0xb82d
callq 0x2270
movl %r15d, %r12d
movq %rbx, %rdi
movl $0x10, %esi
xorl %edx, %edx
callq 0x2d6b
testl %eax, %eax
je 0x3944
movq %rbx, %rdi
movl $0x3, %esi
xorl %edx, %edx
callq 0x2d6b
testl %eax, %eax
cmovel %eax, %r12d
movl %r12d, %ebp
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_flash_read_data(WdtDevice*, unsigned char*, unsigned int, int)
int wh_w8755_dev_flash_read_data(WDT_DEV* pdev, BYTE* data, UINT32 address, int length)
{
	int		addr_start, data_len, packet_size;
	BYTE*	 psource_data = 0;
	int		count = 0;
	int		retval = 1;

	if (!pdev || !data)
		return 0;

	// address and length should be align to 4
	if ((address & 0x3) != 0 || (length & 0x3) != 0)
		return 0;

	data_len = length;
	addr_start = address;
	psource_data = data;

	packet_size = W8755_PACKET_SIZE;

	retval = wh_w8755_dev_exec_report_type_write(pdev, W8755_ISP_SET_FLASH_ADDRESS, (BYTE *) &addr_start, 4);
	if (!retval)
		return 0;

	while(data_len)	{
		if (data_len < W8755_PACKET_SIZE)
			packet_size = data_len;

		if (!wh_w8755_dev_exec_report_type_read(pdev, W8755_ISP_GET_FLASH, psource_data, packet_size, 0)) {
			wh_printf("can't get flash: 0x%x\n", addr_start);
			break;
		}

		data_len = data_len - packet_size;
		psource_data = psource_data + packet_size;
		addr_start = addr_start + packet_size;

		wh_sleep(1);
		count++;
	}

	return retval;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %ecx, %ebx
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
xorl %r12d, %r12d
orb %al, %cl
jne 0x3a87
movl %ebx, %eax
orl %edx, %eax
testb $0x3, %al
jne 0x3a87
movq %rsi, %r14
movq %rdi, %r15
leaq 0xc(%rsp), %rax
movl %edx, (%rax)
movl $0x87, %esi
movq %rax, %rdx
movl $0x4, %ecx
callq 0x2998
testl %eax, %eax
je 0x3a87
movl %eax, %ebp
testl %ebx, %ebx
je 0x3a84
movl $0x3c, %r12d
cmpl $0x3c, %ebx
cmovll %ebx, %r12d
movq %r15, %rdi
movl $0x63, %esi
movq %r14, %rdx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x2b31
testl %eax, %eax
je 0x3a72
movslq %r12d, %rax
addq %rax, %r14
addl %r12d, 0xc(%rsp)
movl $0x1, %edi
callq 0x259c
subl %r12d, %ebx
jne 0x3a35
jmp 0x3a84
movl 0xc(%rsp), %esi
leaq 0x7c49(%rip), %rdi      # 0xb6c6
xorl %eax, %eax
callq 0x2506
movl %ebp, %r12d
movl %r12d, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq