// File: /workspace/github_c_makefile_star2_O1/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 0x5e10
movq %rsi, %rbx
movq 0x8(%rsi), %r14
leaq 0x94a4(%rip), %rdi      # 0xf1c3
movq %r14, %rsi
callq 0x3150
testl %eax, %eax
je 0x5d44
leaq 0x9494(%rip), %rdi      # 0xf1c6
movq %r14, %rsi
callq 0x3150
xorl %ebp, %ebp
cmpl $0x1, %eax
adcl $0x1, %ebp
jmp 0x5d46
xorl %ebp, %ebp
movq 0x10(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x3180
movq %rax, %r15
movq 0x18(%rbx), %rbx
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x31d0
testl %eax, %eax
js 0x5e2f
movl %eax, %r14d
movq %rsp, %rsi
movl %eax, %edi
callq 0x3ef8
testl %eax, %eax
jne 0x5e34
cmpb $0x0, 0x9b(%rsp)
jne 0x5e56
testb $0x1, 0xa6(%rsp)
je 0x5e5f
movl $0x1, %eax
movl %r15d, %ecx
shll %cl, %eax
orb 0xa7(%rsp), %al
movzbl %al, %r15d
movl %r14d, %edi
movl $0xa7, %esi
movl %r15d, %edx
callq 0x3f8e
testl %eax, %eax
jne 0x5e74
leaq 0x963d(%rip), %rsi      # 0xf416
movl $0x1, %edi
movl %r15d, %edx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x31c0
movl %ebp, %edi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x5071
testl %eax, %eax
jne 0x5e9d
xorl %eax, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x111d9(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0x9567(%rip), %rdx      # 0xf388
movl $0x1, %esi
xorl %eax, %eax
callq 0x3240
jmp 0x5e9d
callq 0x33e9
movq 0x111b5(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0x88c0(%rip), %rdx      # 0xe705
movl $0x1, %esi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3240
jmp 0x5e9d
leaq 0x93e0(%rip), %rsi      # 0xf23d
jmp 0x5e66
leaq 0x956e(%rip), %rsi      # 0xf3d4
movl $0x1, %edi
xorl %eax, %eax
callq 0x31c0
jmp 0x5e9d
movq 0x11175(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0x88d5(%rip), %rdx      # 0xe75a
movl $0x1, %esi
movl %r15d, %ecx
movl $0xa7, %r8d
movq %rbx, %r9
xorl %eax, %eax
callq 0x3240
movl $0x1, %edi
callq 0x3220