// File: /workspace/github_c_makefile_star2_O1/kkanellis[P]matvec-sparse/mmio.c
// Function: mm_write_mtx_crd
int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J[],
        double val[], MM_typecode matcode)
{
    FILE *f;
    int i;

    if (strcmp(fname, "stdout") == 0) 
        f = stdout;
    else
    if ((f = fopen(fname, "w")) == NULL)
        return MM_COULD_NOT_WRITE_FILE;
    
    /* print banner followed by typecode */
    fprintf(f, "%s ", MatrixMarketBanner);
    fprintf(f, "%s\n", mm_typecode_to_str(matcode));

    /* print matrix sizes and nonzeros */
    fprintf(f, "%d %d %d\n", M, N, nz);

    /* print values */
    if (mm_is_pattern(matcode))
        for (i=0; i<nz; i++)
            fprintf(f, "%d %d\n", I[i], J[i]);
    else
    if (mm_is_real(matcode))
        for (i=0; i<nz; i++)
            fprintf(f, "%d %d %20.16g\n", I[i], J[i], val[i]);
    else
    if (mm_is_complex(matcode))
        for (i=0; i<nz; i++)
            fprintf(f, "%d %d %20.16g %20.16g\n", I[i], J[i], val[2*i], 
                        val[2*i+1]);
    else
    {
        if (f != stdout) fclose(f);
        return MM_UNSUPPORTED_TYPE;
    }

    if (f !=stdout) fclose(f);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, %rbx
movq %r8, %r14
movl %ecx, %ebp
movl %edx, %r13d
movl %esi, %r12d
movq %rdi, %r15
leaq 0x1308(%rip), %rsi      # 0x3179
callq 0x10e0
testl %eax, %eax
je 0x1e9b
leaq 0x12ff(%rip), %rsi      # 0x3180
movq %r15, %rdi
callq 0x1120
movq %rax, %r15
testq %rax, %rax
jne 0x1ea5
movl $0x11, %ebx
jmp 0x1fe6
movq 0x312e(%rip), %rax      # 0x4fd0
movq (%rax), %r15
movl %ebp, 0x4(%rsp)
movl %r13d, %ebp
movq 0x40(%rsp), %r13
leaq 0x12ca(%rip), %rsi      # 0x3182
leaq 0x1227(%rip), %rdx      # 0x30e6
movq %r15, %rdi
xorl %eax, %eax
callq 0x10f0
movq 0x48(%rsp), %rdi
callq 0x1817
leaq 0x1334(%rip), %rsi      # 0x320e
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x10f0
leaq 0x125d(%rip), %rsi      # 0x314b
movq %r15, %rdi
movl %r12d, %edx
movl %ebp, %ecx
movl 0x4(%rsp), %ebp
movl %ebp, %r8d
xorl %eax, %eax
callq 0x10f0
movq 0x48(%rsp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x52, %eax
je 0x1f91
cmpl $0x50, %eax
je 0x1f63
cmpl $0x43, %eax
jne 0x1fcd
testl %ebp, %ebp
jle 0x1fc2
movl %ebp, %ebp
shlq $0x2, %rbp
xorl %r12d, %r12d
movl (%r14,%r12), %edx
movl (%rbx,%r12), %ecx
movsd (%r13,%r12,4), %xmm0
movsd 0x8(%r13,%r12,4), %xmm1
movq %r15, %rdi
leaq 0x1244(%rip), %rsi      # 0x3195
movb $0x2, %al
callq 0x10f0
addq $0x4, %r12
cmpq %r12, %rbp
jne 0x1f31
jmp 0x1fc2
testl %ebp, %ebp
jle 0x1fc2
movl %ebp, %r13d
leaq 0x11dd(%rip), %r12      # 0x314e
xorl %ebp, %ebp
movl (%r14,%rbp,4), %edx
movl (%rbx,%rbp,4), %ecx
movq %r15, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x10f0
incq %rbp
cmpq %rbp, %r13
jne 0x1f73
jmp 0x1fc2
testl %ebp, %ebp
jle 0x1fc2
movl %ebp, %ebp
xorl %r12d, %r12d
movl (%r14,%r12,4), %edx
movl (%rbx,%r12,4), %ecx
movsd (%r13,%r12,8), %xmm0
movq %r15, %rdi
leaq 0x11d3(%rip), %rsi      # 0x3186
movb $0x1, %al
callq 0x10f0
incq %r12
cmpq %r12, %rbp
jne 0x1f9a
movq 0x3007(%rip), %rax      # 0x4fd0
xorl %ebx, %ebx
jmp 0x1fd9
movq 0x2ffc(%rip), %rax      # 0x4fd0
movl $0xf, %ebx
cmpq (%rax), %r15
je 0x1fe6
movq %r15, %rdi
callq 0x1080
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq