// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/ide.c
// Function: _read_sectors_lba48
static int __read_sectors_lba48(void *data, unsigned long long sector,
			size_t count)
{
	const unsigned long slo = sector & 0xfffffffful;
	const unsigned long shi = sector >> 32;

	const unsigned clo = count & 0xffu;
	const unsigned chi = count >> 8;

	ide_wait_ready();

	out8(IDE_DEVCTL_REG, IDE_NIEN);

	out8(IDE_SC_REG, chi);
	out8(IDE_LBA0_REG, shi & 0xff);
	out8(IDE_LBA1_REG, (shi >> 8) & 0xff);
	out8(IDE_LBA2_REG, (shi >> 16) & 0xff);

	out8(IDE_SC_REG, clo);
	out8(IDE_LBA0_REG, slo & 0xff);
	out8(IDE_LBA1_REG, (slo >> 8) & 0xff);
	out8(IDE_LBA2_REG, (slo >> 16) & 0xff);

	out8(IDE_DEV_REG, IDE_LBA);
	out8(IDE_CMD_REG, IDE_CMD_READ_LBA48);

	ide_wait_ready();

	uint16_t *wptr = (uint16_t *)data;
	const size_t words = IDE_SECTOR_SIZE / sizeof(*wptr);

	for (size_t i = 0; i != count; ++i) {
		for (size_t j = 0; j != words; ++j)
			*wptr++ = in16(IDE_DATA_REG);
		in8(IDE_ASTATUS_REG); // wait one PIO transfer cycle

		if (ide_wait_ready() != 0)
			return -1;
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movabsq $0xffffffff, %rax # imm = 0xFFFFFFFF
andq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
shrq $0x20, %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
andq $0xff, %rax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
shrq $0x8, %rax
movl %eax, -0x38(%rbp)
callq 0xffffffff8010ead0
movl $0x3f6, %edi            # imm = 0x3F6
movl $0x2, %esi
callq 0xffffffff8010eb10
movl -0x38(%rbp), %eax
movl $0x1f2, %edi            # imm = 0x1F2
movzbl %al, %esi
callq 0xffffffff8010eb10
movq -0x30(%rbp), %rax
andq $0xff, %rax
movl $0x1f3, %edi            # imm = 0x1F3
movzbl %al, %esi
callq 0xffffffff8010eb10
movq -0x30(%rbp), %rax
shrq $0x8, %rax
andq $0xff, %rax
movl $0x1f4, %edi            # imm = 0x1F4
movzbl %al, %esi
callq 0xffffffff8010eb10
movq -0x30(%rbp), %rax
shrq $0x10, %rax
andq $0xff, %rax
movl $0x1f5, %edi            # imm = 0x1F5
movzbl %al, %esi
callq 0xffffffff8010eb10
movl -0x34(%rbp), %eax
movl $0x1f2, %edi            # imm = 0x1F2
movzbl %al, %esi
callq 0xffffffff8010eb10
movq -0x28(%rbp), %rax
andq $0xff, %rax
movl $0x1f3, %edi            # imm = 0x1F3
movzbl %al, %esi
callq 0xffffffff8010eb10
movq -0x28(%rbp), %rax
shrq $0x8, %rax
andq $0xff, %rax
movl $0x1f4, %edi            # imm = 0x1F4
movzbl %al, %esi
callq 0xffffffff8010eb10
movq -0x28(%rbp), %rax
shrq $0x10, %rax
andq $0xff, %rax
movl $0x1f5, %edi            # imm = 0x1F5
movzbl %al, %esi
callq 0xffffffff8010eb10
movl $0x1f6, %edi            # imm = 0x1F6
movl $0x40, %esi
callq 0xffffffff8010eb10
movl $0x1f7, %edi            # imm = 0x1F7
movl $0x24, %esi
callq 0xffffffff8010eb10
callq 0xffffffff8010ead0
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $0x100, -0x48(%rbp) # imm = 0x100
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x20(%rbp), %rax
je 0xffffffff8010ea99
movq $0x0, -0x58(%rbp)
cmpq $0x100, -0x58(%rbp) # imm = 0x100
je 0xffffffff8010ea6c
movl $0x1f0, %edi            # imm = 0x1F0
callq 0xffffffff8010eb30
movw %ax, %cx
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x40(%rbp)
movw %cx, (%rax)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0xffffffff8010ea35
movl $0x3f6, %edi            # imm = 0x3F6
callq 0xffffffff8010eb50
callq 0xffffffff8010ead0
cmpl $0x0, %eax
je 0xffffffff8010ea89
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xffffffff8010eaa0
jmp 0xffffffff8010ea8b
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xffffffff8010ea23
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)