// File: /workspace/github_cpp_makefile_star2_O3/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 $0x138, %rsp            # imm = 0x138
movq %rdi, %rbx
leaq 0x6061(%rip), %rsi      # 0xb874
callq 0x2230
testq %rax, %rax
je 0x59f5
movq %rax, %r15
movq %rbx, 0x20(%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 0x30(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdx
callq 0x2330
testq %rax, %rax
je 0x59eb
leaq 0x30(%rsp), %r12
xorl %r13d, %r13d
movq %r14, (%rsp)
movq %r12, %rdi
callq 0x2320
movl %eax, %ebx
leal (%rbx,%r13), %esi
movq %r14, %rdi
callq 0x34e4
testb %al, %al
je 0x59eb
testl %ebx, %ebx
jle 0x59d2
movq %r13, 0x18(%rsp)
movslq %r13d, %r13
shlq $0x4, %r13
orq $0x8, %r13
negl %ebx
xorl %ebp, %ebp
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r15, %r14
movq %r15, %rdx
callq 0x2330
movq (%rsp), %rax
movq 0x58(%rax), %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 0x5fe3(%rip), %rsi      # 0xb90a
leaq 0x34(%rsp), %r9
xorl %eax, %eax
leaq 0x14(%rsp), %r10
pushq %r10
leaq 0x20(%rsp), %r10
pushq %r10
leaq 0x2c(%rsp), %r10
pushq %r10
callq 0x21e0
addq $0x20, %rsp
cmpl $0x7, %eax
jne 0x5997
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
movss %xmm0, 0x4(%r15,%r13)
decl %ebp
addq $0x10, %r13
cmpl %ebp, %ebx
movq %r14, %r15
jne 0x58e5
movq 0x18(%rsp), %r13
subl %ebp, %r13d
movq (%rsp), %r14
leaq 0x30(%rsp), %r12
jmp 0x59d2
movq 0x18(%rsp), %r13
subl %ebp, %r13d
leaq 0x5ee2(%rip), %rdi      # 0xb888
movq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x2050
leaq 0x5ee1(%rip), %rdi      # 0xb89a
movl %r13d, %esi
leaq 0x30(%rsp), %r12
movq %r12, %rdx
xorl %eax, %eax
callq 0x2050
movq %r14, %r15
movq (%rsp), %r14
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdx
callq 0x2330
testq %rax, %rax
jne 0x58ab
movq %r15, %rdi
callq 0x21f0
jmp 0x5a09
leaq 0x5ad4(%rip), %rdi      # 0xb4d0
xorl %r14d, %r14d
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2050
movq %r14, %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq