// File: /workspace/github_c_makefile_star2_O0/blasphemy[P]mmc-utils/mmc_cmds.c
// Function: do_enh_area_set
int do_enh_area_set(int nargs, char **argv)
{
	__u8 value;
	__u8 ext_csd[512];
	int fd, ret;
	char *device;
	int dry_run = 1;
	unsigned int start_kib, length_kib, enh_start_addr, enh_size_mult;
	unsigned long align;

	if (nargs != 5) {
		fprintf(stderr, "Usage: mmc enh_area set <-y|-n|-c> <start KiB> <length KiB> </path/to/mmcblkX>\n");
		exit(1);
	}

	if (!strcmp("-y", argv[1])) {
		dry_run = 0;
	} else if (!strcmp("-c", argv[1])) {
		dry_run = 2;
	}

	start_kib = strtol(argv[2], NULL, 10);
	length_kib = strtol(argv[3], NULL, 10);
	device = argv[4];

	fd = open(device, O_RDWR);
	if (fd < 0) {
		perror("open");
		exit(1);
	}

	ret = read_extcsd(fd, ext_csd);
	if (ret) {
		fprintf(stderr, "Could not read EXT_CSD from %s\n", device);
		exit(1);
	}

	/* assert ENH_ATTRIBUTE_EN */
	if (!(ext_csd[EXT_CSD_PARTITIONING_SUPPORT] & EXT_CSD_ENH_ATTRIBUTE_EN))
	{
		printf(" Device cannot have enhanced tech.\n");
		exit(1);
	}

	/* assert not PARTITION_SETTING_COMPLETED */
	if (ext_csd[EXT_CSD_PARTITION_SETTING_COMPLETED])
	{
		printf(" Device is already partitioned\n");
		exit(1);
	}

	align = 512l * get_hc_wp_grp_size(ext_csd) * get_hc_erase_grp_size(ext_csd);

	enh_size_mult = (length_kib + align/2l) / align;

	enh_start_addr = start_kib * (1024 / (is_blockaddresed(ext_csd) ? 512 : 1));
	enh_start_addr /= align;
	enh_start_addr *= align;

	/* set EXT_CSD_ERASE_GROUP_DEF bit 0 */
	ret = write_extcsd_value(fd, EXT_CSD_ERASE_GROUP_DEF, 0x1);
	if (ret) {
		fprintf(stderr, "Could not write 0x1 to "
			"EXT_CSD[%d] in %s\n",
			EXT_CSD_ERASE_GROUP_DEF, device);
		exit(1);
	}

	/* write to ENH_START_ADDR and ENH_SIZE_MULT and PARTITIONS_ATTRIBUTE's ENH_USR bit */
	value = (enh_start_addr >> 24) & 0xff;
	ret = write_extcsd_value(fd, EXT_CSD_ENH_START_ADDR_3, value);
	if (ret) {
		fprintf(stderr, "Could not write 0x%02x to "
			"EXT_CSD[%d] in %s\n", value,
			EXT_CSD_ENH_START_ADDR_3, device);
		exit(1);
	}
	value = (enh_start_addr >> 16) & 0xff;
	ret = write_extcsd_value(fd, EXT_CSD_ENH_START_ADDR_2, value);
	if (ret) {
		fprintf(stderr, "Could not write 0x%02x to "
			"EXT_CSD[%d] in %s\n", value,
			EXT_CSD_ENH_START_ADDR_2, device);
		exit(1);
	}
	value = (enh_start_addr >> 8) & 0xff;
	ret = write_extcsd_value(fd, EXT_CSD_ENH_START_ADDR_1, value);
	if (ret) {
		fprintf(stderr, "Could not write 0x%02x to "
			"EXT_CSD[%d] in %s\n", value,
			EXT_CSD_ENH_START_ADDR_1, device);
		exit(1);
	}
	value = enh_start_addr & 0xff;
	ret = write_extcsd_value(fd, EXT_CSD_ENH_START_ADDR_0, value);
	if (ret) {
		fprintf(stderr, "Could not write 0x%02x to "
			"EXT_CSD[%d] in %s\n", value,
			EXT_CSD_ENH_START_ADDR_0, device);
		exit(1);
	}

	value = (enh_size_mult >> 16) & 0xff;
	ret = write_extcsd_value(fd, EXT_CSD_ENH_SIZE_MULT_2, value);
	if (ret) {
		fprintf(stderr, "Could not write 0x%02x to "
			"EXT_CSD[%d] in %s\n", value,
			EXT_CSD_ENH_SIZE_MULT_2, device);
		exit(1);
	}
	value = (enh_size_mult >> 8) & 0xff;
	ret = write_extcsd_value(fd, EXT_CSD_ENH_SIZE_MULT_1, value);
	if (ret) {
		fprintf(stderr, "Could not write 0x%02x to "
			"EXT_CSD[%d] in %s\n", value,
			EXT_CSD_ENH_SIZE_MULT_1, device);
		exit(1);
	}
	value = enh_size_mult & 0xff;
	ret = write_extcsd_value(fd, EXT_CSD_ENH_SIZE_MULT_0, value);
	if (ret) {
		fprintf(stderr, "Could not write 0x%02x to "
			"EXT_CSD[%d] in %s\n", value,
			EXT_CSD_ENH_SIZE_MULT_0, device);
		exit(1);
	}
	value = ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE] | EXT_CSD_ENH_USR;
	ret = write_extcsd_value(fd, EXT_CSD_PARTITIONS_ATTRIBUTE, value);
	if (ret) {
		fprintf(stderr, "Could not write EXT_CSD_ENH_USR to "
			"EXT_CSD[%d] in %s\n",
			EXT_CSD_PARTITIONS_ATTRIBUTE, device);
		exit(1);
	}

	ret = check_enhanced_area_total_limit(device, fd);
	if (ret)
		exit(1);

	printf("Done setting ENH_USR area on %s\n", device);

	if (set_partitioning_setting_completed(dry_run, device, fd))
		exit(1);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x234(%rbp)
cmpl $0x5, -0x4(%rbp)
je 0x66e4
movq 0x14927(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
leaq 0xdbda(%rip), %rsi      # 0x142ad
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0xdac0(%rip), %rdi      # 0x141b3
callq 0x3170
cmpl $0x0, %eax
jne 0x6709
movl $0x0, -0x234(%rbp)
jmp 0x672e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0xda9e(%rip), %rdi      # 0x141b6
callq 0x3170
cmpl $0x0, %eax
jne 0x672c
movl $0x2, -0x234(%rbp)
jmp 0x672e
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x31a0
movl %eax, -0x238(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x31a0
movl %eax, -0x23c(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x230(%rbp)
movq -0x230(%rbp), %rdi
movl $0x2, %esi
movb $0x0, %al
callq 0x31e0
movl %eax, -0x224(%rbp)
cmpl $0x0, -0x224(%rbp)
jge 0x67ad
leaq 0xf846(%rip), %rdi      # 0x15fe4
callq 0x3200
movl $0x1, %edi
callq 0x3240
movl -0x224(%rbp), %edi
leaq -0x220(%rbp), %rsi
callq 0x3e90
movl %eax, -0x228(%rbp)
cmpl $0x0, -0x228(%rbp)
je 0x67f7
movq 0x1481b(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movq -0x230(%rbp), %rdx
leaq 0xcf0f(%rip), %rsi      # 0x136f5
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movzbl -0x180(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x681e
leaq 0xdaf0(%rip), %rdi      # 0x142fd
movb $0x0, %al
callq 0x30c0
movl $0x1, %edi
callq 0x3240
cmpb $0x0, -0x185(%rbp)
je 0x683f
leaq 0xd9ff(%rip), %rdi      # 0x1422d
movb $0x0, %al
callq 0x30c0
movl $0x1, %edi
callq 0x3240
leaq -0x220(%rbp), %rdi
callq 0x59d0
movl %eax, %eax
shlq $0x9, %rax
movq %rax, -0x260(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x59f0
movl %eax, %ecx
movq -0x260(%rbp), %rax
movl %ecx, %ecx
imulq %rcx, %rax
movq %rax, -0x250(%rbp)
movl -0x23c(%rbp), %eax
movq -0x250(%rbp), %rcx
shrq %rcx
addq %rcx, %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x250(%rbp)
movl %eax, -0x244(%rbp)
movl -0x238(%rbp), %eax
movl %eax, -0x254(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x59a0
movl %eax, %edx
movl $0x1, %ecx
movl $0x200, %eax            # imm = 0x200
cmpl $0x0, %edx
cmovnel %eax, %ecx
movl $0x400, %eax            # imm = 0x400
cltd
idivl %ecx
movl %eax, %ecx
movl -0x254(%rbp), %eax
imull %ecx, %eax
movl %eax, -0x240(%rbp)
movq -0x250(%rbp), %rcx
movl -0x240(%rbp), %eax
xorl %edx, %edx
divq %rcx
movl %eax, -0x240(%rbp)
movq -0x250(%rbp), %rcx
movl -0x240(%rbp), %eax
imulq %rcx, %rax
movl %eax, -0x240(%rbp)
movl -0x224(%rbp), %edi
movl $0xaf, %esi
movl $0x1, %edx
callq 0x3f30
movl %eax, -0x228(%rbp)
cmpl $0x0, -0x228(%rbp)
je 0x6962
movq 0x146b5(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movq -0x230(%rbp), %rcx
leaq 0xd4b9(%rip), %rsi      # 0x13e05
movl $0xaf, %edx
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movl -0x240(%rbp), %eax
shrl $0x18, %eax
andl $0xff, %eax
movb %al, -0x11(%rbp)
movl -0x224(%rbp), %edi
movl $0x8b, %esi
movzbl -0x11(%rbp), %edx
callq 0x3f30
movl %eax, -0x228(%rbp)
cmpl $0x0, -0x228(%rbp)
je 0x69c8
movq 0x14653(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movzbl -0x11(%rbp), %edx
movq -0x230(%rbp), %r8
leaq 0xcd98(%rip), %rsi      # 0x1374a
movl $0x8b, %ecx
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movl -0x240(%rbp), %eax
shrl $0x10, %eax
andl $0xff, %eax
movb %al, -0x11(%rbp)
movl -0x224(%rbp), %edi
movl $0x8a, %esi
movzbl -0x11(%rbp), %edx
callq 0x3f30
movl %eax, -0x228(%rbp)
cmpl $0x0, -0x228(%rbp)
je 0x6a2e
movq 0x145ed(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movzbl -0x11(%rbp), %edx
movq -0x230(%rbp), %r8
leaq 0xcd32(%rip), %rsi      # 0x1374a
movl $0x8a, %ecx
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movl -0x240(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, -0x11(%rbp)
movl -0x224(%rbp), %edi
movl $0x89, %esi
movzbl -0x11(%rbp), %edx
callq 0x3f30
movl %eax, -0x228(%rbp)
cmpl $0x0, -0x228(%rbp)
je 0x6a94
movq 0x14587(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movzbl -0x11(%rbp), %edx
movq -0x230(%rbp), %r8
leaq 0xcccc(%rip), %rsi      # 0x1374a
movl $0x89, %ecx
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movl -0x240(%rbp), %eax
andl $0xff, %eax
movb %al, -0x11(%rbp)
movl -0x224(%rbp), %edi
movl $0x88, %esi
movzbl -0x11(%rbp), %edx
callq 0x3f30
movl %eax, -0x228(%rbp)
cmpl $0x0, -0x228(%rbp)
je 0x6af7
movq 0x14524(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movzbl -0x11(%rbp), %edx
movq -0x230(%rbp), %r8
leaq 0xcc69(%rip), %rsi      # 0x1374a
movl $0x88, %ecx
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movl -0x244(%rbp), %eax
shrl $0x10, %eax
andl $0xff, %eax
movb %al, -0x11(%rbp)
movl -0x224(%rbp), %edi
movl $0x8e, %esi
movzbl -0x11(%rbp), %edx
callq 0x3f30
movl %eax, -0x228(%rbp)
cmpl $0x0, -0x228(%rbp)
je 0x6b5d
movq 0x144be(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movzbl -0x11(%rbp), %edx
movq -0x230(%rbp), %r8
leaq 0xcc03(%rip), %rsi      # 0x1374a
movl $0x8e, %ecx
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movl -0x244(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, -0x11(%rbp)
movl -0x224(%rbp), %edi
movl $0x8d, %esi
movzbl -0x11(%rbp), %edx
callq 0x3f30
movl %eax, -0x228(%rbp)
cmpl $0x0, -0x228(%rbp)
je 0x6bc3
movq 0x14458(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movzbl -0x11(%rbp), %edx
movq -0x230(%rbp), %r8
leaq 0xcb9d(%rip), %rsi      # 0x1374a
movl $0x8d, %ecx
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movl -0x244(%rbp), %eax
andl $0xff, %eax
movb %al, -0x11(%rbp)
movl -0x224(%rbp), %edi
movl $0x8c, %esi
movzbl -0x11(%rbp), %edx
callq 0x3f30
movl %eax, -0x228(%rbp)
cmpl $0x0, -0x228(%rbp)
je 0x6c26
movq 0x143f5(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movzbl -0x11(%rbp), %edx
movq -0x230(%rbp), %r8
leaq 0xcb3a(%rip), %rsi      # 0x1374a
movl $0x8c, %ecx
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movzbl -0x184(%rbp), %eax
orl $0x1, %eax
movb %al, -0x11(%rbp)
movl -0x224(%rbp), %edi
movl $0x9c, %esi
movzbl -0x11(%rbp), %edx
callq 0x3f30
movl %eax, -0x228(%rbp)
cmpl $0x0, -0x228(%rbp)
je 0x6c84
movq 0x14393(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movq -0x230(%rbp), %rcx
leaq 0xd6b3(%rip), %rsi      # 0x14321
movl $0x9c, %edx
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movq -0x230(%rbp), %rdi
movl -0x224(%rbp), %esi
callq 0x5ba0
movl %eax, -0x228(%rbp)
cmpl $0x0, -0x228(%rbp)
je 0x6caf
movl $0x1, %edi
callq 0x3240
movq -0x230(%rbp), %rsi
leaq 0xd69a(%rip), %rdi      # 0x14357
movb $0x0, %al
callq 0x30c0
movl -0x234(%rbp), %edi
movq -0x230(%rbp), %rsi
movl -0x224(%rbp), %edx
callq 0x5a10
cmpl $0x0, %eax
je 0x6ceb
movl $0x1, %edi
callq 0x3240
xorl %eax, %eax
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
nopw %cs:(%rax,%rax)