// File: /workspace/github_c_makefile_star2_O2/kkanellis[P]matvec-sparse/mmio.c
// Function: mm_read_banner
int mm_read_banner(FILE *f, MM_typecode *matcode)
{
    char line[MM_MAX_LINE_LENGTH];
    char banner[MM_MAX_TOKEN_LENGTH];
    char mtx[MM_MAX_TOKEN_LENGTH]; 
    char crd[MM_MAX_TOKEN_LENGTH];
    char data_type[MM_MAX_TOKEN_LENGTH];
    char storage_scheme[MM_MAX_TOKEN_LENGTH];
    char *p;


    mm_clear_typecode(matcode);  

    if (fgets(line, MM_MAX_LINE_LENGTH, f) == NULL) 
        return MM_PREMATURE_EOF;

    if (sscanf(line, "%s %s %s %s %s", banner, mtx, crd, data_type, 
        storage_scheme) != 5)
        return MM_PREMATURE_EOF;

    for (p=mtx; *p!='\0'; *p=tolower(*p),p++);  /* convert to lower case */
    for (p=crd; *p!='\0'; *p=tolower(*p),p++);  
    for (p=data_type; *p!='\0'; *p=tolower(*p),p++);
    for (p=storage_scheme; *p!='\0'; *p=tolower(*p),p++);

    /* check for banner */
    if (strncmp(banner, MatrixMarketBanner, strlen(MatrixMarketBanner)) != 0)
        return MM_NO_HEADER;

    /* first field should be "mtx" */
    if (strcmp(mtx, MM_MTX_STR) != 0)
        return  MM_UNSUPPORTED_TYPE;
    mm_set_matrix(matcode);


    /* second field describes whether this is a sparse matrix (in coordinate
            storgae) or a dense array */


    if (strcmp(crd, MM_SPARSE_STR) == 0)
        mm_set_sparse(matcode);
    else
    if (strcmp(crd, MM_DENSE_STR) == 0)
            mm_set_dense(matcode);
    else
        return MM_UNSUPPORTED_TYPE;
    

    /* third field */

    if (strcmp(data_type, MM_REAL_STR) == 0)
        mm_set_real(matcode);
    else
    if (strcmp(data_type, MM_COMPLEX_STR) == 0)
        mm_set_complex(matcode);
    else
    if (strcmp(data_type, MM_PATTERN_STR) == 0)
        mm_set_pattern(matcode);
    else
    if (strcmp(data_type, MM_INT_STR) == 0)
        mm_set_integer(matcode);
    else
        return MM_UNSUPPORTED_TYPE;
    

    /* fourth field */

    if (strcmp(storage_scheme, MM_GENERAL_STR) == 0)
        mm_set_general(matcode);
    else
    if (strcmp(storage_scheme, MM_SYMM_STR) == 0)
        mm_set_symmetric(matcode);
    else
    if (strcmp(storage_scheme, MM_HERM_STR) == 0)
        mm_set_hermitian(matcode);
    else
    if (strcmp(storage_scheme, MM_SKEW_STR) == 0)
        mm_set_skew(matcode);
    else
        return MM_UNSUPPORTED_TYPE;
        

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x558, %rsp            # imm = 0x558
movq %rsi, %rbx
movq %rdi, %rdx
movl $0x47202020, (%rsi)     # imm = 0x47202020
leaq 0x150(%rsp), %rdi
movl $0x401, %esi            # imm = 0x401
callq 0x10c0
pushq $0xc
popq %rbp
testq %rax, %rax
je 0x16a5
leaq 0x10(%rsp), %r13
movq %r13, (%rsp)
leaq 0x1c35(%rip), %rsi      # 0x30d7
leaq 0x150(%rsp), %rdi
leaq 0x110(%rsp), %rdx
leaq 0xd0(%rsp), %r12
leaq 0x90(%rsp), %r15
leaq 0x50(%rsp), %r14
movq %r12, %rcx
movq %r15, %r8
movq %r14, %r9
xorl %eax, %eax
callq 0x1110
cmpl $0x5, %eax
jne 0x16a5
movsbq (%r12), %rbp
testq %rbp, %rbp
je 0x1510
callq 0x1180
movq (%rax), %rax
movb (%rax,%rbp,4), %al
movb %al, (%r12)
incq %r12
jmp 0x14e0
callq 0x1180
movq (%rax), %rax
movb (%rax,%r12,4), %al
movb %al, (%r15)
incq %r15
movsbq (%r15), %r12
testq %r12, %r12
jne 0x14fe
jmp 0x152d
callq 0x1180
movq (%rax), %rax
movb (%rax,%r15,4), %al
movb %al, (%r14)
incq %r14
movsbq (%r14), %r15
testq %r15, %r15
jne 0x151b
jmp 0x154b
callq 0x1180
movq (%rax), %rax
movb (%rax,%r14,4), %al
movb %al, (%r13)
incq %r13
movsbq (%r13), %r14
testq %r14, %r14
jne 0x1538
leaq 0x1b8a(%rip), %rsi      # 0x30e6
leaq 0x110(%rsp), %rdi
pushq $0xe
popq %rdx
callq 0x1120
testl %eax, %eax
je 0x1578
pushq $0xe
popq %rbp
jmp 0x16a5
leaq 0x1b76(%rip), %rsi      # 0x30f5
leaq 0xd0(%rsp), %rdi
pushq $0x7
popq %rdx
callq 0x1120
pushq $0xf
popq %rbp
testl %eax, %eax
jne 0x16a5
movb $0x4d, (%rbx)
leaq 0x1b58(%rip), %rsi      # 0x30fc
leaq 0x90(%rsp), %rdi
pushq $0xb
popq %rdx
callq 0x1120
testl %eax, %eax
je 0x15db
leaq 0x1b48(%rip), %rsi      # 0x3107
leaq 0x90(%rsp), %rdi
pushq $0x6
popq %rdx
callq 0x1120
testl %eax, %eax
jne 0x16a5
movb $0x41, %al
jmp 0x15dd
movb $0x43, %al
movb %al, 0x1(%rbx)
leaq 0x1b26(%rip), %rsi      # 0x310d
leaq 0x50(%rsp), %rdi
pushq $0x5
popq %rdx
callq 0x1120
testl %eax, %eax
je 0x162e
movq 0x50(%rsp), %rax
movabsq $0x78656c706d6f63, %rcx # imm = 0x78656C706D6F63
cmpq %rcx, %rax
je 0x1636
movabsq $0x72656765746e69, %rcx # imm = 0x72656765746E69
cmpq %rcx, %rax
je 0x1632
movabsq $0x6e726574746170, %rcx # imm = 0x6E726574746170
cmpq %rcx, %rax
jne 0x16a5
movb $0x50, %al
jmp 0x1638
movb $0x52, %al
jmp 0x1638
movb $0x49, %al
jmp 0x1638
movb $0x43, %al
movb %al, 0x2(%rbx)
movb $0x47, %al
movabsq $0x6c6172656e6567, %rcx # imm = 0x6C6172656E6567
cmpq %rcx, 0x10(%rsp)
je 0x16a0
leaq 0x1aec(%rip), %rsi      # 0x3141
leaq 0x10(%rsp), %rdi
pushq $0xa
popq %rdx
callq 0x1120
testl %eax, %eax
je 0x169a
leaq 0x1ac5(%rip), %rsi      # 0x3132
leaq 0x10(%rsp), %rdi
pushq $0xa
popq %rdx
callq 0x1120
testl %eax, %eax
je 0x169e
leaq 0x1ab7(%rip), %rsi      # 0x313c
leaq 0x10(%rsp), %rdi
pushq $0xf
popq %rdx
callq 0x1120
testl %eax, %eax
jne 0x16a5
movb $0x4b, %al
jmp 0x16a0
movb $0x53, %al
jmp 0x16a0
movb $0x48, %al
movb %al, 0x3(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x558, %rsp            # imm = 0x558
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq