// File: /workspace/github_cpp_makefile_star2_O3/jingdao[P]PointCloudApp/pcd.cpp
// Function: PCD::LoadFromPLY(char const*)
PCD* PCD::LoadFromPLY(const char* fileName) {
	FILE* f = fopen(fileName, "r");
	if (!f) {
		printf("File not found: %s\n", fileName);
		return NULL;
	}
	char buf[256];
	int n;
	PCD* pcd;
	int r,g,b,rgb;
	while (fgets(buf, 256, f)) {
		if (sscanf(buf,"element vertex %d",&n)==1) {
			pcd = new PCD(n);
		} else if (strncmp(buf,"end_header",10)==0) {
			for (int i=0;i<n;i++) {
				fgets(buf,256,f);
				if (sscanf(buf, "%f %f %f %d %d %d", pcd->float_data + i * 4, pcd->float_data + i * 4 + 1,
					pcd->float_data + i * 4 + 2, &r, &g, &b) == 6) {
					rgb = (r<<16) | (g<<8) | b;
					pcd->float_data[i * 4 + 3] = (float) rgb;
				} else if (sscanf(buf, "%f %f %f", pcd->float_data + i * 4, pcd->float_data + i * 4 + 1,
					pcd->float_data + i * 4 + 2) == 3) {
					rgb = 255;
					pcd->float_data[i * 4 + 3] = (float) rgb;
				} else {
					printf("Error parsing %s\n",fileName);
					printf("Line %d: %s\n",i,buf);
					break;
				}
			}
			break;
		}
	}
	fclose(f);
	return pcd;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, %r14
leaq 0x75b9(%rip), %rsi      # 0xb874
callq 0x2230
testq %rax, %rax
je 0x43d7
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %rax, %rdx
callq 0x2330
testq %rax, %rax
je 0x43ed
movq %r14, 0x18(%rsp)
leaq 0x7566(%rip), %r12      # 0xb859
leaq 0x20(%rsp), %r14
leaq 0x8(%rsp), %rbp
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x21e0
cmpl $0x1, %eax
jne 0x4399
movl $0x78, %edi
callq 0x2200
movq %rax, %r15
movq %rbx, %r14
movq %rbp, %rbx
movq %r12, %rbp
movslq 0x8(%rsp), %r12
movl $0x4, 0x40(%rax)
xorl %r13d, %r13d
movq %r13, 0x50(%rax)
movq %r12, %rdi
shlq $0x4, %rdi
callq 0x2270
movq %rax, 0x58(%r15)
movq %r13, 0x48(%r15)
movl %r12d, 0x60(%r15)
movl %r12d, 0x64(%r15)
movq %rbp, %r12
movq %rbx, %rbp
movq %r14, %rbx
leaq 0x20(%rsp), %r14
movl $0x0, 0x68(%r15)
movq %r13, 0x70(%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x1c(%r15)
movl $0x3f800000, 0x2c(%r15) # imm = 0x3F800000
movq %r13, 0x30(%r15)
movabsq $0x3f80000000000000, %rax # imm = 0x3F80000000000000
movq %rax, 0x38(%r15)
jmp 0x43bc
movq 0x20(%rsp), %rax
movabsq $0x646165685f646e65, %rcx # imm = 0x646165685F646E65
xorq %rcx, %rax
movzwl 0x28(%rsp), %ecx
xorq $0x7265, %rcx           # imm = 0x7265
orq %rax, %rcx
je 0x440a
movq %r14, %rdi
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdx
callq 0x2330
testq %rax, %rax
jne 0x42fd
jmp 0x43ed
leaq 0x70f2(%rip), %rdi      # 0xb4d0
xorl %r15d, %r15d
movq %r14, %rsi
xorl %eax, %eax
callq 0x2050
jmp 0x43f5
movq %rbx, %rdi
callq 0x21f0
movq %r15, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0x8(%rsp)
jle 0x43ed
leaq 0x20(%rsp), %r13
leaq 0x14(%rsp), %rbp
xorl %r14d, %r14d
xorl %r12d, %r12d
movq %r13, %rdi
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdx
callq 0x2330
movq 0x58(%r15), %rax
leaq (%rax,%r14), %rdx
leaq (%rax,%r14), %rcx
addq $0x4, %rcx
leaq 0x8(%rax,%r14), %r8
movq %r13, %rdi
leaq 0x7426(%rip), %rsi      # 0xb876
movq %rbp, %r9
xorl %eax, %eax
leaq 0xc(%rsp), %r10
pushq %r10
leaq 0x18(%rsp), %r10
pushq %r10
callq 0x21e0
addq $0x10, %rsp
cmpl $0x6, %eax
jne 0x448e
movl 0x14(%rsp), %eax
shll $0x10, %eax
movl 0x10(%rsp), %ecx
shll $0x8, %ecx
orl %eax, %ecx
orl 0xc(%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
jmp 0x44c4
movq 0x58(%r15), %rax
leaq (%rax,%r14), %rdx
leaq (%rax,%r14), %rcx
addq $0x4, %rcx
leaq (%rax,%r14), %r8
addq $0x8, %r8
movq %r13, %rdi
leaq 0x7054(%rip), %rsi      # 0xb504
xorl %eax, %eax
callq 0x21e0
movss 0x6ff5(%rip), %xmm0     # 0xb4b4
cmpl $0x3, %eax
jne 0x44e9
movq 0x58(%r15), %rax
movss %xmm0, 0xc(%rax,%r14)
incq %r12
movslq 0x8(%rsp), %rax
addq $0x10, %r14
cmpq %rax, %r12
jl 0x4421
jmp 0x43ed
leaq 0x7398(%rip), %rdi      # 0xb888
movq 0x18(%rsp), %rsi
xorl %eax, %eax
callq 0x2050
leaq 0x7397(%rip), %rdi      # 0xb89a
leaq 0x20(%rsp), %rdx
movl %r12d, %esi
xorl %eax, %eax
callq 0x2050
jmp 0x43ed
nop