#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, j, m;
  int *matrix;
  char **data, **coding;
  int *erasures, *erased;
  int *decoding_matrix, *dm_ids;
  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    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11ec <main+0x2c>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe05(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   10a0 <sscanf@plt>
cmp    $0x0,%rax
je     1218 <main+0x58>
cmpl   $0x0,-0x1c(%rbp)
jg     1224 <main+0x64>
lea    0xde4(%rip),%rdi
call   10d0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdcd(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   10a0 <sscanf@plt>
cmp    $0x0,%rax
je     1250 <main+0x90>
cmpl   $0x0,-0x2c(%rbp)
jg     125c <main+0x9c>
lea    0xdb2(%rip),%rdi
call   10d0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xd95(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   10a0 <sscanf@plt>
cmp    $0x0,%rax
je     129c <main+0xdc>
cmpl   $0x8,-0x20(%rbp)
je     12a8 <main+0xe8>
cmpl   $0x10,-0x20(%rbp)
je     12a8 <main+0xe8>
cmpl   $0x20,-0x20(%rbp)
je     12a8 <main+0xe8>
lea    0xd6c(%rip),%rdi
call   10d0 <usage@plt>
cmpl   $0x10,-0x20(%rbp)
jg     12d8 <main+0x118>
mov    -0x1c(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    -0x20(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jle    12d8 <main+0x118>
lea    0xd42(%rip),%rdi
call   10d0 <usage@plt>
mov    -0x1c(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1050 <reed_sol_vandermonde_coding_matrix@plt>
mov    %rax,-0x38(%rbp)
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1070 <jerasure_print_matrix@plt>
lea    0xd52(%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,-0x40(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1393 <main+0x1d3>
mov    $0x8,%edi
call   1090 <malloc@plt>
mov    %rax,%rdx
mov    -0x40(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    $0x0,%al
call   10b0 <lrand48@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x40(%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    1339 <main+0x179>
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    13e0 <main+0x220>
mov    $0x8,%edi
call   1090 <malloc@plt>
mov    %rax,%rdx
mov    -0x48(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    13ad <main+0x1ed>
mov    -0x1c(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x48(%rbp),%r9
movl   $0x8,(%rsp)
call   1040 <jerasure_matrix_encode@plt>
lea    0xc48(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x40(%rbp),%r8
mov    -0x48(%rbp),%r9
mov    $0x8,%ecx
call   1030 <print_data_and_coding@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x2c(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x2c(%rbp),%ecx
add    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jge    148d <main+0x2cd>
mov    -0x58(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    145f <main+0x29f>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1562 <main+0x3a2>
mov    $0x0,%al
call   10b0 <lrand48@plt>
mov    -0x1c(%rbp),%ecx
add    -0x2c(%rbp),%ecx
cltd
idiv   %ecx
mov    -0x50(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x58(%rbp),%rax
mov    -0x50(%rbp),%rcx
movslq -0x24(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    155d <main+0x39d>
mov    -0x58(%rbp),%rax
mov    -0x50(%rbp),%rcx
movslq -0x24(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x50(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x1c(%rbp),%eax
jge    1525 <main+0x365>
mov    -0x40(%rbp),%rax
mov    -0x50(%rbp),%rcx
movslq -0x24(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x70(%rbp)
jmp    1542 <main+0x382>
mov    -0x48(%rbp),%rax
mov    -0x50(%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,-0x70(%rbp)
mov    -0x70(%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    149c <main+0x2dc>
mov    -0x50(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x2c(%rbp),%esi
lea    0xaea(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x40(%rbp),%r8
mov    -0x48(%rbp),%r9
mov    $0x8,%ecx
call   1030 <print_data_and_coding@plt>
mov    -0x1c(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x38(%rbp),%rcx
mov    -0x50(%rbp),%r9
mov    -0x40(%rbp),%r10
mov    -0x48(%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    0xaa5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x40(%rbp),%r8
mov    -0x48(%rbp),%r9
mov    $0x8,%ecx
call   1030 <print_data_and_coding@plt>
xor    %eax,%eax
add    $0x90,%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 i32*
%13 = alloca i8**
%14 = alloca i8**
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 4
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @usage(i8* null)
br label %23
23: ; preds = %21, %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%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* %7)
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %23
%30 = load i32, i32* %7
%31 = icmp sle i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29, %23
%33 = call i32 @usage(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i64 @sscanf(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %11)
%39 = icmp eq i64 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %34
%41 = load i32, i32* %11
%42 = icmp sle i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40, %34
%44 = call i32 @usage(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 3
%48 = load i8*, i8** %47
%49 = call i64 @sscanf(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%50 = icmp eq i64 %49, 0
br i1 %50, label %60, label %51
51: ; preds = %45
%52 = load i32, i32* %8
%53 = icmp ne i32 %52, 8
br i1 %53, label %54, label %62
54: ; preds = %51
%55 = load i32, i32* %8
%56 = icmp ne i32 %55, 16
br i1 %56, label %57, label %62
57: ; preds = %54
%58 = load i32, i32* %8
%59 = icmp ne i32 %58, 32
br i1 %59, label %60, label %62
60: ; preds = %57, %45
%61 = call i32 @usage(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %62
62: ; preds = %60, %57, %54, %51
%63 = load i32, i32* %8
%64 = icmp sle i32 %63, 16
br i1 %64, label %65, label %74
65: ; preds = %62
%66 = load i32, i32* %7
%67 = load i32, i32* %11
%68 = add nsw i32 %66, %67
%69 = load i32, i32* %8
%70 = shl i32 1, %69
%71 = icmp sgt i32 %68, %70
br i1 %71, label %72, label %74
72: ; preds = %65
%73 = call i32 @usage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %74
74: ; preds = %72, %65, %62
%75 = load i32, i32* %7
%76 = load i32, i32* %11
%77 = load i32, i32* %8
%78 = call i32* @reed_sol_vandermonde_coding_matrix(i32 %75, i32 %76, i32 %77)
store i32* %78, i32** %12
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
%80 = load i32*, i32** %12
%81 = load i32, i32* %11
%82 = load i32, i32* %7
%83 = load i32, i32* %8
%84 = call i32 @jerasure_print_matrix(i32* %80, i32 %81, i32 %82, i32 %83)
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%86 = call i32 @srand48(i32 0)
%87 = load i32, i32* %7
%88 = sext i32 %87 to i64
%89 = mul i64 8, %88
%90 = trunc i64 %89 to i32
%91 = call i64 @malloc(i32 %90)
%92 = inttoptr i64 %91 to i8**
store i8** %92, i8*** %13
store i32 0, i32* %9
br label %93
93: ; preds = %112, %74
%94 = load i32, i32* %9
%95 = load i32, i32* %7
%96 = icmp slt i32 %94, %95
br i1 %96, label %97, label %115
97: ; preds = %93
%98 = call i64 @malloc(i32 8)
%99 = inttoptr i64 %98 to i8*
%100 = load i8**, i8*** %13
%101 = load i32, i32* %9
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i8*, i8** %100, i64 %102
store i8* %99, i8** %103
%104 = call i32 (...) @lrand48()
%105 = sext i32 %104 to i64
store i64 %105, i64* %6
%106 = load i8**, i8*** %13
%107 = load i32, i32* %9
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i8*, i8** %106, i64 %108
%110 = load i8*, i8** %109
%111 = call i32 @memcpy(i8* %110, i64* %6, i32 8)
br label %112
112: ; preds = %97
%113 = load i32, i32* %9
%114 = add nsw i32 %113, 1
store i32 %114, i32* %9
br label %93
115: ; preds = %93
%116 = load i32, i32* %11
%117 = sext i32 %116 to i64
%118 = mul i64 8, %117
%119 = trunc i64 %118 to i32
%120 = call i64 @malloc(i32 %119)
%121 = inttoptr i64 %120 to i8**
store i8** %121, i8*** %14
store i32 0, i32* %9
br label %122
122: ; preds = %133, %115
%123 = load i32, i32* %9
%124 = load i32, i32* %11
%125 = icmp slt i32 %123, %124
br i1 %125, label %126, label %136
126: ; preds = %122
%127 = call i64 @malloc(i32 8)
%128 = inttoptr i64 %127 to i8*
%129 = load i8**, i8*** %14
%130 = load i32, i32* %9
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds i8*, i8** %129, i64 %131
store i8* %128, i8** %132
br label %133
133: ; preds = %126
%134 = load i32, i32* %9
%135 = add nsw i32 %134, 1
store i32 %135, i32* %9
br label %122
136: ; preds = %122
%137 = load i32, i32* %7
%138 = load i32, i32* %11
%139 = load i32, i32* %8
%140 = load i32*, i32** %12
%141 = load i8**, i8*** %13
%142 = load i8**, i8*** %14
%143 = call i32 @jerasure_matrix_encode(i32 %137, i32 %138, i32 %139, i32* %140, i8** %141, i8** %142, i32 8)
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%145 = load i32, i32* %7
%146 = load i32, i32* %11
%147 = load i32, i32* %8
%148 = load i8**, i8*** %13
%149 = load i8**, i8*** %14
%150 = call i32 @print_data_and_coding(i32 %145, i32 %146, i32 %147, i32 8, i8** %148, i8** %149)
%151 = load i32, i32* %11
%152 = add nsw i32 %151, 1
%153 = sext i32 %152 to i64
%154 = mul i64 4, %153
%155 = trunc i64 %154 to i32
%156 = call i64 @malloc(i32 %155)
%157 = inttoptr i64 %156 to i32*
store i32* %157, i32** %15
%158 = load i32, i32* %7
%159 = load i32, i32* %11
%160 = add nsw i32 %158, %159
%161 = sext i32 %160 to i64
%162 = mul i64 4, %161
%163 = trunc i64 %162 to i32
%164 = call i64 @malloc(i32 %163)
%165 = inttoptr i64 %164 to i32*
store i32* %165, i32** %16
store i32 0, i32* %9
br label %166
166: ; preds = %177, %136
%167 = load i32, i32* %9
%168 = load i32, i32* %11
%169 = load i32, i32* %7
%170 = add nsw i32 %168, %169
%171 = icmp slt i32 %167, %170
br i1 %171, label %172, label %180
172: ; preds = %166
%173 = load i32*, i32** %16
%174 = load i32, i32* %9
%175 = sext i32 %174 to i64
%176 = getelementptr inbounds i32, i32* %173, i64 %175
store i32 0, i32* %176
br label %177
177: ; preds = %172
%178 = load i32, i32* %9
%179 = add nsw i32 %178, 1
store i32 %179, i32* %9
br label %166
180: ; preds = %166
store i64 0, i64* %6
store i32 0, i32* %9
br label %181
181: ; preds = %248, %180
%182 = load i32, i32* %9
%183 = load i32, i32* %11
%184 = icmp slt i32 %182, %183
br i1 %184, label %185, label %249
185: ; preds = %181
%186 = call i32 (...) @lrand48()
%187 = load i32, i32* %7
%188 = load i32, i32* %11
%189 = add nsw i32 %187, %188
%190 = srem i32 %186, %189
%191 = load i32*, i32** %15
%192 = load i32, i32* %9
%193 = sext i32 %192 to i64
%194 = getelementptr inbounds i32, i32* %191, i64 %193
store i32 %190, i32* %194
%195 = load i32*, i32** %16
%196 = load i32*, i32** %15
%197 = load i32, i32* %9
%198 = sext i32 %197 to i64
%199 = getelementptr inbounds i32, i32* %196, i64 %198
%200 = load i32, i32* %199
%201 = sext i32 %200 to i64
%202 = getelementptr inbounds i32, i32* %195, i64 %201
%203 = load i32, i32* %202
%204 = icmp eq i32 %203, 0
br i1 %204, label %205, label %248
205: ; preds = %185
%206 = load i32*, i32** %16
%207 = load i32*, i32** %15
%208 = load i32, i32* %9
%209 = sext i32 %208 to i64
%210 = getelementptr inbounds i32, i32* %207, i64 %209
%211 = load i32, i32* %210
%212 = sext i32 %211 to i64
%213 = getelementptr inbounds i32, i32* %206, i64 %212
store i32 1, i32* %213
%214 = load i32*, i32** %15
%215 = load i32, i32* %9
%216 = sext i32 %215 to i64
%217 = getelementptr inbounds i32, i32* %214, i64 %216
%218 = load i32, i32* %217
%219 = load i32, i32* %7
%220 = icmp slt i32 %218, %219
br i1 %220, label %221, label %231
221: ; preds = %205
%222 = load i8**, i8*** %13
%223 = load i32*, i32** %15
%224 = load i32, i32* %9
%225 = sext i32 %224 to i64
%226 = getelementptr inbounds i32, i32* %223, i64 %225
%227 = load i32, i32* %226
%228 = sext i32 %227 to i64
%229 = getelementptr inbounds i8*, i8** %222, i64 %228
%230 = load i8*, i8** %229
br label %243
231: ; preds = %205
%232 = load i8**, i8*** %14
%233 = load i32*, i32** %15
%234 = load i32, i32* %9
%235 = sext i32 %234 to i64
%236 = getelementptr inbounds i32, i32* %233, i64 %235
%237 = load i32, i32* %236
%238 = load i32, i32* %7
%239 = sub nsw i32 %237, %238
%240 = sext i32 %239 to i64
%241 = getelementptr inbounds i8*, i8** %232, i64 %240
%242 = load i8*, i8** %241
br label %243
243: ; preds = %231, %221
%244 = phi i8* [ %230, %221 ], [ %242, %231 ]
%245 = call i32 @memcpy(i8* %244, i64* %6, i32 8)
%246 = load i32, i32* %9
%247 = add nsw i32 %246, 1
store i32 %247, i32* %9
br label %248
248: ; preds = %243, %185
br label %181
249: ; preds = %181
%250 = load i32*, i32** %15
%251 = load i32, i32* %9
%252 = sext i32 %251 to i64
%253 = getelementptr inbounds i32, i32* %250, i64 %252
store i32 -1, i32* %253
%254 = load i32, i32* %11
%255 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i32 %254)
%256 = load i32, i32* %7
%257 = load i32, i32* %11
%258 = load i32, i32* %8
%259 = load i8**, i8*** %13
%260 = load i8**, i8*** %14
%261 = call i32 @print_data_and_coding(i32 %256, i32 %257, i32 %258, i32 8, i8** %259, i8** %260)
%262 = load i32, i32* %7
%263 = load i32, i32* %11
%264 = load i32, i32* %8
%265 = load i32*, i32** %12
%266 = load i32*, i32** %15
%267 = load i8**, i8*** %13
%268 = load i8**, i8*** %14
%269 = call i32 @jerasure_matrix_decode(i32 %262, i32 %263, i32 %264, i32* %265, i32 1, i32* %266, i8** %267, i8** %268, i32 8)
store i32 %269, i32* %9
%270 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.9, i64 0, i64 0))
%271 = load i32, i32* %7
%272 = load i32, i32* %11
%273 = load i32, i32* %8
%274 = load i8**, i8*** %13
%275 = load i8**, i8*** %14
%276 = call i32 @print_data_and_coding(i32 %271, i32 %272, i32 %273, i32 8, i8** %274, i8** %275)
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
}