// File: /workspace/github_c_makefile_star2_O0/truenas[P]binaries/src/ixnvdimm.c
// Function: firmware_update
static void
firmware_update(int fd, struct ixnvdimm_info *info, const char *f, int I)
{
	int b, ffd, r, rbs, regions, t, timeout, atimeout, try;
	struct stat sb;
	off_t size;
	uint8_t *image, status[4], buf[7 + BLOCK_SIZE];

	/* Firmware commands timeout in milliseconds. */
	timeout = i2c_read16(fd, 0x00, 0x22);
	if (timeout & 0x8000)
		timeout = (timeout & 0x7fff) * 1000;

	/* Abort commands timeout in milliseconds. */
	atimeout = i2c_read(fd, 0x00, 0x24);
	if (i2c_read(fd, 0x00, 0x11) & 0x02)
		atimeout = atimeout * 1000;

	/* Region size in blocks. */
	rbs = i2c_read(fd, 0x00, 0x32);

	if ((ffd = open(f, O_RDONLY)) < 0)
		err(EX_NOINPUT, "Can't open firmware file '%s'", f);
	if (fstat(ffd, &sb) < 0)
		err(EX_NOINPUT, "Can't stat firmware file '%s'", f);
	size = roundup(sb.st_size, rbs * BLOCK_SIZE);
	regions = size / (rbs * BLOCK_SIZE);
	if (size < BLOCK_SIZE)
		errx(EX_NOINPUT, "Firmware file '%s' is too small", f);
	image = calloc(1, size);
	if (image == NULL)
		err(EX_OSERR, "Can't allocate firmware memory");
	if (read(ffd, image, sb.st_size) != sb.st_size)
		err(EX_OSERR, "Can't read firmware file '%s'", f);
	close(ffd);

	/* Validate firmware image header. */
	if (I)
		t = 0;		/* Ignore any identifiers difference. */
	else if (image[31] == 0)
		t = 0x03;
	else if (image[31] == 1)
		t = image[19];
	else
		errx(EX_NOINPUT, "Unknown Firmware Image Header Format %u", image[31]);
	if ((t & 0x01) && le16dec(&image[0]) != info->VendorId)
		errx(EX_NOINPUT, "Module Manufacturer ID Code does not match");
	if ((t & 0x02) && le16dec(&image[2]) != info->DeviceId)
		errx(EX_NOINPUT, "Module Product Identifier does not match");
	if ((t & 0x04) && le16dec(&image[4]) != info->SubsystemVendorId)
		errx(EX_NOINPUT, "Non-Volatile Memory Subsystem Controller Module Manufacturer ID Code does not match");
	if ((t & 0x08) && le16dec(&image[6]) != info->SubsystemDeviceId)
		errx(EX_NOINPUT, "Non-Volatile Memory Subsystem Controller Module Product Identifier does not match");
	if ((t & 0x10) && image[8] != info->RevisionId)
		errx(EX_NOINPUT, "Module Revision Code does not match");
	if ((t & 0x20) && image[9] != info->SubsystemRevisionId)
		errx(EX_NOINPUT, "Non-Volatile Memory Subsystem Controller Revision Code does not match");
	if (be32dec(&image[20]) != sb.st_size)
		errx(EX_NOINPUT, "Size in firmware header does not match");
	if (be16dec(&image[24]) !=
	    Crc16((char *)image + BLOCK_SIZE, sb.st_size - BLOCK_SIZE))
		errx(EX_NOINPUT, "Checksum in firmware header does not match");

	/* Wait for the Operation In Progress bit in the NVDIMM_CMD_STATUS0 register to be clear. */
	if (i2c_read(fd, 0, NVDIMM_CMD_STATUS0) & 1) {
		printf("Waiting for Operation In Progress to clear\n");
		for (t = 0; (i2c_read(fd, 0, NVDIMM_CMD_STATUS0) & 1) && t < timeout; t++)
			usleep(1000);
		if (t >= timeout) {
			errx(EX_PROTOCOL, "NVDIMM has operation in progress: %02x",
			    i2c_read16(fd, 0, NVDIMM_CMD_STATUS0));
		}
	}

	/* Start firmware update via DSM. */
	i2c_write(fd, 0, NVDIMM_MGT_CMD1, 1 << 1);
	buf[0] = 1;	/* Firmware Slot */
	memset(&status, 0xff, sizeof(status));
	if (calldsm(fd, 22, buf, 1, status, sizeof(status)) != 4)
		err(EX_NOINPUT, "Can't call Start Firmware Update DSM");
	if (le32dec(&status[0]) != 0)
		errx(EX_NOINPUT, "Start Firmware Update DSM failed: %x",
		    le32dec(&status[0]));
	printf("Start Firmware Update succeeded\n");
	fflush(stdout);

	/*
	 * Wait for the Operation In Progress bit in the NVDIMM_CMD_STATUS0
	 * register to be clear.  I have no clue why ACPI DSM does not do it.
	 */
	for (t = 0; (i2c_read(fd, 0, NVDIMM_CMD_STATUS0) & 1) && t < timeout; t++)
		usleep(1000);
	if (t >= timeout) {
		warnx("Start Firmware Update DSM timeout: %04x",
		    i2c_read16(fd, 0, NVDIMM_CMD_STATUS0));
		goto timeout;
	}

	/* Check ACPI enabled firmware update mode. */
	if ((i2c_read(fd, 0, FIRMWARE_OPS_STATUS) & 0x04) == 0) {
		warnx("Firmware update mode is not enabled: %02x",
		    i2c_read(fd, 0, FIRMWARE_OPS_STATUS));
		goto error;
	}

	/* Clear firmware region. */
	i2c_write(fd, 0, NVDIMM_MGT_CMD1, 1 << 1);
	i2c_write(fd, 0, FIRMWARE_OPS_CMD, 0x02);
	for (t = 0; (i2c_read(fd, 0, NVDIMM_CMD_STATUS0) & 1) && t < timeout; t++)
		usleep(1000);
	if (t >= timeout) {
		warnx("Clear Firmware timeout: %04x",
		    i2c_read16(fd, 0, NVDIMM_CMD_STATUS0));
		goto timeout;
	}
	if (i2c_read(fd, 0, FIRMWARE_OPS_STATUS) & 0x02) {
		warnx("Clear Firmware failed: %02x",
		    i2c_read(fd, 0, FIRMWARE_OPS_STATUS));
		goto error2;
	}

	/* Send firmware one region at a time */
	i2c_write(fd, 3, TYPED_BLOCK_DATA, 0x01);
	for (r = 0; r < regions; r++) {
		printf("\r%d/%d ", r, regions);
		fflush(stdout);
		try = 0;

retry:
		/* Send region blocks via Send Firmware Update Data DSM. */
		for (b = 0; b < rbs; b++) {
			le32enc(&buf[0], BLOCK_SIZE);
			le16enc(&buf[4], r);
			buf[6] = b;
			memcpy(&buf[7], &image[(r * rbs + b) * BLOCK_SIZE], BLOCK_SIZE);
			memset(&status, 0xff, sizeof(status));
			if (calldsm(fd, 23, buf, sizeof(buf), status, sizeof(status)) != 4) {
				warn("Can't call Send Firmware Update Data DSM");
				goto error2;
			}
			if (le32dec(&status[0]) != 0) {
				warnx("Send Firmware Update Data DSM failed: %x",
				    le32dec(&status[0]));
				goto error2;
			}
		}

		/* Verify region checksum. */
		i2c_write(fd, 0, NVDIMM_MGT_CMD1, 1 << 1);
		i2c_write(fd, 0, FIRMWARE_OPS_CMD, 0x04);
		for (t = 0; (i2c_read(fd, 0, NVDIMM_CMD_STATUS0) & 1) && t < timeout; t++)
			usleep(1000);
		if (t >= timeout) {
			warnx("Generate Firmware Checksum timeout: %04x",
			    i2c_read16(fd, 0, NVDIMM_CMD_STATUS0));
			goto timeout;
		}
		if (i2c_read(fd, 0, FIRMWARE_OPS_STATUS) & 0x02) {
			warnx("Generate Firmware Checksum failed: %02x",
			    i2c_read(fd, 0, FIRMWARE_OPS_STATUS));
			goto error2;
		}
		if (i2c_read16(fd, 3, FW_REGION_CRC0) !=
		    Crc16((char *)image + r * rbs * BLOCK_SIZE, rbs * BLOCK_SIZE)) {
			if (++try < 3) {
				printf("Region checksum mismatch, retrying\n");
				goto retry;
			} else {
				warnx("Region checksum mismatch");
				goto error2;
			}
		}

		/*
		 * After sending the first region with the header in it ask
		 * the module to check that the new image really applies.
		 */
		if (r == 0) {
			i2c_write(fd, 0, NVDIMM_MGT_CMD1, 1 << 1);
			i2c_write(fd, 0, FIRMWARE_OPS_CMD, 0x10);
			for (t = 0; (i2c_read(fd, 0, NVDIMM_CMD_STATUS0) & 1) && t < timeout; t++)
				usleep(1000);
			if (t >= timeout) {
				warnx("Validate Firmware Header timeout: %04x",
				    i2c_read16(fd, 0, NVDIMM_CMD_STATUS0));
				goto timeout;
			}
			if (i2c_read(fd, 0, FIRMWARE_OPS_STATUS) & 0x02) {
				warnx("Validate Firmware Header failed: %02x",
				    i2c_read(fd, 0, FIRMWARE_OPS_STATUS));
				goto error2;
			}
			printf("\rValidate Firmware Header succeeded\n");
		}

		/* The region seems to be correct, commit it. */
		i2c_write(fd, 0, NVDIMM_MGT_CMD1, 1 << 1);
		i2c_write(fd, 0, FIRMWARE_OPS_CMD, 0x08);
		for (t = 0; (i2c_read(fd, 0, NVDIMM_CMD_STATUS0) & 1) && t < timeout; t++)
			usleep(1000);
		if (t >= timeout) {
			warnx("Commit Firmware timeout: %04x",
			    i2c_read16(fd, 0, NVDIMM_CMD_STATUS0));
			goto timeout;
		}
		if (i2c_read(fd, 0, FIRMWARE_OPS_STATUS) & 0x02) {
			warnx("Commit Firmware failed: %02x",
			    i2c_read(fd, 0, FIRMWARE_OPS_STATUS));
			goto error2;
		}
	}
	i2c_write(fd, 3, TYPED_BLOCK_DATA, 0x00);
	printf("\rSend Firmware Update Data succeeded\n");
	fflush(stdout);

	/* Validate firmware image. */
	printf("Validating firmware image... ");
	fflush(stdout);
	i2c_write(fd, 0, NVDIMM_MGT_CMD1, 1 << 1);
	i2c_write(fd, 0, FIRMWARE_OPS_CMD, 0x20);
	for (t = 0; (i2c_read(fd, 0, NVDIMM_CMD_STATUS0) & 1) && t < timeout; t++)
		usleep(1000);
	if (t >= timeout) {
		warnx("Validate Firmware Image timeout: %02x",
		    i2c_read16(fd, 0, NVDIMM_CMD_STATUS0));
timeout:
		/* Send Abort command. */
		i2c_write(fd, 0, 0x43, 0x10);
		for (t = 0; (i2c_read(fd, 0, NVDIMM_CMD_STATUS0) & 1) && t < atimeout; t++)
			usleep(1000);
		if (t >= atimeout)
			warnx("Abort command timeout: %04x",
			    i2c_read16(fd, 0, NVDIMM_CMD_STATUS0));
		else if ((i2c_read(fd, 0, FIRMWARE_OPS_STATUS) & 0x10) == 0)
			warnx("Abort command haven't succeeded: %02x",
			    i2c_read(fd, 0, FIRMWARE_OPS_STATUS));
		goto error2;
	}
	if (i2c_read(fd, 0, FIRMWARE_OPS_STATUS) & 0x02) {
		warnx("Validate Firmware Image failed: %02x",
		    i2c_read(fd, 0, FIRMWARE_OPS_STATUS));
error2:
		/* Disable firmware update mode. */
		i2c_write(fd, 0, NVDIMM_MGT_CMD1, 1 << 1);
		i2c_write(fd, 0, FIRMWARE_OPS_CMD, 0);
		for (t = 0; (i2c_read(fd, 0, NVDIMM_CMD_STATUS0) & 1) && t < timeout; t++)
			usleep(1000);
		if (t >= timeout)
			warnx("Disable firmware update mode timeout: %04x",
			    i2c_read16(fd, 0, NVDIMM_CMD_STATUS0));
		else if (i2c_read(fd, 0, FIRMWARE_OPS_STATUS) & 0x04)
			warnx("Firmware update mode disable error: %02x",
			    i2c_read(fd, 0, FIRMWARE_OPS_STATUS));
error:
		goto done;
	}
	printf("\rValidate Firmware Image succeeded\n");
	fflush(stdout);

	/* Finish firmware update via DSM. */
	i2c_write(fd, 0, NVDIMM_MGT_CMD1, 1 << 1);
	memset(&status, 0xff, sizeof(status));
	if (calldsm(fd, 24, NULL, 0, status, sizeof(status)) != 4)
		err(EX_NOINPUT, "Can't call Finish Firmware Update DSM");
	if (le32dec(&status[0]) != 0)
		errx(EX_NOINPUT, "Finish Firmware Update DSM status: %x",
		    le32dec(&status[0]));
	printf("Finish Firmware Update succeeded\n");
	fflush(stdout);

	/* Select firmware image slot 1 */
	i2c_write(fd, 0, NVDIMM_MGT_CMD1, 1 << 1);
	buf[0] = 1;	/* Firmware Slot 1 */
	memset(&status, 0xff, sizeof(status));
	if (calldsm(fd, 25, buf, 1, status, sizeof(status)) != 4)
		err(EX_NOINPUT, "Can't call Select Firmware Image Slot DSM");
	if (le32dec(&status[0]) != 0)
		errx(EX_NOINPUT, "Select Firmware Image Slot DSM failed: %x",
		    le32dec(&status[0]));
	printf("Select Firmware Image Slot 1 succeeded\n");
	fflush(stdout);

done:
	free(image);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x22, %edx
callq 0x53b0
movzwl %ax, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x2fec
movl -0x38(%rbp), %eax
andl $0x7fff, %eax           # imm = 0x7FFF
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movl %eax, -0x38(%rbp)
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x24, %edx
callq 0x2e40
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x11, %edx
callq 0x2e40
movzbl %al, %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x3025
imull $0x3e8, -0x3c(%rbp), %eax # imm = 0x3E8
movl %eax, -0x3c(%rbp)
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x32, %edx
callq 0x2e40
movzbl %al, %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x2160
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
jge 0x3066
movq -0x18(%rbp), %rdx
movl $0x42, %edi
leaq 0x32e7(%rip), %rsi      # 0x6346
movb $0x0, %al
callq 0x2140
movl -0x24(%rbp), %edi
leaq -0xd0(%rbp), %rsi
callq 0x21a0
cmpl $0x0, %eax
jge 0x3091
movq -0x18(%rbp), %rdx
movl $0x42, %edi
leaq 0x32da(%rip), %rsi      # 0x6364
movb $0x0, %al
callq 0x2140
movq -0xa0(%rbp), %rax
movl -0x2c(%rbp), %ecx
shll $0x5, %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movl -0x2c(%rbp), %ecx
shll $0x5, %ecx
movslq %ecx, %rcx
cqto
idivq %rcx
movl -0x2c(%rbp), %ecx
shll $0x5, %ecx
movslq %ecx, %rcx
imulq %rcx, %rax
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movl -0x2c(%rbp), %ecx
shll $0x5, %ecx
movslq %ecx, %rcx
cqto
idivq %rcx
movl %eax, -0x30(%rbp)
cmpq $0x20, -0xd8(%rbp)
jge 0x3110
movq -0x18(%rbp), %rdx
movl $0x42, %edi
leaq 0x3279(%rip), %rsi      # 0x6382
movb $0x0, %al
callq 0x2070
movq -0xd8(%rbp), %rsi
movl $0x1, %edi
callq 0x2100
movq %rax, -0xe0(%rbp)
cmpq $0x0, -0xe0(%rbp)
jne 0x3145
movl $0x47, %edi
leaq 0x3264(%rip), %rsi      # 0x63a2
movb $0x0, %al
callq 0x2140
movl -0x24(%rbp), %edi
movq -0xe0(%rbp), %rsi
movq -0xa0(%rbp), %rdx
callq 0x20f0
cmpq -0xa0(%rbp), %rax
je 0x317b
movq -0x18(%rbp), %rdx
movl $0x47, %edi
leaq 0x324d(%rip), %rsi      # 0x63c1
movb $0x0, %al
callq 0x2140
movl -0x24(%rbp), %edi
callq 0x20e0
cmpl $0x0, -0x1c(%rbp)
je 0x3192
movl $0x0, -0x34(%rbp)
jmp 0x31ed
movq -0xe0(%rbp), %rax
movzbl 0x1f(%rax), %eax
cmpl $0x0, %eax
jne 0x31ab
movl $0x3, -0x34(%rbp)
jmp 0x31eb
movq -0xe0(%rbp), %rax
movzbl 0x1f(%rax), %eax
cmpl $0x1, %eax
jne 0x31cb
movq -0xe0(%rbp), %rax
movzbl 0x13(%rax), %eax
movl %eax, -0x34(%rbp)
jmp 0x31e9
movq -0xe0(%rbp), %rax
movzbl 0x1f(%rax), %edx
movl $0x42, %edi
leaq 0x31fd(%rip), %rsi      # 0x63df
movb $0x0, %al
callq 0x2070
jmp 0x31eb
jmp 0x31ed
movl -0x34(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3225
movq -0xe0(%rbp), %rdi
callq 0x5410
movzwl %ax, %eax
movq -0x10(%rbp), %rcx
movzwl (%rcx), %ecx
cmpl %ecx, %eax
je 0x3225
movl $0x42, %edi
leaq 0x3212(%rip), %rsi      # 0x6430
movb $0x0, %al
callq 0x2070
movl -0x34(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x3262
movq -0xe0(%rbp), %rdi
addq $0x2, %rdi
callq 0x5410
movzwl %ax, %eax
movq -0x10(%rbp), %rcx
movzwl 0x2(%rcx), %ecx
cmpl %ecx, %eax
je 0x3262
movl $0x42, %edi
leaq 0x3229(%rip), %rsi      # 0x6484
movb $0x0, %al
callq 0x2070
movl -0x34(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x329f
movq -0xe0(%rbp), %rdi
addq $0x4, %rdi
callq 0x5410
movzwl %ax, %eax
movq -0x10(%rbp), %rcx
movzwl 0x6(%rcx), %ecx
cmpl %ecx, %eax
je 0x329f
movl $0x42, %edi
leaq 0x316f(%rip), %rsi      # 0x6407
movb $0x0, %al
callq 0x2070
movl -0x34(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x32dc
movq -0xe0(%rbp), %rdi
addq $0x6, %rdi
callq 0x5410
movzwl %ax, %eax
movq -0x10(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
cmpl %ecx, %eax
je 0x32dc
movl $0x42, %edi
leaq 0x3186(%rip), %rsi      # 0x645b
movb $0x0, %al
callq 0x2070
movl -0x34(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x3311
movq -0xe0(%rbp), %rax
movzbl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movzwl 0x4(%rcx), %ecx
cmpl %ecx, %eax
je 0x3311
movl $0x42, %edi
leaq 0x31a3(%rip), %rsi      # 0x64ad
movb $0x0, %al
callq 0x2070
movl -0x34(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x3346
movq -0xe0(%rbp), %rax
movzbl 0x9(%rax), %eax
movq -0x10(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
cmpl %ecx, %eax
je 0x3346
movl $0x42, %edi
leaq 0x3192(%rip), %rsi      # 0x64d1
movb $0x0, %al
callq 0x2070
movq -0xe0(%rbp), %rdi
addq $0x14, %rdi
callq 0x5440
movl %eax, %eax
cmpq -0xa0(%rbp), %rax
je 0x3374
movl $0x42, %edi
leaq 0x31aa(%rip), %rsi      # 0x6517
movb $0x0, %al
callq 0x2070
movq -0xe0(%rbp), %rdi
addq $0x18, %rdi
callq 0x5240
movzwl %ax, %eax
movl %eax, -0x11c(%rbp)
movq -0xe0(%rbp), %rdi
addq $0x20, %rdi
movq -0xa0(%rbp), %rax
subq $0x20, %rax
movl %eax, %esi
callq 0x5480
movl %eax, %ecx
movl -0x11c(%rbp), %eax
cmpl %ecx, %eax
je 0x33c9
movl $0x42, %edi
leaq 0x317c(%rip), %rsi      # 0x653e
movb $0x0, %al
callq 0x2070
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x2e40
movzbl %al, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x347d
leaq 0x317b(%rip), %rdi      # 0x6569
movb $0x0, %al
callq 0x2080
movl $0x0, -0x34(%rbp)
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x2e40
movzbl %al, %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x11d(%rbp)
je 0x342d
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
setl %al
movb %al, -0x11d(%rbp)
movb -0x11d(%rbp), %al
testb $0x1, %al
jne 0x3439
jmp 0x344e
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x21b0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x33fc
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x347b
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x53b0
movzwl %ax, %edx
movl $0x4c, %edi
leaq 0x3121(%rip), %rsi      # 0x6595
movb $0x0, %al
callq 0x2070
jmp 0x347d
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x41, %edx
movl $0x2, %ecx
callq 0x4280
movb $0x1, -0x110(%rbp)
leaq -0xe4(%rbp), %rdi
movl $0xff, %esi
movl $0x4, %edx
callq 0x20c0
movl -0x4(%rbp), %edi
leaq -0x110(%rbp), %rdx
leaq -0xe4(%rbp), %r8
movl $0x16, %esi
movl $0x1, %ecx
movl $0x4, %r9d
callq 0x5270
cmpq $0x4, %rax
je 0x34ed
movl $0x42, %edi
leaq 0x30d6(%rip), %rsi      # 0x65bc
movb $0x0, %al
callq 0x2140
leaq -0xe4(%rbp), %rdi
callq 0x5370
cmpl $0x0, %eax
je 0x351f
leaq -0xe4(%rbp), %rdi
callq 0x5370
movl %eax, %edx
movl $0x42, %edi
leaq 0x30c9(%rip), %rsi      # 0x65e1
movb $0x0, %al
callq 0x2070
leaq 0x30e0(%rip), %rdi      # 0x6606
movb $0x0, %al
callq 0x2080
movq 0x6a94(%rip), %rax      # 0x9fc8
movq (%rax), %rdi
callq 0x2150
movl $0x0, -0x34(%rbp)
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x2e40
movzbl %al, %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x11e(%rbp)
je 0x3574
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
setl %al
movb %al, -0x11e(%rbp)
movb -0x11e(%rbp), %al
testb $0x1, %al
jne 0x3580
jmp 0x3595
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x21b0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3543
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x35c2
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x53b0
movzwl %ax, %esi
leaq 0x3071(%rip), %rdi      # 0x6627
movb $0x0, %al
callq 0x2090
jmp 0x3cc8
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x3601
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %esi
leaq 0x305a(%rip), %rdi      # 0x664f
movb $0x0, %al
callq 0x2090
jmp 0x3ec1
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x41, %edx
movl $0x2, %ecx
callq 0x4280
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x4a, %edx
movl $0x2, %ecx
callq 0x4280
movl $0x0, -0x34(%rbp)
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x2e40
movzbl %al, %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x11f(%rbp)
je 0x3661
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
setl %al
movb %al, -0x11f(%rbp)
movb -0x11f(%rbp), %al
testb $0x1, %al
jne 0x366d
jmp 0x3682
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x21b0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3630
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x36af
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x53b0
movzwl %ax, %esi
leaq 0x2fd6(%rip), %rdi      # 0x6679
movb $0x0, %al
callq 0x2090
jmp 0x3cc8
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x36ee
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %esi
leaq 0x2fb4(%rip), %rdi      # 0x6696
movb $0x0, %al
callq 0x2090
jmp 0x3ddb
movl -0x4(%rbp), %edi
movl $0x3, %esi
movl $0x4, %edx
movl $0x1, %ecx
callq 0x4280
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x3bcd
movl -0x28(%rbp), %esi
movl -0x30(%rbp), %edx
leaq 0x2f8d(%rip), %rdi      # 0x66b2
movb $0x0, %al
callq 0x2080
movq 0x6895(%rip), %rax      # 0x9fc8
movq (%rax), %rdi
callq 0x2150
movl $0x0, -0x40(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x3862
leaq -0x110(%rbp), %rdi
movl $0x20, %esi
callq 0x5510
leaq -0x110(%rbp), %rdi
addq $0x4, %rdi
movl -0x28(%rbp), %eax
movzwl %ax, %esi
callq 0x5580
movl -0x20(%rbp), %eax
movb %al, -0x10a(%rbp)
movq -0xe0(%rbp), %rax
movl -0x28(%rbp), %ecx
imull -0x2c(%rbp), %ecx
addl -0x20(%rbp), %ecx
shll $0x5, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx), %rdx
movq %rdx, -0x109(%rbp)
movq 0x8(%rax,%rcx), %rdx
movq %rdx, -0x101(%rbp)
movq 0x10(%rax,%rcx), %rdx
movq %rdx, -0xf9(%rbp)
movq 0x18(%rax,%rcx), %rax
movq %rax, -0xf1(%rbp)
leaq -0xe4(%rbp), %rdi
movl $0xff, %esi
movl $0x4, %edx
callq 0x20c0
movl -0x4(%rbp), %edi
leaq -0x110(%rbp), %rdx
leaq -0xe4(%rbp), %r8
movl $0x17, %esi
movl $0x27, %ecx
movl $0x4, %r9d
callq 0x5270
cmpq $0x4, %rax
je 0x3820
leaq 0x2ea6(%rip), %rdi      # 0x66ba
movb $0x0, %al
callq 0x2050
jmp 0x3ddb
leaq -0xe4(%rbp), %rdi
callq 0x5370
cmpl $0x0, %eax
je 0x3852
leaq -0xe4(%rbp), %rdi
callq 0x5370
movl %eax, %esi
leaq 0x2e9d(%rip), %rdi      # 0x66e3
movb $0x0, %al
callq 0x2090
jmp 0x3ddb
jmp 0x3854
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x3749
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x41, %edx
movl $0x2, %ecx
callq 0x4280
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x4a, %edx
movl $0x4, %ecx
callq 0x4280
movl $0x0, -0x34(%rbp)
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x2e40
movzbl %al, %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x120(%rbp)
je 0x38c2
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
setl %al
movb %al, -0x120(%rbp)
movb -0x120(%rbp), %al
testb $0x1, %al
jne 0x38ce
jmp 0x38e3
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x21b0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3891
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x3910
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x53b0
movzwl %ax, %esi
leaq 0x2e08(%rip), %rdi      # 0x670c
movb $0x0, %al
callq 0x2090
jmp 0x3cc8
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x394f
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %esi
leaq 0x2df2(%rip), %rdi      # 0x6735
movb $0x0, %al
callq 0x2090
jmp 0x3ddb
movl -0x4(%rbp), %edi
movl $0x3, %esi
movl $0x40, %edx
callq 0x53b0
movzwl %ax, %eax
movl %eax, -0x124(%rbp)
movq -0xe0(%rbp), %rdi
movl -0x28(%rbp), %eax
imull -0x2c(%rbp), %eax
shll $0x5, %eax
cltq
addq %rax, %rdi
movl -0x2c(%rbp), %esi
shll $0x5, %esi
callq 0x5480
movl %eax, %ecx
movl -0x124(%rbp), %eax
cmpl %ecx, %eax
je 0x39cb
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
cmpl $0x3, %eax
jge 0x39b8
leaq 0x2db1(%rip), %rdi      # 0x675d
movb $0x0, %al
callq 0x2080
jmp 0x3742
leaq 0x2dc2(%rip), %rdi      # 0x6781
movb $0x0, %al
callq 0x2090
jmp 0x3ddb
cmpl $0x0, -0x28(%rbp)
jne 0x3ad0
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x41, %edx
movl $0x2, %ecx
callq 0x4280
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x4a, %edx
movl $0x10, %ecx
callq 0x4280
movl $0x0, -0x34(%rbp)
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x2e40
movzbl %al, %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x125(%rbp)
je 0x3a35
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
setl %al
movb %al, -0x125(%rbp)
movb -0x125(%rbp), %al
testb $0x1, %al
jne 0x3a41
jmp 0x3a56
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x21b0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3a04
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x3a83
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x53b0
movzwl %ax, %esi
leaq 0x2d23(%rip), %rdi      # 0x679a
movb $0x0, %al
callq 0x2090
jmp 0x3cc8
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x3ac2
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %esi
leaq 0x2d0b(%rip), %rdi      # 0x67c1
movb $0x0, %al
callq 0x2090
jmp 0x3ddb
leaq 0x2d1e(%rip), %rdi      # 0x67e7
movb $0x0, %al
callq 0x2080
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x41, %edx
movl $0x2, %ecx
callq 0x4280
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x4a, %edx
movl $0x8, %ecx
callq 0x4280
movl $0x0, -0x34(%rbp)
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x2e40
movzbl %al, %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x126(%rbp)
je 0x3b30
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
setl %al
movb %al, -0x126(%rbp)
movb -0x126(%rbp), %al
testb $0x1, %al
jne 0x3b3c
jmp 0x3b51
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x21b0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3aff
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x3b7e
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x53b0
movzwl %ax, %esi
leaq 0x2c9a(%rip), %rdi      # 0x680c
movb $0x0, %al
callq 0x2090
jmp 0x3cc8
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x3bbd
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %esi
leaq 0x2c79(%rip), %rdi      # 0x682a
movb $0x0, %al
callq 0x2090
jmp 0x3ddb
jmp 0x3bbf
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x370c
movl -0x4(%rbp), %edi
movl $0x3, %esi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x4280
leaq 0x2c5f(%rip), %rdi      # 0x6847
movb $0x0, %al
callq 0x2080
movq 0x63d2(%rip), %rax      # 0x9fc8
movq (%rax), %rdi
callq 0x2150
leaq 0x2c68(%rip), %rdi      # 0x686d
movb $0x0, %al
callq 0x2080
movq 0x63b5(%rip), %rax      # 0x9fc8
movq (%rax), %rdi
callq 0x2150
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x41, %edx
movl $0x2, %ecx
callq 0x4280
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x4a, %edx
movl $0x20, %ecx
callq 0x4280
movl $0x0, -0x34(%rbp)
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x2e40
movzbl %al, %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x127(%rbp)
je 0x3c7b
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
setl %al
movb %al, -0x127(%rbp)
movb -0x127(%rbp), %al
testb $0x1, %al
jne 0x3c87
jmp 0x3c9c
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x21b0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3c4a
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x3d9d
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x53b0
movzwl %ax, %esi
leaq 0x2bca(%rip), %rdi      # 0x688b
movb $0x0, %al
callq 0x2090
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x43, %edx
movl $0x10, %ecx
callq 0x4280
movl $0x0, -0x34(%rbp)
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x2e40
movzbl %al, %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x128(%rbp)
je 0x3d14
movl -0x34(%rbp), %eax
cmpl -0x3c(%rbp), %eax
setl %al
movb %al, -0x128(%rbp)
movb -0x128(%rbp), %al
testb $0x1, %al
jne 0x3d20
jmp 0x3d35
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x21b0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3ce3
movl -0x34(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jl 0x3d5f
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x53b0
movzwl %ax, %esi
leaq 0x2b5b(%rip), %rdi      # 0x68b1
movb $0x0, %al
callq 0x2090
jmp 0x3d9b
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x3d99
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %esi
leaq 0x2b3b(%rip), %rdi      # 0x68cd
movb $0x0, %al
callq 0x2090
jmp 0x3d9b
jmp 0x3ddb
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x3ec6
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %esi
leaq 0x2b1f(%rip), %rdi      # 0x68f3
movb $0x0, %al
callq 0x2090
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x41, %edx
movl $0x2, %ecx
callq 0x4280
movl -0x4(%rbp), %edi
xorl %ecx, %ecx
movl $0x4a, %edx
movl %ecx, %esi
callq 0x4280
movl $0x0, -0x34(%rbp)
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x2e40
movzbl %al, %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x129(%rbp)
je 0x3e38
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
setl %al
movb %al, -0x129(%rbp)
movb -0x129(%rbp), %al
testb $0x1, %al
jne 0x3e44
jmp 0x3e59
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x21b0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3e07
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x3e83
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x61, %edx
callq 0x53b0
movzwl %ax, %esi
leaq 0x2a9e(%rip), %rdi      # 0x6918
movb $0x0, %al
callq 0x2090
jmp 0x3ebf
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x3ebd
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x71, %edx
callq 0x2e40
movzbl %al, %esi
leaq 0x2a8d(%rip), %rdi      # 0x6943
movb $0x0, %al
callq 0x2090
jmp 0x3ebf
jmp 0x3ec1
jmp 0x4055
leaq 0x2a9f(%rip), %rdi      # 0x696c
movb $0x0, %al
callq 0x2080
movq 0x60ed(%rip), %rax      # 0x9fc8
movq (%rax), %rdi
callq 0x2150
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x41, %edx
movl $0x2, %ecx
callq 0x4280
leaq -0xe4(%rbp), %rdi
movl $0xff, %esi
movl $0x4, %edx
callq 0x20c0
movl -0x4(%rbp), %edi
leaq -0xe4(%rbp), %r8
movl $0x18, %esi
xorl %eax, %eax
movl %eax, %ecx
movl $0x4, %r9d
movq %rcx, %rdx
callq 0x5270
cmpq $0x4, %rax
je 0x3f47
movl $0x42, %edi
leaq 0x2a50(%rip), %rsi      # 0x6990
movb $0x0, %al
callq 0x2140
leaq -0xe4(%rbp), %rdi
callq 0x5370
cmpl $0x0, %eax
je 0x3f79
leaq -0xe4(%rbp), %rdi
callq 0x5370
movl %eax, %edx
movl $0x42, %edi
leaq 0x2a44(%rip), %rsi      # 0x69b6
movb $0x0, %al
callq 0x2070
leaq 0x2a5c(%rip), %rdi      # 0x69dc
movb $0x0, %al
callq 0x2080
movq 0x603a(%rip), %rax      # 0x9fc8
movq (%rax), %rdi
callq 0x2150
movl -0x4(%rbp), %edi
xorl %esi, %esi
movl $0x41, %edx
movl $0x2, %ecx
callq 0x4280
movb $0x1, -0x110(%rbp)
leaq -0xe4(%rbp), %rdi
movl $0xff, %esi
movl $0x4, %edx
callq 0x20c0
movl -0x4(%rbp), %edi
leaq -0x110(%rbp), %rdx
leaq -0xe4(%rbp), %r8
movl $0x19, %esi
movl $0x1, %ecx
movl $0x4, %r9d
callq 0x5270
cmpq $0x4, %rax
je 0x4006
movl $0x42, %edi
leaq 0x29ff(%rip), %rsi      # 0x69fe
movb $0x0, %al
callq 0x2140
leaq -0xe4(%rbp), %rdi
callq 0x5370
cmpl $0x0, %eax
je 0x4038
leaq -0xe4(%rbp), %rdi
callq 0x5370
movl %eax, %edx
movl $0x42, %edi
leaq 0x29f7(%rip), %rsi      # 0x6a28
movb $0x0, %al
callq 0x2070
leaq 0x2a13(%rip), %rdi      # 0x6a52
movb $0x0, %al
callq 0x2080
movq 0x5f7b(%rip), %rax      # 0x9fc8
movq (%rax), %rdi
callq 0x2150
movq -0xe0(%rbp), %rdi
callq 0x2030
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopw (%rax,%rax)