// File: /workspace/github_c_makefile_star2_O3/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 0x272c
movq %rax, %r12
movl (%r14), %r15d
movl (%r13), %r14d
leaq -0x1d8(%rbp), %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x81ec
testq %r12, %r12
je 0x4221
movl %r15d, %eax
xorl $0x5a0, %eax            # imm = 0x5A0
movl %r14d, %ecx
xorl $0xa00, %ecx            # imm = 0xA00
orl %eax, %ecx
je 0x423c
movl %r15d, %r12d
negl %r12d
cmovsl %r15d, %r12d
movl $0x1, %r13d
cmpl $0xa, %r12d
jb 0x42c1
movl $0x4, %r13d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r12d, %ecx
cmpl $0x63, %ecx
jbe 0x42b8
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x42be
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x42c1
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r13d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x41df
addl $-0x3, %r13d
jmp 0x42c1
leaq 0x9848(%rip), %rsi      # 0xda70
leaq -0x1d8(%rbp), %rdx
movq %rbx, %rdi
callq 0x8370
jmp 0x45d4
xorl %eax, %eax
movq %r12, %rcx
leaq (%rax,%rax,2), %rdx
xorl %esi, %esi
cmpb $0x0, 0x3(%rcx,%rsi,4)
je 0x4277
cmpb $0x0, (%rcx,%rsi,4)
jne 0x4277
movq -0x1c8(%rbp), %rdi
movq (%rdi,%rdx,8), %rdi
movb $0x1, (%rdi,%rsi)
movq -0x168(%rbp), %rdi
incl (%rdi,%rax,4)
movq -0x1b0(%rbp), %rdi
incl (%rdi,%rax,4)
incq %rsi
cmpq $0x5a0, %rsi            # imm = 0x5A0
jne 0x4247
incq %rax
addq $0x1680, %rcx           # imm = 0x1680
cmpq $0xa00, %rax            # imm = 0xA00
jne 0x4241
movq %r12, %rdi
callq 0x2260
leaq 0x9956(%rip), %rsi      # 0xdbfa
leaq -0x1d8(%rbp), %rdx
movq %rbx, %rdi
callq 0x844a
jmp 0x45d4
addl $-0x2, %r13d
jmp 0x42c1
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 0x9c92
leaq 0x9780(%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 0x4347
movq %rdx, -0xb0(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xa0(%rbp)
jmp 0x434d
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 0x9b25(%rip), %rsi      # 0xde97
callq 0x23e0
leaq -0x60(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x439b
movq %rdx, -0x70(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x60(%rbp)
jmp 0x43a1
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
movq %rdx, -0x68(%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 0x4418
movl $0x4, %r12d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r15d, %ecx
cmpl $0x63, %ecx
jbe 0x440f
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x4415
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x4418
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r12d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x43dc
addl $-0x3, %r12d
jmp 0x4418
addl $-0x2, %r12d
jmp 0x4418
decl %r12d
shrl $0x1f, %r14d
leal (%r12,%r14), %esi
leaq -0x80(%rbp), %r13
movq %r13, -0x10(%r13)
leaq -0x90(%rbp), %rdi
movl $0x2d, %edx
callq 0x2240
addq -0x90(%rbp), %r14
movq %r14, %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x9c92
movq -0x70(%rbp), %rcx
movq -0x68(%rbp), %r8
movq -0x88(%rbp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %edi
cmpq %rbx, %rcx
je 0x446f
movq -0x60(%rbp), %rdi
movq -0x90(%rbp), %rsi
cmpq %rdi, %rax
jbe 0x448e
movl $0xf, %edi
cmpq %r13, %rsi
je 0x4489
movq -0x80(%rbp), %rdi
cmpq %rdi, %rax
jbe 0x4499
leaq -0x70(%rbp), %rdi
callq 0x20c0
jmp 0x44a9
leaq -0x90(%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 0x44ca
movq %rsi, -0x50(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x40(%rbp)
jmp 0x44d0
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 0x95af(%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 0x4529
movq %rdx, -0x100(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xf0(%rbp)
jmp 0x4530
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 0x83d0
movq -0x100(%rbp), %rdi
cmpq %r15, %rdi
je 0x456f
callq 0x21d0
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4581
callq 0x21d0
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
je 0x4592
callq 0x21d0
movq -0x70(%rbp), %rdi
cmpq %rbx, %rdi
je 0x45a0
callq 0x21d0
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
movq -0x30(%rbp), %rbx
je 0x45bc
callq 0x21d0
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x45d4
callq 0x21d0
movq -0x168(%rbp), %rdi
testq %rdi, %rdi
je 0x45e5
callq 0x21d0
movq -0x180(%rbp), %rdi
testq %rdi, %rdi
je 0x45f6
callq 0x21d0
movq -0x198(%rbp), %rdi
testq %rdi, %rdi
je 0x4607
callq 0x21d0
movq -0x1b0(%rbp), %rdi
testq %rdi, %rdi
je 0x4618
callq 0x21d0
leaq -0x1c8(%rbp), %rdi
callq 0x949c
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 0x4652
callq 0x21d0
jmp 0x4652
movq %rax, %r14
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4669
callq 0x21d0
jmp 0x4669
movq %rax, %r14
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
je 0x467f
callq 0x21d0
jmp 0x467f
movq %rax, %r14
movq -0x70(%rbp), %rdi
cmpq %rbx, %rdi
je 0x4692
callq 0x21d0
jmp 0x4692
movq %rax, %r14
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x46af
callq 0x21d0
jmp 0x46af
movq %rax, %r14
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x46ce
callq 0x21d0
jmp 0x46ce
jmp 0x46cb
movq %rax, %r14
leaq -0x1d8(%rbp), %rdi
callq 0x84aa
movq %r14, %rdi
callq 0x23b0