// File: /workspace/github_c_makefile_star2_O2/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 0x45c2
movq %rsi, %rbx
movq 0x8(%rsi), %rdi
pushq $0xa
popq %rbp
xorl %esi, %esi
movl %ebp, %edx
callq 0x3180
movq %rax, %r15
movq 0x10(%rbx), %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x3180
movq %rax, %r14
movq 0x18(%rbx), %rbx
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x31e0
testl %eax, %eax
js 0x45e6
movl %eax, %ebp
movq %rsp, %rsi
movl %eax, %edi
callq 0x39b8
testl %eax, %eax
jne 0x45fa
cmpl $0x7, %r15d
ja 0x464c
movb 0xb3(%rsp), %al
movl %r15d, %ecx
leaq 0xa0b9(%rip), %rdx      # 0xe62c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
andb $-0x39, %al
jmp 0x458e
andb $-0x39, %al
orb $0x10, %al
jmp 0x458e
orb $0x38, %al
jmp 0x458e
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 0x3a43
testl %eax, %eax
jne 0x461c
xorl %eax, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x13a27(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0xa45f(%rip), %rdx      # 0xea32
pushq $0x1
popq %rbx
movl %ebx, %esi
xorl %eax, %eax
callq 0x3250
movl %ebx, %edi
callq 0x3230
leaq 0xc9f8(%rip), %rdi      # 0x10fe5
callq 0x31f0
pushq $0x1
popq %rdi
callq 0x3230
movq 0x139ef(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0xa0fa(%rip), %rdx      # 0xe705
pushq $0x1
popq %rbp
movl %ebp, %esi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3250
jmp 0x4645
movq 0x139cd(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0xa12d(%rip), %rdx      # 0xe75a
pushq $0x1
popq %rbp
movl %ebp, %esi
movl %r14d, %ecx
movl $0xb3, %r8d
movq %rbx, %r9
xorl %eax, %eax
callq 0x3250
movl %ebp, %edi
callq 0x3230
movq 0x1399d(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0xa422(%rip), %rdx      # 0xea7f
jmp 0x45d3