#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int,
                           double const);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ memcpy(int *, int const *, int);
void fprint_csc2mm(const char *fname, int m, const int *vptr, const int *vpos,
                   const double *vval, int offs) {
  int roffs = 1 - offs;
  FILE *f = fopen(fname, "w");
  int *front = malloc(m * sizeof(int));
  memcpy(front, vptr, m * sizeof(int));
  int done = 0;
  int i = 0;
  while (done != m) {
    int j;
    for (j = 0; j < m; ++j) {
      if (front[j] >= 0) {
        if (front[j] == vptr[j + 1]) {
          front[j] = -1;
          ++done;
        } else {
          int x = front[j] - offs;
          int r = vpos[x] - offs;
          if (r == i) {
            fprintf(f, "%i\t%i\t%.16e\n", r + 1, j + 1, vval[x]);
            ++front[j];
          }
        }
      }
    }
    ++i;
  }
  free(front);
  fclose(f);
}


x86 assembly (clang, -O0):
<fprint_csc2mm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    $0x1,%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     12d8 <fprint_csc2mm+0x178>
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12ca <fprint_csc2mm+0x16a>
mov    -0x40(%rbp),%rax
movslq -0x4c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jl     12b7 <fprint_csc2mm+0x157>
mov    -0x40(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x18(%rbp),%rcx
mov    -0x4c(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jne    1245 <fprint_csc2mm+0xe5>
mov    -0x40(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    12b2 <fprint_csc2mm+0x152>
mov    -0x40(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x48(%rbp),%eax
jne    12ad <fprint_csc2mm+0x14d>
mov    -0x38(%rbp),%rdi
mov    -0x54(%rbp),%edx
add    $0x1,%edx
mov    -0x4c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x28(%rbp),%rax
movslq -0x50(%rbp),%rsi
movsd  (%rax,%rsi,8),%xmm0
lea    0xd6b(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
jmp    12b2 <fprint_csc2mm+0x152>
jmp    12b7 <fprint_csc2mm+0x157>
jmp    12bc <fprint_csc2mm+0x15c>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11e9 <fprint_csc2mm+0x89>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    11d6 <fprint_csc2mm+0x76>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fprint_csc2mm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,0x4(%rsp)
mov    %r8,0x18(%rsp)
mov    %rcx,0x20(%rsp)
mov    %rdx,%rbx
mov    %esi,%r13d
lea    0xe76(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,0x8(%rsp)
lea    0x0(,%r13,4),%r14d
mov    %r14d,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <memcpy@plt>
test   %r13d,%r13d
je     126d <fprint_csc2mm+0x10d>
mov    %r13d,%r14d
neg    %r14
xor    %r15d,%r15d
xor    %ebp,%ebp
mov    %r13,0x10(%rsp)
jmp    11e1 <fprint_csc2mm+0x81>
add    $0x1,%ebp
mov    0x10(%rsp),%r13
cmp    %r13d,%r15d
je     126d <fprint_csc2mm+0x10d>
test   %r13d,%r13d
jle    11d0 <fprint_csc2mm+0x70>
lea    0x1(%rbp),%eax
mov    %eax,(%rsp)
mov    $0x1,%r13d
jmp    121f <fprint_csc2mm+0xbf>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movl   $0xffffffff,-0x4(%r12,%r13,4)
ff ff
add    $0x1,%r15d
lea    (%r14,%r13,1),%rax
add    $0x1,%rax
add    $0x1,%r13
cmp    $0x1,%rax
je     11d0 <fprint_csc2mm+0x70>
mov    -0x4(%r12,%r13,4),%eax
test   %eax,%eax
js     120d <fprint_csc2mm+0xad>
cmp    (%rbx,%r13,4),%eax
je     1200 <fprint_csc2mm+0xa0>
mov    0x4(%rsp),%edx
sub    %edx,%eax
cltq
mov    0x20(%rsp),%rcx
mov    (%rcx,%rax,4),%ecx
sub    %edx,%ecx
cmp    %ebp,%ecx
jne    120d <fprint_csc2mm+0xad>
mov    0x18(%rsp),%rcx
movsd  (%rcx,%rax,8),%xmm0
mov    0x8(%rsp),%rdi
lea    0xda8(%rip),%rsi
mov    (%rsp),%edx
mov    %r13d,%ecx
call   1050 <fprintf@plt>
addl   $0x1,-0x4(%r12,%r13,4)
jmp    120d <fprint_csc2mm+0xad>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [13 x i8] c"%i\09%i\09%.16e\0A\00"
define void @fprint_csc2mm(i8* nocapture %0, i32 %1, i32* %2, i32* nocapture %3, double* nocapture %4, i32 %5) {
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = shl i32 %1, 2
%9 = tail call i32* @malloc(i32 %8)
%10 = tail call i32 @memcpy(i32* %9, i32* %2, i32 %8)
%11 = icmp eq i32 %1, 0
br i1 %11, label %54, label %12
12: ; preds = %6
%13 = icmp sgt i32 %1, 0
%14 = zext i32 %1 to i64
br label %15
15: ; preds = %12, %50
%16 = phi i32 [ 0, %12 ], [ %51, %50 ]
%17 = phi i32 [ 0, %12 ], [ %52, %50 ]
br i1 %13, label %18, label %50
18: ; preds = %15
%19 = add nuw nsw i32 %17, 1
br label %20
20: ; preds = %18, %47
%21 = phi i64 [ 0, %18 ], [ %26, %47 ]
%22 = phi i32 [ %16, %18 ], [ %48, %47 ]
%23 = getelementptr inbounds i32, i32* %9, i64 %21
%24 = load i32, i32* %23
%25 = icmp sgt i32 %24, -1
%26 = add nuw nsw i64 %21, 1
br i1 %25, label %27, label %47
27: ; preds = %20
%28 = getelementptr inbounds i32, i32* %2, i64 %26
%29 = load i32, i32* %28
%30 = icmp eq i32 %24, %29
br i1 %30, label %31, label %33
31: ; preds = %27
store i32 -1, i32* %23
%32 = add nsw i32 %22, 1
br label %47
33: ; preds = %27
%34 = sub nsw i32 %24, %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %3, i64 %35
%37 = load i32, i32* %36
%38 = sub nsw i32 %37, %5
%39 = icmp eq i32 %38, %17
br i1 %39, label %40, label %47
40: ; preds = %33
%41 = getelementptr inbounds double, double* %4, i64 %35
%42 = load double, double* %41
%43 = trunc i64 %26 to i32
%44 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %43, double %42)
%45 = load i32, i32* %23
%46 = add nsw i32 %45, 1
store i32 %46, i32* %23
br label %47
47: ; preds = %20, %33, %40, %31
%48 = phi i32 [ %22, %33 ], [ %22, %40 ], [ %32, %31 ], [ %22, %20 ]
%49 = icmp eq i64 %26, %14
br i1 %49, label %50, label %20
50: ; preds = %47, %15
%51 = phi i32 [ %16, %15 ], [ %48, %47 ]
%52 = add nuw nsw i32 %17, 1
%53 = icmp eq i32 %51, %1
br i1 %53, label %54, label %15
54: ; preds = %50, %6
%55 = tail call i32 @free(i32* %9)
%56 = tail call i32 @fclose(i32* %7)
ret void
}