// File: /workspace/github_cpp_makefile_star2_O1/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 0x137a
movq 0x4ca9(%rip), %r14      # 0x5fd8
leaq 0x1cce(%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 0x13d6
movq 0x4c4b(%rip), %r12      # 0x5fd8
leaq 0x1c91(%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
cmpl $0x1, 0x84(%rbx)
jne 0x14e7
cmpl $0x0, (%rbx)
je 0x142a
movq 0x4be9(%rip), %r14      # 0x5fd8
leaq 0x1c53(%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 0x21e4
movq %rax, %r14
cmpl $0x0, (%rbx)
je 0x1482
movq 0x4b92(%rip), %r12      # 0x5fd8
leaq 0x1c26(%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 0x1a62
movl %eax, %r14d
cmpl $0x0, (%rbx)
je 0x14e7
movq 0x4b3a(%rip), %r12      # 0x5fd8
leaq 0x1bfc(%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
cmpl $0x0, (%rbx)
je 0x153e
movq 0x4ae5(%rip), %r12      # 0x5fd8
leaq 0x1bc8(%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 0x21e4
movq %rax, %r15
cmpl $0x0, (%rbx)
je 0x15a6
movq 0x4a7b(%rip), %r12      # 0x5fd8
leaq 0x1b79(%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 0x2686
movl %eax, %r15d
cmpl $0x0, (%rbx)
je 0x1612
movq 0x4a0f(%rip), %r12      # 0x5fd8
leaq 0x1b28(%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 0x169e
movq 0x49b6(%rip), %r12      # 0x5fd8
leaq 0x1aea(%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 0x2004
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 0x169e
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x10e0
cmpl $0x0, (%rbx)
je 0x178e
movq 0x492a(%rip), %r12      # 0x5fd8
leaq 0x1a7e(%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 0x1a4f(%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 0x19ac(%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 0x192d
cmpl $0x2, %eax
je 0x1884
cmpl $0x3, %eax
jne 0x19bc
cmpl $0x0, (%rbx)
je 0x1807
movq 0x481d(%rip), %r12      # 0x5fd8
leaq 0x19d8(%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 0x185f
movq 0x47c5(%rip), %r12      # 0x5fd8
leaq 0x19ce(%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
movl $0x2, %r12d
cmpl 0xc8(%rbx), %r15d
jle 0x1a1e
cmpl 0xd0(%rbx), %r15d
jl 0x1998
jmp 0x1a1e
movq 0x474d(%rip), %r15      # 0x5fd8
leaq 0x1925(%rip), %rsi      # 0x31b7
movl $0x30, %edx
movq %r15, %rdi
callq 0x1100
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
movl $0x1, %r12d
cmpl $0x0, (%rbx)
je 0x1a1e
movq 0x46fc(%rip), %r15      # 0x5fd8
leaq 0x18b7(%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 0x1a1e
cmpl $0x0, (%rbx)
je 0x1985
movq 0x469f(%rip), %r12      # 0x5fd8
leaq 0x185a(%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
movl $0x2, %r12d
cmpl 0xc8(%rbx), %r15d
jge 0x1a1e
movl $0x6, %r12d
cmpl $0x1, 0x88(%rbx)
jne 0x1a17
movq %rbx, %rdi
movl %r15d, %esi
movl $0x1, %edx
callq 0x1a62
movl %eax, %r14d
jmp 0x1a1e
movq 0x4615(%rip), %r15      # 0x5fd8
leaq 0x17a2(%rip), %rsi      # 0x316c
movl $0x2d, %edx
movq %r15, %rdi
callq 0x1100
movl 0xc0(%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
movl $0x1, %r12d
jmp 0x1a1e
movl 0xd8(%rbx), %r14d
orl $0x4, %r12d
cmpl $0x6, %r12d
je 0x1a2b
xorl %r14d, %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 0x1a59
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x10e0
movq %rbx, %rdi
callq 0x1150
nop