// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/func_i2c.cpp
// Function: wh_i2c_get_feature(WdtDevice*, unsigned char*, unsigned int)
int wh_i2c_get_feature(WDT_DEV *pdev, BYTE* buf, UINT32 buf_size)
{
	int retval;
	REQ_DATA* p_req_data = (REQ_DATA*) buf;
	int data_len = 0;
	BYTE cmd;
	BYTE tx_buffer[10] = {0}; 
	BYTE rx_buffer[80] = {0};
	bool retryflag = true;

	if (buf_size > 64)
		buf_size = 64;

	if (!buf || !pdev) {
		wh_printf("%s : pointer is null\n", __func__);
		return 0;
	}

retry:
	data_len = 0;
	cmd = buf[0];
	tx_buffer[data_len++] = pdev->board_info.dev_hid_desc.wCommandRegister; 
	tx_buffer[data_len++] = pdev->board_info.dev_hid_desc.wCommandRegister>>8; 


	if (p_req_data->DD.report_id > 0xF)
	{
		if(retryflag == true)
			tx_buffer[data_len++] = 0x3F;
		else 
			tx_buffer[data_len++] = 0x30;
		tx_buffer[data_len++] = I2C_HID_OPCODE_GET_REPORT;
		tx_buffer[data_len++] = cmd;
	}
	else
	{
		tx_buffer[data_len++] = 0x30 | cmd;
		tx_buffer[data_len++] = I2C_HID_OPCODE_GET_REPORT;
	}

        tx_buffer[data_len++] = pdev->board_info.dev_hid_desc.wDataRegister;
        tx_buffer[data_len++] = pdev->board_info.dev_hid_desc.wDataRegister>>8;


	if (pdev->pparam->options & EXEC_I2C_REDUNDANT) {
		tx_buffer[data_len++] = 0x00;
		tx_buffer[data_len++] = 0x00;
	}

	retval = wh_i2c_xfer(pdev, pdev->board_info.i2c_address, tx_buffer, data_len, rx_buffer, buf_size + 2);
	if (!retval)
		return 0;

	UINT32 	xfer_length = rx_buffer[1];
	xfer_length = (xfer_length << 8) | rx_buffer[0];

	if (buf_size < xfer_length)
		xfer_length = buf_size;

	memcpy(buf, &rx_buffer[2], xfer_length);

	if( (rx_buffer[2] != cmd) && (retryflag == true) &&
		(p_req_data->DD.report_id > 0xF) ) {
		retryflag = false;
		goto  retry;
	}	

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movw $0x0, 0x8(%rsp)
movq $0x0, (%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
cmpl $0x40, %edx
movl $0x40, %r15d
cmovbl %edx, %r15d
testq %rsi, %rsi
sete %al
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x9745
movq %rsi, %rbx
movq %rdi, %r14
leal 0x2(%r15), %ebp
movb $0x1, %r13b
movb (%rbx), %r12b
movzwl 0x1e7(%r14), %eax
movw %ax, (%rsp)
cmpb $0x10, %r12b
jb 0x9685
testb $0x1, %r13b
je 0x969a
movb $0x3f, 0x2(%rsp)
jmp 0x969f
movl %r12d, %eax
orb $0x30, %al
movb %al, 0x2(%rsp)
movb $0x2, 0x3(%rsp)
movl $0x4, %eax
jmp 0x96ae
movb $0x30, 0x2(%rsp)
movb $0x2, 0x3(%rsp)
movb %r12b, 0x4(%rsp)
movl $0x5, %eax
movzwl 0x1e9(%r14), %ecx
movl %eax, %edx
movw %cx, (%rsp,%rdx)
movq %rdx, %rcx
orq $0x2, %rcx
movq 0x280(%r14), %rsi
testb $0x2, 0x9(%rsi)
je 0x96e3
xorl %esi, %esi
movb %sil, (%rsp,%rcx)
addl $0x4, %eax
movq %rsp, %rcx
movb %sil, 0x3(%rdx,%rcx)
movl %eax, %ecx
movzbl 0x1d6(%r14), %esi
movq %r14, %rdi
movq %rsp, %rdx
leaq 0x10(%rsp), %r8
movl %ebp, %r9d
callq 0x9096
testl %eax, %eax
je 0x975e
movzwl 0x10(%rsp), %edx
cmpl %edx, %r15d
cmovbl %r15d, %edx
movq %rbx, %rdi
leaq 0x12(%rsp), %rsi
callq 0x2150
cmpb %r12b, 0x12(%rsp)
je 0x9734
testb $0x1, %r13b
je 0x9734
cmpb $0xf, (%rbx)
jbe 0x9734
movb $0x1, %al
xorl %r13d, %r13d
jmp 0x9736
xorl %eax, %eax
testb %al, %al
jne 0x9663
movl $0x1, %ebx
jmp 0x9760
leaq 0x3276(%rip), %rdi      # 0xc9c2
leaq 0x32da(%rip), %rsi      # 0xca2d
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2506
jmp 0x9760
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq