#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_generate_decoding_schedule(int, int, int, int *, int *, int);
scalar_t__ malloc(int);
int ***jerasure_generate_schedule_cache(int k, int m, int w, int *bitmatrix,
                                        int smart) {
  int i, tdone;
  char **ptrs;
  int **schedule;
  int ***scache;
  int erasures[3];
  int e1, e2;
  if (m != 2)
    return NULL;
  scache = (int ***)malloc(sizeof(int **) * ((k + m) * (k + m + 1)));
  if (scache == NULL)
    return NULL;
  for (e1 = 0; e1 < k + m; e1++) {
    erasures[0] = e1;
    for (e2 = 0; e2 < e1; e2++) {
      erasures[1] = e2;
      erasures[2] = -1;
      scache[e1 * (k + m) + e2] = jerasure_generate_decoding_schedule(
          k, m, w, bitmatrix, erasures, smart);
      scache[e2 * (k + m) + e1] = scache[e1 * (k + m) + e2];
    }
    erasures[1] = -1;
    scache[e1 * (k + m) + e1] = jerasure_generate_decoding_schedule(
        k, m, w, bitmatrix, erasures, smart);
  }
  return scache;
}


x86 assembly (clang, -O0):
<jerasure_generate_schedule_cache>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
cmpl   $0x2,-0x10(%rbp)
je     1150 <jerasure_generate_schedule_cache+0x30>
movq   $0x0,-0x8(%rbp)
jmp    1296 <jerasure_generate_schedule_cache+0x176>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    -0x10(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    118b <jerasure_generate_schedule_cache+0x6b>
movq   $0x0,-0x8(%rbp)
jmp    1296 <jerasure_generate_schedule_cache+0x176>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    128e <jerasure_generate_schedule_cache+0x16e>
mov    -0x58(%rbp),%eax
mov    %eax,-0x54(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    1242 <jerasure_generate_schedule_cache+0x122>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x50(%rbp)
movl   $0xffffffff,-0x4c(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    -0x54(%rbp),%r8
mov    -0x24(%rbp),%r9d
call   1030 <jerasure_generate_decoding_schedule@plt>
mov    %rax,%rdx
mov    -0x48(%rbp),%rax
mov    -0x58(%rbp),%ecx
mov    -0xc(%rbp),%esi
add    -0x10(%rbp),%esi
imul   %esi,%ecx
add    -0x5c(%rbp),%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x48(%rbp),%rax
mov    -0x58(%rbp),%ecx
mov    -0xc(%rbp),%edx
add    -0x10(%rbp),%edx
imul   %edx,%ecx
add    -0x5c(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x48(%rbp),%rax
mov    -0x5c(%rbp),%ecx
mov    -0xc(%rbp),%esi
add    -0x10(%rbp),%esi
imul   %esi,%ecx
add    -0x58(%rbp),%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    11b0 <jerasure_generate_schedule_cache+0x90>
movl   $0xffffffff,-0x50(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    -0x54(%rbp),%r8
mov    -0x24(%rbp),%r9d
call   1030 <jerasure_generate_decoding_schedule@plt>
mov    %rax,%rdx
mov    -0x48(%rbp),%rax
mov    -0x58(%rbp),%ecx
mov    -0xc(%rbp),%esi
add    -0x10(%rbp),%esi
imul   %esi,%ecx
add    -0x58(%rbp),%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1192 <jerasure_generate_schedule_cache+0x72>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jerasure_generate_schedule_cache>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
cmp    $0x2,%esi
jne    129c <jerasure_generate_schedule_cache+0x17c>
mov    %edi,%r15d
mov    %edx,0xc(%rsp)
mov    %rcx,0x20(%rsp)
mov    %r8d,%r14d
lea    0x2(%r15),%ebp
lea    0x18(,%r15,8),%edi
imul   %ebp,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     129c <jerasure_generate_schedule_cache+0x17c>
cmp    $0xffffffff,%r15d
jl     129e <jerasure_generate_schedule_cache+0x17e>
mov    %ebp,%r13d
lea    0x0(,%r13,8),%rdi
xor    %r12d,%r12d
mov    %rax,%rdx
mov    %rax,%rsi
mov    %rdi,0x38(%rsp)
mov    %rax,0x30(%rsp)
mov    %r13,0x28(%rsp)
mov    %r14d,0x10(%rsp)
jmp    11fb <jerasure_generate_schedule_cache+0xdb>
nopw   0x0(%rax,%rax,1)
xor    %ebp,%ebp
mov    0x20(%rsp),%rcx
mov    0xc(%rsp),%edx
lea    0x14(%rsp),%r8
mov    %rax,%rbx
mov    %r14d,%r9d
movl   $0xffffffff,0x18(%rsp)
ff
mov    %r15d,%edi
mov    $0x2,%esi
mov    %r9d,%r14d
call   1030 <jerasure_generate_decoding_schedule@plt>
add    %r12,%rbp
mov    %rax,(%rbx,%rbp,8)
add    $0x1,%r12
mov    0x48(%rsp),%rsi
add    $0x8,%rsi
mov    0x38(%rsp),%rdi
mov    0x50(%rsp),%rdx
add    %rdi,%rdx
cmp    %r13,%r12
mov    %rbx,%rax
je     129e <jerasure_generate_schedule_cache+0x17e>
mov    %r12d,0x14(%rsp)
test   %r12,%r12
mov    %rdx,0x50(%rsp)
mov    %rsi,0x48(%rsp)
je     11a0 <jerasure_generate_schedule_cache+0x80>
mov    %r12,%rax
imul   %r13,%rax
mov    %rax,0x40(%rsp)
mov    %r15,%r13
mov    %rsi,%r15
xor    %ebp,%ebp
mov    %rdi,%rbx
mov    %r12,%r14
mov    %rdx,%r12
nopl   0x0(%rax)
mov    %ebp,0x18(%rsp)
movl   $0xffffffff,0x1c(%rsp)
ff
mov    %r13d,%edi
mov    $0x2,%esi
mov    0xc(%rsp),%edx
mov    0x20(%rsp),%rcx
lea    0x14(%rsp),%r8
mov    0x10(%rsp),%r9d
call   1030 <jerasure_generate_decoding_schedule@plt>
mov    %rax,(%r12,%rbp,8)
mov    %rax,(%r15)
add    $0x1,%rbp
add    %rbx,%r15
cmp    %rbp,%r14
jne    1230 <jerasure_generate_schedule_cache+0x110>
mov    %r14,%r12
mov    0x20(%rsp),%rcx
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%r9d
mov    %r13,%r15
mov    0x30(%rsp),%rbx
mov    0x28(%rsp),%r13
lea    0x14(%rsp),%r8
mov    0x40(%rsp),%rbp
jmp    11b6 <jerasure_generate_schedule_cache+0x96>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32*** @jerasure_generate_schedule_cache(i32 %0, i32 %1, i32 %2, i32* %3, i32 %4) {
%6 = alloca i32***
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8**
%15 = alloca i32**
%16 = alloca i32***
%17 = alloca [3 x i32]
%18 = alloca i32
%19 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store i32 %4, i32* %11
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 2
br i1 %21, label %22, label %23
22: ; preds = %5
store i32*** null, i32**** %6
br label %123
23: ; preds = %5
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = add nsw i32 %24, %25
%27 = load i32, i32* %7
%28 = load i32, i32* %8
%29 = add nsw i32 %27, %28
%30 = add nsw i32 %29, 1
%31 = mul nsw i32 %26, %30
%32 = sext i32 %31 to i64
%33 = mul i64 8, %32
%34 = trunc i64 %33 to i32
%35 = call i64 @malloc(i32 %34)
%36 = inttoptr i64 %35 to i32***
store i32*** %36, i32**** %16
%37 = load i32***, i32**** %16
%38 = icmp eq i32*** %37, null
br i1 %38, label %39, label %40
39: ; preds = %23
store i32*** null, i32**** %6
br label %123
40: ; preds = %23
store i32 0, i32* %18
br label %41
41: ; preds = %118, %40
%42 = load i32, i32* %18
%43 = load i32, i32* %7
%44 = load i32, i32* %8
%45 = add nsw i32 %43, %44
%46 = icmp slt i32 %42, %45
br i1 %46, label %47, label %121
47: ; preds = %41
%48 = load i32, i32* %18
%49 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 0
store i32 %48, i32* %49
store i32 0, i32* %19
br label %50
50: ; preds = %96, %47
%51 = load i32, i32* %19
%52 = load i32, i32* %18
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %99
54: ; preds = %50
%55 = load i32, i32* %19
%56 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 1
store i32 %55, i32* %56
%57 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 2
store i32 -1, i32* %57
%58 = load i32, i32* %7
%59 = load i32, i32* %8
%60 = load i32, i32* %9
%61 = load i32*, i32** %10
%62 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 0
%63 = load i32, i32* %11
%64 = call i32** @jerasure_generate_decoding_schedule(i32 %58, i32 %59, i32 %60, i32* %61, i32* %62, i32 %63)
%65 = load i32***, i32**** %16
%66 = load i32, i32* %18
%67 = load i32, i32* %7
%68 = load i32, i32* %8
%69 = add nsw i32 %67, %68
%70 = mul nsw i32 %66, %69
%71 = load i32, i32* %19
%72 = add nsw i32 %70, %71
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32**, i32*** %65, i64 %73
store i32** %64, i32*** %74
%75 = load i32***, i32**** %16
%76 = load i32, i32* %18
%77 = load i32, i32* %7
%78 = load i32, i32* %8
%79 = add nsw i32 %77, %78
%80 = mul nsw i32 %76, %79
%81 = load i32, i32* %19
%82 = add nsw i32 %80, %81
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i32**, i32*** %75, i64 %83
%85 = load i32**, i32*** %84
%86 = load i32***, i32**** %16
%87 = load i32, i32* %19
%88 = load i32, i32* %7
%89 = load i32, i32* %8
%90 = add nsw i32 %88, %89
%91 = mul nsw i32 %87, %90
%92 = load i32, i32* %18
%93 = add nsw i32 %91, %92
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i32**, i32*** %86, i64 %94
store i32** %85, i32*** %95
br label %96
96: ; preds = %54
%97 = load i32, i32* %19
%98 = add nsw i32 %97, 1
store i32 %98, i32* %19
br label %50
99: ; preds = %50
%100 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 1
store i32 -1, i32* %100
%101 = load i32, i32* %7
%102 = load i32, i32* %8
%103 = load i32, i32* %9
%104 = load i32*, i32** %10
%105 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 0
%106 = load i32, i32* %11
%107 = call i32** @jerasure_generate_decoding_schedule(i32 %101, i32 %102, i32 %103, i32* %104, i32* %105, i32 %106)
%108 = load i32***, i32**** %16
%109 = load i32, i32* %18
%110 = load i32, i32* %7
%111 = load i32, i32* %8
%112 = add nsw i32 %110, %111
%113 = mul nsw i32 %109, %112
%114 = load i32, i32* %18
%115 = add nsw i32 %113, %114
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i32**, i32*** %108, i64 %116
store i32** %107, i32*** %117
br label %118
118: ; preds = %99
%119 = load i32, i32* %18
%120 = add nsw i32 %119, 1
store i32 %120, i32* %18
br label %41
121: ; preds = %41
%122 = load i32***, i32**** %16
store i32*** %122, i32**** %6
br label %123
123: ; preds = %121, %39, %22
%124 = load i32***, i32**** %6
ret i32*** %124
}

LLVM IR (-O2):
define i32*** @jerasure_generate_schedule_cache(i32 %0, i32 %1, i32 %2, i32* %3, i32 %4) {
%6 = alloca [3 x i32]
%7 = bitcast [3 x i32]* %6 to i8*
%8 = icmp eq i32 %1, 2
br i1 %8, label %9, label %49
9: ; preds = %5
%10 = add nsw i32 %0, 2
%11 = shl i32 %0, 3
%12 = add i32 %11, 24
%13 = mul i32 %12, %10
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32***
%16 = icmp eq i64 %14, 0
br i1 %16, label %49, label %17
17: ; preds = %9
%18 = icmp sgt i32 %0, -2
br i1 %18, label %19, label %49
19: ; preds = %17
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 0
%21 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 1
%22 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 2
%23 = zext i32 %10 to i64
%24 = zext i32 %10 to i64
br label %25
25: ; preds = %19, %42
%26 = phi i64 [ 0, %19 ], [ %47, %42 ]
%27 = trunc i64 %26 to i32
store i32 %27, i32* %20
%28 = icmp eq i64 %26, 0
br i1 %28, label %42, label %29
29: ; preds = %25
%30 = mul nsw i64 %26, %23
br label %31
31: ; preds = %29, %31
%32 = phi i64 [ 0, %29 ], [ %40, %31 ]
%33 = trunc i64 %32 to i32
store i32 %33, i32* %21
store i32 -1, i32* %22
%34 = call i32** @jerasure_generate_decoding_schedule(i32 %0, i32 2, i32 %2, i32* %3, i32* %20, i32 %4)
%35 = add nuw nsw i64 %32, %30
%36 = getelementptr inbounds i32**, i32*** %15, i64 %35
store i32** %34, i32*** %36
%37 = mul nsw i64 %32, %23
%38 = add nuw nsw i64 %37, %26
%39 = getelementptr inbounds i32**, i32*** %15, i64 %38
store i32** %34, i32*** %39
%40 = add nuw nsw i64 %32, 1
%41 = icmp eq i64 %40, %26
br i1 %41, label %42, label %31
42: ; preds = %31, %25
%43 = phi i64 [ 0, %25 ], [ %30, %31 ]
store i32 -1, i32* %21
%44 = call i32** @jerasure_generate_decoding_schedule(i32 %0, i32 2, i32 %2, i32* %3, i32* %20, i32 %4)
%45 = add nsw i64 %43, %26
%46 = getelementptr inbounds i32**, i32*** %15, i64 %45
store i32** %44, i32*** %46
%47 = add nuw nsw i64 %26, 1
%48 = icmp eq i64 %47, %24
br i1 %48, label %49, label %25
49: ; preds = %42, %17, %9, %5
%50 = phi i32*** [ null, %5 ], [ null, %9 ], [ %15, %17 ], [ %15, %42 ]
ret i32*** %50
}