// File: /workspace/github_c_makefile_star2_O0/0x3f00[P]PhotonCpp/PhotonCpp.cpp
// Function: png2layer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
std::pair<std::string, PhotonLayer> png2layer(const std::string & bufferPng)
{
	char* img = nullptr;
	int w = 0;
	int h = 0;
	int n = 0;
	img = (char*)stbi_load_from_memory((unsigned char*)bufferPng.data(), bufferPng.length(), &w, &h, &n, 4);
	PhotonLayer res(w, h);

	if (!img)
		return {"Invalid PNG file format", res};

	if (w != 1440 || h != 2560)
		return { "Invalid PNG image size: (" + std::to_string(w) + "x" + std::to_string(h) + " instead of 1440x2560)", res };

	for (int j = 0; j < h; j++)
		for (int i = 0; i < w; i++)
		{
			int pos = ((w * j) + i) * 4;
			bool present = (img[pos + 3] != 0 /* not alpha transparent */) && (img[pos] == 0 /* probably black */);
			if (present)
				res.supported(i, j);
		}

	stbi_image_free(img);
	return { "", res };
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x1a8(%rbp)
movq %rdi, %rax
movq %rax, -0x1a0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x10(%rbp), %rdi
callq 0x33c0
movq %rax, -0x198(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3480
movq -0x198(%rbp), %rdi
movl %eax, %esi
leaq -0x1c(%rbp), %rdx
leaq -0x20(%rbp), %rcx
leaq -0x24(%rbp), %r8
movl $0x4, %r9d
callq 0x3e80
movq %rax, -0x18(%rbp)
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
leaq -0xb0(%rbp), %rdi
callq 0xbaf0
cmpq $0x0, -0x18(%rbp)
jne 0x4b99
movq -0x1a8(%rbp), %rdi
leaq 0x16efb(%rip), %rsi     # 0x1ba60
leaq -0xb0(%rbp), %rdx
callq 0xbcc0
jmp 0x4b73
movl $0x1, -0xc0(%rbp)
jmp 0x4e8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x4eab
cmpl $0x5a0, -0x1c(%rbp)     # imm = 0x5A0
jne 0x4baf
cmpl $0xa00, -0x20(%rbp)     # imm = 0xA00
je 0x4d7a
movl -0x1c(%rbp), %esi
leaq -0x160(%rbp), %rdi
callq 0xbed0
jmp 0x4bc0
leaq 0x16eb1(%rip), %rsi     # 0x1ba78
leaq -0x140(%rbp), %rdi
leaq -0x160(%rbp), %rdx
callq 0xbe80
jmp 0x4bdc
leaq 0x172a4(%rip), %rdx     # 0x1be87
leaq -0x120(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0xbd60
jmp 0x4bf8
movl -0x20(%rbp), %esi
leaq -0x180(%rbp), %rdi
callq 0xbed0
jmp 0x4c09
leaq -0x100(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq -0x180(%rbp), %rdx
callq 0xbdb0
jmp 0x4c25
leaq 0x16e66(%rip), %rdx     # 0x1ba92
leaq -0xe0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0xbd60
jmp 0x4c41
movq -0x1a8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0xbff0
jmp 0x4c5d
leaq -0xe0(%rbp), %rdi
callq 0x31b0
leaq -0x100(%rbp), %rdi
callq 0x31b0
leaq -0x180(%rbp), %rdi
callq 0x31b0
leaq -0x120(%rbp), %rdi
callq 0x31b0
leaq -0x140(%rbp), %rdi
callq 0x31b0
leaq -0x160(%rbp), %rdi
callq 0x31b0
movl $0x1, -0xc0(%rbp)
jmp 0x4e8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x4d69
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x4d5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x4d51
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x4d45
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
jmp 0x4d39
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x31b0
leaq -0x100(%rbp), %rdi
callq 0x31b0
leaq -0x180(%rbp), %rdi
callq 0x31b0
leaq -0x120(%rbp), %rdi
callq 0x31b0
leaq -0x140(%rbp), %rdi
callq 0x31b0
leaq -0x160(%rbp), %rdi
callq 0x31b0
jmp 0x4eab
movl $0x0, -0x184(%rbp)
movl -0x184(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x4e60
movl $0x0, -0x188(%rbp)
movl -0x188(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x4e4a
movl -0x1c(%rbp), %eax
imull -0x184(%rbp), %eax
addl -0x188(%rbp), %eax
shll $0x2, %eax
movl %eax, -0x18c(%rbp)
movq -0x18(%rbp), %rax
movl -0x18c(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x1a9(%rbp)
je 0x4e01
movq -0x18(%rbp), %rax
movslq -0x18c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
sete %al
movb %al, -0x1a9(%rbp)
movb -0x1a9(%rbp), %al
andb $0x1, %al
movb %al, -0x18d(%rbp)
testb $0x1, -0x18d(%rbp)
je 0x4e34
movl -0x188(%rbp), %esi
movl -0x184(%rbp), %edx
leaq -0xb0(%rbp), %rdi
callq 0xc050
jmp 0x4e32
jmp 0x4e34
jmp 0x4e36
movl -0x188(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x188(%rbp)
jmp 0x4d9d
jmp 0x4e4c
movl -0x184(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x184(%rbp)
jmp 0x4d84
movq -0x18(%rbp), %rdi
callq 0x3760
movq -0x1a8(%rbp), %rdi
leaq 0x16d73(%rip), %rsi     # 0x1bbea
leaq -0xb0(%rbp), %rdx
callq 0xc0c0
jmp 0x4e85
movl $0x1, -0xc0(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0xc160
movq -0x1a0(%rbp), %rax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
leaq -0xb0(%rbp), %rdi
callq 0xc160
movq -0xb8(%rbp), %rdi
callq 0x3570
nopw %cs:(%rax,%rax)