// File: /workspace/github_c_makefile_star2_O0/blasphemy[P]mmc-utils/mmc_cmds.c
// Function: do_writeprotect_user_get
int do_writeprotect_user_get(int nargs, char **argv)
{
	__u8 ext_csd[512];
	int fd, ret;
	char *device;
	int x;
	int y = 0;
	__u32 wp_sizeblks;
	__u32 dev_sizeblks;
	__u32 cnt;
	__u64 bits;
	__u32 wpblk;
	__u32 last_wpblk = 0;
	__u32 prot;
	__u32 last_prot = -1;
	int remain;

	if (nargs != 2) {
		fprintf(stderr, "Usage: mmc writeprotect user get </path/to/mmcblkX>\n");
		exit(1);
	}

	device = argv[1];

	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);
	}

	ret = get_wp_group_size_in_blks(ext_csd, &wp_sizeblks);
	if (ret)
		exit(1);
	printf("Write Protect Group size in blocks/bytes: %d/%d\n",
		wp_sizeblks, wp_sizeblks * 512);
	dev_sizeblks = get_size_in_blks(fd);
	cnt = dev_sizeblks / wp_sizeblks;
	for (x = 0; x < cnt; x += WP_BLKS_PER_QUERY) {
		ret = send_write_protect_type(fd, x * wp_sizeblks, &bits);
		if (ret)
			break;
		remain = cnt - x;
		if (remain > WP_BLKS_PER_QUERY)
			remain = WP_BLKS_PER_QUERY;
		for (y = 0; y < remain; y++) {
			prot = (bits >> (y * 2)) & 0x3;
			if (prot != last_prot) {
				/* not first time */
				if (last_prot != -1) {
					wpblk = x + y;
					print_wp_status(wp_sizeblks,
							last_wpblk,
							wpblk - 1,
							last_prot);
					last_wpblk = wpblk;
				}
				last_prot = prot;
			}
		}
	}
	if (last_wpblk != (x + y - 1))
		print_wp_status(wp_sizeblks, last_wpblk, cnt - 1, last_prot);

	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x228(%rbp)
movl $0x0, -0x248(%rbp)
movl $0xffffffff, -0x250(%rbp) # imm = 0xFFFFFFFF
cmpl $0x2, -0x4(%rbp)
je 0x4408
movq 0x16c03(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
leaq 0xf380(%rip), %rsi      # 0x13777
movb $0x0, %al
callq 0x3180
movl $0x1, %edi
callq 0x3240
movq -0x10(%rbp), %rax
movq 0x8(%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 0x444f
leaq 0x11ba4(%rip), %rdi     # 0x15fe4
callq 0x3200
movl $0x1, %edi
callq 0x3240
movl -0x214(%rbp), %edi
leaq -0x210(%rbp), %rsi
callq 0x3e90
movl %eax, -0x218(%rbp)
cmpl $0x0, -0x218(%rbp)
je 0x4499
movq 0x16b79(%rip), %rax     # 0x1aff0
movq (%rax), %rdi
movq -0x220(%rbp), %rdx
leaq 0xf26d(%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 0x44c5
movl $0x1, %edi
callq 0x3240
movl -0x22c(%rbp), %esi
movl -0x22c(%rbp), %edx
shll $0x9, %edx
leaq 0xf2d1(%rip), %rdi      # 0x137ac
movb $0x0, %al
callq 0x30c0
movl -0x214(%rbp), %edi
callq 0x4700
movl %eax, -0x230(%rbp)
movl -0x230(%rbp), %eax
xorl %edx, %edx
divl -0x22c(%rbp)
movl %eax, -0x234(%rbp)
movl $0x0, -0x224(%rbp)
movl -0x224(%rbp), %eax
cmpl -0x234(%rbp), %eax
jae 0x4642
movl -0x214(%rbp), %edi
movl -0x224(%rbp), %esi
imull -0x22c(%rbp), %esi
leaq -0x240(%rbp), %rdx
callq 0x4780
movl %eax, -0x218(%rbp)
cmpl $0x0, -0x218(%rbp)
je 0x4556
jmp 0x4642
movl -0x234(%rbp), %eax
subl -0x224(%rbp), %eax
movl %eax, -0x254(%rbp)
cmpl $0x20, -0x254(%rbp)
jle 0x457b
movl $0x20, -0x254(%rbp)
movl $0x0, -0x228(%rbp)
movl -0x228(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x462c
movq -0x240(%rbp), %rax
movl -0x228(%rbp), %ecx
shll %ecx
movl %ecx, %ecx
shrq %cl, %rax
andq $0x3, %rax
movl %eax, -0x24c(%rbp)
movl -0x24c(%rbp), %eax
cmpl -0x250(%rbp), %eax
je 0x4616
cmpl $-0x1, -0x250(%rbp)
je 0x460a
movl -0x224(%rbp), %eax
addl -0x228(%rbp), %eax
movl %eax, -0x244(%rbp)
movl -0x22c(%rbp), %edi
movl -0x248(%rbp), %esi
movl -0x244(%rbp), %edx
subl $0x1, %edx
movl -0x250(%rbp), %ecx
callq 0x4870
movl -0x244(%rbp), %eax
movl %eax, -0x248(%rbp)
movl -0x24c(%rbp), %eax
movl %eax, -0x250(%rbp)
jmp 0x4618
movl -0x228(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x228(%rbp)
jmp 0x4585
jmp 0x462e
movl -0x224(%rbp), %eax
addl $0x20, %eax
movl %eax, -0x224(%rbp)
jmp 0x4511
movl -0x248(%rbp), %eax
movl -0x224(%rbp), %ecx
addl -0x228(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x467b
movl -0x22c(%rbp), %edi
movl -0x248(%rbp), %esi
movl -0x234(%rbp), %edx
subl $0x1, %edx
movl -0x250(%rbp), %ecx
callq 0x4870
movl -0x218(%rbp), %eax
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
nopw (%rax,%rax)