// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x211(%rbp)
cmpl $0x4, -0x4(%rbp)
je 0x4f91
movq 0x1607a(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
leaq 0xeaa2(%rip), %rsi      # 0x13a22
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x31a0
movl %eax, -0x22c(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x31a0
movl %eax, -0x230(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x228(%rbp)
movq -0x228(%rbp), %rdi
movl $0x2, %esi
movb $0x0, %al
callq 0x31e0
movl %eax, -0x218(%rbp)
cmpl $0x0, -0x218(%rbp)
jge 0x5010
leaq 0x10fe3(%rip), %rdi     # 0x15fe4
callq 0x3200
movl $0x1, %edi
callq 0x3240
movl -0x218(%rbp), %edi
leaq -0x210(%rbp), %rsi
callq 0x3e90
movl %eax, -0x21c(%rbp)
cmpl $0x0, -0x21c(%rbp)
je 0x505a
movq 0x15fb8(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movq -0x228(%rbp), %rdx
leaq 0xe6ac(%rip), %rsi      # 0x136f5
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movb -0x15d(%rbp), %al
movb %al, -0x211(%rbp)
movl -0x22c(%rbp), %eax
movq %rax, -0x238(%rbp)
subq $0x7, %rax
ja 0x5117
movq -0x238(%rbp), %rax
leaq 0xe5a1(%rip), %rcx      # 0x1362c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzbl -0x211(%rbp), %eax
andl $-0x39, %eax
movb %al, -0x211(%rbp)
jmp 0x5139
movzbl -0x211(%rbp), %eax
orl $0x8, %eax
movb %al, -0x211(%rbp)
movzbl -0x211(%rbp), %eax
andl $-0x31, %eax
movb %al, -0x211(%rbp)
jmp 0x5139
movzbl -0x211(%rbp), %eax
orl $0x10, %eax
movb %al, -0x211(%rbp)
movzbl -0x211(%rbp), %eax
andl $-0x9, %eax
movb %al, -0x211(%rbp)
movzbl -0x211(%rbp), %eax
andl $-0x21, %eax
movb %al, -0x211(%rbp)
jmp 0x5139
movl -0x22c(%rbp), %ecx
shll $0x3, %ecx
movzbl -0x211(%rbp), %eax
orl %ecx, %eax
movb %al, -0x211(%rbp)
jmp 0x5139
movq 0x15ed2(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
leaq 0xe947(%rip), %rsi      # 0x13a6f
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
cmpl $0x0, -0x230(%rbp)
je 0x5154
movzbl -0x211(%rbp), %eax
orl $0x40, %eax
movb %al, -0x211(%rbp)
jmp 0x5164
movzbl -0x211(%rbp), %eax
andl $-0x41, %eax
movb %al, -0x211(%rbp)
movl -0x218(%rbp), %edi
movl $0xb3, %esi
movzbl -0x211(%rbp), %edx
callq 0x3f30
movl %eax, -0x21c(%rbp)
cmpl $0x0, -0x21c(%rbp)
je 0x51bf
movq 0x15e5f(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movzbl -0x211(%rbp), %edx
movq -0x228(%rbp), %r8
leaq 0xe5a1(%rip), %rsi      # 0x1374a
movl $0xb3, %ecx
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movl -0x21c(%rbp), %eax
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
nop