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

	int dry_run = 1;
	int partition;
	char *device;

	if (nargs != 4) {
		fprintf(stderr,"Usage: mmc write_reliability set <-y|-n|-c> <partition> </path/to/mmcblkX>\n");
		exit(1);
	}

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

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

	/* assert not PARTITION_SETTING_COMPLETED */
	if (ext_csd[EXT_CSD_PARTITION_SETTING_COMPLETED])
	{
		printf(" Device is already partitioned\n");
		exit(1);
	}

	/* assert HS_CTRL_REL */
	if (!(ext_csd[EXT_CSD_WR_REL_PARAM] & HS_CTRL_REL)) {
		printf("Cannot set write reliability parameters, WR_REL_SET is "
				"read-only\n");
		exit(1);
	}

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

	printf("Done setting EXT_CSD_WR_REL_SET to 0x%02x on %s\n",
		value, device);

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

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x22c(%rbp)
cmpl $0x4, -0x4(%rbp)
je 0x6d44
movq 0x142c7(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
leaq 0xd645(%rip), %rsi      # 0x14378
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0xd460(%rip), %rdi      # 0x141b3
callq 0x3170
cmpl $0x0, %eax
jne 0x6d69
movl $0x0, -0x22c(%rbp)
jmp 0x6d8e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0xd43e(%rip), %rdi      # 0x141b6
callq 0x3170
cmpl $0x0, %eax
jne 0x6d8c
movl $0x2, -0x22c(%rbp)
jmp 0x6d8e
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, -0x238(%rbp)
movq -0x238(%rbp), %rdi
movl $0x2, %esi
movb $0x0, %al
callq 0x31e0
movl %eax, -0x224(%rbp)
cmpl $0x0, -0x224(%rbp)
jge 0x6df1
leaq 0xf202(%rip), %rdi      # 0x15fe4
callq 0x3200
movl $0x1, %edi
callq 0x3240
movl -0x224(%rbp), %edi
leaq -0x220(%rbp), %rsi
callq 0x3e90
movl %eax, -0x228(%rbp)
cmpl $0x0, -0x228(%rbp)
je 0x6e3b
movq 0x141d7(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movq -0x238(%rbp), %rdx
leaq 0xc8cb(%rip), %rsi      # 0x136f5
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
cmpb $0x0, -0x185(%rbp)
je 0x6e5c
leaq 0xd3e2(%rip), %rdi      # 0x1422d
movb $0x0, %al
callq 0x30c0
movl $0x1, %edi
callq 0x3240
movzbl -0x17a(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x6e83
leaq 0xd552(%rip), %rdi      # 0x143c4
movb $0x0, %al
callq 0x30c0
movl $0x1, %edi
callq 0x3240
movzbl -0x179(%rbp), %eax
movl -0x230(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
orl %ecx, %eax
movb %al, -0x11(%rbp)
movl -0x224(%rbp), %edi
movl $0xa7, %esi
movzbl -0x11(%rbp), %edx
callq 0x3f30
movl %eax, -0x228(%rbp)
cmpl $0x0, -0x228(%rbp)
je 0x6ef3
movq 0x14128(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movzbl -0x11(%rbp), %edx
movq -0x238(%rbp), %r8
leaq 0xc86d(%rip), %rsi      # 0x1374a
movl $0xa7, %ecx
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movzbl -0x11(%rbp), %esi
movq -0x238(%rbp), %rdx
leaq 0xd501(%rip), %rdi      # 0x14406
movb $0x0, %al
callq 0x30c0
movl -0x22c(%rbp), %edi
movq -0x238(%rbp), %rsi
movl -0x224(%rbp), %edx
callq 0x5a10
cmpl $0x0, %eax
je 0x6f33
movl $0x1, %edi
callq 0x3240
xorl %eax, %eax
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
nop