#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint8_t;
typedef int /*<<< orphan*/ result;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int finiteFieldMultiply(int, int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
void calcReedSolomonGenerator(int degree, uint8_t result[]) {
  assert(1 <= degree && degree <= 30);
  memset(result, 0, degree * sizeof(result[0]));
  result[degree - 1] = 1;
  uint8_t root = 1;
  for (int i = 0; i < degree; i++) {
    for (int j = 0; j < degree; j++) {
      result[j] = finiteFieldMultiply(result[j], root);
      if (j + 1 < degree)
        result[j] ^= result[j + 1];
    }
    root = finiteFieldMultiply(root, 0x02);
  }
}


x86 assembly (clang, -O0):
<calcReedSolomonGenerator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    $0x1,%ecx
cmp    -0x4(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jg     115c <calcReedSolomonGenerator+0x2c>
cmpl   $0x1e,-0x4(%rbp)
setle  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movl   $0x1,(%rax,%rcx,4)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    123d <calcReedSolomonGenerator+0x10d>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    121f <calcReedSolomonGenerator+0xef>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x14(%rbp),%esi
call   1030 <finiteFieldMultiply@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cmp    -0x4(%rbp),%eax
jge    120c <calcReedSolomonGenerator+0xdc>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
xor    (%rax,%rcx,4),%edx
mov    %edx,(%rax,%rcx,4)
jmp    1211 <calcReedSolomonGenerator+0xe1>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b3 <calcReedSolomonGenerator+0x83>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
call   1030 <finiteFieldMultiply@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a0 <calcReedSolomonGenerator+0x70>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcReedSolomonGenerator>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    -0x1(%rbp),%r14d
xor    %edi,%edi
cmp    $0x1e,%r14d
setb   %dil
call   1050 <assert@plt>
lea    0x0(,%rbp,4),%edx
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
movslq %r14d,%rax
movl   $0x1,(%rbx,%rax,4)
mov    %rbp,(%rsp)
test   %ebp,%ebp
jle    11e3 <calcReedSolomonGenerator+0xb3>
mov    (%rsp),%r12d
mov    %r12,%r13
neg    %r13
mov    $0x1,%ebp
jmp    11a8 <calcReedSolomonGenerator+0x78>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    $0x2,%esi
call   1030 <finiteFieldMultiply@plt>
mov    %eax,%ebp
add    $0x1,%r15d
cmp    (%rsp),%r15d
je     11e3 <calcReedSolomonGenerator+0xb3>
mov    $0x1,%r14d
jmp    11c2 <calcReedSolomonGenerator+0x92>
lea    (%r14,%r13,1),%rax
add    $0x1,%rax
add    $0x1,%r14
cmp    $0x1,%rax
je     1190 <calcReedSolomonGenerator+0x60>
mov    -0x4(%rbx,%r14,4),%edi
mov    %ebp,%esi
call   1030 <finiteFieldMultiply@plt>
mov    %eax,-0x4(%rbx,%r14,4)
cmp    %r12,%r14
jae    11b0 <calcReedSolomonGenerator+0x80>
xor    (%rbx,%r14,4),%eax
mov    %eax,-0x4(%rbx,%r14,4)
jmp    11b0 <calcReedSolomonGenerator+0x80>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @calcReedSolomonGenerator(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%8 = load i32, i32* %3
%9 = icmp sle i32 1, %8
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* %3
%12 = icmp sle i32 %11, 30
br label %13
13: ; preds = %10, %2
%14 = phi i1 [ false, %2 ], [ %12, %10 ]
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i32*, i32** %4
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 4
%21 = trunc i64 %20 to i32
%22 = call i32 @memset(i32* %17, i32 0, i32 %21)
%23 = load i32*, i32** %4
%24 = load i32, i32* %3
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %23, i64 %26
store i32 1, i32* %27
store i32 1, i32* %5
store i32 0, i32* %6
br label %28
28: ; preds = %73, %13
%29 = load i32, i32* %6
%30 = load i32, i32* %3
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %76
32: ; preds = %28
store i32 0, i32* %7
br label %33
33: ; preds = %67, %32
%34 = load i32, i32* %7
%35 = load i32, i32* %3
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %70
37: ; preds = %33
%38 = load i32*, i32** %4
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32, i32* %41
%43 = load i32, i32* %5
%44 = call i32 @finiteFieldMultiply(i32 %42, i32 %43)
%45 = load i32*, i32** %4
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
store i32 %44, i32* %48
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
%51 = load i32, i32* %3
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %66
53: ; preds = %37
%54 = load i32*, i32** %4
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %54, i64 %57
%59 = load i32, i32* %58
%60 = load i32*, i32** %4
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
%64 = load i32, i32* %63
%65 = xor i32 %64, %59
store i32 %65, i32* %63
br label %66
66: ; preds = %53, %37
br label %67
67: ; preds = %66
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
store i32 %69, i32* %7
br label %33
70: ; preds = %33
%71 = load i32, i32* %5
%72 = call i32 @finiteFieldMultiply(i32 %71, i32 2)
store i32 %72, i32* %5
br label %73
73: ; preds = %70
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
store i32 %75, i32* %6
br label %28
76: ; preds = %28
ret void
}

LLVM IR (-O2):
define void @calcReedSolomonGenerator(i32 %0, i32* %1) {
%3 = add i32 %0, -1
%4 = icmp ult i32 %3, 30
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = shl i32 %0, 2
%8 = tail call i32 @memset(i32* %1, i32 0, i32 %7)
%9 = sext i32 %3 to i64
%10 = getelementptr inbounds i32, i32* %1, i64 %9
store i32 1, i32* %10
%11 = icmp sgt i32 %0, 0
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = zext i32 %0 to i64
%14 = zext i32 %0 to i64
br label %15
15: ; preds = %19, %12
%16 = phi i32 [ 0, %12 ], [ %21, %19 ]
%17 = phi i32 [ 1, %12 ], [ %20, %19 ]
br label %23
18: ; preds = %19, %2
ret void
19: ; preds = %34
%20 = tail call i32 @finiteFieldMultiply(i32 %17, i32 2)
%21 = add nuw nsw i32 %16, 1
%22 = icmp eq i32 %21, %0
br i1 %22, label %18, label %15
23: ; preds = %15, %34
%24 = phi i64 [ 0, %15 ], [ %28, %34 ]
%25 = getelementptr inbounds i32, i32* %1, i64 %24
%26 = load i32, i32* %25
%27 = tail call i32 @finiteFieldMultiply(i32 %26, i32 %17)
store i32 %27, i32* %25
%28 = add nuw nsw i64 %24, 1
%29 = icmp ult i64 %28, %13
br i1 %29, label %30, label %34
30: ; preds = %23
%31 = getelementptr inbounds i32, i32* %1, i64 %28
%32 = load i32, i32* %31
%33 = xor i32 %32, %27
store i32 %33, i32* %25
br label %34
34: ; preds = %23, %30
%35 = icmp eq i64 %28, %14
br i1 %35, label %19, label %23
}