// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]ufat/ufat.c
// Function: ufat_open
int ufat_open(struct ufat *uf, const struct ufat_device *dev)
{
	uf->dev = dev;

	uf->next_seq = 0;
	uf->cache_size = UFAT_CACHE_BYTES >> dev->log2_block_size;

	if (uf->cache_size > UFAT_CACHE_MAX_BLOCKS)
		uf->cache_size = UFAT_CACHE_MAX_BLOCKS;

	if (!uf->cache_size)
		return -UFAT_ERR_BLOCK_SIZE;

	uf->alloc_ptr = 0;
	memset(&uf->stat, 0, sizeof(uf->stat));
	memset(&uf->cache_desc, 0, sizeof(uf->cache_desc));

	return read_bpb(uf);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, (%rdi)
andl $0x0, 0x70(%rdi)
movl (%rsi), %ecx
movl $0x2000, %eax           # imm = 0x2000
shrl %cl, %eax
cmpl $0x9, %ecx
pushq $0x10
popq %rcx
cmovael %eax, %ecx
movl %ecx, 0x74(%rdi)
testl %ecx, %ecx
je 0x169e
movq %rdi, %rbx
andl $0x0, 0x78(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rdi)
movups %xmm0, 0x18(%rdi)
addq $0x80, %rdi
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x1110
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1492
movl %eax, %r14d
testl %eax, %eax
js 0x16a2
movq (%rbx), %rax
movl (%rax), %r15d
movl %r15d, %ecx
shll %cl, %r14d
movzwl 0x18b(%rbx,%r14), %edi
movzbl 0x18d(%rbx,%r14), %r12d
movzwl 0x18e(%rbx,%r14), %r8d
movzwl 0x191(%rbx,%r14), %eax
movzwl 0x196(%rbx,%r14), %ebp
movzwl 0x193(%rbx,%r14), %r13d
movzbl 0x190(%rbx,%r14), %ecx
movl 0x1ac(%rbx,%r14), %esi
andl $0x0, 0x10(%rsp)
andl $0x0, 0xc(%rsp)
shll $0x5, %eax
addl %edi, %eax
decl %eax
cltd
idivl %edi
cmpl $0x9, %r15d
jae 0x16b4
pushq $-0x2
popq %r14
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r13d, %r13d
jne 0x16c1
movl 0x1a0(%rbx,%r14), %r13d
movl %r8d, (%rsp)
movl %eax, 0x4(%rsp)
movl %esi, 0x14(%rsp)
movl %ecx, 0x8(%rsp)
testl %ebp, %ebp
jne 0x16dd
movl 0x1a4(%rbx,%r14), %ebp
leaq 0x10(%rsp), %rsi
callq 0x1d52
pushq $-0x3
popq %rcx
testl %eax, %eax
js 0x1782
leaq 0xc(%rsp), %rsi
movl %r12d, %edi
callq 0x1d52
testl %eax, %eax
js 0x1777
cmpw $0xaa55, 0x37e(%rbx,%r14) # imm = 0xAA55
jne 0x1777
movl 0x10(%rsp), %edx
movl %edx, %ecx
movl 0xc(%rsp), %eax
subl %r15d, %ecx
jae 0x178a
subl %edx, %r15d
pushq $-0x4
popq %r14
movl %eax, %ecx
subl %r15d, %ecx
movl 0x8(%rsp), %r8d
movl 0x4(%rsp), %r9d
movl (%rsp), %r10d
jb 0x16a2
movl %ecx, 0x2c(%rbx)
movl %r9d, %edx
pushq $-0x1
popq %rsi
movl %r15d, %ecx
shll %cl, %esi
orl %r10d, %edx
orl %ebp, %edx
notl %esi
testl %esi, %edx
jne 0x16a2
movl %r10d, %esi
movl %r15d, %ecx
shrl %cl, %esi
movl %ebp, %edx
shrl %cl, %edx
movq %rsi, 0x30(%rbx)
movq %rdx, 0x38(%rbx)
movl %r9d, %edi
shrl %cl, %edi
jmp 0x17b7
pushq $-0x3
popq %rax
movl %eax, %r14d
jmp 0x16a2
movl %ecx, %r14d
jmp 0x16a2
leal (%rax,%rcx), %edx
movl %edx, 0x2c(%rbx)
movl (%rsp), %r10d
movl %r10d, %esi
shll %cl, %esi
movl %ebp, %edx
shll %cl, %edx
movslq %esi, %rsi
movq %rsi, 0x30(%rbx)
movq %rdx, 0x38(%rbx)
movl 0x4(%rsp), %r9d
movl %r9d, %edi
shll %cl, %edi
movl 0x8(%rsp), %r8d
movl %edi, %edi
movq %rdi, 0x60(%rbx)
pushq $-0x3
popq %rcx
movl %ecx, %r14d
testl %r8d, %r8d
je 0x16a2
imull %r8d, %ebp
addl %r9d, %r10d
addl %ebp, %r10d
subl %r10d, %r13d
movl %eax, %ecx
shrl %cl, %r13d
movl %r8d, 0x40(%rbx)
addl $0x2, %r13d
movl %r13d, 0x50(%rbx)
movl 0x14(%rsp), %eax
andl $0xfffffff, %eax        # imm = 0xFFFFFFF
movl %eax, 0x68(%rbx)
movl %r8d, %eax
imulq %rax, %rdx
addq %rsi, %rdx
movq %rdx, 0x58(%rbx)
addq %rdi, %rdx
movq %rdx, 0x48(%rbx)
testl %r9d, %r9d
je 0x1829
andl $0x0, 0x68(%rbx)
xorl %eax, %eax
cmpl $0xff7, %r13d           # imm = 0xFF7
setae %al
leal 0xc(,%rax,4), %eax
jmp 0x182c
pushq $0x20
popq %rax
movl %eax, 0x28(%rbx)
xorl %r14d, %r14d
jmp 0x16a2