// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x5, -0x4(%rbp)
je 0x48fd
jmp 0x4cc1
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x220(%rbp)
movq -0x220(%rbp), %rdi
movl $0x2, %esi
movb $0x0, %al
callq 0x31e0
movl %eax, -0x214(%rbp)
cmpl $0x0, -0x214(%rbp)
jge 0x4944
leaq 0x116af(%rip), %rdi     # 0x15fe4
callq 0x3200
movl $0x1, %edi
callq 0x3240
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xee8a(%rip), %rsi      # 0x137dd
callq 0x3170
cmpl $0x0, %eax
jne 0x4969
movl $0x0, -0x238(%rbp)
jmp 0x49d4
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xee6a(%rip), %rsi      # 0x137e2
callq 0x3170
cmpl $0x0, %eax
jne 0x498e
movl $0x1, -0x238(%rbp)
jmp 0x49d2
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xee4a(%rip), %rsi      # 0x137e7
callq 0x3170
cmpl $0x0, %eax
jne 0x49b3
movl $0x2, -0x238(%rbp)
jmp 0x49d0
movq 0x16636(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
leaq 0xee29(%rip), %rsi      # 0x137ed
movb $0x0, %al
callq 0x3180
jmp 0x4cc1
jmp 0x49d2
jmp 0x49d4
movl -0x214(%rbp), %edi
leaq -0x210(%rbp), %rsi
callq 0x3e90
movl %eax, -0x218(%rbp)
cmpl $0x0, -0x218(%rbp)
je 0x4a1e
movq 0x165f4(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movq -0x220(%rbp), %rdx
leaq 0xece8(%rip), %rsi      # 0x136f5
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
leaq -0x210(%rbp), %rdi
leaq -0x22c(%rbp), %rsi
callq 0x4690
movl %eax, -0x218(%rbp)
cmpl $0x0, -0x218(%rbp)
je 0x4a62
movq 0x165a9(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
leaq 0xedb3(%rip), %rsi      # 0x13804
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x31a0
movl %eax, -0x224(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x31a0
movl %eax, -0x228(%rbp)
movl -0x224(%rbp), %eax
xorl %edx, %edx
divl -0x22c(%rbp)
cmpl $0x0, %edx
jne 0x4aba
movl -0x228(%rbp), %eax
xorl %edx, %edx
divl -0x22c(%rbp)
cmpl $0x0, %edx
je 0x4afa
movq 0x1652f(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
leaq 0xed62(%rip), %rsi      # 0x1382d
movb $0x0, %al
callq 0x3180
movq 0x16517(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movl -0x22c(%rbp), %edx
leaq 0xed6a(%rip), %rsi      # 0x13853
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
cmpl $0x0, -0x238(%rbp)
je 0x4bd0
movb -0x165(%rbp), %al
movb %al, -0x22d(%rbp)
movb -0x22d(%rbp), %al
andb $-0x1e, %al
movb %al, -0x22d(%rbp)
movl -0x238(%rbp), %eax
movl %eax, -0x23c(%rbp)
subl $0x1, %eax
je 0x4b4e
jmp 0x4b34
movl -0x23c(%rbp), %eax
subl $0x2, %eax
je 0x4b50
jmp 0x4b41
movl -0x23c(%rbp), %eax
subl $0x3, %eax
je 0x4b62
jmp 0x4b72
jmp 0x4b72
movzbl -0x22d(%rbp), %eax
orl $0x1, %eax
movb %al, -0x22d(%rbp)
jmp 0x4b72
movzbl -0x22d(%rbp), %eax
orl $0x4, %eax
movb %al, -0x22d(%rbp)
movzbl -0x22d(%rbp), %eax
movzbl -0x165(%rbp), %ecx
cmpl %ecx, %eax
je 0x4bce
movl -0x214(%rbp), %edi
movl $0xab, %esi
movzbl -0x22d(%rbp), %edx
callq 0x3f30
movl %eax, -0x218(%rbp)
cmpl $0x0, -0x218(%rbp)
je 0x4bcc
movq 0x1643f(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
leaq 0xecc2(%rip), %rsi      # 0x1387d
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
jmp 0x4bce
jmp 0x4bd0
movl $0x0, -0x234(%rbp)
movl -0x234(%rbp), %eax
cmpl -0x228(%rbp), %eax
jge 0x4c5f
movl -0x214(%rbp), %edi
movl -0x224(%rbp), %esi
addl -0x234(%rbp), %esi
cmpl $0x0, -0x238(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %edx
callq 0x4cf0
movl %eax, -0x218(%rbp)
cmpl $0x0, -0x218(%rbp)
je 0x4c46
movq 0x163cc(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movq -0x220(%rbp), %rdx
leaq 0xec5f(%rip), %rsi      # 0x13894
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
jmp 0x4c48
movl -0x22c(%rbp), %eax
addl -0x234(%rbp), %eax
movl %eax, -0x234(%rbp)
jmp 0x4bda
cmpl $0x0, -0x238(%rbp)
je 0x4cb2
movl -0x214(%rbp), %edi
movl $0xab, %esi
movzbl -0x165(%rbp), %edx
callq 0x3f30
movl %eax, -0x218(%rbp)
cmpl $0x0, -0x218(%rbp)
je 0x4cb0
movq 0x1635b(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
leaq 0xec19(%rip), %rsi      # 0x138b8
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
jmp 0x4cb2
movl -0x218(%rbp), %eax
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
movq 0x16328(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
leaq 0xebff(%rip), %rsi      # 0x138d1
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
nopw %cs:(%rax,%rax)