// File: /workspace/github_cpp_makefile_star2_O1/xdsopl[P]FEC/testbench.cc
// Function: main
int main()
{
	std::random_device rd;
	std::default_random_engine generator(rd());
	std::uniform_int_distribution<uint8_t> distribution(0, 255);
	std::vector<uint8_t> data(65471*16);
	std::generate(data.begin(), data.end(), std::bind(distribution, generator));
	if (1) {
		BoseChaudhuriHocquenghem<6, 1, 5, GF::Types<4, 0b10011, uint8_t>> bch({0b10011, 0b11111, 0b00111});
		uint8_t code[15] = { 1, 1, 0, 0, 1 };
		uint8_t target[15] = { 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0 };
		test_bch("NASA INTRO BCH(15, 5) T=3", bch, code, target, data);
	}
	if (1) {
		ReedSolomon<4, 0, GF::Types<4, 0b10011, uint8_t>> rs;
		uint8_t code[15] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
		uint8_t target[15] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 3, 12, 12 };
		test_rs("BBC WHP031 RS(15, 11) T=2", rs, code, target, data);
	}
	if (1) {
		ReedSolomon<16, 0, GF::Types<8, 0b100011101, uint8_t>> rs;
		uint8_t code[255], target[255];
		for (int i = 0; i < 239; ++i)
			target[i] = code[i] = i + 1;
		uint8_t parity[16] = { 1, 126, 147, 48, 155, 224, 3, 157, 29, 226, 40, 114, 61, 30, 244, 75 };
		for (int i = 0; i < 16; ++i)
			target[239+i] = parity[i];
		test_rs("DVB-T RS(255, 239) T=8", rs, code, target, data);
	}
	if (1) {
		BoseChaudhuriHocquenghem<24, 1, 65343, GF::Types<16, 0b10000000000101101, uint16_t>> bch({0b10000000000101101, 0b10000000101110011, 0b10000111110111101, 0b10101101001010101, 0b10001111100101111, 0b11111011110110101, 0b11010111101100101, 0b10111001101100111, 0b10000111010100001, 0b10111010110100111, 0b10011101000101101, 0b10001101011100011});
		uint16_t code[65535], target[65535];
		for (int i = 0, s = 0; i < 65343; ++i, s=(s*(s*s*51767+71287)+35149)&0xffffff)
			target[i] = code[i] = (s^=s>>7)&1;
		uint16_t parity[192] = { 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0 };
		for (int i = 0; i < 192; ++i)
			target[65343+i] = parity[i];
		test_bch("DVB-S2 FULL BCH(65535, 65343) T=12", bch, code, target, data);
	}
	if (1) {
		ReedSolomon<64, 1, GF::Types<16, 0b10001000000001011, uint16_t>> rs;
		uint16_t code[65535], target[65535];
		for (int i = 0; i < 65471; ++i)
			target[i] = code[i] = i + 1;
		uint16_t parity[64] = { 25271, 26303, 22052, 31318, 31233, 6076, 40148, 29468, 47507, 32655, 12404, 13265, 23901, 38403, 50967, 50433, 40818, 226, 62296, 23636, 56393, 12952, 11476, 44416, 518, 50014, 10037, 57582, 33421, 42654, 54025, 7157, 4826, 52148, 17167, 23294, 6427, 40953, 11168, 35305, 18209, 1868, 39971, 54928, 27566, 1424, 4846, 25347, 34710, 42190, 56452, 21859, 49805, 28028, 41657, 25756, 22014, 24479, 28758, 17438, 12976, 61743, 46735, 1557 };
		for (int i = 0; i < 64; ++i)
			target[65471+i] = parity[i];
		test_rs("FUN RS(65535, 65471) T=32", rs, code, target, data);
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x415e8, %rsp          # imm = 0x415E8
leaq 0x258(%rsp), %rbx
movq %rbx, %rdi
callq 0x28f4
movq %rbx, %rdi
callq 0x21b0
movl %eax, %r14d
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movl $0xffbf0, %edi          # imm = 0xFFBF0
callq 0x2160
movq %rax, %rbx
movl %r14d, %eax
leaq (%rax,%rax,2), %rax
shrq $0x20, %rax
movl %r14d, %ecx
subl %eax, %ecx
shrl %ecx
addl %eax, %ecx
shrl $0x1e, %ecx
movl %ecx, %r15d
shll $0x1f, %r15d
orl %ecx, %r15d
leal (%r14,%r15), %eax
cmpl $0x1, %eax
adcl %r14d, %r15d
movq %rbx, (%rsp)
movq %rbx, 0x8(%rsp)
movq %rbx, %r14
addq $0xffbf0, %r14          # imm = 0xFFBF0
movq %r14, 0x10(%rsp)
xorl %r12d, %r12d
movl $0xffbf0, %edx          # imm = 0xFFBF0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20b0
movq %r14, 0x8(%rsp)
leaq 0xc8(%rsp), %r14
movw $0xff00, -0x8(%r14)     # imm = 0xFF00
movq %r15, (%r14)
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x76aa
movb %al, (%rbx,%r12)
incq %r12
cmpq $0xffbf0, %r12          # imm = 0xFFBF0
jne 0x2416
movabsq $0x1f00000013, %rax     # imm = 0x1F00000013
leaq 0x215e0(%rsp), %rsi
movq %rax, (%rsi)
movl $0x7, 0x8(%rsi)
leaq 0xd6(%rsp), %rdi
movl $0x3, %edx
callq 0x29ce
movabsq $0x100000101, %rax      # imm = 0x100000101
movq %rax, 0x215e0(%rsp)
movq $0x0, 0x215e7(%rsp)
movabsq $0x1000101010100, %rcx  # imm = 0x1000101010100
movq %rcx, 0x15e7(%rsp)
movq %rax, 0x15e0(%rsp)
leaq 0xb0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xbdd3(%rip), %rsi      # 0xe280
leaq 0xbde5(%rip), %rdx      # 0xe299
leaq 0xa0(%rsp), %rdi
callq 0x75e2
leaq 0xa0(%rsp), %rdi
leaq 0xd6(%rsp), %rsi
leaq 0x215e0(%rsp), %rdx
leaq 0x15e0(%rsp), %rcx
movq %rsp, %r8
callq 0x2c46
movq 0xa0(%rsp), %rdi
cmpq %r14, %rdi
je 0x2506
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0xd6(%rsp), %rdi
callq 0x3998
movabsq $0x807060504030201, %rax # imm = 0x807060504030201
movq %rax, 0x215e0(%rsp)
movq $0xb0a0908, 0x215e7(%rsp) # imm = 0xB0A0908
movabsq $0xc0c03030b0a0908, %rcx # imm = 0xC0C03030B0A0908
movq %rcx, 0x15e7(%rsp)
movq %rax, 0x15e0(%rsp)
leaq 0x90(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xbd3c(%rip), %rsi      # 0xe29a
leaq 0xbd4e(%rip), %rdx      # 0xe2b3
leaq 0x80(%rsp), %rdi
callq 0x75e2
leaq 0x80(%rsp), %rdi
leaq 0xd6(%rsp), %rsi
leaq 0x215e0(%rsp), %rdx
leaq 0x15e0(%rsp), %rcx
movq %rsp, %r8
callq 0x3b40
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0x25b7
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0xd6(%rsp), %rdi
callq 0x4842
xorl %eax, %eax
leaq 0x1(%rax), %rcx
movb %cl, 0x215e0(%rsp,%rax)
movb %cl, 0x15e0(%rsp,%rax)
movq %rcx, %rax
cmpq $0xef, %rcx
jne 0x25c6
movaps 0xe9c5(%rip), %xmm0     # 0x10fb0
movups %xmm0, 0x16cf(%rsp)
leaq 0x70(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xbcb1(%rip), %rsi      # 0xe2b4
leaq 0xbcc0(%rip), %rdx      # 0xe2ca
leaq 0x60(%rsp), %rdi
callq 0x75e2
leaq 0x60(%rsp), %rdi
leaq 0xd6(%rsp), %rsi
leaq 0x215e0(%rsp), %rdx
leaq 0x15e0(%rsp), %rcx
movq %rsp, %r8
callq 0x49fe
movq 0x60(%rsp), %rdi
cmpq %r14, %rdi
je 0x2650
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2170
movups 0xba15(%rip), %xmm0     # 0xe06c
leaq 0x215e0(%rsp), %rsi
movaps %xmm0, 0x20(%rsi)
movups 0xb9f2(%rip), %xmm0     # 0xe05c
movaps %xmm0, 0x10(%rsi)
movups 0xb9d7(%rip), %xmm0     # 0xe04c
movaps %xmm0, (%rsi)
leaq 0xd6(%rsp), %rdi
movl $0xc, %edx
callq 0x56c0
xorl %eax, %eax
xorl %ecx, %ecx
movl %ecx, %edx
shrl $0x7, %edx
xorl %ecx, %edx
movl %edx, %ecx
imull %edx, %ecx
imull $0xca37, %ecx, %ecx     # imm = 0xCA37
addl $0x11677, %ecx          # imm = 0x11677
imull %edx, %ecx
andl $0x1, %edx
movw %dx, 0x215e0(%rsp,%rax,2)
movw %dx, 0x15e0(%rsp,%rax,2)
incq %rax
addl $0x894d, %ecx           # imm = 0x894D
andl $0xffffff, %ecx         # imm = 0xFFFFFF
cmpq $0xff3f, %rax           # imm = 0xFF3F
jne 0x268e
leaq 0x2145e(%rsp), %rdi
leaq 0xb99e(%rip), %rsi      # 0xe080
movl $0x180, %edx            # imm = 0x180
callq 0x2100
leaq 0x50(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xbbcf(%rip), %rsi      # 0xe2cb
leaq 0xbbea(%rip), %rdx      # 0xe2ed
leaq 0x40(%rsp), %rdi
callq 0x75e2
leaq 0x40(%rsp), %rdi
leaq 0xd6(%rsp), %rsi
leaq 0x215e0(%rsp), %rdx
leaq 0x15e0(%rsp), %rcx
movq %rsp, %r8
callq 0x590f
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x2749
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0xd6(%rsp), %rdi
callq 0x66d2
xorl %eax, %eax
leaq 0x1(%rax), %rcx
movw %cx, 0x215e0(%rsp,%rax,2)
movw %cx, 0x15e0(%rsp,%rax,2)
movq %rcx, %rax
cmpq $0xffbf, %rcx           # imm = 0xFFBF
jne 0x2758
leaq 0x2155e(%rsp), %rdi
leaq 0xba79(%rip), %rsi      # 0xe200
movl $0x80, %edx
callq 0x2100
leaq 0x30(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xbb4d(%rip), %rsi      # 0xe2ee
leaq 0xbb5f(%rip), %rdx      # 0xe307
leaq 0x20(%rsp), %rdi
callq 0x75e2
leaq 0x20(%rsp), %rdi
leaq 0xd6(%rsp), %rsi
leaq 0x215e0(%rsp), %rdx
leaq 0x15e0(%rsp), %rcx
movq %rsp, %r8
callq 0x6879
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x27ee
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2170
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2804
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
leaq 0x258(%rsp), %rdi
callq 0x2120
xorl %eax, %eax
addq $0x415e8, %rsp          # imm = 0x415E8
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0x28ec
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x28c1
movq 0x30(%rsp), %rsi
jmp 0x28a9
jmp 0x28be
jmp 0x28be
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x28c1
movq 0x50(%rsp), %rsi
jmp 0x28a9
jmp 0x28be
jmp 0x28be
movq %rax, %rbx
movq 0x60(%rsp), %rdi
cmpq %r14, %rdi
je 0x28c1
movq 0x70(%rsp), %rsi
jmp 0x28a9
jmp 0x28be
jmp 0x28be
movq %rax, %rbx
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0x28c1
movq 0x90(%rsp), %rsi
jmp 0x28a9
jmp 0x28be
jmp 0x28be
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
cmpq %r14, %rdi
je 0x28c1
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2170
jmp 0x28c1
jmp 0x28be
jmp 0x28be
jmp 0x28b9
movq %rax, %rbx
jmp 0x28d7
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x28d7
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
leaq 0x258(%rsp), %rdi
callq 0x2120
movq %rbx, %rdi
callq 0x2210
movq %rax, %rdi
callq 0x75d6