// File: /workspace/github_c_makefile_star2_O3/blasphemy[P]mmc-utils/mmc_cmds.c
// Function: do_write_boot_en
int do_write_boot_en(int nargs, char **argv)
{
	__u8 ext_csd[512];
	__u8 value = 0;
	int fd, ret;
	char *device;
	int boot_area, send_ack;

	if (nargs != 4) {
		fprintf(stderr, "Usage: mmc bootpart enable <partition_number> <send_ack> </path/to/mmcblkX>\n");
		exit(1);
	}

	/*
	 * If <send_ack> is 1, the device will send acknowledgment
	 * pattern "010" to the host when boot operation begins.
	 * If <send_ack> is 0, it won't.
	 */
	boot_area = strtol(argv[1], NULL, 10);
	send_ack = strtol(argv[2], NULL, 10);
	device = argv[3];

	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);
	}

	value = ext_csd[EXT_CSD_PART_CONFIG];

	switch (boot_area) {
	case EXT_CSD_PART_CONFIG_ACC_NONE:
		value &= ~(7 << 3);
		break;
	case EXT_CSD_PART_CONFIG_ACC_BOOT0:
		value |= (1 << 3);
		value &= ~(3 << 4);
		break;
	case EXT_CSD_PART_CONFIG_ACC_BOOT1:
		value |= (1 << 4);
		value &= ~(1 << 3);
		value &= ~(1 << 5);
		break;
	case EXT_CSD_PART_CONFIG_ACC_USER_AREA:
		value |= (boot_area << 3);
		break;
	default:
		fprintf(stderr, "Cannot enable the boot area\n");
		exit(1);
	}
	if (send_ack)
		value |= EXT_CSD_PART_CONFIG_ACC_ACK;
	else
		value &= ~EXT_CSD_PART_CONFIG_ACC_ACK;

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
cmpl $0x4, %edi
jne 0x4aa7
movq %rsi, %rbx
movq 0x8(%rsi), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x3180
movq %rax, %r15
movq 0x10(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x3180
movq %rax, %r14
movq 0x18(%rbx), %rbx
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x31d0
testl %eax, %eax
js 0x4ac6
movl %eax, %ebp
movq %rsp, %rsi
movl %eax, %edi
callq 0x3eac
testl %eax, %eax
jne 0x4acb
cmpl $0x7, %r15d
ja 0x4b20
movb 0xb3(%rsp), %al
movl %r15d, %ecx
leaq 0x9bd4(%rip), %rdx      # 0xe62c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
andb $-0x39, %al
jmp 0x4a73
andb $-0x39, %al
orb $0x10, %al
jmp 0x4a73
orb $0x38, %al
jmp 0x4a73
andb $-0x39, %al
orb $0x8, %al
testl %r14d, %r14d
setne %cl
andb $-0x41, %al
shlb $0x6, %cl
orb %al, %cl
movzbl %cl, %r14d
movl %ebp, %edi
movl $0xb3, %esi
movl %r14d, %edx
callq 0x3f3a
testl %eax, %eax
jne 0x4aed
xorl %eax, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x12542(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0x9f7a(%rip), %rdx      # 0xea32
movl $0x1, %esi
xorl %eax, %eax
callq 0x3240
jmp 0x4b16
callq 0x336a
movq 0x1251e(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0x9c29(%rip), %rdx      # 0xe705
movl $0x1, %esi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3240
jmp 0x4b16
movq 0x124fc(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0x9c5c(%rip), %rdx      # 0xe75a
movl $0x1, %esi
movl %r14d, %ecx
movl $0xb3, %r8d
movq %rbx, %r9
xorl %eax, %eax
callq 0x3240
movl $0x1, %edi
callq 0x3220
movq 0x124c9(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0x9f4e(%rip), %rdx      # 0xea7f
jmp 0x4ab8