// File: /workspace/github_c_makefile_star2_O0/salextpuru[P]speccy-toochain/src/spgbld/func.cxx
// Function: pack_blocks()
void pack_blocks()
{
	struct stat st;
	int s1, s2, sz1, sz2;
	C_PACK p;

	for (int i=0; i<conf.n_blocks; i++) {
		char f1n[16], f2n[16], f3n[16];
		rand_name(f1n);
		rand_name(f2n);
		rand_name(f3n);
		// add errors check here!!!
		FILE* f1 = fopen(f1n, "w+");
		fwrite(blk[i].data, 1, blk[i].size, f1);
		fclose(f1);
		s1 = s2 = 16384;
		sz1 = sz2 = 31;

		if (conf.packer == PM_AUTO || conf.packer == PM_MLZ) {
			std::string cmd("mhmt -mlz ");
			cmd=cmd+f1n+" "+f2n;

			if (system(cmd.c_str()) <0) error(MHMT);

			// if (_spawnlp(_P_WAIT, "mhmt.exe", "dummy", "-mlz", f1n, f2n, NULL) < 0) error(MHMT);
			stat(f2n, &st);
			s1 = st.st_size;
			sz1 = sz(st.st_size);
		}

		if (conf.packer == PM_AUTO || conf.packer == PM_HST) {
			std::string cmd("mhmt -hst ");
			cmd=cmd+f1n+" "+f3n;

			if (system(cmd.c_str()) < 0) error(MHMT);

			// if (_spawnlp(_P_WAIT, "mhmt.exe", "dummy", "-hst", f1n, f3n, NULL) < 0) error(MHMT);
			stat(f3n, &st);
			s2 = st.st_size;
			sz2 = sz(st.st_size);
		}

		remove(f1n);

		if (sz(blk[i].size) <= min(sz1, sz2))   // if unpacked chunk has the same size as packed, leave it unpacked
			p = PM_NONE;

		else
			p = (sz1 <= sz2) ? PM_MLZ : PM_HST;   // if MegaLZ gives the same chunk size as Hrust, use it as faster

		hdr.blk[i].comp = p;

		switch (p) {
		case PM_MLZ: {
			store_block(i, f2n, s1);
			break;
		}

		case PM_HST: {
			store_block(i, f3n, s2);
			break;
		}
		}

		remove(f2n);
		remove(f3n);
	}
}

// Assembly:
subq $0x258, %rsp            # imm = 0x258
movl $0x0, 0x1b0(%rsp)
movl 0x1b0(%rsp), %eax
leaq 0x4449d0(%rip), %rcx    # 0x447dd0
cmpl 0x18(%rcx), %eax
jge 0x3a5e
leaq 0x1a0(%rsp), %rdi
callq 0x3250
leaq 0x190(%rsp), %rdi
callq 0x3250
leaq 0x180(%rsp), %rdi
callq 0x3250
leaq 0x1a0(%rsp), %rdi
leaq 0x1e23(%rip), %rsi      # 0x5262
callq 0x21f0
movq %rax, 0x178(%rsp)
movslq 0x1b0(%rsp), %rax
leaq 0x4175(%rip), %rdi      # 0x75d0
imulq $0x4408, %rax, %rax     # imm = 0x4408
addq %rax, %rdi
addq $0x408, %rdi            # imm = 0x408
movslq 0x1b0(%rsp), %rcx
leaq 0x4155(%rip), %rax      # 0x75d0
imulq $0x4408, %rcx, %rcx     # imm = 0x4408
addq %rcx, %rax
movslq 0x404(%rax), %rdx
movq 0x178(%rsp), %rcx
movl $0x1, %esi
callq 0x2330
movq 0x178(%rsp), %rdi
callq 0x2190
movl $0x4000, 0x1c0(%rsp) # imm = 0x4000
movl $0x4000, 0x1c4(%rsp) # imm = 0x4000
movl $0x1f, 0x1b8(%rsp)
movl $0x1f, 0x1bc(%rsp)
leaq 0x4448f2(%rip), %rax    # 0x447dd0
cmpl $-0x1, (%rax)
je 0x34f3
leaq 0x4448e6(%rip), %rax    # 0x447dd0
cmpl $0x1, (%rax)
jne 0x36fc
leaq 0x157(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x22e0
movq 0x50(%rsp), %rdx
leaq 0x1d54(%rip), %rsi      # 0x5265
leaq 0x158(%rsp), %rdi
callq 0x4630
jmp 0x3520
leaq 0x157(%rsp), %rdi
callq 0x21b0
leaq 0xe0(%rsp), %rdi
leaq 0x158(%rsp), %rsi
leaq 0x1a0(%rsp), %rdx
callq 0x4740
jmp 0x354c
leaq 0x1cc7(%rip), %rdx      # 0x521a
leaq 0x100(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x46f0
jmp 0x356a
leaq 0x120(%rsp), %rdi
leaq 0x100(%rsp), %rsi
leaq 0x190(%rsp), %rdx
callq 0x46f0
jmp 0x3589
leaq 0x158(%rsp), %rdi
movq %rdi, 0x40(%rsp)
leaq 0x120(%rsp), %rsi
movq %rsi, 0x38(%rsp)
callq 0x2220
movq 0x38(%rsp), %rdi
callq 0x20f0
leaq 0x100(%rsp), %rdi
callq 0x20f0
leaq 0xe0(%rsp), %rdi
callq 0x20f0
movq 0x40(%rsp), %rdi
callq 0x2090
movq %rax, %rdi
callq 0x2150
movl %eax, 0x4c(%rsp)
jmp 0x35e4
movl 0x4c(%rsp), %eax
cmpl $0x0, %eax
jge 0x36a0
leaq 0x1c78(%rip), %rdi      # 0x5270
xorl %eax, %eax
callq 0x2030
jmp 0x3601
leaq 0x1a37(%rip), %rdi      # 0x503f
xorl %eax, %eax
callq 0x2030
jmp 0x3611
movl $0xb, %edi
callq 0x2210
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
leaq 0x157(%rsp), %rdi
callq 0x21b0
jmp 0x3a66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
jmp 0x36ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
jmp 0x3691
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x20f0
leaq 0xe0(%rsp), %rdi
callq 0x20f0
jmp 0x36ea
leaq 0x190(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x2160
movq 0x1f8(%rsp), %rax
movl %eax, 0x1c4(%rsp)
movq 0x1f8(%rsp), %rax
subq $0x1, %rax
sarq $0x9, %rax
movl %eax, 0x1bc(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x20f0
jmp 0x36fc
leaq 0x158(%rsp), %rdi
callq 0x20f0
jmp 0x3a66
leaq 0x4446cd(%rip), %rax    # 0x447dd0
cmpl $-0x1, (%rax)
je 0x3718
leaq 0x4446c1(%rip), %rax    # 0x447dd0
cmpl $0x2, (%rax)
jne 0x3909
leaq 0xbf(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x22e0
movq 0x30(%rsp), %rdx
leaq 0x1b6e(%rip), %rsi      # 0x52a4
leaq 0xc0(%rsp), %rdi
callq 0x4630
jmp 0x3745
leaq 0xbf(%rsp), %rdi
callq 0x21b0
leaq 0x58(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0x1a0(%rsp), %rdx
callq 0x4740
jmp 0x376e
leaq 0x1aa5(%rip), %rdx      # 0x521a
leaq 0x78(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x46f0
jmp 0x3786
leaq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0x180(%rsp), %rdx
callq 0x46f0
jmp 0x37a2
leaq 0xc0(%rsp), %rdi
movq %rdi, 0x20(%rsp)
leaq 0x98(%rsp), %rsi
movq %rsi, 0x18(%rsp)
callq 0x2220
movq 0x18(%rsp), %rdi
callq 0x20f0
leaq 0x78(%rsp), %rdi
callq 0x20f0
leaq 0x58(%rsp), %rdi
callq 0x20f0
movq 0x20(%rsp), %rdi
callq 0x2090
movq %rax, %rdi
callq 0x2150
movl %eax, 0x2c(%rsp)
jmp 0x37f7
movl 0x2c(%rsp), %eax
cmpl $0x0, %eax
jge 0x38ad
leaq 0x1a65(%rip), %rdi      # 0x5270
xorl %eax, %eax
callq 0x2030
jmp 0x3814
leaq 0x1824(%rip), %rdi      # 0x503f
xorl %eax, %eax
callq 0x2030
jmp 0x3824
movl $0xb, %edi
callq 0x2210
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
leaq 0xbf(%rsp), %rdi
callq 0x21b0
jmp 0x3a66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
jmp 0x38f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
jmp 0x38a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x20f0
leaq 0x58(%rsp), %rdi
callq 0x20f0
jmp 0x38f7
leaq 0x180(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x2160
movq 0x1f8(%rsp), %rax
movl %eax, 0x1c0(%rsp)
movq 0x1f8(%rsp), %rax
subq $0x1, %rax
sarq $0x9, %rax
movl %eax, 0x1b8(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x20f0
jmp 0x3909
leaq 0xc0(%rsp), %rdi
callq 0x20f0
jmp 0x3a66
leaq 0x1a0(%rsp), %rdi
callq 0x2300
movslq 0x1b0(%rsp), %rcx
leaq 0x3cab(%rip), %rax      # 0x75d0
imulq $0x4408, %rcx, %rcx     # imm = 0x4408
addq %rcx, %rax
movl 0x404(%rax), %eax
subl $0x1, %eax
sarl $0x9, %eax
movl %eax, 0x14(%rsp)
movl 0x1bc(%rsp), %eax
cmpl 0x1b8(%rsp), %eax
jge 0x395c
movl 0x1bc(%rsp), %eax
movl %eax, 0x10(%rsp)
jmp 0x3967
movl 0x1b8(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x14(%rsp), %eax
movl 0x10(%rsp), %ecx
cmpl %ecx, %eax
jg 0x3980
movl $0x0, 0x1b4(%rsp)
jmp 0x39a4
movl 0x1bc(%rsp), %edx
movl 0x1b8(%rsp), %esi
movl $0x2, %eax
movl $0x1, %ecx
cmpl %esi, %edx
cmovlel %ecx, %eax
movl %eax, 0x1b4(%rsp)
movslq 0x1b0(%rsp), %rax
leaq (%rax,%rax,2), %rcx
leaq 0x3819(%rip), %rax      # 0x71d0
movl 0x1b4(%rsp), %esi
movzwl 0x100(%rax,%rcx), %edx
shll $0xe, %esi
andl $0x3fff, %edx           # imm = 0x3FFF
orl %esi, %edx
movw %dx, 0x100(%rax,%rcx)
movl 0x1b4(%rsp), %eax
movl %eax, 0xc(%rsp)
subl $0x1, %eax
je 0x39f6
jmp 0x39eb
movl 0xc(%rsp), %eax
subl $0x2, %eax
je 0x3a13
jmp 0x3a2e
movl 0x1b0(%rsp), %edi
leaq 0x190(%rsp), %rsi
movl 0x1c4(%rsp), %edx
callq 0x32d0
jmp 0x3a2e
movl 0x1b0(%rsp), %edi
leaq 0x180(%rsp), %rsi
movl 0x1c0(%rsp), %edx
callq 0x32d0
leaq 0x190(%rsp), %rdi
callq 0x2300
leaq 0x180(%rsp), %rdi
callq 0x2300
movl 0x1b0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1b0(%rsp)
jmp 0x33f2
addq $0x258, %rsp            # imm = 0x258
retq
movq 0x148(%rsp), %rdi
callq 0x22d0
nopw %cs:(%rax,%rax)