#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_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_r6_coding_matrix(int, int);
int /*<<< orphan*/ reed_sol_r6_encode(int, int, char **, char **, 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 != 3)
    usage(NULL);
  if (sscanf(argv[1], "%d", &k) == 0 || k <= 0)
    usage("Bad k");
  if (sscanf(argv[2], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32))
    usage("Bad w");
  m = 2;
  if (w <= 16 && k + m > (1 << w))
    usage("k + m is too big");
  matrix = reed_sol_r6_coding_matrix(k, w);
  printf("Last 2 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)));
  }
  reed_sol_r6_encode(k, w, 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   $0x3,-0x8(%rbp)
je     11e9 <main+0x29>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe08(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1090 <sscanf@plt>
cmp    $0x0,%rax
je     1215 <main+0x55>
cmpl   $0x0,-0x1c(%rbp)
jg     1221 <main+0x61>
lea    0xde7(%rip),%rdi
call   10c0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdd0(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1090 <sscanf@plt>
cmp    $0x0,%rax
je     1261 <main+0xa1>
cmpl   $0x8,-0x20(%rbp)
je     126d <main+0xad>
cmpl   $0x10,-0x20(%rbp)
je     126d <main+0xad>
cmpl   $0x20,-0x20(%rbp)
je     126d <main+0xad>
lea    0xda1(%rip),%rdi
call   10c0 <usage@plt>
movl   $0x2,-0x28(%rbp)
cmpl   $0x10,-0x20(%rbp)
jg     12a4 <main+0xe4>
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    12a4 <main+0xe4>
lea    0xd70(%rip),%rdi
call   10c0 <usage@plt>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <reed_sol_r6_coding_matrix@plt>
mov    %rax,-0x30(%rbp)
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1060 <jerasure_print_matrix@plt>
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <srand48@plt>
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    135c <main+0x19c>
mov    $0x8,%edi
call   1080 <malloc@plt>
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    $0x0,%al
call   10a0 <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   1070 <memcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1302 <main+0x142>
movslq -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    13a9 <main+0x1e9>
mov    $0x8,%edi
call   1080 <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    1376 <main+0x1b6>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    $0x8,%r8d
call   10e0 <reed_sol_r6_encode@plt>
lea    0xc81(%rip),%rdi
mov    $0x0,%al
call   1050 <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   1080 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x28(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <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    144e <main+0x28e>
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    1420 <main+0x260>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1523 <main+0x363>
mov    $0x0,%al
call   10a0 <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    151e <main+0x35e>
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    14e6 <main+0x326>
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    1503 <main+0x343>
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   1070 <memcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    145d <main+0x29d>
mov    -0x48(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x28(%rbp),%esi
lea    0xb23(%rip),%rdi
mov    $0x0,%al
call   1050 <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   10d0 <jerasure_matrix_decode@plt>
mov    %eax,-0x24(%rbp)
lea    0xade(%rip),%rdi
mov    $0x0,%al
call   1050 <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    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
je     11fd <main+0x1d>
xor    %edi,%edi
call   10e0 <usage@plt>
mov    0x8(%rbx),%rdi
lea    0xdf8(%rip),%rsi
mov    %rsp,%rdx
call   10b0 <sscanf@plt>
test   %rax,%rax
je     121b <main+0x3b>
cmpl   $0x0,(%rsp)
jg     1227 <main+0x47>
lea    0xde1(%rip),%rdi
call   10e0 <usage@plt>
mov    0x10(%rbx),%rdi
lea    0xdce(%rip),%rsi
lea    0x4(%rsp),%rdx
call   10b0 <sscanf@plt>
test   %rax,%rax
je     1262 <main+0x82>
mov    0x4(%rsp),%esi
cmp    $0x20,%rsi
ja     1262 <main+0x82>
movabs $0x100010100,%rax
bt     %rsi,%rax
jae    1262 <main+0x82>
cmp    $0x10,%esi
jle    1277 <main+0x97>
jmp    129a <main+0xba>
lea    0xda0(%rip),%rdi
call   10e0 <usage@plt>
mov    0x4(%rsp),%esi
cmp    $0x10,%esi
jg     129a <main+0xba>
mov    (%rsp),%eax
add    $0x2,%eax
mov    $0x1,%edx
mov    %esi,%ecx
shl    %cl,%edx
cmp    %edx,%eax
jle    129a <main+0xba>
lea    0xd7e(%rip),%rdi
call   10e0 <usage@plt>
mov    0x4(%rsp),%esi
mov    (%rsp),%edi
call   1050 <reed_sol_r6_coding_matrix@plt>
mov    %rax,%rbx
lea    0xd90(%rip),%rdi
call   1060 <puts@plt>
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    %rbx,0x10(%rsp)
mov    %rbx,%rdi
mov    $0x2,%esi
call   1080 <jerasure_print_matrix@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %edi,%edi
call   10d0 <srand48@plt>
mov    (%rsp),%edi
shl    $0x3,%edi
call   10a0 <malloc@plt>
mov    %rax,%r12
cmpl   $0x0,(%rsp)
jle    133a <main+0x15a>
lea    0x8(%rsp),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    $0x8,%edi
call   10a0 <malloc@plt>
mov    %rax,(%r12,%rbp,8)
xor    %eax,%eax
call   10c0 <lrand48@plt>
cltq
mov    %rax,0x8(%rsp)
mov    (%r12,%rbp,8),%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1090 <memcpy@plt>
add    $0x1,%rbp
movslq (%rsp),%rax
cmp    %rax,%rbp
jl     1300 <main+0x120>
mov    $0x10,%edi
call   10a0 <malloc@plt>
mov    %rax,%r15
mov    $0x8,%edi
call   10a0 <malloc@plt>
mov    %rax,(%r15)
mov    $0x8,%edi
call   10a0 <malloc@plt>
mov    %rax,0x8(%r15)
mov    (%rsp),%edi
mov    0x4(%rsp),%esi
mov    %r12,%rdx
mov    %r15,%rcx
mov    $0x8,%r8d
call   1100 <reed_sol_r6_encode@plt>
lea    0xce4(%rip),%rdi
call   1060 <puts@plt>
mov    (%rsp),%edi
mov    0x4(%rsp),%edx
mov    $0x2,%esi
mov    $0x8,%ecx
mov    %r12,%r8
mov    %r15,%r9
call   1030 <print_data_and_coding@plt>
mov    $0xc,%edi
call   10a0 <malloc@plt>
mov    %rax,%r13
mov    (%rsp),%eax
lea    0x8(,%rax,4),%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
cmpl   $0xffffffff,(%rsp)
jl     13e5 <main+0x205>
mov    $0xffffffffffffffff,%rax
xchg   %ax,%ax
movl   $0x0,0x4(%rbx,%rax,4)
movslq (%rsp),%rcx
add    $0x1,%rax
cmp    %rcx,%rax
jle    13d0 <main+0x1f0>
movq   $0x0,0x8(%rsp)
xor    %r14d,%r14d
jmp    1406 <main+0x226>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x2,%r14d
jge    1460 <main+0x280>
xor    %eax,%eax
call   10c0 <lrand48@plt>
mov    (%rsp),%ecx
add    $0x2,%ecx
cltd
idiv   %ecx
movslq %r14d,%rbp
mov    %edx,0x0(%r13,%rbp,4)
movslq %edx,%rax
cmpl   $0x0,(%rbx,%rax,4)
jne    1400 <main+0x220>
movl   $0x1,(%rbx,%rax,4)
movslq 0x0(%r13,%rbp,4),%rax
mov    (%rsp),%ecx
lea    (%r12,%rax,8),%rdx
sub    %ecx,%eax
cltq
lea    (%r15,%rax,8),%rax
cmovl  %rdx,%rax
mov    (%rax),%rdi
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
call   1090 <memcpy@plt>
add    $0x1,%ebp
mov    %ebp,%r14d
jmp    1400 <main+0x220>
mov    %r14d,%eax
movl   $0xffffffff,0x0(%r13,%rax,4)
ff ff
lea    0xbad(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%rsp),%edi
mov    0x4(%rsp),%edx
mov    $0x2,%esi
mov    $0x8,%ecx
mov    %r12,%r8
mov    %r15,%r9
call   1030 <print_data_and_coding@plt>
mov    (%rsp),%edi
mov    0x4(%rsp),%edx
sub    $0x8,%rsp
mov    $0x2,%esi
mov    0x18(%rsp),%rcx
mov    $0x1,%r8d
mov    %r13,%r9
push   $0x8
push   %r15
push   %r12
call   10f0 <jerasure_matrix_decode@plt>
add    $0x20,%rsp
lea    0xbaa(%rip),%rdi
call   1060 <puts@plt>
mov    (%rsp),%edi
mov    0x4(%rsp),%edx
mov    $0x2,%esi
mov    $0x8,%ecx
mov    %r12,%r8
mov    %r15,%r9
call   1030 <print_data_and_coding@plt>
xor    %eax,%eax
add    $0x18,%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 w\00"
@.str.3 = [17 x i8] c"k + m is too big\00"
@.str.4 = [42 x i8] c"Last 2 rows of the Distribution Matrix:\0A\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [21 x i8] c"Encoding Complete:\0A\0A\00"
@.str.7 = [28 x i8] c"Erased %d random devices:\0A\0A\00"
@.str.8 = [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, 3
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* %8)
%36 = icmp eq i64 %35, 0
br i1 %36, label %46, label %37
37: ; preds = %31
%38 = load i32, i32* %8
%39 = icmp ne i32 %38, 8
br i1 %39, label %40, label %48
40: ; preds = %37
%41 = load i32, i32* %8
%42 = icmp ne i32 %41, 16
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = load i32, i32* %8
%45 = icmp ne i32 %44, 32
br i1 %45, label %46, label %48
46: ; preds = %43, %31
%47 = call i32 @usage(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %48
48: ; preds = %46, %43, %40, %37
store i32 2, i32* %10
%49 = load i32, i32* %8
%50 = icmp sle i32 %49, 16
br i1 %50, label %51, label %60
51: ; preds = %48
%52 = load i32, i32* %7
%53 = load i32, i32* %10
%54 = add nsw i32 %52, %53
%55 = load i32, i32* %8
%56 = shl i32 1, %55
%57 = icmp sgt i32 %54, %56
br i1 %57, label %58, label %60
58: ; preds = %51
%59 = call i32 @usage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %60
60: ; preds = %58, %51, %48
%61 = load i32, i32* %7
%62 = load i32, i32* %8
%63 = call i32* @reed_sol_r6_coding_matrix(i32 %61, i32 %62)
store i32* %63, i32** %11
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%65 = load i32*, i32** %11
%66 = load i32, i32* %10
%67 = load i32, i32* %7
%68 = load i32, i32* %8
%69 = call i32 @jerasure_print_matrix(i32* %65, i32 %66, i32 %67, i32 %68)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%71 = call i32 @srand48(i32 0)
%72 = load i32, i32* %7
%73 = sext i32 %72 to i64
%74 = mul i64 8, %73
%75 = trunc i64 %74 to i32
%76 = call i64 @malloc(i32 %75)
%77 = inttoptr i64 %76 to i8**
store i8** %77, i8*** %12
store i32 0, i32* %9
br label %78
78: ; preds = %97, %60
%79 = load i32, i32* %9
%80 = load i32, i32* %7
%81 = icmp slt i32 %79, %80
br i1 %81, label %82, label %100
82: ; preds = %78
%83 = call i64 @malloc(i32 8)
%84 = inttoptr i64 %83 to i8*
%85 = load i8**, i8*** %12
%86 = load i32, i32* %9
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8*, i8** %85, i64 %87
store i8* %84, i8** %88
%89 = call i32 (...) @lrand48()
%90 = sext i32 %89 to i64
store i64 %90, i64* %6
%91 = load i8**, i8*** %12
%92 = load i32, i32* %9
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8*, i8** %91, i64 %93
%95 = load i8*, i8** %94
%96 = call i32 @memcpy(i8* %95, i64* %6, i32 8)
br label %97
97: ; preds = %82
%98 = load i32, i32* %9
%99 = add nsw i32 %98, 1
store i32 %99, i32* %9
br label %78
100: ; preds = %78
%101 = load i32, i32* %10
%102 = sext i32 %101 to i64
%103 = mul i64 8, %102
%104 = trunc i64 %103 to i32
%105 = call i64 @malloc(i32 %104)
%106 = inttoptr i64 %105 to i8**
store i8** %106, i8*** %13
store i32 0, i32* %9
br label %107
107: ; preds = %118, %100
%108 = load i32, i32* %9
%109 = load i32, i32* %10
%110 = icmp slt i32 %108, %109
br i1 %110, label %111, label %121
111: ; preds = %107
%112 = call i64 @malloc(i32 8)
%113 = inttoptr i64 %112 to i8*
%114 = load i8**, i8*** %13
%115 = load i32, i32* %9
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i8*, i8** %114, i64 %116
store i8* %113, i8** %117
br label %118
118: ; preds = %111
%119 = load i32, i32* %9
%120 = add nsw i32 %119, 1
store i32 %120, i32* %9
br label %107
121: ; preds = %107
%122 = load i32, i32* %7
%123 = load i32, i32* %8
%124 = load i8**, i8*** %12
%125 = load i8**, i8*** %13
%126 = call i32 @reed_sol_r6_encode(i32 %122, i32 %123, i8** %124, i8** %125, i32 8)
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%128 = load i32, i32* %7
%129 = load i32, i32* %10
%130 = load i32, i32* %8
%131 = load i8**, i8*** %12
%132 = load i8**, i8*** %13
%133 = call i32 @print_data_and_coding(i32 %128, i32 %129, i32 %130, i32 8, i8** %131, i8** %132)
%134 = load i32, i32* %10
%135 = add nsw i32 %134, 1
%136 = sext i32 %135 to i64
%137 = mul i64 4, %136
%138 = trunc i64 %137 to i32
%139 = call i64 @malloc(i32 %138)
%140 = inttoptr i64 %139 to i32*
store i32* %140, i32** %14
%141 = load i32, i32* %7
%142 = load i32, i32* %10
%143 = add nsw i32 %141, %142
%144 = sext i32 %143 to i64
%145 = mul i64 4, %144
%146 = trunc i64 %145 to i32
%147 = call i64 @malloc(i32 %146)
%148 = inttoptr i64 %147 to i32*
store i32* %148, i32** %15
store i32 0, i32* %9
br label %149
149: ; preds = %160, %121
%150 = load i32, i32* %9
%151 = load i32, i32* %10
%152 = load i32, i32* %7
%153 = add nsw i32 %151, %152
%154 = icmp slt i32 %150, %153
br i1 %154, label %155, label %163
155: ; preds = %149
%156 = load i32*, i32** %15
%157 = load i32, i32* %9
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i32, i32* %156, i64 %158
store i32 0, i32* %159
br label %160
160: ; preds = %155
%161 = load i32, i32* %9
%162 = add nsw i32 %161, 1
store i32 %162, i32* %9
br label %149
163: ; preds = %149
store i64 0, i64* %6
store i32 0, i32* %9
br label %164
164: ; preds = %231, %163
%165 = load i32, i32* %9
%166 = load i32, i32* %10
%167 = icmp slt i32 %165, %166
br i1 %167, label %168, label %232
168: ; preds = %164
%169 = call i32 (...) @lrand48()
%170 = load i32, i32* %7
%171 = load i32, i32* %10
%172 = add nsw i32 %170, %171
%173 = srem i32 %169, %172
%174 = load i32*, i32** %14
%175 = load i32, i32* %9
%176 = sext i32 %175 to i64
%177 = getelementptr inbounds i32, i32* %174, i64 %176
store i32 %173, i32* %177
%178 = load i32*, i32** %15
%179 = load i32*, i32** %14
%180 = load i32, i32* %9
%181 = sext i32 %180 to i64
%182 = getelementptr inbounds i32, i32* %179, i64 %181
%183 = load i32, i32* %182
%184 = sext i32 %183 to i64
%185 = getelementptr inbounds i32, i32* %178, i64 %184
%186 = load i32, i32* %185
%187 = icmp eq i32 %186, 0
br i1 %187, label %188, label %231
188: ; preds = %168
%189 = load i32*, i32** %15
%190 = load i32*, i32** %14
%191 = load i32, i32* %9
%192 = sext i32 %191 to i64
%193 = getelementptr inbounds i32, i32* %190, i64 %192
%194 = load i32, i32* %193
%195 = sext i32 %194 to i64
%196 = getelementptr inbounds i32, i32* %189, i64 %195
store i32 1, i32* %196
%197 = load i32*, i32** %14
%198 = load i32, i32* %9
%199 = sext i32 %198 to i64
%200 = getelementptr inbounds i32, i32* %197, i64 %199
%201 = load i32, i32* %200
%202 = load i32, i32* %7
%203 = icmp slt i32 %201, %202
br i1 %203, label %204, label %214
204: ; preds = %188
%205 = load i8**, i8*** %12
%206 = load i32*, i32** %14
%207 = load i32, i32* %9
%208 = sext i32 %207 to i64
%209 = getelementptr inbounds i32, i32* %206, i64 %208
%210 = load i32, i32* %209
%211 = sext i32 %210 to i64
%212 = getelementptr inbounds i8*, i8** %205, i64 %211
%213 = load i8*, i8** %212
br label %226
214: ; preds = %188
%215 = load i8**, i8*** %13
%216 = load i32*, i32** %14
%217 = load i32, i32* %9
%218 = sext i32 %217 to i64
%219 = getelementptr inbounds i32, i32* %216, i64 %218
%220 = load i32, i32* %219
%221 = load i32, i32* %7
%222 = sub nsw i32 %220, %221
%223 = sext i32 %222 to i64
%224 = getelementptr inbounds i8*, i8** %215, i64 %223
%225 = load i8*, i8** %224
br label %226
226: ; preds = %214, %204
%227 = phi i8* [ %213, %204 ], [ %225, %214 ]
%228 = call i32 @memcpy(i8* %227, i64* %6, i32 8)
%229 = load i32, i32* %9
%230 = add nsw i32 %229, 1
store i32 %230, i32* %9
br label %231
231: ; preds = %226, %168
br label %164
232: ; preds = %164
%233 = load i32*, i32** %14
%234 = load i32, i32* %9
%235 = sext i32 %234 to i64
%236 = getelementptr inbounds i32, i32* %233, i64 %235
store i32 -1, i32* %236
%237 = load i32, i32* %10
%238 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %237)
%239 = load i32, i32* %7
%240 = load i32, i32* %10
%241 = load i32, i32* %8
%242 = load i8**, i8*** %12
%243 = load i8**, i8*** %13
%244 = call i32 @print_data_and_coding(i32 %239, i32 %240, i32 %241, i32 8, i8** %242, i8** %243)
%245 = load i32, i32* %7
%246 = load i32, i32* %10
%247 = load i32, i32* %8
%248 = load i32*, i32** %11
%249 = load i32*, i32** %14
%250 = load i8**, i8*** %12
%251 = load i8**, i8*** %13
%252 = call i32 @jerasure_matrix_decode(i32 %245, i32 %246, i32 %247, i32* %248, i32 1, i32* %249, i8** %250, i8** %251, i32 8)
store i32 %252, i32* %9
%253 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0))
%254 = load i32, i32* %7
%255 = load i32, i32* %10
%256 = load i32, i32* %8
%257 = load i8**, i8*** %12
%258 = load i8**, i8*** %13
%259 = call i32 @print_data_and_coding(i32 %254, i32 %255, i32 %256, i32 8, i8** %257, i8** %258)
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 w\00"
@.str.3 = [17 x i8] c"k + m is too big\00"
@.str.7 = [28 x i8] c"Erased %d random devices:\0A\0A\00"
@str = [41 x i8] c"Last 2 rows of the Distribution Matrix:\0A\00"
@str.9 = [20 x i8] c"Encoding Complete:\0A\00"
@str.10 = [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 = bitcast i64* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @usage(i8* null)
br label %12
12: ; preds = %10, %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%16 = icmp eq i64 %15, 0
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 1
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @usage(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %12, %20
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = call i64 @sscanf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %22
%28 = load i32, i32* %5
switch i32 %28, label %29 [
i32 32, label %32
i32 16, label %32
i32 8, label %32
]
29: ; preds = %27, %22
%30 = call i32 @usage(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* %5
br label %32
32: ; preds = %27, %27, %27, %29
%33 = phi i32 [ %28, %27 ], [ %28, %27 ], [ %28, %27 ], [ %31, %29 ]
%34 = icmp slt i32 %33, 17
br i1 %34, label %35, label %43
35: ; preds = %32
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 2
%38 = shl nuw nsw i32 1, %33
%39 = icmp sgt i32 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = call i32 @usage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%42 = load i32, i32* %5
br label %43
43: ; preds = %40, %35, %32
%44 = phi i32 [ %42, %40 ], [ %33, %35 ], [ %33, %32 ]
%45 = load i32, i32* %4
%46 = call i32* @reed_sol_r6_coding_matrix(i32 %45, i32 %44)
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%48 = load i32, i32* %4
%49 = load i32, i32* %5
%50 = call i32 @jerasure_print_matrix(i32* %46, i32 2, i32 %48, i32 %49)
%51 = call i32 @putchar(i32 10)
%52 = call i32 @srand48(i32 0)
%53 = load i32, i32* %4
%54 = shl i32 %53, 3
%55 = call i64 @malloc(i32 %54)
%56 = inttoptr i64 %55 to i8**
%57 = load i32, i32* %4
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %72
59: ; preds = %43, %59
%60 = phi i64 [ %68, %59 ], [ 0, %43 ]
%61 = call i64 @malloc(i32 8)
%62 = inttoptr i64 %61 to i8*
%63 = getelementptr inbounds i8*, i8** %56, i64 %60
store i8* %62, i8** %63
%64 = call i32 (...) @lrand48()
%65 = sext i32 %64 to i64
store i64 %65, i64* %3
%66 = load i8*, i8** %63
%67 = call i32 @memcpy(i8* %66, i64* %3, i32 8)
%68 = add nuw nsw i64 %60, 1
%69 = load i32, i32* %4
%70 = sext i32 %69 to i64
%71 = icmp slt i64 %68, %70
br i1 %71, label %59, label %72
72: ; preds = %59, %43
%73 = call i64 @malloc(i32 16)
%74 = inttoptr i64 %73 to i8**
%75 = call i64 @malloc(i32 8)
%76 = inttoptr i64 %75 to i8*
store i8* %76, i8** %74
%77 = call i64 @malloc(i32 8)
%78 = inttoptr i64 %77 to i8*
%79 = getelementptr inbounds i8*, i8** %74, i64 1
store i8* %78, i8** %79
%80 = load i32, i32* %4
%81 = load i32, i32* %5
%82 = call i32 @reed_sol_r6_encode(i32 %80, i32 %81, i8** %56, i8** %74, i32 8)
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.9, i64 0, i64 0))
%84 = load i32, i32* %4
%85 = load i32, i32* %5
%86 = call i32 @print_data_and_coding(i32 %84, i32 2, i32 %85, i32 8, i8** %56, i8** %74)
%87 = call i64 @malloc(i32 12)
%88 = inttoptr i64 %87 to i32*
%89 = load i32, i32* %4
%90 = shl i32 %89, 2
%91 = add i32 %90, 8
%92 = call i64 @malloc(i32 %91)
%93 = inttoptr i64 %92 to i32*
%94 = load i32, i32* %4
%95 = icmp sgt i32 %94, -2
br i1 %95, label %96, label %103
96: ; preds = %72, %96
%97 = phi i64 [ %99, %96 ], [ 0, %72 ]
%98 = getelementptr inbounds i32, i32* %93, i64 %97
store i32 0, i32* %98
%99 = add nuw nsw i64 %97, 1
%100 = load i32, i32* %4
%101 = sext i32 %100 to i64
%102 = icmp sgt i64 %97, %101
br i1 %102, label %103, label %96
103: ; preds = %96, %72
store i64 0, i64* %3
br label %104
104: ; preds = %103, %129
%105 = phi i32 [ 0, %103 ], [ %130, %129 ]
%106 = call i32 (...) @lrand48()
%107 = load i32, i32* %4
%108 = add nsw i32 %107, 2
%109 = srem i32 %106, %108
%110 = sext i32 %105 to i64
%111 = getelementptr inbounds i32, i32* %88, i64 %110
store i32 %109, i32* %111
%112 = sext i32 %109 to i64
%113 = getelementptr inbounds i32, i32* %93, i64 %112
%114 = load i32, i32* %113
%115 = icmp eq i32 %114, 0
br i1 %115, label %116, label %129
116: ; preds = %104
store i32 1, i32* %113
%117 = load i32, i32* %111
%118 = load i32, i32* %4
%119 = icmp slt i32 %117, %118
%120 = sext i32 %117 to i64
%121 = getelementptr inbounds i8*, i8** %56, i64 %120
%122 = sub nsw i32 %117, %118
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds i8*, i8** %74, i64 %123
%125 = select i1 %119, i8** %121, i8** %124
%126 = load i8*, i8** %125
%127 = call i32 @memcpy(i8* %126, i64* %3, i32 8)
%128 = add nsw i32 %105, 1
br label %129
129: ; preds = %116, %104
%130 = phi i32 [ %128, %116 ], [ %105, %104 ]
%131 = icmp slt i32 %130, 2
br i1 %131, label %104, label %132
132: ; preds = %129
%133 = zext i32 %130 to i64
%134 = getelementptr inbounds i32, i32* %88, i64 %133
store i32 -1, i32* %134
%135 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 2)
%136 = load i32, i32* %4
%137 = load i32, i32* %5
%138 = call i32 @print_data_and_coding(i32 %136, i32 2, i32 %137, i32 8, i8** %56, i8** %74)
%139 = load i32, i32* %4
%140 = load i32, i32* %5
%141 = call i32 @jerasure_matrix_decode(i32 %139, i32 2, i32 %140, i32* %46, i32 1, i32* %88, i8** %56, i8** %74, i32 8)
%142 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.10, i64 0, i64 0))
%143 = load i32, i32* %4
%144 = load i32, i32* %5
%145 = call i32 @print_data_and_coding(i32 %143, i32 2, i32 %144, i32 8, i8** %56, i8** %74)
ret i32 0
}