#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 short gf4096_inv(unsigned short);
unsigned short gf4096_mul(unsigned short, unsigned short);
int /*<<< orphan*/ sort_coefs(int *, unsigned short *, int);
void solve_3x4(unsigned short m[3][4], unsigned short *coefs, int *row_order) {
  unsigned short tmp[3];
  tmp[0] = gf4096_mul(m[2][3], gf4096_inv(m[2][0]));
  tmp[1] =
      gf4096_mul((gf4096_mul(tmp[0], m[1][0]) ^ m[1][3]), gf4096_inv(m[1][1]));
  tmp[2] = gf4096_mul(
      (gf4096_mul(tmp[0], m[0][0]) ^ gf4096_mul(tmp[1], m[0][1]) ^ m[0][3]),
      gf4096_inv(m[0][2]));
  sort_coefs(row_order, tmp, 3);
  coefs[0] = tmp[0];
  coefs[1] = tmp[1];
  coefs[2] = tmp[2];
}


x86 assembly (clang, -O0):
<solve_3x4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x16(%rax),%ax
mov    %ax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movzwl 0x10(%rax),%edi
call   1050 <gf4096_inv@plt>
mov    -0x28(%rbp),%cx
movzwl %cx,%edi
movzwl %ax,%esi
call   1030 <gf4096_mul@plt>
mov    %ax,-0x1e(%rbp)
mov    -0x1e(%rbp),%cx
mov    -0x8(%rbp),%rax
movzwl %cx,%edi
movzwl 0x8(%rax),%esi
call   1030 <gf4096_mul@plt>
movzwl %ax,%eax
mov    -0x8(%rbp),%rcx
movzwl 0xe(%rcx),%ecx
xor    %ecx,%eax
mov    %ax,-0x26(%rbp)
mov    -0x8(%rbp),%rax
movzwl 0xa(%rax),%edi
call   1050 <gf4096_inv@plt>
mov    -0x26(%rbp),%cx
movzwl %cx,%edi
movzwl %ax,%esi
call   1030 <gf4096_mul@plt>
mov    %ax,-0x1c(%rbp)
mov    -0x1e(%rbp),%cx
mov    -0x8(%rbp),%rax
movzwl %cx,%edi
movzwl (%rax),%esi
call   1030 <gf4096_mul@plt>
movzwl %ax,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%cx
mov    -0x8(%rbp),%rax
movzwl %cx,%edi
movzwl 0x2(%rax),%esi
call   1030 <gf4096_mul@plt>
mov    %ax,%cx
mov    -0x24(%rbp),%eax
movzwl %cx,%ecx
xor    %ecx,%eax
mov    -0x8(%rbp),%rcx
movzwl 0x6(%rcx),%ecx
xor    %ecx,%eax
mov    %ax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movzwl 0x4(%rax),%edi
call   1050 <gf4096_inv@plt>
mov    -0x20(%rbp),%cx
movzwl %cx,%edi
movzwl %ax,%esi
call   1030 <gf4096_mul@plt>
mov    %ax,-0x1a(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x1e(%rbp),%rsi
mov    $0x3,%edx
call   1040 <sort_coefs@plt>
mov    -0x1e(%rbp),%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
mov    -0x1c(%rbp),%cx
mov    -0x10(%rbp),%rax
mov    %cx,0x2(%rax)
mov    -0x1a(%rbp),%cx
mov    -0x10(%rbp),%rax
mov    %cx,0x4(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve_3x4>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movzwl 0x16(%rdi),%ebp
movzwl 0x10(%rdi),%edi
call   1050 <gf4096_inv@plt>
movzwl %ax,%esi
mov    %ebp,%edi
call   1030 <gf4096_mul@plt>
mov    %ax,0xa(%rsp)
movzwl 0x8(%rbx),%esi
movzwl %ax,%r12d
mov    %r12d,%edi
call   1030 <gf4096_mul@plt>
mov    %eax,%ebp
xor    0xe(%rbx),%bp
movzwl 0xa(%rbx),%edi
call   1050 <gf4096_inv@plt>
movzwl %bp,%edi
movzwl %ax,%esi
call   1030 <gf4096_mul@plt>
mov    %eax,%ebp
mov    %ax,0xc(%rsp)
movzwl (%rbx),%esi
mov    %r12d,%edi
call   1030 <gf4096_mul@plt>
mov    %eax,%r12d
movzwl 0x2(%rbx),%esi
movzwl %bp,%edi
call   1030 <gf4096_mul@plt>
mov    %eax,%ebp
xor    %r12d,%ebp
xor    0x6(%rbx),%bp
movzwl 0x4(%rbx),%edi
call   1050 <gf4096_inv@plt>
movzwl %bp,%edi
movzwl %ax,%esi
call   1030 <gf4096_mul@plt>
mov    %ax,0xe(%rsp)
lea    0xa(%rsp),%rsi
mov    %r14,%rdi
mov    $0x3,%edx
call   1040 <sort_coefs@plt>
movzwl 0xa(%rsp),%eax
mov    %ax,(%r15)
movzwl 0xc(%rsp),%eax
mov    %ax,0x2(%r15)
movzwl 0xe(%rsp),%eax
mov    %ax,0x4(%r15)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @solve_3x4([4 x i16]* %0, i16* %1, i32* %2) {
%4 = alloca [4 x i16]*
%5 = alloca i16*
%6 = alloca i32*
%7 = alloca [3 x i16]
store [4 x i16]* %0, [4 x i16]** %4
store i16* %1, i16** %5
store i32* %2, i32** %6
%8 = load [4 x i16]*, [4 x i16]** %4
%9 = getelementptr inbounds [4 x i16], [4 x i16]* %8, i64 2
%10 = getelementptr inbounds [4 x i16], [4 x i16]* %9, i64 0, i64 3
%11 = load i16, i16* %10
%12 = load [4 x i16]*, [4 x i16]** %4
%13 = getelementptr inbounds [4 x i16], [4 x i16]* %12, i64 2
%14 = getelementptr inbounds [4 x i16], [4 x i16]* %13, i64 0, i64 0
%15 = load i16, i16* %14
%16 = call zeroext i16 @gf4096_inv(i16 zeroext %15)
%17 = call zeroext i16 @gf4096_mul(i16 zeroext %11, i16 zeroext %16)
%18 = getelementptr inbounds [3 x i16], [3 x i16]* %7, i64 0, i64 0
store i16 %17, i16* %18
%19 = getelementptr inbounds [3 x i16], [3 x i16]* %7, i64 0, i64 0
%20 = load i16, i16* %19
%21 = load [4 x i16]*, [4 x i16]** %4
%22 = getelementptr inbounds [4 x i16], [4 x i16]* %21, i64 1
%23 = getelementptr inbounds [4 x i16], [4 x i16]* %22, i64 0, i64 0
%24 = load i16, i16* %23
%25 = call zeroext i16 @gf4096_mul(i16 zeroext %20, i16 zeroext %24)
%26 = zext i16 %25 to i32
%27 = load [4 x i16]*, [4 x i16]** %4
%28 = getelementptr inbounds [4 x i16], [4 x i16]* %27, i64 1
%29 = getelementptr inbounds [4 x i16], [4 x i16]* %28, i64 0, i64 3
%30 = load i16, i16* %29
%31 = zext i16 %30 to i32
%32 = xor i32 %26, %31
%33 = trunc i32 %32 to i16
%34 = load [4 x i16]*, [4 x i16]** %4
%35 = getelementptr inbounds [4 x i16], [4 x i16]* %34, i64 1
%36 = getelementptr inbounds [4 x i16], [4 x i16]* %35, i64 0, i64 1
%37 = load i16, i16* %36
%38 = call zeroext i16 @gf4096_inv(i16 zeroext %37)
%39 = call zeroext i16 @gf4096_mul(i16 zeroext %33, i16 zeroext %38)
%40 = getelementptr inbounds [3 x i16], [3 x i16]* %7, i64 0, i64 1
store i16 %39, i16* %40
%41 = getelementptr inbounds [3 x i16], [3 x i16]* %7, i64 0, i64 0
%42 = load i16, i16* %41
%43 = load [4 x i16]*, [4 x i16]** %4
%44 = getelementptr inbounds [4 x i16], [4 x i16]* %43, i64 0
%45 = getelementptr inbounds [4 x i16], [4 x i16]* %44, i64 0, i64 0
%46 = load i16, i16* %45
%47 = call zeroext i16 @gf4096_mul(i16 zeroext %42, i16 zeroext %46)
%48 = zext i16 %47 to i32
%49 = getelementptr inbounds [3 x i16], [3 x i16]* %7, i64 0, i64 1
%50 = load i16, i16* %49
%51 = load [4 x i16]*, [4 x i16]** %4
%52 = getelementptr inbounds [4 x i16], [4 x i16]* %51, i64 0
%53 = getelementptr inbounds [4 x i16], [4 x i16]* %52, i64 0, i64 1
%54 = load i16, i16* %53
%55 = call zeroext i16 @gf4096_mul(i16 zeroext %50, i16 zeroext %54)
%56 = zext i16 %55 to i32
%57 = xor i32 %48, %56
%58 = load [4 x i16]*, [4 x i16]** %4
%59 = getelementptr inbounds [4 x i16], [4 x i16]* %58, i64 0
%60 = getelementptr inbounds [4 x i16], [4 x i16]* %59, i64 0, i64 3
%61 = load i16, i16* %60
%62 = zext i16 %61 to i32
%63 = xor i32 %57, %62
%64 = trunc i32 %63 to i16
%65 = load [4 x i16]*, [4 x i16]** %4
%66 = getelementptr inbounds [4 x i16], [4 x i16]* %65, i64 0
%67 = getelementptr inbounds [4 x i16], [4 x i16]* %66, i64 0, i64 2
%68 = load i16, i16* %67
%69 = call zeroext i16 @gf4096_inv(i16 zeroext %68)
%70 = call zeroext i16 @gf4096_mul(i16 zeroext %64, i16 zeroext %69)
%71 = getelementptr inbounds [3 x i16], [3 x i16]* %7, i64 0, i64 2
store i16 %70, i16* %71
%72 = load i32*, i32** %6
%73 = getelementptr inbounds [3 x i16], [3 x i16]* %7, i64 0, i64 0
%74 = call i32 @sort_coefs(i32* %72, i16* %73, i32 3)
%75 = getelementptr inbounds [3 x i16], [3 x i16]* %7, i64 0, i64 0
%76 = load i16, i16* %75
%77 = load i16*, i16** %5
%78 = getelementptr inbounds i16, i16* %77, i64 0
store i16 %76, i16* %78
%79 = getelementptr inbounds [3 x i16], [3 x i16]* %7, i64 0, i64 1
%80 = load i16, i16* %79
%81 = load i16*, i16** %5
%82 = getelementptr inbounds i16, i16* %81, i64 1
store i16 %80, i16* %82
%83 = getelementptr inbounds [3 x i16], [3 x i16]* %7, i64 0, i64 2
%84 = load i16, i16* %83
%85 = load i16*, i16** %5
%86 = getelementptr inbounds i16, i16* %85, i64 2
store i16 %84, i16* %86
ret void
}

LLVM IR (-O2):
define void @solve_3x4([4 x i16]* nocapture %0, i16* nocapture writeonly %1, i32* %2) {
%4 = alloca [3 x i16]
%5 = bitcast [3 x i16]* %4 to i8*
%6 = getelementptr inbounds [4 x i16], [4 x i16]* %0, i64 2, i64 3
%7 = load i16, i16* %6
%8 = getelementptr inbounds [4 x i16], [4 x i16]* %0, i64 2, i64 0
%9 = load i16, i16* %8
%10 = tail call zeroext i16 @gf4096_inv(i16 zeroext %9)
%11 = tail call zeroext i16 @gf4096_mul(i16 zeroext %7, i16 zeroext %10)
%12 = getelementptr inbounds [3 x i16], [3 x i16]* %4, i64 0, i64 0
store i16 %11, i16* %12
%13 = getelementptr inbounds [4 x i16], [4 x i16]* %0, i64 1, i64 0
%14 = load i16, i16* %13
%15 = tail call zeroext i16 @gf4096_mul(i16 zeroext %11, i16 zeroext %14)
%16 = getelementptr inbounds [4 x i16], [4 x i16]* %0, i64 1, i64 3
%17 = load i16, i16* %16
%18 = xor i16 %17, %15
%19 = getelementptr inbounds [4 x i16], [4 x i16]* %0, i64 1, i64 1
%20 = load i16, i16* %19
%21 = tail call zeroext i16 @gf4096_inv(i16 zeroext %20)
%22 = tail call zeroext i16 @gf4096_mul(i16 zeroext %18, i16 zeroext %21)
%23 = getelementptr inbounds [3 x i16], [3 x i16]* %4, i64 0, i64 1
store i16 %22, i16* %23
%24 = getelementptr inbounds [4 x i16], [4 x i16]* %0, i64 0, i64 0
%25 = load i16, i16* %24
%26 = tail call zeroext i16 @gf4096_mul(i16 zeroext %11, i16 zeroext %25)
%27 = getelementptr inbounds [4 x i16], [4 x i16]* %0, i64 0, i64 1
%28 = load i16, i16* %27
%29 = tail call zeroext i16 @gf4096_mul(i16 zeroext %22, i16 zeroext %28)
%30 = xor i16 %29, %26
%31 = getelementptr inbounds [4 x i16], [4 x i16]* %0, i64 0, i64 3
%32 = load i16, i16* %31
%33 = xor i16 %30, %32
%34 = getelementptr inbounds [4 x i16], [4 x i16]* %0, i64 0, i64 2
%35 = load i16, i16* %34
%36 = tail call zeroext i16 @gf4096_inv(i16 zeroext %35)
%37 = tail call zeroext i16 @gf4096_mul(i16 zeroext %33, i16 zeroext %36)
%38 = getelementptr inbounds [3 x i16], [3 x i16]* %4, i64 0, i64 2
store i16 %37, i16* %38
%39 = call i32 @sort_coefs(i32* %2, i16* %12, i32 3)
%40 = load i16, i16* %12
store i16 %40, i16* %1
%41 = load i16, i16* %23
%42 = getelementptr inbounds i16, i16* %1, i64 1
store i16 %41, i16* %42
%43 = load i16, i16* %38
%44 = getelementptr inbounds i16, i16* %1, i64 2
store i16 %43, i16* %44
ret void
}