// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x298, %rsp            # imm = 0x298
cmpl $0x2, %edi
jne 0x4520
movq 0x8(%rsi), %rbx
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x31d0
testl %eax, %eax
js 0x453f
movl %eax, %ebp
leaq 0x90(%rsp), %rsi
movl %eax, %edi
callq 0x3eac
testl %eax, %eax
jne 0x4544
cmpb $0x5, 0x150(%rsp)
jb 0x4564
cmpb $0x0, 0x13f(%rsp)
je 0x4564
movzbl 0x170(%rsp), %eax
movzbl 0x16d(%rsp), %ecx
imull %eax, %ecx
movl %ecx, %r14d
shll $0xa, %r14d
shll $0x13, %ecx
leaq 0xa4b5(%rip), %rsi      # 0xe7bc
xorl %r13d, %r13d
movl $0x1, %edi
movl %r14d, %edx
xorl %eax, %eax
callq 0x31c0
leaq 0x14(%rsp), %rdx
movl $0x1260, %esi           # imm = 0x1260
movl %ebp, %edi
xorl %eax, %eax
callq 0x30f0
testl %eax, %eax
jne 0x44fe
movl 0x14(%rsp), %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %r14d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl $0x0, %esi
cmpl %ecx, %r14d
ja 0x44da
movl %eax, 0xc(%rsp)
movl %eax, %eax
movq %rax, 0x28(%rsp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl $0xffffffe0, 0x10(%rsp) # imm = 0xFFFFFFE0
xorl %edx, %edx
xorl %esi, %esi
xorl %ebx, %ebx
movl %r14d, 0x8(%rsp)
movl %ebp, 0x24(%rsp)
movl %esi, %r12d
movq %rdx, 0x18(%rsp)
imull %edx, %r14d
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x70(%rsp)
movl $0x1f, 0x48(%rsp)
movabsq $0x100000008, %rcx      # imm = 0x100000008
movq %rcx, 0x64(%rsp)
movl %r14d, 0x4c(%rsp)
movl $0xb5, 0x60(%rsp)
leaq 0x38(%rsp), %rax
movq %rax, 0x80(%rsp)
movl $0xc048b300, %esi       # imm = 0xC048B300
movl %ebp, %edi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x30f0
movl %eax, %r13d
testl %eax, %eax
jne 0x44ad
movl 0x10(%rsp), %eax
addq $0x1f, %rax
movq %rax, 0x30(%rsp)
leaq 0x3f(%rsp), %rax
xorl %ecx, %ecx
xorl %r14d, %r14d
movzbl (%rax), %edx
shlq %cl, %rdx
orq %rdx, %r14
addq $0x8, %rcx
decq %rax
cmpq $0x40, %rcx
jne 0x4404
testl %r13d, %r13d
movl %r12d, %esi
jne 0x44be
movl 0xc(%rsp), %eax
movl %eax, %ebp
movq 0x18(%rsp), %rdx
subl %edx, %ebp
testl %ebp, %ebp
jle 0x448c
cmpl $0x20, %ebp
movl $0x20, %eax
cmovael %eax, %ebp
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %r14, %r12
movl %r13d, %ecx
shrq %cl, %r12
andl $0x3, %r12d
cmpl %r15d, %r12d
je 0x447e
cmpl $-0x1, %r15d
je 0x447b
movq 0x30(%rsp), %rax
leal (%rax,%rbx), %edx
movl 0x8(%rsp), %edi
movl %r15d, %ecx
callq 0x456e
movq 0x18(%rsp), %rdx
leal (%rdx,%rbx), %esi
movl %r12d, %r15d
incq %rbx
addq $0x2, %r13
cmpq %rbp, %rbx
jb 0x4447
jmp 0x448e
xorl %ebx, %ebx
movl 0x8(%rsp), %r14d
addq $0x20, %rdx
addl $0x20, 0x10(%rsp)
cmpq 0x28(%rsp), %rdx
movl 0x24(%rsp), %ebp
jb 0x437b
jmp 0x44ca
leaq 0xd07a(%rip), %rdi      # 0x1152e
callq 0x31e0
jmp 0x43ed
movl 0x8(%rsp), %r14d
movq 0x18(%rsp), %rdx
jmp 0x44cd
xorl %r13d, %r13d
leal (%rbx,%rdx), %eax
decl %eax
cmpl %eax, %esi
movl 0xc(%rsp), %eax
je 0x44e9
decl %eax
movl %r14d, %edi
movl %eax, %edx
movl %r15d, %ecx
callq 0x456e
movl %r13d, %eax
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14(%rsp), %rdi
movl %r14d, %ebx
leaq 0x40(%rsp), %r14
movl %ebx, %esi
movq %r14, %rdx
callq 0x32aa
movl (%r14), %eax
movl %ebx, %r14d
jmp 0x4353
movq 0x12ac9(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0xa256(%rip), %rdx      # 0xe787
movl $0x1, %esi
xorl %eax, %eax
callq 0x3240
jmp 0x4564
callq 0x32f2
movq 0x12aa5(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0xa1b0(%rip), %rdx      # 0xe705
movl $0x1, %esi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3240
movl $0x1, %edi
callq 0x3220