#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 */
scalar_t__ redupe_gf_poly_eval(unsigned char const *, unsigned int,
                               int /*<<< orphan*/);
int /*<<< orphan*/ redupe_gf_pow(int, unsigned int);
int redupe_find_errors(const unsigned char *err_loc, unsigned err_loc_sz,
                       unsigned nmess, unsigned char *err_pos,
                       unsigned *err_pos_sz) {
  const unsigned errs = err_loc_sz - 1;
  *err_pos_sz = 0;
  for (unsigned i = 0; i < nmess; ++i) {
    if (redupe_gf_poly_eval(err_loc, err_loc_sz, redupe_gf_pow(2, i)) == 0) {
      err_pos[*err_pos_sz] = nmess - 1 - i;
      ++*err_pos_sz;
    }
  }
  if (*err_pos_sz != errs) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<redupe_find_errors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    11c9 <redupe_find_errors+0xa9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%esi
mov    $0x2,%edi
call   1030 <redupe_gf_pow@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    %eax,%edx
call   1040 <redupe_gf_poly_eval@plt>
cmp    $0x0,%rax
jne    11b6 <redupe_find_errors+0x96>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
sub    -0x30(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rcx),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11bb <redupe_find_errors+0x9b>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1154 <redupe_find_errors+0x34>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
cmp    -0x2c(%rbp),%eax
je     11e4 <redupe_find_errors+0xc4>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <redupe_find_errors+0xcb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<redupe_find_errors>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,(%rsp)
mov    %esi,%r12d
movl   $0x0,(%r8)
test   %edx,%edx
je     11a2 <redupe_find_errors+0x82>
mov    %r8,%r14
mov    %edx,%ebp
mov    %rdi,%r13
mov    %edx,%r15d
neg    %r15d
add    $0xff,%bpl
xor    %ebx,%ebx
jmp    116e <redupe_find_errors+0x4e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebx
add    $0xff,%bpl
mov    %r15d,%eax
add    %ebx,%eax
je     119d <redupe_find_errors+0x7d>
mov    $0x2,%edi
mov    %ebx,%esi
call   1030 <redupe_gf_pow@plt>
mov    %r13,%rdi
mov    %r12d,%esi
mov    %eax,%edx
call   1040 <redupe_gf_poly_eval@plt>
test   %rax,%rax
jne    1160 <redupe_find_errors+0x40>
mov    (%r14),%eax
mov    (%rsp),%rcx
mov    %bpl,(%rcx,%rax,1)
addl   $0x1,(%r14)
jmp    1160 <redupe_find_errors+0x40>
mov    (%r14),%ecx
jmp    11a4 <redupe_find_errors+0x84>
xor    %ecx,%ecx
add    $0xffffffff,%r12d
xor    %eax,%eax
cmp    %r12d,%ecx
setne  %al
neg    %eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @redupe_find_errors(i8* %0, i32 %1, i32 %2, i8* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32* %4, i32** %11
%14 = load i32, i32* %8
%15 = sub i32 %14, 1
store i32 %15, i32* %12
%16 = load i32*, i32** %11
store i32 0, i32* %16
store i32 0, i32* %13
br label %17
17: ; preds = %43, %5
%18 = load i32, i32* %13
%19 = load i32, i32* %9
%20 = icmp ult i32 %18, %19
br i1 %20, label %21, label %46
21: ; preds = %17
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = load i32, i32* %13
%25 = call i32 @redupe_gf_pow(i32 2, i32 %24)
%26 = call i64 @redupe_gf_poly_eval(i8* %22, i32 %23, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %42
28: ; preds = %21
%29 = load i32, i32* %9
%30 = sub i32 %29, 1
%31 = load i32, i32* %13
%32 = sub i32 %30, %31
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %10
%35 = load i32*, i32** %11
%36 = load i32, i32* %35
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
store i8 %33, i8* %38
%39 = load i32*, i32** %11
%40 = load i32, i32* %39
%41 = add i32 %40, 1
store i32 %41, i32* %39
br label %42
42: ; preds = %28, %21
br label %43
43: ; preds = %42
%44 = load i32, i32* %13
%45 = add i32 %44, 1
store i32 %45, i32* %13
br label %17
46: ; preds = %17
%47 = load i32*, i32** %11
%48 = load i32, i32* %47
%49 = load i32, i32* %12
%50 = icmp ne i32 %48, %49
br i1 %50, label %51, label %52
51: ; preds = %46
store i32 -1, i32* %6
br label %53
52: ; preds = %46
store i32 0, i32* %6
br label %53
53: ; preds = %52, %51
%54 = load i32, i32* %6
ret i32 %54
}

LLVM IR (-O2):
define i32 @redupe_find_errors(i8* %0, i32 %1, i32 %2, i8* nocapture writeonly %3, i32* nocapture %4) {
store i32 0, i32* %4
%6 = icmp eq i32 %2, 0
br i1 %6, label %9, label %14
7: ; preds = %28
%8 = load i32, i32* %4
br label %9
9: ; preds = %7, %5
%10 = phi i32 [ %8, %7 ], [ 0, %5 ]
%11 = add i32 %1, -1
%12 = icmp ne i32 %10, %11
%13 = sext i1 %12 to i32
ret i32 %13
14: ; preds = %5, %28
%15 = phi i32 [ %29, %28 ], [ 0, %5 ]
%16 = tail call i32 @redupe_gf_pow(i32 2, i32 %15)
%17 = tail call i64 @redupe_gf_poly_eval(i8* %0, i32 %1, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %14
%20 = xor i32 %15, -1
%21 = add i32 %20, %2
%22 = trunc i32 %21 to i8
%23 = load i32, i32* %4
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %3, i64 %24
store i8 %22, i8* %25
%26 = load i32, i32* %4
%27 = add i32 %26, 1
store i32 %27, i32* %4
br label %28
28: ; preds = %14, %19
%29 = add nuw i32 %15, 1
%30 = icmp eq i32 %29, %2
br i1 %30, label %7, label %14
}