#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ memmove(unsigned char *, unsigned char *, unsigned int);
int /*<<< orphan*/ redupe_gf_poly_mul(unsigned char *, unsigned int,
                                      unsigned char *, int, unsigned char *,
                                      unsigned int *);
unsigned char redupe_gf_pow(int, unsigned int);
void redupe_generator_poly(unsigned nsym, unsigned char *gen) {
  assert(nsym > 0);
  unsigned char poly1[256];
  unsigned char poly2[256];
  unsigned char tmp[2];
  unsigned poly1_sz = 1;
  unsigned poly2_sz = 0;
  poly1[0] = 1;
  for (unsigned i = 0; i < nsym; ++i) {
    if ((i & 0x1) == 0) {
      tmp[0] = 1;
      tmp[1] = redupe_gf_pow(2, i);
      redupe_gf_poly_mul(poly1, poly1_sz, tmp, 2, poly2, &poly2_sz);
    } else {
      tmp[0] = 1;
      tmp[1] = redupe_gf_pow(2, i);
      redupe_gf_poly_mul(poly2, poly2_sz, tmp, 2, poly1, &poly1_sz);
    }
  }
  if ((nsym & 0x1)) {
    memmove(gen, poly2, poly2_sz * sizeof(unsigned char));
    assert(nsym + 1 == poly2_sz);
  } else {
    memmove(gen, poly1, poly1_sz * sizeof(unsigned char));
    assert(nsym + 1 == poly1_sz);
  }
}


x86 assembly (clang, -O0):
<redupe_generator_poly>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x1,-0x218(%rbp)
movl   $0x0,-0x21c(%rbp)
movb   $0x1,-0x110(%rbp)
movl   $0x0,-0x220(%rbp)
mov    -0x220(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    1259 <redupe_generator_poly+0x119>
mov    -0x220(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    11f7 <redupe_generator_poly+0xb7>
movb   $0x1,-0x212(%rbp)
mov    -0x220(%rbp),%esi
mov    $0x2,%edi
call   1030 <redupe_gf_pow@plt>
mov    %al,-0x211(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x218(%rbp),%esi
lea    -0x212(%rbp),%rdx
lea    -0x210(%rbp),%r8
mov    $0x2,%ecx
lea    -0x21c(%rbp),%r9
call   1050 <redupe_gf_poly_mul@plt>
jmp    1240 <redupe_generator_poly+0x100>
movb   $0x1,-0x212(%rbp)
mov    -0x220(%rbp),%esi
mov    $0x2,%edi
call   1030 <redupe_gf_pow@plt>
mov    %al,-0x211(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x21c(%rbp),%esi
lea    -0x212(%rbp),%rdx
lea    -0x110(%rbp),%r8
mov    $0x2,%ecx
lea    -0x218(%rbp),%r9
call   1050 <redupe_gf_poly_mul@plt>
jmp    1245 <redupe_generator_poly+0x105>
mov    -0x220(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x220(%rbp)
jmp    1188 <redupe_generator_poly+0x48>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     12a2 <redupe_generator_poly+0x162>
mov    -0x10(%rbp),%rdi
lea    -0x210(%rbp),%rsi
mov    -0x21c(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edx
call   1060 <memmove@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cmp    -0x21c(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
jmp    12d7 <redupe_generator_poly+0x197>
mov    -0x10(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    -0x218(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edx
call   1060 <memmove@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cmp    -0x218(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<redupe_generator_poly>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
xor    %edi,%edi
test   %ebx,%ebx
setne  %dil
call   1040 <assert@plt>
movl   $0x1,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movb   $0x1,0x20(%rsp)
test   %ebx,%ebx
je     11ff <redupe_generator_poly+0xbf>
mov    %rbp,0x18(%rsp)
xor    %ebp,%ebp
lea    0x20(%rsp),%r15
lea    0xe(%rsp),%r12
lea    0x120(%rsp),%r13
lea    0x14(%rsp),%r14
jmp    11c1 <redupe_generator_poly+0x81>
mov    0x10(%rsp),%esi
mov    %r13,%rdi
mov    %r12,%rdx
mov    $0x2,%ecx
mov    %r15,%r8
mov    %r14,%r9
call   1050 <redupe_gf_poly_mul@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
je     11f5 <redupe_generator_poly+0xb5>
movb   $0x1,0xe(%rsp)
mov    $0x2,%edi
mov    %ebp,%esi
call   1030 <redupe_gf_pow@plt>
mov    %al,0xf(%rsp)
test   $0x1,%bpl
jne    11a0 <redupe_generator_poly+0x60>
mov    0x14(%rsp),%esi
mov    %r15,%rdi
mov    %r12,%rdx
mov    $0x2,%ecx
mov    %r13,%r8
lea    0x10(%rsp),%r9
jmp    11b5 <redupe_generator_poly+0x75>
test   $0x1,%bl
mov    0x18(%rsp),%rbp
jne    1219 <redupe_generator_poly+0xd9>
mov    0x14(%rsp),%edx
lea    0x20(%rsp),%rsi
mov    %rbp,%rdi
call   1060 <memmove@plt>
add    $0x1,%ebx
cmp    0x14(%rsp),%ebx
jmp    1234 <redupe_generator_poly+0xf4>
mov    0x10(%rsp),%edx
lea    0x120(%rsp),%rsi
mov    %rbp,%rdi
call   1060 <memmove@plt>
add    $0x1,%ebx
cmp    0x10(%rsp),%ebx
sete   %al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @redupe_generator_poly(i32 %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca [2 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = icmp ne i32 %0, 0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%14 = bitcast i32* %6 to i8*
store i32 1, i32* %6
%15 = bitcast i32* %7 to i8*
store i32 0, i32* %7
store i8 1, i8* %11
%16 = icmp eq i32 %0, 0
br i1 %16, label %42, label %17
17: ; preds = %2
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
br label %22
19: ; preds = %33
%20 = and i32 %0, 1
%21 = icmp eq i32 %20, 0
br i1 %21, label %42, label %36
22: ; preds = %17, %33
%23 = phi i32 [ 0, %17 ], [ %34, %33 ]
%24 = and i32 %23, 1
%25 = icmp eq i32 %24, 0
store i8 1, i8* %13
%26 = call zeroext i8 @redupe_gf_pow(i32 2, i32 %23)
store i8 %26, i8* %18
br i1 %25, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* %6
%29 = call i32 @redupe_gf_poly_mul(i8* %11, i32 %28, i8* %13, i32 2, i8* %12, i32* %7)
br label %33
30: ; preds = %22
%31 = load i32, i32* %7
%32 = call i32 @redupe_gf_poly_mul(i8* %12, i32 %31, i8* %13, i32 2, i8* %11, i32* %6)
br label %33
33: ; preds = %27, %30
%34 = add nuw i32 %23, 1
%35 = icmp eq i32 %34, %0
br i1 %35, label %19, label %22
36: ; preds = %19
%37 = load i32, i32* %7
%38 = call i32 @memmove(i8* %1, i8* %12, i32 %37)
%39 = add i32 %0, 1
%40 = load i32, i32* %7
%41 = icmp eq i32 %39, %40
br label %48
42: ; preds = %2, %19
%43 = load i32, i32* %6
%44 = call i32 @memmove(i8* %1, i8* %11, i32 %43)
%45 = add nuw i32 %0, 1
%46 = load i32, i32* %6
%47 = icmp eq i32 %45, %46
br label %48
48: ; preds = %42, %36
%49 = phi i1 [ %47, %42 ], [ %41, %36 ]
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
ret void
}