#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 jerasure_matrix_decode(int, int, int, int *, int, int *, char **, char **,
                           int);
int /*<<< orphan*/ jerasure_matrix_encode(int, int, int, int *, char **,
                                          char **, int);
int /*<<< orphan*/ jerasure_print_matrix(int *, int, int, int);
int lrand48();
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, long *, int);
int /*<<< orphan*/ print_data_and_coding(int, int, int, int, char **, char **);
int /*<<< orphan*/ printf(char *, ...);
int *reed_sol_vandermonde_coding_matrix(int, int, int);
int /*<<< orphan*/ srand48(int /*<<< orphan*/);
scalar_t__ sscanf(char *, char *, int *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  long l;
  int k, w, i, m;
  int *matrix;
  char **data, **coding;
  int *erasures, *erased;
  if (argc != 4)
    usage(NULL);
  if (sscanf(argv[1], "%d", &k) == 0 || k <= 0)
    usage("Bad k");
  if (sscanf(argv[2], "%d", &m) == 0 || m <= 0)
    usage("Bad m");
  if (sscanf(argv[3], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32))
    usage("Bad w");
  if (w <= 16 && k + m > (1 << w))
    usage("k + m is too big");
  matrix = reed_sol_vandermonde_coding_matrix(k, m, w);
  printf("Last m rows of the Distribution Matrix:\n\n");
  jerasure_print_matrix(matrix, m, k, w);
  printf("\n");
  srand48(0);
  data = (char **)malloc(sizeof(char *) * (k));
  for (i = 0; i < k; i++) {
    data[i] = (char *)malloc(sizeof(char) * (sizeof(long)));
    l = lrand48();
    memcpy(data[i], &l, sizeof(long));
  }
  coding = (char **)malloc(sizeof(char *) * (m));
  for (i = 0; i < m; i++) {
    coding[i] = (char *)malloc(sizeof(char) * (sizeof(long)));
  }
  jerasure_matrix_encode(k, m, w, matrix, data, coding, sizeof(long));
  printf("Encoding Complete:\n\n");
  print_data_and_coding(k, m, w, sizeof(long), data, coding);
  erasures = (int *)malloc(sizeof(int) * ((m + 1)));
  erased = (int *)malloc(sizeof(int) * ((k + m)));
  for (i = 0; i < m + k; i++)
    erased[i] = 0;
  l = 0;
  for (i = 0; i < m;) {
    erasures[i] = lrand48() % (k + m);
    if (erased[erasures[i]] == 0) {
      erased[erasures[i]] = 1;
      memcpy((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i] - k],
             &l, sizeof(long));
      i++;
    }
  }
  erasures[i] = -1;
  printf("Erased %d random devices:\n\n", m);
  print_data_and_coding(k, m, w, sizeof(long), data, coding);
  i = jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding,
                             sizeof(long));
  printf("State of the system after decoding:\n\n");
  print_data_and_coding(k, m, w, sizeof(long), data, coding);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11e9 <main+0x29>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe08(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   10a0 <sscanf@plt>
cmp    $0x0,%rax
je     1215 <main+0x55>
cmpl   $0x0,-0x1c(%rbp)
jg     1221 <main+0x61>
lea    0xde7(%rip),%rdi
call   10d0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdd0(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   10a0 <sscanf@plt>
cmp    $0x0,%rax
je     124d <main+0x8d>
cmpl   $0x0,-0x28(%rbp)
jg     1259 <main+0x99>
lea    0xdb5(%rip),%rdi
call   10d0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xd98(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   10a0 <sscanf@plt>
cmp    $0x0,%rax
je     1299 <main+0xd9>
cmpl   $0x8,-0x20(%rbp)
je     12a5 <main+0xe5>
cmpl   $0x10,-0x20(%rbp)
je     12a5 <main+0xe5>
cmpl   $0x20,-0x20(%rbp)
je     12a5 <main+0xe5>
lea    0xd6f(%rip),%rdi
call   10d0 <usage@plt>
cmpl   $0x10,-0x20(%rbp)
jg     12d5 <main+0x115>
mov    -0x1c(%rbp),%eax
add    -0x28(%rbp),%eax
mov    -0x20(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jle    12d5 <main+0x115>
lea    0xd45(%rip),%rdi
call   10d0 <usage@plt>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1050 <reed_sol_vandermonde_coding_matrix@plt>
mov    %rax,-0x30(%rbp)
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1070 <jerasure_print_matrix@plt>
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10c0 <srand48@plt>
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1390 <main+0x1d0>
mov    $0x8,%edi
call   1090 <malloc@plt>
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    $0x0,%al
call   10b0 <lrand48@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1080 <memcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1336 <main+0x176>
movslq -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    13dd <main+0x21d>
mov    $0x8,%edi
call   1090 <malloc@plt>
mov    %rax,%rdx
mov    -0x40(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    13aa <main+0x1ea>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x40(%rbp),%r9
movl   $0x8,(%rsp)
call   1040 <jerasure_matrix_encode@plt>
lea    0xc4b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x38(%rbp),%r8
mov    -0x40(%rbp),%r9
mov    $0x8,%ecx
call   1030 <print_data_and_coding@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x28(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x28(%rbp),%ecx
add    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jge    148a <main+0x2ca>
mov    -0x50(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    145c <main+0x29c>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    155f <main+0x39f>
mov    $0x0,%al
call   10b0 <lrand48@plt>
mov    -0x1c(%rbp),%ecx
add    -0x28(%rbp),%ecx
cltd
idiv   %ecx
mov    -0x48(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x50(%rbp),%rax
mov    -0x48(%rbp),%rcx
movslq -0x24(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    155a <main+0x39a>
mov    -0x50(%rbp),%rax
mov    -0x48(%rbp),%rcx
movslq -0x24(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x48(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x1c(%rbp),%eax
jge    1522 <main+0x362>
mov    -0x38(%rbp),%rax
mov    -0x48(%rbp),%rcx
movslq -0x24(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x58(%rbp)
jmp    153f <main+0x37f>
mov    -0x40(%rbp),%rax
mov    -0x48(%rbp),%rcx
movslq -0x24(%rbp),%rdx
mov    (%rcx,%rdx,4),%ecx
sub    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1080 <memcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1499 <main+0x2d9>
mov    -0x48(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x28(%rbp),%esi
lea    0xaed(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x38(%rbp),%r8
mov    -0x40(%rbp),%r9
mov    $0x8,%ecx
call   1030 <print_data_and_coding@plt>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    -0x48(%rbp),%r9
mov    -0x38(%rbp),%r10
mov    -0x40(%rbp),%rax
mov    $0x1,%r8d
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
movl   $0x8,0x10(%rsp)
call   10e0 <jerasure_matrix_decode@plt>
mov    %eax,-0x24(%rbp)
lea    0xaa8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x38(%rbp),%r8
mov    -0x40(%rbp),%r9
mov    $0x8,%ecx
call   1030 <print_data_and_coding@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
je     11fd <main+0x1d>
xor    %edi,%edi
call   10f0 <usage@plt>
mov    0x8(%rbx),%rdi
lea    0xdf8(%rip),%rsi
lea    0x10(%rsp),%rdx
call   10c0 <sscanf@plt>
test   %rax,%rax
je     121e <main+0x3e>
cmpl   $0x0,0x10(%rsp)
jg     122a <main+0x4a>
lea    0xdde(%rip),%rdi
call   10f0 <usage@plt>
mov    0x10(%rbx),%rdi
lea    0xdcb(%rip),%rsi
lea    0xc(%rsp),%rdx
call   10c0 <sscanf@plt>
test   %rax,%rax
je     124b <main+0x6b>
cmpl   $0x0,0xc(%rsp)
jg     1257 <main+0x77>
lea    0xdb7(%rip),%rdi
call   10f0 <usage@plt>
mov    0x18(%rbx),%rdi
lea    0xd9e(%rip),%rsi
lea    0x14(%rsp),%rdx
call   10c0 <sscanf@plt>
test   %rax,%rax
je     1292 <main+0xb2>
mov    0x14(%rsp),%edx
cmp    $0x20,%rdx
ja     1292 <main+0xb2>
movabs $0x100010100,%rax
bt     %rdx,%rax
jae    1292 <main+0xb2>
cmp    $0x10,%edx
jle    12a7 <main+0xc7>
jmp    12cc <main+0xec>
lea    0xd76(%rip),%rdi
call   10f0 <usage@plt>
mov    0x14(%rsp),%edx
cmp    $0x10,%edx
jg     12cc <main+0xec>
mov    0xc(%rsp),%eax
add    0x10(%rsp),%eax
mov    $0x1,%esi
mov    %edx,%ecx
shl    %cl,%esi
cmp    %esi,%eax
jle    12cc <main+0xec>
lea    0xd52(%rip),%rdi
call   10f0 <usage@plt>
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
call   1070 <reed_sol_vandermonde_coding_matrix@plt>
mov    %rax,%r14
lea    0xd5f(%rip),%rdi
call   1060 <puts@plt>
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    %r14,%rdi
call   1090 <jerasure_print_matrix@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %edi,%edi
call   10e0 <srand48@plt>
mov    0x10(%rsp),%edi
shl    $0x3,%edi
call   10b0 <malloc@plt>
mov    %rax,%r12
cmpl   $0x0,0x10(%rsp)
jle    136b <main+0x18b>
lea    0x18(%rsp),%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x8,%edi
call   10b0 <malloc@plt>
mov    %rax,(%r12,%rbp,8)
xor    %eax,%eax
call   10d0 <lrand48@plt>
cltq
mov    %rax,0x18(%rsp)
mov    (%r12,%rbp,8),%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   10a0 <memcpy@plt>
add    $0x1,%rbp
movslq 0x10(%rsp),%rax
cmp    %rax,%rbp
jl     1330 <main+0x150>
mov    0xc(%rsp),%edi
shl    $0x3,%edi
call   10b0 <malloc@plt>
mov    %rax,%r15
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    13ac <main+0x1cc>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x8,%edi
call   10b0 <malloc@plt>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
movslq 0xc(%rsp),%rsi
cmp    %rsi,%rbx
jl     1390 <main+0x1b0>
mov    0x10(%rsp),%edi
mov    0x14(%rsp),%edx
sub    $0x8,%rsp
mov    %r14,%rcx
mov    %r12,%r8
mov    %r15,%r9
push   $0x8
call   1050 <jerasure_matrix_encode@plt>
add    $0x10,%rsp
lea    0xc98(%rip),%rdi
call   1060 <puts@plt>
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
mov    0x14(%rsp),%edx
mov    $0x8,%ecx
mov    %r12,%r8
mov    %r15,%r9
call   1030 <print_data_and_coding@plt>
mov    0xc(%rsp),%eax
lea    0x4(,%rax,4),%edi
call   10b0 <malloc@plt>
mov    %rax,%r13
mov    0xc(%rsp),%edi
add    0x10(%rsp),%edi
shl    $0x2,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%eax
mov    0x10(%rsp),%ecx
add    %eax,%ecx
jle    144d <main+0x26d>
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
movl   $0x0,(%rbx,%rcx,4)
add    $0x1,%rcx
movslq 0xc(%rsp),%rax
movslq 0x10(%rsp),%rdx
add    %rax,%rdx
cmp    %rdx,%rcx
jl     1430 <main+0x250>
movq   $0x0,0x18(%rsp)
test   %eax,%eax
mov    %r14,0x20(%rsp)
jle    14d4 <main+0x2f4>
xor    %r14d,%r14d
jmp    1477 <main+0x297>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    0xc(%rsp),%r14d
jge    14d7 <main+0x2f7>
xor    %eax,%eax
call   10d0 <lrand48@plt>
mov    0xc(%rsp),%ecx
add    0x10(%rsp),%ecx
cltd
idiv   %ecx
movslq %r14d,%rbp
mov    %edx,0x0(%r13,%rbp,4)
movslq %edx,%rax
cmpl   $0x0,(%rbx,%rax,4)
jne    1470 <main+0x290>
movl   $0x1,(%rbx,%rax,4)
movslq 0x0(%r13,%rbp,4),%rax
mov    0x10(%rsp),%ecx
lea    (%r12,%rax,8),%rdx
sub    %ecx,%eax
cltq
lea    (%r15,%rax,8),%rax
cmovl  %rdx,%rax
mov    (%rax),%rdi
lea    0x18(%rsp),%rsi
mov    $0x8,%edx
call   10a0 <memcpy@plt>
add    $0x1,%ebp
mov    %ebp,%r14d
jmp    1470 <main+0x290>
xor    %r14d,%r14d
movslq %r14d,%rax
movl   $0xffffffff,0x0(%r13,%rax,4)
ff ff
mov    0xc(%rsp),%esi
lea    0xb38(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
mov    0x14(%rsp),%edx
mov    $0x8,%ecx
mov    %r12,%r8
mov    %r15,%r9
call   1030 <print_data_and_coding@plt>
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
mov    0x14(%rsp),%edx
sub    $0x8,%rsp
mov    0x28(%rsp),%rcx
mov    $0x1,%r8d
mov    %r13,%r9
push   $0x8
push   %r15
push   %r12
call   1100 <jerasure_matrix_decode@plt>
add    $0x20,%rsp
lea    0xb3a(%rip),%rdi
call   1060 <puts@plt>
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
mov    0x14(%rsp),%edx
mov    $0x8,%ecx
mov    %r12,%r8
mov    %r15,%r9
call   1030 <print_data_and_coding@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"Bad k\00"
@.str.2 = [6 x i8] c"Bad m\00"
@.str.3 = [6 x i8] c"Bad w\00"
@.str.4 = [17 x i8] c"k + m is too big\00"
@.str.5 = [42 x i8] c"Last m rows of the Distribution Matrix:\0A\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [21 x i8] c"Encoding Complete:\0A\0A\00"
@.str.8 = [28 x i8] c"Erased %d random devices:\0A\0A\00"
@.str.9 = [38 x i8] c"State of the system after decoding:\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i8**
%13 = alloca i8**
%14 = alloca i32*
%15 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 4
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @usage(i8* null)
br label %20
20: ; preds = %18, %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @sscanf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %20
%27 = load i32, i32* %7
%28 = icmp sle i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26, %20
%30 = call i32 @usage(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %26
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i64 @sscanf(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %10)
%36 = icmp eq i64 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %31
%38 = load i32, i32* %10
%39 = icmp sle i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37, %31
%41 = call i32 @usage(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40, %37
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 3
%45 = load i8*, i8** %44
%46 = call i64 @sscanf(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%47 = icmp eq i64 %46, 0
br i1 %47, label %57, label %48
48: ; preds = %42
%49 = load i32, i32* %8
%50 = icmp ne i32 %49, 8
br i1 %50, label %51, label %59
51: ; preds = %48
%52 = load i32, i32* %8
%53 = icmp ne i32 %52, 16
br i1 %53, label %54, label %59
54: ; preds = %51
%55 = load i32, i32* %8
%56 = icmp ne i32 %55, 32
br i1 %56, label %57, label %59
57: ; preds = %54, %42
%58 = call i32 @usage(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %59
59: ; preds = %57, %54, %51, %48
%60 = load i32, i32* %8
%61 = icmp sle i32 %60, 16
br i1 %61, label %62, label %71
62: ; preds = %59
%63 = load i32, i32* %7
%64 = load i32, i32* %10
%65 = add nsw i32 %63, %64
%66 = load i32, i32* %8
%67 = shl i32 1, %66
%68 = icmp sgt i32 %65, %67
br i1 %68, label %69, label %71
69: ; preds = %62
%70 = call i32 @usage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %71
71: ; preds = %69, %62, %59
%72 = load i32, i32* %7
%73 = load i32, i32* %10
%74 = load i32, i32* %8
%75 = call i32* @reed_sol_vandermonde_coding_matrix(i32 %72, i32 %73, i32 %74)
store i32* %75, i32** %11
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
%77 = load i32*, i32** %11
%78 = load i32, i32* %10
%79 = load i32, i32* %7
%80 = load i32, i32* %8
%81 = call i32 @jerasure_print_matrix(i32* %77, i32 %78, i32 %79, i32 %80)
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%83 = call i32 @srand48(i32 0)
%84 = load i32, i32* %7
%85 = sext i32 %84 to i64
%86 = mul i64 8, %85
%87 = trunc i64 %86 to i32
%88 = call i64 @malloc(i32 %87)
%89 = inttoptr i64 %88 to i8**
store i8** %89, i8*** %12
store i32 0, i32* %9
br label %90
90: ; preds = %109, %71
%91 = load i32, i32* %9
%92 = load i32, i32* %7
%93 = icmp slt i32 %91, %92
br i1 %93, label %94, label %112
94: ; preds = %90
%95 = call i64 @malloc(i32 8)
%96 = inttoptr i64 %95 to i8*
%97 = load i8**, i8*** %12
%98 = load i32, i32* %9
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i8*, i8** %97, i64 %99
store i8* %96, i8** %100
%101 = call i32 (...) @lrand48()
%102 = sext i32 %101 to i64
store i64 %102, i64* %6
%103 = load i8**, i8*** %12
%104 = load i32, i32* %9
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i8*, i8** %103, i64 %105
%107 = load i8*, i8** %106
%108 = call i32 @memcpy(i8* %107, i64* %6, i32 8)
br label %109
109: ; preds = %94
%110 = load i32, i32* %9
%111 = add nsw i32 %110, 1
store i32 %111, i32* %9
br label %90
112: ; preds = %90
%113 = load i32, i32* %10
%114 = sext i32 %113 to i64
%115 = mul i64 8, %114
%116 = trunc i64 %115 to i32
%117 = call i64 @malloc(i32 %116)
%118 = inttoptr i64 %117 to i8**
store i8** %118, i8*** %13
store i32 0, i32* %9
br label %119
119: ; preds = %130, %112
%120 = load i32, i32* %9
%121 = load i32, i32* %10
%122 = icmp slt i32 %120, %121
br i1 %122, label %123, label %133
123: ; preds = %119
%124 = call i64 @malloc(i32 8)
%125 = inttoptr i64 %124 to i8*
%126 = load i8**, i8*** %13
%127 = load i32, i32* %9
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds i8*, i8** %126, i64 %128
store i8* %125, i8** %129
br label %130
130: ; preds = %123
%131 = load i32, i32* %9
%132 = add nsw i32 %131, 1
store i32 %132, i32* %9
br label %119
133: ; preds = %119
%134 = load i32, i32* %7
%135 = load i32, i32* %10
%136 = load i32, i32* %8
%137 = load i32*, i32** %11
%138 = load i8**, i8*** %12
%139 = load i8**, i8*** %13
%140 = call i32 @jerasure_matrix_encode(i32 %134, i32 %135, i32 %136, i32* %137, i8** %138, i8** %139, i32 8)
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%142 = load i32, i32* %7
%143 = load i32, i32* %10
%144 = load i32, i32* %8
%145 = load i8**, i8*** %12
%146 = load i8**, i8*** %13
%147 = call i32 @print_data_and_coding(i32 %142, i32 %143, i32 %144, i32 8, i8** %145, i8** %146)
%148 = load i32, i32* %10
%149 = add nsw i32 %148, 1
%150 = sext i32 %149 to i64
%151 = mul i64 4, %150
%152 = trunc i64 %151 to i32
%153 = call i64 @malloc(i32 %152)
%154 = inttoptr i64 %153 to i32*
store i32* %154, i32** %14
%155 = load i32, i32* %7
%156 = load i32, i32* %10
%157 = add nsw i32 %155, %156
%158 = sext i32 %157 to i64
%159 = mul i64 4, %158
%160 = trunc i64 %159 to i32
%161 = call i64 @malloc(i32 %160)
%162 = inttoptr i64 %161 to i32*
store i32* %162, i32** %15
store i32 0, i32* %9
br label %163
163: ; preds = %174, %133
%164 = load i32, i32* %9
%165 = load i32, i32* %10
%166 = load i32, i32* %7
%167 = add nsw i32 %165, %166
%168 = icmp slt i32 %164, %167
br i1 %168, label %169, label %177
169: ; preds = %163
%170 = load i32*, i32** %15
%171 = load i32, i32* %9
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds i32, i32* %170, i64 %172
store i32 0, i32* %173
br label %174
174: ; preds = %169
%175 = load i32, i32* %9
%176 = add nsw i32 %175, 1
store i32 %176, i32* %9
br label %163
177: ; preds = %163
store i64 0, i64* %6
store i32 0, i32* %9
br label %178
178: ; preds = %245, %177
%179 = load i32, i32* %9
%180 = load i32, i32* %10
%181 = icmp slt i32 %179, %180
br i1 %181, label %182, label %246
182: ; preds = %178
%183 = call i32 (...) @lrand48()
%184 = load i32, i32* %7
%185 = load i32, i32* %10
%186 = add nsw i32 %184, %185
%187 = srem i32 %183, %186
%188 = load i32*, i32** %14
%189 = load i32, i32* %9
%190 = sext i32 %189 to i64
%191 = getelementptr inbounds i32, i32* %188, i64 %190
store i32 %187, i32* %191
%192 = load i32*, i32** %15
%193 = load i32*, i32** %14
%194 = load i32, i32* %9
%195 = sext i32 %194 to i64
%196 = getelementptr inbounds i32, i32* %193, i64 %195
%197 = load i32, i32* %196
%198 = sext i32 %197 to i64
%199 = getelementptr inbounds i32, i32* %192, i64 %198
%200 = load i32, i32* %199
%201 = icmp eq i32 %200, 0
br i1 %201, label %202, label %245
202: ; preds = %182
%203 = load i32*, i32** %15
%204 = load i32*, i32** %14
%205 = load i32, i32* %9
%206 = sext i32 %205 to i64
%207 = getelementptr inbounds i32, i32* %204, i64 %206
%208 = load i32, i32* %207
%209 = sext i32 %208 to i64
%210 = getelementptr inbounds i32, i32* %203, i64 %209
store i32 1, i32* %210
%211 = load i32*, i32** %14
%212 = load i32, i32* %9
%213 = sext i32 %212 to i64
%214 = getelementptr inbounds i32, i32* %211, i64 %213
%215 = load i32, i32* %214
%216 = load i32, i32* %7
%217 = icmp slt i32 %215, %216
br i1 %217, label %218, label %228
218: ; preds = %202
%219 = load i8**, i8*** %12
%220 = load i32*, i32** %14
%221 = load i32, i32* %9
%222 = sext i32 %221 to i64
%223 = getelementptr inbounds i32, i32* %220, i64 %222
%224 = load i32, i32* %223
%225 = sext i32 %224 to i64
%226 = getelementptr inbounds i8*, i8** %219, i64 %225
%227 = load i8*, i8** %226
br label %240
228: ; preds = %202
%229 = load i8**, i8*** %13
%230 = load i32*, i32** %14
%231 = load i32, i32* %9
%232 = sext i32 %231 to i64
%233 = getelementptr inbounds i32, i32* %230, i64 %232
%234 = load i32, i32* %233
%235 = load i32, i32* %7
%236 = sub nsw i32 %234, %235
%237 = sext i32 %236 to i64
%238 = getelementptr inbounds i8*, i8** %229, i64 %237
%239 = load i8*, i8** %238
br label %240
240: ; preds = %228, %218
%241 = phi i8* [ %227, %218 ], [ %239, %228 ]
%242 = call i32 @memcpy(i8* %241, i64* %6, i32 8)
%243 = load i32, i32* %9
%244 = add nsw i32 %243, 1
store i32 %244, i32* %9
br label %245
245: ; preds = %240, %182
br label %178
246: ; preds = %178
%247 = load i32*, i32** %14
%248 = load i32, i32* %9
%249 = sext i32 %248 to i64
%250 = getelementptr inbounds i32, i32* %247, i64 %249
store i32 -1, i32* %250
%251 = load i32, i32* %10
%252 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i32 %251)
%253 = load i32, i32* %7
%254 = load i32, i32* %10
%255 = load i32, i32* %8
%256 = load i8**, i8*** %12
%257 = load i8**, i8*** %13
%258 = call i32 @print_data_and_coding(i32 %253, i32 %254, i32 %255, i32 8, i8** %256, i8** %257)
%259 = load i32, i32* %7
%260 = load i32, i32* %10
%261 = load i32, i32* %8
%262 = load i32*, i32** %11
%263 = load i32*, i32** %14
%264 = load i8**, i8*** %12
%265 = load i8**, i8*** %13
%266 = call i32 @jerasure_matrix_decode(i32 %259, i32 %260, i32 %261, i32* %262, i32 1, i32* %263, i8** %264, i8** %265, i32 8)
store i32 %266, i32* %9
%267 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.9, i64 0, i64 0))
%268 = load i32, i32* %7
%269 = load i32, i32* %10
%270 = load i32, i32* %8
%271 = load i8**, i8*** %12
%272 = load i8**, i8*** %13
%273 = call i32 @print_data_and_coding(i32 %268, i32 %269, i32 %270, i32 8, i8** %271, i8** %272)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"Bad k\00"
@.str.2 = [6 x i8] c"Bad m\00"
@.str.3 = [6 x i8] c"Bad w\00"
@.str.4 = [17 x i8] c"k + m is too big\00"
@.str.8 = [28 x i8] c"Erased %d random devices:\0A\0A\00"
@str = [41 x i8] c"Last m rows of the Distribution Matrix:\0A\00"
@str.10 = [20 x i8] c"Encoding Complete:\0A\00"
@str.11 = [37 x i8] c"State of the system after decoding:\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i64* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = icmp eq i32 %0, 4
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = tail call i32 @usage(i8* null)
br label %14
14: ; preds = %12, %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%18 = icmp eq i64 %17, 0
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 1
%21 = select i1 %18, i1 true, i1 %20
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 @usage(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %14, %22
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = call i64 @sscanf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%28 = icmp eq i64 %27, 0
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 1
%31 = select i1 %28, i1 true, i1 %30
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = call i32 @usage(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %24, %32
%35 = getelementptr inbounds i8*, i8** %1, i64 3
%36 = load i8*, i8** %35
%37 = call i64 @sscanf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%38 = icmp eq i64 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %34
%40 = load i32, i32* %5
switch i32 %40, label %41 [
i32 32, label %44
i32 16, label %44
i32 8, label %44
]
41: ; preds = %39, %34
%42 = call i32 @usage(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* %5
br label %44
44: ; preds = %39, %39, %39, %41
%45 = phi i32 [ %40, %39 ], [ %40, %39 ], [ %40, %39 ], [ %43, %41 ]
%46 = icmp slt i32 %45, 17
br i1 %46, label %47, label %56
47: ; preds = %44
%48 = load i32, i32* %4
%49 = load i32, i32* %6
%50 = add nsw i32 %49, %48
%51 = shl nuw nsw i32 1, %45
%52 = icmp sgt i32 %50, %51
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = call i32 @usage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%55 = load i32, i32* %5
br label %56
56: ; preds = %53, %47, %44
%57 = phi i32 [ %55, %53 ], [ %45, %47 ], [ %45, %44 ]
%58 = load i32, i32* %4
%59 = load i32, i32* %6
%60 = call i32* @reed_sol_vandermonde_coding_matrix(i32 %58, i32 %59, i32 %57)
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%62 = load i32, i32* %6
%63 = load i32, i32* %4
%64 = load i32, i32* %5
%65 = call i32 @jerasure_print_matrix(i32* %60, i32 %62, i32 %63, i32 %64)
%66 = call i32 @putchar(i32 10)
%67 = call i32 @srand48(i32 0)
%68 = load i32, i32* %4
%69 = shl i32 %68, 3
%70 = call i64 @malloc(i32 %69)
%71 = inttoptr i64 %70 to i8**
%72 = load i32, i32* %4
%73 = icmp sgt i32 %72, 0
br i1 %73, label %74, label %87
74: ; preds = %56, %74
%75 = phi i64 [ %83, %74 ], [ 0, %56 ]
%76 = call i64 @malloc(i32 8)
%77 = inttoptr i64 %76 to i8*
%78 = getelementptr inbounds i8*, i8** %71, i64 %75
store i8* %77, i8** %78
%79 = call i32 (...) @lrand48()
%80 = sext i32 %79 to i64
store i64 %80, i64* %3
%81 = load i8*, i8** %78
%82 = call i32 @memcpy(i8* %81, i64* %3, i32 8)
%83 = add nuw nsw i64 %75, 1
%84 = load i32, i32* %4
%85 = sext i32 %84 to i64
%86 = icmp slt i64 %83, %85
br i1 %86, label %74, label %87
87: ; preds = %74, %56
%88 = load i32, i32* %6
%89 = shl i32 %88, 3
%90 = call i64 @malloc(i32 %89)
%91 = inttoptr i64 %90 to i8**
%92 = load i32, i32* %6
%93 = icmp sgt i32 %92, 0
br i1 %93, label %94, label %103
94: ; preds = %87, %94
%95 = phi i64 [ %99, %94 ], [ 0, %87 ]
%96 = call i64 @malloc(i32 8)
%97 = inttoptr i64 %96 to i8*
%98 = getelementptr inbounds i8*, i8** %91, i64 %95
store i8* %97, i8** %98
%99 = add nuw nsw i64 %95, 1
%100 = load i32, i32* %6
%101 = sext i32 %100 to i64
%102 = icmp slt i64 %99, %101
br i1 %102, label %94, label %103
103: ; preds = %94, %87
%104 = phi i32 [ %92, %87 ], [ %100, %94 ]
%105 = load i32, i32* %4
%106 = load i32, i32* %5
%107 = call i32 @jerasure_matrix_encode(i32 %105, i32 %104, i32 %106, i32* %60, i8** %71, i8** %91, i32 8)
%108 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.10, i64 0, i64 0))
%109 = load i32, i32* %4
%110 = load i32, i32* %6
%111 = load i32, i32* %5
%112 = call i32 @print_data_and_coding(i32 %109, i32 %110, i32 %111, i32 8, i8** %71, i8** %91)
%113 = load i32, i32* %6
%114 = shl i32 %113, 2
%115 = add i32 %114, 4
%116 = call i64 @malloc(i32 %115)
%117 = inttoptr i64 %116 to i32*
%118 = load i32, i32* %4
%119 = load i32, i32* %6
%120 = add nsw i32 %119, %118
%121 = shl i32 %120, 2
%122 = call i64 @malloc(i32 %121)
%123 = inttoptr i64 %122 to i32*
%124 = load i32, i32* %6
%125 = load i32, i32* %4
%126 = add nsw i32 %125, %124
%127 = icmp sgt i32 %126, 0
br i1 %127, label %128, label %137
128: ; preds = %103, %128
%129 = phi i64 [ %131, %128 ], [ 0, %103 ]
%130 = getelementptr inbounds i32, i32* %123, i64 %129
store i32 0, i32* %130
%131 = add nuw nsw i64 %129, 1
%132 = load i32, i32* %6
%133 = load i32, i32* %4
%134 = add nsw i32 %133, %132
%135 = sext i32 %134 to i64
%136 = icmp slt i64 %131, %135
br i1 %136, label %128, label %137
137: ; preds = %128, %103
%138 = phi i32 [ %124, %103 ], [ %132, %128 ]
store i64 0, i64* %3
%139 = icmp sgt i32 %138, 0
br i1 %139, label %140, label %170
140: ; preds = %137, %166
%141 = phi i32 [ %167, %166 ], [ 0, %137 ]
%142 = call i32 (...) @lrand48()
%143 = load i32, i32* %4
%144 = load i32, i32* %6
%145 = add nsw i32 %144, %143
%146 = srem i32 %142, %145
%147 = sext i32 %141 to i64
%148 = getelementptr inbounds i32, i32* %117, i64 %147
store i32 %146, i32* %148
%149 = sext i32 %146 to i64
%150 = getelementptr inbounds i32, i32* %123, i64 %149
%151 = load i32, i32* %150
%152 = icmp eq i32 %151, 0
br i1 %152, label %153, label %166
153: ; preds = %140
store i32 1, i32* %150
%154 = load i32, i32* %148
%155 = load i32, i32* %4
%156 = icmp slt i32 %154, %155
%157 = sext i32 %154 to i64
%158 = getelementptr inbounds i8*, i8** %71, i64 %157
%159 = sub nsw i32 %154, %155
%160 = sext i32 %159 to i64
%161 = getelementptr inbounds i8*, i8** %91, i64 %160
%162 = select i1 %156, i8** %158, i8** %161
%163 = load i8*, i8** %162
%164 = call i32 @memcpy(i8* %163, i64* %3, i32 8)
%165 = add nsw i32 %141, 1
br label %166
166: ; preds = %153, %140
%167 = phi i32 [ %165, %153 ], [ %141, %140 ]
%168 = load i32, i32* %6
%169 = icmp slt i32 %167, %168
br i1 %169, label %140, label %170
170: ; preds = %166, %137
%171 = phi i32 [ 0, %137 ], [ %167, %166 ]
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds i32, i32* %117, i64 %172
store i32 -1, i32* %173
%174 = load i32, i32* %6
%175 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i32 %174)
%176 = load i32, i32* %4
%177 = load i32, i32* %6
%178 = load i32, i32* %5
%179 = call i32 @print_data_and_coding(i32 %176, i32 %177, i32 %178, i32 8, i8** %71, i8** %91)
%180 = load i32, i32* %4
%181 = load i32, i32* %6
%182 = load i32, i32* %5
%183 = call i32 @jerasure_matrix_decode(i32 %180, i32 %181, i32 %182, i32* %60, i32 1, i32* %117, i8** %71, i8** %91, i32 8)
%184 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.11, i64 0, i64 0))
%185 = load i32, i32* %4
%186 = load i32, i32* %6
%187 = load i32, i32* %5
%188 = call i32 @print_data_and_coding(i32 %185, i32 %186, i32 %187, i32 8, i8** %71, i8** %91)
ret i32 0
}