// File: /workspace/github_cpp_makefile_star2_O1/goodix[P]gdix_hid_firmware_update/gt7868q/gt7868q_update.cpp
// Function: GT7868QUpdate::cfg_update()
int GT7868QUpdate::cfg_update()
{
	int retry;
	int ret = -1, i;
	unsigned char temp_buf[65];
	unsigned char *fw_data = NULL;
	unsigned char cfg_ver_after[3];
	unsigned char cfg_ver_before[3];
	unsigned char tmp_cmd_buf[5];
	unsigned char cfg_ver_infile;
	bool findMatchCfg = false;
	unsigned char *cfg = NULL;

	int sub_cfg_num = image->GetConfigSubCfgNum();
	unsigned char sub_cfg_id;
	unsigned int sub_cfg_len;
	unsigned char buf_dis_report_coor[] = {0x33, 0x00, 0x00, 0x00, 0x33};
	unsigned char buf_en_report_coor[] = {0x34, 0x00, 0x00, 0x00, 0x34};
	unsigned int sub_cfg_info_pos = image->GetConfigSubCfgInfoOffset();
	unsigned int cfg_offset = image->GetConfigSubCfgDataOffset();

	if (sub_cfg_num == 0)
		return -5;
	/*dis report coor*/
	gdix_info("disable report coor in cfg update\n");
	retry = 3;
	do {
		ret = dev->Write(CMD_ADDR, buf_dis_report_coor,
						 sizeof(buf_dis_report_coor));
		if (ret < 0) {
			gdix_err("Failed disable report coor\n");
		}
	} while (--retry);

	// before update config,read curr config version
	dev->Read(CFG_START_ADDR, cfg_ver_before, 3);
	gdix_dbg("Before update,cfg version is 0x%02x 0x%02x 0x%02x\n",
			 cfg_ver_before[0], cfg_ver_before[1], cfg_ver_before[2]);

	/* Start load config */
	fw_data = image->GetFirmwareData();
	if (!fw_data) {
		gdix_err("No valid fw data \n");
		ret = -4;
		goto update_err;
	}

	// fw_data[FW_IMAGE_SUB_FWNUM_OFFSET];
	gdix_dbg("load sub config, sub_cfg_num=%d\n", sub_cfg_num);
	for (i = 0; i < sub_cfg_num; i++) {
		sub_cfg_id = fw_data[sub_cfg_info_pos];
		gdix_dbg("load sub config, sub_cfg_id=0x%x\n", sub_cfg_id);

		sub_cfg_len = (fw_data[sub_cfg_info_pos + 1] << 8) |
					  fw_data[sub_cfg_info_pos + 2];

		if (dev->GetSensorID() == sub_cfg_id) {
			findMatchCfg = true;
			cfg = &fw_data[cfg_offset];
			cfg_ver_infile = cfg[0];
			gdix_info("Find a cfg match sensorID:ID=%d,cfg version=%d\n",
					  dev->GetSensorID(), cfg_ver_infile);
			break;
		}
		cfg_offset += sub_cfg_len;
		sub_cfg_info_pos += 3;
	}

	if (findMatchCfg) {
		// wait untill ic is free
		retry = 10;
		do {
			ret = dev->Read(CMD_ADDR, temp_buf, 1);
			if (ret < 0) {
				gdix_err("Failed read cfg cmd, ret = %d\n", ret);
				goto update_err;
			}
			if (temp_buf[0] == 0xff)
				break;
			gdix_info("0x%x value is 0x%x != 0xff, retry\n", CMD_ADDR,
					  temp_buf[0]);
			usleep(10000);
		} while (--retry);
		if (!retry) {
			gdix_err("Reg 0x%x != 0xff\n", CMD_ADDR);
			ret = -2;
			goto update_err;
		}

		// tell ic i want to send cfg
		cmd_init(temp_buf, 0x80, 0x0);
		ret = dev->Write(CMD_ADDR, temp_buf, 5);
		if (ret < 0) {
			gdix_err("Failed write send cfg cmd\n");
			goto update_err;
		}

		// wait ic to comfirm
		usleep(250000);
		retry = GDIX_RETRY_TIMES;
		do {
			ret = dev->Read(CMD_ADDR, temp_buf, 1);
			gdix_dbg("Wait CMD_ADDR == 0x82...\n");
			if (ret < 0) {
				gdix_err("Failed read 0x%x, ret = %d\n", CMD_ADDR, ret);
			}
			if (temp_buf[0] == 0x82)
				break;
			gdix_info("0x%x value is 0x%x != 0x82, retry\n", CMD_ADDR,
					  temp_buf[0]);
			usleep(30000);
		} while (--retry);

		if (!retry) {
			gdix_err("Reg 0x%x != 0x82\n", CMD_ADDR);
			ret = -2;
			goto update_err;
		}
		gdix_dbg("Wait CMD_ADDR == 0x82 success.\n");

		/* Start load config */
		ret = dev->Write(CFG_START_ADDR, &fw_data[cfg_offset], sub_cfg_len);
		if (ret < 0) {
			gdix_err("Failed write cfg to xdata, ret=%d\n", ret);
			goto update_err;
		}
		usleep(100000);

		// tell ic cfg is ready in xdata
		cmd_init(temp_buf, 0x83, 0);
		ret = dev->Write(CMD_ADDR, temp_buf, 5);
		if (ret < 0) {
			gdix_err("Failed write send cfg finish cmd\n");
			goto update_err;
		}

		// check if ic is ok with the cfg
		usleep(80000);
		retry = GDIX_RETRY_TIMES;
		do {
			ret = dev->Read(CMD_ADDR, temp_buf, 5);
			gdix_dbg("Wait CMD_ADDR == 0x7F...\n");
			if (ret < 0) {
				gdix_err("Failed read 0x%x, ret = %d\n", CMD_ADDR, ret);
			} else if (temp_buf[0] == 0x7f ||
					   (temp_buf[0] == 0x7e && temp_buf[1] == 0x00 &&
						temp_buf[2] == 0x07)) {
				break;
			}
			gdix_info("0x%x value is 0x%x, retry\n", CMD_ADDR, temp_buf[0]);
			usleep(30000);
		} while (--retry);
		gdix_info("check 0x%x value is: 0x%x,0x%x,0x%x,0x%x,0x%x.\n", CMD_ADDR,
				  temp_buf[0], temp_buf[1], temp_buf[2], temp_buf[3],
				  temp_buf[4]);

		/*set 0x7D to end send cfg */
		cmd_init(tmp_cmd_buf, 0x7D, 0);
		ret = dev->Write(CMD_ADDR, tmp_cmd_buf, 5);
		if (ret < 0) {
			gdix_err("Failed write send cfg end cmd\n");
			goto update_err;
		}

		if (!retry) {
			gdix_err("read 0x%x for config send end error\n", CMD_ADDR);
			ret = -2;
			goto update_err;
		}
		if (temp_buf[0] == 0x7e) {
			if (temp_buf[1] == 0x00 && temp_buf[2] == 0x07) {
				gdix_info("config data is equal with falsh\n");
			} else {
				gdix_err("failed send cfg\n");
				ret = -3;
				goto update_err;
			}
		} else if (temp_buf[0] != 0x7f) {
			gdix_err("failed send cfg\n");
			ret = -5;
			goto update_err;
		}

		gdix_info("send config data success!\n");
		// after update config,read curr config version
		dev->Read(CFG_START_ADDR, cfg_ver_after, 3);
		gdix_dbg("After update,cfg version is 0x%02x 0x%02x 0x%02x\n",
				 cfg_ver_after[0], cfg_ver_after[1], cfg_ver_after[2]);

		ret = 0;
	}
update_err:
	/*en report coor*/
	gdix_info("enable report coor\n");
	if (dev->Write(CMD_ADDR, buf_en_report_coor, sizeof(buf_en_report_coor)) <
		0) {
		gdix_err("Failed enable report coor in cfg update\n");
	}
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %r15
movq 0x10(%rdi), %rdi
movq (%rdi), %rax
callq *0x78(%rax)
movl %eax, %ebx
movb $0x33, 0x2c(%rsp)
movl $0x33, 0x28(%rsp)
movb $0x34, 0x24(%rsp)
movl $0x34, 0x20(%rsp)
movq 0x10(%r15), %rdi
movq (%rdi), %rax
callq *0x80(%rax)
movl %eax, %r13d
movq 0x10(%r15), %rdi
movq (%rdi), %rax
callq *0x88(%rax)
testl %ebx, %ebx
je 0x9f09
movl %ebx, 0x14(%rsp)
movl %eax, 0x10(%rsp)
leaq 0x1755b(%rip), %r12     # 0x21291
cmpb $0x1, (%r12)
jne 0x9d61
movq 0x17274(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xd972(%rip), %rsi      # 0x176c0
leaq 0xd99f(%rip), %rdx      # 0x176f4
movl $0x1a1, %ecx            # imm = 0x1A1
xorl %eax, %eax
callq 0x5180
movl $0xfffffffd, %r14d      # imm = 0xFFFFFFFD
leaq 0x28(%rsp), %rbx
movq 0x8(%r15), %rdi
movq (%rdi), %rax
movl $0x4160, %esi           # imm = 0x4160
movq %rbx, %rdx
movl $0x5, %ecx
callq *0x30(%rax)
movl %eax, %ebp
testl %eax, %eax
jns 0x9d90
cmpb $0x1, (%r12)
je 0x9d97
incl %r14d
jne 0x9d6c
jmp 0x9d9e
callq 0x54fd
jmp 0x9d90
movq 0x8(%r15), %rdi
movq (%rdi), %rax
leaq 0x2(%rsp), %rdx
movl $0x96f8, %esi           # imm = 0x96F8
movl $0x3, %ecx
callq *0x20(%rax)
cmpb $0x1, (%r12)
jne 0x9dfe
movq 0x171f3(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
movzbl 0x2(%rsp), %r8d
movzbl 0x3(%rsp), %r9d
movzbl 0x4(%rsp), %r10d
subq $0x8, %rsp
leaq 0xd91a(%rip), %rsi      # 0x176ff
leaq 0xd908(%rip), %rdx      # 0x176f4
movl $0x1ae, %ecx            # imm = 0x1AE
xorl %eax, %eax
pushq %r10
callq 0x5180
addq $0x10, %rsp
movq 0x10(%r15), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movb (%r12), %cl
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x9f13
movq %r15, 0x8(%rsp)
testb %cl, %cl
movl 0x14(%rsp), %ebx
je 0x9e4e
movq 0x1718a(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xd738(%rip), %rsi      # 0x17570
leaq 0xd8b5(%rip), %rdx      # 0x176f4
movl $0x1b9, %ecx            # imm = 0x1B9
movl %ebx, %r8d
xorl %eax, %eax
callq 0x5180
testl %ebx, %ebx
setg %r15b
jle 0x9f2a
movl %ebx, %eax
negl %eax
movq %rax, 0x78(%rsp)
movl $0x1, %r14d
movl %r13d, %eax
movq 0x18(%rsp), %rcx
movzbl (%rcx,%rax), %ebx
leaq 0x17415(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
jne 0x9ea8
movq 0x17130(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xd710(%rip), %rsi      # 0x175a2
leaq 0xd85b(%rip), %rdx      # 0x176f4
movl $0x1bc, %ecx            # imm = 0x1BC
movl %ebx, %r8d
xorl %eax, %eax
callq 0x5180
leal 0x1(%r13), %eax
movq 0x18(%rsp), %rdx
movzbl (%rdx,%rax), %eax
shll $0x8, %eax
leal 0x2(%r13), %ecx
movzbl (%rdx,%rcx), %r12d
orl %eax, %r12d
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x80(%rax)
cmpb %bl, %al
je 0x9f2c
addl %r12d, 0x10(%rsp)
addl $0x3, %r13d
cmpl 0x14(%rsp), %r14d
setl %r15b
movq 0x78(%rsp), %rax
addl %r14d, %eax
incl %eax
movl %r14d, %ecx
incl %ecx
movl %ecx, %r14d
cmpl $0x1, %eax
jne 0x9e69
jmp 0x9f85
movl $0xfffffffb, %ebp       # imm = 0xFFFFFFFB
jmp 0xa5b8
movl $0xfffffffc, %ebp       # imm = 0xFFFFFFFC
testb %cl, %cl
je 0xa566
callq 0x5689
jmp 0xa566
jmp 0x9f85
leaq 0x1735e(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
jne 0x9f85
movl 0x10(%rsp), %eax
movq 0x18(%rsp), %rcx
movzbl (%rcx,%rax), %ebx
movq 0x1706c(%rip), %rax     # 0x20fb8
movq (%rax), %r13
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x80(%rax)
movzbl %al, %r8d
leaq 0xd7d7(%rip), %rsi      # 0x17743
leaq 0xd781(%rip), %rdx      # 0x176f4
movq %r13, %rdi
movl $0x1c6, %ecx            # imm = 0x1C6
movl %ebx, %r9d
xorl %eax, %eax
callq 0x5180
testb $0x1, %r15b
movq 0x8(%rsp), %r15
je 0xa566
movl $0xfffffff6, %ebx       # imm = 0xFFFFFFF6
leaq 0x30(%rsp), %r13
movq 0x17013(%rip), %r14     # 0x20fb8
movq 0x8(%r15), %rdi
movq (%rdi), %rax
movl $0x4160, %esi           # imm = 0x4160
movq %r13, %rdx
movl $0x1, %ecx
callq *0x20(%rax)
testl %eax, %eax
js 0xa02f
movzbl 0x30(%rsp), %r9d
cmpl $0xff, %r9d
je 0xa06d
leaq 0x172b7(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
jne 0xa002
movq (%r14), %rdi
leaq 0xd7cb(%rip), %rsi      # 0x177b4
leaq 0xd704(%rip), %rdx      # 0x176f4
movl $0x1d9, %ecx            # imm = 0x1D9
movl $0x4160, %r8d           # imm = 0x4160
xorl %eax, %eax
callq 0x5180
movl $0x2710, %edi           # imm = 0x2710
callq 0x5170
incl %ebx
jne 0x9fa5
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
leaq 0x17275(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
jne 0xa566
callq 0x5527
jmp 0xa566
movl %eax, %ebp
leaq 0x17259(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
jne 0xa566
movq 0x16f90(%rip), %rax     # 0x20fd8
movq (%rax), %rdi
leaq 0xd732(%rip), %rsi      # 0x17784
leaq 0xd69b(%rip), %rdx      # 0x176f4
movl $0x1d3, %ecx            # imm = 0x1D3
movl %ebp, %r8d
xorl %eax, %eax
callq 0x5180
jmp 0xa566
leaq 0x30(%rsp), %rdx
movl $0x80, (%rdx)
movb $-0x80, 0x4(%rdx)
movq 0x8(%r15), %rdi
movq (%rdi), %rax
movl $0x4160, %esi           # imm = 0x4160
movl $0x5, %ecx
callq *0x30(%rax)
testl %eax, %eax
js 0xa18c
movl $0x3d090, %edi          # imm = 0x3D090
callq 0x5170
movl $0xfffffffa, %r15d      # imm = 0xFFFFFFFA
leaq 0x30(%rsp), %r13
leaq 0xd640(%rip), %rbp      # 0x176f4
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
movl $0x4160, %esi           # imm = 0x4160
movq %r13, %rdx
movl $0x1, %ecx
callq *0x20(%rax)
movl %eax, %ebx
leaq 0x171b8(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
jne 0xa0f7
movq (%r14), %rdi
leaq 0xd74f(%rip), %rsi      # 0x17837
movq %rbp, %rdx
movl $0x1ef, %ecx            # imm = 0x1EF
xorl %eax, %eax
callq 0x5180
testl %ebx, %ebx
jns 0xa107
leaq 0x1718f(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
je 0xa15e
movzbl 0x30(%rsp), %r9d
leaq 0x1717d(%rip), %rax     # 0x21291
movb (%rax), %al
cmpl $0x82, %r9d
je 0xa1a8
testb %al, %al
je 0xa146
movq (%r14), %rdi
leaq 0xd731(%rip), %rsi      # 0x17862
movq %rbp, %rdx
movl $0x1f6, %ecx            # imm = 0x1F6
movl $0x4160, %r8d           # imm = 0x4160
xorl %eax, %eax
callq 0x5180
movl $0x7530, %edi           # imm = 0x7530
callq 0x5170
incl %r15d
jne 0xa0b4
jmp 0xa335
movq 0x16e73(%rip), %rax     # 0x20fd8
movq (%rax), %rdi
leaq 0xd0ff(%rip), %rsi      # 0x1726e
movq %rbp, %rdx
movl $0x1f1, %ecx            # imm = 0x1F1
movl $0x4160, %r8d           # imm = 0x4160
movl %ebx, %r9d
xorl %eax, %eax
callq 0x5180
jmp 0xa107
movl %eax, %ebp
leaq 0x170fc(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
jne 0xa566
callq 0x565f
jmp 0xa566
testb %al, %al
je 0xa1c9
movq (%r14), %rdi
leaq 0xd703(%rip), %rsi      # 0x178b9
leaq 0xd537(%rip), %rdx      # 0x176f4
movl $0x1ff, %ecx            # imm = 0x1FF
xorl %eax, %eax
callq 0x5180
movq 0x8(%rsp), %r15
movq 0x8(%r15), %rdi
movl 0x10(%rsp), %eax
movq 0x18(%rsp), %rdx
addq %rax, %rdx
movq (%rdi), %rax
movl $0x96f8, %esi           # imm = 0x96F8
movl %r12d, %ecx
callq *0x30(%rax)
testl %eax, %eax
js 0xa354
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x5170
leaq 0x30(%rsp), %rdx
movl $0x83, (%rdx)
movb $-0x7d, 0x4(%rdx)
movq 0x8(%r15), %rdi
movq (%rdi), %rax
movl $0x4160, %esi           # imm = 0x4160
movl $0x5, %ecx
callq *0x30(%rax)
testl %eax, %eax
js 0xa388
movq %r14, %r15
movl $0x13880, %edi          # imm = 0x13880
callq 0x5170
movl $0xfffffffa, %r13d      # imm = 0xFFFFFFFA
leaq 0x30(%rsp), %r14
leaq 0xd4ac(%rip), %r12      # 0x176f4
leaq 0xd72d(%rip), %rbp      # 0x1797c
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
movl $0x4160, %esi           # imm = 0x4160
movq %r14, %rdx
movl $0x5, %ecx
callq *0x20(%rax)
movl %eax, %ebx
leaq 0x1701d(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
jne 0xa292
movq (%r15), %rdi
leaq 0xd6ce(%rip), %rsi      # 0x17951
movq %r12, %rdx
movl $0x216, %ecx            # imm = 0x216
xorl %eax, %eax
callq 0x5180
testl %ebx, %ebx
js 0xa2b9
movb 0x30(%rsp), %al
cmpb $0x7f, %al
je 0xa3a4
cmpb $0x7e, %al
jne 0xa2c5
cmpb $0x0, 0x31(%rsp)
jne 0xa2c5
cmpb $0x7, 0x32(%rsp)
jne 0xa2c5
jmp 0xa3a4
leaq 0x16fd1(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
je 0xa30a
leaq 0x16fc5(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
jne 0xa2f2
movq (%r15), %rdi
movzbl 0x30(%rsp), %r9d
movq %rbp, %rsi
movq %r12, %rdx
movl $0x21e, %ecx            # imm = 0x21E
movl $0x4160, %r8d           # imm = 0x4160
xorl %eax, %eax
callq 0x5180
movl $0x7530, %edi           # imm = 0x7530
callq 0x5170
incl %r13d
jne 0xa24f
jmp 0xa3a8
movq 0x16cc7(%rip), %rax     # 0x20fd8
movq (%rax), %rdi
leaq 0xcf53(%rip), %rsi      # 0x1726e
movq %r12, %rdx
movl $0x218, %ecx            # imm = 0x218
movl $0x4160, %r8d           # imm = 0x4160
movl %ebx, %r9d
xorl %eax, %eax
callq 0x5180
jmp 0xa2c5
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
leaq 0x16f50(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
je 0xa540
movq 0x8(%rsp), %r15
jmp 0xa566
movl %eax, %ebp
leaq 0x16f34(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
jne 0xa566
movq 0x16c6b(%rip), %rax     # 0x20fd8
movq (%rax), %rdi
leaq 0xd573(%rip), %rsi      # 0x178ea
leaq 0xd376(%rip), %rdx      # 0x176f4
movl $0x204, %ecx            # imm = 0x204
jmp 0xa05e
movl %eax, %ebp
leaq 0x16f00(%rip), %rax     # 0x21291
cmpb $0x1, (%rax)
jne 0xa566
callq 0x5635
jmp 0xa566
xorl %ebx, %ebx
jmp 0xa3aa
movb $0x1, %bl
leaq 0x16ee0(%rip), %r12     # 0x21291
cmpb $0x1, (%r12)
movq %r15, %r14
jne 0xa40b
movq (%r14), %rdi
movzbl 0x30(%rsp), %r9d
movzbl 0x31(%rsp), %r10d
movzbl 0x32(%rsp), %r11d
movzbl 0x33(%rsp), %r14d
movzbl 0x34(%rsp), %r13d
leaq 0xd5c5(%rip), %rsi      # 0x179a8
leaq 0xd30a(%rip), %rdx      # 0x176f4
movl $0x223, %ecx            # imm = 0x223
movl $0x4160, %r8d           # imm = 0x4160
xorl %eax, %eax
pushq %r13
pushq %r14
movq %r15, %r14
pushq %r11
pushq %r10
callq 0x5180
addq $0x20, %rsp
leaq 0x83(%rsp), %rdx
movl $0x7d, (%rdx)
movb $0x7d, 0x4(%rdx)
movq 0x8(%rsp), %r15
movq 0x8(%r15), %rdi
movq (%rdi), %rax
movl $0x4160, %esi           # imm = 0x4160
movl $0x5, %ecx
callq *0x30(%rax)
testl %eax, %eax
js 0xa458
testb %bl, %bl
je 0xa46f
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
cmpb $0x1, (%r12)
jne 0xa566
callq 0x55db
jmp 0xa566
movl %eax, %ebp
cmpb $0x1, (%r12)
jne 0xa566
callq 0x560b
jmp 0xa566
movzbl 0x30(%rsp), %eax
cmpl $0x7f, %eax
je 0xa4bd
cmpl $0x7e, %eax
jne 0xa54a
cmpb $0x0, 0x31(%rsp)
movb (%r12), %al
jne 0xa55d
cmpb $0x7, 0x32(%rsp)
jne 0xa55d
testb %al, %al
je 0xa4bd
movq (%r14), %rdi
leaq 0xd5a5(%rip), %rsi      # 0x17a4f
leaq 0xd243(%rip), %rdx      # 0x176f4
movl $0x234, %ecx            # imm = 0x234
xorl %eax, %eax
callq 0x5180
cmpb $0x1, (%r12)
jne 0xa4e1
movq (%r14), %rdi
leaq 0xd5d5(%rip), %rsi      # 0x17aa3
leaq 0xd21f(%rip), %rdx      # 0x176f4
movl $0x240, %ecx            # imm = 0x240
xorl %eax, %eax
callq 0x5180
movq 0x8(%r15), %rdi
movq (%rdi), %rax
leaq 0x5(%rsp), %rdx
movl $0x96f8, %esi           # imm = 0x96F8
movl $0x3, %ecx
callq *0x20(%rax)
xorl %ebp, %ebp
cmpb $0x1, (%r12)
jne 0xa566
movq (%r14), %rdi
movzbl 0x5(%rsp), %r8d
movzbl 0x6(%rsp), %r9d
movzbl 0x7(%rsp), %r10d
subq $0x8, %rsp
leaq 0xd5ac(%rip), %rsi      # 0x17acf
leaq 0xd1ca(%rip), %rdx      # 0x176f4
xorl %ebp, %ebp
movl $0x244, %ecx            # imm = 0x244
xorl %eax, %eax
pushq %r10
callq 0x5180
addq $0x10, %rsp
jmp 0xa566
callq 0x5557
jmp 0xa34a
movl $0xfffffffb, %ebp       # imm = 0xFFFFFFFB
cmpb $0x1, (%r12)
jne 0xa566
callq 0x55b1
jmp 0xa566
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
testb %al, %al
jne 0xa5d3
leaq 0x16d24(%rip), %rbx     # 0x21291
cmpb $0x1, (%rbx)
jne 0xa596
movq 0x16a3f(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xc952(%rip), %rsi      # 0x16ed5
leaq 0xd16a(%rip), %rdx      # 0x176f4
movl $0x24a, %ecx            # imm = 0x24A
xorl %eax, %eax
callq 0x5180
movq 0x8(%r15), %rdi
movq (%rdi), %rax
leaq 0x20(%rsp), %rdx
movl $0x4160, %esi           # imm = 0x4160
movl $0x5, %ecx
callq *0x30(%rax)
testl %eax, %eax
jns 0xa5b8
cmpb $0x1, (%rbx)
je 0xa5cc
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x56b3
jmp 0xa5b8
callq 0x5587
jmp 0xa566
nop