// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
cmpl $0x4, %edi
jne 0x58fe
movq %rsi, %rbx
movq 0x8(%rsi), %rcx
movzbl (%rcx), %edx
leal -0x2d(%rdx), %eax
negl %eax
cmpl $0x2d, %edx
jne 0x5831
movzbl 0x1(%rcx), %esi
subl $0x79, %esi
jne 0x5813
movzbl 0x2(%rcx), %esi
negl %esi
testl %esi, %esi
je 0x58f7
cmpb $0x2d, %dl
jne 0x5831
movzbl 0x1(%rcx), %eax
subl $0x63, %eax
jne 0x582f
movzbl 0x2(%rcx), %eax
negl %eax
xorl %ebp, %ebp
cmpl $0x1, %eax
adcl $0x1, %ebp
movq 0x10(%rbx), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x3180
movq %rax, %r15
movq 0x18(%rbx), %rbx
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x31e0
testl %eax, %eax
js 0x591d
movl %eax, %r14d
movq %rsp, %rsi
movl %eax, %edi
callq 0x39b8
testl %eax, %eax
jne 0x5931
cmpb $0x0, 0x9b(%rsp)
jne 0x5953
testb $0x1, 0xa6(%rsp)
je 0x595c
pushq $0x1
popq %rax
movl %r15d, %ecx
shll %cl, %eax
orb 0xa7(%rsp), %al
movzbl %al, %r15d
movl %r14d, %edi
movl $0xa7, %esi
movl %r15d, %edx
callq 0x3a43
testl %eax, %eax
jne 0x5976
leaq 0x9b41(%rip), %rsi      # 0xf407
pushq $0x1
popq %rdi
movl %r15d, %edx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x31d0
movl %ebp, %edi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x4b8b
testl %eax, %eax
jne 0x5929
xorl %eax, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
jmp 0x5839
movq 0x126eb(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0x9a6a(%rip), %rdx      # 0xf379
pushq $0x1
popq %rbx
movl %ebx, %esi
xorl %eax, %eax
callq 0x3250
jmp 0x596f
leaq 0xb6c1(%rip), %rdi      # 0x10fe5
callq 0x31f0
pushq $0x1
popq %rdi
callq 0x3230
movq 0x126b8(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0x8dc3(%rip), %rdx      # 0xe705
pushq $0x1
popq %rbp
movl %ebp, %esi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3250
jmp 0x599f
leaq 0x98d4(%rip), %rsi      # 0xf22e
jmp 0x5963
leaq 0x9a62(%rip), %rsi      # 0xf3c5
pushq $0x1
popq %rbx
movl %ebx, %edi
xorl %eax, %eax
callq 0x31d0
movl %ebx, %edi
callq 0x3230
movq 0x12673(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0x8dd3(%rip), %rdx      # 0xe75a
pushq $0x1
popq %rbp
movl %ebp, %esi
movl %r15d, %ecx
movl $0xa7, %r8d
movq %rbx, %r9
xorl %eax, %eax
callq 0x3250
movl %ebp, %edi
callq 0x3230