// File: /workspace/github_c_makefile_star2_O1/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 0x4572
movq 0x8(%rsi), %rbx
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x31d0
testl %eax, %eax
js 0x4591
movl %eax, %ebp
leaq 0x90(%rsp), %rsi
movl %eax, %edi
callq 0x3ef8
testl %eax, %eax
jne 0x4596
cmpb $0x5, 0x150(%rsp)
setae %al
cmpb $0x0, 0x13f(%rsp)
setne %cl
testb %cl, %al
je 0x45b6
movzbl 0x170(%rsp), %eax
movzbl 0x16d(%rsp), %edx
imull %eax, %edx
shll $0xa, %edx
movl %edx, %ecx
shll $0x9, %ecx
leaq 0xa461(%rip), %rsi      # 0xe7bc
movl $0x1, %edi
movl %edx, 0xc(%rsp)
xorl %eax, %eax
callq 0x31c0
leaq 0x40(%rsp), %rdx
movl $0x1260, %esi           # imm = 0x1260
movl %ebp, %edi
xorl %eax, %eax
callq 0x30f0
testl %eax, %eax
jne 0x4563
movl 0x40(%rsp), %ecx
xorl %esi, %esi
movl %ecx, %eax
xorl %edx, %edx
movl 0xc(%rsp), %edi
divl %edi
movl %eax, %r12d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl $0x0, 0x8(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %edi
ja 0x4537
movl %r12d, %eax
movq %rax, 0x28(%rsp)
movl $0xffffffe0, %r14d      # imm = 0xFFFFFFE0
xorl %edx, %edx
xorl %esi, %esi
xorl %ebx, %ebx
movl %ebp, 0x20(%rsp)
movl %r12d, 0x1c(%rsp)
movl %esi, %r13d
movl 0xc(%rsp), %eax
movq %rdx, 0x10(%rsp)
imull %edx, %eax
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 %eax, 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
testl %eax, %eax
jne 0x4510
movl %r14d, 0x24(%rsp)
movl %r14d, %ecx
addq $0x1f, %rcx
movq %rcx, 0x30(%rsp)
leaq 0x3f(%rsp), %rsi
xorl %ecx, %ecx
xorl %r14d, %r14d
movzbl (%rsi), %edx
shlq %cl, %rdx
orq %rdx, %r14
addq $0x8, %rcx
decq %rsi
cmpq $0x40, %rcx
jne 0x445d
testl %eax, %eax
movl %r13d, %esi
jne 0x4529
movl %r12d, %r13d
movq 0x10(%rsp), %rdx
subl %edx, %r13d
movl $0x0, 0x8(%rsp)
testl %r13d, %r13d
jle 0x44f4
cmpl $0x20, %r13d
movl $0x20, %eax
cmovgel %eax, %r13d
xorl %ebp, %ebp
xorl %ebx, %ebx
movq %r14, %r12
movl %ebp, %ecx
shrq %cl, %r12
andl $0x3, %r12d
cmpl %r15d, %r12d
je 0x44dd
cmpl $-0x1, %r15d
je 0x44da
movq 0x30(%rsp), %rax
leal (%rax,%rbx), %edx
movl 0xc(%rsp), %edi
movl %r15d, %ecx
callq 0x45c0
movq 0x10(%rsp), %rdx
leal (%rdx,%rbx), %esi
movl %r12d, %r15d
incq %rbx
addq $0x2, %rbp
cmpq %r13, %rbx
jb 0x44a7
movl 0x20(%rsp), %ebp
movl 0x1c(%rsp), %r12d
jmp 0x44f6
xorl %ebx, %ebx
addq $0x20, %rdx
movl 0x24(%rsp), %r14d
addl $0x20, %r14d
cmpq 0x28(%rsp), %rdx
jb 0x43d1
jmp 0x4532
leaq 0xd026(%rip), %rdi      # 0x1153d
movl %eax, 0x8(%rsp)
callq 0x31e0
movl 0x8(%rsp), %eax
jmp 0x4442
movl %eax, 0x8(%rsp)
movq 0x10(%rsp), %rdx
leal (%rbx,%rdx), %eax
decl %eax
cmpl %eax, %esi
je 0x454d
decl %r12d
movl 0xc(%rsp), %edi
movl %r12d, %edx
movl %r15d, %ecx
callq 0x45c0
movl 0x8(%rsp), %eax
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x32aa
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jmp 0x438a
movq 0x12a77(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0xa204(%rip), %rdx      # 0xe787
movl $0x1, %esi
xorl %eax, %eax
callq 0x3240
jmp 0x45b6
callq 0x32de
movq 0x12a53(%rip), %rax     # 0x16ff0
movq (%rax), %rdi
leaq 0xa15e(%rip), %rdx      # 0xe705
movl $0x1, %esi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3240
movl $0x1, %edi
callq 0x3220