// File: 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
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq 0xde02(%rip), %rsi      # 0x1378c
callq 0x2230
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x59b9
movq -0x10(%rbp), %rsi
leaq 0xda0b(%rip), %rdi      # 0x133b0
movb $0x0, %al
callq 0x2050
movq $0x0, -0x8(%rbp)
jmp 0x5c9f
jmp 0x59bb
leaq -0x120(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl $0x100, %esi            # imm = 0x100
callq 0x2300
cmpq $0x0, %rax
je 0x5c8b
leaq -0x120(%rbp), %rdi
leaq 0xdd89(%rip), %rsi      # 0x13771
leaq -0x124(%rbp), %rdx
movb $0x0, %al
callq 0x21e0
cmpl $0x1, %eax
jne 0x5a5a
movl $0x78, %edi
callq 0x2200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x158(%rbp)
movl -0x124(%rbp), %esi
callq 0x41e0
jmp 0x5a1f
movq -0x158(%rbp), %rax
movq %rax, -0x130(%rbp)
jmp 0x5c86
movq -0x158(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
movl $0x78, %esi
callq 0x2210
jmp 0x5cac
leaq -0x120(%rbp), %rdi
leaq 0xdd1b(%rip), %rsi      # 0x13783
movl $0xa, %edx
callq 0x20d0
cmpl $0x0, %eax
jne 0x5c84
movl $0x0, -0x150(%rbp)
movl -0x150(%rbp), %eax
cmpl -0x124(%rbp), %eax
jge 0x5c82
leaq -0x120(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl $0x100, %esi            # imm = 0x100
callq 0x2300
leaq -0x120(%rbp), %rdi
movq -0x130(%rbp), %rax
movq 0x58(%rax), %rdx
movl -0x150(%rbp), %eax
shll $0x2, %eax
cltq
shlq $0x2, %rax
addq %rax, %rdx
movq -0x130(%rbp), %rax
movq 0x58(%rax), %rcx
movl -0x150(%rbp), %eax
shll $0x2, %eax
cltq
shlq $0x2, %rax
addq %rax, %rcx
addq $0x4, %rcx
movq -0x130(%rbp), %rax
movq 0x58(%rax), %r8
movl -0x150(%rbp), %eax
shll $0x2, %eax
cltq
shlq $0x2, %rax
addq %rax, %r8
addq $0x8, %r8
leaq 0xdc75(%rip), %rsi      # 0x1378e
leaq -0x134(%rbp), %r9
leaq -0x138(%rbp), %r10
leaq -0x13c(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x21e0
cmpl $0x6, %eax
jne 0x5b8f
movl -0x134(%rbp), %eax
shll $0x10, %eax
movl -0x138(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
orl -0x13c(%rbp), %eax
movl %eax, -0x140(%rbp)
cvtsi2ssl -0x140(%rbp), %xmm0
movq -0x130(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x150(%rbp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
jmp 0x5c6c
leaq -0x120(%rbp), %rdi
movq -0x130(%rbp), %rax
movq 0x58(%rax), %rdx
movl -0x150(%rbp), %eax
shll $0x2, %eax
cltq
shlq $0x2, %rax
addq %rax, %rdx
movq -0x130(%rbp), %rax
movq 0x58(%rax), %rcx
movl -0x150(%rbp), %eax
shll $0x2, %eax
cltq
shlq $0x2, %rax
addq %rax, %rcx
addq $0x4, %rcx
movq -0x130(%rbp), %rax
movq 0x58(%rax), %r8
movl -0x150(%rbp), %eax
shll $0x2, %eax
cltq
shlq $0x2, %rax
addq %rax, %r8
addq $0x8, %r8
leaq 0xd7e8(%rip), %rsi      # 0x133e4
movb $0x0, %al
callq 0x21e0
cmpl $0x3, %eax
jne 0x5c3b
movl $0xff, -0x140(%rbp)
cvtsi2ssl -0x140(%rbp), %xmm0
movq -0x130(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x150(%rbp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
jmp 0x5c6a
movq -0x10(%rbp), %rsi
leaq 0xdb5a(%rip), %rdi      # 0x137a0
movb $0x0, %al
callq 0x2050
movl -0x150(%rbp), %esi
leaq -0x120(%rbp), %rdx
leaq 0xdb51(%rip), %rdi      # 0x137b2
movb $0x0, %al
callq 0x2050
jmp 0x5c82
jmp 0x5c6c
jmp 0x5c6e
movl -0x150(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x150(%rbp)
jmp 0x5a85
jmp 0x5c8b
jmp 0x5c86
jmp 0x59bb
movq -0x18(%rbp), %rdi
callq 0x21f0
movq -0x130(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x148(%rbp), %rdi
callq 0x2380
nopl (%rax,%rax)