// File: /workspace/github_cpp_makefile_star2_O1/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)
pxor %xmm0, %xmm0
movdqu %xmm0, 0x48(%rdi)
movdqu %xmm0, 0x58(%rdi)
movl $0x2, 0x68(%rdi)
movq $0x0, 0x70(%rdi)
leaq 0x85e0(%rip), %rsi      # 0xb7a4
movq %r15, %rdi
callq 0x2230
testq %rax, %rax
je 0x33d8
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %rax, %rdx
callq 0x2330
testq %rax, %rax
je 0x33be
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), %r13
leaq 0x18(%r14), %rbp
leaq 0x30(%rsp), %r12
movq $0x0, (%rsp)
movq %r13, 0x8(%rsp)
movq %r12, %rdi
leaq 0x81d5(%rip), %rsi      # 0xb414
movq %r15, %rdx
xorl %eax, %eax
callq 0x21e0
cmpl $0x1, %eax
jne 0x3268
movslq 0x60(%r14), %rdi
movl %edi, 0x64(%r14)
shlq $0x4, %rdi
callq 0x2270
movq %rax, 0x58(%r14)
jmp 0x33a5
subq $0x8, %rsp
movq %r12, %rdi
leaq 0x81a8(%rip), %rsi      # 0xb41e
movq %r14, %rdx
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r9
xorl %eax, %eax
pushq %rbp
pushq %r13
pushq 0x28(%rsp)
callq 0x21e0
addq $0x20, %rsp
cmpl $0x7, %eax
jne 0x32d3
movl $0x0, 0x1c(%r14)
movl $0x3f800000, 0x3c(%r14) # imm = 0x3F800000
movss (%r14), %xmm0
movss %xmm0, 0x20(%r14)
movq 0x4(%r14), %rax
movq %rax, 0x24(%r14)
movdqu 0xc(%r14), %xmm0
movdqu %xmm0, 0x2c(%r14)
jmp 0x33a5
movq 0x30(%rsp), %rax
movabsq $0x6373612041544144, %rcx # imm = 0x6373612041544144
xorq %rcx, %rax
movzwl 0x38(%rsp), %ecx
xorq $0x6969, %rcx           # imm = 0x6969
orq %rax, %rcx
je 0x339d
movdqu 0x37(%rsp), %xmm0
pcmpeqb 0x8078(%rip), %xmm0     # 0xb380
movdqa 0x30(%rsp), %xmm1
pcmpeqb 0x807a(%rip), %xmm1     # 0xb390
pand %xmm0, %xmm1
pmovmskb %xmm1, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x33fa
cmpl $0x0, 0x68(%r14)
jne 0x33a5
movq 0x58(%r14), %rax
movq (%rsp), %r13
leal (,%r13,4), %ecx
movslq %ecx, %rcx
leaq (%rax,%rcx,4), %rdx
leal 0x1(,%r13,4), %ecx
movslq %ecx, %rcx
leaq (%rax,%rcx,4), %rcx
leal 0x2(,%r13,4), %esi
movslq %esi, %rsi
leaq (%rax,%rsi,4), %r8
leal 0x3(,%r13,4), %esi
movslq %esi, %rsi
leaq (%rax,%rsi,4), %r9
movq %r12, %rdi
leaq 0x80b3(%rip), %rsi      # 0xb431
xorl %eax, %eax
callq 0x21e0
xorl %ecx, %ecx
cmpl $0x3, %eax
setge %cl
addl %r13d, %ecx
movq 0x8(%rsp), %r13
movl %ecx, %eax
movq %rax, (%rsp)
jmp 0x33a5
movl $0x0, 0x68(%r14)
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdx
callq 0x2330
testq %rax, %rax
jne 0x3235
movq %rbx, %rdi
callq 0x21f0
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8021(%rip), %rdi      # 0xb400
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
movl $0x4, %esi
movq %rbx, %rcx
callq 0x22c0
jmp 0x33be
nop