// File: /workspace/github_c_makefile_star2_O3/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 0x130e(%rip), %rsi      # 0x3179
callq 0x10e0
testl %eax, %eax
je 0x1e95
leaq 0x1305(%rip), %rsi      # 0x3180
movq %r15, %rdi
callq 0x1120
movq %rax, %r15
testq %rax, %rax
jne 0x1e9f
movl $0x11, %ebx
jmp 0x1fe0
movq 0x3134(%rip), %rax      # 0x4fd0
movq (%rax), %r15
movl %ebp, 0x4(%rsp)
movl %r13d, %ebp
movq 0x40(%rsp), %r13
leaq 0x12d0(%rip), %rsi      # 0x3182
leaq 0x122d(%rip), %rdx      # 0x30e6
movq %r15, %rdi
xorl %eax, %eax
callq 0x10f0
movq 0x48(%rsp), %rdi
callq 0x1815
leaq 0x133a(%rip), %rsi      # 0x320e
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x10f0
leaq 0x1263(%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 0x1f8b
cmpl $0x50, %eax
je 0x1f5d
cmpl $0x43, %eax
jne 0x1fc7
testl %ebp, %ebp
jle 0x1fbc
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 0x124a(%rip), %rsi      # 0x3195
movb $0x2, %al
callq 0x10f0
addq $0x4, %r12
cmpq %r12, %rbp
jne 0x1f2b
jmp 0x1fbc
testl %ebp, %ebp
jle 0x1fbc
movl %ebp, %r13d
leaq 0x11e3(%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 0x1f6d
jmp 0x1fbc
testl %ebp, %ebp
jle 0x1fbc
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 0x11d9(%rip), %rsi      # 0x3186
movb $0x1, %al
callq 0x10f0
incq %r12
cmpq %r12, %rbp
jne 0x1f94
movq 0x300d(%rip), %rax      # 0x4fd0
xorl %ebx, %ebx
jmp 0x1fd3
movq 0x3002(%rip), %rax      # 0x4fd0
movl $0xf, %ebx
cmpq (%rax), %r15
je 0x1fe0
movq %r15, %rdi
callq 0x1080
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq