#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 const, ...);
void fprint_csr2mm(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 i;
  for (i = 0; i < m; ++i) {
    int rowb = vptr[i] - offs;
    int rowe = vptr[i + 1] - offs;
    int j;
    for (j = rowb; j < rowe; ++j) {
      if (vval == NULL) {
        fprintf(f, "%i\t%i\t1\n", i + 1, vpos[j] + roffs);
      } else {
        fprintf(f, "%i\t%i\t%.16e\n", i + 1, vpos[j] + roffs, vval[j]);
      }
    }
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<fprint_csr2mm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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    0xe9b(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1249 <fprint_csr2mm+0x119>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1236 <fprint_csr2mm+0x106>
cmpq   $0x0,-0x28(%rbp)
jne    11f0 <fprint_csr2mm+0xc0>
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%edx
add    $0x1,%edx
mov    -0x20(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
add    -0x30(%rbp),%ecx
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1223 <fprint_csr2mm+0xf3>
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%edx
add    $0x1,%edx
mov    -0x20(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
add    -0x30(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq -0x48(%rbp),%rsi
movsd  (%rax,%rsi,8),%xmm0
lea    0xdef(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
jmp    1228 <fprint_csr2mm+0xf8>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    11ae <fprint_csr2mm+0x7e>
jmp    123b <fprint_csr2mm+0x10b>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1175 <fprint_csr2mm+0x45>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fprint_csr2mm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,0xc(%rsp)
mov    %r8,%rbx
mov    %rcx,0x20(%rsp)
mov    %rdx,0x18(%rsp)
mov    %esi,%r14d
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbp
test   %r14d,%r14d
jle    120a <fprint_csr2mm+0xda>
mov    $0x1,%r13d
sub    0xc(%rsp),%r13d
mov    %r14d,%eax
mov    %rax,0x10(%rsp)
xor    %r15d,%r15d
jmp    1197 <fprint_csr2mm+0x67>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    0x10(%rsp),%r15
je     120a <fprint_csr2mm+0xda>
mov    0x18(%rsp),%rax
mov    (%rax,%r15,4),%ecx
mov    0x4(%rax,%r15,4),%eax
add    $0x1,%r15
cmp    %eax,%ecx
jge    1190 <fprint_csr2mm+0x60>
mov    0xc(%rsp),%edx
sub    %edx,%eax
sub    %edx,%ecx
movslq %ecx,%r14
movslq %eax,%r12
jmp    11e3 <fprint_csr2mm+0xb3>
nopl   (%rax)
movsd  (%rbx,%r14,8),%xmm0
mov    %rbp,%rdi
lea    0xe3b(%rip),%rsi
mov    %r15d,%edx
mov    $0x1,%al
call   1040 <fprintf@plt>
add    $0x1,%r14
cmp    %r12,%r14
jge    1190 <fprint_csr2mm+0x60>
mov    0x20(%rsp),%rax
mov    (%rax,%r14,4),%ecx
add    %r13d,%ecx
test   %rbx,%rbx
jne    11c0 <fprint_csr2mm+0x90>
mov    %rbp,%rdi
lea    0xe04(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11da <fprint_csr2mm+0xaa>
mov    %rbp,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [9 x i8] c"%i\09%i\091\0A\00"
@.str.2 = [13 x i8] c"%i\09%i\09%.16e\0A\00"
define void @fprint_csr2mm(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
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
%19 = load i32, i32* %12
%20 = sub nsw i32 1, %19
store i32 %20, i32* %13
%21 = load i8*, i8** %7
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %14
store i32 0, i32* %15
br label %23
23: ; preds = %85, %6
%24 = load i32, i32* %15
%25 = load i32, i32* %8
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %88
27: ; preds = %23
%28 = load i32*, i32** %9
%29 = load i32, i32* %15
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = load i32, i32* %12
%34 = sub nsw i32 %32, %33
store i32 %34, i32* %16
%35 = load i32*, i32** %9
%36 = load i32, i32* %15
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %35, i64 %38
%40 = load i32, i32* %39
%41 = load i32, i32* %12
%42 = sub nsw i32 %40, %41
store i32 %42, i32* %17
%43 = load i32, i32* %16
store i32 %43, i32* %18
br label %44
44: ; preds = %81, %27
%45 = load i32, i32* %18
%46 = load i32, i32* %17
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %84
48: ; preds = %44
%49 = load double*, double** %11
%50 = icmp eq double* %49, null
br i1 %50, label %51, label %63
51: ; preds = %48
%52 = load i32*, i32** %14
%53 = load i32, i32* %15
%54 = add nsw i32 %53, 1
%55 = load i32*, i32** %10
%56 = load i32, i32* %18
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
%59 = load i32, i32* %58
%60 = load i32, i32* %13
%61 = add nsw i32 %59, %60
%62 = call i32 (i32*, i8*, i32, i32, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %54, i32 %61)
br label %80
63: ; preds = %48
%64 = load i32*, i32** %14
%65 = load i32, i32* %15
%66 = add nsw i32 %65, 1
%67 = load i32*, i32** %10
%68 = load i32, i32* %18
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %67, i64 %69
%71 = load i32, i32* %70
%72 = load i32, i32* %13
%73 = add nsw i32 %71, %72
%74 = load double*, double** %11
%75 = load i32, i32* %18
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %74, i64 %76
%78 = load double, double* %77
%79 = call i32 (i32*, i8*, i32, i32, ...) @fprintf(i32* %64, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %66, i32 %73, double %78)
br label %80
80: ; preds = %63, %51
br label %81
81: ; preds = %80
%82 = load i32, i32* %18
%83 = add nsw i32 %82, 1
store i32 %83, i32* %18
br label %44
84: ; preds = %44
br label %85
85: ; preds = %84
%86 = load i32, i32* %15
%87 = add nsw i32 %86, 1
store i32 %87, i32* %15
br label %23
88: ; preds = %23
%89 = load i32*, i32** %14
%90 = call i32 @fclose(i32* %89)
ret void
}

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