// File: /workspace/github_c_makefile_star2_O1/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 $0x1b8, %rsp            # imm = 0x1B8
movq %rdi, %rbx
xorl %eax, %eax
leaq -0xbc(%rbp), %r14
movl %eax, (%r14)
leaq -0xb8(%rbp), %r13
movl %eax, (%r13)
leaq -0xb4(%rbp), %rcx
movl %eax, (%rcx)
movq (%rsi), %rdx
movslq 0x8(%rsi), %rsi
leaq -0x1d8(%rbp), %rdi
movq $0x0, 0x10(%rdi)
movl %eax, 0x30(%rdi)
movq %rdx, 0xc8(%rdi)
movq %rdx, 0xb8(%rdi)
addq %rdx, %rsi
movq %rsi, 0xd0(%rdi)
movq %rsi, 0xc0(%rdi)
movq %r14, %rsi
movq %r13, %rdx
movl $0x4, %r8d
callq 0x26b5
movq %rax, %r12
movl (%r14), %r15d
movl (%r13), %r14d
leaq -0x1d8(%rbp), %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x8456
testq %r12, %r12
je 0x40cd
movl %r15d, %eax
xorl $0x5a0, %eax            # imm = 0x5A0
movl %r14d, %ecx
xorl $0xa00, %ecx            # imm = 0xA00
orl %eax, %ecx
je 0x40e8
movl %r15d, %r12d
negl %r12d
cmovsl %r15d, %r12d
movl $0x1, %r13d
cmpl $0xa, %r12d
jb 0x4169
movl $0x4, %r13d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r12d, %ecx
cmpl $0x63, %ecx
jbe 0x4160
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x4166
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x4169
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r13d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x408b
addl $-0x3, %r13d
jmp 0x4169
leaq 0x999c(%rip), %rsi      # 0xda70
leaq -0x1d8(%rbp), %rdx
movq %rbx, %rdi
callq 0x85da
jmp 0x447d
movq %r12, %rax
addq $0x3, %rax
xorl %ecx, %ecx
leaq (%rcx,%rcx,2), %rdx
xorl %esi, %esi
cmpb $0x0, (%rax,%rsi,4)
je 0x4127
cmpb $0x0, -0x3(%rax,%rsi,4)
jne 0x4127
movq -0x1c8(%rbp), %rdi
movq (%rdi,%rdx,8), %rdi
movb $0x1, (%rdi,%rsi)
movq -0x168(%rbp), %rdi
incl (%rdi,%rcx,4)
movq -0x1b0(%rbp), %rdi
incl (%rdi,%rcx,4)
incq %rsi
cmpq %rsi, %r15
jne 0x40f7
incq %rcx
addq $0x1680, %rax           # imm = 0x1680
cmpq %r14, %rcx
jne 0x40f1
movq %r12, %rdi
callq 0x2260
leaq 0x9aae(%rip), %rsi      # 0xdbfa
leaq -0x1d8(%rbp), %rdx
movq %rbx, %rdi
callq 0x86b4
jmp 0x447d
addl $-0x2, %r13d
jmp 0x4169
decl %r13d
movq %rbx, -0x30(%rbp)
shrl $0x1f, %r15d
leal (%r15,%r13), %esi
leaq -0xd0(%rbp), %rax
movq %rax, -0x10(%rax)
leaq -0xe0(%rbp), %rdi
movl $0x2d, %edx
callq 0x2240
leaq -0xe0(%rbp), %rbx
addq (%rbx), %r15
movq %r15, %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x9ef4
leaq 0x98d8(%rip), %rcx      # 0xda88
movl $0x19, %r8d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2220
leaq -0xa0(%rbp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x41ef
movq %rdx, -0xb0(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xa0(%rbp)
jmp 0x41f5
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq -0xb0(%rbp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x9c7d(%rip), %rsi      # 0xde97
callq 0x23e0
leaq -0x80(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4246
movq %rdx, -0x90(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x80(%rbp)
jmp 0x424c
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
movq %rdx, -0x88(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl %r14d, %r15d
negl %r15d
cmovsl %r14d, %r15d
movl $0x1, %r12d
cmpl $0xa, %r15d
jb 0x42c6
movl $0x4, %r12d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r15d, %ecx
cmpl $0x63, %ecx
jbe 0x42bd
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x42c3
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x42c6
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r12d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x428a
addl $-0x3, %r12d
jmp 0x42c6
addl $-0x2, %r12d
jmp 0x42c6
decl %r12d
shrl $0x1f, %r14d
leal (%r12,%r14), %esi
leaq -0x60(%rbp), %r13
movq %r13, -0x10(%r13)
leaq -0x70(%rbp), %rdi
movl $0x2d, %edx
callq 0x2240
addq -0x70(%rbp), %r14
movq %r14, %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x9ef4
movq -0x90(%rbp), %rcx
movq -0x88(%rbp), %r8
movq -0x68(%rbp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %esi
cmpq %rbx, %rcx
je 0x431a
movq -0x80(%rbp), %rsi
cmpq %rsi, %rax
jbe 0x4333
movl $0xf, %esi
cmpq %r13, -0x70(%rbp)
je 0x432e
movq -0x60(%rbp), %rsi
cmpq %rsi, %rax
jbe 0x4345
movq -0x70(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x20c0
jmp 0x4352
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2220
leaq -0x40(%rbp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
je 0x4373
movq %rsi, -0x50(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x40(%rbp)
jmp 0x4379
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, -0x48(%rbp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x9706(%rip), %rsi      # 0xdaa2
leaq -0x50(%rbp), %rdi
callq 0x23e0
leaq -0xf0(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x43d2
movq %rdx, -0x100(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xf0(%rbp)
jmp 0x43d9
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq -0x100(%rbp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x1d8(%rbp), %rdx
movq -0x30(%rbp), %rdi
callq 0x863a
movq -0x100(%rbp), %rdi
cmpq %r15, %rdi
je 0x4418
callq 0x21d0
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x442a
callq 0x21d0
movq -0x70(%rbp), %rdi
cmpq %r13, %rdi
je 0x4438
callq 0x21d0
movq -0x90(%rbp), %rdi
cmpq %rbx, %rdi
je 0x4449
callq 0x21d0
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
movq -0x30(%rbp), %rbx
je 0x4465
callq 0x21d0
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x447d
callq 0x21d0
movq -0x168(%rbp), %rdi
testq %rdi, %rdi
je 0x448e
callq 0x21d0
movq -0x180(%rbp), %rdi
testq %rdi, %rdi
je 0x449f
callq 0x21d0
movq -0x198(%rbp), %rdi
testq %rdi, %rdi
je 0x44b0
callq 0x21d0
movq -0x1b0(%rbp), %rdi
testq %rdi, %rdi
je 0x44c1
callq 0x21d0
leaq -0x1c8(%rbp), %rdi
callq 0x96fa
movq %rbx, %rax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq -0x100(%rbp), %rdi
cmpq %r15, %rdi
je 0x44fb
callq 0x21d0
jmp 0x44fb
movq %rax, %r14
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4512
callq 0x21d0
jmp 0x4512
movq %rax, %r14
movq -0x70(%rbp), %rdi
cmpq %r13, %rdi
je 0x4525
callq 0x21d0
jmp 0x4525
movq %rax, %r14
movq -0x90(%rbp), %rdi
cmpq %rbx, %rdi
je 0x453b
callq 0x21d0
jmp 0x453b
movq %rax, %r14
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x4558
callq 0x21d0
jmp 0x4558
movq %rax, %r14
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x4577
callq 0x21d0
jmp 0x4577
jmp 0x4574
movq %rax, %r14
leaq -0x1d8(%rbp), %rdi
callq 0x8714
movq %r14, %rdi
callq 0x23b0