// File: superblocks[P]superblocks/next.cpp
// Function: Superblocks::getnextblockreward(char const*)
int Superblocks::getnextblockreward( const char* hash )
{

	if( debug ) { cout << "getnextblockreward: LUCK_STEPS: " << LUCK_STEPS << endl; }

	// normal reward - step 0
	int nextreward = reward[0]; 
	if( debug ) { cout << "getnextblockreward: normal reward: " << nextreward << endl; }
	if( secondary_rand[0] == 1 ) {
		if( debug ) { cout << "getnextblockreward: step 0 secondary: ..." << endl; }
		long s_seed = gethashcutout( 0, hash );
//		if( debug ) { cout << "getnextblockreward: step 0 secondary: MT..." << endl; }
//		int s_rand = generateMTRandom(s_seed, secondary_rand_low[0], secondary_rand_high[0]);
		if( debug ) { cout << "getnextblockreward: step 0 secondary: 2nd...." << endl; }
		nextreward = getsecondaryreward( s_seed, 0 );
		if( debug ) { cout << "getnextblockreward: new reward: " << nextreward << endl; }
	}


	// non-normal rewards  
	int step = 1;
	if( debug ) { cout << "getnextblockreward: step: " << step << endl; }

	long seed = gethashcutout( 1, hash );
	if( debug ) { cout << "getnextblockreward: seed: " << seed << endl; }

	int rand = generateMTRandom(seed, rnd_range_low[step], rnd_range_high[step]);
	if( debug ) { cout << "getnextblockreward: rand: " << rand << endl; }

	if( debug ) { cout << "getnextblockreward: luck_type: " << getlucktype(luck_type[step]) << endl; }

	for (int rstep = 1; rstep < LUCK_STEPS ; rstep++) {

		if( debug ) {
			cout << "getnextblockreward: rstep: " << rstep << endl;
			cout << "getnextblockreward: reward: " << reward[rstep] << endl;
			cout << "getnextblockreward: rand: " << rand << endl; 
		}

		switch( luck_type[rstep] ) { 

		default: 
			cout << "getnextblockreward: error: unknown luck type:" << luck_type[rstep] << endl; 
			return 0; 

		case 1: // LUCK_WITH_LESS_THAN_X 

			if( debug ) { cout << "getnextblockreward: luck_x: " << luck_x[rstep] << endl; }
			if( rand < luck_x[rstep] ) {
				nextreward = reward[rstep];
				if( secondary_rand[rstep] == 1 ) { 
					nextreward = getsecondaryreward( rand, rstep );
				}
				goto final_reward;
			}
			break;

		case 2: // LUCK_WITH_MORE_THAN_X 

			cout << "getnextblockreward: TODO luck type 2 MORE THAN X" << endl; 
			if( debug ) { cout << "getnextblockreward: luck_x: " << luck_x[rstep] << endl; }
			return 0;

		case 3: // LUCK_WITH_MORE_THAN_X_AND_LESS_THAN_Y

			if( debug ) { cout << "getnextblockreward: luck_x: " << luck_x[rstep] << endl; }
			if( debug ) { cout << "getnextblockreward: luck_y: " << luck_y[rstep] << endl; }
			if( rand > luck_x[rstep] && rand < luck_y[rstep] ) {
				nextreward = reward[rstep];
				if( secondary_rand[rstep] == 1 ) {
					nextreward = getsecondaryreward( rand, rstep );
				}
				goto final_reward;
			}
			break;
		}
	}

	final_reward:
	return nextreward;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpl $0x0, (%rax)
je 0x245f
movq 0x5ba1(%rip), %rdi      # 0x7fd8
leaq 0x2bc6(%rip), %rsi      # 0x5004
callq 0x2110
movq %rax, %rdi
movl $0x2, %esi
callq 0x21f0
movq %rax, %rdi
movq 0x5b6e(%rip), %rsi      # 0x7fc8
callq 0x2130
movq -0x78(%rbp), %rax
movl 0xd4(%rax), %ecx
movl %ecx, -0x1c(%rbp)
cmpl $0x0, (%rax)
je 0x249e
movq 0x5b60(%rip), %rdi      # 0x7fd8
leaq 0x2ba6(%rip), %rsi      # 0x5025
callq 0x2110
movq %rax, %rdi
movl -0x1c(%rbp), %esi
callq 0x21f0
movq %rax, %rdi
movq 0x5b2f(%rip), %rsi      # 0x7fc8
callq 0x2130
movq -0x78(%rbp), %rax
cmpl $0x1, 0x84(%rax)
jne 0x2569
movq -0x78(%rbp), %rax
cmpl $0x0, (%rax)
je 0x24da
movq 0x5b19(%rip), %rdi      # 0x7fd8
leaq 0x2b83(%rip), %rsi      # 0x5049
callq 0x2110
movq %rax, %rdi
movq 0x5af3(%rip), %rsi      # 0x7fc8
callq 0x2130
movq -0x78(%rbp), %rdi
movq -0x18(%rbp), %rdx
xorl %esi, %esi
callq 0x3590
movq %rax, %rcx
movq -0x78(%rbp), %rax
movq %rcx, -0x28(%rbp)
cmpl $0x0, (%rax)
je 0x251b
movq 0x5ad8(%rip), %rdi      # 0x7fd8
leaq 0x2b6c(%rip), %rsi      # 0x5073
callq 0x2110
movq %rax, %rdi
movq 0x5ab2(%rip), %rsi      # 0x7fc8
callq 0x2130
movq -0x78(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %esi
xorl %edx, %edx
callq 0x2a30
movl %eax, %ecx
movq -0x78(%rbp), %rax
movl %ecx, -0x1c(%rbp)
cmpl $0x0, (%rax)
je 0x2567
movq 0x5a97(%rip), %rdi      # 0x7fd8
leaq 0x2b59(%rip), %rsi      # 0x50a1
callq 0x2110
movq %rax, %rdi
movl -0x1c(%rbp), %esi
callq 0x21f0
movq %rax, %rdi
movq 0x5a66(%rip), %rsi      # 0x7fc8
callq 0x2130
jmp 0x2569
movq -0x78(%rbp), %rax
movl $0x1, -0x2c(%rbp)
cmpl $0x0, (%rax)
je 0x25a6
movq 0x5a58(%rip), %rdi      # 0x7fd8
leaq 0x2b3b(%rip), %rsi      # 0x50c2
callq 0x2110
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x21f0
movq %rax, %rdi
movq 0x5a27(%rip), %rsi      # 0x7fc8
callq 0x2130
movq -0x78(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl $0x1, %esi
callq 0x3590
movq %rax, %rcx
movq -0x78(%rbp), %rax
movq %rcx, -0x38(%rbp)
cmpl $0x0, (%rax)
je 0x25f6
movq 0x5a09(%rip), %rdi      # 0x7fd8
leaq 0x2b07(%rip), %rsi      # 0x50dd
callq 0x2110
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x2230
movq %rax, %rdi
movq 0x59d7(%rip), %rsi      # 0x7fc8
callq 0x2130
movq -0x78(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %esi
movslq -0x2c(%rbp), %rax
movl 0x74(%rdi,%rax,4), %edx
movslq -0x2c(%rbp), %rax
movl 0x7c(%rdi,%rax,4), %ecx
callq 0x39d0
movl %eax, %ecx
movq -0x78(%rbp), %rax
movl %ecx, -0x3c(%rbp)
cmpl $0x0, (%rax)
je 0x2650
movq 0x59ae(%rip), %rdi      # 0x7fd8
leaq 0x2ac7(%rip), %rsi      # 0x50f8
callq 0x2110
movq %rax, %rdi
movl -0x3c(%rbp), %esi
callq 0x21f0
movq %rax, %rdi
movq 0x597d(%rip), %rsi      # 0x7fc8
callq 0x2130
movq -0x78(%rbp), %rax
cmpl $0x0, (%rax)
je 0x26e6
movq 0x5974(%rip), %rdi      # 0x7fd8
leaq 0x2aa8(%rip), %rsi      # 0x5113
callq 0x2110
movq -0x78(%rbp), %rsi
movq %rax, -0x90(%rbp)
movslq -0x2c(%rbp), %rax
movl 0xbc(%rsi,%rax,4), %edx
leaq -0x60(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0x2f10
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x2100
movq %rax, -0x80(%rbp)
jmp 0x26af
movq -0x80(%rbp), %rdi
movq 0x590e(%rip), %rsi      # 0x7fc8
callq 0x2130
jmp 0x26c1
leaq -0x60(%rbp), %rdi
callq 0x2080
jmp 0x26e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x2080
jmp 0x2a22
movl $0x1, -0x70(%rbp)
cmpl $0x2, -0x70(%rbp)
jge 0x2a0e
movq -0x78(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2797
movq 0x58cd(%rip), %rdi      # 0x7fd8
leaq 0x2a21(%rip), %rsi      # 0x5133
callq 0x2110
movq %rax, %rdi
movl -0x70(%rbp), %esi
callq 0x21f0
movq %rax, %rdi
movq 0x589c(%rip), %rsi      # 0x7fc8
callq 0x2130
movq 0x58a0(%rip), %rdi      # 0x7fd8
leaq 0x2a10(%rip), %rsi      # 0x514f
callq 0x2110
movq %rax, %rdi
movq -0x78(%rbp), %rax
movslq -0x70(%rbp), %rcx
movl 0xd4(%rax,%rcx,4), %esi
callq 0x21f0
movq %rax, %rdi
movq 0x5863(%rip), %rsi      # 0x7fc8
callq 0x2130
movq 0x5867(%rip), %rdi      # 0x7fd8
leaq 0x2980(%rip), %rsi      # 0x50f8
callq 0x2110
movq %rax, %rdi
movl -0x3c(%rbp), %esi
callq 0x21f0
movq %rax, %rdi
movq 0x5836(%rip), %rsi      # 0x7fc8
callq 0x2130
movq -0x78(%rbp), %rax
movslq -0x70(%rbp), %rcx
movl 0xbc(%rax,%rcx,4), %eax
movl %eax, -0x94(%rbp)
subl $0x1, %eax
je 0x281a
jmp 0x27b3
movl -0x94(%rbp), %eax
subl $0x2, %eax
je 0x28ac
jmp 0x27c4
movl -0x94(%rbp), %eax
subl $0x3, %eax
je 0x291c
jmp 0x27d5
movq 0x57fc(%rip), %rdi      # 0x7fd8
leaq 0x2989(%rip), %rsi      # 0x516c
callq 0x2110
movq %rax, %rdi
movq -0x78(%rbp), %rax
movslq -0x70(%rbp), %rcx
movl 0xbc(%rax,%rcx,4), %esi
callq 0x21f0
movq %rax, %rdi
movq 0x57bf(%rip), %rsi      # 0x7fc8
callq 0x2130
movl $0x0, -0x4(%rbp)
jmp 0x2a16
movq -0x78(%rbp), %rax
cmpl $0x0, (%rax)
je 0x285c
movq 0x57ae(%rip), %rdi      # 0x7fd8
leaq 0x2969(%rip), %rsi      # 0x519a
callq 0x2110
movq %rax, %rdi
movq -0x78(%rbp), %rax
movslq -0x70(%rbp), %rcx
movl 0xc4(%rax,%rcx,4), %esi
callq 0x21f0
movq %rax, %rdi
movq 0x5771(%rip), %rsi      # 0x7fc8
callq 0x2130
movq -0x78(%rbp), %rcx
movl -0x3c(%rbp), %eax
movslq -0x70(%rbp), %rdx
cmpl 0xc4(%rcx,%rdx,4), %eax
jge 0x28a7
movq -0x78(%rbp), %rax
movslq -0x70(%rbp), %rcx
movl 0xd4(%rax,%rcx,4), %ecx
movl %ecx, -0x1c(%rbp)
movslq -0x70(%rbp), %rcx
cmpl $0x1, 0x84(%rax,%rcx,4)
jne 0x28a2
movq -0x78(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl -0x70(%rbp), %edx
callq 0x2a30
movl %eax, -0x1c(%rbp)
jmp 0x2a10
jmp 0x29fe
movq 0x5725(%rip), %rdi      # 0x7fd8
leaq 0x28fd(%rip), %rsi      # 0x51b7
callq 0x2110
movq %rax, %rdi
movq 0x56ff(%rip), %rsi      # 0x7fc8
callq 0x2130
movq -0x78(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2910
movq 0x56fa(%rip), %rdi      # 0x7fd8
leaq 0x28b5(%rip), %rsi      # 0x519a
callq 0x2110
movq %rax, %rdi
movq -0x78(%rbp), %rax
movslq -0x70(%rbp), %rcx
movl 0xc4(%rax,%rcx,4), %esi
callq 0x21f0
movq %rax, %rdi
movq 0x56bd(%rip), %rsi      # 0x7fc8
callq 0x2130
movl $0x0, -0x4(%rbp)
jmp 0x2a16
movq -0x78(%rbp), %rax
cmpl $0x0, (%rax)
je 0x295e
movq 0x56ac(%rip), %rdi      # 0x7fd8
leaq 0x2867(%rip), %rsi      # 0x519a
callq 0x2110
movq %rax, %rdi
movq -0x78(%rbp), %rax
movslq -0x70(%rbp), %rcx
movl 0xc4(%rax,%rcx,4), %esi
callq 0x21f0
movq %rax, %rdi
movq 0x566f(%rip), %rsi      # 0x7fc8
callq 0x2130
movq -0x78(%rbp), %rax
cmpl $0x0, (%rax)
je 0x29a0
movq 0x566a(%rip), %rdi      # 0x7fd8
leaq 0x2873(%rip), %rsi      # 0x51e8
callq 0x2110
movq %rax, %rdi
movq -0x78(%rbp), %rax
movslq -0x70(%rbp), %rcx
movl 0xcc(%rax,%rcx,4), %esi
callq 0x21f0
movq %rax, %rdi
movq 0x562d(%rip), %rsi      # 0x7fc8
callq 0x2130
movq -0x78(%rbp), %rcx
movl -0x3c(%rbp), %eax
movslq -0x70(%rbp), %rdx
cmpl 0xc4(%rcx,%rdx,4), %eax
jle 0x29fc
movq -0x78(%rbp), %rcx
movl -0x3c(%rbp), %eax
movslq -0x70(%rbp), %rdx
cmpl 0xcc(%rcx,%rdx,4), %eax
jge 0x29fc
movq -0x78(%rbp), %rax
movslq -0x70(%rbp), %rcx
movl 0xd4(%rax,%rcx,4), %ecx
movl %ecx, -0x1c(%rbp)
movslq -0x70(%rbp), %rcx
cmpl $0x1, 0x84(%rax,%rcx,4)
jne 0x29fa
movq -0x78(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl -0x70(%rbp), %edx
callq 0x2a30
movl %eax, -0x1c(%rbp)
jmp 0x2a10
jmp 0x29fe
jmp 0x2a00
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x26ed
jmp 0x2a10
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x2200
nopl (%rax,%rax)