// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
leaq -0x3c(%rbp), %r15
andl $0x0, (%r15)
leaq -0x38(%rbp), %r13
andl $0x0, (%r13)
leaq -0x34(%rbp), %r8
andl $0x0, (%r8)
movq %rdi, %r14
movq (%rsi), %rdi
movl 0x8(%rsi), %esi
pushq $0x4
popq %r9
movq %r15, %rdx
movq %r13, %rcx
callq 0x3abd
movq %rax, %rbx
movl (%r15), %r12d
movl (%r13), %r15d
leaq -0x188(%rbp), %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x7df6
testq %rbx, %rbx
je 0x4bac
movl %r12d, %eax
xorl $0x5a0, %eax            # imm = 0x5A0
movl %r15d, %ecx
xorl $0xa00, %ecx            # imm = 0xA00
orl %eax, %ecx
je 0x4bc4
leaq -0x80(%rbp), %rdi
movl %r12d, %esi
callq 0x8052
leaq 0x7fa0(%rip), %rsi      # 0xca88
leaq -0xa0(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0x8024
leaq 0x8398(%rip), %rdx      # 0xce97
leaq -0xc0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x7f8a
leaq -0x60(%rbp), %rdi
movl %r15d, %esi
callq 0x8052
leaq -0xe0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x7fb3
leaq 0x7f66(%rip), %rdx      # 0xcaa2
leaq -0x100(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x7f8a
leaq -0x100(%rbp), %rsi
leaq -0x188(%rbp), %rdx
movq %r14, %rdi
callq 0x80b2
leaq -0x100(%rbp), %rdi
callq 0x30f0
leaq -0xe0(%rbp), %rdi
callq 0x30f0
leaq -0x60(%rbp), %rdi
callq 0x30f0
leaq -0xc0(%rbp), %rdi
callq 0x30f0
leaq -0xa0(%rbp), %rdi
callq 0x30f0
leaq -0x80(%rbp), %rdi
callq 0x30f0
jmp 0x4c3e
leaq 0x7ebd(%rip), %rsi      # 0xca70
leaq -0x188(%rbp), %rdx
movq %r14, %rdi
callq 0x7f48
jmp 0x4c3e
movq %r14, -0x30(%rbp)
movq %rbx, %r14
addq $0x3, %r14
xorl %r15d, %r15d
leaq -0x188(%rbp), %r12
cmpq $0xa00, %r15            # imm = 0xA00
je 0x4c1c
xorl %r13d, %r13d
cmpq $0x5a0, %r13            # imm = 0x5A0
je 0x4c10
cmpb $0x0, (%r14,%r13,4)
je 0x4c0b
cmpb $0x0, -0x3(%r14,%r13,4)
jne 0x4c0b
movq %r12, %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x80e8
incq %r13
jmp 0x4be5
incq %r15
addq $0x1680, %r14           # imm = 0x1680
jmp 0x4bd9
movq %rbx, %rdi
callq 0x3240
leaq 0x7fcf(%rip), %rsi      # 0xcbfa
leaq -0x188(%rbp), %rdx
movq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0x8112
leaq -0x188(%rbp), %rdi
callq 0x8154
movq %r14, %rax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
callq 0x30f0
jmp 0x4c73
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x30f0
jmp 0x4c84
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x30f0
jmp 0x4c92
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x30f0
jmp 0x4ca3
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x30f0
leaq -0x80(%rbp), %rdi
callq 0x30f0
jmp 0x4cc4
movq %rax, %rbx
jmp 0x4caf
jmp 0x4cc1
movq %rax, %rbx
leaq -0x188(%rbp), %rdi
callq 0x8154
movq %rbx, %rdi
callq 0x33f0