#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 /*<<< orphan*/ ellpack(double **, short **, double *, double *, int);
void compute(int flag, double nzval[][((128 + 4 - 1) / 4)][(1 << 9)],
             short cols[][((128 + 4 - 1) / 4)][(1 << 9)], double vec[],
             double out[][((128 + 4 - 1) / 4)], int num_rows) {
#pragma HLS inline off
  if (flag) {
    double vecs[4][(1 << 12)];
#pragma HLS array_partition variable = vecs dim = 1 complete
    int i, j;
    for (i = 0; i < (1 << 12); i++) {
#pragma HLS pipeline
      for (j = 0; j < 4; j++) {
#pragma HLS unroll
        vecs[j][i] = vec[i];
      }
    }
    for (j = 0; j < 4; j++) {
#pragma HLS unroll
      int pe_rows = num_rows - j * ((128 + 4 - 1) / 4);
      if (pe_rows > ((128 + 4 - 1) / 4))
        pe_rows = ((128 + 4 - 1) / 4);
      if (pe_rows > 0)
        ellpack(nzval[j], cols[j], vecs[j], out[j], pe_rows);
    }
  }
}


x86 assembly (clang, -O0):
<compute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20040,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     128f <compute+0x17f>
movl   $0x0,-0x20034(%rbp)
cmpl   $0x1000,-0x20034(%rbp)
jge    11cb <compute+0xbb>
movl   $0x0,-0x20038(%rbp)
cmpl   $0x4,-0x20038(%rbp)
jge    11b2 <compute+0xa2>
mov    -0x20(%rbp),%rax
movslq -0x20034(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movslq -0x20038(%rbp),%rcx
lea    -0x20030(%rbp),%rax
shl    $0xf,%rcx
add    %rcx,%rax
movslq -0x20034(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20038(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20038(%rbp)
jmp    1160 <compute+0x50>
jmp    11b7 <compute+0xa7>
mov    -0x20034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20034(%rbp)
jmp    1146 <compute+0x36>
movl   $0x0,-0x20038(%rbp)
cmpl   $0x4,-0x20038(%rbp)
jge    128a <compute+0x17a>
mov    -0x2c(%rbp),%eax
mov    -0x20038(%rbp),%ecx
shl    $0x5,%ecx
sub    %ecx,%eax
mov    %eax,-0x2003c(%rbp)
cmpl   $0x20,-0x2003c(%rbp)
jle    120d <compute+0xfd>
movl   $0x20,-0x2003c(%rbp)
cmpl   $0x0,-0x2003c(%rbp)
jle    1271 <compute+0x161>
mov    -0x10(%rbp),%rdi
movslq -0x20038(%rbp),%rax
shl    $0x11,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
movslq -0x20038(%rbp),%rax
shl    $0xf,%rax
add    %rax,%rsi
movslq -0x20038(%rbp),%rax
lea    -0x20030(%rbp),%rdx
shl    $0xf,%rax
add    %rax,%rdx
mov    -0x28(%rbp),%rcx
movslq -0x20038(%rbp),%rax
shl    $0x8,%rax
add    %rax,%rcx
mov    -0x2003c(%rbp),%r8d
call   1030 <ellpack@plt>
jmp    1276 <compute+0x166>
mov    -0x20038(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20038(%rbp)
jmp    11d5 <compute+0xc5>
jmp    128f <compute+0x17f>
add    $0x20040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute>:
test   %edi,%edi
je     1275 <compute+0x155>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20008,%rsp
mov    %r9d,%ebx
mov    %r8,%r14
mov    %rcx,%rbp
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rsp,%rdi
mov    $0x8000,%edx
mov    %rcx,%rsi
call   1030 <memcpy@plt>
lea    0x8000(%rsp),%r13
mov    $0x8000,%edx
mov    %r13,%rdi
mov    %rbp,%rsi
call   1030 <memcpy@plt>
lea    0x10000(%rsp),%rdi
mov    $0x8000,%edx
mov    %rbp,%rsi
call   1030 <memcpy@plt>
lea    0x18000(%rsp),%rdi
mov    $0x8000,%edx
mov    %rbp,%rsi
call   1030 <memcpy@plt>
test   %ebx,%ebx
jle    11bc <compute+0x9c>
cmp    $0x20,%ebx
mov    $0x20,%r8d
cmovb  %ebx,%r8d
mov    %rsp,%rdx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
call   1040 <ellpack@plt>
lea    -0x20(%rbx),%eax
test   %eax,%eax
jle    11ee <compute+0xce>
cmp    $0x20,%eax
mov    $0x20,%r8d
cmovb  %eax,%r8d
lea    0x20000(%r12),%rdi
lea    0x8000(%r15),%rsi
lea    0x100(%r14),%rcx
mov    %r13,%rdx
call   1040 <ellpack@plt>
lea    -0x40(%rbx),%eax
test   %eax,%eax
jle    1225 <compute+0x105>
cmp    $0x20,%eax
mov    $0x20,%r8d
cmovb  %eax,%r8d
lea    0x40000(%r12),%rdi
lea    0x10000(%r15),%rsi
lea    0x200(%r14),%rcx
lea    0x10000(%rsp),%rdx
call   1040 <ellpack@plt>
add    $0xffffffa0,%ebx
test   %ebx,%ebx
jle    1264 <compute+0x144>
cmp    $0x20,%ebx
mov    $0x20,%r8d
cmovb  %ebx,%r8d
add    $0x60000,%r12
add    $0x18000,%r15
add    $0x300,%r14
mov    %r12,%rdi
mov    %r15,%rsi
lea    0x18000(%rsp),%rdx
mov    %r14,%rcx
call   1040 <ellpack@plt>
add    $0x20008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @compute(i32 %0, [32 x [512 x double]]* %1, [32 x [512 x i16]]* %2, double* %3, [32 x double]* %4, i32 %5) {
%7 = alloca i32
%8 = alloca [32 x [512 x double]]*
%9 = alloca [32 x [512 x i16]]*
%10 = alloca double*
%11 = alloca [32 x double]*
%12 = alloca i32
%13 = alloca [4 x [4096 x double]]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %7
store [32 x [512 x double]]* %1, [32 x [512 x double]]** %8
store [32 x [512 x i16]]* %2, [32 x [512 x i16]]** %9
store double* %3, double** %10
store [32 x double]* %4, [32 x double]** %11
store i32 %5, i32* %12
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %90
19: ; preds = %6
store i32 0, i32* %14
br label %20
20: ; preds = %43, %19
%21 = load i32, i32* %14
%22 = icmp slt i32 %21, 4096
br i1 %22, label %23, label %46
23: ; preds = %20
store i32 0, i32* %15
br label %24
24: ; preds = %39, %23
%25 = load i32, i32* %15
%26 = icmp slt i32 %25, 4
br i1 %26, label %27, label %42
27: ; preds = %24
%28 = load double*, double** %10
%29 = load i32, i32* %14
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = load i32, i32* %15
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [4 x [4096 x double]], [4 x [4096 x double]]* %13, i64 0, i64 %34
%36 = load i32, i32* %14
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [4096 x double], [4096 x double]* %35, i64 0, i64 %37
store double %32, double* %38
br label %39
39: ; preds = %27
%40 = load i32, i32* %15
%41 = add nsw i32 %40, 1
store i32 %41, i32* %15
br label %24
42: ; preds = %24
br label %43
43: ; preds = %42
%44 = load i32, i32* %14
%45 = add nsw i32 %44, 1
store i32 %45, i32* %14
br label %20
46: ; preds = %20
store i32 0, i32* %15
br label %47
47: ; preds = %86, %46
%48 = load i32, i32* %15
%49 = icmp slt i32 %48, 4
br i1 %49, label %50, label %89
50: ; preds = %47
%51 = load i32, i32* %12
%52 = load i32, i32* %15
%53 = mul nsw i32 %52, 32
%54 = sub nsw i32 %51, %53
store i32 %54, i32* %16
%55 = load i32, i32* %16
%56 = icmp sgt i32 %55, 32
br i1 %56, label %57, label %58
57: ; preds = %50
store i32 32, i32* %16
br label %58
58: ; preds = %57, %50
%59 = load i32, i32* %16
%60 = icmp sgt i32 %59, 0
br i1 %60, label %61, label %85
61: ; preds = %58
%62 = load [32 x [512 x double]]*, [32 x [512 x double]]** %8
%63 = load i32, i32* %15
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [32 x [512 x double]], [32 x [512 x double]]* %62, i64 %64
%66 = getelementptr inbounds [32 x [512 x double]], [32 x [512 x double]]* %65, i64 0, i64 0
%67 = bitcast [512 x double]* %66 to double**
%68 = load [32 x [512 x i16]]*, [32 x [512 x i16]]** %9
%69 = load i32, i32* %15
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [32 x [512 x i16]], [32 x [512 x i16]]* %68, i64 %70
%72 = getelementptr inbounds [32 x [512 x i16]], [32 x [512 x i16]]* %71, i64 0, i64 0
%73 = bitcast [512 x i16]* %72 to i16**
%74 = load i32, i32* %15
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [4 x [4096 x double]], [4 x [4096 x double]]* %13, i64 0, i64 %75
%77 = getelementptr inbounds [4096 x double], [4096 x double]* %76, i64 0, i64 0
%78 = load [32 x double]*, [32 x double]** %11
%79 = load i32, i32* %15
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [32 x double], [32 x double]* %78, i64 %80
%82 = getelementptr inbounds [32 x double], [32 x double]* %81, i64 0, i64 0
%83 = load i32, i32* %16
%84 = call i32 @ellpack(double** %67, i16** %73, double* %77, double* %82, i32 %83)
br label %85
85: ; preds = %61, %58
br label %86
86: ; preds = %85
%87 = load i32, i32* %15
%88 = add nsw i32 %87, 1
store i32 %88, i32* %15
br label %47
89: ; preds = %47
br label %90
90: ; preds = %89, %6
ret void
}

LLVM IR (-O2):
define void @compute(i32 %0, [32 x [512 x double]]* %1, [32 x [512 x i16]]* %2, double* nocapture %3, [32 x double]* %4, i32 %5) {
%7 = bitcast double* %3 to i8*
%8 = alloca [4 x [4096 x double]]
%9 = bitcast [4 x [4096 x double]]* %8 to i8*
%10 = icmp eq i32 %0, 0
br i1 %10, label %64, label %11
11: ; preds = %6
%12 = getelementptr inbounds [4 x [4096 x double]], [4 x [4096 x double]]* %8, i64 0, i64 1, i64 0
%13 = bitcast double* %12 to i8*
%14 = getelementptr inbounds [4 x [4096 x double]], [4 x [4096 x double]]* %8, i64 0, i64 2, i64 0
%15 = bitcast double* %14 to i8*
%16 = getelementptr inbounds [4 x [4096 x double]], [4 x [4096 x double]]* %8, i64 0, i64 3, i64 0
%17 = bitcast double* %16 to i8*
%18 = icmp sgt i32 %5, 0
br i1 %18, label %19, label %27
19: ; preds = %11
%20 = icmp ult i32 %5, 32
%21 = select i1 %20, i32 %5, i32 32
%22 = bitcast [32 x [512 x double]]* %1 to double**
%23 = bitcast [32 x [512 x i16]]* %2 to i16**
%24 = getelementptr inbounds [4 x [4096 x double]], [4 x [4096 x double]]* %8, i64 0, i64 0, i64 0
%25 = getelementptr inbounds [32 x double], [32 x double]* %4, i64 0, i64 0
%26 = call i32 @ellpack(double** %22, i16** %23, double* %24, double* %25, i32 %21)
br label %27
27: ; preds = %19, %11
%28 = add i32 %5, -32
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = icmp ult i32 %28, 32
%32 = select i1 %31, i32 %28, i32 32
%33 = getelementptr inbounds [32 x [512 x double]], [32 x [512 x double]]* %1, i64 1, i64 0
%34 = bitcast [512 x double]* %33 to double**
%35 = getelementptr inbounds [32 x [512 x i16]], [32 x [512 x i16]]* %2, i64 1, i64 0
%36 = bitcast [512 x i16]* %35 to i16**
%37 = getelementptr inbounds [32 x double], [32 x double]* %4, i64 1, i64 0
%38 = call i32 @ellpack(double** %34, i16** %36, double* %12, double* %37, i32 %32)
br label %39
39: ; preds = %30, %27
%40 = add i32 %5, -64
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %51
42: ; preds = %39
%43 = icmp ult i32 %40, 32
%44 = select i1 %43, i32 %40, i32 32
%45 = getelementptr inbounds [32 x [512 x double]], [32 x [512 x double]]* %1, i64 2, i64 0
%46 = bitcast [512 x double]* %45 to double**
%47 = getelementptr inbounds [32 x [512 x i16]], [32 x [512 x i16]]* %2, i64 2, i64 0
%48 = bitcast [512 x i16]* %47 to i16**
%49 = getelementptr inbounds [32 x double], [32 x double]* %4, i64 2, i64 0
%50 = call i32 @ellpack(double** %46, i16** %48, double* %14, double* %49, i32 %44)
br label %51
51: ; preds = %42, %39
%52 = add i32 %5, -96
%53 = icmp sgt i32 %52, 0
br i1 %53, label %54, label %63
54: ; preds = %51
%55 = icmp ult i32 %52, 32
%56 = select i1 %55, i32 %52, i32 32
%57 = getelementptr inbounds [32 x [512 x double]], [32 x [512 x double]]* %1, i64 3, i64 0
%58 = bitcast [512 x double]* %57 to double**
%59 = getelementptr inbounds [32 x [512 x i16]], [32 x [512 x i16]]* %2, i64 3, i64 0
%60 = bitcast [512 x i16]* %59 to i16**
%61 = getelementptr inbounds [32 x double], [32 x double]* %4, i64 3, i64 0
%62 = call i32 @ellpack(double** %58, i16** %60, double* %16, double* %61, i32 %56)
br label %63
63: ; preds = %54, %51
br label %64
64: ; preds = %63, %6
ret void
}