// File: /workspace/github_cpp_makefile_star2_O2/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, 0x20(%rsp)
leaq 0x1a4e2(%rip), %r15     # 0x20120
leaq 0x3c(%rsp), %r12
leaq 0xf73e(%rip), %r13      # 0x15388
movq $0x0, 0x30(%rsp)
movq $0x0, 0x8(%rsp)
xorl %ebx, %ebx
movq $0x0, 0x10(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x18(%rsp)
movl %ebp, %edi
movq %r14, %rsi
leaq 0xf7a7(%rip), %rdx      # 0x1542c
movq %r15, %rcx
movq %r12, %r8
callq 0x51d0
leal -0x61(%rax), %ecx
cmpl $0x15, %ecx
ja 0x5d9c
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movq 0x1a31b(%rip), %rax     # 0x1ffc8
movq (%rax), %rdi
xorl %esi, %esi
pushq $0x10
popq %rdx
callq 0x5150
movq %rax, 0x30(%rsp)
jmp 0x5c79
movb $0x1, %al
movq %rax, 0x18(%rsp)
jmp 0x5c79
movb $0x1, %al
movq %rax, 0x28(%rsp)
jmp 0x5c79
movb $0x1, 0x1a5b7(%rip)     # 0x20291
jmp 0x5c79
movq 0x1a2e5(%rip), %rax     # 0x1ffc8
movq (%rax), %rbx
movzbl (%rbx), %edi
testl %edi, %edi
je 0x5cf9
callq 0x51a0
movb %al, (%rbx)
incq %rbx
jmp 0x5ce6
movq 0x1a2c8(%rip), %rax     # 0x1ffc8
movq (%rax), %rbx
cmpb $0x1, 0x1a587(%rip)     # 0x20291
jne 0x5c79
movq 0x1a2a1(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xf71a(%rip), %rsi      # 0x1543b
leaq 0xf72f(%rip), %rdx      # 0x15457
movl $0xb5, %ecx
movq %rbx, %r8
jmp 0x5d90
movq 0x1a28f(%rip), %rax     # 0x1ffc8
movq (%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0x5c79
movb $0x1, %al
movq %rax, 0x20(%rsp)
jmp 0x5c79
movq 0x1a26f(%rip), %rax     # 0x1ffc8
movq (%rax), %rax
movq %rax, 0x10(%rsp)
cmpb $0x1, 0x1a529(%rip)     # 0x20291
jne 0x5c79
movq 0x1a243(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xf6dd(%rip), %rsi      # 0x1545c
leaq 0xf6d1(%rip), %rdx      # 0x15457
movl $0xb9, %ecx
movq 0x10(%rsp), %r8
xorl %eax, %eax
callq 0x5180
jmp 0x5c79
cmpl $-0x1, %eax
jne 0x5c79
movq 0x1a234(%rip), %rax     # 0x1ffe0
movslq (%rax), %rax
cmpl %ebp, %eax
jge 0x5f29
movq (%r14,%rax,8), %r14
cmpb $0x1, 0x1a4cf(%rip)     # 0x20291
movq 0x10(%rsp), %r13
jne 0x5f31
movq 0x1a1e4(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xf6a3(%rip), %rsi      # 0x15481
leaq 0xf672(%rip), %rdx      # 0x15457
movl $0xcb, %ecx
movq %r14, %r8
xorl %eax, %eax
callq 0x5180
jmp 0x5f31
movq 0x1a1b8(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xfd8d(%rip), %rsi      # 0x15b97
leaq 0xfd9f(%rip), %rdx      # 0x15bb0
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x5180
jmp 0x5f15
movq (%r14), %rdx
movq 0x1a18f(%rip), %r15     # 0x1ffb8
movq (%r15), %rdi
leaq 0xfb0c(%rip), %rsi      # 0x1593f
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x5180
movq (%r15), %rcx
leaq 0xfb1b(%rip), %rdi      # 0x15961
pushq $0x1f
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x5200
movq (%r15), %rcx
leaq 0xfb23(%rip), %rdi      # 0x15981
pushq $0x3c
popq %r14
movq %r14, %rsi
movq %rbx, %rdx
callq 0x5200
movq (%r15), %rcx
leaq 0xfb47(%rip), %rdi      # 0x159be
pushq $0x4b
popq %rsi
movq %rbx, %rdx
callq 0x5200
movq (%r15), %rcx
leaq 0xfb7e(%rip), %rdi      # 0x15a0a
pushq $0x4d
popq %rsi
movq %rbx, %rdx
callq 0x5200
movq (%r15), %rcx
leaq 0xfbb7(%rip), %rdi      # 0x15a58
pushq $0x25
popq %rsi
movq %rbx, %rdx
callq 0x5200
movq (%r15), %rcx
leaq 0xfbc8(%rip), %rdi      # 0x15a7e
pushq $0x20
popq %rsi
movq %rbx, %rdx
callq 0x5200
movq (%r15), %rcx
leaq 0xfbd4(%rip), %rdi      # 0x15a9f
movq %r14, %rsi
movq %rbx, %rdx
callq 0x5200
movq (%r15), %rcx
leaq 0xfbfc(%rip), %rdi      # 0x15adc
pushq $0x3a
popq %rsi
movq %rbx, %rdx
callq 0x5200
movq (%r15), %rcx
leaq 0xfc22(%rip), %rdi      # 0x15b17
pushq $0x27
popq %rsi
movq %rbx, %rdx
callq 0x5200
movq (%r15), %rcx
leaq 0xfc35(%rip), %rdi      # 0x15b3f
pushq $0x57
popq %rsi
movq %rbx, %rdx
callq 0x5200
movl %ebp, %eax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
movq 0x10(%rsp), %r13
movq %r13, %rax
orq %rbx, %rax
pushq $-0x1
popq %rbp
jne 0x5f67
cmpb $0x1, 0x1a34e(%rip)     # 0x20291
jne 0x5f15
movq 0x1a08c(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0xf54e(%rip), %rsi      # 0x154a4
leaq 0xf4fa(%rip), %rdx      # 0x15457
movl $0xce, %ecx
jmp 0x66af
movq 0x18(%rsp), %rax
orb 0x20(%rsp), %al
testb $0x1, %al
jne 0x5fa4
testq %r14, %r14
jne 0x5fa4
cmpb $0x1, 0x1a311(%rip)     # 0x20291
jne 0x5f15
movq 0x1a04f(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0xf544(%rip), %rsi      # 0x154d7
leaq 0xf4bd(%rip), %rdx      # 0x15457
movl $0xd2, %ecx
jmp 0x66af
testq %rbx, %rbx
je 0x5feb
leaq 0xf54d(%rip), %rsi      # 0x154fd
movq %rbx, %r15
leaq 0x40(%rsp), %rbx
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x5100
pushq $0x1
popq %rdx
movq %rsp, %rcx
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r15, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
je 0x6185
pushq $-0x1
popq %r12
jmp 0x61b5
testq %r13, %r13
je 0x6682
leaq 0xf7fd(%rip), %rsi      # 0x157f8
leaq 0x208(%rsp), %r15
pushq $0x1
popq %rbx
movq %r15, %rdi
movl %ebx, %edx
callq 0x5100
leaq 0xf7f1(%rip), %rsi      # 0x15808
leaq 0x1c8(%rsp), %rdi
movl %ebx, %edx
callq 0x5100
leaq 0xf7eb(%rip), %rsi      # 0x15818
leaq 0x188(%rsp), %rdi
movl %ebx, %edx
callq 0x5100
leaq 0xf7e5(%rip), %rsi      # 0x15828
leaq 0x148(%rsp), %rdi
movl %ebx, %edx
callq 0x5100
leaq 0xf7df(%rip), %rsi      # 0x15838
leaq 0x108(%rsp), %rdi
movl %ebx, %edx
callq 0x5100
leaq 0xf7d9(%rip), %rsi      # 0x15848
leaq 0xc8(%rsp), %rdi
movl %ebx, %edx
callq 0x5100
leaq 0xf7c9(%rip), %rsi      # 0x1584e
leaq 0x88(%rsp), %rdi
movl %ebx, %edx
callq 0x5100
pushq $0x1
popq %rdx
movq %rsp, %rcx
xorl %r12d, %r12d
movq %r15, %rdi
movq %r13, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
je 0x65fc
leaq 0x1c8(%rsp), %rdi
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %r13, %rsi
xorl %r8d, %r8d
callq 0x5120
movl %ebx, %r12d
testl %eax, %eax
je 0x65fc
leaq 0x188(%rsp), %rdi
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %r13, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
je 0x65ec
leaq 0x148(%rsp), %rdi
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %r13, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
je 0x65f0
leaq 0x108(%rsp), %rdi
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %r13, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
je 0x65f4
leaq 0xc8(%rsp), %rdi
pushq $0x1
popq %rdx
movq %rsp, %rcx
xorl %r12d, %r12d
movq %r13, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
je 0x65f8
leaq 0x88(%rsp), %rdi
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %r13, %rsi
xorl %r8d, %r8d
callq 0x5120
negl %eax
sbbl %r12d, %r12d
orl $0x5, %r12d
jmp 0x65fc
cmpb $0x1, 0x1a105(%rip)     # 0x20291
jne 0x61b5
movq 0x19e23(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xf36f(%rip), %rsi      # 0x1550e
leaq 0xf2b1(%rip), %rdx      # 0x15457
xorl %r12d, %r12d
movl $0xdc, %ecx
xorl %eax, %eax
callq 0x5180
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xf372(%rip), %rsi      # 0x1553b
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x5100
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %rbx, %rdi
movq %r15, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x6222
cmpb $0x1, 0x1a09e(%rip)     # 0x20291
movl $0x0, %r12d
jne 0x6222
movq 0x19db6(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xf345(%rip), %rsi      # 0x15551
leaq 0xf244(%rip), %rdx      # 0x15457
xorl %r12d, %r12d
movl $0xe4, %ecx
xorl %eax, %eax
callq 0x5180
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xf348(%rip), %rsi      # 0x1557e
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x5100
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %rbx, %rdi
movq %r15, %r13
movq %r15, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x6290
pushq $0x2
popq %r12
cmpb $0x1, 0x1a02a(%rip)     # 0x20291
jne 0x628d
movq 0x19d48(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xf318(%rip), %rsi      # 0x15592
leaq 0xf1d6(%rip), %rdx      # 0x15457
movl $0xec, %ecx
xorl %eax, %eax
callq 0x5180
movq %r15, %r13
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xf31c(%rip), %rsi      # 0x155c0
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x5100
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %rbx, %rdi
movq %r13, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x62fb
pushq $0x2
popq %r12
cmpb $0x1, 0x19fbf(%rip)     # 0x20291
jne 0x62f8
movq 0x19cdd(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xf2f1(%rip), %rsi      # 0x155d6
leaq 0xf16b(%rip), %rdx      # 0x15457
movl $0xf4, %ecx
xorl %eax, %eax
callq 0x5180
movq %r15, %r13
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xf2f5(%rip), %rsi      # 0x15604
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x5100
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %rbx, %rdi
movq %r13, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x6366
pushq $0x3
popq %r12
cmpb $0x1, 0x19f54(%rip)     # 0x20291
jne 0x6363
movq 0x19c72(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xf2c2(%rip), %rsi      # 0x15612
leaq 0xf100(%rip), %rdx      # 0x15457
movl $0xfc, %ecx
xorl %eax, %eax
callq 0x5180
movq %r15, %r13
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xf2c9(%rip), %rsi      # 0x15643
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x5100
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %rbx, %rdi
movq %r13, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x63d1
pushq $0x3
popq %r12
cmpb $0x1, 0x19ee9(%rip)     # 0x20291
jne 0x63ce
movq 0x19c07(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xf2a0(%rip), %rsi      # 0x1565b
leaq 0xf095(%rip), %rdx      # 0x15457
movl $0x104, %ecx            # imm = 0x104
xorl %eax, %eax
callq 0x5180
movq %r15, %r13
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xf2a7(%rip), %rsi      # 0x1568c
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x5100
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %rbx, %rdi
movq %r13, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x643c
pushq $0x4
popq %r12
cmpb $0x1, 0x19e7e(%rip)     # 0x20291
jne 0x6439
movq 0x19b9c(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xf284(%rip), %rsi      # 0x156aa
leaq 0xf02a(%rip), %rdx      # 0x15457
movl $0x10c, %ecx            # imm = 0x10C
xorl %eax, %eax
callq 0x5180
movq %r15, %r13
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xf28c(%rip), %rsi      # 0x156dc
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x5100
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %rbx, %rdi
movq %r13, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x64a7
pushq $0x6
popq %r12
cmpb $0x1, 0x19e13(%rip)     # 0x20291
jne 0x64a4
movq 0x19b31(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xf264(%rip), %rsi      # 0x156f5
leaq 0xefbf(%rip), %rdx      # 0x15457
movl $0x114, %ecx            # imm = 0x114
xorl %eax, %eax
callq 0x5180
movq %r15, %r13
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xf267(%rip), %rsi      # 0x15722
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x5100
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %rbx, %rdi
movq %r13, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x6512
pushq $0x6
popq %r12
cmpb $0x1, 0x19da8(%rip)     # 0x20291
jne 0x650f
movq 0x19ac6(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xf23d(%rip), %rsi      # 0x15739
leaq 0xef54(%rip), %rdx      # 0x15457
movl $0x11c, %ecx            # imm = 0x11C
xorl %eax, %eax
callq 0x5180
movq %r15, %r13
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xf245(%rip), %rsi      # 0x1576b
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x5100
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %rbx, %rdi
movq %r13, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x657d
pushq $0x6
popq %r12
cmpb $0x1, 0x19d3d(%rip)     # 0x20291
jne 0x657a
movq 0x19a5b(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xf21a(%rip), %rsi      # 0x15781
leaq 0xeee9(%rip), %rdx      # 0x15457
movl $0x124, %ecx            # imm = 0x124
xorl %eax, %eax
callq 0x5180
movq %r15, %r13
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x50d0
leaq 0xf21d(%rip), %rsi      # 0x157ae
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x5100
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %rbx, %rdi
movq %r13, %rsi
xorl %r8d, %r8d
callq 0x5120
testl %eax, %eax
jne 0x65e5
pushq $0x5
popq %r12
cmpb $0x1, 0x19cd2(%rip)     # 0x20291
jne 0x65e5
movq 0x199f0(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xf1f4(%rip), %rsi      # 0x157c6
leaq 0xee7e(%rip), %rdx      # 0x15457
movl $0x12c, %ecx            # imm = 0x12C
xorl %eax, %eax
callq 0x5180
leaq 0x40(%rsp), %rdi
jmp 0x6652
pushq $0x2
jmp 0x65fa
pushq $0x3
jmp 0x65fa
pushq $0x6
jmp 0x65fa
pushq $0x4
popq %r12
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 %r12d, %r12d
js 0x6682
movq 0x30(%rsp), %rax
testb %al, %al
je 0x66bb
cmpl $0x6, %r12d
jne 0x66bb
movzbl %al, %edx
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x10147
xorl %ebp, %ebp
jmp 0x5f15
pushq $-0x6
popq %rbp
cmpb $0x1, 0x19c05(%rip)     # 0x20291
jne 0x5f15
movq 0x1993f(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0xf1b1(%rip), %rsi      # 0x15854
leaq 0xedad(%rip), %rdx      # 0x15457
movl $0x15a, %ecx            # imm = 0x15A
xorl %eax, %eax
callq 0x5180
jmp 0x5f15
cmpl $0x3, %r12d
ja 0x67e1
movl %r12d, %eax
leaq 0xed11(%rip), %rcx      # 0x153e0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x48
popq %rdi
callq 0x50c0
movq %rax, %r15
movq %rax, %rdi
callq 0xa104
pushq $0x38
popq %rdi
callq 0x50c0
movq %rax, %r12
movq %rax, %rdi
callq 0xa4d8
pushq $0x20
popq %rdi
callq 0x50c0
movq %rax, %r13
movl $0x844, %ebx            # imm = 0x844
movq %rax, %rdi
callq 0xa6a4
jmp 0x68ab
pushq $0x48
popq %rdi
callq 0x50c0
movq %rax, %r15
movq %rax, %rdi
callq 0x6ac8
pushq $0x38
popq %rdi
callq 0x50c0
movq %rax, %r12
movq %rax, %rdi
callq 0x9038
pushq $0x20
popq %rdi
callq 0x50c0
movq %rax, %r13
movl $0x1400c, %ebx          # imm = 0x1400C
movq %rax, %rdi
callq 0x921c
jmp 0x68ab
pushq $0x48
popq %rdi
callq 0x50c0
movq %rax, %r15
movq %rax, %rdi
callq 0xd06c
pushq $0x38
popq %rdi
callq 0x50c0
movq %rax, %r12
movq %rax, %rdi
callq 0xd520
pushq $0x20
popq %rdi
callq 0x50c0
movq %rax, %r13
movq %rax, %rdi
callq 0xd6ec
pushq $0xc
jmp 0x68aa
pushq $0x48
popq %rdi
callq 0x50c0
movq %rax, %r15
movq %rax, %rdi
callq 0xbb38
pushq $0x38
popq %rdi
callq 0x50c0
movq %rax, %r12
movq %rax, %rdi
callq 0xc574
pushq $0x20
popq %rdi
callq 0x50c0
movq %rax, %r13
movl $0x1400c, %ebx          # imm = 0x1400C
movq %rax, %rdi
callq 0x6ae2
jmp 0x68ab
cmpl $0x6, %r12d
jne 0x6829
pushq $0x30
popq %rdi
callq 0x50c0
movq %rax, %r15
movq %rax, %rdi
callq 0xece8
movl $0x4e0, %edi            # imm = 0x4E0
callq 0x50c0
movq %rax, %r12
movq %rax, %rdi
callq 0xfa24
pushq $0x20
popq %rdi
callq 0x50c0
movq %rax, %r13
movq %rax, %rdi
callq 0x6afc
pushq $0xb
jmp 0x68aa
cmpl $0x4, %r12d
jne 0x686d
pushq $0x48
popq %rdi
callq 0x50c0
movq %rax, %r15
movq %rax, %rdi
callq 0x6b30
pushq $0x38
popq %rdi
callq 0x50c0
movq %rax, %r12
movq %rax, %rdi
callq 0x7220
pushq $0x20
popq %rdi
callq 0x50c0
movq %rax, %r13
movq %rax, %rdi
callq 0x73ec
jmp 0x6797
pushq $0x30
popq %rdi
callq 0x50c0
movq %rax, %r15
movq %rax, %rdi
callq 0x129b8
movl $0x4e0, %edi            # imm = 0x4E0
callq 0x50c0
movq %rax, %r12
movq %rax, %rdi
callq 0x136e8
pushq $0x20
popq %rdi
callq 0x50c0
movq %rax, %r13
movq %rax, %rdi
callq 0x6b16
pushq $-0x1
popq %rbx
testb $0x1, 0x20(%rsp)
je 0x68f7
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
pushq $0x3c
popq %rcx
movq %r15, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq *0x58(%rax)
testl %eax, %eax
je 0x693d
pushq $0x1
popq %rbp
leaq 0xef98(%rip), %rdi      # 0x15883
movq %rbx, %rsi
xorl %eax, %eax
callq 0x5040
jmp 0x6971
movq (%r15), %rax
movq %r15, %rdi
movq 0x8(%rsp), %rsi
callq *0x10(%rax)
testl %eax, %eax
je 0x694b
cmpb $0x1, 0x19981(%rip)     # 0x20291
jne 0x6971
movq 0x196bf(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0xef8a(%rip), %rsi      # 0x158ad
leaq 0xeb2d(%rip), %rdx      # 0x15457
movl $0x1a2, %ecx            # imm = 0x1A2
movq 0x8(%rsp), %r8
xorl %eax, %eax
callq 0x5180
jmp 0x6971
leaq 0x40(%rsp), %rdi
callq 0x51b0
xorl %ebp, %ebp
jmp 0x6971
testb $0x1, 0x18(%rsp)
je 0x697f
movq (%r15), %rax
movq %r15, %rdi
callq *0x80(%rax)
movzbl %al, %esi
leaq 0xef6d(%rip), %rdi      # 0x158d5
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x5040
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
jmp 0x5f15
movq (%r12), %rax
movq %r12, %rdi
movq %r14, %rsi
callq *(%rax)
testl %eax, %eax
je 0x69c1
cmpb $0x1, 0x198fb(%rip)     # 0x20291
jne 0x69d5
movq 0x19639(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0xef3a(%rip), %rsi      # 0x158e3
leaq 0xeaa7(%rip), %rdx      # 0x15457
movl $0x1af, %ecx            # imm = 0x1AF
movq %r14, %r8
xorl %eax, %eax
callq 0x5180
jmp 0x69d5
movq (%r13), %rax
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *0x10(%rax)
testl %eax, %eax
je 0x69e6
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
pushq $-0x2
popq %rbp
jmp 0x5f15
pushq $0x8
popq %rdi
callq 0x50c0
movq 0x28(%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 0x6a1f
cmpb $0x1, 0x19881(%rip)     # 0x20291
je 0x6a41
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
pushq $-0x4
jmp 0x69e0
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 0x667b
movq 0x19590(%rip), %rcx     # 0x1ffd8
movq (%rcx), %rdi
leaq 0xeec0(%rip), %rsi      # 0x15912
leaq 0xe9fe(%rip), %rdx      # 0x15457
movl $0x1c2, %ecx            # imm = 0x1C2
movl %eax, %r8d
xorl %eax, %eax
callq 0x5180
jmp 0x6a12
jmp 0x6a9b
jmp 0x6a78
jmp 0x6a82
jmp 0x6a9b
jmp 0x6aa6
jmp 0x6ab1
jmp 0x6a9b
movq %rax, %rbx
movl $0x4e0, %esi            # imm = 0x4E0
jmp 0x6aac
movq %rax, %rbx
pushq $0x30
jmp 0x6ab6
jmp 0x6a9b
jmp 0x6aa6
jmp 0x6ab1
jmp 0x6a9b
jmp 0x6aa6
jmp 0x6ab1
jmp 0x6a9b
jmp 0x6aa6
jmp 0x6ab1
movq %rax, %rbx
pushq $0x20
popq %rsi
movq %r13, %rdi
jmp 0x6aba
movq %rax, %rbx
pushq $0x38
popq %rsi
movq %r12, %rdi
jmp 0x6aba
movq %rax, %rbx
pushq $0x48
popq %rsi
movq %r15, %rdi
callq 0x50e0
movq %rbx, %rdi
callq 0x51f0
nop