// File: mhe[P]raytracerframework_cpp/raytracer.cpp
// Function: Raytracer::readScene(char*)
bool Raytracer::readScene(char* inputFilename)
{
	// Initialize a new scene
	scene = new Scene();

	// Open file stream for reading and have the YAML module parse it
	std::ifstream fin(inputFilename);
	if (!fin) {
		cerr << "Error: unable to open " << inputFilename << " for reading." << endl;;
		return false;
	}
	try {
		YAML::Parser parser(fin);
		if (parser) {
	        YAML::Node doc;
	        parser.GetNextDocument(doc);
		
			// Read scene configuration options
			scene->setEye(parseTriple(doc["Eye"]));
		
			// Read and parse the scene objects
			const YAML::Node& sceneObjects = doc["Objects"];
			if (sceneObjects.GetType() != YAML::CT_SEQUENCE) {
				cerr << "Error: expected a sequence of objects." << endl;
				return false;
			}
			for(YAML::Iterator it=sceneObjects.begin();it!=sceneObjects.end();++it) {
				Object *obj = parseObject(*it);
				// Only add object if it is recognized
				if (obj) {
					scene->addObject(obj);
				} else {
					cerr << "Warning: found object of unknown type, ignored." << endl;
				}
			}
		
			// Read and parse light definitions
			const YAML::Node& sceneLights = doc["Lights"];
			if (sceneObjects.GetType() != YAML::CT_SEQUENCE) {
				cerr << "Error: expected a sequence of lights." << endl;
				return false;
			}
			for(YAML::Iterator it=sceneLights.begin();it!=sceneLights.end();++it) {
				scene->addLight(parseLight(*it));
			}
	    }
		if (parser) {
			cerr << "Warning: unexpected YAML document, ignored." << endl;
		}
	} catch(YAML::ParserException& e) {
	    std::cerr << "Error at line " << e.line + 1 << ", col " << e.column + 1 << ": " << e.msg << std::endl;
		return false;
	}

	cout << "YAML parsing results: " << scene->getNumObjects() << " objects read." << endl;
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x460, %rsp            # imm = 0x460
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x338(%rbp)
movl $0x398, %edi            # imm = 0x398
callq 0x53b0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x330(%rbp)
callq 0x219e0
jmp 0x20d5c
movq -0x338(%rbp), %rax
movq -0x330(%rbp), %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rsi
leaq -0x230(%rbp), %rdi
movl $0x8, %edx
callq 0x5700
movq -0x230(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x230(%rbp,%rax), %rdi
callq 0x51a0
movb %al, -0x339(%rbp)
jmp 0x20da2
movb -0x339(%rbp), %al
testb $0x1, %al
jne 0x20db1
jmp 0x20e5d
movq 0x47238(%rip), %rdi     # 0x67ff0
leaq 0x2a765(%rip), %rsi     # 0x4b524
callq 0x5390
movq %rax, -0x348(%rbp)
jmp 0x20dcd
movq -0x348(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x5390
movq %rax, -0x350(%rbp)
jmp 0x20de6
movq -0x350(%rbp), %rdi
leaq 0x2a747(%rip), %rsi     # 0x4b53b
callq 0x5390
movq %rax, -0x358(%rbp)
jmp 0x20e02
movq -0x358(%rbp), %rdi
movq 0x471a0(%rip), %rsi     # 0x67fb0
callq 0x53f0
jmp 0x20e17
movb $0x0, -0x1(%rbp)
movl $0x1, -0x234(%rbp)
jmp 0x21552
movq -0x330(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x398, %esi            # imm = 0x398
callq 0x53c0
jmp 0x21578
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x2156c
leaq -0x278(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x39430
jmp 0x20e72
leaq -0x278(%rbp), %rdi
callq 0x39580
movb %al, -0x359(%rbp)
jmp 0x20e86
movb -0x359(%rbp), %al
testb $0x1, %al
jne 0x20e95
jmp 0x2131e
leaq -0x2d0(%rbp), %rdi
callq 0x379f0
jmp 0x20ea3
leaq -0x278(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x395b0
jmp 0x20eb8
movq -0x338(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x370(%rbp)
leaq 0x2a679(%rip), %rsi     # 0x4b549
leaq -0x2d0(%rbp), %rdi
callq 0x217b0
movq %rax, -0x368(%rbp)
jmp 0x20ee5
movq -0x368(%rbp), %rsi
leaq -0x2e8(%rbp), %rdi
callq 0x20860
jmp 0x20efa
movq -0x370(%rbp), %rdi
movq -0x2d8(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x10(%rax)
movups -0x2e8(%rbp), %xmm0
movups %xmm0, (%rax)
callq 0x32bc0
jmp 0x20f20
leaq 0x2a626(%rip), %rsi     # 0x4b54d
leaq -0x2d0(%rbp), %rdi
callq 0x217b0
movq %rax, -0x378(%rbp)
jmp 0x20f3c
movq -0x378(%rbp), %rax
movq %rax, -0x2f0(%rbp)
movq -0x2f0(%rbp), %rdi
callq 0x386c0
movl %eax, -0x37c(%rbp)
jmp 0x20f5e
movl -0x37c(%rbp), %eax
cmpl $0x2, %eax
je 0x20fe0
movq 0x47080(%rip), %rdi     # 0x67ff0
leaq 0x2a5de(%rip), %rsi     # 0x4b555
callq 0x5390
movq %rax, -0x388(%rbp)
jmp 0x20f85
movq -0x388(%rbp), %rdi
movq 0x4701d(%rip), %rsi     # 0x67fb0
callq 0x53f0
jmp 0x20f9a
movb $0x0, -0x1(%rbp)
movl $0x1, -0x234(%rbp)
jmp 0x212f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x213a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x2139c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x21310
movq -0x2f0(%rbp), %rsi
leaq -0x2f8(%rbp), %rdi
callq 0x38750
jmp 0x20ff5
jmp 0x20ff7
movq -0x2f0(%rbp), %rsi
leaq -0x300(%rbp), %rdi
callq 0x38890
jmp 0x2100c
leaq -0x2f8(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0x348b0
movb %al, -0x389(%rbp)
jmp 0x21027
leaq -0x300(%rbp), %rdi
callq 0x344a0
movb -0x389(%rbp), %al
testb $0x1, %al
jne 0x21086
movl $0x2, -0x234(%rbp)
leaq -0x2f8(%rbp), %rdi
callq 0x344a0
jmp 0x21142
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x21131
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x300(%rbp), %rdi
callq 0x344a0
jmp 0x21131
leaq -0x2f8(%rbp), %rdi
callq 0x345d0
movq %rax, -0x398(%rbp)
jmp 0x2109b
movq -0x398(%rbp), %rsi
movq -0x338(%rbp), %rdi
callq 0x209f0
movq %rax, -0x3a0(%rbp)
jmp 0x210b7
movq -0x3a0(%rbp), %rax
movq %rax, -0x308(%rbp)
cmpq $0x0, -0x308(%rbp)
je 0x210e9
movq -0x338(%rbp), %rax
movq (%rax), %rdi
movq -0x308(%rbp), %rsi
callq 0x32b50
jmp 0x210e7
jmp 0x2111c
movq 0x46f00(%rip), %rdi     # 0x67ff0
leaq 0x2a485(%rip), %rsi     # 0x4b57c
callq 0x5390
movq %rax, -0x3a8(%rbp)
jmp 0x21105
movq -0x3a8(%rbp), %rdi
movq 0x46e9d(%rip), %rsi     # 0x67fb0
callq 0x53f0
jmp 0x2111a
jmp 0x2111c
jmp 0x2111e
leaq -0x2f8(%rbp), %rdi
callq 0x344e0
jmp 0x2112c
jmp 0x20ff7
leaq -0x2f8(%rbp), %rdi
callq 0x344a0
jmp 0x21310
leaq 0x2a463(%rip), %rsi     # 0x4b5ac
leaq -0x2d0(%rbp), %rdi
callq 0x217b0
movq %rax, -0x3b0(%rbp)
jmp 0x2115e
movq -0x3b0(%rbp), %rax
movq %rax, -0x310(%rbp)
movq -0x2f0(%rbp), %rdi
callq 0x386c0
movl %eax, -0x3b4(%rbp)
jmp 0x21180
movl -0x3b4(%rbp), %eax
cmpl $0x2, %eax
je 0x211cf
movq 0x46e5e(%rip), %rdi     # 0x67ff0
leaq 0x2a41a(%rip), %rsi     # 0x4b5b3
callq 0x5390
movq %rax, -0x3c0(%rbp)
jmp 0x211a7
movq -0x3c0(%rbp), %rdi
movq 0x46dfb(%rip), %rsi     # 0x67fb0
callq 0x53f0
jmp 0x211bc
movb $0x0, -0x1(%rbp)
movl $0x1, -0x234(%rbp)
jmp 0x212f6
movq -0x310(%rbp), %rsi
leaq -0x318(%rbp), %rdi
callq 0x38750
jmp 0x211e4
jmp 0x211e6
movq -0x310(%rbp), %rsi
leaq -0x320(%rbp), %rdi
callq 0x38890
jmp 0x211fb
leaq -0x318(%rbp), %rdi
leaq -0x320(%rbp), %rsi
callq 0x348b0
movb %al, -0x3c1(%rbp)
jmp 0x21216
leaq -0x320(%rbp), %rdi
callq 0x344a0
movb -0x3c1(%rbp), %al
testb $0x1, %al
jne 0x21272
movl $0x5, -0x234(%rbp)
leaq -0x318(%rbp), %rdi
callq 0x344a0
jmp 0x212ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x212de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x320(%rbp), %rdi
callq 0x344a0
jmp 0x212de
movq -0x338(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x3d8(%rbp)
leaq -0x318(%rbp), %rdi
callq 0x345d0
movq %rax, -0x3d0(%rbp)
jmp 0x21298
movq -0x3d0(%rbp), %rsi
movq -0x338(%rbp), %rdi
callq 0x20bf0
movq %rax, -0x3e0(%rbp)
jmp 0x212b4
movq -0x3e0(%rbp), %rsi
movq -0x3d8(%rbp), %rdi
callq 0x32b80
jmp 0x212c9
jmp 0x212cb
leaq -0x318(%rbp), %rdi
callq 0x344e0
jmp 0x212d9
jmp 0x211e6
leaq -0x318(%rbp), %rdi
callq 0x344a0
jmp 0x21310
movl $0x0, -0x234(%rbp)
leaq -0x2d0(%rbp), %rdi
callq 0x37a30
movl -0x234(%rbp), %eax
testl %eax, %eax
jne 0x2137b
jmp 0x2130e
jmp 0x2131e
leaq -0x2d0(%rbp), %rdi
callq 0x37a30
jmp 0x2139c
leaq -0x278(%rbp), %rdi
callq 0x39580
movb %al, -0x3e1(%rbp)
jmp 0x21332
movb -0x3e1(%rbp), %al
testb $0x1, %al
jne 0x2133e
jmp 0x21371
movq 0x46cab(%rip), %rdi     # 0x67ff0
leaq 0x2a28d(%rip), %rsi     # 0x4b5d9
callq 0x5390
movq %rax, -0x3f0(%rbp)
jmp 0x2135a
movq -0x3f0(%rbp), %rdi
movq 0x46c48(%rip), %rsi     # 0x67fb0
callq 0x53f0
jmp 0x2136f
jmp 0x21371
movl $0x0, -0x234(%rbp)
leaq -0x278(%rbp), %rdi
callq 0x39530
movl -0x234(%rbp), %eax
testl %eax, %eax
jne 0x21552
jmp 0x21397
jmp 0x214c5
leaq -0x278(%rbp), %rdi
callq 0x39530
movl -0x24(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2156c
movq -0x20(%rbp), %rdi
callq 0x5150
movq %rax, -0x328(%rbp)
movq 0x46c21(%rip), %rdi     # 0x67ff0
leaq 0x2a22f(%rip), %rsi     # 0x4b605
callq 0x5390
movq %rax, -0x3f8(%rbp)
jmp 0x213e4
movq -0x3f8(%rbp), %rdi
movq -0x328(%rbp), %rax
movl 0x8(%rax), %esi
incl %esi
callq 0x56a0
movq %rax, -0x400(%rbp)
jmp 0x21405
movq -0x400(%rbp), %rdi
leaq 0x2a201(%rip), %rsi     # 0x4b614
callq 0x5390
movq %rax, -0x408(%rbp)
jmp 0x21421
movq -0x408(%rbp), %rdi
movq -0x328(%rbp), %rax
movl 0xc(%rax), %esi
incl %esi
callq 0x56a0
movq %rax, -0x410(%rbp)
jmp 0x21442
movq -0x410(%rbp), %rdi
leaq 0x29da5(%rip), %rsi     # 0x4b1f5
callq 0x5390
movq %rax, -0x418(%rbp)
jmp 0x2145e
movq -0x418(%rbp), %rdi
movq -0x328(%rbp), %rsi
addq $0x10, %rsi
callq 0x5360
movq %rax, -0x420(%rbp)
jmp 0x2147e
movq -0x420(%rbp), %rdi
movq 0x46b24(%rip), %rsi     # 0x67fb0
callq 0x53f0
jmp 0x21493
movb $0x0, -0x1(%rbp)
movl $0x1, -0x234(%rbp)
callq 0x5640
jmp 0x214bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x5640
jmp 0x214c0
jmp 0x21552
jmp 0x2156c
movq 0x46b04(%rip), %rdi     # 0x67fd0
leaq 0x2a148(%rip), %rsi     # 0x4b61b
callq 0x5390
movq %rax, -0x428(%rbp)
jmp 0x214e1
movq -0x338(%rbp), %rax
movq (%rax), %rdi
callq 0x21a20
movl %eax, -0x42c(%rbp)
jmp 0x214f8
movl -0x42c(%rbp), %esi
movq -0x428(%rbp), %rdi
callq 0x5580
movq %rax, -0x438(%rbp)
jmp 0x21513
movq -0x438(%rbp), %rdi
leaq 0x2a111(%rip), %rsi     # 0x4b632
callq 0x5390
movq %rax, -0x440(%rbp)
jmp 0x2152f
movq -0x440(%rbp), %rdi
movq 0x46a73(%rip), %rsi     # 0x67fb0
callq 0x53f0
jmp 0x21544
movb $0x1, -0x1(%rbp)
movl $0x1, -0x234(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x5100
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x460, %rsp            # imm = 0x460
popq %rbp
retq
leaq -0x230(%rbp), %rdi
callq 0x5100
movq -0x20(%rbp), %rdi
callq 0x56c0
movq %rax, %rdi
callq 0x20780
nopl (%rax)