// File: hamikm[P]Raytracer/src/driver.cc
// Function: main
int main(int argc, char **argv) {

	if (argc != 4 && argc != 3) {
		usage(argv[0]);
		return 1;
	}
	int width = atoi(argv[1]);
	int height = atoi(argv[2]);
	bool shadowsOn = false;
	if(argc == 4) {
		stringstream ss;
		ss << argv[3];
		if(ss.str() == "-s") {
			shadowsOn = true;
		}
		else {
			usage(argv[0]);
			return 1;
		}
	}

	/* Make the string-readerFunction mappings. */
	readerFuncs["sphere"] = readSphere;
	readerFuncs["plane"] = readPlane;
	readerFuncs["cylinder"] = readCylinder;

	scene3d scene(shadowsOn);
	sp_camerad cam;
	string type;

	while (cin >> type) {

		// If the type is mapped to a shape reader function...
		if (readerFuncs.find(type) != readerFuncs.end()) {
			sp_shape3d shape;
			shape = readerFuncs[type](cin);
			scene.addShape(shape);
		}
		// Otherwise if it's a light...
		else if (type == "light") {
			sp_lightd light;
			light = readLight(cin);
			scene.addPointLight(light);
		}
		// Otherwise if it's a spot light...
		else if (type == "spotlight") {
			sp_spotlightd slight;
			slight = readSpotLight(cin);
			scene.addSpotLight(slight);
		}
		// Otherwise if it's an area light...
		else if (type == "arealight") {
			sp_arealightd alight;
			alight = readAreaLight(cin);
			scene.addAreaLight(alight);
		}
		// Otherwise if the type is camera...
		else if (type == "camera") {
			cam = readCamera(cin);
		}
		// Otherwise if we see the scene description's end...
		else if (type == "end") {
			break;
		}
		// Otherwise if the "type" is a comment start character...
		// Note that comments must begin with a # AND a space, like "# ",
		// and that the "# " must be at the beginning of the line.
		else if (type == "#") {
			string throwaway;
			getline(cin, throwaway);
		}
		// Otherwise we have an unrecognized type, which is an error.
		else {
			cerr << "ERROR: \"" << type << "\" is not a recognized scene " <<
					"description type." << endl;
			return 1;
		}
	}

	/* Render width x height image of this scene. */
	scene.renderPPM(*cam, width, height, cout);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4e0, %rsp            # imm = 0x4E0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x4, -0x8(%rbp)
je 0x3fcd
cmpl $0x3, -0x8(%rbp)
je 0x3fcd
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x3e90
movl $0x1, -0x4(%rbp)
jmp 0x4a58
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3340
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3340
movl %eax, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
cmpl $0x4, -0x8(%rbp)
jne 0x40fa
leaq -0x1a8(%rbp), %rdi
callq 0x3170
leaq -0x198(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x3240
jmp 0x401d
leaq -0x1d8(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x3230
jmp 0x4032
leaq 0xc0d4(%rip), %rsi      # 0x1010d
leaq -0x1d8(%rbp), %rdi
callq 0x5ac0
movb %al, -0x3d9(%rbp)
jmp 0x404d
leaq -0x1d8(%rbp), %rdi
callq 0x3130
movb -0x3d9(%rbp), %al
testb $0x1, %al
jne 0x4065
jmp 0x409f
movb $0x1, -0x19(%rbp)
jmp 0x40c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x40e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x3130
jmp 0x40e9
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x3e90
jmp 0x40ad
movl $0x1, -0x4(%rbp)
movl $0x1, -0x1dc(%rbp)
jmp 0x40ca
movl $0x0, -0x1dc(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x31a0
movl -0x1dc(%rbp), %eax
testl %eax, %eax
je 0x40e7
jmp 0x40e2
jmp 0x4a58
jmp 0x40fa
leaq -0x1a8(%rbp), %rdi
callq 0x31a0
jmp 0x4a64
leaq -0x201(%rbp), %rdi
movq %rdi, -0x3e8(%rbp)
callq 0x3390
movq -0x3e8(%rbp), %rdx
leaq 0xc0d4(%rip), %rsi      # 0x101ef
leaq -0x200(%rbp), %rdi
callq 0x5bd0
jmp 0x4129
leaq 0x150e8(%rip), %rdi     # 0x19218
leaq -0x200(%rbp), %rsi
callq 0x5af0
movq %rax, -0x3f0(%rbp)
jmp 0x4145
movq -0x3f0(%rbp), %rax
leaq -0xc03(%rip), %rcx      # 0x3550
movq %rcx, (%rax)
leaq -0x200(%rbp), %rdi
callq 0x3130
leaq -0x201(%rbp), %rdi
callq 0x32a0
leaq -0x229(%rbp), %rdi
movq %rdi, -0x3f8(%rbp)
callq 0x3390
movq -0x3f8(%rbp), %rdx
leaq 0xc067(%rip), %rsi      # 0x101f6
leaq -0x228(%rbp), %rdi
callq 0x5bd0
jmp 0x419d
leaq 0x15074(%rip), %rdi     # 0x19218
leaq -0x228(%rbp), %rsi
callq 0x5af0
movq %rax, -0x400(%rbp)
jmp 0x41b9
movq -0x400(%rbp), %rax
leaq -0xa17(%rip), %rcx      # 0x37b0
movq %rcx, (%rax)
leaq -0x228(%rbp), %rdi
callq 0x3130
leaq -0x229(%rbp), %rdi
callq 0x32a0
leaq -0x251(%rbp), %rdi
movq %rdi, -0x408(%rbp)
callq 0x3390
movq -0x408(%rbp), %rdx
leaq 0xbff9(%rip), %rsi      # 0x101fc
leaq -0x250(%rbp), %rdi
callq 0x5bd0
jmp 0x4211
leaq 0x15000(%rip), %rdi     # 0x19218
leaq -0x250(%rbp), %rsi
callq 0x5af0
movq %rax, -0x410(%rbp)
jmp 0x422d
movq -0x410(%rbp), %rax
leaq -0xbeb(%rip), %rcx      # 0x3650
movq %rcx, (%rax)
leaq -0x250(%rbp), %rdi
callq 0x3130
leaq -0x251(%rbp), %rdi
callq 0x32a0
movb -0x19(%rbp), %al
leaq -0x2a8(%rbp), %rdi
andb $0x1, %al
movzbl %al, %esi
callq 0x5c80
leaq -0x2b8(%rbp), %rdi
callq 0x5cd0
leaq -0x2d8(%rbp), %rdi
callq 0x3310
movq 0x14d4f(%rip), %rdi     # 0x18fd8
leaq -0x2d8(%rbp), %rsi
callq 0x32f0
movq %rax, -0x418(%rbp)
jmp 0x429e
movq -0x418(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32e0
movb %al, -0x419(%rbp)
jmp 0x42bc
movb -0x419(%rbp), %al
testb $0x1, %al
jne 0x42cb
jmp 0x49d1
leaq 0x14f46(%rip), %rdi     # 0x19218
leaq -0x2d8(%rbp), %rsi
callq 0x5d30
movq %rax, -0x428(%rbp)
jmp 0x42e7
movq -0x428(%rbp), %rax
movq %rax, -0x2e0(%rbp)
leaq 0x14f1c(%rip), %rdi     # 0x19218
callq 0x5d60
movq %rax, -0x2e8(%rbp)
leaq -0x2e0(%rbp), %rdi
leaq -0x2e8(%rbp), %rsi
callq 0x5d00
testb $0x1, %al
jne 0x4324
jmp 0x4504
leaq -0x2f8(%rbp), %rdi
callq 0x5d90
leaq 0x14ee1(%rip), %rdi     # 0x19218
leaq -0x2d8(%rbp), %rsi
callq 0x5dc0
movq %rax, -0x430(%rbp)
jmp 0x434c
movq -0x430(%rbp), %rax
movq (%rax), %rax
movq 0x14c7b(%rip), %rsi     # 0x18fd8
leaq -0x308(%rbp), %rdi
callq *%rax
jmp 0x4368
leaq -0x2f8(%rbp), %rdi
movq %rdi, -0x440(%rbp)
leaq -0x308(%rbp), %rsi
movq %rsi, -0x448(%rbp)
callq 0x5ea0
movq -0x448(%rbp), %rdi
callq 0x4ef0
movq -0x440(%rbp), %rsi
leaq -0x318(%rbp), %rdi
movq %rdi, -0x438(%rbp)
callq 0x5f60
movq -0x438(%rbp), %rsi
leaq -0x2a8(%rbp), %rdi
callq 0x5ef0
jmp 0x43c4
leaq -0x318(%rbp), %rdi
callq 0x4ef0
leaq -0x2f8(%rbp), %rdi
callq 0x4ef0
jmp 0x49cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x4413
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x3130
leaq -0x201(%rbp), %rdi
callq 0x32a0
jmp 0x4a64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x4456
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x3130
leaq -0x229(%rbp), %rdi
callq 0x32a0
jmp 0x4a64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x4499
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x250(%rbp), %rdi
callq 0x3130
leaq -0x251(%rbp), %rdi
callq 0x32a0
jmp 0x4a64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x4a32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x44f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x318(%rbp), %rdi
callq 0x4ef0
leaq -0x2f8(%rbp), %rdi
callq 0x4ef0
jmp 0x4a32
leaq 0xbd08(%rip), %rsi      # 0x10213
leaq -0x2d8(%rbp), %rdi
callq 0x5ac0
movb %al, -0x449(%rbp)
jmp 0x451f
movb -0x449(%rbp), %al
testb $0x1, %al
jne 0x452e
jmp 0x460b
leaq -0x328(%rbp), %rdi
callq 0x5fa0
movq 0x14a97(%rip), %rsi     # 0x18fd8
leaq -0x338(%rbp), %rdi
callq 0x38b0
jmp 0x454f
leaq -0x328(%rbp), %rdi
movq %rdi, -0x460(%rbp)
leaq -0x338(%rbp), %rsi
movq %rsi, -0x468(%rbp)
callq 0x5fd0
movq -0x468(%rbp), %rdi
callq 0x5300
movq -0x460(%rbp), %rsi
leaq -0x348(%rbp), %rdi
movq %rdi, -0x458(%rbp)
callq 0x6090
movq -0x458(%rbp), %rsi
leaq -0x2a8(%rbp), %rdi
callq 0x6020
jmp 0x45ab
leaq -0x348(%rbp), %rdi
callq 0x5300
leaq -0x328(%rbp), %rdi
callq 0x5300
jmp 0x49ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x45fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x348(%rbp), %rdi
callq 0x5300
leaq -0x328(%rbp), %rdi
callq 0x5300
jmp 0x4a32
leaq 0xbbf3(%rip), %rsi      # 0x10205
leaq -0x2d8(%rbp), %rdi
callq 0x5ac0
movb %al, -0x469(%rbp)
jmp 0x4626
movb -0x469(%rbp), %al
testb $0x1, %al
jne 0x4635
jmp 0x4712
leaq -0x358(%rbp), %rdi
callq 0x60d0
movq 0x14990(%rip), %rsi     # 0x18fd8
leaq -0x368(%rbp), %rdi
callq 0x3980
jmp 0x4656
leaq -0x358(%rbp), %rdi
movq %rdi, -0x480(%rbp)
leaq -0x368(%rbp), %rsi
movq %rsi, -0x488(%rbp)
callq 0x6100
movq -0x488(%rbp), %rdi
callq 0x55f0
movq -0x480(%rbp), %rsi
leaq -0x378(%rbp), %rdi
movq %rdi, -0x478(%rbp)
callq 0x61c0
movq -0x478(%rbp), %rsi
leaq -0x2a8(%rbp), %rdi
callq 0x6150
jmp 0x46b2
leaq -0x378(%rbp), %rdi
callq 0x55f0
leaq -0x358(%rbp), %rdi
callq 0x55f0
jmp 0x49c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x4701
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x55f0
leaq -0x358(%rbp), %rdi
callq 0x55f0
jmp 0x4a32
leaq 0xbaf6(%rip), %rsi      # 0x1020f
leaq -0x2d8(%rbp), %rdi
callq 0x5ac0
movb %al, -0x489(%rbp)
jmp 0x472d
movb -0x489(%rbp), %al
testb $0x1, %al
jne 0x473c
jmp 0x4819
leaq -0x388(%rbp), %rdi
callq 0x6200
movq 0x14889(%rip), %rsi     # 0x18fd8
leaq -0x398(%rbp), %rdi
callq 0x3bc0
jmp 0x475d
leaq -0x388(%rbp), %rdi
movq %rdi, -0x4a0(%rbp)
leaq -0x398(%rbp), %rsi
movq %rsi, -0x4a8(%rbp)
callq 0x6230
movq -0x4a8(%rbp), %rdi
callq 0x5850
movq -0x4a0(%rbp), %rsi
leaq -0x3a8(%rbp), %rdi
movq %rdi, -0x498(%rbp)
callq 0x63a0
movq -0x498(%rbp), %rsi
leaq -0x2a8(%rbp), %rdi
callq 0x6280
jmp 0x47b9
leaq -0x3a8(%rbp), %rdi
callq 0x5850
leaq -0x388(%rbp), %rdi
callq 0x5850
jmp 0x49c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x4808
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x3a8(%rbp), %rdi
callq 0x5850
leaq -0x388(%rbp), %rdi
callq 0x5850
jmp 0x4a32
leaq 0xb9f9(%rip), %rsi      # 0x10219
leaq -0x2d8(%rbp), %rdi
callq 0x5ac0
movb %al, -0x4a9(%rbp)
jmp 0x4834
movb -0x4a9(%rbp), %al
testb $0x1, %al
jne 0x4840
jmp 0x4879
movq 0x14791(%rip), %rsi     # 0x18fd8
leaq -0x3b8(%rbp), %rdi
callq 0x3d70
jmp 0x4855
leaq -0x2b8(%rbp), %rdi
leaq -0x3b8(%rbp), %rsi
callq 0x63e0
leaq -0x3b8(%rbp), %rdi
callq 0x5a60
jmp 0x49c4
leaq 0xb9a0(%rip), %rsi      # 0x10220
leaq -0x2d8(%rbp), %rdi
callq 0x5ac0
movb %al, -0x4aa(%rbp)
jmp 0x4894
movb -0x4aa(%rbp), %al
testb $0x1, %al
jne 0x48a0
jmp 0x48a5
jmp 0x49d1
leaq 0xb978(%rip), %rsi      # 0x10224
leaq -0x2d8(%rbp), %rdi
callq 0x5ac0
movb %al, -0x4ab(%rbp)
jmp 0x48c0
movb -0x4ab(%rbp), %al
testb $0x1, %al
jne 0x48cc
jmp 0x4928
leaq -0x3d8(%rbp), %rdi
movq %rdi, -0x4b8(%rbp)
callq 0x3310
movq -0x4b8(%rbp), %rsi
movq 0x146eb(%rip), %rdi     # 0x18fd8
callq 0x3060
jmp 0x48f4
leaq -0x3d8(%rbp), %rdi
callq 0x3130
jmp 0x49c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x3d8(%rbp), %rdi
callq 0x3130
jmp 0x4a32
movq 0x146c1(%rip), %rdi     # 0x18ff0
leaq 0xb8f0(%rip), %rsi      # 0x10226
callq 0x3240
movq %rax, -0x4c0(%rbp)
jmp 0x4944
movq -0x4c0(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0x3210
movq %rax, -0x4c8(%rbp)
jmp 0x4960
movq -0x4c8(%rbp), %rdi
leaq 0xb8c1(%rip), %rsi      # 0x1022f
callq 0x3240
movq %rax, -0x4d0(%rbp)
jmp 0x497c
movq -0x4d0(%rbp), %rdi
leaq 0xb8c2(%rip), %rsi      # 0x1024c
callq 0x3240
movq %rax, -0x4d8(%rbp)
jmp 0x4998
movq -0x4d8(%rbp), %rdi
movq 0x14612(%rip), %rsi     # 0x18fb8
callq 0x3280
jmp 0x49ad
movl $0x1, -0x4(%rbp)
movl $0x1, -0x1dc(%rbp)
jmp 0x4a0c
jmp 0x49c2
jmp 0x49c4
jmp 0x49c6
jmp 0x49c8
jmp 0x49ca
jmp 0x49cc
jmp 0x4282
leaq -0x2b8(%rbp), %rdi
callq 0x65e0
movq %rax, %rsi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
movq 0x145db(%rip), %r8      # 0x18fc8
leaq -0x2a8(%rbp), %rdi
callq 0x6430
jmp 0x49fb
movl $0x0, -0x4(%rbp)
movl $0x1, -0x1dc(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0x3130
leaq -0x2b8(%rbp), %rdi
callq 0x5a60
leaq -0x2a8(%rbp), %rdi
callq 0x6630
jmp 0x4a58
leaq -0x2d8(%rbp), %rdi
callq 0x3130
leaq -0x2b8(%rbp), %rdi
callq 0x5a60
leaq -0x2a8(%rbp), %rdi
callq 0x6630
jmp 0x4a64
movl -0x4(%rbp), %eax
addq $0x4e0, %rsp            # imm = 0x4E0
popq %rbp
retq
movq -0x1b0(%rbp), %rdi
callq 0x3380