// File: /workspace/github_c_makefile_star2_O2/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 $0x288, %rsp            # imm = 0x288
cmpl $0x2, %edi
jne 0x4019
movq 0x8(%rsi), %r14
pushq $0x2
popq %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x31e0
testl %eax, %eax
js 0x4038
movl %eax, %ebx
leaq 0x80(%rsp), %rsi
movl %eax, %edi
callq 0x39b8
testl %eax, %eax
jne 0x404c
cmpb $0x5, 0x140(%rsp)
jb 0x4044
cmpb $0x0, 0x12f(%rsp)
je 0x4044
movzbl 0x160(%rsp), %eax
movzbl 0x15d(%rsp), %ecx
imull %eax, %ecx
movl %ecx, %edx
shll $0xa, %edx
shll $0x13, %ecx
leaq 0xa997(%rip), %rsi      # 0xe7bc
pushq $0x1
popq %rdi
movl %edx, 0x4(%rsp)
xorl %eax, %eax
callq 0x31d0
leaq 0x30(%rsp), %rdx
movl $0x1260, %esi           # imm = 0x1260
movl %ebx, %edi
xorl %eax, %eax
callq 0x30f0
pushq $-0x1
popq %r14
testl %eax, %eax
jne 0x3fe0
movl 0x30(%rsp), %eax
xorl %edx, %edx
divl 0x4(%rsp)
movq %rax, 0x8(%rsp)
xorl %edx, %edx
xorl %r15d, %r15d
xorl %esi, %esi
movl %ebx, 0x14(%rsp)
cmpq 0x8(%rsp), %rdx
jae 0x3fab
movl %esi, %ebp
movl 0x4(%rsp), %eax
movq %rdx, 0x18(%rsp)
imull %edx, %eax
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x60(%rsp)
movl $0x1f, 0x38(%rsp)
movabsq $0x100000008, %rcx      # imm = 0x100000008
movq %rcx, 0x54(%rsp)
movl %eax, 0x3c(%rsp)
movl $0xb5, 0x50(%rsp)
leaq 0x28(%rsp), %rax
movq %rax, 0x70(%rsp)
movl $0xc048b300, %esi       # imm = 0xC048B300
movl %ebx, %edi
leaq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x30f0
movl %eax, %r13d
testl %eax, %eax
jne 0x3f9a
leaq 0x2f(%rsp), %rax
xorl %ecx, %ecx
xorl %r12d, %r12d
movl %ebp, %esi
cmpq $0x40, %rcx
je 0x3f0b
movzbl (%rax), %edx
shlq %cl, %rdx
orq %rdx, %r12
addq $0x8, %rcx
decq %rax
jmp 0x3ef3
testl %r13d, %r13d
movq 0x18(%rsp), %rdx
jne 0x3fae
movq 0x8(%rsp), %rax
subl %edx, %eax
cmpl $0x20, %eax
pushq $0x20
popq %rcx
cmovgel %ecx, %eax
cltq
leaq -0x1(%rdx), %rcx
movq %rcx, 0x20(%rsp)
xorl %r13d, %r13d
xorl %r15d, %r15d
cmpq %rax, %r15
jge 0x3f8d
movq %r12, %rbp
movl %r13d, %ecx
shrq %cl, %rbp
andl $0x3, %ebp
cmpl %r14d, %ebp
jne 0x3f55
movl %r14d, %ebp
jmp 0x3f81
cmpl $-0x1, %r14d
je 0x3f81
leal (%rdx,%r15), %ebx
movq 0x20(%rsp), %rcx
leal (%rcx,%r15), %edx
movl 0x4(%rsp), %edi
movl %r14d, %ecx
movq %rax, %r14
callq 0x4073
movq %r14, %rax
movq 0x18(%rsp), %rdx
movl %ebx, %esi
incq %r15
addq $0x2, %r13
movl %ebp, %r14d
jmp 0x3f3a
addq $0x20, %rdx
movl 0x14(%rsp), %ebx
jmp 0x3e6c
leaq 0xd5c7(%rip), %rdi      # 0x11568
callq 0x31f0
jmp 0x3ee7
xorl %r13d, %r13d
leal (%r15,%rdx), %eax
decl %eax
cmpl %eax, %esi
je 0x3fcb
movq 0x8(%rsp), %rdx
decl %edx
movl 0x4(%rsp), %edi
movl %r14d, %ecx
callq 0x4073
movl %r13d, %eax
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x14009(%rip), %rax     # 0x17ff0
movq (%rax), %r15
callq 0x3050
movl (%rax), %ecx
leaq 0xd8f4(%rip), %rdx      # 0x118ec
pushq $0x1
popq %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x3250
leaq 0xa5ed(%rip), %rdi      # 0xe5f9
callq 0x31f0
movl %r14d, %eax
jmp 0x3e56
movq 0x13fd0(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0xa75d(%rip), %rdx      # 0xe787
pushq $0x1
popq %rbx
movl %ebx, %esi
xorl %eax, %eax
callq 0x3250
jmp 0x406c
leaq 0xcfa6(%rip), %rdi      # 0x10fe5
callq 0x31f0
pushq $0x1
popq %rdi
callq 0x3230
movq 0x13f9d(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0xa6a8(%rip), %rdx      # 0xe705
pushq $0x1
popq %rbx
movl %ebx, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x3250
movl %ebx, %edi
callq 0x3230