// File: /workspace/github_cpp_makefile_star2_O3/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 0x13de
movq 0x4ca5(%rip), %r14      # 0x5fd8
leaq 0x1cca(%rip), %rsi      # 0x3004
movl $0x20, %edx
movq %r14, %rdi
callq 0x1100
movq %r14, %rdi
movl $0x2, %esi
callq 0x1140
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
movl 0xd4(%rbx), %r14d
cmpl $0x0, (%rbx)
je 0x13e5
movq 0x4c47(%rip), %r12      # 0x5fd8
leaq 0x1c8d(%rip), %rsi      # 0x3025
movl $0x23, %edx
movq %r12, %rdi
callq 0x1100
movq %r12, %rdi
movl %r14d, %esi
callq 0x1140
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
movl (%rbx), %eax
jmp 0x13e7
movl 0xd4(%rbx), %r14d
xorl %eax, %eax
cmpl $0x1, 0x84(%rbx)
jne 0x14fd
testl %eax, %eax
je 0x143a
movq 0x4bd9(%rip), %r14      # 0x5fd8
leaq 0x1c43(%rip), %rsi      # 0x3049
movl $0x29, %edx
movq %r14, %rdi
callq 0x1100
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x21dc
movq %rax, %r14
cmpl $0x0, (%rbx)
je 0x1492
movq 0x4b82(%rip), %r12      # 0x5fd8
leaq 0x1c16(%rip), %rsi      # 0x3073
movl $0x2d, %edx
movq %r12, %rdi
callq 0x1100
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
movq %rbx, %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x1a56
movl %eax, %r14d
cmpl $0x0, (%rbx)
je 0x1553
movq 0x4b26(%rip), %r12      # 0x5fd8
leaq 0x1be8(%rip), %rsi      # 0x30a1
movl $0x20, %edx
movq %r12, %rdi
callq 0x1100
movq %r12, %rdi
movl %r14d, %esi
callq 0x1140
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
movl (%rbx), %eax
testl %eax, %eax
je 0x1553
movq 0x4ad0(%rip), %r12      # 0x5fd8
leaq 0x1bb3(%rip), %rsi      # 0x30c2
movl $0x1a, %edx
movq %r12, %rdi
callq 0x1100
movq %r12, %rdi
movl $0x1, %esi
callq 0x1140
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
movq %rbx, %rdi
movl $0x1, %esi
movq %r15, %rdx
callq 0x21dc
movq %rax, %r15
cmpl $0x0, (%rbx)
je 0x15bb
movq 0x4a66(%rip), %r12      # 0x5fd8
leaq 0x1b64(%rip), %rsi      # 0x30dd
movl $0x1a, %edx
movq %r12, %rdi
callq 0x1100
movq %r12, %rdi
movq %r15, %rsi
callq 0x10c0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
movl 0x78(%rbx), %edx
movl 0x80(%rbx), %ecx
movq %rbx, %rdi
movl %r15d, %esi
callq 0x268e
movl %eax, %r15d
cmpl $0x0, (%rbx)
je 0x17a7
movq 0x49f6(%rip), %r12      # 0x5fd8
leaq 0x1b0f(%rip), %rsi      # 0x30f8
movl $0x1a, %edx
movq %r12, %rdi
callq 0x1100
movq %r12, %rdi
movl %r15d, %esi
callq 0x1140
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
cmpl $0x0, (%rbx)
je 0x17a7
movq 0x499d(%rip), %r12      # 0x5fd8
leaq 0x1ad1(%rip), %rsi      # 0x3113
movl $0x1f, %edx
movq %r12, %rdi
callq 0x1100
movl 0xc0(%rbx), %edx
leaq -0x48(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1ffa
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %r12, %rdi
callq 0x1100
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16b7
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x10e0
cmpl $0x0, (%rbx)
je 0x17a7
movq 0x4911(%rip), %r12      # 0x5fd8
leaq 0x1a65(%rip), %rsi      # 0x3133
movl $0x1b, %edx
movq %r12, %rdi
callq 0x1100
movq %r12, %rdi
movl $0x1, %esi
callq 0x1140
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r13, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
leaq 0x1a36(%rip), %rsi      # 0x314f
movl $0x1c, %edx
movq %r12, %rdi
callq 0x1100
movl 0xd8(%rbx), %esi
movq %r12, %rdi
callq 0x1140
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r13, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
leaq 0x1993(%rip), %rsi      # 0x30f8
movl $0x1a, %edx
movq %r12, %rdi
callq 0x1100
movq %r12, %rdi
movl %r15d, %esi
callq 0x1140
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
movl 0xc0(%rbx), %eax
cmpl $0x1, %eax
je 0x1941
cmpl $0x2, %eax
je 0x189b
cmpl $0x3, %eax
jne 0x19c0
cmpl $0x0, (%rbx)
je 0x187c
movq 0x4800(%rip), %r12      # 0x5fd8
leaq 0x19bb(%rip), %rsi      # 0x319a
movl $0x1c, %edx
movq %r12, %rdi
callq 0x1100
movl 0xc8(%rbx), %esi
movq %r12, %rdi
callq 0x1140
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
cmpl $0x0, (%rbx)
je 0x187c
movq 0x47a8(%rip), %r12      # 0x5fd8
leaq 0x19b1(%rip), %rsi      # 0x31e8
movl $0x1c, %edx
movq %r12, %rdi
callq 0x1100
movl 0xd0(%rbx), %esi
movq %r12, %rdi
callq 0x1140
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
cmpl 0xc8(%rbx), %r15d
jle 0x1a1f
cmpl 0xd0(%rbx), %r15d
jl 0x19a2
jmp 0x1a1f
movq 0x4736(%rip), %r14      # 0x5fd8
leaq 0x190e(%rip), %rsi      # 0x31b7
movl $0x30, %edx
movq %r14, %rdi
callq 0x1100
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
xorl %r14d, %r14d
cmpl $0x0, (%rbx)
je 0x1a1f
movq 0x46e8(%rip), %r15      # 0x5fd8
leaq 0x18a3(%rip), %rsi      # 0x319a
movl $0x1c, %edx
movq %r15, %rdi
callq 0x1100
movl 0xc8(%rbx), %esi
movq %r15, %rdi
callq 0x1140
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
jmp 0x1a1f
cmpl $0x0, (%rbx)
je 0x1999
movq 0x468b(%rip), %r12      # 0x5fd8
leaq 0x1846(%rip), %rsi      # 0x319a
movl $0x1c, %edx
movq %r12, %rdi
callq 0x1100
movl 0xc8(%rbx), %esi
movq %r12, %rdi
callq 0x1140
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
cmpl 0xc8(%rbx), %r15d
jge 0x1a1f
cmpl $0x1, 0x88(%rbx)
jne 0x1a18
movq %rbx, %rdi
movl %r15d, %esi
movl $0x1, %edx
callq 0x1a56
movl %eax, %r14d
jmp 0x1a1f
movq 0x4611(%rip), %r14      # 0x5fd8
leaq 0x179e(%rip), %rsi      # 0x316c
movl $0x2d, %edx
movq %r14, %rdi
callq 0x1100
movl 0xc0(%rbx), %esi
movq %r14, %rdi
callq 0x1140
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
xorl %r14d, %r14d
jmp 0x1a1f
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 -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1a4d
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x10e0
movq %rbx, %rdi
callq 0x1150
nop