// File: /workspace/github_c_makefile_star2_O2/blasphemy[P]mmc-utils/mmc_cmds.c
// Function: do_boot_bus_conditions_set
int do_boot_bus_conditions_set(int nargs, char **argv)
{
	__u8 ext_csd[512];
	__u8 value = 0;
	int fd, ret;
	char *device;

	if (nargs != 5) {
		fprintf(stderr, "Usage: mmc: bootbus set <boot_mode> <reset_boot_bus_conditions> <boot_bus_width> <device>\n");
		exit(1);
	}

	if (strcmp(argv[1], "single_backward") == 0)
		value |= 0;
	else if (strcmp(argv[1], "single_hs") == 0)
		value |= 0x8;
	else if (strcmp(argv[1], "dual") == 0)
		value |= 0x10;
	else {
		fprintf(stderr, "illegal <boot_mode> specified\n");
		exit(1);
	}

	if (strcmp(argv[2], "x1") == 0)
		value |= 0;
	else if (strcmp(argv[2], "retain") == 0)
		value |= 0x4;
	else {
		fprintf(stderr,
			"illegal <reset_boot_bus_conditions> specified\n");
		exit(1);
	}

	if (strcmp(argv[3], "x1") == 0)
		value |= 0;
	else if (strcmp(argv[3], "x4") == 0)
		value |= 0x1;
	else if (strcmp(argv[3], "x8") == 0)
		value |= 0x2;
	else {
		fprintf(stderr,	"illegal <boot_bus_width> specified\n");
		exit(1);
	}

	device = argv[4];
	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);
	}
	printf("Changing ext_csd[BOOT_BUS_CONDITIONS] from 0x%02x to 0x%02x\n",
		ext_csd[EXT_CSD_BOOT_BUS_CONDITIONS], value);

	ret = write_extcsd_value(fd, EXT_CSD_BOOT_BUS_CONDITIONS, value);
	if (ret) {
		fprintf(stderr, "Could not write 0x%02x to "
			"EXT_CSD[%d] in %s\n",
			value, EXT_CSD_BOOT_BUS_CONDITIONS, device);
		exit(1);
	}
	close(fd);
	return ret;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x200, %rsp            # imm = 0x200
cmpl $0x5, %edi
jne 0x47d2
movq %rsi, %rbx
movq 0x8(%rsi), %r14
leaq 0xa473(%rip), %rsi      # 0xeaf7
movq %r14, %rdi
callq 0x3150
testl %eax, %eax
je 0x46cf
leaq 0xa470(%rip), %rsi      # 0xeb07
movq %r14, %rdi
callq 0x3150
testl %eax, %eax
je 0x46d4
leaq 0xa467(%rip), %rsi      # 0xeb11
movq %r14, %rdi
callq 0x3150
movb $0x10, %r14b
testl %eax, %eax
je 0x46d7
movq 0x13930(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0xa44c(%rip), %rdx      # 0xeb16
jmp 0x485c
xorl %r14d, %r14d
jmp 0x46d7
movb $0x8, %r14b
movq 0x10(%rbx), %rdi
cmpb $0x78, (%rdi)
jne 0x46ec
cmpb $0x31, 0x1(%rdi)
jne 0x46ec
cmpb $0x0, 0x2(%rdi)
je 0x4704
leaq 0xa442(%rip), %rsi      # 0xeb35
callq 0x3150
testl %eax, %eax
jne 0x484b
orb $0x4, %r14b
movq 0x18(%rbx), %rax
cmpb $0x78, (%rax)
jne 0x47bc
cmpb $0x31, 0x1(%rax)
jne 0x471d
cmpb $0x0, 0x2(%rax)
je 0x4741
cmpb $0x34, 0x1(%rax)
jne 0x472d
cmpb $0x0, 0x2(%rax)
je 0x47b6
cmpb $0x38, 0x1(%rax)
jne 0x47bc
cmpb $0x0, 0x2(%rax)
jne 0x47bc
orb $0x2, %r14b
movq 0x20(%rbx), %rbx
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x31e0
testl %eax, %eax
js 0x47e5
movl %eax, %ebp
movq %rsp, %rsi
movl %eax, %edi
callq 0x39b8
testl %eax, %eax
jne 0x47f9
movzbl 0xb1(%rsp), %edx
movzbl %r14b, %r14d
leaq 0xa40e(%rip), %rsi      # 0xeb8f
pushq $0x1
popq %rdi
movl %r14d, %ecx
xorl %eax, %eax
callq 0x31d0
movl %ebp, %edi
movl $0xb1, %esi
movl %r14d, %edx
callq 0x3a43
testl %eax, %eax
jne 0x481b
movl %ebp, %edi
callq 0x3100
xorl %eax, %eax
addq $0x200, %rsp            # imm = 0x200
popq %rbx
popq %r14
popq %rbp
retq
orb $0x1, %r14b
jmp 0x4741
movq 0x1382d(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0xa39e(%rip), %rdx      # 0xeb6b
jmp 0x485c
movq 0x13817(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0xa2b9(%rip), %rdx      # 0xea9c
jmp 0x485c
leaq 0xc7f9(%rip), %rdi      # 0x10fe5
callq 0x31f0
pushq $0x1
popq %rdi
callq 0x3230
movq 0x137f0(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0x9efb(%rip), %rdx      # 0xe705
pushq $0x1
popq %rbp
movl %ebp, %esi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3250
jmp 0x4844
movq 0x137ce(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0x9f2e(%rip), %rdx      # 0xe75a
pushq $0x1
popq %rbp
movl %ebp, %esi
movl %r14d, %ecx
movl $0xb1, %r8d
movq %rbx, %r9
xorl %eax, %eax
callq 0x3250
movl %ebp, %edi
callq 0x3230
movq 0x1379e(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0xa2e0(%rip), %rdx      # 0xeb3c
pushq $0x1
popq %rbx
movl %ebx, %esi
xorl %eax, %eax
callq 0x3250
movl %ebx, %edi
callq 0x3230