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

	if (nargs != 7) {
		fprintf(stderr, "Usage: mmc gp create <-y|-n|-c> <length KiB> <partition> <enh_attr> <ext_attr> </path/to/mmcblkX>\n");
		exit(1);
	}

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

	length_kib = strtol(argv[2], NULL, 10);
	partition = strtol(argv[3], NULL, 10);
	enh_attr = strtol(argv[4], NULL, 10);
	ext_attr = strtol(argv[5], NULL, 10);
	device = argv[6];

	if (partition < 1 || partition > 4) {
		printf("Invalid gp partition number; valid range [1-4].\n");
		exit(1);
	}

	if (enh_attr && ext_attr) {
		printf("Not allowed to set both enhanced attribute and extended attribute\n");
		exit(1);
	}

	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 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);
	gp_size_mult = (length_kib + align/2l) / 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);
	}

	value = (gp_size_mult >> 16) & 0xff;
	address = EXT_CSD_GP_SIZE_MULT_1_2 + (partition - 1) * 3;
	ret = write_extcsd_value(fd, address, value);
	if (ret) {
		fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
			value, address, device);
		exit(1);
	}
	value = (gp_size_mult >> 8) & 0xff;
	address = EXT_CSD_GP_SIZE_MULT_1_1 + (partition - 1) * 3;
	ret = write_extcsd_value(fd, address, value);
	if (ret) {
		fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
			value, address, device);
		exit(1);
	}
	value = gp_size_mult & 0xff;
	address = EXT_CSD_GP_SIZE_MULT_1_0 + (partition - 1) * 3;
	ret = write_extcsd_value(fd, address, value);
	if (ret) {
		fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
			value, address, device);
		exit(1);
	}

	value = ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE];
	if (enh_attr)
		value |= (1 << partition);
	else
		value &= ~(1 << partition);

	ret = write_extcsd_value(fd, EXT_CSD_PARTITIONS_ATTRIBUTE, value);
	if (ret) {
		fprintf(stderr, "Could not write EXT_CSD_ENH_%x to EXT_CSD[%d] in %s\n",
			partition, EXT_CSD_PARTITIONS_ATTRIBUTE, device);
		exit(1);
	}

	address = EXT_CSD_EXT_PARTITIONS_ATTRIBUTE_0 + (partition - 1) / 2;
	value = ext_csd[address];
	if (ext_attr)
		value |= (ext_attr << (4 * ((partition - 1) % 2)));
	else
		value &= (0xF << (4 * ((partition % 2))));

	ret = write_extcsd_value(fd, address, value);
	if (ret) {
		fprintf(stderr, "Could not write 0x%x to EXT_CSD[%d] in %s\n",
			value, address, device);
		exit(1);
	}

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

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

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x23c(%rbp)
cmpl $0x7, -0x4(%rbp)
je 0x60b4
movq 0x14f57(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
leaq 0xe0ad(%rip), %rsi      # 0x14150
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0xe0f0(%rip), %rdi      # 0x141b3
callq 0x3170
cmpl $0x0, %eax
jne 0x60d9
movl $0x0, -0x23c(%rbp)
jmp 0x60fe
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0xe0ce(%rip), %rdi      # 0x141b6
callq 0x3170
cmpl $0x0, %eax
jne 0x60fc
movl $0x2, -0x23c(%rbp)
jmp 0x60fe
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x31a0
movl %eax, -0x24c(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x31a0
movl %eax, -0x240(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x31a0
movl %eax, -0x244(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x31a0
movl %eax, -0x248(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x238(%rbp)
cmpl $0x1, -0x240(%rbp)
jl 0x618f
cmpl $0x4, -0x240(%rbp)
jle 0x61a7
leaq 0xe023(%rip), %rdi      # 0x141b9
movb $0x0, %al
callq 0x30c0
movl $0x1, %edi
callq 0x3240
cmpl $0x0, -0x244(%rbp)
je 0x61d1
cmpl $0x0, -0x248(%rbp)
je 0x61d1
leaq 0xe02a(%rip), %rdi      # 0x141ea
movb $0x0, %al
callq 0x30c0
movl $0x1, %edi
callq 0x3240
movq -0x238(%rbp), %rdi
movl $0x2, %esi
movb $0x0, %al
callq 0x31e0
movl %eax, -0x228(%rbp)
cmpl $0x0, -0x228(%rbp)
jge 0x6209
leaq 0xfdea(%rip), %rdi      # 0x15fe4
callq 0x3200
movl $0x1, %edi
callq 0x3240
movl -0x228(%rbp), %edi
leaq -0x220(%rbp), %rsi
callq 0x3e90
movl %eax, -0x22c(%rbp)
cmpl $0x0, -0x22c(%rbp)
je 0x6253
movq 0x14dbf(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movq -0x238(%rbp), %rdx
leaq 0xd4b3(%rip), %rsi      # 0x136f5
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
cmpb $0x0, -0x185(%rbp)
je 0x6274
leaq 0xdfca(%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, -0x258(%rbp)
movl -0x24c(%rbp), %eax
movq -0x258(%rbp), %rcx
shrq %rcx
addq %rcx, %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x258(%rbp)
movl %eax, -0x250(%rbp)
movl -0x228(%rbp), %edi
movl $0xaf, %esi
movl $0x1, %edx
callq 0x3f30
movl %eax, -0x22c(%rbp)
cmpl $0x0, -0x22c(%rbp)
je 0x6325
movq 0x14cf2(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movq -0x238(%rbp), %rcx
leaq 0xdaf6(%rip), %rsi      # 0x13e05
movl $0xaf, %edx
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movl -0x250(%rbp), %eax
shrl $0x10, %eax
andl $0xff, %eax
movb %al, -0x11(%rbp)
movl -0x240(%rbp), %eax
subl $0x1, %eax
imull $0x3, %eax, %eax
addl $0x91, %eax
movb %al, -0x221(%rbp)
movl -0x228(%rbp), %edi
movb -0x221(%rbp), %al
movzbl %al, %esi
movzbl -0x11(%rbp), %edx
callq 0x3f30
movl %eax, -0x22c(%rbp)
cmpl $0x0, -0x22c(%rbp)
je 0x63a8
movq 0x14c75(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movzbl -0x11(%rbp), %edx
movzbl -0x221(%rbp), %ecx
movq -0x238(%rbp), %r8
leaq 0xd3b3(%rip), %rsi      # 0x1374a
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movl -0x250(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, -0x11(%rbp)
movl -0x240(%rbp), %eax
subl $0x1, %eax
imull $0x3, %eax, %eax
addl $0x90, %eax
movb %al, -0x221(%rbp)
movl -0x228(%rbp), %edi
movb -0x221(%rbp), %al
movzbl %al, %esi
movzbl -0x11(%rbp), %edx
callq 0x3f30
movl %eax, -0x22c(%rbp)
cmpl $0x0, -0x22c(%rbp)
je 0x642b
movq 0x14bf2(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movzbl -0x11(%rbp), %edx
movzbl -0x221(%rbp), %ecx
movq -0x238(%rbp), %r8
leaq 0xd330(%rip), %rsi      # 0x1374a
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movl -0x250(%rbp), %eax
andl $0xff, %eax
movb %al, -0x11(%rbp)
movl -0x240(%rbp), %eax
subl $0x1, %eax
imull $0x3, %eax, %eax
addl $0x8f, %eax
movb %al, -0x221(%rbp)
movl -0x228(%rbp), %edi
movb -0x221(%rbp), %al
movzbl %al, %esi
movzbl -0x11(%rbp), %edx
callq 0x3f30
movl %eax, -0x22c(%rbp)
cmpl $0x0, -0x22c(%rbp)
je 0x64ab
movq 0x14b72(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movzbl -0x11(%rbp), %edx
movzbl -0x221(%rbp), %ecx
movq -0x238(%rbp), %r8
leaq 0xd2b0(%rip), %rsi      # 0x1374a
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movb -0x184(%rbp), %al
movb %al, -0x11(%rbp)
cmpl $0x0, -0x244(%rbp)
je 0x64d7
movl -0x240(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movzbl -0x11(%rbp), %eax
orl %ecx, %eax
movb %al, -0x11(%rbp)
jmp 0x64f2
movl -0x240(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
xorl $-0x1, %ecx
movzbl -0x11(%rbp), %eax
andl %ecx, %eax
movb %al, -0x11(%rbp)
movl -0x228(%rbp), %edi
movl $0x9c, %esi
movzbl -0x11(%rbp), %edx
callq 0x3f30
movl %eax, -0x22c(%rbp)
cmpl $0x0, -0x22c(%rbp)
je 0x6549
movq 0x14ad4(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movl -0x240(%rbp), %edx
movq -0x238(%rbp), %r8
leaq 0xdd1a(%rip), %rsi      # 0x1424d
movl $0x9c, %ecx
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movl -0x240(%rbp), %eax
subl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
addl $0x34, %eax
movb %al, -0x221(%rbp)
movzbl -0x221(%rbp), %eax
movb -0x220(%rbp,%rax), %al
movb %al, -0x11(%rbp)
cmpl $0x0, -0x248(%rbp)
je 0x65b4
movl -0x248(%rbp), %eax
movl %eax, -0x264(%rbp)
movl -0x240(%rbp), %eax
subl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl -0x264(%rbp), %eax
movl %edx, %ecx
shll $0x2, %ecx
shll %cl, %eax
movl %eax, %ecx
movzbl -0x11(%rbp), %eax
orl %ecx, %eax
movb %al, -0x11(%rbp)
jmp 0x65d9
movl -0x240(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %edx, %ecx
shll $0x2, %ecx
movl $0xf, %eax
shll %cl, %eax
movl %eax, %ecx
movzbl -0x11(%rbp), %eax
andl %ecx, %eax
movb %al, -0x11(%rbp)
movl -0x228(%rbp), %edi
movb -0x221(%rbp), %al
movzbl %al, %esi
movzbl -0x11(%rbp), %edx
callq 0x3f30
movl %eax, -0x22c(%rbp)
cmpl $0x0, -0x22c(%rbp)
je 0x6634
movq 0x149e9(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movzbl -0x11(%rbp), %edx
movzbl -0x221(%rbp), %ecx
movq -0x238(%rbp), %r8
leaq 0xdc5f(%rip), %rsi      # 0x14282
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movq -0x238(%rbp), %rdi
movl -0x228(%rbp), %esi
callq 0x5ba0
movl %eax, -0x22c(%rbp)
cmpl $0x0, -0x22c(%rbp)
je 0x665f
movl $0x1, %edi
callq 0x3240
movl -0x23c(%rbp), %edi
movq -0x238(%rbp), %rsi
movl -0x228(%rbp), %edx
callq 0x5a10
cmpl $0x0, %eax
je 0x6686
movl $0x1, %edi
callq 0x3240
xorl %eax, %eax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
nopw %cs:(%rax,%rax)