#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*/ gfexp(unsigned char, int);
unsigned char gfmul(unsigned char, int /*<<< orphan*/);
void polysolve(unsigned char polynom[4], unsigned char roots[3], int *numsol) {
  extern unsigned char e2v[256];
  int i, j;
  unsigned char y;
  *numsol = 0;
  for (i = 0; i < 255; i++) {
    y = 0;
    for (j = 0; j < 4; j++)
      y = ((y) ^ (gfmul(polynom[j], gfexp(e2v[i], j))));
    if (y == 0) {
      roots[*numsol] = e2v[i];
      *numsol = *numsol + 1;
    }
  }
}


x86 assembly (clang, -O0):
<polysolve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xff,-0x1c(%rbp)
jge    1208 <polysolve+0xe8>
movb   $0x0,-0x21(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    11bd <polysolve+0x9d>
movzbl -0x21(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
movslq -0x1c(%rbp),%rcx
mov    0x2e61(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    -0x20(%rbp),%esi
movzbl %al,%edi
call   1030 <gfexp@plt>
mov    %eax,%esi
mov    -0x29(%rbp),%al
movzbl %al,%edi
call   1040 <gfmul@plt>
mov    %al,%cl
mov    -0x28(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115d <polysolve+0x3d>
movzbl -0x21(%rbp),%eax
cmp    $0x0,%eax
jne    11f5 <polysolve+0xd5>
movslq -0x1c(%rbp),%rcx
mov    0x2e13(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11fa <polysolve+0xda>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1145 <polysolve+0x25>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<polysolve>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x8(%rsp)
mov    %rdi,%r12
mov    %rdx,0x10(%rsp)
movl   $0x0,(%rdx)
xor    %r15d,%r15d
jmp    1161 <polysolve+0x41>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    $0xff,%r15
je     121d <polysolve+0xfd>
movzbl (%r12),%ebp
mov    0x2e7b(%rip),%rax
movzbl (%rax,%r15,1),%edi
mov    %rax,%rbx
xor    %esi,%esi
call   1030 <gfexp@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <gfmul@plt>
mov    %eax,%r13d
movzbl 0x1(%r12),%ebp
movzbl (%rbx,%r15,1),%edi
mov    $0x1,%esi
call   1030 <gfexp@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <gfmul@plt>
mov    %eax,%r14d
xor    %r13b,%r14b
movzbl 0x2(%r12),%ebp
movzbl (%rbx,%r15,1),%edi
mov    %rbx,%r13
mov    $0x2,%esi
call   1030 <gfexp@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <gfmul@plt>
mov    %eax,%ebx
xor    %r14b,%bl
movzbl 0x3(%r12),%ebp
movzbl 0x0(%r13,%r15,1),%edi
mov    $0x3,%esi
call   1030 <gfexp@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <gfmul@plt>
cmp    %bl,%al
jne    1150 <polysolve+0x30>
mov    0x2de8(%rip),%rax
movzbl (%rax,%r15,1),%eax
mov    0x10(%rsp),%rdx
movslq (%rdx),%rcx
mov    0x8(%rsp),%rsi
mov    %al,(%rsi,%rcx,1)
addl   $0x1,(%rdx)
jmp    1150 <polysolve+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@e2v = external global [256 x i8]
define void @polysolve(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%10 = load i32*, i32** %6
store i32 0, i32* %10
store i32 0, i32* %7
br label %11
11: ; preds = %58, %3
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 255
br i1 %13, label %14, label %61
14: ; preds = %11
store i8 0, i8* %9
store i32 0, i32* %8
br label %15
15: ; preds = %36, %14
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %39
18: ; preds = %15
%19 = load i8, i8* %9
%20 = zext i8 %19 to i32
%21 = load i8*, i8** %4
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [256 x i8], [256 x i8]* @e2v, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = load i32, i32* %8
%31 = call i32 @gfexp(i8 zeroext %29, i32 %30)
%32 = call zeroext i8 @gfmul(i8 zeroext %25, i32 %31)
%33 = zext i8 %32 to i32
%34 = xor i32 %20, %33
%35 = trunc i32 %34 to i8
store i8 %35, i8* %9
br label %36
36: ; preds = %18
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %15
39: ; preds = %15
%40 = load i8, i8* %9
%41 = zext i8 %40 to i32
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %57
43: ; preds = %39
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [256 x i8], [256 x i8]* @e2v, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = load i8*, i8** %5
%49 = load i32*, i32** %6
%50 = load i32, i32* %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
store i8 %47, i8* %52
%53 = load i32*, i32** %6
%54 = load i32, i32* %53
%55 = add nsw i32 %54, 1
%56 = load i32*, i32** %6
store i32 %55, i32* %56
br label %57
57: ; preds = %43, %39
br label %58
58: ; preds = %57
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %11
61: ; preds = %11
ret void
}

LLVM IR (-O2):
@e2v = external global [256 x i8]
define void @polysolve(i8* nocapture %0, i8* nocapture writeonly %1, i32* nocapture %2) {
store i32 0, i32* %2
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = getelementptr inbounds i8, i8* %0, i64 2
%6 = getelementptr inbounds i8, i8* %0, i64 3
br label %7
7: ; preds = %3, %36
%8 = phi i64 [ 0, %3 ], [ %37, %36 ]
%9 = getelementptr inbounds [256 x i8], [256 x i8]* @e2v, i64 0, i64 %8
%10 = load i8, i8* %0
%11 = load i8, i8* %9
%12 = tail call i32 @gfexp(i8 zeroext %11, i32 0)
%13 = tail call zeroext i8 @gfmul(i8 zeroext %10, i32 %12)
%14 = load i8, i8* %4
%15 = load i8, i8* %9
%16 = tail call i32 @gfexp(i8 zeroext %15, i32 1)
%17 = tail call zeroext i8 @gfmul(i8 zeroext %14, i32 %16)
%18 = xor i8 %17, %13
%19 = load i8, i8* %5
%20 = load i8, i8* %9
%21 = tail call i32 @gfexp(i8 zeroext %20, i32 2)
%22 = tail call zeroext i8 @gfmul(i8 zeroext %19, i32 %21)
%23 = xor i8 %22, %18
%24 = load i8, i8* %6
%25 = load i8, i8* %9
%26 = tail call i32 @gfexp(i8 zeroext %25, i32 3)
%27 = tail call zeroext i8 @gfmul(i8 zeroext %24, i32 %26)
%28 = icmp eq i8 %27, %23
br i1 %28, label %29, label %36
29: ; preds = %7
%30 = load i8, i8* %9
%31 = load i32, i32* %2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %1, i64 %32
store i8 %30, i8* %33
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 1
store i32 %35, i32* %2
br label %36
36: ; preds = %7, %29
%37 = add nuw nsw i64 %8, 1
%38 = icmp eq i64 %37, 255
br i1 %38, label %39, label %7
39: ; preds = %36
ret void
}