#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 */
unsigned char const redupe_gf_mul(unsigned int, unsigned int);
unsigned redupe_gf_poly_eval(const unsigned char *poly, unsigned poly_sz,
                             unsigned x) {
  if (poly_sz == 0) {
    return 0;
  }
  unsigned y = poly[0];
  for (unsigned i = 1; i < poly_sz; ++i) {
    y = redupe_gf_mul(y, x) ^ poly[i];
  }
  return y;
}


x86 assembly (clang, -O0):
<redupe_gf_poly_eval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1138 <redupe_gf_poly_eval+0x28>
movl   $0x0,-0x4(%rbp)
jmp    1187 <redupe_gf_poly_eval+0x77>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1181 <redupe_gf_poly_eval+0x71>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <redupe_gf_mul@plt>
movzbl %al,%eax
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%edx
movzbl (%rcx,%rdx,1),%ecx
xor    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1149 <redupe_gf_poly_eval+0x39>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<redupe_gf_poly_eval>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
je     114a <redupe_gf_poly_eval+0x3a>
mov    %rdi,%r15
movzbl (%rdi),%edi
cmp    $0x1,%esi
je     114c <redupe_gf_poly_eval+0x3c>
mov    %edx,%r14d
mov    %esi,%ebp
mov    $0x1,%ebx
mov    %r14d,%esi
call   1030 <redupe_gf_mul@plt>
xor    (%r15,%rbx,1),%al
add    $0x1,%rbx
movzbl %al,%edi
cmp    %rbx,%rbp
jne    1130 <redupe_gf_poly_eval+0x20>
jmp    114c <redupe_gf_poly_eval+0x3c>
xor    %edi,%edi
mov    %edi,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @redupe_gf_poly_eval(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 0, i32* %4
br label %39
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
store i32 %17, i32* %8
store i32 1, i32* %9
br label %18
18: ; preds = %34, %13
%19 = load i32, i32* %9
%20 = load i32, i32* %6
%21 = icmp ult i32 %19, %20
br i1 %21, label %22, label %37
22: ; preds = %18
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = call zeroext i8 @redupe_gf_mul(i32 %23, i32 %24)
%26 = zext i8 %25 to i32
%27 = load i8*, i8** %5
%28 = load i32, i32* %9
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = xor i32 %26, %32
store i32 %33, i32* %8
br label %34
34: ; preds = %22
%35 = load i32, i32* %9
%36 = add i32 %35, 1
store i32 %36, i32* %9
br label %18
37: ; preds = %18
%38 = load i32, i32* %8
store i32 %38, i32* %4
br label %39
39: ; preds = %37, %12
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
define i32 @redupe_gf_poly_eval(i8* nocapture %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %21, label %5
5: ; preds = %3
%6 = load i8, i8* %0
%7 = zext i8 %6 to i32
%8 = icmp eq i32 %1, 1
br i1 %8, label %21, label %9
9: ; preds = %5
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 1, %9 ], [ %18, %11 ]
%13 = phi i32 [ %7, %9 ], [ %19, %11 ]
%14 = tail call zeroext i8 @redupe_gf_mul(i32 %13, i32 %2)
%15 = getelementptr inbounds i8, i8* %0, i64 %12
%16 = load i8, i8* %15
%17 = xor i8 %16, %14
%18 = add nuw nsw i64 %12, 1
%19 = zext i8 %17 to i32
%20 = icmp eq i64 %18, %10
br i1 %20, label %21, label %11
21: ; preds = %11, %5, %3
%22 = phi i32 [ 0, %3 ], [ %7, %5 ], [ %19, %11 ]
ret i32 %22
}