#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*/ ec_encode_data_base(int, int, int, int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ **,
                                       int /*<<< orphan*/ **);
int /*<<< orphan*/ gf_2vect_dot_prod_avx(int, int, int /*<<< orphan*/ *,
                                         int /*<<< orphan*/ **,
                                         int /*<<< orphan*/ **);
int /*<<< orphan*/ gf_3vect_dot_prod_avx(int, int, int /*<<< orphan*/ *,
                                         int /*<<< orphan*/ **,
                                         int /*<<< orphan*/ **);
int /*<<< orphan*/ gf_4vect_dot_prod_avx(int, int, int /*<<< orphan*/ *,
                                         int /*<<< orphan*/ **,
                                         int /*<<< orphan*/ **);
int /*<<< orphan*/ gf_vect_dot_prod_avx(int, int, int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ **,
                                        int /*<<< orphan*/ *);
void ec_encode_data_avx(int len, int k, int rows, uint8_t *g_tbls,
                        uint8_t **data, uint8_t **coding) {
  if (len < 16) {
    ec_encode_data_base(len, k, rows, g_tbls, data, coding);
    return;
  }
  while (rows >= 4) {
    gf_4vect_dot_prod_avx(len, k, g_tbls, data, coding);
    g_tbls += 4 * k * 32;
    coding += 4;
    rows -= 4;
  }
  switch (rows) {
  case 3:
    gf_3vect_dot_prod_avx(len, k, g_tbls, data, coding);
    break;
  case 2:
    gf_2vect_dot_prod_avx(len, k, g_tbls, data, coding);
    break;
  case 1:
    gf_vect_dot_prod_avx(len, k, g_tbls, data, *coding);
    break;
  case 0:
    break;
  }
}


x86 assembly (clang, -O0):
<ec_encode_data_avx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
cmpl   $0x10,-0x4(%rbp)
jge    1196 <ec_encode_data_avx+0x46>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
call   1050 <ec_encode_data_base@plt>
jmp    1272 <ec_encode_data_avx+0x122>
jmp    119b <ec_encode_data_avx+0x4b>
cmpl   $0x4,-0xc(%rbp)
jl     11f1 <ec_encode_data_avx+0xa1>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1060 <gf_4vect_dot_prod_avx@plt>
mov    -0x8(%rbp),%ecx
shl    $0x2,%ecx
shl    $0x5,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0xc(%rbp)
jmp    119b <ec_encode_data_avx+0x4b>
mov    -0xc(%rbp),%eax
mov    %rax,-0x30(%rbp)
sub    $0x3,%rax
ja     1272 <ec_encode_data_avx+0x122>
mov    -0x30(%rbp),%rax
lea    0xdf3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1070 <gf_3vect_dot_prod_avx@plt>
jmp    1272 <ec_encode_data_avx+0x122>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1040 <gf_2vect_dot_prod_avx@plt>
jmp    1272 <ec_encode_data_avx+0x122>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    (%rax),%r8
call   1030 <gf_vect_dot_prod_avx@plt>
jmp    1272 <ec_encode_data_avx+0x122>
jmp    1272 <ec_encode_data_avx+0x122>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ec_encode_data_avx>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r15
mov    %r8,%r12
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %esi,%r13d
mov    %edi,%r14d
cmp    $0x10,%edi
jge    1195 <ec_encode_data_avx+0x45>
mov    %r14d,%edi
mov    %r13d,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
mov    %r12,%r8
mov    %r15,%r9
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <ec_encode_data_base@plt>
cmp    $0x4,%ebp
jl     1207 <ec_encode_data_avx+0xb7>
mov    %r13d,%eax
shl    $0x7,%eax
cltq
shl    $0x2,%rax
mov    %rax,(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
call   1060 <gf_4vect_dot_prod_avx@plt>
add    $0x20,%r15
lea    -0x4(%rbp),%eax
add    (%rsp),%rbx
cmp    $0x7,%ebp
mov    %eax,%ebp
ja     11b0 <ec_encode_data_avx+0x60>
cmp    $0x1,%eax
je     120e <ec_encode_data_avx+0xbe>
cmp    $0x2,%eax
je     1230 <ec_encode_data_avx+0xe0>
cmp    $0x3,%eax
jne    1252 <ec_encode_data_avx+0x102>
mov    %r14d,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <gf_3vect_dot_prod_avx@plt>
mov    %ebp,%eax
cmp    $0x1,%eax
jne    11db <ec_encode_data_avx+0x8b>
mov    (%r15),%r8
mov    %r14d,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <gf_vect_dot_prod_avx@plt>
mov    %r14d,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <gf_2vect_dot_prod_avx@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @ec_encode_data_avx(i32 %0, i32 %1, i32 %2, i32* %3, i32** %4, i32** %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32**
%12 = alloca i32**
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store i32** %4, i32*** %11
store i32** %5, i32*** %12
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 16
br i1 %14, label %15, label %23
15: ; preds = %6
%16 = load i32, i32* %7
%17 = load i32, i32* %8
%18 = load i32, i32* %9
%19 = load i32*, i32** %10
%20 = load i32**, i32*** %11
%21 = load i32**, i32*** %12
%22 = call i32 @ec_encode_data_base(i32 %16, i32 %17, i32 %18, i32* %19, i32** %20, i32** %21)
br label %69
23: ; preds = %6
br label %24
24: ; preds = %27, %23
%25 = load i32, i32* %9
%26 = icmp sge i32 %25, 4
br i1 %26, label %27, label %44
27: ; preds = %24
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = load i32*, i32** %10
%31 = load i32**, i32*** %11
%32 = load i32**, i32*** %12
%33 = call i32 @gf_4vect_dot_prod_avx(i32 %28, i32 %29, i32* %30, i32** %31, i32** %32)
%34 = load i32, i32* %8
%35 = mul nsw i32 4, %34
%36 = mul nsw i32 %35, 32
%37 = load i32*, i32** %10
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i32, i32* %37, i64 %38
store i32* %39, i32** %10
%40 = load i32**, i32*** %12
%41 = getelementptr inbounds i32*, i32** %40, i64 4
store i32** %41, i32*** %12
%42 = load i32, i32* %9
%43 = sub nsw i32 %42, 4
store i32 %43, i32* %9
br label %24
44: ; preds = %24
%45 = load i32, i32* %9
switch i32 %45, label %69 [
i32 3, label %46
i32 2, label %53
i32 1, label %60
i32 0, label %68
]
46: ; preds = %44
%47 = load i32, i32* %7
%48 = load i32, i32* %8
%49 = load i32*, i32** %10
%50 = load i32**, i32*** %11
%51 = load i32**, i32*** %12
%52 = call i32 @gf_3vect_dot_prod_avx(i32 %47, i32 %48, i32* %49, i32** %50, i32** %51)
br label %69
53: ; preds = %44
%54 = load i32, i32* %7
%55 = load i32, i32* %8
%56 = load i32*, i32** %10
%57 = load i32**, i32*** %11
%58 = load i32**, i32*** %12
%59 = call i32 @gf_2vect_dot_prod_avx(i32 %54, i32 %55, i32* %56, i32** %57, i32** %58)
br label %69
60: ; preds = %44
%61 = load i32, i32* %7
%62 = load i32, i32* %8
%63 = load i32*, i32** %10
%64 = load i32**, i32*** %11
%65 = load i32**, i32*** %12
%66 = load i32*, i32** %65
%67 = call i32 @gf_vect_dot_prod_avx(i32 %61, i32 %62, i32* %63, i32** %64, i32* %66)
br label %69
68: ; preds = %44
br label %69
69: ; preds = %15, %44, %68, %60, %53, %46
ret void
}

LLVM IR (-O2):
define void @ec_encode_data_avx(i32 %0, i32 %1, i32 %2, i32* %3, i32** %4, i32** %5) {
%7 = icmp slt i32 %0, 16
br i1 %7, label %13, label %8
8: ; preds = %6
%9 = icmp sgt i32 %2, 3
br i1 %9, label %10, label %24
10: ; preds = %8
%11 = shl nsw i32 %1, 7
%12 = sext i32 %11 to i64
br label %15
13: ; preds = %6
%14 = tail call i32 @ec_encode_data_base(i32 %0, i32 %1, i32 %2, i32* %3, i32** %4, i32** %5)
br label %35
15: ; preds = %10, %15
%16 = phi i32** [ %5, %10 ], [ %21, %15 ]
%17 = phi i32 [ %2, %10 ], [ %22, %15 ]
%18 = phi i32* [ %3, %10 ], [ %20, %15 ]
%19 = tail call i32 @gf_4vect_dot_prod_avx(i32 %0, i32 %1, i32* %18, i32** %4, i32** %16)
%20 = getelementptr inbounds i32, i32* %18, i64 %12
%21 = getelementptr inbounds i32*, i32** %16, i64 4
%22 = add nsw i32 %17, -4
%23 = icmp ugt i32 %17, 7
br i1 %23, label %15, label %24
24: ; preds = %15, %8
%25 = phi i32* [ %3, %8 ], [ %20, %15 ]
%26 = phi i32 [ %2, %8 ], [ %22, %15 ]
%27 = phi i32** [ %5, %8 ], [ %21, %15 ]
switch i32 %26, label %35 [
i32 3, label %28
i32 2, label %30
i32 1, label %32
]
28: ; preds = %24
%29 = tail call i32 @gf_3vect_dot_prod_avx(i32 %0, i32 %1, i32* %25, i32** %4, i32** %27)
br label %35
30: ; preds = %24
%31 = tail call i32 @gf_2vect_dot_prod_avx(i32 %0, i32 %1, i32* %25, i32** %4, i32** %27)
br label %35
32: ; preds = %24
%33 = load i32*, i32** %27
%34 = tail call i32 @gf_vect_dot_prod_avx(i32 %0, i32 %1, i32* %25, i32** %4, i32* %33)
br label %35
35: ; preds = %13, %24, %32, %30, %28
ret void
}