// File: /workspace/github_c_makefile_star2_O0/blasphemy[P]mmc-utils/mmc_cmds.c
// Function: do_disable_512B_emulation
int do_disable_512B_emulation(int nargs, char **argv)
{
	__u8 ext_csd[512], native_sector_size, data_sector_size, wr_rel_param;
	int fd, ret;
	char *device;

	if (nargs != 2) {
		fprintf(stderr, "Usage: mmc disable 512B emulation </path/to/mmcblkX>\n");
		exit(1);
	}

	device = argv[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);
	}

	wr_rel_param = ext_csd[EXT_CSD_WR_REL_PARAM];
	native_sector_size = ext_csd[EXT_CSD_NATIVE_SECTOR_SIZE];
	data_sector_size = ext_csd[EXT_CSD_DATA_SECTOR_SIZE];

	if (native_sector_size && !data_sector_size &&
	   (wr_rel_param & EN_REL_WR)) {
		ret = write_extcsd_value(fd, EXT_CSD_USE_NATIVE_SECTOR, 1);

		if (ret) {
			fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n",
					1, EXT_CSD_NATIVE_SECTOR_SIZE, device);
			exit(1);
		}
		printf("MMC disable 512B emulation successful.  Now reset the device to switch to 4KB native sector mode.\n");
	} else if (native_sector_size && data_sector_size) {
		printf("MMC 512B emulation mode is already disabled; doing nothing.\n");
	} else {
		printf("MMC does not support disabling 512B emulation mode.\n");
	}

	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x4(%rbp)
je 0x4dba
movq 0x16251(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
leaq 0xeb6e(%rip), %rsi      # 0x13917
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movq -0x10(%rbp), %rax
movq 0x8(%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 0x4e01
leaq 0x111f2(%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 0x4e4b
movq 0x161c7(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movq -0x228(%rbp), %rdx
leaq 0xe8bb(%rip), %rsi      # 0x136f5
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movb -0x16a(%rbp), %al
movb %al, -0x213(%rbp)
movb -0x1d1(%rbp), %al
movb %al, -0x211(%rbp)
movb -0x1d3(%rbp), %al
movb %al, -0x212(%rbp)
movzbl -0x211(%rbp), %eax
cmpl $0x0, %eax
je 0x4efa
cmpb $0x0, -0x212(%rbp)
jne 0x4efa
movzbl -0x213(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x4efa
movl -0x218(%rbp), %edi
movl $0x3e, %esi
movl $0x1, %edx
callq 0x3f30
movl %eax, -0x21c(%rbp)
cmpl $0x0, -0x21c(%rbp)
je 0x4eea
movq 0x16132(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movq -0x228(%rbp), %r8
leaq 0xe87b(%rip), %rsi      # 0x1374a
movl $0x1, %edx
movl $0x3f, %ecx
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
leaq 0xea5c(%rip), %rdi      # 0x1394d
movb $0x0, %al
callq 0x30c0
jmp 0x4f32
movzbl -0x211(%rbp), %eax
cmpl $0x0, %eax
je 0x4f22
movzbl -0x212(%rbp), %eax
cmpl $0x0, %eax
je 0x4f22
leaq 0xea97(%rip), %rdi      # 0x139b0
movb $0x0, %al
callq 0x30c0
jmp 0x4f30
leaq 0xeac4(%rip), %rdi      # 0x139ed
movb $0x0, %al
callq 0x30c0
jmp 0x4f32
movl -0x21c(%rbp), %eax
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
nopw %cs:(%rax,%rax)