// File: /workspace/github_cpp_makefile_star2_O1/goodix[P]gdix_hid_firmware_update/main.cpp
// Function: main
int main(int argc, char **argv)
{
	int ret = 0;
	int opt;
	int index;
	int chipType = -1;
	GTmodel *gt_model = NULL;
	FirmwareImage *fw_image = NULL;
	GTupdate *gt_update = NULL;
	GTUpdatePara *gt_update_para = NULL;
	unsigned int firmware_flag = 0xFFFFFFFF;
	uint8_t i2cAddr = 0;

	regex_t reg_x3xx;
	regex_t reg_x5xx;
	regex_t reg_x2xx;
	regex_t reg_x8xx;
	regex_t reg_x9xx;
	regex_t reg_7868;
	regex_t reg_brla;
	regmatch_t pamtch[1]; // match container

	char *deviceName = NULL;
	const char *firmwareName = NULL;
	const char *pid = NULL;
	const char *productionTypeName = NULL;
	bool force = false;
	static struct option long_options[] = {
		{"help", 0, NULL, 'h'},
		{"force", 0, NULL, 'f'},
		{"device", 1, NULL, 'd'},
		{"fw-props", 0, NULL, 'p'},
		{"version", 0, NULL, 'v'},
		{"type", 1, NULL, 't'},
		{"series", 1, NULL, 's'},
		{"info", 0, NULL, 'i'},
		{"module", 0, NULL, 'm'},
		{"i2c-addr", 1, NULL, 'a'},
		{0, 0, 0, 0},
	};
	bool printFirmwareProps = false;
	bool printModuleId = false;
	while ((opt = getopt_long(argc, argv, GTPUPDATE_GETOPTS, long_options,
							  &index)) != -1) {
		switch (opt) {
		case 'h':
			printHelp(argv[0]);
			return 0;
		case 'f':
			force = true;
			break;
		case 'd':
			deviceName = optarg;
			break;
		case 'p':
			printFirmwareProps = true;
			break;
		case 'v':
			printVersion();
			return 0;
		case 't':
			lowercase_str((unsigned char *)optarg);
			pid = optarg;
			gdix_dbg("pid is %s\n", pid);
			break;
		case 's':
			productionTypeName = optarg;
			gdix_dbg("product type is %s\n", productionTypeName);
			break;
		case 'i':
			pdebug = true;
			break;
		case 'm':
			printModuleId = true;
			break;
		case 'a':
			i2cAddr = strtol(optarg, NULL, 16);
			break;
		default:
			break;
		}
	}

	if (optind < argc) {
		firmwareName = argv[optind];
		gdix_dbg("firmware name:%s\n", firmwareName);
	}
	if (NULL == productionTypeName && NULL == pid) {
		gdix_err("please input pid or product type\n");
		return -1;
	}
	if (!printModuleId && !printFirmwareProps && NULL == firmwareName) {
		gdix_err("file name not found\n");
		return -1;
	}

	// check chip type
	if (pid != NULL) {
		regex_t reg_pid;
		regcomp(&reg_pid, "^011[0-9A-Fa-f]$", REG_EXTENDED); // phoenix pid
															 // 011x
		if (REG_NOERROR == regexec(&reg_pid, pid, 1, pamtch, 0)) {
			gdix_dbg("pid match phoenix pid 011x\n");
			chipType = TYPE_PHOENIX;
		}
		regfree(&reg_pid);

		regcomp(&reg_pid, "^0[eE][0-9A-Fa-f]{2}$",
				REG_EXTENDED); // phoenix pid 0exx
		if (REG_NOERROR == regexec(&reg_pid, pid, 1, pamtch, 0)) {
			gdix_dbg("pid match phoenix pid 0exx\n");
			chipType = TYPE_PHOENIX;
		}
		regfree(&reg_pid);

		regcomp(&reg_pid, "^01[fF][0-9A-Fa-f]$",
				REG_EXTENDED); // mouse pad pid 01fx
		if (REG_NOERROR == regexec(&reg_pid, pid, 1, pamtch, 0)) {
			gdix_dbg("pid match mousepad pid 01fx\n");
			chipType = TYPE_MOUSEPAD;
		}
		regfree(&reg_pid);

		regcomp(&reg_pid, "^0[fF][0-9A-Fa-f]{2}$",
				REG_EXTENDED); // mouse pad pid 0fxx
		if (REG_NOERROR == regexec(&reg_pid, pid, 1, pamtch, 0)) {
			gdix_dbg("pid match mousepad pid 0fxx\n");
			chipType = TYPE_MOUSEPAD;
		}
		regfree(&reg_pid);

		regcomp(&reg_pid, "^01[eE][0-7]$",
				REG_EXTENDED); // 7863 windows pid 01e0~01e7
		if (REG_NOERROR == regexec(&reg_pid, pid, 1, pamtch, 0)) {
			gdix_dbg("pid match GT7863 pid 01e0_01e7\n");
			chipType = TYPE_NORMANDYL;
		}
		regfree(&reg_pid);

		regcomp(&reg_pid, "^0[dD][0-7][0-9A-Fa-f]$",
				REG_EXTENDED); // 7863 chrome pid 0d00~0d7f
		if (REG_NOERROR == regexec(&reg_pid, pid, 1, pamtch, 0)) {
			gdix_dbg("pid match GT7863 pid 0d00_0d7f\n");
			chipType = TYPE_NORMANDYL;
		}
		regfree(&reg_pid);

		regcomp(&reg_pid, "^0[dD][8-9A-Ba-b][0-9A-Fa-f]$",
				REG_EXTENDED); // 7868Q chrome pid 0d80~0dbf
		if (REG_NOERROR == regexec(&reg_pid, pid, 1, pamtch, 0)) {
			gdix_dbg("pid match GT7868Q pid 0d80_0dbf\n");
			chipType = TYPE_YELLOWSTONE;
		}
		regfree(&reg_pid);

		/* 0EB* 0EC* is BerlinB */
		regcomp(&reg_pid, "^0[eE][bBcC][0-9A-Fa-f]$", REG_EXTENDED);
		if (REG_NOERROR == regexec(&reg_pid, pid, 1, pamtch, 0)) {
			gdix_dbg("pid match BerlinB pid 0EBx\n");
			chipType = TYPE_BERLINB;
		}
		regfree(&reg_pid);

		/* 0EA5~0EAF is BerlinB */
		regcomp(&reg_pid, "^0[eE][aA][5-9A-Fa-f]$", REG_EXTENDED);
		if (REG_NOERROR == regexec(&reg_pid, pid, 1, pamtch, 0)) {
			gdix_dbg("pid match BerlinB pid 0EA5~0EAF\n");
			chipType = TYPE_BERLINB;
		}
		regfree(&reg_pid);

		/* 0Cxx is BerlinB */
		regcomp(&reg_pid, "^0[cC][0-9A-Fa-f]{2}$", REG_EXTENDED);
		if (REG_NOERROR == regexec(&reg_pid, pid, 1, pamtch, 0)) {
			gdix_dbg("pid match BerlinB pid 0Cxx\n");
			chipType = TYPE_BERLINB;
		}
		regfree(&reg_pid);

		/* 0F60~0F7F is BerlinA */
		regcomp(&reg_pid, "^0[fF][6-7][0-9A-Fa-f]$", REG_EXTENDED);
		if (REG_NOERROR == regexec(&reg_pid, pid, 1, pamtch, 0)) {
			gdix_dbg("pid match BerlinA pid 0F60~0F7F\n");
			chipType = TYPE_BERLINA;
		}
		regfree(&reg_pid);		
	} else if (productionTypeName != NULL) {
		regcomp(&reg_x3xx, "^[0-9]3[0-9]{2}", REG_EXTENDED);
		regcomp(&reg_x5xx, "^[0-9]5[0-9]{2}", REG_EXTENDED);
		regcomp(&reg_x2xx, "^[0-9]2[0-9]{2}", REG_EXTENDED);
		regcomp(&reg_x8xx, "^[0-9]8[0-9]{2}", REG_EXTENDED);
		regcomp(&reg_x9xx, "^[0-9]9[0-9]{2}", REG_EXTENDED);
		regcomp(&reg_7868, "^7868", REG_EXTENDED);
		regcomp(&reg_brla, "^7726", REG_EXTENDED);

		if (REG_NOERROR == regexec(&reg_x3xx, productionTypeName, 1, pamtch, 0))
			chipType = TYPE_PHOENIX; // 7388 match
		else if (REG_NOERROR ==
				 regexec(&reg_x5xx, productionTypeName, 1, pamtch, 0))
			chipType = TYPE_NANJING; // 8589 match
		else if (REG_NOERROR ==
				 regexec(&reg_x2xx, productionTypeName, 1, pamtch, 0))
			chipType = TYPE_MOUSEPAD; // 7288 match
		else if (REG_NOERROR ==
				 regexec(&reg_x8xx, productionTypeName, 1, pamtch, 0))
			chipType = TYPE_NORMANDYL; // 7863 match
		else if (REG_NOERROR ==
				 regexec(&reg_x9xx, productionTypeName, 1, pamtch, 0))
			chipType = TYPE_BERLINB; // 9966 match
		else if (REG_NOERROR ==
				 regexec(&reg_7868, productionTypeName, 1, pamtch, 0))
			chipType = TYPE_YELLOWSTONE; // 7868 match
		else if (REG_NOERROR ==
				 regexec(&reg_brla, productionTypeName, 1, pamtch, 0))
			chipType = TYPE_BERLINA; // 7726 match
		else
			chipType = -1; // no match

		regfree(&reg_x3xx);
		regfree(&reg_x5xx);
		regfree(&reg_x2xx);
		regfree(&reg_x8xx);
		regfree(&reg_x9xx);
		regfree(&reg_7868);
		regfree(&reg_brla);
	}

	if (chipType < 0) {
		gdix_err("Find No match pid or product\n");
		delete gt_model;
		return -6;
	}

	/* i2c update */
	if (i2cAddr > 0 && chipType == TYPE_BERLINB) {
		gdix_do_fw_update(deviceName, firmwareName, i2cAddr);
		return 0;
	}

	if (chipType == TYPE_MOUSEPAD) {
		gt_model = new GTx2Device;
		fw_image = new GTX2FirmwareImage;
		gt_update = new GTx2Update;
		firmware_flag = 0x1400C; // update type:0x02,0x03,0x0e,0x10
	} else if (chipType == TYPE_NANJING) {
		gt_model = new GTx5Device;
		fw_image = new GTX5FirmwareImage;
		gt_update = new GTx5Update;
		firmware_flag = 0x1400C; // update type:0x02,0x03,0x03,0x10;
	} else if (chipType == TYPE_PHOENIX) {
		gt_model = new GTx3Device;
		fw_image = new GTX3FirmwareImage;
		gt_update = new GTx3Update;
		firmware_flag = 0x844; // update type:0x02,0x03,0x03,0x10;
	} else if (chipType == TYPE_NORMANDYL) {
		gt_model = new GTx8Device;
		fw_image = new GTX8FirmwareImage;
		gt_update = new GTx8Update;
		firmware_flag = 0x0C; // update type:0x02,0x03;
	} else if (chipType == TYPE_BERLINB) {
		gt_model = new GTx9Device;
		fw_image = new GTX9FirmwareImage;
		gt_update = new GTx9Update;
		firmware_flag = 0x0B; // don't update type:0x0B;
	} else if (chipType == TYPE_YELLOWSTONE) {
		gt_model = new GT7868QDevice;
		fw_image = new GT7868QFirmwareImage;
		gt_update = new GT7868QUpdate;
		firmware_flag = 0x0C; // update type:0x02,0x03;
	} else if (chipType == TYPE_BERLINA) {
		gt_model = new BrlADevice;
		fw_image = new BrlAFirmwareImage;
		gt_update = new BrlAUpdate;
	} else {
		if (pid != NULL)
			gdix_err("unsupported pid number:%s\n", pid);
		else
			gdix_err("unsupported product type number:%s\n",
					 productionTypeName);
		return -1;
	}

	/* get and print active FW version */
	if (printFirmwareProps) {
		char props_buf[60] = {0};
		ret = gt_model->GetFirmwareProps(deviceName, props_buf,
										 sizeof(props_buf));
		if (ret) {
			printf("Failed to read properties from device %s\n", deviceName);
			delete gt_model;
			return 1;
		} else {
			printf("%s\n", props_buf);
			delete gt_model;
			return 0;
		}
	}

	ret = gt_model->Open(deviceName);
	if (ret) {
		gdix_err("failed open device:%s\n", deviceName);
		delete gt_model;
		return -1;
	}

	if (printModuleId) {
		printf("module_id:%d\n", gt_model->GetSensorID());
		delete gt_model;
		return 0;
	}

	ret = fw_image->Initialize(firmwareName);
	if (ret) {
		gdix_err("Failed read firmware file:%s\n", firmwareName);
		delete gt_model;
		return -2;
	}

	ret = gt_update->Initialize(gt_model, fw_image);
	if (ret) {
		// gdix_err("Failed read firmware file:%s\n", firmwareName);
		delete gt_model;
		return -2;
	}

	// run update
	gt_update_para = new GTUpdatePara;
	gt_update_para->force = force;
	gt_update_para->firmwareFlag = firmware_flag;

	ret = gt_update->Run(gt_update_para);
	if (ret) {
		gdix_err("Firmware update err:ret=%d\n", ret);
		delete gt_model;
		return -4;
	}

	delete gt_model;
	delete fw_image;
	delete gt_update;

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq %rsi, %r14
movl %edi, %ebp
movq $0x0, 0x18(%rsp)
leaq 0x3c(%rsp), %r15
leaq 0xec0d(%rip), %r13      # 0x16388
movq $0x0, 0x10(%rsp)
xorl %r12d, %r12d
xorl %ebx, %ebx
movq $0x0, 0x30(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movl %ebp, %edi
movq %r14, %rsi
leaq 0xec7c(%rip), %rdx      # 0x1642c
leaq 0x19969(%rip), %rcx     # 0x21120
movq %r15, %r8
callq 0x51d0
leal -0x61(%rax), %ecx
cmpl $0x15, %ecx
ja 0x78d9
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movq 0x197ec(%rip), %rax     # 0x20fc8
movq (%rax), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x5150
movq %rax, 0x18(%rsp)
jmp 0x77a4
movb $0x1, %al
movq %rax, 0x28(%rsp)
jmp 0x77a4
movb $0x1, %al
movq %rax, 0x30(%rsp)
jmp 0x77a4
movb $0x1, 0x19a86(%rip)     # 0x21291
jmp 0x77a4
movq %rbx, %r12
movq 0x197b1(%rip), %rax     # 0x20fc8
movq (%rax), %rbx
movb (%rbx), %al
testb %al, %al
je 0x7837
incq %rbx
movzbl %al, %edi
callq 0x51a0
movb %al, -0x1(%rbx)
movb (%rbx), %al
incq %rbx
testb %al, %al
jne 0x7823
movq 0x1978a(%rip), %rax     # 0x20fc8
movq (%rax), %rax
cmpb $0x1, 0x19a49(%rip)     # 0x21291
movq %r12, %rbx
movq %rax, %r12
jne 0x77a4
movq 0x1975d(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xebd6(%rip), %rsi      # 0x1643b
leaq 0xebeb(%rip), %rdx      # 0x16457
movl $0xb5, %ecx
movq %r12, %r8
jmp 0x78cd
movq 0x1974b(%rip), %rax     # 0x20fc8
movq (%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x77a4
movb $0x1, %al
movq %rax, 0x20(%rsp)
jmp 0x77a4
movq 0x1972b(%rip), %rax     # 0x20fc8
movq (%rax), %rbx
cmpb $0x1, 0x199ea(%rip)     # 0x21291
jne 0x77a4
movq 0x19704(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xeb9e(%rip), %rsi      # 0x1645c
leaq 0xeb92(%rip), %rdx      # 0x16457
movl $0xb9, %ecx
movq %rbx, %r8
xorl %eax, %eax
callq 0x5180
jmp 0x77a4
cmpl $-0x1, %eax
jne 0x77a4
movq 0x196f7(%rip), %rax     # 0x20fe0
movslq (%rax), %rax
cmpl %ebp, %eax
jge 0x7a82
movq (%r14,%rax,8), %r14
cmpb $0x1, 0x19992(%rip)     # 0x21291
jne 0x7a85
movq 0x196ac(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xeb6b(%rip), %rsi      # 0x16481
leaq 0xeb3a(%rip), %rdx      # 0x16457
movl $0xcb, %ecx
movq %r14, %r8
xorl %eax, %eax
callq 0x5180
jmp 0x7a85
movq 0x19680(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xf2b6(%rip), %rsi      # 0x16bf8
leaq 0xf2c8(%rip), %rdx      # 0x16c11
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x5180
jmp 0x7a6e
movq (%r14), %rdx
movq 0x19657(%rip), %r14     # 0x20fb8
movq (%r14), %rdi
leaq 0xf035(%rip), %rsi      # 0x169a0
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x5180
movq (%r14), %rcx
leaq 0xf044(%rip), %rdi      # 0x169c2
movl $0x1f, %esi
movl $0x1, %edx
callq 0x5200
movq (%r14), %rcx
leaq 0xf04b(%rip), %rdi      # 0x169e2
movl $0x3c, %esi
movl $0x1, %edx
callq 0x5200
movq (%r14), %rcx
leaq 0xf06f(%rip), %rdi      # 0x16a1f
movl $0x4b, %esi
movl $0x1, %edx
callq 0x5200
movq (%r14), %rcx
leaq 0xf0a2(%rip), %rdi      # 0x16a6b
movl $0x4d, %esi
movl $0x1, %edx
callq 0x5200
movq (%r14), %rcx
leaq 0xf0d7(%rip), %rdi      # 0x16ab9
movl $0x25, %esi
movl $0x1, %edx
callq 0x5200
movq (%r14), %rcx
leaq 0xf0e4(%rip), %rdi      # 0x16adf
movl $0x20, %esi
movl $0x1, %edx
callq 0x5200
movq (%r14), %rcx
leaq 0xf0ec(%rip), %rdi      # 0x16b00
movl $0x3c, %esi
movl $0x1, %edx
callq 0x5200
movq (%r14), %rcx
leaq 0xf110(%rip), %rdi      # 0x16b3d
movl $0x3a, %esi
movl $0x1, %edx
callq 0x5200
movq (%r14), %rcx
leaq 0xf132(%rip), %rdi      # 0x16b78
movl $0x27, %esi
movl $0x1, %edx
callq 0x5200
movq (%r14), %rcx
leaq 0xf141(%rip), %rdi      # 0x16ba0
movl $0x57, %esi
movl $0x1, %edx
callq 0x5200
movl %ebx, %eax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
movq %rbx, %rax
orq %r12, %rax
jne 0x7aa2
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpb $0x1, 0x197f8(%rip)     # 0x21291
jne 0x7a6e
callq 0x52c8
jmp 0x7a6e
testb $0x1, 0x28(%rsp)
jne 0x7aca
testb $0x1, 0x20(%rsp)
jne 0x7aca
testq %r14, %r14
jne 0x7aca
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpb $0x1, 0x197d0(%rip)     # 0x21291
jne 0x7a6e
callq 0x5274
jmp 0x7a6e
testq %r12, %r12
je 0x7fa9
movq %rbx, %r15
leaq 0xea20(%rip), %rsi      # 0x164fd
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5100
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq 0x5120
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x7b44
cmpb $0x1, 0x1977a(%rip)     # 0x21291
movl $0x0, %ebp
jne 0x7b44
movq 0x19493(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe9df(%rip), %rsi      # 0x1650e
leaq 0xe921(%rip), %rdx      # 0x16457
xorl %ebp, %ebp
movl $0xdc, %ecx
xorl %eax, %eax
callq 0x5180
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xe9e3(%rip), %rsi      # 0x1653b
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5100
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x7bb5
cmpb $0x1, 0x19709(%rip)     # 0x21291
movl $0x0, %ebp
jne 0x7bb5
movq 0x19422(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe9b1(%rip), %rsi      # 0x16551
leaq 0xe8b0(%rip), %rdx      # 0x16457
xorl %ebp, %ebp
movl $0xe4, %ecx
xorl %eax, %eax
callq 0x5180
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xe9b5(%rip), %rsi      # 0x1657e
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5100
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x7c24
movl $0x2, %ebp
cmpb $0x1, 0x19693(%rip)     # 0x21291
jne 0x7c24
movq 0x193b1(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe981(%rip), %rsi      # 0x16592
leaq 0xe83f(%rip), %rdx      # 0x16457
movl $0xec, %ecx
xorl %eax, %eax
callq 0x5180
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xe988(%rip), %rsi      # 0x165c0
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5100
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x7c93
movl $0x2, %ebp
cmpb $0x1, 0x19624(%rip)     # 0x21291
jne 0x7c93
movq 0x19342(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe956(%rip), %rsi      # 0x165d6
leaq 0xe7d0(%rip), %rdx      # 0x16457
movl $0xf4, %ecx
xorl %eax, %eax
callq 0x5180
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xe95d(%rip), %rsi      # 0x16604
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5100
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x7d02
movl $0x3, %ebp
cmpb $0x1, 0x195b5(%rip)     # 0x21291
jne 0x7d02
movq 0x192d3(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe923(%rip), %rsi      # 0x16612
leaq 0xe761(%rip), %rdx      # 0x16457
movl $0xfc, %ecx
xorl %eax, %eax
callq 0x5180
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xe92d(%rip), %rsi      # 0x16643
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5100
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x7d71
movl $0x3, %ebp
cmpb $0x1, 0x19546(%rip)     # 0x21291
jne 0x7d71
movq 0x19264(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe8fd(%rip), %rsi      # 0x1665b
leaq 0xe6f2(%rip), %rdx      # 0x16457
movl $0x104, %ecx            # imm = 0x104
xorl %eax, %eax
callq 0x5180
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xe907(%rip), %rsi      # 0x1668c
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5100
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x7de0
movl $0x4, %ebp
cmpb $0x1, 0x194d7(%rip)     # 0x21291
jne 0x7de0
movq 0x191f5(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe8dd(%rip), %rsi      # 0x166aa
leaq 0xe683(%rip), %rdx      # 0x16457
movl $0x10c, %ecx            # imm = 0x10C
xorl %eax, %eax
callq 0x5180
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xe8e8(%rip), %rsi      # 0x166dc
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5100
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x7e4f
movl $0x6, %ebp
cmpb $0x1, 0x19468(%rip)     # 0x21291
jne 0x7e4f
movq 0x19186(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe8b9(%rip), %rsi      # 0x166f5
leaq 0xe614(%rip), %rdx      # 0x16457
movl $0x114, %ecx            # imm = 0x114
xorl %eax, %eax
callq 0x5180
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xe8bf(%rip), %rsi      # 0x16722
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5100
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x7ebe
movl $0x6, %ebp
cmpb $0x1, 0x193f9(%rip)     # 0x21291
jne 0x7ebe
movq 0x19117(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe88e(%rip), %rsi      # 0x16739
leaq 0xe5a5(%rip), %rdx      # 0x16457
movl $0x11c, %ecx            # imm = 0x11C
xorl %eax, %eax
callq 0x5180
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xe899(%rip), %rsi      # 0x1676b
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5100
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x7f2d
movl $0x6, %ebp
cmpb $0x1, 0x1938a(%rip)     # 0x21291
jne 0x7f2d
movq 0x190a8(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe867(%rip), %rsi      # 0x16781
leaq 0xe536(%rip), %rdx      # 0x16457
movl $0x124, %ecx            # imm = 0x124
xorl %eax, %eax
callq 0x5180
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xe86d(%rip), %rsi      # 0x167ae
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5100
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
movq %r15, %rbx
jne 0x7f9f
movl $0x5, %ebp
cmpb $0x1, 0x19318(%rip)     # 0x21291
jne 0x7f9f
movq 0x19036(%rip), %rax     # 0x20fb8
movq (%rax), %rdi
leaq 0xe83a(%rip), %rsi      # 0x167c6
leaq 0xe4c4(%rip), %rdx      # 0x16457
movl $0x12c, %ecx            # imm = 0x12C
xorl %eax, %eax
callq 0x5180
leaq 0x40(%rsp), %rdi
jmp 0x81dd
testq %rbx, %rbx
je 0x8166
leaq 0xe83f(%rip), %rsi      # 0x167f8
movq %rbx, %r15
leaq 0x208(%rsp), %rbx
movq %rbx, %rdi
movl $0x1, %edx
callq 0x5100
leaq 0xe830(%rip), %rsi      # 0x16808
leaq 0x1c8(%rsp), %rdi
movl $0x1, %edx
callq 0x5100
leaq 0xe827(%rip), %rsi      # 0x16818
leaq 0x188(%rsp), %rdi
movl $0x1, %edx
callq 0x5100
leaq 0xe81e(%rip), %rsi      # 0x16828
leaq 0x148(%rsp), %rdi
movl $0x1, %edx
callq 0x5100
leaq 0xe815(%rip), %rsi      # 0x16838
leaq 0x108(%rsp), %rdi
movl $0x1, %edx
callq 0x5100
leaq 0xe80c(%rip), %rsi      # 0x16848
leaq 0xc8(%rsp), %rdi
movl $0x1, %edx
callq 0x5100
leaq 0xe7f9(%rip), %rsi      # 0x1684e
leaq 0x88(%rsp), %rdi
movl $0x1, %edx
callq 0x5100
leaq 0x8(%rsp), %rcx
xorl %ebp, %ebp
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rbx
movq %r15, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
je 0x8187
leaq 0x1c8(%rsp), %rdi
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rsi
xorl %r8d, %r8d
callq 0x5120
movl $0x1, %ebp
testl %eax, %eax
je 0x8187
leaq 0x188(%rsp), %rdi
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
je 0x816d
leaq 0x148(%rsp), %rdi
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
je 0x8174
leaq 0x108(%rsp), %rdi
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
je 0x817b
leaq 0xc8(%rsp), %rdi
leaq 0x8(%rsp), %rcx
xorl %ebp, %ebp
movl $0x1, %edx
movq %rbx, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
je 0x8182
leaq 0x88(%rsp), %rdi
leaq 0x8(%rsp), %rcx
movl $0x1, %edx
movq %rbx, %rsi
xorl %r8d, %r8d
callq 0x5120
negl %eax
sbbl %ebp, %ebp
orl $0x5, %ebp
jmp 0x8187
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x81e2
movl $0x2, %ebp
jmp 0x8187
movl $0x3, %ebp
jmp 0x8187
movl $0x6, %ebp
jmp 0x8187
movl $0x4, %ebp
leaq 0x208(%rsp), %rdi
callq 0x50d0
leaq 0x1c8(%rsp), %rdi
callq 0x50d0
leaq 0x188(%rsp), %rdi
callq 0x50d0
leaq 0x148(%rsp), %rdi
callq 0x50d0
leaq 0x108(%rsp), %rdi
callq 0x50d0
leaq 0xc8(%rsp), %rdi
callq 0x50d0
leaq 0x88(%rsp), %rdi
callq 0x50d0
testl %ebp, %ebp
js 0x820b
cmpb $0x0, 0x18(%rsp)
je 0x8227
cmpl $0x6, %ebp
jne 0x8227
movzbl 0x18(%rsp), %edx
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x11524
xorl %ebx, %ebx
jmp 0x7a6e
movl $0xfffffffa, %ebx       # imm = 0xFFFFFFFA
cmpb $0x1, 0x1907a(%rip)     # 0x21291
jne 0x7a6e
callq 0x529e
jmp 0x7a6e
cmpl $0x3, %ebp
ja 0x8397
movl %ebp, %eax
leaq 0xe1a7(%rip), %rcx      # 0x163e0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x48, %edi
callq 0x50c0
movq %rax, %r15
movq %rax, %rdi
callq 0xb960
movq 0x10(%rsp), %rbp
movl $0x38, %edi
callq 0x50c0
movq %rax, %r12
movq %rax, %rdi
callq 0xbcec
movl $0x20, %edi
callq 0x50c0
movq %rax, %r13
movl $0x844, %ebx            # imm = 0x844
movq %rax, %rdi
callq 0xbec4
jmp 0x84aa
movl $0x48, %edi
callq 0x50c0
movq %rax, %r15
movq %rax, %rdi
callq 0xd244
movq 0x10(%rsp), %rbp
leaq 0x17d87(%rip), %rax     # 0x20038
addq $0x10, %rax
movq %rax, (%r15)
movl $0x38, %edi
callq 0x50c0
movq %rax, %r12
movq %rax, %rdi
callq 0xa910
movl $0x20, %edi
callq 0x50c0
movq %rax, %r13
movl $0x1400c, %ebx          # imm = 0x1400C
movq %rax, %rdi
callq 0xab2c
jmp 0x84aa
movl $0x48, %edi
callq 0x50c0
movq %rax, %r15
movq %rax, %rdi
callq 0xe6fc
movq 0x10(%rsp), %rbp
movl $0x38, %edi
callq 0x50c0
movq %rax, %r12
movq %rax, %rdi
callq 0xeb58
movl $0x20, %edi
callq 0x50c0
movq %rax, %r13
movl $0xc, %ebx
movq %rax, %rdi
callq 0xed30
jmp 0x84aa
movl $0x48, %edi
callq 0x50c0
movq %rax, %r15
movq %rax, %rdi
callq 0xd244
movq 0x10(%rsp), %rbp
movl $0x38, %edi
callq 0x50c0
movq %rax, %r12
movq %rax, %rdi
callq 0xdc9c
movl $0x20, %edi
callq 0x50c0
movq %rax, %r13
movq %rax, %rdi
callq 0x7510
leaq 0x1830b(%rip), %rax     # 0x20690
addq $0x10, %rax
movq %rax, (%r13)
movl $0x1400c, %ebx          # imm = 0x1400C
jmp 0x84aa
cmpl $0x6, %ebp
jne 0x83f9
movl $0x30, %edi
callq 0x50c0
movq %rax, %r15
movq %rax, %rdi
callq 0x1022c
movl $0x4e0, %edi            # imm = 0x4E0
callq 0x50c0
movq %rax, %r12
movq %rax, %rdi
callq 0x10e1c
movq 0x10(%rsp), %rbp
movl $0x20, %edi
callq 0x50c0
movq %rax, %r13
movq %rax, %rdi
callq 0x7510
leaq 0x18721(%rip), %rax     # 0x20b08
addq $0x10, %rax
movq %rax, (%r13)
movl $0xb, %ebx
jmp 0x84aa
cmpl $0x5, %ebp
je 0x8452
cmpl $0x4, %ebp
jne 0x85d4
movl $0x48, %edi
callq 0x50c0
movq %rax, %r15
movq %rax, %rdi
callq 0x8770
movl $0x38, %edi
callq 0x50c0
movq %rax, %r12
movq %rax, %rdi
callq 0x8db0
movq 0x10(%rsp), %rbp
movl $0x20, %edi
callq 0x50c0
movq %rax, %r13
movl $0xc, %ebx
movq %rax, %rdi
callq 0x8f88
jmp 0x84aa
movl $0x30, %edi
callq 0x50c0
movq %rax, %r15
movq %rax, %rdi
callq 0x13a28
movl $0x4e0, %edi            # imm = 0x4E0
callq 0x50c0
movq %rax, %r12
movq %rax, %rdi
callq 0x1460c
movq 0x10(%rsp), %rbp
movl $0x20, %edi
callq 0x50c0
movq %rax, %r13
movq %rax, %rdi
callq 0x7510
leaq 0x188a3(%rip), %rax     # 0x20d40
addq $0x10, %rax
movq %rax, (%r13)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testb $0x1, 0x20(%rsp)
je 0x84f5
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rdx
movups %xmm0, 0x2c(%rdx)
movaps %xmm0, 0x20(%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, (%rdx)
movq (%r15), %rax
movq %r15, %rdi
movq %rbp, %rsi
movl $0x3c, %ecx
callq *0x58(%rax)
testl %eax, %eax
je 0x8525
leaq 0xe400(%rip), %rdi      # 0x168e4
movq %rbp, %rsi
xorl %eax, %eax
callq 0x5040
movl $0x1, %ebx
jmp 0x8559
movq (%r15), %rax
movq %r15, %rdi
movq %rbp, %rsi
callq *0x10(%rax)
testl %eax, %eax
je 0x8533
cmpb $0x1, 0x18d85(%rip)     # 0x21291
je 0x8615
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x7a6e
leaq 0x40(%rsp), %rdi
callq 0x51b0
xorl %ebx, %ebx
jmp 0x8559
testb $0x1, 0x28(%rsp)
je 0x8567
movq (%r15), %rax
movq %r15, %rdi
callq *0x80(%rax)
movzbl %al, %esi
leaq 0xe3e6(%rip), %rdi      # 0x16936
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x5040
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
jmp 0x7a6e
movq (%r12), %rax
movq %r12, %rdi
movq %r14, %rsi
callq *(%rax)
testl %eax, %eax
je 0x85a9
cmpb $0x1, 0x18d13(%rip)     # 0x21291
jne 0x85c1
movq 0x18a51(%rip), %rax     # 0x20fd8
movq (%rax), %rdi
leaq 0xe3b3(%rip), %rsi      # 0x16944
leaq 0xdebf(%rip), %rdx      # 0x16457
movl $0x1af, %ecx            # imm = 0x1AF
movq %r14, %r8
xorl %eax, %eax
callq 0x5180
jmp 0x85c1
movq (%r13), %rax
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *0x10(%rax)
testl %eax, %eax
je 0x8641
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
jmp 0x7a6e
movb 0x18cb7(%rip), %al      # 0x21291
testq %r12, %r12
je 0x8682
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testb %al, %al
je 0x7a6e
movq 0x189e1(%rip), %rax     # 0x20fd8
movq (%rax), %rdi
leaq 0xe282(%rip), %rsi      # 0x16883
leaq 0xde4f(%rip), %rdx      # 0x16457
movl $0x189, %ecx            # imm = 0x189
movq %r12, %r8
jmp 0x86af
movq 0x189bc(%rip), %rax     # 0x20fd8
movq (%rax), %rdi
leaq 0xe2e8(%rip), %rsi      # 0x1690e
leaq 0xde2a(%rip), %rdx      # 0x16457
movl $0x1a2, %ecx            # imm = 0x1A2
movq %rbp, %r8
xorl %eax, %eax
callq 0x5180
jmp 0x8512
movl $0x8, %edi
callq 0x50c0
movq 0x30(%rsp), %rcx
movb %cl, (%rax)
movl %ebx, 0x4(%rax)
movq (%r13), %rcx
movq %r13, %rdi
movq %rax, %rsi
callq *0x18(%rcx)
testl %eax, %eax
je 0x86bb
cmpb $0x1, 0x18c24(%rip)     # 0x21291
je 0x86dd
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
movl $0xfffffffc, %ebx       # imm = 0xFFFFFFFC
jmp 0x7a6e
movq %rbx, %r8
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testb %al, %al
je 0x7a6e
movq 0x1893f(%rip), %rax     # 0x20fd8
movq (%rax), %rdi
leaq 0xe20c(%rip), %rsi      # 0x168af
leaq 0xddad(%rip), %rdx      # 0x16457
movl $0x18c, %ecx            # imm = 0x18C
xorl %eax, %eax
callq 0x5180
jmp 0x7a6e
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
movq (%r12), %rax
movq %r12, %rdi
callq *0x50(%rax)
movq (%r13), %rax
movq %r13, %rdi
callq *0x8(%rax)
jmp 0x8204
movq 0x188f4(%rip), %rcx     # 0x20fd8
movq (%rcx), %rdi
leaq 0xe285(%rip), %rsi      # 0x16973
leaq 0xdd62(%rip), %rdx      # 0x16457
movl $0x1c2, %ecx            # imm = 0x1C2
movl %eax, %r8d
xorl %eax, %eax
callq 0x5180
jmp 0x866f
jmp 0x873d
jmp 0x8717
jmp 0x8721
jmp 0x873d
jmp 0x874a
jmp 0x8757
jmp 0x873d
movq %rax, %rbx
movl $0x4e0, %esi            # imm = 0x4E0
jmp 0x8752
movq %rax, %rbx
movl $0x30, %esi
jmp 0x875f
jmp 0x873d
jmp 0x874a
jmp 0x8757
jmp 0x873d
jmp 0x874a
jmp 0x8757
jmp 0x873d
jmp 0x874a
jmp 0x8757
movq %rax, %rbx
movl $0x20, %esi
movq %r13, %rdi
jmp 0x8762
movq %rax, %rbx
movl $0x38, %esi
movq %r12, %rdi
jmp 0x8762
movq %rax, %rbx
movl $0x48, %esi
movq %r15, %rdi
callq 0x50e0
movq %rbx, %rdi
callq 0x51f0
nop