#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 /*<<< orphan*/ ec_encode_data_base(int, int, int, unsigned char *,
                                       unsigned char **, unsigned char **);
int /*<<< orphan*/ gf_2vect_dot_prod_avx2(int, int, unsigned char *,
                                          unsigned char **, unsigned char **);
int /*<<< orphan*/ gf_3vect_dot_prod_avx2(int, int, unsigned char *,
                                          unsigned char **, unsigned char **);
int /*<<< orphan*/ gf_4vect_dot_prod_avx2(int, int, unsigned char *,
                                          unsigned char **, unsigned char **);
int /*<<< orphan*/ gf_vect_dot_prod_avx2(int, int, unsigned char *,
                                         unsigned char **, unsigned char *);
void ec_encode_data_avx2(int len, int k, int rows, unsigned char *g_tbls,
                         unsigned char **data, unsigned char **coding) {
  if (len < 32) {
    ec_encode_data_base(len, k, rows, g_tbls, data, coding);
    return;
  }
  while (rows >= 4) {
    gf_4vect_dot_prod_avx2(len, k, g_tbls, data, coding);
    g_tbls += 4 * k * 32;
    coding += 4;
    rows -= 4;
  }
  switch (rows) {
  case 3:
    gf_3vect_dot_prod_avx2(len, k, g_tbls, data, coding);
    break;
  case 2:
    gf_2vect_dot_prod_avx2(len, k, g_tbls, data, coding);
    break;
  case 1:
    gf_vect_dot_prod_avx2(len, k, g_tbls, data, *coding);
    break;
  case 0:
    break;
  }
}


x86 assembly (clang, -O0):
<ec_encode_data_avx2>:
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   $0x20,-0x4(%rbp)
jge    1196 <ec_encode_data_avx2+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   1040 <ec_encode_data_base@plt>
jmp    126e <ec_encode_data_avx2+0x11e>
jmp    119b <ec_encode_data_avx2+0x4b>
cmpl   $0x4,-0xc(%rbp)
jl     11ed <ec_encode_data_avx2+0x9d>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1030 <gf_4vect_dot_prod_avx2@plt>
mov    -0x8(%rbp),%ecx
shl    $0x2,%ecx
shl    $0x5,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%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_avx2+0x4b>
mov    -0xc(%rbp),%eax
mov    %rax,-0x30(%rbp)
sub    $0x3,%rax
ja     126e <ec_encode_data_avx2+0x11e>
mov    -0x30(%rbp),%rax
lea    0xdf7(%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_avx2@plt>
jmp    126e <ec_encode_data_avx2+0x11e>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1060 <gf_2vect_dot_prod_avx2@plt>
jmp    126e <ec_encode_data_avx2+0x11e>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    (%rax),%r8
call   1050 <gf_vect_dot_prod_avx2@plt>
jmp    126e <ec_encode_data_avx2+0x11e>
jmp    126e <ec_encode_data_avx2+0x11e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ec_encode_data_avx2>:
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    $0x20,%edi
jge    1195 <ec_encode_data_avx2+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    1040 <ec_encode_data_base@plt>
cmp    $0x4,%ebp
jl     1207 <ec_encode_data_avx2+0xb7>
mov    %r13d,%eax
shl    $0x7,%eax
cltq
mov    %rax,(%rsp)
cs nopw 0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
call   1030 <gf_4vect_dot_prod_avx2@plt>
add    (%rsp),%rbx
add    $0x20,%r15
lea    -0x4(%rbp),%eax
cmp    $0x7,%ebp
mov    %eax,%ebp
ja     11b0 <ec_encode_data_avx2+0x60>
cmp    $0x1,%eax
je     120e <ec_encode_data_avx2+0xbe>
cmp    $0x2,%eax
je     1230 <ec_encode_data_avx2+0xe0>
cmp    $0x3,%eax
jne    1252 <ec_encode_data_avx2+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_avx2@plt>
mov    %ebp,%eax
cmp    $0x1,%eax
jne    11db <ec_encode_data_avx2+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    1050 <gf_vect_dot_prod_avx2@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    1060 <gf_2vect_dot_prod_avx2@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_avx2(i32 %0, i32 %1, i32 %2, i8* %3, i8** %4, i8** %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8**
%12 = alloca i8**
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i8** %4, i8*** %11
store i8** %5, i8*** %12
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 32
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 i8*, i8** %10
%20 = load i8**, i8*** %11
%21 = load i8**, i8*** %12
%22 = call i32 @ec_encode_data_base(i32 %16, i32 %17, i32 %18, i8* %19, i8** %20, i8** %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 i8*, i8** %10
%31 = load i8**, i8*** %11
%32 = load i8**, i8*** %12
%33 = call i32 @gf_4vect_dot_prod_avx2(i32 %28, i32 %29, i8* %30, i8** %31, i8** %32)
%34 = load i32, i32* %8
%35 = mul nsw i32 4, %34
%36 = mul nsw i32 %35, 32
%37 = load i8*, i8** %10
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i8, i8* %37, i64 %38
store i8* %39, i8** %10
%40 = load i8**, i8*** %12
%41 = getelementptr inbounds i8*, i8** %40, i64 4
store i8** %41, i8*** %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 i8*, i8** %10
%50 = load i8**, i8*** %11
%51 = load i8**, i8*** %12
%52 = call i32 @gf_3vect_dot_prod_avx2(i32 %47, i32 %48, i8* %49, i8** %50, i8** %51)
br label %69
53: ; preds = %44
%54 = load i32, i32* %7
%55 = load i32, i32* %8
%56 = load i8*, i8** %10
%57 = load i8**, i8*** %11
%58 = load i8**, i8*** %12
%59 = call i32 @gf_2vect_dot_prod_avx2(i32 %54, i32 %55, i8* %56, i8** %57, i8** %58)
br label %69
60: ; preds = %44
%61 = load i32, i32* %7
%62 = load i32, i32* %8
%63 = load i8*, i8** %10
%64 = load i8**, i8*** %11
%65 = load i8**, i8*** %12
%66 = load i8*, i8** %65
%67 = call i32 @gf_vect_dot_prod_avx2(i32 %61, i32 %62, i8* %63, i8** %64, i8* %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_avx2(i32 %0, i32 %1, i32 %2, i8* %3, i8** %4, i8** %5) {
%7 = icmp slt i32 %0, 32
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, i8* %3, i8** %4, i8** %5)
br label %35
15: ; preds = %10, %15
%16 = phi i8** [ %5, %10 ], [ %21, %15 ]
%17 = phi i32 [ %2, %10 ], [ %22, %15 ]
%18 = phi i8* [ %3, %10 ], [ %20, %15 ]
%19 = tail call i32 @gf_4vect_dot_prod_avx2(i32 %0, i32 %1, i8* %18, i8** %4, i8** %16)
%20 = getelementptr inbounds i8, i8* %18, i64 %12
%21 = getelementptr inbounds i8*, i8** %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 i8* [ %3, %8 ], [ %20, %15 ]
%26 = phi i32 [ %2, %8 ], [ %22, %15 ]
%27 = phi i8** [ %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_avx2(i32 %0, i32 %1, i8* %25, i8** %4, i8** %27)
br label %35
30: ; preds = %24
%31 = tail call i32 @gf_2vect_dot_prod_avx2(i32 %0, i32 %1, i8* %25, i8** %4, i8** %27)
br label %35
32: ; preds = %24
%33 = load i8*, i8** %27
%34 = tail call i32 @gf_vect_dot_prod_avx2(i32 %0, i32 %1, i8* %25, i8** %4, i8* %33)
br label %35
35: ; preds = %13, %24, %32, %30, %28
ret void
}