#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, j, x, y, sptr, pstarted, index;
  char *dptr, *pptr;
  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    $0x70,%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    $0x70,%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
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i8*
%25 = alloca i8*
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
%26 = load i32, i32* %16
%27 = sext i32 %26 to i64
%28 = urem i64 %27, 8
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %8
%31 = load i32, i32* @stderr
%32 = load i32, i32* %16
%33 = call i32 (i32, i8*, i32, i8, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %32, i8 signext 37)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %8
%36 = load i32, i32* %15
%37 = load i32, i32* %16
%38 = load i32, i32* %11
%39 = mul nsw i32 %37, %38
%40 = srem i32 %36, %39
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = load i32, i32* %15
%45 = load i32, i32* %16
%46 = load i32, i32* %11
%47 = call i32 (i32, i8*, i32, i8, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i32 %44, i8 signext 37, i32 %45, i32 %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %35
store i32 0, i32* %17
br label %50
50: ; preds = %75, %49
%51 = load i32, i32* %17
%52 = load i32, i32* %10
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %78
54: ; preds = %50
%55 = load i32, i32* %9
%56 = load i32, i32* %11
%57 = load i32*, i32** %12
%58 = load i32, i32* %17
%59 = load i32, i32* %9
%60 = mul nsw i32 %58, %59
%61 = load i32, i32* %11
%62 = mul nsw i32 %60, %61
%63 = load i32, i32* %11
%64 = mul nsw i32 %62, %63
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %57, i64 %65
%67 = load i32, i32* %9
%68 = load i32, i32* %17
%69 = add nsw i32 %67, %68
%70 = load i8**, i8*** %13
%71 = load i8**, i8*** %14
%72 = load i32, i32* %15
%73 = load i32, i32* %16
%74 = call i32 @jerasure_bitmatrix_dotprod(i32 %55, i32 %56, i32* %66, i32* null, i32 %69, i8** %70, i8** %71, i32 %72, i32 %73)
br label %75
75: ; preds = %54
%76 = load i32, i32* %17
%77 = add nsw i32 %76, 1
store i32 %77, i32* %17
br label %50
78: ; preds = %50
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
}