// File: /workspace/github_c_makefile_star2_O1/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 %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
movl $0xc, %ebp
testq %rax, %rax
je 0x180b
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
leaq 0x1b3d(%rip), %rsi      # 0x30d7
leaq 0x150(%rsp), %rdi
leaq 0x110(%rsp), %rdx
leaq 0xd0(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x90(%rsp), %r9
xorl %eax, %eax
callq 0x1110
cmpl $0x5, %eax
jne 0x180b
movb 0xd0(%rsp), %bpl
testb %bpl, %bpl
je 0x1601
callq 0x1170
leaq 0xd1(%rsp), %rcx
movq (%rax), %rdx
movsbq %bpl, %rsi
movb (%rdx,%rsi,4), %dl
movb %dl, -0x1(%rcx)
movb (%rcx), %bpl
incq %rcx
testb %bpl, %bpl
jne 0x15e9
movb 0x50(%rsp), %bpl
testb %bpl, %bpl
je 0x162d
callq 0x1170
leaq 0x51(%rsp), %rcx
movq (%rax), %rdx
movsbq %bpl, %rsi
movb (%rdx,%rsi,4), %dl
movb %dl, -0x1(%rcx)
movb (%rcx), %bpl
incq %rcx
testb %bpl, %bpl
jne 0x1615
movb 0x90(%rsp), %bpl
testb %bpl, %bpl
je 0x165f
callq 0x1170
leaq 0x91(%rsp), %rcx
movq (%rax), %rdx
movsbq %bpl, %rsi
movb (%rdx,%rsi,4), %dl
movb %dl, -0x1(%rcx)
movb (%rcx), %bpl
incq %rcx
testb %bpl, %bpl
jne 0x1647
movb 0x10(%rsp), %bpl
testb %bpl, %bpl
je 0x168b
callq 0x1170
leaq 0x11(%rsp), %rcx
movq (%rax), %rdx
movsbq %bpl, %rsi
movb (%rdx,%rsi,4), %dl
movb %dl, -0x1(%rcx)
movb (%rcx), %bpl
incq %rcx
testb %bpl, %bpl
jne 0x1673
movabsq $0x78697274614d2525, %rax # imm = 0x78697274614D2525
xorq 0x110(%rsp), %rax
movabsq $0x74656b72614d7869, %rcx # imm = 0x74656B72614D7869
xorq 0x116(%rsp), %rcx
orq %rax, %rcx
movl $0xe, %ebp
jne 0x180b
movl $0x7274616d, %eax       # imm = 0x7274616D
xorl 0xd0(%rsp), %eax
movl $0x786972, %ecx         # imm = 0x786972
xorl 0xd3(%rsp), %ecx
orl %eax, %ecx
movl $0xf, %ebp
jne 0x180b
movb $0x4d, (%rbx)
movabsq $0x616e6964726f6f63, %rax # imm = 0x616E6964726F6F63
xorq 0x50(%rsp), %rax
movabsq $0x6574616e696472, %rcx # imm = 0x6574616E696472
xorq 0x53(%rsp), %rcx
orq %rax, %rcx
je 0x1725
movl $0x61727261, %eax       # imm = 0x61727261
xorl 0x50(%rsp), %eax
movzwl 0x54(%rsp), %ecx
xorl $0x79, %ecx
orl %eax, %ecx
jne 0x180b
movb $0x41, %al
jmp 0x1727
movb $0x43, %al
movb %al, 0x1(%rbx)
movl $0x6c616572, %eax       # imm = 0x6C616572
xorl 0x90(%rsp), %eax
movzbl 0x94(%rsp), %ecx
orl %eax, %ecx
je 0x177f
movq 0x90(%rsp), %rax
movabsq $0x78656c706d6f63, %rcx # imm = 0x78656C706D6F63
cmpq %rcx, %rax
je 0x1787
movabsq $0x72656765746e69, %rcx # imm = 0x72656765746E69
cmpq %rcx, %rax
je 0x1783
movabsq $0x6e726574746170, %rcx # imm = 0x6E726574746170
cmpq %rcx, %rax
jne 0x180b
movb $0x50, %al
jmp 0x1789
movb $0x52, %al
jmp 0x1789
movb $0x49, %al
jmp 0x1789
movb $0x43, %al
movb %al, 0x2(%rbx)
movb $0x47, %al
movabsq $0x6c6172656e6567, %rcx # imm = 0x6C6172656E6567
cmpq %rcx, 0x10(%rsp)
je 0x1806
movabsq $0x697274656d6d7973, %rax # imm = 0x697274656D6D7973
xorq 0x10(%rsp), %rax
movzwl 0x18(%rsp), %ecx
xorq $0x63, %rcx
orq %rax, %rcx
je 0x1800
movabsq $0x616974696d726568, %rax # imm = 0x616974696D726568
xorq 0x10(%rsp), %rax
movzwl 0x18(%rsp), %ecx
xorq $0x6e, %rcx
orq %rax, %rcx
je 0x1804
movabsq $0x6d79732d77656b73, %rax # imm = 0x6D79732D77656B73
xorq 0x10(%rsp), %rax
movabsq $0x63697274656d6d, %rcx # imm = 0x63697274656D6D
xorq 0x17(%rsp), %rcx
orq %rax, %rcx
jne 0x180b
movb $0x4b, %al
jmp 0x1806
movb $0x53, %al
jmp 0x1806
movb $0x48, %al
movb %al, 0x3(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x558, %rsp            # imm = 0x558
popq %rbx
popq %rbp
retq