// File: sgielen[P]clife/multi_indep.cpp
// Function: main
int main(int argc, char *argv[]) {
	int microsleeptime = 100000;
	if(argc == 2) {
		std::stringstream ss;
		ss << argv[1];
		ss >> microsleeptime;
		if(!ss) {
			std::cerr << "Usage: " << argv[0] << " [microsleeptime]" << std::endl;
		}
	} else if(argc > 2) {
		std::cerr << "Usage: " << argv[0] << " [microsleeptime]" << std::endl;
	}

	init_random();

	std::vector<uint64_t> earlier_hashes;
	GameOfLifeField<SimpleValue<char(0x80), 0>> red(8, 80);
	GameOfLifeField<SimpleValue<char(0x80), 0>> green(8, 80);
	GameOfLifeField<SimpleValue<char(0x80), 0>> blue(8, 80);

	red.generateRandom(35);
	green.generateRandom(35);
	blue.generateRandom(35);

	bool red_done = false;
	bool green_done = false;
	bool blue_done = false;
	int repeats_to_do = 0;
	print_rgb(red, green, blue);
	while(!red_done || !green_done || !blue_done || repeats_to_do > 0) {
		if(repeats_to_do > 0) {
			--repeats_to_do;
		}
		red.nextState();
		green.nextState();
		blue.nextState();
		print_rgb(red, green, blue);
		if(!red_done || !green_done || !blue_done) {
			check_stop_condition(red, earlier_hashes, red_done, repeats_to_do);
			check_stop_condition(green, earlier_hashes, green_done, repeats_to_do);
			check_stop_condition(blue, earlier_hashes, blue_done, repeats_to_do);
		}
		usleep(microsleeptime);
		continue;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x380, %rsp            # imm = 0x380
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x186a0, -0x14(%rbp)   # imm = 0x186A0
cmpl $0x2, -0x8(%rbp)
jne 0x56f9
leaq -0x1a0(%rbp), %rdi
callq 0x20d0
leaq -0x190(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x2140
jmp 0x561c
leaq -0x1a0(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x20c0
jmp 0x562e
movq -0x1a0(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x1a0(%rbp,%rax), %rdi
callq 0x2080
movb %al, -0x351(%rbp)
jmp 0x564e
movb -0x351(%rbp), %al
testb $0x1, %al
jne 0x565d
jmp 0x56eb
movq 0xa984(%rip), %rdi      # 0xffe8
leaq 0x5b15(%rip), %rsi      # 0xb180
callq 0x2140
movq %rax, -0x360(%rbp)
jmp 0x5679
movq -0x360(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x2140
movq %rax, -0x368(%rbp)
jmp 0x5695
movq -0x368(%rbp), %rdi
leaq 0x5ae5(%rip), %rsi      # 0xb188
callq 0x2140
movq %rax, -0x370(%rbp)
jmp 0x56b1
movq -0x370(%rbp), %rdi
movq 0xa8e9(%rip), %rsi      # 0xffa8
callq 0x2170
jmp 0x56c6
jmp 0x56eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x20f0
jmp 0x5c7d
leaq -0x1a0(%rbp), %rdi
callq 0x20f0
jmp 0x5741
cmpl $0x2, -0x8(%rbp)
jle 0x573f
movq 0xa8e2(%rip), %rdi      # 0xffe8
leaq 0x5a73(%rip), %rsi      # 0xb180
callq 0x2140
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x5a5d(%rip), %rsi      # 0xb188
callq 0x2140
movq %rax, %rdi
movq 0xa86e(%rip), %rsi      # 0xffa8
callq 0x2170
jmp 0x5741
callq 0x55a0
leaq -0x1c8(%rbp), %rdi
callq 0x7660
leaq -0x1e8(%rbp), %rdi
movl $0x8, %esi
movl $0x50, %edx
callq 0x7680
jmp 0x576a
leaq -0x208(%rbp), %rdi
movl $0x8, %esi
movl $0x50, %edx
callq 0x7680
jmp 0x5782
leaq -0x228(%rbp), %rdi
movl $0x8, %esi
movl $0x50, %edx
callq 0x7680
jmp 0x579a
leaq -0x1e8(%rbp), %rdi
movl $0x23, %esi
callq 0x7720
jmp 0x57ad
leaq -0x208(%rbp), %rdi
movl $0x23, %esi
callq 0x7720
jmp 0x57c0
leaq -0x228(%rbp), %rdi
movl $0x23, %esi
callq 0x7720
jmp 0x57d3
movb $0x0, -0x229(%rbp)
movb $0x0, -0x22a(%rbp)
movb $0x0, -0x22b(%rbp)
movl $0x0, -0x230(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x7990
jmp 0x5807
leaq -0x270(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x7990
jmp 0x581c
leaq -0x290(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0x7990
jmp 0x5831
leaq -0x250(%rbp), %rdi
leaq -0x270(%rbp), %rsi
leaq -0x290(%rbp), %rdx
callq 0x7840
jmp 0x584d
leaq -0x290(%rbp), %rdi
callq 0x79d0
leaq -0x270(%rbp), %rdi
callq 0x79d0
leaq -0x250(%rbp), %rdi
callq 0x79d0
movb $0x1, %al
testb $0x1, -0x229(%rbp)
movb %al, -0x371(%rbp)
je 0x58b4
movb $0x1, %al
testb $0x1, -0x22a(%rbp)
movb %al, -0x371(%rbp)
je 0x58b4
movb $0x1, %al
testb $0x1, -0x22b(%rbp)
movb %al, -0x371(%rbp)
je 0x58b4
cmpl $0x0, -0x230(%rbp)
setg %al
movb %al, -0x371(%rbp)
movb -0x371(%rbp), %al
testb $0x1, %al
jne 0x58c3
jmp 0x5c11
cmpl $0x0, -0x230(%rbp)
jle 0x59a3
movl -0x230(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x230(%rbp)
jmp 0x59a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x5c71
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x5c65
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x5c59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x5c4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x5992
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x5986
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x79d0
leaq -0x270(%rbp), %rdi
callq 0x79d0
leaq -0x250(%rbp), %rdi
callq 0x79d0
jmp 0x5c4d
leaq -0x1e8(%rbp), %rdi
callq 0x79f0
jmp 0x59b1
leaq -0x208(%rbp), %rdi
callq 0x79f0
jmp 0x59bf
leaq -0x228(%rbp), %rdi
callq 0x79f0
jmp 0x59cd
leaq -0x2b0(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x7990
jmp 0x59e2
leaq -0x2d0(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x7990
jmp 0x59f7
leaq -0x2f0(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0x7990
jmp 0x5a0c
leaq -0x2b0(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
leaq -0x2f0(%rbp), %rdx
callq 0x7840
jmp 0x5a28
leaq -0x2f0(%rbp), %rdi
callq 0x79d0
leaq -0x2d0(%rbp), %rdi
callq 0x79d0
leaq -0x2b0(%rbp), %rdi
callq 0x79d0
testb $0x1, -0x229(%rbp)
je 0x5a6b
testb $0x1, -0x22a(%rbp)
je 0x5a6b
testb $0x1, -0x22b(%rbp)
jne 0x5c02
leaq -0x310(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x7990
jmp 0x5a80
leaq -0x310(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
leaq -0x229(%rbp), %rdx
leaq -0x230(%rbp), %rcx
callq 0x7ca0
jmp 0x5aa3
leaq -0x310(%rbp), %rdi
callq 0x79d0
leaq -0x330(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x7990
jmp 0x5ac4
leaq -0x330(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
leaq -0x22a(%rbp), %rdx
leaq -0x230(%rbp), %rcx
callq 0x7ca0
jmp 0x5ae7
leaq -0x330(%rbp), %rdi
callq 0x79d0
leaq -0x350(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0x7990
jmp 0x5b08
leaq -0x350(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
leaq -0x22b(%rbp), %rdx
leaq -0x230(%rbp), %rcx
callq 0x7ca0
jmp 0x5b2b
leaq -0x350(%rbp), %rdi
callq 0x79d0
jmp 0x5c02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x5b8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
jmp 0x5b82
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x2f0(%rbp), %rdi
callq 0x79d0
leaq -0x2d0(%rbp), %rdi
callq 0x79d0
leaq -0x2b0(%rbp), %rdi
callq 0x79d0
jmp 0x5c4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x310(%rbp), %rdi
callq 0x79d0
jmp 0x5c4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x330(%rbp), %rdi
callq 0x79d0
jmp 0x5c4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1ac(%rbp)
leaq -0x350(%rbp), %rdi
callq 0x79d0
jmp 0x5c4d
movl -0x14(%rbp), %edi
callq 0x21b0
jmp 0x5c0c
jmp 0x5871
leaq -0x228(%rbp), %rdi
callq 0x79d0
leaq -0x208(%rbp), %rdi
callq 0x79d0
leaq -0x1e8(%rbp), %rdi
callq 0x79d0
leaq -0x1c8(%rbp), %rdi
callq 0x7d40
movl -0x4(%rbp), %eax
addq $0x380, %rsp            # imm = 0x380
popq %rbp
retq
leaq -0x228(%rbp), %rdi
callq 0x79d0
leaq -0x208(%rbp), %rdi
callq 0x79d0
leaq -0x1e8(%rbp), %rdi
callq 0x79d0
leaq -0x1c8(%rbp), %rdi
callq 0x7d40
movq -0x1a8(%rbp), %rdi
callq 0x2220
nopl (%rax)