// File: /workspace/github_c_makefile_star2_O3/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 0x4659
movq %rsi, %r12
movq 0x20(%rsi), %r14
movq %r14, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x31d0
movl %eax, (%rsp)
testl %eax, %eax
js 0x4829
movq 0x8(%r12), %rbx
leaq 0xa1e7(%rip), %rsi      # 0xe7ed
movq %rbx, %rdi
callq 0x3150
movl %eax, %ebp
testl %eax, %eax
je 0x466f
leaq 0xa1d7(%rip), %rsi      # 0xe7f2
movq %rbx, %rdi
callq 0x3150
testl %eax, %eax
je 0x466f
leaq 0xa1c9(%rip), %rsi      # 0xe7f7
movq %rbx, %rdi
callq 0x3150
movb $0x1, %bl
testl %eax, %eax
je 0x4671
movq 0x129ad(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0xa1b0(%rip), %rdx      # 0xe7fd
movl $0x1, %esi
xorl %eax, %eax
callq 0x3240
movq 0x12990(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0xa277(%rip), %rdx      # 0xe8e1
jmp 0x4887
xorl %ebx, %ebx
leaq 0x60(%rsp), %rsi
movl (%rsp), %edi
callq 0x3eac
testl %eax, %eax
jne 0x482e
cmpb $0x5, 0x120(%rsp)
jb 0x4850
cmpb $0x0, 0x10f(%rsp)
je 0x4850
movzbl 0x140(%rsp), %eax
movzbl 0x13d(%rsp), %r15d
imull %eax, %r15d
shll $0xa, %r15d
movq 0x10(%r12), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3180
movq %rax, %r13
movq 0x18(%r12), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3180
movq %rax, %r12
movl %r13d, %eax
xorl %edx, %edx
divl %r15d
testl %edx, %edx
jne 0x47f1
movl %r12d, %eax
xorl %edx, %edx
divl %r15d
testl %edx, %edx
jne 0x47f1
movq %r14, 0x8(%rsp)
movl %ebp, 0x4(%rsp)
testl %ebp, %ebp
je 0x4733
movb 0x10b(%rsp), %cl
movl %ecx, %eax
andb $-0x1e, %al
orb %bl, %al
cmpb %cl, %al
je 0x4733
movzbl %al, %edx
movl (%rsp), %edi
movl $0xab, %esi
callq 0x3f3a
testl %eax, %eax
jne 0x4876
testl %r12d, %r12d
jle 0x47aa
cmpl $0x1, 0x4(%rsp)
movl $0x0, %r14d
adcl $0x1c, %r14d
leaq 0x10(%rsp), %rbx
xorl %ebp, %ebp
leal (%r13,%rbp), %eax
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x50(%rsp)
movl $0x1, 0x10(%rsp)
movl %r14d, 0x18(%rsp)
movl %eax, 0x1c(%rsp)
movl $0x49d, 0x30(%rsp)      # imm = 0x49D
movl $0xc048b300, %esi       # imm = 0xC048B300
movl (%rsp), %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x30f0
testl %eax, %eax
jne 0x47e2
addl %r15d, %ebp
cmpl %r12d, %ebp
jl 0x474e
cmpl $0x0, 0x4(%rsp)
je 0x47ce
movzbl 0x10b(%rsp), %edx
movl (%rsp), %edi
movl $0xab, %esi
callq 0x3f3a
testl %eax, %eax
jne 0x4863
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 0x3307
movq 0x127f8(%rip), %rbx     # 0x16ff0
movq (%rbx), %rdi
leaq 0xa03b(%rip), %rdx      # 0xe83d
movl $0x1, %esi
xorl %eax, %eax
callq 0x3240
movq (%rbx), %rdi
leaq 0xa04b(%rip), %rdx      # 0xe863
movl $0x1, %esi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3240
jmp 0x4893
callq 0x3340
movq 0x127bb(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0x9ec6(%rip), %rdx      # 0xe705
movl $0x1, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x3240
jmp 0x4893
movq 0x12799(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0x9fb3(%rip), %rdx      # 0xe814
jmp 0x4887
movq 0x12786(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0xa054(%rip), %rdx      # 0xe8c8
jmp 0x4887
movq 0x12773(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0xa006(%rip), %rdx      # 0xe88d
movl $0x1, %esi
xorl %eax, %eax
callq 0x3240
movl $0x1, %edi
callq 0x3220