#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char, ...);
int /*<<< orphan*/ jerasure_bitmatrix_dotprod(int, int, int *,
                                              int /*<<< orphan*/ *, int,
                                              char **, char **, int, int);
int /*<<< orphan*/ stderr;
void jerasure_bitmatrix_encode(int k, int m, int w, int *bitmatrix,
                               char **data_ptrs, char **coding_ptrs, int size,
                               int packetsize) {
  int i;
  if (packetsize % sizeof(long) != 0) {
    fprintf(stderr,
            "jerasure_bitmatrix_encode - packetsize(%d) %c sizeof(long) != 0\n",
            packetsize, '%');
    exit(1);
  }
  if (size % (packetsize * w) != 0) {
    fprintf(stderr,
            "jerasure_bitmatrix_encode - size(%d) %c (packetsize(%d)*w(%d))) "
            "!= 0\n",
            size, '%', packetsize, w);
    exit(1);
  }
  for (i = 0; i < m; i++) {
    jerasure_bitmatrix_dotprod(k, w, bitmatrix + i * k * w * w, NULL, k + i,
                               data_ptrs, coding_ptrs, size, packetsize);
  }
}


x86 assembly (clang, -O0):
<jerasure_bitmatrix_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movslq 0x18(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
je     118e <jerasure_bitmatrix_encode+0x5e>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    0x18(%rbp),%edx
lea    0xe88(%rip),%rsi
mov    $0x25,%ecx
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    0x10(%rbp),%eax
mov    0x18(%rbp),%ecx
imul   -0xc(%rbp),%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11d5 <jerasure_bitmatrix_encode+0xa5>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbp),%edx
mov    0x18(%rbp),%r8d
mov    -0xc(%rbp),%r9d
lea    0xe82(%rip),%rsi
mov    $0x25,%ecx
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1243 <jerasure_bitmatrix_encode+0x113>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x2c(%rbp),%eax
imul   -0x4(%rbp),%eax
imul   -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdx
mov    -0x4(%rbp),%r8d
add    -0x2c(%rbp),%r8d
mov    -0x20(%rbp),%r9
mov    -0x28(%rbp),%r11
mov    0x10(%rbp),%r10d
mov    0x18(%rbp),%eax
xor    %ecx,%ecx
mov    %r11,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1050 <jerasure_bitmatrix_dotprod@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11dc <jerasure_bitmatrix_encode+0xac>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jerasure_bitmatrix_encode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x68(%rsp),%ebx
test   $0x7,%bl
jne    11f9 <jerasure_bitmatrix_encode+0xc9>
mov    %edx,%r14d
mov    0x60(%rsp),%r11d
mov    %ebx,%ebp
imul   %edx,%ebp
mov    %r11d,%eax
cltd
idiv   %ebp
test   %edx,%edx
jne    1221 <jerasure_bitmatrix_encode+0xf1>
test   %esi,%esi
jle    11ea <jerasure_bitmatrix_encode+0xba>
mov    %r9,%r15
mov    %r8,%r12
mov    %edi,%eax
mov    %rax,0x18(%rsp)
mov    %esi,%eax
mov    %rax,0x10(%rsp)
mov    %r14d,%eax
imul   %r14d,%eax
imul   %edi,%eax
mov    %eax,0x8(%rsp)
xor    %r13d,%r13d
xor    %ebp,%ebp
mov    %r14d,0xc(%rsp)
mov    %rcx,0x20(%rsp)
nop
movslq %r13d,%r13
lea    (%rcx,%r13,4),%rdx
mov    0x18(%rsp),%rdi
lea    (%rdi,%rbp,1),%r8d
sub    $0x8,%rsp
mov    %r14d,%esi
xor    %ecx,%ecx
mov    %r12,%r9
push   %rbx
push   %r11
push   %r15
mov    %r11,%r14
call   1050 <jerasure_bitmatrix_dotprod@plt>
mov    0x40(%rsp),%rcx
mov    %r14,%r11
mov    0x2c(%rsp),%r14d
add    $0x20,%rsp
add    $0x1,%rbp
add    0x8(%rsp),%r13d
cmp    %rbp,0x10(%rsp)
jne    11a0 <jerasure_bitmatrix_encode+0x70>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
mov    %ebx,%edx
mov    $0x25,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
mov    %r11d,%edx
mov    $0x25,%ecx
mov    %ebx,%r8d
mov    %r14d,%r9d
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [65 x i8] c"jerasure_bitmatrix_encode - packetsize(%d) %c sizeof(long) != 0\0A\00"
@.str.1 = [70 x i8] c"jerasure_bitmatrix_encode - size(%d) %c (packetsize(%d)*w(%d))) != 0\0A\00"
define void @jerasure_bitmatrix_encode(i32 %0, i32 %1, i32 %2, i32* %3, i8** %4, i8** %5, i32 %6, i32 %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i8**
%14 = alloca i8**
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 %0, i32* %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32* %3, i32** %12
store i8** %4, i8*** %13
store i8** %5, i8*** %14
store i32 %6, i32* %15
store i32 %7, i32* %16
%18 = load i32, i32* %16
%19 = sext i32 %18 to i64
%20 = urem i64 %19, 8
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %8
%23 = load i32, i32* @stderr
%24 = load i32, i32* %16
%25 = call i32 (i32, i8*, i32, i8, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %24, i8 signext 37)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %8
%28 = load i32, i32* %15
%29 = load i32, i32* %16
%30 = load i32, i32* %11
%31 = mul nsw i32 %29, %30
%32 = srem i32 %28, %31
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %27
%35 = load i32, i32* @stderr
%36 = load i32, i32* %15
%37 = load i32, i32* %16
%38 = load i32, i32* %11
%39 = call i32 (i32, i8*, i32, i8, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i32 %36, i8 signext 37, i32 %37, i32 %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %27
store i32 0, i32* %17
br label %42
42: ; preds = %67, %41
%43 = load i32, i32* %17
%44 = load i32, i32* %10
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %70
46: ; preds = %42
%47 = load i32, i32* %9
%48 = load i32, i32* %11
%49 = load i32*, i32** %12
%50 = load i32, i32* %17
%51 = load i32, i32* %9
%52 = mul nsw i32 %50, %51
%53 = load i32, i32* %11
%54 = mul nsw i32 %52, %53
%55 = load i32, i32* %11
%56 = mul nsw i32 %54, %55
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %49, i64 %57
%59 = load i32, i32* %9
%60 = load i32, i32* %17
%61 = add nsw i32 %59, %60
%62 = load i8**, i8*** %13
%63 = load i8**, i8*** %14
%64 = load i32, i32* %15
%65 = load i32, i32* %16
%66 = call i32 @jerasure_bitmatrix_dotprod(i32 %47, i32 %48, i32* %58, i32* null, i32 %61, i8** %62, i8** %63, i32 %64, i32 %65)
br label %67
67: ; preds = %46
%68 = load i32, i32* %17
%69 = add nsw i32 %68, 1
store i32 %69, i32* %17
br label %42
70: ; preds = %42
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [65 x i8] c"jerasure_bitmatrix_encode - packetsize(%d) %c sizeof(long) != 0\0A\00"
@.str.1 = [70 x i8] c"jerasure_bitmatrix_encode - size(%d) %c (packetsize(%d)*w(%d))) != 0\0A\00"
define void @jerasure_bitmatrix_encode(i32 %0, i32 %1, i32 %2, i32* %3, i8** %4, i8** %5, i32 %6, i32 %7) {
%9 = and i32 %7, 7
%10 = icmp eq i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, i32, i8, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %7, i8 signext 37)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %8
%16 = mul nsw i32 %7, %2
%17 = srem i32 %6, %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = icmp sgt i32 %1, 0
br i1 %20, label %21, label %40
21: ; preds = %19
%22 = mul i32 %2, %0
%23 = mul i32 %22, %2
%24 = zext i32 %1 to i64
br label %29
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, i32, i8, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i32 %6, i8 signext 37, i32 %7, i32 %2)
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %21, %29
%30 = phi i64 [ 0, %21 ], [ %38, %29 ]
%31 = trunc i64 %30 to i32
%32 = mul i32 %23, %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %3, i64 %33
%35 = trunc i64 %30 to i32
%36 = add i32 %35, %0
%37 = tail call i32 @jerasure_bitmatrix_dotprod(i32 %0, i32 %2, i32* %34, i32* null, i32 %36, i8** %4, i8** %5, i32 %6, i32 %7)
%38 = add nuw nsw i64 %30, 1
%39 = icmp eq i64 %38, %24
br i1 %39, label %40, label %29
40: ; preds = %29, %19
ret void
}