#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*/ memmove(unsigned char *, unsigned char *, unsigned int);
int /*<<< orphan*/ redupe_gf_poly_add(unsigned char *, int, unsigned char *,
                                      int, unsigned char *, unsigned int *);
int /*<<< orphan*/ redupe_gf_poly_mul(unsigned char *, unsigned int,
                                      unsigned char *, unsigned int,
                                      unsigned char *, unsigned int *);
unsigned char redupe_gf_pow(int, unsigned char const);
void redupe_find_errata_locator(const unsigned char *err_pos,
                                unsigned err_pos_sz, unsigned char *err_loc,
                                unsigned *err_loc_sz) {
  *err_loc_sz = 1;
  err_loc[0] = 1;
  for (unsigned i = 0; i < err_pos_sz; ++i) {
    unsigned char A[] = {1};
    unsigned char B[] = {redupe_gf_pow(2, err_pos[i]), 0};
    unsigned char tmpa[256];
    unsigned tmpa_sz = 0;
    redupe_gf_poly_add(A, 1, B, 2, tmpa, &tmpa_sz);
    unsigned char tmpe[256];
    unsigned tmpe_sz = *err_loc_sz;
    memmove(tmpe, err_loc, tmpe_sz);
    redupe_gf_poly_mul(tmpe, tmpe_sz, tmpa, tmpa_sz, err_loc, err_loc_sz);
  }
}


x86 assembly (clang, -O0):
<redupe_find_errata_locator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x1,(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1229 <redupe_find_errata_locator+0xe9>
mov    0xe7c(%rip),%al
mov    %al,-0x25(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    $0x2,%edi
movzbl (%rax,%rcx,1),%esi
call   1030 <redupe_gf_pow@plt>
mov    %al,-0x27(%rbp)
movb   $0x0,-0x26(%rbp)
movl   $0x0,-0x134(%rbp)
lea    -0x25(%rbp),%rdi
lea    -0x27(%rbp),%rdx
lea    -0x130(%rbp),%r8
mov    $0x1,%esi
mov    $0x2,%ecx
lea    -0x134(%rbp),%r9
call   1050 <redupe_gf_poly_add@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x244(%rbp)
lea    -0x240(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x244(%rbp),%edx
call   1060 <memmove@plt>
lea    -0x240(%rbp),%rdi
mov    -0x244(%rbp),%esi
lea    -0x130(%rbp),%rdx
mov    -0x134(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
call   1040 <redupe_gf_poly_mul@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1172 <redupe_find_errata_locator+0x32>
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<redupe_find_errata_locator>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
movl   $0x1,(%rcx)
movb   $0x1,(%rdx)
test   %esi,%esi
je     1210 <redupe_find_errata_locator+0xd0>
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %esi,%eax
mov    %rax,0x18(%rsp)
xor    %r15d,%r15d
mov    %rdi,0x10(%rsp)
nopw   0x0(%rax,%rax,1)
movb   $0x1,0x9(%rsp)
movzbl (%rdi,%r15,1),%esi
mov    $0x2,%edi
call   1030 <redupe_gf_pow@plt>
mov    %al,0xa(%rsp)
movb   $0x0,0xb(%rsp)
movl   $0x0,0xc(%rsp)
lea    0x9(%rsp),%rdi
mov    $0x1,%esi
lea    0xa(%rsp),%rdx
mov    $0x2,%ecx
lea    0x120(%rsp),%r13
mov    %r13,%r8
lea    0xc(%rsp),%r9
call   1050 <redupe_gf_poly_add@plt>
mov    (%rbx),%r12d
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
call   1060 <memmove@plt>
mov    0xc(%rsp),%ecx
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r13,%rdx
mov    %rbp,%r8
mov    %rbx,%r9
call   1040 <redupe_gf_poly_mul@plt>
mov    0x10(%rsp),%rdi
add    $0x1,%r15
cmp    %r15,0x18(%rsp)
jne    1180 <redupe_find_errata_locator+0x40>
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @redupe_find_errata_locator(i8* nocapture %0, i32 %1, i8* %2, i32* %3) {
%5 = alloca [1 x i8]
%6 = alloca [2 x i8]
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = alloca [256 x i8]
store i32 1, i32* %3
store i8 1, i8* %2
%10 = icmp eq i32 %1, 0
br i1 %10, label %19, label %11
11: ; preds = %4
%12 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%16 = bitcast i32* %8 to i8*
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%18 = zext i32 %1 to i64
br label %20
19: ; preds = %20, %4
ret void
20: ; preds = %11, %20
%21 = phi i64 [ 0, %11 ], [ %30, %20 ]
store i8 1, i8* %12
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = call zeroext i8 @redupe_gf_pow(i32 2, i8 zeroext %23)
store i8 %24, i8* %13
store i8 0, i8* %14
store i32 0, i32* %8
%25 = call i32 @redupe_gf_poly_add(i8* %12, i32 1, i8* %13, i32 2, i8* %15, i32* %8)
%26 = load i32, i32* %3
%27 = call i32 @memmove(i8* %17, i8* %2, i32 %26)
%28 = load i32, i32* %8
%29 = call i32 @redupe_gf_poly_mul(i8* %17, i32 %26, i8* %15, i32 %28, i8* %2, i32* %3)
%30 = add nuw nsw i64 %21, 1
%31 = icmp eq i64 %30, %18
br i1 %31, label %19, label %20
}