// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r15
movq %rdi, %rbx
cmpl $0x0, (%rdi)
je 0x1364
movq 0x4cc9(%rip), %rdi      # 0x5fd8
leaq 0x1cee(%rip), %rsi      # 0x3004
callq 0x10e0
pushq $0x2
popq %rsi
movq %rax, %rdi
callq 0x1110
movq %rax, %rdi
callq 0x1050
movl 0xd4(%rbx), %r14d
cmpl $0x0, (%rbx)
je 0x136b
movq 0x4c97(%rip), %rdi      # 0x5fd8
leaq 0x1cdd(%rip), %rsi      # 0x3025
callq 0x10e0
movq %rax, %rdi
movl %r14d, %esi
callq 0x1110
movq %rax, %rdi
callq 0x1050
movl (%rbx), %eax
jmp 0x136d
movl 0xd4(%rbx), %r14d
xorl %eax, %eax
cmpl $0x1, 0x84(%rbx)
jne 0x1406
testl %eax, %eax
je 0x1399
movq 0x4c53(%rip), %rdi      # 0x5fd8
leaq 0x1cbd(%rip), %rsi      # 0x3049
callq 0x10e0
movq %rax, %rdi
callq 0x1050
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x1c30
movq %rax, %r14
cmpl $0x0, (%rbx)
je 0x13c9
movq 0x4c23(%rip), %rdi      # 0x5fd8
leaq 0x1cb7(%rip), %rsi      # 0x3073
callq 0x10e0
movq %rax, %rdi
callq 0x1050
movq %rbx, %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x1716
movl %eax, %r14d
cmpl $0x0, (%rbx)
je 0x1430
movq 0x4bf3(%rip), %rdi      # 0x5fd8
leaq 0x1cb5(%rip), %rsi      # 0x30a1
callq 0x10e0
movq %rax, %rdi
movl %r14d, %esi
callq 0x1110
movq %rax, %rdi
callq 0x1050
movl (%rbx), %eax
testl %eax, %eax
je 0x1430
movq 0x4bc7(%rip), %rdi      # 0x5fd8
leaq 0x1caa(%rip), %rsi      # 0x30c2
callq 0x10e0
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x1110
movq %rax, %rdi
callq 0x1050
pushq $0x1
popq %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x1c30
movq %rax, %r15
cmpl $0x0, (%rbx)
je 0x146c
movq 0x4b8b(%rip), %rdi      # 0x5fd8
leaq 0x1c89(%rip), %rsi      # 0x30dd
callq 0x10e0
movq %rax, %rdi
movq %r15, %rsi
callq 0x10d0
movq %rax, %rdi
callq 0x1050
movl 0x78(%rbx), %edx
movl 0x80(%rbx), %ecx
movq %rbx, %rdi
movl %r15d, %esi
callq 0x1e9a
movl %eax, %r15d
cmpl $0x0, (%rbx)
je 0x1577
movq 0x4b45(%rip), %rdi      # 0x5fd8
leaq 0x1c5e(%rip), %rsi      # 0x30f8
callq 0x10e0
movq %rax, %rdi
movl %r15d, %esi
callq 0x1110
movq %rax, %rdi
callq 0x1050
cmpl $0x0, (%rbx)
je 0x1577
movq 0x4b16(%rip), %rdi      # 0x5fd8
leaq 0x1c4a(%rip), %rsi      # 0x3113
callq 0x10e0
movq %rax, %r12
movl 0xc0(%rbx), %edx
leaq -0x48(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1a54
movq %r12, %rdi
movq %r13, %rsi
callq 0x10c0
movq %rax, %rdi
callq 0x1050
leaq -0x48(%rbp), %rdi
callq 0x1040
cmpl $0x0, (%rbx)
je 0x1577
movq 0x4aca(%rip), %r12      # 0x5fd8
leaq 0x1c1e(%rip), %rsi      # 0x3133
movq %r12, %rdi
callq 0x10e0
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x1110
movq %rax, %rdi
callq 0x1050
leaq 0x1c18(%rip), %rsi      # 0x314f
movq %r12, %rdi
callq 0x10e0
movl 0xd8(%rbx), %esi
movq %rax, %rdi
callq 0x1110
movq %rax, %rdi
callq 0x1050
leaq 0x1b9c(%rip), %rsi      # 0x30f8
movq %r12, %rdi
callq 0x10e0
movq %rax, %rdi
movl %r15d, %esi
callq 0x1110
movq %rax, %rdi
callq 0x1050
movl 0xc0(%rbx), %eax
cmpl $0x1, %eax
je 0x1668
cmpl $0x2, %eax
je 0x1613
cmpl $0x3, %eax
jne 0x16bb
cmpl $0x0, (%rbx)
je 0x15f4
movq 0x4a34(%rip), %rdi      # 0x5fd8
leaq 0x1bef(%rip), %rsi      # 0x319a
callq 0x10e0
movl 0xc8(%rbx), %esi
movq %rax, %rdi
callq 0x1110
movq %rax, %rdi
callq 0x1050
cmpl $0x0, (%rbx)
je 0x15f4
movq 0x4a06(%rip), %rdi      # 0x5fd8
leaq 0x1c0f(%rip), %rsi      # 0x31e8
callq 0x10e0
movl 0xd0(%rbx), %esi
movq %rax, %rdi
callq 0x1110
movq %rax, %rdi
callq 0x1050
cmpl 0xc8(%rbx), %r15d
jle 0x16f0
cmpl 0xd0(%rbx), %r15d
jl 0x169f
jmp 0x16f0
movq 0x49be(%rip), %rdi      # 0x5fd8
leaq 0x1b96(%rip), %rsi      # 0x31b7
callq 0x10e0
movq %rax, %rdi
callq 0x1050
xorl %r14d, %r14d
cmpl $0x0, (%rbx)
je 0x16f0
movq 0x4997(%rip), %rdi      # 0x5fd8
leaq 0x1b52(%rip), %rsi      # 0x319a
callq 0x10e0
movl 0xc8(%rbx), %esi
movq %rax, %rdi
callq 0x1110
movq %rax, %rdi
callq 0x1050
jmp 0x16f0
cmpl $0x0, (%rbx)
je 0x1696
movq 0x4964(%rip), %rdi      # 0x5fd8
leaq 0x1b1f(%rip), %rsi      # 0x319a
callq 0x10e0
movl 0xc8(%rbx), %esi
movq %rax, %rdi
callq 0x1110
movq %rax, %rdi
callq 0x1050
cmpl 0xc8(%rbx), %r15d
jge 0x16f0
cmpl $0x1, 0x88(%rbx)
jne 0x16e9
pushq $0x1
popq %rdx
movq %rbx, %rdi
movl %r15d, %esi
callq 0x1716
movl %eax, %r14d
jmp 0x16f0
movq 0x4916(%rip), %rdi      # 0x5fd8
leaq 0x1aa3(%rip), %rsi      # 0x316c
callq 0x10e0
movl 0xc0(%rbx), %esi
movq %rax, %rdi
callq 0x1110
movq %rax, %rdi
callq 0x1050
xorl %r14d, %r14d
jmp 0x16f0
movl 0xd8(%rbx), %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x1040
movq %rbx, %rdi
callq 0x1120