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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, %rbx
leaq 0x6073(%rip), %rsi      # 0xb7a4
callq 0x2230
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x58ea
movq %rbx, 0x30(%rsp)
movl $0x78, %edi
callq 0x2200
movq %rax, %r14
movl $0x4, 0x40(%rax)
xorl %ebx, %ebx
movq %rbx, 0x50(%rax)
xorl %edi, %edi
callq 0x2270
movq %rax, 0x58(%r14)
movq %rbx, 0x48(%r14)
movq %rbx, 0x60(%r14)
movl $0x0, 0x68(%r14)
movq %rbx, 0x70(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x1c(%r14)
movl $0x3f800000, 0x2c(%r14) # imm = 0x3F800000
movq %rbx, 0x30(%r14)
movabsq $0x3f80000000000000, %rax # imm = 0x3F80000000000000
movq %rax, 0x38(%r14)
leaq 0x40(%rsp), %r12
xorl %r15d, %r15d
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
movq 0x10(%rsp), %rdx
callq 0x2330
testq %rax, %rax
je 0x58de
movq %r12, %rdi
callq 0x2320
movl %eax, %ebx
leal (%rbx,%r15), %esi
movq %r14, %rdi
callq 0x34de
movl %eax, %edx
xorb $0x1, %dl
testl %ebx, %ebx
setle %cl
orb %dl, %cl
jne 0x58d6
movb %al, 0xf(%rsp)
movq %r15, 0x28(%rsp)
movslq %r15d, %r13
shlq $0x4, %r13
orq $0x8, %r13
negl %ebx
xorl %ebp, %ebp
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
movq 0x10(%rsp), %rdx
callq 0x2330
movq 0x58(%r14), %r15
leaq (%r15,%r13), %r8
leaq (%r15,%r13), %rdx
addq $-0x8, %rdx
leaq (%r15,%r13), %rcx
addq $-0x4, %rcx
subq $0x8, %rsp
movq %r12, %rdi
leaq 0x5ffb(%rip), %rsi      # 0xb83a
leaq 0x44(%rsp), %r9
xorl %eax, %eax
leaq 0x24(%rsp), %r10
pushq %r10
leaq 0x30(%rsp), %r10
pushq %r10
leaq 0x3c(%rsp), %r10
pushq %r10
callq 0x21e0
addq $0x20, %rsp
cmpl $0x7, %eax
jne 0x58a3
movl 0x24(%rsp), %eax
shll $0x10, %eax
movl 0x20(%rsp), %ecx
shll $0x8, %ecx
orl %eax, %ecx
orl 0x1c(%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
movss %xmm0, 0x4(%r15,%r13)
decl %ebp
addq $0x10, %r13
cmpl %ebp, %ebx
jne 0x5807
movq 0x28(%rsp), %r15
subl %ebp, %r15d
jmp 0x58d2
movq 0x28(%rsp), %r15
subl %ebp, %r15d
leaq 0x5f06(%rip), %rdi      # 0xb7b8
movq 0x30(%rsp), %rsi
xorl %eax, %eax
callq 0x2050
leaq 0x5f05(%rip), %rdi      # 0xb7ca
movl %r15d, %esi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2050
movb 0xf(%rsp), %al
testb %al, %al
jne 0x57ac
movq 0x10(%rsp), %rdi
callq 0x21f0
jmp 0x58fe
leaq 0x5b0f(%rip), %rdi      # 0xb400
xorl %r14d, %r14d
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2050
movq %r14, %rax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop