// File: /workspace/github_c_makefile_star2_O2/dlbeer[P]ufat/ufat_mkfs.c
// Function: ufat_mkfs
int ufat_mkfs(struct ufat_device *dev, ufat_block_t nblk)
{
	struct fs_layout fl;
	int err;

	err = calculate_layout(&fl, nblk, dev->log2_block_size);
	if (err < 0)
		return err;

	err = erase_reserved_blocks(dev, &fl);
	if (err < 0)
		return err;

	switch (fl.type) {
	case UFAT_TYPE_FAT12:
		err = init_fat12(dev, &fl);
		break;

	case UFAT_TYPE_FAT16:
		err = init_fat16(dev, &fl);
		break;

	case UFAT_TYPE_FAT32:
		err = init_fat32(dev, &fl);
		break;
	}

	if (err < 0)
		return err;

	if (fl.type == UFAT_TYPE_FAT32)
		err = init_root_cluster(dev, &fl);
	else
		err = init_root_blocks(dev, &fl);

	if (err < 0)
		return err;

	if (fl.type == UFAT_TYPE_FAT32) {
		err = write_fsinfo(dev, &fl);
		if (err < 0)
			return err;
	}

	return write_bpb(dev, &fl);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl (%rdi), %eax
cmpq $0xc, %rax
jbe 0x3a9a
pushq $-0x2
popq %rbp
jmp 0x3d2f
xorl %r13d, %r13d
pushq $0x9
popq %r8
movl %r8d, %edx
subl %eax, %edx
cmoval %eax, %r8d
cmovbl %r13d, %edx
movl %eax, %r9d
subl %r8d, %r9d
leal (%rdx,%r13), %ecx
movq %rsi, %r10
shrq %cl, %r10
leal (%r9,%r13), %ecx
addl $0x9, %ecx
incq %r13
cmpl $0xb, %ecx
ja 0x3ad6
movq %r10, %rcx
shrq $0x20, %rcx
jne 0x3ab4
addq %r13, %rdx
decq %rdx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl %edx, %ecx
shlq %cl, %r9
shrq $0x20, %r10
testq %r10, %r10
cmovneq %r9, %rsi
movl %eax, %r10d
subl %r8d, %r10d
movq %rsi, %r9
shrq %cl, %r9
leal (%r10,%r13), %ecx
addl $0x8, %ecx
movl %ecx, 0x18(%rsp)
pushq $0x1
popq %rcx
cmpl $0x20cf, %r9d           # imm = 0x20CF
movq %rdi, 0x10(%rsp)
ja 0x3b2c
movl $0xc, 0x44(%rsp)
movl $0x1000, %r10d          # imm = 0x1000
pushq $0xc
jmp 0x3b45
cmpl $0xfffff, %r9d          # imm = 0xFFFFF
ja 0x3b50
movl $0x10, 0x44(%rsp)
movl $0x10000, %r10d         # imm = 0x10000
pushq $0x10
popq %rbx
movl $0x0, 0xc(%rsp)
jmp 0x3b6b
movl $0x20, 0x44(%rsp)
movl $0x200000, %r10d        # imm = 0x200000
pushq $0x3
popq %rcx
pushq $0x20
popq %rbx
movb $0x1, %dil
movl %edi, 0xc(%rsp)
movl %ecx, %r11d
movl %eax, %r14d
subl %r8d, %r14d
addl %ecx, %r14d
addl %r13d, %r14d
addl $0x8, %r14d
xorl %r15d, %r15d
leaq (%r11,%r15), %rcx
cmpl $0x7, %ecx
je 0x3ba3
leal (%r14,%r15), %r12d
movl %r9d, %ebp
shrl %cl, %ebp
cmpl $0xe, %r12d
ja 0x3ba3
cmpl %r10d, %ebp
jbe 0x3ba3
incq %r15
jmp 0x3b81
subl %r8d, %r11d
leal (%r11,%r13), %r14d
addl $0x8, %r14d
addq %r15, %r14
cmpb $0x0, 0xc(%rsp)
pushq $0x20
popq %rcx
pushq $0x1
popq %r15
cmovneq %rcx, %r15
movl %edx, %ecx
shlq %cl, %r15
movq %rsi, %rdx
subq %r15, %rdx
movl %r14d, %ecx
shrq %cl, %rdx
movl %r14d, 0x1c(%rsp)
movq %r15, 0x20(%rsp)
addl $0x2, %edx
cmpl $0x10, %ebx
je 0x3bee
cmpl $0x20, %ebx
jne 0x3bf2
shll $0x2, %edx
jmp 0x3bf9
addl %edx, %edx
jmp 0x3bf9
leal (%rdx,%rdx,2), %edx
incl %edx
shrl %edx
pushq $-0x1
popq %rbp
movl %ebp, %r12d
movl %eax, %ecx
shll %cl, %r12d
notl %r12d
addl %edx, %r12d
shrl %cl, %r12d
movl $0x3fff, %edx           # imm = 0x3FFF
shrq %cl, %rdx
incq %rdx
xorl %r13d, %r13d
movl 0xc(%rsp), %r9d
testb %r9b, %r9b
cmovneq %r13, %rdx
leaq (%rdx,%r15), %rax
leaq (%rax,%r12,2), %rax
movq %rsi, %rdi
subq %rax, %rdi
movl %r14d, %ecx
shrq %cl, %rdi
leal 0x2(%rdi), %r8d
shll %cl, %edi
leaq (%r15,%r12,2), %rax
addq %rdi, %rax
movq %r12, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movl %r8d, 0x40(%rsp)
testb %r9b, %r9b
jne 0x3c67
subq %rax, %rsi
movq %rsi, 0x28(%rsp)
movq %rsi, %r13
addq %r13, %rax
movq %rax, 0x38(%rsp)
movq 0x10(%rsp), %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x43b4
testl %eax, %eax
js 0x3d2f
addq %r12, %r12
cmpl $0x20, %ebx
je 0x3cdc
cmpl $0x10, %ebx
je 0x3cac
cmpl $0xc, %ebx
movq 0x10(%rsp), %rbx
jne 0x3cc9
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x3d40
jmp 0x3cbe
leaq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x3e8a
testl %eax, %eax
js 0x3d2f
cmpb $0x0, 0xc(%rsp)
jne 0x3cf2
addq %r15, %r12
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x43b4
jmp 0x3d1c
leaq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x3f95
testl %eax, %eax
js 0x3d2f
addq %r15, %r12
addq %r13, %r12
pushq $0x1
popq %rdx
movl %r14d, %ecx
shll %cl, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x43b4
testl %eax, %eax
js 0x3d2f
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x40ae
testl %eax, %eax
js 0x3d2f
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x418a
movl %eax, %ebp
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq