// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x415e0, %rsp          # imm = 0x415E0
leaq 0x258(%rsp), %rbx
movq %rbx, %rdi
callq 0x27a6
movq %rbx, %rdi
callq 0x21b0
movl %eax, %ebx
leaq 0x8(%rsp), %rdi
leaq 0x215e0(%rsp), %rdx
movl $0xffbf0, %esi          # imm = 0xFFBF0
callq 0x27fc
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ebx, %eax
xorl %edx, %edx
divl %ecx
cmpl $0x1, %edx
adcl $0x0, %edx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
leaq 0xc0(%rsp), %rax
movw $0xff00, (%rax)         # imm = 0xFF00
movq %rdx, 0x8(%rax)
movq %rax, %rdx
callq 0x284d
movabsq $0x1f00000013, %rax     # imm = 0x1F00000013
leaq 0x215e0(%rsp), %rsi
movq %rax, (%rsi)
movl $0x7, 0x8(%rsi)
leaq 0xd6(%rsp), %rdi
pushq $0x3
popq %rdx
callq 0x2876
movabsq $0x100000101, %rax      # imm = 0x100000101
movq %rax, 0x215e0(%rsp)
andq $0x0, 0x215e7(%rsp)
movabsq $0x1000101010100, %rcx  # imm = 0x1000101010100
movq %rcx, 0x15e7(%rsp)
movq %rax, 0x15e0(%rsp)
leaq 0x9e6f(%rip), %rsi      # 0xc280
leaq 0xa0(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3508
leaq 0xa0(%rsp), %rdi
leaq 0xd6(%rsp), %rsi
leaq 0x215e0(%rsp), %rdx
leaq 0x15e0(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x2ac1
leaq 0xa0(%rsp), %rdi
callq 0x2090
leaq 0xd6(%rsp), %rdi
callq 0x3544
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 0x9df4(%rip), %rsi      # 0xc29a
leaq 0x80(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3508
leaq 0x80(%rsp), %rdi
leaq 0xd6(%rsp), %rsi
leaq 0x215e0(%rsp), %rdx
leaq 0x15e0(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x36aa
leaq 0x80(%rsp), %rdi
callq 0x2090
leaq 0xd6(%rsp), %rdi
callq 0x40be
xorl %eax, %eax
cmpq $0xef, %rax
je 0x251d
leaq 0x1(%rax), %rcx
movb %cl, 0x215e0(%rsp,%rax)
movb %cl, 0x15e0(%rsp,%rax)
movq %rcx, %rax
jmp 0x24fe
xorl %eax, %eax
leaq 0xca8a(%rip), %rcx      # 0xefb0
cmpq $0x10, %rax
je 0x253b
movb (%rax,%rcx), %dl
movb %dl, 0x16cf(%rsp,%rax)
incq %rax
jmp 0x2526
leaq 0x9d72(%rip), %rsi      # 0xc2b4
leaq 0x60(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3508
leaq 0x60(%rsp), %rdi
leaq 0xd6(%rsp), %rsi
leaq 0x215e0(%rsp), %rdx
leaq 0x15e0(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x4217
leaq 0x60(%rsp), %rdi
callq 0x2090
movups 0x9ae3(%rip), %xmm0     # 0xc06c
leaq 0x215e0(%rsp), %rsi
movaps %xmm0, 0x20(%rsi)
movups 0x9ac0(%rip), %xmm0     # 0xc05c
movaps %xmm0, 0x10(%rsi)
movups 0x9aa5(%rip), %xmm0     # 0xc04c
movaps %xmm0, (%rsi)
leaq 0xd6(%rsp), %rdi
pushq $0xc
popq %rdx
callq 0x4c50
xorl %eax, %eax
xorl %ecx, %ecx
cmpq $0xff3f, %rax           # imm = 0xFF3F
je 0x2605
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
jmp 0x25be
xorl %eax, %eax
leaq 0x9a72(%rip), %rcx      # 0xc080
cmpq $0x180, %rax            # imm = 0x180
je 0x2628
movzwl (%rax,%rcx), %edx
movw %dx, 0x2145e(%rsp,%rax)
addq $0x2, %rax
jmp 0x260e
leaq 0x9c9c(%rip), %rsi      # 0xc2cb
leaq 0x40(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3508
leaq 0x40(%rsp), %rdi
leaq 0xd6(%rsp), %rsi
leaq 0x215e0(%rsp), %rdx
leaq 0x15e0(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x4e3d
leaq 0x40(%rsp), %rdi
callq 0x2090
leaq 0xd6(%rsp), %rdi
callq 0x58e6
xorl %eax, %eax
cmpq $0xffbf, %rax           # imm = 0xFFBF
je 0x269f
leaq 0x1(%rax), %rcx
movw %cx, 0x215e0(%rsp,%rax,2)
movw %cx, 0x15e0(%rsp,%rax,2)
movq %rcx, %rax
jmp 0x267e
xorl %eax, %eax
leaq 0x9b58(%rip), %rcx      # 0xc200
cmpq $0x80, %rax
je 0x26c2
movzwl (%rax,%rcx), %edx
movw %dx, 0x2155e(%rsp,%rax)
addq $0x2, %rax
jmp 0x26a8
leaq 0x9c25(%rip), %rsi      # 0xc2ee
leaq 0x20(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3508
leaq 0x20(%rsp), %rdi
leaq 0xd6(%rsp), %rsi
leaq 0x215e0(%rsp), %rdx
leaq 0x15e0(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x5a50
leaq 0x20(%rsp), %rdi
callq 0x2090
leaq 0x8(%rsp), %rdi
callq 0x65dc
leaq 0x258(%rsp), %rdi
callq 0x64da
xorl %eax, %eax
addq $0x415e0, %rsp          # imm = 0x415E0
popq %rbx
retq
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
jmp 0x2771
jmp 0x277c
jmp 0x277c
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
jmp 0x2771
jmp 0x277c
jmp 0x277c
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
jmp 0x2771
jmp 0x277c
jmp 0x277c
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
jmp 0x2771
jmp 0x277c
jmp 0x277c
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x2090
jmp 0x277f
jmp 0x277c
jmp 0x277c
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x65dc
leaq 0x258(%rsp), %rdi
callq 0x64da
movq %rbx, %rdi
callq 0x21f0
jmp 0x27a0
movq %rax, %rbx
jmp 0x2789
nop