// File: goodix[P]gdix_hid_firmware_update/gtx8/gtx8_update.cpp
// Function: GTx8Update::fw_update(unsigned int)
int GTx8Update::fw_update(unsigned int firmware_flag)
{
	int retry;
	int ret, i;
	unsigned char temp_buf[65];
	unsigned char *fw_data = NULL;
	unsigned char buf_switch_to_patch[] = {0x00, 0x10, 0x00, 0x00, 0x01, 0x01};
	unsigned char buf_start_update[] = {0x00, 0x11, 0x00, 0x00, 0x01, 0x01};
	unsigned char buf_restart[] = {0x0E, 0x13, 0x00, 0x00, 0x01, 0x01};
	unsigned char buf_switch_ptp_mode[] = {0x03, 0x03, 0x00, 0x00, 0x01, 0x01};

	int sub_fw_num = 0;
	unsigned char sub_fw_type;
	unsigned int sub_fw_len;
	unsigned int sub_fw_flash_addr;
	unsigned int sub_fw_info_pos =
		image->GetFirmwareSubFwInfoOffset(); // SUB_FW_INFO_OFFSET;
	unsigned int fw_image_offset =
		image->GetFirmwareSubFwDataOffset(); // SUB_FW_DATA_OFFSET;

	/* close report */
	ret = this->DisableReport();
	if (ret < 0)
		return ret;

	ret = dev->Write(buf_switch_to_patch, sizeof(buf_switch_to_patch));
	if (ret < 0) {
		gdix_err("Failed switch to patch\n");
		goto update_err;
	}

	usleep(250000);
	retry = GDIX_RETRY_TIMES;
	do {
		ret = dev->Read(BL_STATE_ADDR, temp_buf, 1);
		gdix_dbg("BL_STATE_ADDR:0x%x\n", BL_STATE_ADDR);
		if (ret < 0) {
			gdix_err("Failed read 0x%x, ret = %d\n", BL_STATE_ADDR, ret);
			goto update_err;
		}
		if (temp_buf[0] == 0xDD)
			break;
		gdix_info("0x%x value is 0x%x != 0xDD, retry\n", BL_STATE_ADDR,
				  temp_buf[0]);
		usleep(30000);
	} while (--retry);

	if (!retry) {
		gdix_err("Reg 0x%x != 0xDD\n", BL_STATE_ADDR);
		ret = -2;
		goto update_err;
	}

	ret = this->DisableReport();
	if (ret < 0)
		goto update_err;

	/* Start update */
	ret = dev->Write(buf_start_update, sizeof(buf_start_update));
	if (ret < 0) {
		gdix_err("Failed start update, ret=%d\n", ret);
		goto update_err;
	}
	usleep(100000);

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

	sub_fw_num =
		image->GetFirmwareSubFwNum(); // fw_data[FW_IMAGE_SUB_FWNUM_OFFSET];
	sub_fw_info_pos =
		image->GetFirmwareSubFwInfoOffset(); // SUB_FW_INFO_OFFSET;
	fw_image_offset =
		image->GetFirmwareSubFwDataOffset(); // SUB_FW_DATA_OFFSET;
	gdix_dbg("load sub firmware, sub_fw_num=%d\n", sub_fw_num);
	if (sub_fw_num == 0)
		return -5;

	/* load normal firmware package */
	for (i = 0; i < sub_fw_num; i++) {
		sub_fw_type = fw_data[sub_fw_info_pos];
		gdix_dbg("load sub firmware, sub_fw_type=0x%x\n", sub_fw_type);
		sub_fw_len = (fw_data[sub_fw_info_pos + 1] << 24) |
					 (fw_data[sub_fw_info_pos + 2] << 16) |
					 (fw_data[sub_fw_info_pos + 3] << 8) |
					 fw_data[sub_fw_info_pos + 4];

		sub_fw_flash_addr =
			(fw_data[sub_fw_info_pos + 5] << 8) | fw_data[sub_fw_info_pos + 6];
		sub_fw_flash_addr = sub_fw_flash_addr << 8;
		if (!(firmware_flag & (0x01 << sub_fw_type))) {
			gdix_info("Sub firmware type does not math:type=%d\n", sub_fw_type);
			fw_image_offset += sub_fw_len;
			sub_fw_info_pos += 8;
			continue;
		}

		/* if sub fw type is HID subsystem we need compare version before update
		 */
		// TODO update hid subsystem
		gdix_dbg("load sub firmware addr:0x%x,len:0x%x\n", sub_fw_flash_addr,
				 sub_fw_len);
		ret = load_sub_firmware(sub_fw_flash_addr, &fw_data[fw_image_offset],
								sub_fw_len);
		if (ret < 0) {
			gdix_dbg("Failed load sub firmware, ret=%d\n", ret);
			goto update_err;
		}
		fw_image_offset += sub_fw_len;
		sub_fw_info_pos += 8;
	}

	/* flash config with isp if NEED_UPDATE_CONFIG_WITH_ISP flag is setted or
	 * hid subsystem updated.
	 */
	if (image->GetUpdateFlag() & NEED_UPDATE_CONFIG_WITH_ISP) {
		this->is_cfg_flashed_with_isp = true;
		ret = flash_cfg_with_isp();
		if (ret < 0) {
			gdix_err("failed flash config with isp, ret %d\n", ret);
			goto update_err;
		}
	}

	/* reset IC */
	gdix_dbg("reset ic\n");
	retry = 3;
	do {
		ret = dev->Write(buf_restart, sizeof(buf_restart));
		if (ret >= 0)
			break;
		usleep(20000);
	} while (--retry);
	if (retry == 0 && ret < 0)
		gdix_dbg("Failed write restart command, ret=%d\n", ret);
	else
		ret = 0;

	usleep(300000);

	if (dev->WriteSpeCmd(buf_switch_ptp_mode, sizeof(buf_switch_ptp_mode)) <
		0) {
		gdix_err("Failed switch to ptp mode\n");
	}
	return ret;

update_err:
	/* reset IC */
	gdix_dbg("reset ic\n");
	retry = 3;
	do {
		if (dev->Write(buf_restart, sizeof(buf_restart)) >= 0)
			break;
		usleep(20000);
	} while (--retry);
	if (retry == 0 && ret < 0)
		gdix_dbg("Failed write restart command, ret=%d\n", ret);

	usleep(300000);
	if (dev->WriteSpeCmd(buf_switch_ptp_mode, sizeof(buf_switch_ptp_mode)) <
		0) {
		gdix_err("Failed switch to ptp mode\n");
	}
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq $0x0, -0x78(%rbp)
movl 0xcedf(%rip), %ecx      # 0x1ea4a
movl %ecx, -0x7e(%rbp)
movw 0xced9(%rip), %cx       # 0x1ea4e
movw %cx, -0x7a(%rbp)
movl 0xced1(%rip), %ecx      # 0x1ea50
movl %ecx, -0x84(%rbp)
movw 0xcec8(%rip), %cx       # 0x1ea54
movw %cx, -0x80(%rbp)
movl 0xcec0(%rip), %ecx      # 0x1ea56
movl %ecx, -0x8a(%rbp)
movw 0xceb7(%rip), %cx       # 0x1ea5a
movw %cx, -0x86(%rbp)
movl 0xceac(%rip), %ecx      # 0x1ea5c
movl %ecx, -0x90(%rbp)
movw 0xcea3(%rip), %cx       # 0x1ea60
movw %cx, -0x8c(%rbp)
movl $0x0, -0x94(%rbp)
movq 0x10(%rax), %rdi
movq (%rdi), %rax
callq *0x60(%rax)
movl %eax, %ecx
movq -0xb0(%rbp), %rax
movl %ecx, -0xa4(%rbp)
movq 0x10(%rax), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
movq -0xb0(%rbp), %rdi
movl %eax, -0xa8(%rbp)
callq 0x11900
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x11c17
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x12481
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x7e(%rbp), %rsi
movq (%rdi), %rax
movl $0x6, %edx
callq *0x38(%rax)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x11c73
jmp 0x11c3c
leaq 0x14656(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x11c6c
movq 0x14389(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0xb596(%rip), %rsi      # 0x1d1ef
leaq 0xd59c(%rip), %rdx      # 0x1f1fc
movl $0xbb, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x11c6e
jmp 0x1235c
movl $0x3d090, %edi          # imm = 0x3D090
callq 0x5180
movl $0x6, -0x18(%rbp)
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x70(%rbp), %rdx
movq (%rdi), %rax
movl $0x5095, %esi           # imm = 0x5095
movl $0x1, %ecx
callq *0x20(%rax)
movl %eax, -0x1c(%rbp)
leaq 0x145ec(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x11cdc
movq 0x142ff(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
leaq 0xb57b(%rip), %rsi      # 0x1d23e
leaq 0xd532(%rip), %rdx      # 0x1f1fc
movl $0xc3, %ecx
movl $0x5095, %r8d           # imm = 0x5095
movb $0x0, %al
callq 0x5190
jmp 0x11cde
cmpl $0x0, -0x1c(%rbp)
jge 0x11d27
jmp 0x11ce6
leaq 0x145ac(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x11d20
movq 0x142df(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
movl -0x1c(%rbp), %r9d
leaq 0xb55c(%rip), %rsi      # 0x1d263
leaq 0xd4ee(%rip), %rdx      # 0x1f1fc
movl $0xc5, %ecx
movl $0x5095, %r8d           # imm = 0x5095
movb $0x0, %al
callq 0x5190
jmp 0x11d22
jmp 0x1235c
movzbl -0x70(%rbp), %eax
cmpl $0xdd, %eax
jne 0x11d34
jmp 0x11d8f
jmp 0x11d36
leaq 0x1455c(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x11d71
movq 0x1426f(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x70(%rbp), %r9d
leaq 0xb538(%rip), %rsi      # 0x1d290
leaq 0xd49d(%rip), %rdx      # 0x1f1fc
movl $0xcb, %ecx
movl $0x5095, %r8d           # imm = 0x5095
movb $0x0, %al
callq 0x5190
jmp 0x11d73
movl $0x7530, %edi           # imm = 0x7530
callq 0x5180
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, %eax
jne 0x11c84
cmpl $0x0, -0x18(%rbp)
jne 0x11ddb
jmp 0x11d97
leaq 0x144fb(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x11dcd
movq 0x1422e(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0xb510(%rip), %rsi      # 0x1d2c4
leaq 0xd441(%rip), %rdx      # 0x1f1fc
movl $0xd0, %ecx
movl $0x5095, %r8d           # imm = 0x5095
movb $0x0, %al
callq 0x5190
jmp 0x11dcf
movl $0xfffffffe, -0x1c(%rbp) # imm = 0xFFFFFFFE
jmp 0x1235c
movq -0xb0(%rbp), %rdi
callq 0x11900
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x11df5
jmp 0x1235c
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x84(%rbp), %rsi
movq (%rdi), %rax
movl $0x6, %edx
callq *0x38(%rax)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x11e58
jmp 0x11e1d
leaq 0x14475(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x11e51
movq 0x141a8(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
movl -0x1c(%rbp), %r8d
leaq 0xb4a9(%rip), %rsi      # 0x1d2e7
leaq 0xd3b7(%rip), %rdx      # 0x1f1fc
movl $0xdc, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x11e53
jmp 0x1235c
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x5180
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x11ebe
jmp 0x11e80
leaq 0x14412(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x11eb0
movq 0x14145(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0xb478(%rip), %rsi      # 0x1d315
leaq 0xd358(%rip), %rdx      # 0x1f1fc
movl $0xe4, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x11eb2
movl $0xfffffffc, -0x1c(%rbp) # imm = 0xFFFFFFFC
jmp 0x1235c
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rdi
movq (%rdi), %rax
callq *0x58(%rax)
movl %eax, %ecx
movq -0xb0(%rbp), %rax
movl %ecx, -0x94(%rbp)
movq 0x10(%rax), %rdi
movq (%rdi), %rax
callq *0x60(%rax)
movl %eax, %ecx
movq -0xb0(%rbp), %rax
movl %ecx, -0xa4(%rbp)
movq 0x10(%rax), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
movl %eax, -0xa8(%rbp)
leaq 0x1438b(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x11f3e
movq 0x1409e(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movl -0x94(%rbp), %r8d
leaq 0xb40e(%rip), %rsi      # 0x1d339
leaq 0xd2ca(%rip), %rdx      # 0x1f1fc
movl $0xef, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x11f40
cmpl $0x0, -0x94(%rbp)
jne 0x11f55
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0x12481
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x94(%rbp), %eax
jge 0x121b2
movq -0x78(%rbp), %rax
movl -0xa4(%rbp), %ecx
movb (%rax,%rcx), %al
movb %al, -0x95(%rbp)
leaq 0x14314(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x11fb6
movq 0x14027(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x95(%rbp), %r8d
leaq 0xb3c9(%rip), %rsi      # 0x1d36c
leaq 0xd252(%rip), %rdx      # 0x1f1fc
movl $0xf6, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x11fb8
movq -0x78(%rbp), %rax
movl -0xa4(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
shll $0x18, %eax
movq -0x78(%rbp), %rcx
movl -0xa4(%rbp), %edx
addl $0x2, %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movq -0x78(%rbp), %rcx
movl -0xa4(%rbp), %edx
addl $0x3, %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movq -0x78(%rbp), %rcx
movl -0xa4(%rbp), %edx
addl $0x4, %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x9c(%rbp)
movq -0x78(%rbp), %rax
movl -0xa4(%rbp), %ecx
addl $0x5, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x78(%rbp), %rcx
movl -0xa4(%rbp), %edx
addl $0x6, %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
shll $0x8, %eax
movl %eax, -0xa0(%rbp)
movl -0x14(%rbp), %eax
movzbl -0x95(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x120d5
jmp 0x12075
leaq 0x1421d(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x120ad
movq 0x13f30(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movzbl -0x95(%rbp), %r8d
leaq 0xb308(%rip), %rsi      # 0x1d3a2
leaq 0xd15b(%rip), %rdx      # 0x1f1fc
movl $0x100, %ecx            # imm = 0x100
movb $0x0, %al
callq 0x5190
jmp 0x120af
movl -0x9c(%rbp), %eax
addl -0xa8(%rbp), %eax
movl %eax, -0xa8(%rbp)
movl -0xa4(%rbp), %eax
addl $0x8, %eax
movl %eax, -0xa4(%rbp)
jmp 0x121a4
jmp 0x120d7
leaq 0x141bb(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x12115
movq 0x13ece(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movl -0xa0(%rbp), %r8d
movl -0x9c(%rbp), %r9d
leaq 0xb2da(%rip), %rsi      # 0x1d3dc
leaq 0xd0f3(%rip), %rdx      # 0x1f1fc
movl $0x10a, %ecx            # imm = 0x10A
movb $0x0, %al
callq 0x5190
jmp 0x12117
movq -0xb0(%rbp), %rdi
movl -0xa0(%rbp), %esi
movq -0x78(%rbp), %rdx
movl -0xa8(%rbp), %eax
addq %rax, %rdx
movl -0x9c(%rbp), %ecx
movq (%rdi), %rax
callq *0x28(%rax)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x12183
jmp 0x12148
leaq 0x1414a(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x1217c
movq 0x13e5d(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movl -0x1c(%rbp), %r8d
leaq 0xb2aa(%rip), %rsi      # 0x1d413
leaq 0xd08c(%rip), %rdx      # 0x1f1fc
movl $0x10e, %ecx            # imm = 0x10E
movb $0x0, %al
callq 0x5190
jmp 0x1217e
jmp 0x1235c
movl -0x9c(%rbp), %eax
addl -0xa8(%rbp), %eax
movl %eax, -0xa8(%rbp)
movl -0xa4(%rbp), %eax
addl $0x8, %eax
movl %eax, -0xa4(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x11f5c
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rdi
movq (%rdi), %rax
callq *0xa8(%rax)
andl $0x10, %eax
cmpl $0x0, %eax
je 0x12227
movq -0xb0(%rbp), %rdi
movb $0x1, 0x1a(%rdi)
movq (%rdi), %rax
callq *0x40(%rax)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x12225
jmp 0x121ea
leaq 0x140a8(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x1221e
movq 0x13ddb(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
movl -0x1c(%rbp), %r8d
leaq 0xb23b(%rip), %rsi      # 0x1d446
leaq 0xcfea(%rip), %rdx      # 0x1f1fc
movl $0x11c, %ecx            # imm = 0x11C
movb $0x0, %al
callq 0x5190
jmp 0x12220
jmp 0x1235c
jmp 0x12227
jmp 0x12229
leaq 0x14069(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x12259
movq 0x13d7c(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
leaq 0xb263(%rip), %rsi      # 0x1d4a9
leaq 0xcfaf(%rip), %rdx      # 0x1f1fc
movl $0x122, %ecx            # imm = 0x122
movb $0x0, %al
callq 0x5190
jmp 0x1225b
movl $0x3, -0x18(%rbp)
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x8a(%rbp), %rsi
movq (%rdi), %rax
movl $0x6, %edx
callq *0x38(%rax)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x1228a
jmp 0x122a2
movl $0x4e20, %edi           # imm = 0x4E20
callq 0x5180
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, %eax
jne 0x12262
cmpl $0x0, -0x18(%rbp)
jne 0x122e8
cmpl $0x0, -0x1c(%rbp)
jge 0x122e8
jmp 0x122b0
leaq 0x13fe2(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x122e4
movq 0x13cf5(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movl -0x1c(%rbp), %r8d
leaq 0xb1f3(%rip), %rsi      # 0x1d4c4
leaq 0xcf24(%rip), %rdx      # 0x1f1fc
movl $0x12b, %ecx            # imm = 0x12B
movb $0x0, %al
callq 0x5190
jmp 0x122e6
jmp 0x122ef
movl $0x0, -0x1c(%rbp)
movl $0x493e0, %edi          # imm = 0x493E0
callq 0x5180
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x90(%rbp), %rsi
movq (%rdi), %rax
movl $0x6, %edx
callq *0x40(%rax)
cmpl $0x0, %eax
jge 0x12351
jmp 0x1231d
leaq 0x13f75(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x1234d
movq 0x13ca8(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0xb1c1(%rip), %rsi      # 0x1d4fb
leaq 0xcebb(%rip), %rdx      # 0x1f1fc
movl $0x133, %ecx            # imm = 0x133
movb $0x0, %al
callq 0x5190
jmp 0x1234f
jmp 0x12351
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x12481
jmp 0x1235e
leaq 0x13f34(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x1238e
movq 0x13c47(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
leaq 0xb12e(%rip), %rsi      # 0x1d4a9
leaq 0xce7a(%rip), %rdx      # 0x1f1fc
movl $0x139, %ecx            # imm = 0x139
movb $0x0, %al
callq 0x5190
jmp 0x12390
movl $0x3, -0x18(%rbp)
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x8a(%rbp), %rsi
movq (%rdi), %rax
movl $0x6, %edx
callq *0x38(%rax)
cmpl $0x0, %eax
jl 0x123bb
jmp 0x123d3
movl $0x4e20, %edi           # imm = 0x4E20
callq 0x5180
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, %eax
jne 0x12397
cmpl $0x0, -0x18(%rbp)
jne 0x12419
cmpl $0x0, -0x1c(%rbp)
jge 0x12419
jmp 0x123e1
leaq 0x13eb1(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x12415
movq 0x13bc4(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movl -0x1c(%rbp), %r8d
leaq 0xb0c2(%rip), %rsi      # 0x1d4c4
leaq 0xcdf3(%rip), %rdx      # 0x1f1fc
movl $0x141, %ecx            # imm = 0x141
movb $0x0, %al
callq 0x5190
jmp 0x12417
jmp 0x12419
movl $0x493e0, %edi          # imm = 0x493E0
callq 0x5180
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x90(%rbp), %rsi
movq (%rdi), %rax
movl $0x6, %edx
callq *0x40(%rax)
cmpl $0x0, %eax
jge 0x1247b
jmp 0x12447
leaq 0x13e4b(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x12477
movq 0x13b7e(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0xb097(%rip), %rsi      # 0x1d4fb
leaq 0xcd91(%rip), %rdx      # 0x1f1fc
movl $0x146, %ecx            # imm = 0x146
movb $0x0, %al
callq 0x5190
jmp 0x12479
jmp 0x1247b
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)