#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 EINVAL;
int err_pos(unsigned short);
int /*<<< orphan*/ find_2bit_err_pats(unsigned short, unsigned short,
                                      unsigned short, unsigned short,
                                      unsigned short *);
int /*<<< orphan*/ find_2x2_soln(unsigned short, unsigned short, unsigned short,
                                 unsigned short, unsigned short, unsigned short,
                                 unsigned short *);
unsigned short gf4096_inv(unsigned short);
unsigned short gf4096_mul(unsigned short, unsigned short);
int chk_2_err_only(unsigned short *chk_syndrome_list,
                   unsigned short *err_info) {
  unsigned short tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  unsigned short coefs[4];
  unsigned short err_pats[4];
  int found_num_root = 0;
  unsigned short bit2_root0, bit2_root1;
  unsigned short bit2_root0_inv, bit2_root1_inv;
  unsigned short err_loc_eqn, test_root;
  unsigned short bit2_loc0, bit2_loc1;
  unsigned short bit2_pat0, bit2_pat1;
  find_2x2_soln(chk_syndrome_list[1], chk_syndrome_list[0],
                chk_syndrome_list[2], chk_syndrome_list[1],
                chk_syndrome_list[2], chk_syndrome_list[3], coefs);
  for (test_root = 0x1; test_root < 0xfff; test_root++) {
    err_loc_eqn = gf4096_mul(coefs[1], gf4096_mul(test_root, test_root)) ^
                  gf4096_mul(coefs[0], test_root) ^ 0x1;
    if (err_loc_eqn == 0x0) {
      if (found_num_root == 0) {
        bit2_root0 = test_root;
        found_num_root = 1;
      } else if (found_num_root == 1) {
        bit2_root1 = test_root;
        found_num_root = 2;
        break;
      }
    }
  }
  if (found_num_root != 2)
    return -EINVAL;
  else {
    bit2_root0_inv = gf4096_inv(bit2_root0);
    bit2_root1_inv = gf4096_inv(bit2_root1);
    find_2bit_err_pats(chk_syndrome_list[0], chk_syndrome_list[1],
                       bit2_root0_inv, bit2_root1_inv, err_pats);
    bit2_pat0 = err_pats[0];
    bit2_pat1 = err_pats[1];
    tmp0 = gf4096_mul(gf4096_mul(bit2_root0_inv, bit2_root0_inv),
                      gf4096_mul(bit2_root0_inv, bit2_root0_inv));
    tmp1 = gf4096_mul(bit2_root0_inv, tmp0);
    tmp2 = gf4096_mul(bit2_root0_inv, tmp1);
    tmp3 = gf4096_mul(bit2_root0_inv, tmp2);
    tmp4 = gf4096_mul(gf4096_mul(bit2_root1_inv, bit2_root1_inv),
                      gf4096_mul(bit2_root1_inv, bit2_root1_inv));
    tmp5 = gf4096_mul(bit2_root1_inv, tmp4);
    tmp6 = gf4096_mul(bit2_root1_inv, tmp5);
    tmp7 = gf4096_mul(bit2_root1_inv, tmp6);
    if ((chk_syndrome_list[4] ==
         (gf4096_mul(bit2_pat0, tmp0) ^ gf4096_mul(bit2_pat1, tmp4))) &
        (chk_syndrome_list[5] ==
         (gf4096_mul(bit2_pat0, tmp1) ^ gf4096_mul(bit2_pat1, tmp5))) &
        (chk_syndrome_list[6] ==
         (gf4096_mul(bit2_pat0, tmp2) ^ gf4096_mul(bit2_pat1, tmp6))) &
        (chk_syndrome_list[7] ==
         (gf4096_mul(bit2_pat0, tmp3) ^ gf4096_mul(bit2_pat1, tmp7)))) {
      if ((err_pos(bit2_root0_inv) == 0xfff) |
          (err_pos(bit2_root1_inv) == 0xfff)) {
        return -EINVAL;
      } else {
        bit2_loc0 = 0x55e - err_pos(bit2_root0_inv);
        bit2_loc1 = 0x55e - err_pos(bit2_root1_inv);
        err_info[0] = 0x2;
        err_info[1] = bit2_loc0;
        err_info[2] = bit2_loc1;
        err_info[5] = bit2_pat0;
        err_info[6] = bit2_pat1;
        return 0;
      }
    } else
      return -EINVAL;
  }
}


x86 assembly (clang, -O0):
<chk_2_err_only>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%di
mov    -0x10(%rbp),%rax
mov    (%rax),%si
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%dx
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%cx
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%r8w
mov    -0x10(%rbp),%rax
mov    0x6(%rax),%r9w
lea    -0x30(%rbp),%rax
movzwl %di,%edi
movzwl %si,%esi
movzwl %dx,%edx
movzwl %cx,%ecx
movzwl %r8w,%r8d
movzwl %r9w,%r9d
mov    %rax,(%rsp)
call   1050 <find_2x2_soln@plt>
movw   $0x1,-0x48(%rbp)
movzwl -0x48(%rbp),%eax
cmp    $0xfff,%eax
jge    1289 <chk_2_err_only+0x139>
mov    -0x2e(%rbp),%ax
mov    %ax,-0x56(%rbp)
mov    -0x48(%rbp),%ax
movzwl %ax,%edi
movzwl -0x48(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    -0x56(%rbp),%cx
movzwl %cx,%edi
movzwl %ax,%esi
call   1040 <gf4096_mul@plt>
movzwl %ax,%eax
mov    %eax,-0x54(%rbp)
mov    -0x30(%rbp),%ax
movzwl %ax,%edi
movzwl -0x48(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    %ax,%cx
mov    -0x54(%rbp),%eax
movzwl %cx,%ecx
xor    %ecx,%eax
xor    $0x1,%eax
mov    %ax,-0x46(%rbp)
movzwl -0x46(%rbp),%eax
cmp    $0x0,%eax
jne    1273 <chk_2_err_only+0x123>
cmpl   $0x0,-0x3c(%rbp)
jne    124b <chk_2_err_only+0xfb>
mov    -0x48(%rbp),%ax
mov    %ax,-0x3e(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    126e <chk_2_err_only+0x11e>
cmpl   $0x1,-0x3c(%rbp)
jne    1269 <chk_2_err_only+0x119>
mov    -0x48(%rbp),%ax
mov    %ax,-0x40(%rbp)
movl   $0x2,-0x3c(%rbp)
jmp    1289 <chk_2_err_only+0x139>
jmp    126e <chk_2_err_only+0x11e>
jmp    1273 <chk_2_err_only+0x123>
jmp    1278 <chk_2_err_only+0x128>
mov    -0x48(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x48(%rbp)
jmp    11c2 <chk_2_err_only+0x72>
cmpl   $0x2,-0x3c(%rbp)
je     12a6 <chk_2_err_only+0x156>
xor    %eax,%eax
mov    0x2d44(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1615 <chk_2_err_only+0x4c5>
movzwl -0x3e(%rbp),%edi
call   1070 <gf4096_inv@plt>
mov    %ax,-0x42(%rbp)
movzwl -0x40(%rbp),%edi
call   1070 <gf4096_inv@plt>
mov    %ax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%si
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%dx
mov    -0x42(%rbp),%cx
mov    -0x44(%rbp),%ax
lea    -0x38(%rbp),%r8
movzwl %si,%edi
movzwl %dx,%esi
movzwl %cx,%edx
movzwl %ax,%ecx
call   1060 <find_2bit_err_pats@plt>
mov    -0x38(%rbp),%ax
mov    %ax,-0x4e(%rbp)
mov    -0x36(%rbp),%ax
mov    %ax,-0x50(%rbp)
mov    -0x42(%rbp),%ax
movzwl %ax,%edi
movzwl -0x42(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    %ax,-0x88(%rbp)
mov    -0x42(%rbp),%ax
movzwl %ax,%edi
movzwl -0x42(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    -0x88(%rbp),%cx
movzwl %cx,%edi
movzwl %ax,%esi
call   1040 <gf4096_mul@plt>
mov    %ax,-0x1a(%rbp)
mov    -0x42(%rbp),%ax
movzwl %ax,%edi
movzwl -0x1a(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    %ax,-0x1c(%rbp)
mov    -0x42(%rbp),%ax
movzwl %ax,%edi
movzwl -0x1c(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    %ax,-0x1e(%rbp)
mov    -0x42(%rbp),%ax
movzwl %ax,%edi
movzwl -0x1e(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    %ax,-0x20(%rbp)
mov    -0x44(%rbp),%ax
movzwl %ax,%edi
movzwl -0x44(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    %ax,-0x86(%rbp)
mov    -0x44(%rbp),%ax
movzwl %ax,%edi
movzwl -0x44(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    -0x86(%rbp),%cx
movzwl %cx,%edi
movzwl %ax,%esi
call   1040 <gf4096_mul@plt>
mov    %ax,-0x22(%rbp)
mov    -0x44(%rbp),%ax
movzwl %ax,%edi
movzwl -0x22(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    %ax,-0x24(%rbp)
mov    -0x44(%rbp),%ax
movzwl %ax,%edi
movzwl -0x24(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    %ax,-0x26(%rbp)
mov    -0x44(%rbp),%ax
movzwl %ax,%edi
movzwl -0x26(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    %ax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movzwl 0x8(%rax),%eax
mov    %eax,-0x80(%rbp)
mov    -0x4e(%rbp),%ax
movzwl %ax,%edi
movzwl -0x1a(%rbp),%esi
call   1040 <gf4096_mul@plt>
movzwl %ax,%eax
mov    %eax,-0x84(%rbp)
mov    -0x50(%rbp),%ax
movzwl %ax,%edi
movzwl -0x22(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    -0x84(%rbp),%ecx
mov    %ax,%dx
mov    -0x80(%rbp),%eax
movzwl %dx,%edx
xor    %edx,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x74(%rbp)
mov    -0x10(%rbp),%rax
movzwl 0xa(%rax),%eax
mov    %eax,-0x78(%rbp)
mov    -0x4e(%rbp),%ax
movzwl %ax,%edi
movzwl -0x1c(%rbp),%esi
call   1040 <gf4096_mul@plt>
movzwl %ax,%eax
mov    %eax,-0x7c(%rbp)
mov    -0x50(%rbp),%ax
movzwl %ax,%edi
movzwl -0x24(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    -0x7c(%rbp),%edx
mov    -0x78(%rbp),%ecx
mov    %ax,%si
mov    -0x74(%rbp),%eax
movzwl %si,%esi
xor    %esi,%edx
cmp    %edx,%ecx
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
mov    %eax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
movzwl 0xc(%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x4e(%rbp),%ax
movzwl %ax,%edi
movzwl -0x1e(%rbp),%esi
call   1040 <gf4096_mul@plt>
movzwl %ax,%eax
mov    %eax,-0x70(%rbp)
mov    -0x50(%rbp),%ax
movzwl %ax,%edi
movzwl -0x26(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    -0x70(%rbp),%edx
mov    -0x6c(%rbp),%ecx
mov    %ax,%si
mov    -0x68(%rbp),%eax
movzwl %si,%esi
xor    %esi,%edx
cmp    %edx,%ecx
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
movzwl 0xe(%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x4e(%rbp),%ax
movzwl %ax,%edi
movzwl -0x20(%rbp),%esi
call   1040 <gf4096_mul@plt>
movzwl %ax,%eax
mov    %eax,-0x64(%rbp)
mov    -0x50(%rbp),%ax
movzwl %ax,%edi
movzwl -0x28(%rbp),%esi
call   1040 <gf4096_mul@plt>
mov    -0x64(%rbp),%edx
mov    -0x60(%rbp),%ecx
mov    %ax,%si
mov    -0x5c(%rbp),%eax
movzwl %si,%esi
xor    %esi,%edx
cmp    %edx,%ecx
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1607 <chk_2_err_only+0x4b7>
movzwl -0x42(%rbp),%edi
call   1030 <err_pos@plt>
cmp    $0xfff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x8c(%rbp)
movzwl -0x44(%rbp),%edi
call   1030 <err_pos@plt>
mov    %eax,%ecx
mov    -0x8c(%rbp),%eax
cmp    $0xfff,%ecx
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
cmp    $0x0,%eax
je     1596 <chk_2_err_only+0x446>
xor    %eax,%eax
mov    0x2a54(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1615 <chk_2_err_only+0x4c5>
movzwl -0x42(%rbp),%edi
call   1030 <err_pos@plt>
mov    %eax,%ecx
mov    $0x55e,%eax
sub    %ecx,%eax
mov    %ax,-0x4a(%rbp)
movzwl -0x44(%rbp),%edi
call   1030 <err_pos@plt>
mov    %eax,%ecx
mov    $0x55e,%eax
sub    %ecx,%eax
mov    %ax,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
movw   $0x2,(%rax)
mov    -0x4a(%rbp),%cx
mov    -0x18(%rbp),%rax
mov    %cx,0x2(%rax)
mov    -0x4c(%rbp),%cx
mov    -0x18(%rbp),%rax
mov    %cx,0x4(%rax)
mov    -0x4e(%rbp),%cx
mov    -0x18(%rbp),%rax
mov    %cx,0xa(%rax)
mov    -0x50(%rbp),%cx
mov    -0x18(%rbp),%rax
mov    %cx,0xc(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1615 <chk_2_err_only+0x4c5>
xor    %eax,%eax
mov    0x29d0(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chk_2_err_only>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,0x40(%rsp)
mov    %rdi,%r13
movzwl 0x2(%rdi),%ecx
movzwl (%rdi),%esi
movzwl 0x4(%rdi),%edx
movzwl 0x6(%rdi),%r9d
lea    0x38(%rsp),%rax
mov    %rax,(%rsp)
mov    %ecx,%edi
mov    %edx,%r8d
call   1050 <find_2x2_soln@plt>
mov    $0x1,%bx
xor    %r15d,%r15d
jmp    11b8 <chk_2_err_only+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12d,%eax
add    $0x1,%ebx
movzwl %bx,%ecx
mov    %eax,%r12d
cmp    $0xfff,%ecx
je     1427 <chk_2_err_only+0x2d7>
movzwl 0x3a(%rsp),%r14d
movzwl %bx,%ebp
mov    %ebp,%edi
mov    %ebp,%esi
call   1040 <gf4096_mul@plt>
movzwl %ax,%esi
mov    %r14d,%edi
call   1040 <gf4096_mul@plt>
mov    %eax,%r14d
movzwl 0x38(%rsp),%edi
mov    %ebp,%esi
call   1040 <gf4096_mul@plt>
xor    %r14d,%eax
cmp    $0x1,%ax
jne    11a0 <chk_2_err_only+0x50>
mov    %ebx,%eax
test   %r15d,%r15d
mov    $0x1,%r15d
je     11a3 <chk_2_err_only+0x53>
movzwl %r12w,%edi
call   1070 <gf4096_inv@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1070 <gf4096_inv@plt>
movzwl 0x0(%r13),%edi
movzwl 0x2(%r13),%esi
movzwl %bx,%ebx
movzwl %ax,%ebp
lea    0x30(%rsp),%r8
mov    %ebx,%edx
mov    %ebp,%ecx
call   1060 <find_2bit_err_pats@plt>
movzwl 0x30(%rsp),%r14d
movzwl 0x32(%rsp),%eax
mov    %ax,0xa(%rsp)
mov    %ebx,%edi
mov    %ebx,%esi
call   1040 <gf4096_mul@plt>
mov    %eax,%r15d
mov    %ebx,%edi
mov    %ebx,%esi
call   1040 <gf4096_mul@plt>
movzwl %r15w,%edi
movzwl %ax,%esi
call   1040 <gf4096_mul@plt>
movzwl %ax,%r15d
mov    %ebx,%edi
mov    %r15d,%esi
call   1040 <gf4096_mul@plt>
movzwl %ax,%esi
mov    %esi,0x10(%rsp)
mov    %ebx,%edi
call   1040 <gf4096_mul@plt>
movzwl %ax,%esi
mov    %esi,0x14(%rsp)
mov    %ebx,0x24(%rsp)
mov    %ebx,%edi
call   1040 <gf4096_mul@plt>
mov    %ax,0x22(%rsp)
mov    %ebp,%edi
mov    %ebp,%esi
call   1040 <gf4096_mul@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %ebp,%esi
call   1040 <gf4096_mul@plt>
movzwl %bx,%edi
movzwl %ax,%esi
call   1040 <gf4096_mul@plt>
movzwl %ax,%r12d
mov    %ebp,%edi
mov    %r12d,%esi
call   1040 <gf4096_mul@plt>
movzwl %ax,%esi
mov    %esi,0xc(%rsp)
mov    %ebp,%edi
call   1040 <gf4096_mul@plt>
movzwl %ax,%esi
mov    %esi,0x2c(%rsp)
mov    %ebp,0x28(%rsp)
mov    %ebp,%edi
call   1040 <gf4096_mul@plt>
mov    %ax,0x1e(%rsp)
movzwl 0x8(%r13),%eax
mov    %ax,0x20(%rsp)
mov    %r14w,0x1a(%rsp)
movzwl %r14w,%r14d
mov    %r14d,%edi
mov    %r15d,%esi
call   1040 <gf4096_mul@plt>
mov    %eax,%r15d
movzwl 0xa(%rsp),%ebp
mov    %ebp,%edi
mov    %r12d,%esi
call   1040 <gf4096_mul@plt>
mov    %eax,%ebx
xor    %r15d,%ebx
movzwl 0xa(%r13),%eax
mov    %ax,0x1c(%rsp)
mov    %r14d,%edi
mov    0x10(%rsp),%esi
call   1040 <gf4096_mul@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
mov    0xc(%rsp),%esi
call   1040 <gf4096_mul@plt>
mov    %eax,%r15d
movzwl 0xc(%r13),%eax
mov    %ax,0xc(%rsp)
mov    %r14d,%edi
mov    0x14(%rsp),%esi
call   1040 <gf4096_mul@plt>
mov    %eax,0x14(%rsp)
mov    %ebp,%edi
mov    0x2c(%rsp),%esi
call   1040 <gf4096_mul@plt>
mov    %eax,%r12d
movzwl 0xe(%r13),%r13d
movzwl 0x22(%rsp),%esi
mov    %r14d,%edi
call   1040 <gf4096_mul@plt>
mov    %eax,%r14d
movzwl 0x1e(%rsp),%esi
mov    %ebp,%edi
call   1040 <gf4096_mul@plt>
cmp    %bx,0x20(%rsp)
jne    1427 <chk_2_err_only+0x2d7>
xor    0x10(%rsp),%r15d
cmp    %r15w,0x1c(%rsp)
jne    1427 <chk_2_err_only+0x2d7>
xor    0x14(%rsp),%r12d
cmp    %r12w,0xc(%rsp)
jne    1427 <chk_2_err_only+0x2d7>
xor    %r14d,%eax
cmp    %ax,%r13w
jne    1427 <chk_2_err_only+0x2d7>
mov    0x24(%rsp),%ebp
mov    %ebp,%edi
call   1030 <err_pos@plt>
mov    %eax,%ebx
mov    0x28(%rsp),%r14d
mov    %r14d,%edi
call   1030 <err_pos@plt>
cmp    $0xfff,%ebx
je     1427 <chk_2_err_only+0x2d7>
cmp    $0xfff,%eax
je     1427 <chk_2_err_only+0x2d7>
mov    %ebp,%edi
call   1030 <err_pos@plt>
mov    $0x55e,%ebx
mov    $0x55e,%ebp
sub    %eax,%ebp
mov    %r14d,%edi
call   1030 <err_pos@plt>
sub    %eax,%ebx
mov    0x40(%rsp),%rax
movw   $0x2,(%rax)
mov    %bp,0x2(%rax)
mov    %bx,0x4(%rax)
movzwl 0x1a(%rsp),%ecx
mov    %cx,0xa(%rax)
movzwl 0xa(%rsp),%ecx
mov    %cx,0xc(%rax)
xor    %eax,%eax
jmp    1432 <chk_2_err_only+0x2e2>
mov    0x2bb2(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EINVAL = global i32 0
define i32 @chk_2_err_only(i16* %0, i16* %1) {
%3 = alloca i32
%4 = alloca i16*
%5 = alloca i16*
%6 = alloca i16
%7 = alloca i16
%8 = alloca i16
%9 = alloca i16
%10 = alloca i16
%11 = alloca i16
%12 = alloca i16
%13 = alloca i16
%14 = alloca [4 x i16]
%15 = alloca [4 x i16]
%16 = alloca i32
%17 = alloca i16
%18 = alloca i16
%19 = alloca i16
%20 = alloca i16
%21 = alloca i16
%22 = alloca i16
%23 = alloca i16
%24 = alloca i16
%25 = alloca i16
%26 = alloca i16
store i16* %0, i16** %4
store i16* %1, i16** %5
store i32 0, i32* %16
%27 = load i16*, i16** %4
%28 = getelementptr inbounds i16, i16* %27, i64 1
%29 = load i16, i16* %28
%30 = load i16*, i16** %4
%31 = getelementptr inbounds i16, i16* %30, i64 0
%32 = load i16, i16* %31
%33 = load i16*, i16** %4
%34 = getelementptr inbounds i16, i16* %33, i64 2
%35 = load i16, i16* %34
%36 = load i16*, i16** %4
%37 = getelementptr inbounds i16, i16* %36, i64 1
%38 = load i16, i16* %37
%39 = load i16*, i16** %4
%40 = getelementptr inbounds i16, i16* %39, i64 2
%41 = load i16, i16* %40
%42 = load i16*, i16** %4
%43 = getelementptr inbounds i16, i16* %42, i64 3
%44 = load i16, i16* %43
%45 = getelementptr inbounds [4 x i16], [4 x i16]* %14, i64 0, i64 0
%46 = call i32 @find_2x2_soln(i16 zeroext %29, i16 zeroext %32, i16 zeroext %35, i16 zeroext %38, i16 zeroext %41, i16 zeroext %44, i16* %45)
store i16 1, i16* %22
br label %47
47: ; preds = %83, %2
%48 = load i16, i16* %22
%49 = zext i16 %48 to i32
%50 = icmp slt i32 %49, 4095
br i1 %50, label %51, label %86
51: ; preds = %47
%52 = getelementptr inbounds [4 x i16], [4 x i16]* %14, i64 0, i64 1
%53 = load i16, i16* %52
%54 = load i16, i16* %22
%55 = load i16, i16* %22
%56 = call zeroext i16 @gf4096_mul(i16 zeroext %54, i16 zeroext %55)
%57 = call zeroext i16 @gf4096_mul(i16 zeroext %53, i16 zeroext %56)
%58 = zext i16 %57 to i32
%59 = getelementptr inbounds [4 x i16], [4 x i16]* %14, i64 0, i64 0
%60 = load i16, i16* %59
%61 = load i16, i16* %22
%62 = call zeroext i16 @gf4096_mul(i16 zeroext %60, i16 zeroext %61)
%63 = zext i16 %62 to i32
%64 = xor i32 %58, %63
%65 = xor i32 %64, 1
%66 = trunc i32 %65 to i16
store i16 %66, i16* %21
%67 = load i16, i16* %21
%68 = zext i16 %67 to i32
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %82
70: ; preds = %51
%71 = load i32, i32* %16
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = load i16, i16* %22
store i16 %74, i16* %17
store i32 1, i32* %16
br label %81
75: ; preds = %70
%76 = load i32, i32* %16
%77 = icmp eq i32 %76, 1
br i1 %77, label %78, label %80
78: ; preds = %75
%79 = load i16, i16* %22
store i16 %79, i16* %18
store i32 2, i32* %16
br label %86
80: ; preds = %75
br label %81
81: ; preds = %80, %73
br label %82
82: ; preds = %81, %51
br label %83
83: ; preds = %82
%84 = load i16, i16* %22
%85 = add i16 %84, 1
store i16 %85, i16* %22
br label %47
86: ; preds = %78, %47
%87 = load i32, i32* %16
%88 = icmp ne i32 %87, 2
br i1 %88, label %89, label %92
89: ; preds = %86
%90 = load i32, i32* @EINVAL
%91 = sub nsw i32 0, %90
store i32 %91, i32* %3
br label %247
92: ; preds = %86
%93 = load i16, i16* %17
%94 = call zeroext i16 @gf4096_inv(i16 zeroext %93)
store i16 %94, i16* %19
%95 = load i16, i16* %18
%96 = call zeroext i16 @gf4096_inv(i16 zeroext %95)
store i16 %96, i16* %20
%97 = load i16*, i16** %4
%98 = getelementptr inbounds i16, i16* %97, i64 0
%99 = load i16, i16* %98
%100 = load i16*, i16** %4
%101 = getelementptr inbounds i16, i16* %100, i64 1
%102 = load i16, i16* %101
%103 = load i16, i16* %19
%104 = load i16, i16* %20
%105 = getelementptr inbounds [4 x i16], [4 x i16]* %15, i64 0, i64 0
%106 = call i32 @find_2bit_err_pats(i16 zeroext %99, i16 zeroext %102, i16 zeroext %103, i16 zeroext %104, i16* %105)
%107 = getelementptr inbounds [4 x i16], [4 x i16]* %15, i64 0, i64 0
%108 = load i16, i16* %107
store i16 %108, i16* %25
%109 = getelementptr inbounds [4 x i16], [4 x i16]* %15, i64 0, i64 1
%110 = load i16, i16* %109
store i16 %110, i16* %26
%111 = load i16, i16* %19
%112 = load i16, i16* %19
%113 = call zeroext i16 @gf4096_mul(i16 zeroext %111, i16 zeroext %112)
%114 = load i16, i16* %19
%115 = load i16, i16* %19
%116 = call zeroext i16 @gf4096_mul(i16 zeroext %114, i16 zeroext %115)
%117 = call zeroext i16 @gf4096_mul(i16 zeroext %113, i16 zeroext %116)
store i16 %117, i16* %6
%118 = load i16, i16* %19
%119 = load i16, i16* %6
%120 = call zeroext i16 @gf4096_mul(i16 zeroext %118, i16 zeroext %119)
store i16 %120, i16* %7
%121 = load i16, i16* %19
%122 = load i16, i16* %7
%123 = call zeroext i16 @gf4096_mul(i16 zeroext %121, i16 zeroext %122)
store i16 %123, i16* %8
%124 = load i16, i16* %19
%125 = load i16, i16* %8
%126 = call zeroext i16 @gf4096_mul(i16 zeroext %124, i16 zeroext %125)
store i16 %126, i16* %9
%127 = load i16, i16* %20
%128 = load i16, i16* %20
%129 = call zeroext i16 @gf4096_mul(i16 zeroext %127, i16 zeroext %128)
%130 = load i16, i16* %20
%131 = load i16, i16* %20
%132 = call zeroext i16 @gf4096_mul(i16 zeroext %130, i16 zeroext %131)
%133 = call zeroext i16 @gf4096_mul(i16 zeroext %129, i16 zeroext %132)
store i16 %133, i16* %10
%134 = load i16, i16* %20
%135 = load i16, i16* %10
%136 = call zeroext i16 @gf4096_mul(i16 zeroext %134, i16 zeroext %135)
store i16 %136, i16* %11
%137 = load i16, i16* %20
%138 = load i16, i16* %11
%139 = call zeroext i16 @gf4096_mul(i16 zeroext %137, i16 zeroext %138)
store i16 %139, i16* %12
%140 = load i16, i16* %20
%141 = load i16, i16* %12
%142 = call zeroext i16 @gf4096_mul(i16 zeroext %140, i16 zeroext %141)
store i16 %142, i16* %13
%143 = load i16*, i16** %4
%144 = getelementptr inbounds i16, i16* %143, i64 4
%145 = load i16, i16* %144
%146 = zext i16 %145 to i32
%147 = load i16, i16* %25
%148 = load i16, i16* %6
%149 = call zeroext i16 @gf4096_mul(i16 zeroext %147, i16 zeroext %148)
%150 = zext i16 %149 to i32
%151 = load i16, i16* %26
%152 = load i16, i16* %10
%153 = call zeroext i16 @gf4096_mul(i16 zeroext %151, i16 zeroext %152)
%154 = zext i16 %153 to i32
%155 = xor i32 %150, %154
%156 = icmp eq i32 %146, %155
%157 = zext i1 %156 to i32
%158 = load i16*, i16** %4
%159 = getelementptr inbounds i16, i16* %158, i64 5
%160 = load i16, i16* %159
%161 = zext i16 %160 to i32
%162 = load i16, i16* %25
%163 = load i16, i16* %7
%164 = call zeroext i16 @gf4096_mul(i16 zeroext %162, i16 zeroext %163)
%165 = zext i16 %164 to i32
%166 = load i16, i16* %26
%167 = load i16, i16* %11
%168 = call zeroext i16 @gf4096_mul(i16 zeroext %166, i16 zeroext %167)
%169 = zext i16 %168 to i32
%170 = xor i32 %165, %169
%171 = icmp eq i32 %161, %170
%172 = zext i1 %171 to i32
%173 = and i32 %157, %172
%174 = load i16*, i16** %4
%175 = getelementptr inbounds i16, i16* %174, i64 6
%176 = load i16, i16* %175
%177 = zext i16 %176 to i32
%178 = load i16, i16* %25
%179 = load i16, i16* %8
%180 = call zeroext i16 @gf4096_mul(i16 zeroext %178, i16 zeroext %179)
%181 = zext i16 %180 to i32
%182 = load i16, i16* %26
%183 = load i16, i16* %12
%184 = call zeroext i16 @gf4096_mul(i16 zeroext %182, i16 zeroext %183)
%185 = zext i16 %184 to i32
%186 = xor i32 %181, %185
%187 = icmp eq i32 %177, %186
%188 = zext i1 %187 to i32
%189 = and i32 %173, %188
%190 = load i16*, i16** %4
%191 = getelementptr inbounds i16, i16* %190, i64 7
%192 = load i16, i16* %191
%193 = zext i16 %192 to i32
%194 = load i16, i16* %25
%195 = load i16, i16* %9
%196 = call zeroext i16 @gf4096_mul(i16 zeroext %194, i16 zeroext %195)
%197 = zext i16 %196 to i32
%198 = load i16, i16* %26
%199 = load i16, i16* %13
%200 = call zeroext i16 @gf4096_mul(i16 zeroext %198, i16 zeroext %199)
%201 = zext i16 %200 to i32
%202 = xor i32 %197, %201
%203 = icmp eq i32 %193, %202
%204 = zext i1 %203 to i32
%205 = and i32 %189, %204
%206 = icmp ne i32 %205, 0
br i1 %206, label %207, label %244
207: ; preds = %92
%208 = load i16, i16* %19
%209 = call i32 @err_pos(i16 zeroext %208)
%210 = icmp eq i32 %209, 4095
%211 = zext i1 %210 to i32
%212 = load i16, i16* %20
%213 = call i32 @err_pos(i16 zeroext %212)
%214 = icmp eq i32 %213, 4095
%215 = zext i1 %214 to i32
%216 = or i32 %211, %215
%217 = icmp ne i32 %216, 0
br i1 %217, label %218, label %221
218: ; preds = %207
%219 = load i32, i32* @EINVAL
%220 = sub nsw i32 0, %219
store i32 %220, i32* %3
br label %247
221: ; preds = %207
%222 = load i16, i16* %19
%223 = call i32 @err_pos(i16 zeroext %222)
%224 = sub nsw i32 1374, %223
%225 = trunc i32 %224 to i16
store i16 %225, i16* %23
%226 = load i16, i16* %20
%227 = call i32 @err_pos(i16 zeroext %226)
%228 = sub nsw i32 1374, %227
%229 = trunc i32 %228 to i16
store i16 %229, i16* %24
%230 = load i16*, i16** %5
%231 = getelementptr inbounds i16, i16* %230, i64 0
store i16 2, i16* %231
%232 = load i16, i16* %23
%233 = load i16*, i16** %5
%234 = getelementptr inbounds i16, i16* %233, i64 1
store i16 %232, i16* %234
%235 = load i16, i16* %24
%236 = load i16*, i16** %5
%237 = getelementptr inbounds i16, i16* %236, i64 2
store i16 %235, i16* %237
%238 = load i16, i16* %25
%239 = load i16*, i16** %5
%240 = getelementptr inbounds i16, i16* %239, i64 5
store i16 %238, i16* %240
%241 = load i16, i16* %26
%242 = load i16*, i16** %5
%243 = getelementptr inbounds i16, i16* %242, i64 6
store i16 %241, i16* %243
store i32 0, i32* %3
br label %247
244: ; preds = %92
%245 = load i32, i32* @EINVAL
%246 = sub nsw i32 0, %245
store i32 %246, i32* %3
br label %247
247: ; preds = %244, %221, %218, %89
%248 = load i32, i32* %3
ret i32 %248
}

LLVM IR (-O2):
@EINVAL = global i32 0
define i32 @chk_2_err_only(i16* nocapture %0, i16* nocapture writeonly %1) {
%3 = alloca [4 x i16]
%4 = alloca [4 x i16]
%5 = bitcast [4 x i16]* %3 to i8*
%6 = bitcast [4 x i16]* %4 to i8*
%7 = getelementptr inbounds i16, i16* %0, i64 1
%8 = load i16, i16* %7
%9 = load i16, i16* %0
%10 = getelementptr inbounds i16, i16* %0, i64 2
%11 = load i16, i16* %10
%12 = getelementptr inbounds i16, i16* %0, i64 3
%13 = load i16, i16* %12
%14 = getelementptr inbounds [4 x i16], [4 x i16]* %3, i64 0, i64 0
%15 = call i32 @find_2x2_soln(i16 zeroext %8, i16 zeroext %9, i16 zeroext %11, i16 zeroext %8, i16 zeroext %11, i16 zeroext %13, i16* %14)
%16 = getelementptr inbounds [4 x i16], [4 x i16]* %3, i64 0, i64 1
br label %17
17: ; preds = %2, %30
%18 = phi i32 [ 0, %2 ], [ %32, %30 ]
%19 = phi i16 [ undef, %2 ], [ %31, %30 ]
%20 = phi i16 [ 1, %2 ], [ %33, %30 ]
%21 = load i16, i16* %16
%22 = call zeroext i16 @gf4096_mul(i16 zeroext %20, i16 zeroext %20)
%23 = call zeroext i16 @gf4096_mul(i16 zeroext %21, i16 zeroext %22)
%24 = load i16, i16* %14
%25 = call zeroext i16 @gf4096_mul(i16 zeroext %24, i16 zeroext %20)
%26 = xor i16 %25, %23
%27 = icmp eq i16 %26, 1
br i1 %27, label %28, label %30
28: ; preds = %17
%29 = icmp eq i32 %18, 0
br i1 %29, label %30, label %38
30: ; preds = %28, %17
%31 = phi i16 [ %19, %17 ], [ %20, %28 ]
%32 = phi i32 [ %18, %17 ], [ 1, %28 ]
%33 = add nuw nsw i16 %20, 1
%34 = icmp eq i16 %33, 4095
br i1 %34, label %35, label %17
35: ; preds = %30
%36 = load i32, i32* @EINVAL
%37 = sub nsw i32 0, %36
br label %110
38: ; preds = %28
%39 = call zeroext i16 @gf4096_inv(i16 zeroext %19)
%40 = call zeroext i16 @gf4096_inv(i16 zeroext %20)
%41 = load i16, i16* %0
%42 = load i16, i16* %7
%43 = getelementptr inbounds [4 x i16], [4 x i16]* %4, i64 0, i64 0
%44 = call i32 @find_2bit_err_pats(i16 zeroext %41, i16 zeroext %42, i16 zeroext %39, i16 zeroext %40, i16* %43)
%45 = load i16, i16* %43
%46 = getelementptr inbounds [4 x i16], [4 x i16]* %4, i64 0, i64 1
%47 = load i16, i16* %46
%48 = call zeroext i16 @gf4096_mul(i16 zeroext %39, i16 zeroext %39)
%49 = call zeroext i16 @gf4096_mul(i16 zeroext %39, i16 zeroext %39)
%50 = call zeroext i16 @gf4096_mul(i16 zeroext %48, i16 zeroext %49)
%51 = call zeroext i16 @gf4096_mul(i16 zeroext %39, i16 zeroext %50)
%52 = call zeroext i16 @gf4096_mul(i16 zeroext %39, i16 zeroext %51)
%53 = call zeroext i16 @gf4096_mul(i16 zeroext %39, i16 zeroext %52)
%54 = call zeroext i16 @gf4096_mul(i16 zeroext %40, i16 zeroext %40)
%55 = call zeroext i16 @gf4096_mul(i16 zeroext %40, i16 zeroext %40)
%56 = call zeroext i16 @gf4096_mul(i16 zeroext %54, i16 zeroext %55)
%57 = call zeroext i16 @gf4096_mul(i16 zeroext %40, i16 zeroext %56)
%58 = call zeroext i16 @gf4096_mul(i16 zeroext %40, i16 zeroext %57)
%59 = call zeroext i16 @gf4096_mul(i16 zeroext %40, i16 zeroext %58)
%60 = getelementptr inbounds i16, i16* %0, i64 4
%61 = load i16, i16* %60
%62 = call zeroext i16 @gf4096_mul(i16 zeroext %45, i16 zeroext %50)
%63 = call zeroext i16 @gf4096_mul(i16 zeroext %47, i16 zeroext %56)
%64 = xor i16 %63, %62
%65 = icmp eq i16 %61, %64
%66 = getelementptr inbounds i16, i16* %0, i64 5
%67 = load i16, i16* %66
%68 = call zeroext i16 @gf4096_mul(i16 zeroext %45, i16 zeroext %51)
%69 = call zeroext i16 @gf4096_mul(i16 zeroext %47, i16 zeroext %57)
%70 = xor i16 %69, %68
%71 = icmp eq i16 %67, %70
%72 = and i1 %65, %71
%73 = getelementptr inbounds i16, i16* %0, i64 6
%74 = load i16, i16* %73
%75 = call zeroext i16 @gf4096_mul(i16 zeroext %45, i16 zeroext %52)
%76 = call zeroext i16 @gf4096_mul(i16 zeroext %47, i16 zeroext %58)
%77 = xor i16 %76, %75
%78 = icmp eq i16 %74, %77
%79 = and i1 %72, %78
%80 = getelementptr inbounds i16, i16* %0, i64 7
%81 = load i16, i16* %80
%82 = call zeroext i16 @gf4096_mul(i16 zeroext %45, i16 zeroext %53)
%83 = call zeroext i16 @gf4096_mul(i16 zeroext %47, i16 zeroext %59)
%84 = xor i16 %83, %82
%85 = icmp eq i16 %81, %84
%86 = and i1 %79, %85
br i1 %86, label %87, label %107
87: ; preds = %38
%88 = call i32 @err_pos(i16 zeroext %39)
%89 = icmp eq i32 %88, 4095
%90 = call i32 @err_pos(i16 zeroext %40)
%91 = icmp eq i32 %90, 4095
%92 = or i1 %89, %91
br i1 %92, label %93, label %96
93: ; preds = %87
%94 = load i32, i32* @EINVAL
%95 = sub nsw i32 0, %94
br label %110
96: ; preds = %87
%97 = call i32 @err_pos(i16 zeroext %39)
%98 = trunc i32 %97 to i16
%99 = sub i16 1374, %98
%100 = call i32 @err_pos(i16 zeroext %40)
%101 = trunc i32 %100 to i16
%102 = sub i16 1374, %101
store i16 2, i16* %1
%103 = getelementptr inbounds i16, i16* %1, i64 1
store i16 %99, i16* %103
%104 = getelementptr inbounds i16, i16* %1, i64 2
store i16 %102, i16* %104
%105 = getelementptr inbounds i16, i16* %1, i64 5
store i16 %45, i16* %105
%106 = getelementptr inbounds i16, i16* %1, i64 6
store i16 %47, i16* %106
br label %110
107: ; preds = %38
%108 = load i32, i32* @EINVAL
%109 = sub nsw i32 0, %108
br label %110
110: ; preds = %107, %96, %93, %35
%111 = phi i32 [ %37, %35 ], [ %95, %93 ], [ 0, %96 ], [ %109, %107 ]
ret i32 %111
}