// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
leaq 0x6775(%rip), %rsi      # 0xa81c
callq 0x2240
testq %rax, %rax
je 0x412d
movq %rax, %rbx
movq %r15, 0x18(%rsp)
leaq 0x20(%rsp), %r15
leaq 0x8(%rsp), %r13
leaq 0x6749(%rip), %rbp      # 0xa813
pushq $0xa
popq %r12
movq %r15, %rdi
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdx
callq 0x2340
testq %rax, %rax
je 0x4240
movq %r15, %rdi
leaq 0x6710(%rip), %rsi      # 0xa801
movq %r13, %rdx
xorl %eax, %eax
callq 0x21e0
cmpl $0x1, %eax
je 0x4114
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x2220
testl %eax, %eax
jne 0x40ce
jmp 0x4146
pushq $0x78
popq %rdi
callq 0x2200
movq %rax, %r14
movl 0x8(%rsp), %esi
movq %rax, %rdi
callq 0x3330
jmp 0x40ce
leaq 0x6344(%rip), %rdi      # 0xa478
xorl %r14d, %r14d
movq %r15, %rsi
xorl %eax, %eax
callq 0x2050
jmp 0x4248
leaq 0x20(%rsp), %r13
leaq 0x14(%rsp), %r15
xorl %ebp, %ebp
xorl %r12d, %r12d
movslq 0x8(%rsp), %rax
cmpq %rax, %r12
jge 0x4240
movq %r13, %rdi
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdx
callq 0x2340
movq 0x58(%r14), %rax
leaq (%rax,%rbp), %rdx
leaq (%rax,%rbp), %rcx
addq $0x4, %rcx
leaq 0x8(%rax,%rbp), %r8
movq %r13, %rdi
leaq 0x668c(%rip), %rsi      # 0xa81e
movq %r15, %r9
xorl %eax, %eax
leaq 0xc(%rsp), %r10
pushq %r10
leaq 0x18(%rsp), %r10
pushq %r10
callq 0x21e0
popq %rcx
popq %rdx
cmpl $0x6, %eax
jne 0x41cb
movl 0x14(%rsp), %eax
shll $0x10, %eax
movl 0x10(%rsp), %ecx
shll $0x8, %ecx
orl %eax, %ecx
orl 0xc(%rsp), %ecx
cvtsi2ss %ecx, %xmm0
jmp 0x4201
movq 0x58(%r14), %rax
leaq (%rax,%rbp), %rdx
leaq (%rax,%rbp), %rcx
addq $0x4, %rcx
leaq (%rax,%rbp), %r8
addq $0x8, %r8
movq %r13, %rdi
leaq 0x62bf(%rip), %rsi      # 0xa4ac
xorl %eax, %eax
callq 0x21e0
movss 0x6268(%rip), %xmm0     # 0xa464
cmpl $0x3, %eax
jne 0x4217
movq 0x58(%r14), %rax
movss %xmm0, 0xc(%rax,%rbp)
incq %r12
addq $0x10, %rbp
jmp 0x4155
leaq 0x6612(%rip), %rdi      # 0xa830
movq 0x18(%rsp), %rsi
xorl %eax, %eax
callq 0x2050
leaq 0x6611(%rip), %rdi      # 0xa842
leaq 0x20(%rsp), %rdx
movl %r12d, %esi
xorl %eax, %eax
callq 0x2050
movq %rbx, %rdi
callq 0x21f0
movq %r14, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop