#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ _gf256v_madd(int /*<<< orphan*/ *,
                                int /*<<< orphan*/ const *,
                                int /*<<< orphan*/ const, unsigned int);
int /*<<< orphan*/ gf256v_set_zero(int /*<<< orphan*/ *, unsigned int);
void gf256mat_mul(uint8_t *c, const uint8_t *a, const uint8_t *b,
                  unsigned len_vec) {
  unsigned n_vec_byte = len_vec;
  for (unsigned k = 0; k < len_vec; k++) {
    gf256v_set_zero(c, n_vec_byte);
    const uint8_t *bk = b + n_vec_byte * k;
    for (unsigned i = 0; i < len_vec; i++) {
      _gf256v_madd(c, a + n_vec_byte * i, bk[i], n_vec_byte);
    }
    c += n_vec_byte;
  }
}


x86 assembly (clang, -O0):
<gf256mat_mul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    11e1 <gf256mat_mul+0xc1>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <gf256v_set_zero@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x24(%rbp),%ecx
mov    %ecx,%ecx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    11bf <gf256mat_mul+0x9f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%eax
imul   -0x34(%rbp),%eax
mov    %eax,%eax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    (%rax,%rcx,4),%edx
mov    -0x20(%rbp),%ecx
call   1030 <_gf256v_madd@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    117b <gf256mat_mul+0x5b>
mov    -0x20(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,%ecx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1144 <gf256mat_mul+0x24>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gf256mat_mul>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    %ecx,0x4(%rsp)
test   %ecx,%ecx
je     11bf <gf256mat_mul+0x9f>
mov    %rdi,%rbx
mov    0x4(%rsp),%ebp
xor    %eax,%eax
xor    %ecx,%ecx
mov    0x8(%rsp),%r12
mov    %rcx,0x18(%rsp)
mov    %rax,0x20(%rsp)
mov    %eax,%eax
mov    0x10(%rsp),%rcx
lea    (%rcx,%rax,4),%r13
mov    %rbx,%rdi
mov    0x4(%rsp),%esi
call   1040 <gf256v_set_zero@plt>
xor    %r14d,%r14d
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %r14d,%eax
lea    (%r12,%rax,4),%rsi
mov    0x0(%r13,%r15,4),%edx
mov    %rbx,%rdi
mov    %ebp,%ecx
call   1030 <_gf256v_madd@plt>
add    $0x1,%r15
add    0x4(%rsp),%r14d
cmp    %r15,%rbp
jne    1180 <gf256mat_mul+0x60>
lea    (%rbx,%rbp,4),%rbx
mov    0x18(%rsp),%rcx
add    $0x1,%rcx
mov    0x20(%rsp),%rax
add    0x4(%rsp),%eax
cmp    %rbp,%rcx
jne    1150 <gf256mat_mul+0x30>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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