// File: /workspace/github_cpp_makefile_star2_O2/jingdao[P]PointCloudApp/pcd.cpp
// Function: PCD::PCD(char const*)
PCD::PCD(const char* fileName) {
	numFields = 4;
	data = NULL;
	float_data = NULL;
	fields = NULL;
	numPoints = 0;
	capacity = 0;
	data_storage = NONE;
	kdtree = NULL;
	FILE* f = fopen(fileName, "r");
	if (!f) {
		printf("File not found: %s\n", fileName);
		return;
	}
	char buf[256];
	int pointsParsed = 0;
	while (fgets(buf, 256, f)) {
		if (sscanf(buf, "POINTS %d", &numPoints) == 1) {
			capacity = numPoints;
			float_data = (float*)malloc(4 * numPoints * sizeof(float));
		}
		else if (sscanf(buf, "VIEWPOINT %f %f %f %f %f %f %f", &viewpoint[0], &viewpoint[1], &viewpoint[2],
			&viewpoint[3], &viewpoint[4], &viewpoint[5], &viewpoint[6]) == 7) {
			camera.position.r = 0;
			camera.focal_length = DEFAULT_FOCAL_LENGTH;
			camera.position.i = (float)viewpoint[0];
			camera.position.j = (float)viewpoint[1];
			camera.position.k = (float)viewpoint[2];
			camera.rotation.r = (float)viewpoint[3];
			camera.rotation.i = (float)viewpoint[4];
			camera.rotation.j = (float)viewpoint[5];
			camera.rotation.k = (float)viewpoint[6];
		} else if (strncmp(buf,"DATA ascii",10)==0) {
			data_storage = ASCII;
		} else if (strncmp(buf,"DATA binary_compressed",23)==0) {
			data_storage = BINARY;
			fread(float_data,sizeof(float),numPoints*4,f);
			break;
		}
		else if (data_storage == ASCII) {
			if (sscanf(buf, "%f %f %f %f", &float_data[pointsParsed * 4], &float_data[pointsParsed * 4 + 1],
				&float_data[pointsParsed * 4 + 2], &float_data[pointsParsed * 4 + 3]) >= 3) {
				pointsParsed++;
			}
		}
	}
	fclose(f);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rsi, %r15
movq %rdi, %r14
movl $0x4, 0x40(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rdi)
movups %xmm0, 0x58(%rdi)
movl $0x2, 0x68(%rdi)
andq $0x0, 0x70(%rdi)
leaq 0x76ea(%rip), %rsi      # 0xa81c
movq %r15, %rdi
callq 0x2240
testq %rax, %rax
je 0x32d4
movq %rax, %rbx
leaq 0x60(%r14), %r15
leaq 0x4(%r14), %rax
movq %rax, 0x28(%rsp)
leaq 0x8(%r14), %rax
movq %rax, 0x20(%rsp)
leaq 0xc(%r14), %rax
movq %rax, 0x18(%rsp)
leaq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
leaq 0x14(%r14), %rax
movq %rax, 0x8(%rsp)
leaq 0x18(%r14), %rbp
leaq 0x30(%rsp), %r12
leaq 0x7305(%rip), %r13      # 0xa48c
movq $0x0, (%rsp)
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdx
callq 0x2340
testq %rax, %rax
je 0x3315
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x21e0
cmpl $0x1, %eax
jne 0x31d4
movslq 0x60(%r14), %rdi
movl %edi, 0x64(%r14)
shlq $0x4, %rdi
callq 0x2280
movq %rax, 0x58(%r14)
jmp 0x318f
subq $0x8, %rsp
movq %r12, %rdi
leaq 0x72b4(%rip), %rsi      # 0xa496
movq %r14, %rdx
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r9
xorl %eax, %eax
pushq %rbp
pushq 0x18(%rsp)
pushq 0x28(%rsp)
callq 0x21e0
addq $0x20, %rsp
cmpl $0x7, %eax
jne 0x3240
andl $0x0, 0x1c(%r14)
movl $0x3f800000, 0x3c(%r14) # imm = 0x3F800000
movups (%r14), %xmm0
movups %xmm0, 0x20(%r14)
movsd 0x10(%r14), %xmm0
movsd %xmm0, 0x30(%r14)
movss 0x18(%r14), %xmm0
movss %xmm0, 0x38(%r14)
jmp 0x318f
movq %r12, %rdi
leaq 0x726b(%rip), %rsi      # 0xa4b5
pushq $0xa
popq %rdx
callq 0x2220
testl %eax, %eax
je 0x32ca
movq %r12, %rdi
leaq 0x7260(%rip), %rsi      # 0xa4c0
pushq $0x17
popq %rdx
callq 0x2220
testl %eax, %eax
je 0x32f6
cmpl $0x0, 0x68(%r14)
jne 0x318f
movq 0x58(%r14), %rax
movq (%rsp), %rcx
leal (,%rcx,4), %esi
leaq (%rax,%rsi,4), %rdx
leaq (%rax,%rsi,4), %rcx
addq $0x4, %rcx
leaq 0x8(%rax,%rsi,4), %r8
leaq (%rax,%rsi,4), %r9
addq $0xc, %r9
movq %r12, %rdi
leaq 0x71fc(%rip), %rsi      # 0xa4a9
xorl %eax, %eax
callq 0x21e0
xorl %ecx, %ecx
cmpl $0x3, %eax
setge %cl
addl (%rsp), %ecx
movl %ecx, %eax
movq %rax, (%rsp)
jmp 0x318f
andl $0x0, 0x68(%r14)
jmp 0x318f
leaq 0x719d(%rip), %rdi      # 0xa478
movq %r15, %rsi
xorl %eax, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2050
movl $0x1, 0x68(%r14)
movq 0x58(%r14), %rdi
movslq 0x60(%r14), %rdx
shlq $0x2, %rdx
pushq $0x4
popq %rsi
movq %rbx, %rcx
callq 0x22d0
movq %rbx, %rdi
callq 0x21f0
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop