// File: /workspace/github_c_makefile_star2_O1/blasphemy[P]mmc-utils/mmc_cmds.c
// Function: do_writeprotect_user_set
int do_writeprotect_user_set(int nargs, char **argv)
{
	__u8 ext_csd[512];
	int fd, ret;
	char *device;
	int blk_start;
	int blk_cnt;
	__u32 wp_blks;
	__u8 user_wp;
	int x;
	int wptype;

	if (nargs != 5)
		goto usage;
	device = argv[4];
	fd = open(device, O_RDWR);
	if (fd < 0) {
		perror("open");
		exit(1);
	}
	if (!strcmp(argv[1], "none")) {
		wptype = WPTYPE_NONE;
	} else if (!strcmp(argv[1], "temp")) {
		wptype = WPTYPE_TEMP;
	} else if (!strcmp(argv[1], "pwron")) {
		wptype = WPTYPE_PWRON;
#ifdef DANGEROUS_COMMANDS_ENABLED
	} else if (!strcmp(argv[1], "perm")) {
		wptype = WPTYPE_PERM;
#endif /* DANGEROUS_COMMANDS_ENABLED */
	} else {
		fprintf(stderr, "Error, invalid \"type\"\n");
		goto usage;
	}
	ret = read_extcsd(fd, ext_csd);
	if (ret) {
		fprintf(stderr, "Could not read EXT_CSD from %s\n", device);
		exit(1);
	}
	ret = get_wp_group_size_in_blks(ext_csd, &wp_blks);
	if (ret) {
		fprintf(stderr, "Operation not supported for this device\n");
		exit(1);
	}
	blk_start = strtol(argv[2], NULL, 0);
	blk_cnt = strtol(argv[3], NULL, 0);
	if ((blk_start % wp_blks) || (blk_cnt % wp_blks)) {
		fprintf(stderr, "<start block> and <blocks> must be a ");
		fprintf(stderr, "multiple of the Write Protect Group (%d)\n",
			wp_blks);
		exit(1);
	}
	if (wptype != WPTYPE_NONE) {
		user_wp = ext_csd[EXT_CSD_USER_WP];
		user_wp &= ~USER_WP_CLEAR;
		switch (wptype) {
		case WPTYPE_TEMP:
			break;
		case WPTYPE_PWRON:
			user_wp |= USER_WP_US_PWR_WP_EN;
			break;
		case WPTYPE_PERM:
			user_wp |= USER_WP_US_PERM_WP_EN;
			break;
		}
		if (user_wp != ext_csd[EXT_CSD_USER_WP]) {
			ret = write_extcsd_value(fd, EXT_CSD_USER_WP, user_wp);
			if (ret) {
				fprintf(stderr, "Error setting EXT_CSD\n");
				exit(1);
			}
		}
	}
	for (x = 0; x < blk_cnt; x += wp_blks) {
		ret = set_write_protect(fd, blk_start + x,
					wptype != WPTYPE_NONE);
		if (ret) {
			fprintf(stderr,
				"Could not set write protect for %s\n", device);
			exit(1);
		}
	}
	if (wptype != WPTYPE_NONE) {
		ret = write_extcsd_value(fd, EXT_CSD_USER_WP,
					ext_csd[EXT_CSD_USER_WP]);
		if (ret) {
			fprintf(stderr, "Error restoring EXT_CSD\n");
			exit(1);
		}
	}
	return ret;

usage:
	fprintf(stderr,
		"Usage: mmc writeprotect user set <type><start block><blocks><device>\n");
	exit(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
cmpl $0x5, %edi
jne 0x46ac
movq %rsi, %r13
movq 0x20(%rsi), %rbp
movq %rbp, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x31d0
movl %eax, 0x4(%rsp)
testl %eax, %eax
js 0x487d
movq 0x8(%r13), %rbx
leaq 0xa195(%rip), %rsi      # 0xe7ed
movq %rbx, %rdi
callq 0x3150
movl %eax, %r14d
testl %eax, %eax
je 0x46c2
leaq 0xa184(%rip), %rsi      # 0xe7f2
movq %rbx, %rdi
callq 0x3150
testl %eax, %eax
je 0x46c2
leaq 0xa176(%rip), %rsi      # 0xe7f7
movq %rbx, %rdi
callq 0x3150
movb $0x1, %bl
testl %eax, %eax
je 0x46c4
movq 0x1295a(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0xa15d(%rip), %rdx      # 0xe7fd
movl $0x1, %esi
xorl %eax, %eax
callq 0x3240
movq 0x1293d(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0xa224(%rip), %rdx      # 0xe8e1
jmp 0x48db
xorl %ebx, %ebx
leaq 0x60(%rsp), %rsi
movl 0x4(%rsp), %edi
callq 0x3ef8
testl %eax, %eax
jne 0x4882
cmpb $0x5, 0x120(%rsp)
setae %al
cmpb $0x0, 0x10f(%rsp)
setne %cl
testb %cl, %al
je 0x48a4
movzbl 0x140(%rsp), %eax
movzbl 0x13d(%rsp), %r15d
imull %eax, %r15d
shll $0xa, %r15d
movq 0x10(%r13), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3180
movq %rax, %r12
movq 0x18(%r13), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3180
movq %rax, %r13
movl %r12d, %eax
xorl %edx, %edx
divl %r15d
testl %edx, %edx
jne 0x4845
movl %r13d, %eax
xorl %edx, %edx
divl %r15d
testl %edx, %edx
jne 0x4845
movq %rbp, 0x8(%rsp)
testl %r14d, %r14d
je 0x4785
movb 0x10b(%rsp), %cl
movl %ecx, %eax
andb $-0x1e, %al
orb %bl, %al
cmpb %cl, %al
je 0x4785
movzbl %al, %edx
movl 0x4(%rsp), %edi
movl $0xab, %esi
callq 0x3f8e
testl %eax, %eax
jne 0x48ca
testl %r13d, %r13d
jle 0x47ff
leaq 0x10(%rsp), %rbx
xorl %ebp, %ebp
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x50(%rsp)
movl $0x1, 0x10(%rsp)
testl %r14d, %r14d
je 0x47c8
movl $0x1c, 0x18(%rsp)
jmp 0x47d0
movl $0x1d, 0x18(%rsp)
leal (%r12,%rbp), %eax
movl %eax, 0x1c(%rsp)
movl $0x49d, 0x30(%rsp)      # imm = 0x49D
movl $0xc048b300, %esi       # imm = 0xC048B300
movl 0x4(%rsp), %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x30f0
testl %eax, %eax
jne 0x4836
addl %r15d, %ebp
cmpl %r13d, %ebp
jl 0x4791
testl %r14d, %r14d
je 0x4822
movzbl 0x10b(%rsp), %edx
movl 0x4(%rsp), %edi
movl $0xab, %esi
callq 0x3f8e
testl %eax, %eax
jne 0x48b7
xorl %eax, %eax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x32f3
movq 0x127a4(%rip), %rbx     # 0x16ff0
movq (%rbx), %rdi
leaq 0x9fe7(%rip), %rdx      # 0xe83d
movl $0x1, %esi
xorl %eax, %eax
callq 0x3240
movq (%rbx), %rdi
leaq 0x9ff7(%rip), %rdx      # 0xe863
movl $0x1, %esi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3240
jmp 0x48e7
callq 0x332c
movq 0x12767(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0x9e72(%rip), %rdx      # 0xe705
movl $0x1, %esi
movq %rbp, %rcx
xorl %eax, %eax
callq 0x3240
jmp 0x48e7
movq 0x12745(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0x9f5f(%rip), %rdx      # 0xe814
jmp 0x48db
movq 0x12732(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0xa000(%rip), %rdx      # 0xe8c8
jmp 0x48db
movq 0x1271f(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0x9fb2(%rip), %rdx      # 0xe88d
movl $0x1, %esi
xorl %eax, %eax
callq 0x3240
movl $0x1, %edi
callq 0x3220