// File: /workspace/github_c_makefile_star2_O1/lb3361[P]dosfs/ff.c
// Function: create_partition
static FRESULT create_partition (
	BYTE drv,			/* Physical drive number */
	const LBA_t plst[],	/* Partition list */
	BYTE sys,			/* System ID (for only MBR, temp setting) */
	BYTE* buf			/* Working buffer for a sector */
)
{
	UINT i, cy;
	LBA_t sz_drv;
	DWORD sz_drv32, s_lba32, n_lba32;
	BYTE *pte, hd, n_hd, sc, n_sc;

	/* Get drive size */
	if (disk_ioctl(drv, GET_SECTOR_COUNT, &sz_drv) != RES_OK) return FR_DISK_ERR;

#if FF_LBA64
	if (sz_drv >= FF_MIN_GPT) {	/* Create partitions in GPT */
		WORD ss;
		UINT sz_pt, pi, si, ofs;
		DWORD bcc, rnd, align;
		QWORD s_lba64, n_lba64, sz_pool, s_bpt;
		static const BYTE gpt_mbr[16] = {0x00, 0x00, 0x02, 0x00, 0xEE, 0xFE, 0xFF, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};

#if FF_MAX_SS != FF_MIN_SS
		if (disk_ioctl(drv, GET_SECTOR_SIZE, &ss) != RES_OK) return FR_DISK_ERR;	/* Get sector size */
		if (ss > FF_MAX_SS || ss < FF_MIN_SS || (ss & (ss - 1))) return FR_DISK_ERR;
#else
		ss = FF_MAX_SS;
#endif
		rnd = GET_FATTIME();			/* Random seed */
		align = GPT_ALIGN / ss;			/* Partition alignment [sector] */
		sz_pt = GPT_ITEMS * SZ_GPTE / ss;	/* Size of PT [sector] */
		s_bpt = sz_drv - sz_pt - 1;		/* Backup PT start sector */
		s_lba64 = 2 + sz_pt;			/* First allocatable sector */
		sz_pool = s_bpt - s_lba64;		/* Size of allocatable area */
		bcc = 0xFFFFFFFF; n_lba64 = 1;
		pi = si = 0;	/* partition table index, size table index */
		do {
			if (pi * SZ_GPTE % ss == 0) mem_set(buf, 0, ss);	/* Clean the buffer if needed */
			if (n_lba64 != 0) {	/* Is the size table not termintated? */
				s_lba64 = (s_lba64 + align - 1) & ((QWORD)0 - align);	/* Align partition start */
				n_lba64 = plst[si++];	/* Get a partition size */
				if (n_lba64 <= 100) {	/* Is the size in percentage? */
					n_lba64 = sz_pool * n_lba64 / 100;
					n_lba64 = (n_lba64 + align - 1) & ((QWORD)0 - align);	/* Align partition end (only if in percentage) */
				}
				if (s_lba64 + n_lba64 > s_bpt) {	/* Clip at end of the pool */
					n_lba64 = (s_lba64 < s_bpt) ? s_bpt - s_lba64 : 0;
				}
			}
			if (n_lba64 != 0) {		/* Add a partition? */
				ofs = pi * SZ_GPTE % ss;
				mem_cpy(buf + ofs + GPTE_PtGuid, GUID_MS_Basic, 16);	/* Partition GUID (Microsoft Basic Data) */
				rnd = make_rand(rnd, buf + ofs + GPTE_UpGuid, 16);		/* Unique partition GUID */
				st_qword(buf + ofs + GPTE_FstLba, s_lba64);				/* Partition start LBA */
				st_qword(buf + ofs + GPTE_LstLba, s_lba64 + n_lba64 - 1);	/* Partition end LBA */
				s_lba64 += n_lba64;		/* Next partition LBA */
			}
			if ((pi + 1) * SZ_GPTE % ss == 0) {		/* Write the buffer if it is filled up */
				for (i = 0; i < ss; bcc = crc32(bcc, buf[i++])) ;	/* Calculate table check sum */
				if (disk_write(drv, buf, 2 + pi * SZ_GPTE / ss, 1) != RES_OK) return FR_DISK_ERR;		/* Primary table */
				if (disk_write(drv, buf, s_bpt + pi * SZ_GPTE / ss, 1) != RES_OK) return FR_DISK_ERR;	/* Secondary table */
			}
		} while (++pi < GPT_ITEMS);

		/* Create primary GPT header */
		mem_set(buf, 0, ss);
		mem_cpy(buf + GPTH_Sign, "EFI PART" "\0\0\1\0" "\x5C\0\0", 16);	/* Signature, version (1.0) and size (92) */
		st_dword(buf + GPTH_PtBcc, ~bcc);				/* Table check sum */
		st_qword(buf + GPTH_CurLba, 1);					/* LBA of this header */
		st_qword(buf + GPTH_BakLba, sz_drv - 1);		/* LBA of another header */
		st_qword(buf + GPTH_FstLba, 2 + sz_pt);			/* LBA of first allocatable sector */
		st_qword(buf + GPTH_LstLba, s_bpt - 1);			/* LBA of last allocatable sector */
		st_dword(buf + GPTH_PteSize, SZ_GPTE);			/* Size of a table entry */
		st_dword(buf + GPTH_PtNum, GPT_ITEMS);			/* Number of table entries */
		st_dword(buf + GPTH_PtOfs, 2);					/* LBA of this table */
		rnd = make_rand(rnd, buf + GPTH_DskGuid, 16);	/* Disk GUID */
		for (i = 0, bcc= 0xFFFFFFFF; i < 92; bcc = crc32(bcc, buf[i++])) ;	/* Calculate header check sum */
		st_dword(buf + GPTH_Bcc, ~bcc);					/* Header check sum */
		if (disk_write(drv, buf, 1, 1) != RES_OK) return FR_DISK_ERR;

		/* Create secondary GPT header */
		st_qword(buf + GPTH_CurLba, sz_drv - 1);		/* LBA of this header */
		st_qword(buf + GPTH_BakLba, 1);					/* LBA of another header */
		st_qword(buf + GPTH_PtOfs, s_bpt);				/* LBA of this table */
		st_dword(buf + GPTH_Bcc, 0);
		for (i = 0, bcc= 0xFFFFFFFF; i < 92; bcc = crc32(bcc, buf[i++])) ;	/* Calculate header check sum */
		st_dword(buf + GPTH_Bcc, ~bcc);					/* Header check sum */
		if (disk_write(drv, buf, sz_drv - 1, 1) != RES_OK) return FR_DISK_ERR;

		/* Create protective MBR */
		mem_set(buf, 0, ss);
		mem_cpy(buf + MBR_Table, gpt_mbr, 16);			/* Create a GPT partition */
		st_word(buf + BS_55AA, 0xAA55);
		if (disk_write(drv, buf, 0, 1) != RES_OK) return FR_DISK_ERR;

	} else
#endif
	{					/* Create partitions in MBR */
		sz_drv32 = (DWORD)sz_drv;
		n_sc = N_SEC_TRACK;		/* Determine drive CHS without any consideration of the drive geometry */
		for (n_hd = 8; n_hd != 0 && sz_drv32 / n_hd / n_sc > 1024; n_hd *= 2) ;
		if (n_hd == 0) n_hd = 255;	/* Number of heads needs to be <256 */

		mem_set(buf, 0, FF_MAX_SS);	/* Clear MBR */
		pte = buf + MBR_Table;	/* Partition table in the MBR */
		for (i = 0, s_lba32 = n_sc; i < 4 && s_lba32 != 0 && s_lba32 < sz_drv32; i++, s_lba32 += n_lba32) {
			n_lba32 = (DWORD)plst[i];	/* Get partition size */
			if (n_lba32 <= 100) n_lba32 = (n_lba32 == 100) ? sz_drv32 : sz_drv32 / 100 * n_lba32;	/* Size in percentage? */
			if (s_lba32 + n_lba32 > sz_drv32 || s_lba32 + n_lba32 < s_lba32) n_lba32 = sz_drv32 - s_lba32;	/* Clip at drive size */
			if (n_lba32 == 0) break;	/* End of table or no sector to allocate? */

			st_dword(pte + PTE_StLba, s_lba32);		/* Start LBA */
			st_dword(pte + PTE_SizLba, n_lba32);	/* Number of sectors */
			pte[PTE_System] = sys;					/* System type */

			cy = (UINT)(s_lba32 / n_sc / n_hd);		/* Start cylinder */
			hd = (BYTE)(s_lba32 / n_sc % n_hd);		/* Start head */
			sc = (BYTE)(s_lba32 % n_sc + 1);		/* Start sector */
			pte[PTE_StHead] = hd;
			pte[PTE_StSec] = (BYTE)((cy >> 2 & 0xC0) | sc);
			pte[PTE_StCyl] = (BYTE)cy;

			cy = (UINT)((s_lba32 + n_lba32 - 1) / n_sc / n_hd);	/* End cylinder */
			hd = (BYTE)((s_lba32 + n_lba32 - 1) / n_sc % n_hd);	/* End head */
			sc = (BYTE)((s_lba32 + n_lba32 - 1) % n_sc + 1);	/* End sector */
			pte[PTE_EdHead] = hd;
			pte[PTE_EdSec] = (BYTE)((cy >> 2 & 0xC0) | sc);
			pte[PTE_EdCyl] = (BYTE)cy;

			pte += SZ_PTE;		/* Next entry */
		}

		st_word(buf + BS_55AA, 0xAA55);		/* MBR signature */
		if (disk_write(drv, buf, 0, 1) != RES_OK) return FR_DISK_ERR;	/* Write it to the MBR */
	}

	return FR_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, 0x8(%rsp)
movl %edx, %r15d
movq %rsi, 0x30(%rsp)
movl %edi, %ebp
movl $0x1, (%rsp)
leaq 0x28(%rsp), %rdx
movl $0x1, %esi
callq 0x2dcc
testl %eax, %eax
je 0xae3a
movl (%rsp), %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%rsp), %r12
movzbl %bpl, %eax
movl %eax, 0x4(%rsp)
cmpq $0x10000000, %r12       # imm = 0x10000000
jb 0xb3b8
callq 0x2e38
movl %eax, %r15d
movq 0x28(%rsp), %rax
leaq -0x21(%rax), %rsi
movq %rax, 0x38(%rsp)
addq $-0x43, %rax
movq %rax, 0x40(%rsp)
movl $0x1, %r12d
movl $0x22, %ebx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %edi, %edi
leaq 0x2623(%rip), %rbp      # 0xd4b0
movl $0x0, 0x24(%rsp)
movq %rsi, 0x18(%rsp)
movl %edi, %r8d
shll $0x7, %r8d
movl %r8d, %r13d
andl $0x180, %r13d           # imm = 0x180
jne 0xaeda
movl $0x200, %edx            # imm = 0x200
movq %rdi, 0x10(%rsp)
movq 0x8(%rsp), %rdi
xorl %esi, %esi
movq %r8, %rbp
callq 0x2120
movq %rbp, %r8
leaq 0x25e0(%rip), %rbp      # 0xd4b0
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
testq %r12, %r12
je 0xaf4e
movl 0x24(%rsp), %eax
movq 0x30(%rsp), %rcx
movq (%rcx,%rax,8), %r12
cmpq $0x64, %r12
ja 0xaf21
imulq 0x40(%rsp), %r12
shrq $0x2, %r12
movq %r12, %rax
movabsq $0x28f5c28f5c28f5c3, %rcx # imm = 0x28F5C28F5C28F5C3
mulq %rcx
movq %rdx, %r12
shrq $0x2, %r12
addq $0x7ff, %r12            # imm = 0x7FF
andq $-0x800, %r12           # imm = 0xF800
addq $0x7ff, %rbx            # imm = 0x7FF
andq $-0x800, %rbx           # imm = 0xF800
incl 0x24(%rsp)
leaq (%r12,%rbx), %rax
cmpq %rsi, %rax
jbe 0xaf51
movq %rsi, %rax
subq %rbx, %rax
movl $0x0, %r12d
cmovaeq %rax, %r12
jmp 0xaf51
xorl %r12d, %r12d
testq %r12, %r12
je 0xb069
movl %edi, %ecx
andl $0x3, %ecx
shll $0x7, %ecx
movq 0x8(%rsp), %rdx
addq %rdx, %rcx
movl %r13d, %eax
addq %rdx, %rax
xorl %edx, %edx
movb (%rdx,%rbp), %sil
movb %sil, (%rcx,%rdx)
incq %rdx
cmpl $0x10, %edx
jne 0xaf72
movq %r8, 0x10(%rsp)
movq %rdi, %r13
leaq 0x10(%rax), %rcx
cmpl $0x1, %r15d
adcl $0x0, %r15d
movl $0x10, %edx
movl $0x8, %esi
movl %r15d, %edi
shrl %edi
movl %edi, %r8d
xorl $0xa3000000, %r8d       # imm = 0xA3000000
testb $0x1, %r15b
movl %r8d, %r15d
cmovel %edi, %r15d
decl %esi
jne 0xafa0
movb %r15b, (%rcx)
incq %rcx
decl %edx
jne 0xaf9b
movb %bl, 0x20(%rax)
movb %bh, 0x21(%rax)
movl %ebx, %esi
movq %rbx, %rdi
movq %rbx, %r8
movq %rbx, %r9
movq %rbx, %r10
leaq (%r12,%rbx), %rcx
leaq (%r12,%rbx), %rdx
decq %rdx
movl %ebx, %r11d
shrl $0x10, %r11d
movb %r11b, 0x22(%rax)
shrl $0x18, %esi
movb %sil, 0x23(%rax)
shrq $0x20, %rdi
movb %dil, 0x24(%rax)
shrq $0x28, %r8
movb %r8b, 0x25(%rax)
shrq $0x30, %r9
movb %r9b, 0x26(%rax)
shrq $0x38, %r10
movb %r10b, 0x27(%rax)
movb %dl, 0x28(%rax)
movb %dh, 0x29(%rax)
movl %edx, %esi
shrl $0x10, %esi
movb %sil, 0x2a(%rax)
movl %edx, %esi
shrl $0x18, %esi
movb %sil, 0x2b(%rax)
movq %rdx, %rsi
shrq $0x20, %rsi
movb %sil, 0x2c(%rax)
movq %rdx, %rsi
shrq $0x28, %rsi
movb %sil, 0x2d(%rax)
movq %rdx, %rsi
shrq $0x30, %rsi
movb %sil, 0x2e(%rax)
shrq $0x38, %rdx
movb %dl, 0x2f(%rax)
movq %rcx, %rbx
movq 0x18(%rsp), %rsi
movq %r13, %rdi
movq 0x10(%rsp), %r8
incl %edi
testb $0x3, %dil
jne 0xb119
movq %rdi, 0x10(%rsp)
xorl %eax, %eax
movq 0x8(%rsp), %rcx
movb (%rcx,%rax), %cl
movb $0x1, %dl
testb %cl, %dl
sete %sil
xorb %r14b, %sil
movl %r14d, %edi
shrl %edi
movl %edi, %r14d
xorl $0xedb88320, %r14d      # imm = 0xEDB88320
testb $0x1, %sil
cmovnel %edi, %r14d
addb %dl, %dl
jne 0xb086
incq %rax
cmpq $0x200, %rax            # imm = 0x200
jne 0xb07c
shrl $0x9, %r8d
leal 0x2(%r8), %edx
movl $0x1, (%rsp)
movl 0x4(%rsp), %edi
movq 0x8(%rsp), %rsi
movl $0x1, %ecx
movq %r8, %r13
callq 0x2d47
testl %eax, %eax
movq 0x18(%rsp), %rax
jne 0xae28
movl %r13d, %edx
addq %rax, %rdx
movl $0x1, (%rsp)
movl 0x4(%rsp), %edi
movq 0x8(%rsp), %rsi
movl $0x1, %ecx
callq 0x2d47
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
testl %eax, %eax
jne 0xae28
cmpl $0x80, %edi
jne 0xae9a
xorl %ebx, %ebx
movl $0x200, %edx            # imm = 0x200
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
callq 0x2120
leaq 0x237e(%rip), %rax      # 0xd4c0
movb (%rbx,%rax), %cl
movb %cl, (%rbp,%rbx)
incq %rbx
cmpl $0x10, %ebx
jne 0xb142
notl %r14d
movl %r14d, 0x58(%rbp)
movb $0x1, 0x18(%rbp)
xorl %eax, %eax
movl %eax, 0x19(%rbp)
movl %eax, 0x1c(%rbp)
movq 0x28(%rsp), %rcx
decq %rcx
leaq 0x21(%rbp), %rbx
movb %cl, 0x20(%rbp)
movb %ch, 0x21(%rbp)
movl %ecx, %edx
shrl $0x10, %edx
movb %dl, 0x22(%rbp)
movl %ecx, %edx
shrl $0x18, %edx
movb %dl, 0x23(%rbp)
movq %rcx, %rdx
shrq $0x20, %rdx
movb %dl, 0x24(%rbp)
movq %rcx, %rdx
shrq $0x28, %rdx
movb %dl, 0x25(%rbp)
movq %rcx, %rdx
shrq $0x30, %rdx
movb %dl, 0x26(%rbp)
shrq $0x38, %rcx
movb %cl, 0x27(%rbp)
movb $0x22, 0x28(%rbp)
movq 0x38(%rsp), %rdx
addq $-0x22, %rdx
movl %eax, 0x29(%rbp)
movl %eax, 0x2c(%rbp)
movb %dl, 0x30(%rbp)
movb %dh, 0x31(%rbp)
movl %edx, %ecx
shrl $0x10, %ecx
movb %cl, 0x32(%rbp)
movl %edx, %ecx
shrl $0x18, %ecx
movb %cl, 0x33(%rbp)
movq %rdx, %rcx
shrq $0x20, %rcx
movb %cl, 0x34(%rbp)
movq %rdx, %rcx
shrq $0x28, %rcx
movb %cl, 0x35(%rbp)
movq %rdx, %rcx
shrq $0x30, %rcx
movb %cl, 0x36(%rbp)
shrq $0x38, %rdx
movb %dl, 0x37(%rbp)
movl $0x80, %ecx
movl %ecx, 0x54(%rbp)
movl %ecx, 0x50(%rbp)
movl $0x2, 0x48(%rbp)
leaq 0x38(%rbp), %rcx
cmpl $0x1, %r15d
adcl %eax, %r15d
movl $0x10, %eax
movl $0x8, %edx
movl %r15d, %esi
shrl %esi
movl %esi, %edi
xorl $0xa3000000, %edi       # imm = 0xA3000000
testb $0x1, %r15b
movl %edi, %r15d
cmovel %esi, %r15d
decl %edx
jne 0xb220
movb %r15b, (%rcx)
incq %rcx
decl %eax
jne 0xb21b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movb (%rbp,%rcx), %dl
movb $0x1, %sil
testb %dl, %sil
sete %dil
xorb %al, %dil
movl %eax, %r8d
shrl %r8d
movl %r8d, %eax
xorl $0xedb88320, %eax       # imm = 0xEDB88320
testb $0x1, %dil
cmovnel %r8d, %eax
addb %sil, %sil
jne 0xb254
incq %rcx
cmpq $0x5c, %rcx
jne 0xb24d
notl %eax
movl %eax, 0x10(%rbp)
movl $0x1, (%rsp)
movl $0x1, %edx
movl 0x4(%rsp), %edi
movq %rbp, %rsi
movl $0x1, %ecx
callq 0x2d47
testl %eax, %eax
movq 0x18(%rsp), %rcx
jne 0xae28
movq 0x28(%rsp), %rdx
decq %rdx
movq 0x8(%rsp), %rsi
movb %dl, 0x18(%rsi)
movb %dh, 0x19(%rsi)
movl %edx, %eax
shrl $0x10, %eax
movb %al, 0x1a(%rsi)
movl %edx, %eax
shrl $0x18, %eax
movb %al, 0x1b(%rsi)
movq %rdx, %rax
shrq $0x20, %rax
movb %al, 0x1c(%rsi)
movq %rdx, %rax
shrq $0x28, %rax
movb %al, 0x1d(%rsi)
movq %rdx, %rax
shrq $0x30, %rax
movb %al, 0x1e(%rsi)
movq %rdx, %rax
shrq $0x38, %rax
movb %al, 0x1f(%rsi)
movb $0x1, 0x20(%rsi)
xorl %eax, %eax
movl %eax, 0x3(%rbx)
movl %eax, (%rbx)
movq %rcx, 0x48(%rsi)
movl %eax, 0x10(%rsi)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movb (%rsi,%rax), %r10b
movb $0x1, %dil
testb %r10b, %dil
sete %r8b
xorb %cl, %r8b
movl %ecx, %r9d
shrl %r9d
movl %r9d, %ecx
xorl $0xedb88320, %ecx       # imm = 0xEDB88320
testb $0x1, %r8b
cmovnel %r9d, %ecx
addb %dil, %dil
jne 0xb31a
incq %rax
cmpq $0x5c, %rax
jne 0xb313
notl %ecx
movl %ecx, 0x10(%rsi)
movl $0x1, (%rsp)
movl 0x4(%rsp), %edi
movl $0x1, %ecx
callq 0x2d47
testl %eax, %eax
jne 0xae28
xorl %ebx, %ebx
movl $0x200, %edx            # imm = 0x200
movq 0x8(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2120
leaq 0x2148(%rip), %rax      # 0xd4d0
movb (%rbx,%rax), %cl
movb %cl, 0x1be(%r14,%rbx)
incq %rbx
cmpl $0x10, %ebx
jne 0xb388
movw $0xaa55, 0x1fe(%r14)    # imm = 0xAA55
movl $0x1, (%rsp)
movl 0x4(%rsp), %edi
movq %r14, %rsi
jmp 0xb53a
movb $0x8, %bl
movq 0x8(%rsp), %rdi
movzbl %bl, %ecx
movl %r12d, %eax
xorl %edx, %edx
divl %ecx
cmpl $0xfc3f, %eax           # imm = 0xFC3F
jb 0xb3d6
addb %bl, %bl
jne 0xb3bf
movb $-0x1, %bl
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x2120
cmpq $0x40, %r12
jb 0xb521
movl %r12d, %eax
imulq $0x51eb851f, %rax, %rsi # imm = 0x51EB851F
shrq $0x25, %rsi
movzbl %bl, %edi
movq 0x8(%rsp), %rax
leaq 0x1cd(%rax), %rbp
movl $0x3f, %edx
xorl %r8d, %r8d
movl $0xc0, %r9d
movq 0x30(%rsp), %rax
movl (%rax,%r8,8), %eax
movl %esi, %ebx
imull %eax, %ebx
cmpl $0x64, %eax
cmovel %r12d, %ebx
cmoval %eax, %ebx
movl %r12d, %eax
subl %edx, %eax
movl %ebx, %ecx
addl %edx, %ecx
cmovbl %eax, %ebx
cmpl %r12d, %ecx
cmoval %eax, %ebx
testl %ebx, %ebx
je 0xb521
movb %dl, -0x7(%rbp)
movb %dh, -0x6(%rbp)
movl %edx, %eax
shrl $0x10, %eax
movb %al, -0x5(%rbp)
movl %edx, %eax
shrl $0x18, %eax
movb %al, -0x4(%rbp)
movb %bl, -0x3(%rbp)
movb %bh, -0x2(%rbp)
movl %ebx, %eax
shrl $0x10, %eax
movb %al, -0x1(%rbp)
movl %ebx, %eax
shrl $0x18, %eax
movb %al, (%rbp)
movb %r15b, -0xb(%rbp)
movl %edx, %eax
imulq $0x4104105, %rax, %rax  # imm = 0x4104105
shrq $0x20, %rax
movl %edx, %ecx
subl %eax, %ecx
shrl %ecx
addl %eax, %ecx
shrl $0x5, %ecx
movq %rdx, %r14
movl %ecx, %edx
shll $0x6, %edx
movl %ecx, %eax
subl %edx, %ecx
xorl %edx, %edx
divl %edi
addl %r14d, %ecx
incl %ecx
movb %dl, -0xe(%rbp)
movl %eax, %edx
shrl $0x2, %edx
andl %r9d, %edx
orl %ecx, %edx
movb %dl, -0xd(%rbp)
movb %al, -0xc(%rbp)
addl %ebx, %r14d
movl %r14d, %r11d
addl $-0x1, %r11d
setb %r10b
imulq $0x4104105, %r11, %rax  # imm = 0x4104105
shrq $0x20, %rax
movl %r11d, %ecx
subl %eax, %ecx
shrl %ecx
addl %eax, %ecx
shrl $0x5, %ecx
movl %ecx, %edx
shll $0x6, %edx
movl %ecx, %eax
subl %edx, %ecx
xorl %edx, %edx
divl %edi
addl %r11d, %ecx
incl %ecx
movb %dl, -0xa(%rbp)
movl %eax, %edx
shrl $0x2, %edx
andl %r9d, %edx
orl %ecx, %edx
movb %dl, -0x9(%rbp)
movb %al, -0x8(%rbp)
cmpq $0x2, %r8
ja 0xb521
testb %r10b, %r10b
je 0xb521
movq %r14, %rdx
incq %r8
addq $0x10, %rbp
cmpl %r12d, %edx
jb 0xb417
movq 0x8(%rsp), %rsi
movw $0xaa55, 0x1fe(%rsi)    # imm = 0xAA55
movl $0x1, (%rsp)
movl 0x4(%rsp), %edi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x2d47
testl %eax, %eax
jne 0xae28
movl $0x0, (%rsp)
jmp 0xae28