#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 */
float **convert_matrix(float *, int, int, int, int);
int /*<<< orphan*/ free_convert_matrix(float **, int, int, int, int);
int /*<<< orphan*/ free_lvector(unsigned long *, int, int);
int /*<<< orphan*/ free_vector(float *, int, int);
unsigned long *lvector(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprsax(float *, unsigned long *, float *, float *,
                          unsigned long);
int /*<<< orphan*/ sprsin(float **, int, double, int, float *, unsigned long *);
float *vector(int, int);
int main(void) {
  unsigned long i, j, msize, *ija;
  float **a, *sa, *ax, *b;
  static float ainit[5][5] = {3.0, 0.0, 1.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0,
                              0.0, 0.0, 7.0, 5.0, 9.0, 0.0, 0.0, 0.0, 0.0,
                              0.0, 2.0, 0.0, 0.0, 0.0, 6.0, 5.0};
  static float x[5 + 1] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
  ija = lvector(1, (2 * 5 * 5 + 1));
  ax = vector(1, 5);
  b = vector(1, 5);
  sa = vector(1, (2 * 5 * 5 + 1));
  a = convert_matrix(&ainit[0][0], 1, 5, 1, 5);
  sprsin(a, 5, 0.5, (2 * 5 * 5 + 1), sa, ija);
  msize = ija[1] - 2;
  sprsax(sa, ija, x, b, msize);
  for (i = 1; i <= msize; i++)
    for (ax[i] = 0.0, j = 1; j <= msize; j++)
      ax[i] += a[i][j] * x[j];
  printf("\tReference\tsprsax result\n");
  for (i = 1; i <= msize; i++)
    printf("\t%5.2f\t\t%5.2f\n", ax[i], b[i]);
  free_convert_matrix(a, 1, 5, 1, 5);
  free_vector(sa, 1, (2 * 5 * 5 + 1));
  free_vector(b, 1, 5);
  free_vector(ax, 1, 5);
  free_lvector(ija, 1, (2 * 5 * 5 + 1));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%edi
mov    $0x33,%esi
call   10b0 <lvector@plt>
mov    %rax,-0x28(%rbp)
mov    $0x1,%edi
mov    $0x5,%esi
call   1070 <vector@plt>
mov    %rax,-0x40(%rbp)
mov    $0x1,%edi
mov    $0x5,%esi
call   1070 <vector@plt>
mov    %rax,-0x48(%rbp)
mov    $0x1,%edi
mov    $0x33,%esi
call   1070 <vector@plt>
mov    %rax,-0x38(%rbp)
lea    0x2e7e(%rip),%rdi
mov    $0x1,%ecx
mov    $0x5,%r8d
mov    %ecx,%esi
mov    %r8d,%edx
call   10a0 <convert_matrix@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    $0x5,%esi
movsd  0xddc(%rip),%xmm0
mov    $0x33,%edx
call   1090 <sprsin@plt>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
sub    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x48(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0x2e8b(%rip),%rdx
call   1080 <sprsax@plt>
movq   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
ja     12fc <main+0x16c>
mov    -0x40(%rbp),%rax
mov    -0x10(%rbp),%rcx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
movq   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
ja     12e6 <main+0x156>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x18(%rbp),%rcx
lea    0x2e2a(%rip),%rax
movss  (%rax,%rcx,4),%xmm2
mov    -0x40(%rbp),%rax
mov    -0x10(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1288 <main+0xf8>
jmp    12eb <main+0x15b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1262 <main+0xd2>
lea    0xd05(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
ja     1361 <main+0x1d1>
mov    -0x40(%rbp),%rax
mov    -0x10(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x48(%rbp),%rax
mov    -0x10(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xcd9(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1312 <main+0x182>
mov    -0x30(%rbp),%rdi
mov    $0x1,%ecx
mov    $0x5,%r8d
mov    %ecx,%esi
mov    %r8d,%edx
call   1030 <free_convert_matrix@plt>
mov    -0x38(%rbp),%rdi
mov    $0x1,%esi
mov    $0x33,%edx
call   1060 <free_vector@plt>
mov    -0x48(%rbp),%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1060 <free_vector@plt>
mov    -0x40(%rbp),%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1060 <free_vector@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
mov    $0x33,%edx
call   1040 <free_lvector@plt>
xor    %eax,%eax
add    $0x50,%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    $0x1,%edi
mov    $0x33,%esi
call   10c0 <lvector@plt>
mov    %rax,%rbp
mov    $0x1,%edi
mov    $0x5,%esi
call   1080 <vector@plt>
mov    %rax,%rbx
mov    $0x1,%edi
mov    $0x5,%esi
call   1080 <vector@plt>
mov    %rax,%r15
mov    $0x1,%edi
mov    $0x33,%esi
call   1080 <vector@plt>
mov    %rax,%r14
lea    0x2e83(%rip),%rdi
mov    $0x1,%esi
mov    $0x5,%edx
mov    $0x1,%ecx
mov    $0x5,%r8d
call   10b0 <convert_matrix@plt>
mov    %rax,%r13
movsd  0xdde(%rip),%xmm0
mov    %rax,%rdi
mov    $0x5,%esi
mov    $0x33,%edx
mov    %r14,%rcx
mov    %rbp,%r8
call   10a0 <sprsin@plt>
mov    %rbp,%rsi
mov    0x8(%rbp),%r12
lea    0x2ea8(%rip),%rbp
lea    -0x2(%r12),%r8
mov    %r14,0x8(%rsp)
mov    %r14,%rdi
mov    %rsi,0x10(%rsp)
mov    %rbp,%rdx
mov    %r15,%rcx
call   1090 <sprsax@plt>
mov    %r12,%r14
add    $0xfffffffffffffffe,%r14
je     1378 <main+0x1d8>
add    $0xffffffffffffffff,%r12
cmp    $0x3,%r12
mov    $0x2,%r9d
cmovae %r12,%r9
lea    -0x1(%r9),%r8
mov    %r8,%rdx
and    $0xfffffffffffffffe,%rdx
neg    %rdx
mov    $0x1,%esi
jmp    12ad <main+0x10d>
nopl   0x0(%rax)
add    $0x1,%rsi
cmp    %r9,%rsi
je     132a <main+0x18a>
movl   $0x0,(%rbx,%rsi,4)
mov    0x0(%r13,%rsi,8),%rdi
xorps  %xmm0,%xmm0
mov    $0x1,%ecx
cmp    $0x3,%r12
jb     130b <main+0x16b>
mov    $0x1,%ecx
xorps  %xmm0,%xmm0
nop
movss  (%rdi,%rcx,4),%xmm1
mulss  0x0(%rbp,%rcx,4),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,(%rbx,%rsi,4)
movss  0x4(%rdi,%rcx,4),%xmm0
mulss  0x4(%rbp,%rcx,4),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,(%rbx,%rsi,4)
lea    (%rdx,%rcx,1),%rax
add    $0x2,%rax
add    $0x2,%rcx
cmp    $0x1,%rax
jne    12d0 <main+0x130>
test   $0x1,%r8b
je     12a0 <main+0x100>
movss  (%rdi,%rcx,4),%xmm1
mulss  0x0(%rbp,%rcx,4),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,(%rbx,%rsi,4)
jmp    12a0 <main+0x100>
lea    0xce6(%rip),%rdi
call   1040 <puts@plt>
test   %r14,%r14
je     1384 <main+0x1e4>
mov    $0x1,%ebp
lea    0xcc1(%rip),%r12
nopw   0x0(%rax,%rax,1)
movss  (%rbx,%rbp,4),%xmm0
cvtss2sd %xmm0,%xmm0
movss  (%r15,%rbp,4),%xmm1
cvtss2sd %xmm1,%xmm1
mov    %r12,%rdi
mov    $0x2,%al
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %r14,%rbp
jbe    1350 <main+0x1b0>
jmp    1384 <main+0x1e4>
lea    0xc98(%rip),%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x5,%edx
mov    $0x1,%ecx
mov    $0x5,%r8d
call   1030 <free_convert_matrix@plt>
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0x33,%edx
call   1070 <free_vector@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1070 <free_vector@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1070 <free_vector@plt>
mov    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x33,%edx
call   1050 <free_lvector@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@main.ainit = internal global [5 x [5 x float]] [[5 x float] [float 3.000000e+00, float 0.000000e+00, float 1.000000e+00, float 0.000000e+00, float 0.000000e+00], [5 x float] [float 0.000000e+00, float 4.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00], [5 x float] [float 0.000000e+00, float 7.000000e+00, float 5.000000e+00, float 9.000000e+00, float 0.000000e+00], [5 x float] [float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 2.000000e+00], [5 x float] [float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 6.000000e+00, float 5.000000e+00]]
@main.x = internal global [6 x float] [float 0.000000e+00, float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00]
@.str = [26 x i8] c"\09Reference\09sprsax result\0A\00"
@.str.1 = [15 x i8] c"\09%5.2f\09\09%5.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64*
%6 = alloca float**
%7 = alloca float*
%8 = alloca float*
%9 = alloca float*
store i32 0, i32* %1
%10 = call i64* @lvector(i32 1, i32 51)
store i64* %10, i64** %5
%11 = call float* @vector(i32 1, i32 5)
store float* %11, float** %8
%12 = call float* @vector(i32 1, i32 5)
store float* %12, float** %9
%13 = call float* @vector(i32 1, i32 51)
store float* %13, float** %7
%14 = call float** @convert_matrix(float* getelementptr inbounds ([5 x [5 x float]], [5 x [5 x float]]* @main.ainit, i64 0, i64 0, i64 0), i32 1, i32 5, i32 1, i32 5)
store float** %14, float*** %6
%15 = load float**, float*** %6
%16 = load float*, float** %7
%17 = load i64*, i64** %5
%18 = call i32 @sprsin(float** %15, i32 5, double 5.000000e-01, i32 51, float* %16, i64* %17)
%19 = load i64*, i64** %5
%20 = getelementptr inbounds i64, i64* %19, i64 1
%21 = load i64, i64* %20
%22 = sub i64 %21, 2
store i64 %22, i64* %4
%23 = load float*, float** %7
%24 = load i64*, i64** %5
%25 = load float*, float** %9
%26 = load i64, i64* %4
%27 = call i32 @sprsax(float* %23, i64* %24, float* getelementptr inbounds ([6 x float], [6 x float]* @main.x, i64 0, i64 0), float* %25, i64 %26)
store i64 1, i64* %2
br label %28
28: ; preds = %60, %0
%29 = load i64, i64* %2
%30 = load i64, i64* %4
%31 = icmp ule i64 %29, %30
br i1 %31, label %32, label %63
32: ; preds = %28
%33 = load float*, float** %8
%34 = load i64, i64* %2
%35 = getelementptr inbounds float, float* %33, i64 %34
store float 0.000000e+00, float* %35
store i64 1, i64* %3
br label %36
36: ; preds = %56, %32
%37 = load i64, i64* %3
%38 = load i64, i64* %4
%39 = icmp ule i64 %37, %38
br i1 %39, label %40, label %59
40: ; preds = %36
%41 = load float**, float*** %6
%42 = load i64, i64* %2
%43 = getelementptr inbounds float*, float** %41, i64 %42
%44 = load float*, float** %43
%45 = load i64, i64* %3
%46 = getelementptr inbounds float, float* %44, i64 %45
%47 = load float, float* %46
%48 = load i64, i64* %3
%49 = getelementptr inbounds [6 x float], [6 x float]* @main.x, i64 0, i64 %48
%50 = load float, float* %49
%51 = load float*, float** %8
%52 = load i64, i64* %2
%53 = getelementptr inbounds float, float* %51, i64 %52
%54 = load float, float* %53
%55 = call float @llvm.fmuladd.f32(float %47, float %50, float %54)
store float %55, float* %53
br label %56
56: ; preds = %40
%57 = load i64, i64* %3
%58 = add i64 %57, 1
store i64 %58, i64* %3
br label %36
59: ; preds = %36
br label %60
60: ; preds = %59
%61 = load i64, i64* %2
%62 = add i64 %61, 1
store i64 %62, i64* %2
br label %28
63: ; preds = %28
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i64 1, i64* %2
br label %65
65: ; preds = %81, %63
%66 = load i64, i64* %2
%67 = load i64, i64* %4
%68 = icmp ule i64 %66, %67
br i1 %68, label %69, label %84
69: ; preds = %65
%70 = load float*, float** %8
%71 = load i64, i64* %2
%72 = getelementptr inbounds float, float* %70, i64 %71
%73 = load float, float* %72
%74 = fpext float %73 to double
%75 = load float*, float** %9
%76 = load i64, i64* %2
%77 = getelementptr inbounds float, float* %75, i64 %76
%78 = load float, float* %77
%79 = fpext float %78 to double
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %74, double %79)
br label %81
81: ; preds = %69
%82 = load i64, i64* %2
%83 = add i64 %82, 1
store i64 %83, i64* %2
br label %65
84: ; preds = %65
%85 = load float**, float*** %6
%86 = call i32 @free_convert_matrix(float** %85, i32 1, i32 5, i32 1, i32 5)
%87 = load float*, float** %7
%88 = call i32 @free_vector(float* %87, i32 1, i32 51)
%89 = load float*, float** %9
%90 = call i32 @free_vector(float* %89, i32 1, i32 5)
%91 = load float*, float** %8
%92 = call i32 @free_vector(float* %91, i32 1, i32 5)
%93 = load i64*, i64** %5
%94 = call i32 @free_lvector(i64* %93, i32 1, i32 51)
ret i32 0
}

LLVM IR (-O2):
@main.ainit = internal global [5 x [5 x float]] [[5 x float] [float 3.000000e+00, float 0.000000e+00, float 1.000000e+00, float 0.000000e+00, float 0.000000e+00], [5 x float] [float 0.000000e+00, float 4.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00], [5 x float] [float 0.000000e+00, float 7.000000e+00, float 5.000000e+00, float 9.000000e+00, float 0.000000e+00], [5 x float] [float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 2.000000e+00], [5 x float] [float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 6.000000e+00, float 5.000000e+00]]
@main.x = internal global [6 x float] [float 0.000000e+00, float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00]
@.str.1 = [15 x i8] c"\09%5.2f\09\09%5.2f\0A\00"
@str = [25 x i8] c"\09Reference\09sprsax result\00"
define i32 @main() {
%1 = tail call i64* @lvector(i32 1, i32 51)
%2 = tail call float* @vector(i32 1, i32 5)
%3 = tail call float* @vector(i32 1, i32 5)
%4 = tail call float* @vector(i32 1, i32 51)
%5 = tail call float** @convert_matrix(float* getelementptr inbounds ([5 x [5 x float]], [5 x [5 x float]]* @main.ainit, i64 0, i64 0, i64 0), i32 1, i32 5, i32 1, i32 5)
%6 = tail call i32 @sprsin(float** %5, i32 5, double 5.000000e-01, i32 51, float* %4, i64* %1)
%7 = getelementptr inbounds i64, i64* %1, i64 1
%8 = load i64, i64* %7
%9 = add i64 %8, -2
%10 = tail call i32 @sprsax(float* %4, i64* %1, float* getelementptr inbounds ([6 x float], [6 x float]* @main.x, i64 0, i64 0), float* %3, i64 %9)
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %70
14: ; preds = %0
%15 = add i64 %8, -1
%16 = call i64 @llvm.umax.i64(i64 %15, i64 2)
%17 = add i64 %16, -1
%18 = and i64 %17, 1
%19 = icmp ult i64 %15, 3
%20 = and i64 %17, -2
%21 = icmp eq i64 %18, 0
br label %22
22: ; preds = %54, %14
%23 = phi i64 [ 1, %14 ], [ %55, %54 ]
%24 = getelementptr inbounds float, float* %2, i64 %23
store float 0.000000e+00, float* %24
%25 = getelementptr inbounds float*, float** %5, i64 %23
%26 = load float*, float** %25
br i1 %19, label %45, label %27
27: ; preds = %22, %27
%28 = phi float [ %41, %27 ], [ 0.000000e+00, %22 ]
%29 = phi i64 [ %42, %27 ], [ 1, %22 ]
%30 = phi i64 [ %43, %27 ], [ 0, %22 ]
%31 = getelementptr inbounds float, float* %26, i64 %29
%32 = load float, float* %31
%33 = getelementptr inbounds [6 x float], [6 x float]* @main.x, i64 0, i64 %29
%34 = load float, float* %33
%35 = tail call float @llvm.fmuladd.f32(float %32, float %34, float %28)
store float %35, float* %24
%36 = add nuw i64 %29, 1
%37 = getelementptr inbounds float, float* %26, i64 %36
%38 = load float, float* %37
%39 = getelementptr inbounds [6 x float], [6 x float]* @main.x, i64 0, i64 %36
%40 = load float, float* %39
%41 = tail call float @llvm.fmuladd.f32(float %38, float %40, float %35)
store float %41, float* %24
%42 = add nuw i64 %29, 2
%43 = add i64 %30, 2
%44 = icmp eq i64 %43, %20
br i1 %44, label %45, label %27
45: ; preds = %27, %22
%46 = phi float [ 0.000000e+00, %22 ], [ %41, %27 ]
%47 = phi i64 [ 1, %22 ], [ %42, %27 ]
br i1 %21, label %54, label %48
48: ; preds = %45
%49 = getelementptr inbounds float, float* %26, i64 %47
%50 = load float, float* %49
%51 = getelementptr inbounds [6 x float], [6 x float]* @main.x, i64 0, i64 %47
%52 = load float, float* %51
%53 = tail call float @llvm.fmuladd.f32(float %50, float %52, float %46)
store float %53, float* %24
br label %54
54: ; preds = %45, %48
%55 = add nuw i64 %23, 1
%56 = icmp eq i64 %55, %16
br i1 %56, label %57, label %22
57: ; preds = %54
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br i1 %11, label %70, label %59
59: ; preds = %57, %59
%60 = phi i64 [ %68, %59 ], [ 1, %57 ]
%61 = getelementptr inbounds float, float* %2, i64 %60
%62 = load float, float* %61
%63 = fpext float %62 to double
%64 = getelementptr inbounds float, float* %3, i64 %60
%65 = load float, float* %64
%66 = fpext float %65 to double
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %63, double %66)
%68 = add i64 %60, 1
%69 = icmp ugt i64 %68, %9
br i1 %69, label %70, label %59
70: ; preds = %59, %12, %57
%71 = tail call i32 @free_convert_matrix(float** %5, i32 1, i32 5, i32 1, i32 5)
%72 = tail call i32 @free_vector(float* %4, i32 1, i32 51)
%73 = tail call i32 @free_vector(float* %3, i32 1, i32 5)
%74 = tail call i32 @free_vector(float* %2, i32 1, i32 5)
%75 = tail call i32 @free_lvector(i64* %1, i32 1, i32 51)
ret i32 0
}